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