|
Botan
1.11.15
|
#include <rdrand.h>
Public Member Functions | |
| std::string | name () const |
| void | poll (Entropy_Accumulator &accum) |
Static Public Member Functions | |
| static void | poll_available_sources (class Entropy_Accumulator &accum) |
Entropy source using the rdrand instruction first introduced on Intel's Ivy Bridge architecture.
| std::string Botan::Intel_Rdrand::name | ( | ) | const [inline, virtual] |
Implements Botan::EntropySource.
Definition at line 22 of file rdrand.h.
{ return "Intel Rdrand"; }
| void Botan::Intel_Rdrand::poll | ( | Entropy_Accumulator & | accum | ) | [virtual] |
Perform an entropy gathering poll
| accum | is an accumulator object that will be given entropy |
Implements Botan::EntropySource.
Definition at line 20 of file rdrand.cpp.
References Botan::Entropy_Accumulator::add(), and Botan::CPUID::has_rdrand().
{
if(!CPUID::has_rdrand())
return;
/*
* Put an upper bound on the total entropy we're willing to claim
* for any one polling of rdrand to prevent it from swamping our
* poll. Internally, the rdrand system is a DRGB that reseeds at a
* somewhat unpredictable rate (the current conditions are
* documented, but that might not be true for different
* implementations, eg on Haswell or a future AMD chip, so I don't
* want to assume). This limit ensures we're going to poll at least
* one other source so we have some diversity in our inputs.
*/
const size_t POLL_UPPER_BOUND = 96;
const size_t RDRAND_POLLS = 32;
const double ENTROPY_PER_POLL =
static_cast<double>(POLL_UPPER_BOUND) / (RDRAND_POLLS * 4);
for(size_t i = 0; i != RDRAND_POLLS; ++i)
{
unsigned int r = 0;
#if BOTAN_USE_GCC_INLINE_ASM
int cf = 0;
// Encoding of rdrand %eax
asm(".byte 0x0F, 0xC7, 0xF0; adcl $0,%1" :
"=a" (r), "=r" (cf) : "0" (r), "1" (cf) : "cc");
#else
int cf = _rdrand32_step(&r);
#endif
if(cf == 1)
accum.add(r, ENTROPY_PER_POLL);
}
}
| void Botan::EntropySource::poll_available_sources | ( | class Entropy_Accumulator & | accum | ) | [static, inherited] |
Definition at line 108 of file entropy_srcs.cpp.
References Botan::Entropy_Accumulator::polling_goal_achieved().
Referenced by Botan::HMAC_RNG::reseed().
{
static std::vector<std::unique_ptr<EntropySource>> g_sources(get_default_entropy_sources());
if(g_sources.empty())
throw std::runtime_error("No entropy sources enabled at build time, poll failed");
size_t poll_attempt = 0;
while(!accum.polling_goal_achieved() && poll_attempt < 16)
{
const size_t src_idx = poll_attempt % g_sources.size();
g_sources[src_idx]->poll(accum);
++poll_attempt;
}
}
1.7.6.1