• 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

84.0
/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/internal/loadstor.h>
11
#endif
12

13
#include <array>
14

15
namespace Botan_Tests {
16

17
#if defined(BOTAN_HAS_AES)
18

19
void CTR_DRBG_AES256::clear() {
1,800✔
20
   const uint8_t zeros[32] = {0};
1,800✔
21
   m_cipher->set_key(zeros, 32);
×
22
   m_V0 = 0;
1,800✔
23
   m_V1 = 0;
1,800✔
24
}
×
25

26
void CTR_DRBG_AES256::fill_bytes_with_input(std::span<uint8_t> output, std::span<const uint8_t> input) {
5,400✔
27
   if(!input.empty()) {
5,400✔
28
      if(input.size() != 48)
1,800✔
29
         throw Test_Error("CTR_DRBG(AES-256) assumes 48 byte input");
×
30

31
      clear();
1,800✔
32
      update(input);
1,800✔
33
   }
34

35
   if(!output.empty()) {
5,400✔
36
      const size_t full_blocks = output.size() / 16;
3,600✔
37
      const size_t leftover_bytes = output.size() % 16;
3,600✔
38

39
      for(size_t i = 0; i != full_blocks; ++i)
12,000✔
40
         incr_V_into(output.subspan(i * 16, 16));
8,400✔
41

42
      m_cipher->encrypt_n(output.data(), output.data(), full_blocks);
3,600✔
43

44
      if(leftover_bytes > 0) {
3,600✔
45
         uint8_t block[16];
×
46
         incr_V_into(block);
×
47
         m_cipher->encrypt(block);
×
48
         Botan::copy_mem(output.subspan(full_blocks * 16).data(), block, leftover_bytes);
×
49
      }
50

51
      update({});
3,600✔
52
   }
53
}
5,400✔
54

55
CTR_DRBG_AES256::CTR_DRBG_AES256(std::span<const uint8_t> seed) {
1,800✔
56
   m_cipher = Botan::BlockCipher::create_or_throw("AES-256");
1,800✔
57
   add_entropy(seed);
1,800✔
58
}
1,800✔
59

60
void CTR_DRBG_AES256::incr_V_into(std::span<uint8_t> output) {
24,600✔
61
   BOTAN_ASSERT_NOMSG(output.size() == 16);
24,600✔
62

63
   m_V1 += 1;
24,600✔
64
   if(m_V1 == 0)
24,600✔
65
      m_V0 += 1;
×
66

67
   Botan::store_be<uint64_t>(output.data(), m_V0, m_V1);
24,600✔
68
}
24,600✔
69

70
void CTR_DRBG_AES256::update(std::span<const uint8_t> provided_data) {
5,400✔
71
   std::array<uint8_t, 3 * 16> temp = {0};
5,400✔
72

73
   std::span<uint8_t> t(temp);
5,400✔
74
   for(size_t i = 0; i != 3; ++i) {
21,600✔
75
      incr_V_into(t.subspan(16 * i, 16));
16,200✔
76
   }
77

78
   m_cipher->encrypt_n(temp.data(), temp.data(), 3);
5,400✔
79

80
   if(!provided_data.empty()) {
5,400✔
81
      BOTAN_ASSERT_NOMSG(provided_data.size() == temp.size());
1,800✔
82
      for(size_t i = 0; i != provided_data.size(); i++)
88,200✔
83
         temp[i] ^= provided_data[i];
86,400✔
84
   }
85

86
   m_cipher->set_key(temp.data(), 32);  // TODO: adapt after GH #3297
5,400✔
87

88
   m_V0 = Botan::load_be<uint64_t>(temp.data() + 32, 0);
5,400✔
89
   m_V1 = Botan::load_be<uint64_t>(temp.data() + 32, 1);
5,400✔
90
}
5,400✔
91

92
#endif
93

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

© 2025 Coveralls, Inc