Botan  2.1.0
Crypto and TLS for C++11
rdrand.cpp
Go to the documentation of this file.
1 /*
2 * Entropy Source Using Intel's rdrand instruction
3 * (C) 2012,2015 Jack Lloyd
4 * (C) 2015 Daniel Neus
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #include <botan/internal/rdrand.h>
10 #include <botan/rdrand_rng.h>
11 #include <botan/cpuid.h>
12 #include <botan/build.h>
13 
14 namespace Botan {
15 
17  if(CPUID::has_rdrand() && BOTAN_ENTROPY_INTEL_RNG_POLLS > 0)
18  {
19  RDRAND_RNG rdrand_rng;
20  secure_vector<uint8_t> buf(4 * BOTAN_ENTROPY_INTEL_RNG_POLLS);
21 
22  rdrand_rng.randomize(buf.data(), buf.size());
23  rng.add_entropy(buf.data(), buf.size());
24  }
25 
26  // RDRAND is used but not trusted
27  return 0;
28  }
29 
30 }
virtual void add_entropy(const uint8_t input[], size_t length)=0
void randomize(uint8_t out[], size_t out_len) override
Definition: rdrand_rng.cpp:66
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Definition: alg_id.cpp:13
size_t poll(RandomNumberGenerator &rng) override
Definition: rdrand.cpp:16