3 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6 // Implementation of SHA256 hash function.
7 // Original author: Tom St Denis, tomstdenis@gmail.com, http://libtom.org
8 // Modified by WaterJuice retaining Public Domain license.
10 // This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30 #define SHA256_HASH_SIZE ( 256 / 8 )
34 uint8_t bytes [SHA256_HASH_SIZE];
37 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 // Initialises a SHA256 Context. Use this to initialise/reset a context.
45 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 Sha256Context* Context // [out]
52 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55 // Adds data to the SHA256 context. This will process the data and update the internal state of the context. Keep on
56 // calling this function until all the data has been added. Then call Sha256Finalise to calculate the hash.
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 Sha256Context* Context, // [in out]
62 void const* Buffer, // [in]
63 uint32_t BufferSize // [in]
66 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69 // Performs the final calculation of the hash and returns the digest (32 byte buffer containing 256bit hash). After
70 // calling this, Sha256Initialised must be used to reuse the context.
71 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 Sha256Context* Context, // [in out]
76 SHA256_HASH* Digest // [out]
79 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 // Combines Sha256Initialise, Sha256Update, and Sha256Finalise into one function. Calculates the SHA256 hash of the
84 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 void const* Buffer, // [in]
89 uint32_t BufferSize, // [in]
90 SHA256_HASH* Digest // [in]
92 #endif /* __SHA2_H__ */