9#ifndef BOTAN_KDF_BASE_H_
10#define BOTAN_KDF_BASE_H_
12#include <botan/concepts.h>
13#include <botan/exceptn.h>
14#include <botan/mem_ops.h>
15#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 =
"");
48 static std::vector<std::string> providers(std::string_view algo_spec);
53 virtual std::string
name()
const = 0;
67 void kdf(uint8_t key[],
69 const uint8_t secret[],
73 const uint8_t label[],
74 size_t label_len)
const {
75 derive_key({key, key_len}, {secret, secret_len}, {salt, salt_len}, {label, label_len});
67 void kdf(uint8_t key[], {
…}
89 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
91 T derive_key(
size_t key_len,
92 const uint8_t secret[],
96 const uint8_t label[] =
nullptr,
97 size_t label_len = 0)
const {
98 return derive_key<T>(key_len, {secret, secret_len}, {salt, salt_len}, {label, label_len});
91 T derive_key(
size_t key_len, {
…}
109 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
111 std::span<const uint8_t> secret,
112 std::string_view salt =
"",
113 std::string_view label =
"")
const {
114 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 {
131 perform_kdf(key, secret, salt, label);
142 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
144 std::span<const uint8_t> secret,
145 std::span<const uint8_t> salt,
146 std::span<const uint8_t> label)
const {
148 perform_kdf(key, secret, salt, label);
161 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
163 T derive_key(
size_t key_len,
164 std::span<const uint8_t> secret,
165 const uint8_t salt[],
167 std::string_view label = "")
const {
168 return derive_key<T>(key_len, secret, {salt, salt_len}, {
cast_char_ptr_to_uint8(label.data()), label.size()});
163 T derive_key(
size_t key_len, {
…}
180 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
182 T derive_key(
size_t key_len,
183 const uint8_t secret[],
185 std::string_view salt = "",
186 std::string_view label = "")
const {
187 return derive_key<T>(key_len,
188 {secret, secret_len},
182 T derive_key(
size_t key_len, {
…}
201 template <
size_t key_len>
202 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
203 std::span<const uint8_t> salt = {},
204 std::span<const uint8_t> label = {}) {
205 std::array<uint8_t, key_len> key;
206 perform_kdf(key, secret, salt, label);
202 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret, {
…}
218 template <
size_t key_len>
219 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
220 std::span<const uint8_t> salt = {},
221 std::string_view label =
"") {
219 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret, {
…}
233 template <
size_t key_len>
234 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
235 std::string_view salt =
"",
236 std::string_view label =
"") {
237 return derive_key<key_len>(secret,
234 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret, {
…}
250 KDF*
clone()
const {
return this->new_object().release(); }
265 std::span<const uint8_t> secret,
266 std::span<const uint8_t> salt,
267 std::span<const uint8_t> label)
const = 0;
282 return kdf.release();
285 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
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={})
std::array< uint8_t, key_len > derive_key(std::span< const uint8_t > secret, std::string_view salt="", std::string_view label="")
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)
const uint8_t * cast_char_ptr_to_uint8(const char *s)