8#include <botan/internal/sp800_108.h>
10#include <botan/exceptn.h>
11#include <botan/internal/fmt.h>
12#include <botan/internal/loadstor.h>
18 return fmt(
"SP800-108-Counter({})", m_prf->name());
22 return std::make_unique<SP800_108_Counter>(m_prf->new_object());
27 const uint8_t secret[],
31 const uint8_t label[],
32 size_t label_len)
const {
33 const std::size_t prf_len = m_prf->output_length();
35 const uint64_t blocks_required = (key_len + prf_len - 1) / prf_len;
37 if(blocks_required > 0xFFFFFFFF) {
41 const uint8_t delim = 0;
42 const uint32_t length =
static_cast<uint32_t
>(key_len * 8);
46 uint8_t be_len[4] = {0};
50 m_prf->set_key(secret, secret_len);
52 while(p < key + key_len) {
53 const std::size_t to_copy = std::min<std::size_t>(key + key_len - p, prf_len);
54 uint8_t be_cnt[4] = {0};
58 m_prf->update(be_cnt, 4);
59 m_prf->update(label, label_len);
61 m_prf->update(salt, salt_len);
62 m_prf->update(be_len, 4);
74 return fmt(
"SP800-108-Feedback({})", m_prf->name());
78 return std::make_unique<SP800_108_Feedback>(m_prf->new_object());
83 const uint8_t secret[],
87 const uint8_t label[],
88 size_t label_len)
const {
89 const uint32_t length =
static_cast<uint32_t
>(key_len * 8);
90 const std::size_t prf_len = m_prf->output_length();
91 const std::size_t iv_len = (salt_len >= prf_len ? prf_len : 0);
92 const uint8_t delim = 0;
94 const uint64_t blocks_required = (key_len + prf_len - 1) / prf_len;
96 if(blocks_required > 0xFFFFFFFF) {
101 uint32_t counter = 1;
102 uint8_t be_len[4] = {0};
107 m_prf->set_key(secret, secret_len);
109 while(p < key + key_len) {
110 const std::size_t to_copy = std::min<std::size_t>(key + key_len - p, prf_len);
111 uint8_t be_cnt[4] = {0};
116 m_prf->update(be_cnt, 4);
117 m_prf->update(label, label_len);
118 m_prf->update(delim);
120 m_prf->update(be_len, 4);
133 return fmt(
"SP800-108-Pipeline({})", m_prf->name());
137 return std::make_unique<SP800_108_Pipeline>(m_prf->new_object());
142 const uint8_t secret[],
144 const uint8_t salt[],
146 const uint8_t label[],
147 size_t label_len)
const {
148 const uint32_t length =
static_cast<uint32_t
>(key_len * 8);
149 const std::size_t prf_len = m_prf->output_length();
150 const uint8_t delim = 0;
152 const uint64_t blocks_required = (key_len + prf_len - 1) / prf_len;
154 if(blocks_required > 0xFFFFFFFF) {
159 uint32_t counter = 1;
160 uint8_t be_len[4] = {0};
164 m_prf->set_key(secret, secret_len);
167 std::copy(label, label + label_len, std::back_inserter(ai));
168 ai.emplace_back(delim);
169 std::copy(salt, salt + salt_len, std::back_inserter(ai));
170 std::copy(be_len, be_len + 4, std::back_inserter(ai));
172 while(p < key + key_len) {
178 const std::size_t to_copy = std::min<std::size_t>(key + key_len - p, prf_len);
179 uint8_t be_cnt[4] = {0};
184 m_prf->update(be_cnt, 4);
185 m_prf->update(label, label_len);
186 m_prf->update(delim);
187 m_prf->update(salt, salt_len);
188 m_prf->update(be_len, 4);
#define BOTAN_ASSERT(expr, assertion_made)
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 override
std::string name() const override
std::unique_ptr< KDF > new_object() const override
std::string name() const override
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 override
std::unique_ptr< KDF > new_object() const override
std::unique_ptr< KDF > new_object() const override
std::string name() const override
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 override
std::string fmt(std::string_view format, const T &... args)
std::vector< T, secure_allocator< T > > secure_vector
constexpr void copy_mem(T *out, const T *in, size_t n)
constexpr auto store_be(ParamTs &&... params)