hash_algorithms.h
Go to the documentation of this file.
1 /**
2  * @file hash_algorithms.h
3  * @brief Collection of hash algorithms
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.6
29  **/
30 
31 #ifndef _HASH_ALGORITHMS_H
32 #define _HASH_ALGORITHMS_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //MD2 hash support?
38 #if (MD2_SUPPORT == ENABLED)
39  #include "hash/md2.h"
40 #endif
41 
42 //MD4 hash support?
43 #if (MD4_SUPPORT == ENABLED)
44  #include "hash/md4.h"
45 #endif
46 
47 //MD5 hash support?
48 #if (MD5_SUPPORT == ENABLED)
49  #include "hash/md5.h"
50 #endif
51 
52 //RIPEMD-128 hash support?
53 #if (RIPEMD128_SUPPORT == ENABLED)
54  #include "hash/ripemd128.h"
55 #endif
56 
57 //RIPEMD-160 hash support?
58 #if (RIPEMD160_SUPPORT == ENABLED)
59  #include "hash/ripemd160.h"
60 #endif
61 
62 //SHA-1 hash support?
63 #if (SHA1_SUPPORT == ENABLED)
64  #include "hash/sha1.h"
65 #endif
66 
67 //SHA-224 hash support?
68 #if (SHA224_SUPPORT == ENABLED)
69  #include "hash/sha224.h"
70 #endif
71 
72 //SHA-256 hash support?
73 #if (SHA256_SUPPORT == ENABLED)
74  #include "hash/sha256.h"
75 #endif
76 
77 //SHA-384 hash support?
78 #if (SHA384_SUPPORT == ENABLED)
79  #include "hash/sha384.h"
80 #endif
81 
82 //SHA-512 hash support?
83 #if (SHA512_SUPPORT == ENABLED)
84  #include "hash/sha512.h"
85 #endif
86 
87 //SHA-512/224 hash support?
88 #if (SHA512_224_SUPPORT == ENABLED)
89  #include "hash/sha512_224.h"
90 #endif
91 
92 //SHA-512/256 hash support?
93 #if (SHA512_256_SUPPORT == ENABLED)
94  #include "hash/sha512_256.h"
95 #endif
96 
97 //SHA3-224 hash support?
98 #if (SHA3_224_SUPPORT == ENABLED)
99  #include "hash/sha3_224.h"
100 #endif
101 
102 //SHA3-256 hash support?
103 #if (SHA3_256_SUPPORT == ENABLED)
104  #include "hash/sha3_256.h"
105 #endif
106 
107 //SHA3-384 hash support?
108 #if (SHA3_384_SUPPORT == ENABLED)
109  #include "hash/sha3_384.h"
110 #endif
111 
112 //SHA3-512 hash support?
113 #if (SHA3_512_SUPPORT == ENABLED)
114  #include "hash/sha3_512.h"
115 #endif
116 
117 //SHAKE128/256 hash support?
118 #if (SHAKE128_256_SUPPORT == ENABLED)
119  #include "hash/shake128_256.h"
120 #endif
121 
122 //SHAKE256/512 hash support?
123 #if (SHAKE256_512_SUPPORT == ENABLED)
124  #include "hash/shake256_512.h"
125 #endif
126 
127 //TupleHash hash support?
128 #if (TUPLE_HASH_SUPPORT == ENABLED)
129  #include "hash/tuple_hash.h"
130 #endif
131 
132 //ParallelHash hash support?
133 #if (PARALLEL_HASH_SUPPORT == ENABLED)
134  #include "hash/parallel_hash.h"
135 #endif
136 
137 //Ascon-Hash256 hash support?
138 #if (ASCON_HASH256_SUPPORT == ENABLED)
139  #include "lwc/ascon_hash256.h"
140 #endif
141 
142 //BLAKE2b-160 hash support?
143 #if (BLAKE2B160_SUPPORT == ENABLED)
144  #include "hash/blake2b160.h"
145 #endif
146 
147 //BLAKE2b-256 hash support?
148 #if (BLAKE2B256_SUPPORT == ENABLED)
149  #include "hash/blake2b256.h"
150 #endif
151 
152 //BLAKE2b-384 hash support?
153 #if (BLAKE2B384_SUPPORT == ENABLED)
154  #include "hash/blake2b384.h"
155 #endif
156 
157 //BLAKE2b-512 hash support?
158 #if (BLAKE2B512_SUPPORT == ENABLED)
159  #include "hash/blake2b512.h"
160 #endif
161 
162 //BLAKE2s-128 hash support?
163 #if (BLAKE2S128_SUPPORT == ENABLED)
164  #include "hash/blake2s128.h"
165 #endif
166 
167 //BLAKE2s-160 hash support?
168 #if (BLAKE2S160_SUPPORT == ENABLED)
169  #include "hash/blake2s160.h"
170 #endif
171 
172 //BLAKE2s-224 hash support?
173 #if (BLAKE2S224_SUPPORT == ENABLED)
174  #include "hash/blake2s224.h"
175 #endif
176 
177 //BLAKE2s-256 hash support?
178 #if (BLAKE2S256_SUPPORT == ENABLED)
179  #include "hash/blake2s256.h"
180 #endif
181 
182 //SM3 hash support?
183 #if (SM3_SUPPORT == ENABLED)
184  #include "hash/sm3.h"
185 #endif
186 
187 //Tiger hash support?
188 #if (TIGER_SUPPORT == ENABLED)
189  #include "hash/tiger.h"
190 #endif
191 
192 //Whirlpool hash support?
193 #if (WHIRLPOOL_SUPPORT == ENABLED)
194  #include "hash/whirlpool.h"
195 #endif
196 
197 //Maximum block size
198 #if (SHAKE128_256_SUPPORT == ENABLED)
199  #define MAX_HASH_BLOCK_SIZE SHAKE128_256_BLOCK_SIZE
200 #elif (SHA3_224_SUPPORT == ENABLED)
201  #define MAX_HASH_BLOCK_SIZE SHA3_224_BLOCK_SIZE
202 #elif (SHAKE256_512_SUPPORT == ENABLED)
203  #define MAX_HASH_BLOCK_SIZE SHAKE256_512_BLOCK_SIZE
204 #elif (SHA3_256_SUPPORT == ENABLED)
205  #define MAX_HASH_BLOCK_SIZE SHA3_256_BLOCK_SIZE
206 #elif (BLAKE2B512_SUPPORT == ENABLED)
207  #define MAX_HASH_BLOCK_SIZE BLAKE2B512_BLOCK_SIZE
208 #elif (BLAKE2B384_SUPPORT == ENABLED)
209  #define MAX_HASH_BLOCK_SIZE BLAKE2B384_BLOCK_SIZE
210 #elif (BLAKE2B256_SUPPORT == ENABLED)
211  #define MAX_HASH_BLOCK_SIZE BLAKE2B256_BLOCK_SIZE
212 #elif (BLAKE2B160_SUPPORT == ENABLED)
213  #define MAX_HASH_BLOCK_SIZE BLAKE2B160_BLOCK_SIZE
214 #elif (SHA512_SUPPORT == ENABLED)
215  #define MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
216 #elif (SHA384_SUPPORT == ENABLED)
217  #define MAX_HASH_BLOCK_SIZE SHA384_BLOCK_SIZE
218 #elif (SHA512_256_SUPPORT == ENABLED)
219  #define MAX_HASH_BLOCK_SIZE SHA512_256_BLOCK_SIZE
220 #elif (SHA512_224_SUPPORT == ENABLED)
221  #define MAX_HASH_BLOCK_SIZE SHA512_224_BLOCK_SIZE
222 #elif (SHA3_384_SUPPORT == ENABLED)
223  #define MAX_HASH_BLOCK_SIZE SHA3_384_BLOCK_SIZE
224 #elif (SHA3_512_SUPPORT == ENABLED)
225  #define MAX_HASH_BLOCK_SIZE SHA3_512_BLOCK_SIZE
226 #elif (BLAKE2S256_SUPPORT == ENABLED)
227  #define MAX_HASH_BLOCK_SIZE BLAKE2S256_BLOCK_SIZE
228 #elif (BLAKE2S224_SUPPORT == ENABLED)
229  #define MAX_HASH_BLOCK_SIZE BLAKE2S224_BLOCK_SIZE
230 #elif (BLAKE2S160_SUPPORT == ENABLED)
231  #define MAX_HASH_BLOCK_SIZE BLAKE2S160_BLOCK_SIZE
232 #elif (BLAKE2S128_SUPPORT == ENABLED)
233  #define MAX_HASH_BLOCK_SIZE BLAKE2S128_BLOCK_SIZE
234 #elif (SHA256_SUPPORT == ENABLED)
235  #define MAX_HASH_BLOCK_SIZE SHA256_BLOCK_SIZE
236 #elif (SHA224_SUPPORT == ENABLED)
237  #define MAX_HASH_BLOCK_SIZE SHA224_BLOCK_SIZE
238 #elif (SHA1_SUPPORT == ENABLED)
239  #define MAX_HASH_BLOCK_SIZE SHA1_BLOCK_SIZE
240 #elif (SM3_SUPPORT == ENABLED)
241  #define MAX_HASH_BLOCK_SIZE SM3_BLOCK_SIZE
242 #elif (WHIRLPOOL_SUPPORT == ENABLED)
243  #define MAX_HASH_BLOCK_SIZE WHIRLPOOL_BLOCK_SIZE
244 #elif (TIGER_SUPPORT == ENABLED)
245  #define MAX_HASH_BLOCK_SIZE TIGER_BLOCK_SIZE
246 #elif (RIPEMD160_SUPPORT == ENABLED)
247  #define MAX_HASH_BLOCK_SIZE RIPEMD160_BLOCK_SIZE
248 #elif (RIPEMD128_SUPPORT == ENABLED)
249  #define MAX_HASH_BLOCK_SIZE RIPEMD128_BLOCK_SIZE
250 #elif (MD5_SUPPORT == ENABLED)
251  #define MAX_HASH_BLOCK_SIZE MD5_BLOCK_SIZE
252 #elif (MD4_SUPPORT == ENABLED)
253  #define MAX_HASH_BLOCK_SIZE MD4_BLOCK_SIZE
254 #elif (MD2_SUPPORT == ENABLED)
255  #define MAX_HASH_BLOCK_SIZE MD2_BLOCK_SIZE
256 #elif (ASCON_HASH256_SUPPORT == ENABLED)
257  #define MAX_HASH_BLOCK_SIZE ASCON_HASH256_BLOCK_SIZE
258 #endif
259 
260 //Maximum digest size
261 #if (WHIRLPOOL_SUPPORT == ENABLED)
262  #define MAX_HASH_DIGEST_SIZE WHIRLPOOL_DIGEST_SIZE
263 #elif (BLAKE2B512_SUPPORT == ENABLED)
264  #define MAX_HASH_DIGEST_SIZE BLAKE2B512_DIGEST_SIZE
265 #elif (SHAKE256_512_SUPPORT == ENABLED)
266  #define MAX_HASH_DIGEST_SIZE SHAKE256_512_DIGEST_SIZE
267 #elif (SHA3_512_SUPPORT == ENABLED)
268  #define MAX_HASH_DIGEST_SIZE SHA3_512_DIGEST_SIZE
269 #elif (SHA512_SUPPORT == ENABLED)
270  #define MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
271 #elif (BLAKE2B384_SUPPORT == ENABLED)
272  #define MAX_HASH_DIGEST_SIZE BLAKE2B384_DIGEST_SIZE
273 #elif (SHA3_384_SUPPORT == ENABLED)
274  #define MAX_HASH_DIGEST_SIZE SHA3_384_DIGEST_SIZE
275 #elif (SHA384_SUPPORT == ENABLED)
276  #define MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
277 #elif (BLAKE2B256_SUPPORT == ENABLED)
278  #define MAX_HASH_DIGEST_SIZE BLAKE2B256_DIGEST_SIZE
279 #elif (BLAKE2S256_SUPPORT == ENABLED)
280  #define MAX_HASH_DIGEST_SIZE BLAKE2S256_DIGEST_SIZE
281 #elif (SHAKE128_256_SUPPORT == ENABLED)
282  #define MAX_HASH_DIGEST_SIZE SHAKE128_256_DIGEST_SIZE
283 #elif (SHA3_256_SUPPORT == ENABLED)
284  #define MAX_HASH_DIGEST_SIZE SHA3_256_DIGEST_SIZE
285 #elif (SHA512_256_SUPPORT == ENABLED)
286  #define MAX_HASH_DIGEST_SIZE SHA512_256_DIGEST_SIZE
287 #elif (SHA256_SUPPORT == ENABLED)
288  #define MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
289 #elif (ASCON_HASH256_SUPPORT == ENABLED)
290  #define MAX_HASH_DIGEST_SIZE ASCON_HASH256_DIGEST_SIZE
291 #elif (SM3_SUPPORT == ENABLED)
292  #define MAX_HASH_DIGEST_SIZE SM3_DIGEST_SIZE
293 #elif (BLAKE2S224_SUPPORT == ENABLED)
294  #define MAX_HASH_DIGEST_SIZE BLAKE2S224_DIGEST_SIZE
295 #elif (SHA3_224_SUPPORT == ENABLED)
296  #define MAX_HASH_DIGEST_SIZE SHA3_224_DIGEST_SIZE
297 #elif (SHA512_224_SUPPORT == ENABLED)
298  #define MAX_HASH_DIGEST_SIZE SHA512_224_DIGEST_SIZE
299 #elif (SHA224_SUPPORT == ENABLED)
300  #define MAX_HASH_DIGEST_SIZE SHA224_DIGEST_SIZE
301 #elif (TIGER_SUPPORT == ENABLED)
302  #define MAX_HASH_DIGEST_SIZE TIGER_DIGEST_SIZE
303 #elif (BLAKE2B160_SUPPORT == ENABLED)
304  #define MAX_HASH_DIGEST_SIZE BLAKE2B160_DIGEST_SIZE
305 #elif (BLAKE2S160_SUPPORT == ENABLED)
306  #define MAX_HASH_DIGEST_SIZE BLAKE2S160_DIGEST_SIZE
307 #elif (SHA1_SUPPORT == ENABLED)
308  #define MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
309 #elif (RIPEMD160_SUPPORT == ENABLED)
310  #define MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
311 #elif (BLAKE2S128_SUPPORT == ENABLED)
312  #define MAX_HASH_DIGEST_SIZE BLAKE2S128_DIGEST_SIZE
313 #elif (RIPEMD128_SUPPORT == ENABLED)
314  #define MAX_HASH_DIGEST_SIZE RIPEMD128_DIGEST_SIZE
315 #elif (MD5_SUPPORT == ENABLED)
316  #define MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
317 #elif (MD4_SUPPORT == ENABLED)
318  #define MAX_HASH_DIGEST_SIZE MD4_DIGEST_SIZE
319 #elif (MD2_SUPPORT == ENABLED)
320  #define MAX_HASH_DIGEST_SIZE MD2_DIGEST_SIZE
321 #endif
322 
323 //C++ guard
324 #ifdef __cplusplus
325 extern "C" {
326 #endif
327 
328 
329 /**
330  * @brief Generic hash algorithm context
331  **/
332 
333 typedef union
334 {
335 #if (MD2_SUPPORT == ENABLED)
337 #endif
338 #if (MD4_SUPPORT == ENABLED)
340 #endif
341 #if (MD5_SUPPORT == ENABLED)
343 #endif
344 #if (RIPEMD128_SUPPORT == ENABLED)
346 #endif
347 #if (RIPEMD160_SUPPORT == ENABLED)
349 #endif
350 #if (SHA1_SUPPORT == ENABLED)
352 #endif
353 #if (SHA224_SUPPORT == ENABLED)
355 #endif
356 #if (SHA256_SUPPORT == ENABLED)
358 #endif
359 #if (SHA384_SUPPORT == ENABLED)
361 #endif
362 #if (SHA512_SUPPORT == ENABLED)
364 #endif
365 #if (SHA512_224_SUPPORT == ENABLED)
367 #endif
368 #if (SHA512_256_SUPPORT == ENABLED)
370 #endif
371 #if (SHA3_224_SUPPORT == ENABLED)
373 #endif
374 #if (SHA3_256_SUPPORT == ENABLED)
376 #endif
377 #if (SHA3_384_SUPPORT == ENABLED)
379 #endif
380 #if (SHA3_512_SUPPORT == ENABLED)
382 #endif
383 #if (SHAKE128_256_SUPPORT == ENABLED)
385 #endif
386 #if (SHAKE256_512_SUPPORT == ENABLED)
388 #endif
389 #if (TUPLE_HASH_SUPPORT == ENABLED)
391 #endif
392 #if (PARALLEL_HASH_SUPPORT == ENABLED)
394 #endif
395 #if (ASCON_HASH256_SUPPORT == ENABLED)
397 #endif
398 #if (BLAKE2B160_SUPPORT == ENABLED)
400 #endif
401 #if (BLAKE2B256_SUPPORT == ENABLED)
403 #endif
404 #if (BLAKE2B384_SUPPORT == ENABLED)
406 #endif
407 #if (BLAKE2B512_SUPPORT == ENABLED)
409 #endif
410 #if (BLAKE2S128_SUPPORT == ENABLED)
412 #endif
413 #if (BLAKE2S160_SUPPORT == ENABLED)
415 #endif
416 #if (BLAKE2S224_SUPPORT == ENABLED)
418 #endif
419 #if (BLAKE2S256_SUPPORT == ENABLED)
421 #endif
422 #if (SM3_SUPPORT == ENABLED)
424 #endif
425 #if (TIGER_SUPPORT == ENABLED)
427 #endif
428 #if (WHIRLPOOL_SUPPORT == ENABLED)
430 #endif
431 } HashContext;
432 
433 
434 //C++ guard
435 #ifdef __cplusplus
436 }
437 #endif
438 
439 #endif
TupleHash hash function.
SHA-512/256 (Secure Hash Algorithm)
Sha256Context sha256Context
Generic hash algorithm context.
SHA3-512 hash function (SHA-3 with 512-bit output)
Blake2b160Context blake2b160Context
BLAKE2s-128 hash function.
Sha3_512Context sha3_512Context
RIPEMD-128 hash function.
SHA-256 algorithm context.
Definition: sha256.h:62
Sha512_224Context sha512_224Context
SHA3-224 hash function (SHA-3 with 224-bit output)
SHA-1 (Secure Hash Algorithm 1)
SHA3-384 hash function (SHA-3 with 384-bit output)
Blake2s128Context blake2s128Context
Shake128_256Context shake128_256Context
Keccak context.
Definition: keccak.h:116
BLAKE2s-160 hash function.
Blake2s160Context blake2s160Context
AsconHash256Context asconHash256Context
Blake2b512Context blake2b512Context
SHA-512 (Secure Hash Algorithm 512)
SM3 algorithm context.
Definition: sm3.h:62
Md4Context md4Context
Sha384Context sha384Context
Sha3_224Context sha3_224Context
Sha3_256Context sha3_256Context
ParallelHash hash function.
BLAKE2s-224 hash function.
Tiger hash function.
BLAKE2b-256 hash function.
Ripemd128Context ripemd128Context
ParallelHashContext parallelHashContext
Sha1Context sha1Context
Sha3_384Context sha3_384Context
SHA-512 algorithm context.
Definition: sha512.h:62
Ascon-Hash256 algorithm context.
Definition: ascon_hash256.h:63
General definitions for cryptographic algorithms.
MD2 algorithm context.
Definition: md2.h:57
RIPEMD-160 algorithm context.
Definition: ripemd160.h:57
Sm3Context sm3Context
MD4 algorithm context.
Definition: md4.h:57
MD5 algorithm context.
Definition: md5.h:62
BLAKE2s algorithm context.
Definition: blake2s.h:51
SHAKE algorithm context.
Definition: shake.h:53
SHA-384 (Secure Hash Algorithm 384)
BLAKE2b algorithm context.
Definition: blake2b.h:51
Sha224Context sha224Context
Md2Context md2Context
SM3 hash function.
Tiger algorithm context.
Definition: tiger.h:57
Whirlpool algorithm context.
Definition: whirlpool.h:57
Blake2s256Context blake2s256Context
RIPEMD-160 hash function.
SHA-512/224 (Secure Hash Algorithm)
SHA-256 (Secure Hash Algorithm 256)
BLAKE2s-256 hash function.
SHAKE128/256 hash function.
MD4 (Message-Digest Algorithm)
TupleHashContext tupleHashContext
BLAKE2b-384 hash function.
MD5 (Message-Digest Algorithm)
TupleHash algorithm context.
Definition: tuple_hash.h:54
MD2 (Message-Digest Algorithm)
Blake2s224Context blake2s224Context
TigerContext tigerContext
Ripemd160Context ripemd160Context
SHA-1 algorithm context.
Definition: sha1.h:62
RIPEMD-128 algorithm context.
Definition: ripemd128.h:57
Ascon-Hash256 hash function.
Blake2b384Context blake2b384Context
Whirlpool hash function.
Sha512Context sha512Context
SHAKE256/512 hash function.
Sha512_256Context sha512_256Context
ParallelHash algorithm context.
Definition: parallel_hash.h:54
SHA3-256 hash function (SHA-3 with 256-bit output)
WhirlpoolContext whirlpoolContext
BLAKE2b-160 hash function.
Md5Context md5Context
BLAKE2b-512 hash function.
Shake256_512Context shake256_512Context
Blake2b256Context blake2b256Context
SHA-224 (Secure Hash Algorithm 224)