shacal_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_BLOCK_CIPHERS_DETAIL_SHACAL_FUNCTIONS_HPP
26 #define CRYPTO3_BLOCK_CIPHERS_DETAIL_SHACAL_FUNCTIONS_HPP
27 
28 #include <nil/crypto3/detail/basic_functions.hpp>
29 
30 namespace nil {
31  namespace crypto3 {
32  namespace block {
33  namespace detail {
34 
43  template<std::size_t WordBits>
45  typedef typename ::nil::crypto3::detail::basic_functions<WordBits>::word_type word_type;
46 
48  return (x & y) ^ (~x & z);
49  }
50 
52  return (x & y) ^ (x & z) ^ (y & z);
53  }
54  };
55 
58  return x ^ y ^ z;
59  }
60 
61  static word_type f(unsigned t, word_type x, word_type y, word_type z) {
62  if (t < 40) {
63  if (t < 20) {
64  return Ch(x, y, z);
65  }
66  } else {
67  if (t < 60) {
68  return Maj(x, y, z);
69  }
70  }
71  return Parity(x, y, z);
72  }
73  };
74 
77 
78  template<std::size_t WordBits>
80 
81  template<>
82  struct shacal2_functions<32> : public basic_shacal_functions<32> {
84  return rotr<2>(x) ^ rotr<13>(x) ^ rotr<22>(x);
85  }
86 
88  return rotr<6>(x) ^ rotr<11>(x) ^ rotr<25>(x);
89  }
90 
92  return rotr<7>(x) ^ rotr<18>(x) ^ shr<3>(x);
93  }
94 
96  return rotr<17>(x) ^ rotr<19>(x) ^ shr<10>(x);
97  }
98  };
99 
100  template<>
101  struct shacal2_functions<64> : public basic_shacal_functions<64> {
103  return rotr<28>(x) ^ rotr<34>(x) ^ rotr<39>(x);
104  }
105 
107  return rotr<14>(x) ^ rotr<18>(x) ^ rotr<41>(x);
108  }
109 
111  return rotr<1>(x) ^ rotr<8>(x) ^ shr<7>(x);
112  }
113 
115  return rotr<19>(x) ^ rotr<61>(x) ^ shr<6>(x);
116  }
117  };
118 
119  } // namespace detail
120  } // namespace block
121  } // namespace crypto3
122 } // namespace nil
123 
124 #endif // CRYPTO3_BLOCK_CIPHERS_DETAIL_SHACAL_FUNCTIONS_HPP
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
shacal_functions shacal0_functions
Definition: shacal_functions.hpp:75
shacal_functions shacal1_functions
Definition: shacal_functions.hpp:76
Definition: pair.hpp:31
Definition: shacal_functions.hpp:44
::nil::crypto3::detail::basic_functions< WordBits >::word_type word_type
Definition: shacal_functions.hpp:45
static word_type Ch(word_type x, word_type y, word_type z)
Definition: shacal_functions.hpp:47
static word_type Maj(word_type x, word_type y, word_type z)
Definition: shacal_functions.hpp:51
static word_type Sigma_1(word_type x)
Definition: shacal_functions.hpp:87
static word_type sigma_1(word_type x)
Definition: shacal_functions.hpp:95
static word_type Sigma_0(word_type x)
Definition: shacal_functions.hpp:83
static word_type sigma_0(word_type x)
Definition: shacal_functions.hpp:91
static word_type Sigma_1(word_type x)
Definition: shacal_functions.hpp:106
static word_type sigma_0(word_type x)
Definition: shacal_functions.hpp:110
static word_type Sigma_0(word_type x)
Definition: shacal_functions.hpp:102
static word_type sigma_1(word_type x)
Definition: shacal_functions.hpp:114
Definition: shacal_functions.hpp:79
Definition: shacal_functions.hpp:56
static word_type Parity(word_type x, word_type y, word_type z)
Definition: shacal_functions.hpp:57
static word_type f(unsigned t, word_type x, word_type y, word_type z)
Definition: shacal_functions.hpp:61
Definition: block/include/nil/crypto3/detail/basic_functions.hpp:37
boost::uint_t< word_bits >::exact word_type
Definition: block/include/nil/crypto3/detail/basic_functions.hpp:42