9#ifndef BOTAN_KDF_BASE_H_
10#define BOTAN_KDF_BASE_H_
12#include <botan/concepts.h>
13#include <botan/secmem.h>
36 static std::unique_ptr<KDF>
create(std::string_view algo_spec, std::string_view provider =
"");
43 static std::unique_ptr<KDF>
create_or_throw(std::string_view algo_spec, std::string_view provider =
"");
49 static std::vector<std::string>
providers(std::string_view algo_spec);
55 virtual std::string
name()
const = 0;
69 void
kdf(uint8_t key[],
71 const uint8_t secret[],
75 const uint8_t label[],
76 size_t label_len)
const {
77 derive_key({key, key_len}, {secret, secret_len}, {salt, salt_len}, {label, label_len});
91 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
94 const uint8_t secret[],
98 const uint8_t label[] =
nullptr,
99 size_t label_len = 0)
const {
100 return derive_key<T>(key_len, {secret, secret_len}, {salt, salt_len}, {label, label_len});
111 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
113 std::span<const uint8_t> secret,
114 std::string_view salt =
"",
115 std::string_view label =
"")
const {
116 return derive_key<T>(key_len, secret, _as_span(salt), _as_span(label));
127 std::span<const uint8_t> secret,
128 std::span<const uint8_t> salt,
129 std::span<const uint8_t> label)
const {
141 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
143 std::span<const uint8_t> secret,
144 std::span<const uint8_t> salt,
145 std::span<const uint8_t> label)
const {
160 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
163 std::span<const uint8_t> secret,
164 const uint8_t salt[],
166 std::string_view label =
"")
const {
167 return derive_key<T>(key_len, secret, {salt, salt_len}, _as_span(label));
179 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
182 const uint8_t secret[],
184 std::string_view salt =
"",
185 std::string_view label =
"")
const {
186 return derive_key<T>(key_len, {secret, secret_len}, _as_span(salt), _as_span(label));
197 template <
size_t key_len>
198 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
199 std::span<const uint8_t> salt = {},
200 std::span<const uint8_t> label = {}) {
201 std::array<uint8_t, key_len> key{};
202 perform_kdf(key, secret, salt, label);
214 template <
size_t key_len>
215 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
216 std::span<const uint8_t> salt = {},
217 std::string_view label =
"") {
218 return derive_key<key_len>(secret, salt, _as_span(label));
229 template <
size_t key_len>
230 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
231 std::string_view salt =
"",
232 std::string_view label =
"") {
261 std::span<const uint8_t> secret,
262 std::span<const uint8_t> salt,
263 std::span<const uint8_t> label)
const = 0;
266 static std::span<const uint8_t> _as_span(std::string_view s);
279 if(algo_spec ==
"Raw") {
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_DEPRECATED(msg)
void derive_key(std::span< uint8_t > key, std::span< const uint8_t > secret, std::span< const uint8_t > salt, std::span< const uint8_t > label) const
virtual std::unique_ptr< KDF > new_object() const =0
T derive_key(size_t key_len, std::span< const uint8_t > secret, std::string_view salt="", std::string_view label="") const
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)
virtual void perform_kdf(std::span< uint8_t > key, std::span< const uint8_t > secret, std::span< const uint8_t > salt, std::span< const uint8_t > label) const =0
std::array< uint8_t, key_len > derive_key(std::span< const uint8_t > secret, std::span< const uint8_t > salt={}, std::string_view label="")
static std::unique_ptr< KDF > create(std::string_view algo_spec, std::string_view provider="")
std::array< uint8_t, key_len > derive_key(std::span< const uint8_t > secret, std::span< const uint8_t > salt={}, std::span< const uint8_t > label={})
T derive_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[]=nullptr, size_t label_len=0) const
std::array< uint8_t, key_len > derive_key(std::span< const uint8_t > secret, std::string_view salt="", std::string_view label="")
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
virtual std::string name() const =0
T derive_key(size_t key_len, std::span< const uint8_t > secret, std::span< const uint8_t > salt, std::span< const uint8_t > label) const
KDF * get_kdf(std::string_view algo_spec)