kasumi_functions.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_KASUMI_FUNCTIONS_CPP_HPP
26 #define CRYPTO3_KASUMI_FUNCTIONS_CPP_HPP
27 
29 
30 namespace nil {
31  namespace crypto3 {
32  namespace block {
33  namespace detail {
34  struct kasumi_functions : public kasumi_policy {
35  constexpr static const std::size_t word_bits = kasumi_policy::word_bits;
37 
38  static inline word_type FI(word_type I, word_type K) {
39  word_type D9 = (I >> 7);
40  word_type D7 = (I & 0x7F);
41  D9 = s9_substitution[D9] ^ D7;
42  D7 = s7_substitution[D7] ^ (D9 & 0x7F);
43 
44  D7 ^= (K >> 9);
45  D9 = s9_substitution[D9 ^ (K & 0x1FF)] ^ D7;
46  D7 = s7_substitution[D7] ^ (D9 & 0x7F);
47  return static_cast<word_type>(D7 << 9) | D9;
48  }
49  };
50  } // namespace detail
51  } // namespace block
52  } // namespace crypto3
53 } // namespace nil
54 
55 #endif // CRYPTO3_KASUMI_FUNCTIONS_CPP_HPP
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
Definition: pair.hpp:31
Definition: kasumi_functions.hpp:34
kasumi_policy::word_type word_type
Definition: kasumi_functions.hpp:36
static word_type FI(word_type I, word_type K)
Definition: kasumi_functions.hpp:38
constexpr static const std::size_t word_bits
Definition: kasumi_functions.hpp:35
Definition: kasumi_policy.hpp:36
constexpr static const std::size_t word_bits
Definition: kasumi_policy.hpp:37
constexpr static const s9_substitution_type s9_substitution
Definition: kasumi_policy.hpp:74
::nil::crypto3::detail::basic_functions< 16 >::word_type word_type
Definition: kasumi_policy.hpp:39
constexpr static const s7_substitution_type s7_substitution
Definition: kasumi_policy.hpp:62