Botan  2.9.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")
19  {
20  if(CPUID::has_rdseed())
21  {
22  for(size_t p = 0; p != BOTAN_ENTROPY_INTEL_RNG_POLLS; ++p)
23  {
24  for(size_t i = 0; i != BOTAN_ENTROPY_RDSEED_RETRIES; ++i)
25  {
26  uint32_t r = 0;
27 
28 #if defined(BOTAN_USE_GCC_INLINE_ASM)
29  int cf = 0;
30 
31  // Encoding of rdseed %eax
32  asm(".byte 0x0F, 0xC7, 0xF8; adcl $0,%1" :
33  "=a" (r), "=r" (cf) : "0" (r), "1" (cf) : "cc");
34 #else
35  int cf = _rdseed32_step(&r);
36 #endif
37  if(1 == cf)
38  {
39  rng.add_entropy_T(r);
40  break;
41  }
42  }
43  }
44  }
45 
46  return 0;
47  }
48 
49 }
#define BOTAN_FUNC_ISA(isa)
Definition: compiler.h:71
Definition: alg_id.cpp:13