kdf1.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2019 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_KDF_KDF1_HPP
26 #define CRYPTO3_KDF_KDF1_HPP
27 
29 #include <vector>
30 
31 namespace nil {
32  namespace crypto3 {
33  namespace kdf {
39  template<typename Hash>
40  class kdf1 {
42 
43  public:
45 
46  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
48 
49  constexpr static const std::size_t secret_bits = policy_type::secret_bits;
51 
52  constexpr static const std::size_t label_bits = policy_type::label_bits;
54 
55  constexpr static const std::size_t salt_bits = policy_type::salt_bits;
57 
58  static inline digest_type process() {
60  process(digest);
61  return digest;
62  }
63 
64  static void process(digest_type &digest) {
65  m_hash->update(secret, secret_len);
66  m_hash->update(label, label_len);
67  m_hash->update(salt, salt_len);
68 
69  if (key_len < m_hash->output_length()) {
70  std::vector<uint8_t> v = m_hash->final();
71  copy_mem(key, v.data(), key_len);
72  return key_len;
73  }
74 
75  m_hash->final(key);
76  return m_hash->output_length();
77  }
78 
79  protected:
81  };
82  } // namespace kdf
83  } // namespace crypto3
84 } // namespace nil
85 #endif
KDF1, from IEEE 1363.
Definition: kdf1.hpp:40
hash_type hash
Definition: kdf1.hpp:80
policy_type::salt_type salt_type
Definition: kdf1.hpp:56
policy_type::hash_type hash_type
Definition: kdf1.hpp:44
policy_type::digest_type digest_type
Definition: kdf1.hpp:47
constexpr static const std::size_t salt_bits
Definition: kdf1.hpp:55
policy_type::label_type label_type
Definition: kdf1.hpp:53
static void process(digest_type &digest)
Definition: kdf1.hpp:64
static digest_type process()
Definition: kdf1.hpp:58
constexpr static const std::size_t digest_bits
Definition: kdf1.hpp:46
constexpr static const std::size_t label_bits
Definition: kdf1.hpp:52
constexpr static const std::size_t secret_bits
Definition: kdf1.hpp:49
policy_type::secret_type secret_type
Definition: kdf1.hpp:50
boost::mpl::apply< AccumulatorSet, tag::kdf< Mode > >::type::result_type kdf(const AccumulatorSet &acc)
Definition: kdf.hpp:177
boost::container::small_vector< octet_type, DigestBits/octet_bits > digest
Definition: codec/include/nil/crypto3/detail/digest.hpp:71
void copy_mem(T *out, const T *in, size_t n)
Definition: memory_operations.hpp:186
Definition: pair.hpp:31
Definition: block/include/nil/crypto3/detail/digest.hpp:72
Definition: kdf1_functions.hpp:35
constexpr static const std::size_t salt_bits
Definition: kdf1_functions.hpp:46
policy_type::label_type label_type
Definition: kdf1_functions.hpp:44
policy_type::hash_type hash_type
Definition: kdf1_functions.hpp:38
constexpr static const std::size_t secret_bits
Definition: kdf1_functions.hpp:40
policy_type::digest_type digest_type
Definition: kdf1_functions.hpp:50
policy_type::salt_type salt_type
Definition: kdf1_functions.hpp:47
policy_type::secret_type secret_type
Definition: kdf1_functions.hpp:41
constexpr static const std::size_t label_bits
Definition: kdf1_functions.hpp:43
constexpr static const std::size_t digest_bits
Definition: kdf1_functions.hpp:49