74#define SHA1_ROTL(bits,word) \
75 (((word) << (bits)) | ((word) >> (32-(bits))))
82#define SHA1AddLength(context, length) \
83 (addTemp = (context)->Length_Low, \
84 (context)->Corrupted = \
85 (((context)->Length_Low += (length)) < addTemp) && \
86 (++(context)->Length_High == 0) ? shaInputTooLong \
87 : (context)->Corrupted )
108 context->Message_Block_Index = 0;
111 context->Intermediate_Hash[0] = 0x67452301;
112 context->Intermediate_Hash[1] = 0xEFCDAB89;
113 context->Intermediate_Hash[2] = 0x98BADCFE;
114 context->Intermediate_Hash[3] = 0x10325476;
115 context->Intermediate_Hash[4] = 0xC3D2E1F0;
134 const uint8_t *message_array,
unsigned length)
142 if (!message_array) {
182 static uint8_t masks[8] = {
189 static uint8_t markbit[8] = {
209 (uint8_t) ((message_bits & masks[length]) |
233 if (!Message_Digest) {
245 Message_Digest[i] = (uint8_t) (
context->Intermediate_Hash[i >> 2]
246 >> (8 * (3 - (i & 0x03))));
262 const uint32_t K[4] = {
263 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6
268 uint32_t A, B, C, D, E;
273 for (t = 0; t < 16; t++) {
274 W[t] = ((uint32_t)
context->Message_Block[t * 4]) << 24;
275 W[t] |= ((uint32_t)
context->Message_Block[t * 4 + 1]) << 16;
276 W[t] |= ((uint32_t)
context->Message_Block[t * 4 + 2]) << 8;
277 W[t] |= ((uint32_t)
context->Message_Block[t * 4 + 3]);
280 for (t = 16; t < 80; t++) {
281 W[t] =
SHA1_ROTL(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]);
284 A =
context->Intermediate_Hash[0];
285 B =
context->Intermediate_Hash[1];
286 C =
context->Intermediate_Hash[2];
287 D =
context->Intermediate_Hash[3];
288 E =
context->Intermediate_Hash[4];
290 for (t = 0; t < 20; t++) {
299 for (t = 20; t < 40; t++) {
308 for (t = 40; t < 60; t++) {
317 for (t = 60; t < 80; t++) {
326 context->Intermediate_Hash[0] += A;
327 context->Intermediate_Hash[1] += B;
328 context->Intermediate_Hash[2] += C;
329 context->Intermediate_Hash[3] += D;
330 context->Intermediate_Hash[4] += E;
332 context->Message_Block_Index = 0;
379 context->Message_Block[
context->Message_Block_Index++] = Pad_Byte;
386 context->Message_Block[
context->Message_Block_Index++] = Pad_Byte;
395 context->Message_Block[56] = (uint8_t) (
context->Length_High >> 24);
396 context->Message_Block[57] = (uint8_t) (
context->Length_High >> 16);
397 context->Message_Block[58] = (uint8_t) (
context->Length_High >> 8);
399 context->Message_Block[60] = (uint8_t) (
context->Length_Low >> 24);
400 context->Message_Block[61] = (uint8_t) (
context->Length_Low >> 16);
401 context->Message_Block[62] = (uint8_t) (
context->Length_Low >> 8);
static void SHA1PadMessage(SHA1Context *context, uint8_t Pad_Byte)
Pad message to be 512 bits.
#define SHA1_ROTL(bits, word)
int SHA1Reset(SHA1Context *context)
SHA1Reset.
#define SHA1AddLength(context, length)
int SHA1Input(SHA1Context *context, const uint8_t *message_array, unsigned length)
SHA1Input.
static void SHA1ProcessMessageBlock(SHA1Context *context)
Process the next 512 bits of the message stored in the Message_Block array.
int SHA1Result(SHA1Context *context, uint8_t Message_Digest[SHA1HashSize])
SHA1Result Returns the resulting 160-bit digest.
static void SHA1Finalize(SHA1Context *context, uint8_t Pad_Byte)
This helper function finishes off the digest calculations.
int SHA1FinalBits(SHA1Context *context, uint8_t message_bits, unsigned int length)
SHA1FinalBits Add in any final bits of the message.
@ SHA1_Message_Block_Size
#define SHA_Parity(x, y, z)