8 #include <botan/prf_x942.h>
9 #include <botan/der_enc.h>
10 #include <botan/oids.h>
11 #include <botan/hash.h>
12 #include <botan/loadstor.h>
22 std::vector<uint8_t> encode_x942_int(uint32_t n)
24 uint8_t n_buf[4] = { 0 };
26 return DER_Encoder().encode(n_buf, 4,
OCTET_STRING).get_contents_unlocked();
32 const uint8_t secret[],
size_t secret_len,
33 const uint8_t salt[],
size_t salt_len,
34 const uint8_t label[],
size_t label_len)
const
37 const OID kek_algo(m_key_wrap_oid);
44 in.reserve(salt_len + label_len);
45 in += std::make_pair(label,label_len);
46 in += std::make_pair(salt,salt_len);
48 while(offset != key_len && counter)
50 hash->update(secret, secret_len);
57 .raw_bytes(encode_x942_int(counter))
60 .encode_if(salt_len != 0,
68 .raw_bytes(encode_x942_int(static_cast<uint32_t>(8 * key_len)))
71 .end_cons().get_contents()
75 const size_t copied =
std::min(h.size(), key_len - offset);
76 copy_mem(&key[offset], h.data(), copied);
void store_be(uint16_t in, uint8_t out[2])
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
size_t 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::vector< T, secure_allocator< T >> secure_vector
std::string lookup(const OID &oid)
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
X942_PRF(const std::string &oid)
void copy_mem(T *out, const T *in, size_t n)
bool have_oid(const std::string &oid)