mac/include/nil/crypto3/mac/detail/basic_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_MAC_BASIC_FUNCTIONS_HPP
26 #define CRYPTO3_MAC_BASIC_FUNCTIONS_HPP
27 
28 #include <boost/integer.hpp>
29 #include <boost/static_assert.hpp>
30 
31 namespace nil {
32  namespace crypto3 {
33  namespace mac {
34  namespace detail {
35  template<std::size_t WordBits>
36  struct basic_functions {
37  typedef typename boost::uint_t<CHAR_BIT>::exact byte_type;
38 
39  constexpr static const std::size_t word_bits = WordBits;
40  typedef typename boost::uint_t<word_bits>::exact word_type;
41 
42  static inline word_type shr(word_type x, std::size_t n) {
43  return x >> n;
44  }
45 
46  template<std::size_t n>
47  static inline word_type shr(word_type x) {
48  BOOST_STATIC_ASSERT(n < word_bits);
49  return x >> n;
50  }
51 
52  static inline word_type shl(word_type x, std::size_t n) {
53  return x << n;
54  }
55 
56  template<std::size_t n>
57  static inline word_type shl(word_type x) {
58  BOOST_STATIC_ASSERT(n < word_bits);
59  return x << n;
60  }
61 
62  static inline word_type rotr(word_type x, std::size_t n) {
63  return shr(x, n) | shl(x, word_bits - n);
64  }
65 
66  template<std::size_t n>
67  static inline word_type rotr(word_type x) {
68  return shr<n>(x) | shl<word_bits - n>(x);
69  }
70 
71  static inline word_type rotl(word_type x, std::size_t n) {
72  return shl(x, n) | shr(x, word_bits - n);
73  }
74 
75  template<std::size_t n>
76  static inline word_type rotl(word_type x) {
77  return shl<n>(x) | shr<word_bits - n>(x);
78  }
79  };
80  } // namespace detail
81  } // namespace mac
82  } // namespace crypto3
83 } // namespace nil
84 
85 #endif // CRYPTO3_BASIC_FUNCTIONS_HPP
boost::mpl::apply< AccumulatorSet, tag::mac< ProcessingPolicy > >::type::result_type mac(const AccumulatorSet &acc)
Definition: accumulators/mac.hpp:99
Definition: pair.hpp:31
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:36
static word_type shr(word_type x)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:47
static word_type rotr(word_type x, std::size_t n)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:62
static word_type rotl(word_type x, std::size_t n)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:71
static word_type shl(word_type x)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:57
boost::uint_t< CHAR_BIT >::exact byte_type
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:37
static word_type rotr(word_type x)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:67
constexpr static const std::size_t word_bits
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:39
static word_type shr(word_type x, std::size_t n)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:42
boost::uint_t< word_bits >::exact word_type
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:40
static word_type rotl(word_type x)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:76
static word_type shl(word_type x, std::size_t n)
Definition: mac/include/nil/crypto3/mac/detail/basic_functions.hpp:52