1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 
4 #ifndef TOMCRYPT_CUSTOM_H_
5 #define TOMCRYPT_CUSTOM_H_
6 
7 /* macros for various libc functions you can change for embedded targets */
8 #ifndef XMALLOC
9 #define XMALLOC  malloc
10 #endif
11 #ifndef XREALLOC
12 #define XREALLOC realloc
13 #endif
14 #ifndef XCALLOC
15 #define XCALLOC  calloc
16 #endif
17 #ifndef XFREE
18 #define XFREE    free
19 #endif
20 
21 #ifndef XMEMSET
22 #define XMEMSET  memset
23 #endif
24 #ifndef XMEMCPY
25 #define XMEMCPY  memcpy
26 #endif
27 #ifndef XMEMMOVE
28 #define XMEMMOVE memmove
29 #endif
30 #ifndef XMEMCMP
31 #define XMEMCMP  memcmp
32 #endif
33 /* A memory compare function that has to run in constant time,
34  * c.f. mem_neq() API summary.
35  */
36 #ifndef XMEM_NEQ
37 #define XMEM_NEQ  mem_neq
38 #endif
39 #ifndef XSTRCMP
40 #define XSTRCMP  strcmp
41 #endif
42 #ifndef XSTRLEN
43 #define XSTRLEN  strlen
44 #endif
45 #ifndef XSTRNCPY
46 #define XSTRNCPY strncpy
47 #endif
48 
49 #ifndef XCLOCK
50 #define XCLOCK   clock
51 #endif
52 
53 #ifndef XQSORT
54 #define XQSORT qsort
55 #endif
56 
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
62 #endif
63 
64 /* shortcut to disable automatic inclusion */
65 #if defined LTC_NOTHING && !defined LTC_EASY
66   #define LTC_NO_CIPHERS
67   #define LTC_NO_MODES
68   #define LTC_NO_HASHES
69   #define LTC_NO_MACS
70   #define LTC_NO_PRNGS
71   #define LTC_NO_PK
72   #define LTC_NO_PKCS
73   #define LTC_NO_MISC
74 #endif /* LTC_NOTHING */
75 
76 /* Easy button? */
77 #ifdef LTC_EASY
78    #define LTC_NO_CIPHERS
79    #define LTC_RIJNDAEL
80    #define LTC_BLOWFISH
81    #define LTC_DES
82    #define LTC_CAST5
83 
84    #define LTC_NO_MODES
85    #define LTC_ECB_MODE
86    #define LTC_CBC_MODE
87    #define LTC_CTR_MODE
88 
89    #define LTC_NO_HASHES
90    #define LTC_SHA1
91    #define LTC_SHA3
92    #define LTC_SHA512
93    #define LTC_SHA384
94    #define LTC_SHA256
95    #define LTC_SHA224
96    #define LTC_HASH_HELPERS
97 
98    #define LTC_NO_MACS
99    #define LTC_HMAC
100    #define LTC_OMAC
101    #define LTC_CCM_MODE
102 
103    #define LTC_NO_PRNGS
104    #define LTC_SPRNG
105    #define LTC_YARROW
106    #define LTC_DEVRANDOM
107    #define LTC_TRY_URANDOM_FIRST
108    #define LTC_RNG_GET_BYTES
109    #define LTC_RNG_MAKE_PRNG
110 
111    #define LTC_NO_PK
112    #define LTC_MRSA
113    #define LTC_MECC
114 
115    #define LTC_NO_MISC
116    #define LTC_BASE64
117 #endif /* LTC_EASY */
118 
119 /* The minimal set of functionality to run the tests */
120 #ifdef LTC_MINIMAL
121    #define LTC_RIJNDAEL
122    #define LTC_SHA256
123    #define LTC_YARROW
124    #define LTC_CTR_MODE
125 
126    #define LTC_RNG_MAKE_PRNG
127    #define LTC_RNG_GET_BYTES
128    #define LTC_DEVRANDOM
129    #define LTC_TRY_URANDOM_FIRST
130 
131    #undef LTC_NO_FILE
132 #endif /* LTC_MINIMAL */
133 
134 /* Enable self-test test vector checking */
135 #ifndef LTC_NO_TEST
136    #define LTC_TEST
137 #endif
138 /* Enable extended self-tests */
139 /* #define LTC_TEST_EXT */
140 
141 /* Use small code where possible */
142 /* #define LTC_SMALL_CODE */
143 
144 /* clean the stack of functions which put private information on stack */
145 /* #define LTC_CLEAN_STACK */
146 
147 /* disable all file related functions */
148 /* #define LTC_NO_FILE */
149 
150 /* disable all forms of ASM */
151 /* #define LTC_NO_ASM */
152 
153 /* disable FAST mode */
154 /* #define LTC_NO_FAST */
155 
156 /* disable BSWAP on x86 */
157 /* #define LTC_NO_BSWAP */
158 
159 /* ---> math provider? <--- */
160 #ifndef LTC_NO_MATH
161 
162 /* LibTomMath */
163 /* #define LTM_DESC */
164 
165 /* TomsFastMath */
166 /* #define TFM_DESC */
167 
168 /* GNU Multiple Precision Arithmetic Library */
169 /* #define GMP_DESC */
170 
171 #endif /* LTC_NO_MATH */
172 
173 /* ---> Symmetric Block Ciphers <--- */
174 #ifndef LTC_NO_CIPHERS
175 
176 #define LTC_BLOWFISH
177 #define LTC_RC2
178 #define LTC_RC5
179 #define LTC_RC6
180 #define LTC_SAFERP
181 #define LTC_RIJNDAEL
182 #ifndef LTC_NO_AES_NI
183    #define LTC_AES_NI
184 #endif
185 #define LTC_XTEA
186 /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
187  * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
188 #define LTC_TWOFISH
189 #ifndef LTC_NO_TABLES
190    #define LTC_TWOFISH_TABLES
191    /* #define LTC_TWOFISH_ALL_TABLES */
192 #else
193    #define LTC_TWOFISH_SMALL
194 #endif
195 /* #define LTC_TWOFISH_SMALL */
196 /* LTC_DES includes EDE triple-DES */
197 #define LTC_DES
198 #define LTC_CAST5
199 #define LTC_NOEKEON
200 #define LTC_SKIPJACK
201 #define LTC_SAFER
202 #define LTC_KHAZAD
203 #define LTC_ANUBIS
204 #define LTC_ANUBIS_TWEAK
205 #define LTC_KSEED
206 #define LTC_KASUMI
207 #define LTC_MULTI2
208 #define LTC_CAMELLIA
209 #define LTC_IDEA
210 #define LTC_SERPENT
211 #define LTC_TEA
212 
213 /* stream ciphers */
214 #define LTC_CHACHA
215 #define LTC_SALSA20
216 #define LTC_XSALSA20
217 #define LTC_SOSEMANUK
218 #define LTC_RABBIT
219 #define LTC_RC4_STREAM
220 #define LTC_SOBER128_STREAM
221 
222 #endif /* LTC_NO_CIPHERS */
223 
224 
225 /* ---> Block Cipher Modes of Operation <--- */
226 #ifndef LTC_NO_MODES
227 
228 #define LTC_CFB_MODE
229 #define LTC_OFB_MODE
230 #define LTC_ECB_MODE
231 #define LTC_CBC_MODE
232 #define LTC_CTR_MODE
233 
234 /* F8 chaining mode */
235 #define LTC_F8_MODE
236 
237 /* LRW mode */
238 #define LTC_LRW_MODE
239 #ifndef LTC_NO_TABLES
240    /* like GCM mode this will enable 16 8x128 tables [64KB] that make
241     * seeking very fast.
242     */
243    #define LTC_LRW_TABLES
244 #endif
245 
246 /* XTS mode */
247 #define LTC_XTS_MODE
248 
249 #endif /* LTC_NO_MODES */
250 
251 /* ---> One-Way Hash Functions <--- */
252 #ifndef LTC_NO_HASHES
253 
254 #define LTC_CHC_HASH
255 #define LTC_WHIRLPOOL
256 #define LTC_SHA3
257 #define LTC_KECCAK
258 #define LTC_SHA512
259 #define LTC_SHA512_256
260 #define LTC_SHA512_224
261 #define LTC_SHA384
262 #define LTC_SHA256
263 #define LTC_SHA224
264 #define LTC_TIGER
265 #define LTC_SHA1
266 #define LTC_MD5
267 #define LTC_MD4
268 #define LTC_MD2
269 #define LTC_RIPEMD128
270 #define LTC_RIPEMD160
271 #define LTC_RIPEMD256
272 #define LTC_RIPEMD320
273 #define LTC_BLAKE2S
274 #define LTC_BLAKE2B
275 
276 #define LTC_HASH_HELPERS
277 
278 #endif /* LTC_NO_HASHES */
279 
280 
281 /* ---> MAC functions <--- */
282 #ifndef LTC_NO_MACS
283 
284 #define LTC_HMAC
285 #define LTC_OMAC
286 #define LTC_PMAC
287 #define LTC_XCBC
288 #define LTC_F9_MODE
289 #define LTC_PELICAN
290 #define LTC_POLY1305
291 #define LTC_BLAKE2SMAC
292 #define LTC_BLAKE2BMAC
293 
294 /* ---> Encrypt + Authenticate Modes <--- */
295 
296 #define LTC_EAX_MODE
297 
298 #define LTC_OCB_MODE
299 #define LTC_OCB3_MODE
300 #define LTC_CCM_MODE
301 #define LTC_GCM_MODE
302 #define LTC_CHACHA20POLY1305_MODE
303 
304 /* Use 64KiB tables */
305 #ifndef LTC_NO_TABLES
306    #define LTC_GCM_TABLES
307 #endif
308 
309 /* USE SSE2? requires GCC works on x86_32 and x86_64*/
310 #ifdef LTC_GCM_TABLES
311 /* #define LTC_GCM_TABLES_SSE2 */
312 #endif
313 
314 #endif /* LTC_NO_MACS */
315 
316 
317 /* --> Pseudo Random Number Generators <--- */
318 #ifndef LTC_NO_PRNGS
319 
320 /* Yarrow */
321 #define LTC_YARROW
322 
323 /* a PRNG that simply reads from an available system source */
324 #define LTC_SPRNG
325 
326 /* The RC4 stream cipher based PRNG */
327 #define LTC_RC4
328 
329 /* The ChaCha20 stream cipher based PRNG */
330 #define LTC_CHACHA20_PRNG
331 
332 /* Fortuna PRNG */
333 #define LTC_FORTUNA
334 
335 /* Greg's SOBER128 stream cipher based PRNG */
336 #define LTC_SOBER128
337 
338 #if !defined(_WIN32) && !defined(_WIN32_WCE)
339 /* the *nix style /dev/random device */
340 #define LTC_DEVRANDOM
341 /* try /dev/urandom before trying /dev/random
342  * are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
343 #define LTC_TRY_URANDOM_FIRST
344 #endif /* not Windows */
345 
346 /* rng_get_bytes() */
347 #define LTC_RNG_GET_BYTES
348 /* rng_make_prng() */
349 #define LTC_RNG_MAKE_PRNG
350 
351 /* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */
352 /* #define LTC_PRNG_ENABLE_LTC_RNG */
353 
354 #endif /* LTC_NO_PRNGS */
355 
356 #ifdef LTC_YARROW
357 
358 /* which descriptor of AES to use?  */
359 /* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
360 #ifdef ENCRYPT_ONLY
361   #define LTC_YARROW_AES 0
362 #else
363   #define LTC_YARROW_AES 2
364 #endif
365 
366 #endif /* LTC_YARROW */
367 
368 #ifdef LTC_FORTUNA
369 
370 #if !defined(LTC_FORTUNA_RESEED_RATELIMIT_STATIC) && \
371       ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || defined(_WIN32))
372 
373 /* time-based rate limit of the reseeding */
374 #define LTC_FORTUNA_RESEED_RATELIMIT_TIMED
375 
376 /* with non-glibc or glibc 2.17+ prefer clock_gettime over gettimeofday */
377 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
378    #if __GLIBC_PREREQ(2, 17)
379       #define LTC_CLOCK_GETTIME
380    #endif
381 #elif defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
382   #define LTC_CLOCK_GETTIME
383 #endif
384 
385 #else
386 
387 #ifndef LTC_FORTUNA_WD
388 /* reseed every N calls to the read function */
389 #define LTC_FORTUNA_WD    10
390 #endif
391 
392 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
393 /* make sure only one of
394  *   LTC_FORTUNA_RESEED_RATELIMIT_STATIC
395  * and
396  *   LTC_FORTUNA_RESEED_RATELIMIT_TIMED
397  * is defined.
398  */
399 #undef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
400 #warning "undef'ed LTC_FORTUNA_RESEED_RATELIMIT_TIMED, looks like your architecture doesn't support it"
401 #endif
402 
403 #endif
404 
405 #ifndef LTC_FORTUNA_POOLS
406 /* number of pools (4..32) can save a bit of ram by lowering the count */
407 #define LTC_FORTUNA_POOLS 32
408 #endif
409 
410 /* at compile time you can decide whether fortuna uses the regular AES APIs
411  * or whether it will use the 'encrypt_only' variants.
412  * This is useful for custom builds of libtomcrypt for size-constrained targets. */
413 /* #define LTC_FORTUNA_USE_ENCRYPT_ONLY */
414 
415 #endif /* LTC_FORTUNA */
416 
417 
418 /* ---> Public Key Crypto <--- */
419 #ifndef LTC_NO_PK
420 
421 /* Include RSA support */
422 #define LTC_MRSA
423 
424 /* Include Diffie-Hellman support */
425 /* is_prime fails for GMP */
426 #define LTC_MDH
427 /* Supported Key Sizes */
428 #define LTC_DH768
429 #define LTC_DH1024
430 #define LTC_DH1536
431 #define LTC_DH2048
432 
433 #if defined(LTM_DESC) || defined(GMP_DESC)
434 /* tfm has a problem in fp_isprime for larger key sizes */
435 #define LTC_DH3072
436 #define LTC_DH4096
437 #define LTC_DH6144
438 #define LTC_DH8192
439 #endif
440 
441 /* Digital Signature Algorithm */
442 #define LTC_MDSA
443 
444 /* Ed25519 & X25519 */
445 #define LTC_CURVE25519
446 
447 /* ECC */
448 #define LTC_MECC
449 
450 /* use Shamir's trick for point mul (speeds up signature verification) */
451 #define LTC_ECC_SHAMIR
452 
453 #if defined(TFM_DESC) && defined(LTC_MECC)
454    #define LTC_MECC_ACCEL
455 #endif
456 
457 /* do we want fixed point ECC */
458 /* #define LTC_MECC_FP */
459 
460 #endif /* LTC_NO_PK */
461 
462 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
463 /* Enable RSA blinding when doing private key operations by default */
464 #define LTC_RSA_BLINDING
465 #endif  /* LTC_NO_RSA_BLINDING */
466 
467 #if defined(LTC_MRSA) && !defined(LTC_NO_RSA_CRT_HARDENING)
468 /* Enable RSA CRT hardening when doing private key operations by default */
469 #define LTC_RSA_CRT_HARDENING
470 #endif  /* LTC_NO_RSA_CRT_HARDENING */
471 
472 #if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
473 /* Enable ECC timing resistant version by default */
474 #define LTC_ECC_TIMING_RESISTANT
475 #endif
476 
477 /* PKCS #1 (RSA) and #5 (Password Handling) stuff */
478 #ifndef LTC_NO_PKCS
479 
480 #define LTC_PKCS_1
481 #define LTC_PKCS_5
482 #define LTC_PKCS_8
483 #define LTC_PKCS_12
484 
485 /* Include ASN.1 DER (required by DSA/RSA) */
486 #define LTC_DER
487 
488 #define LTC_MPI
489 
490 #endif /* LTC_NO_PKCS */
491 
492 /* misc stuff */
493 #ifndef LTC_NO_MISC
494 
495 /* Various tidbits of modern neatoness */
496 #define LTC_BASE64
497 /* ... and it's URL safe version */
498 #define LTC_BASE64_URL
499 /* Base32 encoding/decoding */
500 #define LTC_BASE32
501 /* Base16/hex encoding/decoding */
502 #define LTC_BASE16
503 
504 #define LTC_BCRYPT
505 
506 #ifndef LTC_BCRYPT_DEFAULT_ROUNDS
507 #define LTC_BCRYPT_DEFAULT_ROUNDS 10
508 #endif
509 
510 /* Keep LTC_NO_HKDF for compatibility reasons
511  * superseeded by LTC_NO_MISC*/
512 #ifndef LTC_NO_HKDF
513 /* HKDF Key Derivation/Expansion stuff */
514 #define LTC_HKDF
515 #endif /* LTC_NO_HKDF */
516 
517 #define LTC_ADLER32
518 
519 #define LTC_CRC32
520 
521 #define LTC_SSH
522 
523 #define LTC_PADDING
524 
525 #define LTC_PBES
526 
527 #endif /* LTC_NO_MISC */
528 
529 /* cleanup */
530 
531 #ifdef LTC_MECC
532 /* Supported ECC Key Sizes */
533 #ifndef LTC_NO_CURVES
534    #define LTC_ECC_BRAINPOOLP160R1
535    #define LTC_ECC_BRAINPOOLP160T1
536    #define LTC_ECC_BRAINPOOLP192R1
537    #define LTC_ECC_BRAINPOOLP192T1
538    #define LTC_ECC_BRAINPOOLP224R1
539    #define LTC_ECC_BRAINPOOLP224T1
540    #define LTC_ECC_BRAINPOOLP256R1
541    #define LTC_ECC_BRAINPOOLP256T1
542    #define LTC_ECC_BRAINPOOLP320R1
543    #define LTC_ECC_BRAINPOOLP320T1
544    #define LTC_ECC_BRAINPOOLP384R1
545    #define LTC_ECC_BRAINPOOLP384T1
546    #define LTC_ECC_BRAINPOOLP512R1
547    #define LTC_ECC_BRAINPOOLP512T1
548    #define LTC_ECC_PRIME192V2
549    #define LTC_ECC_PRIME192V3
550    #define LTC_ECC_PRIME239V1
551    #define LTC_ECC_PRIME239V2
552    #define LTC_ECC_PRIME239V3
553    #define LTC_ECC_SECP112R1
554    #define LTC_ECC_SECP112R2
555    #define LTC_ECC_SECP128R1
556    #define LTC_ECC_SECP128R2
557    #define LTC_ECC_SECP160K1
558    #define LTC_ECC_SECP160R1
559    #define LTC_ECC_SECP160R2
560    #define LTC_ECC_SECP192K1
561    #define LTC_ECC_SECP192R1
562    #define LTC_ECC_SECP224K1
563    #define LTC_ECC_SECP224R1
564    #define LTC_ECC_SECP256K1
565    #define LTC_ECC_SECP256R1
566    #define LTC_ECC_SECP384R1
567    #define LTC_ECC_SECP521R1
568 #endif
569 #endif /* LTC_MECC */
570 
571 #if defined(LTC_DER)
572    #ifndef LTC_DER_MAX_RECURSION
573       /* Maximum recursion limit when processing nested ASN.1 types. */
574       #define LTC_DER_MAX_RECURSION 30
575    #endif
576 #endif
577 
578 #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_SSH)
579    #ifndef LTC_PK_MAX_RETRIES
580       /* iterations limit for retry-loops */
581       #define LTC_PK_MAX_RETRIES  20
582    #endif
583 #endif
584 
585 #ifdef LTC_MRSA
586    #define LTC_PKCS_1
587 #endif
588 
589 #if defined(LTC_MRSA) || defined(LTC_MECC)
590    #define LTC_PKCS_8
591 #endif
592 
593 #ifdef LTC_PKCS_8
594    #define LTC_PADDING
595    #define LTC_PBES
596 #endif
597 
598 #if defined(LTC_CLEAN_STACK)
599 /* if you're sure that you want to use it, remove the line below */
600    #error LTC_CLEAN_STACK is considered as broken
601 #endif
602 
603 #if defined(LTC_PBES) && !defined(LTC_PKCS_5)
604    #error LTC_PBES requires LTC_PKCS_5
605 #endif
606 
607 #if defined(LTC_PBES) && !defined(LTC_PKCS_12)
608    #error LTC_PBES requires LTC_PKCS_12
609 #endif
610 
611 #if defined(LTC_PKCS_5) && !defined(LTC_HMAC)
612    #error LTC_PKCS_5 requires LTC_HMAC
613 #endif
614 
615 #if defined(LTC_PKCS_5) && !defined(LTC_HASH_HELPERS)
616    #error LTC_PKCS_5 requires LTC_HASH_HELPERS
617 #endif
618 
619 #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL)
620    #error Pelican-MAC requires LTC_RIJNDAEL
621 #endif
622 
623 #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC))
624    #error LTC_EAX_MODE requires CTR and LTC_OMAC mode
625 #endif
626 
627 #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE)
628    #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined!
629 #endif
630 
631 #if defined(LTC_DER) && !defined(LTC_MPI)
632    #error ASN.1 DER requires MPI functionality
633 #endif
634 
635 #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC)) && !defined(LTC_DER)
636    #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
637 #endif
638 
639 #if defined(LTC_BCRYPT) && !defined(LTC_BLOWFISH)
640    #error LTC_BCRYPT requires LTC_BLOWFISH
641 #endif
642 
643 #if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305))
644    #error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305
645 #endif
646 
647 #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA)
648    #error LTC_CHACHA20_PRNG requires LTC_CHACHA
649 #endif
650 
651 #if defined(LTC_XSALSA20) && !defined(LTC_SALSA20)
652    #error LTC_XSALSA20 requires LTC_SALSA20
653 #endif
654 
655 #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM)
656    #error LTC_RC4 requires LTC_RC4_STREAM
657 #endif
658 
659 #if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM)
660    #error LTC_SOBER128 requires LTC_SOBER128_STREAM
661 #endif
662 
663 #if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S)
664    #error LTC_BLAKE2SMAC requires LTC_BLAKE2S
665 #endif
666 
667 #if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B)
668    #error LTC_BLAKE2BMAC requires LTC_BLAKE2B
669 #endif
670 
671 #if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES)
672    #error LTC_SPRNG requires LTC_RNG_GET_BYTES
673 #endif
674 
675 #if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC))
676    #error LTC_NO_MATH defined, but also a math descriptor
677 #endif
678 
679 /* THREAD management */
680 #if defined(_CFG_CORE_LTC_OPTEE_THREAD)
681 
682 #include <kernel/mutex.h>
683 
684 #define LTC_MUTEX_GLOBAL(x)   struct mutex x = MUTEX_INITIALIZER;
685 #define LTC_MUTEX_PROTO(x)    extern struct mutex x;
686 #define LTC_MUTEX_TYPE(x)     struct mutex x;
687 #define LTC_MUTEX_INIT(x)     mutex_init(x);
688 #define LTC_MUTEX_LOCK(x)     mutex_lock(x);
689 #define LTC_MUTEX_UNLOCK(x)   mutex_unlock(x);
690 
691 #elif defined(LTC_PTHREAD)
692 
693 #include <pthread.h>
694 
695 #define LTC_MUTEX_GLOBAL(x)   pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
696 #define LTC_MUTEX_PROTO(x)    extern pthread_mutex_t x;
697 #define LTC_MUTEX_TYPE(x)     pthread_mutex_t x;
698 #define LTC_MUTEX_INIT(x)     LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0);
699 #define LTC_MUTEX_LOCK(x)     LTC_ARGCHK(pthread_mutex_lock(x) == 0);
700 #define LTC_MUTEX_UNLOCK(x)   LTC_ARGCHK(pthread_mutex_unlock(x) == 0);
701 #define LTC_MUTEX_DESTROY(x)  LTC_ARGCHK(pthread_mutex_destroy(x) == 0);
702 
703 #else
704 
705 /* default no functions */
706 #define LTC_MUTEX_GLOBAL(x)
707 #define LTC_MUTEX_PROTO(x)
708 #define LTC_MUTEX_TYPE(x)
709 #define LTC_MUTEX_INIT(x)
710 #define LTC_MUTEX_LOCK(x)
711 #define LTC_MUTEX_UNLOCK(x)
712 #define LTC_MUTEX_DESTROY(x)
713 
714 #endif /* LTC_PTHREAD */
715 
716 /* Debuggers */
717 
718 /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
719 /* #define LTC_VALGRIND */
720 
721 #ifndef LTC_NO_FILE
722    /* buffer size for reading from a file via fread(..) */
723    #ifndef LTC_FILE_READ_BUFSIZE
724    #define LTC_FILE_READ_BUFSIZE 8192
725    #endif
726 #endif
727 
728 /* ECC backwards compatibility */
729 #if !defined(LTC_ECC_SECP112R1) && defined(LTC_ECC112)
730 #define LTC_ECC_SECP112R1
731 #undef LTC_ECC112
732 #endif
733 #if !defined(LTC_ECC_SECP128R1) && defined(LTC_ECC128)
734 #define LTC_ECC_SECP128R1
735 #undef LTC_ECC128
736 #endif
737 #if !defined(LTC_ECC_SECP160R1) && defined(LTC_ECC160)
738 #define LTC_ECC_SECP160R1
739 #undef LTC_ECC160
740 #endif
741 #if !defined(LTC_ECC_SECP192R1) && defined(LTC_ECC192)
742 #define LTC_ECC_SECP192R1
743 #undef LTC_ECC192
744 #endif
745 #if !defined(LTC_ECC_SECP224R1) && defined(LTC_ECC224)
746 #define LTC_ECC_SECP224R1
747 #undef LTC_ECC224
748 #endif
749 #if !defined(LTC_ECC_SECP256R1) && defined(LTC_ECC256)
750 #define LTC_ECC_SECP256R1
751 #undef LTC_ECC256
752 #endif
753 #if !defined(LTC_ECC_SECP384R1) && defined(LTC_ECC384)
754 #define LTC_ECC_SECP384R1
755 #undef LTC_ECC384
756 #endif
757 #if !defined(LTC_ECC_SECP512R1) && defined(LTC_ECC521)
758 #define LTC_ECC_SECP521R1
759 #undef LTC_ECC521
760 #endif
761 
762 #endif /* TOMCRYPT_CUSTOM_H_ */
763