Botan 3.0.0
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 bool is_seeded() const override;
24
25 bool accepts_input() const override { return true; }
26
27 /**
28 * Mark state as requiring a reseed on next use
29 */
30 void force_reseed();
31
32 size_t reseed(Entropy_Sources& srcs,
33 size_t poll_bits = BOTAN_RNG_RESEED_POLL_BITS,
34 std::chrono::milliseconds poll_timeout = BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) override;
35
36 std::string name() const override;
37
38 void clear() override;
39
40 /**
41 * Uses the system RNG (if available) or else a default group of
42 * entropy sources (all other systems) to gather seed material.
43 *
44 * @param reseed_interval specifies a limit of how many times
45 * the RNG will be called before automatic reseeding is performed
46 */
47 AutoSeeded_RNG(size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
48
49 /**
50 * Create an AutoSeeded_RNG which will get seed material from some other
51 * RNG instance. For example you could provide a reference to the system
52 * RNG or a hardware RNG.
53 *
54 * @param underlying_rng is a reference to some RNG which will be used
55 * to perform the periodic reseeding
56 * @param reseed_interval specifies a limit of how many times
57 * the RNG will be called before automatic reseeding is performed
58 */
60 size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
61
62 /**
63 * Create an AutoSeeded_RNG which will get seed material from a set of
64 * entropy sources.
65 *
66 * @param entropy_sources will be polled to perform reseeding periodically
67 * @param reseed_interval specifies a limit of how many times
68 * the RNG will be called before automatic reseeding is performed
69 */
70 AutoSeeded_RNG(Entropy_Sources& entropy_sources,
71 size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
72
73 /**
74 * Create an AutoSeeded_RNG which will get seed material from both an
75 * underlying RNG and a set of entropy sources.
76 *
77 * @param underlying_rng is a reference to some RNG which will be used
78 * to perform the periodic reseeding
79 * @param entropy_sources will be polled to perform reseeding periodically
80 * @param reseed_interval specifies a limit of how many times
81 * the RNG will be called before automatic reseeding is performed
82 */
84 Entropy_Sources& entropy_sources,
85 size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
86
88
89 private:
90 void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;
91
92 private:
93 std::unique_ptr<Stateful_RNG> m_rng;
94 };
95
96}
97
98#endif
bool accepts_input() const override
Definition: auto_rng.h:25
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:405
#define BOTAN_RNG_RESEED_DEFAULT_TIMEOUT
Definition: build.h:410
#define BOTAN_RNG_RESEED_POLL_BITS
Definition: build.h:408
Definition: alg_id.cpp:12