|
Lines 176-183
Link Here
|
| 176 |
* only. |
176 |
* only. |
| 177 |
*/ |
177 |
*/ |
| 178 |
void SHA512_Last(SHA512_CTX*); |
178 |
void SHA512_Last(SHA512_CTX*); |
| 179 |
void SHA256_Transform(SHA256_CTX*, const sha2_word32*); |
179 |
void _SHA256_Transform(SHA256_CTX*, const sha2_word32*); |
| 180 |
void SHA512_Transform(SHA512_CTX*, const sha2_word64*); |
180 |
void _SHA512_Transform(SHA512_CTX*, const sha2_word64*); |
| 181 |
|
181 |
|
| 182 |
|
182 |
|
| 183 |
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/ |
183 |
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/ |
|
Lines 329-335
Link Here
|
| 329 |
(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \ |
329 |
(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \ |
| 330 |
j++ |
330 |
j++ |
| 331 |
|
331 |
|
| 332 |
void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) { |
332 |
void _SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) { |
| 333 |
sha2_word32 a, b, c, d, e, f, g, h, s0, s1; |
333 |
sha2_word32 a, b, c, d, e, f, g, h, s0, s1; |
| 334 |
sha2_word32 T1, *W256; |
334 |
sha2_word32 T1, *W256; |
| 335 |
int j; |
335 |
int j; |
|
Lines 387-393
Link Here
|
| 387 |
|
387 |
|
| 388 |
#else /* SHA2_UNROLL_TRANSFORM */ |
388 |
#else /* SHA2_UNROLL_TRANSFORM */ |
| 389 |
|
389 |
|
| 390 |
void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) { |
390 |
void _SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) { |
| 391 |
sha2_word32 a, b, c, d, e, f, g, h, s0, s1; |
391 |
sha2_word32 a, b, c, d, e, f, g, h, s0, s1; |
| 392 |
sha2_word32 T1, T2, *W256; |
392 |
sha2_word32 T1, T2, *W256; |
| 393 |
int j; |
393 |
int j; |
|
Lines 489-495
Link Here
|
| 489 |
context->bitcount += freespace << 3; |
489 |
context->bitcount += freespace << 3; |
| 490 |
len -= freespace; |
490 |
len -= freespace; |
| 491 |
data += freespace; |
491 |
data += freespace; |
| 492 |
SHA256_Transform(context, (sha2_word32*)context->buffer); |
492 |
_SHA256_Transform(context, (sha2_word32*)context->buffer); |
| 493 |
} else { |
493 |
} else { |
| 494 |
/* The buffer is not yet full */ |
494 |
/* The buffer is not yet full */ |
| 495 |
MEMCPY_BCOPY(&context->buffer[usedspace], data, len); |
495 |
MEMCPY_BCOPY(&context->buffer[usedspace], data, len); |
|
Lines 501-507
Link Here
|
| 501 |
} |
501 |
} |
| 502 |
while (len >= SHA256_BLOCK_LENGTH) { |
502 |
while (len >= SHA256_BLOCK_LENGTH) { |
| 503 |
/* Process as many complete blocks as we can */ |
503 |
/* Process as many complete blocks as we can */ |
| 504 |
SHA256_Transform(context, (const sha2_word32*)data); |
504 |
_SHA256_Transform(context, (const sha2_word32*)data); |
| 505 |
context->bitcount += SHA256_BLOCK_LENGTH << 3; |
505 |
context->bitcount += SHA256_BLOCK_LENGTH << 3; |
| 506 |
len -= SHA256_BLOCK_LENGTH; |
506 |
len -= SHA256_BLOCK_LENGTH; |
| 507 |
data += SHA256_BLOCK_LENGTH; |
507 |
data += SHA256_BLOCK_LENGTH; |
|
Lines 541-547
Link Here
|
| 541 |
MEMSET_BZERO(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace); |
541 |
MEMSET_BZERO(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace); |
| 542 |
} |
542 |
} |
| 543 |
/* Do second-to-last transform: */ |
543 |
/* Do second-to-last transform: */ |
| 544 |
SHA256_Transform(context, (sha2_word32*)context->buffer); |
544 |
_SHA256_Transform(context, (sha2_word32*)context->buffer); |
| 545 |
|
545 |
|
| 546 |
/* And set-up for the last transform: */ |
546 |
/* And set-up for the last transform: */ |
| 547 |
MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH); |
547 |
MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH); |
|
Lines 557-563
Link Here
|
| 557 |
*(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount; |
557 |
*(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount; |
| 558 |
|
558 |
|
| 559 |
/* Final transform: */ |
559 |
/* Final transform: */ |
| 560 |
SHA256_Transform(context, (sha2_word32*)context->buffer); |
560 |
_SHA256_Transform(context, (sha2_word32*)context->buffer); |
| 561 |
|
561 |
|
| 562 |
#ifndef WORDS_BIGENDIAN |
562 |
#ifndef WORDS_BIGENDIAN |
| 563 |
{ |
563 |
{ |
|
Lines 624-630
Link Here
|
| 624 |
(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \ |
624 |
(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \ |
| 625 |
j++ |
625 |
j++ |
| 626 |
|
626 |
|
| 627 |
void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) { |
627 |
void _SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) { |
| 628 |
sha2_word64 a, b, c, d, e, f, g, h, s0, s1; |
628 |
sha2_word64 a, b, c, d, e, f, g, h, s0, s1; |
| 629 |
sha2_word64 T1, *W512 = (sha2_word64*)context->buffer; |
629 |
sha2_word64 T1, *W512 = (sha2_word64*)context->buffer; |
| 630 |
int j; |
630 |
int j; |
|
Lines 679-685
Link Here
|
| 679 |
|
679 |
|
| 680 |
#else /* SHA2_UNROLL_TRANSFORM */ |
680 |
#else /* SHA2_UNROLL_TRANSFORM */ |
| 681 |
|
681 |
|
| 682 |
void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) { |
682 |
void _SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) { |
| 683 |
sha2_word64 a, b, c, d, e, f, g, h, s0, s1; |
683 |
sha2_word64 a, b, c, d, e, f, g, h, s0, s1; |
| 684 |
sha2_word64 T1, T2, *W512 = (sha2_word64*)context->buffer; |
684 |
sha2_word64 T1, T2, *W512 = (sha2_word64*)context->buffer; |
| 685 |
int j; |
685 |
int j; |
|
Lines 779-785
Link Here
|
| 779 |
ADDINC128(context->bitcount, freespace << 3); |
779 |
ADDINC128(context->bitcount, freespace << 3); |
| 780 |
len -= freespace; |
780 |
len -= freespace; |
| 781 |
data += freespace; |
781 |
data += freespace; |
| 782 |
SHA512_Transform(context, (const sha2_word64*)context->buffer); |
782 |
_SHA512_Transform(context, (const sha2_word64*)context->buffer); |
| 783 |
} else { |
783 |
} else { |
| 784 |
/* The buffer is not yet full */ |
784 |
/* The buffer is not yet full */ |
| 785 |
MEMCPY_BCOPY(&context->buffer[usedspace], data, len); |
785 |
MEMCPY_BCOPY(&context->buffer[usedspace], data, len); |
|
Lines 791-797
Link Here
|
| 791 |
} |
791 |
} |
| 792 |
while (len >= SHA512_BLOCK_LENGTH) { |
792 |
while (len >= SHA512_BLOCK_LENGTH) { |
| 793 |
/* Process as many complete blocks as we can */ |
793 |
/* Process as many complete blocks as we can */ |
| 794 |
SHA512_Transform(context, (const sha2_word64*)data); |
794 |
_SHA512_Transform(context, (const sha2_word64*)data); |
| 795 |
ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); |
795 |
ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); |
| 796 |
len -= SHA512_BLOCK_LENGTH; |
796 |
len -= SHA512_BLOCK_LENGTH; |
| 797 |
data += SHA512_BLOCK_LENGTH; |
797 |
data += SHA512_BLOCK_LENGTH; |
|
Lines 826-832
Link Here
|
| 826 |
MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace); |
826 |
MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace); |
| 827 |
} |
827 |
} |
| 828 |
/* Do second-to-last transform: */ |
828 |
/* Do second-to-last transform: */ |
| 829 |
SHA512_Transform(context, (const sha2_word64*)context->buffer); |
829 |
_SHA512_Transform(context, (const sha2_word64*)context->buffer); |
| 830 |
|
830 |
|
| 831 |
/* And set-up for the last transform: */ |
831 |
/* And set-up for the last transform: */ |
| 832 |
MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2); |
832 |
MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2); |
|
Lines 843-849
Link Here
|
| 843 |
*(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0]; |
843 |
*(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0]; |
| 844 |
|
844 |
|
| 845 |
/* Final transform: */ |
845 |
/* Final transform: */ |
| 846 |
SHA512_Transform(context, (const sha2_word64*)context->buffer); |
846 |
_SHA512_Transform(context, (const sha2_word64*)context->buffer); |
| 847 |
} |
847 |
} |
| 848 |
|
848 |
|
| 849 |
void SHA512_Finish(SHA512_CTX* context, sha2_byte digest[]) { |
849 |
void SHA512_Finish(SHA512_CTX* context, sha2_byte digest[]) { |