]>
Dogcows Code - chaz/p5-File-KDBX-XS/blob - tomcrypt_custom.h
b13c2e08ff11e8169d2b96cc319d70a4d2d6bcf7
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
4 #ifndef TOMCRYPT_CUSTOM_H_
5 #define TOMCRYPT_CUSTOM_H_
7 /* macros for various libc functions you can change for embedded targets */
12 #define XREALLOC realloc
15 #define XCALLOC calloc
22 #define XMEMSET memset
25 #define XMEMCPY memcpy
28 #define XMEMMOVE memmove
31 #define XMEMCMP memcmp
33 /* A memory compare function that has to run in constant time,
34 * c.f. mem_neq() API summary.
37 #define XMEM_NEQ mem_neq
40 #define XSTRCMP strcmp
43 #define XSTRLEN strlen
46 #define XSTRNCPY strncpy
57 #if ( defined(malloc) || defined(realloc) || defined(calloc) || defined(free) || \
58 defined(memset) || defined(memcpy) || defined(memcmp) || defined(strcmp) || \
59 defined(strlen) || defined(strncpy) || defined(clock) || defined(qsort) ) \
60 && !defined(LTC_NO_PROTOTYPES)
61 #define LTC_NO_PROTOTYPES
64 /* shortcut to disable automatic inclusion */
65 #if defined LTC_NOTHING && !defined LTC_EASY
66 #define LTC_NO_CIPHERS
74 #endif /* LTC_NOTHING */
78 #define LTC_NO_CIPHERS
96 #define LTC_HASH_HELPERS
106 #define LTC_DEVRANDOM
107 #define LTC_TRY_URANDOM_FIRST
108 #define LTC_RNG_GET_BYTES
109 #define LTC_RNG_MAKE_PRNG
119 /* The minimal set of functionality to run the tests */
126 #define LTC_RNG_MAKE_PRNG
127 #define LTC_RNG_GET_BYTES
128 #define LTC_DEVRANDOM
129 #define LTC_TRY_URANDOM_FIRST
134 /* Enable self-test test vector checking */
138 /* Enable extended self-tests */
139 /* #define LTC_TEST_EXT */
141 /* Use small code where possible */
142 /* #define LTC_SMALL_CODE */
144 /* clean the stack of functions which put private information on stack */
145 /* #define LTC_CLEAN_STACK */
147 /* disable all file related functions */
148 /* #define LTC_NO_FILE */
150 /* disable all forms of ASM */
151 /* #define LTC_NO_ASM */
153 /* disable FAST mode */
154 /* #define LTC_NO_FAST */
156 /* disable BSWAP on x86 */
157 /* #define LTC_NO_BSWAP */
159 /* ---> math provider? <--- */
163 /* #define LTM_DESC */
166 /* #define TFM_DESC */
168 /* GNU Multiple Precision Arithmetic Library */
169 /* #define GMP_DESC */
171 #endif /* LTC_NO_MATH */
173 /* ---> Symmetric Block Ciphers <--- */
174 #ifndef LTC_NO_CIPHERS
183 /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
184 * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
186 #ifndef LTC_NO_TABLES
187 #define LTC_TWOFISH_TABLES
188 /* #define LTC_TWOFISH_ALL_TABLES */
190 #define LTC_TWOFISH_SMALL
192 /* #define LTC_TWOFISH_SMALL */
193 /* LTC_DES includes EDE triple-DES */
201 #define LTC_ANUBIS_TWEAK
214 #define LTC_SOSEMANUK
216 #define LTC_RC4_STREAM
217 #define LTC_SOBER128_STREAM
219 #endif /* LTC_NO_CIPHERS */
222 /* ---> Block Cipher Modes of Operation <--- */
231 /* F8 chaining mode */
236 #ifndef LTC_NO_TABLES
237 /* like GCM mode this will enable 16 8x128 tables [64KB] that make
240 #define LTC_LRW_TABLES
246 #endif /* LTC_NO_MODES */
248 /* ---> One-Way Hash Functions <--- */
249 #ifndef LTC_NO_HASHES
252 #define LTC_WHIRLPOOL
256 #define LTC_SHA512_256
257 #define LTC_SHA512_224
266 #define LTC_RIPEMD128
267 #define LTC_RIPEMD160
268 #define LTC_RIPEMD256
269 #define LTC_RIPEMD320
273 #define LTC_HASH_HELPERS
275 #endif /* LTC_NO_HASHES */
278 /* ---> MAC functions <--- */
288 #define LTC_BLAKE2SMAC
289 #define LTC_BLAKE2BMAC
291 /* ---> Encrypt + Authenticate Modes <--- */
296 #define LTC_OCB3_MODE
299 #define LTC_CHACHA20POLY1305_MODE
301 /* Use 64KiB tables */
302 #ifndef LTC_NO_TABLES
303 #define LTC_GCM_TABLES
306 /* USE SSE2? requires GCC works on x86_32 and x86_64*/
307 #ifdef LTC_GCM_TABLES
308 /* #define LTC_GCM_TABLES_SSE2 */
311 #endif /* LTC_NO_MACS */
314 /* --> Pseudo Random Number Generators <--- */
320 /* a PRNG that simply reads from an available system source */
323 /* The RC4 stream cipher based PRNG */
326 /* The ChaCha20 stream cipher based PRNG */
327 #define LTC_CHACHA20_PRNG
332 /* Greg's SOBER128 stream cipher based PRNG */
335 /* the *nix style /dev/random device */
336 #define LTC_DEVRANDOM
337 /* try /dev/urandom before trying /dev/random
338 * are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
339 #define LTC_TRY_URANDOM_FIRST
340 /* rng_get_bytes() */
341 #define LTC_RNG_GET_BYTES
342 /* rng_make_prng() */
343 #define LTC_RNG_MAKE_PRNG
345 /* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */
346 /* #define LTC_PRNG_ENABLE_LTC_RNG */
348 #endif /* LTC_NO_PRNGS */
352 /* which descriptor of AES to use? */
353 /* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
355 #define LTC_YARROW_AES 0
357 #define LTC_YARROW_AES 2
364 #if !defined(LTC_FORTUNA_RESEED_RATELIMIT_STATIC) && \
365 ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || defined(_WIN32))
367 /* time-based rate limit of the reseeding */
368 #define LTC_FORTUNA_RESEED_RATELIMIT_TIMED
370 /* with non-glibc or glibc 2.17+ prefer clock_gettime over gettimeofday */
371 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
372 #if __GLIBC_PREREQ(2, 17)
373 #define LTC_CLOCK_GETTIME
375 #elif defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
376 #define LTC_CLOCK_GETTIME
381 #ifndef LTC_FORTUNA_WD
382 /* reseed every N calls to the read function */
383 #define LTC_FORTUNA_WD 10
386 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
387 /* make sure only one of
388 * LTC_FORTUNA_RESEED_RATELIMIT_STATIC
390 * LTC_FORTUNA_RESEED_RATELIMIT_TIMED
393 #undef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
394 #warning "undef'ed LTC_FORTUNA_RESEED_RATELIMIT_TIMED, looks like your architecture doesn't support it"
399 #ifndef LTC_FORTUNA_POOLS
400 /* number of pools (4..32) can save a bit of ram by lowering the count */
401 #define LTC_FORTUNA_POOLS 32
404 #endif /* LTC_FORTUNA */
407 /* ---> Public Key Crypto <--- */
410 /* Include RSA support */
413 /* Include Diffie-Hellman support */
414 /* is_prime fails for GMP */
416 /* Supported Key Sizes */
422 #if defined(LTM_DESC) || defined(GMP_DESC)
423 /* tfm has a problem in fp_isprime for larger key sizes */
430 /* Digital Signature Algorithm */
433 /* Ed25519 & X25519 */
434 #define LTC_CURVE25519
439 /* use Shamir's trick for point mul (speeds up signature verification) */
440 #define LTC_ECC_SHAMIR
442 #if defined(TFM_DESC) && defined(LTC_MECC)
443 #define LTC_MECC_ACCEL
446 /* do we want fixed point ECC */
447 /* #define LTC_MECC_FP */
449 #endif /* LTC_NO_PK */
451 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
452 /* Enable RSA blinding when doing private key operations by default */
453 #define LTC_RSA_BLINDING
454 #endif /* LTC_NO_RSA_BLINDING */
456 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_CRT_HARDENING)
457 /* Enable RSA CRT hardening when doing private key operations by default */
458 #define LTC_RSA_CRT_HARDENING
459 #endif /* LTC_NO_RSA_CRT_HARDENING */
461 #if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
462 /* Enable ECC timing resistant version by default */
463 #define LTC_ECC_TIMING_RESISTANT
466 /* PKCS #1 (RSA) and #5 (Password Handling) stuff */
474 /* Include ASN.1 DER (required by DSA/RSA) */
477 #endif /* LTC_NO_PKCS */
482 /* Various tidbits of modern neatoness */
484 /* ... and it's URL safe version */
485 #define LTC_BASE64_URL
486 /* Base32 encoding/decoding */
488 /* Base16/hex encoding/decoding */
493 #ifndef LTC_BCRYPT_DEFAULT_ROUNDS
494 #define LTC_BCRYPT_DEFAULT_ROUNDS 10
497 /* Keep LTC_NO_HKDF for compatibility reasons
498 * superseeded by LTC_NO_MISC*/
500 /* HKDF Key Derivation/Expansion stuff */
502 #endif /* LTC_NO_HKDF */
514 #endif /* LTC_NO_MISC */
519 /* Supported ECC Key Sizes */
520 #ifndef LTC_NO_CURVES
521 #define LTC_ECC_BRAINPOOLP160R1
522 #define LTC_ECC_BRAINPOOLP160T1
523 #define LTC_ECC_BRAINPOOLP192R1
524 #define LTC_ECC_BRAINPOOLP192T1
525 #define LTC_ECC_BRAINPOOLP224R1
526 #define LTC_ECC_BRAINPOOLP224T1
527 #define LTC_ECC_BRAINPOOLP256R1
528 #define LTC_ECC_BRAINPOOLP256T1
529 #define LTC_ECC_BRAINPOOLP320R1
530 #define LTC_ECC_BRAINPOOLP320T1
531 #define LTC_ECC_BRAINPOOLP384R1
532 #define LTC_ECC_BRAINPOOLP384T1
533 #define LTC_ECC_BRAINPOOLP512R1
534 #define LTC_ECC_BRAINPOOLP512T1
535 #define LTC_ECC_PRIME192V2
536 #define LTC_ECC_PRIME192V3
537 #define LTC_ECC_PRIME239V1
538 #define LTC_ECC_PRIME239V2
539 #define LTC_ECC_PRIME239V3
540 #define LTC_ECC_SECP112R1
541 #define LTC_ECC_SECP112R2
542 #define LTC_ECC_SECP128R1
543 #define LTC_ECC_SECP128R2
544 #define LTC_ECC_SECP160K1
545 #define LTC_ECC_SECP160R1
546 #define LTC_ECC_SECP160R2
547 #define LTC_ECC_SECP192K1
548 #define LTC_ECC_SECP192R1
549 #define LTC_ECC_SECP224K1
550 #define LTC_ECC_SECP224R1
551 #define LTC_ECC_SECP256K1
552 #define LTC_ECC_SECP256R1
553 #define LTC_ECC_SECP384R1
554 #define LTC_ECC_SECP521R1
559 #ifndef LTC_DER_MAX_RECURSION
560 /* Maximum recursion limit when processing nested ASN.1 types. */
561 #define LTC_DER_MAX_RECURSION 30
565 #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_SSH)
566 /* Include the MPI functionality? (required by the PK algorithms) */
569 #ifndef LTC_PK_MAX_RETRIES
570 /* iterations limit for retry-loops */
571 #define LTC_PK_MAX_RETRIES 20
579 #if defined(LTC_MRSA) || defined(LTC_MECC)
588 #if defined(LTC_CLEAN_STACK)
589 /* if you're sure that you want to use it, remove the line below */
590 #error LTC_CLEAN_STACK is considered as broken
593 #if defined(LTC_PBES) && !defined(LTC_PKCS_5)
594 #error LTC_PBES requires LTC_PKCS_5
597 #if defined(LTC_PBES) && !defined(LTC_PKCS_12)
598 #error LTC_PBES requires LTC_PKCS_12
601 #if defined(LTC_PKCS_5) && !defined(LTC_HMAC)
602 #error LTC_PKCS_5 requires LTC_HMAC
605 #if defined(LTC_PKCS_5) && !defined(LTC_HASH_HELPERS)
606 #error LTC_PKCS_5 requires LTC_HASH_HELPERS
609 #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL)
610 #error Pelican-MAC requires LTC_RIJNDAEL
613 #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC))
614 #error LTC_EAX_MODE requires CTR and LTC_OMAC mode
617 #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE)
618 #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined!
621 #if defined(LTC_DER) && !defined(LTC_MPI)
622 #error ASN.1 DER requires MPI functionality
625 #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC)) && !defined(LTC_DER)
626 #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
629 #if defined(LTC_BCRYPT) && !defined(LTC_BLOWFISH)
630 #error LTC_BCRYPT requires LTC_BLOWFISH
633 #if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305))
634 #error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305
637 #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA)
638 #error LTC_CHACHA20_PRNG requires LTC_CHACHA
641 #if defined(LTC_XSALSA20) && !defined(LTC_SALSA20)
642 #error LTC_XSALSA20 requires LTC_SALSA20
645 #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM)
646 #error LTC_RC4 requires LTC_RC4_STREAM
649 #if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM)
650 #error LTC_SOBER128 requires LTC_SOBER128_STREAM
653 #if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S)
654 #error LTC_BLAKE2SMAC requires LTC_BLAKE2S
657 #if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B)
658 #error LTC_BLAKE2BMAC requires LTC_BLAKE2B
661 #if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES)
662 #error LTC_SPRNG requires LTC_RNG_GET_BYTES
665 #if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
666 #error LTC_NO_MATH defined, but also a math descriptor
669 /* THREAD management */
674 #define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
675 #define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
676 #define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
677 #define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
678 #define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
679 #define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
680 #define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
684 /* default no functions */
685 #define LTC_MUTEX_GLOBAL(x)
686 #define LTC_MUTEX_PROTO(x)
687 #define LTC_MUTEX_TYPE(x)
688 #define LTC_MUTEX_INIT(x)
689 #define LTC_MUTEX_LOCK(x)
690 #define LTC_MUTEX_UNLOCK(x)
691 #define LTC_MUTEX_DESTROY(x)
697 /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
698 /* #define LTC_VALGRIND */
703 /* buffer size for reading from a file via fread(..) */
704 #ifndef LTC_FILE_READ_BUFSIZE
705 #define LTC_FILE_READ_BUFSIZE 8192
709 /* ECC backwards compatibility */
710 #if !defined(LTC_ECC_SECP112R1) && defined(LTC_ECC112)
711 #define LTC_ECC_SECP112R1
714 #if !defined(LTC_ECC_SECP128R1) && defined(LTC_ECC128)
715 #define LTC_ECC_SECP128R1
718 #if !defined(LTC_ECC_SECP160R1) && defined(LTC_ECC160)
719 #define LTC_ECC_SECP160R1
722 #if !defined(LTC_ECC_SECP192R1) && defined(LTC_ECC192)
723 #define LTC_ECC_SECP192R1
726 #if !defined(LTC_ECC_SECP224R1) && defined(LTC_ECC224)
727 #define LTC_ECC_SECP224R1
730 #if !defined(LTC_ECC_SECP256R1) && defined(LTC_ECC256)
731 #define LTC_ECC_SECP256R1
734 #if !defined(LTC_ECC_SECP384R1) && defined(LTC_ECC384)
735 #define LTC_ECC_SECP384R1
738 #if !defined(LTC_ECC_SECP512R1) && defined(LTC_ECC521)
739 #define LTC_ECC_SECP521R1
This page took 0.05952 seconds and 3 git commands to generate.