ripemd_functions.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_RIPEMD_FUNCTIONS_HPP
27 #define CRYPTO3_RIPEMD_FUNCTIONS_HPP
28 
30 
31 namespace nil {
32  namespace crypto3 {
33  namespace hashes {
34  namespace detail {
35  template<std::size_t DigestBits>
36  struct ripemd_functions : public ripemd_policy<DigestBits> {
38 
40 
41  struct f1 {
43  return x ^ y ^ z;
44  }
45  };
46 
47  struct f2 {
49  return (x & y) | (~x & z);
50  }
51  };
52 
53  struct f3 {
55  return (x | ~y) ^ z;
56  }
57  };
58 
59  struct f4 {
61  return (x & z) | (y & ~z);
62  }
63  };
64 
65  struct f5 {
67  return x ^ (y | ~z);
68  }
69  };
70 
71  template<typename F>
72  inline static void transform(word_type &a, word_type &b, word_type &c, word_type &d, word_type x,
73  word_type k, word_type s) {
74  word_type T = policy_type::rotl(a + F()(b, c, d) + x + k, s);
75  a = d;
76  d = c;
77  c = b;
78  b = T;
79  }
80 
81  template<typename Functor>
82  inline static void transform(word_type &a, word_type &b, word_type &c, word_type &d, word_type &e,
83  word_type x, word_type k, word_type s) {
84  word_type T = policy_type::rotl(a + Functor()(b, c, d) + x + k, s) + e;
85  a = e;
86  e = d;
87  d = policy_type::template rotl<10>(c);
88  c = b;
89  b = T;
90  }
91  };
92  } // namespace detail
93  } // namespace hashes
94  } // namespace crypto3
95 } // namespace nil
96 
97 #endif // CRYPTO3_RIPEMD_FUNCTIONS_HPP
Definition: pair.hpp:31
boost::uint_t< word_bits >::exact word_type
Definition: block/include/nil/crypto3/detail/basic_functions.hpp:89
static word_type rotl(word_type x, std::size_t n)
Definition: block/include/nil/crypto3/detail/basic_functions.hpp:125
Definition: ripemd_functions.hpp:41
word_type operator()(word_type x, word_type y, word_type z) const
Definition: ripemd_functions.hpp:42
Definition: ripemd_functions.hpp:47
word_type operator()(word_type x, word_type y, word_type z) const
Definition: ripemd_functions.hpp:48
Definition: ripemd_functions.hpp:53
word_type operator()(word_type x, word_type y, word_type z) const
Definition: ripemd_functions.hpp:54
Definition: ripemd_functions.hpp:59
word_type operator()(word_type x, word_type y, word_type z) const
Definition: ripemd_functions.hpp:60
Definition: ripemd_functions.hpp:65
word_type operator()(word_type x, word_type y, word_type z) const
Definition: ripemd_functions.hpp:66
Definition: ripemd_functions.hpp:36
static void transform(word_type &a, word_type &b, word_type &c, word_type &d, word_type &e, word_type x, word_type k, word_type s)
Definition: ripemd_functions.hpp:82
static void transform(word_type &a, word_type &b, word_type &c, word_type &d, word_type x, word_type k, word_type s)
Definition: ripemd_functions.hpp:72
ripemd_policy< DigestBits > policy_type
Definition: ripemd_functions.hpp:37
policy_type::word_type word_type
Definition: ripemd_functions.hpp:39
Definition: ripemd_policy.hpp:112