Botan 3.0.0-alpha0
Crypto and TLS for C&
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
13namespace Botan {
14
15class Stateful_RNG;
16
17/**
18* A userspace PRNG
19*/
21 {
22 public:
23 void randomize(uint8_t out[], size_t len) override;
24
25 void randomize_with_input(uint8_t output[], size_t output_len,
26 const uint8_t input[], size_t input_len) override;
27
28 bool is_seeded() const override;
29
30 bool accepts_input() const override { return true; }
31
32 /**
33 * Mark state as requiring a reseed on next use
34 */
35 void force_reseed();
36
37 size_t reseed(Entropy_Sources& srcs,
38 size_t poll_bits = BOTAN_RNG_RESEED_POLL_BITS,
39 std::chrono::milliseconds poll_timeout = BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) override;
40
41 void add_entropy(const uint8_t in[], size_t len) override;
42
43 std::string name() const override;
44
45 void clear() override;
46
47 /**
48 * Uses the system RNG (if available) or else a default group of
49 * entropy sources (all other systems) to gather seed material.
50 *
51 * @param reseed_interval specifies a limit of how many times
52 * the RNG will be called before automatic reseeding is performed
53 */
54 AutoSeeded_RNG(size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
55
56 /**
57 * Create an AutoSeeded_RNG which will get seed material from some other
58 * RNG instance. For example you could provide a reference to the system
59 * RNG or a hardware RNG.
60 *
61 * @param underlying_rng is a reference to some RNG which will be used
62 * to perform the periodic reseeding
63 * @param reseed_interval specifies a limit of how many times
64 * the RNG will be called before automatic reseeding is performed
65 */
67 size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
68
69 /**
70 * Create an AutoSeeded_RNG which will get seed material from a set of
71 * entropy sources.
72 *
73 * @param entropy_sources will be polled to perform reseeding periodically
74 * @param reseed_interval specifies a limit of how many times
75 * the RNG will be called before automatic reseeding is performed
76 */
77 AutoSeeded_RNG(Entropy_Sources& entropy_sources,
78 size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
79
80 /**
81 * Create an AutoSeeded_RNG which will get seed material from both an
82 * underlying RNG and a set of entropy sources.
83 *
84 * @param underlying_rng is a reference to some RNG which will be used
85 * to perform the periodic reseeding
86 * @param entropy_sources will be polled to perform reseeding periodically
87 * @param reseed_interval specifies a limit of how many times
88 * the RNG will be called before automatic reseeding is performed
89 */
91 Entropy_Sources& entropy_sources,
92 size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
93
95
96 private:
97 std::unique_ptr<Stateful_RNG> m_rng;
98 };
99
100}
101
102#endif
bool accepts_input() const override
Definition: auto_rng.h:30
std::string name
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
#define BOTAN_RNG_DEFAULT_RESEED_INTERVAL
Definition: build.h:409
#define BOTAN_RNG_RESEED_DEFAULT_TIMEOUT
Definition: build.h:415
#define BOTAN_RNG_RESEED_POLL_BITS
Definition: build.h:412
Definition: alg_id.cpp:13