1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

Tests/LibCrypto: Test block splitting logic for SHA1/SHA256

We were not testing this logic and I caused a regression while
modifying some of the hashing code, so let's add these. Note that I only
added two tests to test both 'families' of implementations for the SHA
hashes.
This commit is contained in:
Jelle Raaijmakers 2023-03-24 14:53:07 +01:00 committed by Linus Groh
parent 88b0b80aab
commit 0606d371fe

View file

@ -142,6 +142,15 @@ TEST_CASE(test_SHA1_hash_successive_updates)
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA1::digest_size()) == 0);
}
TEST_CASE(test_SHA1_hash_split_into_blocks)
{
u8 result[] {
0x53, 0x58, 0x96, 0x2d, 0xac, 0x60, 0xb6, 0xcf, 0xdc, 0xc0, 0x2c, 0x70, 0xc5, 0x36, 0xdb, 0x0b, 0x3c, 0x01, 0xc9, 0x90
};
auto digest = Crypto::Hash::SHA1::hash("0123456789012345678901234567890123456789012345678901234567890123abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA1::digest_size()) == 0);
}
TEST_CASE(test_SHA256_name)
{
Crypto::Hash::SHA256 sha;
@ -166,6 +175,15 @@ TEST_CASE(test_SHA256_hash_empty_string)
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA256::digest_size()) == 0);
}
TEST_CASE(test_SHA256_hash_split_into_blocks)
{
u8 result[] {
0x1b, 0x90, 0x74, 0xf9, 0x9b, 0xf3, 0x56, 0x20, 0xd3, 0xf6, 0xbf, 0x7d, 0x72, 0x53, 0xb3, 0x3c, 0xd1, 0x1b, 0x7d, 0xd8, 0xa9, 0xa0, 0x4e, 0x55, 0xf5, 0x72, 0x43, 0x94, 0xaf, 0x27, 0x6c, 0x5c
};
auto digest = Crypto::Hash::SHA256::hash("0123456789012345678901234567890123456789012345678901234567890123abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd"sv);
EXPECT(memcmp(result, digest.data, Crypto::Hash::SHA256::digest_size()) == 0);
}
TEST_CASE(test_SHA384_name)
{
Crypto::Hash::SHA384 sha;