8#ifndef BOTAN_ENTROPY_H_
9#define BOTAN_ENTROPY_H_
35 using Sink = std::function<void(std::span<const uint8_t>)>;
55 void add(std::span<const uint8_t> data,
size_t estimated_entropy_bits);
61 requires std::is_standard_layout_v<T> && std::is_trivial_v<T>
62 void add_T(
const T& t,
size_t estimated_entropy_bits) {
63 this->
add(std::span(
reinterpret_cast<const uint8_t*
>(&t),
sizeof(T)), estimated_entropy_bits);
79 bool goal_reached()
const {
return m_bits_collected >= m_goal_bits; }
84 size_t bytes_contributed()
const {
return m_bytes_contributed; }
91 void credit(
size_t estimated_entropy_bits,
size_t data_bytes);
95 size_t m_bytes_contributed = 0;
96 size_t m_bits_collected = 0;
110 static std::unique_ptr<Entropy_Source>
create(std::string_view type);
115 virtual std::string
name()
const = 0;
182 void add_source(std::unique_ptr<Entropy_Source> src);
261 std::vector<std::unique_ptr<Entropy_Source>> m_srcs;
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_DEPRECATED(msg)
void add(std::span< const uint8_t > data, size_t estimated_entropy_bits)
Entropy_Accumulator(Entropy_Accumulator &&other)=delete
Entropy_Accumulator(const Entropy_Accumulator &other)=delete
friend class Entropy_Source
Entropy_Accumulator & operator=(Entropy_Accumulator &&other)=delete
Entropy_Accumulator & operator=(const Entropy_Accumulator &other)=delete
Entropy_Accumulator(size_t goal_bits, Sink sink)
void add_T(const T &t, size_t estimated_entropy_bits)
~Entropy_Accumulator()=default
std::function< void(std::span< const uint8_t >)> Sink
bool goal_reached() const
size_t bits_collected() const
virtual void gather(Entropy_Accumulator &acc)
virtual std::string name() const =0
static std::unique_ptr< Entropy_Source > create(std::string_view type)
Entropy_Source(const Entropy_Source &other)=delete
Entropy_Source(Entropy_Source &&other)=delete
virtual ~Entropy_Source()=default
Entropy_Source & operator=(Entropy_Source &&other)=delete
Entropy_Source & operator=(const Entropy_Source &other)=delete
virtual size_t poll(RandomNumberGenerator &rng)
static Entropy_Sources & global_sources()
size_t _gather(Entropy_Accumulator &acc)
size_t poll_just(RandomNumberGenerator &rng, std::string_view src)
Entropy_Sources(Entropy_Sources &&other)=delete
~Entropy_Sources()=default
Entropy_Sources & operator=(Entropy_Sources &&other)=delete
void add_source(std::unique_ptr< Entropy_Source > src)
Entropy_Sources()=default
size_t poll(RandomNumberGenerator &rng, size_t bits, std::chrono::milliseconds timeout)
size_t _gather_just(Entropy_Accumulator &acc, std::string_view src)
Entropy_Sources(const Entropy_Sources &other)=delete
Entropy_Sources & operator=(const Entropy_Sources &other)=delete
std::vector< std::string > enabled_sources() const