1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
10 #ifndef TOMCRYPT_CUSTOM_H_
11 #define TOMCRYPT_CUSTOM_H_
13 /* macros for various libc functions you can change for embedded targets */
15 #define XMALLOC malloc
18 #define XREALLOC realloc
21 #define XCALLOC calloc
28 #define XMEMSET memset
31 #define XMEMCPY memcpy
34 #define XMEMMOVE memmove
37 #define XMEMCMP memcmp
39 /* A memory compare function that has to run in constant time,
40 * c.f. mem_neq() API summary.
43 #define XMEM_NEQ mem_neq
46 #define XSTRCMP strcmp
57 #if ( defined(malloc) || defined(realloc) || defined(calloc) || defined(free) || \
58 defined(memset) || defined(memcpy) || defined(memcmp) || defined(strcmp) || \
59 defined(clock) || defined(qsort) ) && !defined(LTC_NO_PROTOTYPES)
60 #define LTC_NO_PROTOTYPES
63 /* shortcut to disable automatic inclusion */
64 #if defined LTC_NOTHING && !defined LTC_EASY
65 #define LTC_NO_CIPHERS
73 #endif /* LTC_NOTHING */
77 #define LTC_NO_CIPHERS
95 #define LTC_HASH_HELPERS
105 #define LTC_DEVRANDOM
106 #define LTC_TRY_URANDOM_FIRST
107 #define LTC_RNG_GET_BYTES
108 #define LTC_RNG_MAKE_PRNG
118 /* The minimal set of functionality to run the tests */
125 #define LTC_RNG_MAKE_PRNG
126 #define LTC_RNG_GET_BYTES
127 #define LTC_DEVRANDOM
128 #define LTC_TRY_URANDOM_FIRST
133 /* Enable self-test test vector checking */
137 /* Enable extended self-tests */
138 /* #define LTC_TEST_EXT */
140 /* Use small code where possible */
141 /* #define LTC_SMALL_CODE */
143 /* clean the stack of functions which put private information on stack */
144 /* #define LTC_CLEAN_STACK */
146 /* disable all file related functions */
147 /* #define LTC_NO_FILE */
149 /* disable all forms of ASM */
150 /* #define LTC_NO_ASM */
152 /* disable FAST mode */
153 /* #define LTC_NO_FAST */
155 /* disable BSWAP on x86 */
156 /* #define LTC_NO_BSWAP */
158 /* ---> math provider? <--- */
162 /* #define LTM_DESC */
165 /* #define TFM_DESC */
167 /* GNU Multiple Precision Arithmetic Library */
168 /* #define GMP_DESC */
170 #endif /* LTC_NO_MATH */
172 /* ---> Symmetric Block Ciphers <--- */
173 #ifndef LTC_NO_CIPHERS
182 /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
183 * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
185 #ifndef LTC_NO_TABLES
186 #define LTC_TWOFISH_TABLES
187 /* #define LTC_TWOFISH_ALL_TABLES */
189 #define LTC_TWOFISH_SMALL
191 /* #define LTC_TWOFISH_SMALL */
192 /* LTC_DES includes EDE triple-DES */
200 #define LTC_ANUBIS_TWEAK
208 #define LTC_RC4_STREAM
209 #define LTC_SOBER128_STREAM
211 #endif /* LTC_NO_CIPHERS */
214 /* ---> Block Cipher Modes of Operation <--- */
223 /* F8 chaining mode */
228 #ifndef LTC_NO_TABLES
229 /* like GCM mode this will enable 16 8x128 tables [64KB] that make
232 #define LTC_LRW_TABLES
238 #endif /* LTC_NO_MODES */
240 /* ---> One-Way Hash Functions <--- */
241 #ifndef LTC_NO_HASHES
244 #define LTC_WHIRLPOOL
247 #define LTC_SHA512_256
248 #define LTC_SHA512_224
257 #define LTC_RIPEMD128
258 #define LTC_RIPEMD160
259 #define LTC_RIPEMD256
260 #define LTC_RIPEMD320
264 #define LTC_HASH_HELPERS
266 #endif /* LTC_NO_HASHES */
269 /* ---> MAC functions <--- */
279 #define LTC_BLAKE2SMAC
280 #define LTC_BLAKE2BMAC
282 /* ---> Encrypt + Authenticate Modes <--- */
287 #define LTC_OCB3_MODE
290 #define LTC_CHACHA20POLY1305_MODE
292 /* Use 64KiB tables */
293 #ifndef LTC_NO_TABLES
294 #define LTC_GCM_TABLES
297 /* USE SSE2? requires GCC works on x86_32 and x86_64*/
298 #ifdef LTC_GCM_TABLES
299 /* #define LTC_GCM_TABLES_SSE2 */
302 #endif /* LTC_NO_MACS */
305 /* --> Pseudo Random Number Generators <--- */
311 /* a PRNG that simply reads from an available system source */
314 /* The RC4 stream cipher based PRNG */
317 /* The ChaCha20 stream cipher based PRNG */
318 #define LTC_CHACHA20_PRNG
323 /* Greg's SOBER128 stream cipher based PRNG */
326 /* the *nix style /dev/random device */
327 #define LTC_DEVRANDOM
328 /* try /dev/urandom before trying /dev/random
329 * are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
330 #define LTC_TRY_URANDOM_FIRST
331 /* rng_get_bytes() */
332 #define LTC_RNG_GET_BYTES
333 /* rng_make_prng() */
334 #define LTC_RNG_MAKE_PRNG
336 /* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */
337 /* #define LTC_PRNG_ENABLE_LTC_RNG */
339 #endif /* LTC_NO_PRNGS */
343 /* which descriptor of AES to use? */
344 /* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
346 #define LTC_YARROW_AES 0
348 #define LTC_YARROW_AES 2
355 #ifndef LTC_FORTUNA_WD
356 /* reseed every N calls to the read function */
357 #define LTC_FORTUNA_WD 10
360 #ifndef LTC_FORTUNA_POOLS
361 /* number of pools (4..32) can save a bit of ram by lowering the count */
362 #define LTC_FORTUNA_POOLS 32
365 #endif /* LTC_FORTUNA */
368 /* ---> Public Key Crypto <--- */
371 /* Include RSA support */
374 /* Include Diffie-Hellman support */
375 /* is_prime fails for GMP */
377 /* Supported Key Sizes */
384 /* tfm has a problem in fp_isprime for larger key sizes */
391 /* Include Katja (a Rabin variant like RSA) */
392 /* #define LTC_MKAT */
394 /* Digital Signature Algorithm */
400 /* use Shamir's trick for point mul (speeds up signature verification) */
401 #define LTC_ECC_SHAMIR
403 #if defined(TFM_DESC) && defined(LTC_MECC)
404 #define LTC_MECC_ACCEL
407 /* do we want fixed point ECC */
408 /* #define LTC_MECC_FP */
410 #endif /* LTC_NO_PK */
412 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
413 /* Enable RSA blinding when doing private key operations by default */
414 #define LTC_RSA_BLINDING
415 #endif /* LTC_NO_RSA_BLINDING */
417 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_CRT_HARDENING)
418 /* Enable RSA CRT hardening when doing private key operations by default */
419 #define LTC_RSA_CRT_HARDENING
420 #endif /* LTC_NO_RSA_CRT_HARDENING */
422 #if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
423 /* Enable ECC timing resistant version by default */
424 #define LTC_ECC_TIMING_RESISTANT
427 /* PKCS #1 (RSA) and #5 (Password Handling) stuff */
433 /* Include ASN.1 DER (required by DSA/RSA) */
436 #endif /* LTC_NO_PKCS */
441 /* Various tidbits of modern neatoness */
443 /* ... and it's URL safe version */
444 #define LTC_BASE64_URL
446 /* Keep LTC_NO_HKDF for compatibility reasons
447 * superseeded by LTC_NO_MISC*/
449 /* HKDF Key Derivation/Expansion stuff */
451 #endif /* LTC_NO_HKDF */
457 #endif /* LTC_NO_MISC */
462 /* Supported ECC Key Sizes */
463 #ifndef LTC_NO_CURVES
476 #ifndef LTC_DER_MAX_RECURSION
477 /* Maximum recursion limit when processing nested ASN.1 types. */
478 #define LTC_DER_MAX_RECURSION 30
482 #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT)
483 /* Include the MPI functionality? (required by the PK algorithms) */
486 #ifndef LTC_PK_MAX_RETRIES
487 /* iterations limit for retry-loops */
488 #define LTC_PK_MAX_RETRIES 20
496 #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL)
497 #error Pelican-MAC requires LTC_RIJNDAEL
500 #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC))
501 #error LTC_EAX_MODE requires CTR and LTC_OMAC mode
504 #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE)
505 #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined!
508 #if defined(LTC_DER) && !defined(LTC_MPI)
509 #error ASN.1 DER requires MPI functionality
512 #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC) || defined(LTC_MKAT)) && !defined(LTC_DER)
513 #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
516 #if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305))
517 #error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305
520 #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA)
521 #error LTC_CHACHA20_PRNG requires LTC_CHACHA
524 #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM)
525 #error LTC_RC4 requires LTC_RC4_STREAM
528 #if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM)
529 #error LTC_SOBER128 requires LTC_SOBER128_STREAM
532 #if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S)
533 #error LTC_BLAKE2SMAC requires LTC_BLAKE2S
536 #if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B)
537 #error LTC_BLAKE2BMAC requires LTC_BLAKE2B
540 #if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES)
541 #error LTC_SPRNG requires LTC_RNG_GET_BYTES
544 #if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
545 #error LTC_NO_MATH defined, but also a math descriptor
548 /* THREAD management */
553 #define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
554 #define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
555 #define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
556 #define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
557 #define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0);
558 #define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
559 #define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
563 /* default no functions */
564 #define LTC_MUTEX_GLOBAL(x)
565 #define LTC_MUTEX_PROTO(x)
566 #define LTC_MUTEX_TYPE(x)
567 #define LTC_MUTEX_INIT(x)
568 #define LTC_MUTEX_LOCK(x)
569 #define LTC_MUTEX_UNLOCK(x)
570 #define LTC_MUTEX_DESTROY(x)
576 /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
577 /* #define LTC_VALGRIND */
582 /* buffer size for reading from a file via fread(..) */
583 #ifndef LTC_FILE_READ_BUFSIZE
584 #define LTC_FILE_READ_BUFSIZE 8192
588 /* ref: $Format:%D$ */
589 /* git commit: $Format:%H$ */
590 /* commit time: $Format:%ai$ */