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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

95.45
/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/entropy_src.h>
10
#include <botan/internal/loadstor.h>
11
#include <botan/internal/os_utils.h>
12

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

17
#include <array>
18

19
namespace Botan {
20

21
void RandomNumberGenerator::randomize_with_ts_input(std::span<uint8_t> output) {
4,498✔
22
   if(this->accepts_input()) {
4,498✔
23
      constexpr auto s_hd_clk = sizeof(decltype(OS::get_high_resolution_clock()));
4,498✔
24
      constexpr auto s_sys_ts = sizeof(decltype(OS::get_system_timestamp_ns()));
4,498✔
25
      constexpr auto s_pid = sizeof(decltype(OS::get_process_id()));
4,498✔
26

27
      std::array<uint8_t, s_hd_clk + s_sys_ts + s_pid> additional_input = {0};
4,498✔
28
      auto s_additional_input = std::span(additional_input.begin(), additional_input.end());
4,498✔
29

30
      store_le(OS::get_high_resolution_clock(), s_additional_input.data());
4,498✔
31
      s_additional_input = s_additional_input.subspan(s_hd_clk);
4,498✔
32

33
#if defined(BOTAN_HAS_SYSTEM_RNG)
34
      System_RNG system_rng;
4,498✔
35
      system_rng.randomize(s_additional_input);
4,498✔
36
#else
37
      store_le(OS::get_system_timestamp_ns(), s_additional_input.data());
38
      s_additional_input = s_additional_input.subspan(s_sys_ts);
39

40
      store_le(OS::get_process_id(), s_additional_input.data());
41
#endif
42

43
      this->fill_bytes_with_input(output, additional_input);
4,498✔
44
   } else {
4,498✔
45
      this->fill_bytes_with_input(output, {});
×
46
   }
47
}
4,498✔
48

49
size_t RandomNumberGenerator::reseed(Entropy_Sources& srcs, size_t poll_bits, std::chrono::milliseconds poll_timeout) {
10✔
50
   if(this->accepts_input()) {
10✔
51
      return srcs.poll(*this, poll_bits, poll_timeout);
9✔
52
   } else {
53
      return 0;
54
   }
55
}
56

57
void RandomNumberGenerator::reseed_from_rng(RandomNumberGenerator& rng, size_t poll_bits) {
166✔
58
   if(this->accepts_input()) {
166✔
59
      this->add_entropy(rng.random_vec(poll_bits / 8));
319✔
60
   }
61
}
157✔
62

63
}
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