• 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

95.38
/src/lib/modes/aead/aead.cpp
1
/*
2
* (C) 2013,2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/aead.h>
8

9
#include <botan/assert.h>
10
#include <botan/exceptn.h>
11
#include <botan/internal/parsing.h>
12
#include <botan/internal/scan_name.h>
13
#include <sstream>
14

15
#if defined(BOTAN_HAS_BLOCK_CIPHER)
16
   #include <botan/block_cipher.h>
17
#endif
18

19
#if defined(BOTAN_HAS_AEAD_CCM)
20
   #include <botan/internal/ccm.h>
21
#endif
22

23
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
24
   #include <botan/internal/chacha20poly1305.h>
25
#endif
26

27
#if defined(BOTAN_HAS_AEAD_EAX)
28
   #include <botan/internal/eax.h>
29
#endif
30

31
#if defined(BOTAN_HAS_AEAD_GCM)
32
   #include <botan/internal/gcm.h>
33
#endif
34

35
#if defined(BOTAN_HAS_AEAD_OCB)
36
   #include <botan/internal/ocb.h>
37
#endif
38

39
#if defined(BOTAN_HAS_AEAD_SIV)
40
   #include <botan/internal/siv.h>
41
#endif
42

43
#if defined(BOTAN_HAS_ASCON_AEAD128)
44
   #include <botan/internal/ascon_aead128.h>
45
#endif
46

47
namespace Botan {
48

49
std::unique_ptr<AEAD_Mode> AEAD_Mode::create_or_throw(std::string_view algo,
7,342✔
50
                                                      Cipher_Dir dir,
51
                                                      std::string_view provider) {
52
   if(auto aead = AEAD_Mode::create(algo, dir, provider)) {
7,342✔
53
      return aead;
7,342✔
54
   }
7,342✔
55

56
   throw Lookup_Error("AEAD", algo, provider);
×
57
}
58

59
std::unique_ptr<AEAD_Mode> AEAD_Mode::create(std::string_view algo, Cipher_Dir dir, std::string_view provider) {
52,469✔
60
   BOTAN_UNUSED(provider);
52,469✔
61
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
62
   if(algo == "ChaCha20Poly1305") {
52,469✔
63
      if(dir == Cipher_Dir::Encryption) {
17,903✔
64
         return std::make_unique<ChaCha20Poly1305_Encryption>();
8,954✔
65
      } else {
66
         return std::make_unique<ChaCha20Poly1305_Decryption>();
8,949✔
67
      }
68
   }
69
#endif
70

71
#if defined(BOTAN_HAS_ASCON_AEAD128)
72
   if(algo == "Ascon-AEAD128") {
34,566✔
73
      if(dir == Cipher_Dir::Encryption) {
484✔
74
         return std::make_unique<Ascon_AEAD128_Encryption>();
242✔
75
      } else {
76
         return std::make_unique<Ascon_AEAD128_Decryption>();
242✔
77
      }
78
   }
79
#endif
80

81
   if(algo.find('/') != std::string::npos) {
34,082✔
82
      const std::vector<std::string> algo_parts = split_on(algo, '/');
13,883✔
83
      if(algo_parts.size() < 2) {
13,883✔
84
         return std::unique_ptr<AEAD_Mode>();
×
85
      }
86
      const std::string_view cipher_name = algo_parts[0];
13,883✔
87
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
13,883✔
88

89
      if(mode_info.empty()) {
13,883✔
90
         return std::unique_ptr<AEAD_Mode>();
×
91
      }
92

93
      std::ostringstream mode_name;
13,883✔
94

95
      mode_name << mode_info[0] << '(' << cipher_name;
13,883✔
96
      for(size_t i = 1; i < mode_info.size(); ++i) {
14,940✔
97
         mode_name << ',' << mode_info[i];
1,057✔
98
      }
99
      for(size_t i = 2; i < algo_parts.size(); ++i) {
15,337✔
100
         mode_name << ',' << algo_parts[i];
1,454✔
101
      }
102
      mode_name << ')';
13,883✔
103

104
      return AEAD_Mode::create(mode_name.str(), dir);
13,883✔
105
   }
13,883✔
106

107
#if defined(BOTAN_HAS_BLOCK_CIPHER)
108

109
   const SCAN_Name req(algo);
20,199✔
110

111
   if(req.arg_count() == 0) {
20,199✔
112
      return std::unique_ptr<AEAD_Mode>();
1✔
113
   }
114

115
   auto bc = BlockCipher::create(req.arg(0), provider);
20,198✔
116

117
   if(!bc) {
20,198✔
118
      return std::unique_ptr<AEAD_Mode>();
3✔
119
   }
120

121
   #if defined(BOTAN_HAS_AEAD_CCM)
122
   if(req.algo_name() == "CCM") {
20,195✔
123
      const size_t tag_len = req.arg_as_integer(1, 16);
246✔
124
      const size_t L_len = req.arg_as_integer(2, 3);
246✔
125
      if(dir == Cipher_Dir::Encryption) {
246✔
126
         return std::make_unique<CCM_Encryption>(std::move(bc), tag_len, L_len);
124✔
127
      } else {
128
         return std::make_unique<CCM_Decryption>(std::move(bc), tag_len, L_len);
122✔
129
      }
130
   }
131
   #endif
132

133
   #if defined(BOTAN_HAS_AEAD_GCM)
134
   if(req.algo_name() == "GCM") {
19,949✔
135
      const size_t tag_len = req.arg_as_integer(1, 16);
4,430✔
136
      if(dir == Cipher_Dir::Encryption) {
4,430✔
137
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,740✔
138
      } else {
139
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,690✔
140
      }
141
   }
142
   #endif
143

144
   #if defined(BOTAN_HAS_AEAD_OCB)
145
   if(req.algo_name() == "OCB") {
15,519✔
146
      const size_t tag_len = req.arg_as_integer(1, 16);
318✔
147
      if(dir == Cipher_Dir::Encryption) {
318✔
148
         return std::make_unique<OCB_Encryption>(std::move(bc), tag_len);
182✔
149
      } else {
150
         return std::make_unique<OCB_Decryption>(std::move(bc), tag_len);
136✔
151
      }
152
   }
153
   #endif
154

155
   #if defined(BOTAN_HAS_AEAD_EAX)
156
   if(req.algo_name() == "EAX") {
15,201✔
157
      const size_t tag_len = req.arg_as_integer(1, bc->block_size());
1,214✔
158
      if(dir == Cipher_Dir::Encryption) {
1,214✔
159
         return std::make_unique<EAX_Encryption>(std::move(bc), tag_len);
702✔
160
      } else {
161
         return std::make_unique<EAX_Decryption>(std::move(bc), tag_len);
512✔
162
      }
163
   }
164
   #endif
165

166
   #if defined(BOTAN_HAS_AEAD_SIV)
167
   if(req.algo_name() == "SIV") {
13,987✔
168
      if(dir == Cipher_Dir::Encryption) {
1,626✔
169
         return std::make_unique<SIV_Encryption>(std::move(bc));
978✔
170
      } else {
171
         return std::make_unique<SIV_Decryption>(std::move(bc));
648✔
172
      }
173
   }
174
   #endif
175

176
#endif
177

178
   return std::unique_ptr<AEAD_Mode>();
12,361✔
179
}
20,199✔
180

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