davies_meyer_compressor.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_HASH_DAVIES_MEYER_COMPRESSOR_HPP
26 #define CRYPTO3_HASH_DAVIES_MEYER_COMPRESSOR_HPP
27 
28 #include <cstddef>
29 
30 namespace nil {
31  namespace crypto3 {
32  namespace hashes {
43  template<typename BlockCipher, typename CombineFunction>
46 
47  constexpr static const std::size_t word_bits = block_cipher_type::word_bits;
48  typedef typename block_cipher_type::word_type word_type;
49 
50  constexpr static const std::size_t state_bits = block_cipher_type::block_bits;
51  constexpr static const std::size_t state_words = block_cipher_type::block_words;
52  typedef typename block_cipher_type::block_type state_type;
53 
54  constexpr static const std::size_t block_bits = block_cipher_type::key_bits;
55  constexpr static const std::size_t block_words = block_cipher_type::key_words;
56  typedef typename block_cipher_type::key_type block_type;
57 
58  inline static void process_block(state_type &state, const block_type &block) {
59  block_cipher_type cipher(block);
60  state_type new_state = cipher.encrypt((const state_type &)state);
61  CombineFunction f;
62  f(state, new_state);
63  }
64  };
65  } // namespace hashes
66  } // namespace crypto3
67 } // namespace nil
68 
69 #endif // CRYPTO3_HASH_DAVIES_MEYER_COMPRESSOR_HPP
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
boost::accumulators::accumulator_set< mac::digest< MessageAuthenticationCode::input_block_bits >, boost::accumulators::features< accumulators::tag::mac< MessageAuthenticationCode > >> BlockCipher
Definition: cbc_mac_state.hpp:40
Definition: pair.hpp:31
Definition: davies_meyer_compressor.hpp:44
block_cipher_type::block_type state_type
Definition: davies_meyer_compressor.hpp:52
block_cipher_type::word_type word_type
Definition: davies_meyer_compressor.hpp:48
constexpr static const std::size_t state_bits
Definition: davies_meyer_compressor.hpp:50
constexpr static const std::size_t block_words
Definition: davies_meyer_compressor.hpp:55
constexpr static const std::size_t state_words
Definition: davies_meyer_compressor.hpp:51
constexpr static const std::size_t block_bits
Definition: davies_meyer_compressor.hpp:54
BlockCipher block_cipher_type
Definition: davies_meyer_compressor.hpp:45
block_cipher_type::key_type block_type
Definition: davies_meyer_compressor.hpp:56
static void process_block(state_type &state, const block_type &block)
Definition: davies_meyer_compressor.hpp:58
constexpr static const std::size_t word_bits
Definition: davies_meyer_compressor.hpp:47