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

randombit / botan / 30732274987

01 Aug 2026 02:42PM UTC coverage: 89.532% (+0.01%) from 89.522%
30732274987

push

github

web-flow
Merge pull request #5781 from randombit/jack/srp6-opt

Optimize SRP6's server step2

116608 of 130242 relevant lines covered (89.53%)

10499235.95 hits per line

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

94.37
/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_GCM_SIV)
36
   #include <botan/internal/gcm_siv.h>
37
#endif
38

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

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

47
#if defined(BOTAN_HAS_ASCON_AEAD128)
48
   #include <botan/internal/ascon_aead128.h>
49
#endif
50

51
namespace Botan {
52

53
std::unique_ptr<AEAD_Mode> AEAD_Mode::create_or_throw(std::string_view algo,
7,768✔
54
                                                      Cipher_Dir dir,
55
                                                      std::string_view provider) {
56
   if(auto aead = AEAD_Mode::create(algo, dir, provider)) {
7,768✔
57
      return aead;
7,768✔
58
   }
7,768✔
59

60
   throw Lookup_Error("AEAD", algo, provider);
×
61
}
62

63
std::unique_ptr<AEAD_Mode> AEAD_Mode::create(std::string_view algo, Cipher_Dir dir, std::string_view provider) {
56,589✔
64
   BOTAN_UNUSED(provider);
56,589✔
65
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
66
   if(algo == "ChaCha20Poly1305") {
56,589✔
67
      if(dir == Cipher_Dir::Encryption) {
17,915✔
68
         return std::make_unique<ChaCha20Poly1305_Encryption>();
8,960✔
69
      } else {
70
         return std::make_unique<ChaCha20Poly1305_Decryption>();
8,955✔
71
      }
72
   }
73
#endif
74

75
#if defined(BOTAN_HAS_ASCON_AEAD128)
76
   if(algo == "Ascon-AEAD128") {
38,674✔
77
      if(dir == Cipher_Dir::Encryption) {
484✔
78
         return std::make_unique<Ascon_AEAD128_Encryption>();
242✔
79
      } else {
80
         return std::make_unique<Ascon_AEAD128_Decryption>();
242✔
81
      }
82
   }
83
#endif
84

85
   if(algo.find('/') != std::string::npos) {
38,190✔
86
      const std::vector<std::string> algo_parts = split_on(algo, '/');
15,937✔
87
      if(algo_parts.size() < 2) {
15,937✔
88
         return std::unique_ptr<AEAD_Mode>();
×
89
      }
90
      const std::string_view cipher_name = algo_parts[0];
15,937✔
91
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
15,937✔
92

93
      if(mode_info.empty()) {
15,937✔
94
         return std::unique_ptr<AEAD_Mode>();
×
95
      }
96

97
      std::ostringstream mode_name;
15,937✔
98

99
      mode_name << mode_info[0] << '(' << cipher_name;
15,937✔
100
      for(size_t i = 1; i < mode_info.size(); ++i) {
17,002✔
101
         mode_name << ',' << mode_info[i];
1,065✔
102
      }
103
      for(size_t i = 2; i < algo_parts.size(); ++i) {
17,391✔
104
         mode_name << ',' << algo_parts[i];
1,454✔
105
      }
106
      mode_name << ')';
15,937✔
107

108
      return AEAD_Mode::create(mode_name.str(), dir);
15,937✔
109
   }
15,937✔
110

111
#if defined(BOTAN_HAS_BLOCK_CIPHER)
112

113
   const SCAN_Name req(algo);
22,253✔
114

115
   if(req.arg_count() == 0) {
22,253✔
116
      return std::unique_ptr<AEAD_Mode>();
1✔
117
   }
118

119
   auto bc = BlockCipher::create(req.arg(0), provider);
22,252✔
120

121
   if(!bc) {
22,252✔
122
      return std::unique_ptr<AEAD_Mode>();
3✔
123
   }
124

125
   #if defined(BOTAN_HAS_AEAD_CCM)
126
   if(req.algo_name() == "CCM") {
22,249✔
127
      const size_t tag_len = req.arg_as_integer(1, 16);
262✔
128
      const size_t L_len = req.arg_as_integer(2, 3);
262✔
129
      if(dir == Cipher_Dir::Encryption) {
262✔
130
         return std::make_unique<CCM_Encryption>(std::move(bc), tag_len, L_len);
132✔
131
      } else {
132
         return std::make_unique<CCM_Decryption>(std::move(bc), tag_len, L_len);
130✔
133
      }
134
   }
135
   #endif
136

137
   #if defined(BOTAN_HAS_AEAD_GCM)
138
   if(req.algo_name() == "GCM") {
21,987✔
139
      const size_t tag_len = req.arg_as_integer(1, 16);
4,828✔
140
      if(dir == Cipher_Dir::Encryption) {
4,828✔
141
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,945✔
142
      } else {
143
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,883✔
144
      }
145
   }
146
   #endif
147

148
   #if defined(BOTAN_HAS_AEAD_GCM_SIV)
149
   if(req.algo_name() == "GCM-SIV") {
17,159✔
150
      // Unlike GCM the tag length is fixed, so reject eg "AES-128/GCM-SIV(12)"
151
      if(req.arg_count() != 1) {
1,640✔
152
         return std::unique_ptr<AEAD_Mode>();
×
153
      }
154
      if(dir == Cipher_Dir::Encryption) {
1,640✔
155
         return std::make_unique<GCM_SIV_Encryption>(std::move(bc));
820✔
156
      } else {
157
         return std::make_unique<GCM_SIV_Decryption>(std::move(bc));
820✔
158
      }
159
   }
160
   #endif
161

162
   #if defined(BOTAN_HAS_AEAD_OCB)
163
   if(req.algo_name() == "OCB") {
15,519✔
164
      const size_t tag_len = req.arg_as_integer(1, 16);
318✔
165
      if(dir == Cipher_Dir::Encryption) {
318✔
166
         return std::make_unique<OCB_Encryption>(std::move(bc), tag_len);
182✔
167
      } else {
168
         return std::make_unique<OCB_Decryption>(std::move(bc), tag_len);
136✔
169
      }
170
   }
171
   #endif
172

173
   #if defined(BOTAN_HAS_AEAD_EAX)
174
   if(req.algo_name() == "EAX") {
15,201✔
175
      const size_t tag_len = req.arg_as_integer(1, bc->block_size());
1,214✔
176
      if(dir == Cipher_Dir::Encryption) {
1,214✔
177
         return std::make_unique<EAX_Encryption>(std::move(bc), tag_len);
702✔
178
      } else {
179
         return std::make_unique<EAX_Decryption>(std::move(bc), tag_len);
512✔
180
      }
181
   }
182
   #endif
183

184
   #if defined(BOTAN_HAS_AEAD_SIV)
185
   if(req.algo_name() == "SIV") {
13,987✔
186
      if(dir == Cipher_Dir::Encryption) {
1,626✔
187
         return std::make_unique<SIV_Encryption>(std::move(bc));
978✔
188
      } else {
189
         return std::make_unique<SIV_Decryption>(std::move(bc));
648✔
190
      }
191
   }
192
   #endif
193

194
#endif
195

196
   return std::unique_ptr<AEAD_Mode>();
12,361✔
197
}
22,253✔
198

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