9#include <botan/internal/prf_x942.h>
11#include <botan/der_enc.h>
12#include <botan/hash.h>
13#include <botan/internal/bit_ops.h>
14#include <botan/internal/loadstor.h>
15#include <botan/internal/stl_util.h>
24std::vector<uint8_t> encode_x942_int(uint32_t n) {
27 std::vector<uint8_t> output;
34void X942_PRF::perform_kdf(std::span<uint8_t> key,
35 std::span<const uint8_t> secret,
36 std::span<const uint8_t> salt,
37 std::span<const uint8_t> label)
const {
42 constexpr size_t sha1_output_bytes = 20;
43 const auto blocks_required =
ceil_division<uint64_t >(key.size(), sha1_output_bytes);
48 BOTAN_ARG_CHECK(blocks_required <= 0xFFFFFFFE,
"X942_PRF maximum output length exceeeded");
54 for(uint32_t counter = 1; !k.full(); ++counter) {
64 .raw_bytes(encode_x942_int(counter))
70 .raw_bytes(encode_x942_int(
static_cast<uint32_t
>(8 * key.size())))
78 if(k.remaining_capacity() >= sha1_output_bytes) {
79 hash->final(k.next(sha1_output_bytes));
81 std::array<uint8_t, sha1_output_bytes> h;
83 k.append(std::span{h}.first(k.remaining_capacity()));
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ARG_CHECK(expr, msg)
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
std::string to_formatted_string() const
std::string name() const override
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
constexpr T ceil_division(T a, T b)
constexpr auto concat(Rs &&... ranges)
constexpr auto store_be(ParamTs &&... params)