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

randombit / botan / 21768358452

06 Feb 2026 10:35PM UTC coverage: 90.064% (-0.003%) from 90.067%
21768358452

Pull #5289

github

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

102238 of 113517 relevant lines covered (90.06%)

11357432.36 hits per line

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

92.16
/src/tests/test_rngs.cpp
1
/*
2
* (C) 2023 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "test_rng.h"
8

9
#if defined(BOTAN_HAS_AES)
10
   #include <botan/block_cipher.h>
11
   #include <botan/internal/loadstor.h>
12
#endif
13

14
#include <array>
15

16
namespace Botan_Tests {
17

18
#if defined(BOTAN_HAS_AES)
19

20
CTR_DRBG_AES256::~CTR_DRBG_AES256() = default;
3,810✔
21

22
void CTR_DRBG_AES256::clear() {
1,917✔
23
   const uint8_t zeros[32] = {0};
1,917✔
24
   m_cipher->set_key(zeros, 32);
×
25
   m_V0 = 0;
1,917✔
26
   m_V1 = 0;
1,917✔
27
}
×
28

29
void CTR_DRBG_AES256::fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) {
6,883✔
30
   if(!input.empty()) {
6,883✔
31
      if(input.size() != 48) {
1,917✔
32
         throw Test_Error("CTR_DRBG(AES-256) assumes 48 byte input");
×
33
      }
34

35
      clear();
1,917✔
36
      update(input);
1,917✔
37
   }
38

39
   if(!output.empty()) {
6,883✔
40
      const size_t full_blocks = output.size() / 16;
4,966✔
41
      const size_t leftover_bytes = output.size() % 16;
4,966✔
42

43
      for(size_t i = 0; i != full_blocks; ++i) {
52,788✔
44
         incr_V_into(output.subspan(i * 16, 16));
47,822✔
45
      }
46

47
      m_cipher->encrypt_n(output.data(), output.data(), full_blocks);
4,966✔
48

49
      if(leftover_bytes > 0) {
4,966✔
50
         uint8_t block[16];
566✔
51
         incr_V_into(block);
566✔
52
         m_cipher->encrypt(block);
566✔
53
         Botan::copy_mem(output.subspan(full_blocks * 16).data(), block, leftover_bytes);
566✔
54
      }
55

56
      update({});
4,966✔
57
   }
58
}
6,883✔
59

60
CTR_DRBG_AES256::CTR_DRBG_AES256(std::span<const uint8_t> seed) :
1,917✔
61
      m_cipher(Botan::BlockCipher::create_or_throw("AES-256")) {
1,917✔
62
   add_entropy(seed);
1,917✔
63
}
1,917✔
64

65
void CTR_DRBG_AES256::incr_V_into(std::span<uint8_t> output) {
69,037✔
66
   BOTAN_ASSERT_NOMSG(output.size() == 16);
69,037✔
67

68
   m_V1 += 1;
69,037✔
69
   if(m_V1 == 0) {
69,037✔
70
      m_V0 += 1;
×
71
   }
72

73
   Botan::store_be<uint64_t>(output.data(), m_V0, m_V1);
69,037✔
74
}
69,037✔
75

76
void CTR_DRBG_AES256::update(std::span<const uint8_t> provided_data) {
6,883✔
77
   std::array<uint8_t, 3 * 16> temp = {0};
6,883✔
78

79
   const std::span<uint8_t> t(temp);
6,883✔
80
   for(size_t i = 0; i != 3; ++i) {
27,532✔
81
      incr_V_into(t.subspan(16 * i, 16));
20,649✔
82
   }
83

84
   m_cipher->encrypt_n(temp.data(), temp.data(), 3);
6,883✔
85

86
   if(!provided_data.empty()) {
6,883✔
87
      BOTAN_ASSERT_NOMSG(provided_data.size() == temp.size());
1,917✔
88
      for(size_t i = 0; i != provided_data.size(); i++) {
93,933✔
89
         temp[i] ^= provided_data[i];
92,016✔
90
      }
91
   }
92

93
   m_cipher->set_key(std::span(temp).first(32));
6,883✔
94

95
   m_V0 = Botan::load_be<uint64_t>(temp.data() + 32, 0);
6,883✔
96
   m_V1 = Botan::load_be<uint64_t>(temp.data() + 32, 1);
6,883✔
97
}
6,883✔
98

99
#endif
100

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