mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 03:02:29 +00:00
feat(sha1): add SHA1_InterleaveHash
This commit is contained in:
parent
ca7b7c3bc6
commit
04ee35a71b
3 changed files with 89 additions and 0 deletions
|
|
@ -55,3 +55,35 @@ TEST_CASE("SHA1_Final", "[util]") {
|
|||
REQUIRE(memcmp(digest, expected, sizeof(digest)) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SHA1_InterleaveHash", "[sha1]") {
|
||||
SECTION("correctly computes interleaved digest of empty string") {
|
||||
auto input = "";
|
||||
uint8_t digest[SHA1_DIGEST_SIZE * 2];
|
||||
uint8_t expected[SHA1_DIGEST_SIZE * 2] = { 0xda, 0xda, 0x39, 0x39, 0xa3, 0xa3, 0xee, 0xee, 0x5e, 0x5e, 0x6b, 0x6b, 0x4b, 0x4b, 0x0d, 0x0d, 0x32, 0x32, 0x55, 0x55, 0xbf, 0xbf, 0xef, 0xef, 0x95, 0x95, 0x60, 0x60, 0x18, 0x18, 0x90, 0x90, 0xaf, 0xaf, 0xd8, 0xd8, 0x07, 0x07, 0x09, 0x09 };
|
||||
|
||||
SHA1_InterleaveHash(digest, reinterpret_cast<const uint8_t*>(input), strlen(input));
|
||||
|
||||
REQUIRE(memcmp(digest, expected, sizeof(digest)) == 0);
|
||||
}
|
||||
|
||||
SECTION("correctly computes interleaved digest of 'xyz'") {
|
||||
auto input = "xyz";
|
||||
uint8_t digest[SHA1_DIGEST_SIZE * 2];
|
||||
uint8_t expected[SHA1_DIGEST_SIZE * 2] = { 0x95, 0x39, 0xcb, 0x5d, 0x0b, 0xf8, 0xfd, 0xf7, 0x29, 0xc5, 0x77, 0x1f, 0xc7, 0x00, 0x61, 0x70, 0x29, 0x19, 0x8d, 0xcb, 0x96, 0x30, 0x24, 0x20, 0xe4, 0x1c, 0xb4, 0x49, 0xd4, 0xe8, 0xc7, 0x84, 0x2a, 0xb4, 0x39, 0x6b, 0x97, 0x92, 0x4a, 0xfa };
|
||||
|
||||
SHA1_InterleaveHash(digest, reinterpret_cast<const uint8_t*>(input), strlen(input));
|
||||
|
||||
REQUIRE(memcmp(digest, expected, sizeof(digest)) == 0);
|
||||
}
|
||||
|
||||
SECTION("correctly computes interleaved digest of 'foobar'") {
|
||||
auto input = "foobar";
|
||||
uint8_t digest[SHA1_DIGEST_SIZE * 2];
|
||||
uint8_t expected[SHA1_DIGEST_SIZE * 2] = { 0xba, 0xdf, 0x06, 0x40, 0x23, 0x4f, 0xbd, 0x14, 0xc6, 0x5f, 0x7c, 0x1c, 0x26, 0xe8, 0xd2, 0x31, 0x05, 0x06, 0xbb, 0x50, 0x58, 0x88, 0xac, 0x33, 0xc0, 0xf5, 0xaa, 0xe3, 0x9d, 0x03, 0xe6, 0x71, 0x6b, 0xdf, 0xa6, 0x84, 0x0c, 0x40, 0x24, 0xba };
|
||||
|
||||
SHA1_InterleaveHash(digest, reinterpret_cast<const uint8_t*>(input), strlen(input));
|
||||
|
||||
REQUIRE(memcmp(digest, expected, sizeof(digest)) == 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue