Botan 3.11.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#include <memory>
13
14namespace Botan {
15
16class Stateful_RNG;
17
18/**
19* A userspace PRNG
20*/
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_from_sources(Entropy_Sources& srcs,
33 size_t poll_bits = RandomNumberGenerator::DefaultPollBits) override;
34
35 std::string name() const override;
36
37 void clear() override;
38
39 /**
40 * Uses the system RNG (if available) or else a default group of
41 * entropy sources (all other systems) to gather seed material.
42 *
43 * @param reseed_interval specifies a limit of how many times
44 * the RNG will be called before automatic reseeding is performed
45 */
47
48 /**
49 * Create an AutoSeeded_RNG which will get seed material from some other
50 * RNG instance. For example you could provide a reference to the system
51 * RNG or a hardware RNG.
52 *
53 * @param underlying_rng is a reference to some RNG which will be used
54 * to perform the periodic reseeding
55 * @param reseed_interval specifies a limit of how many times
56 * the RNG will be called before automatic reseeding is performed
57 */
59 size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
60
61 /**
62 * Create an AutoSeeded_RNG which will get seed material from a set of
63 * entropy sources.
64 *
65 * @param entropy_sources will be polled to perform reseeding periodically
66 * @param reseed_interval specifies a limit of how many times
67 * the RNG will be called before automatic reseeding is performed
68 */
70 size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
71
72 /**
73 * Create an AutoSeeded_RNG which will get seed material from both an
74 * underlying RNG and a set of entropy sources.
75 *
76 * @param underlying_rng is a reference to some RNG which will be used
77 * to perform the periodic reseeding
78 * @param entropy_sources will be polled to perform reseeding periodically
79 * @param reseed_interval specifies a limit of how many times
80 * the RNG will be called before automatic reseeding is performed
81 */
83 Entropy_Sources& entropy_sources,
84 size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
85
86 AutoSeeded_RNG(const AutoSeeded_RNG& other) = delete;
87 AutoSeeded_RNG(AutoSeeded_RNG&& other) noexcept;
88 AutoSeeded_RNG& operator=(const AutoSeeded_RNG& other) = delete;
90
91 ~AutoSeeded_RNG() override;
92
93 private:
94 void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;
95
96 private:
97 std::unique_ptr<Stateful_RNG> m_rng;
98};
99
100} // namespace Botan
101
102#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
AutoSeeded_RNG(const AutoSeeded_RNG &other)=delete
AutoSeeded_RNG & operator=(AutoSeeded_RNG &&other)=delete
~AutoSeeded_RNG() override
BOTAN_FUTURE_EXPLICIT AutoSeeded_RNG(size_t reseed_interval=RandomNumberGenerator::DefaultReseedInterval)
Definition auto_rng.cpp:68
AutoSeeded_RNG & operator=(const AutoSeeded_RNG &other)=delete
AutoSeeded_RNG(AutoSeeded_RNG &&other) noexcept
bool accepts_input() const override
Definition auto_rng.h:25
bool is_seeded() const override
Definition auto_rng.cpp:90
static constexpr size_t DefaultPollBits
Definition rng.h:50
static constexpr size_t DefaultReseedInterval
Definition rng.h:45