diff --git a/include/duckhandy/tiger_bt.hpp b/include/duckhandy/tiger_bt.hpp index 7c07bfc..7281f7e 100644 --- a/include/duckhandy/tiger_bt.hpp +++ b/include/duckhandy/tiger_bt.hpp @@ -24,18 +24,18 @@ #include namespace dhandy::bt { - struct HashType { - consteval HashType ( uint64_t parA, uint64_t parB, uint64_t parC ) : + struct TigerHash { + consteval TigerHash ( uint64_t parA, uint64_t parB, uint64_t parC ) : a(parA), b(parB), c(parC) { } - consteval HashType ( uint64_t parAP, uint64_t parA, uint64_t parBP, uint64_t parB, uint64_t parCP, uint64_t parC ) : + consteval TigerHash ( uint64_t parAP, uint64_t parA, uint64_t parBP, uint64_t parB, uint64_t parCP, uint64_t parC ) : a(0 == parAP ? parA : (0 == parBP ? parB : (0 == parCP ? parC : throw 0))), b(1 == parAP ? parA : (1 == parBP ? parB : (1 == parCP ? parC : throw 0))), c(2 == parAP ? parA : (2 == parBP ? parB : (2 == parCP ? parC : throw 0))) { } - consteval HashType ( const HashType& ) = default; + consteval TigerHash ( const TigerHash& ) = default; consteval uint64_t operator[] ( uint64_t parIndex ) const { return (parIndex == 0 ? a : (parIndex == 1 ? b : @@ -53,7 +53,7 @@ namespace dhandy::bt { inline const constexpr char TigerPaddingV2 = 0x80; [[gnu::const]] - consteval HashType tiger ( const char* parStr, uint64_t parLen, char parPad ); + consteval TigerHash tiger ( const char* parStr, uint64_t parLen, char parPad ); } //namespace dhandy::bt #include "tiger_bt.inl" diff --git a/include/duckhandy/tiger_bt.inl b/include/duckhandy/tiger_bt.inl index c982962..8ec5a6c 100644 --- a/include/duckhandy/tiger_bt.inl +++ b/include/duckhandy/tiger_bt.inl @@ -358,8 +358,8 @@ namespace dhandy::bt { return (r >> (a * CHAR_BIT)) bitand 0xff; } - consteval HashType round (uint64_t mul, uint64_t a, uint64_t b, uint64_t c, uint64_t x, const TigerBlock& block, const HashType& hash) { - return HashType( + consteval TigerHash round (uint64_t mul, uint64_t a, uint64_t b, uint64_t c, uint64_t x, const TigerBlock& block, const TigerHash& hash) { + return TigerHash( a, hash[a] - ( table[ gb(hash[c] xor block[x], 0)] xor @@ -377,7 +377,7 @@ namespace dhandy::bt { ); } - consteval HashType pass (uint64_t a, uint64_t b, uint64_t c, uint64_t mul, const TigerBlock& block, const HashType& hash, uint64_t x=0) { + consteval TigerHash pass (uint64_t a, uint64_t b, uint64_t c, uint64_t mul, const TigerBlock& block, const TigerHash& hash, uint64_t x=0) { return ( 8 == x ? //if 0 == x @@ -426,15 +426,15 @@ namespace dhandy::bt { ); } - consteval HashType finalize_tiger_step (HashType parOriginal, HashType parPartial) { - return HashType( + consteval TigerHash finalize_tiger_step (TigerHash parOriginal, TigerHash parPartial) { + return TigerHash( parPartial.a ^ parOriginal.a, parPartial.b - parOriginal.b, parPartial.c + parOriginal.c ); } - consteval HashType tiger_block (const TigerBlock& parBlock, HashType parHash) { + consteval TigerHash tiger_block (const TigerBlock& parBlock, TigerHash parHash) { return finalize_tiger_step( parHash, pass(1, 2, 0, 9, key_sched(key_sched(parBlock)), @@ -445,11 +445,11 @@ namespace dhandy::bt { ); } - consteval HashType tiger_block (const char* parStr, HashType parHash) { + consteval TigerHash tiger_block (const char* parStr, TigerHash parHash) { return tiger_block(TigerBlock(parStr), parHash); } - consteval HashType tiger_chunk (const char* parStr, uint64_t parLen, HashType parHash) { + consteval TigerHash tiger_chunk (const char* parStr, uint64_t parLen, TigerHash parHash) { return (parLen == 0 ? //if parLen == 0 parHash @@ -459,7 +459,7 @@ namespace dhandy::bt { ); } - consteval HashType tiger_last_chunk (const char* parStr, uint64_t parLen, uint64_t parRealLen, HashType parHash, char parPad) { + consteval TigerHash tiger_last_chunk (const char* parStr, uint64_t parLen, uint64_t parRealLen, TigerHash parHash, char parPad) { return ( parLen + 1 + ((8 - parLen - 1) bitand 7) == 64 ? tiger_block( @@ -472,7 +472,7 @@ namespace dhandy::bt { } } //namespace implem - consteval HashType tiger (const char* parStr, uint64_t parLen, char parPad) { + consteval TigerHash tiger (const char* parStr, uint64_t parLen, char parPad) { return implem::tiger_last_chunk( parStr + (parLen bitand ~static_cast(0x3f)), parLen - (parLen bitand ~static_cast(0x3f)), @@ -480,7 +480,7 @@ namespace dhandy::bt { implem::tiger_chunk( parStr, parLen bitand ~static_cast(0x3f), - HashType(0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL, 0xF096A5B4C3B2E187ULL) + TigerHash{0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL, 0xF096A5B4C3B2E187ULL} ), parPad ); diff --git a/test/unit/tiger_test.cpp b/test/unit/tiger_test.cpp index dd695e7..bdcda38 100644 --- a/test/unit/tiger_test.cpp +++ b/test/unit/tiger_test.cpp @@ -20,36 +20,36 @@ TEST_CASE("Build-time Tiger hash tests", "[hash][bt][tiger]") { using dhandy::bt::tiger; - using dhandy::bt::HashType; + using dhandy::bt::TigerHash; using dhandy::bt::TigerPaddingV1; using dhandy::bt::TigerPaddingV2; - constexpr HashType h1 = tiger("", 0, TigerPaddingV2); + constexpr TigerHash h1 = tiger("", 0, TigerPaddingV2); CHECK(h1.a == 0x738701f675be4144); CHECK(h1.b == 0x924b374527c206c2); CHECK(h1.c == 0x419f91ef3f31a84a); - constexpr HashType h2 = tiger("", 0, TigerPaddingV1); + constexpr TigerHash h2 = tiger("", 0, TigerPaddingV1); CHECK(h2.a == 0x24f0130c63ac9332); CHECK(h2.b == 0x16166e76b1bb925f); CHECK(h2.c == 0xf373de2d49584e7a); - constexpr HashType h3 = tiger("message digest", 14, TigerPaddingV2); + constexpr TigerHash h3 = tiger("message digest", 14, TigerPaddingV2); CHECK(h3.a == 0x9d25fab5a11994e2); CHECK(h3.b == 0xea7850e77d5e00e8); CHECK(h3.c == 0x2d465225ef42a581); - constexpr HashType h4 = tiger("message digest", 14, TigerPaddingV1); + constexpr TigerHash h4 = tiger("message digest", 14, TigerPaddingV1); CHECK(h4.a == 0x951a2078cbf881d9); CHECK(h4.b == 0x1c441e754830cf0d); CHECK(h4.c == 0xf6295aa51aca7f51); - constexpr HashType h5 = tiger("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, TigerPaddingV2); + constexpr TigerHash h5 = tiger("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, TigerPaddingV2); CHECK(h5.a == 0x517bee8c22b69aea); CHECK(h5.b == 0x8c6c06a6fc4475b7); CHECK(h5.c == 0xcd059531e6ba5bbb); - constexpr HashType h6 = tiger("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, TigerPaddingV1); + constexpr TigerHash h6 = tiger("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, TigerPaddingV1); CHECK(h6.a == 0xee8375a180a6ce8d); CHECK(h6.b == 0x5186363c8aa32b50); CHECK(h6.c == 0xcca849dcccfb0f89);