1 /*
2 * Copyright (C) 2017 - This file is part of libecc project
3 *
4 * Authors:
5 * Ryad BENADJILA <ryadbenadjila@gmail.com>
6 * Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7 * Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
8 *
9 * Contributors:
10 * Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11 * Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12 *
13 * This software is licensed under a dual BSD and GPL v2 license.
14 * See LICENSE file at the root folder of the project.
15 */
16 #ifndef __HASH_ALGS_H__
17 #define __HASH_ALGS_H__
18
19 #include <libecc/lib_ecc_config.h>
20 #include <libecc/lib_ecc_types.h>
21 #include <libecc/words/words.h>
22 #include <libecc/hash/sha224.h>
23 #include <libecc/hash/sha256.h>
24 #include <libecc/hash/sha384.h>
25 #include <libecc/hash/sha512.h>
26 #include <libecc/hash/sha512-224.h>
27 #include <libecc/hash/sha512-256.h>
28 #include <libecc/hash/sha3-224.h>
29 #include <libecc/hash/sha3-256.h>
30 #include <libecc/hash/sha3-384.h>
31 #include <libecc/hash/sha3-512.h>
32 #include <libecc/hash/sm3.h>
33 #include <libecc/hash/shake256.h>
34 #include <libecc/hash/streebog256.h>
35 #include <libecc/hash/streebog512.h>
36 #include <libecc/hash/ripemd160.h>
37 #include <libecc/hash/belt-hash.h>
38 #include <libecc/hash/bash224.h>
39 #include <libecc/hash/bash256.h>
40 #include <libecc/hash/bash384.h>
41 #include <libecc/hash/bash512.h>
42 #include <libecc/utils/utils.h>
43
44 #if (MAX_DIGEST_SIZE == 0)
45 #error "It seems you disabled all hash algorithms in lib_ecc_config.h"
46 #endif
47
48 #if (MAX_BLOCK_SIZE == 0)
49 #error "It seems you disabled all hash algorithms in lib_ecc_config.h"
50 #endif
51
52 typedef union {
53 #ifdef SHA224_BLOCK_SIZE
54 sha224_context sha224;
55 #endif
56 #ifdef SHA256_BLOCK_SIZE
57 sha256_context sha256;
58 #endif
59 #ifdef SHA384_BLOCK_SIZE
60 sha384_context sha384;
61 #endif
62 #ifdef SHA512_BLOCK_SIZE
63 sha512_context sha512;
64 #endif
65 #ifdef SHA512_224_BLOCK_SIZE
66 sha512_224_context sha512_224;
67 #endif
68 #ifdef SHA512_256_BLOCK_SIZE
69 sha512_256_context sha512_256;
70 #endif
71 #ifdef SHA3_224_BLOCK_SIZE
72 sha3_224_context sha3_224;
73 #endif
74 #ifdef SHA3_256_BLOCK_SIZE
75 sha3_256_context sha3_256;
76 #endif
77 #ifdef SHA3_384_BLOCK_SIZE
78 sha3_384_context sha3_384;
79 #endif
80 #ifdef SHA3_512_BLOCK_SIZE
81 sha3_512_context sha3_512;
82 #endif
83 #ifdef SHAKE256_BLOCK_SIZE
84 shake256_context shake256;
85 #endif
86 #ifdef SM3_BLOCK_SIZE
87 sm3_context sm3;
88 #endif
89 #ifdef STREEBOG256_BLOCK_SIZE
90 streebog256_context streebog256;
91 #endif
92 #ifdef STREEBOG512_BLOCK_SIZE
93 streebog512_context streebog512;
94 #endif
95 #ifdef RIPEMD160_BLOCK_SIZE
96 ripemd160_context ripemd160;
97 #endif
98 #ifdef BELT_HASH_BLOCK_SIZE
99 belt_hash_context belt_hash;
100 #endif
101 #ifdef BASH224_HASH_BLOCK_SIZE
102 bash224_context bash224;
103 #endif
104 #ifdef BASH256_HASH_BLOCK_SIZE
105 bash256_context bash256;
106 #endif
107 #ifdef BASH384_HASH_BLOCK_SIZE
108 bash384_context bash384;
109 #endif
110 #ifdef BASH512_HASH_BLOCK_SIZE
111 bash512_context bash512;
112 #endif
113 } hash_context;
114
115 typedef int (*_hfunc_init) (hash_context * hctx);
116 typedef int (*_hfunc_update) (hash_context * hctx,
117 const unsigned char *chunk, u32 chunklen);
118 typedef int (*_hfunc_finalize) (hash_context * hctx, unsigned char *output);
119 typedef int (*_hfunc_scattered) (const unsigned char **inputs,
120 const u32 *ilens, unsigned char *output);
121
122 /*****************************************/
123 /* Trampolines to each specific function to
124 * handle typing of our generic union structure.
125 */
126 #ifdef WITH_HASH_SHA224
127 ATTRIBUTE_WARN_UNUSED_RET int _sha224_init(hash_context * hctx);
128 ATTRIBUTE_WARN_UNUSED_RET int _sha224_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
129 ATTRIBUTE_WARN_UNUSED_RET int _sha224_final(hash_context * hctx, unsigned char *output);
130 #endif
131 #ifdef WITH_HASH_SHA256
132 ATTRIBUTE_WARN_UNUSED_RET int _sha256_init(hash_context * hctx);
133 ATTRIBUTE_WARN_UNUSED_RET int _sha256_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
134 ATTRIBUTE_WARN_UNUSED_RET int _sha256_final(hash_context * hctx, unsigned char *output);
135 #endif
136 #ifdef WITH_HASH_SHA384
137 ATTRIBUTE_WARN_UNUSED_RET int _sha384_init(hash_context * hctx);
138 ATTRIBUTE_WARN_UNUSED_RET int _sha384_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
139 ATTRIBUTE_WARN_UNUSED_RET int _sha384_final(hash_context * hctx, unsigned char *output);
140 #endif
141 #ifdef WITH_HASH_SHA512
142 ATTRIBUTE_WARN_UNUSED_RET int _sha512_init(hash_context * hctx);
143 ATTRIBUTE_WARN_UNUSED_RET int _sha512_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
144 ATTRIBUTE_WARN_UNUSED_RET int _sha512_final(hash_context * hctx, unsigned char *output);
145 #endif
146 #ifdef WITH_HASH_SHA512_224
147 ATTRIBUTE_WARN_UNUSED_RET int _sha512_224_init(hash_context * hctx);
148 ATTRIBUTE_WARN_UNUSED_RET int _sha512_224_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
149 ATTRIBUTE_WARN_UNUSED_RET int _sha512_224_final(hash_context * hctx, unsigned char *output);
150 #endif
151 #ifdef WITH_HASH_SHA512_256
152 ATTRIBUTE_WARN_UNUSED_RET int _sha512_256_init(hash_context * hctx);
153 ATTRIBUTE_WARN_UNUSED_RET int _sha512_256_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
154 ATTRIBUTE_WARN_UNUSED_RET int _sha512_256_final(hash_context * hctx, unsigned char *output);
155 #endif
156 #ifdef WITH_HASH_SHA3_224
157 ATTRIBUTE_WARN_UNUSED_RET int _sha3_224_init(hash_context * hctx);
158 ATTRIBUTE_WARN_UNUSED_RET int _sha3_224_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
159 ATTRIBUTE_WARN_UNUSED_RET int _sha3_224_final(hash_context * hctx, unsigned char *output);
160 #endif
161 #ifdef WITH_HASH_SHA3_256
162 ATTRIBUTE_WARN_UNUSED_RET int _sha3_256_init(hash_context * hctx);
163 ATTRIBUTE_WARN_UNUSED_RET int _sha3_256_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
164 ATTRIBUTE_WARN_UNUSED_RET int _sha3_256_final(hash_context * hctx, unsigned char *output);
165 #endif
166 #ifdef WITH_HASH_SHA3_384
167 ATTRIBUTE_WARN_UNUSED_RET int _sha3_384_init(hash_context * hctx);
168 ATTRIBUTE_WARN_UNUSED_RET int _sha3_384_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
169 ATTRIBUTE_WARN_UNUSED_RET int _sha3_384_final(hash_context * hctx, unsigned char *output);
170 #endif
171 #ifdef WITH_HASH_SHA3_512
172 ATTRIBUTE_WARN_UNUSED_RET int _sha3_512_init(hash_context * hctx);
173 ATTRIBUTE_WARN_UNUSED_RET int _sha3_512_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
174 ATTRIBUTE_WARN_UNUSED_RET int _sha3_512_final(hash_context * hctx, unsigned char *output);
175 #endif
176 #ifdef WITH_HASH_SM3
177 ATTRIBUTE_WARN_UNUSED_RET int _sm3_init(hash_context * hctx);
178 ATTRIBUTE_WARN_UNUSED_RET int _sm3_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
179 ATTRIBUTE_WARN_UNUSED_RET int _sm3_final(hash_context * hctx, unsigned char *output);
180 #endif
181 #ifdef WITH_HASH_SHAKE256
182 ATTRIBUTE_WARN_UNUSED_RET int _shake256_init(hash_context * hctx);
183 ATTRIBUTE_WARN_UNUSED_RET int _shake256_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
184 ATTRIBUTE_WARN_UNUSED_RET int _shake256_final(hash_context * hctx, unsigned char *output);
185 #endif
186 #ifdef WITH_HASH_STREEBOG256
187 ATTRIBUTE_WARN_UNUSED_RET int _streebog256_init(hash_context * hctx);
188 ATTRIBUTE_WARN_UNUSED_RET int _streebog256_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
189 ATTRIBUTE_WARN_UNUSED_RET int _streebog256_final(hash_context * hctx, unsigned char *output);
190 #endif
191 #ifdef WITH_HASH_STREEBOG512
192 ATTRIBUTE_WARN_UNUSED_RET int _streebog512_init(hash_context * hctx);
193 ATTRIBUTE_WARN_UNUSED_RET int _streebog512_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
194 ATTRIBUTE_WARN_UNUSED_RET int _streebog512_final(hash_context * hctx, unsigned char *output);
195 #endif
196 #ifdef WITH_HASH_RIPEMD160
197 ATTRIBUTE_WARN_UNUSED_RET int _ripemd160_init(hash_context * hctx);
198 ATTRIBUTE_WARN_UNUSED_RET int _ripemd160_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
199 ATTRIBUTE_WARN_UNUSED_RET int _ripemd160_final(hash_context * hctx, unsigned char *output);
200 #endif
201 #ifdef WITH_HASH_BELT_HASH
202 ATTRIBUTE_WARN_UNUSED_RET int _belt_hash_init(hash_context * hctx);
203 ATTRIBUTE_WARN_UNUSED_RET int _belt_hash_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
204 ATTRIBUTE_WARN_UNUSED_RET int _belt_hash_final(hash_context * hctx, unsigned char *output);
205 #endif
206 #ifdef WITH_HASH_BASH224
207 ATTRIBUTE_WARN_UNUSED_RET int _bash224_init(hash_context * hctx);
208 ATTRIBUTE_WARN_UNUSED_RET int _bash224_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
209 ATTRIBUTE_WARN_UNUSED_RET int _bash224_final(hash_context * hctx, unsigned char *output);
210 #endif
211 #ifdef WITH_HASH_BASH256
212 ATTRIBUTE_WARN_UNUSED_RET int _bash256_init(hash_context * hctx);
213 ATTRIBUTE_WARN_UNUSED_RET int _bash256_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
214 ATTRIBUTE_WARN_UNUSED_RET int _bash256_final(hash_context * hctx, unsigned char *output);
215 #endif
216 #ifdef WITH_HASH_BASH384
217 ATTRIBUTE_WARN_UNUSED_RET int _bash384_init(hash_context * hctx);
218 ATTRIBUTE_WARN_UNUSED_RET int _bash384_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
219 ATTRIBUTE_WARN_UNUSED_RET int _bash384_final(hash_context * hctx, unsigned char *output);
220 #endif
221 #ifdef WITH_HASH_BASH512
222 ATTRIBUTE_WARN_UNUSED_RET int _bash512_init(hash_context * hctx);
223 ATTRIBUTE_WARN_UNUSED_RET int _bash512_update(hash_context * hctx, const unsigned char *chunk, u32 chunklen);
224 ATTRIBUTE_WARN_UNUSED_RET int _bash512_final(hash_context * hctx, unsigned char *output);
225 #endif
226
227 /*
228 * All the hash algorithms we support are abstracted using the following
229 * structure (and following map) which provides for each hash alg its
230 * digest size, its block size and the associated scattered function.
231 */
232 typedef struct {
233 hash_alg_type type;
234 const char *name;
235 u8 digest_size;
236 u8 block_size;
237 ATTRIBUTE_WARN_UNUSED_RET _hfunc_init hfunc_init;
238 ATTRIBUTE_WARN_UNUSED_RET _hfunc_update hfunc_update;
239 ATTRIBUTE_WARN_UNUSED_RET _hfunc_finalize hfunc_finalize;
240 ATTRIBUTE_WARN_UNUSED_RET _hfunc_scattered hfunc_scattered;
241 } hash_mapping;
242
hash_mapping_sanity_check(const hash_mapping * hm)243 ATTRIBUTE_WARN_UNUSED_RET static inline int hash_mapping_sanity_check(const hash_mapping *hm)
244 {
245 int ret;
246
247 MUST_HAVE(((hm != NULL) && (hm->name != NULL) && (hm->hfunc_init != NULL) &&
248 (hm->hfunc_update != NULL) && (hm->hfunc_finalize != NULL) &&
249 (hm->hfunc_scattered != NULL)), ret, err);
250
251 ret = 0;
252
253 err:
254 return ret;
255 }
256
257 #define MAX_HASH_ALG_NAME_LEN 0
258 static const hash_mapping hash_maps[] = {
259 #ifdef WITH_HASH_SHA224
260 {.type = SHA224, /* SHA224 */
261 .name = "SHA224",
262 .digest_size = SHA224_DIGEST_SIZE,
263 .block_size = SHA224_BLOCK_SIZE,
264 .hfunc_init = _sha224_init,
265 .hfunc_update = _sha224_update,
266 .hfunc_finalize = _sha224_final,
267 .hfunc_scattered = sha224_scattered},
268 #if (MAX_HASH_ALG_NAME_LEN < 7)
269 #undef MAX_HASH_ALG_NAME_LEN
270 #define MAX_HASH_ALG_NAME_LEN 7
271 #endif /* MAX_HASH_ALG_NAME_LEN */
272 #endif /* WITH_HASH_SHA224 */
273 #ifdef WITH_HASH_SHA256
274 {.type = SHA256, /* SHA256 */
275 .name = "SHA256",
276 .digest_size = SHA256_DIGEST_SIZE,
277 .block_size = SHA256_BLOCK_SIZE,
278 .hfunc_init = _sha256_init,
279 .hfunc_update = _sha256_update,
280 .hfunc_finalize = _sha256_final,
281 .hfunc_scattered = sha256_scattered},
282 #if (MAX_HASH_ALG_NAME_LEN < 7)
283 #undef MAX_HASH_ALG_NAME_LEN
284 #define MAX_HASH_ALG_NAME_LEN 7
285 #endif /* MAX_HASH_ALG_NAME_LEN */
286 #endif /* WITH_HASH_SHA256 */
287 #ifdef WITH_HASH_SHA384
288 {.type = SHA384, /* SHA384 */
289 .name = "SHA384",
290 .digest_size = SHA384_DIGEST_SIZE,
291 .block_size = SHA384_BLOCK_SIZE,
292 .hfunc_init = _sha384_init,
293 .hfunc_update = _sha384_update,
294 .hfunc_finalize = _sha384_final,
295 .hfunc_scattered = sha384_scattered},
296 #if (MAX_HASH_ALG_NAME_LEN < 7)
297 #undef MAX_HASH_ALG_NAME_LEN
298 #define MAX_HASH_ALG_NAME_LEN 7
299 #endif /* MAX_HASH_ALG_NAME_LEN */
300 #endif /* WITH_HASH_SHA384 */
301 #ifdef WITH_HASH_SHA512
302 {.type = SHA512, /* SHA512 */
303 .name = "SHA512",
304 .digest_size = SHA512_DIGEST_SIZE,
305 .block_size = SHA512_BLOCK_SIZE,
306 .hfunc_init = _sha512_init,
307 .hfunc_update = _sha512_update,
308 .hfunc_finalize = _sha512_final,
309 .hfunc_scattered = sha512_scattered},
310 #if (MAX_HASH_ALG_NAME_LEN < 7)
311 #undef MAX_HASH_ALG_NAME_LEN
312 #define MAX_HASH_ALG_NAME_LEN 7
313 #endif /* MAX_HASH_ALG_NAME_LEN */
314 #endif /* WITH_HASH_SHA512 */
315 #ifdef WITH_HASH_SHA512_224
316 {.type = SHA512_224, /* SHA512_224 */
317 .name = "SHA512_224",
318 .digest_size = SHA512_224_DIGEST_SIZE,
319 .block_size = SHA512_224_BLOCK_SIZE,
320 .hfunc_init = _sha512_224_init,
321 .hfunc_update = _sha512_224_update,
322 .hfunc_finalize = _sha512_224_final,
323 .hfunc_scattered = sha512_224_scattered},
324 #if (MAX_HASH_ALG_NAME_LEN < 7)
325 #undef MAX_HASH_ALG_NAME_LEN
326 #define MAX_HASH_ALG_NAME_LEN 7
327 #endif /* MAX_HASH_ALG_NAME_LEN */
328 #endif /* WITH_HASH_SHA512_224 */
329 #ifdef WITH_HASH_SHA512_256
330 {.type = SHA512_256, /* SHA512_256 */
331 .name = "SHA512_256",
332 .digest_size = SHA512_256_DIGEST_SIZE,
333 .block_size = SHA512_256_BLOCK_SIZE,
334 .hfunc_init = _sha512_256_init,
335 .hfunc_update = _sha512_256_update,
336 .hfunc_finalize = _sha512_256_final,
337 .hfunc_scattered = sha512_256_scattered},
338 #if (MAX_HASH_ALG_NAME_LEN < 7)
339 #undef MAX_HASH_ALG_NAME_LEN
340 #define MAX_HASH_ALG_NAME_LEN 7
341 #endif /* MAX_HASH_ALG_NAME_LEN */
342 #endif /* WITH_HASH_SHA512_256 */
343 #ifdef WITH_HASH_SHA3_224
344 {.type = SHA3_224, /* SHA3_224 */
345 .name = "SHA3_224",
346 .digest_size = SHA3_224_DIGEST_SIZE,
347 .block_size = SHA3_224_BLOCK_SIZE,
348 .hfunc_init = _sha3_224_init,
349 .hfunc_update = _sha3_224_update,
350 .hfunc_finalize = _sha3_224_final,
351 .hfunc_scattered = sha3_224_scattered},
352 #if (MAX_HASH_ALG_NAME_LEN < 9)
353 #undef MAX_HASH_ALG_NAME_LEN
354 #define MAX_HASH_ALG_NAME_LEN 9
355 #endif /* MAX_HASH_ALG_NAME_LEN */
356 #endif /* WITH_HASH_SHA3_224 */
357 #ifdef WITH_HASH_SHA3_256
358 {.type = SHA3_256, /* SHA3_256 */
359 .name = "SHA3_256",
360 .digest_size = SHA3_256_DIGEST_SIZE,
361 .block_size = SHA3_256_BLOCK_SIZE,
362 .hfunc_init = _sha3_256_init,
363 .hfunc_update = _sha3_256_update,
364 .hfunc_finalize = _sha3_256_final,
365 .hfunc_scattered = sha3_256_scattered},
366 #if (MAX_HASH_ALG_NAME_LEN < 9)
367 #undef MAX_HASH_ALG_NAME_LEN
368 #define MAX_HASH_ALG_NAME_LEN 9
369 #endif /* MAX_HASH_ALG_NAME_LEN */
370 #endif /* WITH_HASH_SHA3_256 */
371 #ifdef WITH_HASH_SHA3_384
372 {.type = SHA3_384, /* SHA3_384 */
373 .name = "SHA3_384",
374 .digest_size = SHA3_384_DIGEST_SIZE,
375 .block_size = SHA3_384_BLOCK_SIZE,
376 .hfunc_init = _sha3_384_init,
377 .hfunc_update = _sha3_384_update,
378 .hfunc_finalize = _sha3_384_final,
379 .hfunc_scattered = sha3_384_scattered},
380 #if (MAX_HASH_ALG_NAME_LEN < 9)
381 #undef MAX_HASH_ALG_NAME_LEN
382 #define MAX_HASH_ALG_NAME_LEN 9
383 #endif /* MAX_HASH_ALG_NAME_LEN */
384 #endif /* WITH_HASH_SHA3_384 */
385 #ifdef WITH_HASH_SHA3_512
386 {.type = SHA3_512, /* SHA3_512 */
387 .name = "SHA3_512",
388 .digest_size = SHA3_512_DIGEST_SIZE,
389 .block_size = SHA3_512_BLOCK_SIZE,
390 .hfunc_init = _sha3_512_init,
391 .hfunc_update = _sha3_512_update,
392 .hfunc_finalize = _sha3_512_final,
393 .hfunc_scattered = sha3_512_scattered},
394 #if (MAX_HASH_ALG_NAME_LEN < 9)
395 #undef MAX_HASH_ALG_NAME_LEN
396 #define MAX_HASH_ALG_NAME_LEN 9
397 #endif /* MAX_HASH_ALG_NAME_LEN */
398 #endif /* WITH_HASH_SHA3_512 */
399 #ifdef WITH_HASH_SM3
400 {.type = SM3, /* SM3 */
401 .name = "SM3",
402 .digest_size = SM3_DIGEST_SIZE,
403 .block_size = SM3_BLOCK_SIZE,
404 .hfunc_init = _sm3_init,
405 .hfunc_update = _sm3_update,
406 .hfunc_finalize = _sm3_final,
407 .hfunc_scattered = sm3_scattered},
408 #if (MAX_HASH_ALG_NAME_LEN < 4)
409 #undef MAX_HASH_ALG_NAME_LEN
410 #define MAX_HASH_ALG_NAME_LEN 4
411 #endif /* MAX_HASH_ALG_NAME_LEN */
412 #endif /* WITH_HASH_SM3 */
413 #ifdef WITH_HASH_SHAKE256
414 {.type = SHAKE256, /* SHAKE256 */
415 .name = "SHAKE256",
416 .digest_size = SHAKE256_DIGEST_SIZE,
417 .block_size = SHAKE256_BLOCK_SIZE,
418 .hfunc_init = _shake256_init,
419 .hfunc_update = _shake256_update,
420 .hfunc_finalize = _shake256_final,
421 .hfunc_scattered = shake256_scattered},
422 #if (MAX_HASH_ALG_NAME_LEN < 9)
423 #undef MAX_HASH_ALG_NAME_LEN
424 #define MAX_HASH_ALG_NAME_LEN 9
425 #endif /* MAX_HASH_ALG_NAME_LEN */
426 #endif /* WITH_HASH_SHAKE256 */
427 #ifdef WITH_HASH_STREEBOG256
428 {.type = STREEBOG256, /* STREEBOG256 */
429 .name = "STREEBOG256",
430 .digest_size = STREEBOG256_DIGEST_SIZE,
431 .block_size = STREEBOG256_BLOCK_SIZE,
432 .hfunc_init = _streebog256_init,
433 .hfunc_update = _streebog256_update,
434 .hfunc_finalize = _streebog256_final,
435 .hfunc_scattered = streebog256_scattered},
436 #if (MAX_HASH_ALG_NAME_LEN < 12)
437 #undef MAX_HASH_ALG_NAME_LEN
438 #define MAX_HASH_ALG_NAME_LEN 12
439 #endif /* MAX_HASH_ALG_NAME_LEN */
440 #endif /* WITH_HASH_STREEBOG256 */
441 #ifdef WITH_HASH_STREEBOG512
442 {.type = STREEBOG512, /* STREEBOG512 */
443 .name = "STREEBOG512",
444 .digest_size = STREEBOG512_DIGEST_SIZE,
445 .block_size = STREEBOG512_BLOCK_SIZE,
446 .hfunc_init = _streebog512_init,
447 .hfunc_update = _streebog512_update,
448 .hfunc_finalize = _streebog512_final,
449 .hfunc_scattered = streebog512_scattered},
450 #if (MAX_HASH_ALG_NAME_LEN < 12)
451 #undef MAX_HASH_ALG_NAME_LEN
452 #define MAX_HASH_ALG_NAME_LEN 12
453 #endif /* MAX_HASH_ALG_NAME_LEN */
454 #endif /* WITH_HASH_STREEBOG512 */
455 #ifdef WITH_HASH_RIPEMD160
456 {.type = RIPEMD160, /* RIPEMD160 */
457 .name = "RIPEMD160",
458 .digest_size = RIPEMD160_DIGEST_SIZE,
459 .block_size = RIPEMD160_BLOCK_SIZE,
460 .hfunc_init = _ripemd160_init,
461 .hfunc_update = _ripemd160_update,
462 .hfunc_finalize = _ripemd160_final,
463 .hfunc_scattered = ripemd160_scattered},
464 #if (MAX_HASH_ALG_NAME_LEN < 9)
465 #undef MAX_HASH_ALG_NAME_LEN
466 #define MAX_HASH_ALG_NAME_LEN 9
467 #endif /* MAX_HASH_ALG_NAME_LEN */
468 #endif /* WITH_HASH_RIPEMD160 */
469 #ifdef WITH_HASH_BELT_HASH
470 {.type = BELT_HASH, /* BELT_HASH */
471 .name = "BELT_HASH",
472 .digest_size = BELT_HASH_DIGEST_SIZE,
473 .block_size = BELT_HASH_BLOCK_SIZE,
474 .hfunc_init = _belt_hash_init,
475 .hfunc_update = _belt_hash_update,
476 .hfunc_finalize = _belt_hash_final,
477 .hfunc_scattered = belt_hash_scattered},
478 #if (MAX_HASH_ALG_NAME_LEN < 9)
479 #undef MAX_HASH_ALG_NAME_LEN
480 #define MAX_HASH_ALG_NAME_LEN 9
481 #endif /* MAX_HASH_ALG_NAME_LEN */
482 #endif /* WITH_HASH_BELT_HASH */
483 #ifdef WITH_HASH_BASH224
484 {.type = BASH224, /* BASH224 */
485 .name = "BASH224",
486 .digest_size = BASH224_DIGEST_SIZE,
487 .block_size = BASH224_BLOCK_SIZE,
488 .hfunc_init = _bash224_init,
489 .hfunc_update = _bash224_update,
490 .hfunc_finalize = _bash224_final,
491 .hfunc_scattered = bash224_scattered},
492 #if (MAX_HASH_ALG_NAME_LEN < 8)
493 #undef MAX_HASH_ALG_NAME_LEN
494 #define MAX_HASH_ALG_NAME_LEN 8
495 #endif /* MAX_HASH_ALG_NAME_LEN */
496 #endif /* WITH_HASH_BASH224 */
497 #ifdef WITH_HASH_BASH256
498 {.type = BASH256, /* BASH256 */
499 .name = "BASH256",
500 .digest_size = BASH256_DIGEST_SIZE,
501 .block_size = BASH256_BLOCK_SIZE,
502 .hfunc_init = _bash256_init,
503 .hfunc_update = _bash256_update,
504 .hfunc_finalize = _bash256_final,
505 .hfunc_scattered = bash256_scattered},
506 #if (MAX_HASH_ALG_NAME_LEN < 8)
507 #undef MAX_HASH_ALG_NAME_LEN
508 #define MAX_HASH_ALG_NAME_LEN 8
509 #endif /* MAX_HASH_ALG_NAME_LEN */
510 #endif /* WITH_HASH_BASH256 */
511 #ifdef WITH_HASH_BASH384
512 {.type = BASH384, /* BASH384 */
513 .name = "BASH384",
514 .digest_size = BASH384_DIGEST_SIZE,
515 .block_size = BASH384_BLOCK_SIZE,
516 .hfunc_init = _bash384_init,
517 .hfunc_update = _bash384_update,
518 .hfunc_finalize = _bash384_final,
519 .hfunc_scattered = bash384_scattered},
520 #if (MAX_HASH_ALG_NAME_LEN < 8)
521 #undef MAX_HASH_ALG_NAME_LEN
522 #define MAX_HASH_ALG_NAME_LEN 8
523 #endif /* MAX_HASH_ALG_NAME_LEN */
524 #endif /* WITH_HASH_BASH384 */
525 #ifdef WITH_HASH_BASH512
526 {.type = BASH512, /* BASH512 */
527 .name = "BASH512",
528 .digest_size = BASH512_DIGEST_SIZE,
529 .block_size = BASH512_BLOCK_SIZE,
530 .hfunc_init = _bash512_init,
531 .hfunc_update = _bash512_update,
532 .hfunc_finalize = _bash512_final,
533 .hfunc_scattered = bash512_scattered},
534 #if (MAX_HASH_ALG_NAME_LEN < 8)
535 #undef MAX_HASH_ALG_NAME_LEN
536 #define MAX_HASH_ALG_NAME_LEN 8
537 #endif /* MAX_HASH_ALG_NAME_LEN */
538 #endif /* WITH_HASH_BASH512 */
539 {.type = UNKNOWN_HASH_ALG, /* Needs to be kept last */
540 .name = "UNKNOWN",
541 .digest_size = 0,
542 .block_size = 0,
543 .hfunc_init = NULL,
544 .hfunc_update = NULL,
545 .hfunc_finalize = NULL,
546 .hfunc_scattered = NULL},
547 };
548
549 ATTRIBUTE_WARN_UNUSED_RET int get_hash_by_name(const char *hash_name, const hash_mapping **hm);
550 ATTRIBUTE_WARN_UNUSED_RET int get_hash_by_type(hash_alg_type hash_type, const hash_mapping **hm);
551 ATTRIBUTE_WARN_UNUSED_RET int get_hash_sizes(hash_alg_type hash_type, u8 *digest_size, u8 *block_size);
552 ATTRIBUTE_WARN_UNUSED_RET int hash_mapping_callbacks_sanity_check(const hash_mapping *h);
553
554 #endif /* __HASH_ALGS_H__ */
555