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