Debian Codegraph @

contrib/LibSha1.h

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