]> git.tdb.fi Git - libs/crypto.git/blobdiff - source/sha2.cpp
Account for SHA-512 asking for a 128-bit message length
[libs/crypto.git] / source / sha2.cpp
index 24514423580ce6e76ed6a76950248a5294235854..c7f51a5bb00cffeecc9147e6d1dff116401e1534 100644 (file)
@@ -122,8 +122,9 @@ unsigned SHA2<C>::get_digest(char *digest, unsigned len) const
        SHA2<Constants> padded = *this;
 
        char padding[Constants::BLOCK_SIZE] = { static_cast<char>(0x80) };
-       padded.update(padding, Constants::BLOCK_SIZE-(this->unprocessed_bytes+8)%Constants::BLOCK_SIZE);
+       padded.update(padding, Constants::BLOCK_SIZE-(this->unprocessed_bytes+Constants::MIN_PADDING)%Constants::BLOCK_SIZE);
 
+       padded.update(padding+1, Constants::MIN_PADDING-8);
        UInt64 message_length = (processed_bytes+this->unprocessed_bytes)*8;
        write_word(message_length, padding);
        padded.update(padding, 8);