Botan 3.8.1
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
13#include <memory>
14
15namespace Botan {
16
17class Stateful_RNG;
18
19/**
20* A userspace PRNG
21*/
23 public:
24 bool is_seeded() const override;
25
26 bool accepts_input() const override { return true; }
27
28 /**
29 * Mark state as requiring a reseed on next use
30 */
31 void force_reseed();
32
33 size_t reseed(Entropy_Sources& srcs,
35 std::chrono::milliseconds poll_timeout = RandomNumberGenerator::DefaultPollTimeout) override;
36
37 std::string name() const override;
38
39 void clear() override;
40
41 /**
42 * Uses the system RNG (if available) or else a default group of
43 * entropy sources (all other systems) to gather seed material.
44 *
45 * @param reseed_interval specifies a limit of how many times
46 * the RNG will be called before automatic reseeding is performed
47 */
49
50 /**
51 * Create an AutoSeeded_RNG which will get seed material from some other
52 * RNG instance. For example you could provide a reference to the system
53 * RNG or a hardware RNG.
54 *
55 * @param underlying_rng is a reference to some RNG which will be used
56 * to perform the periodic reseeding
57 * @param reseed_interval specifies a limit of how many times
58 * the RNG will be called before automatic reseeding is performed
59 */
61 size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
62
63 /**
64 * Create an AutoSeeded_RNG which will get seed material from a set of
65 * entropy sources.
66 *
67 * @param entropy_sources will be polled to perform reseeding periodically
68 * @param reseed_interval specifies a limit of how many times
69 * the RNG will be called before automatic reseeding is performed
70 */
71 AutoSeeded_RNG(Entropy_Sources& entropy_sources,
72 size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
73
74 /**
75 * Create an AutoSeeded_RNG which will get seed material from both an
76 * underlying RNG and a set of entropy sources.
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 */
85 Entropy_Sources& entropy_sources,
86 size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
87
88 ~AutoSeeded_RNG() override;
89
90 private:
91 void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;
92
93 private:
94 std::unique_ptr<Stateful_RNG> m_rng;
95};
96
97} // namespace Botan
98
99#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
~AutoSeeded_RNG() override
AutoSeeded_RNG(size_t reseed_interval=RandomNumberGenerator::DefaultReseedInterval)
Definition auto_rng.cpp:64
bool accepts_input() const override
Definition auto_rng.h:26
bool is_seeded() const override
Definition auto_rng.cpp:86
static constexpr size_t DefaultPollBits
Definition rng.h:41
static constexpr size_t DefaultReseedInterval
Definition rng.h:36
static constexpr auto DefaultPollTimeout
Definition rng.h:46