Skip to content

Commit

Permalink
Add test/detail_keccak.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Feb 1, 2025
1 parent 4534d6e commit 0cbc312
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ run hmac_sha2.cpp ;
run sha2_cx.cpp ;
run sha2_cx_2.cpp ;

run detail_keccak.cpp ;
run sha3.cpp ;
# run hmac_sha3.cpp ;
# run sha3_cx.cpp ;
Expand Down
48 changes: 48 additions & 0 deletions test/detail_keccak.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/hash2/detail/keccak.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdint>

// https://github.com/XKCP/XKCP/blob/master/tests/TestVectors/KeccakF-1600-IntermediateValues.txt

static const std::uint64_t ref[ 25 ] =
{
0xF1258F7940E1DDE7, 0x84D5CCF933C0478A, 0xD598261EA65AA9EE, 0xBD1547306F80494D, 0x8B284E056253D057,
0xFF97A42D7F8E6FD4, 0x90FEE5A0A44647C4, 0x8C5BDA0CD6192E76, 0xAD30A6F71B19059C, 0x30935AB7D08FFC64,
0xEB5AA93F2317D635, 0xA9A6E6260D712103, 0x81A57C16DBCF555F, 0x43B831CD0347C826, 0x01F22F1A11A5569F,
0x05E5635A21D9AE61, 0x64BEFEF28CC970F2, 0x613670957BC46611, 0xB87C5A554FD00ECB, 0x8C3EE88A1CCF32C8,
0x940C7922AE3A2614, 0x1841F924A2C509E4, 0x16F53526E70465C2, 0x75F644E97F30A13B, 0xEAF1FF7B5CECA249,
};

static const std::uint64_t ref2[ 25 ] =
{
0x2D5C954DF96ECB3C, 0x6A332CD07057B56D, 0x093D8D1270D76B6C, 0x8A20D9B25569D094, 0x4F9C4F99E5E7F156,
0xF957B9A2DA65FB38, 0x85773DAE1275AF0D, 0xFAF4F247C3D810F7, 0x1F1B9EE6F79A8759, 0xE4FECC0FEE98B425,
0x68CE61B6B9CE68A1, 0xDEEA66C4BA8F974F, 0x33C43D836EAFB1F5, 0xE00654042719DBD9, 0x7CF8A9F009831265,
0xFD5449A6BF174743, 0x97DDAD33D8994B40, 0x48EAD5FC5D0BE774, 0xE3B8C8EE55B7B03C, 0x91A0226E649E42E9,
0x900E3129E7BADD7B, 0x202A9EC5FAA3CCE8, 0x5B3402464E1C3DB6, 0x609F4E62A44C1059, 0x20D06CD26A8FBF5C,
};

int main()
{
std::uint64_t state[ 25 ] = {};

boost::hash2::detail::keccak_permute( state );

for( int i = 0; i < 25; ++i )
{
BOOST_TEST_EQ( state[ i ], ref[ i ] );
}

boost::hash2::detail::keccak_permute( state );

for( int i = 0; i < 25; ++i )
{
BOOST_TEST_EQ( state[ i ], ref2[ i ] );
}

return boost::report_errors();
}

0 comments on commit 0cbc312

Please sign in to comment.