• 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

95.24
/src/tests/test_rng_kat.cpp
1
/*
2
* (C) 2014,2015,2017 Jack Lloyd
3
* (C) 2016 René Korthaus, Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_HMAC_DRBG)
11
   #include <botan/hmac_drbg.h>
12
   #include <botan/mac.h>
13
#endif
14

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

19
namespace Botan_Tests {
20

21
namespace {
22

23
#if defined(BOTAN_HAS_HMAC_DRBG)
24

25
class HMAC_DRBG_Tests final : public Text_Based_Test {
×
26
   public:
27
      HMAC_DRBG_Tests() :
1✔
28
            Text_Based_Test(
29
               "rng/hmac_drbg.vec", "EntropyInput,EntropyInputReseed,Out", "AdditionalInput1,AdditionalInput2") {}
2✔
30

31
      Test::Result run_one_test(const std::string& algo, const VarMap& vars) override {
1,680✔
32
         const std::vector<uint8_t> seed_input = vars.get_req_bin("EntropyInput");
1,680✔
33
         const std::vector<uint8_t> reseed_input = vars.get_req_bin("EntropyInputReseed");
1,680✔
34
         const std::vector<uint8_t> expected = vars.get_req_bin("Out");
1,680✔
35

36
         const std::vector<uint8_t> ad1 = vars.get_opt_bin("AdditionalInput1");
1,680✔
37
         const std::vector<uint8_t> ad2 = vars.get_opt_bin("AdditionalInput2");
1,680✔
38

39
         Test::Result result("HMAC_DRBG(" + algo + ")");
5,040✔
40

41
         auto mac = Botan::MessageAuthenticationCode::create("HMAC(" + algo + ")");
5,040✔
42

43
         if(!mac) {
1,680✔
44
            result.note_missing("HMAC(" + algo + ")");
720✔
45
            return result;
240✔
46
         }
47

48
         auto rng = std::make_unique<Botan::HMAC_DRBG>(std::move(mac));
1,440✔
49
         rng->initialize_with(seed_input.data(), seed_input.size());
1,440✔
50

51
         // now reseed
52
         rng->add_entropy(reseed_input.data(), reseed_input.size());
1,440✔
53

54
         std::vector<uint8_t> out(expected.size());
1,440✔
55
         // first block is discarded
56
         rng->randomize_with_input(out.data(), out.size(), ad1.data(), ad1.size());
1,440✔
57
         rng->randomize_with_input(out.data(), out.size(), ad2.data(), ad2.size());
1,440✔
58

59
         result.test_eq("rng", out, expected);
2,880✔
60
         return result;
1,440✔
61
      }
9,840✔
62
};
63

64
BOTAN_REGISTER_SMOKE_TEST("rng", "hmac_drbg", HMAC_DRBG_Tests);
65

66
#endif
67

68
#if defined(BOTAN_HAS_CHACHA_RNG)
69

70
class ChaCha_RNG_Tests final : public Text_Based_Test {
×
71
   public:
72
      ChaCha_RNG_Tests() :
1✔
73
            Text_Based_Test(
74
               "rng/chacha_rng.vec", "EntropyInput,EntropyInputReseed,Out", "AdditionalInput1,AdditionalInput2") {}
2✔
75

76
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
21✔
77
         const std::vector<uint8_t> seed_input = vars.get_req_bin("EntropyInput");
21✔
78
         const std::vector<uint8_t> reseed_input = vars.get_req_bin("EntropyInputReseed");
21✔
79
         const std::vector<uint8_t> expected = vars.get_req_bin("Out");
21✔
80

81
         const std::vector<uint8_t> ad1 = vars.get_opt_bin("AdditionalInput1");
21✔
82
         const std::vector<uint8_t> ad2 = vars.get_opt_bin("AdditionalInput2");
21✔
83

84
         Test::Result result("ChaCha_RNG");
21✔
85

86
         Botan::ChaCha_RNG rng;
21✔
87
         rng.initialize_with(seed_input.data(), seed_input.size());
21✔
88

89
         // now reseed
90
         rng.add_entropy(reseed_input.data(), reseed_input.size());
21✔
91

92
         std::vector<uint8_t> out(expected.size());
21✔
93
         // first block is discarded
94
         rng.randomize_with_input(out.data(), out.size(), ad1.data(), ad1.size());
21✔
95
         rng.randomize_with_input(out.data(), out.size(), ad2.data(), ad2.size());
21✔
96

97
         result.test_eq("rng", out, expected);
42✔
98
         return result;
21✔
99
      }
124✔
100
};
101

102
BOTAN_REGISTER_TEST("rng", "chacha_rng", ChaCha_RNG_Tests);
103

104
#endif
105

106
}  // namespace
107

108
}  // namespace Botan_Tests
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