2004-12-30 23:55:53 +00:00
|
|
|
#ifndef TOMCRYPT_CUSTOM_H_
|
|
|
|
#define TOMCRYPT_CUSTOM_H_
|
2003-03-03 01:03:50 +00:00
|
|
|
|
2004-06-20 02:41:49 +00:00
|
|
|
/* macros for various libc functions you can change for embedded targets */
|
2005-11-24 11:57:58 +00:00
|
|
|
#ifndef XMALLOC
|
2004-06-20 02:41:49 +00:00
|
|
|
#define XMALLOC malloc
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef XREALLOC
|
2003-03-03 01:03:50 +00:00
|
|
|
#define XREALLOC realloc
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef XCALLOC
|
2004-06-20 02:41:49 +00:00
|
|
|
#define XCALLOC calloc
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef XFREE
|
2004-06-20 02:41:49 +00:00
|
|
|
#define XFREE free
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
2004-06-20 02:41:49 +00:00
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#ifndef XMEMSET
|
2004-06-20 02:41:49 +00:00
|
|
|
#define XMEMSET memset
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef XMEMCPY
|
2004-06-20 02:41:49 +00:00
|
|
|
#define XMEMCPY memcpy
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef XMEMCMP
|
|
|
|
#define XMEMCMP memcmp
|
|
|
|
#endif
|
2004-06-20 02:41:49 +00:00
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#ifndef XCLOCK
|
2004-06-20 02:41:49 +00:00
|
|
|
#define XCLOCK clock
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef XCLOCKS_PER_SEC
|
2003-03-03 01:03:50 +00:00
|
|
|
#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef XQSORT
|
|
|
|
#define XQSORT qsort
|
|
|
|
#endif
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2006-01-26 18:11:56 +00:00
|
|
|
/* Easy button? */
|
|
|
|
#ifdef LTC_EASY
|
|
|
|
#define LTC_NO_CIPHERS
|
|
|
|
#define RIJNDAEL
|
|
|
|
#define BLOWFISH
|
|
|
|
#define DES
|
|
|
|
#define CAST5
|
|
|
|
|
|
|
|
#define LTC_NO_MODES
|
|
|
|
#define ECB
|
|
|
|
#define CBC
|
|
|
|
#define CTR
|
|
|
|
|
|
|
|
#define LTC_NO_HASHES
|
|
|
|
#define SHA1
|
|
|
|
#define SHA512
|
|
|
|
#define SHA384
|
|
|
|
#define SHA256
|
|
|
|
#define SHA224
|
|
|
|
#define WHIRLPOOL
|
|
|
|
|
|
|
|
#define LTC_NO_MACS
|
|
|
|
#define HMAC
|
|
|
|
#define OMAC
|
|
|
|
#define CCM_MODE
|
|
|
|
|
|
|
|
#define LTC_NO_PRNGS
|
|
|
|
#define SPRNG
|
|
|
|
#define YARROW
|
|
|
|
#define DEVRANDOM
|
|
|
|
#define TRY_URANDOM_FIRST
|
|
|
|
|
|
|
|
#define LTC_NO_PK
|
|
|
|
#define MRSA
|
|
|
|
#define MECC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-31 02:36:47 +00:00
|
|
|
/* Use small code where possible */
|
2005-04-17 11:37:13 +00:00
|
|
|
/* #define LTC_SMALL_CODE */
|
2004-05-31 02:36:47 +00:00
|
|
|
|
|
|
|
/* Enable self-test test vector checking */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_TEST
|
|
|
|
#define LTC_TEST
|
|
|
|
#endif
|
2004-05-31 02:36:47 +00:00
|
|
|
|
|
|
|
/* clean the stack of functions which put private information on stack */
|
2005-04-17 11:37:13 +00:00
|
|
|
/* #define LTC_CLEAN_STACK */
|
2004-05-31 02:36:47 +00:00
|
|
|
|
|
|
|
/* disable all file related functions */
|
2005-04-17 11:37:13 +00:00
|
|
|
/* #define LTC_NO_FILE */
|
2004-12-30 23:55:53 +00:00
|
|
|
|
|
|
|
/* disable all forms of ASM */
|
2005-04-17 11:37:13 +00:00
|
|
|
/* #define LTC_NO_ASM */
|
|
|
|
|
|
|
|
/* disable FAST mode */
|
|
|
|
/* #define LTC_NO_FAST */
|
|
|
|
|
|
|
|
/* disable BSWAP on x86 */
|
|
|
|
/* #define LTC_NO_BSWAP */
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* ---> Symmetric Block Ciphers <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_CIPHERS
|
|
|
|
|
2003-03-03 01:03:50 +00:00
|
|
|
#define BLOWFISH
|
|
|
|
#define RC2
|
|
|
|
#define RC5
|
|
|
|
#define RC6
|
|
|
|
#define SAFERP
|
|
|
|
#define RIJNDAEL
|
|
|
|
#define XTEA
|
2004-10-30 03:00:26 +00:00
|
|
|
/* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
|
|
|
|
* (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define TWOFISH
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_TABLES
|
|
|
|
#define TWOFISH_TABLES
|
|
|
|
/* #define TWOFISH_ALL_TABLES */
|
|
|
|
#else
|
|
|
|
#define TWOFISH_SMALL
|
|
|
|
#endif
|
2005-04-17 11:37:13 +00:00
|
|
|
/* #define TWOFISH_SMALL */
|
2004-10-30 03:00:26 +00:00
|
|
|
/* DES includes EDE triple-DES */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define DES
|
|
|
|
#define CAST5
|
|
|
|
#define NOEKEON
|
2003-12-24 18:59:57 +00:00
|
|
|
#define SKIPJACK
|
2005-04-17 11:37:13 +00:00
|
|
|
#define SAFER
|
2004-12-30 23:55:53 +00:00
|
|
|
#define KHAZAD
|
|
|
|
#define ANUBIS
|
|
|
|
#define ANUBIS_TWEAK
|
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
#endif /* LTC_NO_CIPHERS */
|
|
|
|
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* ---> Block Cipher Modes of Operation <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_MODES
|
|
|
|
|
2003-03-03 01:03:50 +00:00
|
|
|
#define CFB
|
|
|
|
#define OFB
|
|
|
|
#define ECB
|
|
|
|
#define CBC
|
|
|
|
#define CTR
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2006-06-18 01:37:50 +00:00
|
|
|
/* F8 chaining mode */
|
|
|
|
#define LTC_F8_MODE
|
|
|
|
|
2006-01-26 18:11:56 +00:00
|
|
|
/* LRW mode */
|
|
|
|
#define LRW_MODE
|
|
|
|
#ifndef LTC_NO_TABLES
|
|
|
|
/* like GCM mode this will enable 16 8x128 tables [64KB] that make
|
|
|
|
* seeking very fast.
|
|
|
|
*/
|
|
|
|
#define LRW_TABLES
|
|
|
|
#endif
|
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
#endif /* LTC_NO_MODES */
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* ---> One-Way Hash Functions <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_HASHES
|
|
|
|
|
2004-10-30 03:00:26 +00:00
|
|
|
#define CHC_HASH
|
2004-02-20 20:03:32 +00:00
|
|
|
#define WHIRLPOOL
|
2003-03-03 01:03:50 +00:00
|
|
|
#define SHA512
|
|
|
|
#define SHA384
|
|
|
|
#define SHA256
|
2003-12-24 18:59:57 +00:00
|
|
|
#define SHA224
|
2003-03-03 01:03:50 +00:00
|
|
|
#define TIGER
|
|
|
|
#define SHA1
|
|
|
|
#define MD5
|
|
|
|
#define MD4
|
|
|
|
#define MD2
|
2003-09-08 01:06:11 +00:00
|
|
|
#define RIPEMD128
|
|
|
|
#define RIPEMD160
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
#endif /* LTC_NO_HASHES */
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* ---> MAC functions <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_MACS
|
|
|
|
|
2003-03-03 01:03:50 +00:00
|
|
|
#define HMAC
|
2003-12-24 18:59:57 +00:00
|
|
|
#define OMAC
|
2004-02-20 20:03:32 +00:00
|
|
|
#define PMAC
|
2005-04-17 11:37:13 +00:00
|
|
|
#define PELICAN
|
|
|
|
|
|
|
|
#if defined(PELICAN) && !defined(RIJNDAEL)
|
|
|
|
#error Pelican-MAC requires RIJNDAEL
|
|
|
|
#endif
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* ---> Encrypt + Authenticate Modes <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
|
2004-01-25 17:40:34 +00:00
|
|
|
#define EAX_MODE
|
2004-12-30 23:55:53 +00:00
|
|
|
#if defined(EAX_MODE) && !(defined(CTR) && defined(OMAC))
|
|
|
|
#error EAX_MODE requires CTR and OMAC mode
|
|
|
|
#endif
|
|
|
|
|
2004-01-25 17:40:34 +00:00
|
|
|
#define OCB_MODE
|
2005-04-17 11:37:13 +00:00
|
|
|
#define CCM_MODE
|
|
|
|
#define GCM_MODE
|
2005-06-09 00:08:13 +00:00
|
|
|
|
2005-04-17 11:37:13 +00:00
|
|
|
/* Use 64KiB tables */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_TABLES
|
|
|
|
#define GCM_TABLES
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* LTC_NO_MACS */
|
2004-05-31 02:36:47 +00:00
|
|
|
|
|
|
|
/* Various tidbits of modern neatoness */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define BASE64
|
2004-08-06 16:42:41 +00:00
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* --> Pseudo Random Number Generators <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_PRNGS
|
|
|
|
|
2004-08-06 16:42:41 +00:00
|
|
|
/* Yarrow */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define YARROW
|
2005-04-17 11:37:13 +00:00
|
|
|
/* which descriptor of AES to use? */
|
|
|
|
/* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
|
2004-05-31 02:36:47 +00:00
|
|
|
#define YARROW_AES 0
|
2004-08-06 16:42:41 +00:00
|
|
|
|
|
|
|
#if defined(YARROW) && !defined(CTR)
|
|
|
|
#error YARROW requires CTR chaining mode to be defined!
|
|
|
|
#endif
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* a PRNG that simply reads from an available system source */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define SPRNG
|
2004-12-30 23:55:53 +00:00
|
|
|
|
|
|
|
/* The RC4 stream cipher */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define RC4
|
2004-07-23 15:40:22 +00:00
|
|
|
|
2004-08-06 16:42:41 +00:00
|
|
|
/* Fortuna PRNG */
|
2004-07-23 15:40:22 +00:00
|
|
|
#define FORTUNA
|
|
|
|
/* reseed every N calls to the read function */
|
2004-08-06 16:42:41 +00:00
|
|
|
#define FORTUNA_WD 10
|
|
|
|
/* number of pools (4..32) can save a bit of ram by lowering the count */
|
|
|
|
#define FORTUNA_POOLS 32
|
2004-07-23 15:40:22 +00:00
|
|
|
|
2004-08-06 16:42:41 +00:00
|
|
|
/* Greg's SOBER128 PRNG ;-0 */
|
|
|
|
#define SOBER128
|
2004-07-23 15:40:22 +00:00
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* the *nix style /dev/random device */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define DEVRANDOM
|
2004-12-30 23:55:53 +00:00
|
|
|
/* try /dev/urandom before trying /dev/random */
|
2004-05-12 20:42:16 +00:00
|
|
|
#define TRY_URANDOM_FIRST
|
2004-05-31 02:36:47 +00:00
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
#endif /* LTC_NO_PRNGS */
|
|
|
|
|
2005-08-01 16:36:47 +00:00
|
|
|
/* ---> math provider? <--- */
|
|
|
|
#ifndef LTC_NO_MATH
|
|
|
|
|
|
|
|
/* LibTomMath */
|
|
|
|
/* #define LTM_DESC */
|
|
|
|
|
|
|
|
/* TomsFastMath */
|
|
|
|
/* #define TFM_DESC */
|
|
|
|
|
|
|
|
#endif /* LTC_NO_MATH */
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* ---> Public Key Crypto <--- */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_PK
|
|
|
|
|
2005-08-01 16:36:47 +00:00
|
|
|
/* Include RSA support */
|
2003-03-03 01:03:50 +00:00
|
|
|
#define MRSA
|
2004-06-20 02:41:49 +00:00
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
/* Include Katja (a Rabin variant like RSA) */
|
2006-04-06 19:48:32 +00:00
|
|
|
/* #define MKAT */
|
2005-11-18 05:15:37 +00:00
|
|
|
|
2004-06-20 02:41:49 +00:00
|
|
|
/* Digital Signature Algorithm */
|
2003-12-24 18:59:57 +00:00
|
|
|
#define MDSA
|
2004-06-20 02:41:49 +00:00
|
|
|
|
|
|
|
/* ECC */
|
|
|
|
#define MECC
|
2005-08-01 16:36:47 +00:00
|
|
|
|
2006-04-06 19:48:32 +00:00
|
|
|
#if defined(TFM_DESC) && defined(MECC)
|
|
|
|
#define MECC_ACCEL
|
|
|
|
#endif
|
|
|
|
|
2006-05-29 23:12:56 +00:00
|
|
|
/* do we want fixed point ECC */
|
|
|
|
/* #define MECC_FP */
|
|
|
|
|
2005-08-01 16:36:47 +00:00
|
|
|
/* Timing Resistant? */
|
|
|
|
/* #define LTC_ECC_TIMING_RESISTANT */
|
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
#endif /* LTC_NO_PK */
|
|
|
|
|
2004-10-30 03:00:26 +00:00
|
|
|
/* PKCS #1 (RSA) and #5 (Password Handling) stuff */
|
2005-06-09 00:08:13 +00:00
|
|
|
#ifndef LTC_NO_PKCS
|
|
|
|
|
2004-05-12 20:42:16 +00:00
|
|
|
#define PKCS_1
|
|
|
|
#define PKCS_5
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
/* Include ASN.1 DER (required by DSA/RSA) */
|
|
|
|
#define LTC_DER
|
2005-11-24 11:57:58 +00:00
|
|
|
|
|
|
|
#endif /* LTC_NO_PKCS */
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
|
|
|
|
#ifdef MECC
|
|
|
|
/* Supported ECC Key Sizes */
|
|
|
|
#ifndef LTC_NO_CURVES
|
|
|
|
#define ECC192
|
|
|
|
#define ECC224
|
|
|
|
#define ECC256
|
|
|
|
#define ECC384
|
|
|
|
#define ECC521
|
|
|
|
#endif
|
2004-12-30 23:55:53 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#if defined(MECC) || defined(MRSA) || defined(MDSA) || defined(MKATJA)
|
|
|
|
/* Include the MPI functionality? (required by the PK algorithms) */
|
|
|
|
#define MPI
|
2004-12-30 23:55:53 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#ifdef MRSA
|
|
|
|
#define PKCS_1
|
|
|
|
#endif
|
2005-06-09 00:08:13 +00:00
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#if defined(LTC_DER) && !defined(MPI)
|
|
|
|
#error ASN.1 DER requires MPI functionality
|
2003-03-03 01:03:50 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#if (defined(MDSA) || defined(MRSA) || defined(MECC) || defined(MKATJA)) && !defined(LTC_DER)
|
|
|
|
#error PK requires ASN.1 DER functionality, make sure LTC_DER is enabled
|
|
|
|
#endif
|
2005-06-09 00:08:13 +00:00
|
|
|
|
2005-06-27 11:47:35 +00:00
|
|
|
/* THREAD management */
|
|
|
|
|
|
|
|
#ifdef LTC_PTHREAD
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#define LTC_MUTEX_GLOBAL(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#define LTC_MUTEX_PROTO(x) extern pthread_mutex_t x;
|
2005-11-18 05:15:37 +00:00
|
|
|
#define LTC_MUTEX_TYPE(x) pthread_mutex_t x;
|
|
|
|
#define LTC_MUTEX_INIT(x) pthread_mutex_init(x, NULL);
|
2005-06-27 11:47:35 +00:00
|
|
|
#define LTC_MUTEX_LOCK(x) pthread_mutex_lock(x);
|
|
|
|
#define LTC_MUTEX_UNLOCK(x) pthread_mutex_unlock(x);
|
|
|
|
|
2005-11-18 05:15:37 +00:00
|
|
|
#else
|
2005-06-27 11:47:35 +00:00
|
|
|
|
|
|
|
/* default no functions */
|
|
|
|
#define LTC_MUTEX_GLOBAL(x)
|
|
|
|
#define LTC_MUTEX_PROTO(x)
|
2005-11-18 05:15:37 +00:00
|
|
|
#define LTC_MUTEX_TYPE(x)
|
|
|
|
#define LTC_MUTEX_INIT(x)
|
2005-06-27 11:47:35 +00:00
|
|
|
#define LTC_MUTEX_LOCK(x)
|
|
|
|
#define LTC_MUTEX_UNLOCK(x)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-24 11:57:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-06-27 11:47:35 +00:00
|
|
|
|
2005-06-09 00:08:13 +00:00
|
|
|
/* $Source$ */
|
|
|
|
/* $Revision$ */
|
|
|
|
/* $Date$ */
|