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

randombit / botan / 13544361846

26 Feb 2025 12:54PM UTC coverage: 91.693% (+0.002%) from 91.691%
13544361846

push

github

web-flow
Merge pull request #4716 from randombit/jack/emit-fpic-for-static-lib

Emit -fPIC or equivalent even for the static library

95830 of 104512 relevant lines covered (91.69%)

11425901.7 hits per line

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

96.61
/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
namespace Botan {
43

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

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

54
std::unique_ptr<AEAD_Mode> AEAD_Mode::create(std::string_view algo, Cipher_Dir dir, std::string_view provider) {
48,702✔
55
   BOTAN_UNUSED(provider);
48,702✔
56
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
57
   if(algo == "ChaCha20Poly1305") {
48,702✔
58
      if(dir == Cipher_Dir::Encryption) {
13,184✔
59
         return std::make_unique<ChaCha20Poly1305_Encryption>();
6,594✔
60
      } else {
61
         return std::make_unique<ChaCha20Poly1305_Decryption>();
6,590✔
62
      }
63
   }
64
#endif
65

66
   if(algo.find('/') != std::string::npos) {
35,518✔
67
      const std::vector<std::string> algo_parts = split_on(algo, '/');
13,881✔
68
      std::string_view cipher_name = algo_parts[0];
13,881✔
69
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
13,881✔
70

71
      if(mode_info.empty()) {
13,881✔
72
         return std::unique_ptr<AEAD_Mode>();
×
73
      }
74

75
      std::ostringstream mode_name;
13,881✔
76

77
      mode_name << mode_info[0] << '(' << cipher_name;
13,881✔
78
      for(size_t i = 1; i < mode_info.size(); ++i) {
14,859✔
79
         mode_name << ',' << mode_info[i];
978✔
80
      }
81
      for(size_t i = 2; i < algo_parts.size(); ++i) {
15,545✔
82
         mode_name << ',' << algo_parts[i];
1,664✔
83
      }
84
      mode_name << ')';
13,881✔
85

86
      return AEAD_Mode::create(mode_name.str(), dir);
13,881✔
87
   }
13,881✔
88

89
#if defined(BOTAN_HAS_BLOCK_CIPHER)
90

91
   SCAN_Name req(algo);
21,637✔
92

93
   if(req.arg_count() == 0) {
21,637✔
94
      return std::unique_ptr<AEAD_Mode>();
1✔
95
   }
96

97
   auto bc = BlockCipher::create(req.arg(0), provider);
21,636✔
98

99
   if(!bc) {
21,636✔
100
      return std::unique_ptr<AEAD_Mode>();
3✔
101
   }
102

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

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

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

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

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

158
#endif
159

160
   return std::unique_ptr<AEAD_Mode>();
15,241✔
161
}
21,637✔
162

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