Go to the documentation of this file.
36 #include "crypto_config.h"
64 #ifndef GPL_LICENSE_TERMS_ACCEPTED
65 #error Before compiling CycloneCRYPTO Open, you must accept the terms of the GPL license
69 #define CYCLONE_CRYPTO_VERSION_STRING "2.0.2"
71 #define CYCLONE_CRYPTO_MAJOR_VERSION 2
73 #define CYCLONE_CRYPTO_MINOR_VERSION 0
75 #define CYCLONE_CRYPTO_REV_NUMBER 2
79 #define MPI_SUPPORT ENABLED
80 #elif (MPI_SUPPORT != ENABLED && MPI_SUPPORT != DISABLED)
81 #error MPI_SUPPORT parameter is not valid
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
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
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
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
114 #define MD2_SUPPORT DISABLED
115 #elif (MD2_SUPPORT != ENABLED && MD2_SUPPORT != DISABLED)
116 #error MD2_SUPPORT parameter is not valid
121 #define MD4_SUPPORT DISABLED
122 #elif (MD4_SUPPORT != ENABLED && MD4_SUPPORT != DISABLED)
123 #error MD4_SUPPORT parameter is not valid
128 #define MD5_SUPPORT ENABLED
129 #elif (MD5_SUPPORT != ENABLED && MD5_SUPPORT != DISABLED)
130 #error MD5_SUPPORT parameter is not valid
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
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
149 #define SHA1_SUPPORT ENABLED
150 #elif (SHA1_SUPPORT != ENABLED && SHA1_SUPPORT != DISABLED)
151 #error SHA1_SUPPORT parameter is not valid
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
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
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
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
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
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
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
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
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
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
225 #ifndef SHAKE_SUPPORT
226 #define SHAKE_SUPPORT DISABLED
227 #elif (SHAKE_SUPPORT != ENABLED && SHAKE_SUPPORT != DISABLED)
228 #error SHAKE_SUPPORT parameter is not valid
232 #ifndef CSHAKE_SUPPORT
233 #define CSHAKE_SUPPORT DISABLED
234 #elif (CSHAKE_SUPPORT != ENABLED && CSHAKE_SUPPORT != DISABLED)
235 #error CSHAKE_SUPPORT parameter is not valid
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
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
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
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
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
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
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
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
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
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
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
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
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
331 #define CMAC_SUPPORT DISABLED
332 #elif (CMAC_SUPPORT != ENABLED && CMAC_SUPPORT != DISABLED)
333 #error CMAC_SUPPORT parameter is not valid
338 #define GMAC_SUPPORT DISABLED
339 #elif (GMAC_SUPPORT != ENABLED && GMAC_SUPPORT != DISABLED)
340 #error GMAC_SUPPORT parameter is not valid
345 #define HMAC_SUPPORT ENABLED
346 #elif (HMAC_SUPPORT != ENABLED && HMAC_SUPPORT != DISABLED)
347 #error HMAC_SUPPORT parameter is not valid
352 #define KMAC_SUPPORT DISABLED
353 #elif (KMAC_SUPPORT != ENABLED && GMAC_SUPPORT != DISABLED)
354 #error KMAC_SUPPORT parameter is not valid
359 #define RC2_SUPPORT DISABLED
360 #elif (RC2_SUPPORT != ENABLED && RC2_SUPPORT != DISABLED)
361 #error RC2_SUPPORT parameter is not valid
366 #define RC4_SUPPORT DISABLED
367 #elif (RC4_SUPPORT != ENABLED && RC4_SUPPORT != DISABLED)
368 #error RC4_SUPPORT parameter is not valid
373 #define RC6_SUPPORT DISABLED
374 #elif (RC6_SUPPORT != ENABLED && RC6_SUPPORT != DISABLED)
375 #error RC6_SUPPORT parameter is not valid
380 #define IDEA_SUPPORT DISABLED
381 #elif (IDEA_SUPPORT != ENABLED && IDEA_SUPPORT != DISABLED)
382 #error IDEA_SUPPORT parameter is not valid
387 #define DES_SUPPORT ENABLED
388 #elif (DES_SUPPORT != ENABLED && DES_SUPPORT != DISABLED)
389 #error DES_SUPPORT parameter is not valid
394 #define DES3_SUPPORT ENABLED
395 #elif (DES3_SUPPORT != ENABLED && DES3_SUPPORT != DISABLED)
396 #error DES3_SUPPORT parameter is not valid
401 #define AES_SUPPORT ENABLED
402 #elif (AES_SUPPORT != ENABLED && AES_SUPPORT != DISABLED)
403 #error AES_SUPPORT parameter is not valid
407 #ifndef BLOWFISH_SUPPORT
408 #define BLOWFISH_SUPPORT DISABLED
409 #elif (BLOWFISH_SUPPORT != ENABLED && BLOWFISH_SUPPORT != DISABLED)
410 #error BLOWFISH_SUPPORT parameter is not valid
414 #ifndef CAMELLIA_SUPPORT
415 #define CAMELLIA_SUPPORT ENABLED
416 #elif (CAMELLIA_SUPPORT != ENABLED && CAMELLIA_SUPPORT != DISABLED)
417 #error CAMELLIA_SUPPORT parameter is not valid
422 #define SEED_SUPPORT ENABLED
423 #elif (SEED_SUPPORT != ENABLED && SEED_SUPPORT != DISABLED)
424 #error SEED_SUPPORT parameter is not valid
429 #define ARIA_SUPPORT ENABLED
430 #elif (ARIA_SUPPORT != ENABLED && ARIA_SUPPORT != DISABLED)
431 #error ARIA_SUPPORT parameter is not valid
435 #ifndef PRESENT_SUPPORT
436 #define PRESENT_SUPPORT DISABLED
437 #elif (PRESENT_SUPPORT != ENABLED && PRESENT_SUPPORT != DISABLED)
438 #error PRESENT_SUPPORT parameter is not valid
442 #ifndef TRIVIUM_SUPPORT
443 #define TRIVIUM_SUPPORT DISABLED
444 #elif (TRIVIUM_SUPPORT != ENABLED && TRIVIUM_SUPPORT != DISABLED)
445 #error TRIVIUM_SUPPORT parameter is not valid
450 #define ECB_SUPPORT ENABLED
451 #elif (ECB_SUPPORT != ENABLED && ECB_SUPPORT != DISABLED)
452 #error ECB_SUPPORT parameter is not valid
457 #define CBC_SUPPORT ENABLED
458 #elif (CBC_SUPPORT != ENABLED && CBC_SUPPORT != DISABLED)
459 #error CBC_SUPPORT parameter is not valid
464 #define CFB_SUPPORT ENABLED
465 #elif (CFB_SUPPORT != ENABLED && CFB_SUPPORT != DISABLED)
466 #error CFB_SUPPORT parameter is not valid
471 #define OFB_SUPPORT ENABLED
472 #elif (OFB_SUPPORT != ENABLED && OFB_SUPPORT != DISABLED)
473 #error OFB_SUPPORT parameter is not valid
478 #define CTR_SUPPORT ENABLED
479 #elif (CTR_SUPPORT != ENABLED && CTR_SUPPORT != DISABLED)
480 #error CTR_SUPPORT parameter is not valid
485 #define XTS_SUPPORT ENABLED
486 #elif (XTS_SUPPORT != ENABLED && XTS_SUPPORT != DISABLED)
487 #error XTS_SUPPORT parameter is not valid
492 #define CCM_SUPPORT ENABLED
493 #elif (CCM_SUPPORT != ENABLED && CCM_SUPPORT != DISABLED)
494 #error CCM_SUPPORT parameter is not valid
499 #define GCM_SUPPORT ENABLED
500 #elif (GCM_SUPPORT != ENABLED && GCM_SUPPORT != DISABLED)
501 #error GCM_SUPPORT parameter is not valid
505 #ifndef SALSA20_SUPPORT
506 #define SALSA20_SUPPORT DISABLED
507 #elif (SALSA20_SUPPORT != ENABLED && SALSA20_SUPPORT != DISABLED)
508 #error SALSA20_SUPPORT parameter is not valid
512 #ifndef CHACHA_SUPPORT
513 #define CHACHA_SUPPORT DISABLED
514 #elif (CHACHA_SUPPORT != ENABLED && CHACHA_SUPPORT != DISABLED)
515 #error CHACHA_SUPPORT parameter is not valid
519 #ifndef POLY1305_SUPPORT
520 #define POLY1305_SUPPORT DISABLED
521 #elif (POLY1305_SUPPORT != ENABLED && POLY1305_SUPPORT != DISABLED)
522 #error POLY1305_SUPPORT parameter is not valid
526 #ifndef CHACHA20_POLY1305_SUPPORT
527 #define CHACHA20_POLY1305_SUPPORT DISABLED
528 #elif (CHACHA20_POLY1305_SUPPORT != ENABLED && CHACHA20_POLY1305_SUPPORT != DISABLED)
529 #error CHACHA20_POLY1305_SUPPORT parameter is not valid
534 #define DH_SUPPORT ENABLED
535 #elif (DH_SUPPORT != ENABLED && DH_SUPPORT != DISABLED)
536 #error DH_SUPPORT parameter is not valid
541 #define RSA_SUPPORT ENABLED
542 #elif (RSA_SUPPORT != ENABLED && RSA_SUPPORT != DISABLED)
543 #error RSA_SUPPORT parameter is not valid
548 #define DSA_SUPPORT ENABLED
549 #elif (DSA_SUPPORT != ENABLED && DSA_SUPPORT != DISABLED)
550 #error DSA_SUPPORT parameter is not valid
555 #define EC_SUPPORT ENABLED
556 #elif (EC_SUPPORT != ENABLED && EC_SUPPORT != DISABLED)
557 #error EC_SUPPORT parameter is not valid
562 #define ECDH_SUPPORT ENABLED
563 #elif (ECDH_SUPPORT != ENABLED && ECDH_SUPPORT != DISABLED)
564 #error ECDH_SUPPORT parameter is not valid
568 #ifndef ECDSA_SUPPORT
569 #define ECDSA_SUPPORT ENABLED
570 #elif (ECDSA_SUPPORT != ENABLED && ECDSA_SUPPORT != DISABLED)
571 #error ECDSA_SUPPORT parameter is not valid
576 #define HKDF_SUPPORT DISABLED
577 #elif (HKDF_SUPPORT != ENABLED && HKDF_SUPPORT != DISABLED)
578 #error HKDF_SUPPORT parameter is not valid
582 #ifndef PBKDF_SUPPORT
583 #define PBKDF_SUPPORT ENABLED
584 #elif (PBKDF_SUPPORT != ENABLED && PKCS5_SUPPORT != DISABLED)
585 #error PBKDF_SUPPORT parameter is not valid
589 #ifndef BCRYPT_SUPPORT
590 #define BCRYPT_SUPPORT ENABLED
591 #elif (BCRYPT_SUPPORT != ENABLED && BCRYPT_SUPPORT != DISABLED)
592 #error BCRYPT_SUPPORT parameter is not valid
596 #ifndef SCRYPT_SUPPORT
597 #define SCRYPT_SUPPORT ENABLED
598 #elif (SCRYPT_SUPPORT != ENABLED && SCRYPT_SUPPORT != DISABLED)
599 #error SCRYPT_SUPPORT parameter is not valid
603 #ifndef YARROW_SUPPORT
604 #define YARROW_SUPPORT ENABLED
605 #elif (YARROW_SUPPORT != ENABLED && YARROW_SUPPORT != DISABLED)
606 #error YARROW_SUPPORT parameter is not valid
611 #define OID_SUPPORT ENABLED
612 #elif (OID_SUPPORT != ENABLED && OID_SUPPORT != DISABLED)
613 #error OID_SUPPORT parameter is not valid
618 #define ASN1_SUPPORT ENABLED
619 #elif (ASN1_SUPPORT != ENABLED && ASN1_SUPPORT != DISABLED)
620 #error ASN1_SUPPORT parameter is not valid
625 #define PEM_SUPPORT ENABLED
626 #elif (PEM_SUPPORT != ENABLED && PEM_SUPPORT != DISABLED)
627 #error PEM_SUPPORT parameter is not valid
632 #define X509_SUPPORT ENABLED
633 #elif (X509_SUPPORT != ENABLED && X509_SUPPORT != DISABLED)
634 #error X509_SUPPORT parameter is not valid
638 #ifndef cryptoAllocMem
639 #define cryptoAllocMem(size) osAllocMem(size)
643 #ifndef cryptoFreeMem
644 #define cryptoFreeMem(p) osFreeMem(p)
648 #if (SHA3_512_SUPPORT == ENABLED)
649 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_512Context)
650 #elif (SHA3_384_SUPPORT == ENABLED)
651 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_384Context)
652 #elif (SHA3_256_SUPPORT == ENABLED)
653 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_256Context)
654 #elif (SHA3_224_SUPPORT == ENABLED)
655 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha3_224Context)
656 #elif (WHIRLPOOL_SUPPORT == ENABLED)
657 #define MAX_HASH_CONTEXT_SIZE sizeof(WhirlpoolContext)
658 #elif (BLAKE2B512_SUPPORT == ENABLED)
659 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b512Context)
660 #elif (BLAKE2B384_SUPPORT == ENABLED)
661 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b384Context)
662 #elif (BLAKE2B256_SUPPORT == ENABLED)
663 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b256Context)
664 #elif (BLAKE2B160_SUPPORT == ENABLED)
665 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2b160Context)
666 #elif (SHA512_SUPPORT == ENABLED)
667 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512Context)
668 #elif (SHA384_SUPPORT == ENABLED)
669 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha384Context)
670 #elif (SHA512_256_SUPPORT == ENABLED)
671 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512_256Context)
672 #elif (SHA512_224_SUPPORT == ENABLED)
673 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha512_224Context)
674 #elif (BLAKE2S256_SUPPORT == ENABLED)
675 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s256Context)
676 #elif (BLAKE2S224_SUPPORT == ENABLED)
677 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s224Context)
678 #elif (BLAKE2S160_SUPPORT == ENABLED)
679 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s160Context)
680 #elif (BLAKE2S128_SUPPORT == ENABLED)
681 #define MAX_HASH_CONTEXT_SIZE sizeof(Blake2s128Context)
682 #elif (SHA256_SUPPORT == ENABLED)
683 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha256Context)
684 #elif (SHA224_SUPPORT == ENABLED)
685 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha224Context)
686 #elif (TIGER_SUPPORT == ENABLED)
687 #define MAX_HASH_CONTEXT_SIZE sizeof(TigerContext)
688 #elif (SHA1_SUPPORT == ENABLED)
689 #define MAX_HASH_CONTEXT_SIZE sizeof(Sha1Context)
690 #elif (RIPEMD160_SUPPORT == ENABLED)
691 #define MAX_HASH_CONTEXT_SIZE sizeof(Ripemd160Context)
692 #elif (RIPEMD128_SUPPORT == ENABLED)
693 #define MAX_HASH_CONTEXT_SIZE sizeof(Ripemd128Context)
694 #elif (MD5_SUPPORT == ENABLED)
695 #define MAX_HASH_CONTEXT_SIZE sizeof(Md5Context)
696 #elif (MD4_SUPPORT == ENABLED)
697 #define MAX_HASH_CONTEXT_SIZE sizeof(Md4Context)
698 #elif (MD2_SUPPORT == ENABLED)
699 #define MAX_HASH_CONTEXT_SIZE sizeof(Md2Context)
703 #if (SHA3_224_SUPPORT == ENABLED)
704 #define MAX_HASH_BLOCK_SIZE SHA3_224_BLOCK_SIZE
705 #elif (SHA3_256_SUPPORT == ENABLED)
706 #define MAX_HASH_BLOCK_SIZE SHA3_256_BLOCK_SIZE
707 #elif (BLAKE2B512_SUPPORT == ENABLED)
708 #define MAX_HASH_BLOCK_SIZE BLAKE2B512_BLOCK_SIZE
709 #elif (BLAKE2B384_SUPPORT == ENABLED)
710 #define MAX_HASH_BLOCK_SIZE BLAKE2B384_BLOCK_SIZE
711 #elif (BLAKE2B256_SUPPORT == ENABLED)
712 #define MAX_HASH_BLOCK_SIZE BLAKE2B256_BLOCK_SIZE
713 #elif (BLAKE2B160_SUPPORT == ENABLED)
714 #define MAX_HASH_BLOCK_SIZE BLAKE2B160_BLOCK_SIZE
715 #elif (SHA512_SUPPORT == ENABLED)
716 #define MAX_HASH_BLOCK_SIZE SHA512_BLOCK_SIZE
717 #elif (SHA384_SUPPORT == ENABLED)
718 #define MAX_HASH_BLOCK_SIZE SHA384_BLOCK_SIZE
719 #elif (SHA512_256_SUPPORT == ENABLED)
720 #define MAX_HASH_BLOCK_SIZE SHA512_256_BLOCK_SIZE
721 #elif (SHA512_224_SUPPORT == ENABLED)
722 #define MAX_HASH_BLOCK_SIZE SHA512_224_BLOCK_SIZE
723 #elif (SHA3_384_SUPPORT == ENABLED)
724 #define MAX_HASH_BLOCK_SIZE SHA3_384_BLOCK_SIZE
725 #elif (SHA3_512_SUPPORT == ENABLED)
726 #define MAX_HASH_BLOCK_SIZE SHA3_512_BLOCK_SIZE
727 #elif (BLAKE2S256_SUPPORT == ENABLED)
728 #define MAX_HASH_BLOCK_SIZE BLAKE2S256_BLOCK_SIZE
729 #elif (BLAKE2S224_SUPPORT == ENABLED)
730 #define MAX_HASH_BLOCK_SIZE BLAKE2S224_BLOCK_SIZE
731 #elif (BLAKE2S160_SUPPORT == ENABLED)
732 #define MAX_HASH_BLOCK_SIZE BLAKE2S160_BLOCK_SIZE
733 #elif (BLAKE2S128_SUPPORT == ENABLED)
734 #define MAX_HASH_BLOCK_SIZE BLAKE2S128_BLOCK_SIZE
735 #elif (SHA256_SUPPORT == ENABLED)
736 #define MAX_HASH_BLOCK_SIZE SHA256_BLOCK_SIZE
737 #elif (SHA224_SUPPORT == ENABLED)
738 #define MAX_HASH_BLOCK_SIZE SHA224_BLOCK_SIZE
739 #elif (SHA1_SUPPORT == ENABLED)
740 #define MAX_HASH_BLOCK_SIZE SHA1_BLOCK_SIZE
741 #elif (WHIRLPOOL_SUPPORT == ENABLED)
742 #define MAX_HASH_BLOCK_SIZE WHIRLPOOL_BLOCK_SIZE
743 #elif (TIGER_SUPPORT == ENABLED)
744 #define MAX_HASH_BLOCK_SIZE TIGER_BLOCK_SIZE
745 #elif (RIPEMD160_SUPPORT == ENABLED)
746 #define MAX_HASH_BLOCK_SIZE RIPEMD160_BLOCK_SIZE
747 #elif (RIPEMD128_SUPPORT == ENABLED)
748 #define MAX_HASH_BLOCK_SIZE RIPEMD128_BLOCK_SIZE
749 #elif (MD5_SUPPORT == ENABLED)
750 #define MAX_HASH_BLOCK_SIZE MD5_BLOCK_SIZE
751 #elif (MD4_SUPPORT == ENABLED)
752 #define MAX_HASH_BLOCK_SIZE MD4_BLOCK_SIZE
753 #elif (MD2_SUPPORT == ENABLED)
754 #define MAX_HASH_BLOCK_SIZE MD2_BLOCK_SIZE
758 #if (WHIRLPOOL_SUPPORT == ENABLED)
759 #define MAX_HASH_DIGEST_SIZE WHIRLPOOL_DIGEST_SIZE
760 #elif (BLAKE2B512_SUPPORT == ENABLED)
761 #define MAX_HASH_DIGEST_SIZE BLAKE2B512_DIGEST_SIZE
762 #elif (SHA3_512_SUPPORT == ENABLED)
763 #define MAX_HASH_DIGEST_SIZE SHA3_512_DIGEST_SIZE
764 #elif (SHA512_SUPPORT == ENABLED)
765 #define MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
766 #elif (BLAKE2B384_SUPPORT == ENABLED)
767 #define MAX_HASH_DIGEST_SIZE BLAKE2B384_DIGEST_SIZE
768 #elif (SHA3_384_SUPPORT == ENABLED)
769 #define MAX_HASH_DIGEST_SIZE SHA3_384_DIGEST_SIZE
770 #elif (SHA384_SUPPORT == ENABLED)
771 #define MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
772 #elif (BLAKE2B256_SUPPORT == ENABLED)
773 #define MAX_HASH_DIGEST_SIZE BLAKE2B256_DIGEST_SIZE
774 #elif (BLAKE2S256_SUPPORT == ENABLED)
775 #define MAX_HASH_DIGEST_SIZE BLAKE2S256_DIGEST_SIZE
776 #elif (SHA3_256_SUPPORT == ENABLED)
777 #define MAX_HASH_DIGEST_SIZE SHA3_256_DIGEST_SIZE
778 #elif (SHA512_256_SUPPORT == ENABLED)
779 #define MAX_HASH_DIGEST_SIZE SHA512_256_DIGEST_SIZE
780 #elif (SHA256_SUPPORT == ENABLED)
781 #define MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
782 #elif (BLAKE2S224_SUPPORT == ENABLED)
783 #define MAX_HASH_DIGEST_SIZE BLAKE2S224_DIGEST_SIZE
784 #elif (SHA3_224_SUPPORT == ENABLED)
785 #define MAX_HASH_DIGEST_SIZE SHA3_224_DIGEST_SIZE
786 #elif (SHA512_224_SUPPORT == ENABLED)
787 #define MAX_HASH_DIGEST_SIZE SHA512_224_DIGEST_SIZE
788 #elif (SHA224_SUPPORT == ENABLED)
789 #define MAX_HASH_DIGEST_SIZE SHA224_DIGEST_SIZE
790 #elif (TIGER_SUPPORT == ENABLED)
791 #define MAX_HASH_DIGEST_SIZE TIGER_DIGEST_SIZE
792 #elif (BLAKE2B160_SUPPORT == ENABLED)
793 #define MAX_HASH_DIGEST_SIZE BLAKE2B160_DIGEST_SIZE
794 #elif (BLAKE2S160_SUPPORT == ENABLED)
795 #define MAX_HASH_DIGEST_SIZE BLAKE2S160_DIGEST_SIZE
796 #elif (SHA1_SUPPORT == ENABLED)
797 #define MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
798 #elif (RIPEMD160_SUPPORT == ENABLED)
799 #define MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
800 #elif (BLAKE2S128_SUPPORT == ENABLED)
801 #define MAX_HASH_DIGEST_SIZE BLAKE2S128_DIGEST_SIZE
802 #elif (RIPEMD128_SUPPORT == ENABLED)
803 #define MAX_HASH_DIGEST_SIZE RIPEMD128_DIGEST_SIZE
804 #elif (MD5_SUPPORT == ENABLED)
805 #define MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
806 #elif (MD4_SUPPORT == ENABLED)
807 #define MAX_HASH_DIGEST_SIZE MD4_DIGEST_SIZE
808 #elif (MD2_SUPPORT == ENABLED)
809 #define MAX_HASH_DIGEST_SIZE MD2_DIGEST_SIZE
813 #if (BLOWFISH_SUPPORT == ENABLED)
814 #define MAX_CIPHER_CONTEXT_SIZE sizeof(BlowfishContext)
815 #elif (ARIA_SUPPORT == ENABLED)
816 #define MAX_CIPHER_CONTEXT_SIZE sizeof(AriaContext)
817 #elif (AES_SUPPORT == ENABLED)
818 #define MAX_CIPHER_CONTEXT_SIZE sizeof(AesContext)
819 #elif (DES3_SUPPORT == ENABLED)
820 #define MAX_CIPHER_CONTEXT_SIZE sizeof(Des3Context)
821 #elif (CAMELLIA_SUPPORT == ENABLED)
822 #define MAX_CIPHER_CONTEXT_SIZE sizeof(CamelliaContext)
823 #elif (PRESENT_SUPPORT == ENABLED)
824 #define MAX_CIPHER_CONTEXT_SIZE sizeof(PresentContext)
825 #elif (RC6_SUPPORT == ENABLED)
826 #define MAX_CIPHER_CONTEXT_SIZE sizeof(Rc6Context)
827 #elif (IDEA_SUPPORT == ENABLED)
828 #define MAX_CIPHER_CONTEXT_SIZE sizeof(IdeaContext)
829 #elif (DES_SUPPORT == ENABLED)
830 #define MAX_CIPHER_CONTEXT_SIZE sizeof(DesContext)
831 #elif (SEED_SUPPORT == ENABLED)
832 #define MAX_CIPHER_CONTEXT_SIZE sizeof(SeedContext)
833 #elif (RC2_SUPPORT == ENABLED)
834 #define MAX_CIPHER_CONTEXT_SIZE sizeof(Rc2Context)
838 #if (CAMELLIA_SUPPORT == ENABLED)
839 #define MAX_CIPHER_BLOCK_SIZE CAMELLIA_BLOCK_SIZE
840 #elif (AES_SUPPORT == ENABLED)
841 #define MAX_CIPHER_BLOCK_SIZE AES_BLOCK_SIZE
842 #elif (ARIA_SUPPORT == ENABLED)
843 #define MAX_CIPHER_BLOCK_SIZE ARIA_BLOCK_SIZE
844 #elif (SEED_SUPPORT == ENABLED)
845 #define MAX_CIPHER_BLOCK_SIZE SEED_BLOCK_SIZE
846 #elif (RC6_SUPPORT == ENABLED)
847 #define MAX_CIPHER_BLOCK_SIZE RC6_BLOCK_SIZE
848 #elif (DES3_SUPPORT == ENABLED)
849 #define MAX_CIPHER_BLOCK_SIZE DES3_BLOCK_SIZE
850 #elif (DES_SUPPORT == ENABLED)
851 #define MAX_CIPHER_BLOCK_SIZE DES_BLOCK_SIZE
852 #elif (IDEA_SUPPORT == ENABLED)
853 #define MAX_CIPHER_BLOCK_SIZE IDEA_BLOCK_SIZE
854 #elif (BLOWFISH_SUPPORT == ENABLED)
855 #define MAX_CIPHER_BLOCK_SIZE BLOWFISH_BLOCK_SIZE
856 #elif (PRESENT_SUPPORT == ENABLED)
857 #define MAX_CIPHER_BLOCK_SIZE PRESENT_BLOCK_SIZE
858 #elif (RC2_SUPPORT == ENABLED)
859 #define MAX_CIPHER_BLOCK_SIZE RC2_BLOCK_SIZE
863 #define ROL8(a, n) (((a) << (n)) | ((a) >> (8 - (n))))
864 #define ROL16(a, n) (((a) << (n)) | ((a) >> (16 - (n))))
865 #define ROL32(a, n) (((a) << (n)) | ((a) >> (32 - (n))))
866 #define ROL64(a, n) (((a) << (n)) | ((a) >> (64 - (n))))
869 #define ROR8(a, n) (((a) >> (n)) | ((a) << (8 - (n))))
870 #define ROR16(a, n) (((a) >> (n)) | ((a) << (16 - (n))))
871 #define ROR32(a, n) (((a) >> (n)) | ((a) << (32 - (n))))
872 #define ROR64(a, n) (((a) >> (n)) | ((a) << (64 - (n))))
875 #define SHL8(a, n) ((a) << (n))
876 #define SHL16(a, n) ((a) << (n))
877 #define SHL32(a, n) ((a) << (n))
878 #define SHL64(a, n) ((a) << (n))
881 #define SHR8(a, n) ((a) >> (n))
882 #define SHR16(a, n) ((a) >> (n))
883 #define SHR32(a, n) ((a) >> (n))
884 #define SHR64(a, n) ((a) >> (n))
887 #define _U8(x) ((uint8_t) (x))
888 #define _U16(x) ((uint16_t) (x))
889 #define _U32(x) ((uint32_t) (x))
890 #define _U64(x) ((uint64_t) (x))
893 #define CRYPTO_TEST_Z_8(a) \
894 _U8((_U8((_U8(a) | (~_U8(a) + 1U))) >> 7U) ^ 1U)
897 #define CRYPTO_TEST_NZ_8(a) \
898 _U8(_U8((_U8(a) | (~_U8(a) + 1U))) >> 7U)
901 #define CRYPTO_TEST_EQ_8(a, b) \
902 _U8((_U8(((_U8(a) ^ _U8(b)) | (~(_U8(a) ^ _U8(b)) + 1U))) >> 7U) ^ 1U)
905 #define CRYPTO_TEST_NEQ_8(a, b) \
906 _U8(_U8(((_U8(a) ^ _U8(b)) | (~(_U8(a) ^ _U8(b)) + 1U))) >> 7U)
909 #define CRYPTO_TEST_LT_8(a, b) \
910 _U8(_U8((((_U8(a) - _U8(b)) ^ _U8(b)) | (_U8(a) ^ _U8(b))) ^ _U8(a)) >> 7U)
913 #define CRYPTO_TEST_LTE_8(a, b) \
914 _U8((_U8((((_U8(b) - _U8(a)) ^ _U8(a)) | (_U8(a) ^ _U8(b))) ^ _U8(b)) >> 7U) ^ 1U)
917 #define CRYPTO_TEST_GT_8(a, b) \
918 _U8(_U8((((_U8(b) - _U8(a)) ^ _U8(a)) | (_U8(a) ^ _U8(b))) ^ _U8(b)) >> 7U)
921 #define CRYPTO_TEST_GTE_8(a, b) \
922 _U8((_U8((((_U8(a) - _U8(b)) ^ _U8(b)) | (_U8(a) ^ _U8(b))) ^ _U8(a)) >> 7U) ^ 1U)
925 #define CRYPTO_SELECT_8(a, b, c) \
926 _U8((_U8(a) & (_U8(c) - 1U)) | (_U8(b) & ~(_U8(c) - 1U)))
929 #define CRYPTO_TEST_Z_16(a) \
930 _U16((_U16((_U16(a) | (~_U16(a) + 1U))) >> 15U) ^ 1U)
933 #define CRYPTO_TEST_NZ_16(a) \
934 _U16(_U16((_U16(a) | (~_U16(a) + 1U))) >> 15U)
937 #define CRYPTO_TEST_EQ_16(a, b) \
938 _U16((_U16(((_U16(a) ^ _U16(b)) | (~(_U16(a) ^ _U16(b)) + 1U))) >> 15U) ^ 1U)
941 #define CRYPTO_TEST_NEQ_16(a, b) \
942 _U16(_U16(((_U16(a) ^ _U16(b)) | (~(_U16(a) ^ _U16(b)) + 1U))) >> 15U)
945 #define CRYPTO_TEST_LT_16(a, b) \
946 _U16(_U16((((_U16(a) - _U16(b)) ^ _U16(b)) | (_U16(a) ^ _U16(b))) ^ _U16(a)) >> 15U)
949 #define CRYPTO_TEST_LTE_16(a, b) \
950 _U16((_U16((((_U16(b) - _U16(a)) ^ _U16(a)) | (_U16(a) ^ _U16(b))) ^ _U16(b)) >> 15U) ^ 1U)
953 #define CRYPTO_TEST_GT_16(a, b) \
954 _U16(_U16((((_U16(b) - _U16(a)) ^ _U16(a)) | (_U16(a) ^ _U16(b))) ^ _U16(b)) >> 15U)
957 #define CRYPTO_TEST_GTE_16(a, b) \
958 _U16((_U16((((_U16(a) - _U16(b)) ^ _U16(b)) | (_U16(a) ^ _U16(b))) ^ _U16(a)) >> 15U) ^ 1U)
961 #define CRYPTO_SELECT_16(a, b, c) \
962 _U16((_U16(a) & (_U16(c) - 1U)) | (_U16(b) & ~(_U16(c) - 1U)))
965 #define CRYPTO_TEST_Z_32(a) \
966 _U32((_U32((_U32(a) | (~_U32(a) + 1U))) >> 31U) ^ 1U)
969 #define CRYPTO_TEST_NZ_32(a) \
970 _U32(_U32((_U32(a) | (~_U32(a) + 1U))) >> 31U)
973 #define CRYPTO_TEST_EQ_32(a, b) \
974 _U32((_U32(((_U32(a) ^ _U32(b)) | (~(_U32(a) ^ _U32(b)) + 1U))) >> 31U) ^ 1U)
977 #define CRYPTO_TEST_NEQ_32(a, b) \
978 _U32(_U32(((_U32(a) ^ _U32(b)) | (~(_U32(a) ^ _U32(b)) + 1U))) >> 31U)
981 #define CRYPTO_TEST_LT_32(a, b) \
982 _U32(_U32((((_U32(a) - _U32(b)) ^ _U32(b)) | (_U32(a) ^ _U32(b))) ^ _U32(a)) >> 31U)
985 #define CRYPTO_TEST_LTE_32(a, b) \
986 _U32((_U32((((_U32(b) - _U32(a)) ^ _U32(a)) | (_U32(a) ^ _U32(b))) ^ _U32(b)) >> 31U) ^ 1U)
989 #define CRYPTO_TEST_GT_32(a, b) \
990 _U32(_U32((((_U32(b) - _U32(a)) ^ _U32(a)) | (_U32(a) ^ _U32(b))) ^ _U32(b)) >> 31U)
993 #define CRYPTO_TEST_GTE_32(a, b) \
994 _U32((_U32((((_U32(a) - _U32(b)) ^ _U32(b)) | (_U32(a) ^ _U32(b))) ^ _U32(a)) >> 31U) ^ 1U)
997 #define CRYPTO_SELECT_32(a, b, c) \
998 _U32((_U32(a) & (_U32(c) - 1U)) | (_U32(b) & ~(_U32(c) - 1U)))
1001 #define CRYPTO_SELECT_64(a, b, c) \
1002 _U64((_U64(a) & (_U64(c) - 1U)) | (_U64(b) & ~(_U64(c) - 1U)))
void(* CipherAlgoDecryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length)
void(* HashAlgoInit)(void *context)
Common interface for pseudo-random number generators.
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
CipherAlgoDecryptBlock decryptBlock
void(* PrngAlgoRelease)(void *context)
CipherAlgoType
Encryption algorithm type.
error_t(* PrngAlgoAddEntropy)(void *context, uint_t source, const uint8_t *input, size_t length, size_t entropy)
CipherAlgoEncryptBlock encryptBlock
void(* HashAlgoUpdate)(void *context, const void *data, size_t length)
CipherAlgoEncryptStream encryptStream
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
void(* CipherAlgoEncryptStream)(void *context, const uint8_t *input, uint8_t *output, size_t length)
CipherAlgoDecryptStream decryptStream
CipherMode
Cipher operation modes.
error_t(* PrngAlgoRead)(void *context, uint8_t *output, size_t length)
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
PrngAlgoAddEntropy addEntropy
void(* HashAlgoFinal)(void *context, uint8_t *digest)
Common interface for encryption algorithms.
@ CIPHER_ALGO_TYPE_STREAM
Common interface for hash algorithms.
@ CIPHER_MODE_CHACHA20_POLY1305
error_t(* HashAlgoCompute)(const void *data, size_t length, uint8_t *digest)
error_t(* PrngAlgoSeed)(void *context, const uint8_t *input, size_t length)
error_t(* PrngAlgoInit)(void *context)
void(* HashAlgoFinalRaw)(void *context, uint8_t *digest)
Generic hash algorithm context.
HashAlgoFinalRaw finalRaw