passhash9_policy.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_PASSHASH_PASSHASH9_POLICY_HPP
26 #define CRYPTO3_PASSHASH_PASSHASH9_POLICY_HPP
27 
28 #include <cstdlib>
29 
31 
32 namespace nil {
33  namespace crypto3 {
34  namespace block {
35  struct blowfish;
36  }
37 
38  namespace hashes {
39  struct sha1;
40 
41  template<std::size_t Version>
42  struct sha2;
43  } // namespace hashes
44 
45  namespace mac {
46  template<typename Hash>
47  struct hmac;
48 
49  template<typename BlockCipher>
50  struct cmac;
51  } // namespace mac
52 
53  namespace passhash {
54  namespace detail {
55  template<typename MessageAuthenticationCode, std::size_t Workfactor, typename ParamsType>
56  struct passhash9_policy : passhash9_functions<MessageAuthenticationCode, Workfactor, ParamsType> {
57  typedef MessageAuthenticationCode mac_type;
58  typedef ParamsType params_type;
59 
60  typedef const char* prefix_type;
61  constexpr static prefix_type prefix = params_type::prefix;
62 
63  constexpr static const std::size_t algid_bits = params_type::algid_bits;
64 
65  constexpr static const std::size_t workfactor = Workfactor;
66  constexpr static const std::size_t workfactor_bits = params_type::workfactor_bits;
67  constexpr static const std::size_t workfactor_scale = params_type::workfactor_scale;
68 
69  constexpr static const std::size_t salt_bits = params_type::salt_bits;
70  constexpr static const std::size_t pbkdf_output_bits = params_type::pbkdf_output_bits;
71  };
72 
73  template<std::size_t Workfactor, typename ParamsType>
74  struct passhash9_policy<mac::hmac<hashes::sha1>, Workfactor, ParamsType>
75  : passhash9_functions<mac::hmac<hashes::sha1>, Workfactor, ParamsType> {
77  typedef ParamsType params_type;
78 
79  typedef const char* prefix_type;
80  constexpr static prefix_type prefix = params_type::prefix;
81 
82  constexpr static const std::size_t algid = 0;
83  constexpr static const std::size_t algid_bits = params_type::algid_bits;
84 
85  constexpr static const std::size_t workfactor = Workfactor;
86  constexpr static const std::size_t workfactor_bits = params_type::workfactor_bits;
87  constexpr static const std::size_t workfactor_scale = params_type::workfactor_scale;
88 
89  constexpr static const std::size_t salt_bits = params_type::salt_bits;
90  constexpr static const std::size_t pbkdf_output_bits = params_type::pbkdf_output_bits;
91  };
92 
93  template<std::size_t Workfactor, typename ParamsType>
94  struct passhash9_policy<mac::hmac<hashes::sha2<256>>, Workfactor, ParamsType>
95  : passhash9_functions<mac::hmac<hashes::sha2<256>>, Workfactor, ParamsType> {
97  typedef ParamsType params_type;
98 
99  typedef const char* prefix_type;
100  constexpr static prefix_type prefix = params_type::prefix;
101 
102  constexpr static const std::size_t algid = 1;
103  constexpr static const std::size_t algid_bits = params_type::algid_bits;
104 
105  constexpr static const std::size_t workfactor = Workfactor;
106  constexpr static const std::size_t workfactor_bits = params_type::workfactor_bits;
107  constexpr static const std::size_t workfactor_scale = params_type::workfactor_scale;
108 
109  constexpr static const std::size_t salt_bits = params_type::salt_bits;
110  constexpr static const std::size_t pbkdf_output_bits = params_type::pbkdf_output_bits;
111  };
112 
113  template<std::size_t Workfactor, typename ParamsType>
114  struct passhash9_policy<mac::cmac<block::blowfish>, Workfactor, ParamsType>
115  : passhash9_functions<mac::cmac<block::blowfish>, Workfactor, ParamsType> {
117  typedef ParamsType params_type;
118 
119  typedef const char* prefix_type;
120  constexpr static prefix_type prefix = params_type::prefix;
121 
122  constexpr static const std::size_t algid = 2;
123  constexpr static const std::size_t algid_bits = params_type::algid_bits;
124 
125  constexpr static const std::size_t workfactor = Workfactor;
126  constexpr static const std::size_t workfactor_bits = params_type::workfactor_bits;
127  constexpr static const std::size_t workfactor_scale = params_type::workfactor_scale;
128 
129  constexpr static const std::size_t salt_bits = params_type::salt_bits;
130  constexpr static const std::size_t pbkdf_output_bits = params_type::pbkdf_output_bits;
131  };
132 
133  template<std::size_t Workfactor, typename ParamsType>
134  struct passhash9_policy<mac::hmac<hashes::sha2<384>>, Workfactor, ParamsType>
135  : passhash9_functions<mac::hmac<hashes::sha2<384>>, Workfactor, ParamsType> {
137  typedef ParamsType params_type;
138 
139  typedef const char* prefix_type;
140  constexpr static prefix_type prefix = params_type::prefix;
141 
142  constexpr static const std::size_t algid = 3;
143  constexpr static const std::size_t algid_bits = params_type::algid_bits;
144 
145  constexpr static const std::size_t workfactor = Workfactor;
146  constexpr static const std::size_t workfactor_bits = params_type::workfactor_bits;
147  constexpr static const std::size_t workfactor_scale = params_type::workfactor_scale;
148 
149  constexpr static const std::size_t salt_bits = params_type::salt_bits;
150  constexpr static const std::size_t pbkdf_output_bits = params_type::pbkdf_output_bits;
151  };
152 
153  template<std::size_t Workfactor, typename ParamsType>
154  struct passhash9_policy<mac::hmac<hashes::sha2<512>>, Workfactor, ParamsType>
155  : passhash9_functions<mac::hmac<hashes::sha2<512>>, Workfactor, ParamsType> {
157  typedef ParamsType params_type;
158 
159  typedef const char* prefix_type;
160  constexpr static prefix_type prefix = params_type::prefix;
161 
162  constexpr static const std::size_t algid = 4;
163  constexpr static const std::size_t algid_bits = params_type::algid_bits;
164 
165  constexpr static const std::size_t workfactor = Workfactor;
166  constexpr static const std::size_t workfactor_bits = params_type::workfactor_bits;
167  constexpr static const std::size_t workfactor_scale = params_type::workfactor_scale;
168 
169  constexpr static const std::size_t salt_bits = params_type::salt_bits;
170  constexpr static const std::size_t pbkdf_output_bits = params_type::pbkdf_output_bits;
171  };
172  } // namespace detail
173  } // namespace passhash
174  } // namespace crypto3
175 } // namespace nil
176 
177 #endif // CRYPTO3_PASSHASH9_POLICY_HPP
CMAC, also known as OMAC1.
Definition: cmac.hpp:42
boost::mpl::apply< AccumulatorSet, tag::mac< ProcessingPolicy > >::type::result_type mac(const AccumulatorSet &acc)
Definition: accumulators/mac.hpp:99
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
boost::mpl::apply< AccumulatorSet, tag::passhash< Hash > >::type::result_type passhash(const AccumulatorSet &acc)
Definition: accumulators/passhash.hpp:121
Definition: pair.hpp:31
Definition: hmac.hpp:47
Definition: passhash9_functions.hpp:36
Definition: passhash9_policy.hpp:56
constexpr static const std::size_t pbkdf_output_bits
Definition: passhash9_policy.hpp:70
ParamsType params_type
Definition: passhash9_policy.hpp:58
const char * prefix_type
Definition: passhash9_policy.hpp:60
constexpr static const std::size_t workfactor_bits
Definition: passhash9_policy.hpp:66
constexpr static const std::size_t salt_bits
Definition: passhash9_policy.hpp:69
constexpr static const std::size_t algid_bits
Definition: passhash9_policy.hpp:63
constexpr static prefix_type prefix
Definition: passhash9_policy.hpp:61
constexpr static const std::size_t workfactor_scale
Definition: passhash9_policy.hpp:67
constexpr static const std::size_t workfactor
Definition: passhash9_policy.hpp:65
MessageAuthenticationCode mac_type
Definition: passhash9_policy.hpp:57