10 #include <botan/scan_name.h>
11 #include <botan/exceptn.h>
13 #if defined(BOTAN_HAS_HKDF)
14 #include <botan/hkdf.h>
17 #if defined(BOTAN_HAS_KDF1)
18 #include <botan/kdf1.h>
21 #if defined(BOTAN_HAS_KDF2)
22 #include <botan/kdf2.h>
25 #if defined(BOTAN_HAS_KDF1_18033)
26 #include <botan/kdf1_iso18033.h>
29 #if defined(BOTAN_HAS_TLS_V10_PRF)
30 #include <botan/prf_tls.h>
33 #if defined(BOTAN_HAS_TLS_V12_PRF)
34 #include <botan/prf_tls.h>
37 #if defined(BOTAN_HAS_X942_PRF)
38 #include <botan/prf_x942.h>
41 #if defined(BOTAN_HAS_SP800_108)
42 #include <botan/sp800_108.h>
45 #if defined(BOTAN_HAS_SP800_56C)
46 #include <botan/sp800_56c.h>
53 template<
typename KDF_Type>
55 kdf_create_mac_or_hash(
const std::string& nm)
58 return std::unique_ptr<KDF>(
new KDF_Type(mac.release()));
61 return std::unique_ptr<KDF>(
new KDF_Type(mac.release()));
68 std::unique_ptr<KDF>
KDF::create(
const std::string& algo_spec,
69 const std::string& provider)
73 #if defined(BOTAN_HAS_HKDF)
76 if(provider.empty() || provider ==
"base")
78 return kdf_create_mac_or_hash<HKDF>(req.
arg(0));
84 if(provider.empty() || provider ==
"base")
86 return kdf_create_mac_or_hash<HKDF_Extract>(req.
arg(0));
92 if(provider.empty() || provider ==
"base")
94 return kdf_create_mac_or_hash<HKDF_Expand>(req.
arg(0));
99 #if defined(BOTAN_HAS_KDF2)
102 if(provider.empty() || provider ==
"base")
105 return std::unique_ptr<KDF>(
new KDF2(
hash.release()));
110 #if defined(BOTAN_HAS_KDF1_18033)
113 if(provider.empty() || provider ==
"base")
121 #if defined(BOTAN_HAS_KDF1)
124 if(provider.empty() || provider ==
"base")
127 return std::unique_ptr<KDF>(
new KDF1(
hash.release()));
132 #if defined(BOTAN_HAS_TLS_V10_PRF)
135 if(provider.empty() || provider ==
"base")
137 return std::unique_ptr<KDF>(
new TLS_PRF);
142 #if defined(BOTAN_HAS_TLS_V12_PRF)
145 if(provider.empty() || provider ==
"base")
147 return kdf_create_mac_or_hash<TLS_12_PRF>(req.
arg(0));
152 #if defined(BOTAN_HAS_X942_PRF)
155 if(provider.empty() || provider ==
"base")
157 return std::unique_ptr<KDF>(
new X942_PRF(req.
arg(0)));
162 #if defined(BOTAN_HAS_SP800_108)
165 if(provider.empty() || provider ==
"base")
167 return kdf_create_mac_or_hash<SP800_108_Counter>(req.
arg(0));
173 if(provider.empty() || provider ==
"base")
175 return kdf_create_mac_or_hash<SP800_108_Feedback>(req.
arg(0));
181 if(provider.empty() || provider ==
"base")
183 return kdf_create_mac_or_hash<SP800_108_Pipeline>(req.
arg(0));
188 #if defined(BOTAN_HAS_SP800_56C)
191 std::unique_ptr<KDF> exp(kdf_create_mac_or_hash<SP800_108_Feedback>(req.
arg(0)));
195 return std::unique_ptr<KDF>(
new SP800_56C(mac.release(), exp.release()));
198 return std::unique_ptr<KDF>(
new SP800_56C(mac.release(), exp.release()));
212 const std::string& provider)
223 return probe_providers_of<KDF>(algo_spec, {
"base" });
237 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)
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< KDF > create(const std::string &algo_spec, const std::string &provider="")
const std::string & algo_name() const
KDF * get_kdf(const std::string &algo_spec)
static std::unique_ptr< KDF > create_or_throw(const std::string &algo_spec, const std::string &provider="")