103 Message_Block_Index = 0;
148 for(i = 0; i < 5; i++)
150 message_digest_array[i] = H[i];
182 if (Computed || Corrupted)
188 while(length-- && !Corrupted)
190 Message_Block[Message_Block_Index++] = (*message_array & 0xFF);
193 Length_Low &= 0xFFFFFFFF;
197 Length_High &= 0xFFFFFFFF;
198 if (Length_High == 0)
204 if (Message_Block_Index == 64)
206 ProcessMessageBlock();
236 Input((
unsigned char *) message_array, length);
257 Input(&message_element, 1);
278 Input((
unsigned char *) &message_element, 1);
301 const char *p = message_array;
332 const unsigned char *p = message_array;
362 Input((
unsigned char *) &message_element, 1);
386 Input(&message_element, 1);
410 void SHA1::ProcessMessageBlock()
412 const unsigned K[] = {
421 unsigned A, B, C, D, E;
426 for(t = 0; t < 16; t++)
428 W[t] = Message_Block[t * 4] << 24;
429 W[t] |= Message_Block[t * 4 + 1] << 16;
430 W[t] |= Message_Block[t * 4 + 2] << 8;
431 W[t] |= Message_Block[t * 4 + 3];
434 for(t = 16; t < 80; t++)
436 W[t] = CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
445 for(t = 0; t < 20; t++)
447 temp = CircularShift(5,A) + ((B & C) | ((~B) & D)) + E + W[t] + K[0];
451 C = CircularShift(30,B);
456 for(t = 20; t < 40; t++)
458 temp = CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
462 C = CircularShift(30,B);
467 for(t = 40; t < 60; t++)
469 temp = CircularShift(5,A) +
470 ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
474 C = CircularShift(30,B);
479 for(t = 60; t < 80; t++)
481 temp = CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
485 C = CircularShift(30,B);
490 H[0] = (H[0] + A) & 0xFFFFFFFF;
491 H[1] = (H[1] + B) & 0xFFFFFFFF;
492 H[2] = (H[2] + C) & 0xFFFFFFFF;
493 H[3] = (H[3] + D) & 0xFFFFFFFF;
494 H[4] = (H[4] + E) & 0xFFFFFFFF;
496 Message_Block_Index = 0;
520 void SHA1::PadMessage()
527 if (Message_Block_Index > 55)
529 Message_Block[Message_Block_Index++] = 0x80;
530 while(Message_Block_Index < 64)
532 Message_Block[Message_Block_Index++] = 0;
535 ProcessMessageBlock();
537 while(Message_Block_Index < 56)
539 Message_Block[Message_Block_Index++] = 0;
544 Message_Block[Message_Block_Index++] = 0x80;
545 while(Message_Block_Index < 56)
547 Message_Block[Message_Block_Index++] = 0;
555 Message_Block[56] = (Length_High >> 24) & 0xFF;
556 Message_Block[57] = (Length_High >> 16) & 0xFF;
557 Message_Block[58] = (Length_High >> 8) & 0xFF;
558 Message_Block[59] = (Length_High) & 0xFF;
559 Message_Block[60] = (Length_Low >> 24) & 0xFF;
560 Message_Block[61] = (Length_Low >> 16) & 0xFF;
561 Message_Block[62] = (Length_Low >> 8) & 0xFF;
562 Message_Block[63] = (Length_Low) & 0xFF;
564 ProcessMessageBlock();
586 unsigned SHA1::CircularShift(
int bits,
unsigned word)
588 return ((word << bits) & 0xFFFFFFFF) | ((word & 0xFFFFFFFF) >> (32-bits));