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 #define LTC_XTEA 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 */ 185 #define LTC_TWOFISH 186 #ifndef LTC_NO_TABLES 187 #define LTC_TWOFISH_TABLES 188 /* #define LTC_TWOFISH_ALL_TABLES */ 189 #else 190 #define LTC_TWOFISH_SMALL 191 #endif 192 /* #define LTC_TWOFISH_SMALL */ 193 /* LTC_DES includes EDE triple-DES */ 194 #define LTC_DES 195 #define LTC_CAST5 196 #define LTC_NOEKEON 197 #define LTC_SKIPJACK 198 #define LTC_SAFER 199 #define LTC_KHAZAD 200 #define LTC_ANUBIS 201 #define LTC_ANUBIS_TWEAK 202 #define LTC_KSEED 203 #define LTC_KASUMI 204 #define LTC_MULTI2 205 #define LTC_CAMELLIA 206 #define LTC_IDEA 207 #define LTC_SERPENT 208 #define LTC_TEA 209 210 /* stream ciphers */ 211 #define LTC_CHACHA 212 #define LTC_SALSA20 213 #define LTC_XSALSA20 214 #define LTC_SOSEMANUK 215 #define LTC_RABBIT 216 #define LTC_RC4_STREAM 217 #define LTC_SOBER128_STREAM 218 219 #endif /* LTC_NO_CIPHERS */ 220 221 222 /* ---> Block Cipher Modes of Operation <--- */ 223 #ifndef LTC_NO_MODES 224 225 #define LTC_CFB_MODE 226 #define LTC_OFB_MODE 227 #define LTC_ECB_MODE 228 #define LTC_CBC_MODE 229 #define LTC_CTR_MODE 230 231 /* F8 chaining mode */ 232 #define LTC_F8_MODE 233 234 /* LRW mode */ 235 #define LTC_LRW_MODE 236 #ifndef LTC_NO_TABLES 237 /* like GCM mode this will enable 16 8x128 tables [64KB] that make 238 * seeking very fast. 239 */ 240 #define LTC_LRW_TABLES 241 #endif 242 243 /* XTS mode */ 244 #define LTC_XTS_MODE 245 246 #endif /* LTC_NO_MODES */ 247 248 /* ---> One-Way Hash Functions <--- */ 249 #ifndef LTC_NO_HASHES 250 251 #define LTC_CHC_HASH 252 #define LTC_WHIRLPOOL 253 #define LTC_SHA3 254 #define LTC_KECCAK 255 #define LTC_SHA512 256 #define LTC_SHA512_256 257 #define LTC_SHA512_224 258 #define LTC_SHA384 259 #define LTC_SHA256 260 #define LTC_SHA224 261 #define LTC_TIGER 262 #define LTC_SHA1 263 #define LTC_MD5 264 #define LTC_MD4 265 #define LTC_MD2 266 #define LTC_RIPEMD128 267 #define LTC_RIPEMD160 268 #define LTC_RIPEMD256 269 #define LTC_RIPEMD320 270 #define LTC_BLAKE2S 271 #define LTC_BLAKE2B 272 273 #define LTC_HASH_HELPERS 274 275 #endif /* LTC_NO_HASHES */ 276 277 278 /* ---> MAC functions <--- */ 279 #ifndef LTC_NO_MACS 280 281 #define LTC_HMAC 282 #define LTC_OMAC 283 #define LTC_PMAC 284 #define LTC_XCBC 285 #define LTC_F9_MODE 286 #define LTC_PELICAN 287 #define LTC_POLY1305 288 #define LTC_BLAKE2SMAC 289 #define LTC_BLAKE2BMAC 290 291 /* ---> Encrypt + Authenticate Modes <--- */ 292 293 #define LTC_EAX_MODE 294 295 #define LTC_OCB_MODE 296 #define LTC_OCB3_MODE 297 #define LTC_CCM_MODE 298 #define LTC_GCM_MODE 299 #define LTC_CHACHA20POLY1305_MODE 300 301 /* Use 64KiB tables */ 302 #ifndef LTC_NO_TABLES 303 #define LTC_GCM_TABLES 304 #endif 305 306 /* USE SSE2? requires GCC works on x86_32 and x86_64*/ 307 #ifdef LTC_GCM_TABLES 308 /* #define LTC_GCM_TABLES_SSE2 */ 309 #endif 310 311 #endif /* LTC_NO_MACS */ 312 313 314 /* --> Pseudo Random Number Generators <--- */ 315 #ifndef LTC_NO_PRNGS 316 317 /* Yarrow */ 318 #define LTC_YARROW 319 320 /* a PRNG that simply reads from an available system source */ 321 #define LTC_SPRNG 322 323 /* The RC4 stream cipher based PRNG */ 324 #define LTC_RC4 325 326 /* The ChaCha20 stream cipher based PRNG */ 327 #define LTC_CHACHA20_PRNG 328 329 /* Fortuna PRNG */ 330 #define LTC_FORTUNA 331 332 /* Greg's SOBER128 stream cipher based PRNG */ 333 #define LTC_SOBER128 334 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 344 345 /* enable the ltc_rng hook to integrate e.g. embedded hardware RNG's easily */ 346 /* #define LTC_PRNG_ENABLE_LTC_RNG */ 347 348 #endif /* LTC_NO_PRNGS */ 349 350 #ifdef LTC_YARROW 351 352 /* which descriptor of AES to use? */ 353 /* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */ 354 #ifdef ENCRYPT_ONLY 355 #define LTC_YARROW_AES 0 356 #else 357 #define LTC_YARROW_AES 2 358 #endif 359 360 #endif /* LTC_YARROW */ 361 362 #ifdef LTC_FORTUNA 363 364 #if !defined(LTC_FORTUNA_RESEED_RATELIMIT_STATIC) && \ 365 ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || defined(_WIN32)) 366 367 /* time-based rate limit of the reseeding */ 368 #define LTC_FORTUNA_RESEED_RATELIMIT_TIMED 369 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 374 #endif 375 #elif defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L 376 #define LTC_CLOCK_GETTIME 377 #endif 378 379 #else 380 381 #ifndef LTC_FORTUNA_WD 382 /* reseed every N calls to the read function */ 383 #define LTC_FORTUNA_WD 10 384 #endif 385 386 #ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED 387 /* make sure only one of 388 * LTC_FORTUNA_RESEED_RATELIMIT_STATIC 389 * and 390 * LTC_FORTUNA_RESEED_RATELIMIT_TIMED 391 * is defined. 392 */ 393 #undef LTC_FORTUNA_RESEED_RATELIMIT_TIMED 394 #warning "undef'ed LTC_FORTUNA_RESEED_RATELIMIT_TIMED, looks like your architecture doesn't support it" 395 #endif 396 397 #endif 398 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 402 #endif 403 404 #endif /* LTC_FORTUNA */ 405 406 407 /* ---> Public Key Crypto <--- */ 408 #ifndef LTC_NO_PK 409 410 /* Include RSA support */ 411 #define LTC_MRSA 412 413 /* Include Diffie-Hellman support */ 414 /* is_prime fails for GMP */ 415 #define LTC_MDH 416 /* Supported Key Sizes */ 417 #define LTC_DH768 418 #define LTC_DH1024 419 #define LTC_DH1536 420 #define LTC_DH2048 421 422 #if defined(LTM_DESC) || defined(GMP_DESC) 423 /* tfm has a problem in fp_isprime for larger key sizes */ 424 #define LTC_DH3072 425 #define LTC_DH4096 426 #define LTC_DH6144 427 #define LTC_DH8192 428 #endif 429 430 /* Digital Signature Algorithm */ 431 #define LTC_MDSA 432 433 /* Ed25519 & X25519 */ 434 #define LTC_CURVE25519 435 436 /* ECC */ 437 #define LTC_MECC 438 439 /* use Shamir's trick for point mul (speeds up signature verification) */ 440 #define LTC_ECC_SHAMIR 441 442 #if defined(TFM_DESC) && defined(LTC_MECC) 443 #define LTC_MECC_ACCEL 444 #endif 445 446 /* do we want fixed point ECC */ 447 /* #define LTC_MECC_FP */ 448 449 #endif /* LTC_NO_PK */ 450 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 */ 455 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 */ 460 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 464 #endif 465 466 /* PKCS #1 (RSA) and #5 (Password Handling) stuff */ 467 #ifndef LTC_NO_PKCS 468 469 #define LTC_PKCS_1 470 #define LTC_PKCS_5 471 #define LTC_PKCS_8 472 #define LTC_PKCS_12 473 474 /* Include ASN.1 DER (required by DSA/RSA) */ 475 #define LTC_DER 476 477 #define LTC_MPI 478 479 #endif /* LTC_NO_PKCS */ 480 481 /* misc stuff */ 482 #ifndef LTC_NO_MISC 483 484 /* Various tidbits of modern neatoness */ 485 #define LTC_BASE64 486 /* ... and it's URL safe version */ 487 #define LTC_BASE64_URL 488 /* Base32 encoding/decoding */ 489 #define LTC_BASE32 490 /* Base16/hex encoding/decoding */ 491 #define LTC_BASE16 492 493 #define LTC_BCRYPT 494 495 #ifndef LTC_BCRYPT_DEFAULT_ROUNDS 496 #define LTC_BCRYPT_DEFAULT_ROUNDS 10 497 #endif 498 499 /* Keep LTC_NO_HKDF for compatibility reasons 500 * superseeded by LTC_NO_MISC*/ 501 #ifndef LTC_NO_HKDF 502 /* HKDF Key Derivation/Expansion stuff */ 503 #define LTC_HKDF 504 #endif /* LTC_NO_HKDF */ 505 506 #define LTC_ADLER32 507 508 #define LTC_CRC32 509 510 #define LTC_SSH 511 512 #define LTC_PADDING 513 514 #define LTC_PBES 515 516 #endif /* LTC_NO_MISC */ 517 518 /* cleanup */ 519 520 #ifdef LTC_MECC 521 /* Supported ECC Key Sizes */ 522 #ifndef LTC_NO_CURVES 523 #define LTC_ECC_BRAINPOOLP160R1 524 #define LTC_ECC_BRAINPOOLP160T1 525 #define LTC_ECC_BRAINPOOLP192R1 526 #define LTC_ECC_BRAINPOOLP192T1 527 #define LTC_ECC_BRAINPOOLP224R1 528 #define LTC_ECC_BRAINPOOLP224T1 529 #define LTC_ECC_BRAINPOOLP256R1 530 #define LTC_ECC_BRAINPOOLP256T1 531 #define LTC_ECC_BRAINPOOLP320R1 532 #define LTC_ECC_BRAINPOOLP320T1 533 #define LTC_ECC_BRAINPOOLP384R1 534 #define LTC_ECC_BRAINPOOLP384T1 535 #define LTC_ECC_BRAINPOOLP512R1 536 #define LTC_ECC_BRAINPOOLP512T1 537 #define LTC_ECC_PRIME192V2 538 #define LTC_ECC_PRIME192V3 539 #define LTC_ECC_PRIME239V1 540 #define LTC_ECC_PRIME239V2 541 #define LTC_ECC_PRIME239V3 542 #define LTC_ECC_SECP112R1 543 #define LTC_ECC_SECP112R2 544 #define LTC_ECC_SECP128R1 545 #define LTC_ECC_SECP128R2 546 #define LTC_ECC_SECP160K1 547 #define LTC_ECC_SECP160R1 548 #define LTC_ECC_SECP160R2 549 #define LTC_ECC_SECP192K1 550 #define LTC_ECC_SECP192R1 551 #define LTC_ECC_SECP224K1 552 #define LTC_ECC_SECP224R1 553 #define LTC_ECC_SECP256K1 554 #define LTC_ECC_SECP256R1 555 #define LTC_ECC_SECP384R1 556 #define LTC_ECC_SECP521R1 557 #endif 558 #endif /* LTC_MECC */ 559 560 #if defined(LTC_DER) 561 #ifndef LTC_DER_MAX_RECURSION 562 /* Maximum recursion limit when processing nested ASN.1 types. */ 563 #define LTC_DER_MAX_RECURSION 30 564 #endif 565 #endif 566 567 #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_SSH) 568 #ifndef LTC_PK_MAX_RETRIES 569 /* iterations limit for retry-loops */ 570 #define LTC_PK_MAX_RETRIES 20 571 #endif 572 #endif 573 574 #ifdef LTC_MRSA 575 #define LTC_PKCS_1 576 #endif 577 578 #if defined(LTC_MRSA) || defined(LTC_MECC) 579 #define LTC_PKCS_8 580 #endif 581 582 #ifdef LTC_PKCS_8 583 #define LTC_PADDING 584 #define LTC_PBES 585 #endif 586 587 #if defined(LTC_CLEAN_STACK) 588 /* if you're sure that you want to use it, remove the line below */ 589 #error LTC_CLEAN_STACK is considered as broken 590 #endif 591 592 #if defined(LTC_PBES) && !defined(LTC_PKCS_5) 593 #error LTC_PBES requires LTC_PKCS_5 594 #endif 595 596 #if defined(LTC_PBES) && !defined(LTC_PKCS_12) 597 #error LTC_PBES requires LTC_PKCS_12 598 #endif 599 600 #if defined(LTC_PKCS_5) && !defined(LTC_HMAC) 601 #error LTC_PKCS_5 requires LTC_HMAC 602 #endif 603 604 #if defined(LTC_PKCS_5) && !defined(LTC_HASH_HELPERS) 605 #error LTC_PKCS_5 requires LTC_HASH_HELPERS 606 #endif 607 608 #if defined(LTC_PELICAN) && !defined(LTC_RIJNDAEL) 609 #error Pelican-MAC requires LTC_RIJNDAEL 610 #endif 611 612 #if defined(LTC_EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(LTC_OMAC)) 613 #error LTC_EAX_MODE requires CTR and LTC_OMAC mode 614 #endif 615 616 #if defined(LTC_YARROW) && !defined(LTC_CTR_MODE) 617 #error LTC_YARROW requires LTC_CTR_MODE chaining mode to be defined! 618 #endif 619 620 #if defined(LTC_DER) && !defined(LTC_MPI) 621 #error ASN.1 DER requires MPI functionality 622 #endif 623 624 #if (defined(LTC_MDSA) || defined(LTC_MRSA) || defined(LTC_MECC)) && !defined(LTC_DER) 625 #error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled 626 #endif 627 628 #if defined(LTC_BCRYPT) && !defined(LTC_BLOWFISH) 629 #error LTC_BCRYPT requires LTC_BLOWFISH 630 #endif 631 632 #if defined(LTC_CHACHA20POLY1305_MODE) && (!defined(LTC_CHACHA) || !defined(LTC_POLY1305)) 633 #error LTC_CHACHA20POLY1305_MODE requires LTC_CHACHA + LTC_POLY1305 634 #endif 635 636 #if defined(LTC_CHACHA20_PRNG) && !defined(LTC_CHACHA) 637 #error LTC_CHACHA20_PRNG requires LTC_CHACHA 638 #endif 639 640 #if defined(LTC_XSALSA20) && !defined(LTC_SALSA20) 641 #error LTC_XSALSA20 requires LTC_SALSA20 642 #endif 643 644 #if defined(LTC_RC4) && !defined(LTC_RC4_STREAM) 645 #error LTC_RC4 requires LTC_RC4_STREAM 646 #endif 647 648 #if defined(LTC_SOBER128) && !defined(LTC_SOBER128_STREAM) 649 #error LTC_SOBER128 requires LTC_SOBER128_STREAM 650 #endif 651 652 #if defined(LTC_BLAKE2SMAC) && !defined(LTC_BLAKE2S) 653 #error LTC_BLAKE2SMAC requires LTC_BLAKE2S 654 #endif 655 656 #if defined(LTC_BLAKE2BMAC) && !defined(LTC_BLAKE2B) 657 #error LTC_BLAKE2BMAC requires LTC_BLAKE2B 658 #endif 659 660 #if defined(LTC_SPRNG) && !defined(LTC_RNG_GET_BYTES) 661 #error LTC_SPRNG requires LTC_RNG_GET_BYTES 662 #endif 663 664 #if defined(LTC_NO_MATH) && (defined(LTM_DESC) || defined(TFM_DESC) || defined(GMP_DESC)) 665 #error LTC_NO_MATH defined, but also a math descriptor 666 #endif 667 668 /* THREAD management */ 669 #if defined(_CFG_CORE_LTC_OPTEE_THREAD) 670 671 #include <kernel/mutex.h> 672 673 #define LTC_MUTEX_GLOBAL(x) struct mutex x = MUTEX_INITIALIZER; 674 #define LTC_MUTEX_PROTO(x) extern struct mutex x; 675 #define LTC_MUTEX_TYPE(x) struct mutex x; 676 #define LTC_MUTEX_INIT(x) mutex_init(x); 677 #define LTC_MUTEX_LOCK(x) mutex_lock(x); 678 #define LTC_MUTEX_UNLOCK(x) mutex_unlock(x); 679 680 #elif defined(LTC_PTHREAD) 681 682 #include <pthread.h> 683 684 #define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER; 685 #define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x; 686 #define LTC_MUTEX_TYPE(x) pthread_mutex_t x; 687 #define LTC_MUTEX_INIT(x) LTC_ARGCHK(pthread_mutex_init(x, NULL) == 0); 688 #define LTC_MUTEX_LOCK(x) LTC_ARGCHK(pthread_mutex_lock(x) == 0); 689 #define LTC_MUTEX_UNLOCK(x) LTC_ARGCHK(pthread_mutex_unlock(x) == 0); 690 #define LTC_MUTEX_DESTROY(x) LTC_ARGCHK(pthread_mutex_destroy(x) == 0); 691 692 #else 693 694 /* default no functions */ 695 #define LTC_MUTEX_GLOBAL(x) 696 #define LTC_MUTEX_PROTO(x) 697 #define LTC_MUTEX_TYPE(x) 698 #define LTC_MUTEX_INIT(x) 699 #define LTC_MUTEX_LOCK(x) 700 #define LTC_MUTEX_UNLOCK(x) 701 #define LTC_MUTEX_DESTROY(x) 702 703 #endif /* LTC_PTHREAD */ 704 705 /* Debuggers */ 706 707 /* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */ 708 /* #define LTC_VALGRIND */ 709 710 #ifndef LTC_NO_FILE 711 /* buffer size for reading from a file via fread(..) */ 712 #ifndef LTC_FILE_READ_BUFSIZE 713 #define LTC_FILE_READ_BUFSIZE 8192 714 #endif 715 #endif 716 717 /* ECC backwards compatibility */ 718 #if !defined(LTC_ECC_SECP112R1) && defined(LTC_ECC112) 719 #define LTC_ECC_SECP112R1 720 #undef LTC_ECC112 721 #endif 722 #if !defined(LTC_ECC_SECP128R1) && defined(LTC_ECC128) 723 #define LTC_ECC_SECP128R1 724 #undef LTC_ECC128 725 #endif 726 #if !defined(LTC_ECC_SECP160R1) && defined(LTC_ECC160) 727 #define LTC_ECC_SECP160R1 728 #undef LTC_ECC160 729 #endif 730 #if !defined(LTC_ECC_SECP192R1) && defined(LTC_ECC192) 731 #define LTC_ECC_SECP192R1 732 #undef LTC_ECC192 733 #endif 734 #if !defined(LTC_ECC_SECP224R1) && defined(LTC_ECC224) 735 #define LTC_ECC_SECP224R1 736 #undef LTC_ECC224 737 #endif 738 #if !defined(LTC_ECC_SECP256R1) && defined(LTC_ECC256) 739 #define LTC_ECC_SECP256R1 740 #undef LTC_ECC256 741 #endif 742 #if !defined(LTC_ECC_SECP384R1) && defined(LTC_ECC384) 743 #define LTC_ECC_SECP384R1 744 #undef LTC_ECC384 745 #endif 746 #if !defined(LTC_ECC_SECP512R1) && defined(LTC_ECC521) 747 #define LTC_ECC_SECP521R1 748 #undef LTC_ECC521 749 #endif 750 751 #endif /* TOMCRYPT_CUSTOM_H_ */ 752