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-2024 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.4.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 //BLAKE2b-160 hash support?
118 #if (BLAKE2B160_SUPPORT == ENABLED)
119  #include "hash/blake2b160.h"
120 #endif
121 
122 //BLAKE2b-256 hash support?
123 #if (BLAKE2B256_SUPPORT == ENABLED)
124  #include "hash/blake2b256.h"
125 #endif
126 
127 //BLAKE2b-384 hash support?
128 #if (BLAKE2B384_SUPPORT == ENABLED)
129  #include "hash/blake2b384.h"
130 #endif
131 
132 //BLAKE2b-512 hash support?
133 #if (BLAKE2B512_SUPPORT == ENABLED)
134  #include "hash/blake2b512.h"
135 #endif
136 
137 //BLAKE2s-128 hash support?
138 #if (BLAKE2S128_SUPPORT == ENABLED)
139  #include "hash/blake2s128.h"
140 #endif
141 
142 //BLAKE2s-160 hash support?
143 #if (BLAKE2S160_SUPPORT == ENABLED)
144  #include "hash/blake2s160.h"
145 #endif
146 
147 //BLAKE2s-224 hash support?
148 #if (BLAKE2S224_SUPPORT == ENABLED)
149  #include "hash/blake2s224.h"
150 #endif
151 
152 //BLAKE2s-256 hash support?
153 #if (BLAKE2S256_SUPPORT == ENABLED)
154  #include "hash/blake2s256.h"
155 #endif
156 
157 //SM3 hash support?
158 #if (SM3_SUPPORT == ENABLED)
159  #include "hash/sm3.h"
160 #endif
161 
162 //Tiger hash support?
163 #if (TIGER_SUPPORT == ENABLED)
164  #include "hash/tiger.h"
165 #endif
166 
167 //Whirlpool hash support?
168 #if (WHIRLPOOL_SUPPORT == ENABLED)
169  #include "hash/whirlpool.h"
170 #endif
171 
172 //Maximum block size
173 #if (SHA3_224_SUPPORT == ENABLED)
174  #define MAX_HASH_BLOCK_SIZE SHA3_224_BLOCK_SIZE
175 #elif (SHA3_256_SUPPORT == ENABLED)
176  #define MAX_HASH_BLOCK_SIZE SHA3_256_BLOCK_SIZE
177 #elif (BLAKE2B512_SUPPORT == ENABLED)
178  #define MAX_HASH_BLOCK_SIZE BLAKE2B512_BLOCK_SIZE
179 #elif (BLAKE2B384_SUPPORT == ENABLED)
180  #define MAX_HASH_BLOCK_SIZE BLAKE2B384_BLOCK_SIZE
181 #elif (BLAKE2B256_SUPPORT == ENABLED)
182  #define MAX_HASH_BLOCK_SIZE BLAKE2B256_BLOCK_SIZE
183 #elif (BLAKE2B160_SUPPORT == ENABLED)
184  #define MAX_HASH_BLOCK_SIZE BLAKE2B160_BLOCK_SIZE
185 #elif (SHA512_SUPPORT == ENABLED)
186  #define MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
187 #elif (SHA384_SUPPORT == ENABLED)
188  #define MAX_HASH_BLOCK_SIZE SHA384_BLOCK_SIZE
189 #elif (SHA512_256_SUPPORT == ENABLED)
190  #define MAX_HASH_BLOCK_SIZE SHA512_256_BLOCK_SIZE
191 #elif (SHA512_224_SUPPORT == ENABLED)
192  #define MAX_HASH_BLOCK_SIZE SHA512_224_BLOCK_SIZE
193 #elif (SHA3_384_SUPPORT == ENABLED)
194  #define MAX_HASH_BLOCK_SIZE SHA3_384_BLOCK_SIZE
195 #elif (SHA3_512_SUPPORT == ENABLED)
196  #define MAX_HASH_BLOCK_SIZE SHA3_512_BLOCK_SIZE
197 #elif (BLAKE2S256_SUPPORT == ENABLED)
198  #define MAX_HASH_BLOCK_SIZE BLAKE2S256_BLOCK_SIZE
199 #elif (BLAKE2S224_SUPPORT == ENABLED)
200  #define MAX_HASH_BLOCK_SIZE BLAKE2S224_BLOCK_SIZE
201 #elif (BLAKE2S160_SUPPORT == ENABLED)
202  #define MAX_HASH_BLOCK_SIZE BLAKE2S160_BLOCK_SIZE
203 #elif (BLAKE2S128_SUPPORT == ENABLED)
204  #define MAX_HASH_BLOCK_SIZE BLAKE2S128_BLOCK_SIZE
205 #elif (SHA256_SUPPORT == ENABLED)
206  #define MAX_HASH_BLOCK_SIZE SHA256_BLOCK_SIZE
207 #elif (SHA224_SUPPORT == ENABLED)
208  #define MAX_HASH_BLOCK_SIZE SHA224_BLOCK_SIZE
209 #elif (SHA1_SUPPORT == ENABLED)
210  #define MAX_HASH_BLOCK_SIZE SHA1_BLOCK_SIZE
211 #elif (SM3_SUPPORT == ENABLED)
212  #define MAX_HASH_BLOCK_SIZE SM3_BLOCK_SIZE
213 #elif (WHIRLPOOL_SUPPORT == ENABLED)
214  #define MAX_HASH_BLOCK_SIZE WHIRLPOOL_BLOCK_SIZE
215 #elif (TIGER_SUPPORT == ENABLED)
216  #define MAX_HASH_BLOCK_SIZE TIGER_BLOCK_SIZE
217 #elif (RIPEMD160_SUPPORT == ENABLED)
218  #define MAX_HASH_BLOCK_SIZE RIPEMD160_BLOCK_SIZE
219 #elif (RIPEMD128_SUPPORT == ENABLED)
220  #define MAX_HASH_BLOCK_SIZE RIPEMD128_BLOCK_SIZE
221 #elif (MD5_SUPPORT == ENABLED)
222  #define MAX_HASH_BLOCK_SIZE MD5_BLOCK_SIZE
223 #elif (MD4_SUPPORT == ENABLED)
224  #define MAX_HASH_BLOCK_SIZE MD4_BLOCK_SIZE
225 #elif (MD2_SUPPORT == ENABLED)
226  #define MAX_HASH_BLOCK_SIZE MD2_BLOCK_SIZE
227 #endif
228 
229 //Maximum digest size
230 #if (WHIRLPOOL_SUPPORT == ENABLED)
231  #define MAX_HASH_DIGEST_SIZE WHIRLPOOL_DIGEST_SIZE
232 #elif (BLAKE2B512_SUPPORT == ENABLED)
233  #define MAX_HASH_DIGEST_SIZE BLAKE2B512_DIGEST_SIZE
234 #elif (SHA3_512_SUPPORT == ENABLED)
235  #define MAX_HASH_DIGEST_SIZE SHA3_512_DIGEST_SIZE
236 #elif (SHA512_SUPPORT == ENABLED)
237  #define MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
238 #elif (BLAKE2B384_SUPPORT == ENABLED)
239  #define MAX_HASH_DIGEST_SIZE BLAKE2B384_DIGEST_SIZE
240 #elif (SHA3_384_SUPPORT == ENABLED)
241  #define MAX_HASH_DIGEST_SIZE SHA3_384_DIGEST_SIZE
242 #elif (SHA384_SUPPORT == ENABLED)
243  #define MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
244 #elif (BLAKE2B256_SUPPORT == ENABLED)
245  #define MAX_HASH_DIGEST_SIZE BLAKE2B256_DIGEST_SIZE
246 #elif (BLAKE2S256_SUPPORT == ENABLED)
247  #define MAX_HASH_DIGEST_SIZE BLAKE2S256_DIGEST_SIZE
248 #elif (SHA3_256_SUPPORT == ENABLED)
249  #define MAX_HASH_DIGEST_SIZE SHA3_256_DIGEST_SIZE
250 #elif (SHA512_256_SUPPORT == ENABLED)
251  #define MAX_HASH_DIGEST_SIZE SHA512_256_DIGEST_SIZE
252 #elif (SHA256_SUPPORT == ENABLED)
253  #define MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
254 #elif (SM3_SUPPORT == ENABLED)
255  #define MAX_HASH_DIGEST_SIZE SM3_DIGEST_SIZE
256 #elif (BLAKE2S224_SUPPORT == ENABLED)
257  #define MAX_HASH_DIGEST_SIZE BLAKE2S224_DIGEST_SIZE
258 #elif (SHA3_224_SUPPORT == ENABLED)
259  #define MAX_HASH_DIGEST_SIZE SHA3_224_DIGEST_SIZE
260 #elif (SHA512_224_SUPPORT == ENABLED)
261  #define MAX_HASH_DIGEST_SIZE SHA512_224_DIGEST_SIZE
262 #elif (SHA224_SUPPORT == ENABLED)
263  #define MAX_HASH_DIGEST_SIZE SHA224_DIGEST_SIZE
264 #elif (TIGER_SUPPORT == ENABLED)
265  #define MAX_HASH_DIGEST_SIZE TIGER_DIGEST_SIZE
266 #elif (BLAKE2B160_SUPPORT == ENABLED)
267  #define MAX_HASH_DIGEST_SIZE BLAKE2B160_DIGEST_SIZE
268 #elif (BLAKE2S160_SUPPORT == ENABLED)
269  #define MAX_HASH_DIGEST_SIZE BLAKE2S160_DIGEST_SIZE
270 #elif (SHA1_SUPPORT == ENABLED)
271  #define MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
272 #elif (RIPEMD160_SUPPORT == ENABLED)
273  #define MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
274 #elif (BLAKE2S128_SUPPORT == ENABLED)
275  #define MAX_HASH_DIGEST_SIZE BLAKE2S128_DIGEST_SIZE
276 #elif (RIPEMD128_SUPPORT == ENABLED)
277  #define MAX_HASH_DIGEST_SIZE RIPEMD128_DIGEST_SIZE
278 #elif (MD5_SUPPORT == ENABLED)
279  #define MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
280 #elif (MD4_SUPPORT == ENABLED)
281  #define MAX_HASH_DIGEST_SIZE MD4_DIGEST_SIZE
282 #elif (MD2_SUPPORT == ENABLED)
283  #define MAX_HASH_DIGEST_SIZE MD2_DIGEST_SIZE
284 #endif
285 
286 //C++ guard
287 #ifdef __cplusplus
288 extern "C" {
289 #endif
290 
291 
292 /**
293  * @brief Generic hash algorithm context
294  **/
295 
296 typedef union
297 {
298  uint8_t digest[MAX_HASH_DIGEST_SIZE];
299 #if (MD2_SUPPORT == ENABLED)
301 #endif
302 #if (MD4_SUPPORT == ENABLED)
304 #endif
305 #if (MD5_SUPPORT == ENABLED)
307 #endif
308 #if (RIPEMD128_SUPPORT == ENABLED)
310 #endif
311 #if (RIPEMD160_SUPPORT == ENABLED)
313 #endif
314 #if (SHA1_SUPPORT == ENABLED)
316 #endif
317 #if (SHA224_SUPPORT == ENABLED)
319 #endif
320 #if (SHA256_SUPPORT == ENABLED)
322 #endif
323 #if (SHA384_SUPPORT == ENABLED)
325 #endif
326 #if (SHA512_SUPPORT == ENABLED)
328 #endif
329 #if (SHA512_224_SUPPORT == ENABLED)
331 #endif
332 #if (SHA512_256_SUPPORT == ENABLED)
334 #endif
335 #if (SHA3_224_SUPPORT == ENABLED)
337 #endif
338 #if (SHA3_256_SUPPORT == ENABLED)
340 #endif
341 #if (SHA3_384_SUPPORT == ENABLED)
343 #endif
344 #if (SHA3_512_SUPPORT == ENABLED)
346 #endif
347 #if (BLAKE2B160_SUPPORT == ENABLED)
349 #endif
350 #if (BLAKE2B256_SUPPORT == ENABLED)
352 #endif
353 #if (BLAKE2B384_SUPPORT == ENABLED)
355 #endif
356 #if (BLAKE2B512_SUPPORT == ENABLED)
358 #endif
359 #if (BLAKE2S128_SUPPORT == ENABLED)
361 #endif
362 #if (BLAKE2S160_SUPPORT == ENABLED)
364 #endif
365 #if (BLAKE2S224_SUPPORT == ENABLED)
367 #endif
368 #if (BLAKE2S256_SUPPORT == ENABLED)
370 #endif
371 #if (SM3_SUPPORT == ENABLED)
373 #endif
374 #if (TIGER_SUPPORT == ENABLED)
376 #endif
377 #if (WHIRLPOOL_SUPPORT == ENABLED)
379 #endif
380 } HashContext;
381 
382 
383 //C++ guard
384 #ifdef __cplusplus
385 }
386 #endif
387 
388 #endif
BLAKE2b-160 hash function.
BLAKE2b-256 hash function.
BLAKE2b-384 hash function.
BLAKE2b-512 hash function.
BLAKE2s-128 hash function.
BLAKE2s-160 hash function.
BLAKE2s-224 hash function.
BLAKE2s-256 hash function.
General definitions for cryptographic algorithms.
#define MAX_HASH_DIGEST_SIZE
MD2 (Message-Digest Algorithm)
MD4 (Message-Digest Algorithm)
MD5 (Message-Digest Algorithm)
RIPEMD-128 hash function.
RIPEMD-160 hash function.
SHA-1 (Secure Hash Algorithm 1)
SHA-224 (Secure Hash Algorithm 224)
SHA-256 (Secure Hash Algorithm 256)
SHA-384 (Secure Hash Algorithm 384)
SHA3-224 hash function (SHA-3 with 224-bit output)
SHA3-256 hash function (SHA-3 with 256-bit output)
SHA3-384 hash function (SHA-3 with 384-bit output)
SHA3-512 hash function (SHA-3 with 512-bit output)
SHA-512 (Secure Hash Algorithm 512)
SHA-512/224 (Secure Hash Algorithm)
SHA-512/256 (Secure Hash Algorithm)
SM3 hash function.
BLAKE2b algorithm context.
Definition: blake2b.h:51
BLAKE2s algorithm context.
Definition: blake2s.h:51
Keccak context.
Definition: keccak.h:110
MD2 algorithm context.
Definition: md2.h:57
MD4 algorithm context.
Definition: md4.h:57
MD5 algorithm context.
Definition: md5.h:62
RIPEMD-128 algorithm context.
Definition: ripemd128.h:57
RIPEMD-160 algorithm context.
Definition: ripemd160.h:57
SHA-1 algorithm context.
Definition: sha1.h:62
SHA-256 algorithm context.
Definition: sha256.h:62
SHA-512 algorithm context.
Definition: sha512.h:62
SM3 algorithm context.
Definition: sm3.h:62
Tiger algorithm context.
Definition: tiger.h:57
Whirlpool algorithm context.
Definition: whirlpool.h:57
Tiger hash function.
Generic hash algorithm context.
Ripemd160Context ripemd160Context
WhirlpoolContext whirlpoolContext
Sha256Context sha256Context
Sha512Context sha512Context
Sha1Context sha1Context
Sha3_224Context sha3_224Context
Sha512_256Context sha512_256Context
Blake2b256Context blake2b256Context
Blake2s224Context blake2s224Context
Sha3_512Context sha3_512Context
Md4Context md4Context
Blake2b512Context blake2b512Context
Md2Context md2Context
Blake2s256Context blake2s256Context
Blake2s160Context blake2s160Context
Sm3Context sm3Context
Md5Context md5Context
Sha224Context sha224Context
Blake2s128Context blake2s128Context
Sha384Context sha384Context
Sha3_256Context sha3_256Context
Sha512_224Context sha512_224Context
Sha3_384Context sha3_384Context
Ripemd128Context ripemd128Context
TigerContext tigerContext
Blake2b384Context blake2b384Context
Blake2b160Context blake2b160Context
Whirlpool hash function.