7#include <botan/stateful_rng.h>
9#include <botan/internal/loadstor.h>
10#include <botan/internal/os_utils.h>
28 return m_reseed_counter > 0;
38void Stateful_RNG::generate_batched_output(std::span<uint8_t> output, std::span<const uint8_t> input) {
43 if(max_per_request == 0) {
48 while(!output.empty()) {
49 const size_t this_req = std::min(max_per_request, output.size());
57 output = output.subspan(this_req);
62void Stateful_RNG::fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) {
70 reset_reseed_counter();
73 generate_batched_output(output, input);
83 reset_reseed_counter();
86 return bits_collected;
95 reset_reseed_counter();
99void Stateful_RNG::reset_reseed_counter() {
101 m_reseed_counter = 1;
109 const bool fork_detected = (m_last_pid > 0) && (cur_pid != m_last_pid);
111 if(
is_seeded() ==
false || fork_detected || (m_reseed_interval > 0 && m_reseed_counter >= m_reseed_interval)) {
112 m_reseed_counter = 0;
113 m_last_pid = cur_pid;
115 if(m_underlying_rng) {
119 if(m_entropy_sources) {
125 throw Invalid_State(
"Detected use of fork but cannot reseed DRBG");
132 m_reseed_counter += 1;
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT(expr, assertion_made)
void add_entropy(std::span< const uint8_t > input)
virtual void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS)
virtual std::string name() const =0
virtual size_t reseed(Entropy_Sources &srcs, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS, std::chrono::milliseconds poll_timeout=BOTAN_RNG_RESEED_DEFAULT_TIMEOUT)
bool is_seeded() const final
virtual size_t security_level() const =0
virtual void clear_state()=0
size_t reseed(Entropy_Sources &srcs, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS, std::chrono::milliseconds poll_timeout=BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) override
virtual void generate_output(std::span< uint8_t > output, std::span< const uint8_t > input)=0
virtual size_t max_number_of_bytes_per_request() const =0
void reseed_from_rng(RandomNumberGenerator &rng, size_t poll_bits=BOTAN_RNG_RESEED_POLL_BITS) final
void initialize_with(std::span< const uint8_t > input)
int(* update)(CTX *, const void *, CC_LONG len)
uint32_t BOTAN_TEST_API get_process_id()
secure_vector< T > lock(const std::vector< T > &in)
lock_guard< T > lock_guard_type