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

randombit / botan / 17355784936

31 Aug 2025 10:19AM UTC coverage: 90.681% (+0.01%) from 90.669%
17355784936

Pull #5076

github

web-flow
Merge 4bf7b9f0b into 73ef15481
Pull Request #5076: Feature: Ascon-AEAD128

100419 of 110739 relevant lines covered (90.68%)

12265631.61 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/internal/parsing.h>
11
#include <botan/internal/scan_name.h>
12
#include <sstream>
13

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

18
#if defined(BOTAN_HAS_ASCON_AEAD128)
19
   #include <botan/internal/ascon_aead128.h>
20
#endif
21

22
#if defined(BOTAN_HAS_AEAD_CCM)
23
   #include <botan/internal/ccm.h>
24
#endif
25

26
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
27
   #include <botan/internal/chacha20poly1305.h>
28
#endif
29

30
#if defined(BOTAN_HAS_AEAD_EAX)
31
   #include <botan/internal/eax.h>
32
#endif
33

34
#if defined(BOTAN_HAS_AEAD_GCM)
35
   #include <botan/internal/gcm.h>
36
#endif
37

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

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

46
namespace Botan {
47

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

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

58
std::unique_ptr<AEAD_Mode> AEAD_Mode::create(std::string_view algo, Cipher_Dir dir, std::string_view provider) {
49,494✔
59
   BOTAN_UNUSED(provider);
49,494✔
60

61
#if defined(BOTAN_HAS_ASCON_AEAD128)
62
   if(algo == "Ascon-AEAD128") {
49,494✔
63
      if(dir == Cipher_Dir::Encryption) {
484✔
64
         return std::make_unique<Ascon_AEAD128_Encryption>();
242✔
65
      } else {
66
         return std::make_unique<Ascon_AEAD128_Decryption>();
242✔
67
      }
68
   }
69
#endif
70

71
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
72
   if(algo == "ChaCha20Poly1305") {
49,010✔
73
      if(dir == Cipher_Dir::Encryption) {
12,932✔
74
         return std::make_unique<ChaCha20Poly1305_Encryption>();
6,468✔
75
      } else {
76
         return std::make_unique<ChaCha20Poly1305_Decryption>();
6,464✔
77
      }
78
   }
79
#endif
80

81
   if(algo.find('/') != std::string::npos) {
36,078✔
82
      const std::vector<std::string> algo_parts = split_on(algo, '/');
14,161✔
83
      std::string_view cipher_name = algo_parts[0];
14,161✔
84
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
14,161✔
85

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

90
      std::ostringstream mode_name;
14,161✔
91

92
      mode_name << mode_info[0] << '(' << cipher_name;
14,161✔
93
      for(size_t i = 1; i < mode_info.size(); ++i) {
15,139✔
94
         mode_name << ',' << mode_info[i];
978✔
95
      }
96
      for(size_t i = 2; i < algo_parts.size(); ++i) {
15,825✔
97
         mode_name << ',' << algo_parts[i];
1,664✔
98
      }
99
      mode_name << ')';
14,161✔
100

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

104
#if defined(BOTAN_HAS_BLOCK_CIPHER)
105

106
   SCAN_Name req(algo);
21,917✔
107

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

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

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

118
   #if defined(BOTAN_HAS_AEAD_CCM)
119
   if(req.algo_name() == "CCM") {
21,913✔
120
      size_t tag_len = req.arg_as_integer(1, 16);
244✔
121
      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") {
21,669✔
132
      size_t tag_len = req.arg_as_integer(1, 16);
3,686✔
133
      if(dir == Cipher_Dir::Encryption) {
3,686✔
134
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,194✔
135
      } else {
136
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,492✔
137
      }
138
   }
139
   #endif
140

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

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

163
   #if defined(BOTAN_HAS_AEAD_SIV)
164
   if(req.algo_name() == "SIV") {
16,540✔
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>();
15,241✔
176
}
21,917✔
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