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

randombit / botan / 13274522654

11 Feb 2025 11:26PM UTC coverage: 91.645% (-0.007%) from 91.652%
13274522654

push

github

web-flow
Merge pull request #4647 from randombit/jack/internal-assert-and-mem-ops

Avoid using mem_ops.h or assert.h in public headers

94854 of 103501 relevant lines covered (91.65%)

11334975.77 hits per line

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

98.65
/src/lib/block/block_cipher.cpp
1
/*
2
* Block Ciphers
3
* (C) 2015 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/block_cipher.h>
9

10
#include <botan/assert.h>
11
#include <botan/exceptn.h>
12
#include <botan/internal/scan_name.h>
13

14
#if defined(BOTAN_HAS_AES)
15
   #include <botan/internal/aes.h>
16
#endif
17

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

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

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

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

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

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

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

46
#if defined(BOTAN_HAS_IDEA)
47
   #include <botan/internal/idea.h>
48
#endif
49

50
#if defined(BOTAN_HAS_KUZNYECHIK)
51
   #include <botan/internal/kuznyechik.h>
52
#endif
53

54
#if defined(BOTAN_HAS_LION)
55
   #include <botan/internal/lion.h>
56
#endif
57

58
#if defined(BOTAN_HAS_NOEKEON)
59
   #include <botan/internal/noekeon.h>
60
#endif
61

62
#if defined(BOTAN_HAS_SEED)
63
   #include <botan/internal/seed.h>
64
#endif
65

66
#if defined(BOTAN_HAS_SERPENT)
67
   #include <botan/internal/serpent.h>
68
#endif
69

70
#if defined(BOTAN_HAS_SHACAL2)
71
   #include <botan/internal/shacal2.h>
72
#endif
73

74
#if defined(BOTAN_HAS_SM4)
75
   #include <botan/internal/sm4.h>
76
#endif
77

78
#if defined(BOTAN_HAS_TWOFISH)
79
   #include <botan/internal/twofish.h>
80
#endif
81

82
#if defined(BOTAN_HAS_THREEFISH_512)
83
   #include <botan/internal/threefish_512.h>
84
#endif
85

86
#if defined(BOTAN_HAS_COMMONCRYPTO)
87
   #include <botan/internal/commoncrypto.h>
88
#endif
89

90
namespace Botan {
91

92
std::unique_ptr<BlockCipher> BlockCipher::create(std::string_view algo, std::string_view provider) {
454,239✔
93
#if defined(BOTAN_HAS_COMMONCRYPTO)
94
   if(provider.empty() || provider == "commoncrypto") {
95
      if(auto bc = make_commoncrypto_block_cipher(algo))
96
         return bc;
97

98
      if(!provider.empty())
99
         return nullptr;
100
   }
101
#endif
102

103
   // TODO: CryptoAPI
104
   // TODO: /dev/crypto
105

106
   // Only base providers from here on out
107
   if(provider.empty() == false && provider != "base") {
674,782✔
108
      return nullptr;
200,326✔
109
   }
110

111
#if defined(BOTAN_HAS_AES)
112
   if(algo == "AES-128") {
253,913✔
113
      return std::make_unique<AES_128>();
78,943✔
114
   }
115

116
   if(algo == "AES-192") {
174,970✔
117
      return std::make_unique<AES_192>();
4,103✔
118
   }
119

120
   if(algo == "AES-256") {
170,867✔
121
      return std::make_unique<AES_256>();
78,488✔
122
   }
123
#endif
124

125
#if defined(BOTAN_HAS_ARIA)
126
   if(algo == "ARIA-128") {
92,379✔
127
      return std::make_unique<ARIA_128>();
10,483✔
128
   }
129

130
   if(algo == "ARIA-192") {
81,896✔
131
      return std::make_unique<ARIA_192>();
4✔
132
   }
133

134
   if(algo == "ARIA-256") {
81,892✔
135
      return std::make_unique<ARIA_256>();
10,482✔
136
   }
137
#endif
138

139
#if defined(BOTAN_HAS_SERPENT)
140
   if(algo == "Serpent") {
142,820✔
141
      return std::make_unique<Serpent>();
10,348✔
142
   }
143
#endif
144

145
#if defined(BOTAN_HAS_SHACAL2)
146
   if(algo == "SHACAL2") {
61,062✔
147
      return std::make_unique<SHACAL2>();
8,202✔
148
   }
149
#endif
150

151
#if defined(BOTAN_HAS_TWOFISH)
152
   if(algo == "Twofish") {
52,860✔
153
      return std::make_unique<Twofish>();
6,012✔
154
   }
155
#endif
156

157
#if defined(BOTAN_HAS_THREEFISH_512)
158
   if(algo == "Threefish-512") {
46,848✔
159
      return std::make_unique<Threefish_512>();
49✔
160
   }
161
#endif
162

163
#if defined(BOTAN_HAS_BLOWFISH)
164
   if(algo == "Blowfish") {
46,799✔
165
      return std::make_unique<Blowfish>();
259✔
166
   }
167
#endif
168

169
#if defined(BOTAN_HAS_CAMELLIA)
170
   if(algo == "Camellia-128") {
46,540✔
171
      return std::make_unique<Camellia_128>();
10,503✔
172
   }
173

174
   if(algo == "Camellia-192") {
36,037✔
175
      return std::make_unique<Camellia_192>();
6✔
176
   }
177

178
   if(algo == "Camellia-256") {
36,031✔
179
      return std::make_unique<Camellia_256>();
10,455✔
180
   }
181
#endif
182

183
#if defined(BOTAN_HAS_DES)
184
   if(algo == "DES") {
25,576✔
185
      return std::make_unique<DES>();
3,183✔
186
   }
187

188
   if(algo == "TripleDES" || algo == "3DES" || algo == "DES-EDE") {
40,037✔
189
      return std::make_unique<TripleDES>();
15,467✔
190
   }
191
#endif
192

193
#if defined(BOTAN_HAS_NOEKEON)
194
   if(algo == "Noekeon") {
6,926✔
195
      return std::make_unique<Noekeon>();
4,364✔
196
   }
197
#endif
198

199
#if defined(BOTAN_HAS_CAST_128)
200
   if(algo == "CAST-128" || algo == "CAST5") {
2,675✔
201
      return std::make_unique<CAST_128>();
226✔
202
   }
203
#endif
204

205
#if defined(BOTAN_HAS_IDEA)
206
   if(algo == "IDEA") {
2,449✔
207
      return std::make_unique<IDEA>();
2,168✔
208
   }
209
#endif
210

211
#if defined(BOTAN_HAS_KUZNYECHIK)
212
   if(algo == "Kuznyechik") {
281✔
213
      return std::make_unique<Kuznyechik>();
130✔
214
   }
215
#endif
216

217
#if defined(BOTAN_HAS_SEED)
218
   if(algo == "SEED") {
151✔
219
      return std::make_unique<SEED>();
8✔
220
   }
221
#endif
222

223
#if defined(BOTAN_HAS_SM4)
224
   if(algo == "SM4") {
143✔
225
      return std::make_unique<SM4>();
64✔
226
   }
227
#endif
228

229
   const SCAN_Name req(algo);
79✔
230

231
#if defined(BOTAN_HAS_GOST_28147_89)
232
   if(req.algo_name() == "GOST-28147-89") {
79✔
233
      return std::make_unique<GOST_28147_89>(req.arg(0, "R3411_94_TestParam"));
56✔
234
   }
235
#endif
236

237
#if defined(BOTAN_HAS_CASCADE)
238
   if(req.algo_name() == "Cascade" && req.arg_count() == 2) {
23✔
239
      auto c1 = BlockCipher::create(req.arg(0));
12✔
240
      auto c2 = BlockCipher::create(req.arg(1));
12✔
241

242
      if(c1 && c2) {
12✔
243
         return std::make_unique<Cascade_Cipher>(std::move(c1), std::move(c2));
12✔
244
      }
245
   }
12✔
246
#endif
247

248
#if defined(BOTAN_HAS_LION)
249
   if(req.algo_name() == "Lion" && req.arg_count_between(2, 3)) {
11✔
250
      auto hash = HashFunction::create(req.arg(0));
2✔
251
      auto stream = StreamCipher::create(req.arg(1));
2✔
252

253
      if(hash && stream) {
2✔
254
         const size_t block_size = req.arg_as_integer(2, 1024);
2✔
255
         return std::make_unique<Lion>(std::move(hash), std::move(stream), block_size);
2✔
256
      }
257
   }
2✔
258
#endif
259

260
   BOTAN_UNUSED(req);
9✔
261
   BOTAN_UNUSED(provider);
9✔
262

263
   return nullptr;
9✔
264
}
79✔
265

266
//static
267
std::unique_ptr<BlockCipher> BlockCipher::create_or_throw(std::string_view algo, std::string_view provider) {
2,726✔
268
   if(auto bc = BlockCipher::create(algo, provider)) {
2,726✔
269
      return bc;
2,726✔
270
   }
2,726✔
271
   throw Lookup_Error("Block cipher", algo, provider);
×
272
}
273

274
std::vector<std::string> BlockCipher::providers(std::string_view algo) {
200,326✔
275
   return probe_providers_of<BlockCipher>(algo, {"base", "commoncrypto"});
200,326✔
276
}
277

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