Botan  2.4.0
Crypto and TLS for C++11
rdseed.cpp
Go to the documentation of this file.
1 /*
2 * Entropy Source Using Intel's rdseed instruction
3 * (C) 2015 Jack Lloyd, Daniel Neus
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/internal/rdseed.h>
9 #include <botan/cpuid.h>
10 
11 #if !defined(BOTAN_USE_GCC_INLINE_ASM)
12  #include <immintrin.h>
13 #endif
14 
15 namespace Botan {
16 
17 BOTAN_FUNC_ISA("rdseed")
18 size_t Intel_Rdseed::poll(RandomNumberGenerator& rng) {
19  if(CPUID::has_rdseed())
20  {
21  for(size_t p = 0; p != BOTAN_ENTROPY_INTEL_RNG_POLLS; ++p)
22  {
23  for(size_t i = 0; i != BOTAN_ENTROPY_RDSEED_RETRIES; ++i)
24  {
25  uint32_t r = 0;
26 
27 #if defined(BOTAN_USE_GCC_INLINE_ASM)
28  int cf = 0;
29 
30  // Encoding of rdseed %eax
31  asm(".byte 0x0F, 0xC7, 0xF8; adcl $0,%1" :
32  "=a" (r), "=r" (cf) : "0" (r), "1" (cf) : "cc");
33 #else
34  int cf = _rdseed32_step(&r);
35 #endif
36  if(1 == cf)
37  {
38  rng.add_entropy_T(r);
39  break;
40  }
41  }
42  }
43  }
44 
45  return 0;
46  }
47 
48 }
#define BOTAN_FUNC_ISA(isa)
Definition: compiler.h:75
Definition: alg_id.cpp:13