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

randombit / botan / 11300480493

11 Oct 2024 11:12PM UTC coverage: 91.113% (+0.1%) from 90.981%
11300480493

push

github

web-flow
Merge pull request #4367 from randombit/jack/refactor-speed-pk

Refactor public key related performance test code

90011 of 98791 relevant lines covered (91.11%)

9071963.87 hits per line

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

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

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

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

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

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

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

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

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

41
namespace Botan {
42

43
std::unique_ptr<AEAD_Mode> AEAD_Mode::create_or_throw(std::string_view algo,
6,222✔
44
                                                      Cipher_Dir dir,
45
                                                      std::string_view provider) {
46
   if(auto aead = AEAD_Mode::create(algo, dir, provider)) {
6,222✔
47
      return aead;
6,222✔
48
   }
6,222✔
49

50
   throw Lookup_Error("AEAD", algo, provider);
×
51
}
52

53
std::unique_ptr<AEAD_Mode> AEAD_Mode::create(std::string_view algo, Cipher_Dir dir, std::string_view provider) {
51,784✔
54
   BOTAN_UNUSED(provider);
51,784✔
55
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
56
   if(algo == "ChaCha20Poly1305") {
51,784✔
57
      if(dir == Cipher_Dir::Encryption) {
13,142✔
58
         return std::make_unique<ChaCha20Poly1305_Encryption>();
6,573✔
59
      } else {
60
         return std::make_unique<ChaCha20Poly1305_Decryption>();
6,569✔
61
      }
62
   }
63
#endif
64

65
   if(algo.find('/') != std::string::npos) {
38,642✔
66
      const std::vector<std::string> algo_parts = split_on(algo, '/');
14,907✔
67
      std::string_view cipher_name = algo_parts[0];
14,907✔
68
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
14,907✔
69

70
      if(mode_info.empty()) {
14,907✔
71
         return std::unique_ptr<AEAD_Mode>();
×
72
      }
73

74
      std::ostringstream mode_name;
14,907✔
75

76
      mode_name << mode_info[0] << '(' << cipher_name;
14,907✔
77
      for(size_t i = 1; i < mode_info.size(); ++i) {
15,919✔
78
         mode_name << ',' << mode_info[i];
1,012✔
79
      }
80
      for(size_t i = 2; i < algo_parts.size(); ++i) {
16,900✔
81
         mode_name << ',' << algo_parts[i];
1,993✔
82
      }
83
      mode_name << ')';
14,907✔
84

85
      return AEAD_Mode::create(mode_name.str(), dir);
14,907✔
86
   }
14,907✔
87

88
#if defined(BOTAN_HAS_BLOCK_CIPHER)
89

90
   SCAN_Name req(algo);
23,735✔
91

92
   if(req.arg_count() == 0) {
23,735✔
93
      return std::unique_ptr<AEAD_Mode>();
×
94
   }
95

96
   auto bc = BlockCipher::create(req.arg(0), provider);
23,735✔
97

98
   if(!bc) {
23,735✔
99
      return std::unique_ptr<AEAD_Mode>();
3✔
100
   }
101

102
   #if defined(BOTAN_HAS_AEAD_CCM)
103
   if(req.algo_name() == "CCM") {
23,732✔
104
      size_t tag_len = req.arg_as_integer(1, 16);
238✔
105
      size_t L_len = req.arg_as_integer(2, 3);
238✔
106
      if(dir == Cipher_Dir::Encryption) {
238✔
107
         return std::make_unique<CCM_Encryption>(std::move(bc), tag_len, L_len);
119✔
108
      } else {
109
         return std::make_unique<CCM_Decryption>(std::move(bc), tag_len, L_len);
119✔
110
      }
111
   }
112
   #endif
113

114
   #if defined(BOTAN_HAS_AEAD_GCM)
115
   if(req.algo_name() == "GCM") {
23,494✔
116
      size_t tag_len = req.arg_as_integer(1, 16);
3,353✔
117
      if(dir == Cipher_Dir::Encryption) {
3,353✔
118
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,012✔
119
      } else {
120
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,341✔
121
      }
122
   }
123
   #endif
124

125
   #if defined(BOTAN_HAS_AEAD_OCB)
126
   if(req.algo_name() == "OCB") {
20,141✔
127
      size_t tag_len = req.arg_as_integer(1, 16);
292✔
128
      if(dir == Cipher_Dir::Encryption) {
292✔
129
         return std::make_unique<OCB_Encryption>(std::move(bc), tag_len);
146✔
130
      } else {
131
         return std::make_unique<OCB_Decryption>(std::move(bc), tag_len);
146✔
132
      }
133
   }
134
   #endif
135

136
   #if defined(BOTAN_HAS_AEAD_EAX)
137
   if(req.algo_name() == "EAX") {
19,849✔
138
      size_t tag_len = req.arg_as_integer(1, bc->block_size());
1,151✔
139
      if(dir == Cipher_Dir::Encryption) {
1,151✔
140
         return std::make_unique<EAX_Encryption>(std::move(bc), tag_len);
575✔
141
      } else {
142
         return std::make_unique<EAX_Decryption>(std::move(bc), tag_len);
576✔
143
      }
144
   }
145
   #endif
146

147
   #if defined(BOTAN_HAS_AEAD_SIV)
148
   if(req.algo_name() == "SIV") {
18,698✔
149
      if(dir == Cipher_Dir::Encryption) {
1,299✔
150
         return std::make_unique<SIV_Encryption>(std::move(bc));
652✔
151
      } else {
152
         return std::make_unique<SIV_Decryption>(std::move(bc));
647✔
153
      }
154
   }
155
   #endif
156

157
#endif
158

159
   return std::unique_ptr<AEAD_Mode>();
17,399✔
160
}
23,735✔
161

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