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-2025 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.5.0
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 //Ascon-Hash256 hash support?
118 #if (ASCON_HASH256_SUPPORT == ENABLED)
119  #include "lwc/ascon_hash256.h"
120 #endif
121 
122 //BLAKE2b-160 hash support?
123 #if (BLAKE2B160_SUPPORT == ENABLED)
124  #include "hash/blake2b160.h"
125 #endif
126 
127 //BLAKE2b-256 hash support?
128 #if (BLAKE2B256_SUPPORT == ENABLED)
129  #include "hash/blake2b256.h"
130 #endif
131 
132 //BLAKE2b-384 hash support?
133 #if (BLAKE2B384_SUPPORT == ENABLED)
134  #include "hash/blake2b384.h"
135 #endif
136 
137 //BLAKE2b-512 hash support?
138 #if (BLAKE2B512_SUPPORT == ENABLED)
139  #include "hash/blake2b512.h"
140 #endif
141 
142 //BLAKE2s-128 hash support?
143 #if (BLAKE2S128_SUPPORT == ENABLED)
144  #include "hash/blake2s128.h"
145 #endif
146 
147 //BLAKE2s-160 hash support?
148 #if (BLAKE2S160_SUPPORT == ENABLED)
149  #include "hash/blake2s160.h"
150 #endif
151 
152 //BLAKE2s-224 hash support?
153 #if (BLAKE2S224_SUPPORT == ENABLED)
154  #include "hash/blake2s224.h"
155 #endif
156 
157 //BLAKE2s-256 hash support?
158 #if (BLAKE2S256_SUPPORT == ENABLED)
159  #include "hash/blake2s256.h"
160 #endif
161 
162 //SM3 hash support?
163 #if (SM3_SUPPORT == ENABLED)
164  #include "hash/sm3.h"
165 #endif
166 
167 //Tiger hash support?
168 #if (TIGER_SUPPORT == ENABLED)
169  #include "hash/tiger.h"
170 #endif
171 
172 //Whirlpool hash support?
173 #if (WHIRLPOOL_SUPPORT == ENABLED)
174  #include "hash/whirlpool.h"
175 #endif
176 
177 //Maximum block size
178 #if (SHA3_224_SUPPORT == ENABLED)
179  #define MAX_HASH_BLOCK_SIZE SHA3_224_BLOCK_SIZE
180 #elif (SHA3_256_SUPPORT == ENABLED)
181  #define MAX_HASH_BLOCK_SIZE SHA3_256_BLOCK_SIZE
182 #elif (BLAKE2B512_SUPPORT == ENABLED)
183  #define MAX_HASH_BLOCK_SIZE BLAKE2B512_BLOCK_SIZE
184 #elif (BLAKE2B384_SUPPORT == ENABLED)
185  #define MAX_HASH_BLOCK_SIZE BLAKE2B384_BLOCK_SIZE
186 #elif (BLAKE2B256_SUPPORT == ENABLED)
187  #define MAX_HASH_BLOCK_SIZE BLAKE2B256_BLOCK_SIZE
188 #elif (BLAKE2B160_SUPPORT == ENABLED)
189  #define MAX_HASH_BLOCK_SIZE BLAKE2B160_BLOCK_SIZE
190 #elif (SHA512_SUPPORT == ENABLED)
191  #define MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
192 #elif (SHA384_SUPPORT == ENABLED)
193  #define MAX_HASH_BLOCK_SIZE SHA384_BLOCK_SIZE
194 #elif (SHA512_256_SUPPORT == ENABLED)
195  #define MAX_HASH_BLOCK_SIZE SHA512_256_BLOCK_SIZE
196 #elif (SHA512_224_SUPPORT == ENABLED)
197  #define MAX_HASH_BLOCK_SIZE SHA512_224_BLOCK_SIZE
198 #elif (SHA3_384_SUPPORT == ENABLED)
199  #define MAX_HASH_BLOCK_SIZE SHA3_384_BLOCK_SIZE
200 #elif (SHA3_512_SUPPORT == ENABLED)
201  #define MAX_HASH_BLOCK_SIZE SHA3_512_BLOCK_SIZE
202 #elif (BLAKE2S256_SUPPORT == ENABLED)
203  #define MAX_HASH_BLOCK_SIZE BLAKE2S256_BLOCK_SIZE
204 #elif (BLAKE2S224_SUPPORT == ENABLED)
205  #define MAX_HASH_BLOCK_SIZE BLAKE2S224_BLOCK_SIZE
206 #elif (BLAKE2S160_SUPPORT == ENABLED)
207  #define MAX_HASH_BLOCK_SIZE BLAKE2S160_BLOCK_SIZE
208 #elif (BLAKE2S128_SUPPORT == ENABLED)
209  #define MAX_HASH_BLOCK_SIZE BLAKE2S128_BLOCK_SIZE
210 #elif (SHA256_SUPPORT == ENABLED)
211  #define MAX_HASH_BLOCK_SIZE SHA256_BLOCK_SIZE
212 #elif (SHA224_SUPPORT == ENABLED)
213  #define MAX_HASH_BLOCK_SIZE SHA224_BLOCK_SIZE
214 #elif (SHA1_SUPPORT == ENABLED)
215  #define MAX_HASH_BLOCK_SIZE SHA1_BLOCK_SIZE
216 #elif (SM3_SUPPORT == ENABLED)
217  #define MAX_HASH_BLOCK_SIZE SM3_BLOCK_SIZE
218 #elif (WHIRLPOOL_SUPPORT == ENABLED)
219  #define MAX_HASH_BLOCK_SIZE WHIRLPOOL_BLOCK_SIZE
220 #elif (TIGER_SUPPORT == ENABLED)
221  #define MAX_HASH_BLOCK_SIZE TIGER_BLOCK_SIZE
222 #elif (RIPEMD160_SUPPORT == ENABLED)
223  #define MAX_HASH_BLOCK_SIZE RIPEMD160_BLOCK_SIZE
224 #elif (RIPEMD128_SUPPORT == ENABLED)
225  #define MAX_HASH_BLOCK_SIZE RIPEMD128_BLOCK_SIZE
226 #elif (MD5_SUPPORT == ENABLED)
227  #define MAX_HASH_BLOCK_SIZE MD5_BLOCK_SIZE
228 #elif (MD4_SUPPORT == ENABLED)
229  #define MAX_HASH_BLOCK_SIZE MD4_BLOCK_SIZE
230 #elif (MD2_SUPPORT == ENABLED)
231  #define MAX_HASH_BLOCK_SIZE MD2_BLOCK_SIZE
232 #elif (ASCON_HASH256_SUPPORT == ENABLED)
233  #define MAX_HASH_BLOCK_SIZE ASCON_HASH256_BLOCK_SIZE
234 #endif
235 
236 //Maximum digest size
237 #if (WHIRLPOOL_SUPPORT == ENABLED)
238  #define MAX_HASH_DIGEST_SIZE WHIRLPOOL_DIGEST_SIZE
239 #elif (BLAKE2B512_SUPPORT == ENABLED)
240  #define MAX_HASH_DIGEST_SIZE BLAKE2B512_DIGEST_SIZE
241 #elif (SHA3_512_SUPPORT == ENABLED)
242  #define MAX_HASH_DIGEST_SIZE SHA3_512_DIGEST_SIZE
243 #elif (SHA512_SUPPORT == ENABLED)
244  #define MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
245 #elif (BLAKE2B384_SUPPORT == ENABLED)
246  #define MAX_HASH_DIGEST_SIZE BLAKE2B384_DIGEST_SIZE
247 #elif (SHA3_384_SUPPORT == ENABLED)
248  #define MAX_HASH_DIGEST_SIZE SHA3_384_DIGEST_SIZE
249 #elif (SHA384_SUPPORT == ENABLED)
250  #define MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
251 #elif (BLAKE2B256_SUPPORT == ENABLED)
252  #define MAX_HASH_DIGEST_SIZE BLAKE2B256_DIGEST_SIZE
253 #elif (BLAKE2S256_SUPPORT == ENABLED)
254  #define MAX_HASH_DIGEST_SIZE BLAKE2S256_DIGEST_SIZE
255 #elif (SHA3_256_SUPPORT == ENABLED)
256  #define MAX_HASH_DIGEST_SIZE SHA3_256_DIGEST_SIZE
257 #elif (SHA512_256_SUPPORT == ENABLED)
258  #define MAX_HASH_DIGEST_SIZE SHA512_256_DIGEST_SIZE
259 #elif (SHA256_SUPPORT == ENABLED)
260  #define MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
261 #elif (ASCON_HASH256_SUPPORT == ENABLED)
262  #define MAX_HASH_DIGEST_SIZE ASCON_HASH256_DIGEST_SIZE
263 #elif (SM3_SUPPORT == ENABLED)
264  #define MAX_HASH_DIGEST_SIZE SM3_DIGEST_SIZE
265 #elif (BLAKE2S224_SUPPORT == ENABLED)
266  #define MAX_HASH_DIGEST_SIZE BLAKE2S224_DIGEST_SIZE
267 #elif (SHA3_224_SUPPORT == ENABLED)
268  #define MAX_HASH_DIGEST_SIZE SHA3_224_DIGEST_SIZE
269 #elif (SHA512_224_SUPPORT == ENABLED)
270  #define MAX_HASH_DIGEST_SIZE SHA512_224_DIGEST_SIZE
271 #elif (SHA224_SUPPORT == ENABLED)
272  #define MAX_HASH_DIGEST_SIZE SHA224_DIGEST_SIZE
273 #elif (TIGER_SUPPORT == ENABLED)
274  #define MAX_HASH_DIGEST_SIZE TIGER_DIGEST_SIZE
275 #elif (BLAKE2B160_SUPPORT == ENABLED)
276  #define MAX_HASH_DIGEST_SIZE BLAKE2B160_DIGEST_SIZE
277 #elif (BLAKE2S160_SUPPORT == ENABLED)
278  #define MAX_HASH_DIGEST_SIZE BLAKE2S160_DIGEST_SIZE
279 #elif (SHA1_SUPPORT == ENABLED)
280  #define MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
281 #elif (RIPEMD160_SUPPORT == ENABLED)
282  #define MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
283 #elif (BLAKE2S128_SUPPORT == ENABLED)
284  #define MAX_HASH_DIGEST_SIZE BLAKE2S128_DIGEST_SIZE
285 #elif (RIPEMD128_SUPPORT == ENABLED)
286  #define MAX_HASH_DIGEST_SIZE RIPEMD128_DIGEST_SIZE
287 #elif (MD5_SUPPORT == ENABLED)
288  #define MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
289 #elif (MD4_SUPPORT == ENABLED)
290  #define MAX_HASH_DIGEST_SIZE MD4_DIGEST_SIZE
291 #elif (MD2_SUPPORT == ENABLED)
292  #define MAX_HASH_DIGEST_SIZE MD2_DIGEST_SIZE
293 #endif
294 
295 //C++ guard
296 #ifdef __cplusplus
297 extern "C" {
298 #endif
299 
300 
301 /**
302  * @brief Generic hash algorithm context
303  **/
304 
305 typedef union
306 {
307 #if (MD2_SUPPORT == ENABLED)
309 #endif
310 #if (MD4_SUPPORT == ENABLED)
312 #endif
313 #if (MD5_SUPPORT == ENABLED)
315 #endif
316 #if (RIPEMD128_SUPPORT == ENABLED)
318 #endif
319 #if (RIPEMD160_SUPPORT == ENABLED)
321 #endif
322 #if (SHA1_SUPPORT == ENABLED)
324 #endif
325 #if (SHA224_SUPPORT == ENABLED)
327 #endif
328 #if (SHA256_SUPPORT == ENABLED)
330 #endif
331 #if (SHA384_SUPPORT == ENABLED)
333 #endif
334 #if (SHA512_SUPPORT == ENABLED)
336 #endif
337 #if (SHA512_224_SUPPORT == ENABLED)
339 #endif
340 #if (SHA512_256_SUPPORT == ENABLED)
342 #endif
343 #if (SHA3_224_SUPPORT == ENABLED)
345 #endif
346 #if (SHA3_256_SUPPORT == ENABLED)
348 #endif
349 #if (SHA3_384_SUPPORT == ENABLED)
351 #endif
352 #if (SHA3_512_SUPPORT == ENABLED)
354 #endif
355 #if (ASCON_HASH256_SUPPORT == ENABLED)
357 #endif
358 #if (BLAKE2B160_SUPPORT == ENABLED)
360 #endif
361 #if (BLAKE2B256_SUPPORT == ENABLED)
363 #endif
364 #if (BLAKE2B384_SUPPORT == ENABLED)
366 #endif
367 #if (BLAKE2B512_SUPPORT == ENABLED)
369 #endif
370 #if (BLAKE2S128_SUPPORT == ENABLED)
372 #endif
373 #if (BLAKE2S160_SUPPORT == ENABLED)
375 #endif
376 #if (BLAKE2S224_SUPPORT == ENABLED)
378 #endif
379 #if (BLAKE2S256_SUPPORT == ENABLED)
381 #endif
382 #if (SM3_SUPPORT == ENABLED)
384 #endif
385 #if (TIGER_SUPPORT == ENABLED)
387 #endif
388 #if (WHIRLPOOL_SUPPORT == ENABLED)
390 #endif
391 } HashContext;
392 
393 
394 //C++ guard
395 #ifdef __cplusplus
396 }
397 #endif
398 
399 #endif
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
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
BLAKE2s-224 hash function.
Tiger hash function.
BLAKE2b-256 hash function.
Ripemd128Context ripemd128Context
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
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.
MD4 (Message-Digest Algorithm)
BLAKE2b-384 hash function.
MD5 (Message-Digest Algorithm)
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
Sha512_256Context sha512_256Context
SHA3-256 hash function (SHA-3 with 256-bit output)
WhirlpoolContext whirlpoolContext
BLAKE2b-160 hash function.
Md5Context md5Context
BLAKE2b-512 hash function.
Blake2b256Context blake2b256Context
SHA-224 (Secure Hash Algorithm 224)