Create an instance based on a name, or return null if the algo/provider combination cannot be found. If provider is empty then best available is chosen.
103 {
104#if defined(BOTAN_HAS_COMMONCRYPTO)
107 return hash;
108
110 return nullptr;
111 }
112#endif
113
115 return nullptr;
116 }
117
118#if defined(BOTAN_HAS_SHA1)
119 if(algo_spec == "SHA-1") {
120 return std::make_unique<SHA_1>();
121 }
122#endif
123
124#if defined(BOTAN_HAS_SHA2_32)
125 if(algo_spec == "SHA-224") {
126 return std::make_unique<SHA_224>();
127 }
128
129 if(algo_spec == "SHA-256") {
130 return std::make_unique<SHA_256>();
131 }
132#endif
133
134#if defined(BOTAN_HAS_SHA2_64)
135 if(algo_spec == "SHA-384") {
136 return std::make_unique<SHA_384>();
137 }
138
139 if(algo_spec == "SHA-512") {
140 return std::make_unique<SHA_512>();
141 }
142
143 if(algo_spec == "SHA-512-256") {
144 return std::make_unique<SHA_512_256>();
145 }
146#endif
147
148#if defined(BOTAN_HAS_RIPEMD_160)
149 if(algo_spec == "RIPEMD-160") {
150 return std::make_unique<RIPEMD_160>();
151 }
152#endif
153
154#if defined(BOTAN_HAS_WHIRLPOOL)
155 if(algo_spec == "Whirlpool") {
156 return std::make_unique<Whirlpool>();
157 }
158#endif
159
160#if defined(BOTAN_HAS_MD5)
161 if(algo_spec == "MD5") {
162 return std::make_unique<MD5>();
163 }
164#endif
165
166#if defined(BOTAN_HAS_MD4)
167 if(algo_spec == "MD4") {
168 return std::make_unique<MD4>();
169 }
170#endif
171
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>();
175 }
176#endif
177
178#if defined(BOTAN_HAS_ADLER32)
179 if(algo_spec == "Adler32") {
180 return std::make_unique<Adler32>();
181 }
182#endif
183
184#if defined(BOTAN_HAS_CRC24)
185 if(algo_spec == "CRC24") {
186 return std::make_unique<CRC24>();
187 }
188#endif
189
190#if defined(BOTAN_HAS_CRC32)
191 if(algo_spec == "CRC32") {
192 return std::make_unique<CRC32>();
193 }
194#endif
195
196#if defined(BOTAN_HAS_STREEBOG)
197 if(algo_spec == "Streebog-256") {
198 return std::make_unique<Streebog>(256);
199 }
200 if(algo_spec == "Streebog-512") {
201 return std::make_unique<Streebog>(512);
202 }
203#endif
204
205#if defined(BOTAN_HAS_SM3)
206 if(algo_spec == "SM3") {
207 return std::make_unique<SM3>();
208 }
209#endif
210
211 const SCAN_Name req(algo_spec);
212
213#if defined(BOTAN_HAS_SKEIN_512)
214 if(req.algo_name() == "Skein-512") {
215 return std::make_unique<Skein_512>(req.arg_as_integer(0, 512), req.arg(1, ""));
216 }
217#endif
218
219#if defined(BOTAN_HAS_BLAKE2B)
220 if(req.algo_name() == "Blake2b" || req.algo_name() == "BLAKE2b") {
221 return std::make_unique<BLAKE2b>(req.arg_as_integer(0, 512));
222 }
223#endif
224
225#if defined(BOTAN_HAS_KECCAK)
226 if(req.algo_name() == "Keccak-1600") {
227 return std::make_unique<Keccak_1600>(req.arg_as_integer(0, 512));
228 }
229#endif
230
231#if defined(BOTAN_HAS_SHA3)
232 if(req.algo_name() == "SHA-3") {
233 return std::make_unique<SHA_3>(req.arg_as_integer(0, 512));
234 }
235#endif
236
237#if defined(BOTAN_HAS_SHAKE)
238 if(req.algo_name() == "SHAKE-128" && req.arg_count() == 1) {
239 return std::make_unique<SHAKE_128>(req.arg_as_integer(0));
240 }
241 if(req.algo_name() == "SHAKE-256" && req.arg_count() == 1) {
242 return std::make_unique<SHAKE_256>(req.arg_as_integer(0));
243 }
244#endif
245
246#if defined(BOTAN_HAS_PARALLEL_HASH)
247 if(req.algo_name() == "Parallel") {
248 std::vector<std::unique_ptr<HashFunction>> hashes;
249
250 for(size_t i = 0; i != req.arg_count(); ++i) {
252 if(!h) {
253 return nullptr;
254 }
255 hashes.push_back(std::move(h));
256 }
257
258 return std::make_unique<Parallel>(hashes);
259 }
260#endif
261
262#if defined(BOTAN_HAS_TRUNCATED_HASH)
263 if(req.algo_name() == "Truncated" && req.arg_count() == 2) {
265 if(!hash) {
266 return nullptr;
267 }
268
269 return std::make_unique<Truncated_Hash>(std::move(hash), req.arg_as_integer(1));
270 }
271#endif
272
273#if defined(BOTAN_HAS_COMB4P)
274 if(req.algo_name() == "Comb4P" && req.arg_count() == 2) {
277
278 if(h1 && h2) {
279 return std::make_unique<Comb4P>(std::move(h1), std::move(h2));
280 }
281 }
282#endif
283
284 return nullptr;
285}
virtual std::string provider() const
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
std::unique_ptr< HashFunction > make_commoncrypto_hash(std::string_view name)