8 #include <botan/entropy_src.h>
11 #if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
12 #include <botan/internal/rdrand.h>
15 #if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
16 #include <botan/internal/rdseed.h>
19 #if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
20 #include <botan/internal/dev_random.h>
23 #if defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
24 #include <botan/internal/es_capi.h>
27 #if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
28 #include <botan/internal/es_win32.h>
31 #if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER)
32 #include <botan/internal/proc_walk.h>
35 #if defined(BOTAN_HAS_ENTROPY_SRC_DARWIN_SECRANDOM)
36 #include <botan/internal/darwin_secrandom.h>
39 #if defined(BOTAN_HAS_ENTROPY_SRC_GETENTROPY)
40 #include <botan/internal/getentropy.h>
49 #if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
50 return std::unique_ptr<Entropy_Source>(
new Intel_Rdrand);
56 #if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
57 return std::unique_ptr<Entropy_Source>(
new Intel_Rdseed);
61 if(name ==
"darwin_secrandom")
63 #if defined(BOTAN_HAS_ENTROPY_SRC_DARWIN_SECRANDOM)
68 if(name ==
"getentropy")
70 #if defined(BOTAN_HAS_ENTROPY_SRC_GETENTROPY)
71 return std::unique_ptr<Entropy_Source>(
new Getentropy);
75 if(name ==
"dev_random")
77 #if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
82 if(name ==
"win32_cryptoapi")
84 #if defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
89 if(name ==
"proc_walk")
91 #if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER)
92 const std::string root_dir = BOTAN_ENTROPY_PROC_FS_PATH;
98 if(name ==
"system_stats")
100 #if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
105 return std::unique_ptr<Entropy_Source>();
112 m_srcs.push_back(src.release());
118 std::vector<std::string> sources;
119 for(
size_t i = 0; i != m_srcs.size(); ++i)
121 sources.push_back(m_srcs[i]->name());
128 std::chrono::milliseconds timeout)
130 typedef std::chrono::system_clock clock;
132 auto deadline = clock::now() + timeout;
134 size_t bits_collected = 0;
138 bits_collected += src->poll(rng);
140 if (bits_collected >= poll_bits || clock::now() > deadline)
144 return bits_collected;
149 for(
size_t i = 0; i != m_srcs.size(); ++i)
151 if(m_srcs[i]->name() == the_src)
153 return m_srcs[i]->poll(rng);
162 for(
auto&& src_name : sources)
170 for(
size_t i = 0; i != m_srcs.size(); ++i)
180 static Entropy_Sources global_entropy_sources(BOTAN_ENTROPY_DEFAULT_SOURCES);
182 return global_entropy_sources;
std::vector< std::string > enabled_sources() const
size_t poll_just(RandomNumberGenerator &rng, const std::string &src)
void add_source(std::unique_ptr< Entropy_Source > src)
static std::unique_ptr< Entropy_Source > create(const std::string &type)
static Entropy_Sources & global_sources()
size_t poll(RandomNumberGenerator &rng, size_t bits, std::chrono::milliseconds timeout)