Coverage Report

Created: 2025-07-11 06:15

/src/Botan-3.4.0/build/include/public/botan/auto_rng.h
Line
Count
Source (jump to first uncovered line)
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
namespace Botan {
14
15
class Stateful_RNG;
16
17
/**
18
* A userspace PRNG
19
*/
20
class BOTAN_PUBLIC_API(2, 0) AutoSeeded_RNG final : public RandomNumberGenerator {
21
   public:
22
      bool is_seeded() const override;
23
24
0
      bool accepts_input() const override { return true; }
25
26
      /**
27
      * Mark state as requiring a reseed on next use
28
      */
29
      void force_reseed();
30
31
      size_t reseed(Entropy_Sources& srcs,
32
                    size_t poll_bits = BOTAN_RNG_RESEED_POLL_BITS,
33
                    std::chrono::milliseconds poll_timeout = BOTAN_RNG_RESEED_DEFAULT_TIMEOUT) 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
      */
46
      AutoSeeded_RNG(size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
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
      */
58
      AutoSeeded_RNG(RandomNumberGenerator& underlying_rng, size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
59
60
      /**
61
      * Create an AutoSeeded_RNG which will get seed material from a set of
62
      * entropy sources.
63
      *
64
      * @param entropy_sources will be polled to perform reseeding periodically
65
      * @param reseed_interval specifies a limit of how many times
66
      * the RNG will be called before automatic reseeding is performed
67
      */
68
      AutoSeeded_RNG(Entropy_Sources& entropy_sources, size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
69
70
      /**
71
      * Create an AutoSeeded_RNG which will get seed material from both an
72
      * underlying RNG and a set of entropy sources.
73
      *
74
      * @param underlying_rng is a reference to some RNG which will be used
75
      * to perform the periodic reseeding
76
      * @param entropy_sources will be polled to perform reseeding periodically
77
      * @param reseed_interval specifies a limit of how many times
78
      * the RNG will be called before automatic reseeding is performed
79
      */
80
      AutoSeeded_RNG(RandomNumberGenerator& underlying_rng,
81
                     Entropy_Sources& entropy_sources,
82
                     size_t reseed_interval = BOTAN_RNG_DEFAULT_RESEED_INTERVAL);
83
84
      ~AutoSeeded_RNG() override;
85
86
   private:
87
      void fill_bytes_with_input(std::span<uint8_t> out, std::span<const uint8_t> in) override;
88
89
   private:
90
      std::unique_ptr<Stateful_RNG> m_rng;
91
};
92
93
}  // namespace Botan
94
95
#endif