• 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

92.98
/src/lib/mac/mac.cpp
1
/*
2
* Message Authentication Code base class
3
* (C) 1999-2008 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/mac.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/ct_utils.h>
12
#include <botan/internal/scan_name.h>
13

14
#if defined(BOTAN_HAS_CMAC)
15
   #include <botan/internal/cmac.h>
16
#endif
17

18
#if defined(BOTAN_HAS_GMAC)
19
   #include <botan/block_cipher.h>
20
   #include <botan/internal/gmac.h>
21
#endif
22

23
#if defined(BOTAN_HAS_HMAC)
24
   #include <botan/hash.h>
25
   #include <botan/internal/hmac.h>
26
#endif
27

28
#if defined(BOTAN_HAS_POLY1305)
29
   #include <botan/internal/poly1305.h>
30
#endif
31

32
#if defined(BOTAN_HAS_SIPHASH)
33
   #include <botan/internal/siphash.h>
34
#endif
35

36
#if defined(BOTAN_HAS_ANSI_X919_MAC)
37
   #include <botan/internal/x919_mac.h>
38
#endif
39

40
#if defined(BOTAN_HAS_BLAKE2BMAC)
41
   #include <botan/internal/blake2bmac.h>
42
#endif
43

44
#if defined(BOTAN_HAS_KMAC)
45
   #include <botan/internal/kmac.h>
46
#endif
47

48
namespace Botan {
49

50
std::unique_ptr<MessageAuthenticationCode> MessageAuthenticationCode::create(std::string_view algo_spec,
43,325✔
51
                                                                             std::string_view provider) {
52
   const SCAN_Name req(algo_spec);
43,325✔
53

54
#if defined(BOTAN_HAS_BLAKE2BMAC)
55
   if(req.algo_name() == "Blake2b" || req.algo_name() == "BLAKE2b") {
43,325✔
56
      if(provider.empty() || provider == "base") {
1,092✔
57
         return std::make_unique<BLAKE2bMAC>(req.arg_as_integer(0, 512));
546✔
58
      }
59
   }
60
#endif
61

62
#if defined(BOTAN_HAS_GMAC)
63
   if(req.algo_name() == "GMAC" && req.arg_count() == 1) {
42,779✔
64
      if(provider.empty() || provider == "base") {
2,289✔
65
         if(auto bc = BlockCipher::create(req.arg(0))) {
2,290✔
66
            return std::make_unique<GMAC>(std::move(bc));
1,145✔
67
         }
1,145✔
68
      }
69
   }
70
#endif
71

72
#if defined(BOTAN_HAS_HMAC)
73
   if(req.algo_name() == "HMAC" && req.arg_count() == 1) {
41,634✔
74
      if(provider.empty() || provider == "base") {
22,741✔
75
         if(auto hash = HashFunction::create(req.arg(0))) {
45,184✔
76
            return std::make_unique<HMAC>(std::move(hash));
20,684✔
77
         }
22,592✔
78
      }
79
   }
80
#endif
81

82
#if defined(BOTAN_HAS_POLY1305)
83
   if(req.algo_name() == "Poly1305" && req.arg_count() == 0) {
20,950✔
84
      if(provider.empty() || provider == "base") {
18,898✔
85
         return std::make_unique<Poly1305>();
18,406✔
86
      }
87
   }
88
#endif
89

90
#if defined(BOTAN_HAS_SIPHASH)
91
   if(req.algo_name() == "SipHash") {
2,544✔
92
      if(provider.empty() || provider == "base") {
237✔
93
         return std::make_unique<SipHash>(req.arg_as_integer(0, 2), req.arg_as_integer(1, 4));
119✔
94
      }
95
   }
96
#endif
97

98
#if defined(BOTAN_HAS_CMAC)
99
   if((req.algo_name() == "CMAC" || req.algo_name() == "OMAC") && req.arg_count() == 1) {
2,425✔
100
      if(provider.empty() || provider == "base") {
554✔
101
         if(auto bc = BlockCipher::create(req.arg(0))) {
952✔
102
            return std::make_unique<CMAC>(std::move(bc));
476✔
103
         }
476✔
104
      }
105
   }
106
#endif
107

108
#if defined(BOTAN_HAS_ANSI_X919_MAC)
109
   if(req.algo_name() == "X9.19-MAC") {
1,949✔
110
      if(provider.empty() || provider == "base") {
24✔
111
         return std::make_unique<ANSI_X919_MAC>();
12✔
112
      }
113
   }
114
#endif
115

116
#if defined(BOTAN_HAS_KMAC)
117
   if(req.algo_name() == "KMAC-128") {
1,937✔
118
      if(provider.empty() || provider == "base") {
28✔
119
         if(req.arg_count() != 1) {
14✔
120
            throw Invalid_Argument(
×
121
               "invalid algorithm specification for KMAC-128: need exactly one argument for output bit length");
×
122
         }
123
         return std::make_unique<KMAC128>(req.arg_as_integer(0));
14✔
124
      }
125
   }
126

127
   if(req.algo_name() == "KMAC-256") {
1,923✔
128
      if(provider.empty() || provider == "base") {
28✔
129
         if(req.arg_count() != 1) {
14✔
130
            throw Invalid_Argument(
×
131
               "invalid algorithm specification for KMAC-256: need exactly one argument for output bit length");
×
132
         }
133
         return std::make_unique<KMAC256>(req.arg_as_integer(0));
14✔
134
      }
135
   }
136
#endif
137

138
   BOTAN_UNUSED(req);
1,909✔
139
   BOTAN_UNUSED(provider);
1,909✔
140

141
   return nullptr;
1,909✔
142
}
43,325✔
143

144
std::vector<std::string> MessageAuthenticationCode::providers(std::string_view algo_spec) {
1,284✔
145
   return probe_providers_of<MessageAuthenticationCode>(algo_spec);
1,284✔
146
}
147

148
//static
149
std::unique_ptr<MessageAuthenticationCode> MessageAuthenticationCode::create_or_throw(std::string_view algo,
9,430✔
150
                                                                                      std::string_view provider) {
151
   if(auto mac = MessageAuthenticationCode::create(algo, provider)) {
9,430✔
152
      return mac;
9,429✔
153
   }
9,429✔
154
   throw Lookup_Error("MAC", algo, provider);
1✔
155
}
156

157
/*
158
* Default (deterministic) MAC verification operation
159
*/
160
bool MessageAuthenticationCode::verify_mac_result(std::span<const uint8_t> mac) {
3,386✔
161
   secure_vector<uint8_t> our_mac = final();
3,386✔
162

163
   if(our_mac.size() != mac.size()) {
3,386✔
164
      return false;
165
   }
166

167
   return CT::is_equal(our_mac.data(), mac.data(), mac.size()).as_bool();
3,384✔
168
}
3,386✔
169

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