Botan  2.1.0
Crypto and TLS for C++11
hkdf.h
Go to the documentation of this file.
1 /*
2 * HKDF
3 * (C) 2013,2015 Jack Lloyd
4 * (C) 2016 RenĂ© Korthaus, Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #ifndef BOTAN_HKDF_H__
10 #define BOTAN_HKDF_H__
11 
12 #include <botan/mac.h>
13 #include <botan/hash.h>
14 #include <botan/kdf.h>
15 
16 namespace Botan {
17 
18 /**
19 * HKDF from RFC 5869.
20 */
21 class BOTAN_DLL HKDF final : public KDF
22  {
23  public:
24  /**
25  * @param prf MAC algorithm to use
26  */
27  explicit HKDF(MessageAuthenticationCode* prf) : m_prf(prf) {}
28 
29  KDF* clone() const override { return new HKDF(m_prf->clone()); }
30 
31  std::string name() const override { return "HKDF(" + m_prf->name() + ")"; }
32 
33  size_t kdf(uint8_t key[], size_t key_len,
34  const uint8_t secret[], size_t secret_len,
35  const uint8_t salt[], size_t salt_len,
36  const uint8_t label[], size_t label_len) const override;
37 
38  private:
39  std::unique_ptr<MessageAuthenticationCode> m_prf;
40  };
41 
42 /**
43 * HKDF Extraction Step from RFC 5869.
44 */
45 class BOTAN_DLL HKDF_Extract final : public KDF
46  {
47  public:
48  /**
49  * @param prf MAC algorithm to use
50  */
51  explicit HKDF_Extract(MessageAuthenticationCode* prf) : m_prf(prf) {}
52 
53  KDF* clone() const override { return new HKDF_Extract(m_prf->clone()); }
54 
55  std::string name() const override { return "HKDF-Extract(" + m_prf->name() + ")"; }
56 
57  size_t kdf(uint8_t key[], size_t key_len,
58  const uint8_t secret[], size_t secret_len,
59  const uint8_t salt[], size_t salt_len,
60  const uint8_t label[], size_t label_len) const override;
61 
62  private:
63  std::unique_ptr<MessageAuthenticationCode> m_prf;
64  };
65 
66 /**
67 * HKDF Expansion Step from RFC 5869.
68 */
69 class BOTAN_DLL HKDF_Expand final : public KDF
70  {
71  public:
72  /**
73  * @param prf MAC algorithm to use
74  */
75  explicit HKDF_Expand(MessageAuthenticationCode* prf) : m_prf(prf) {}
76 
77  KDF* clone() const override { return new HKDF_Expand(m_prf->clone()); }
78 
79  std::string name() const override { return "HKDF-Expand(" + m_prf->name() + ")"; }
80 
81  size_t kdf(uint8_t key[], size_t key_len,
82  const uint8_t secret[], size_t secret_len,
83  const uint8_t salt[], size_t salt_len,
84  const uint8_t label[], size_t label_len) const override;
85 
86  private:
87  std::unique_ptr<MessageAuthenticationCode> m_prf;
88  };
89 
90 }
91 
92 #endif
KDF * clone() const override
Definition: hkdf.h:53
std::string name() const override
Definition: hkdf.h:31
std::string name() const override
Definition: hkdf.h:79
KDF * clone() const override
Definition: hkdf.h:29
std::string name() const override
Definition: hkdf.h:55
KDF * clone() const override
Definition: hkdf.h:77
Definition: alg_id.cpp:13
Definition: kdf.h:20
HKDF(MessageAuthenticationCode *prf)
Definition: hkdf.h:27
HKDF_Extract(MessageAuthenticationCode *prf)
Definition: hkdf.h:51
HKDF_Expand(MessageAuthenticationCode *prf)
Definition: hkdf.h:75