1c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  LibSha1
3c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//
4c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Implementation of SHA1 hash function.
5c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Original author:  Steve Reid <sreid@sea-to-sky.net>
6c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Contributions by: James H. Brown <jbrown@burgoyne.com>, Saul Kravitz <Saul.Kravitz@celera.com>,
7c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  and Ralph Giles <giles@ghostscript.com>
8c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Modified by WaterJuice retaining Public Domain license.
9c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//
10c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
11c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
13c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines#ifndef _sha1_h_
14c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines#define _sha1_h_
15c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
16c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  IMPORTS
18c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
20c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines#include <stdint.h>
21c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines#include <stdio.h>
22c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
23c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  TYPES
25c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
27c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines// Sha1Context - This must be initialised using Sha1Initialised. Do not modify the contents of this structure directly.
28c1db824828d45eb475220c26226b1cc58cd77f23Richard Hainestypedef struct
29c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines{
30c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    uint32_t        State[5];
31c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    uint32_t        Count[2];
32c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    uint8_t         Buffer[64];
33c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines} Sha1Context;
34c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
35c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines#define SHA1_HASH_SIZE           ( 160 / 8 )
36c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
37c1db824828d45eb475220c26226b1cc58cd77f23Richard Hainestypedef struct
38c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines{
39c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    uint8_t      bytes [SHA1_HASH_SIZE];
40c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines} SHA1_HASH;
41c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
42c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  PUBLIC FUNCTIONS
44c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
46c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Sha1Initialise
48c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//
49c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Initialises an SHA1 Context. Use this to initialise/reset a context.
50c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51c1db824828d45eb475220c26226b1cc58cd77f23Richard Hainesvoid
52c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    Sha1Initialise
53c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    (
54c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines        Sha1Context*                Context
55c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    );
56c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
57c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Sha1Update
59c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//
60c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Adds data to the SHA1 context. This will process the data and update the internal state of the context. Keep on
61c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  calling this function until all the data has been added. Then call Sha1Finalise to calculate the hash.
62c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63c1db824828d45eb475220c26226b1cc58cd77f23Richard Hainesvoid
64c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    Sha1Update
65c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    (
66c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines        Sha1Context*        Context,
67c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines        void*               Buffer,
68c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines        uint32_t            BufferSize
69c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    );
70c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
71c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Sha1Finalise
73c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//
74c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  Performs the final calculation of the hash and returns the digest (20 byte buffer containing 160bit hash). After
75c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines//  calling this, Sha1Initialised must be used to reuse the context.
76c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77c1db824828d45eb475220c26226b1cc58cd77f23Richard Hainesvoid
78c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    Sha1Finalise
79c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    (
80c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines        Sha1Context*                Context,
81c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines        SHA1_HASH*                  Digest
82c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines    );
83c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines
84c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85c1db824828d45eb475220c26226b1cc58cd77f23Richard Haines#endif //_sha1_h_
86