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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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,508✔
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") {
715,932✔
103
      return nullptr;
512,508✔
104
   }
105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

218
   const SCAN_Name req(algo);
121✔
219

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

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

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

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

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

249
   BOTAN_UNUSED(req);
51✔
250
   BOTAN_UNUSED(provider);
51✔
251

252
   return nullptr;
51✔
253
}
121✔
254

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

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

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

© 2025 Coveralls, Inc