Botan: src/engine/core_engine/lookup_block.cpp Source File

Botan 1.10.17

lookup_block.cpp
Go to the documentation of this file.
1 /*
2 * Block Cipher Lookup
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/internal/core_engine.h>
9 #include <botan/scan_name.h>
10 #include <botan/algo_factory.h>
11
12 #if defined(BOTAN_HAS_AES)
13 #include <botan/aes.h>
14 #endif
15
16 #if defined(BOTAN_HAS_BLOWFISH)
17 #include <botan/blowfish.h>
18 #endif
19
20 #if defined(BOTAN_HAS_CAMELLIA)
21 #include <botan/camellia.h>
22 #endif
23
24 #if defined(BOTAN_HAS_CAST)
25 #include <botan/cast128.h>
26 #include <botan/cast256.h>
27 #endif
28
29 #if defined(BOTAN_HAS_CASCADE)
30 #include <botan/cascade.h>
31 #endif
32
33 #if defined(BOTAN_HAS_DES)
34 #include <botan/des.h>
35 #include <botan/desx.h>
36 #endif
37
38 #if defined(BOTAN_HAS_GOST_28147_89)
39 #include <botan/gost_28147.h>
40 #endif
41
42 #if defined(BOTAN_HAS_IDEA)
43 #include <botan/idea.h>
44 #endif
45
46 #if defined(BOTAN_HAS_KASUMI)
47 #include <botan/kasumi.h>
48 #endif
49
50 #if defined(BOTAN_HAS_LION)
51 #include <botan/lion.h>
52 #endif
53
54 #if defined(BOTAN_HAS_LUBY_RACKOFF)
55 #include <botan/lubyrack.h>
56 #endif
57
58 #if defined(BOTAN_HAS_MARS)
59 #include <botan/mars.h>
60 #endif
61
62 #if defined(BOTAN_HAS_MISTY1)
63 #include <botan/misty1.h>
64 #endif
65
66 #if defined(BOTAN_HAS_NOEKEON)
67 #include <botan/noekeon.h>
68 #endif
69
70 #if defined(BOTAN_HAS_RC2)
71 #include <botan/rc2.h>
72 #endif
73
74 #if defined(BOTAN_HAS_RC5)
75 #include <botan/rc5.h>
76 #endif
77
78 #if defined(BOTAN_HAS_RC6)
79 #include <botan/rc6.h>
80 #endif
81
82 #if defined(BOTAN_HAS_SAFER)
83 #include <botan/safer_sk.h>
84 #endif
85
86 #if defined(BOTAN_HAS_SEED)
87 #include <botan/seed.h>
88 #endif
89
90 #if defined(BOTAN_HAS_SERPENT)
91 #include <botan/serpent.h>
92 #endif
93
94 #if defined(BOTAN_HAS_SKIPJACK)
95 #include <botan/skipjack.h>
96 #endif
97
98 #if defined(BOTAN_HAS_SQUARE)
99 #include <botan/square.h>
100 #endif
101
102 #if defined(BOTAN_HAS_TEA)
103 #include <botan/tea.h>
104 #endif
105
106 #if defined(BOTAN_HAS_TWOFISH)
107 #include <botan/twofish.h>
108 #endif
109
110 #if defined(BOTAN_HAS_XTEA)
111 #include <botan/xtea.h>
112 #endif
113
114 namespace Botan {
115
116 /*
117 * Look for an algorithm with this name
118 */
119 BlockCipher* Core_Engine::find_block_cipher(const SCAN_Name& request,
120 Algorithm_Factory& af) const
121 {
122
123 #if defined(BOTAN_HAS_AES)
124 if(request.algo_name() == "AES-128")
125 return new AES_128;
126 if(request.algo_name() == "AES-192")
127 return new AES_192;
128 if(request.algo_name() == "AES-256")
129 return new AES_256;
130 #endif
131
132 #if defined(BOTAN_HAS_BLOWFISH)
133 if(request.algo_name() == "Blowfish")
134 return new Blowfish;
135 #endif
136
137 #if defined(BOTAN_HAS_CAMELLIA)
138 if(request.algo_name() == "Camellia-128")
139 return new Camellia_128;
140 if(request.algo_name() == "Camellia-192")
141 return new Camellia_192;
142 if(request.algo_name() == "Camellia-256")
143 return new Camellia_256;
144 #endif
145
146 #if defined(BOTAN_HAS_CAST)
147 if(request.algo_name() == "CAST-128")
148 return new CAST_128;
149 if(request.algo_name() == "CAST-256")
150 return new CAST_256;
151 #endif
152
153 #if defined(BOTAN_HAS_DES)
154 if(request.algo_name() == "DES")
155 return new DES;
156 if(request.algo_name() == "DESX")
157 return new DESX;
158 if(request.algo_name() == "TripleDES")
159 return new TripleDES;
160 #endif
161
162 #if defined(BOTAN_HAS_GOST_28147_89)
163 if(request.algo_name() == "GOST-28147-89")
164 return new GOST_28147_89(request.arg(0, "R3411_94_TestParam"));
165 #endif
166
167 #if defined(BOTAN_HAS_IDEA)
168 if(request.algo_name() == "IDEA")
169 return new IDEA;
170 #endif
171
172 #if defined(BOTAN_HAS_KASUMI)
173 if(request.algo_name() == "KASUMI")
174 return new KASUMI;
175 #endif
176
177 #if defined(BOTAN_HAS_MARS)
178 if(request.algo_name() == "MARS")
179 return new MARS;
180 #endif
181
182 #if defined(BOTAN_HAS_MISTY1)
183 if(request.algo_name() == "MISTY1")
184 return new MISTY1(request.arg_as_integer(0, 8));
185 #endif
186
187 #if defined(BOTAN_HAS_NOEKEON)
188 if(request.algo_name() == "Noekeon")
189 return new Noekeon;
190 #endif
191
192 #if defined(BOTAN_HAS_RC2)
193 if(request.algo_name() == "RC2")
194 return new RC2;
195 #endif
196
197 #if defined(BOTAN_HAS_RC5)
198 if(request.algo_name() == "RC5")
199 return new RC5(request.arg_as_integer(0, 12));
200 #endif
201
202 #if defined(BOTAN_HAS_RC6)
203 if(request.algo_name() == "RC6")
204 return new RC6;
205 #endif
206
207 #if defined(BOTAN_HAS_SAFER)
208 if(request.algo_name() == "SAFER-SK")
209 return new SAFER_SK(request.arg_as_integer(0, 10));
210 #endif
211
212 #if defined(BOTAN_HAS_SEED)
213 if(request.algo_name() == "SEED")
214 return new SEED;
215 #endif
216
217 #if defined(BOTAN_HAS_SERPENT)
218 if(request.algo_name() == "Serpent")
219 return new Serpent;
220 #endif
221
222 #if defined(BOTAN_HAS_SKIPJACK)
223 if(request.algo_name() == "Skipjack")
224 return new Skipjack;
225 #endif
226
227 #if defined(BOTAN_HAS_SQUARE)
228 if(request.algo_name() == "Square")
229 return new Square;
230 #endif
231
232 #if defined(BOTAN_HAS_TEA)
233 if(request.algo_name() == "TEA")
234 return new TEA;
235 #endif
236
237 #if defined(BOTAN_HAS_TWOFISH)
238 if(request.algo_name() == "Twofish")
239 return new Twofish;
240 #endif
241
242 #if defined(BOTAN_HAS_XTEA)
243 if(request.algo_name() == "XTEA")
244 return new XTEA;
245 #endif
246
247 #if defined(BOTAN_HAS_LUBY_RACKOFF)
248 if(request.algo_name() == "Luby-Rackoff" && request.arg_count() == 1)
249 {
250 const HashFunction* hash = af.prototype_hash_function(request.arg(0));
251
252 if(hash)
253 return new LubyRackoff(hash->clone());
254 }
255 #endif
256
257 #if defined(BOTAN_HAS_CASCADE)
258 if(request.algo_name() == "Cascade" && request.arg_count() == 2)
259 {
260 const BlockCipher* c1 = af.prototype_block_cipher(request.arg(0));
261 const BlockCipher* c2 = af.prototype_block_cipher(request.arg(1));
262
263 if(c1 && c2)
264 return new Cascade_Cipher(c1->clone(), c2->clone());
265 }
266 #endif
267
268 #if defined(BOTAN_HAS_LION)
269 if(request.algo_name() == "Lion" && request.arg_count_between(2, 3))
270 {
271 const size_t block_size = request.arg_as_integer(2, 1024);
272
273 const HashFunction* hash =
274 af.prototype_hash_function(request.arg(0));
275
276 const StreamCipher* stream_cipher =
277 af.prototype_stream_cipher(request.arg(1));
278
279 if(!hash || !stream_cipher)
280 return 0;
281
282 return new Lion(hash->clone(), stream_cipher->clone(), block_size);
283 }
284 #endif
285
286 return 0;
287 }
288
289 }
Botan::XTEA
Definition: xtea.h:18
Botan::CAST_128
Definition: cast128.h:18
Botan::Camellia_256
Definition: camellia.h:54
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47
Botan::SEED
Definition: seed.h:18
Botan::GOST_28147_89
Definition: gost_28147.h:52
Botan::SCAN_Name::arg_as_integer
size_t arg_as_integer(size_t i, size_t def_value) const
Definition: scan_name.cpp:167
Botan::AES_128
Definition: aes.h:18
Botan::BlockCipher::clone
virtual BlockCipher * clone() const =0
Botan::Algorithm_Factory::prototype_block_cipher
const BlockCipher * prototype_block_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:193
Botan::Camellia_128
Definition: camellia.h:18
Botan::IDEA
Definition: idea.h:18
Botan::HashFunction::clone
virtual HashFunction * clone() const =0
Botan::Serpent
Definition: serpent.h:18
Botan::Skipjack
Definition: skipjack.h:18
Botan::Algorithm_Factory::prototype_hash_function
const HashFunction * prototype_hash_function(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:215
Botan::MISTY1
Definition: misty1.h:18
Botan::Twofish
Definition: twofish.h:18
Botan::AES_192
Definition: aes.h:40
Botan::SAFER_SK
Definition: safer_sk.h:18
Botan::Camellia_192
Definition: camellia.h:36
Botan::StreamCipher
Definition: stream_cipher.h:18
Botan::Lion
Definition: lion.h:25
Botan::KASUMI
Definition: kasumi.h:18
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:153
Botan::Cascade_Cipher
Definition: cascade.h:18
Botan::LubyRackoff
Definition: lubyrack.h:19
Botan::TEA
Definition: tea.h:18
Botan
Definition: algo_base.h:14
Botan::MARS
Definition: mars.h:18
Botan::SCAN_Name
Definition: scan_name.h:21
Botan::Square
Definition: square.h:18
Botan::HashFunction
Definition: hash.h:20
Botan::RC2
Definition: rc2.h:18
Botan::StreamCipher::clone
virtual StreamCipher * clone() const =0
Botan::DESX
Definition: desx.h:18
Botan::SCAN_Name::arg_count_between
bool arg_count_between(size_t lower, size_t upper) const
Definition: scan_name.h:54
Botan::AES_256
Definition: aes.h:62
Botan::Blowfish
Definition: blowfish.h:18
Botan::DES
Definition: des.h:18
Botan::TripleDES
Definition: des.h:38
Botan::Core_Engine::find_block_cipher
BlockCipher * find_block_cipher(const SCAN_Name &, Algorithm_Factory &) const
Definition: lookup_block.cpp:119
Botan::SCAN_Name::algo_name
std::string algo_name() const
Definition: scan_name.h:37
Botan::Noekeon
Definition: noekeon.h:18
Botan::Algorithm_Factory::prototype_stream_cipher
const StreamCipher * prototype_stream_cipher(const std::string &algo_spec, const std::string &provider="")
Definition: algo_factory.cpp:204
Botan::BlockCipher
Definition: block_cipher.h:18
Botan::CAST_256
Definition: cast256.h:18