7#include <botan/auto_rng.h>
9#include <botan/assert.h>
10#include <botan/exceptn.h>
11#include <botan/hmac_drbg.h>
14#if defined(BOTAN_HAS_ENTROPY_SOURCE)
15 #include <botan/entropy_src.h>
18#if defined(BOTAN_HAS_SYSTEM_RNG)
19 #include <botan/system_rng.h>
26std::unique_ptr<MessageAuthenticationCode> auto_rng_hmac() {
27 const std::string possible_auto_rng_hmacs[] = {
32 for(
const auto& hmac : possible_auto_rng_hmacs) {
49 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(), underlying_rng, reseed_interval);
55 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(), entropy_sources, reseed_interval);
62 size_t reseed_interval) {
63 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(), underlying_rng, entropy_sources, reseed_interval);
69#if defined(BOTAN_HAS_SYSTEM_RNG)
70 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(),
system_rng(), reseed_interval);
71#elif defined(BOTAN_HAS_ENTROPY_SOURCE)
75 throw Not_Implemented(
"AutoSeeded_RNG default constructor not available due to no RNG or entropy sources");
82 m_rng->force_reseed();
85 if(!m_rng->is_seeded()) {
91 return m_rng->is_seeded();
103 return m_rng->reseed_from_sources(srcs, poll_bits);
106void AutoSeeded_RNG::fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) {
108 m_rng->randomize_with_ts_input(out);
110 m_rng->randomize_with_input(out, in);
std::string name() const override
size_t reseed_from_sources(Entropy_Sources &srcs, size_t poll_bits=RandomNumberGenerator::DefaultPollBits) override
~AutoSeeded_RNG() override
BOTAN_FUTURE_EXPLICIT AutoSeeded_RNG(size_t reseed_interval=RandomNumberGenerator::DefaultReseedInterval)
bool is_seeded() const override
static Entropy_Sources & global_sources()
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
RandomNumberGenerator()=default
RandomNumberGenerator & system_rng()