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:
@@ -1,5 +1,6 @@
|
||||
#include <tomcrypt_test.h>
|
||||
|
||||
#ifdef LTC_BASE64
|
||||
int base64_test(void)
|
||||
{
|
||||
unsigned char in[64], out[256], tmp[64];
|
||||
@@ -57,6 +58,7 @@ int base64_test(void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
|
||||
+38
-32
@@ -3,8 +3,7 @@
|
||||
|
||||
int modes_test(void)
|
||||
{
|
||||
unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16];
|
||||
int cipher_idx;
|
||||
int ret = CRYPT_NOP;
|
||||
#ifdef LTC_CBC_MODE
|
||||
symmetric_CBC cbc;
|
||||
#endif
|
||||
@@ -14,44 +13,48 @@ int modes_test(void)
|
||||
#ifdef LTC_OFB_MODE
|
||||
symmetric_OFB ofb;
|
||||
#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;
|
||||
|
||||
|
||||
/* make a random pt, key and iv */
|
||||
yarrow_read(pt, 64, &yarrow_prng);
|
||||
yarrow_read(key, 16, &yarrow_prng);
|
||||
yarrow_read(iv, 16, &yarrow_prng);
|
||||
|
||||
|
||||
/* get idx of AES handy */
|
||||
cipher_idx = find_cipher("aes");
|
||||
if (cipher_idx == -1) {
|
||||
fprintf(stderr, "test requires AES");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
DO(f8_test_mode());
|
||||
#endif
|
||||
|
||||
DO(ret = f8_test_mode());
|
||||
#endif
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
DO(lrw_test());
|
||||
DO(ret = lrw_test());
|
||||
#endif
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
/* test CBC mode */
|
||||
/* 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);
|
||||
DO(cbc_getiv(iv2, &l, &cbc));
|
||||
DO(ret = cbc_getiv(iv2, &l, &cbc));
|
||||
if (l != 16 || memcmp(iv2, iv, 16)) {
|
||||
fprintf(stderr, "cbc_getiv failed");
|
||||
return 1;
|
||||
}
|
||||
DO(cbc_encrypt(pt, ct, 64, &cbc));
|
||||
|
||||
DO(ret = cbc_encrypt(pt, ct, 64, &cbc));
|
||||
|
||||
/* decode the block */
|
||||
DO(cbc_setiv(iv2, l, &cbc));
|
||||
DO(ret = cbc_setiv(iv2, l, &cbc));
|
||||
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) {
|
||||
fprintf(stderr, "CBC failed");
|
||||
return 1;
|
||||
@@ -61,56 +64,59 @@ int modes_test(void)
|
||||
#ifdef LTC_CFB_MODE
|
||||
/* test CFB mode */
|
||||
/* 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);
|
||||
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 */
|
||||
if (l != 16) {
|
||||
fprintf(stderr, "cfb_getiv failed");
|
||||
return 1;
|
||||
}
|
||||
DO(cfb_encrypt(pt, ct, 64, &cfb));
|
||||
|
||||
DO(ret = cfb_encrypt(pt, ct, 64, &cfb));
|
||||
|
||||
/* decode the block */
|
||||
DO(cfb_setiv(iv, l, &cfb));
|
||||
DO(ret = cfb_setiv(iv, l, &cfb));
|
||||
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) {
|
||||
fprintf(stderr, "CFB failed");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
/* test OFB mode */
|
||||
/* 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);
|
||||
DO(ofb_getiv(iv2, &l, &ofb));
|
||||
DO(ret = ofb_getiv(iv2, &l, &ofb));
|
||||
if (l != 16 || memcmp(iv2, iv, 16)) {
|
||||
fprintf(stderr, "ofb_getiv failed");
|
||||
return 1;
|
||||
}
|
||||
DO(ofb_encrypt(pt, ct, 64, &ofb));
|
||||
|
||||
DO(ret = ofb_encrypt(pt, ct, 64, &ofb));
|
||||
|
||||
/* decode the block */
|
||||
DO(ofb_setiv(iv2, l, &ofb));
|
||||
DO(ret = ofb_setiv(iv2, l, &ofb));
|
||||
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) {
|
||||
fprintf(stderr, "OFB failed");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
DO(ctr_test());
|
||||
#if defined(LTC_CTR_MODE) && defined(LTC_RIJNDAEL)
|
||||
DO(ret = ctr_test());
|
||||
#endif
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
DO(xts_test());
|
||||
DO(ret = xts_test());
|
||||
#endif
|
||||
|
||||
|
||||
if (ret == CRYPT_NOP)
|
||||
fprintf(stderr, "NOP");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+15
-1
@@ -451,13 +451,14 @@ int time_keysched(void)
|
||||
|
||||
int time_cipher(void)
|
||||
{
|
||||
fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
|
||||
#ifdef LTC_ECB_MODE
|
||||
unsigned long x, y1;
|
||||
ulong64 t1, t2, c1, c2, a1, a2;
|
||||
symmetric_ECB ecb;
|
||||
unsigned char key[MAXBLOCKSIZE], pt[4096];
|
||||
int err;
|
||||
|
||||
fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
|
||||
no_results = 0;
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb);
|
||||
@@ -516,6 +517,9 @@ int time_cipher(void)
|
||||
#undef DO1
|
||||
}
|
||||
tally_results(1);
|
||||
#else
|
||||
fprintf(stderr, "NOP");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1312,6 +1316,7 @@ void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
|
||||
|
||||
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];
|
||||
ulong64 t1, t2;
|
||||
unsigned long x, z;
|
||||
@@ -1433,6 +1438,10 @@ void time_macs_(unsigned long MAC_SIZE)
|
||||
#endif
|
||||
|
||||
XFREE(buf);
|
||||
#else
|
||||
LTC_UNUSED_PARAM(MAC_SIZE);
|
||||
fprintf(stderr, "NO MACs\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void time_macs(void)
|
||||
@@ -1444,6 +1453,7 @@ void time_macs(void)
|
||||
|
||||
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];
|
||||
ulong64 t1, t2;
|
||||
unsigned long x, z;
|
||||
@@ -1600,6 +1610,10 @@ __attribute__ ((aligned (16)))
|
||||
}
|
||||
|
||||
#endif
|
||||
#else
|
||||
LTC_UNUSED_PARAM(MAC_SIZE);
|
||||
fprintf(stderr, "NO ENCMACs\n");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user