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

randombit / botan / 19078852043

04 Nov 2025 12:08PM UTC coverage: 90.688% (+0.009%) from 90.679%
19078852043

push

github

web-flow
Merge pull request #5076 from reneme/feature/ascon_aead128

Feature: Ascon-AEAD128

100608 of 110939 relevant lines covered (90.69%)

12613541.58 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_AEAD_CCM)
19
   #include <botan/internal/ccm.h>
20
#endif
21

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

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

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

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

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

42
#if defined(BOTAN_HAS_ASCON_AEAD128)
43
   #include <botan/internal/ascon_aead128.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,513✔
59
   BOTAN_UNUSED(provider);
49,513✔
60
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
61
   if(algo == "ChaCha20Poly1305") {
49,513✔
62
      if(dir == Cipher_Dir::Encryption) {
12,932✔
63
         return std::make_unique<ChaCha20Poly1305_Encryption>();
6,468✔
64
      } else {
65
         return std::make_unique<ChaCha20Poly1305_Decryption>();
6,464✔
66
      }
67
   }
68
#endif
69

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

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

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

89
      std::ostringstream mode_name;
14,168✔
90

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

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

103
#if defined(BOTAN_HAS_BLOCK_CIPHER)
104

105
   SCAN_Name req(algo);
21,929✔
106

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

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

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

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

129
   #if defined(BOTAN_HAS_AEAD_GCM)
130
   if(req.algo_name() == "GCM") {
21,681✔
131
      size_t tag_len = req.arg_as_integer(1, 16);
3,688✔
132
      if(dir == Cipher_Dir::Encryption) {
3,688✔
133
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,195✔
134
      } else {
135
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,493✔
136
      }
137
   }
138
   #endif
139

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

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

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

172
#endif
173

174
   return std::unique_ptr<AEAD_Mode>();
15,251✔
175
}
21,929✔
176

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