Botan  2.7.0
Crypto and TLS for C++11
sp800_56c.h
Go to the documentation of this file.
1 /*
2 * KDF defined in NIST SP 800-56c
3 * (C) 2016 Kai Michaelis
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_SP800_56C_H_
9 #define BOTAN_SP800_56C_H_
10 
11 #include <botan/kdf.h>
12 #include <botan/mac.h>
13 
14 namespace Botan {
15 
16 /**
17  * NIST SP 800-56C KDF
18  */
19 class BOTAN_PUBLIC_API(2,0) SP800_56C final : public KDF
20  {
21  public:
22  std::string name() const override { return "SP800-56C(" + m_prf->name() + ")"; }
23 
24  KDF* clone() const override { return new SP800_56C(m_prf->clone(), m_exp->clone()); }
25 
26  /**
27  * Derive a key using the SP800-56C KDF.
28  *
29  * The implementation hard codes the context value for the
30  * expansion step to the empty string.
31  *
32  * @param key derived keying material K_M
33  * @param key_len the desired output length in bytes
34  * @param secret shared secret Z
35  * @param secret_len size of Z in bytes
36  * @param salt salt s of the extraction step
37  * @param salt_len size of s in bytes
38  * @param label label for the expansion step
39  * @param label_len size of label in bytes
40  *
41  * @throws Invalid_Argument key_len > 2^32
42  */
43  size_t kdf(uint8_t key[], size_t key_len,
44  const uint8_t secret[], size_t secret_len,
45  const uint8_t salt[], size_t salt_len,
46  const uint8_t label[], size_t label_len) const override;
47 
48  /**
49  * @param mac MAC algorithm used for randomness extraction
50  * @param exp KDF used for key expansion
51  */
52  SP800_56C(MessageAuthenticationCode* mac, KDF* exp) : m_prf(mac), m_exp(exp) {}
53  private:
54  std::unique_ptr<MessageAuthenticationCode> m_prf;
55  std::unique_ptr<KDF> m_exp;
56  };
57 }
58 
59 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
KDF * clone() const override
Definition: sp800_56c.h:24
SP800_56C(MessageAuthenticationCode *mac, KDF *exp)
Definition: sp800_56c.h:52
size_t salt_len
Definition: x509_obj.cpp:26
Definition: alg_id.cpp:13
Definition: kdf.h:20
std::string name() const override
Definition: sp800_56c.h:22