8#include <botan/libstate.h>
9#include <botan/internal/mutex.h>
11#if defined(BOTAN_HAS_RANDPOOL)
12 #include <botan/randpool.h>
15#if defined(BOTAN_HAS_HMAC_RNG)
16 #include <botan/hmac_rng.h>
19#if defined(BOTAN_HAS_X931_RNG)
20 #include <botan/x931_rng.h>
23#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER)
24 #include <botan/internal/hres_timer.h>
27#if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
28 #include <botan/internal/rdrand.h>
31#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
32 #include <botan/internal/dev_random.h>
35#if defined(BOTAN_HAS_ENTROPY_SRC_EGD)
36 #include <botan/internal/es_egd.h>
39#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX)
40 #include <botan/internal/es_unix.h>
43#if defined(BOTAN_HAS_ENTROPY_SRC_BEOS)
44 #include <botan/internal/es_beos.h>
47#if defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
48 #include <botan/internal/es_capi.h>
51#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
52 #include <botan/internal/es_win32.h>
55#if defined(BOTAN_HAS_ENTROPY_SRC_FTW)
56 #include <botan/internal/es_ftw.h>
68#if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER)
72#if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
76#if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
77 rng->add_entropy_source(
79 split_on(
"/dev/urandom:/dev/srandom:/dev/random",
':')
84#if defined(BOTAN_HAS_ENTROPY_SRC_EGD)
85 rng->add_entropy_source(
90#if defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
94#if defined(BOTAN_HAS_ENTROPY_SRC_FTW)
98#if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
102#if defined(BOTAN_HAS_ENTROPY_SRC_BEOS)
106#if defined(BOTAN_HAS_ENTROPY_SRC_UNIX)
107 rng->add_entropy_source(
116 void randomize(
byte out[],
size_t len)
118 Mutex_Holder lock(mutex);
119 rng->randomize(out, len);
122 bool is_seeded()
const
124 Mutex_Holder lock(mutex);
125 return rng->is_seeded();
130 Mutex_Holder lock(mutex);
134 std::string name()
const
136 Mutex_Holder lock(mutex);
140 void reseed(
size_t poll_bits)
142 Mutex_Holder lock(mutex);
143 rng->reseed(poll_bits);
146 void add_entropy_source(EntropySource* es)
148 Mutex_Holder lock(mutex);
149 rng->add_entropy_source(es);
152 void add_entropy(
const byte in[],
size_t len)
154 Mutex_Holder lock(mutex);
155 rng->add_entropy(in, len);
159 Serialized_PRNG(RandomNumberGenerator* r, Mutex* m) :
162 ~Serialized_PRNG() {
delete rng; }
165 RandomNumberGenerator* rng;
173 RandomNumberGenerator* rng = 0;
175#if defined(BOTAN_HAS_HMAC_RNG)
177 rng =
new HMAC_RNG(af.make_mac(
"HMAC(SHA-512)"),
178 af.make_mac(
"HMAC(SHA-256)"));
180#elif defined(BOTAN_HAS_RANDPOOL)
182 rng =
new Randpool(af.make_block_cipher(
"AES-256"),
183 af.make_mac(
"HMAC(SHA-256)"));
191#if defined(BOTAN_HAS_X931_RNG)
193 rng =
new ANSI_X931_RNG(af.make_block_cipher(
"AES-256"), rng);
197 add_entropy_sources(rng);
201 return new Serialized_PRNG(rng, mutex);
ANSI_X931_RNG(BlockCipher *cipher, RandomNumberGenerator *rng)
Device_EntropySource(const std::vector< std::string > &fsnames)
EGD_EntropySource(const std::vector< std::string > &)
FTW_EntropySource(const std::string &root_dir)
HMAC_RNG(MessageAuthenticationCode *extractor, MessageAuthenticationCode *prf)
Randpool(BlockCipher *cipher, MessageAuthenticationCode *mac, size_t pool_blocks=32, size_t iterations_before_reseed=128)
Unix_EntropySource(const std::vector< std::string > &path)
std::vector< std::string > split_on(const std::string &str, char delim)
Internal_Error(const std::string &err)