• 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.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
#endif
13

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

18
namespace Botan_Tests {
19

20
namespace {
21

22
#if defined(BOTAN_HAS_HMAC_DRBG)
23

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

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

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

38
         Test::Result result("HMAC_DRBG(" + algo + ")");
1,680✔
39

40
         auto mac = Botan::MessageAuthenticationCode::create("HMAC(" + algo + ")");
3,360✔
41

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

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

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

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

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

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

65
#endif
66

67
#if defined(BOTAN_HAS_CHACHA_RNG)
68

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

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

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

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

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

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

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

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

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

103
#endif
104

105
}
106

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