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

randombit / botan / 12732895979

12 Jan 2025 11:00AM UTC coverage: 91.237% (-0.003%) from 91.24%
12732895979

push

github

web-flow
Merge pull request #4525 from randombit/jack/entropy-is-optional

Let the entropy module be optional

93458 of 102434 relevant lines covered (91.24%)

11406941.45 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/internal/loadstor.h>
10

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

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

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

23
#include <array>
24

25
namespace Botan {
26

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

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

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

45
      this->fill_bytes_with_input(output, additional_input);
4,647✔
46
   } else {
47
      this->fill_bytes_with_input(output, {});
×
48
   }
49
}
13,941✔
50

51
size_t RandomNumberGenerator::reseed(Entropy_Sources& srcs, size_t poll_bits, std::chrono::milliseconds poll_timeout) {
11✔
52
   if(this->accepts_input()) {
11✔
53
#if defined(BOTAN_HAS_ENTROPY_SOURCE)
54
      return srcs.poll(*this, poll_bits, poll_timeout);
10✔
55
#else
56
      BOTAN_UNUSED(srcs, poll_bits, poll_timeout);
57
#endif
58
   }
59

60
   return 0;
61
}
62

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

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

76
}  // 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