10#include <botan/exceptn.h>
11#include <botan/internal/scan_name.h>
13#if defined(BOTAN_HAS_ADLER32)
14 #include <botan/internal/adler32.h>
17#if defined(BOTAN_HAS_CRC24)
18 #include <botan/internal/crc24.h>
21#if defined(BOTAN_HAS_CRC32)
22 #include <botan/internal/crc32.h>
25#if defined(BOTAN_HAS_GOST_34_11)
26 #include <botan/internal/gost_3411.h>
29#if defined(BOTAN_HAS_KECCAK)
30 #include <botan/internal/keccak.h>
33#if defined(BOTAN_HAS_MD4)
34 #include <botan/internal/md4.h>
37#if defined(BOTAN_HAS_MD5)
38 #include <botan/internal/md5.h>
41#if defined(BOTAN_HAS_RIPEMD_160)
42 #include <botan/internal/rmd160.h>
45#if defined(BOTAN_HAS_SHA1)
46 #include <botan/internal/sha1.h>
49#if defined(BOTAN_HAS_SHA2_32)
50 #include <botan/internal/sha2_32.h>
53#if defined(BOTAN_HAS_SHA2_64)
54 #include <botan/internal/sha2_64.h>
57#if defined(BOTAN_HAS_SHA3)
58 #include <botan/internal/sha3.h>
61#if defined(BOTAN_HAS_SHAKE)
62 #include <botan/internal/shake.h>
65#if defined(BOTAN_HAS_SKEIN_512)
66 #include <botan/internal/skein_512.h>
69#if defined(BOTAN_HAS_STREEBOG)
70 #include <botan/internal/streebog.h>
73#if defined(BOTAN_HAS_SM3)
74 #include <botan/internal/sm3.h>
77#if defined(BOTAN_HAS_WHIRLPOOL)
78 #include <botan/internal/whrlpool.h>
81#if defined(BOTAN_HAS_PARALLEL_HASH)
82 #include <botan/internal/par_hash.h>
85#if defined(BOTAN_HAS_TRUNCATED_HASH)
86 #include <botan/internal/trunc_hash.h>
89#if defined(BOTAN_HAS_COMB4P)
90 #include <botan/internal/comb4p.h>
93#if defined(BOTAN_HAS_BLAKE2B)
94 #include <botan/internal/blake2b.h>
97#if defined(BOTAN_HAS_COMMONCRYPTO)
98 #include <botan/internal/commoncrypto.h>
104#if defined(BOTAN_HAS_COMMONCRYPTO)
118#if defined(BOTAN_HAS_SHA1)
119 if(algo_spec ==
"SHA-1") {
120 return std::make_unique<SHA_1>();
124#if defined(BOTAN_HAS_SHA2_32)
125 if(algo_spec ==
"SHA-224") {
126 return std::make_unique<SHA_224>();
129 if(algo_spec ==
"SHA-256") {
130 return std::make_unique<SHA_256>();
134#if defined(BOTAN_HAS_SHA2_64)
135 if(algo_spec ==
"SHA-384") {
136 return std::make_unique<SHA_384>();
139 if(algo_spec ==
"SHA-512") {
140 return std::make_unique<SHA_512>();
143 if(algo_spec ==
"SHA-512-256") {
144 return std::make_unique<SHA_512_256>();
148#if defined(BOTAN_HAS_RIPEMD_160)
149 if(algo_spec ==
"RIPEMD-160") {
150 return std::make_unique<RIPEMD_160>();
154#if defined(BOTAN_HAS_WHIRLPOOL)
155 if(algo_spec ==
"Whirlpool") {
156 return std::make_unique<Whirlpool>();
160#if defined(BOTAN_HAS_MD5)
161 if(algo_spec ==
"MD5") {
162 return std::make_unique<MD5>();
166#if defined(BOTAN_HAS_MD4)
167 if(algo_spec ==
"MD4") {
168 return std::make_unique<MD4>();
172#if defined(BOTAN_HAS_GOST_34_11)
173 if(algo_spec ==
"GOST-R-34.11-94" || algo_spec ==
"GOST-34.11") {
174 return std::make_unique<GOST_34_11>();
178#if defined(BOTAN_HAS_ADLER32)
179 if(algo_spec ==
"Adler32") {
180 return std::make_unique<Adler32>();
184#if defined(BOTAN_HAS_CRC24)
185 if(algo_spec ==
"CRC24") {
186 return std::make_unique<CRC24>();
190#if defined(BOTAN_HAS_CRC32)
191 if(algo_spec ==
"CRC32") {
192 return std::make_unique<CRC32>();
196#if defined(BOTAN_HAS_STREEBOG)
197 if(algo_spec ==
"Streebog-256") {
198 return std::make_unique<Streebog>(256);
200 if(algo_spec ==
"Streebog-512") {
201 return std::make_unique<Streebog>(512);
205#if defined(BOTAN_HAS_SM3)
206 if(algo_spec ==
"SM3") {
207 return std::make_unique<SM3>();
213#if defined(BOTAN_HAS_SKEIN_512)
219#if defined(BOTAN_HAS_BLAKE2B)
225#if defined(BOTAN_HAS_KECCAK)
231#if defined(BOTAN_HAS_SHA3)
237#if defined(BOTAN_HAS_SHAKE)
246#if defined(BOTAN_HAS_PARALLEL_HASH)
248 std::vector<std::unique_ptr<HashFunction>> hashes;
250 for(
size_t i = 0; i != req.
arg_count(); ++i) {
255 hashes.push_back(std::move(h));
258 return std::make_unique<Parallel>(hashes);
262#if defined(BOTAN_HAS_TRUNCATED_HASH)
269 return std::make_unique<Truncated_Hash>(std::move(hash), req.
arg_as_integer(1));
273#if defined(BOTAN_HAS_COMB4P)
279 return std::make_unique<Comb4P>(std::move(h1), std::move(h2));
296 return probe_providers_of<HashFunction>(algo_spec, {
"base",
"commoncrypto"});
static std::vector< std::string > providers(std::string_view algo_spec)
virtual std::string provider() const
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
std::string arg(size_t i) const
const std::string algo_name() const
size_t arg_as_integer(size_t i, size_t def_value) const
std::unique_ptr< HashFunction > make_commoncrypto_hash(std::string_view name)