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>
22#if defined(BOTAN_HAS_CPUID)
23 #include <botan/internal/cpuid.h>
30std::unique_ptr<MessageAuthenticationCode> auto_rng_hmac() {
31 const bool has_hardware_sha256_support = []() {
32#if defined(BOTAN_HAS_SHA2_32_X86)
38#if defined(BOTAN_HAS_SHA2_32_ARMV8)
48 if(!has_hardware_sha256_support && HasNative64BitRegisters) {
70 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(), underlying_rng, reseed_interval);
76 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(), entropy_sources, reseed_interval);
83 size_t reseed_interval) {
84 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(), underlying_rng, entropy_sources, reseed_interval);
90#if defined(BOTAN_HAS_SYSTEM_RNG)
91 m_rng = std::make_unique<HMAC_DRBG>(auto_rng_hmac(),
system_rng(), reseed_interval);
92#elif defined(BOTAN_HAS_ENTROPY_SOURCE)
96 throw Not_Implemented(
"AutoSeeded_RNG default constructor not available due to no RNG or entropy sources");
104 m_rng->force_reseed();
109 return m_rng && m_rng->is_seeded();
119 return m_rng->name();
124 return m_rng->reseed_from_sources(srcs, poll_bits);
127void AutoSeeded_RNG::accept_seed_material(std::span<const uint8_t> input) {
129 m_rng->add_entropy(input);
132void AutoSeeded_RNG::fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) {
135 if(out.empty() && in.empty()) {
137 }
else if(in.empty()) {
138 m_rng->randomize_with_ts_input(out);
140 m_rng->randomize_with_input(out, in);
#define BOTAN_STATE_CHECK(expr)
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 bool has(CPUID::Feature feat)
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()