10#include <botan/hash.h>
11#include <botan/internal/scan_name.h>
12#include <botan/internal/fmt.h>
13#include <botan/exceptn.h>
15#if defined(BOTAN_HAS_HKDF)
16#include <botan/internal/hkdf.h>
19#if defined(BOTAN_HAS_KDF1)
20#include <botan/internal/kdf1.h>
23#if defined(BOTAN_HAS_KDF2)
24#include <botan/internal/kdf2.h>
27#if defined(BOTAN_HAS_KDF1_18033)
28#include <botan/internal/kdf1_iso18033.h>
31#if defined(BOTAN_HAS_TLS_V12_PRF)
32#include <botan/internal/prf_tls.h>
35#if defined(BOTAN_HAS_X942_PRF)
36#include <botan/internal/prf_x942.h>
39#if defined(BOTAN_HAS_SP800_108)
40#include <botan/internal/sp800_108.h>
43#if defined(BOTAN_HAS_SP800_56A)
44#include <botan/internal/sp800_56a.h>
47#if defined(BOTAN_HAS_SP800_56C)
48#include <botan/internal/sp800_56c.h>
55template<
typename KDF_Type>
57kdf_create_mac_or_hash(std::string_view nm)
60 return std::make_unique<KDF_Type>(std::move(mac));
63 return std::make_unique<KDF_Type>(std::move(mac));
71 std::string_view provider)
75#if defined(BOTAN_HAS_HKDF)
78 if(provider.empty() || provider ==
"base")
80 return kdf_create_mac_or_hash<HKDF>(req.
arg(0));
86 if(provider.empty() || provider ==
"base")
88 return kdf_create_mac_or_hash<HKDF_Extract>(req.
arg(0));
94 if(provider.empty() || provider ==
"base")
96 return kdf_create_mac_or_hash<HKDF_Expand>(req.
arg(0));
101#if defined(BOTAN_HAS_KDF2)
104 if(provider.empty() || provider ==
"base")
107 return std::make_unique<KDF2>(std::move(hash));
112#if defined(BOTAN_HAS_KDF1_18033)
115 if(provider.empty() || provider ==
"base")
118 return std::make_unique<KDF1_18033>(std::move(hash));
123#if defined(BOTAN_HAS_KDF1)
126 if(provider.empty() || provider ==
"base")
129 return std::make_unique<KDF1>(std::move(hash));
134#if defined(BOTAN_HAS_TLS_V12_PRF)
137 if(provider.empty() || provider ==
"base")
139 return kdf_create_mac_or_hash<TLS_12_PRF>(req.
arg(0));
144#if defined(BOTAN_HAS_X942_PRF)
147 if(provider.empty() || provider ==
"base")
149 return std::make_unique<X942_PRF>(req.
arg(0));
154#if defined(BOTAN_HAS_SP800_108)
157 if(provider.empty() || provider ==
"base")
159 return kdf_create_mac_or_hash<SP800_108_Counter>(req.
arg(0));
165 if(provider.empty() || provider ==
"base")
167 return kdf_create_mac_or_hash<SP800_108_Feedback>(req.
arg(0));
173 if(provider.empty() || provider ==
"base")
175 return kdf_create_mac_or_hash<SP800_108_Pipeline>(req.
arg(0));
180#if defined(BOTAN_HAS_SP800_56A)
184 return std::make_unique<SP800_56A_Hash>(std::move(hash));
186 return std::make_unique<SP800_56A_HMAC>(std::move(mac));
190#if defined(BOTAN_HAS_SP800_56C)
193 std::unique_ptr<KDF> exp(kdf_create_mac_or_hash<SP800_108_Feedback>(req.
arg(0)));
197 return std::make_unique<SP800_56C>(std::move(mac), std::move(exp));
200 return std::make_unique<SP800_56C>(std::move(mac), std::move(exp));
214 std::string_view provider)
225 return probe_providers_of<KDF>(algo_spec);
#define BOTAN_UNUSED(...)
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::vector< std::string > providers(std::string_view algo_spec)
static std::unique_ptr< KDF > create(std::string_view algo_spec, std::string_view provider="")
virtual 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 =0
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
std::string arg(size_t i) const
const std::string algo_name() const
std::string fmt(std::string_view format, const T &... args)