Coverage Report

Created: 2026-12-01 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Botan-3.13.0/build/include/public/botan/auto_rng.h
Line
Count
Source
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
14
namespace Botan {
15
16
class Stateful_RNG;
17
18
/**
19
* A userspace PRNG
20
*/
21
class BOTAN_PUBLIC_API(2, 0) AutoSeeded_RNG final : public RandomNumberGenerator {
22
   public:
23
      /**
24
      * Test whether this RNG has been seeded
25
      * @return true if this RNG is seeded and ready for use
26
      */
27
      bool is_seeded() const override;
28
29
      /**
30
      * Test whether this RNG accepts externally provided input
31
      * @return false if this RNG is known to ignore provided inputs
32
      */
33
0
      bool accepts_input() const override { return true; }
34
35
      /**
36
      * Mark state as requiring a reseed on next use
37
      */
38
      void force_reseed();
39
40
      /**
41
      * Poll the provided sources for entropy and reseed from them
42
      * @param srcs the entropy sources to poll
43
      * @param poll_bits the number of bits to collect
44
      * @return estimate of the number of bits collected
45
      */
46
      size_t reseed_from_sources(Entropy_Sources& srcs,
47
                                 size_t poll_bits = RandomNumberGenerator::DefaultPollBits) override;
48
49
      /**
50
      * Return the name of this RNG type
51
      * @return the name of this RNG type
52
      */
53
      std::string name() const override;
54
55
      /**
56
      * Clear all internally held values of this RNG
57
      */
58
      void clear() override;
59
60
      /**
61
      * Uses the system RNG (if available) or else a default group of
62
      * entropy sources (all other systems) to gather seed material.
63
      *
64
      * @param reseed_interval specifies a limit of how many times
65
      * the RNG will be called before automatic reseeding is performed
66
      */
67
      BOTAN_FUTURE_EXPLICIT AutoSeeded_RNG(size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
68
69
      /**
70
      * Create an AutoSeeded_RNG which will get seed material from some other
71
      * RNG instance. For example you could provide a reference to the system
72
      * RNG or a hardware RNG.
73
      *
74
      * @param underlying_rng is a reference to some RNG which will be used
75
      * to perform the periodic reseeding
76
      * @param reseed_interval specifies a limit of how many times
77
      * the RNG will be called before automatic reseeding is performed
78
      */
79
      BOTAN_FUTURE_EXPLICIT AutoSeeded_RNG(RandomNumberGenerator& underlying_rng,
80
                                           size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
81
82
      /**
83
      * Create an AutoSeeded_RNG which will get seed material from a set of
84
      * entropy sources.
85
      *
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
      */
90
      BOTAN_FUTURE_EXPLICIT AutoSeeded_RNG(Entropy_Sources& entropy_sources,
91
                                           size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
92
93
      /**
94
      * Create an AutoSeeded_RNG which will get seed material from both an
95
      * underlying RNG and a set of entropy sources.
96
      *
97
      * @param underlying_rng is a reference to some RNG which will be used
98
      * to perform the periodic reseeding
99
      * @param entropy_sources will be polled to perform reseeding periodically
100
      * @param reseed_interval specifies a limit of how many times
101
      * the RNG will be called before automatic reseeding is performed
102
      */
103
      AutoSeeded_RNG(RandomNumberGenerator& underlying_rng,
104
                     Entropy_Sources& entropy_sources,
105
                     size_t reseed_interval = RandomNumberGenerator::DefaultReseedInterval);
106
107
      AutoSeeded_RNG(const AutoSeeded_RNG& other) = delete;
108
      /**
109
      * Move constructor
110
      */
111
      AutoSeeded_RNG(AutoSeeded_RNG&& other) noexcept;
112
      AutoSeeded_RNG& operator=(const AutoSeeded_RNG& other) = delete;
113
      AutoSeeded_RNG& operator=(AutoSeeded_RNG&& other) = delete;
114
115
      ~AutoSeeded_RNG() override;
116
117
   private:
118
      void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;
119
120
   private:
121
      std::unique_ptr<Stateful_RNG> m_rng;
122
};
123
124
}  // namespace Botan
125
126
#endif