Botan 3.4.0
Crypto and TLS for C&
sp800_56a.h
Go to the documentation of this file.
1/*
2* KDF defined in NIST SP 800-56a revision 2 (Single-step key-derivation function)
3*
4* (C) 2017 Ribose Inc. Written by Krzysztof Kwiatkowski.
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_SP800_56A_H_
10#define BOTAN_SP800_56A_H_
11
12#include <botan/hash.h>
13#include <botan/kdf.h>
14#include <botan/mac.h>
15
16namespace Botan {
17
18/**
19 * NIST SP 800-56A KDF using hash function
20 * @warning This KDF ignores the provided salt value
21 */
22class SP800_56A_Hash final : public KDF {
23 public:
24 std::string name() const override;
25
26 std::unique_ptr<KDF> new_object() const override;
27
28 /**
29 * Derive a key using the SP800-56A KDF.
30 *
31 * The implementation hard codes the context value for the
32 * expansion step to the empty string.
33 *
34 * @param key derived keying material K_M
35 * @param key_len the desired output length in bytes
36 * @param secret shared secret Z
37 * @param secret_len size of Z in bytes
38 * @param salt ignored
39 * @param salt_len ignored
40 * @param label label for the expansion step
41 * @param label_len size of label in bytes
42 *
43 * @throws Invalid_Argument key_len > 2^32
44 */
45 void kdf(uint8_t key[],
46 size_t key_len,
47 const uint8_t secret[],
48 size_t secret_len,
49 const uint8_t salt[],
50 size_t salt_len,
51 const uint8_t label[],
52 size_t label_len) const override;
53
54 /**
55 * @param hash the hash function to use as the auxiliary function
56 */
57 explicit SP800_56A_Hash(std::unique_ptr<HashFunction> hash) : m_hash(std::move(hash)) {}
58
59 private:
60 std::unique_ptr<HashFunction> m_hash;
61};
62
63/**
64 * NIST SP 800-56A KDF using HMAC
65 */
66class SP800_56A_HMAC final : public KDF {
67 public:
68 std::string name() const override;
69
70 std::unique_ptr<KDF> new_object() const override;
71
72 /**
73 * Derive a key using the SP800-56A KDF.
74 *
75 * The implementation hard codes the context value for the
76 * expansion step to the empty string.
77 *
78 * @param key derived keying material K_M
79 * @param key_len the desired output length in bytes
80 * @param secret shared secret Z
81 * @param secret_len size of Z in bytes
82 * @param salt ignored
83 * @param salt_len ignored
84 * @param label label for the expansion step
85 * @param label_len size of label in bytes
86 *
87 * @throws Invalid_Argument key_len > 2^32 or MAC is not a HMAC
88 */
89 void kdf(uint8_t key[],
90 size_t key_len,
91 const uint8_t secret[],
92 size_t secret_len,
93 const uint8_t salt[],
94 size_t salt_len,
95 const uint8_t label[],
96 size_t label_len) const override;
97
98 /**
99 * @param mac the HMAC to use as the auxiliary function
100 */
101 explicit SP800_56A_HMAC(std::unique_ptr<MessageAuthenticationCode> mac);
102
103 private:
104 std::unique_ptr<MessageAuthenticationCode> m_mac;
105};
106
107} // namespace Botan
108
109#endif
SP800_56A_HMAC(std::unique_ptr< MessageAuthenticationCode > mac)
Definition sp800_56a.cpp:78
std::string name() const override
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 sp800_56a.cpp:85
std::unique_ptr< KDF > new_object() const override
SP800_56A_Hash(std::unique_ptr< HashFunction > hash)
Definition sp800_56a.h:57
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 sp800_56a.cpp:53
std::string name() const override
Definition sp800_56a.cpp:70
std::unique_ptr< KDF > new_object() const override
Definition sp800_56a.cpp:74
int(* final)(unsigned char *, CTX *)