Home | History | Annotate | Download | only in sha2

Lines Matching full:context

334 void SHA256_Init(SHA256_CTX* context) {
335 if (context == (SHA256_CTX*)0) {
338 bcopy(sha256_initial_hash_value, context->state, SHA256_DIGEST_LENGTH);
339 bzero(context->buffer, SHA256_BLOCK_LENGTH);
340 context->bitcount = 0;
380 void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
385 W256 = (sha2_word32*)context->buffer;
388 a = context->state[0];
389 b = context->state[1];
390 c = context->state[2];
391 d = context->state[3];
392 e = context->state[4];
393 f = context->state[5];
394 g = context->state[6];
395 h = context->state[7];
423 context->state[0] += a;
424 context->state[1] += b;
425 context->state[2] += c;
426 context->state[3] += d;
427 context->state[4] += e;
428 context->state[5] += f;
429 context->state[6] += g;
430 context->state[7] += h;
438 void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
443 W256 = (sha2_word32*)context->buffer;
446 a = context->state[0];
447 b = context->state[1];
448 c = context->state[2];
449 d = context->state[3];
450 e = context->state[4];
451 f = context->state[5];
452 g = context->state[6];
453 h = context->state[7];
503 context->state[0] += a;
504 context->state[1] += b;
505 context->state[2] += c;
506 context->state[3] += d;
507 context->state[4] += e;
508 context->state[5] += f;
509 context->state[6] += g;
510 context->state[7] += h;
518 void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
527 assert(context != (SHA256_CTX*)0 && data != (sha2_byte*)0);
529 usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
536 bcopy(data, &context->buffer[usedspace], freespace);
537 context->bitcount += freespace << 3;
540 SHA256_Transform(context, (sha2_word32*)context->buffer);
543 bcopy(data, &context->buffer[usedspace], len);
544 context->bitcount += len << 3;
552 SHA256_Transform(context, (const sha2_word32*)data);
553 context->bitcount += SHA256_BLOCK_LENGTH << 3;
559 bcopy(data, context->buffer, len);
560 context->bitcount += len << 3;
566 void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
571 assert(context != (SHA256_CTX*)0);
575 usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
578 REVERSE64(context->bitcount,context->bitcount);
582 context->buffer[usedspace++] = 0x80;
586 bzero(&context->buffer[usedspace], SHA256_SHORT_BLOCK_LENGTH - usedspace);
589 bzero(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace);
592 SHA256_Transform(context, (sha2_word32*)context->buffer);
595 bzero(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
599 bzero(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
602 *context->buffer = 0x80;
605 *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
608 SHA256_Transform(context, (sha2_word32*)context->buffer);
615 REVERSE32(context->state[j],context->state[j]);
616 *d++ = context->state[j];
620 bcopy(context->state, d, SHA256_DIGEST_LENGTH);
625 bzero(context, sizeof(*context));
629 char *SHA256_End(SHA256_CTX* context, char buffer[]) {
634 assert(context != (SHA256_CTX*)0);
637 SHA256_Final(digest, context);
646 bzero(context, sizeof(*context));
653 SHA256_CTX context;
655 SHA256_Init(&context);
656 SHA256_Update(&context, data, len);
657 return SHA256_End(&context, digest);
662 void SHA512_Init(SHA512_CTX* context) {
663 if (context == (SHA512_CTX*)0) {
666 bcopy(sha512_initial_hash_value, context->state, SHA512_DIGEST_LENGTH);
667 bzero(context->buffer, SHA512_BLOCK_LENGTH);
668 context->bitcount[0] = context->bitcount[1] = 0;
707 void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
709 sha2_word64 T1, *W512 = (sha2_word64*)context->buffer;
713 a = context->state[0];
714 b = context->state[1];
715 c = context->state[2];
716 d = context->state[3];
717 e = context->state[4];
718 f = context->state[5];
719 g = context->state[6];
720 h = context->state[7];
747 context->state[0] += a;
748 context->state[1] += b;
749 context->state[2] += c;
750 context->state[3] += d;
751 context->state[4] += e;
752 context->state[5] += f;
753 context->state[6] += g;
754 context->state[7] += h;
762 void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
764 sha2_word64 T1, T2, *W512 = (sha2_word64*)context->buffer;
768 a = context->state[0];
769 b = context->state[1];
770 c = context->state[2];
771 d = context->state[3];
772 e = context->state[4];
773 f = context->state[5];
774 g = context->state[6];
775 h = context->state[7];
825 context->state[0] += a;
826 context->state[1] += b;
827 context->state[2] += c;
828 context->state[3] += d;
829 context->state[4] += e;
830 context->state[5] += f;
831 context->state[6] += g;
832 context->state[7] += h;
840 void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
849 assert(context != (SHA512_CTX*)0 && data != (sha2_byte*)0);
851 usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
858 bcopy(data, &context->buffer[usedspace], freespace);
859 ADDINC128(context->bitcount, freespace << 3);
862 SHA512_Transform(context, (sha2_word64*)context->buffer);
865 bcopy(data, &context->buffer[usedspace], len);
866 ADDINC128(context->bitcount, len << 3);
874 SHA512_Transform(context, (const sha2_word64*)data);
875 ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
881 bcopy(data, context->buffer, len);
882 ADDINC128(context->bitcount, len << 3);
888 void SHA512_Last(SHA512_CTX* context) {
891 usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
894 REVERSE64(context->bitcount[0],context->bitcount[0]);
895 REVERSE64(context->bitcount[1],context->bitcount[1]);
899 context->buffer[usedspace++] = 0x80;
903 bzero(&context->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace);
906 bzero(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace);
909 SHA512_Transform(context, (sha2_word64*)context->buffer);
912 bzero(context->buffer, SHA512_BLOCK_LENGTH - 2);
916 bzero(context->buffer, SHA512_SHORT_BLOCK_LENGTH);
919 *context->buffer = 0x80;
922 *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
923 *(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
926 SHA512_Transform(context, (sha2_word64*)context->buffer);
929 void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
933 assert(context != (SHA512_CTX*)0);
937 SHA512_Last(context);
945 REVERSE64(context->state[j],context->state[j]);
946 *d++ = context->state[j];
950 bcopy(context->state, d, SHA512_DIGEST_LENGTH);
955 bzero(context, sizeof(*context));
958 char *SHA512_End(SHA512_CTX* context, char buffer[]) {
963 assert(context != (SHA512_CTX*)0);
966 SHA512_Final(digest, context);
975 bzero(context, sizeof(*context));
982 SHA512_CTX context;
984 SHA512_Init(&context);
985 SHA512_Update(&context, data, len);
986 return SHA512_End(&context, digest);
991 void SHA384_Init(SHA384_CTX* context) {
992 if (context == (SHA384_CTX*)0) {
995 bcopy(sha384_initial_hash_value, context->state, SHA512_DIGEST_LENGTH);
996 bzero(context->buffer, SHA384_BLOCK_LENGTH);
997 context->bitcount[0] = context->bitcount[1] = 0;
1000 void SHA384_Update(SHA384_CTX* context, const sha2_byte* data, size_t len) {
1001 SHA512_Update((SHA512_CTX*)context, data, len);
1004 void SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
1008 assert(context != (SHA384_CTX*)0);
1012 SHA512_Last((SHA512_CTX*)context);
1020 REVERSE64(context->state[j],context->state[j]);
1021 *d++ = context->state[j];
1025 bcopy(context->state, d, SHA384_DIGEST_LENGTH);
1030 bzero(context, sizeof(*context));
1033 char *SHA384_End(SHA384_CTX* context, char buffer[]) {
1038 assert(context != (SHA384_CTX*)0);
1041 SHA384_Final(digest, context);
1050 bzero(context, sizeof(*context));
1057 SHA384_CTX context;
1059 SHA384_Init(&context);
1060 SHA384_Update(&context, data, len);
1061 return SHA384_End(&context, digest);