8#ifndef BOTAN_KDF_BASE_H_
9#define BOTAN_KDF_BASE_H_
11#include <botan/concepts.h>
12#include <botan/exceptn.h>
13#include <botan/mem_ops.h>
14#include <botan/secmem.h>
35 static std::unique_ptr<KDF> create(std::string_view algo_spec, std::string_view provider =
"");
42 static std::unique_ptr<KDF> create_or_throw(std::string_view algo_spec, std::string_view provider =
"");
47 static std::vector<std::string> providers(std::string_view algo_spec);
52 virtual std::string
name()
const = 0;
65 virtual void kdf(uint8_t key[],
67 const uint8_t secret[],
71 const uint8_t label[],
72 size_t label_len)
const = 0;
85 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
87 const uint8_t secret[],
91 const uint8_t label[] =
nullptr,
92 size_t label_len = 0)
const {
94 kdf(key.data(), key.size(), secret, secret_len, salt, salt_len, label, label_len);
106 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
108 std::span<const uint8_t> secret,
109 std::string_view salt =
"",
110 std::string_view label =
"")
const {
111 return derive_key<T>(key_len,
128 std::span<const uint8_t> secret,
129 std::span<const uint8_t> salt,
130 std::span<const uint8_t> label)
const {
132 key.data(), key.size(), secret.data(), secret.size(), salt.data(), salt.size(), label.data(), label.size());
143 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
145 std::span<const uint8_t> secret,
146 std::span<const uint8_t> salt,
147 std::span<const uint8_t> label)
const {
148 return derive_key<T>(
149 key_len, secret.data(), secret.size(), salt.data(), salt.size(), label.data(), label.size());
161 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>(
168 key_len, secret.data(), secret.size(), salt, salt_len,
cast_char_ptr_to_uint8(label.data()), label.size());
180 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,
203 KDF*
clone()
const {
return this->new_object().release(); }
218 return kdf.release();
221 if(algo_spec ==
"Raw") {
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(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
T derive_key(size_t key_len, const uint8_t secret[], size_t secret_len, std::string_view salt="", std::string_view label="") const
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
T derive_key(size_t key_len, std::span< const uint8_t > secret, const uint8_t salt[], size_t salt_len, std::string_view label="") 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
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_DEPRECATED(msg)
KDF * get_kdf(std::string_view algo_spec)
const uint8_t * cast_char_ptr_to_uint8(const char *s)