summaryrefslogtreecommitdiff
path: root/Tests/LibCrypto
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2023-03-24 14:53:07 +0100
committerLinus Groh <mail@linusgroh.de>2023-03-24 15:28:10 +0000
commit0606d371fe07eb0261abff8b6c271e518903513f (patch)
tree468fdcdcb00c55fcfb17e0a8bb79c9fef97fb51d /Tests/LibCrypto
parent88b0b80aab65493b1b547879dd145c8f457576e0 (diff)
downloadserenity-0606d371fe07eb0261abff8b6c271e518903513f.zip
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.
Diffstat (limited to 'Tests/LibCrypto')
-rw-r--r--Tests/LibCrypto/TestHash.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Tests/LibCrypto/TestHash.cpp b/Tests/LibCrypto/TestHash.cpp
index d59ba7defd..25e14cf540 100644
--- a/Tests/LibCrypto/TestHash.cpp
+++ b/Tests/LibCrypto/TestHash.cpp
@@ -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;