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-2020 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 1.9.8
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 "1.9.8"
70 //Major version
71 #define CYCLONE_CRYPTO_MAJOR_VERSION 1
72 //Minor version
73 #define CYCLONE_CRYPTO_MINOR_VERSION 9
74 //Revision number
75 #define CYCLONE_CRYPTO_REV_NUMBER 8
76 
77 //Multiple precision integer support
78 #ifndef MPI_SUPPORT
79  #define MPI_SUPPORT ENABLED
80 #elif (MPI_SUPPORT != ENABLED && MPI_SUPPORT != DISABLED)
81  #error MPI_SUPPORT parameter is not valid
82 #endif
83 
84 //Assembly optimizations for time-critical routines
85 #ifndef MPI_ASM_SUPPORT
86  #define MPI_ASM_SUPPORT DISABLED
87 #elif (MPI_ASM_SUPPORT != ENABLED && MPI_ASM_SUPPORT != DISABLED)
88  #error MPI_ASM_SUPPORT parameter is not valid
89 #endif
90 
91 //Base64 encoding support
92 #ifndef BASE64_SUPPORT
93  #define BASE64_SUPPORT ENABLED
94 #elif (BASE64_SUPPORT != ENABLED && BASE64_SUPPORT != DISABLED)
95  #error BASE64_SUPPORT parameter is not valid
96 #endif
97 
98 //Base64url encoding support
99 #ifndef BASE64URL_SUPPORT
100  #define BASE64URL_SUPPORT ENABLED
101 #elif (BASE64URL_SUPPORT != ENABLED && BASE64URL_SUPPORT != DISABLED)
102  #error BASE64URL_SUPPORT parameter is not valid
103 #endif
104 
105 //Radix64 encoding support
106 #ifndef RADIX64_SUPPORT
107  #define RADIX64_SUPPORT ENABLED
108 #elif (RADIX64_SUPPORT != ENABLED && RADIX64_SUPPORT != DISABLED)
109  #error RADIX64_SUPPORT parameter is not valid
110 #endif
111 
112 //MD2 hash support
113 #ifndef MD2_SUPPORT
114  #define MD2_SUPPORT DISABLED
115 #elif (MD2_SUPPORT != ENABLED && MD2_SUPPORT != DISABLED)
116  #error MD2_SUPPORT parameter is not valid
117 #endif
118 
119 //MD4 hash support
120 #ifndef MD4_SUPPORT
121  #define MD4_SUPPORT DISABLED
122 #elif (MD4_SUPPORT != ENABLED && MD4_SUPPORT != DISABLED)
123  #error MD4_SUPPORT parameter is not valid
124 #endif
125 
126 //MD5 hash support
127 #ifndef MD5_SUPPORT
128  #define MD5_SUPPORT ENABLED
129 #elif (MD5_SUPPORT != ENABLED && MD5_SUPPORT != DISABLED)
130  #error MD5_SUPPORT parameter is not valid
131 #endif
132 
133 //RIPEMD-128 hash support
134 #ifndef RIPEMD128_SUPPORT
135  #define RIPEMD128_SUPPORT DISABLED
136 #elif (RIPEMD128_SUPPORT != ENABLED && RIPEMD128_SUPPORT != DISABLED)
137  #error RIPEMD128_SUPPORT parameter is not valid
138 #endif
139 
140 //RIPEMD-160 hash support
141 #ifndef RIPEMD160_SUPPORT
142  #define RIPEMD160_SUPPORT DISABLED
143 #elif (RIPEMD160_SUPPORT != ENABLED && RIPEMD160_SUPPORT != DISABLED)
144  #error RIPEMD160_SUPPORT parameter is not valid
145 #endif
146 
147 //SHA-1 hash support
148 #ifndef SHA1_SUPPORT
149  #define SHA1_SUPPORT ENABLED
150 #elif (SHA1_SUPPORT != ENABLED && SHA1_SUPPORT != DISABLED)
151  #error SHA1_SUPPORT parameter is not valid
152 #endif
153 
154 //SHA-224 hash support
155 #ifndef SHA224_SUPPORT
156  #define SHA224_SUPPORT ENABLED
157 #elif (SHA224_SUPPORT != ENABLED && SHA224_SUPPORT != DISABLED)
158  #error SHA224_SUPPORT parameter is not valid
159 #endif
160 
161 //SHA-256 hash support
162 #ifndef SHA256_SUPPORT
163  #define SHA256_SUPPORT ENABLED
164 #elif (SHA256_SUPPORT != ENABLED && SHA256_SUPPORT != DISABLED)
165  #error SHA256_SUPPORT parameter is not valid
166 #endif
167 
168 //SHA-384 hash support
169 #ifndef SHA384_SUPPORT
170  #define SHA384_SUPPORT ENABLED
171 #elif (SHA384_SUPPORT != ENABLED && SHA384_SUPPORT != DISABLED)
172  #error SHA384_SUPPORT parameter is not valid
173 #endif
174 
175 //SHA-512 hash support
176 #ifndef SHA512_SUPPORT
177  #define SHA512_SUPPORT ENABLED
178 #elif (SHA512_SUPPORT != ENABLED && SHA512_SUPPORT != DISABLED)
179  #error SHA512_SUPPORT parameter is not valid
180 #endif
181 
182 //SHA-512/224 hash support
183 #ifndef SHA512_224_SUPPORT
184  #define SHA512_224_SUPPORT DISABLED
185 #elif (SHA512_224_SUPPORT != ENABLED && SHA512_224_SUPPORT != DISABLED)
186  #error SHA512_224_SUPPORT parameter is not valid
187 #endif
188 
189 //SHA-512/256 hash support
190 #ifndef SHA512_256_SUPPORT
191  #define SHA512_256_SUPPORT DISABLED
192 #elif (SHA512_256_SUPPORT != ENABLED && SHA512_256_SUPPORT != DISABLED)
193  #error SHA512_256_SUPPORT parameter is not valid
194 #endif
195 
196 //SHA3-224 hash support
197 #ifndef SHA3_224_SUPPORT
198  #define SHA3_224_SUPPORT DISABLED
199 #elif (SHA3_224_SUPPORT != ENABLED && SHA3_224_SUPPORT != DISABLED)
200  #error SHA3_224_SUPPORT parameter is not valid
201 #endif
202 
203 //SHA3-256 hash support
204 #ifndef SHA3_256_SUPPORT
205  #define SHA3_256_SUPPORT DISABLED
206 #elif (SHA3_256_SUPPORT != ENABLED && SHA3_256_SUPPORT != DISABLED)
207  #error SHA3_256_SUPPORT parameter is not valid
208 #endif
209 
210 //SHA3-384 hash support
211 #ifndef SHA3_384_SUPPORT
212  #define SHA3_384_SUPPORT DISABLED
213 #elif (SHA3_384_SUPPORT != ENABLED && SHA3_384_SUPPORT != DISABLED)
214  #error SHA3_384_SUPPORT parameter is not valid
215 #endif
216 
217 //SHA3-512 hash support
218 #ifndef SHA3_512_SUPPORT
219  #define SHA3_512_SUPPORT DISABLED
220 #elif (SHA3_512_SUPPORT != ENABLED && SHA3_512_SUPPORT != DISABLED)
221  #error SHA3_512_SUPPORT parameter is not valid
222 #endif
223 
224 //SHAKE128 support
225 #ifndef SHAKE128_SUPPORT
226  #define SHAKE128_SUPPORT DISABLED
227 #elif (SHAKE128_SUPPORT != ENABLED && SHAKE128_SUPPORT != DISABLED)
228  #error SHAKE128_SUPPORT parameter is not valid
229 #endif
230 
231 //SHAKE256 support
232 #ifndef SHAKE256_SUPPORT
233  #define SHAKE256_SUPPORT DISABLED
234 #elif (SHAKE256_SUPPORT != ENABLED && SHAKE256_SUPPORT != DISABLED)
235  #error SHAKE256_SUPPORT parameter is not valid
236 #endif
237 
238 //Keccak support
239 #ifndef KECCAK_SUPPORT
240  #define KECCAK_SUPPORT DISABLED
241 #elif (KECCAK_SUPPORT != ENABLED && KECCAK_SUPPORT != DISABLED)
242  #error KECCAK_SUPPORT parameter is not valid
243 #endif
244 
245 //BLAKE2b support
246 #ifndef BLAKE2B_SUPPORT
247  #define BLAKE2B_SUPPORT DISABLED
248 #elif (BLAKE2B_SUPPORT != ENABLED && BLAKE2B_SUPPORT != DISABLED)
249  #error BLAKE2B_SUPPORT parameter is not valid
250 #endif
251 
252 //BLAKE2b-160 hash support
253 #ifndef BLAKE2B160_SUPPORT
254  #define BLAKE2B160_SUPPORT DISABLED
255 #elif (BLAKE2B160_SUPPORT != ENABLED && BLAKE2B160_SUPPORT != DISABLED)
256  #error BLAKE2B160_SUPPORT parameter is not valid
257 #endif
258 
259 //BLAKE2b-256 hash support
260 #ifndef BLAKE2B256_SUPPORT
261  #define BLAKE2B256_SUPPORT DISABLED
262 #elif (BLAKE2B256_SUPPORT != ENABLED && BLAKE2B256_SUPPORT != DISABLED)
263  #error BLAKE2B256_SUPPORT parameter is not valid
264 #endif
265 
266 //BLAKE2b-384 hash support
267 #ifndef BLAKE2B384_SUPPORT
268  #define BLAKE2B384_SUPPORT DISABLED
269 #elif (BLAKE2B384_SUPPORT != ENABLED && BLAKE2B384_SUPPORT != DISABLED)
270  #error BLAKE2B384_SUPPORT parameter is not valid
271 #endif
272 
273 //BLAKE2b-512 hash support
274 #ifndef BLAKE2B512_SUPPORT
275  #define BLAKE2B512_SUPPORT DISABLED
276 #elif (BLAKE2B512_SUPPORT != ENABLED && BLAKE2B512_SUPPORT != DISABLED)
277  #error BLAKE2B512_SUPPORT parameter is not valid
278 #endif
279 
280 //BLAKE2s support
281 #ifndef BLAKE2S_SUPPORT
282  #define BLAKE2S_SUPPORT DISABLED
283 #elif (BLAKE2S_SUPPORT != ENABLED && BLAKE2S_SUPPORT != DISABLED)
284  #error BLAKE2S_SUPPORT parameter is not valid
285 #endif
286 
287 //BLAKE2s-128 hash support
288 #ifndef BLAKE2S128_SUPPORT
289  #define BLAKE2S128_SUPPORT DISABLED
290 #elif (BLAKE2S128_SUPPORT != ENABLED && BLAKE2S128_SUPPORT != DISABLED)
291  #error BLAKE2S128_SUPPORT parameter is not valid
292 #endif
293 
294 //BLAKE2s-160 hash support
295 #ifndef BLAKE2S160_SUPPORT
296  #define BLAKE2S160_SUPPORT DISABLED
297 #elif (BLAKE2S160_SUPPORT != ENABLED && BLAKE2S160_SUPPORT != DISABLED)
298  #error BLAKE2S160_SUPPORT parameter is not valid
299 #endif
300 
301 //BLAKE2s-224 hash support
302 #ifndef BLAKE2S224_SUPPORT
303  #define BLAKE2S224_SUPPORT DISABLED
304 #elif (BLAKE2S224_SUPPORT != ENABLED && BLAKE2S224_SUPPORT != DISABLED)
305  #error BLAKE2S224_SUPPORT parameter is not valid
306 #endif
307 
308 //BLAKE2s-256 hash support
309 #ifndef BLAKE2S256_SUPPORT
310  #define BLAKE2S256_SUPPORT DISABLED
311 #elif (BLAKE2S256_SUPPORT != ENABLED && BLAKE2S256_SUPPORT != DISABLED)
312  #error BLAKE2S256_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 //CMAC support
330 #ifndef CMAC_SUPPORT
331  #define CMAC_SUPPORT DISABLED
332 #elif (CMAC_SUPPORT != ENABLED && CMAC_SUPPORT != DISABLED)
333  #error CMAC_SUPPORT parameter is not valid
334 #endif
335 
336 //HMAC support
337 #ifndef HMAC_SUPPORT
338  #define HMAC_SUPPORT ENABLED
339 #elif (HMAC_SUPPORT != ENABLED && HMAC_SUPPORT != DISABLED)
340  #error HMAC_SUPPORT parameter is not valid
341 #endif
342 
343 //GMAC support
344 #ifndef GMAC_SUPPORT
345  #define GMAC_SUPPORT DISABLED
346 #elif (GMAC_SUPPORT != ENABLED && GMAC_SUPPORT != DISABLED)
347  #error GMAC_SUPPORT parameter is not valid
348 #endif
349 
350 //RC2 encryption support
351 #ifndef RC2_SUPPORT
352  #define RC2_SUPPORT DISABLED
353 #elif (RC2_SUPPORT != ENABLED && RC2_SUPPORT != DISABLED)
354  #error RC2_SUPPORT parameter is not valid
355 #endif
356 
357 //RC4 encryption support
358 #ifndef RC4_SUPPORT
359  #define RC4_SUPPORT DISABLED
360 #elif (RC4_SUPPORT != ENABLED && RC4_SUPPORT != DISABLED)
361  #error RC4_SUPPORT parameter is not valid
362 #endif
363 
364 //RC6 encryption support
365 #ifndef RC6_SUPPORT
366  #define RC6_SUPPORT DISABLED
367 #elif (RC6_SUPPORT != ENABLED && RC6_SUPPORT != DISABLED)
368  #error RC6_SUPPORT parameter is not valid
369 #endif
370 
371 //IDEA encryption support
372 #ifndef IDEA_SUPPORT
373  #define IDEA_SUPPORT DISABLED
374 #elif (IDEA_SUPPORT != ENABLED && IDEA_SUPPORT != DISABLED)
375  #error IDEA_SUPPORT parameter is not valid
376 #endif
377 
378 //DES encryption support
379 #ifndef DES_SUPPORT
380  #define DES_SUPPORT ENABLED
381 #elif (DES_SUPPORT != ENABLED && DES_SUPPORT != DISABLED)
382  #error DES_SUPPORT parameter is not valid
383 #endif
384 
385 //Triple DES encryption support
386 #ifndef DES3_SUPPORT
387  #define DES3_SUPPORT ENABLED
388 #elif (DES3_SUPPORT != ENABLED && DES3_SUPPORT != DISABLED)
389  #error DES3_SUPPORT parameter is not valid
390 #endif
391 
392 //AES encryption support
393 #ifndef AES_SUPPORT
394  #define AES_SUPPORT ENABLED
395 #elif (AES_SUPPORT != ENABLED && AES_SUPPORT != DISABLED)
396  #error AES_SUPPORT parameter is not valid
397 #endif
398 
399 //Blowfish encryption support
400 #ifndef BLOWFISH_SUPPORT
401  #define BLOWFISH_SUPPORT DISABLED
402 #elif (BLOWFISH_SUPPORT != ENABLED && BLOWFISH_SUPPORT != DISABLED)
403  #error BLOWFISH_SUPPORT parameter is not valid
404 #endif
405 
406 //Camellia encryption support
407 #ifndef CAMELLIA_SUPPORT
408  #define CAMELLIA_SUPPORT ENABLED
409 #elif (CAMELLIA_SUPPORT != ENABLED && CAMELLIA_SUPPORT != DISABLED)
410  #error CAMELLIA_SUPPORT parameter is not valid
411 #endif
412 
413 //SEED encryption support
414 #ifndef SEED_SUPPORT
415  #define SEED_SUPPORT ENABLED
416 #elif (SEED_SUPPORT != ENABLED && SEED_SUPPORT != DISABLED)
417  #error SEED_SUPPORT parameter is not valid
418 #endif
419 
420 //ARIA encryption support
421 #ifndef ARIA_SUPPORT
422  #define ARIA_SUPPORT ENABLED
423 #elif (ARIA_SUPPORT != ENABLED && ARIA_SUPPORT != DISABLED)
424  #error ARIA_SUPPORT parameter is not valid
425 #endif
426 
427 //PRESENT encryption support
428 #ifndef PRESENT_SUPPORT
429  #define PRESENT_SUPPORT DISABLED
430 #elif (PRESENT_SUPPORT != ENABLED && PRESENT_SUPPORT != DISABLED)
431  #error PRESENT_SUPPORT parameter is not valid
432 #endif
433 
434 //ECB mode support
435 #ifndef ECB_SUPPORT
436  #define ECB_SUPPORT ENABLED
437 #elif (ECB_SUPPORT != ENABLED && ECB_SUPPORT != DISABLED)
438  #error ECB_SUPPORT parameter is not valid
439 #endif
440 
441 //CBC mode support
442 #ifndef CBC_SUPPORT
443  #define CBC_SUPPORT ENABLED
444 #elif (CBC_SUPPORT != ENABLED && CBC_SUPPORT != DISABLED)
445  #error CBC_SUPPORT parameter is not valid
446 #endif
447 
448 //CFB mode support
449 #ifndef CFB_SUPPORT
450  #define CFB_SUPPORT ENABLED
451 #elif (CFB_SUPPORT != ENABLED && CFB_SUPPORT != DISABLED)
452  #error CFB_SUPPORT parameter is not valid
453 #endif
454 
455 //OFB mode support
456 #ifndef OFB_SUPPORT
457  #define OFB_SUPPORT ENABLED
458 #elif (OFB_SUPPORT != ENABLED && OFB_SUPPORT != DISABLED)
459  #error OFB_SUPPORT parameter is not valid
460 #endif
461 
462 //CTR mode support
463 #ifndef CTR_SUPPORT
464  #define CTR_SUPPORT ENABLED
465 #elif (CTR_SUPPORT != ENABLED && CTR_SUPPORT != DISABLED)
466  #error CTR_SUPPORT parameter is not valid
467 #endif
468 
469 //XTS mode support
470 #ifndef XTS_SUPPORT
471  #define XTS_SUPPORT ENABLED
472 #elif (XTS_SUPPORT != ENABLED && XTS_SUPPORT != DISABLED)
473  #error XTS_SUPPORT parameter is not valid
474 #endif
475 
476 //CCM mode support
477 #ifndef CCM_SUPPORT
478  #define CCM_SUPPORT ENABLED
479 #elif (CCM_SUPPORT != ENABLED && CCM_SUPPORT != DISABLED)
480  #error CCM_SUPPORT parameter is not valid
481 #endif
482 
483 //GCM mode support
484 #ifndef GCM_SUPPORT
485  #define GCM_SUPPORT ENABLED
486 #elif (GCM_SUPPORT != ENABLED && GCM_SUPPORT != DISABLED)
487  #error GCM_SUPPORT parameter is not valid
488 #endif
489 
490 //Salsa20 support
491 #ifndef SALSA20_SUPPORT
492  #define SALSA20_SUPPORT DISABLED
493 #elif (SALSA20_SUPPORT != ENABLED && SALSA20_SUPPORT != DISABLED)
494  #error SALSA20_SUPPORT parameter is not valid
495 #endif
496 
497 //Chacha support
498 #ifndef CHACHA_SUPPORT
499  #define CHACHA_SUPPORT DISABLED
500 #elif (CHACHA_SUPPORT != ENABLED && CHACHA_SUPPORT != DISABLED)
501  #error CHACHA_SUPPORT parameter is not valid
502 #endif
503 
504 //Poly1305 support
505 #ifndef POLY1305_SUPPORT
506  #define POLY1305_SUPPORT DISABLED
507 #elif (POLY1305_SUPPORT != ENABLED && POLY1305_SUPPORT != DISABLED)
508  #error POLY1305_SUPPORT parameter is not valid
509 #endif
510 
511 //Chacha20Poly1305 support
512 #ifndef CHACHA20_POLY1305_SUPPORT
513  #define CHACHA20_POLY1305_SUPPORT DISABLED
514 #elif (CHACHA20_POLY1305_SUPPORT != ENABLED && CHACHA20_POLY1305_SUPPORT != DISABLED)
515  #error CHACHA20_POLY1305_SUPPORT parameter is not valid
516 #endif
517 
518 //Diffie-Hellman support
519 #ifndef DH_SUPPORT
520  #define DH_SUPPORT ENABLED
521 #elif (DH_SUPPORT != ENABLED && DH_SUPPORT != DISABLED)
522  #error DH_SUPPORT parameter is not valid
523 #endif
524 
525 //RSA support
526 #ifndef RSA_SUPPORT
527  #define RSA_SUPPORT ENABLED
528 #elif (RSA_SUPPORT != ENABLED && RSA_SUPPORT != DISABLED)
529  #error RSA_SUPPORT parameter is not valid
530 #endif
531 
532 //DSA support
533 #ifndef DSA_SUPPORT
534  #define DSA_SUPPORT ENABLED
535 #elif (DSA_SUPPORT != ENABLED && DSA_SUPPORT != DISABLED)
536  #error DSA_SUPPORT parameter is not valid
537 #endif
538 
539 //Elliptic curve cryptography support
540 #ifndef EC_SUPPORT
541  #define EC_SUPPORT ENABLED
542 #elif (EC_SUPPORT != ENABLED && EC_SUPPORT != DISABLED)
543  #error EC_SUPPORT parameter is not valid
544 #endif
545 
546 //ECDH support
547 #ifndef ECDH_SUPPORT
548  #define ECDH_SUPPORT ENABLED
549 #elif (ECDH_SUPPORT != ENABLED && ECDH_SUPPORT != DISABLED)
550  #error ECDH_SUPPORT parameter is not valid
551 #endif
552 
553 //ECDSA support
554 #ifndef ECDSA_SUPPORT
555  #define ECDSA_SUPPORT ENABLED
556 #elif (ECDSA_SUPPORT != ENABLED && ECDSA_SUPPORT != DISABLED)
557  #error ECDSA_SUPPORT parameter is not valid
558 #endif
559 
560 //HKDF support
561 #ifndef HKDF_SUPPORT
562  #define HKDF_SUPPORT DISABLED
563 #elif (HKDF_SUPPORT != ENABLED && HKDF_SUPPORT != DISABLED)
564  #error HKDF_SUPPORT parameter is not valid
565 #endif
566 
567 //PKCS #5 support
568 #ifndef PKCS5_SUPPORT
569  #define PKCS5_SUPPORT ENABLED
570 #elif (PKCS5_SUPPORT != ENABLED && PKCS5_SUPPORT != DISABLED)
571  #error PKCS5_SUPPORT parameter is not valid
572 #endif
573 
574 //bcrypt support
575 #ifndef BCRYPT_SUPPORT
576  #define BCRYPT_SUPPORT ENABLED
577 #elif (BCRYPT_SUPPORT != ENABLED && BCRYPT_SUPPORT != DISABLED)
578  #error BCRYPT_SUPPORT parameter is not valid
579 #endif
580 
581 //scrypt support
582 #ifndef SCRYPT_SUPPORT
583  #define SCRYPT_SUPPORT ENABLED
584 #elif (SCRYPT_SUPPORT != ENABLED && SCRYPT_SUPPORT != DISABLED)
585  #error SCRYPT_SUPPORT parameter is not valid
586 #endif
587 
588 //Yarrow PRNG support
589 #ifndef YARROW_SUPPORT
590  #define YARROW_SUPPORT ENABLED
591 #elif (YARROW_SUPPORT != ENABLED && YARROW_SUPPORT != DISABLED)
592  #error YARROW_SUPPORT parameter is not valid
593 #endif
594 
595 //Object identifier support
596 #ifndef OID_SUPPORT
597  #define OID_SUPPORT ENABLED
598 #elif (OID_SUPPORT != ENABLED && OID_SUPPORT != DISABLED)
599  #error OID_SUPPORT parameter is not valid
600 #endif
601 
602 //ASN.1 syntax support
603 #ifndef ASN1_SUPPORT
604  #define ASN1_SUPPORT ENABLED
605 #elif (ASN1_SUPPORT != ENABLED && ASN1_SUPPORT != DISABLED)
606  #error ASN1_SUPPORT parameter is not valid
607 #endif
608 
609 //PEM file support
610 #ifndef PEM_SUPPORT
611  #define PEM_SUPPORT ENABLED
612 #elif (PEM_SUPPORT != ENABLED && PEM_SUPPORT != DISABLED)
613  #error PEM_SUPPORT parameter is not valid
614 #endif
615 
616 //X.509 certificate support
617 #ifndef X509_SUPPORT
618  #define X509_SUPPORT ENABLED
619 #elif (X509_SUPPORT != ENABLED && X509_SUPPORT != DISABLED)
620  #error X509_SUPPORT parameter is not valid
621 #endif
622 
623 //Allocate memory block
624 #ifndef cryptoAllocMem
625  #define cryptoAllocMem(size) osAllocMem(size)
626 #endif
627 
628 //Deallocate memory block
629 #ifndef cryptoFreeMem
630  #define cryptoFreeMem(p) osFreeMem(p)
631 #endif
632 
633 //Maximum context size (hash algorithms)
634 #if (SHA3_512_SUPPORT == ENABLED)
635  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_512Context)
636 #elif (SHA3_384_SUPPORT == ENABLED)
637  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_384Context)
638 #elif (SHA3_256_SUPPORT == ENABLED)
639  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_256Context)
640 #elif (SHA3_224_SUPPORT == ENABLED)
641  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_224Context)
642 #elif (WHIRLPOOL_SUPPORT == ENABLED)
643  #define MAX_HASH_CONTEXT_SIZE sizeof(WhirlpoolContext)
644 #elif (BLAKE2B512_SUPPORT == ENABLED)
645  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b512Context)
646 #elif (BLAKE2B384_SUPPORT == ENABLED)
647  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b384Context)
648 #elif (BLAKE2B256_SUPPORT == ENABLED)
649  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b256Context)
650 #elif (BLAKE2B160_SUPPORT == ENABLED)
651  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b160Context)
652 #elif (SHA512_SUPPORT == ENABLED)
653  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512Context)
654 #elif (SHA384_SUPPORT == ENABLED)
655  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha384Context)
656 #elif (SHA512_256_SUPPORT == ENABLED)
657  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512_256Context)
658 #elif (SHA512_224_SUPPORT == ENABLED)
659  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512_224Context)
660 #elif (BLAKE2S256_SUPPORT == ENABLED)
661  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s256Context)
662 #elif (BLAKE2S224_SUPPORT == ENABLED)
663  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s224Context)
664 #elif (BLAKE2S160_SUPPORT == ENABLED)
665  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s160Context)
666 #elif (BLAKE2S128_SUPPORT == ENABLED)
667  #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s128Context)
668 #elif (SHA256_SUPPORT == ENABLED)
669  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha256Context)
670 #elif (SHA224_SUPPORT == ENABLED)
671  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha224Context)
672 #elif (TIGER_SUPPORT == ENABLED)
673  #define MAX_HASH_CONTEXT_SIZE sizeof(TigerContext)
674 #elif (SHA1_SUPPORT == ENABLED)
675  #define MAX_HASH_CONTEXT_SIZE sizeof(Sha1Context)
676 #elif (RIPEMD160_SUPPORT == ENABLED)
677  #define MAX_HASH_CONTEXT_SIZE sizeof(Ripemd160Context)
678 #elif (RIPEMD128_SUPPORT == ENABLED)
679  #define MAX_HASH_CONTEXT_SIZE sizeof(Ripemd128Context)
680 #elif (MD5_SUPPORT == ENABLED)
681  #define MAX_HASH_CONTEXT_SIZE sizeof(Md5Context)
682 #elif (MD4_SUPPORT == ENABLED)
683  #define MAX_HASH_CONTEXT_SIZE sizeof(Md4Context)
684 #elif (MD2_SUPPORT == ENABLED)
685  #define MAX_HASH_CONTEXT_SIZE sizeof(Md2Context)
686 #endif
687 
688 //Maximum block size (hash algorithms)
689 #if (SHA3_224_SUPPORT == ENABLED)
690  #define MAX_HASH_BLOCK_SIZE SHA3_224_BLOCK_SIZE
691 #elif (SHA3_256_SUPPORT == ENABLED)
692  #define MAX_HASH_BLOCK_SIZE SHA3_256_BLOCK_SIZE
693 #elif (BLAKE2B512_SUPPORT == ENABLED)
694  #define MAX_HASH_BLOCK_SIZE BLAKE2B512_BLOCK_SIZE
695 #elif (BLAKE2B384_SUPPORT == ENABLED)
696  #define MAX_HASH_BLOCK_SIZE BLAKE2B384_BLOCK_SIZE
697 #elif (BLAKE2B256_SUPPORT == ENABLED)
698  #define MAX_HASH_BLOCK_SIZE BLAKE2B256_BLOCK_SIZE
699 #elif (BLAKE2B160_SUPPORT == ENABLED)
700  #define MAX_HASH_BLOCK_SIZE BLAKE2B160_BLOCK_SIZE
701 #elif (SHA512_SUPPORT == ENABLED)
702  #define MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
703 #elif (SHA384_SUPPORT == ENABLED)
704  #define MAX_HASH_BLOCK_SIZE SHA384_BLOCK_SIZE
705 #elif (SHA512_256_SUPPORT == ENABLED)
706  #define MAX_HASH_BLOCK_SIZE SHA512_256_BLOCK_SIZE
707 #elif (SHA512_224_SUPPORT == ENABLED)
708  #define MAX_HASH_BLOCK_SIZE SHA512_224_BLOCK_SIZE
709 #elif (SHA3_384_SUPPORT == ENABLED)
710  #define MAX_HASH_BLOCK_SIZE SHA3_384_BLOCK_SIZE
711 #elif (SHA3_512_SUPPORT == ENABLED)
712  #define MAX_HASH_BLOCK_SIZE SHA3_512_BLOCK_SIZE
713 #elif (BLAKE2S256_SUPPORT == ENABLED)
714  #define MAX_HASH_BLOCK_SIZE BLAKE2S256_BLOCK_SIZE
715 #elif (BLAKE2S224_SUPPORT == ENABLED)
716  #define MAX_HASH_BLOCK_SIZE BLAKE2S224_BLOCK_SIZE
717 #elif (BLAKE2S160_SUPPORT == ENABLED)
718  #define MAX_HASH_BLOCK_SIZE BLAKE2S160_BLOCK_SIZE
719 #elif (BLAKE2S128_SUPPORT == ENABLED)
720  #define MAX_HASH_BLOCK_SIZE BLAKE2S128_BLOCK_SIZE
721 #elif (SHA256_SUPPORT == ENABLED)
722  #define MAX_HASH_BLOCK_SIZE SHA256_BLOCK_SIZE
723 #elif (SHA224_SUPPORT == ENABLED)
724  #define MAX_HASH_BLOCK_SIZE SHA224_BLOCK_SIZE
725 #elif (SHA1_SUPPORT == ENABLED)
726  #define MAX_HASH_BLOCK_SIZE SHA1_BLOCK_SIZE
727 #elif (WHIRLPOOL_SUPPORT == ENABLED)
728  #define MAX_HASH_BLOCK_SIZE WHIRLPOOL_BLOCK_SIZE
729 #elif (TIGER_SUPPORT == ENABLED)
730  #define MAX_HASH_BLOCK_SIZE TIGER_BLOCK_SIZE
731 #elif (RIPEMD160_SUPPORT == ENABLED)
732  #define MAX_HASH_BLOCK_SIZE RIPEMD160_BLOCK_SIZE
733 #elif (RIPEMD128_SUPPORT == ENABLED)
734  #define MAX_HASH_BLOCK_SIZE RIPEMD128_BLOCK_SIZE
735 #elif (MD5_SUPPORT == ENABLED)
736  #define MAX_HASH_BLOCK_SIZE MD5_BLOCK_SIZE
737 #elif (MD4_SUPPORT == ENABLED)
738  #define MAX_HASH_BLOCK_SIZE MD4_BLOCK_SIZE
739 #elif (MD2_SUPPORT == ENABLED)
740  #define MAX_HASH_BLOCK_SIZE MD2_BLOCK_SIZE
741 #endif
742 
743 //Maximum digest size (hash algorithms)
744 #if (WHIRLPOOL_SUPPORT == ENABLED)
745  #define MAX_HASH_DIGEST_SIZE WHIRLPOOL_DIGEST_SIZE
746 #elif (BLAKE2B512_SUPPORT == ENABLED)
747  #define MAX_HASH_DIGEST_SIZE BLAKE2B512_DIGEST_SIZE
748 #elif (SHA3_512_SUPPORT == ENABLED)
749  #define MAX_HASH_DIGEST_SIZE SHA3_512_DIGEST_SIZE
750 #elif (SHA512_SUPPORT == ENABLED)
751  #define MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
752 #elif (BLAKE2B384_SUPPORT == ENABLED)
753  #define MAX_HASH_DIGEST_SIZE BLAKE2B384_DIGEST_SIZE
754 #elif (SHA3_384_SUPPORT == ENABLED)
755  #define MAX_HASH_DIGEST_SIZE SHA3_384_DIGEST_SIZE
756 #elif (SHA384_SUPPORT == ENABLED)
757  #define MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
758 #elif (BLAKE2B256_SUPPORT == ENABLED)
759  #define MAX_HASH_DIGEST_SIZE BLAKE2B256_DIGEST_SIZE
760 #elif (BLAKE2S256_SUPPORT == ENABLED)
761  #define MAX_HASH_DIGEST_SIZE BLAKE2S256_DIGEST_SIZE
762 #elif (SHA3_256_SUPPORT == ENABLED)
763  #define MAX_HASH_DIGEST_SIZE SHA3_256_DIGEST_SIZE
764 #elif (SHA512_256_SUPPORT == ENABLED)
765  #define MAX_HASH_DIGEST_SIZE SHA512_256_DIGEST_SIZE
766 #elif (SHA256_SUPPORT == ENABLED)
767  #define MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
768 #elif (BLAKE2S224_SUPPORT == ENABLED)
769  #define MAX_HASH_DIGEST_SIZE BLAKE2S224_DIGEST_SIZE
770 #elif (SHA3_224_SUPPORT == ENABLED)
771  #define MAX_HASH_DIGEST_SIZE SHA3_224_DIGEST_SIZE
772 #elif (SHA512_224_SUPPORT == ENABLED)
773  #define MAX_HASH_DIGEST_SIZE SHA512_224_DIGEST_SIZE
774 #elif (SHA224_SUPPORT == ENABLED)
775  #define MAX_HASH_DIGEST_SIZE SHA224_DIGEST_SIZE
776 #elif (TIGER_SUPPORT == ENABLED)
777  #define MAX_HASH_DIGEST_SIZE TIGER_DIGEST_SIZE
778 #elif (BLAKE2B160_SUPPORT == ENABLED)
779  #define MAX_HASH_DIGEST_SIZE BLAKE2B160_DIGEST_SIZE
780 #elif (BLAKE2S160_SUPPORT == ENABLED)
781  #define MAX_HASH_DIGEST_SIZE BLAKE2S160_DIGEST_SIZE
782 #elif (SHA1_SUPPORT == ENABLED)
783  #define MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
784 #elif (RIPEMD160_SUPPORT == ENABLED)
785  #define MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
786 #elif (BLAKE2S128_SUPPORT == ENABLED)
787  #define MAX_HASH_DIGEST_SIZE BLAKE2S128_DIGEST_SIZE
788 #elif (RIPEMD128_SUPPORT == ENABLED)
789  #define MAX_HASH_DIGEST_SIZE RIPEMD128_DIGEST_SIZE
790 #elif (MD5_SUPPORT == ENABLED)
791  #define MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
792 #elif (MD4_SUPPORT == ENABLED)
793  #define MAX_HASH_DIGEST_SIZE MD4_DIGEST_SIZE
794 #elif (MD2_SUPPORT == ENABLED)
795  #define MAX_HASH_DIGEST_SIZE MD2_DIGEST_SIZE
796 #endif
797 
798 //Maximum context size (block cipher algorithms)
799 #if (BLOWFISH_SUPPORT == ENABLED)
800  #define MAX_CIPHER_CONTEXT_SIZE sizeof(BlowfishContext)
801 #elif (ARIA_SUPPORT == ENABLED)
802  #define MAX_CIPHER_CONTEXT_SIZE sizeof(AriaContext)
803 #elif (AES_SUPPORT == ENABLED)
804  #define MAX_CIPHER_CONTEXT_SIZE sizeof(AesContext)
805 #elif (DES3_SUPPORT == ENABLED)
806  #define MAX_CIPHER_CONTEXT_SIZE sizeof(Des3Context)
807 #elif (CAMELLIA_SUPPORT == ENABLED)
808  #define MAX_CIPHER_CONTEXT_SIZE sizeof(CamelliaContext)
809 #elif (PRESENT_SUPPORT == ENABLED)
810  #define MAX_CIPHER_CONTEXT_SIZE sizeof(PresentContext)
811 #elif (RC6_SUPPORT == ENABLED)
812  #define MAX_CIPHER_CONTEXT_SIZE sizeof(Rc6Context)
813 #elif (IDEA_SUPPORT == ENABLED)
814  #define MAX_CIPHER_CONTEXT_SIZE sizeof(IdeaContext)
815 #elif (DES_SUPPORT == ENABLED)
816  #define MAX_CIPHER_CONTEXT_SIZE sizeof(DesContext)
817 #elif (SEED_SUPPORT == ENABLED)
818  #define MAX_CIPHER_CONTEXT_SIZE sizeof(SeedContext)
819 #elif (RC2_SUPPORT == ENABLED)
820  #define MAX_CIPHER_CONTEXT_SIZE sizeof(Rc2Context)
821 #endif
822 
823 //Maximum block size (block cipher algorithms)
824 #if (CAMELLIA_SUPPORT == ENABLED)
825  #define MAX_CIPHER_BLOCK_SIZE CAMELLIA_BLOCK_SIZE
826 #elif (AES_SUPPORT == ENABLED)
827  #define MAX_CIPHER_BLOCK_SIZE AES_BLOCK_SIZE
828 #elif (ARIA_SUPPORT == ENABLED)
829  #define MAX_CIPHER_BLOCK_SIZE ARIA_BLOCK_SIZE
830 #elif (SEED_SUPPORT == ENABLED)
831  #define MAX_CIPHER_BLOCK_SIZE SEED_BLOCK_SIZE
832 #elif (RC6_SUPPORT == ENABLED)
833  #define MAX_CIPHER_BLOCK_SIZE RC6_BLOCK_SIZE
834 #elif (DES3_SUPPORT == ENABLED)
835  #define MAX_CIPHER_BLOCK_SIZE DES3_BLOCK_SIZE
836 #elif (DES_SUPPORT == ENABLED)
837  #define MAX_CIPHER_BLOCK_SIZE DES_BLOCK_SIZE
838 #elif (IDEA_SUPPORT == ENABLED)
839  #define MAX_CIPHER_BLOCK_SIZE IDEA_BLOCK_SIZE
840 #elif (BLOWFISH_SUPPORT == ENABLED)
841  #define MAX_CIPHER_BLOCK_SIZE BLOWFISH_BLOCK_SIZE
842 #elif (PRESENT_SUPPORT == ENABLED)
843  #define MAX_CIPHER_BLOCK_SIZE PRESENT_BLOCK_SIZE
844 #elif (RC2_SUPPORT == ENABLED)
845  #define MAX_CIPHER_BLOCK_SIZE RC2_BLOCK_SIZE
846 #endif
847 
848 //Rotate left operation
849 #define ROL8(a, n) (((a) << (n)) | ((a) >> (8 - (n))))
850 #define ROL16(a, n) (((a) << (n)) | ((a) >> (16 - (n))))
851 #define ROL32(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
852 #define ROL64(a, n) (((a) << (n)) | ((a) >> (64 - (n))))
853 
854 //Rotate right operation
855 #define ROR8(a, n) (((a) >> (n)) | ((a) << (8 - (n))))
856 #define ROR16(a, n) (((a) >> (n)) | ((a) << (16 - (n))))
857 #define ROR32(a, n) (((a) >> (n)) | ((a) << (32 - (n))))
858 #define ROR64(a, n) (((a) >> (n)) | ((a) << (64 - (n))))
859 
860 //Shift left operation
861 #define SHL8(a, n) ((a) << (n))
862 #define SHL16(a, n) ((a) << (n))
863 #define SHL32(a, n) ((a) << (n))
864 #define SHL64(a, n) ((a) << (n))
865 
866 //Shift right operation
867 #define SHR8(a, n) ((a) >> (n))
868 #define SHR16(a, n) ((a) >> (n))
869 #define SHR32(a, n) ((a) >> (n))
870 #define SHR64(a, n) ((a) >> (n))
871 
872 //Micellaneous macros
873 #define _U8(x) ((uint8_t) (x))
874 #define _U16(x) ((uint16_t) (x))
875 #define _U32(x) ((uint32_t) (x))
876 #define _U64(x) ((uint64_t) (x))
877 
878 //Test if a 8-bit integer is zero
879 #define CRYPTO_TEST_Z_8(a) \
880  _U8((_U8((_U8(a) | (~_U8(a) + 1U))) >> 7U) ^ 1U)
881 
882 //Test if a 8-bit integer is nonzero
883 #define CRYPTO_TEST_NZ_8(a) \
884  _U8(_U8((_U8(a) | (~_U8(a) + 1U))) >> 7U)
885 
886 //Test if two 8-bit integers are equal
887 #define CRYPTO_TEST_EQ_8(a, b) \
888  _U8((_U8(((_U8(a) ^ _U8(b)) | (~(_U8(a) ^ _U8(b)) + 1U))) >> 7U) ^ 1U)
889 
890 //Test if two 8-bit integers are not equal
891 #define CRYPTO_TEST_NEQ_8(a, b) \
892  _U8(_U8(((_U8(a) ^ _U8(b)) | (~(_U8(a) ^ _U8(b)) + 1U))) >> 7U)
893 
894 //Test if a 8-bit integer is lower than another 8-bit integer
895 #define CRYPTO_TEST_LT_8(a, b) \
896  _U8(_U8((((_U8(a) - _U8(b)) ^ _U8(b)) | (_U8(a) ^ _U8(b))) ^ _U8(a)) >> 7U)
897 
898 //Test if a 8-bit integer is lower or equal than another 8-bit integer
899 #define CRYPTO_TEST_LTE_8(a, b) \
900  _U8((_U8((((_U8(b) - _U8(a)) ^ _U8(a)) | (_U8(a) ^ _U8(b))) ^ _U8(b)) >> 7U) ^ 1U)
901 
902 //Test if a 8-bit integer is greater than another 8-bit integer
903 #define CRYPTO_TEST_GT_8(a, b) \
904  _U8(_U8((((_U8(b) - _U8(a)) ^ _U8(a)) | (_U8(a) ^ _U8(b))) ^ _U8(b)) >> 7U)
905 
906 //Test if a 8-bit integer is greater or equal than another 8-bit integer
907 #define CRYPTO_TEST_GTE_8(a, b) \
908  _U8((_U8((((_U8(a) - _U8(b)) ^ _U8(b)) | (_U8(a) ^ _U8(b))) ^ _U8(a)) >> 7U) ^ 1U)
909 
910 //Select between two 8-bit integers
911 #define CRYPTO_SELECT_8(a, b, c) \
912  _U8((_U8(a) & (_U8(c) - 1U)) | (_U8(b) & ~(_U8(c) - 1U)))
913 
914 //Test if a 16-bit integer is zero
915 #define CRYPTO_TEST_Z_16(a) \
916  _U16((_U16((_U16(a) | (~_U16(a) + 1U))) >> 15U) ^ 1U)
917 
918 //Test if a 16-bit integer is nonzero
919 #define CRYPTO_TEST_NZ_16(a) \
920  _U16(_U16((_U16(a) | (~_U16(a) + 1U))) >> 15U)
921 
922 //Test if two 16-bit integers are equal
923 #define CRYPTO_TEST_EQ_16(a, b) \
924  _U16((_U16(((_U16(a) ^ _U16(b)) | (~(_U16(a) ^ _U16(b)) + 1U))) >> 15U) ^ 1U)
925 
926 //Test if two 16-bit integers are not equal
927 #define CRYPTO_TEST_NEQ_16(a, b) \
928  _U16(_U16(((_U16(a) ^ _U16(b)) | (~(_U16(a) ^ _U16(b)) + 1U))) >> 15U)
929 
930 //Test if a 16-bit integer is lower than another 16-bit integer
931 #define CRYPTO_TEST_LT_16(a, b) \
932  _U16(_U16((((_U16(a) - _U16(b)) ^ _U16(b)) | (_U16(a) ^ _U16(b))) ^ _U16(a)) >> 15U)
933 
934 //Test if a 16-bit integer is lower or equal than another 16-bit integer
935 #define CRYPTO_TEST_LTE_16(a, b) \
936  _U16((_U16((((_U16(b) - _U16(a)) ^ _U16(a)) | (_U16(a) ^ _U16(b))) ^ _U16(b)) >> 15U) ^ 1U)
937 
938 //Test if a 16-bit integer is greater than another 16-bit integer
939 #define CRYPTO_TEST_GT_16(a, b) \
940  _U16(_U16((((_U16(b) - _U16(a)) ^ _U16(a)) | (_U16(a) ^ _U16(b))) ^ _U16(b)) >> 15U)
941 
942 //Test if a 16-bit integer is greater or equal than another 16-bit integer
943 #define CRYPTO_TEST_GTE_16(a, b) \
944  _U16((_U16((((_U16(a) - _U16(b)) ^ _U16(b)) | (_U16(a) ^ _U16(b))) ^ _U16(a)) >> 15U) ^ 1U)
945 
946 //Select between two 16-bit integers
947 #define CRYPTO_SELECT_16(a, b, c) \
948  _U16((_U16(a) & (_U16(c) - 1U)) | (_U16(b) & ~(_U16(c) - 1U)))
949 
950 //Test if a 32-bit integer is zero
951 #define CRYPTO_TEST_Z_32(a) \
952  _U32((_U32((_U32(a) | (~_U32(a) + 1U))) >> 31U) ^ 1U)
953 
954 //Test if a 32-bit integer is nonzero
955 #define CRYPTO_TEST_NZ_32(a) \
956  _U32(_U32((_U32(a) | (~_U32(a) + 1U))) >> 31U)
957 
958 //Test if two 32-bit integers are equal
959 #define CRYPTO_TEST_EQ_32(a, b) \
960  _U32((_U32(((_U32(a) ^ _U32(b)) | (~(_U32(a) ^ _U32(b)) + 1U))) >> 31U) ^ 1U)
961 
962 //Test if two 32-bit integers are not equal
963 #define CRYPTO_TEST_NEQ_32(a, b) \
964  _U32(_U32(((_U32(a) ^ _U32(b)) | (~(_U32(a) ^ _U32(b)) + 1U))) >> 31U)
965 
966 //Test if a 32-bit integer is lower than another 32-bit integer
967 #define CRYPTO_TEST_LT_32(a, b) \
968  _U32(_U32((((_U32(a) - _U32(b)) ^ _U32(b)) | (_U32(a) ^ _U32(b))) ^ _U32(a)) >> 31U)
969 
970 //Test if a 32-bit integer is lower or equal than another 32-bit integer
971 #define CRYPTO_TEST_LTE_32(a, b) \
972  _U32((_U32((((_U32(b) - _U32(a)) ^ _U32(a)) | (_U32(a) ^ _U32(b))) ^ _U32(b)) >> 31U) ^ 1U)
973 
974 //Test if a 32-bit integer is greater than another 32-bit integer
975 #define CRYPTO_TEST_GT_32(a, b) \
976  _U32(_U32((((_U32(b) - _U32(a)) ^ _U32(a)) | (_U32(a) ^ _U32(b))) ^ _U32(b)) >> 31U)
977 
978 //Test if a 32-bit integer is greater or equal than another 32-bit integer
979 #define CRYPTO_TEST_GTE_32(a, b) \
980  _U32((_U32((((_U32(a) - _U32(b)) ^ _U32(b)) | (_U32(a) ^ _U32(b))) ^ _U32(a)) >> 31U) ^ 1U)
981 
982 //Select between two 32-bit integers
983 #define CRYPTO_SELECT_32(a, b, c) \
984  _U32((_U32(a) & (_U32(c) - 1U)) | (_U32(b) & ~(_U32(c) - 1U)))
985 
986 //Select between two 64-bit integers
987 #define CRYPTO_SELECT_64(a, b, c) \
988  _U64((_U64(a) & (_U64(c) - 1U)) | (_U64(b) & ~(_U64(c) - 1U)))
989 
990 //C++ guard
991 #ifdef __cplusplus
992 extern "C" {
993 #endif
994 
995 
996 /**
997  * @brief Encryption algorithm type
998  **/
999 
1000 typedef enum
1001 {
1004 } CipherAlgoType;
1005 
1006 
1007 /**
1008  * @brief Cipher operation modes
1009  **/
1010 
1011 typedef enum
1012 {
1023 } CipherMode;
1024 
1025 
1026 //Common API for hash algorithms
1027 typedef error_t (*HashAlgoCompute)(const void *data, size_t length, uint8_t *digest);
1028 typedef void (*HashAlgoInit)(void *context);
1029 typedef void (*HashAlgoUpdate)(void *context, const void *data, size_t length);
1030 typedef void (*HashAlgoFinal)(void *context, uint8_t *digest);
1031 typedef void (*HashAlgoFinalRaw)(void *context, uint8_t *digest);
1032 
1033 //Common API for encryption algorithms
1034 typedef error_t (*CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen);
1035 typedef void (*CipherAlgoEncryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length);
1036 typedef void (*CipherAlgoDecryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length);
1037 typedef void (*CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output);
1038 typedef void (*CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output);
1039 
1040 //Common API for pseudo-random number generators
1041 typedef error_t (*PrngAlgoInit)(void *context);
1042 typedef void (*PrngAlgoRelease)(void *context);
1043 typedef error_t (*PrngAlgoSeed)(void *context, const uint8_t *input, size_t length);
1044 typedef error_t (*PrngAlgoAddEntropy)(void *context, uint_t source, const uint8_t *input, size_t length, size_t entropy);
1045 typedef error_t (*PrngAlgoRead)(void *context, uint8_t *output, size_t length);
1046 
1047 
1048 /**
1049  * @brief Generic hash algorithm context
1050  **/
1051 
1052 typedef struct
1053 {
1054  uint8_t digest[1];
1055 } HashContext;
1056 
1057 
1058 /**
1059  * @brief Common interface for hash algorithms
1060  **/
1061 
1062 typedef struct
1063 {
1064  const char_t *name;
1065  const uint8_t *oid;
1066  size_t oidSize;
1067  size_t contextSize;
1068  size_t blockSize;
1069  size_t digestSize;
1070  size_t minPadSize;
1077 } HashAlgo;
1078 
1079 
1080 /**
1081  * @brief Common interface for encryption algorithms
1082  **/
1083 
1084 typedef struct
1085 {
1086  const char_t *name;
1087  size_t contextSize;
1089  size_t blockSize;
1095 } CipherAlgo;
1096 
1097 
1098 /**
1099  * @brief Common interface for pseudo-random number generators
1100  **/
1101 
1102 typedef struct
1103 {
1104  const char_t *name;
1105  size_t contextSize;
1111 } PrngAlgo;
1112 
1113 //C++ guard
1114 #ifdef __cplusplus
1115 }
1116 #endif
1117 
1118 #endif
uint8_t length
Definition: coap_common.h:190
void(* CipherAlgoDecryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length)
Definition: crypto.h:1036
HashAlgoInit init
Definition: crypto.h:1073
int bool_t
Definition: compiler_port.h:49
void(* HashAlgoInit)(void *context)
Definition: crypto.h:1028
const uint8_t * oid
Definition: crypto.h:1065
uint8_t data[]
Definition: ethernet.h:209
Common interface for pseudo-random number generators.
Definition: crypto.h:1102
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1037
CipherAlgoDecryptBlock decryptBlock
Definition: crypto.h:1094
PrngAlgoRead read
Definition: crypto.h:1110
void(* PrngAlgoRelease)(void *context)
Definition: crypto.h:1042
Legacy definitions.
size_t digestSize
Definition: crypto.h:1069
const char_t * name
Definition: crypto.h:1086
HashAlgoUpdate update
Definition: crypto.h:1074
CipherAlgoType
Encryption algorithm type.
Definition: crypto.h:1000
size_t blockSize
Definition: crypto.h:1089
error_t(* PrngAlgoAddEntropy)(void *context, uint_t source, const uint8_t *input, size_t length, size_t entropy)
Definition: crypto.h:1044
size_t blockSize
Definition: crypto.h:1068
size_t contextSize
Definition: crypto.h:1105
const char_t * name
Definition: crypto.h:1104
CipherAlgoEncryptBlock encryptBlock
Definition: crypto.h:1093
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
Definition: crypto.h:1029
size_t contextSize
Definition: crypto.h:1067
size_t oidSize
Definition: crypto.h:1066
CipherAlgoInit init
Definition: crypto.h:1090
CipherAlgoEncryptStream encryptStream
Definition: crypto.h:1091
PrngAlgoRelease release
Definition: crypto.h:1107
error_t
Error codes.
Definition: error.h:42
HashAlgoCompute compute
Definition: crypto.h:1072
CipherAlgoType type
Definition: crypto.h:1088
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1038
const char_t * name
Definition: crypto.h:1064
void(* CipherAlgoEncryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length)
Definition: crypto.h:1035
PrngAlgoInit init
Definition: crypto.h:1106
CipherAlgoDecryptStream decryptStream
Definition: crypto.h:1092
Error codes description.
PrngAlgoSeed seed
Definition: crypto.h:1108
Byte order conversion.
CipherMode
Cipher operation modes.
Definition: crypto.h:1011
error_t(* PrngAlgoRead)(void *context, uint8_t *output, size_t length)
Definition: crypto.h:1045
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:1034
PrngAlgoAddEntropy addEntropy
Definition: crypto.h:1109
void(* HashAlgoFinal)(void *context, uint8_t *digest)
Definition: crypto.h:1030
char char_t
Definition: compiler_port.h:43
size_t contextSize
Definition: crypto.h:1087
size_t minPadSize
Definition: crypto.h:1070
Common interface for encryption algorithms.
Definition: crypto.h:1084
Common interface for hash algorithms.
Definition: crypto.h:1062
bool_t bigEndian
Definition: crypto.h:1071
unsigned int uint_t
Definition: compiler_port.h:45
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
Definition: crypto.h:1027
error_t(* PrngAlgoSeed)(void *context, const uint8_t *input, size_t length)
Definition: crypto.h:1043
error_t(* PrngAlgoInit)(void *context)
Definition: crypto.h:1041
void(* HashAlgoFinalRaw)(void *context, uint8_t *digest)
Definition: crypto.h:1031
RTOS abstraction layer.
Generic hash algorithm context.
Definition: crypto.h:1052
HashAlgoFinalRaw finalRaw
Definition: crypto.h:1076