10 #include <botan/hash.h>
11 #include <botan/scan_name.h>
12 #include <botan/exceptn.h>
14 #if defined(BOTAN_HAS_HKDF)
15 #include <botan/hkdf.h>
18 #if defined(BOTAN_HAS_KDF1)
19 #include <botan/kdf1.h>
22 #if defined(BOTAN_HAS_KDF2)
23 #include <botan/kdf2.h>
26 #if defined(BOTAN_HAS_KDF1_18033)
27 #include <botan/kdf1_iso18033.h>
30 #if defined(BOTAN_HAS_TLS_V10_PRF) || defined(BOTAN_HAS_TLS_V12_PRF)
31 #include <botan/prf_tls.h>
34 #if defined(BOTAN_HAS_X942_PRF)
35 #include <botan/prf_x942.h>
38 #if defined(BOTAN_HAS_SP800_108)
39 #include <botan/sp800_108.h>
42 #if defined(BOTAN_HAS_SP800_56A)
43 #include <botan/sp800_56a.h>
46 #if defined(BOTAN_HAS_SP800_56C)
47 #include <botan/sp800_56c.h>
54 template<
typename KDF_Type>
56 kdf_create_mac_or_hash(
const std::string& nm)
59 return std::unique_ptr<KDF>(
new KDF_Type(mac.release()));
62 return std::unique_ptr<KDF>(
new KDF_Type(mac.release()));
69 std::unique_ptr<KDF>
KDF::create(
const std::string& algo_spec,
70 const std::string& provider)
74 #if defined(BOTAN_HAS_HKDF)
77 if(provider.empty() || provider ==
"base")
79 return kdf_create_mac_or_hash<HKDF>(req.
arg(0));
85 if(provider.empty() || provider ==
"base")
87 return kdf_create_mac_or_hash<HKDF_Extract>(req.
arg(0));
93 if(provider.empty() || provider ==
"base")
95 return kdf_create_mac_or_hash<HKDF_Expand>(req.
arg(0));
100 #if defined(BOTAN_HAS_KDF2)
103 if(provider.empty() || provider ==
"base")
106 return std::unique_ptr<KDF>(
new KDF2(
hash.release()));
111 #if defined(BOTAN_HAS_KDF1_18033)
114 if(provider.empty() || provider ==
"base")
122 #if defined(BOTAN_HAS_KDF1)
125 if(provider.empty() || provider ==
"base")
128 return std::unique_ptr<KDF>(
new KDF1(
hash.release()));
133 #if defined(BOTAN_HAS_TLS_V10_PRF)
136 if(provider.empty() || provider ==
"base")
141 if(hmac_md5 && hmac_sha1)
142 return std::unique_ptr<KDF>(
new TLS_PRF(std::move(hmac_md5), std::move(hmac_sha1)));
147 #if defined(BOTAN_HAS_TLS_V12_PRF)
150 if(provider.empty() || provider ==
"base")
152 return kdf_create_mac_or_hash<TLS_12_PRF>(req.
arg(0));
157 #if defined(BOTAN_HAS_X942_PRF)
160 if(provider.empty() || provider ==
"base")
162 return std::unique_ptr<KDF>(
new X942_PRF(req.
arg(0)));
167 #if defined(BOTAN_HAS_SP800_108)
170 if(provider.empty() || provider ==
"base")
172 return kdf_create_mac_or_hash<SP800_108_Counter>(req.
arg(0));
178 if(provider.empty() || provider ==
"base")
180 return kdf_create_mac_or_hash<SP800_108_Feedback>(req.
arg(0));
186 if(provider.empty() || provider ==
"base")
188 return kdf_create_mac_or_hash<SP800_108_Pipeline>(req.
arg(0));
193 #if defined(BOTAN_HAS_SP800_56A)
203 #if defined(BOTAN_HAS_SP800_56C)
206 std::unique_ptr<KDF> exp(kdf_create_mac_or_hash<SP800_108_Feedback>(req.
arg(0)));
210 return std::unique_ptr<KDF>(
new SP800_56C(mac.release(), exp.release()));
213 return std::unique_ptr<KDF>(
new SP800_56C(mac.release(), exp.release()));
227 const std::string& provider)
238 return probe_providers_of<KDF>(algo_spec, {
"base" });
252 return kdf.release();
std::string arg(size_t i) const
static std::unique_ptr< MessageAuthenticationCode > create(const std::string &algo_spec, const std::string &provider="")
static std::vector< std::string > providers(const std::string &algo_spec)
KDF * get_kdf(const std::string &algo_spec)
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
#define BOTAN_UNUSED(...)
static std::unique_ptr< KDF > create(const std::string &algo_spec, const std::string &provider="")
const std::string & algo_name() const
virtual size_t 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 =0
static std::unique_ptr< KDF > create_or_throw(const std::string &algo_spec, const std::string &provider="")