mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:08:10 +00:00
LibCrypto: Add support for BLAKE2b
This commit is contained in:
parent
da2c18d1f9
commit
1b3ad1c721
8 changed files with 302 additions and 2 deletions
|
@ -6,12 +6,69 @@
|
|||
|
||||
#include <LibCrypto/Authentication/GHash.h>
|
||||
#include <LibCrypto/Authentication/HMAC.h>
|
||||
#include <LibCrypto/Hash/BLAKE2b.h>
|
||||
#include <LibCrypto/Hash/MD5.h>
|
||||
#include <LibCrypto/Hash/SHA1.h>
|
||||
#include <LibCrypto/Hash/SHA2.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <cstring>
|
||||
|
||||
TEST_CASE(test_BLAKE2b_name)
|
||||
{
|
||||
Crypto::Hash::BLAKE2b blake2b;
|
||||
EXPECT_EQ(blake2b.class_name(), "BLAKE2b"sv);
|
||||
}
|
||||
|
||||
TEST_CASE(test_BLAKE2b_hash_string)
|
||||
{
|
||||
u8 result[] {
|
||||
0x9d, 0xaa, 0x2e, 0x57, 0xc4, 0x94, 0xb6, 0xfd, 0x61, 0x6e, 0x39, 0x0b, 0x71, 0xf4, 0x19, 0x03, 0x41, 0x5c, 0x5c, 0x61, 0x7e, 0x30, 0x0a, 0xf0, 0x0b, 0x3e, 0x9c, 0x77, 0x23, 0x1f, 0x11, 0x4d, 0x83, 0x9d, 0xd6, 0xe0, 0x4a, 0x92, 0x19, 0xae, 0xec, 0xc9, 0x13, 0x57, 0xc6, 0xf1, 0x06, 0x92, 0xb9, 0xf9, 0x97, 0x3e, 0xfd, 0xb3, 0x6f, 0xc8, 0xe1, 0x94, 0xad, 0x8e, 0x33, 0xc2, 0x66, 0x3f
|
||||
};
|
||||
auto digest = Crypto::Hash::BLAKE2b::hash("Well hello friends"sv);
|
||||
EXPECT(memcmp(result, digest.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_BLAKE2b_hash_empty_string)
|
||||
{
|
||||
u8 result[] {
|
||||
0x78, 0x6a, 0x02, 0xf7, 0x42, 0x01, 0x59, 0x03, 0xc6, 0xc6, 0xfd, 0x85, 0x25, 0x52, 0xd2, 0x72, 0x91, 0x2f, 0x47, 0x40, 0xe1, 0x58, 0x47, 0x61, 0x8a, 0x86, 0xe2, 0x17, 0xf7, 0x1f, 0x54, 0x19, 0xd2, 0x5e, 0x10, 0x31, 0xaf, 0xee, 0x58, 0x53, 0x13, 0x89, 0x64, 0x44, 0x93, 0x4e, 0xb0, 0x4b, 0x90, 0x3a, 0x68, 0x5b, 0x14, 0x48, 0xb7, 0x55, 0xd5, 0x6f, 0x70, 0x1a, 0xfe, 0x9b, 0xe2, 0xce
|
||||
};
|
||||
auto digest = Crypto::Hash::BLAKE2b::hash(""sv);
|
||||
EXPECT(memcmp(result, digest.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_BLAKE2b_consecutive_multiple_updates)
|
||||
{
|
||||
u8 result[] {
|
||||
0x9d, 0xaa, 0x2e, 0x57, 0xc4, 0x94, 0xb6, 0xfd, 0x61, 0x6e, 0x39, 0x0b, 0x71, 0xf4, 0x19, 0x03, 0x41, 0x5c, 0x5c, 0x61, 0x7e, 0x30, 0x0a, 0xf0, 0x0b, 0x3e, 0x9c, 0x77, 0x23, 0x1f, 0x11, 0x4d, 0x83, 0x9d, 0xd6, 0xe0, 0x4a, 0x92, 0x19, 0xae, 0xec, 0xc9, 0x13, 0x57, 0xc6, 0xf1, 0x06, 0x92, 0xb9, 0xf9, 0x97, 0x3e, 0xfd, 0xb3, 0x6f, 0xc8, 0xe1, 0x94, 0xad, 0x8e, 0x33, 0xc2, 0x66, 0x3f
|
||||
};
|
||||
Crypto::Hash::BLAKE2b blake2b;
|
||||
|
||||
blake2b.update("Well"sv);
|
||||
blake2b.update(" hello "sv);
|
||||
blake2b.update("friends"sv);
|
||||
auto digest = blake2b.digest();
|
||||
|
||||
EXPECT(memcmp(result, digest.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_BLAKE2b_consecutive_updates_reuse)
|
||||
{
|
||||
Crypto::Hash::BLAKE2b blake2b;
|
||||
|
||||
blake2b.update("Well"sv);
|
||||
blake2b.update(" hello "sv);
|
||||
blake2b.update("friends"sv);
|
||||
auto digest0 = blake2b.digest();
|
||||
|
||||
blake2b.update("Well"sv);
|
||||
blake2b.update(" hello "sv);
|
||||
blake2b.update("friends"sv);
|
||||
auto digest1 = blake2b.digest();
|
||||
|
||||
EXPECT(memcmp(digest0.data, digest1.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(test_MD5_name)
|
||||
{
|
||||
Crypto::Hash::MD5 md5;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue