Skip to content

Commit

Permalink
Merge pull request #1570 from evoskuil/master
Browse files Browse the repository at this point in the history
Generalize algorithm<sha>::hash(byte_t) tests.
  • Loading branch information
evoskuil authored Dec 19, 2024
2 parents 998d1a8 + 2a87ba9 commit d0b6b2c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions test/hash/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ constexpr auto rmd_half160 = base16_array("d1a70126ff7a149ca6f9b638db084480440ff
constexpr auto rmd_full160 = base16_array("9b8ccc2f374ae313a914763cc9cdfb47bfe1c229");

// null hash vectors.
constexpr auto sha_byte160 = base16_array("5ba93c9db0cff93f52b521d7420e43f6eda2784f");
constexpr auto sha_half160 = base16_array("de8a847bff8c343d69b853a215e6ee775ef2ef96");
constexpr auto sha_full160 = base16_array("c8d7d0ef0eedfa82d2ea1aa592845b9a6d4b02b7");
constexpr auto sha_byte256 = base16_array("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d");
constexpr auto sha_half256 = base16_array("66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925");
constexpr auto sha_full256 = base16_array("f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b");
constexpr auto sha_byte512 = base16_array("b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee");
constexpr auto sha_half512 = base16_array("7be9fda48f4179e611c698a73cff09faf72869431efee6eaad14de0cb44bbf66503f752b7a8eb17083355f3ce6eb7d2806f236b25af96a24e22b887405c20081");
constexpr auto sha_full512 = base16_array("ab942f526272e456ed68a979f50202905ca903a141ed98443567b11ef0bf25a552d639051a01be58558122c58e3de07d749ee59ded36acf0c55cd91924d6ba11");

Expand Down
2 changes: 2 additions & 0 deletions test/hash/sha/sha160.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
BOOST_AUTO_TEST_SUITE(sha160_tests_)

// Other test vectors are dependent upon the correctness of these.
static_assert(sha160::hash(sha160::byte_t{}) == sha_byte160);
static_assert(sha160::hash(sha160::half_t{}) == sha_half160);
static_assert(sha160::hash(sha160::block_t{}) == sha_full160);

Expand All @@ -31,6 +32,7 @@ constexpr auto native = with_shani || with_neon;
BOOST_AUTO_TEST_CASE(sha160__hash__null_hash__expected)
{
// Correlate non-const-evaluated to const-evaluated.
BOOST_REQUIRE_EQUAL(sha160::hash(sha160::byte_t{}), sha_byte160);
BOOST_REQUIRE_EQUAL(sha160::hash(sha160::half_t{}), sha_half160);
BOOST_REQUIRE_EQUAL(sha160::hash(sha160::block_t{}), sha_full160);
}
Expand Down
14 changes: 6 additions & 8 deletions test/hash/sha/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ BOOST_AUTO_TEST_SUITE(sha256_tests_)
constexpr auto vector = with_sse41 || with_avx2 || with_avx512;
constexpr auto native = with_shani || with_neon;

// Other test vectors are dependent upon the correctness of these.
static_assert(sha256::hash(sha256::byte_t{}) == sha_byte256);
static_assert(sha256::hash(sha256::half_t{}) == sha_half256);
static_assert(sha256::hash(sha256::block_t{}) == sha_full256);

BOOST_AUTO_TEST_CASE(sha256__hash__null_hash__expected)
{
// Correlate non-const-evaluated to const-evaluated.
BOOST_REQUIRE_EQUAL(sha256::hash(sha256::byte_t{}), sha_byte256);
BOOST_REQUIRE_EQUAL(sha256::hash(sha256::half_t{}), sha_half256);
BOOST_REQUIRE_EQUAL(sha256::hash(sha256::block_t{}), sha_full256);
}
Expand Down Expand Up @@ -201,14 +207,6 @@ BOOST_AUTO_TEST_CASE(sha256__hash__quart_blocks__expected)
BOOST_CHECK_EQUAL(sha256::hash(sha256::quart_t{ 0 }, sha256::quart_t{ 0 }), expected);
}

BOOST_AUTO_TEST_CASE(sha256__hash__byte__expected)
{
// github.com/mit-dci/rustreexo/blob/main/src/accumulator/node_hash.rs#L338
constexpr auto expected = base16_array("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d");
static_assert(sha256::hash(0) == expected);
BOOST_CHECK_EQUAL(sha256::hash(0), expected);
}

// sha256::double_hash
BOOST_AUTO_TEST_CASE(sha256__double_hash__full_block__expected)
{
Expand Down
6 changes: 6 additions & 0 deletions test/hash/sha/sha512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ BOOST_AUTO_TEST_SUITE(sha512_tests_)
constexpr auto vector = (with_sse41 || with_avx2 || with_avx512) && !build_x32;
constexpr auto native = /*(with_shani || with_neon)*/ false;

// Other test vectors are dependent upon the correctness of these.
static_assert(sha512::hash(sha512::byte_t{}) == sha_byte512);
static_assert(sha512::hash(sha512::half_t{}) == sha_half512);
static_assert(sha512::hash(sha512::block_t{}) == sha_full512);

BOOST_AUTO_TEST_CASE(sha512__hash__null_hash__expected)
{
// Correlate non-const-evaluated to const-evaluated.
BOOST_REQUIRE_EQUAL(sha512::hash(sha512::byte_t{}), sha_byte512);
BOOST_REQUIRE_EQUAL(sha512::hash(sha512::half_t{}), sha_half512);
BOOST_REQUIRE_EQUAL(sha512::hash(sha512::block_t{}), sha_full512);
}
Expand Down

0 comments on commit d0b6b2c

Please # to comment.