25 #ifndef CRYPTO3_KECCAK_FINALIZER_HPP
26 #define CRYPTO3_KECCAK_FINALIZER_HPP
30 #include <boost/endian/conversion.hpp>
36 template<
typename PolicyType>
38 typedef PolicyType policy_type;
40 constexpr
static const std::size_t word_bits = policy_type::word_bits;
41 typedef typename policy_type::word_type word_type;
43 constexpr
static const std::size_t state_bits = policy_type::state_bits;
44 constexpr
static const std::size_t state_words = policy_type::state_words;
45 typedef typename policy_type::state_type state_type;
47 constexpr
static const std::size_t block_bits = policy_type::block_bits;
48 constexpr
static const std::size_t block_words = policy_type::block_words;
49 typedef typename policy_type::block_type block_type;
51 constexpr
static const std::size_t digest_bits = policy_type::digest_bits;
52 constexpr
static const std::size_t digest_blocks = digest_bits / block_bits;
53 constexpr
static const std::size_t last_digest_bits = digest_bits % block_bits;
54 constexpr
static const std::size_t last_digest_words =
55 last_digest_bits / word_bits + ((last_digest_bits % word_bits) ? 1 : 0);
57 typedef typename policy_type::digest_type digest_type;
62 state_type temp_state;
63 std::fill(temp_state.begin(), temp_state.end(), 0);
65 for (std::size_t i = 0; i != digest_blocks; ++i) {
66 for (std::size_t j = 0; j != block_words; ++j)
67 temp_state[i * block_words + j] = state[j];
69 for (std::size_t i = 0; i != state_words; ++i)
70 boost::endian::endian_reverse_inplace(state[i]);
74 for (std::size_t i = 0; i != state_words; ++i)
75 boost::endian::endian_reverse_inplace(state[i]);
78 if (last_digest_bits) {
79 for (std::size_t j = 0; j != last_digest_words; ++j)
80 temp_state[digest_blocks * block_words + j] = state[j];
Definition: keccak_finalizer.hpp:37
void operator()(state_type &state)
Definition: keccak_finalizer.hpp:61
constexpr matrix< T, N, M > fill(T value)
generates a matrix containing a single value
Definition: matrix/utility.hpp:102
Definition: keccak_functions.hpp:36
static void permute(state_type &A)
Definition: keccak_functions.hpp:57