@@ -670,6 +670,23 @@ CSHA256& CSHA256::Write(const unsigned char* data, size_t len)
670
670
}
671
671
return *this ;
672
672
}
673
+ //
674
+ // void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
675
+ // {
676
+ // static const unsigned char pad[64] = {0x80};
677
+ // unsigned char sizedesc[8];
678
+ // WriteBE64(sizedesc, bytes << 3);
679
+ // Write(pad, 1 + ((119 - (bytes % 64)) % 64));
680
+ // Write(sizedesc, 8);
681
+ // WriteBE32(hash, s[0]);
682
+ // WriteBE32(hash + 4, s[1]);
683
+ // WriteBE32(hash + 8, s[2]);
684
+ // WriteBE32(hash + 12, s[3]);
685
+ // WriteBE32(hash + 16, s[4]);
686
+ // WriteBE32(hash + 20, s[5]);
687
+ // WriteBE32(hash + 24, s[6]);
688
+ // WriteBE32(hash + 28, s[7]);
689
+ // }
673
690
674
691
void CSHA256::Finalize (unsigned char hash[OUTPUT_SIZE])
675
692
{
@@ -678,6 +695,11 @@ void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
678
695
WriteBE64 (sizedesc, bytes << 3 );
679
696
Write (pad, 1 + ((119 - (bytes % 64 )) % 64 ));
680
697
Write (sizedesc, 8 );
698
+ Midstate (hash, NULL , NULL );
699
+ }
700
+
701
+ void CSHA256::Midstate (unsigned char hash[OUTPUT_SIZE], uint64_t * len, unsigned char *buffer)
702
+ {
681
703
WriteBE32 (hash, s[0 ]);
682
704
WriteBE32 (hash + 4 , s[1 ]);
683
705
WriteBE32 (hash + 8 , s[2 ]);
@@ -686,6 +708,12 @@ void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
686
708
WriteBE32 (hash + 20 , s[5 ]);
687
709
WriteBE32 (hash + 24 , s[6 ]);
688
710
WriteBE32 (hash + 28 , s[7 ]);
711
+ if (len) {
712
+ *len = bytes << 3 ;
713
+ }
714
+ if (buffer) {
715
+ memcpy (buffer, buf, bytes % 64 );
716
+ }
689
717
}
690
718
691
719
CSHA256& CSHA256::Reset ()
0 commit comments