Coverage Report

Created: 2025-08-25 06:58

/src/Botan-3.4.0/build/include/internal/botan/internal/hkdf.h
Line
Count
Source (jump to first uncovered line)
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
15
namespace Botan {
16
17
/**
18
* HKDF from RFC 5869.
19
*/
20
class HKDF final : public KDF {
21
   public:
22
      /**
23
      * @param prf MAC algorithm to use
24
      */
25
0
      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
*/
47
class HKDF_Extract final : public KDF {
48
   public:
49
      /**
50
      * @param prf MAC algorithm to use
51
      */
52
0
      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
*/
74
class HKDF_Expand final : public KDF {
75
   public:
76
      /**
77
      * @param prf MAC algorithm to use
78
      */
79
0
      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
*/
109
secure_vector<uint8_t> BOTAN_TEST_API hkdf_expand_label(std::string_view hash_fn,
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