mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Add support for SHA-256 midstate access
This commit is contained in:
parent
7a01d4f395
commit
7f65e76735
2 changed files with 31 additions and 0 deletions
|
|
@ -670,6 +670,23 @@ CSHA256& CSHA256::Write(const unsigned char* data, size_t len)
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
//
|
||||
//void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
|
||||
//{
|
||||
// static const unsigned char pad[64] = {0x80};
|
||||
// unsigned char sizedesc[8];
|
||||
// WriteBE64(sizedesc, bytes << 3);
|
||||
// Write(pad, 1 + ((119 - (bytes % 64)) % 64));
|
||||
// Write(sizedesc, 8);
|
||||
// WriteBE32(hash, s[0]);
|
||||
// WriteBE32(hash + 4, s[1]);
|
||||
// WriteBE32(hash + 8, s[2]);
|
||||
// WriteBE32(hash + 12, s[3]);
|
||||
// WriteBE32(hash + 16, s[4]);
|
||||
// WriteBE32(hash + 20, s[5]);
|
||||
// WriteBE32(hash + 24, s[6]);
|
||||
// WriteBE32(hash + 28, s[7]);
|
||||
//}
|
||||
|
||||
void CSHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
|
||||
{
|
||||
|
|
@ -678,6 +695,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]);
|
||||
|
|
@ -686,6 +708,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()
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ public:
|
|||
CSHA256();
|
||||
CSHA256& Write(const unsigned char* data, size_t len);
|
||||
void Finalize(unsigned char hash[OUTPUT_SIZE]);
|
||||
//TODO: Midstate is a hack'ish speedup that probably should make way for something
|
||||
//akin to the SHA256D64 speedups
|
||||
void Midstate(unsigned char hash[OUTPUT_SIZE], uint64_t* len, unsigned char *buffer);
|
||||
CSHA256& Reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue