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

randombit / botan / 21753596263

06 Feb 2026 02:13PM UTC coverage: 90.063% (-0.01%) from 90.073%
21753596263

Pull #5289

github

web-flow
Merge 587099284 into 8ea0ca252
Pull Request #5289: Further misc header reductions, forward declarations, etc

102237 of 113517 relevant lines covered (90.06%)

11402137.11 hits per line

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

96.83
/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,
6,325✔
50
                                                      Cipher_Dir dir,
51
                                                      std::string_view provider) {
52
   if(auto aead = AEAD_Mode::create(algo, dir, provider)) {
6,325✔
53
      return aead;
6,325✔
54
   }
6,325✔
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) {
48,634✔
60
   BOTAN_UNUSED(provider);
48,634✔
61
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
62
   if(algo == "ChaCha20Poly1305") {
48,634✔
63
      if(dir == Cipher_Dir::Encryption) {
17,224✔
64
         return std::make_unique<ChaCha20Poly1305_Encryption>();
8,614✔
65
      } else {
66
         return std::make_unique<ChaCha20Poly1305_Decryption>();
8,610✔
67
      }
68
   }
69
#endif
70

71
#if defined(BOTAN_HAS_ASCON_AEAD128)
72
   if(algo == "Ascon-AEAD128") {
31,410✔
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) {
30,926✔
82
      const std::vector<std::string> algo_parts = split_on(algo, '/');
12,407✔
83
      const std::string_view cipher_name = algo_parts[0];
12,407✔
84
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
12,407✔
85

86
      if(mode_info.empty()) {
12,407✔
87
         return std::unique_ptr<AEAD_Mode>();
×
88
      }
89

90
      std::ostringstream mode_name;
12,407✔
91

92
      mode_name << mode_info[0] << '(' << cipher_name;
12,407✔
93
      for(size_t i = 1; i < mode_info.size(); ++i) {
13,385✔
94
         mode_name << ',' << mode_info[i];
978✔
95
      }
96
      for(size_t i = 2; i < algo_parts.size(); ++i) {
13,775✔
97
         mode_name << ',' << algo_parts[i];
1,368✔
98
      }
99
      mode_name << ')';
12,407✔
100

101
      return AEAD_Mode::create(mode_name.str(), dir);
12,407✔
102
   }
12,407✔
103

104
#if defined(BOTAN_HAS_BLOCK_CIPHER)
105

106
   const SCAN_Name req(algo);
18,519✔
107

108
   if(req.arg_count() == 0) {
18,519✔
109
      return std::unique_ptr<AEAD_Mode>();
1✔
110
   }
111

112
   auto bc = BlockCipher::create(req.arg(0), provider);
18,518✔
113

114
   if(!bc) {
18,518✔
115
      return std::unique_ptr<AEAD_Mode>();
3✔
116
   }
117

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

130
   #if defined(BOTAN_HAS_AEAD_GCM)
131
   if(req.algo_name() == "GCM") {
18,271✔
132
      const size_t tag_len = req.arg_as_integer(1, 16);
3,724✔
133
      if(dir == Cipher_Dir::Encryption) {
3,724✔
134
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,213✔
135
      } else {
136
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,511✔
137
      }
138
   }
139
   #endif
140

141
   #if defined(BOTAN_HAS_AEAD_OCB)
142
   if(req.algo_name() == "OCB") {
14,547✔
143
      const size_t tag_len = req.arg_as_integer(1, 16);
272✔
144
      if(dir == Cipher_Dir::Encryption) {
272✔
145
         return std::make_unique<OCB_Encryption>(std::move(bc), tag_len);
136✔
146
      } else {
147
         return std::make_unique<OCB_Decryption>(std::move(bc), tag_len);
136✔
148
      }
149
   }
150
   #endif
151

152
   #if defined(BOTAN_HAS_AEAD_EAX)
153
   if(req.algo_name() == "EAX") {
14,275✔
154
      const size_t tag_len = req.arg_as_integer(1, bc->block_size());
1,023✔
155
      if(dir == Cipher_Dir::Encryption) {
1,023✔
156
         return std::make_unique<EAX_Encryption>(std::move(bc), tag_len);
511✔
157
      } else {
158
         return std::make_unique<EAX_Decryption>(std::move(bc), tag_len);
512✔
159
      }
160
   }
161
   #endif
162

163
   #if defined(BOTAN_HAS_AEAD_SIV)
164
   if(req.algo_name() == "SIV") {
13,252✔
165
      if(dir == Cipher_Dir::Encryption) {
1,299✔
166
         return std::make_unique<SIV_Encryption>(std::move(bc));
652✔
167
      } else {
168
         return std::make_unique<SIV_Decryption>(std::move(bc));
647✔
169
      }
170
   }
171
   #endif
172

173
#endif
174

175
   return std::unique_ptr<AEAD_Mode>();
11,953✔
176
}
18,519✔
177

178
}  // namespace Botan
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

© 2026 Coveralls, Inc