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