Botan  1.11.34
Crypto and TLS for C++11
auto_rng.h
Go to the documentation of this file.
1 /*
2 * Auto Seeded RNG
3 * (C) 2008,2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_AUTO_SEEDING_RNG_H__
9 #define BOTAN_AUTO_SEEDING_RNG_H__
10 
11 #include <botan/rng.h>
12 
13 namespace Botan {
14 
15 class Stateful_RNG;
16 
17 /**
18 * A userspace PRNG
19 */
20 class BOTAN_DLL AutoSeeded_RNG final : public RandomNumberGenerator
21  {
22  public:
23  void randomize(byte out[], size_t len) override;
24 
25  void randomize_with_input(byte output[], size_t output_len,
26  const byte input[], size_t input_len) override;
27 
28  bool is_seeded() const override;
29 
30  /**
31  * Mark state as requiring a reseed on next use
32  */
33  void force_reseed();
34 
35  size_t reseed(Entropy_Sources& srcs,
36  size_t poll_bits = BOTAN_RNG_RESEED_POLL_BITS,
37  std::chrono::milliseconds poll_timeout = BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) override;
38 
39  void add_entropy(const byte in[], size_t len) override;
40 
41  std::string name() const override;
42 
43  void clear() override;
44 
45  /**
46  * Uses the system RNG (if available) or else a default group of
47  * entropy sources (all other systems) to gather seed material.
48  *
49  * @param reseed_interval specifies a limit of how many times
50  * the RNG will be called before automatic reseeding is performed
51  */
52  AutoSeeded_RNG(size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
53 
54  /**
55  * Uses the BOTAN_AUTO_RNG_DRBG RNG to gather seed material.
56  *
57  * @param underlying_rng is a reference to some RNG which will be used
58  * to perform the periodic reseeding
59  * @param reseed_interval specifies a limit of how many times
60  * the RNG will be called before automatic reseeding is performed
61  */
62  AutoSeeded_RNG(RandomNumberGenerator& underlying_rng,
63  size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
64 
65  /**
66  * Uses the BOTAN_AUTO_RNG_DRBG RNG to gather seed material.
67  *
68  * @param entropy_sources will be polled to perform reseeding periodically
69  * @param reseed_interval specifies a limit of how many times
70  * the RNG will be called before automatic reseeding is performed
71  */
72  AutoSeeded_RNG(Entropy_Sources& entropy_sources,
73  size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
74 
75  /**
76  * Uses the BOTAN_AUTO_RNG_DRBG RNG to gather seed material.
77  *
78  * @param underlying_rng is a reference to some RNG which will be used
79  * to perform the periodic reseeding
80  * @param entropy_sources will be polled to perform reseeding periodically
81  * @param reseed_interval specifies a limit of how many times
82  * the RNG will be called before automatic reseeding is performed
83  */
84  AutoSeeded_RNG(RandomNumberGenerator& underlying_rng,
85  Entropy_Sources& entropy_sources,
86  size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
87 
88  ~AutoSeeded_RNG();
89 
90  private:
91  std::unique_ptr<Stateful_RNG> m_rng;
92  };
93 
94 }
95 
96 #endif
Definition: alg_id.cpp:13
std::uint8_t byte
Definition: types.h:31