• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 21753596263

06 Feb 2026 02:13PM UTC coverage: 90.063% (-0.01%) from 90.073%
21753596263

Pull #5289

github

web-flow
Merge 587099284 into 8ea0ca252
Pull Request #5289: Further misc header reductions, forward declarations, etc

102237 of 113517 relevant lines covered (90.06%)

11402137.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/src/lib/rng/rng.cpp
1
/*
2
* (C) 2016 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/rng.h>
8

9
#include <botan/exceptn.h>
10
#include <botan/internal/loadstor.h>
11

12
#if defined(BOTAN_HAS_ENTROPY_SOURCE)
13
   #include <botan/entropy_src.h>
14
#endif
15

16
#if defined(BOTAN_HAS_SYSTEM_RNG)
17
   #include <botan/system_rng.h>
18
#endif
19

20
#if defined(BOTAN_HAS_OS_UTILS)
21
   #include <botan/internal/os_utils.h>
22
#endif
23

24
#include <array>
25

26
namespace Botan {
27

28
void RandomNumberGenerator::randomize_with_ts_input(std::span<uint8_t> output) {
4,643✔
29
   if(this->accepts_input()) {
4,643✔
30
      std::array<uint8_t, 32> additional_input = {0};
4,643✔
31

32
#if defined(BOTAN_HAS_OS_UTILS)
33
      store_le(std::span{additional_input}.subspan<0, 8>(), OS::get_high_resolution_clock());
4,643✔
34
      store_le(std::span{additional_input}.subspan<8, 4>(), OS::get_process_id());
4,643✔
35
      constexpr size_t offset = 12;
4,643✔
36
#else
37
      constexpr size_t offset = 0;
38
#endif
39

40
#if defined(BOTAN_HAS_SYSTEM_RNG)
41
      system_rng().randomize(std::span{additional_input}.subspan<offset>());
4,643✔
42
#else
43
      BOTAN_UNUSED(offset);
44
#endif
45

46
      this->fill_bytes_with_input(output, additional_input);
4,643✔
47
   } else {
48
      this->fill_bytes_with_input(output, {});
×
49
   }
50
}
13,929✔
51

52
size_t RandomNumberGenerator::reseed_from_sources(Entropy_Sources& srcs, size_t poll_bits) {
12✔
53
   if(this->accepts_input()) {
12✔
54
#if defined(BOTAN_HAS_ENTROPY_SOURCE)
55
      return srcs.poll(*this, poll_bits);
10✔
56
#else
57
      BOTAN_UNUSED(srcs, poll_bits);
58
#endif
59
   }
60

61
   return 0;
62
}
63

64
void RandomNumberGenerator::reseed_from_rng(RandomNumberGenerator& rng, size_t poll_bits) {
195✔
65
   if(this->accepts_input()) {
195✔
66
      this->add_entropy(rng.random_vec(poll_bits / 8));
377✔
67
   }
68
}
186✔
69

70
void Null_RNG::fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> /* ignored */) {
10✔
71
   // throw if caller tries to obtain random bytes
72
   if(!output.empty()) {
10✔
73
      throw PRNG_Unseeded("Null_RNG called");
10✔
74
   }
75
}
×
76

77
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc