Botan: Botan::Intel_Rdrand Class Reference

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::Intel_Rdrand Class Reference

`#include <rdrand.h>`

Inheritance diagram for Botan::Intel_Rdrand:

## Public Member Functions
std::string | name () const
void | poll (Entropy_Accumulator &accum)

## Detailed Description

Entropy source using the rdrand instruction first introduced on Intel's Ivy Bridge architecture.

Definition at line 19 of file rdrand.h.

## Member Function Documentation

std::string Botan::Intel_Rdrand::name | ( |  | ) | const
| inlinevirtual

Returns
  name identifying this entropy source

Implements Botan::EntropySource.

Definition at line 22 of file rdrand.h.

References poll().

22 { return "Intel Rdrand"; }

void Botan::Intel_Rdrand::poll | ( | Entropy_Accumulator & | accum | ) |
| virtual

Perform an entropy gathering poll

Parameters

  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().

Referenced by name().

21 {
22 if(!CPUID::has_rdrand())
23 return;
24
25 /*
26 * Put an upper bound on the total entropy we're willing to claim
27 * for any one polling of rdrand to prevent it from swamping our
28 * poll. Internally, the rdrand system is a DRGB that reseeds at a
29 * somewhat unpredictable rate (the current conditions are
30 * documented, but that might not be true for different
31 * implementations, eg on Haswell or a future AMD chip, so I don't
32 * want to assume). This limit ensures we're going to poll at least
33 * one other source so we have some diversity in our inputs.
34 */
35
36 const size_t POLL_UPPER_BOUND = 96;
37 const size_t RDRAND_POLLS = 32;
38 const double ENTROPY_PER_POLL =
39 static_cast<double>(POLL_UPPER_BOUND) / (RDRAND_POLLS * 4);
40
41 for(size_t i = 0; i != RDRAND_POLLS; ++i)
42 {
43 unsigned int r = 0;
44
45 #if BOTAN_USE_GCC_INLINE_ASM
46 int cf = 0;
47
48 // Encoding of rdrand %eax
49 asm(".byte 0x0F, 0xC7, 0xF0; adcl $0,%1" :
50 "=a" (r), "=r" (cf) : "0" (r), "1" (cf) : "cc");
51 #else
52 int cf = _rdrand32_step(&r);
53 #endif
54
55 if(cf == 1)
56 accum.add(r, ENTROPY_PER_POLL);
57 }
58 }
Botan::CPUID::has_rdrand
static bool has_rdrand()
Definition: cpuid.h:88

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

- src/entropy/rdrand/rdrand.h
- src/entropy/rdrand/rdrand.cpp