matyas_meyer_oseas_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_MATYAS_MEYER_OSEAS_COMPRESSOR_HPP
26 #define CRYPTO3_MATYAS_MEYER_OSEAS_COMPRESSOR_HPP
27 
28 namespace nil {
29  namespace crypto3 {
30  namespace hash {
41  template<typename BlockCipher, typename CombineFunction, typename KeyConverterFunctor>
44 
45  constexpr static const std::size_t word_bits = block_cipher_type::word_bits;
46  typedef typename block_cipher_type::word_type word_type;
47 
48  constexpr static const std::size_t key_bits = block_cipher_type::key_bits;
49  typedef typename block_cipher_type::key_type key_type;
50 
51  constexpr static const std::size_t state_bits = block_cipher_type::block_bits;
52  constexpr static const std::size_t state_words = block_cipher_type::block_words;
53  typedef typename block_cipher_type::block_type state_type;
54 
55  constexpr static const std::size_t block_bits = block_cipher_type::key_bits;
56  constexpr static const std::size_t block_words = block_cipher_type::key_words;
57  typedef typename block_cipher_type::block_type block_type;
58 
59  static inline void process_block(state_type &state, const block_type &block) {
60  KeyConverterFunctor k;
61  key_type key = {0};
62  k(key, state);
63 
64  block_cipher_type cipher(key);
65  state_type new_state = cipher.encrypt(block);
66 
67  CombineFunction f;
68  f(new_state, block);
69  state = new_state;
70  }
71  };
72  } // namespace hash
73  } // namespace crypto3
74 } // namespace nil
75 
76 #endif // CRYPTO3_MATYAS_MEYER_OSEAS_COMPRESSOR_HPP
std::enable_if<!boost::accumulators::detail::is_accumulator_set< OutputIterator >::value, OutputIterator >::type hash(InputIterator first, InputIterator last, OutputIterator out)
Definition: algorithm/hash.hpp:78
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: matyas_meyer_oseas_compressor.hpp:42
constexpr static const std::size_t state_words
Definition: matyas_meyer_oseas_compressor.hpp:52
block_cipher_type::key_type key_type
Definition: matyas_meyer_oseas_compressor.hpp:49
static void process_block(state_type &state, const block_type &block)
Definition: matyas_meyer_oseas_compressor.hpp:59
constexpr static const std::size_t block_bits
Definition: matyas_meyer_oseas_compressor.hpp:55
block_cipher_type::word_type word_type
Definition: matyas_meyer_oseas_compressor.hpp:46
constexpr static const std::size_t state_bits
Definition: matyas_meyer_oseas_compressor.hpp:51
BlockCipher block_cipher_type
Definition: matyas_meyer_oseas_compressor.hpp:43
constexpr static const std::size_t key_bits
Definition: matyas_meyer_oseas_compressor.hpp:48
block_cipher_type::block_type state_type
Definition: matyas_meyer_oseas_compressor.hpp:53
constexpr static const std::size_t word_bits
Definition: matyas_meyer_oseas_compressor.hpp:45
constexpr static const std::size_t block_words
Definition: matyas_meyer_oseas_compressor.hpp:56
block_cipher_type::block_type block_type
Definition: matyas_meyer_oseas_compressor.hpp:57