Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 #include <botan/build.h>
11
12 #if !defined(BOTAN_USE_GCC_INLINE_ASM)
13 #include <immintrin.h>
14 #endif
15
16 namespace Botan {
17
18 BOTAN_FUNC_ISA("rdseed")
19 size_t Intel_Rdseed::poll(RandomNumberGenerator& rng) {
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 }
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::Intel_Rdseed
Definition: rdseed.h:19
BOTAN_FUNC_ISA
#define BOTAN_FUNC_ISA(isa)
Definition: compiler.h:48
Botan
Definition: alg_id.cpp:13