mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Add mistate output to CSHA256.
This allows the intermediate state of a SHA-256 run to be saved for future resumption, or in the case of fast Merkle trees to perform a non-padded hash.
This commit is contained in:
parent
cc49c12e0a
commit
29ad41dd56
2 changed files with 12 additions and 0 deletions
|
|
@ -171,6 +171,11 @@ void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
|
|||
WriteBE64(sizedesc, bytes << 3);
|
||||
Write(pad, 1 + ((119 - (bytes % 64)) % 64));
|
||||
Write(sizedesc, 8);
|
||||
Midstate(hash, NULL, NULL);
|
||||
}
|
||||
|
||||
void CSHA256::Midstate(unsigned char hash[OUTPUT_SIZE], uint64_t* len, unsigned char *buffer)
|
||||
{
|
||||
WriteBE32(hash, s[0]);
|
||||
WriteBE32(hash + 4, s[1]);
|
||||
WriteBE32(hash + 8, s[2]);
|
||||
|
|
@ -179,6 +184,12 @@ void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
|
|||
WriteBE32(hash + 20, s[5]);
|
||||
WriteBE32(hash + 24, s[6]);
|
||||
WriteBE32(hash + 28, s[7]);
|
||||
if (len) {
|
||||
*len = bytes << 3;
|
||||
}
|
||||
if (buffer) {
|
||||
memcpy(buffer, buf, bytes % 64);
|
||||
}
|
||||
}
|
||||
|
||||
CSHA256& CSHA256::Reset()
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
CSHA256();
|
||||
CSHA256& Write(const unsigned char* data, size_t len);
|
||||
void Finalize(unsigned char hash[OUTPUT_SIZE]);
|
||||
void Midstate(unsigned char hash[OUTPUT_SIZE], uint64_t* bytes, unsigned char *buffer);
|
||||
CSHA256& Reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue