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

randombit / botan / 29673219783

18 Jul 2026 10:42PM UTC coverage: 89.416% (+0.009%) from 89.407%
29673219783

push

github

randombit
Fix EC_Scalar_Data_BN::square_self

It computed the square then failed to update the stored value

114352 of 127887 relevant lines covered (89.42%)

10766049.99 hits per line

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

97.06
/src/lib/mac/cmac/cmac.cpp
1
/*
2
* CMAC
3
* (C) 1999-2007,2014 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/cmac.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/mem_ops.h>
12
#include <botan/internal/buffer_slicer.h>
13
#include <botan/internal/fmt.h>
14
#include <botan/internal/poly_dbl.h>
15

16
namespace Botan {
17

18
/*
19
* Update an CMAC Calculation
20
*/
21
void CMAC::add_data(std::span<const uint8_t> input) {
337,648✔
22
   assert_key_material_set();
337,648✔
23

24
   const size_t bs = output_length();
334,544✔
25

26
   const size_t initial_fill = std::min(m_buffer.size() - m_position, input.size());
334,544✔
27
   copy_mem(m_buffer.data() + m_position, input.data(), initial_fill);
334,544✔
28

29
   if(m_position + input.size() > bs) {
334,544✔
30
      xor_buf(m_state, m_buffer, bs);
19,548✔
31
      m_cipher->encrypt(m_state);
19,548✔
32

33
      BufferSlicer in(input);
19,548✔
34
      in.skip(bs - m_position);
19,548✔
35
      while(in.remaining() > bs) {
42,140✔
36
         xor_buf(m_state, in.take(bs), bs);
22,592✔
37
         m_cipher->encrypt(m_state);
64,732✔
38
      }
39

40
      const auto remaining = in.take(in.remaining());
19,548✔
41
      copy_mem(m_buffer.data(), remaining.data(), remaining.size());
19,548✔
42
      m_position = remaining.size();
19,548✔
43
   } else {
44
      m_position += input.size();
314,996✔
45
   }
46
}
334,544✔
47

48
/*
49
* Finalize an CMAC Calculation
50
*/
51
void CMAC::final_result(std::span<uint8_t> mac) {
150,199✔
52
   xor_buf(m_state, m_buffer, m_position);
150,199✔
53

54
   if(m_position == output_length()) {
150,199✔
55
      xor_buf(m_state, m_B, output_length());
130,679✔
56
   } else {
57
      m_state[m_position] ^= 0x80;
19,520✔
58
      xor_buf(m_state, m_P, output_length());
19,520✔
59
   }
60

61
   m_cipher->encrypt(m_state);
150,199✔
62

63
   copy_mem(mac.data(), m_state.data(), output_length());
149,776✔
64

65
   zeroise(m_state);
1,702,224✔
66
   zeroise(m_buffer);
149,776✔
67
   m_position = 0;
149,776✔
68
}
149,776✔
69

70
void CMAC::start_msg(std::span<const uint8_t> nonce) {
493✔
71
   if(!nonce.empty()) {
493✔
72
      throw Invalid_IV_Length(name(), nonce.size());
×
73
   }
74
   assert_key_material_set();
493✔
75

76
   zeroise(m_state);
9,394✔
77
   zeroise(m_buffer);
493✔
78
   m_position = 0;
493✔
79
}
493✔
80

81
bool CMAC::has_keying_material() const {
339,284✔
82
   return m_cipher->has_keying_material();
339,284✔
83
}
84

85
/*
86
* CMAC Key Schedule
87
*/
88
void CMAC::key_schedule(std::span<const uint8_t> key) {
4,039✔
89
   clear();
4,039✔
90
   m_cipher->set_key(key);
4,039✔
91
   m_cipher->encrypt(m_B);
4,039✔
92
   poly_double_n(m_B.data(), m_B.size());
4,039✔
93
   poly_double_n(m_P.data(), m_B.data(), m_P.size());
4,039✔
94
}
4,039✔
95

96
/*
97
* Clear memory of sensitive data
98
*/
99
void CMAC::clear() {
5,145✔
100
   m_cipher->clear();
5,145✔
101
   zeroise(m_state);
88,778✔
102
   zeroise(m_buffer);
83,633✔
103
   zeroise(m_B);
83,633✔
104
   zeroise(m_P);
5,145✔
105
   m_position = 0;
5,145✔
106
}
5,145✔
107

108
/*
109
* Return the name of this type
110
*/
111
std::string CMAC::name() const {
4,329✔
112
   return fmt("CMAC({})", m_cipher->name());
4,329✔
113
}
114

115
/*
116
* Return a new_object of this object
117
*/
118
std::unique_ptr<MessageAuthenticationCode> CMAC::new_object() const {
438✔
119
   return std::make_unique<CMAC>(m_cipher->new_object());
438✔
120
}
121

122
/*
123
* CMAC Constructor
124
*/
125
CMAC::CMAC(std::unique_ptr<BlockCipher> cipher) : m_cipher(std::move(cipher)), m_block_size(m_cipher->block_size()) {
3,754✔
126
   if(!poly_double_supported_size(m_block_size)) {
3,754✔
127
      throw Invalid_Argument(fmt("CMAC cannot use the {} bit cipher {}", m_block_size * 8, m_cipher->name()));
×
128
   }
129

130
   m_state.resize(output_length());
3,754✔
131
   m_buffer.resize(output_length());
3,754✔
132
   m_B.resize(output_length());
3,754✔
133
   m_P.resize(output_length());
3,754✔
134
   m_position = 0;
3,754✔
135
}
3,754✔
136

137
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc