clean-up test-build and extend tomcrypt_custom.h

added LTC_MINIMAL to be able do a build without nearly any
functionality :)
make sure timing resistant RSA & ECC are enabled if not said otherwise
This commit is contained in:
Steffen Jaeckel 2015-09-01 10:09:41 +02:00
parent 8cb20e6059
commit 6ec93afa3c
5 changed files with 99 additions and 50 deletions

View File

@ -12,7 +12,7 @@
/** /**
@file des.c @file des.c
LTC_DES code submitted by Dobes Vandermeer DES code submitted by Dobes Vandermeer
*/ */
#ifdef LTC_DES #ifdef LTC_DES

View File

@ -125,6 +125,19 @@
#define LTC_BASE64 #define LTC_BASE64
#endif #endif
/* The minimal set of functionality to run the tests */
#ifdef LTC_MINIMAL
#define LTC_SHA256
#define LTC_CTR_MODE
#define LTC_RNG_MAKE_PRNG
#define LTC_RNG_GET_BYTES
#define LTC_YARROW
#define LTC_DEVRANDOM
#define LTC_TRY_URANDOM_FIRST
#undef LTC_NO_FILE
#endif
/* Enable self-test test vector checking */ /* Enable self-test test vector checking */
#ifndef LTC_NO_TEST #ifndef LTC_NO_TEST
#define LTC_TEST #define LTC_TEST
@ -252,6 +265,7 @@
#endif /* LTC_NO_HASHES */ #endif /* LTC_NO_HASHES */
/* ---> MAC functions <--- */ /* ---> MAC functions <--- */
#ifndef LTC_NO_MACS #ifndef LTC_NO_MACS
@ -283,6 +297,7 @@
#endif /* LTC_NO_MACS */ #endif /* LTC_NO_MACS */
/* --> Pseudo Random Number Generators <--- */ /* --> Pseudo Random Number Generators <--- */
#ifndef LTC_NO_PRNGS #ifndef LTC_NO_PRNGS
@ -304,17 +319,14 @@
/* Fortuna PRNG */ /* Fortuna PRNG */
#define LTC_FORTUNA #define LTC_FORTUNA
/* reseed every N calls to the read function */
#define LTC_FORTUNA_WD 10
/* number of pools (4..32) can save a bit of ram by lowering the count */
#define LTC_FORTUNA_POOLS 32
/* Greg's LTC_SOBER128 PRNG ;-0 */ /* Greg's LTC_SOBER128 PRNG ;-0 */
#define LTC_SOBER128 #define LTC_SOBER128
/* the *nix style /dev/random device */ /* the *nix style /dev/random device */
#define LTC_DEVRANDOM #define LTC_DEVRANDOM
/* try /dev/urandom before trying /dev/random */ /* try /dev/urandom before trying /dev/random
* are you sure you want to disable this? http://www.2uo.de/myths-about-urandom/ */
#define LTC_TRY_URANDOM_FIRST #define LTC_TRY_URANDOM_FIRST
/* rng_get_bytes() */ /* rng_get_bytes() */
#define LTC_RNG_GET_BYTES #define LTC_RNG_GET_BYTES
@ -323,17 +335,27 @@
#endif /* LTC_NO_PRNGS */ #endif /* LTC_NO_PRNGS */
#ifdef LTC_FORTUNA
#ifndef LTC_FORTUNA_WD
/* reseed every N calls to the read function */
#define LTC_FORTUNA_WD 10
#endif
#ifndef LTC_FORTUNA_POOLS
/* number of pools (4..32) can save a bit of ram by lowering the count */
#define LTC_FORTUNA_POOLS 32
#endif
#endif /* LTC_FORTUNA */
/* ---> Public Key Crypto <--- */ /* ---> Public Key Crypto <--- */
#ifndef LTC_NO_PK #ifndef LTC_NO_PK
/* Include RSA support */ /* Include RSA support */
#define LTC_MRSA #define LTC_MRSA
#ifndef LTC_NO_RSA_BLINDING
/* Enable RSA blinding when doing private key operations by default */
#define LTC_RSA_BLINDING
#endif /* LTC_NO_RSA_BLINDING */
/* Include Diffie-Hellman support */ /* Include Diffie-Hellman support */
#ifndef GMP_DESC #ifndef GMP_DESC
/* is_prime fails for GMP */ /* is_prime fails for GMP */
@ -373,13 +395,18 @@
/* do we want fixed point ECC */ /* do we want fixed point ECC */
/* #define LTC_MECC_FP */ /* #define LTC_MECC_FP */
#ifndef LTC_NO_ECC_TIMING_RESISTANT #endif /* LTC_NO_PK */
#if defined(LTC_MRSA) && !defined(LTC_NO_RSA_BLINDING)
/* Enable RSA blinding when doing private key operations by default */
#define LTC_RSA_BLINDING
#endif /* LTC_NO_RSA_BLINDING */
#if defined(LTC_MECC) && !defined(LTC_NO_ECC_TIMING_RESISTANT)
/* Enable ECC timing resistant version by default */ /* Enable ECC timing resistant version by default */
#define LTC_ECC_TIMING_RESISTANT #define LTC_ECC_TIMING_RESISTANT
#endif #endif
#endif /* LTC_NO_PK */
/* define these PK sizes out of LTC_NO_PK /* define these PK sizes out of LTC_NO_PK
* to have them always defined * to have them always defined
*/ */

View File

@ -1,5 +1,6 @@
#include <tomcrypt_test.h> #include <tomcrypt_test.h>
#ifdef LTC_BASE64
int base64_test(void) int base64_test(void)
{ {
unsigned char in[64], out[256], tmp[64]; unsigned char in[64], out[256], tmp[64];
@ -57,6 +58,7 @@ int base64_test(void)
} }
return 0; return 0;
} }
#endif
/* $Source$ */ /* $Source$ */
/* $Revision$ */ /* $Revision$ */

View File

@ -3,8 +3,7 @@
int modes_test(void) int modes_test(void)
{ {
unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16]; int ret = CRYPT_NOP;
int cipher_idx;
#ifdef LTC_CBC_MODE #ifdef LTC_CBC_MODE
symmetric_CBC cbc; symmetric_CBC cbc;
#endif #endif
@ -14,6 +13,9 @@ int modes_test(void)
#ifdef LTC_OFB_MODE #ifdef LTC_OFB_MODE
symmetric_OFB ofb; symmetric_OFB ofb;
#endif #endif
#if defined(LTC_CBC_MODE) || defined(LTC_CFB_MODE) || defined(LTC_OFB_MODE)
unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16];
int cipher_idx;
unsigned long l; unsigned long l;
/* make a random pt, key and iv */ /* make a random pt, key and iv */
@ -27,31 +29,32 @@ int modes_test(void)
fprintf(stderr, "test requires AES"); fprintf(stderr, "test requires AES");
return 1; return 1;
} }
#endif
#ifdef LTC_F8_MODE #ifdef LTC_F8_MODE
DO(f8_test_mode()); DO(ret = f8_test_mode());
#endif #endif
#ifdef LTC_LRW_MODE #ifdef LTC_LRW_MODE
DO(lrw_test()); DO(ret = lrw_test());
#endif #endif
#ifdef LTC_CBC_MODE #ifdef LTC_CBC_MODE
/* test CBC mode */ /* test CBC mode */
/* encode the block */ /* encode the block */
DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc)); DO(ret = cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
l = sizeof(iv2); l = sizeof(iv2);
DO(cbc_getiv(iv2, &l, &cbc)); DO(ret = cbc_getiv(iv2, &l, &cbc));
if (l != 16 || memcmp(iv2, iv, 16)) { if (l != 16 || memcmp(iv2, iv, 16)) {
fprintf(stderr, "cbc_getiv failed"); fprintf(stderr, "cbc_getiv failed");
return 1; return 1;
} }
DO(cbc_encrypt(pt, ct, 64, &cbc)); DO(ret = cbc_encrypt(pt, ct, 64, &cbc));
/* decode the block */ /* decode the block */
DO(cbc_setiv(iv2, l, &cbc)); DO(ret = cbc_setiv(iv2, l, &cbc));
zeromem(tmp, sizeof(tmp)); zeromem(tmp, sizeof(tmp));
DO(cbc_decrypt(ct, tmp, 64, &cbc)); DO(ret = cbc_decrypt(ct, tmp, 64, &cbc));
if (memcmp(tmp, pt, 64) != 0) { if (memcmp(tmp, pt, 64) != 0) {
fprintf(stderr, "CBC failed"); fprintf(stderr, "CBC failed");
return 1; return 1;
@ -61,20 +64,20 @@ int modes_test(void)
#ifdef LTC_CFB_MODE #ifdef LTC_CFB_MODE
/* test CFB mode */ /* test CFB mode */
/* encode the block */ /* encode the block */
DO(cfb_start(cipher_idx, iv, key, 16, 0, &cfb)); DO(ret = cfb_start(cipher_idx, iv, key, 16, 0, &cfb));
l = sizeof(iv2); l = sizeof(iv2);
DO(cfb_getiv(iv2, &l, &cfb)); DO(ret = cfb_getiv(iv2, &l, &cfb));
/* note we don't memcmp iv2/iv since cfb_start processes the IV for the first block */ /* note we don't memcmp iv2/iv since cfb_start processes the IV for the first block */
if (l != 16) { if (l != 16) {
fprintf(stderr, "cfb_getiv failed"); fprintf(stderr, "cfb_getiv failed");
return 1; return 1;
} }
DO(cfb_encrypt(pt, ct, 64, &cfb)); DO(ret = cfb_encrypt(pt, ct, 64, &cfb));
/* decode the block */ /* decode the block */
DO(cfb_setiv(iv, l, &cfb)); DO(ret = cfb_setiv(iv, l, &cfb));
zeromem(tmp, sizeof(tmp)); zeromem(tmp, sizeof(tmp));
DO(cfb_decrypt(ct, tmp, 64, &cfb)); DO(ret = cfb_decrypt(ct, tmp, 64, &cfb));
if (memcmp(tmp, pt, 64) != 0) { if (memcmp(tmp, pt, 64) != 0) {
fprintf(stderr, "CFB failed"); fprintf(stderr, "CFB failed");
return 1; return 1;
@ -84,33 +87,36 @@ int modes_test(void)
#ifdef LTC_OFB_MODE #ifdef LTC_OFB_MODE
/* test OFB mode */ /* test OFB mode */
/* encode the block */ /* encode the block */
DO(ofb_start(cipher_idx, iv, key, 16, 0, &ofb)); DO(ret = ofb_start(cipher_idx, iv, key, 16, 0, &ofb));
l = sizeof(iv2); l = sizeof(iv2);
DO(ofb_getiv(iv2, &l, &ofb)); DO(ret = ofb_getiv(iv2, &l, &ofb));
if (l != 16 || memcmp(iv2, iv, 16)) { if (l != 16 || memcmp(iv2, iv, 16)) {
fprintf(stderr, "ofb_getiv failed"); fprintf(stderr, "ofb_getiv failed");
return 1; return 1;
} }
DO(ofb_encrypt(pt, ct, 64, &ofb)); DO(ret = ofb_encrypt(pt, ct, 64, &ofb));
/* decode the block */ /* decode the block */
DO(ofb_setiv(iv2, l, &ofb)); DO(ret = ofb_setiv(iv2, l, &ofb));
zeromem(tmp, sizeof(tmp)); zeromem(tmp, sizeof(tmp));
DO(ofb_decrypt(ct, tmp, 64, &ofb)); DO(ret = ofb_decrypt(ct, tmp, 64, &ofb));
if (memcmp(tmp, pt, 64) != 0) { if (memcmp(tmp, pt, 64) != 0) {
fprintf(stderr, "OFB failed"); fprintf(stderr, "OFB failed");
return 1; return 1;
} }
#endif #endif
#ifdef LTC_CTR_MODE #if defined(LTC_CTR_MODE) && defined(LTC_RIJNDAEL)
DO(ctr_test()); DO(ret = ctr_test());
#endif #endif
#ifdef LTC_XTS_MODE #ifdef LTC_XTS_MODE
DO(xts_test()); DO(ret = xts_test());
#endif #endif
if (ret == CRYPT_NOP)
fprintf(stderr, "NOP");
return 0; return 0;
} }

View File

@ -451,13 +451,14 @@ int time_keysched(void)
int time_cipher(void) int time_cipher(void)
{ {
fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
#ifdef LTC_ECB_MODE
unsigned long x, y1; unsigned long x, y1;
ulong64 t1, t2, c1, c2, a1, a2; ulong64 t1, t2, c1, c2, a1, a2;
symmetric_ECB ecb; symmetric_ECB ecb;
unsigned char key[MAXBLOCKSIZE], pt[4096]; unsigned char key[MAXBLOCKSIZE], pt[4096];
int err; int err;
fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
no_results = 0; no_results = 0;
for (x = 0; cipher_descriptor[x].name != NULL; x++) { for (x = 0; cipher_descriptor[x].name != NULL; x++) {
ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb); ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb);
@ -516,6 +517,9 @@ int time_cipher(void)
#undef DO1 #undef DO1
} }
tally_results(1); tally_results(1);
#else
fprintf(stderr, "NOP");
#endif
return 0; return 0;
} }
@ -1312,6 +1316,7 @@ void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
void time_macs_(unsigned long MAC_SIZE) void time_macs_(unsigned long MAC_SIZE)
{ {
#if defined(LTC_OMAC) || defined(LTC_XCBC) || defined(LTC_F9_MODE) || defined(LTC_PMAC) || defined(LTC_PELICAN) || defined(LTC_HMAC)
unsigned char *buf, key[16], tag[16]; unsigned char *buf, key[16], tag[16];
ulong64 t1, t2; ulong64 t1, t2;
unsigned long x, z; unsigned long x, z;
@ -1433,6 +1438,10 @@ void time_macs_(unsigned long MAC_SIZE)
#endif #endif
XFREE(buf); XFREE(buf);
#else
LTC_UNUSED_PARAM(MAC_SIZE);
fprintf(stderr, "NO MACs\n");
#endif
} }
void time_macs(void) void time_macs(void)
@ -1444,6 +1453,7 @@ void time_macs(void)
void time_encmacs_(unsigned long MAC_SIZE) void time_encmacs_(unsigned long MAC_SIZE)
{ {
#if defined(LTC_EAX_MODE) || defined(LTC_OCB_MODE) || defined(LTC_OCB3_MODE) || defined(LTC_CCM_MODE) || defined(LTC_GCM_MODE)
unsigned char *buf, IV[16], key[16], tag[16]; unsigned char *buf, IV[16], key[16], tag[16];
ulong64 t1, t2; ulong64 t1, t2;
unsigned long x, z; unsigned long x, z;
@ -1600,6 +1610,10 @@ __attribute__ ((aligned (16)))
} }
#endif #endif
#else
LTC_UNUSED_PARAM(MAC_SIZE);
fprintf(stderr, "NO ENCMACs\n");
#endif
} }