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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

98.61
/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/exceptn.h>
11
#include <botan/internal/scan_name.h>
12

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

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

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

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

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

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

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

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

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

49
#if defined(BOTAN_HAS_LION)
50
   #include <botan/internal/lion.h>
51
#endif
52

53
#if defined(BOTAN_HAS_NOEKEON)
54
   #include <botan/internal/noekeon.h>
55
#endif
56

57
#if defined(BOTAN_HAS_SEED)
58
   #include <botan/internal/seed.h>
59
#endif
60

61
#if defined(BOTAN_HAS_SERPENT)
62
   #include <botan/internal/serpent.h>
63
#endif
64

65
#if defined(BOTAN_HAS_SHACAL2)
66
   #include <botan/internal/shacal2.h>
67
#endif
68

69
#if defined(BOTAN_HAS_SM4)
70
   #include <botan/internal/sm4.h>
71
#endif
72

73
#if defined(BOTAN_HAS_TWOFISH)
74
   #include <botan/internal/twofish.h>
75
#endif
76

77
#if defined(BOTAN_HAS_THREEFISH_512)
78
   #include <botan/internal/threefish_512.h>
79
#endif
80

81
#if defined(BOTAN_HAS_COMMONCRYPTO)
82
   #include <botan/internal/commoncrypto.h>
83
#endif
84

