Skip to content

Commit d0b6b2c

Browse files
authored
Merge pull request #1570 from evoskuil/master
Generalize algorithm<sha>::hash(byte_t) tests.
2 parents 998d1a8 + 2a87ba9 commit d0b6b2c

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

test/hash/hash.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ constexpr auto rmd_half160 = base16_array("d1a70126ff7a149ca6f9b638db084480440ff
2828
constexpr auto rmd_full160 = base16_array("9b8ccc2f374ae313a914763cc9cdfb47bfe1c229");
2929

3030
// null hash vectors.
31+
constexpr auto sha_byte160 = base16_array("5ba93c9db0cff93f52b521d7420e43f6eda2784f");
3132
constexpr auto sha_half160 = base16_array("de8a847bff8c343d69b853a215e6ee775ef2ef96");
3233
constexpr auto sha_full160 = base16_array("c8d7d0ef0eedfa82d2ea1aa592845b9a6d4b02b7");
34+
constexpr auto sha_byte256 = base16_array("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d");
3335
constexpr auto sha_half256 = base16_array("66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925");
3436
constexpr auto sha_full256 = base16_array("f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b");
37+
constexpr auto sha_byte512 = base16_array("b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee");
3538
constexpr auto sha_half512 = base16_array("7be9fda48f4179e611c698a73cff09faf72869431efee6eaad14de0cb44bbf66503f752b7a8eb17083355f3ce6eb7d2806f236b25af96a24e22b887405c20081");
3639
constexpr auto sha_full512 = base16_array("ab942f526272e456ed68a979f50202905ca903a141ed98443567b11ef0bf25a552d639051a01be58558122c58e3de07d749ee59ded36acf0c55cd91924d6ba11");
3740

test/hash/sha/sha160.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
BOOST_AUTO_TEST_SUITE(sha160_tests_)
2323

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

@@ -31,6 +32,7 @@ constexpr auto native = with_shani || with_neon;
3132
BOOST_AUTO_TEST_CASE(sha160__hash__null_hash__expected)
3233
{
3334
// Correlate non-const-evaluated to const-evaluated.
35+
BOOST_REQUIRE_EQUAL(sha160::hash(sha160::byte_t{}), sha_byte160);
3436
BOOST_REQUIRE_EQUAL(sha160::hash(sha160::half_t{}), sha_half160);
3537
BOOST_REQUIRE_EQUAL(sha160::hash(sha160::block_t{}), sha_full160);
3638
}

test/hash/sha/sha256.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ BOOST_AUTO_TEST_SUITE(sha256_tests_)
2424
constexpr auto vector = with_sse41 || with_avx2 || with_avx512;
2525
constexpr auto native = with_shani || with_neon;
2626

27+
// Other test vectors are dependent upon the correctness of these.
28+
static_assert(sha256::hash(sha256::byte_t{}) == sha_byte256);
29+
static_assert(sha256::hash(sha256::half_t{}) == sha_half256);
30+
static_assert(sha256::hash(sha256::block_t{}) == sha_full256);
31+
2732
BOOST_AUTO_TEST_CASE(sha256__hash__null_hash__expected)
2833
{
2934
// Correlate non-const-evaluated to const-evaluated.
35+
BOOST_REQUIRE_EQUAL(sha256::hash(sha256::byte_t{}), sha_byte256);
3036
BOOST_REQUIRE_EQUAL(sha256::hash(sha256::half_t{}), sha_half256);
3137
BOOST_REQUIRE_EQUAL(sha256::hash(sha256::block_t{}), sha_full256);
3238
}
@@ -201,14 +207,6 @@ BOOST_AUTO_TEST_CASE(sha256__hash__quart_blocks__expected)
201207
BOOST_CHECK_EQUAL(sha256::hash(sha256::quart_t{ 0 }, sha256::quart_t{ 0 }), expected);
202208
}
203209

204-
BOOST_AUTO_TEST_CASE(sha256__hash__byte__expected)
205-
{
206-
// github.com/mit-dci/rustreexo/blob/main/src/accumulator/node_hash.rs#L338
207-
constexpr auto expected = base16_array("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d");
208-
static_assert(sha256::hash(0) == expected);
209-
BOOST_CHECK_EQUAL(sha256::hash(0), expected);
210-
}
211-
212210
// sha256::double_hash
213211
BOOST_AUTO_TEST_CASE(sha256__double_hash__full_block__expected)
214212
{

test/hash/sha/sha512.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ BOOST_AUTO_TEST_SUITE(sha512_tests_)
2424
constexpr auto vector = (with_sse41 || with_avx2 || with_avx512) && !build_x32;
2525
constexpr auto native = /*(with_shani || with_neon)*/ false;
2626

27+
// Other test vectors are dependent upon the correctness of these.
28+
static_assert(sha512::hash(sha512::byte_t{}) == sha_byte512);
29+
static_assert(sha512::hash(sha512::half_t{}) == sha_half512);
30+
static_assert(sha512::hash(sha512::block_t{}) == sha_full512);
31+
2732
BOOST_AUTO_TEST_CASE(sha512__hash__null_hash__expected)
2833
{
2934
// Correlate non-const-evaluated to const-evaluated.
35+
BOOST_REQUIRE_EQUAL(sha512::hash(sha512::byte_t{}), sha_byte512);
3036
BOOST_REQUIRE_EQUAL(sha512::hash(sha512::half_t{}), sha_half512);
3137
BOOST_REQUIRE_EQUAL(sha512::hash(sha512::block_t{}), sha_full512);
3238
}

0 commit comments

Comments
 (0)