Botan 1.10.17

lookup_hash.cpp
Go to the documentation of this file.
1 /*
2 * Hash Algorithms 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 #include <memory>
12
13 #if defined(BOTAN_HAS_ADLER32)
14 #include <botan/adler32.h>
15 #endif
16
17 #if defined(BOTAN_HAS_CRC24)
18 #include <botan/crc24.h>
19 #endif
20
21 #if defined(BOTAN_HAS_CRC32)
22 #include <botan/crc32.h>
23 #endif
24
25 #if defined(BOTAN_HAS_BMW_512)
26 #include <botan/bmw_512.h>
27 #endif
28
29 #if defined(BOTAN_HAS_GOST_34_11)
30 #include <botan/gost_3411.h>
31 #endif
32
33 #if defined(BOTAN_HAS_HAS_160)
34 #include <botan/has160.h>
35 #endif
36
37 #if defined(BOTAN_HAS_KECCAK)
38 #include <botan/keccak.h>
39 #endif
40
41 #if defined(BOTAN_HAS_MD2)
42 #include <botan/md2.h>
43 #endif
44
45 #if defined(BOTAN_HAS_MD4)
46 #include <botan/md4.h>
47 #endif
48
49 #if defined(BOTAN_HAS_MD5)
50 #include <botan/md5.h>
51 #endif
52
53 #if defined(BOTAN_HAS_RIPEMD_128)
54 #include <botan/rmd128.h>
55 #endif
56
57 #if defined(BOTAN_HAS_RIPEMD_160)
58 #include <botan/rmd160.h>
59 #endif
60
61 #if defined(BOTAN_HAS_SHA1)
62 #include <botan/sha160.h>
63 #endif
64
65 #if defined(BOTAN_HAS_SHA2_32)
66 #include <botan/sha2_32.h>
67 #endif
68
69 #if defined(BOTAN_HAS_SHA2_64)
70 #include <botan/sha2_64.h>
71 #endif
72
73 #if defined(BOTAN_HAS_SKEIN_512)
74 #include <botan/skein_512.h>
75 #endif
76
77 #if defined(BOTAN_HAS_TIGER)
78 #include <botan/tiger.h>
79 #endif
80
81 #if defined(BOTAN_HAS_WHIRLPOOL)
82 #include <botan/whrlpool.h>
83 #endif
84
85 #if defined(BOTAN_HAS_PARALLEL_HASH)
86 #include <botan/par_hash.h>
87 #endif
88
89 #if defined(BOTAN_HAS_COMB4P)
90 #include <botan/comb4p.h>
91 #endif
92
93 namespace Botan {
94
95 /*
96 * Look for an algorithm with this name
97 */
98 HashFunction* Core_Engine::find_hash(const SCAN_Name& request,
99 Algorithm_Factory& af) const
100 {
101 #if defined(BOTAN_HAS_ADLER32)
102 if(request.algo_name() == "Adler32")
103 return new Adler32;
104 #endif
105
106 #if defined(BOTAN_HAS_CRC24)
107 if(request.algo_name() == "CRC24")
108 return new CRC24;
109 #endif
110
111 #if defined(BOTAN_HAS_CRC32)
112 if(request.algo_name() == "CRC32")
113 return new CRC32;
114 #endif
115
116 #if defined(BOTAN_HAS_BMW_512)
117 if(request.algo_name() == "BMW-512")
118 return new BMW_512;
119 #endif
120
121 #if defined(BOTAN_HAS_GOST_34_11)
122 if(request.algo_name() == "GOST-34.11")
123 return new GOST_34_11;
124 #endif
125
126 #if defined(BOTAN_HAS_HAS_160)
127 if(request.algo_name() == "HAS-160")
128 return new HAS_160;
129 #endif
130
131 #if defined(BOTAN_HAS_KECCAK)
132 if(request.algo_name() == "Keccak-1600")
133 return new Keccak_1600(request.arg_as_integer(0, 512));
134 #endif
135
136 #if defined(BOTAN_HAS_MD2)
137 if(request.algo_name() == "MD2")
138 return new MD2;
139 #endif
140
141 #if defined(BOTAN_HAS_MD4)
142 if(request.algo_name() == "MD4")
143 return new MD4;
144 #endif
145
146 #if defined(BOTAN_HAS_MD5)
147 if(request.algo_name() == "MD5")
148 return new MD5;
149 #endif
150
151 #if defined(BOTAN_HAS_RIPEMD_128)
152 if(request.algo_name() == "RIPEMD-128")
153 return new RIPEMD_128;
154 #endif
155
156 #if defined(BOTAN_HAS_RIPEMD_160)
157 if(request.algo_name() == "RIPEMD-160")
158 return new RIPEMD_160;
159 #endif
160
161 #if defined(BOTAN_HAS_SHA1)
162 if(request.algo_name() == "SHA-160")
163 return new SHA_160;
164 #endif
165
166 #if defined(BOTAN_HAS_SHA2_32)
167 if(request.algo_name() == "SHA-224")
168 return new SHA_224;
169 if(request.algo_name() == "SHA-256")
170 return new SHA_256;
171 #endif
172
173 #if defined(BOTAN_HAS_SHA2_64)
174 if(request.algo_name() == "SHA-384")
175 return new SHA_384;
176 if(request.algo_name() == "SHA-512")
177 return new SHA_512;
178 #endif
179
180 #if defined(BOTAN_HAS_TIGER)
181 if(request.algo_name() == "Tiger")
182 return new Tiger(request.arg_as_integer(0, 24), // hash output
183 request.arg_as_integer(1, 3)); // # passes
184 #endif
185
186 #if defined(BOTAN_HAS_SKEIN_512)
187 if(request.algo_name() == "Skein-512")
188 return new Skein_512(request.arg_as_integer(0, 512),
189 request.arg(1, ""));
190 #endif
191
192 #if defined(BOTAN_HAS_WHIRLPOOL)
193 if(request.algo_name() == "Whirlpool")
194 return new Whirlpool;
195 #endif
196
197 #if defined(BOTAN_HAS_COMB4P)
198 if(request.algo_name() == "Comb4P" && request.arg_count() == 2)
199 {
200 const HashFunction* h1 = af.prototype_hash_function(request.arg(0));
201 const HashFunction* h2 = af.prototype_hash_function(request.arg(1));
202
203 if(h1 && h2)
204 return new Comb4P(h1->clone(), h2->clone());
205 }
206 #endif
207
208 #if defined(BOTAN_HAS_PARALLEL_HASH)
209
210 if(request.algo_name() == "Parallel")
211 {
212 std::vector<const HashFunction*> hash_prototypes;
213
214 /* First pass, just get the prototypes (no memory allocation). Then
215 if all were found, replace each prototype with a newly created clone
216 */
217 for(size_t i = 0; i != request.arg_count(); ++i)
218 {
219 const HashFunction* hash = af.prototype_hash_function(request.arg(i));
220 if(!hash)
221 return 0;
222
223 hash_prototypes.push_back(hash);
224 }
225
226 std::vector<HashFunction*> hashes;
227 for(size_t i = 0; i != hash_prototypes.size(); ++i)
228 hashes.push_back(hash_prototypes[i]->clone());
229
230 return new Parallel(hashes);
231 }
232
233 #endif
234
235 return 0;
236 }
237
238 }
Botan::Adler32
Definition: adler32.h:18
Botan::Algorithm_Factory
Definition: algo_factory.h:34
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47
Botan::Tiger
Definition: tiger.h:18
Botan::RIPEMD_160
Definition: rmd160.h:18
Botan::MD4
Definition: md4.h:18
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::RIPEMD_128
Definition: rmd128.h:18
Botan::HashFunction::clone
virtual HashFunction * clone() const =0
Botan::MD2
Definition: md2.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::SHA_224
Definition: sha2_32.h:19
Botan::Skein_512
Definition: skein_512.h:20
Botan::CRC32
Definition: crc32.h:18
Botan::GOST_34_11
Definition: gost_3411.h:19
Botan::CRC24
Definition: crc24.h:18
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:153
Botan::MD5
Definition: md5.h:18
Botan::SHA_160
Definition: sha160.h:18
Botan
Definition: algo_base.h:14
Botan::BMW_512
Definition: bmw_512.h:18
Botan::Whirlpool
Definition: whrlpool.h:18
Botan::SCAN_Name
Definition: scan_name.h:21
Botan::HashFunction
Definition: hash.h:20
Botan::HAS_160
Definition: has160.h:19
Botan::Parallel
Definition: par_hash.h:19
Botan::Comb4P
Definition: comb4p.h:19
Botan::SHA_384
Definition: sha2_64.h:18
Botan::SHA_256
Definition: sha2_32.h:40
Botan::SHA_512
Definition: sha2_64.h:39
Botan::SCAN_Name::algo_name
std::string algo_name() const
Definition: scan_name.h:37
Botan::Keccak_1600
Definition: keccak.h:20
Botan::Core_Engine::find_hash
HashFunction * find_hash(const SCAN_Name &request, Algorithm_Factory &) const
Definition: lookup_hash.cpp:98