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/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});
89 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
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});
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, secret, _as_span(salt), _as_span(label));
125 std::span<const uint8_t> secret,
126 std::span<const uint8_t> salt,
127 std::span<const uint8_t> label)
const {
139 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
141 std::span<const uint8_t> secret,
142 std::span<const uint8_t> salt,
143 std::span<const uint8_t> label)
const {
158 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
161 std::span<const uint8_t> secret,
162 const uint8_t salt[],
164 std::string_view label =
"")
const {
165 return derive_key<T>(key_len, secret, {salt, salt_len}, _as_span(label));
177 template <concepts::resizable_
byte_buffer T = secure_vector<u
int8_t>>
180 const uint8_t secret[],
182 std::string_view salt =
"",
183 std::string_view label =
"")
const {
184 return derive_key<T>(key_len, {secret, secret_len}, _as_span(salt), _as_span(label));
195 template <
size_t key_len>
196 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
197 std::span<const uint8_t> salt = {},
198 std::span<const uint8_t> label = {}) {
199 std::array<uint8_t, key_len> key;
200 perform_kdf(key, secret, salt, label);
212 template <
size_t key_len>
213 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
214 std::span<const uint8_t> salt = {},
215 std::string_view label =
"") {
216 return derive_key<key_len>(secret, salt, _as_span(label));
227 template <
size_t key_len>
228 std::array<uint8_t, key_len>
derive_key(std::span<const uint8_t> secret,
229 std::string_view salt =
"",
230 std::string_view label =
"") {
257 std::span<const uint8_t> secret,
258 std::span<const uint8_t> salt,
259 std::span<const uint8_t> label)
const = 0;
262 static std::span<const uint8_t> _as_span(std::string_view s) {
263 return {
reinterpret_cast<const uint8_t*
>(s.data()), s.size()};
277 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)