Botan 3.14.1
Crypto and TLS for C&
Botan::Entropy_Accumulator Class Referencefinal

#include <entropy_src.h>

Public Types

using Sink = std::function<void(std::span<const uint8_t>)>

Public Member Functions

void add (std::span< const uint8_t > data, size_t estimated_entropy_bits)
template<typename T>
void add_T (const T &t, size_t estimated_entropy_bits)
size_t bits_collected () const
 Entropy_Accumulator (const Entropy_Accumulator &other)=delete
 Entropy_Accumulator (Entropy_Accumulator &&other)=delete
 Entropy_Accumulator (size_t goal_bits, Sink sink)
size_t goal_bits () const
bool goal_reached () const
Entropy_Accumulator & operator= (const Entropy_Accumulator &other)=delete
Entropy_Accumulator & operator= (Entropy_Accumulator &&other)=delete
 ~Entropy_Accumulator ()=default

Friends

class Entropy_Source

Detailed Description

Collects entropy on behalf of an RNG which is being seeded

An Entropy_Source is handed an accumulator rather than the RNG itself. A source can only contribute data plus a conservative estimate of how much entropy that data contains. The RNG later decides, from the accumulated estimate, whether the seeding succeeded.

Definition at line 33 of file entropy_src.h.

Member Typedef Documentation

◆ Sink

using Botan::Entropy_Accumulator::Sink = std::function<void(std::span<const uint8_t>)>

Definition at line 35 of file entropy_src.h.

Constructor & Destructor Documentation

◆ Entropy_Accumulator() [1/3]

Botan::Entropy_Accumulator::Entropy_Accumulator ( size_t goal_bits,
Sink sink )
Parameters
goal_bitshow many bits of entropy the caller hopes to collect
sinkreceives all data contributed to the accumulator

Definition at line 178 of file entropy_srcs.cpp.

178 :
179 m_sink(std::move(sink)), m_goal_bits(goal_bits) {
180 BOTAN_ARG_CHECK(m_sink != nullptr, "Entropy_Accumulator requires a sink");
181}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, and goal_bits().

Referenced by Entropy_Accumulator(), Entropy_Accumulator(), operator=(), and operator=().

◆ Entropy_Accumulator() [2/3]

Botan::Entropy_Accumulator::Entropy_Accumulator ( const Entropy_Accumulator & other)
delete

References Entropy_Accumulator().

◆ Entropy_Accumulator() [3/3]

Botan::Entropy_Accumulator::Entropy_Accumulator ( Entropy_Accumulator && other)
delete

References Entropy_Accumulator().

◆ ~Entropy_Accumulator()

Botan::Entropy_Accumulator::~Entropy_Accumulator ( )
default

References add().

Member Function Documentation

◆ add()

void Botan::Entropy_Accumulator::add ( std::span< const uint8_t > data,
size_t estimated_entropy_bits )

Contribute data along with a conservative estimate of the entropy it contains. Data of unknown or untrusted quality should be contributed with an estimate of zero; it is still mixed into the RNG but not credited. The estimate is capped at the bit length of the data.

Definition at line 183 of file entropy_srcs.cpp.

183 {
184 if(data.empty()) {
185 return;
186 }
187
188 m_sink(data);
189 m_bytes_contributed += data.size();
190 credit(estimated_entropy_bits, data.size());
191}

Referenced by add_T(), Botan::Getentropy::gather(), Botan::Intel_Rdseed::gather(), and ~Entropy_Accumulator().

◆ add_T()

template<typename T>
void Botan::Entropy_Accumulator::add_T ( const T & t,
size_t estimated_entropy_bits )
inline

Contribute the representation of a trivial object, see add

Definition at line 62 of file entropy_src.h.

62 {
63 this->add(std::span(reinterpret_cast<const uint8_t*>(&t), sizeof(T)), estimated_entropy_bits);
64 }
void add(std::span< const uint8_t > data, size_t estimated_entropy_bits)

References add().

Referenced by Botan::Win32_EntropySource::gather().

◆ bits_collected()

size_t Botan::Entropy_Accumulator::bits_collected ( ) const
inline
Returns
the entropy estimate accumulated so far, in bits

Definition at line 69 of file entropy_src.h.

69{ return m_bits_collected; }

Referenced by Botan::Entropy_Sources::_gather(), Botan::Entropy_Sources::_gather_just(), Botan::Entropy_Source::poll(), and Botan::Entropy_Sources::poll().

◆ goal_bits()

size_t Botan::Entropy_Accumulator::goal_bits ( ) const
inline
Returns
the number of bits the caller hopes to collect

Definition at line 74 of file entropy_src.h.

74{ return m_goal_bits; }

Referenced by Entropy_Accumulator().

◆ goal_reached()

bool Botan::Entropy_Accumulator::goal_reached ( ) const
inline
Returns
true once the goal has been reached; a source may stop polling early

Definition at line 79 of file entropy_src.h.

79{ return m_bits_collected >= m_goal_bits; }

Referenced by Botan::Entropy_Sources::_gather(), and Botan::Entropy_Sources::poll().

◆ operator=() [1/2]

Entropy_Accumulator & Botan::Entropy_Accumulator::operator= ( const Entropy_Accumulator & other)
delete

References Entropy_Accumulator().

◆ operator=() [2/2]

Entropy_Accumulator & Botan::Entropy_Accumulator::operator= ( Entropy_Accumulator && other)
delete

References Entropy_Accumulator().

◆ Entropy_Source

friend class Entropy_Source
friend

Definition at line 82 of file entropy_src.h.

References Entropy_Source.

Referenced by Entropy_Source.


The documentation for this class was generated from the following files: