Botan 2.19.1
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::Entropy_Source Class Referenceabstract

#include <entropy_src.h>

Inheritance diagram for Botan::Entropy_Source:
Botan::Device_EntropySource Botan::Getentropy Botan::Intel_Rdseed Botan::ProcWalking_EntropySource Botan::Win32_EntropySource

Public Member Functions

 Entropy_Source ()=default
 
 Entropy_Source (const Entropy_Source &other)=delete
 
 Entropy_Source (Entropy_Source &&other)=delete
 
virtual std::string name () const =0
 
Entropy_Sourceoperator= (const Entropy_Source &other)=delete
 
virtual size_t poll (RandomNumberGenerator &rng)=0
 
virtual ~Entropy_Source ()=default
 

Static Public Member Functions

static std::unique_ptr< Entropy_Sourcecreate (const std::string &type)
 

Detailed Description

Abstract interface to a source of entropy

Definition at line 25 of file entropy_src.h.

Constructor & Destructor Documentation

◆ Entropy_Source() [1/3]

Botan::Entropy_Source::Entropy_Source ( )
default

◆ Entropy_Source() [2/3]

Botan::Entropy_Source::Entropy_Source ( const Entropy_Source other)
delete

◆ Entropy_Source() [3/3]

Botan::Entropy_Source::Entropy_Source ( Entropy_Source &&  other)
delete

◆ ~Entropy_Source()

virtual Botan::Entropy_Source::~Entropy_Source ( )
virtualdefault

Member Function Documentation

◆ create()

std::unique_ptr< Entropy_Source > Botan::Entropy_Source::create ( const std::string &  type)
static

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 107 of file entropy_srcs.cpp.

108 {
109#if defined(BOTAN_HAS_SYSTEM_RNG)
110 if(name == "system_rng" || name == "win32_cryptoapi")
111 {
112 return std::unique_ptr<Entropy_Source>(new System_RNG_EntropySource);
113 }
114#endif
115
116#if defined(BOTAN_HAS_PROCESSOR_RNG)
117 if(name == "hwrng" || name == "rdrand" || name == "p9_darn")
118 {
120 {
121 return std::unique_ptr<Entropy_Source>(new Processor_RNG_EntropySource);
122 }
123 }
124#endif
125
126#if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
127 if(name == "rdseed")
128 {
129 return std::unique_ptr<Entropy_Source>(new Intel_Rdseed);
130 }
131#endif
132
133#if defined(BOTAN_HAS_ENTROPY_SRC_GETENTROPY)
134 if(name == "getentropy")
135 {
136 return std::unique_ptr<Entropy_Source>(new Getentropy);
137 }
138#endif
139
140#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
141 if(name == "dev_random")
142 {
143 return std::unique_ptr<Entropy_Source>(new Device_EntropySource(BOTAN_SYSTEM_RNG_POLL_DEVICES));
144 }
145#endif
146
147#if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER)
148 if(name == "proc_walk" && OS::running_in_privileged_state() == false)
149 {
150 const std::string root_dir = BOTAN_ENTROPY_PROC_FS_PATH;
151 if(!root_dir.empty())
152 return std::unique_ptr<Entropy_Source>(new ProcWalking_EntropySource(root_dir));
153 }
154#endif
155
156#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
157 if(name == "system_stats")
158 {
159 return std::unique_ptr<Entropy_Source>(new Win32_EntropySource);
160 }
161#endif
162
164 return std::unique_ptr<Entropy_Source>();
165 }
#define BOTAN_UNUSED(...)
Definition: assert.h:142
virtual std::string name() const =0
static bool available()
bool running_in_privileged_state()
Definition: os_utils.cpp:143

References Botan::Processor_RNG::available(), BOTAN_UNUSED, name(), and Botan::OS::running_in_privileged_state().

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

◆ name()

virtual std::string Botan::Entropy_Source::name ( ) const
pure virtual
Returns
name identifying this entropy source

Implemented in Botan::Device_EntropySource, Botan::Getentropy, Botan::ProcWalking_EntropySource, Botan::Intel_Rdseed, and Botan::Win32_EntropySource.

Referenced by create().

◆ operator=()

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

◆ poll()

virtual size_t Botan::Entropy_Source::poll ( RandomNumberGenerator rng)
pure virtual

Perform an entropy gathering poll

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

Implemented in Botan::Device_EntropySource, Botan::Getentropy, Botan::ProcWalking_EntropySource, Botan::Intel_Rdseed, and Botan::Win32_EntropySource.


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