Botan  2.11.0
Crypto and TLS for C++11
rdrand_rng.h
Go to the documentation of this file.
1 /*
2 * RDRAND RNG
3 * (C) 2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_RNG_RDRAND_H_
9 #define BOTAN_RNG_RDRAND_H_
10 
11 #include <botan/rng.h>
12 
13 namespace Botan {
14 
15 class BOTAN_PUBLIC_API(2,0) RDRAND_RNG final : public Hardware_RNG
16  {
17  public:
18  /**
19  * On correctly working hardware, RDRAND is always supposed to
20  * succeed within a set number of retries. If after that many
21  * retries RDRAND has still not suceeded, sets ok = false and
22  * returns 0.
23  */
24  static uint32_t rdrand_status(bool& ok);
25 
26  /*
27  * Calls RDRAND until it succeeds, this could hypothetically
28  * loop forever on broken hardware.
29  */
30  static uint32_t rdrand();
31 
32  /**
33  * Return true if RDRAND is available on the current processor
34  */
35  static bool available();
36 
37  bool accepts_input() const override { return false; }
38 
39  /**
40  * Constructor will throw if CPU does not have RDRAND bit set
41  */
42  RDRAND_RNG();
43 
44  /**
45  * Uses RDRAND to produce output
46  */
47  void randomize(uint8_t out[], size_t out_len) override;
48 
49  /*
50  * No way to provide entropy to RDRAND generator, so add_entropy is ignored
51  */
52  void add_entropy(const uint8_t[], size_t) override
53  { /* no op */ }
54 
55  /*
56  * No way to reseed RDRAND generator, so reseed is ignored
57  */
58  size_t reseed(Entropy_Sources&, size_t, std::chrono::milliseconds) override
59  { return 0; /* no op */ }
60 
61  std::string name() const override { return "RDRAND"; }
62 
63  bool is_seeded() const override { return true; }
64  };
65 
66 }
67 
68 #endif
uint8_t size_t out_len
Definition: pbkdf2.h:19
int(* final)(unsigned char *, CTX *)
char * name
Definition: ffi.h:330
Definition: alg_id.cpp:13
uint8_t out[]
Definition: pbkdf2.h:19
class BOTAN_PUBLIC_API(2, 0) AlgorithmIdentifier final bool BOTAN_PUBLIC_API(2, 0) operator
Name Constraints.
Definition: asn1_obj.h:66