9#include <botan/tpm2_rng.h>
11#include <botan/internal/stl_util.h>
12#include <botan/internal/tpm2_util.h>
14#include <tss2/tss2_esys.h>
19 m_ctx(std::move(ctx)), m_sessions(std::move(sessions)) {
21 m_max_tpm2_rng_bytes = m_ctx->max_random_bytes_per_request();
24void RandomNumberGenerator::fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) {
25 constexpr size_t MAX_STIR_RANDOM_SIZE = 128;
29 const size_t chunk = std::min(in.remaining(), MAX_STIR_RANDOM_SIZE);
32 check_rc(
"Esys_StirRandom", Esys_StirRandom(*m_ctx, m_sessions[0], m_sessions[1], m_sessions[2], &data));
39 const auto requested_bytes = std::min(out.remaining_capacity(), m_max_tpm2_rng_bytes);
41 Esys_GetRandom(*m_ctx, m_sessions[0], m_sessions[1], m_sessions[2], requested_bytes,
out_ptr(digest)));
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT_NONNULL(ptr)
Helper class to ease in-place marshalling of concatenated fixed-length values.
RandomNumberGenerator()=default
constexpr void check_rc(std::string_view location, TSS2_RC rc)
std::unique_ptr< T, esys_liberator > unique_esys_ptr
A unique pointer type for ESYS handles that automatically frees the handle.
constexpr void copy_into(T &dest, std::span< const uint8_t > data)
constexpr auto as_span(tpm2_buffer auto &data)
Construct a std::span as a view into a TPM2 buffer.
constexpr auto out_ptr(T &outptr) noexcept