Botan 3.6.1
Crypto and TLS for C&
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/kdf.h>
13#include <botan/mac.h>
14
15namespace Botan {
16
17/**
18* HKDF from RFC 5869.
19*/
20class HKDF final : public KDF {
21 public:
22 /**
23 * @param prf MAC algorithm to use
24 */
25 explicit HKDF(std::unique_ptr<MessageAuthenticationCode> prf) : m_prf(std::move(prf)) {}
26
27 std::unique_ptr<KDF> new_object() const override;
28
29 std::string name() const override;
30
31 void kdf(uint8_t key[],
32 size_t key_len,
33 const uint8_t secret[],
34 size_t secret_len,
35 const uint8_t salt[],
36 size_t salt_len,
37 const uint8_t label[],
38 size_t label_len) const override;
39
40 private:
41 std::unique_ptr<MessageAuthenticationCode> m_prf;
42};
43
44/**
45* HKDF Extraction Step from RFC 5869.
46*/
47class HKDF_Extract final : public KDF {
48 public:
49 /**
50 * @param prf MAC algorithm to use
51 */
52 explicit HKDF_Extract(std::unique_ptr<MessageAuthenticationCode> prf) : m_prf(std::move(prf)) {}
53
54 std::unique_ptr<KDF> new_object() const override;
55
56 std::string name() const override;
57
58 void kdf(uint8_t key[],
59 size_t key_len,
60 const uint8_t secret[],
61 size_t secret_len,
62 const uint8_t salt[],
63 size_t salt_len,
64 const uint8_t label[],
65 size_t label_len) const override;
66
67 private:
68 std::unique_ptr<MessageAuthenticationCode> m_prf;
69};
70
71/**
72* HKDF Expansion Step from RFC 5869.
73*/
74class HKDF_Expand final : public KDF {
75 public:
76 /**
77 * @param prf MAC algorithm to use
78 */
79 explicit HKDF_Expand(std::unique_ptr<MessageAuthenticationCode> prf) : m_prf(std::move(prf)) {}
80
81 std::unique_ptr<KDF> new_object() const override;
82
83 std::string name() const override;
84
85 void kdf(uint8_t key[],
86 size_t key_len,
87 const uint8_t secret[],
88 size_t secret_len,
89 const uint8_t salt[],
90 size_t salt_len,
91 const uint8_t label[],
92 size_t label_len) const override;
93
94 private:
95 std::unique_ptr<MessageAuthenticationCode> m_prf;
96};
97
98/**
99* HKDF-Expand-Label from TLS 1.3/QUIC
100* @param hash_fn the hash to use
101* @param secret the secret bits
102* @param secret_len the length of secret
103* @param label the full label (no "TLS 1.3, " or "tls13 " prefix
104* is applied)
105* @param hash_val the previous hash value (used for chaining, may be empty)
106* @param hash_val_len the length of hash_val
107* @param length the desired output length
108*/
110 const uint8_t secret[],
111 size_t secret_len,
112 std::string_view label,
113 const uint8_t hash_val[],
114 size_t hash_val_len,
115 size_t length);
116
117} // namespace Botan
118
119#endif
std::string name() const override
Definition hkdf.cpp:92
std::unique_ptr< KDF > new_object() const override
Definition hkdf.cpp:88
void kdf(uint8_t key[], size_t key_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len) const override
Definition hkdf.cpp:96
HKDF_Expand(std::unique_ptr< MessageAuthenticationCode > prf)
Definition hkdf.h:79
std::unique_ptr< KDF > new_object() const override
Definition hkdf.cpp:41
HKDF_Extract(std::unique_ptr< MessageAuthenticationCode > prf)
Definition hkdf.h:52
std::string name() const override
Definition hkdf.cpp:45
void kdf(uint8_t key[], size_t key_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len) const override
Definition hkdf.cpp:49
std::string name() const override
Definition hkdf.cpp:21
std::unique_ptr< KDF > new_object() const override
Definition hkdf.cpp:17
void kdf(uint8_t key[], size_t key_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len) const override
Definition hkdf.cpp:25
HKDF(std::unique_ptr< MessageAuthenticationCode > prf)
Definition hkdf.h:25
int(* final)(unsigned char *, CTX *)
#define BOTAN_TEST_API
Definition compiler.h:51
secure_vector< uint8_t > hkdf_expand_label(std::string_view hash_fn, const uint8_t secret[], size_t secret_len, std::string_view label, const uint8_t hash_val[], size_t hash_val_len, size_t length)
Definition hkdf.cpp:131
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61