8 #include <botan/block_cipher.h>
9 #include <botan/scan_name.h>
10 #include <botan/exceptn.h>
12 #if defined(BOTAN_HAS_AES)
13 #include <botan/aes.h>
16 #if defined(BOTAN_HAS_ARIA)
17 #include <botan/aria.h>
20 #if defined(BOTAN_HAS_BLOWFISH)
21 #include <botan/blowfish.h>
24 #if defined(BOTAN_HAS_CAMELLIA)
25 #include <botan/camellia.h>
28 #if defined(BOTAN_HAS_CAST_128)
29 #include <botan/cast128.h>
32 #if defined(BOTAN_HAS_CAST_256)
33 #include <botan/cast256.h>
36 #if defined(BOTAN_HAS_CASCADE)
37 #include <botan/cascade.h>
40 #if defined(BOTAN_HAS_DES)
41 #include <botan/des.h>
42 #include <botan/desx.h>
45 #if defined(BOTAN_HAS_GOST_28147_89)
46 #include <botan/gost_28147.h>
49 #if defined(BOTAN_HAS_IDEA)
50 #include <botan/idea.h>
53 #if defined(BOTAN_HAS_KASUMI)
54 #include <botan/kasumi.h>
57 #if defined(BOTAN_HAS_LION)
58 #include <botan/lion.h>
61 #if defined(BOTAN_HAS_MISTY1)
62 #include <botan/misty1.h>
65 #if defined(BOTAN_HAS_NOEKEON)
66 #include <botan/noekeon.h>
69 #if defined(BOTAN_HAS_SEED)
70 #include <botan/seed.h>
73 #if defined(BOTAN_HAS_SERPENT)
74 #include <botan/serpent.h>
77 #if defined(BOTAN_HAS_SHACAL2)
78 #include <botan/shacal2.h>
81 #if defined(BOTAN_HAS_SM4)
82 #include <botan/sm4.h>
85 #if defined(BOTAN_HAS_TWOFISH)
86 #include <botan/twofish.h>
89 #if defined(BOTAN_HAS_THREEFISH_512)
90 #include <botan/threefish_512.h>
93 #if defined(BOTAN_HAS_XTEA)
94 #include <botan/xtea.h>
97 #if defined(BOTAN_HAS_OPENSSL)
98 #include <botan/internal/openssl.h>
101 #if defined(BOTAN_HAS_COMMONCRYPTO)
102 #include <botan/internal/commoncrypto.h>
107 std::unique_ptr<BlockCipher>
109 const std::string& provider)
111 #if defined(BOTAN_HAS_COMMONCRYPTO)
112 if(provider.empty() || provider ==
"commoncrypto")
117 if(!provider.empty())
122 #if defined(BOTAN_HAS_OPENSSL)
123 if(provider.empty() || provider ==
"openssl")
128 if(!provider.empty())
137 if(provider.empty() ==
false && provider !=
"base")
140 #if defined(BOTAN_HAS_AES)
141 if(algo ==
"AES-128")
143 return std::unique_ptr<BlockCipher>(
new AES_128);
146 if(algo ==
"AES-192")
148 return std::unique_ptr<BlockCipher>(
new AES_192);
151 if(algo ==
"AES-256")
153 return std::unique_ptr<BlockCipher>(
new AES_256);
157 #if defined(BOTAN_HAS_ARIA)
158 if(algo ==
"ARIA-128")
160 return std::unique_ptr<BlockCipher>(
new ARIA_128);
163 if(algo ==
"ARIA-192")
165 return std::unique_ptr<BlockCipher>(
new ARIA_192);
168 if(algo ==
"ARIA-256")
170 return std::unique_ptr<BlockCipher>(
new ARIA_256);
174 #if defined(BOTAN_HAS_SERPENT)
175 if(algo ==
"Serpent")
177 return std::unique_ptr<BlockCipher>(
new Serpent);
181 #if defined(BOTAN_HAS_SHACAL2)
182 if(algo ==
"SHACAL2")
184 return std::unique_ptr<BlockCipher>(
new SHACAL2);
188 #if defined(BOTAN_HAS_TWOFISH)
189 if(algo ==
"Twofish")
191 return std::unique_ptr<BlockCipher>(
new Twofish);
195 #if defined(BOTAN_HAS_THREEFISH_512)
196 if(algo ==
"Threefish-512")
202 #if defined(BOTAN_HAS_BLOWFISH)
203 if(algo ==
"Blowfish")
205 return std::unique_ptr<BlockCipher>(
new Blowfish);
209 #if defined(BOTAN_HAS_CAMELLIA)
210 if(algo ==
"Camellia-128")
215 if(algo ==
"Camellia-192")
220 if(algo ==
"Camellia-256")
226 #if defined(BOTAN_HAS_DES)
229 return std::unique_ptr<BlockCipher>(
new DES);
234 return std::unique_ptr<BlockCipher>(
new DESX);
237 if(algo ==
"TripleDES" || algo ==
"3DES" || algo ==
"DES-EDE")
239 return std::unique_ptr<BlockCipher>(
new TripleDES);
243 #if defined(BOTAN_HAS_NOEKEON)
244 if(algo ==
"Noekeon")
246 return std::unique_ptr<BlockCipher>(
new Noekeon);
250 #if defined(BOTAN_HAS_CAST_128)
251 if(algo ==
"CAST-128" || algo ==
"CAST5")
253 return std::unique_ptr<BlockCipher>(
new CAST_128);
257 #if defined(BOTAN_HAS_CAST_256)
258 if(algo ==
"CAST-256")
260 return std::unique_ptr<BlockCipher>(
new CAST_256);
264 #if defined(BOTAN_HAS_IDEA)
267 return std::unique_ptr<BlockCipher>(
new IDEA);
271 #if defined(BOTAN_HAS_KASUMI)
274 return std::unique_ptr<BlockCipher>(
new KASUMI);
278 #if defined(BOTAN_HAS_MISTY1)
281 return std::unique_ptr<BlockCipher>(
new MISTY1);
285 #if defined(BOTAN_HAS_SEED)
288 return std::unique_ptr<BlockCipher>(
new SEED);
292 #if defined(BOTAN_HAS_SM4)
295 return std::unique_ptr<BlockCipher>(
new SM4);
299 #if defined(BOTAN_HAS_XTEA)
302 return std::unique_ptr<BlockCipher>(
new XTEA);
308 #if defined(BOTAN_HAS_GOST_28147_89)
311 return std::unique_ptr<BlockCipher>(
new GOST_28147_89(req.
arg(0,
"R3411_94_TestParam")));
315 #if defined(BOTAN_HAS_CASCADE)
322 return std::unique_ptr<BlockCipher>(
new Cascade_Cipher(c1.release(), c2.release()));
326 #if defined(BOTAN_HAS_LION)
335 return std::unique_ptr<BlockCipher>(
new Lion(hash.release(), stream.release(),
block_size));
347 std::unique_ptr<BlockCipher>
349 const std::string& provider)
360 return probe_providers_of<BlockCipher>(algo, {
"base",
"openssl",
"commoncrypto" });
std::string arg(size_t i) const
std::unique_ptr< BlockCipher > make_commoncrypto_block_cipher(const std::string &name)
static std::vector< std::string > providers(const std::string &algo_spec)
bool arg_count_between(size_t lower, size_t upper) const
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
size_t arg_as_integer(size_t i, size_t def_value) const
#define BOTAN_UNUSED(...)
static std::unique_ptr< BlockCipher > create_or_throw(const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
const std::string & algo_name() const
static std::unique_ptr< StreamCipher > create(const std::string &algo_spec, const std::string &provider="")
std::unique_ptr< BlockCipher > make_openssl_block_cipher(const std::string &name)
virtual size_t block_size() const =0