85
namespace Botan {
86

87
std::unique_ptr<BlockCipher> BlockCipher::create(std::string_view algo, std::string_view provider) {
512,590✔
88
#if defined(BOTAN_HAS_COMMONCRYPTO)
89
   if(provider.empty() || provider == "commoncrypto") {
90
      if(auto bc = make_commoncrypto_block_cipher(algo))
91
         return bc;
92

93
      if(!provider.empty())
94
         return nullptr;
95
   }
96
#endif
97

98
   // TODO: CryptoAPI
99
   // TODO: /dev/crypto
100

101
   // Only base providers from here on out
102
   if(provider.empty() == false && provider != "base")
716,014✔
103
      return nullptr;
512,590✔
104

105
#if defined(BOTAN_HAS_AES)
106
   if(algo == "AES-128") {
518,366✔
107
      return std::make_unique<AES_128>();
72,686✔
108
   }
109

110
   if(algo == "AES-192") {
442,479✔
111
      return std::make_unique<AES_192>();
3,201✔
112
   }
113

114
   if(algo == "AES-256") {
277,898✔
115
      return std::make_unique<AES_256>();
161,380✔
116
   }
117
#endif
118

119
#if defined(BOTAN_HAS_ARIA)
120
   if(algo == "ARIA-128") {
98,583✔
121
      return std::make_unique<ARIA_128>();
9,788✔
122
   }
123

124
   if(algo == "ARIA-192") {
88,791✔
125
      return std::make_unique<ARIA_192>();
4✔
126
   }
127

128
   if(algo == "ARIA-256") {
78,998✔
129
      return std::make_unique<ARIA_256>();
9,789✔
130
   }
131
#endif
132

133
#if defined(BOTAN_HAS_SERPENT)
134
   if(algo == "Serpent") {
86,111✔
135
      return std::make_unique<Serpent>();
10,826✔
136
   }
137
#endif
138

139
#if defined(BOTAN_HAS_SHACAL2)
140
   if(algo == "SHACAL2") {
69,123✔
141
      return std::make_unique<SHACAL2>();
6,162✔
142
   }
143
#endif
144

145
#if defined(BOTAN_HAS_TWOFISH)
146
   if(algo == "Twofish") {
56,469✔
147
      return std::make_unique<Twofish>();
6,492✔
148
   }
149
#endif
150

151
#if defined(BOTAN_HAS_THREEFISH_512)
152
   if(algo == "Threefish-512") {
45,348✔
153
      return std::make_unique<Threefish_512>();
51✔
154
   }
155
#endif
156

157
#if defined(BOTAN_HAS_BLOWFISH)
158
   if(algo == "Blowfish") {
45,417✔
159
      return std::make_unique<Blowfish>();
261✔
160
   }
161
#endif
162

163
#if defined(BOTAN_HAS_CAMELLIA)
164
   if(algo == "Camellia-128") {
54,802✔
165
      return std::make_unique<Camellia_128>();
9,808✔
166
   }
167

168
   if(algo == "Camellia-192") {
44,988✔
169
      return std::make_unique<Camellia_192>();
6✔
170
   }
171

172
   if(algo == "Camellia-256") {
35,222✔
173
      return std::make_unique<Camellia_256>();
9,760✔
174
   }
175
#endif
176

177
#if defined(BOTAN_HAS_DES)
178
   if(algo == "DES") {
25,473✔
179
      return std::make_unique<DES>();
3,494✔
180
   }
181

182
   if(algo == "TripleDES" || algo == "3DES" || algo == "DES-EDE") {
43,706✔
183
      return std::make_unique<TripleDES>();
14,927✔
184
   }
185
#endif
186

187
#if defined(BOTAN_HAS_NOEKEON)
188
   if(algo == "Noekeon") {
7,050✔
189
      return std::make_unique<Noekeon>();
4,620✔
190
   }
191
#endif
192

193
#if defined(BOTAN_HAS_CAST_128)
194
   if(algo == "CAST-128" || algo == "CAST5") {
2,543✔
195
      return std::make_unique<CAST_128>();
115✔
196
   }
197
#endif
198

199
#if defined(BOTAN_HAS_IDEA)
200
   if(algo == "IDEA") {
2,317✔
201
      return std::make_unique<IDEA>();
2,168✔
202
   }
203
#endif
204

205
#if defined(BOTAN_HAS_SEED)
206
   if(algo == "SEED") {
141✔
207
      return std::make_unique<SEED>();
8✔
208
   }
209
#endif
210

211
#if defined(BOTAN_HAS_SM4)
212
   if(algo == "SM4") {
133✔
213
      return std::make_unique<SM4>();
8✔
214
   }
215
#endif
216

217
   const SCAN_Name req(algo);
121✔
218

219
#if defined(BOTAN_HAS_GOST_28147_89)
220
   if(req.algo_name() == "GOST-28147-89") {
242✔
221
      return std::make_unique<GOST_28147_89>(req.arg(0, "R3411_94_TestParam"));
92✔
222
   }
223
#endif
224

225
#if defined(BOTAN_HAS_CASCADE)
226
   if(req.algo_name() == "Cascade" && req.arg_count() == 2) {
195✔
227
      auto c1 = BlockCipher::create(req.arg(0));
12✔
228
      auto c2 = BlockCipher::create(req.arg(1));
12✔
229

230
      if(c1 && c2)
12✔
231
         return std::make_unique<Cascade_Cipher>(std::move(c1), std::move(c2));
12✔
232
   }
12✔
233
#endif
234

235
#if defined(BOTAN_HAS_LION)
236
   if(req.algo_name() == "Lion" && req.arg_count_between(2, 3)) {
108✔
237
      auto hash = HashFunction::create(req.arg(0));
2✔
238
      auto stream = StreamCipher::create(req.arg(1));
2✔
239

240
      if(hash && stream) {
2✔
241
         const size_t block_size = req.arg_as_integer(2, 1024);
2✔
242
         return std::make_unique<Lion>(std::move(hash), std::move(stream), block_size);
2✔
243
      }
244
   }
2✔
245
#endif
246

247
   BOTAN_UNUSED(req);
51✔
248
   BOTAN_UNUSED(provider);
51✔
249

250
   return nullptr;
51✔
251
}
121✔
252

253
//static
254
std::unique_ptr<BlockCipher> BlockCipher::create_or_throw(std::string_view algo, std::string_view provider) {
2,569✔
255
   if(auto bc = BlockCipher::create(algo, provider)) {
2,569✔
256
      return bc;
2,569✔
257
   }
2,569✔
258
   throw Lookup_Error("Block cipher", algo, provider);
×
259
}
260

261
std::vector<std::string> BlockCipher::providers(std::string_view algo) {
185,672✔
262
   return probe_providers_of<BlockCipher>(algo, {"base", "commoncrypto"});
557,016✔
263
}
264

265
}
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

© 2025 Coveralls, Inc