keccak.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020 Alexander Sokolov <asokolov@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_HASH_KECCAK_HPP
27 #define CRYPTO3_HASH_KECCAK_HPP
28 
31 
36 
37 #include <boost/endian/conversion.hpp>
38 
39 namespace nil {
40  namespace crypto3 {
41  namespace hashes {
42  template<std::size_t DigestBits = 512>
44  protected:
46 
47  public:
48  constexpr static const std::size_t word_bits = policy_type::word_bits;
50 
51  constexpr static const std::size_t state_bits = policy_type::state_bits;
52  constexpr static const std::size_t state_words = policy_type::state_words;
54 
55  constexpr static const std::size_t block_bits = policy_type::block_bits;
56  constexpr static const std::size_t block_words = policy_type::block_words;
58 
59  static void process_block(state_type &state, const block_type &block) {
60  for (std::size_t i = 0; i != block_words; ++i)
61  state[i] ^= block[i];
62 
63  for (std::size_t i = 0; i != state_words; ++i)
64  boost::endian::endian_reverse_inplace(state[i]);
65 
66  policy_type::permute(state);
67 
68  for (std::size_t i = 0; i != state_words; ++i)
69  boost::endian::endian_reverse_inplace(state[i]);
70  }
71  };
72 
78  template<std::size_t DigestBits = 512>
79  class keccak_1600 {
81 
82  public:
83  constexpr static const std::size_t word_bits = policy_type::word_bits;
85 
86  constexpr static const std::size_t block_bits = policy_type::block_bits;
87  constexpr static const std::size_t block_words = policy_type::block_words;
89 
90  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
92 
93  struct construction {
94  struct params_type {
96 
97  constexpr static const std::size_t length_bits = policy_type::length_bits;
98  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
99  };
100 
101  typedef sponge_construction<
105  };
106 
107  template<typename StateAccumulator, std::size_t ValueBits>
109  struct params_type {
111 
112  constexpr static const std::size_t value_bits = ValueBits;
113  };
114 
116  };
117  };
118  } // namespace hashes
119  } // namespace crypto3
120 } // namespace nil
121 
122 #endif
This will do the usual Merkle-Damgård-style strengthening, padding with a 1 bit, then 0 bits as neede...
Definition: hash/include/nil/crypto3/hash/detail/block_stream_processor.hpp:55
Definition: keccak_finalizer.hpp:37
Definition: keccak_padding.hpp:37
detail::keccak_1600_functions< DigestBits > policy_type
Definition: keccak.hpp:45
policy_type::word_type word_type
Definition: keccak.hpp:49
constexpr static const std::size_t word_bits
Definition: keccak.hpp:48
policy_type::state_type state_type
Definition: keccak.hpp:53
policy_type::block_type block_type
Definition: keccak.hpp:57
static void process_block(state_type &state, const block_type &block)
Definition: keccak.hpp:59
constexpr static const std::size_t state_words
Definition: keccak.hpp:52
constexpr static const std::size_t state_bits
Definition: keccak.hpp:51
constexpr static const std::size_t block_bits
Definition: keccak.hpp:55
constexpr static const std::size_t block_words
Definition: keccak.hpp:56
Definition: keccak.hpp:79
constexpr static const std::size_t digest_bits
Definition: keccak.hpp:90
policy_type::block_type block_type
Definition: keccak.hpp:88
policy_type::digest_type digest_type
Definition: keccak.hpp:91
constexpr static const std::size_t block_words
Definition: keccak.hpp:87
constexpr static const std::size_t word_bits
Definition: keccak.hpp:83
policy_type::word_type word_type
Definition: keccak.hpp:84
constexpr static const std::size_t block_bits
Definition: keccak.hpp:86
Definition: sponge_construction.hpp:56
Definition: block/include/nil/crypto3/detail/static_digest.hpp:72
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
Definition: pair.hpp:31
constexpr static const std::size_t word_bits
Definition: block/include/nil/crypto3/detail/basic_functions.hpp:41
boost::uint_t< word_bits >::exact word_type
Definition: block/include/nil/crypto3/detail/basic_functions.hpp:42
Definition: keccak_functions.hpp:36
static void permute(state_type &A)
Definition: keccak_functions.hpp:57
policy_type::word_type word_type
Definition: keccak_functions.hpp:40
constexpr static const std::size_t word_bits
Definition: keccak_functions.hpp:39
policy_type::state_type state_type
Definition: keccak_functions.hpp:42
Definition: keccak_policy.hpp:36
constexpr static const std::size_t block_words
Definition: keccak_policy.hpp:46
constexpr static const std::size_t digest_bits
Definition: keccak_policy.hpp:38
constexpr static const std::size_t length_bits
Definition: keccak_policy.hpp:49
std::array< word_type, block_words > block_type
Definition: keccak_policy.hpp:47
constexpr static const std::size_t state_words
Definition: keccak_policy.hpp:42
constexpr static const std::size_t state_bits
Definition: keccak_policy.hpp:41
constexpr static const std::size_t block_bits
Definition: keccak_policy.hpp:45
constexpr static const std::size_t digest_bits
Definition: keccak.hpp:98
policy_type::digest_endian digest_endian
Definition: keccak.hpp:95
constexpr static const std::size_t length_bits
Definition: keccak.hpp:97
sponge_construction< params_type, typename policy_type::iv_generator, keccak_1600_compressor< DigestBits >, detail::keccak_1600_padding< policy_type >, detail::keccak_1600_finalizer< policy_type > > type
Definition: keccak.hpp:104
constexpr static const std::size_t value_bits
Definition: keccak.hpp:112
policy_type::digest_endian digest_endian
Definition: keccak.hpp:110
block_stream_processor< construction, StateAccumulator, params_type > type
Definition: keccak.hpp:115
Definition: algebra/include/nil/crypto3/detail/stream_endian.hpp:39