crypto.h
Go to the documentation of this file.
1 /**
2  * @file crypto.h
3  * @brief General definitions for cryptographic 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.4
29  **/
30 
31 #ifndef _CRYPTO_H
32 #define _CRYPTO_H
33 
34 //Dependencies
35 #include "os_port.h"
36 #include "crypto_config.h"
37 #include "crypto_legacy.h"
38 #include "cpu_endian.h"
39 #include "error.h"
40 
41 
42 /*
43  * CycloneCRYPTO Open is licensed under GPL version 2. In particular:
44  *
45  * - If you link your program to CycloneCRYPTO Open, the result is a derivative
46  * work that can only be distributed under the same GPL license terms.
47  *
48  * - If additions or changes to CycloneCRYPTO Open are made, the result is a
49  * derivative work that can only be distributed under the same license terms.
50  *
51  * - The GPL license requires that you make the source code available to
52  * whoever you make the binary available to.
53  *
54  * - If you sell or distribute a hardware product that runs CycloneCRYPTO Open,
55  * the GPL license requires you to provide public and full access to all
56  * source code on a nondiscriminatory basis.
57  *
58  * If you fully understand and accept the terms of the GPL license, then edit
59  * the os_port_config.h header and add the following directive:
60  *
61  * #define GPL_LICENSE_TERMS_ACCEPTED
62  */
63 
64 #ifndef GPL_LICENSE_TERMS_ACCEPTED
65  #error Before compiling CycloneCRYPTO Open, you must accept the terms of the GPL license
66 #endif
67 
68 //Version string
69 #define CYCLONE_CRYPTO_VERSION_STRING "2.5.4"
70 //Major version
71 #define CYCLONE_CRYPTO_MAJOR_VERSION 2
72 //Minor version
73 #define CYCLONE_CRYPTO_MINOR_VERSION 5
74 //Revision number
75 #define CYCLONE_CRYPTO_REV_NUMBER 4
76 
77 //Static memory allocation
78 #ifndef CRYPTO_STATIC_MEM_SUPPORT
79  #define CRYPTO_STATIC_MEM_SUPPORT DISABLED
80 #elif (CRYPTO_STATIC_MEM_SUPPORT != ENABLED && CRYPTO_STATIC_MEM_SUPPORT != DISABLED)
81  #error CRYPTO_STATIC_MEM_SUPPORT parameter is not valid
82 #endif
83 
84 //Multiple precision integer support
85 #ifndef MPI_SUPPORT
86  #define MPI_SUPPORT ENABLED
87 #elif (MPI_SUPPORT != ENABLED && MPI_SUPPORT != DISABLED)
88  #error MPI_SUPPORT parameter is not valid
89 #endif
90 
91 //Assembly optimizations for time-critical routines
92 #ifndef MPI_ASM_SUPPORT
93  #define MPI_ASM_SUPPORT DISABLED
94 #elif (MPI_ASM_SUPPORT != ENABLED && MPI_ASM_SUPPORT != DISABLED)
95  #error MPI_ASM_SUPPORT parameter is not valid
96 #endif
97 
98 //Base64 encoding support
99 #ifndef BASE64_SUPPORT
100  #define BASE64_SUPPORT ENABLED
101 #elif (BASE64_SUPPORT != ENABLED && BASE64_SUPPORT != DISABLED)
102  #error BASE64_SUPPORT parameter is not valid
103 #endif
104 
105 //Base64url encoding support
106 #ifndef BASE64URL_SUPPORT
107  #define BASE64URL_SUPPORT ENABLED
108 #elif (BASE64URL_SUPPORT != ENABLED && BASE64URL_SUPPORT != DISABLED)
109  #error BASE64URL_SUPPORT parameter is not valid
110 #endif
111 
112 //Radix64 encoding support
113 #ifndef RADIX64_SUPPORT
114  #define RADIX64_SUPPORT ENABLED
115 #elif (RADIX64_SUPPORT != ENABLED && RADIX64_SUPPORT != DISABLED)
116  #error RADIX64_SUPPORT parameter is not valid
117 #endif
118 
119 //MD2 hash support
120 #ifndef MD2_SUPPORT
121  #define MD2_SUPPORT DISABLED
122 #elif (MD2_SUPPORT != ENABLED && MD2_SUPPORT != DISABLED)
123  #error MD2_SUPPORT parameter is not valid
124 #endif
125 
126 //MD4 hash support
127 #ifndef MD4_SUPPORT
128  #define MD4_SUPPORT DISABLED
129 #elif (MD4_SUPPORT != ENABLED && MD4_SUPPORT != DISABLED)
130  #error MD4_SUPPORT parameter is not valid
131 #endif
132 
133 //MD5 hash support
134 #ifndef MD5_SUPPORT
135  #define MD5_SUPPORT DISABLED
136 #elif (MD5_SUPPORT != ENABLED && MD5_SUPPORT != DISABLED)
137  #error MD5_SUPPORT parameter is not valid
138 #endif
139 
140 //RIPEMD-128 hash support
141 #ifndef RIPEMD128_SUPPORT
142  #define RIPEMD128_SUPPORT DISABLED
143 #elif (RIPEMD128_SUPPORT != ENABLED && RIPEMD128_SUPPORT != DISABLED)
144  #error RIPEMD128_SUPPORT parameter is not valid
145 #endif
146 
147 //RIPEMD-160 hash support
148 #ifndef RIPEMD160_SUPPORT
149  #define RIPEMD160_SUPPORT DISABLED
150 #elif (RIPEMD160_SUPPORT != ENABLED && RIPEMD160_SUPPORT != DISABLED)
151  #error RIPEMD160_SUPPORT parameter is not valid
152 #endif
153 
154 //SHA-1 hash support
155 #ifndef SHA1_SUPPORT
156  #define SHA1_SUPPORT ENABLED
157 #elif (SHA1_SUPPORT != ENABLED && SHA1_SUPPORT != DISABLED)
158  #error SHA1_SUPPORT parameter is not valid
159 #endif
160 
161 //SHA-224 hash support
162 #ifndef SHA224_SUPPORT
163  #define SHA224_SUPPORT ENABLED
164 #elif (SHA224_SUPPORT != ENABLED && SHA224_SUPPORT != DISABLED)
165  #error SHA224_SUPPORT parameter is not valid
166 #endif
167 
168 //SHA-256 hash support
169 #ifndef SHA256_SUPPORT
170  #define SHA256_SUPPORT ENABLED
171 #elif (SHA256_SUPPORT != ENABLED && SHA256_SUPPORT != DISABLED)
172  #error SHA256_SUPPORT parameter is not valid
173 #endif
174 
175 //SHA-384 hash support
176 #ifndef SHA384_SUPPORT
177  #define SHA384_SUPPORT ENABLED
178 #elif (SHA384_SUPPORT != ENABLED && SHA384_SUPPORT != DISABLED)
179  #error SHA384_SUPPORT parameter is not valid
180 #endif
181 
182 //SHA-512 hash support
183 #ifndef SHA512_SUPPORT
184  #define SHA512_SUPPORT ENABLED
185 #elif (SHA512_SUPPORT != ENABLED && SHA512_SUPPORT != DISABLED)
186  #error SHA512_SUPPORT parameter is not valid
187 #endif
188 
189 //SHA-512/224 hash support
190 #ifndef SHA512_224_SUPPORT
191  #define SHA512_224_SUPPORT DISABLED
192 #elif (SHA512_224_SUPPORT != ENABLED && SHA512_224_SUPPORT != DISABLED)
193  #error SHA512_224_SUPPORT parameter is not valid
194 #endif
195 
196 //SHA-512/256 hash support
197 #ifndef SHA512_256_SUPPORT
198  #define SHA512_256_SUPPORT DISABLED
199 #elif (SHA512_256_SUPPORT != ENABLED && SHA512_256_SUPPORT != DISABLED)
200  #error SHA512_256_SUPPORT parameter is not valid
201 #endif
202 
203 //SHA3-224 hash support
204 #ifndef SHA3_224_SUPPORT
205  #define SHA3_224_SUPPORT DISABLED
206 #elif (SHA3_224_SUPPORT != ENABLED && SHA3_224_SUPPORT != DISABLED)
207  #error SHA3_224_SUPPORT parameter is not valid
208 #endif
209 
210 //SHA3-256 hash support
211 #ifndef SHA3_256_SUPPORT
212  #define SHA3_256_SUPPORT DISABLED
213 #elif (SHA3_256_SUPPORT != ENABLED && SHA3_256_SUPPORT != DISABLED)
214  #error SHA3_256_SUPPORT parameter is not valid
215 #endif
216 
217 //SHA3-384 hash support
218 #ifndef SHA3_384_SUPPORT
219  #define SHA3_384_SUPPORT DISABLED
220 #elif (SHA3_384_SUPPORT != ENABLED && SHA3_384_SUPPORT != DISABLED)
221  #error SHA3_384_SUPPORT parameter is not valid
222 #endif
223 
224 //SHA3-512 hash support
225 #ifndef SHA3_512_SUPPORT
226  #define SHA3_512_SUPPORT DISABLED
227 #elif (SHA3_512_SUPPORT != ENABLED && SHA3_512_SUPPORT != DISABLED)
228  #error SHA3_512_SUPPORT parameter is not valid
229 #endif
230 
231 //Ascon-Hash256 hash support
232 #ifndef ASCON_HASH256_SUPPORT
233  #define ASCON_HASH256_SUPPORT DISABLED
234 #elif (ASCON_HASH256_SUPPORT != ENABLED && ASCON_HASH256_SUPPORT != DISABLED)
235  #error ASCON_HASH256_SUPPORT parameter is not valid
236 #endif
237 
238 //BLAKE2b support
239 #ifndef BLAKE2B_SUPPORT
240  #define BLAKE2B_SUPPORT DISABLED
241 #elif (BLAKE2B_SUPPORT != ENABLED && BLAKE2B_SUPPORT != DISABLED)
242  #error BLAKE2B_SUPPORT parameter is not valid
243 #endif
244 
245 //BLAKE2b-160 hash support
246 #ifndef BLAKE2B160_SUPPORT
247  #define BLAKE2B160_SUPPORT DISABLED
248 #elif (BLAKE2B160_SUPPORT != ENABLED && BLAKE2B160_SUPPORT != DISABLED)
249  #error BLAKE2B160_SUPPORT parameter is not valid
250 #endif
251 
252 //BLAKE2b-256 hash support
253 #ifndef BLAKE2B256_SUPPORT
254  #define BLAKE2B256_SUPPORT DISABLED
255 #elif (BLAKE2B256_SUPPORT != ENABLED && BLAKE2B256_SUPPORT != DISABLED)
256  #error BLAKE2B256_SUPPORT parameter is not valid
257 #endif
258 
259 //BLAKE2b-384 hash support
260 #ifndef BLAKE2B384_SUPPORT
261  #define BLAKE2B384_SUPPORT DISABLED
262 #elif (BLAKE2B384_SUPPORT != ENABLED && BLAKE2B384_SUPPORT != DISABLED)
263  #error BLAKE2B384_SUPPORT parameter is not valid
264 #endif
265 
266 //BLAKE2b-512 hash support
267 #ifndef BLAKE2B512_SUPPORT
268  #define BLAKE2B512_SUPPORT DISABLED
269 #elif (BLAKE2B512_SUPPORT != ENABLED && BLAKE2B512_SUPPORT != DISABLED)
270  #error BLAKE2B512_SUPPORT parameter is not valid
271 #endif
272 
273 //BLAKE2s support
274 #ifndef BLAKE2S_SUPPORT
275  #define BLAKE2S_SUPPORT DISABLED
276 #elif (BLAKE2S_SUPPORT != ENABLED && BLAKE2S_SUPPORT != DISABLED)
277  #error BLAKE2S_SUPPORT parameter is not valid
278 #endif
279 
280 //BLAKE2s-128 hash support
281 #ifndef BLAKE2S128_SUPPORT
282  #define BLAKE2S128_SUPPORT DISABLED
283 #elif (BLAKE2S128_SUPPORT != ENABLED && BLAKE2S128_SUPPORT != DISABLED)
284  #error BLAKE2S128_SUPPORT parameter is not valid
285 #endif
286 
287 //BLAKE2s-160 hash support
288 #ifndef BLAKE2S160_SUPPORT
289  #define BLAKE2S160_SUPPORT DISABLED
290 #elif (BLAKE2S160_SUPPORT != ENABLED && BLAKE2S160_SUPPORT != DISABLED)
291  #error BLAKE2S160_SUPPORT parameter is not valid
292 #endif
293 
294 //BLAKE2s-224 hash support
295 #ifndef BLAKE2S224_SUPPORT
296  #define BLAKE2S224_SUPPORT DISABLED
297 #elif (BLAKE2S224_SUPPORT != ENABLED && BLAKE2S224_SUPPORT != DISABLED)
298  #error BLAKE2S224_SUPPORT parameter is not valid
299 #endif
300 
301 //BLAKE2s-256 hash support
302 #ifndef BLAKE2S256_SUPPORT
303  #define BLAKE2S256_SUPPORT DISABLED
304 #elif (BLAKE2S256_SUPPORT != ENABLED && BLAKE2S256_SUPPORT != DISABLED)
305  #error BLAKE2S256_SUPPORT parameter is not valid
306 #endif
307 
308 //SM3 hash support
309 #ifndef SM3_SUPPORT
310  #define SM3_SUPPORT DISABLED
311 #elif (SM3_SUPPORT != ENABLED && SM3_SUPPORT != DISABLED)
312  #error SM3_SUPPORT parameter is not valid
313 #endif
314 
315 //Tiger hash support
316 #ifndef TIGER_SUPPORT
317  #define TIGER_SUPPORT DISABLED
318 #elif (TIGER_SUPPORT != ENABLED && TIGER_SUPPORT != DISABLED)
319  #error TIGER_SUPPORT parameter is not valid
320 #endif
321 
322 //Whirlpool hash support
323 #ifndef WHIRLPOOL_SUPPORT
324  #define WHIRLPOOL_SUPPORT DISABLED
325 #elif (WHIRLPOOL_SUPPORT != ENABLED && WHIRLPOOL_SUPPORT != DISABLED)
326  #error WHIRLPOOL_SUPPORT parameter is not valid
327 #endif
328 
329 //Keccak support
330 #ifndef KECCAK_SUPPORT
331  #define KECCAK_SUPPORT DISABLED
332 #elif (KECCAK_SUPPORT != ENABLED && KECCAK_SUPPORT != DISABLED)
333  #error KECCAK_SUPPORT parameter is not valid
334 #endif
335 
336 //SHAKE support
337 #ifndef SHAKE_SUPPORT
338  #define SHAKE_SUPPORT DISABLED
339 #elif (SHAKE_SUPPORT != ENABLED && SHAKE_SUPPORT != DISABLED)
340  #error SHAKE_SUPPORT parameter is not valid
341 #endif
342 
343 //cSHAKE support
344 #ifndef CSHAKE_SUPPORT
345  #define CSHAKE_SUPPORT DISABLED
346 #elif (CSHAKE_SUPPORT != ENABLED && CSHAKE_SUPPORT != DISABLED)
347  #error CSHAKE_SUPPORT parameter is not valid
348 #endif
349 
350 //Ascon-XOF128 support
351 #ifndef ASCON_XOF128_SUPPORT
352  #define ASCON_XOF128_SUPPORT DISABLED
353 #elif (ASCON_XOF128_SUPPORT != ENABLED && ASCON_XOF128_SUPPORT != DISABLED)
354  #error ASCON_XOF128_SUPPORT parameter is not valid
355 #endif
356 
357 //Ascon-CXOF128 support
358 #ifndef ASCON_CXOF128_SUPPORT
359  #define ASCON_CXOF128_SUPPORT DISABLED
360 #elif (ASCON_CXOF128_SUPPORT != ENABLED && ASCON_CXOF128_SUPPORT != DISABLED)
361  #error ASCON_CXOF128_SUPPORT parameter is not valid
362 #endif
363 
364 //CMAC support
365 #ifndef CMAC_SUPPORT
366  #define CMAC_SUPPORT DISABLED
367 #elif (CMAC_SUPPORT != ENABLED && CMAC_SUPPORT != DISABLED)
368  #error CMAC_SUPPORT parameter is not valid
369 #endif
370 
371 //HMAC support
372 #ifndef HMAC_SUPPORT
373  #define HMAC_SUPPORT ENABLED
374 #elif (HMAC_SUPPORT != ENABLED && HMAC_SUPPORT != DISABLED)
375  #error HMAC_SUPPORT parameter is not valid
376 #endif
377 
378 //GMAC support
379 #ifndef GMAC_SUPPORT
380  #define GMAC_SUPPORT DISABLED
381 #elif (GMAC_SUPPORT != ENABLED && GMAC_SUPPORT != DISABLED)
382  #error GMAC_SUPPORT parameter is not valid
383 #endif
384 
385 //KMAC support
386 #ifndef KMAC_SUPPORT
387  #define KMAC_SUPPORT DISABLED
388 #elif (KMAC_SUPPORT != ENABLED && KMAC_SUPPORT != DISABLED)
389  #error KMAC_SUPPORT parameter is not valid
390 #endif
391 
392 //XCBC-MAC support
393 #ifndef XCBC_MAC_SUPPORT
394  #define XCBC_MAC_SUPPORT DISABLED
395 #elif (XCBC_MAC_SUPPORT != ENABLED && XCBC_MAC_SUPPORT != DISABLED)
396  #error XCBC_MAC_SUPPORT parameter is not valid
397 #endif
398 
399 //Poly1305 support
400 #ifndef POLY1305_SUPPORT
401  #define POLY1305_SUPPORT DISABLED
402 #elif (POLY1305_SUPPORT != ENABLED && POLY1305_SUPPORT != DISABLED)
403  #error POLY1305_SUPPORT parameter is not valid
404 #endif
405 
406 //RC2 block cipher support
407 #ifndef RC2_SUPPORT
408  #define RC2_SUPPORT DISABLED
409 #elif (RC2_SUPPORT != ENABLED && RC2_SUPPORT != DISABLED)
410  #error RC2_SUPPORT parameter is not valid
411 #endif
412 
413 //RC4 stream cipher support
414 #ifndef RC4_SUPPORT
415  #define RC4_SUPPORT DISABLED
416 #elif (RC4_SUPPORT != ENABLED && RC4_SUPPORT != DISABLED)
417  #error RC4_SUPPORT parameter is not valid
418 #endif
419 
420 //RC6 block cipher support
421 #ifndef RC6_SUPPORT
422  #define RC6_SUPPORT DISABLED
423 #elif (RC6_SUPPORT != ENABLED && RC6_SUPPORT != DISABLED)
424  #error RC6_SUPPORT parameter is not valid
425 #endif
426 
427 //CAST-128 block cipher support
428 #ifndef CAST128_SUPPORT
429  #define CAST128_SUPPORT DISABLED
430 #elif (CAST128_SUPPORT != ENABLED && CAST128_SUPPORT != DISABLED)
431  #error CAST128_SUPPORT parameter is not valid
432 #endif
433 
434 //CAST-256 block cipher support
435 #ifndef CAST256_SUPPORT
436  #define CAST256_SUPPORT DISABLED
437 #elif (CAST256_SUPPORT != ENABLED && CAST256_SUPPORT != DISABLED)
438  #error CAST256_SUPPORT parameter is not valid
439 #endif
440 
441 //IDEA block cipher support
442 #ifndef IDEA_SUPPORT
443  #define IDEA_SUPPORT DISABLED
444 #elif (IDEA_SUPPORT != ENABLED && IDEA_SUPPORT != DISABLED)
445  #error IDEA_SUPPORT parameter is not valid
446 #endif
447 
448 //DES block cipher support
449 #ifndef DES_SUPPORT
450  #define DES_SUPPORT DISABLED
451 #elif (DES_SUPPORT != ENABLED && DES_SUPPORT != DISABLED)
452  #error DES_SUPPORT parameter is not valid
453 #endif
454 
455 //Triple DES block cipher support
456 #ifndef DES3_SUPPORT
457  #define DES3_SUPPORT DISABLED
458 #elif (DES3_SUPPORT != ENABLED && DES3_SUPPORT != DISABLED)
459  #error DES3_SUPPORT parameter is not valid
460 #endif
461 
462 //AES block cipher support
463 #ifndef AES_SUPPORT
464  #define AES_SUPPORT ENABLED
465 #elif (AES_SUPPORT != ENABLED && AES_SUPPORT != DISABLED)
466  #error AES_SUPPORT parameter is not valid
467 #endif
468 
469 //Blowfish block cipher support
470 #ifndef BLOWFISH_SUPPORT
471  #define BLOWFISH_SUPPORT DISABLED
472 #elif (BLOWFISH_SUPPORT != ENABLED && BLOWFISH_SUPPORT != DISABLED)
473  #error BLOWFISH_SUPPORT parameter is not valid
474 #endif
475 
476 //Twofish block cipher support
477 #ifndef TWOFISH_SUPPORT
478  #define TWOFISH_SUPPORT DISABLED
479 #elif (TWOFISH_SUPPORT != ENABLED && TWOFISH_SUPPORT != DISABLED)
480  #error TWOFISH_SUPPORT parameter is not valid
481 #endif
482 
483 //MARS block cipher support
484 #ifndef MARS_SUPPORT
485  #define MARS_SUPPORT DISABLED
486 #elif (MARS_SUPPORT != ENABLED && MARS_SUPPORT != DISABLED)
487  #error MARS_SUPPORT parameter is not valid
488 #endif
489 
490 //Serpent block cipher support
491 #ifndef SERPENT_SUPPORT
492  #define SERPENT_SUPPORT DISABLED
493 #elif (SERPENT_SUPPORT != ENABLED && SERPENT_SUPPORT != DISABLED)
494  #error SERPENT_SUPPORT parameter is not valid
495 #endif
496 
497 //Camellia block cipher support
498 #ifndef CAMELLIA_SUPPORT
499  #define CAMELLIA_SUPPORT DISABLED
500 #elif (CAMELLIA_SUPPORT != ENABLED && CAMELLIA_SUPPORT != DISABLED)
501  #error CAMELLIA_SUPPORT parameter is not valid
502 #endif
503 
504 //ARIA block cipher support
505 #ifndef ARIA_SUPPORT
506  #define ARIA_SUPPORT DISABLED
507 #elif (ARIA_SUPPORT != ENABLED && ARIA_SUPPORT != DISABLED)
508  #error ARIA_SUPPORT parameter is not valid
509 #endif
510 
511 //SEED block cipher support
512 #ifndef SEED_SUPPORT
513  #define SEED_SUPPORT DISABLED
514 #elif (SEED_SUPPORT != ENABLED && SEED_SUPPORT != DISABLED)
515  #error SEED_SUPPORT parameter is not valid
516 #endif
517 
518 //SM4 block cipher support
519 #ifndef SM4_SUPPORT
520  #define SM4_SUPPORT DISABLED
521 #elif (SM4_SUPPORT != ENABLED && SM4_SUPPORT != DISABLED)
522  #error SM4_SUPPORT parameter is not valid
523 #endif
524 
525 //PRESENT block cipher support
526 #ifndef PRESENT_SUPPORT
527  #define PRESENT_SUPPORT DISABLED
528 #elif (PRESENT_SUPPORT != ENABLED && PRESENT_SUPPORT != DISABLED)
529  #error PRESENT_SUPPORT parameter is not valid
530 #endif
531 
532 //TEA block cipher support
533 #ifndef TEA_SUPPORT
534  #define TEA_SUPPORT DISABLED
535 #elif (TEA_SUPPORT != ENABLED && TEA_SUPPORT != DISABLED)
536  #error TEA_SUPPORT parameter is not valid
537 #endif
538 
539 //XTEA block cipher support
540 #ifndef XTEA_SUPPORT
541  #define XTEA_SUPPORT DISABLED
542 #elif (XTEA_SUPPORT != ENABLED && XTEA_SUPPORT != DISABLED)
543  #error XTEA_SUPPORT parameter is not valid
544 #endif
545 
546 //ChaCha stream cipher support
547 #ifndef CHACHA_SUPPORT
548  #define CHACHA_SUPPORT DISABLED
549 #elif (CHACHA_SUPPORT != ENABLED && CHACHA_SUPPORT != DISABLED)
550  #error CHACHA_SUPPORT parameter is not valid
551 #endif
552 
553 //Salsa20 stream cipher support
554 #ifndef SALSA20_SUPPORT
555  #define SALSA20_SUPPORT DISABLED
556 #elif (SALSA20_SUPPORT != ENABLED && SALSA20_SUPPORT != DISABLED)
557  #error SALSA20_SUPPORT parameter is not valid
558 #endif
559 
560 //Trivium stream cipher support
561 #ifndef TRIVIUM_SUPPORT
562  #define TRIVIUM_SUPPORT DISABLED
563 #elif (TRIVIUM_SUPPORT != ENABLED && TRIVIUM_SUPPORT != DISABLED)
564  #error TRIVIUM_SUPPORT parameter is not valid
565 #endif
566 
567 //ZUC stream cipher support
568 #ifndef ZUC_SUPPORT
569  #define ZUC_SUPPORT DISABLED
570 #elif (ZUC_SUPPORT != ENABLED && ZUC_SUPPORT != DISABLED)
571  #error ZUC_SUPPORT parameter is not valid
572 #endif
573 
574 //ECB mode support
575 #ifndef ECB_SUPPORT
576  #define ECB_SUPPORT ENABLED
577 #elif (ECB_SUPPORT != ENABLED && ECB_SUPPORT != DISABLED)
578  #error ECB_SUPPORT parameter is not valid
579 #endif
580 
581 //CBC mode support
582 #ifndef CBC_SUPPORT
583  #define CBC_SUPPORT ENABLED
584 #elif (CBC_SUPPORT != ENABLED && CBC_SUPPORT != DISABLED)
585  #error CBC_SUPPORT parameter is not valid
586 #endif
587 
588 //CFB mode support
589 #ifndef CFB_SUPPORT
590  #define CFB_SUPPORT ENABLED
591 #elif (CFB_SUPPORT != ENABLED && CFB_SUPPORT != DISABLED)
592  #error CFB_SUPPORT parameter is not valid
593 #endif
594 
595 //OFB mode support
596 #ifndef OFB_SUPPORT
597  #define OFB_SUPPORT ENABLED
598 #elif (OFB_SUPPORT != ENABLED && OFB_SUPPORT != DISABLED)
599  #error OFB_SUPPORT parameter is not valid
600 #endif
601 
602 //CTR mode support
603 #ifndef CTR_SUPPORT
604  #define CTR_SUPPORT ENABLED
605 #elif (CTR_SUPPORT != ENABLED && CTR_SUPPORT != DISABLED)
606  #error CTR_SUPPORT parameter is not valid
607 #endif
608 
609 //XTS mode support
610 #ifndef XTS_SUPPORT
611  #define XTS_SUPPORT ENABLED
612 #elif (XTS_SUPPORT != ENABLED && XTS_SUPPORT != DISABLED)
613  #error XTS_SUPPORT parameter is not valid
614 #endif
615 
616 //CCM mode support
617 #ifndef CCM_SUPPORT
618  #define CCM_SUPPORT ENABLED
619 #elif (CCM_SUPPORT != ENABLED && CCM_SUPPORT != DISABLED)
620  #error CCM_SUPPORT parameter is not valid
621 #endif
622 
623 //GCM mode support
624 #ifndef GCM_SUPPORT
625  #define GCM_SUPPORT ENABLED
626 #elif (GCM_SUPPORT != ENABLED && GCM_SUPPORT != DISABLED)
627  #error GCM_SUPPORT parameter is not valid
628 #endif
629 
630 //SIV mode support
631 #ifndef SIV_SUPPORT
632  #define SIV_SUPPORT DISABLED
633 #elif (SIV_SUPPORT != ENABLED && SIV_SUPPORT != DISABLED)
634  #error SIV_SUPPORT parameter is not valid
635 #endif
636 
637 //Ascon-AEAD128 support
638 #ifndef ASCON_AEAD128_SUPPORT
639  #define ASCON_AEAD128_SUPPORT DISABLED
640 #elif (ASCON_AEAD128_SUPPORT != ENABLED && ASCON_AEAD128_SUPPORT != DISABLED)
641  #error ASCON_AEAD128_SUPPORT parameter is not valid
642 #endif
643 
644 //ChaCha20Poly1305 support
645 #ifndef CHACHA20_POLY1305_SUPPORT
646  #define CHACHA20_POLY1305_SUPPORT DISABLED
647 #elif (CHACHA20_POLY1305_SUPPORT != ENABLED && CHACHA20_POLY1305_SUPPORT != DISABLED)
648  #error CHACHA20_POLY1305_SUPPORT parameter is not valid
649 #endif
650 
651 //Diffie-Hellman support
652 #ifndef DH_SUPPORT
653  #define DH_SUPPORT DISABLED
654 #elif (DH_SUPPORT != ENABLED && DH_SUPPORT != DISABLED)
655  #error DH_SUPPORT parameter is not valid
656 #endif
657 
658 //RSA support
659 #ifndef RSA_SUPPORT
660  #define RSA_SUPPORT ENABLED
661 #elif (RSA_SUPPORT != ENABLED && RSA_SUPPORT != DISABLED)
662  #error RSA_SUPPORT parameter is not valid
663 #endif
664 
665 //DSA support
666 #ifndef DSA_SUPPORT
667  #define DSA_SUPPORT DISABLED
668 #elif (DSA_SUPPORT != ENABLED && DSA_SUPPORT != DISABLED)
669  #error DSA_SUPPORT parameter is not valid
670 #endif
671 
672 //Elliptic curve cryptography support
673 #ifndef EC_SUPPORT
674  #define EC_SUPPORT ENABLED
675 #elif (EC_SUPPORT != ENABLED && EC_SUPPORT != DISABLED)
676  #error EC_SUPPORT parameter is not valid
677 #endif
678 
679 //ECDH support
680 #ifndef ECDH_SUPPORT
681  #define ECDH_SUPPORT ENABLED
682 #elif (ECDH_SUPPORT != ENABLED && ECDH_SUPPORT != DISABLED)
683  #error ECDH_SUPPORT parameter is not valid
684 #endif
685 
686 //ECDSA support
687 #ifndef ECDSA_SUPPORT
688  #define ECDSA_SUPPORT ENABLED
689 #elif (ECDSA_SUPPORT != ENABLED && ECDSA_SUPPORT != DISABLED)
690  #error ECDSA_SUPPORT parameter is not valid
691 #endif
692 
693 //Key encapsulation mechanism support
694 #ifndef KEM_SUPPORT
695  #define KEM_SUPPORT DISABLED
696 #elif (KEM_SUPPORT != ENABLED && KEM_SUPPORT != DISABLED)
697  #error KEM_SUPPORT parameter is not valid
698 #endif
699 
700 //ML-KEM-512 support
701 #ifndef MLKEM512_SUPPORT
702  #define MLKEM512_SUPPORT DISABLED
703 #elif (MLKEM512_SUPPORT != ENABLED && MLKEM512_SUPPORT != DISABLED)
704  #error MLKEM512_SUPPORT parameter is not valid
705 #endif
706 
707 //ML-KEM-768 support
708 #ifndef MLKEM768_SUPPORT
709  #define MLKEM768_SUPPORT DISABLED
710 #elif (MLKEM768_SUPPORT != ENABLED && MLKEM768_SUPPORT != DISABLED)
711  #error MLKEM768_SUPPORT parameter is not valid
712 #endif
713 
714 //ML-KEM-1024 support
715 #ifndef MLKEM1024_SUPPORT
716  #define MLKEM1024_SUPPORT DISABLED
717 #elif (MLKEM1024_SUPPORT != ENABLED && MLKEM1024_SUPPORT != DISABLED)
718  #error MLKEM1024_SUPPORT parameter is not valid
719 #endif
720 
721 //Streamlined NTRU Prime 761 support
722 #ifndef SNTRUP761_SUPPORT
723  #define SNTRUP761_SUPPORT DISABLED
724 #elif (SNTRUP761_SUPPORT != ENABLED && SNTRUP761_SUPPORT != DISABLED)
725  #error SNTRUP761_SUPPORT parameter is not valid
726 #endif
727 
728 //HKDF support
729 #ifndef HKDF_SUPPORT
730  #define HKDF_SUPPORT DISABLED
731 #elif (HKDF_SUPPORT != ENABLED && HKDF_SUPPORT != DISABLED)
732  #error HKDF_SUPPORT parameter is not valid
733 #endif
734 
735 //PBKDF support
736 #ifndef PBKDF_SUPPORT
737  #define PBKDF_SUPPORT DISABLED
738 #elif (PBKDF_SUPPORT != ENABLED && PBKDF_SUPPORT != DISABLED)
739  #error PBKDF_SUPPORT parameter is not valid
740 #endif
741 
742 //Concat KDF support
743 #ifndef CONCAT_KDF_SUPPORT
744  #define CONCAT_KDF_SUPPORT DISABLED
745 #elif (CONCAT_KDF_SUPPORT != ENABLED && CONCAT_KDF_SUPPORT != DISABLED)
746  #error CONCAT_KDF_SUPPORT parameter is not valid
747 #endif
748 
749 //bcrypt support
750 #ifndef BCRYPT_SUPPORT
751  #define BCRYPT_SUPPORT DISABLED
752 #elif (BCRYPT_SUPPORT != ENABLED && BCRYPT_SUPPORT != DISABLED)
753  #error BCRYPT_SUPPORT parameter is not valid
754 #endif
755 
756 //scrypt support
757 #ifndef SCRYPT_SUPPORT
758  #define SCRYPT_SUPPORT DISABLED
759 #elif (SCRYPT_SUPPORT != ENABLED && SCRYPT_SUPPORT != DISABLED)
760  #error SCRYPT_SUPPORT parameter is not valid
761 #endif
762 
763 //MD5-crypt support
764 #ifndef MD5_CRYPT_SUPPORT
765  #define MD5_CRYPT_SUPPORT DISABLED
766 #elif (MD5_CRYPT_SUPPORT != ENABLED && MD5_CRYPT_SUPPORT != DISABLED)
767  #error MD5_CRYPT_SUPPORT parameter is not valid
768 #endif
769 
770 //SHA-crypt support
771 #ifndef SHA_CRYPT_SUPPORT
772  #define SHA_CRYPT_SUPPORT DISABLED
773 #elif (SHA_CRYPT_SUPPORT != ENABLED && SHA_CRYPT_SUPPORT != DISABLED)
774  #error SHA_CRYPT_SUPPORT parameter is not valid
775 #endif
776 
777 //Hash_DRBG PRNG support
778 #ifndef HASH_DRBG_SUPPORT
779  #define HASH_DRBG_SUPPORT DISABLED
780 #elif (HASH_DRBG_SUPPORT != ENABLED && HASH_DRBG_SUPPORT != DISABLED)
781  #error HASH_DRBG_SUPPORT parameter is not valid
782 #endif
783 
784 //HMAC_DRBG PRNG support
785 #ifndef HMAC_DRBG_SUPPORT
786  #define HMAC_DRBG_SUPPORT DISABLED
787 #elif (HMAC_DRBG_SUPPORT != ENABLED && HMAC_DRBG_SUPPORT != DISABLED)
788  #error HMAC_DRBG_SUPPORT parameter is not valid
789 #endif
790 
791 //CTR_DRBG PRNG support
792 #ifndef CTR_DRBG_SUPPORT
793  #define CTR_DRBG_SUPPORT DISABLED
794 #elif (CTR_DRBG_SUPPORT != ENABLED && CTR_DRBG_SUPPORT != DISABLED)
795  #error CTR_DRBG_SUPPORT parameter is not valid
796 #endif
797 
798 //XDRBG PRNG support
799 #ifndef XDRBG_SUPPORT
800  #define XDRBG_SUPPORT DISABLED
801 #elif (XDRBG_SUPPORT != ENABLED && XDRBG_SUPPORT != DISABLED)
802  #error XDRBG_SUPPORT parameter is not valid
803 #endif
804 
805 //Yarrow PRNG support
806 #ifndef YARROW_SUPPORT
807  #define YARROW_SUPPORT ENABLED
808 #elif (YARROW_SUPPORT != ENABLED && YARROW_SUPPORT != DISABLED)
809  #error YARROW_SUPPORT parameter is not valid
810 #endif
811 
812 //Object identifier support
813 #ifndef OID_SUPPORT
814  #define OID_SUPPORT ENABLED
815 #elif (OID_SUPPORT != ENABLED && OID_SUPPORT != DISABLED)
816  #error OID_SUPPORT parameter is not valid
817 #endif
818 
819 //ASN.1 syntax support
820 #ifndef ASN1_SUPPORT
821  #define ASN1_SUPPORT ENABLED
822 #elif (ASN1_SUPPORT != ENABLED && ASN1_SUPPORT != DISABLED)
823  #error ASN1_SUPPORT parameter is not valid
824 #endif
825 
826 //PEM file support
827 #ifndef PEM_SUPPORT
828  #define PEM_SUPPORT ENABLED
829 #elif (PEM_SUPPORT != ENABLED && PEM_SUPPORT != DISABLED)
830  #error PEM_SUPPORT parameter is not valid
831 #endif
832 
833 //X.509 certificate support
834 #ifndef X509_SUPPORT
835  #define X509_SUPPORT ENABLED
836 #elif (X509_SUPPORT != ENABLED && X509_SUPPORT != DISABLED)
837  #error X509_SUPPORT parameter is not valid
838 #endif
839 
840 //PKCS #5 support
841 #ifndef PKCS5_SUPPORT
842  #define PKCS5_SUPPORT DISABLED
843 #elif (PKCS5_SUPPORT != ENABLED && PKCS5_SUPPORT != DISABLED)
844  #error PKCS5_SUPPORT parameter is not valid
845 #endif
846 
847 //PKCS #7 support
848 #ifndef PKCS7_SUPPORT
849  #define PKCS7_SUPPORT DISABLED
850 #elif (PKCS7_SUPPORT != ENABLED && PKCS7_SUPPORT != DISABLED)
851  #error PKCS7_SUPPORT parameter is not valid
852 #endif
853 
854 //Allocate memory block
855 #ifndef cryptoAllocMem
856  #define cryptoAllocMem(size) osAllocMem(size)
857 #endif
858 
859 //Deallocate memory block
860 #ifndef cryptoFreeMem
861  #define cryptoFreeMem(p) osFreeMem(p)
862 #endif
863 
864 //Rotate left operation
865 #define ROL8(a, n) (((a) << (n)) | ((a) >> (8 - (n))))
866 #define ROL16(a, n) (((a) << (n)) | ((a) >> (16 - (n))))
867 #define ROL32(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
868 #define ROL64(a, n) (((a) << (n)) | ((a) >> (64 - (n))))
869 
870 //Rotate right operation
871 #define ROR8(a, n) (((a) >> (n)) | ((a) << (8 - (n))))
872 #define ROR16(a, n) (((a) >> (n)) | ((a) << (16 - (n))))
873 #define ROR32(a, n) (((a) >> (n)) | ((a) << (32 - (n))))
874 #define ROR64(a, n) (((a) >> (n)) | ((a) << (64 - (n))))
875 
876 //Shift left operation
877 #define SHL8(a, n) ((a) << (n))
878 #define SHL16(a, n) ((a) << (n))
879 #define SHL32(a, n) ((a) << (n))
880 #define SHL64(a, n) ((a) << (n))
881 
882 //Shift right operation
883 #define SHR8(a, n) ((a) >> (n))
884 #define SHR16(a, n) ((a) >> (n))
885 #define SHR32(a, n) ((a) >> (n))
886 #define SHR64(a, n) ((a) >> (n))
887 
888 //Micellaneous macros
889 #define _U8(x) ((uint8_t) (x))
890 #define _U16(x) ((uint16_t) (x))
891 #define _U32(x) ((uint32_t) (x))
892 #define _U64(x) ((uint64_t) (x))
893 
894 //Test if a 8-bit integer is zero
895 #define CRYPTO_TEST_Z_8(a) \
896  _U8((_U8((_U8(a) | (~_U8(a) + 1U))) >> 7U) ^ 1U)
897 
898 //Test if a 8-bit integer is nonzero
899 #define CRYPTO_TEST_NZ_8(a) \
900  _U8(_U8((_U8(a) | (~_U8(a) + 1U))) >> 7U)
901 
902 //Test if two 8-bit integers are equal
903 #define CRYPTO_TEST_EQ_8(a, b) \
904  _U8((_U8(((_U8(a) ^ _U8(b)) | (~(_U8(a) ^ _U8(b)) + 1U))) >> 7U) ^ 1U)
905 
906 //Test if two 8-bit integers are not equal
907 #define CRYPTO_TEST_NEQ_8(a, b) \
908  _U8(_U8(((_U8(a) ^ _U8(b)) | (~(_U8(a) ^ _U8(b)) + 1U))) >> 7U)
909 
910 //Test if a 8-bit integer is lower than another 8-bit integer
911 #define CRYPTO_TEST_LT_8(a, b) \
912  _U8(_U8((((_U8(a) - _U8(b)) ^ _U8(b)) | (_U8(a) ^ _U8(b))) ^ _U8(a)) >> 7U)
913 
914 //Test if a 8-bit integer is lower or equal than another 8-bit integer
915 #define CRYPTO_TEST_LTE_8(a, b) \
916  _U8((_U8((((_U8(b) - _U8(a)) ^ _U8(a)) | (_U8(a) ^ _U8(b))) ^ _U8(b)) >> 7U) ^ 1U)
917 
918 //Test if a 8-bit integer is greater than another 8-bit integer
919 #define CRYPTO_TEST_GT_8(a, b) \
920  _U8(_U8((((_U8(b) - _U8(a)) ^ _U8(a)) | (_U8(a) ^ _U8(b))) ^ _U8(b)) >> 7U)
921 
922 //Test if a 8-bit integer is greater or equal than another 8-bit integer
923 #define CRYPTO_TEST_GTE_8(a, b) \
924  _U8((_U8((((_U8(a) - _U8(b)) ^ _U8(b)) | (_U8(a) ^ _U8(b))) ^ _U8(a)) >> 7U) ^ 1U)
925 
926 //Select between two 8-bit integers
927 #define CRYPTO_SELECT_8(a, b, c) \
928  _U8((_U8(a) & (_U8(c) - 1U)) | (_U8(b) & ~(_U8(c) - 1U)))
929 
930 //Test if a 16-bit integer is zero
931 #define CRYPTO_TEST_Z_16(a) \
932  _U16((_U16((_U16(a) | (~_U16(a) + 1U))) >> 15U) ^ 1U)
933 
934 //Test if a 16-bit integer is nonzero
935 #define CRYPTO_TEST_NZ_16(a) \
936  _U16(_U16((_U16(a) | (~_U16(a) + 1U))) >> 15U)
937 
938 //Test if two 16-bit integers are equal
939 #define CRYPTO_TEST_EQ_16(a, b) \
940  _U16((_U16(((_U16(a) ^ _U16(b)) | (~(_U16(a) ^ _U16(b)) + 1U))) >> 15U) ^ 1U)
941 
942 //Test if two 16-bit integers are not equal
943 #define CRYPTO_TEST_NEQ_16(a, b) \
944  _U16(_U16(((_U16(a) ^ _U16(b)) | (~(_U16(a) ^ _U16(b)) + 1U))) >> 15U)
945 
946 //Test if a 16-bit integer is lower than another 16-bit integer
947 #define CRYPTO_TEST_LT_16(a, b) \
948  _U16(_U16((((_U16(a) - _U16(b)) ^ _U16(b)) | (_U16(a) ^ _U16(b))) ^ _U16(a)) >> 15U)
949 
950 //Test if a 16-bit integer is lower or equal than another 16-bit integer
951 #define CRYPTO_TEST_LTE_16(a, b) \
952  _U16((_U16((((_U16(b) - _U16(a)) ^ _U16(a)) | (_U16(a) ^ _U16(b))) ^ _U16(b)) >> 15U) ^ 1U)
953 
954 //Test if a 16-bit integer is greater than another 16-bit integer
955 #define CRYPTO_TEST_GT_16(a, b) \
956  _U16(_U16((((_U16(b) - _U16(a)) ^ _U16(a)) | (_U16(a) ^ _U16(b))) ^ _U16(b)) >> 15U)
957 
958 //Test if a 16-bit integer is greater or equal than another 16-bit integer
959 #define CRYPTO_TEST_GTE_16(a, b) \
960  _U16((_U16((((_U16(a) - _U16(b)) ^ _U16(b)) | (_U16(a) ^ _U16(b))) ^ _U16(a)) >> 15U) ^ 1U)
961 
962 //Select between two 16-bit integers
963 #define CRYPTO_SELECT_16(a, b, c) \
964  _U16((_U16(a) & (_U16(c) - 1U)) | (_U16(b) & ~(_U16(c) - 1U)))
965 
966 //Test if a 32-bit integer is zero
967 #define CRYPTO_TEST_Z_32(a) \
968  _U32((_U32((_U32(a) | (~_U32(a) + 1U))) >> 31U) ^ 1U)
969 
970 //Test if a 32-bit integer is nonzero
971 #define CRYPTO_TEST_NZ_32(a) \
972  _U32(_U32((_U32(a) | (~_U32(a) + 1U))) >> 31U)
973 
974 //Test if two 32-bit integers are equal
975 #define CRYPTO_TEST_EQ_32(a, b) \
976  _U32((_U32(((_U32(a) ^ _U32(b)) | (~(_U32(a) ^ _U32(b)) + 1U))) >> 31U) ^ 1U)
977 
978 //Test if two 32-bit integers are not equal
979 #define CRYPTO_TEST_NEQ_32(a, b) \
980  _U32(_U32(((_U32(a) ^ _U32(b)) | (~(_U32(a) ^ _U32(b)) + 1U))) >> 31U)
981 
982 //Test if a 32-bit integer is lower than another 32-bit integer
983 #define CRYPTO_TEST_LT_32(a, b) \
984  _U32(_U32((((_U32(a) - _U32(b)) ^ _U32(b)) | (_U32(a) ^ _U32(b))) ^ _U32(a)) >> 31U)
985 
986 //Test if a 32-bit integer is lower or equal than another 32-bit integer
987 #define CRYPTO_TEST_LTE_32(a, b) \
988  _U32((_U32((((_U32(b) - _U32(a)) ^ _U32(a)) | (_U32(a) ^ _U32(b))) ^ _U32(b)) >> 31U) ^ 1U)
989 
990 //Test if a 32-bit integer is greater than another 32-bit integer
991 #define CRYPTO_TEST_GT_32(a, b) \
992  _U32(_U32((((_U32(b) - _U32(a)) ^ _U32(a)) | (_U32(a) ^ _U32(b))) ^ _U32(b)) >> 31U)
993 
994 //Test if a 32-bit integer is greater or equal than another 32-bit integer
995 #define CRYPTO_TEST_GTE_32(a, b) \
996  _U32((_U32((((_U32(a) - _U32(b)) ^ _U32(b)) | (_U32(a) ^ _U32(b))) ^ _U32(a)) >> 31U) ^ 1U)
997 
998 //Select between two 32-bit integers
999 #define CRYPTO_SELECT_32(a, b, c) \
1000  _U32((_U32(a) & (_U32(c) - 1U)) | (_U32(b) & ~(_U32(c) - 1U)))
1001 
1002 //Select between two 64-bit integers
1003 #define CRYPTO_SELECT_64(a, b, c) \
1004  _U64((_U64(a) & (_U64(c) - 1U)) | (_U64(b) & ~(_U64(c) - 1U)))
1005 
1006 //Forward declaration of PrngAlgo structure
1007 struct _PrngAlgo;
1008 #define PrngAlgo struct _PrngAlgo
1009 
1010 //C++ guard
1011 #ifdef __cplusplus
1012 extern "C" {
1013 #endif
1014 
1015 
1016 /**
1017  * @brief Encryption algorithm type
1018  **/
1019 
1020 typedef enum
1021 {
1025 
1026 
1027 /**
1028  * @brief Cipher operation modes
1029  **/
1030 
1031 typedef enum
1032 {
1045 
1046 
1047 /**
1048  * @brief Data chunk descriptor
1049  **/
1050 
1051 typedef struct
1052 {
1053  const void *buffer;
1054  size_t length;
1055 } DataChunk;
1056 
1057 
1058 //Common API for hash algorithms
1059 typedef error_t (*HashAlgoCompute)(const void *data, size_t length,
1060  uint8_t *digest);
1061 
1062 typedef void (*HashAlgoInit)(void *context);
1063 typedef void (*HashAlgoUpdate)(void *context, const void *data, size_t length);
1064 typedef void (*HashAlgoFinal)(void *context, uint8_t *digest);
1065 typedef void (*HashAlgoFinalRaw)(void *context, uint8_t *digest);
1066 
1067 //Common API for XOF algorithms
1068 typedef error_t (*XofAlgoCompute)(const void *input, size_t inputLen,
1069  uint8_t *output, size_t outputLen);
1070 
1071 typedef void (*XofAlgoInit)(void *context);
1072 typedef void (*XofAlgoAbsorb)(void *context, const void *input, size_t length);
1073 typedef void (*XofAlgoFinal)(void *context);
1074 typedef void (*XofAlgoSqueeze)(void *context, uint8_t *output, size_t length);
1075 
1076 //Common API for encryption algorithms
1077 typedef error_t (*CipherAlgoInit)(void *context, const uint8_t *key,
1078  size_t keyLen);
1079 
1080 typedef void (*CipherAlgoEncryptStream)(void *context, const uint8_t *input,
1081  uint8_t *output, size_t length);
1082 
1083 typedef void (*CipherAlgoDecryptStream)(void *context, const uint8_t *input,
1084  uint8_t *output, size_t length);
1085 
1086 typedef void (*CipherAlgoEncryptBlock)(void *context, const uint8_t *input,
1087  uint8_t *output);
1088 
1089 typedef void (*CipherAlgoDecryptBlock)(void *context, const uint8_t *input,
1090  uint8_t *output);
1091 
1092 typedef void (*CipherAlgoDeinit)(void *context);
1093 
1094 //Common interface for key encapsulation mechanisms (KEM)
1095 typedef error_t (*KemAlgoGenerateKeyPair)(const PrngAlgo *prngAlgo,
1096  void *prngContext, uint8_t *pk, uint8_t *sk);
1097 
1098 typedef error_t (*KemAlgoEncapsulate)(const PrngAlgo *prngAlgo,
1099  void *prngContext, uint8_t *ct, uint8_t *ss, const uint8_t *pk);
1100 
1101 typedef error_t (*KemAlgoDecapsulate)(uint8_t *ss, const uint8_t *ct,
1102  const uint8_t *sk);
1103 
1104 //Common API for pseudo-random number generators (PRNG)
1105 typedef error_t (*PrngAlgoInit)(void *context);
1106 
1107 typedef error_t (*PrngAlgoSeed)(void *context, const uint8_t *seed,
1108  size_t length);
1109 
1110 typedef error_t (*PrngAlgoReseed)(void *context, const uint8_t *seed,
1111  size_t length);
1112 
1113 typedef error_t (*PrngAlgoGenerate)(void *context, uint8_t *output,
1114  size_t length);
1115 
1116 typedef void (*PrngAlgoDeinit)(void *context);
1117 
1118 
1119 /**
1120  * @brief Common interface for hash algorithms
1121  **/
1122 
1123 typedef struct
1124 {
1125  const char_t *name;
1126  const uint8_t *oid;
1127  size_t oidSize;
1128  size_t contextSize;
1129  size_t blockSize;
1130  size_t digestSize;
1131  size_t minPadSize;
1138 } HashAlgo;
1139 
1140 
1141 /**
1142  * @brief Common interface for XOF algorithms
1143  **/
1144 
1145 typedef struct
1146 {
1147  const char_t *name;
1148  const uint8_t *oid;
1149  size_t oidSize;
1150  size_t contextSize;
1156 } XofAlgo;
1157 
1158 
1159 /**
1160  * @brief Common interface for encryption algorithms
1161  **/
1162 
1163 typedef struct
1164 {
1165  const char_t *name;
1166  size_t contextSize;
1168  size_t blockSize;
1175 } CipherAlgo;
1176 
1177 
1178 /**
1179  * @brief Common interface for key encapsulation mechanisms (KEM)
1180  **/
1181 
1182 typedef struct
1183 {
1184  const char_t *name;
1192 } KemAlgo;
1193 
1194 
1195 /**
1196  * @brief Common interface for pseudo-random number generators (PRNG)
1197  **/
1198 
1200 {
1201  const char_t *name;
1202  size_t contextSize;
1208 };
1209 
1210 
1211 //C++ guard
1212 #ifdef __cplusplus
1213 }
1214 #endif
1215 
1216 #endif
void(* CipherAlgoDecryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length)
Definition: crypto.h:1083
HashAlgoInit init
Definition: crypto.h:1134
int bool_t
Definition: compiler_port.h:61
void(* HashAlgoInit)(void *context)
Definition: crypto.h:1062
@ CIPHER_MODE_CBC
Definition: crypto.h:1036
const uint8_t * oid
Definition: crypto.h:1126
void(* XofAlgoAbsorb)(void *context, const void *input, size_t length)
Definition: crypto.h:1072
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1086
CipherAlgoDecryptBlock decryptBlock
Definition: crypto.h:1173
#define PrngAlgo
Definition: crypto.h:1008
@ CIPHER_MODE_OFB
Definition: crypto.h:1038
@ CIPHER_MODE_GCM
Definition: crypto.h:1041
Legacy definitions.
size_t contextSize
Definition: crypto.h:1202
@ CIPHER_ALGO_TYPE_BLOCK
Definition: crypto.h:1023
uint8_t data[]
Definition: ethernet.h:224
size_t digestSize
Definition: crypto.h:1130
const char_t * name
Definition: crypto.h:1165
const void * buffer
Definition: crypto.h:1053
HashAlgoUpdate update
Definition: crypto.h:1135
error_t(* PrngAlgoSeed)(void *context, const uint8_t *seed, size_t length)
Definition: crypto.h:1107
CipherAlgoType
Encryption algorithm type.
Definition: crypto.h:1021
size_t blockSize
Definition: crypto.h:1168
size_t blockSize
Definition: crypto.h:1129
size_t publicKeySize
Definition: crypto.h:1185
PrngAlgoGenerate generate
Definition: crypto.h:1206
size_t oidSize
Definition: crypto.h:1149
error_t(* PrngAlgoReseed)(void *context, const uint8_t *seed, size_t length)
Definition: crypto.h:1110
@ CIPHER_MODE_CTR
Definition: crypto.h:1039
XofAlgoInit init
Definition: crypto.h:1152
@ CIPHER_MODE_ECB
Definition: crypto.h:1035
CipherAlgoEncryptBlock encryptBlock
Definition: crypto.h:1172
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
Definition: crypto.h:1063
size_t contextSize
Definition: crypto.h:1128
size_t oidSize
Definition: crypto.h:1127
XofAlgoSqueeze squeeze
Definition: crypto.h:1155
CipherAlgoInit init
Definition: crypto.h:1169
CipherAlgoEncryptStream encryptStream
Definition: crypto.h:1170
PrngAlgoSeed seed
Definition: crypto.h:1204
XofAlgoAbsorb absorb
Definition: crypto.h:1153
XofAlgoCompute compute
Definition: crypto.h:1151
error_t
Error codes.
Definition: error.h:43
@ CIPHER_MODE_CFB
Definition: crypto.h:1037
HashAlgoCompute compute
Definition: crypto.h:1133
PrngAlgoReseed reseed
Definition: crypto.h:1205
size_t sharedSecretSize
Definition: crypto.h:1188
CipherAlgoType type
Definition: crypto.h:1167
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1089
const char_t * name
Definition: crypto.h:1125
void(* CipherAlgoEncryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length)
Definition: crypto.h:1080
CipherAlgoDecryptStream decryptStream
Definition: crypto.h:1171
KemAlgoDecapsulate decapsulate
Definition: crypto.h:1191
Error codes description.
uint8_t length
Definition: tcp.h:375
@ CIPHER_MODE_STREAM
Definition: crypto.h:1034
Byte order conversion.
CipherMode
Cipher operation modes.
Definition: crypto.h:1032
size_t secretKeySize
Definition: crypto.h:1186
const char_t * name
Definition: crypto.h:1147
const char_t * name
Definition: crypto.h:1201
@ CIPHER_MODE_ASCON_AEAD128
Definition: crypto.h:1042
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:1077
error_t(* XofAlgoCompute)(const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
Definition: crypto.h:1068
void(* HashAlgoFinal)(void *context, uint8_t *digest)
Definition: crypto.h:1064
Data chunk descriptor.
Definition: crypto.h:1052
const uint8_t * oid
Definition: crypto.h:1148
Common interface for XOF algorithms.
Definition: crypto.h:1146
void(* PrngAlgoDeinit)(void *context)
Definition: crypto.h:1116
char char_t
Definition: compiler_port.h:55
error_t(* KemAlgoGenerateKeyPair)(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *pk, uint8_t *sk)
Definition: crypto.h:1095
@ CIPHER_MODE_CCM
Definition: crypto.h:1040
size_t contextSize
Definition: crypto.h:1166
PrngAlgoInit init
Definition: crypto.h:1203
Common interface for pseudo-random number generators (PRNG)
Definition: crypto.h:1200
KemAlgoGenerateKeyPair generateKeyPair
Definition: crypto.h:1189
KemAlgoEncapsulate encapsulate
Definition: crypto.h:1190
Common interface for key encapsulation mechanisms (KEM)
Definition: crypto.h:1183
error_t(* PrngAlgoGenerate)(void *context, uint8_t *output, size_t length)
Definition: crypto.h:1113
CipherAlgoDeinit deinit
Definition: crypto.h:1174
size_t ciphertextSize
Definition: crypto.h:1187
size_t minPadSize
Definition: crypto.h:1131
Common interface for encryption algorithms.
Definition: crypto.h:1164
void(* XofAlgoInit)(void *context)
Definition: crypto.h:1071
error_t(* KemAlgoDecapsulate)(uint8_t *ss, const uint8_t *ct, const uint8_t *sk)
Definition: crypto.h:1101
size_t contextSize
Definition: crypto.h:1150
error_t(* KemAlgoEncapsulate)(const PrngAlgo *prngAlgo, void *prngContext, uint8_t *ct, uint8_t *ss, const uint8_t *pk)
Definition: crypto.h:1098
size_t length
Definition: crypto.h:1054
@ CIPHER_ALGO_TYPE_STREAM
Definition: crypto.h:1022
Common interface for hash algorithms.
Definition: crypto.h:1124
PrngAlgoDeinit deinit
Definition: crypto.h:1207
@ CIPHER_MODE_NULL
Definition: crypto.h:1033
@ CIPHER_MODE_CHACHA20_POLY1305
Definition: crypto.h:1043
void(* XofAlgoSqueeze)(void *context, uint8_t *output, size_t length)
Definition: crypto.h:1074
bool_t bigEndian
Definition: crypto.h:1132
void(* CipherAlgoDeinit)(void *context)
Definition: crypto.h:1092
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
Definition: crypto.h:1059
error_t(* PrngAlgoInit)(void *context)
Definition: crypto.h:1105
void(* HashAlgoFinalRaw)(void *context, uint8_t *digest)
Definition: crypto.h:1065
RTOS abstraction layer.
HashAlgoFinalRaw finalRaw
Definition: crypto.h:1137
void(* XofAlgoFinal)(void *context)
Definition: crypto.h:1073
const char_t * name
Definition: crypto.h:1184