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

#include <getentropy.h>

Inheritance diagram for Botan::Getentropy:
Botan::Entropy_Source

Public Member Functions

void gather (Entropy_Accumulator &acc) override
std::string name () const override
virtual size_t poll (RandomNumberGenerator &rng)

Static Public Member Functions

static std::unique_ptr< Entropy_Source > create (std::string_view type)

Detailed Description

Entropy source using the getentropy(2) system call first introduced in OpenBSD 5.6 and added to Solaris 11.3.

Definition at line 19 of file getentropy.h.

Member Function Documentation

◆ create()

std::unique_ptr< Entropy_Source > Botan::Entropy_Source::create ( std::string_view type)
staticinherited

Return a new entropy source of a particular type, or null Each entropy source may require substantial resources (eg, a file handle or socket instance), so try to share them among multiple RNGs, or just use the preconfigured global list accessed by Entropy_Sources::global_sources()

Definition at line 217 of file entropy_srcs.cpp.

217 {
218#if defined(BOTAN_HAS_SYSTEM_RNG)
219 if(name == "system_rng") {
220 return std::make_unique<System_RNG_EntropySource>();
221 }
222#endif
223
224#if defined(BOTAN_HAS_PROCESSOR_RNG)
225 if(name == "hwrng") {
227 return std::make_unique<Processor_RNG_EntropySource>();
228 }
229 }
230#endif
231
232#if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
233 if(name == "rdseed") {
234 return std::make_unique<Intel_Rdseed>();
235 }
236#endif
237
238#if defined(BOTAN_HAS_ENTROPY_SRC_GETENTROPY)
239 if(name == "getentropy") {
240 return std::make_unique<Getentropy>();
241 }
242#endif
243
244#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
245 if(name == "system_stats") {
246 return std::make_unique<Win32_EntropySource>();
247 }
248#endif
249
250#if defined(BOTAN_HAS_JITTER_RNG)
251 if(name == "jitter_rng") {
252 return std::make_unique<Jitter_RNG_EntropySource>(Jitter_RNG::Mode::Default);
253 }
254 if(name == "jitter_rng_fips") {
255 return std::make_unique<Jitter_RNG_EntropySource>(Jitter_RNG::Mode::FIPS);
256 }
257 if(name == "jitter_rng_ntg1") {
258 return std::make_unique<Jitter_RNG_EntropySource>(Jitter_RNG::Mode::NTG1);
259 }
260#endif
261
263 return nullptr;
264}
#define BOTAN_UNUSED
Definition assert.h:151
virtual std::string name() const =0
static bool available()

References Botan::Processor_RNG::available(), BOTAN_UNUSED, Botan::Jitter_RNG::Default, Botan::Jitter_RNG::FIPS, name(), and Botan::Jitter_RNG::NTG1.

Referenced by Botan::Entropy_Sources::Entropy_Sources().

◆ gather()

void Botan::Getentropy::gather ( Entropy_Accumulator & acc)
overridevirtual

Gather 256 bytes entropy from getentropy(2). Note that maximum buffer size is limited to 256 bytes. On OpenBSD this does neither block nor fail.

Reimplemented from Botan::Entropy_Source.

Definition at line 25 of file getentropy.cpp.

25 {
27
28 if(::getentropy(buf.data(), buf.size()) == 0) {
29 acc.add(buf, buf.size() * 8);
30 }
31}
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128

References Botan::Entropy_Accumulator::add().

◆ name()

std::string Botan::Getentropy::name ( ) const
inlineoverridevirtual

Return a free-form string identifying this entropy source

Implements Botan::Entropy_Source.

Definition at line 21 of file getentropy.h.

21{ return "getentropy"; }

◆ poll()

size_t Botan::Entropy_Source::poll ( RandomNumberGenerator & rng)
virtualinherited

Perform an entropy gathering poll (legacy interface)

Parameters
Random Number Generatorswill be provided with entropy via calls to add_entropy
Returns
conservative estimate of actual entropy added to rng during poll

New sources should implement gather instead. The default implementation of this function forwards to gather.

TODO(Botan4) remove this function

Definition at line 206 of file entropy_srcs.cpp.

206 {
207 // A source implementing neither interface would otherwise recurse forever
208 if(dynamic_cast<Legacy_Poll_RNG*>(&rng) != nullptr) {
209 throw Not_Implemented(fmt("Entropy source {} does not implement gather", name()));
210 }
211
212 Entropy_Accumulator acc(RandomNumberGenerator::DefaultPollBits, additional_input_sink(rng));
213 this->gather(acc);
214 return acc.bits_collected();
215}
virtual void gather(Entropy_Accumulator &acc)
static constexpr size_t DefaultPollBits
Definition rng.h:50
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::Entropy_Accumulator::bits_collected(), Botan::RandomNumberGenerator::DefaultPollBits, Botan::fmt(), gather(), and name().

Referenced by gather(), and name().


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