8 #include <botan/hash.h>
9 #include <botan/scan_name.h>
10 #include <botan/exceptn.h>
12 #if defined(BOTAN_HAS_ADLER32)
13 #include <botan/adler32.h>
16 #if defined(BOTAN_HAS_CRC24)
17 #include <botan/crc24.h>
20 #if defined(BOTAN_HAS_CRC32)
21 #include <botan/crc32.h>
24 #if defined(BOTAN_HAS_GOST_34_11)
25 #include <botan/gost_3411.h>
28 #if defined(BOTAN_HAS_KECCAK)
29 #include <botan/keccak.h>
32 #if defined(BOTAN_HAS_MD4)
33 #include <botan/md4.h>
36 #if defined(BOTAN_HAS_MD5)
37 #include <botan/md5.h>
40 #if defined(BOTAN_HAS_RIPEMD_160)
41 #include <botan/rmd160.h>
44 #if defined(BOTAN_HAS_SHA1)
45 #include <botan/sha160.h>
48 #if defined(BOTAN_HAS_SHA2_32)
49 #include <botan/sha2_32.h>
52 #if defined(BOTAN_HAS_SHA2_64)
53 #include <botan/sha2_64.h>
56 #if defined(BOTAN_HAS_SHA3)
57 #include <botan/sha3.h>
60 #if defined(BOTAN_HAS_SHAKE)
61 #include <botan/shake.h>
64 #if defined(BOTAN_HAS_SKEIN_512)
65 #include <botan/skein_512.h>
68 #if defined(BOTAN_HAS_STREEBOG)
69 #include <botan/streebog.h>
72 #if defined(BOTAN_HAS_SM3)
73 #include <botan/sm3.h>
76 #if defined(BOTAN_HAS_TIGER)
77 #include <botan/tiger.h>
80 #if defined(BOTAN_HAS_WHIRLPOOL)
81 #include <botan/whrlpool.h>
84 #if defined(BOTAN_HAS_PARALLEL_HASH)
85 #include <botan/par_hash.h>
88 #if defined(BOTAN_HAS_COMB4P)
89 #include <botan/comb4p.h>
92 #if defined(BOTAN_HAS_BLAKE2B)
93 #include <botan/blake2b.h>
96 #if defined(BOTAN_HAS_OPENSSL)
97 #include <botan/internal/openssl.h>
100 #if defined(BOTAN_HAS_COMMONCRYPTO)
101 #include <botan/internal/commoncrypto.h>
107 const std::string& provider)
110 #if defined(BOTAN_HAS_COMMONCRYPTO)
111 if(provider.empty() || provider ==
"commoncrypto")
116 if(!provider.empty())
121 #if defined(BOTAN_HAS_OPENSSL)
122 if(provider.empty() || provider ==
"openssl")
127 if(!provider.empty())
132 if(provider.empty() ==
false && provider !=
"base")
135 #if defined(BOTAN_HAS_SHA1)
136 if(algo_spec ==
"SHA-160" ||
137 algo_spec ==
"SHA-1" ||
140 return std::unique_ptr<HashFunction>(
new SHA_160);
144 #if defined(BOTAN_HAS_SHA2_32)
145 if(algo_spec ==
"SHA-224")
147 return std::unique_ptr<HashFunction>(
new SHA_224);
150 if(algo_spec ==
"SHA-256")
152 return std::unique_ptr<HashFunction>(
new SHA_256);
156 #if defined(BOTAN_HAS_SHA2_64)
157 if(algo_spec ==
"SHA-384")
159 return std::unique_ptr<HashFunction>(
new SHA_384);
162 if(algo_spec ==
"SHA-512")
164 return std::unique_ptr<HashFunction>(
new SHA_512);
167 if(algo_spec ==
"SHA-512-256")
169 return std::unique_ptr<HashFunction>(
new SHA_512_256);
173 #if defined(BOTAN_HAS_RIPEMD_160)
174 if(algo_spec ==
"RIPEMD-160")
176 return std::unique_ptr<HashFunction>(
new RIPEMD_160);
180 #if defined(BOTAN_HAS_WHIRLPOOL)
181 if(algo_spec ==
"Whirlpool")
183 return std::unique_ptr<HashFunction>(
new Whirlpool);
187 #if defined(BOTAN_HAS_MD5)
188 if(algo_spec ==
"MD5")
190 return std::unique_ptr<HashFunction>(
new MD5);
194 #if defined(BOTAN_HAS_MD4)
195 if(algo_spec ==
"MD4")
197 return std::unique_ptr<HashFunction>(
new MD4);
201 #if defined(BOTAN_HAS_GOST_34_11)
202 if(algo_spec ==
"GOST-R-34.11-94" || algo_spec ==
"GOST-34.11")
204 return std::unique_ptr<HashFunction>(
new GOST_34_11);
208 #if defined(BOTAN_HAS_ADLER32)
209 if(algo_spec ==
"Adler32")
211 return std::unique_ptr<HashFunction>(
new Adler32);
215 #if defined(BOTAN_HAS_CRC24)
216 if(algo_spec ==
"CRC24")
218 return std::unique_ptr<HashFunction>(
new CRC24);
222 #if defined(BOTAN_HAS_CRC32)
223 if(algo_spec ==
"CRC32")
225 return std::unique_ptr<HashFunction>(
new CRC32);
231 #if defined(BOTAN_HAS_TIGER)
234 return std::unique_ptr<HashFunction>(
240 #if defined(BOTAN_HAS_SKEIN_512)
243 return std::unique_ptr<HashFunction>(
248 #if defined(BOTAN_HAS_BLAKE2B)
251 return std::unique_ptr<HashFunction>(
256 #if defined(BOTAN_HAS_KECCAK)
259 return std::unique_ptr<HashFunction>(
264 #if defined(BOTAN_HAS_SHA3)
267 return std::unique_ptr<HashFunction>(
272 #if defined(BOTAN_HAS_SHAKE)
283 #if defined(BOTAN_HAS_STREEBOG)
284 if(algo_spec ==
"Streebog-256")
288 if(algo_spec ==
"Streebog-512")
294 #if defined(BOTAN_HAS_SM3)
295 if(algo_spec ==
"SM3")
297 return std::unique_ptr<HashFunction>(
new SM3);
301 #if defined(BOTAN_HAS_WHIRLPOOL)
304 return std::unique_ptr<HashFunction>(
new Whirlpool);
308 #if defined(BOTAN_HAS_PARALLEL_HASH)
311 std::vector<std::unique_ptr<HashFunction>> hashes;
313 for(
size_t i = 0; i != req.
arg_count(); ++i)
320 hashes.push_back(std::move(h));
323 return std::unique_ptr<HashFunction>(
new Parallel(hashes));
327 #if defined(BOTAN_HAS_COMB4P)
334 return std::unique_ptr<HashFunction>(
new Comb4P(h1.release(), h2.release()));
343 std::unique_ptr<HashFunction>
345 const std::string& provider)
356 return probe_providers_of<HashFunction>(algo_spec, {
"base",
"openssl",
"commoncrypto"});
std::string arg(size_t i) const
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
std::unique_ptr< HashFunction > make_openssl_hash(const std::string &name)
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
static std::vector< std::string > providers(const std::string &algo_spec)
std::unique_ptr< HashFunction > make_commoncrypto_hash(const std::string &name)
const std::string & algo_name() const