Botan  2.19.1
Crypto and TLS for C++11
rdrand_rng.cpp
Go to the documentation of this file.
1 /*
2 * RDRAND RNG
3 * (C) 2016,2019 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/rdrand_rng.h>
9 #include <botan/processor_rng.h>
10 #include <botan/loadstor.h>
11 
12 namespace Botan {
13 
14 void RDRAND_RNG::randomize(uint8_t out[], size_t out_len)
15  {
16  Processor_RNG rng;
17  rng.randomize(out, out_len);
18  }
19 
21  {
22  // Will throw if instruction is not available
23  Processor_RNG rng;
24  }
25 
26 //static
28  {
29  return Processor_RNG::available();
30  }
31 
32 //static
34  {
35  Processor_RNG rng;
36 
37  for(;;)
38  {
39  try
40  {
41  uint8_t out[4];
42  rng.randomize(out, 4);
43  return load_le<uint32_t>(out, 0);
44  }
45  catch(PRNG_Unseeded&) {}
46  }
47  }
48 
49 //static
50 uint32_t RDRAND_RNG::rdrand_status(bool& ok)
51  {
52  ok = false;
53  Processor_RNG rng;
54 
55  try
56  {
57  uint8_t out[4];
58  rng.randomize(out, 4);
59  ok = true;
60  return load_le<uint32_t>(out, 0);
61  }
62  catch(PRNG_Unseeded&) {}
63 
64  return 0;
65  }
66 
67 }
static bool available()
Definition: rdrand_rng.cpp:27
void randomize(uint8_t out[], size_t out_len) override
Definition: rdrand_rng.cpp:14
uint32_t load_le< uint32_t >(const uint8_t in[], size_t off)
Definition: loadstor.h:198
static uint32_t rdrand_status(bool &ok)
Definition: rdrand_rng.cpp:50
Definition: alg_id.cpp:13
static uint32_t rdrand()
Definition: rdrand_rng.cpp:33
static bool available()
void randomize(uint8_t out[], size_t out_len) override