diff --git a/build.sh b/build.sh index 590fc443..b1e6de36 100755 --- a/build.sh +++ b/build.sh @@ -15,9 +15,9 @@ fi CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j$MAKE_JOBS -f $3 all_test 1>gcc_1.txt 2>gcc_2.txt mret=$? cnt=$(wc -l < gcc_2.txt) -# ignore 2 lines since ar prints to stderr instead of stdout and ar is called for -# $(LIBNAME) and testprof/$(LIBTEST_S) -if [[ $mret -ne 0 ]] || [[ $cnt -gt 2 ]]; then +# ignore 1 line since ar prints to stderr instead of stdout and ar is called for +# $(LIBNAME) +if [[ $mret -ne 0 ]] || [[ $cnt -gt 1 ]]; then echo "build $1 failed! printing gcc_2.txt now for convenience" cat gcc_2.txt exit 1 diff --git a/coverage_more.sh b/coverage_more.sh index c7eababa..2b8009c7 100755 --- a/coverage_more.sh +++ b/coverage_more.sh @@ -5,7 +5,7 @@ set -e ./sizes ./constants -for i in $(for j in $(echo $(./hashsum -h | tail -n +3)); do echo $j; done | sort); do echo -n "$i: " && ./hashsum -a $i testprof/test.key ; done > hashsum_tv.txt +for i in $(for j in $(echo $(./hashsum -h | tail -n +3)); do echo $j; done | sort); do echo -n "$i: " && ./hashsum -a $i tests/test.key ; done > hashsum_tv.txt difftroubles=$(diff -i -w -B hashsum_tv.txt notes/hashsum_tv.txt | grep '^<') || true if [ -n "$difftroubles" ]; then echo "FAILURE: hashsum_tv.tx" diff --git a/demos/hashsum.c b/demos/hashsum.c index 8a864fb7..24373f45 100644 --- a/demos/hashsum.c +++ b/demos/hashsum.c @@ -27,8 +27,6 @@ '\255') #define HEXOF(x) (x - _base(x)) -static void register_algs(void); - static char* hashsum; static void die(int status) @@ -159,7 +157,8 @@ int main(int argc, char **argv) hashsum = strdup(basename(argv[0])); /* You need to register algorithms before using them */ - register_algs(); + register_all_ciphers(); + register_all_hashes(); if (argc > 1 && (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0)) { die(EXIT_SUCCESS); } @@ -261,87 +260,6 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } -static void register_algs(void) -{ - int err; - LTC_UNUSED_PARAM(err); - -#ifdef LTC_TIGER - register_hash (&tiger_desc); -#endif -#ifdef LTC_MD2 - register_hash (&md2_desc); -#endif -#ifdef LTC_MD4 - register_hash (&md4_desc); -#endif -#ifdef LTC_MD5 - register_hash (&md5_desc); -#endif -#ifdef LTC_SHA1 - register_hash (&sha1_desc); -#endif -#ifdef LTC_SHA224 - register_hash (&sha224_desc); -#endif -#ifdef LTC_SHA256 - register_hash (&sha256_desc); -#endif -#ifdef LTC_SHA384 - register_hash (&sha384_desc); -#endif -#ifdef LTC_SHA512 - register_hash (&sha512_desc); -#endif -#ifdef LTC_SHA512_224 - register_hash (&sha512_224_desc); -#endif -#ifdef LTC_SHA512_256 - register_hash (&sha512_256_desc); -#endif -#ifdef LTC_SHA3 - register_hash (&sha3_224_desc); - register_hash (&sha3_256_desc); - register_hash (&sha3_384_desc); - register_hash (&sha3_512_desc); -#endif -#ifdef LTC_RIPEMD128 - register_hash (&rmd128_desc); -#endif -#ifdef LTC_RIPEMD160 - register_hash (&rmd160_desc); -#endif -#ifdef LTC_RIPEMD256 - register_hash (&rmd256_desc); -#endif -#ifdef LTC_RIPEMD320 - register_hash (&rmd320_desc); -#endif -#ifdef LTC_WHIRLPOOL - register_hash (&whirlpool_desc); -#endif -#ifdef LTC_BLAKE2S - register_hash (&blake2s_128_desc); - register_hash (&blake2s_160_desc); - register_hash (&blake2s_224_desc); - register_hash (&blake2s_256_desc); -#endif -#ifdef LTC_BLAKE2B - register_hash (&blake2b_160_desc); - register_hash (&blake2b_256_desc); - register_hash (&blake2b_384_desc); - register_hash (&blake2b_512_desc); -#endif -#ifdef LTC_CHC_HASH - register_hash(&chc_desc); - if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) { - printf("chc_register error: %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } -#endif - -} - /* $Source$ */ /* $Revision$ */ /* $Date$ */ diff --git a/demos/ltcrypt.c b/demos/ltcrypt.c index 75aee702..d4f16d81 100644 --- a/demos/ltcrypt.c +++ b/demos/ltcrypt.c @@ -22,74 +22,6 @@ int usage(char *name) exit(1); } -void register_algs(void) -{ -#ifdef LTC_RIJNDAEL - register_cipher (&aes_desc); -#endif -#ifdef LTC_BLOWFISH - register_cipher (&blowfish_desc); -#endif -#ifdef LTC_XTEA - register_cipher (&xtea_desc); -#endif -#ifdef LTC_RC5 - register_cipher (&rc5_desc); -#endif -#ifdef LTC_RC6 - register_cipher (&rc6_desc); -#endif -#ifdef LTC_SAFERP - register_cipher (&saferp_desc); -#endif -#ifdef LTC_TWOFISH - register_cipher (&twofish_desc); -#endif -#ifdef LTC_SAFER - register_cipher (&safer_k64_desc); - register_cipher (&safer_sk64_desc); - register_cipher (&safer_k128_desc); - register_cipher (&safer_sk128_desc); -#endif -#ifdef LTC_RC2 - register_cipher (&rc2_desc); -#endif -#ifdef LTC_DES - register_cipher (&des_desc); - register_cipher (&des3_desc); -#endif -#ifdef LTC_CAST5 - register_cipher (&cast5_desc); -#endif -#ifdef LTC_NOEKEON - register_cipher (&noekeon_desc); -#endif -#ifdef LTC_SKIPJACK - register_cipher (&skipjack_desc); -#endif -#ifdef LTC_KHAZAD - register_cipher (&khazad_desc); -#endif -#ifdef LTC_ANUBIS - register_cipher (&anubis_desc); -#endif - - if (register_hash(&sha256_desc) == -1) { - printf("Error registering LTC_SHA256\n"); - exit(-1); - } - - if (register_prng(&yarrow_desc) == -1) { - printf("Error registering yarrow PRNG\n"); - exit(-1); - } - - if (register_prng(&sprng_desc) == -1) { - printf("Error registering sprng PRNG\n"); - exit(-1); - } -} - int main(int argc, char *argv[]) { unsigned char plaintext[512],ciphertext[512]; @@ -104,7 +36,8 @@ int main(int argc, char *argv[]) int err; /* register algs, so they can be printed */ - register_algs(); + register_all_ciphers(); + register_all_hashes(); if (argc < 4) { if ((argc > 2) && (!strcmp(argv[1], "-t"))) { diff --git a/demos/test.c b/demos/test.c deleted file mode 100644 index 3474f7e0..00000000 --- a/demos/test.c +++ /dev/null @@ -1,114 +0,0 @@ -#include - -#ifndef GIT_VERSION -#define GIT_VERSION "Undefined version" -#endif - -#define LTC_TEST_FN(f) { f, #f } - -static const struct { - int (*fn)(void); - const char* name; -} test_functions[] = -{ - LTC_TEST_FN(store_test), - LTC_TEST_FN(rotate_test), - LTC_TEST_FN(misc_test), - LTC_TEST_FN(cipher_hash_test), - LTC_TEST_FN(mac_test), - LTC_TEST_FN(modes_test), - LTC_TEST_FN(der_tests), - LTC_TEST_FN(pkcs_1_test), - LTC_TEST_FN(pkcs_1_pss_test), - LTC_TEST_FN(pkcs_1_oaep_test), - LTC_TEST_FN(pkcs_1_emsa_test), - LTC_TEST_FN(pkcs_1_eme_test), - LTC_TEST_FN(rsa_test), - LTC_TEST_FN(dh_test), - LTC_TEST_FN(ecc_tests), - LTC_TEST_FN(dsa_test), - LTC_TEST_FN(katja_test), - LTC_TEST_FN(file_test), - LTC_TEST_FN(multi_test), -}; - -int main(int argc, char **argv) -{ - int x, pass = 0, fail = 0, nop = 0; - size_t fn_len, i, dots; - char *single_test = NULL; - ulong64 ts; - long delta, dur = 0; - reg_algs(); - - printf("build == %s\n%s\n", GIT_VERSION, crypt_build_settings); - -#ifdef USE_LTM - ltc_mp = ltm_desc; - printf("math provider = libtommath\n"); -#elif defined(USE_TFM) - ltc_mp = tfm_desc; - printf("math provider = tomsfastmath\n"); -#elif defined(USE_GMP) - ltc_mp = gmp_desc; - printf("math provider = gnump\n"); -#else - extern ltc_math_descriptor EXT_MATH_LIB; - ltc_mp = EXT_MATH_LIB; - printf("math provider = EXT_MATH_LIB\n"); -#endif - printf("MP_DIGIT_BIT = %d\n", MP_DIGIT_BIT); - - fn_len = 0; - for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) { - size_t len = strlen(test_functions[i].name); - if (fn_len < len) fn_len = len; - } - - fn_len = fn_len + (4 - (fn_len % 4)); - - /* single test name from commandline */ - if (argc > 1) single_test = argv[1]; - - for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) { - if (single_test && strcmp(test_functions[i].name, single_test)) { - continue; - } - dots = fn_len - strlen(test_functions[i].name); - - printf("\n%s", test_functions[i].name); - while(dots--) printf("."); - fflush(stdout); - - ts = epoch_usec(); - x = test_functions[i].fn(); - delta = (long)(epoch_usec() - ts); - dur += delta; - - if (x == CRYPT_OK) { - printf("passed %10.3fms", (double)(delta)/1000); - pass++; - } - else if (x == CRYPT_NOP) { - printf("nop"); - nop++; - } - else { - printf("failed %10.3fms", (double)(delta)/1000); - fail++; - } - } - - if (fail > 0 || fail+pass+nop == 0) { - printf("\n\nFAILURE: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000)); - return EXIT_FAILURE; - } - else { - printf("\n\nSUCCESS: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000)); - return EXIT_SUCCESS; - } -} - -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/demos/timing.c b/demos/timing.c index 76fd8cd1..f03d74f4 100644 --- a/demos/timing.c +++ b/demos/timing.c @@ -1,10 +1,1359 @@ -#include +#include + +#if defined(_WIN32) + #define PRI64 "I64d" +#else + #define PRI64 "ll" +#endif + +static prng_state yarrow_prng; + +/* timing */ +#define KTIMES 25 +#define TIMES 100000 + +static struct list { + int id; + ulong64 spd1, spd2, avg; +} results[100]; +static int no_results; + +static int sorter(const void *a, const void *b) +{ + const struct list *A, *B; + A = a; + B = b; + if (A->avg < B->avg) return -1; + if (A->avg > B->avg) return 1; + return 0; +} + +static void tally_results(int type) +{ + int x; + + /* qsort the results */ + qsort(results, no_results, sizeof(struct list), &sorter); + + fprintf(stderr, "\n"); + if (type == 0) { + for (x = 0; x < no_results; x++) { + fprintf(stderr, "%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1); + } + } else if (type == 1) { + for (x = 0; x < no_results; x++) { + printf + ("%-20s[%3d]: Encrypt at %5"PRI64"u, Decrypt at %5"PRI64"u\n", cipher_descriptor[results[x].id].name, cipher_descriptor[results[x].id].ID, results[x].spd1, results[x].spd2); + } + } else { + for (x = 0; x < no_results; x++) { + printf + ("%-20s: Process at %5"PRI64"u\n", hash_descriptor[results[x].id].name, results[x].spd1 / 1000); + } + } +} + +/* RDTSC from Scott Duplichan */ +static ulong64 rdtsc (void) + { + #if defined __GNUC__ && !defined(LTC_NO_ASM) + #if defined(__i386__) || defined(__x86_64__) + /* version from http://www.mcs.anl.gov/~kazutomo/rdtsc.html + * the old code always got a warning issued by gcc, clang did not complain... + */ + unsigned hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ((ulong64)lo)|( ((ulong64)hi)<<32); + #elif defined(LTC_PPC32) || defined(TFM_PPC32) + unsigned long a, b; + __asm__ __volatile__ ("mftbu %1 \nmftb %0\n":"=r"(a), "=r"(b)); + return (((ulong64)b) << 32ULL) | ((ulong64)a); + #elif defined(__ia64__) /* gcc-IA64 version */ + unsigned long result; + __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); + while (__builtin_expect ((int) result == -1, 0)) + __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); + return result; + #elif defined(__sparc__) + #if defined(__arch64__) + ulong64 a; + asm volatile("rd %%tick,%0" : "=r" (a)); + return a; + #else + register unsigned long x, y; + __asm__ __volatile__ ("rd %%tick, %0; clruw %0, %1; srlx %0, 32, %0" : "=r" (x), "=r" (y) : "0" (x), "1" (y)); + return ((unsigned long long) x << 32) | y; + #endif + #else + return XCLOCK(); + #endif + + /* Microsoft and Intel Windows compilers */ + #elif defined _M_IX86 && !defined(LTC_NO_ASM) + __asm rdtsc + #elif defined _M_AMD64 && !defined(LTC_NO_ASM) + return __rdtsc (); + #elif defined _M_IA64 && !defined(LTC_NO_ASM) + #if defined __INTEL_COMPILER + #include + #endif + return __getReg (3116); + #else + return XCLOCK(); + #endif + } + +static ulong64 timer, skew = 0; + +static void t_start(void) +{ + timer = rdtsc(); +} + +static ulong64 t_read(void) +{ + return rdtsc() - timer; +} + +static void init_timer(void) +{ + ulong64 c1, c2, t1, t2; + unsigned long y1; + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < TIMES*100; y1++) { + t_start(); + t1 = t_read(); + t2 = (t_read() - t1)>>1; + + c1 = (t1 > c1) ? t1 : c1; + c2 = (t2 > c2) ? t2 : c2; + } + skew = c2 - c1; + fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew); +} + +static int time_keysched(void) +{ + unsigned long x, y1; + ulong64 t1, c1; + symmetric_key skey; + int kl; + int (*func) (const unsigned char *, int , int , symmetric_key *); + unsigned char key[MAXBLOCKSIZE]; + + fprintf(stderr, "\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n"); + no_results = 0; + for (x = 0; cipher_descriptor[x].name != NULL; x++) { +#define DO1(k) func(k, kl, 0, &skey); + + func = cipher_descriptor[x].setup; + kl = cipher_descriptor[x].min_key_length; + c1 = (ulong64)-1; + for (y1 = 0; y1 < KTIMES; y1++) { + yarrow_read(key, kl, &yarrow_prng); + t_start(); + DO1(key); + t1 = t_read(); + c1 = (t1 > c1) ? c1 : t1; + } + t1 = c1 - skew; + results[no_results].spd1 = results[no_results].avg = t1; + results[no_results++].id = x; + fprintf(stderr, "."); fflush(stdout); + +#undef DO1 + } + tally_results(0); + + return 0; +} + +#ifdef LTC_ECB_MODE +static int time_cipher_ecb(void) +{ + 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); + + /* sanity check on cipher */ + if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { + fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + +#define DO1 ecb_encrypt(pt, pt, sizeof(pt), &ecb); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a1 = c2 - c1 - skew; + +#undef DO1 +#undef DO2 +#define DO1 ecb_decrypt(pt, pt, sizeof(pt), &ecb); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a2 = c2 - c1 - skew; + ecb_done(&ecb); + + results[no_results].id = x; + results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; + ++no_results; + fprintf(stderr, "."); fflush(stdout); + +#undef DO2 +#undef DO1 + } + tally_results(1); + + return 0; +} +#else +static int time_cipher_ecb(void) { fprintf(stderr, "NO ECB\n"); return 0; } +#endif + +#ifdef LTC_CBC_MODE +static int time_cipher_cbc(void) +{ + unsigned long x, y1; + ulong64 t1, t2, c1, c2, a1, a2; + symmetric_CBC cbc; + unsigned char key[MAXBLOCKSIZE], pt[4096]; + int err; + + fprintf(stderr, "\n\nCBC Time Trials for the Symmetric Ciphers:\n"); + no_results = 0; + for (x = 0; cipher_descriptor[x].name != NULL; x++) { + cbc_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &cbc); + + /* sanity check on cipher */ + if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { + fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + +#define DO1 cbc_encrypt(pt, pt, sizeof(pt), &cbc); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a1 = c2 - c1 - skew; + +#undef DO1 +#undef DO2 +#define DO1 cbc_decrypt(pt, pt, sizeof(pt), &cbc); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a2 = c2 - c1 - skew; + cbc_done(&cbc); + + results[no_results].id = x; + results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; + ++no_results; + fprintf(stderr, "."); fflush(stdout); + +#undef DO2 +#undef DO1 + } + tally_results(1); + + return 0; +} +#else +static int time_cipher_cbc(void) { fprintf(stderr, "NO CBC\n"); return 0; } +#endif + +#ifdef LTC_CTR_MODE +static int time_cipher_ctr(void) +{ + unsigned long x, y1; + ulong64 t1, t2, c1, c2, a1, a2; + symmetric_CTR ctr; + unsigned char key[MAXBLOCKSIZE], pt[4096]; + int err; + + fprintf(stderr, "\n\nCTR Time Trials for the Symmetric Ciphers:\n"); + no_results = 0; + for (x = 0; cipher_descriptor[x].name != NULL; x++) { + ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr); + + /* sanity check on cipher */ + if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { + fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + +#define DO1 ctr_encrypt(pt, pt, sizeof(pt), &ctr); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a1 = c2 - c1 - skew; + +#undef DO1 +#undef DO2 +#define DO1 ctr_decrypt(pt, pt, sizeof(pt), &ctr); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a2 = c2 - c1 - skew; + ctr_done(&ctr); + + results[no_results].id = x; + results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; + ++no_results; + fprintf(stderr, "."); fflush(stdout); + +#undef DO2 +#undef DO1 + } + tally_results(1); + + return 0; +} +#else +static int time_cipher_ctr(void) { fprintf(stderr, "NO CTR\n"); return 0; } +#endif + +#ifdef LTC_LRW_MODE +static int time_cipher_lrw(void) +{ + unsigned long x, y1; + ulong64 t1, t2, c1, c2, a1, a2; + symmetric_LRW lrw; + unsigned char key[MAXBLOCKSIZE], pt[4096]; + int err; + + fprintf(stderr, "\n\nLRW Time Trials for the Symmetric Ciphers:\n"); + no_results = 0; + for (x = 0; cipher_descriptor[x].name != NULL; x++) { + if (cipher_descriptor[x].block_length != 16) continue; + lrw_start(x, pt, key, cipher_descriptor[x].min_key_length, key, 0, &lrw); + + /* sanity check on cipher */ + if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { + fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + +#define DO1 lrw_encrypt(pt, pt, sizeof(pt), &lrw); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a1 = c2 - c1 - skew; + +#undef DO1 +#undef DO2 +#define DO1 lrw_decrypt(pt, pt, sizeof(pt), &lrw); +#define DO2 DO1 DO1 + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < 100; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read(); + t2 -= t1; + + c1 = (t1 > c1 ? c1 : t1); + c2 = (t2 > c2 ? c2 : t2); + } + a2 = c2 - c1 - skew; + + lrw_done(&lrw); + + results[no_results].id = x; + results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); + results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; + ++no_results; + fprintf(stderr, "."); fflush(stdout); + +#undef DO2 +#undef DO1 + } + tally_results(1); + + return 0; +} +#else +static int time_cipher_lrw(void) { fprintf(stderr, "NO LRW\n"); return 0; } +#endif + + +static int time_hash(void) +{ + unsigned long x, y1, len; + ulong64 t1, t2, c1, c2; + hash_state md; + int (*func)(hash_state *, const unsigned char *, unsigned long), err; + unsigned char pt[MAXBLOCKSIZE]; + + + fprintf(stderr, "\n\nHASH Time Trials for:\n"); + no_results = 0; + for (x = 0; hash_descriptor[x].name != NULL; x++) { + + /* sanity check on hash */ + if ((err = hash_descriptor[x].test()) != CRYPT_OK) { + fprintf(stderr, "\n\nERROR: Hash %s failed self-test %s\n", hash_descriptor[x].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + + hash_descriptor[x].init(&md); + +#define DO1 func(&md,pt,len); +#define DO2 DO1 DO1 + + func = hash_descriptor[x].process; + len = hash_descriptor[x].blocksize; + + c1 = c2 = (ulong64)-1; + for (y1 = 0; y1 < TIMES; y1++) { + t_start(); + DO1; + t1 = t_read(); + DO2; + t2 = t_read() - t1; + c1 = (t1 > c1) ? c1 : t1; + c2 = (t2 > c2) ? c2 : t2; + } + t1 = c2 - c1 - skew; + t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize); + results[no_results].id = x; + results[no_results].spd1 = results[no_results].avg = t1; + ++no_results; + fprintf(stderr, "."); fflush(stdout); +#undef DO2 +#undef DO1 + } + tally_results(2); + + return 0; +} + +/*#warning you need an mp_rand!!!*/ +#ifndef USE_LTM + #undef LTC_MPI +#endif + +#ifdef LTC_MPI +static void time_mult(void) +{ + ulong64 t1, t2; + unsigned long x, y; + void *a, *b, *c; + + fprintf(stderr, "Timing Multiplying:\n"); + mp_init_multi(&a,&b,&c,NULL); + for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) { + mp_rand(a, x); + mp_rand(b, x); + +#define DO1 mp_mul(a, b, c); +#define DO2 DO1; DO1; + + t2 = -1; + for (y = 0; y < TIMES; y++) { + t_start(); + t1 = t_read(); + DO2; + t1 = (t_read() - t1)>>1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2); + } + mp_clear_multi(a,b,c,NULL); + +#undef DO1 +#undef DO2 +} + +static void time_sqr(void) +{ + ulong64 t1, t2; + unsigned long x, y; + void *a, *b; + + fprintf(stderr, "Timing Squaring:\n"); + mp_init_multi(&a,&b,NULL); + for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) { + mp_rand(a, x); + +#define DO1 mp_sqr(a, b); +#define DO2 DO1; DO1; + + t2 = -1; + for (y = 0; y < TIMES; y++) { + t_start(); + t1 = t_read(); + DO2; + t1 = (t_read() - t1)>>1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2); + } + mp_clear_multi(a,b,NULL); + +#undef DO1 +#undef DO2 +} +#else +static void time_mult(void) { fprintf(stderr, "NO MULT\n"); } +static void time_sqr(void) { fprintf(stderr, "NO SQR\n"); } +#endif + +static void time_prng(void) +{ + ulong64 t1, t2; + unsigned char buf[4096]; + prng_state tprng; + unsigned long x, y; + int err; + + fprintf(stderr, "Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n"); + for (x = 0; prng_descriptor[x].name != NULL; x++) { + + /* sanity check on prng */ + if ((err = prng_descriptor[x].test()) != CRYPT_OK) { + fprintf(stderr, "\n\nERROR: PRNG %s failed self-test %s\n", prng_descriptor[x].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + + prng_descriptor[x].start(&tprng); + zeromem(buf, 256); + prng_descriptor[x].add_entropy(buf, 256, &tprng); + prng_descriptor[x].ready(&tprng); + t2 = -1; + +#define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); } +#define DO2 DO1 DO1 + for (y = 0; y < 10000; y++) { + t_start(); + t1 = t_read(); + DO2; + t1 = (t_read() - t1)>>1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "%20s: %5"PRI64"u ", prng_descriptor[x].name, t2>>12); +#undef DO2 +#undef DO1 + +#define DO1 prng_descriptor[x].start(&tprng); prng_descriptor[x].add_entropy(buf, 32, &tprng); prng_descriptor[x].ready(&tprng); prng_descriptor[x].done(&tprng); +#define DO2 DO1 DO1 + for (y = 0; y < 10000; y++) { + t_start(); + t1 = t_read(); + DO2; + t1 = (t_read() - t1)>>1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "%5"PRI64"u\n", t2); +#undef DO2 +#undef DO1 + + } +} + +#ifdef LTC_MDSA +/* time various DSA operations */ +static void time_dsa(void) +{ + dsa_key key; + ulong64 t1, t2; + unsigned long x, y; + int err; +static const struct { + int group, modulus; +} groups[] = { +{ 20, 96 }, +{ 20, 128 }, +{ 24, 192 }, +{ 28, 256 }, +{ 32, 512 } +}; + + for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) { + t2 = 0; + for (y = 0; y < 4; y++) { + t_start(); + t1 = t_read(); + if ((err = dsa_make_key(&yarrow_prng, find_prng("yarrow"), groups[x].group, groups[x].modulus, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\ndsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; + +#ifdef LTC_PROFILE + t2 <<= 2; + break; +#endif + if (y < 3) { + dsa_free(&key); + } + } + t2 >>= 2; + fprintf(stderr, "DSA-(%lu, %lu) make_key took %15"PRI64"u cycles\n", (unsigned long)groups[x].group*8, (unsigned long)groups[x].modulus*8, t2); + } + fprintf(stderr, "\n\n"); +} +#else +static void time_dsa(void) { fprintf(stderr, "NO DSA\n"); } +#endif + + +#ifdef LTC_MRSA +/* time various RSA operations */ +static void time_rsa(void) +{ + rsa_key key; + ulong64 t1, t2; + unsigned char buf[2][2048]; + unsigned long x, y, z, zzz; + int err, zz, stat; + + for (x = 1024; x <= 2048; x += 256) { + t2 = 0; + for (y = 0; y < 4; y++) { + t_start(); + t1 = t_read(); + if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nrsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; + +#ifdef LTC_PROFILE + t2 <<= 2; + break; +#endif + + if (y < 3) { + rsa_free(&key); + } + } + t2 >>= 2; + fprintf(stderr, "RSA-%lu make_key took %15"PRI64"u cycles\n", x, t2); + + t2 = 0; + for (y = 0; y < 16; y++) { + t_start(); + t1 = t_read(); + z = sizeof(buf[1]); + if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, (const unsigned char *)"testprog", 8, &yarrow_prng, + find_prng("yarrow"), find_hash("sha1"), + &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 4; + break; +#endif + } + t2 >>= 4; + fprintf(stderr, "RSA-%lu encrypt_key took %15"PRI64"u cycles\n", x, t2); + + t2 = 0; + for (y = 0; y < 2048; y++) { + t_start(); + t1 = t_read(); + zzz = sizeof(buf[0]); + if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, (const unsigned char *)"testprog", 8, find_hash("sha1"), + &zz, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 11; + break; +#endif + } + t2 >>= 11; + fprintf(stderr, "RSA-%lu decrypt_key took %15"PRI64"u cycles\n", x, t2); + + t2 = 0; + for (y = 0; y < 256; y++) { + t_start(); + t1 = t_read(); + z = sizeof(buf[1]); + if ((err = rsa_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng, + find_prng("yarrow"), find_hash("sha1"), 8, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nrsa_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 8; + break; +#endif + } + t2 >>= 8; + fprintf(stderr, "RSA-%lu sign_hash took %15"PRI64"u cycles\n", x, t2); + + t2 = 0; + for (y = 0; y < 2048; y++) { + t_start(); + t1 = t_read(); + if ((err = rsa_verify_hash(buf[1], z, buf[0], 20, find_hash("sha1"), 8, &stat, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nrsa_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + if (stat == 0) { + fprintf(stderr, "\n\nrsa_verify_hash for RSA-%lu failed to verify signature(%lu)\n", x, y); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 11; + break; +#endif + } + t2 >>= 11; + fprintf(stderr, "RSA-%lu verify_hash took %15"PRI64"u cycles\n", x, t2); + fprintf(stderr, "\n\n"); + rsa_free(&key); + } +} +#else +static void time_rsa(void) { fprintf(stderr, "NO RSA\n"); } +#endif + +#ifdef LTC_MKAT +/* time various KAT operations */ +static void time_katja(void) +{ + katja_key key; + ulong64 t1, t2; + unsigned char buf[2][4096]; + unsigned long x, y, z, zzz; + int err, zz; + + for (x = 1024; x <= 2048; x += 256) { + t2 = 0; + for (y = 0; y < 4; y++) { + t_start(); + t1 = t_read(); + if ((err = katja_make_key(&yarrow_prng, find_prng("yarrow"), x/8, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nkatja_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; + + if (y < 3) { + katja_free(&key); + } + } + t2 >>= 2; + fprintf(stderr, "Katja-%lu make_key took %15"PRI64"u cycles\n", x, t2); + + t2 = 0; + for (y = 0; y < 16; y++) { + t_start(); + t1 = t_read(); + z = sizeof(buf[1]); + if ((err = katja_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng, + find_prng("yarrow"), find_hash("sha1"), + &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nkatja_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; + } + t2 >>= 4; + fprintf(stderr, "Katja-%lu encrypt_key took %15"PRI64"u cycles\n", x, t2); + + t2 = 0; + for (y = 0; y < 2048; y++) { + t_start(); + t1 = t_read(); + zzz = sizeof(buf[0]); + if ((err = katja_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"), + &zz, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\nkatja_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; + } + t2 >>= 11; + fprintf(stderr, "Katja-%lu decrypt_key took %15"PRI64"u cycles\n", x, t2); + + + katja_free(&key); + } +} +#else +static void time_katja(void) { fprintf(stderr, "NO Katja\n"); } +#endif + +#ifdef LTC_MECC +/* time various ECC operations */ +static void time_ecc(void) +{ + ecc_key key; + ulong64 t1, t2; + unsigned char buf[2][256]; + unsigned long i, w, x, y, z; + int err, stat; + static unsigned long sizes[] = { +#ifdef LTC_ECC112 +112/8, +#endif +#ifdef LTC_ECC128 +128/8, +#endif +#ifdef LTC_ECC160 +160/8, +#endif +#ifdef LTC_ECC192 +192/8, +#endif +#ifdef LTC_ECC224 +224/8, +#endif +#ifdef LTC_ECC256 +256/8, +#endif +#ifdef LTC_ECC384 +384/8, +#endif +#ifdef LTC_ECC521 +521/8, +#endif +100000}; + + for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { + t2 = 0; + for (y = 0; y < 256; y++) { + t_start(); + t1 = t_read(); + if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; + +#ifdef LTC_PROFILE + t2 <<= 8; + break; +#endif + + if (y < 255) { + ecc_free(&key); + } + } + t2 >>= 8; + fprintf(stderr, "ECC-%lu make_key took %15"PRI64"u cycles\n", x*8, t2); + + t2 = 0; + for (y = 0; y < 256; y++) { + t_start(); + t1 = t_read(); + z = sizeof(buf[1]); + if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), + &key)) != CRYPT_OK) { + fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 8; + break; +#endif + } + t2 >>= 8; + fprintf(stderr, "ECC-%lu encrypt_key took %15"PRI64"u cycles\n", x*8, t2); + + t2 = 0; + for (y = 0; y < 256; y++) { + t_start(); + t1 = t_read(); + w = 20; + if ((err = ecc_decrypt_key(buf[1], z, buf[0], &w, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\necc_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 8; + break; +#endif + } + t2 >>= 8; + fprintf(stderr, "ECC-%lu decrypt_key took %15"PRI64"u cycles\n", x*8, t2); + + t2 = 0; + for (y = 0; y < 256; y++) { + t_start(); + t1 = t_read(); + z = sizeof(buf[1]); + if ((err = ecc_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng, + find_prng("yarrow"), &key)) != CRYPT_OK) { + fprintf(stderr, "\n\necc_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 8; + break; +#endif + } + t2 >>= 8; + fprintf(stderr, "ECC-%lu sign_hash took %15"PRI64"u cycles\n", x*8, t2); + + t2 = 0; + for (y = 0; y < 256; y++) { + t_start(); + t1 = t_read(); + if ((err = ecc_verify_hash(buf[1], z, buf[0], 20, &stat, &key)) != CRYPT_OK) { + fprintf(stderr, "\n\necc_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); + exit(EXIT_FAILURE); + } + if (stat == 0) { + fprintf(stderr, "\n\necc_verify_hash for ECC-%lu failed to verify signature(%lu)\n", x*8, y); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + t2 += t1; +#ifdef LTC_PROFILE + t2 <<= 8; + break; +#endif + } + t2 >>= 8; + fprintf(stderr, "ECC-%lu verify_hash took %15"PRI64"u cycles\n", x*8, t2); + + fprintf(stderr, "\n\n"); + ecc_free(&key); + } +} +#else +static void time_ecc(void) { fprintf(stderr, "NO ECC\n"); } +#endif + +static 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; + int err, cipher_idx, hash_idx; + + fprintf(stderr, "\nMAC Timings (cycles/byte on %luKB blocks):\n", MAC_SIZE); + + buf = XMALLOC(MAC_SIZE*1024); + if (buf == NULL) { + fprintf(stderr, "\n\nout of heap yo\n\n"); + exit(EXIT_FAILURE); + } + + cipher_idx = find_cipher("aes"); + hash_idx = find_hash("sha1"); + + if (cipher_idx == -1 || hash_idx == -1) { + fprintf(stderr, "Warning the MAC tests requires AES and SHA1 to operate... so sorry\n"); + exit(EXIT_FAILURE); + } + + yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); + yarrow_read(key, 16, &yarrow_prng); + +#ifdef LTC_OMAC + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = omac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\n\nomac-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "OMAC-%s\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_XCBC + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = xcbc_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\n\nxcbc-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "XCBC-%s\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_F9_MODE + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = f9_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\n\nF9-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "F9-%s\t\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_PMAC + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = pmac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\n\npmac-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "PMAC-%s\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_PELICAN + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = pelican_memory(key, 16, buf, MAC_SIZE*1024, tag)) != CRYPT_OK) { + fprintf(stderr, "\n\npelican error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "PELICAN \t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_HMAC + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = hmac_memory(hash_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\n\nhmac-%s error... %s\n", hash_descriptor[hash_idx].name, error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "HMAC-%s\t\t%9"PRI64"u\n", hash_descriptor[hash_idx].name, t2/(ulong64)(MAC_SIZE*1024)); +#endif + + XFREE(buf); +#else + LTC_UNUSED_PARAM(MAC_SIZE); + fprintf(stderr, "NO MACs\n"); +#endif +} + +static void time_macs(void) +{ + time_macs_(1); + time_macs_(4); + time_macs_(32); +} + +static 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; + int err, cipher_idx; + symmetric_key skey; + + fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE); + + buf = XMALLOC(MAC_SIZE*1024); + if (buf == NULL) { + fprintf(stderr, "\n\nout of heap yo\n\n"); + exit(EXIT_FAILURE); + } + + cipher_idx = find_cipher("aes"); + + yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); + yarrow_read(key, 16, &yarrow_prng); + yarrow_read(IV, 16, &yarrow_prng); + +#ifdef LTC_EAX_MODE + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = eax_encrypt_authenticate_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\nEAX error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "EAX \t\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_OCB_MODE + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = ocb_encrypt_authenticate_memory(cipher_idx, key, 16, IV, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\nOCB error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "OCB \t\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_OCB3_MODE + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = ocb3_encrypt_authenticate_memory(cipher_idx, key, 16, IV, 16, (unsigned char*)"", 0, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\nOCB3 error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "OCB3 \t\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); +#endif + +#ifdef LTC_CCM_MODE + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = ccm_memory(cipher_idx, key, 16, NULL, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { + fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "CCM (no-precomp) \t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); + + cipher_descriptor[cipher_idx].setup(key, 16, 0, &skey); + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = ccm_memory(cipher_idx, key, 16, &skey, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { + fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "CCM (precomp) \t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); + cipher_descriptor[cipher_idx].done(&skey); +#endif + +#ifdef LTC_GCM_MODE + t2 = -1; + for (x = 0; x < 100; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = gcm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, GCM_ENCRYPT)) != CRYPT_OK) { + fprintf(stderr, "\nGCM error... %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "GCM (no-precomp)\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); + + { + gcm_state gcm +#ifdef LTC_GCM_TABLES_SSE2 +__attribute__ ((aligned (16))) +#endif +; + + if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); } + t2 = -1; + for (x = 0; x < 10000; x++) { + t_start(); + t1 = t_read(); + z = 16; + if ((err = gcm_reset(&gcm)) != CRYPT_OK) { + fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); + exit(EXIT_FAILURE); + } + if ((err = gcm_add_iv(&gcm, IV, 16)) != CRYPT_OK) { + fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); + exit(EXIT_FAILURE); + } + if ((err = gcm_add_aad(&gcm, NULL, 0)) != CRYPT_OK) { + fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); + exit(EXIT_FAILURE); + } + if ((err = gcm_process(&gcm, buf, MAC_SIZE*1024, buf, GCM_ENCRYPT)) != CRYPT_OK) { + fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); + exit(EXIT_FAILURE); + } + + if ((err = gcm_done(&gcm, tag, &z)) != CRYPT_OK) { + fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); + exit(EXIT_FAILURE); + } + t1 = t_read() - t1; + if (t1 < t2) t2 = t1; + } + fprintf(stderr, "GCM (precomp)\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); + } + +#endif +#else + LTC_UNUSED_PARAM(MAC_SIZE); + fprintf(stderr, "NO ENCMACs\n"); +#endif + +} + +static void time_encmacs(void) +{ + time_encmacs_(1); + time_encmacs_(4); + time_encmacs_(32); +} int main(void) { - +int err; init_timer(); -reg_algs(); +register_all_ciphers(); +register_all_hashes(); +register_all_prngs(); #ifdef USE_LTM ltc_mp = ltm_desc; @@ -17,11 +1366,16 @@ reg_algs(); ltc_mp = EXT_MATH_LIB; #endif +if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { + fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); +} + time_keysched(); -time_cipher(); -time_cipher2(); -time_cipher3(); -time_cipher4(); +time_cipher_ecb(); +time_cipher_cbc(); +time_cipher_ctr(); +time_cipher_lrw(); time_hash(); time_macs(); time_encmacs(); @@ -29,10 +1383,9 @@ time_prng(); time_mult(); time_sqr(); time_rsa(); +time_dsa(); time_ecc(); -#ifdef USE_LTM time_katja(); -#endif return EXIT_SUCCESS; } diff --git a/demos/tv_gen.c b/demos/tv_gen.c index 5acb28b0..93de2db8 100644 --- a/demos/tv_gen.c +++ b/demos/tv_gen.c @@ -1,151 +1,5 @@ #include -void reg_algs(void) -{ - int err; - LTC_UNUSED_PARAM(err); - -#ifdef LTC_RIJNDAEL - register_cipher (&aes_desc); -#endif -#ifdef LTC_BLOWFISH - register_cipher (&blowfish_desc); -#endif -#ifdef LTC_XTEA - register_cipher (&xtea_desc); -#endif -#ifdef LTC_RC5 - register_cipher (&rc5_desc); -#endif -#ifdef LTC_RC6 - register_cipher (&rc6_desc); -#endif -#ifdef LTC_SAFERP - register_cipher (&saferp_desc); -#endif -#ifdef LTC_TWOFISH - register_cipher (&twofish_desc); -#endif -#ifdef LTC_SAFER - register_cipher (&safer_k64_desc); - register_cipher (&safer_sk64_desc); - register_cipher (&safer_k128_desc); - register_cipher (&safer_sk128_desc); -#endif -#ifdef LTC_RC2 - register_cipher (&rc2_desc); -#endif -#ifdef LTC_DES - register_cipher (&des_desc); - register_cipher (&des3_desc); -#endif -#ifdef LTC_CAST5 - register_cipher (&cast5_desc); -#endif -#ifdef LTC_NOEKEON - register_cipher (&noekeon_desc); -#endif -#ifdef LTC_SKIPJACK - register_cipher (&skipjack_desc); -#endif -#ifdef LTC_ANUBIS - register_cipher (&anubis_desc); -#endif -#ifdef LTC_KHAZAD - register_cipher (&khazad_desc); -#endif -#ifdef LTC_CAMELLIA - register_cipher (&camellia_desc); -#endif - -#ifdef LTC_TIGER - register_hash (&tiger_desc); -#endif -#ifdef LTC_MD2 - register_hash (&md2_desc); -#endif -#ifdef LTC_MD4 - register_hash (&md4_desc); -#endif -#ifdef LTC_MD5 - register_hash (&md5_desc); -#endif -#ifdef LTC_SHA1 - register_hash (&sha1_desc); -#endif -#ifdef LTC_SHA224 - register_hash (&sha224_desc); -#endif -#ifdef LTC_SHA256 - register_hash (&sha256_desc); -#endif -#ifdef LTC_SHA384 - register_hash (&sha384_desc); -#endif -#ifdef LTC_SHA512 - register_hash (&sha512_desc); -#endif -#ifdef LTC_SHA512_224 - register_hash (&sha512_224_desc); -#endif -#ifdef LTC_SHA512_256 - register_hash (&sha512_256_desc); -#endif -#ifdef LTC_SHA3 - register_hash (&sha3_224_desc); - register_hash (&sha3_256_desc); - register_hash (&sha3_384_desc); - register_hash (&sha3_512_desc); -#endif -#ifdef LTC_RIPEMD128 - register_hash (&rmd128_desc); -#endif -#ifdef LTC_RIPEMD160 - register_hash (&rmd160_desc); -#endif -#ifdef LTC_RIPEMD256 - register_hash (&rmd256_desc); -#endif -#ifdef LTC_RIPEMD320 - register_hash (&rmd320_desc); -#endif -#ifdef LTC_WHIRLPOOL - register_hash (&whirlpool_desc); -#endif -#ifdef LTC_BLAKE2S - register_hash (&blake2s_128_desc); - register_hash (&blake2s_160_desc); - register_hash (&blake2s_224_desc); - register_hash (&blake2s_256_desc); -#endif -#ifdef LTC_BLAKE2B - register_hash (&blake2b_160_desc); - register_hash (&blake2b_256_desc); - register_hash (&blake2b_384_desc); - register_hash (&blake2b_512_desc); -#endif -#ifdef LTC_CHC_HASH - register_hash(&chc_desc); - if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) { - printf("chc_register error: %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } -#endif - -#ifdef USE_LTM - ltc_mp = ltm_desc; -#elif defined(USE_TFM) - ltc_mp = tfm_desc; -#elif defined(USE_GMP) - ltc_mp = gmp_desc; -#else - extern ltc_math_descriptor EXT_MATH_LIB; - ltc_mp = EXT_MATH_LIB; -#endif - - -} - void hash_gen(void) { unsigned char md[MAXBLOCKSIZE], *buf; @@ -880,7 +734,23 @@ void lrw_gen(void) int main(void) { - reg_algs(); + register_all_ciphers(); + register_all_hashes(); + register_all_prngs(); +#ifdef USE_LTM + ltc_mp = ltm_desc; +#elif defined(USE_TFM) + ltc_mp = tfm_desc; +#elif defined(USE_GMP) + ltc_mp = gmp_desc; +#elif defined(EXT_MATH_LIB) + extern ltc_math_descriptor EXT_MATH_LIB; + ltc_mp = EXT_MATH_LIB; +#else + fprintf(stderr, "No MPI provider available\n"); + exit(EXIT_FAILURE); +#endif + printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); diff --git a/helper.pl b/helper.pl index 81269543..6a90cfea 100755 --- a/helper.pl +++ b/helper.pl @@ -27,7 +27,7 @@ sub write_file { sub check_source { my @all_files = (bsd_glob("makefile*"), bsd_glob("*.sh"), bsd_glob("*.pl")); - find({ wanted=>sub { push @all_files, $_ if -f $_ }, no_chdir=>1 }, qw/src testprof demos/); + find({ wanted=>sub { push @all_files, $_ if -f $_ }, no_chdir=>1 }, qw/src tests demos/); my $fails = 0; for my $file (sort @all_files) { @@ -81,22 +81,33 @@ sub check_defines { return $fails; } -sub check_hashes { +sub check_descriptor { + my $which = shift; + my $what = shift; my @src; my @descriptors; - find({ wanted => sub { push @src, $_ if $_ =~ /\.c$/ }, no_chdir=>1 }, './src/hashes/'); + find({ wanted => sub { push @src, $_ if $_ =~ /\.c$/ }, no_chdir=>1 }, "./src/${which}/"); for my $f (@src) { - my @n = map { my $x = $_; $x =~ s/^.*?ltc_hash_descriptor\s+(\S+).*$/$1/; $x } grep { $_ =~ /ltc_hash_descriptor/ } split /\n/, read_file($f); + my @n = map { my $x = $_; $x =~ s/^.*?ltc_${what}_descriptor\s+(\S+).*$/$1/; $x } grep { $_ =~ /ltc_${what}_descriptor/ } split /\n/, read_file($f); push @descriptors, @n if @n; } my $fails = 0; for my $d (@descriptors) { - for my $f (qw{ demos/tv_gen.c demos/hashsum.c testprof/x86_prof.c }) { + for my $f ("./src/misc/crypt/crypt_register_all_${which}.c") { my $txt = read_file($f); warn "$d missing in $f\n" and $fails++ if $txt !~ /\Q$d\E/; } } - warn( $fails > 0 ? "check-hashes: FAIL $fails\n" : "check-hashes: PASS\n" ); + my $name = sprintf("%-17s", "check-${which}:"); + warn( $fails > 0 ? "${name}FAIL $fails\n" : "${name}PASS\n" ); + return $fails; +} + +sub check_descriptors { + my $fails = 0; + $fails = $fails + check_descriptor("ciphers", "cipher"); + $fails = $fails + check_descriptor("hashes", "hash"); + $fails = $fails + check_descriptor("prngs", "prng"); return $fails; } @@ -234,7 +245,7 @@ sub process_makefiles { my @all = (); find({ no_chdir => 1, wanted => sub { push @all, $_ if -f $_ && $_ =~ /\.(c|h)$/ } }, 'src'); my @t = qw(); - find({ no_chdir => 1, wanted => sub { push @t, $_ if $_ =~ /(no_prng|test_driver|x86_prof|_tests?).c$/ } }, 'testprof'); + find({ no_chdir => 1, wanted => sub { push @t, $_ if $_ =~ /(common|no_prng|_tests?|test).c$/ } }, 'tests'); my @o = sort ('src/ciphers/aes/aes_enc.o', map { my $x = $_; $x =~ s/\.c$/.o/; $x } @c); my $var_o = prepare_variable("OBJECTS", @o); @@ -291,14 +302,14 @@ sub die_usage { MARKER } -GetOptions( "s|check-source" => \my $check_source, - "d|check-defines" => \my $check_defines, - "h|check-hashes" => \my $check_hashes, - "m|check-makefiles" => \my $check_makefiles, - "a|check-all" => \my $check_all, - "u|update-makefiles" => \my $update_makefiles, - "f|fixupind=s" => \my $fixupind, - "h|help" => \my $help +GetOptions( "s|check-source" => \my $check_source, + "c|check-descriptors" => \my $check_descriptors, + "d|check-defines" => \my $check_defines, + "m|check-makefiles" => \my $check_makefiles, + "a|check-all" => \my $check_all, + "u|update-makefiles" => \my $update_makefiles, + "f|fixupind=s" => \my $fixupind, + "h|help" => \my $help ) or die_usage; if ($fixupind) { @@ -311,7 +322,7 @@ if ($fixupind) { my $failure; $failure ||= check_source() if $check_all || $check_source; $failure ||= check_defines() if $check_all || $check_defines; -$failure ||= check_hashes() if $check_all || $check_hashes; +$failure ||= check_descriptors() if $check_all || $check_descriptors; $failure ||= process_makefiles(0) if $check_all || $check_makefiles; $failure ||= process_makefiles(1) if $update_makefiles; diff --git a/libtomcrypt_VS2008.vcproj b/libtomcrypt_VS2008.vcproj index f5f14636..9aa9c512 100644 --- a/libtomcrypt_VS2008.vcproj +++ b/libtomcrypt_VS2008.vcproj @@ -1343,6 +1343,10 @@ RelativePath="src\misc\burn_stack.c" > + + @@ -1462,6 +1466,18 @@ RelativePath="src\misc\crypt\crypt_prng_rng_descriptor.c" > + + + + + + diff --git a/makefile b/makefile index aa569a42..4620b86a 100644 --- a/makefile +++ b/makefile @@ -27,9 +27,6 @@ INSTALL_CMD = install ifndef LIBNAME LIBNAME=libtomcrypt.a endif -ifndef LIBTEST - LIBTEST=libtomcrypt_prof.a -endif include makefile_include.mk @@ -61,27 +58,17 @@ ifneq ($V,1) endif ${silent} $(RANLIB) $@ -$(LIBTEST): $(TOBJECTS) -ifneq ($V,1) - @echo " * ${AR} $@" -endif - ${silent} $(AR) $(ARFLAGS) $@ $(TOBJECTS) -ifneq ($V,1) - @echo " * ${RANLIB} $@" -endif - ${silent} $(RANLIB) $@ - -timing: $(LIBNAME) $(LIBTEST) $(TIMINGS) +timing: $(LIBNAME) $(TIMINGS) ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} $(CC) $(LDFLAGS) $(TIMINGS) $(LIBTEST) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING) + ${silent} $(CC) $(LDFLAGS) $(TIMINGS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING) -test: $(LIBNAME) $(LIBTEST) $(TESTS) +test: $(LIBNAME) $(TOBJECTS) ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} $(CC) $(LDFLAGS) $(TESTS) $(LIBTEST) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST) + ${silent} $(CC) $(LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST) # build the demos from a template define DEMO_template @@ -102,8 +89,6 @@ install: .common_install install_bins: .common_install_bins -install_test: .common_install_test - profile: CFLAGS="$(CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov" ./timing diff --git a/makefile.mingw b/makefile.mingw index 5b1cbc27..add777f3 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -25,7 +25,7 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath EXTRALIBS = -L../libtommath -ltommath #Compilation flags -LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itestprof -DLTC_SOURCE +LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itests -DLTC_SOURCE LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS) VERSION=1.17 @@ -33,7 +33,6 @@ VERSION=1.17 LIBMAIN_S =libtomcrypt.a LIBMAIN_I =libtomcrypt.dll.a LIBMAIN_D =libtomcrypt.dll -LIBTEST_S =libtomcrypt_prof.a #List of objects to compile (all goes to libtomcrypt.a) OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \ @@ -92,17 +91,19 @@ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \ src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \ src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \ -src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crc32.o \ -src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \ -src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ -src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ -src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ -src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ -src/misc/crypt/crypt_prng_rng_descriptor.o src/misc/crypt/crypt_register_cipher.o \ +src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ +src/misc/compare_testvector.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \ +src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \ +src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ +src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ +src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \ +src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \ +src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \ +src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \ +src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \ src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ @@ -187,13 +188,12 @@ src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \ src/stream/sober128/sober128_test.o -#List of test objects to compile (all goes to libtomcrypt_prof.a) -TOBJECTS=testprof/base64_test.o testprof/cipher_hash_test.o testprof/der_tests.o testprof/dh_test.o \ -testprof/dsa_test.o testprof/ecc_test.o testprof/file_test.o testprof/katja_test.o testprof/mac_test.o \ -testprof/misc_test.o testprof/modes_test.o testprof/multi_test.o testprof/no_prng.o \ -testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test.o \ -testprof/pkcs_1_pss_test.o testprof/pkcs_1_test.o testprof/rotate_test.o testprof/rsa_test.o \ -testprof/store_test.o testprof/test_driver.o testprof/x86_prof.o +#List of test objects to compile +TOBJECTS=tests/base64_test.o tests/cipher_hash_test.o tests/common.o tests/der_test.o tests/dh_test.o \ +tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o tests/mac_test.o tests/misc_test.o \ +tests/modes_test.o tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o \ +tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o tests/prng_test.o \ +tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o #The following headers will be installed by "make install" HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \ @@ -220,16 +220,11 @@ src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c #Dependencies on *.h $(OBJECTS): $(HEADERS) -$(TOBJECTS): $(HEADERS) testprof/tomcrypt_test.h +$(TOBJECTS): $(HEADERS) tests/tomcrypt_test.h .c.o: $(CC) $(LTC_CFLAGS) -c $< -o $@ -#Create libtomcrypt_prof.a -$(LIBTEST_S): $(TOBJECTS) - $(AR) $(ARFLAGS) $@ $(TOBJECTS) - $(RANLIB) $@ - #Create libtomcrypt.a $(LIBMAIN_S): $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS) @@ -242,32 +237,31 @@ $(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS) #Demo tools/utilities hashsum.exe: demos/hashsum.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ ltcrypt.exe: demos/ltcrypt.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/ltcrypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ small.exe: demos/small.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ tv_gen.exe: demos/tv_gen.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +timing.exe: demos/timing.o $(LIBMAIN_S) + $(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ -#Tests + timing tests -timing.exe: demos/timing.o $(LIBTEST_S) $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ - @echo NOTICE: start the tests by: timing.exe -test.exe: demos/test.o $(LIBTEST_S) $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ - @echo NOTICE: start the tests by: test.exe +#Tests +test.exe: $(TOBJECTS) $(LIBMAIN_S) + $(CC) $(TOBJECTS) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ + @echo NOTICE: start the tests by launching test.exe -all: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) $(LIBTEST_S) hashsum.exe ltcrypt.exe small.exe tv_gen.exe timing.exe test.exe +all: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) hashsum.exe ltcrypt.exe small.exe tv_gen.exe timing.exe test.exe test: test.exe clean: - @cmd /c del /Q *_tv.txt 2>nul - @cmd /c del /Q /S *.o *.a *.exe *.dll 2>nul + @-cmd /c del /Q *_tv.txt 2>nul + @-cmd /c del /Q /S *.o *.a *.exe *.dll 2>nul #Install the library + headers -install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) $(LIBTEST_S) +install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D) cmd /c if not exist "$(DESTDIR)\bin" mkdir "$(DESTDIR)\bin" cmd /c if not exist "$(DESTDIR)\lib" mkdir "$(DESTDIR)\lib" cmd /c if not exist "$(DESTDIR)\include" mkdir "$(DESTDIR)\include" diff --git a/makefile.msvc b/makefile.msvc index 2c434afb..7c748d23 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -20,13 +20,12 @@ CFLAGS = /Ox /DUSE_LTM /DLTM_DESC /I../libtommath EXTRALIBS = ../libtommath/tommath.lib #Compilation flags -LTC_CFLAGS = $(CFLAGS) /nologo /Isrc/headers/ /Itestprof/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3 +LTC_CFLAGS = $(CFLAGS) /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3 LTC_LDFLAGS = advapi32.lib $(EXTRALIBS) VERSION=1.17 #Libraries to be created (this makefile builds only static libraries) LIBMAIN_S =tomcrypt.lib -LIBTEST_S =tomcrypt_prof.lib #List of objects to compile (all goes to tomcrypt.lib) OBJECTS=src/ciphers/aes/aes.obj src/ciphers/aes/aes_enc.obj src/ciphers/anubis.obj src/ciphers/blowfish.obj \ @@ -85,17 +84,19 @@ src/mac/xcbc/xcbc_file.obj src/mac/xcbc/xcbc_init.obj src/mac/xcbc/xcbc_memory.o src/mac/xcbc/xcbc_memory_multi.obj src/mac/xcbc/xcbc_process.obj src/mac/xcbc/xcbc_test.obj \ src/math/fp/ltc_ecc_fp_mulmod.obj src/math/gmp_desc.obj src/math/ltm_desc.obj src/math/multi.obj \ src/math/rand_bn.obj src/math/rand_prime.obj src/math/tfm_desc.obj src/misc/adler32.obj \ -src/misc/base64/base64_decode.obj src/misc/base64/base64_encode.obj src/misc/burn_stack.obj src/misc/crc32.obj \ -src/misc/crypt/crypt.obj src/misc/crypt/crypt_argchk.obj src/misc/crypt/crypt_cipher_descriptor.obj \ -src/misc/crypt/crypt_cipher_is_valid.obj src/misc/crypt/crypt_constants.obj \ -src/misc/crypt/crypt_find_cipher.obj src/misc/crypt/crypt_find_cipher_any.obj \ -src/misc/crypt/crypt_find_cipher_id.obj src/misc/crypt/crypt_find_hash.obj \ -src/misc/crypt/crypt_find_hash_any.obj src/misc/crypt/crypt_find_hash_id.obj \ -src/misc/crypt/crypt_find_hash_oid.obj src/misc/crypt/crypt_find_prng.obj src/misc/crypt/crypt_fsa.obj \ -src/misc/crypt/crypt_hash_descriptor.obj src/misc/crypt/crypt_hash_is_valid.obj \ -src/misc/crypt/crypt_inits.obj src/misc/crypt/crypt_ltc_mp_descriptor.obj \ -src/misc/crypt/crypt_prng_descriptor.obj src/misc/crypt/crypt_prng_is_valid.obj \ -src/misc/crypt/crypt_prng_rng_descriptor.obj src/misc/crypt/crypt_register_cipher.obj \ +src/misc/base64/base64_decode.obj src/misc/base64/base64_encode.obj src/misc/burn_stack.obj \ +src/misc/compare_testvector.obj src/misc/crc32.obj src/misc/crypt/crypt.obj src/misc/crypt/crypt_argchk.obj \ +src/misc/crypt/crypt_cipher_descriptor.obj src/misc/crypt/crypt_cipher_is_valid.obj \ +src/misc/crypt/crypt_constants.obj src/misc/crypt/crypt_find_cipher.obj \ +src/misc/crypt/crypt_find_cipher_any.obj src/misc/crypt/crypt_find_cipher_id.obj \ +src/misc/crypt/crypt_find_hash.obj src/misc/crypt/crypt_find_hash_any.obj \ +src/misc/crypt/crypt_find_hash_id.obj src/misc/crypt/crypt_find_hash_oid.obj \ +src/misc/crypt/crypt_find_prng.obj src/misc/crypt/crypt_fsa.obj src/misc/crypt/crypt_hash_descriptor.obj \ +src/misc/crypt/crypt_hash_is_valid.obj src/misc/crypt/crypt_inits.obj \ +src/misc/crypt/crypt_ltc_mp_descriptor.obj src/misc/crypt/crypt_prng_descriptor.obj \ +src/misc/crypt/crypt_prng_is_valid.obj src/misc/crypt/crypt_prng_rng_descriptor.obj \ +src/misc/crypt/crypt_register_all_ciphers.obj src/misc/crypt/crypt_register_all_hashes.obj \ +src/misc/crypt/crypt_register_all_prngs.obj src/misc/crypt/crypt_register_cipher.obj \ src/misc/crypt/crypt_register_hash.obj src/misc/crypt/crypt_register_prng.obj src/misc/crypt/crypt_sizes.obj \ src/misc/crypt/crypt_unregister_cipher.obj src/misc/crypt/crypt_unregister_hash.obj \ src/misc/crypt/crypt_unregister_prng.obj src/misc/error_to_string.obj src/misc/hkdf/hkdf.obj \ @@ -180,13 +181,12 @@ src/stream/chacha/chacha_keystream.obj src/stream/chacha/chacha_setup.obj src/st src/stream/rc4/rc4.obj src/stream/rc4/rc4_test.obj src/stream/sober128/sober128.obj \ src/stream/sober128/sober128_test.obj -#List of test objects to compile (all goes to tomcrypt_prof.lib) -TOBJECTS=testprof/base64_test.obj testprof/cipher_hash_test.obj testprof/der_tests.obj testprof/dh_test.obj \ -testprof/dsa_test.obj testprof/ecc_test.obj testprof/file_test.obj testprof/katja_test.obj testprof/mac_test.obj \ -testprof/misc_test.obj testprof/modes_test.obj testprof/multi_test.obj testprof/no_prng.obj \ -testprof/pkcs_1_eme_test.obj testprof/pkcs_1_emsa_test.obj testprof/pkcs_1_oaep_test.obj \ -testprof/pkcs_1_pss_test.obj testprof/pkcs_1_test.obj testprof/rotate_test.obj testprof/rsa_test.obj \ -testprof/store_test.obj testprof/test_driver.obj testprof/x86_prof.obj +#List of test objects to compile +TOBJECTS=tests/base64_test.obj tests/cipher_hash_test.obj tests/common.obj tests/der_test.obj tests/dh_test.obj \ +tests/dsa_test.obj tests/ecc_test.obj tests/file_test.obj tests/katja_test.obj tests/mac_test.obj tests/misc_test.obj \ +tests/modes_test.obj tests/multi_test.obj tests/no_prng.obj tests/pkcs_1_eme_test.obj tests/pkcs_1_emsa_test.obj \ +tests/pkcs_1_oaep_test.obj tests/pkcs_1_pss_test.obj tests/pkcs_1_test.obj tests/prng_test.obj \ +tests/rotate_test.obj tests/rsa_test.obj tests/store_test.obj tests/test.obj #The following headers will be installed by "make install" HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \ @@ -213,45 +213,42 @@ src/hashes/sha2/sha256.obj: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c #Dependencies on *.h $(OBJECTS): $(HEADERS) -$(TOBJECTS): $(HEADERS) testprof/tomcrypt_test.h +$(TOBJECTS): $(HEADERS) tests/tomcrypt_test.h .c.obj: $(CC) $(LTC_CFLAGS) /c $< /Fo$@ -#Create tomcrypt_prof.lib -$(LIBTEST_S): $(TOBJECTS) - lib /out:$(LIBTEST_S) $(TOBJECTS) - #Create tomcrypt.lib $(LIBMAIN_S): $(OBJECTS) lib /out:$(LIBMAIN_S) $(OBJECTS) #Demo tools/utilities -hashsum.exe: demos/hashsum.c $(LIBMAIN_S) - cl $(LTC_CFLAGS) demos/hashsum.c $(LIBMAIN_S) $(LTC_LDFLAGS) +hashsum.exe: demos/hashsum.c tests/common.c $(LIBMAIN_S) + cl $(LTC_CFLAGS) demos/hashsum.c tests/common.c $(LIBMAIN_S) $(LTC_LDFLAGS) /Fe$@ ltcrypt.exe: demos/ltcrypt.c $(LIBMAIN_S) - cl $(LTC_CFLAGS) demos/ltcrypt.c $(LIBMAIN_S) $(LTC_LDFLAGS) + cl $(LTC_CFLAGS) demos/ltcrypt.c tests/common.c $(LIBMAIN_S) $(LTC_LDFLAGS) /Fe$@ small.exe: demos/small.c $(LIBMAIN_S) - cl $(LTC_CFLAGS) demos/small.c $(LIBMAIN_S) $(LTC_LDFLAGS) + cl $(LTC_CFLAGS) demos/small.c tests/common.c $(LIBMAIN_S) $(LTC_LDFLAGS) /Fe$@ tv_gen.exe: demos/tv_gen.c $(LIBMAIN_S) - cl $(LTC_CFLAGS) demos/tv_gen.c $(LIBMAIN_S) $(LTC_LDFLAGS) + cl $(LTC_CFLAGS) demos/tv_gen.c tests/common.c $(LIBMAIN_S) $(LTC_LDFLAGS) /Fe$@ +timing.exe: demos/timing.c $(LIBMAIN_S) + cl $(LTC_CFLAGS) demos/timing.c tests/common.c $(LIBMAIN_S) $(LTC_LDFLAGS) /Fe$@ -#Tests + timing tests -timing.exe: demos/timing.c $(LIBMAIN_S) $(LIBTEST_S) - cl $(LTC_CFLAGS) demos/timing.c $(LIBTEST_S) $(LIBMAIN_S) $(LTC_LDFLAGS) -test.exe: demos/test.c $(LIBMAIN_S) $(LIBTEST_S) - cl $(LTC_CFLAGS) demos/test.c $(LIBTEST_S) $(LIBMAIN_S) $(LTC_LDFLAGS) +#Tests +test.exe: $(LIBMAIN_S) $(TOBJECTS) + cl $(LTC_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTC_LDFLAGS) /Fe$@ + @echo NOTICE: start the tests by launching test.exe -all: $(LIBMAIN_S) $(LIBTEST_S) hashsum.exe ltcrypt.exe small.exe tv_gen.exe timing.exe test.exe +all: $(LIBMAIN_S) hashsum.exe ltcrypt.exe small.exe tv_gen.exe timing.exe test.exe test: test.exe clean: - @cmd /c del /Q *_tv.txt 2>nul - @cmd /c del /Q /S *.OBJ *.LIB *.EXE *.DLL 2>nul + @-cmd /c del /Q *_tv.txt 2>nul + @-cmd /c del /Q /S *.OBJ *.LIB *.EXE *.DLL 2>nul #Install the library + headers -install: $(LIBMAIN_S) $(LIBTEST_S) +install: $(LIBMAIN_S) cmd /c if not exist "$(DESTDIR)\bin" mkdir "$(DESTDIR)\bin" cmd /c if not exist "$(DESTDIR)\lib" mkdir "$(DESTDIR)\lib" cmd /c if not exist "$(DESTDIR)\include" mkdir "$(DESTDIR)\include" diff --git a/makefile.shared b/makefile.shared index c6086985..e6be085d 100644 --- a/makefile.shared +++ b/makefile.shared @@ -18,9 +18,6 @@ LTCOMPILE = $(LT) --mode=compile --tag=CC $(CC) INSTALL_CMD = $(LT) --mode=install install #Output filenames for various targets. -ifndef LIBTEST - LIBTEST=libtomcrypt_prof.la -endif ifndef LIBNAME LIBNAME=libtomcrypt.la endif @@ -39,9 +36,6 @@ src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c $(LIBNAME): $(OBJECTS) $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) `find ./src -type f -name "*.lo" | LC_ALL=C sort` $(EXTRALIBS) -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) -$(LIBTEST): $(TOBJECTS) - $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) `find ./testprof -type f -name "*.lo" | LC_ALL=C sort` -o $@ -rpath $(LIBPATH) -version-info $(VERSION_LT) - install: .common_install sed -e 's,^prefix=.*,prefix=$(DESTDIR),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > libtomcrypt.pc install -d $(LIBPATH)/pkgconfig @@ -49,13 +43,11 @@ install: .common_install install_bins: .common_install_bins -install_test: .common_install_test +test: $(LIBNAME) $(TOBJECTS) + $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) -test: $(LIBNAME) $(LIBTEST) $(TESTS) - $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(TESTS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) - -timing: $(LIBNAME) $(LIBTEST) $(TIMINGS) - $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TIMING) $(TIMINGS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) +timing: $(TIMINGS) $(LIBNAME) + $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS) # build the demos from a template define DEMO_template diff --git a/makefile.unix b/makefile.unix index b93315cd..e0ea2d9b 100644 --- a/makefile.unix +++ b/makefile.unix @@ -32,13 +32,12 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath EXTRALIBS = ../libtommath/libtommath.a #Compilation flags -LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itestprof -DLTC_SOURCE +LTC_CFLAGS = $(CFLAGS) -Isrc/headers -Itests -DLTC_SOURCE LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS) VERSION=1.17 #Libraries to be created (this makefile builds only static libraries) LIBMAIN_S =libtomcrypt.a -LIBTEST_S =libtomcrypt_prof.a #List of objects to compile (all goes to libtomcrypt.a) OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \ @@ -97,17 +96,19 @@ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \ src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \ src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \ -src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crc32.o \ -src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \ -src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ -src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ -src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ -src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ -src/misc/crypt/crypt_prng_rng_descriptor.o src/misc/crypt/crypt_register_cipher.o \ +src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ +src/misc/compare_testvector.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \ +src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \ +src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ +src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ +src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \ +src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \ +src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \ +src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \ +src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \ src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ @@ -193,12 +194,11 @@ src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \ src/stream/sober128/sober128_test.o #List of test objects to compile (all goes to libtomcrypt_prof.a) -TOBJECTS=testprof/base64_test.o testprof/cipher_hash_test.o testprof/der_tests.o testprof/dh_test.o \ -testprof/dsa_test.o testprof/ecc_test.o testprof/file_test.o testprof/katja_test.o testprof/mac_test.o \ -testprof/misc_test.o testprof/modes_test.o testprof/multi_test.o testprof/no_prng.o \ -testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test.o \ -testprof/pkcs_1_pss_test.o testprof/pkcs_1_test.o testprof/rotate_test.o testprof/rsa_test.o \ -testprof/store_test.o testprof/test_driver.o testprof/x86_prof.o +TOBJECTS=tests/base64_test.o tests/cipher_hash_test.o tests/common.o tests/der_test.o tests/dh_test.o \ +tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o tests/mac_test.o tests/misc_test.o \ +tests/modes_test.o tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o \ +tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o tests/prng_test.o \ +tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o #The following headers will be installed by "make install" HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \ @@ -225,18 +225,13 @@ src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c #Dependencies on *.h $(OBJECTS): $(HEADERS) -$(TOBJECTS): $(HEADERS) testprof/tomcrypt_test.h +$(TOBJECTS): $(HEADERS) tests/tomcrypt_test.h #This is necessary for compatibility with BSD make (namely on OpenBSD) .SUFFIXES: .o .c .c.o: $(CC) $(LTC_CFLAGS) -c $< -o $@ -#Create libtomcrypt_prof.a -$(LIBTEST_S): $(TOBJECTS) - $(AR) $(ARFLAGS) $@ $(TOBJECTS) - $(RANLIB) $@ - #Create libtomcrypt.a $(LIBMAIN_S): $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS) @@ -244,28 +239,27 @@ $(LIBMAIN_S): $(OBJECTS) #Demo tools/utilities hashsum: demos/hashsum.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ ltcrypt: demos/ltcrypt.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/ltcrypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ small: demos/small.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ tv_gen: demos/tv_gen.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ + $(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +timing: demos/timing.o $(LIBMAIN_S) + $(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ -#Tests + timing tests -timing: demos/timing.o $(LIBTEST_S) $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ - @echo "NOTICE: start the timing tests by: ./timing" -test: demos/test.o $(LIBTEST_S) $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ +#Tests +test: $(TOBJECTS) $(LIBMAIN_S) + $(CC) $(TOBJECTS) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ @echo "NOTICE: start the tests by: ./test" -all: $(LIBMAIN_S) $(LIBTEST_S) hashsum ltcrypt small tv_gen timing test +all: $(LIBMAIN_S) hashsum ltcrypt small tv_gen timing test #NOTE: this makefile works also on cygwin, thus we need to delete *.exe clean: -@rm -f $(OBJECTS) $(TOBJECTS) - -@rm -f $(LIBMAIN_S) $(LIBTEST_S) + -@rm -f $(LIBMAIN_S) -@rm -f demos/*.o *_tv.txt -@rm -f test tv_gen hashsum crypt small timing -@rm -f test.exe tv_gen.exe hashsum.exe crypt.exe small.exe timing.exe diff --git a/makefile_include.mk b/makefile_include.mk index d493d0ef..2c3f24f7 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -63,10 +63,11 @@ CFLAGS += -Wno-type-limits ifdef LTC_DEBUG # compile for DEBUGGING (required for ccmalloc checking!!!) +CFLAGS += -g3 -DLTC_NO_ASM ifneq (,$(strip $(LTC_DEBUG))) -CFLAGS += -g3 -DLTC_NO_ASM -DLTC_TEST_DBG=$(LTC_DEBUG) +CFLAGS += -DLTC_TEST_DBG=$(LTC_DEBUG) else -CFLAGS += -g3 -DLTC_NO_ASM -DLTC_TEST_DBG +CFLAGS += -DLTC_TEST_DBG endif else @@ -102,8 +103,8 @@ endif DSOURCES = $(wildcard demos/*.c) DOBJECTS = $(DSOURCES:.c=.o) -#List of testprof headers -THEADERS = $(wildcard testprof/*.h) +#List of tests headers +THEADERS = $(wildcard tests/*.h) TIMING=timing TEST=test @@ -113,7 +114,6 @@ UNBROKEN_DEMOS=$(USEFUL_DEMOS) ltcrypt small tv_gen sizes constants DEMOS=$(UNBROKEN_DEMOS) openssl-enc TIMINGS=demos/timing.o -TESTS=demos/test.o #LIBPATH The directory for libtomcrypt to be installed to. #INCPATH The directory to install the header files for libtomcrypt. @@ -195,17 +195,19 @@ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \ src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \ src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \ src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \ -src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crc32.o \ -src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \ -src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ -src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ -src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ -src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ -src/misc/crypt/crypt_prng_rng_descriptor.o src/misc/crypt/crypt_register_cipher.o \ +src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ +src/misc/compare_testvector.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \ +src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \ +src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ +src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ +src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \ +src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \ +src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \ +src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \ +src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \ src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ @@ -291,12 +293,11 @@ src/stream/rc4/rc4.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128.o \ src/stream/sober128/sober128_test.o # List of test objects to compile (all goes to libtomcrypt_prof.a) -TOBJECTS=testprof/base64_test.o testprof/cipher_hash_test.o testprof/der_tests.o testprof/dh_test.o \ -testprof/dsa_test.o testprof/ecc_test.o testprof/file_test.o testprof/katja_test.o testprof/mac_test.o \ -testprof/misc_test.o testprof/modes_test.o testprof/multi_test.o testprof/no_prng.o \ -testprof/pkcs_1_eme_test.o testprof/pkcs_1_emsa_test.o testprof/pkcs_1_oaep_test.o \ -testprof/pkcs_1_pss_test.o testprof/pkcs_1_test.o testprof/rotate_test.o testprof/rsa_test.o \ -testprof/store_test.o testprof/test_driver.o testprof/x86_prof.o +TOBJECTS=tests/base64_test.o tests/cipher_hash_test.o tests/common.o tests/der_test.o tests/dh_test.o \ +tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o tests/mac_test.o tests/misc_test.o \ +tests/modes_test.o tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o \ +tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o tests/prng_test.o \ +tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o # The following headers will be installed by "make install" HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \ @@ -318,8 +319,8 @@ src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c #The default rule for make builds the libtomcrypt library. default:library -$(DOBJECTS): CFLAGS += -Itestprof -$(TOBJECTS): CFLAGS += -Itestprof +$(DOBJECTS): CFLAGS += -Itests +$(TOBJECTS): CFLAGS += -Itests #This rule makes the libtomcrypt library. library: $(LIBNAME) @@ -354,12 +355,6 @@ install_all: install install_bins install_docs install_test install -d $(BINPATH) $(INSTALL_CMD) -m 775 $(USEFUL_DEMOS) $(BINPATH) -.common_install_test: $(LIBTEST) - install -d $(LIBPATH) - install -d $(INCPATH) - install -m 644 testprof/tomcrypt_test.h $(INCPATH) - $(INSTALL_CMD) -m 644 $(LIBTEST) $(LIBPATH) - install_docs: doc/crypt.pdf install -d $(DATAPATH) install -m 644 doc/crypt.pdf $(DATAPATH) diff --git a/notes/ccm_tv.txt b/notes/ccm_tv.txt index aa8f9e6d..40cb2f19 100644 --- a/notes/ccm_tv.txt +++ b/notes/ccm_tv.txt @@ -212,6 +212,41 @@ CCM-anubis (16 byte key) 31: B8176469E6A0D5797ED6421A871FEECDE48ACF011E394981C43AC917E8FFD5, E9B01383DB1A32E6126BD802A6C6F47E 32: AB6A0AA29B687D05735167D78DB697BA2478BD14ECD059AE9D1239E7F2AB48FD, A560A30FD87CF28BA66F5B2638567E4B +CCM-seed (16 byte key) + 0: , 960414F81DF9F363AE6234067B946EA6 + 1: 15, 17746EC09B06AF1DE24710D2506629CD + 2: 892C, 828705A8CF1E51688EC4F1FFAC4C151A + 3: E411A7, 1AF2DD611D05DAF48118D1E7D810C173 + 4: B9DC8276, 4D335DF8B860AF121904310F5C004212 + 5: 8182C84A25, B713177663D498218908178B3EA3C65E + 6: 5933E7872324, 52413BB22BABEC9E43F1A98B78B4496E + 7: A243E381075DEA, 8FF3D2D465748AAF2373D1D8F8EDCFC3 + 8: 57A4E46B9B5C1795, B26653992639D54D5CEBAC7473CD3285 + 9: 4D05D6669D9A0C3079, 6B26FA6D5271D74D444985466D2CF0AA + 10: 1D35BB653A9F48C3314B, 494E108B0780280DF7CB4BE24CACB5CB + 11: 9A227951B4565021D29DD4, 3E21A07540744E26424996B0670CB07A + 12: 3E893574DD3D82CCD83E87E0, 017D51F744FE95E375D0456FA8BB0EC9 + 13: 5DF04297D842B3CEFCF93F5B95, 49CCE7A12C85648BD2A07944623C81AC + 14: 27F7D25EDE3471AAE1B91BBAEAD0, A6F1DD19DF08160D982184A414247B8B + 15: 6F8583E5B88B15F89070FB7A49383F, 4C98CC3884A2BD20AC6FA5184FB72670 + 16: 5D8D511AE705860B1A55E2FDAE9581D9, 96EF02C285AFD27D2B26BCAC02EC56A0 + 17: C4508E9E03DFE7C3B89192589CFD171A16, A2A4DC81E900BC5C404389BBD0B4710D + 18: 3163AE0E74B3DE3779745A82B783D882F092, A89574F7D1C2B90241A702A2C6A2AD86 + 19: 2D9C64EF9D8C2E195AF05BAE747A7BF8EC6C30, 07EEB7667A539164862E472366FFAD68 + 20: 03D145C9133E9108BB7A61D17880B155A56A58E6, 4F8EBC9A3F3C74EEA02099BB5AE6D456 + 21: 41C20EF2D199B6C0FAD9DA02DA0296D37B23059C3A, 062AE92091F7A8CF74A8E9DAFC58BEDE + 22: 402912121F84EDB82F101195A68EF214F0A8F4DA6DC0, B35C944A4E5BA8AB60A4415B5BDF6E30 + 23: 4D3F14438904F8F4F911CE729B26415F4EF819F80D2254, 2304E0373E136010B9BC6E061660D881 + 24: A855C170C1E2D326D74996939C48A85EDEED2E06F97BE61A, E66F188735CDBD27F6354C260A4796BA + 25: F882B023A3B25B878073DF739A234256E4174238A30A5B5062, 3C8BEBFA98ABF880891AF2539D3A0FCF + 26: C66F850279CD23D5243CF15E6084A17C124DDDE840DFD9532954, 003202A7E393626BFF93D48207E7DE39 + 27: BAC89C099A8AF633EFAFA496198DC9398DB3AAB47A8D24E2FE7D62, 32583F94ADE55278F2533ABE934CD535 + 28: B9EB02F63EFB72455CFFA2799A5BFA9E0BFDE240379AA98B4D0532C8, 5D01FD2F100C003EA284A2AF55EE5934 + 29: BAD5BB6B8DF316401B12B2BF36329F1D977E1FD943F594A6F4ED696194, 3D91CE3618998F3E060038D4DCAAD084 + 30: 8964B7FAC865310E56DB3238E03803F3B79D095523D278D609AD34BA8B67, C57D3AA1FF71636CC7497DF3CB4F7B71 + 31: F83C35D61E5C48CC7C402C9C78758D0DC696D2708FBC5294879DBF700BAF75, C69997844AB43312C90E995AD8C91E58 + 32: 03CA8E42B89C0AEEF0B7A364E94E326C537AFC4392AED3E6DA71EE65032A5CDB, E8DCD9120DE61900A194E8B94AEF6B2B + CCM-camellia (16 byte key) 0: , 3B53D5CC8B26A5FFC78D2E974E45A661 1: 5B, ED7741D8C258D56A29392A7A65CF147D diff --git a/notes/cipher_tv.txt b/notes/cipher_tv.txt index d8ddb298..604f01c2 100644 --- a/notes/cipher_tv.txt +++ b/notes/cipher_tv.txt @@ -1965,6 +1965,168 @@ Key Size: 16 bytes 49: 0133E1745856C44C +Cipher: seed +Key Size: 16 bytes + 0: A6E8D7325BBE0998CF235C1B57E64360 + 1: 83A2EB0094D1CF95E683DE8BA93DE478 + 2: 3DF178E121DA1CDB77ACFB37F9499A3B + 3: 785A1D88210885D6D2D84C2CB4461D57 + 4: 4F177E4C76F6CA9C989E724A0EC275F4 + 5: 3AC502689139EC1AFA7EDCDB622A6061 + 6: E1B9675AEFFE45A249644E7E0863110D + 7: C8A4294FF821E88EC5D181E54BBD3919 + 8: 7598C35780522C63B531758F53B7CCCE + 9: 3E59799FC5A5F99100A3791F6AA284EA +10: A8572971F5FC281E7617BCB8D616FAD3 +11: 3C5DCA82BA53DAC088D34E6C4D069E22 +12: 0886C2F45E358409230F6FA0F4ADB7BF +13: F4BF0388027AFBADEB6AD1AD0AC9339E +14: 587F60852DA55F76C486D9A6BA884F8A +15: A6F2518AD3B9A68C3FB8847E28B15212 +16: 6B6DB6C7085FEF6FD2BF32CAA2FEC2E2 +17: 40FF5FC134BC3911614A4E021254EFDF +18: 9B1016CD948F70B8A04D2604D4FF08AD +19: FBB86D1B49204838C7D544C8BAAE61F9 +20: 02EDFBE9A9A4CA2206CF9047FF146949 +21: 6B9FF89C1E607E494204B28D4391ED35 +22: BB85B8BAA9A4B74ED66C7485415834A0 +23: A6F72520E6F0248D88AFDBDA7CBDD6FE +24: 4BC1D4E990FC80E9ABF9E0FBC745E2D4 +25: 0358D44D7A59743AAF6D25CA179FB6FE +26: 320924C80B53E406DE45D31AB0E265F3 +27: B727A4AB9E8455EF11B18F300E22ADED +28: DCB6BEF8F35FFA2F2CDADAE161E56D48 +29: 847A39F0670E930BF7899656908C2B92 +30: B5223282B9328ACC4C6BF06F15C920EB +31: C265081FC225CA4ED28FABBF0BBB0298 +32: 35F6113CEA7C15DB21223D5AB0E9E558 +33: 3437EECD2984AADC9F07286CC23FB940 +34: D0C878AC8C01BB9868B499691373988A +35: 684381B5D98E9D1290AF5D633A903F68 +36: 69652249BD52F49ED11219881059ED38 +37: 08DD215881D98B1D8234FA1806E634FF +38: BFA836EB71C35B3E3CC9BFE9168D1B5F +39: 238BDB3340961C47A13F011AAB45FC5A +40: F55C630CE6008E7F15EA1686D887DEA4 +41: B78DED6C49E3167CD7ACF2CCB4E365DC +42: 79990527F22373B043039F18E343A8B7 +43: ACD08505E2759003C016F6E820DDC562 +44: 8DB7189177EF39A7A969F28B882CFF05 +45: EC0BEA22AE28469B91AAD4654858367E +46: 19A7F32CBCB4CE89163EC6F98FACFF36 +47: 3747F9C67FA044D52C3893D170DEC4A9 +48: DE799E6986BB77CA5C24F9A956BC28E4 +49: AD4CEBB75177F1CBD6FCEBF8457F85D2 + + +Cipher: kasumi +Key Size: 16 bytes + 0: BB6B2E0C88AD7C37 + 1: 5AFA50CBEF3FD5A4 + 2: 1914DFD8DD86C361 + 3: 0976E7F6AEBFFEDF + 4: DE0EF590AEC61F17 + 5: 089FA192859E6124 + 6: 72E283C82D366B51 + 7: 61DA033662AF0B74 + 8: C4CFA2C3ECA84CEA + 9: 15757205BAAC8639 +10: 4349914688A6A850 +11: 4B1F5E0D5B7ABBDF +12: 5482444DC8815041 +13: A8C198FB1D865A93 +14: C2641B2501AB6525 +15: FE492BE02E717496 +16: 03B3034E3A26006D +17: 0CB4B7FBA4582D1B +18: A61C750E5DFF1791 +19: AD5374F2B0860365 +20: CBC588879F98A820 +21: 04CA5EABB466C1C1 +22: F4DF5CEDAE6C0E17 +23: 6133AAD21D875DBB +24: D386BCFA19FAA860 +25: 68C9ED9206F07F47 +26: 00A49444A0C176CC +27: 4BEA00D55452196A +28: A9A3FAC7A2D553A3 +29: BE61DDF4CFA8EC8E +30: B1547D01A23C2632 +31: 400604E71F3F85AC +32: 8F431BCB447A132D +33: 0ED503EBD61D4286 +34: DF7B087B7D315E2C +35: 247A7872587F0507 +36: 7814D6B13A08CA60 +37: ADE44D69362B8199 +38: 49FF8C275D50A175 +39: 5DAC0F53391421C5 +40: B1C316E682E4F314 +41: 72FFFEA2DFD85E08 +42: 0418F02B7A89FC43 +43: 12826A96C5633C97 +44: A4726DA149DBFED1 +45: 5B276374E1EFC6CF +46: A91C4E4804D9A103 +47: 7A2894030C9FE01E +48: 0C59C6FA87DF2DCD +49: A86C6D3C7EAE644D + + +Cipher: multi2 +Key Size: 40 bytes + 0: A69A64BE9EAF56FC + 1: A8AB26A19D7804C6 + 2: D5468EF0C9CDF530 + 3: 2D08D23459949175 + 4: EE66EB212BEC593C + 5: A2D088F95C855F60 + 6: C206004787FEECEE + 7: E4875B7BE2C819B2 + 8: FBC692536393F8C5 + 9: 886DB391EE3BA443 +10: F45359B08EFC56FF +11: 1113E4F4A177E1DC +12: 8A02560CAD0CCF87 +13: CF57FF05E6BB7A67 +14: 21F4EDCF8E8A3D9D +15: 26A26EEFDF51B7F6 +16: E9AF9D2EF2A9EE4A +17: 6866182BC49D09D7 +18: 657E0D732BD7B5CF +19: EFCC33778BC265AE +20: 3556CD607D59C32B +21: A7477466892D114F +22: E210A7B32E9A2E08 +23: 9EBC0B60EB1FEA70 +24: C1E8C3A38E0063B9 +25: 3C9FC4089F87B0D6 +26: 100EA58D00F38495 +27: 3BB3D47D52A81774 +28: F1FA3DE89274A681 +29: 18DF1E38CC0C5230 +30: C3FDCDD9159B0258 +31: EA6ADFAF7D8D3C87 +32: FC4C369E7835461A +33: 791D1D34EBEF801B +34: 3B5A5B64C72B2F77 +35: 55ECED8C5D0F69FC +36: A6DE960F4B81C114 +37: 3C4EDB0671BFFC57 +38: C493186F4BF52F5D +39: 01B2C607B2329E87 +40: 109035510A1AEB20 +41: 0EA4699CA4A161FC +42: 182665FBB15EBD34 +43: 04458216DCB8F55F +44: 850BD374C892FC07 +45: 4C428488381D6FD0 +46: 56FF4CE0AA4132D9 +47: 9F95F0A47D70A317 +48: E12CC913356EFF86 +49: 7E614927A295C45B + + Cipher: camellia Key Size: 16 bytes 0: ED18D83F3153160C5A6D01AC3717515C diff --git a/notes/eax_tv.txt b/notes/eax_tv.txt index 3bedbc12..3d11a178 100644 --- a/notes/eax_tv.txt +++ b/notes/eax_tv.txt @@ -459,6 +459,79 @@ EAX-khazad (16 byte key) 15: 14DA751E5AF7E01F35B3CE74EE1ACF, 3C76AB64E1724DCE 16: A13BBC7E408D2C550634CBC64690B8FE, 3D4BBC0C76536730 +EAX-seed (16 byte key) + 0: , 3D0715108CEA3BE144350082B1BC4F25 + 1: EF, E56898AEDB0F461980587FFBDB83EE59 + 2: 9552, 9647B7FCEDBB9EF4EDEBCD98831E5BDE + 3: 25DCD8, 3647D80EF3529C72F16D223D04D7ACAA + 4: 3D169011, 7A741FA2536E5905FD4ABAB104062D3B + 5: A92411F6BC, 18A306E5DBF4DBDCE21505F16DA85482 + 6: 9D4661D2859F, 7B2FC34AB3DE45DB4AE8C97BF3B32BA9 + 7: 0E8C26E24B0961, DFF098B44E7D57A71F68FD0D2D2416C7 + 8: 485EE54D5D2684DF, C8FCF501065D23F936A4A530BB028EA0 + 9: 768888B50865A635A2, 8121463B762AC12D19EE21C58A8A1B7B + 10: 647FF44F0B350385BF27, 883241565540347D491C0E397FF5D663 + 11: FD868A569E2E597EB3B5AC, 4DE96B6810A1FC5F19A085B4F4C8B687 + 12: 342D72063420F3FCFC1EF71F, 88B94C3FFD74F052CC44722B87E1A45D + 13: C768F88646D47D5201FDF47A1E, A01EB1FBB3AB135F258B87C30A8E1A13 + 14: 44BF87EC9A5F5E20E5D972ECAE4C, 6F1C44EDB3533EFF973B53EAAF84D601 + 15: FDE60E4F25C4B9388BD3D348912B7F, 863871D706A32F92DAD13803CF2008E1 + 16: 69881E58AF690C5EEBC00DABDAAFBCA9, BD3911C5E41B327A10DC7D03435FB8AC + 17: 41AC0D70E8ECB01CFFFC9352E3800F568E, CCD63A0D20D0FD385EB720B2D60D20EF + 18: 88301B40FA8B84ECEE7238F17B08EC2A2DA3, AD10D120ABCCB67FD3F12C8D8BD216F7 + 19: CCD0F8187B7455274D80A2387599617582B7C5, 3DAA6952A9AA160863E4F489AF04C6A5 + 20: CB955D3B6044F1712DEDC65451E46B8D9FBE5067, D46FEEFA0A0069115F262877050265E9 + 21: 373B8AD20672BEADE5B742C72306455549B26DB631, 16DC5FE5C7C0D5478FF67AD00463AEF1 + 22: CAB49183077EB4DF3BFBF7FE026BCA8311A6BC067EDB, 8F4497F253167AB81A70A05218734C1F + 23: C2F860DA7EC7801FE30FF8C362EFA11E9392E029E24407, 1612D514BF9F365EB0E5CA13E974670D + 24: F0084F22D7AE598FF5DFEF76CCC0728325BB5D3DF5467B2F, 1DE5CD767D2B731DE4C9B4E303A7E771 + 25: F5E907AC398B2C7BE124ACCAD1FEB001BC3EC7C77C21E94110, D8C7D50EFB0CCE2926DA9E796EA46E17 + 26: D65A41B86D24C573D21EE416F2F853E8FF7A0788120102E8BABB, 3EEDB65BCF0E32C24B797D972913F943 + 27: 3B39B9994248DD1FB3EFD68820D19E8436F66FF0E6D82F40E50AFF, 7892720F9AA0ABC34E05FD982396C13A + 28: 9B924A2F620E5160B8F6C8DD313F39D6DC22B7E0596C8D0BFCA14907, E417D1FE5569975E8698C4D80684A613 + 29: 01068AA5F6FBFFDE1A8290CB315426F8CFD2438C09FD5982BE45EB21CC, A7DB568F037E8A4DB2D73CB2DF2BABA4 + 30: D39210874C4B7BEB63966BDC89AC7279B67C118618E9C44C1C563A10F74B, FB64939029B8E5DC1318EBE3FDAFC9F6 + 31: 8338B7BCA36C104C4B7EEBFF582FEAF879894FD6F00434859AD94E644BEC60, 93DECCE7AD61E69A2BD6621FEE2953D9 + 32: 21DC38BE252ECCA74963965660C98B5D9B5C2411945D8AAF9EF93732748A6162, 2BBE555F1D3C94BC6F1665A6DEDB536C + +EAX-kasumi (16 byte key) + 0: , 9E0C41B26B960E81 + 1: 03, 26B904336B9E0BDA + 2: 9EB8, 18E90B52DB587A8B + 3: F8E4F4, 9842D0A42ACC7717 + 4: B5688382, 2134820AF25CFFF5 + 5: 582E9402B2, 9C0F60D5B2D4BEA8 + 6: 836A3CEA4965, 6EB7565E0FF7FFCA + 7: 00DD66F0AB54AE, 0CAFA81DFB52F835 + 8: F5824156469E77DA, 44AEED7DA55C7C2F + 9: FCED54C15FAE6EB601, 95D7A3592D5F3B0E + 10: 0630750CAF71D334562C, D8F7432F9AAEC624 + 11: 25E3C5FAFE86F59D30BEDE, 42E3F6C3B8F73F64 + 12: B98480D54E604E4CFB988EFB, 2BCA65A62CE3E363 + 13: F07F1F98A2411749EA11FD87F2, EC7C07D37B7CC07C + 14: 19A6D648AD698ADED0AF37001479, F88417372E600717 + 15: 17CE88FC64ED98233BBAB20AA4DA45, 4959410987AE317B + 16: 61EE83703D8CA5D652F8E1E83C86D58F, 57EC73A828C20B68 + +EAX-multi2 (40 byte key) + 0: , E3EB492A2A560816 + 1: C6, E0A176A66E269255 + 2: 1D00, 472E25EF8B4ED450 + 3: 1DFE5A, BEDB3404162C7122 + 4: 915B77D4, BABBB74A3EE61755 + 5: 3C966136E8, 603664C04EF42178 + 6: E4A4925C9F75, 41B77B32F28613DB + 7: 365BC4FEF0B1B0, BB09E42F396F3832 + 8: FFCE6DA57D7FE9D1, C11BA7A7B580032C + 9: 0413506EE42819574C, 9B5C6A8111BE7B29 + 10: 531319C06A4B68AE226C, 77BC1DF09414D212 + 11: 85C0454EB3B9CDEDD32EF9, 39576F2268A59EF6 + 12: 8FB1732015FD006D2FFA8D9C, F8F51511ECA4E0A7 + 13: 1654F11C940FCBA529D2384A0D, 871B4541612C7CCE + 14: F119DC9F998D92B4C45185CFA2D1, B50D3A61F3CE76B0 + 15: 05B051F7DA81609FAC41BF0A19C45A, DF1265F3F69625F5 + 16: A313136E4E7F1314E7ED504B48324047, A9D1C5527D6EF7D7 + EAX-camellia (16 byte key) 0: , 9E8CDB7237166EF9FD0605A0AD3E4070 1: 8A, 23F462AC7E22EB9078DAC34CB1CFFB08 diff --git a/notes/gcm_tv.txt b/notes/gcm_tv.txt index b5191f8f..1e998458 100644 --- a/notes/gcm_tv.txt +++ b/notes/gcm_tv.txt @@ -212,6 +212,41 @@ GCM-anubis (16 byte key) 31: 72DFB9E91A78EAFE758B4542206A4A957B4523A58428398C11BCF2AEAE1938, 307D0B876130E82804C1167E03B69B2F 32: 7275C6EBDC2680DFCB73326A987D2FBCE83E40A9AEFE6351CFDA7251A6FE10A6, 895E6EEAA9BD88594903325A063CA45F +GCM-seed (16 byte key) + 0: , C11F22F20140505084483597E4370F43 + 1: E1, D39B9E55EF1C94F1E15397E083346491 + 2: D46C, 1303648548ECD8B3992C803A648E3BEF + 3: CBBF1C, C965567985BCF2BCD4C9CF66B2168BD6 + 4: 30544838, 88D10DE290E82F2EFDBF50AD062A13FB + 5: 544DCAFBCB, 52AE6D0576B4D65D82088179EE8E5121 + 6: 26F91824D36D, 7EFF9AED81561EFD2FD4CCAA8CA3E49C + 7: ABAF75A310B8B2, C3E0E6FE9EF8B91325E7952205C3B215 + 8: 460EB25BAF346FEC, 78293B6E454C7A820B0D6ED86399CC70 + 9: CCE2D164E8BA0B80E2, 0DB9D3A14CDC8F8CBAE68D092D769697 + 10: 1C700418306E0FB9A09B, 5ACFC32C1CC06D63DA8F8139909FBB10 + 11: 8A306163BC711A92C1ED0C, 0518DED52A4D698C43709B17F8E6409F + 12: 7FAC8AE98C5D035703D3257D, EBD479B656C24E4E256CC207D26DCB2F + 13: 26DDDDAEAF072E292D9D3A8917, D1AE629015A78A35580B96B524C35A5C + 14: DA8D19951BC8EC2657142DB6239F, 56753850A747FCA0445BF881EFB466D3 + 15: EB82C127979C395018BC346B46C4C8, EFEBDA26F5A1F53BE6A2DECD5DAC0D88 + 16: AE6050FAB41D6EDCE402ED3FA5F56AE9, 2A8922AF8AC424433B13C96EF64721FE + 17: 47D7E682FF60C6F8B4DC1D43CCA75B7CDE, F7CEC551D1855914534CBF4B0F90AB36 + 18: 7DCD5194A227EC2AD352F14C4BC2958067D0, DA444BF98069E6BC209C9AE8C669E892 + 19: 3F9E6101EFFF05D547C881F463FFB43B0CC131, 0FCD327A4C3D9FB679E192C887CD0642 + 20: 70BE93EA6FB611EA7656A70B42AA444403DCD945, 75FA8421BF145219B6973657F9FAB726 + 21: 39A97F1B32D664E53734F506515BEFB3674E2F265C, FC47392114426ABEB42E9B7BD15ED237 + 22: 4D54574772CC127C2E87186E30D6BBD050231601B80E, 48E3BFD70F52434C8D92D412018345DE + 23: 6C757A980FAC2BA8257750293EB63E52A9F7EE10C96005, 4057EB8AF43227A23A85651C002BB795 + 24: 817FDC2FB49084CB3E0F306154ED9252C3FE1C39DF481DF7, 9F510141E2E1716F4738D9979C440C04 + 25: A55CECDEE410C0ED7140BDCEDDF57652D5400793996CB376AA, 0897B814408133BCD6F6392489BDDE4C + 26: BD5E9C3A051AC1FA975649EF4B8E2B6E8C317586643597548E8B, 316C16B9643C1704503CBAB5D01215DE + 27: 4AE2A8FBDA0E92A7C32F95FE5DC63AAD97CE8D07133F0787E1C2E0, B518CE779929E704846376C043D481EC + 28: 3AB6AB78B1C3978951A17A5DC6FEE1F2DA096770246DC040F72FD070, E459B8B8CC525428FB851D9B7616084A + 29: ECD99B0E203AD3E722ADD6A38159C4A2C9C4A4B1A4448EE55091D382E8, 49C80A40C5BC637BB27B69BC2AD0B9A3 + 30: 4EEFF7BF368A278B1C8524F0C805C37F84F6D54785D79BA378A6B9B2999D, 491F2F02B7CDC02A627BD052A007EE56 + 31: 3490DA4EA01B23E86382D3F7BFF3239190F4E19BC4A9BAEA8AEF893F382062, 8431CE0772CBF6867F4F40E45031D9F7 + 32: 590E5508063DC675310C74227B886E68E2C61825C5E9A08231810D11EA695481, B96C6391C22F3961B307578D47120C52 + GCM-camellia (16 byte key) 0: , 477650012AA6284033E1B85321EEF770 1: E1, 2E95EDCCAF3264B5178CD6ED0F2EDEEA diff --git a/notes/hashsum_tv.txt b/notes/hashsum_tv.txt index 228d9f0a..c7ee41a1 100644 --- a/notes/hashsum_tv.txt +++ b/notes/hashsum_tv.txt @@ -1,29 +1,29 @@ -blake2b-160: 684b540eb245ebba2cd66b7814fe6d787868a5bb *testprof/test.key -blake2b-256: 3aaa08120aa0174c105fd1f3412e3da30c3bbb9073569b0b8ae458b34de7780e *testprof/test.key -blake2b-384: c33f39ab19099d5dea6789479e23447857803a3f45361ea58dd69c7b8037c8697544b6a741e236215adcb8b38fa0cfc4 *testprof/test.key -blake2b-512: a2daabae6996e3bbfb76c5d277fb881107037c756173f510d83a78f669cf0b70a5088b971e30ca2168381568ea3d30b80a7b500944a5e2e3294f25aed4c3a5f1 *testprof/test.key -blake2s-128: 7e1f9b6de11a3c597308f9d8aacd7321 *testprof/test.key -blake2s-160: 3d1c9ae1a0afe8a6ef8b61d5380de7b061cd353c *testprof/test.key -blake2s-224: 95dacd83d0421b2d69a52d92ee54143bb97c91a61450d917a88d4388 *testprof/test.key -blake2s-256: 92ac6dc88b9ce4a75b2a54783435a37919303f713396db0e9ccd976d8c55f1cf *testprof/test.key -chc_hash: d50da1ea9b53c0b891c8bcb0a4c6e5e0 *testprof/test.key -md2: 0b327a17a102580ccde8081c18f137c7 *testprof/test.key -md4: 6df7b3c1f7fbcbf6b8246dc0046e9d6b *testprof/test.key -md5: 48fd9ed11c633069c3cf721611696a73 *testprof/test.key -rmd128: a78170e11d56605eb0f5e05e6a218e61 *testprof/test.key -rmd160: 56236b14cd15958c58136a295fa2b07c5edee009 *testprof/test.key -rmd256: a0a658b25b8841f20be8151eb5e2c1229f085dd5cf7aa8bef4c8e07ea5738913 *testprof/test.key -rmd320: 2ec15ca947f29dd8cef4782aeaeb4541ac00dc29e1649c4f5f4578ef0287091e513f9da423ce7319 *testprof/test.key -sha1: c17a11eef02d7a2ad7250bc2ee22bdf37ed21f0f *testprof/test.key -sha224: b226daa069512c849d55866470c23543d87e1fb768171efdcc6ab59a *testprof/test.key -sha256: 76ec7faebdc42a4de35ca70024c2d273e9f7856ca61612e89f5f66350ba8cf5f *testprof/test.key -sha3-224: 09525d6410c462e00e72ccd4304290bc59ff2b1b8e5322dbc197e169 *testprof/test.key -sha3-256: b9016fc9976545ad0183775d88f20df5295d40b31db00d85f6916333260b8ae2 *testprof/test.key -sha3-384: 5452977763b602df4185bbe7cce193346b09ee20d4a45a780fd44237e335ceaa71b9da06242621e159d796db9043c9be *testprof/test.key -sha3-512: 1fadf63073c8613d38d5c944e2e3f7e086d94d93dceb2eec1e9693fd44158f3127c90cbaa8a13035cc9ff9b3572c9dce836bea15c92e8a78b036ec382caceb0f *testprof/test.key -sha384: 7cc080c662524617e56d5a49f1c185909e9b1858a86684161ddd97fc5426f693b53f59d779de16da25dcb1259df879e5 *testprof/test.key -sha512: f90afe4d254716a9770fd2c4f29ca544f2975f961cbd7fa207117383e4e48f7a2e1ade4aac333a2cb8c227dd6af2fff4d87c31c2a3916ae24d507c7c94c21818 *testprof/test.key -sha512-224: 64ec566b5c2de736eab1b4e8542dc110f736819ea7f8f48e3712fbad *testprof/test.key -sha512-256: db880bce4beb7246510febb961c7595aab57a15de6f90cd079f145e476b5d773 *testprof/test.key -tiger: 97d713850e7affac30a642572c1ee7b18793d5b9e0ef5932 *testprof/test.key -whirlpool: d7d41c755e0f28313f254cb198e0bfa42f56670595d97b80dceec754825d69938a9c11e5bf16e9a3809a62a09bddf021f3dbff4302ceec7ba46c88b41772b711 *testprof/test.key +blake2b-160: 684b540eb245ebba2cd66b7814fe6d787868a5bb *tests/test.key +blake2b-256: 3aaa08120aa0174c105fd1f3412e3da30c3bbb9073569b0b8ae458b34de7780e *tests/test.key +blake2b-384: c33f39ab19099d5dea6789479e23447857803a3f45361ea58dd69c7b8037c8697544b6a741e236215adcb8b38fa0cfc4 *tests/test.key +blake2b-512: a2daabae6996e3bbfb76c5d277fb881107037c756173f510d83a78f669cf0b70a5088b971e30ca2168381568ea3d30b80a7b500944a5e2e3294f25aed4c3a5f1 *tests/test.key +blake2s-128: 7e1f9b6de11a3c597308f9d8aacd7321 *tests/test.key +blake2s-160: 3d1c9ae1a0afe8a6ef8b61d5380de7b061cd353c *tests/test.key +blake2s-224: 95dacd83d0421b2d69a52d92ee54143bb97c91a61450d917a88d4388 *tests/test.key +blake2s-256: 92ac6dc88b9ce4a75b2a54783435a37919303f713396db0e9ccd976d8c55f1cf *tests/test.key +chc_hash: d50da1ea9b53c0b891c8bcb0a4c6e5e0 *tests/test.key +md2: 0b327a17a102580ccde8081c18f137c7 *tests/test.key +md4: 6df7b3c1f7fbcbf6b8246dc0046e9d6b *tests/test.key +md5: 48fd9ed11c633069c3cf721611696a73 *tests/test.key +rmd128: a78170e11d56605eb0f5e05e6a218e61 *tests/test.key +rmd160: 56236b14cd15958c58136a295fa2b07c5edee009 *tests/test.key +rmd256: a0a658b25b8841f20be8151eb5e2c1229f085dd5cf7aa8bef4c8e07ea5738913 *tests/test.key +rmd320: 2ec15ca947f29dd8cef4782aeaeb4541ac00dc29e1649c4f5f4578ef0287091e513f9da423ce7319 *tests/test.key +sha1: c17a11eef02d7a2ad7250bc2ee22bdf37ed21f0f *tests/test.key +sha224: b226daa069512c849d55866470c23543d87e1fb768171efdcc6ab59a *tests/test.key +sha256: 76ec7faebdc42a4de35ca70024c2d273e9f7856ca61612e89f5f66350ba8cf5f *tests/test.key +sha3-224: 09525d6410c462e00e72ccd4304290bc59ff2b1b8e5322dbc197e169 *tests/test.key +sha3-256: b9016fc9976545ad0183775d88f20df5295d40b31db00d85f6916333260b8ae2 *tests/test.key +sha3-384: 5452977763b602df4185bbe7cce193346b09ee20d4a45a780fd44237e335ceaa71b9da06242621e159d796db9043c9be *tests/test.key +sha3-512: 1fadf63073c8613d38d5c944e2e3f7e086d94d93dceb2eec1e9693fd44158f3127c90cbaa8a13035cc9ff9b3572c9dce836bea15c92e8a78b036ec382caceb0f *tests/test.key +sha384: 7cc080c662524617e56d5a49f1c185909e9b1858a86684161ddd97fc5426f693b53f59d779de16da25dcb1259df879e5 *tests/test.key +sha512: f90afe4d254716a9770fd2c4f29ca544f2975f961cbd7fa207117383e4e48f7a2e1ade4aac333a2cb8c227dd6af2fff4d87c31c2a3916ae24d507c7c94c21818 *tests/test.key +sha512-224: 64ec566b5c2de736eab1b4e8542dc110f736819ea7f8f48e3712fbad *tests/test.key +sha512-256: db880bce4beb7246510febb961c7595aab57a15de6f90cd079f145e476b5d773 *tests/test.key +tiger: 97d713850e7affac30a642572c1ee7b18793d5b9e0ef5932 *tests/test.key +whirlpool: d7d41c755e0f28313f254cb198e0bfa42f56670595d97b80dceec754825d69938a9c11e5bf16e9a3809a62a09bddf021f3dbff4302ceec7ba46c88b41772b711 *tests/test.key diff --git a/notes/ocb3_tv.txt b/notes/ocb3_tv.txt index c923fa32..5e9e8bf6 100644 --- a/notes/ocb3_tv.txt +++ b/notes/ocb3_tv.txt @@ -459,6 +459,79 @@ OCB-khazad (16 byte key) 15: B5F13633767C37E2A5BE44B95AC80D, C66A029513179FAF 16: BBAB31F93B165465FE5E2133810E46C2, 146A3AA6A6A68E2A +OCB-seed (16 byte key) + 0: , 31FC3BE15BE66DE898D8E64F043EF5F2 + 1: 13, 71D7F7D74329C74E68209EBCEC6ED76B + 2: 65DE, 63484B2DB036CE460F25E5F42FB996D9 + 3: A6F3A8, 779A84F1B325BC7746DD61C982C0C84A + 4: CD93DE8A, 78B2B22BF20F341225D239AD89BC0400 + 5: 39D1DC6410, 6BD9D8849627A1C866C8882686F59F8E + 6: 1A90FE8478E0, D99148D2185D130069D1007F759F1952 + 7: 7B021158285E6F, D64304C2FCB0C4207E1172D9F5EDFA54 + 8: 3938321C337EB440, 7535C124E443A1AAC16FF84A8A2D4E73 + 9: 69D89353ACD77C251A, 8BE9575D98A8F6BBA1BCF49F0D133A57 + 10: 4FA9D0AA53C795D8B4A6, D424622976F53C3F862D9C09780D134B + 11: 10E2F16190079B783912FC, 3354E1E8AC4D661B82C1BE44A094E9C0 + 12: 87769AA867DF8624E1C6CC9C, 537FCA01A65D7783E7DF1D337D6F71E9 + 13: 0547E2F6A8017FF31D24EC9F20, 2ECC8DD05C36CCCB1262FFBE6A810E79 + 14: 6B234F55551F86F2478D6A7E910C, 91863300122086508F0259054125736E + 15: AAF361AFF276F996740A110F1868F8, 9DCF980FB47D0533D168490887E1718F + 16: 114A274873A4E60CD175DCC60823DE3F, 9C5F32D0D32F82FFE776025BACFFBF20 + 17: B13F7DC743D559613F563315D68EE30AF2, 9FDA482FEFFFE96F8F748A7B0DA24D71 + 18: 79A2D1D9667777680DB25BB68105378B7981, CC45BA5C13450BCDEACEDD602729A337 + 19: 683E53C85E7000019CD5B8C78FB66E3D4EE0C9, AA4533EBB37F197D1402143CCB0887F0 + 20: 546D9B5CF8FB4BC20CE200C67ACBEB79530AEEA8, 5E9C1CF09C360A0F0C386BD93A9C91F5 + 21: 8CB773A96DA7E4A83FA214BC94117CE042CC2620DD, 058229EBA77FF300E0448C29D37C839A + 22: B13348E2E498E2A02B08CD94B5A66786334B0A415C4B, C9E19F610CC82B0242E8546272D20E3D + 23: 53BD3612B86412C39B98C322AA0E6352A1A3A66A992EC2, 3880B204A156302679F07932103DD531 + 24: 30E2B86833BE1A5187E65F4EFC24D1F753EA2B5D89C87F06, 99FCBA36AB397837A7F9F53C0EF7DBC6 + 25: 03D03F968292C26A26CA833F5F186ACE9BC5D2B6678C4DC220, 3F34D2FBDFBD688A03C29E49B02DDF04 + 26: D443389FE849AF4A74DBDFA2936C8D7DC0C69721C2B3375DFA24, 10198F7477ECF631207AACEC364638A2 + 27: BAF661D4BA70F9E310CD930F36DE90CCDD9DB3473B8A5747A0B5A8, B080FEBEC0497EB16D978E3B8DFFDB77 + 28: 5FE274B3A042BC903879B600C0DF31EB66A260D8ECAE09E45DFA4650, EB35B008EBB5098CFA03B010E1B4AD4F + 29: B124A2D8B0187DD409C7CAA44764C587052FB9B4750CA0DB0174D120CB, 2C48CC7B2D61D68B311F294AE6D6292B + 30: 8488F0C46151994F7798F70F55C7DA1D242B58CFF49BBFF458D5E574EAD0, 94C2D7BB27BBE184AC75213C1147DA71 + 31: 84050C6EBBD37CFCB7DAAC665A15FE459E420FC32CB7677089B236E6EC06F4, 5AC1CDFB43DC955D727FDED9847D9CCE + 32: 3EF03B96631A35B492DD1DC49D7862AA4D0DBDC9161D46711FA5360C1B4E76C7, 567869D045CF62531A10C6B9C3E4CE29 + +OCB-kasumi (16 byte key) + 0: , 8A6AB01A47834615 + 1: 23, 5184BF3E82D10C7F + 2: FDDB, EA45B282D973729D + 3: 8E3693, 432EFEDC2F238A6C + 4: 2409AE69, 7899D1928D55C08B + 5: CA037E6EF1, CA831CE963C9AD95 + 6: BC530A4140A2, EA77571BFFF105A1 + 7: 98B672C2D201EF, 607822313DBC9796 + 8: 26F9AB69E145B531, 7951CE4DC8C47F98 + 9: 30BFC33675F27F7EEB, D17DC60BF79939D2 + 10: F5F816B636D91279AC1C, E2C7B48991DEEF2F + 11: 705C47FABE7905757C0ED2, AADB2A403B861D55 + 12: 50DEB9C57870B744152ADF08, CB6126DAB93504D1 + 13: 767CB16AA8380C8F25A28A2039, F2C271CC48E067E6 + 14: 3A67656FD8B6ABA8BE7F3BE6C123, 462B6736DF6DC3B1 + 15: 21FB98C62DF932E70D05EB915BA8CF, AEFB635A4E0B6C60 + 16: EA8305ADB368267AB86F3ADDE5EE1719, 97E72E1B174A04F7 + +OCB-multi2 (40 byte key) + 0: , AF7F5567D2CFBAA8 + 1: 15, 66BDF680986FAD17 + 2: C94C, D35B49ADC2B24181 + 3: A0516B, DBA6331562F87FE7 + 4: 49C24A69, 6B88C358FF40AD0F + 5: E1839EFAB4, 08B6C2F97518E402 + 6: 71CF3D6DC458, 7CA89CC9D23CF4CE + 7: 02AC7B36DCD0CC, 00331F043D5FB756 + 8: 216F3088BE2553AA, 8A58C76BF8EBC046 + 9: DA0CC0753327707AE3, 8716B1FB7196CB14 + 10: 12B88569BDAAACA144AE, 71A031364BF44ECD + 11: 35B7F2ECD911F86DA2040C, 7649CD32D29AA258 + 12: BF20840BA08B0C85BEAC80B6, C8BD34015F1E3578 + 13: 2A3F508352AA5673BD5A880093, 9987F70EF92CE4E6 + 14: 5DC44D52A234D9A1ABA4C9BF8301, 728D3D9BC56140E7 + 15: 5FCB0AF77D9BA605056BA9178B15FC, A59675797C1307E2 + 16: 09BB95F7F998572CC38719BC4047BA3A, 5F4DA28D281C7FE9 + OCB-camellia (16 byte key) 0: , 3F877FAB2796D87C990AE311F952ABD1 1: 00, DD1FC339F770744F39B1A41A3A82CAEA diff --git a/notes/ocb_tv.txt b/notes/ocb_tv.txt index b93d7e29..076885db 100644 --- a/notes/ocb_tv.txt +++ b/notes/ocb_tv.txt @@ -459,6 +459,79 @@ OCB-khazad (16 byte key) 15: D870479780CC5B3B13A7A39029A56F, 003D3FCD31D497B5 16: A47BF1218AC86A60F6002CE004AF5E50, B4EC27091D5DCD58 +OCB-seed (16 byte key) + 0: , D80D16D2D0FB2BD9EBA4912468B893D7 + 1: 12, 8776140CB818C1CBFD2CFCD8BDFC9FFA + 2: F8A1, 597381977898AC43194C302216113CEB + 3: B35B5E, BC327275E7A552C4E0AC0FCB8403A6C4 + 4: 19F57542, 4E49DE569547B619E4187239D9B755C2 + 5: EAD2D99E86, 53DCC5FAB4DE25541A22AF0309C9FE78 + 6: 4902A8FF9AF9, 950D9A28DFBDAECE5F14D47E6B7A8B8B + 7: 45FE502602EA4E, 69CD243A3CF17FE51ABBFA2CDE510BCC + 8: D54F2EDE48207CFB, 775EE6140AACF9D56787071F08F36F67 + 9: FEDBBFD9FAABC80186, B37B2C643D62A205BD009BB55D50B918 + 10: 3541A86C889AFEB783B7, FE41A36AC076F417B6A3870DB712CC1F + 11: 62EB71A2EAFDDE1A050AFC, A953ECF1F0B53438E869F0CFB84CB142 + 12: 77AFE377460D6A51208194DB, 5CC2A9D8499F1B25D78937DAFB1DED10 + 13: A34FCDD7CA45DFAA2178CDC7E8, A14A119115143EE2B4719282C9E2356C + 14: A61FA4E9550280C8AAC87EF7A204, A87DDD9631C87ED0792C067E8D7F1D9B + 15: EE82AF5C51896AED298B0C12E00ECF, 9051873090B013508F93677D3A080E96 + 16: 5D532646FAD510E984959C4E14F853D7, 275D8DF932818030F1269804DE06A73B + 17: 1D77F8916DF479DDCE3F49A1D9DEFA40FB, 99611A067F45F140AFDB6FB7E9C23DF2 + 18: 5857267B77E7B8D7732509AEAC0AA80BDB2C, 3159BF09910493977A33268C7F7DBC01 + 19: 1CF64E54D48811F02DAAE472846E65235DC8B7, 78F88A35E2D93A0746058D1B37762A27 + 20: 8CC20A5FEFE9AAE81742DE70453F62A961188DB7, EDA9E9208EC38152E53AFD62ABC77F0B + 21: 1D6CCEEEC72CC7369C33F5CD83ED0DCD6F5613D562, 9FEFD274F3F906B11DD87CC2C0F9D0A2 + 22: 20A9C1EAD88F005DB8F69C8BE005D8A010B261FF2EAD, A341F754932DCBC6DAFE4231918A9CF1 + 23: DCEC1BB28E8D77D69B5148FB02E02C281B68BA6E9768B0, 6AAB2EEB1D25D2DF7CEEFA6054E295DA + 24: 7C4F7165943DB1EFA5731F5C75931F4391F0C40D5731BC54, 3FBFF88733ACE5289D9FB9CD24C44C3F + 25: F5E2C8A9B3A02E0BB86F9E969B0EDA5F554B0C8902BB6F4643, DFB22569019686B2EE92ABA9EE6610B0 + 26: 42B7D0E9613AFAD6E8093E4F638BC96E22413F15A84202188C31, 002F0F602F596236A8F239E81CE47FC0 + 27: 88B89B7756BD3BE09467998FABD12BCE87E5FE994ADE9B30844AE6, 05E0E8AFA55C3B571A849CE4C9F1F477 + 28: 10452565D15D1D829FC54F61960C6A749AFB91086E388269CF6B588A, DD88B0C63E040DF8878B3C919AA95218 + 29: E68619409B86082C744496FC3F645CE1134E84192D2CBCE1CFEEB12612, 83258C337EF21302724CE051A03195D6 + 30: 840277319319EF1DDF6A57682B6695550157F5B76756BF81BFFB3394AFC0, 183FA85F8E91F8972DA23108FA066F20 + 31: C74A4B01328B809397C07F4FC16131FBEE6396293181C327ADB50EF39CC936, D6C5CF79D47995D7CDB5745F601D859F + 32: FF3FEE866339B01DD2C1EC0C0E569A458A77DD014AF0CC9C0A8DC52A52133940, BF1AF01F2CB34CBAF1EAB96FBCCB5404 + +OCB-kasumi (16 byte key) + 0: , 7B4CE3A5B7284F8B + 1: F8, 80584D787B7AE753 + 2: D37A, 7BD7B52BE65B995C + 3: 2D07BF, 6E6E16FDFE808D21 + 4: 9F1A8E7F, 810CDE98B80F2CF2 + 5: C6A7842512, CB6E9709AD7E8545 + 6: 056553F25EE5, 24A74A113D68E373 + 7: C3E0215DEABD43, 80B9F0ABDC207E04 + 8: 38DA7B24B04DDF91, AEEB273DCAE4F743 + 9: 34169FBF64966E0EB8, 1D10D18FC0DF5372 + 10: 5B3A510F1AE97BFCE1EA, 5B1342A77724DBF7 + 11: 39D1B5067E584E59BB6603, 38EDA20D46B2563D + 12: AC2DD02E2406D7D8175EB308, AE7DCB1AE6188975 + 13: B0623EDBC20FEBEDF9B4AB70E6, E218732D221A04A4 + 14: 82F57A435A92E28B56F4EF5E7EA8, CC5842752D089C26 + 15: F2D54E3B9022AB32F668AD5A20D050, D811DF3DE76089FF + 16: 1CAC13A538AFC64D9747226AC23F072C, 2DF49C64213B35B9 + +OCB-multi2 (40 byte key) + 0: , 70A2AD75028C8B3E + 1: 3E, 76BE76B249142049 + 2: 5C21, E31CDBD0ED6B864D + 3: 62BC9F, F1124FC4C9C82617 + 4: BB5AC85A, 97035E20D4FFEC81 + 5: 500D9D05E3, 86D5EC5AD1D55434 + 6: 5179B8442E46, 432EAB80B938A00E + 7: 361000D13C364B, 5ADB3F9FD65EC776 + 8: 5C5BD790B927CBE4, F6ED8E9D330FD37E + 9: 2020DD735C5D7B4739, F98DEFD6A8368E1F + 10: 008A8548790A3582C2AC, 041C4E2FA196390C + 11: E6409403D3E2E4385EE54E, 25AE9113A0E7A3EF + 12: E23E598908C755FCF9D51E39, 21BF8C9F319FB44F + 13: C1F13F46FF04717C7E54FFBDC7, E7D8CDF40A1D78A5 + 14: 27721EB66D4F6362308B96DD9895, A374C96FCA94C809 + 15: 1A393F94CB9ACD3BB93D8766C63569, 45A090303B71D35D + 16: BCC0498FB13CEE8A615FF6409EDF1707, 9589A4CBC481A455 + OCB-camellia (16 byte key) 0: , 6972CC27A9711EAE6654851AB8E0C53F 1: A2, 208D783961FD532E14376B4EE904FE52 diff --git a/notes/omac_tv.txt b/notes/omac_tv.txt index c98baca2..bffaaf68 100644 --- a/notes/omac_tv.txt +++ b/notes/omac_tv.txt @@ -459,6 +459,79 @@ OMAC-khazad (16 byte key) 15: BCAB623CAB7AAA23 16: 9BCEAB857596E478 +OMAC-seed (16 byte key) + 0: F184C3569AE39C95609E878E8E69D276 + 1: 6B94C6CEB7347C7E478D33FD1892032B + 2: 9FA405B299D5887181C5F09A27AF9F76 + 3: 7457B824FA672F0D939B3CD161A3D229 + 4: EF164E3F30058EA7BA10B1D7ABD945F8 + 5: 22FAD3E42EB96A6E6A66FA73FC96A9E4 + 6: 9BE414C3CD92860A67AFB7C45D0E0EEE + 7: 40DA2A768F6593E45214CB7F054A9BAA + 8: 9AFBBEEC8EFAFA7A22752F3BEE055811 + 9: 45EBA2A3EE9276A90FE7FC705086F59B + 10: 9FE7E1DE176065440B45B1F8F012B8E7 + 11: 5D45CE9EFB14AE973C6567E804492D4A + 12: BB37B25C98998B0CBDF7AA2BF86FBF3B + 13: D68EA4AD5B7C3E243872F5BCF7F24EE2 + 14: E880AEA09E328C58ED99928C7BB97DEE + 15: 4A9EBD30EAB684544D79A066545B100A + 16: CEFD858C3179B39BADA7EA0F6D3AB150 + 17: BD3336CB8C5AC6D327B310C2093FD087 + 18: ACB4B352003B45FE5E872647ACD2C945 + 19: 74FF04F0ED7ACBDFC2B8EDB0193312BF + 20: 950B9587B448A73F0566B6E5D30BD85E + 21: A1CEB1E515BEE6C0C2253415CEDB7F54 + 22: 5E3B9B8F983B882D48853403152BBD09 + 23: E7BB12680BFDC81851D08870862F5F70 + 24: C89D50E7BC1692A3EE29585F4C2861DB + 25: 1ACBB14354F3A1E002BBD065930F56B8 + 26: AECF4E3972E26A862DC9A0D0F78F4A75 + 27: 4E8663B1FD460CC7B6CA7D6D880209C8 + 28: 0350DFE2A107BB68BAD09A9461EE5E64 + 29: 89B70BBAF6E7F4E7E37F40D122588B0A + 30: EB0B22BCD7D61272372502B7EADA68A7 + 31: CC4FB973D094008F4B90D687CD91B4C9 + 32: C7162431A53216C22D47FA511B0A619E + +OMAC-kasumi (16 byte key) + 0: AF4289889D9AD5A1 + 1: C58E7863B4E8CE54 + 2: 2927047C455329BD + 3: 62905068423B826C + 4: 0BC0C92B5162FA20 + 5: 03E6D71DE770BB3A + 6: 6D48AB1CE5EC49FB + 7: 338597E9545657E8 + 8: 418BAF4EFB83DD50 + 9: A47BA8181D187753 + 10: 76FAA6B0FF3B9D4D + 11: C540C8A06345FAAE + 12: 67E454776D871265 + 13: D4E0ABD317993766 + 14: BD328F89D3C1FEA5 + 15: 580E74CB054A9F7D + 16: 121002BF94F18D90 + +OMAC-multi2 (40 byte key) + 0: 3A06523F10C9F2C5 + 1: 310F665F3A12E82A + 2: 459FB6A9AC69FE27 + 3: DEB259E248440826 + 4: 6598F16BC1BFB8C8 + 5: B37DFDF8DD61D479 + 6: 0CE3BD7843FC83C4 + 7: 3BB7880A7E8D6C9E + 8: 74BAA5B4EEFCFDB5 + 9: B71CC55A72D4BB4F + 10: BEF0C7D0781B368B + 11: 0CA0D02961398164 + 12: CF3848FA94C45657 + 13: 57EA86B185A210D3 + 14: 05887EB7679F4B62 + 15: F6A007FF4A175F82 + 16: 57E61B59AC9F3240 + OMAC-camellia (16 byte key) 0: B5664C5148FFB45297703BCC46C19E4E 1: 126EC31A554E8B3B635DE4617092ECE8 diff --git a/notes/pmac_tv.txt b/notes/pmac_tv.txt index 2f9d1753..81df41a0 100644 --- a/notes/pmac_tv.txt +++ b/notes/pmac_tv.txt @@ -459,6 +459,79 @@ PMAC-khazad (16 byte key) 15: 93098DA8A180AA35 16: BACE2F4DA8A89E32 +PMAC-seed (16 byte key) + 0: 58844BC0C53AACF808587A7C35C37DE2 + 1: 481E3E0831DF5AED135C71BBBD075F4A + 2: 11355F9D42E7BAD967DF90E9088D45A7 + 3: 5E3F82EF0B3CA70DCB614C1016DDB052 + 4: 35E283B0E6C538ED5F2DF4E004324865 + 5: 56467B8BA87BDE89DF4A64DC9B9409CF + 6: 9315AAAE6CA0868FDCBC397B7DC2DF84 + 7: A265D861DCE6C9B80CCFF92463DB27D3 + 8: 196A0813E4EB49F47A1C3713950B194E + 9: 261372868D259E609BE5080F282B361A + 10: DFDC55CDF60A0CB6A33BC6F4B5E5A481 + 11: 0BD99E075BC93386CDB40C2AAF8E8918 + 12: CA1B80D0088D7267C9AFB037DCD8FA56 + 13: 8EDBC9F77D4DAB3DFABEAB0891622F1C + 14: D1A8F869C961739ABFE7F401FA41D6F6 + 15: 653041670E0BAD5D1FE77A19D9439CEE + 16: 440EF361908A528B2A3ED7C50C1A47AB + 17: DCE2613438A5DC42AC8F5CE753DDF01D + 18: F9E313156CA5345CECB1A5F963E9B201 + 19: 34D72FB89BA3C41E1D0597531849C6C9 + 20: 7ED20B28067BA27E37606387D641B75F + 21: 933A2E06DA91C208297305FFF4F7795B + 22: CC455E1FB196CF5B233921AA6A048B81 + 23: 613AC1EE5B8D0C3123A18BED9A352980 + 24: 00A2BBEEB98DB190A694B67EF85A65A4 + 25: 1A7D50E6051D85CA81D9DD7DE81BF02E + 26: A7F948B36D7AF08FB405A1B8C8C6AC6D + 27: 967DC3981E7C718B562A93E5292B872F + 28: 2674544D8D3E3F750590992C0AFB36AF + 29: 193A2CC794CB285B4CB87197EE3550ED + 30: 312AAC97C92279428FB1AA0882DB7088 + 31: 3B9CBA2FF7FF4113BB2DC0DF6BCADDD0 + 32: 45C5C71122C70F4337F5EC74BA6B446D + +PMAC-kasumi (16 byte key) + 0: 52DF2D9A9EB4816A + 1: 201C1024E6D2AF23 + 2: 04E7B341BFC96D1A + 3: CC11D07594C50F31 + 4: EE27EAEED00E2F97 + 5: 51DB73EC42ADB789 + 6: 097A5F01A90BFE7F + 7: 7FD121FD6B504A9D + 8: 8A09BC5C1E7FA48C + 9: B7A88328D7D84C9E + 10: 1D34173FA9F1DFCD + 11: 129AC84C0429E80E + 12: 81D236AC427123E4 + 13: 72D4EFEDD56F6253 + 14: ACFC8D6AF30F8B64 + 15: C7F75094394C1765 + 16: D95208BCB48FAA38 + +PMAC-multi2 (40 byte key) + 0: 4799ECD07D95FF68 + 1: 5B94DBFD53C531D7 + 2: DF09EDE792536619 + 3: 01FB72E4EE79DFEF + 4: 4159642D6ED0D4D8 + 5: B6909A449A0A85BB + 6: 20B167D3AA349DEA + 7: E550AAB246D99D92 + 8: 5E1042397C86B08C + 9: 3789D96B64C85AC0 + 10: 72C0921EF5B5DEDE + 11: 5923493300FA910E + 12: B589609B09B4D12F + 13: 5EA42FE501CD696D + 14: 4413763D2689108B + 15: 07207040BAFC8E6D + 16: 4E80F408AA6F1DD9 + PMAC-camellia (16 byte key) 0: 33C03F6AA205F3816A17DA92BEE0BAD2 1: AD1EC293DD032511579235B2F29CC909 diff --git a/run.sh b/run.sh index 5c5b3922..a0f6af35 100755 --- a/run.sh +++ b/run.sh @@ -22,6 +22,16 @@ else exit 1 fi +rm -f testok.txt +bash build.sh " $1" "$2" "$3 LTC_DEBUG=1" "$4" "$5" +if [ -a testok.txt ] && [ -f testok.txt ]; then + echo +else + echo + echo "Test failed" + exit 1 +fi + rm -f testok.txt bash build.sh " $1" "$2" "$3" "$4" "$5" if [ -a testok.txt ] && [ -f testok.txt ]; then diff --git a/src/ciphers/safer/safer.c b/src/ciphers/safer/safer.c index 85af1f20..11f4b1b1 100644 --- a/src/ciphers/safer/safer.c +++ b/src/ciphers/safer/safer.c @@ -35,8 +35,7 @@ #define __LTC_SAFER_TAB_C__ #include "safer_tab.c" -const struct ltc_cipher_descriptor - safer_k64_desc = { +const struct ltc_cipher_descriptor safer_k64_desc = { "safer-k64", 8, 8, 8, 8, LTC_SAFER_K64_DEFAULT_NOF_ROUNDS, &safer_k64_setup, diff --git a/src/encauth/ccm/ccm_memory.c b/src/encauth/ccm/ccm_memory.c index 3e1920a8..de842816 100644 --- a/src/encauth/ccm/ccm_memory.c +++ b/src/encauth/ccm/ccm_memory.c @@ -378,7 +378,9 @@ int ccm_memory(int cipher, } #ifdef LTC_CLEAN_STACK +#ifdef LTC_FAST fastMask = 0; +#endif mask = 0; zeromem(skey, sizeof(*skey)); zeromem(PAD, sizeof(PAD)); diff --git a/src/encauth/ccm/ccm_test.c b/src/encauth/ccm/ccm_test.c index 51bc4afb..1177a0f8 100644 --- a/src/encauth/ccm/ccm_test.c +++ b/src/encauth/ccm/ccm_test.c @@ -165,27 +165,10 @@ int ccm_test(void) } } - if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) { -#if defined(LTC_TEST_DBG) - printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); - print_hex("ct is ", buf, tests[x].ptlen); - print_hex("ct should", tests[x].ct, tests[x].ptlen); -#endif + if (compare_testvector(buf, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "CCM encrypt data", x)) { return CRYPT_FAIL_TESTVECTOR; } - if (tests[x].taglen != taglen) { -#if defined(LTC_TEST_DBG) - printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); - printf("taglen %lu (is) %lu (should)\n", taglen, tests[x].taglen); -#endif - return CRYPT_FAIL_TESTVECTOR; - } - if (XMEMCMP(tag, tests[x].tag, tests[x].taglen)) { -#if defined(LTC_TEST_DBG) - printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); - print_hex("tag is ", tag, tests[x].taglen); - print_hex("tag should", tests[x].tag, tests[x].taglen); -#endif + if (compare_testvector(tag, taglen, tests[x].tag, tests[x].taglen, "CCM encrypt tag", x)) { return CRYPT_FAIL_TESTVECTOR; } @@ -220,12 +203,8 @@ int ccm_test(void) } } - if (XMEMCMP(buf2, tests[x].pt, tests[x].ptlen)) { -#if defined(LTC_TEST_DBG) - printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); - print_hex("pt is ", buf2, tests[x].ptlen); - print_hex("pt should", tests[x].pt, tests[x].ptlen); -#endif + + if (compare_testvector(buf2, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "CCM decrypt data", x)) { return CRYPT_FAIL_TESTVECTOR; } if (y == 0) { @@ -243,27 +222,12 @@ int ccm_test(void) tag3, &taglen, 1 )) != CRYPT_ERROR) { return CRYPT_FAIL_TESTVECTOR; } - if (XMEMCMP(buf2, zero, tests[x].ptlen)) { -#if defined(LTC_CCM_TEST_DBG) - printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); - print_hex("pt is ", buf2, tests[x].ptlen); - print_hex("pt should", zero, tests[x].ptlen); -#endif - return CRYPT_FAIL_TESTVECTOR; + if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) { + return CRYPT_FAIL_TESTVECTOR; } } else { - /* FIXME: Only check the tag if ccm_memory was not called: ccm_memory already - validates the tag. ccm_process and ccm_done should somehow do the same, - although with current setup it is impossible to keep the plaintext hidden - if the tag is incorrect. - */ - if (XMEMCMP(tag2, tests[x].tag, tests[x].taglen)) { -#if defined(LTC_TEST_DBG) - printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); - print_hex("tag is ", tag2, tests[x].taglen); - print_hex("tag should", tests[x].tag, tests[x].taglen); -#endif - return CRYPT_FAIL_TESTVECTOR; + if (compare_testvector(tag2, taglen, tests[x].tag, tests[x].taglen, "CCM decrypt tag", x)) { + return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/headers/tomcrypt_cipher.h b/src/headers/tomcrypt_cipher.h index 58f02db4..b49a799d 100644 --- a/src/headers/tomcrypt_cipher.h +++ b/src/headers/tomcrypt_cipher.h @@ -933,6 +933,7 @@ int find_cipher_any(const char *name, int blocklen, int keylen); int find_cipher_id(unsigned char ID); int register_cipher(const struct ltc_cipher_descriptor *cipher); int unregister_cipher(const struct ltc_cipher_descriptor *cipher); +int register_all_ciphers(void); int cipher_is_valid(int idx); LTC_MUTEX_PROTO(ltc_cipher_mutex) diff --git a/src/headers/tomcrypt_hash.h b/src/headers/tomcrypt_hash.h index c73d387a..1c272e2d 100644 --- a/src/headers/tomcrypt_hash.h +++ b/src/headers/tomcrypt_hash.h @@ -461,6 +461,7 @@ int find_hash_oid(const unsigned long *ID, unsigned long IDlen); int find_hash_any(const char *name, int digestlen); int register_hash(const struct ltc_hash_descriptor *hash); int unregister_hash(const struct ltc_hash_descriptor *hash); +int register_all_hashes(void); int hash_is_valid(int idx); LTC_MUTEX_PROTO(ltc_hash_mutex) diff --git a/src/headers/tomcrypt_misc.h b/src/headers/tomcrypt_misc.h index 76f4f6bc..fa0b7956 100644 --- a/src/headers/tomcrypt_misc.h +++ b/src/headers/tomcrypt_misc.h @@ -99,14 +99,7 @@ void crc32_finish(crc32_state *ctx, void *hash, unsigned long size); int crc32_test(void); #endif -/* yeah it's not exactly in misc in the library, but in testprof/x86_prof.c */ -#if defined(LTC_TEST) && defined(LTC_TEST_DBG) -void print_hex(const char* what, const void* v, const unsigned long l); int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which); -#else -#define compare_testvector(is, is_len, should, should_len, what, which) \ - ((((is_len) != (should_len)) || (XMEMCMP((is), (should), (is_len)) != 0)) ? 1 : 0) -#endif /* $Source$ */ /* $Revision$ */ diff --git a/src/headers/tomcrypt_prng.h b/src/headers/tomcrypt_prng.h index e06c68b8..1849e55a 100644 --- a/src/headers/tomcrypt_prng.h +++ b/src/headers/tomcrypt_prng.h @@ -199,6 +199,7 @@ extern const struct ltc_prng_descriptor sober128_desc; int find_prng(const char *name); int register_prng(const struct ltc_prng_descriptor *prng); int unregister_prng(const struct ltc_prng_descriptor *prng); +int register_all_prngs(void); int prng_is_valid(int idx); LTC_MUTEX_PROTO(ltc_prng_mutex) diff --git a/src/mac/hmac/hmac_test.c b/src/mac/hmac/hmac_test.c index 0c311c6b..f0b5e20b 100644 --- a/src/mac/hmac/hmac_test.c +++ b/src/mac/hmac/hmac_test.c @@ -609,20 +609,8 @@ int hmac_test(void) return err; } - if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0) { + if(compare_testvector(digest, outlen, cases[i].digest, (size_t)hash_descriptor[hash].hashsize, cases[i].num, i)) { failed++; -#ifdef LTC_TEST_DBG - { - printf("\nHMAC-%s test %s: Failed\n", cases[i].algo, cases[i].num); - print_hex("is", digest, hash_descriptor[hash].hashsize); - print_hex("should", cases[i].digest, hash_descriptor[hash].hashsize); - return CRYPT_FAIL_TESTVECTOR; - } -#if LTC_TEST_DBG > 1 - } else { - printf("HMAC-%s test %s: Passed\n", cases[i].algo, cases[i].num); -#endif -#endif } } diff --git a/src/misc/compare_testvector.c b/src/misc/compare_testvector.c new file mode 100644 index 00000000..64e4e63f --- /dev/null +++ b/src/misc/compare_testvector.c @@ -0,0 +1,77 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + */ + +#include "tomcrypt.h" + +/** + @file compare_testvecotr.c + Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel +*/ + +#if defined(LTC_TEST) && defined(LTC_TEST_DBG) +static void _print_hex(const char* what, const void* v, const unsigned long l) +{ + const unsigned char* p = v; + unsigned long x, y = 0, z; + fprintf(stderr, "%s contents: \n", what); + for (x = 0; x < l; ) { + fprintf(stderr, "%02X ", p[x]); + if (!(++x % 16) || x == l) { + if((x % 16) != 0) { + z = 16 - (x % 16); + if(z >= 8) + fprintf(stderr, " "); + for (; z != 0; --z) { + fprintf(stderr, " "); + } + } + fprintf(stderr, " | "); + for(; y < x; y++) { + if((y % 8) == 0) + fprintf(stderr, " "); + if(isgraph(p[y])) + fprintf(stderr, "%c", p[y]); + else + fprintf(stderr, "."); + } + fprintf(stderr, "\n"); + } + else if((x % 8) == 0) { + fprintf(stderr, " "); + } + } +} +#endif + +int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which) +{ + int res = 0; + if(is_len != should_len) + res = is_len > should_len ? -1 : 1; + else + res = XMEMCMP(is, should, MAX(is_len, should_len)); + +#if defined(LTC_TEST) && defined(LTC_TEST_DBG) + if (res != 0) { + fprintf(stderr, "Testvector #%i of %s failed:\n", which, what); + _print_hex("SHOULD", should, should_len); + _print_hex("IS ", is, is_len); + } +#else + LTC_UNUSED_PARAM(which); + LTC_UNUSED_PARAM(what); +#endif + + return res; +} + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/src/misc/crypt/crypt_find_cipher_any.c b/src/misc/crypt/crypt_find_cipher_any.c index 34cd8f00..a25a5b54 100644 --- a/src/misc/crypt/crypt_find_cipher_any.c +++ b/src/misc/crypt/crypt_find_cipher_any.c @@ -26,10 +26,10 @@ int find_cipher_any(const char *name, int blocklen, int keylen) { int x; - LTC_ARGCHK(name != NULL); - - x = find_cipher(name); - if (x != -1) return x; + if(name != NULL) { + x = find_cipher(name); + if (x != -1) return x; + } LTC_MUTEX_LOCK(<c_cipher_mutex); for (x = 0; x < TAB_SIZE; x++) { diff --git a/src/misc/crypt/crypt_inits.c b/src/misc/crypt/crypt_inits.c index cc92f52f..4df6051d 100644 --- a/src/misc/crypt/crypt_inits.c +++ b/src/misc/crypt/crypt_inits.c @@ -19,24 +19,25 @@ #ifdef LTM_DESC -void init_LTM(void) { +void init_LTM(void) +{ ltc_mp = ltm_desc; } #endif #ifdef TFM_DESC -void init_TFM(void) { +void init_TFM(void) +{ ltc_mp = tfm_desc; } #endif -/* *** use of GMP is untested *** #ifdef GMP_DESC -void init_GMP(void) { +void init_GMP(void) +{ ltc_mp = gmp_desc; } #endif -*/ /* $Source$ */ diff --git a/src/misc/crypt/crypt_register_all_ciphers.c b/src/misc/crypt/crypt_register_all_ciphers.c new file mode 100644 index 00000000..7d83acb2 --- /dev/null +++ b/src/misc/crypt/crypt_register_all_ciphers.c @@ -0,0 +1,98 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +#include "tomcrypt.h" + +/** + @file crypt_register_all_ciphers.c + + Steffen Jaeckel +*/ + +#define REGISTER_CIPHER(h) do {\ + LTC_ARGCHK((err = register_cipher(h) == -1 ? CRYPT_ERROR : CRYPT_OK) == CRYPT_OK); \ +} while(0) + +int register_all_ciphers(void) +{ + int err = CRYPT_NOP; + +#ifdef LTC_RIJNDAEL +#ifdef ENCRYPT_ONLY + /* alternative would be + * register_cipher(&rijndael_enc_desc); + */ + REGISTER_CIPHER(&aes_enc_desc); +#else + /* alternative would be + * register_cipher(&rijndael_desc); + */ + REGISTER_CIPHER(&aes_desc); +#endif +#endif +#ifdef LTC_BLOWFISH + REGISTER_CIPHER(&blowfish_desc); +#endif +#ifdef LTC_XTEA + REGISTER_CIPHER(&xtea_desc); +#endif +#ifdef LTC_RC5 + REGISTER_CIPHER(&rc5_desc); +#endif +#ifdef LTC_RC6 + REGISTER_CIPHER(&rc6_desc); +#endif +#ifdef LTC_SAFERP + REGISTER_CIPHER(&saferp_desc); +#endif +#ifdef LTC_TWOFISH + REGISTER_CIPHER(&twofish_desc); +#endif +#ifdef LTC_SAFER + REGISTER_CIPHER(&safer_k64_desc); + REGISTER_CIPHER(&safer_sk64_desc); + REGISTER_CIPHER(&safer_k128_desc); + REGISTER_CIPHER(&safer_sk128_desc); +#endif +#ifdef LTC_RC2 + REGISTER_CIPHER(&rc2_desc); +#endif +#ifdef LTC_DES + REGISTER_CIPHER(&des_desc); + REGISTER_CIPHER(&des3_desc); +#endif +#ifdef LTC_CAST5 + REGISTER_CIPHER(&cast5_desc); +#endif +#ifdef LTC_NOEKEON + REGISTER_CIPHER(&noekeon_desc); +#endif +#ifdef LTC_SKIPJACK + REGISTER_CIPHER(&skipjack_desc); +#endif +#ifdef LTC_ANUBIS + REGISTER_CIPHER(&anubis_desc); +#endif +#ifdef LTC_KHAZAD + REGISTER_CIPHER(&khazad_desc); +#endif +#ifdef LTC_KSEED + REGISTER_CIPHER(&kseed_desc); +#endif +#ifdef LTC_KASUMI + REGISTER_CIPHER(&kasumi_desc); +#endif +#ifdef LTC_MULTI2 + REGISTER_CIPHER(&multi2_desc); +#endif +#ifdef LTC_CAMELLIA + REGISTER_CIPHER(&camellia_desc); +#endif + return err; +} diff --git a/src/misc/crypt/crypt_register_all_hashes.c b/src/misc/crypt/crypt_register_all_hashes.c new file mode 100644 index 00000000..64ec0ccf --- /dev/null +++ b/src/misc/crypt/crypt_register_all_hashes.c @@ -0,0 +1,96 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +#include "tomcrypt.h" + +/** + @file crypt_register_all_hashes.c + + Steffen Jaeckel +*/ + +#define REGISTER_HASH(h) do {\ + LTC_ARGCHK((err = register_hash(h) == -1 ? CRYPT_ERROR : CRYPT_OK) == CRYPT_OK); \ +} while(0) + +int register_all_hashes(void) +{ + int err = CRYPT_NOP; +#ifdef LTC_TIGER + REGISTER_HASH(&tiger_desc); +#endif +#ifdef LTC_MD2 + REGISTER_HASH(&md2_desc); +#endif +#ifdef LTC_MD4 + REGISTER_HASH(&md4_desc); +#endif +#ifdef LTC_MD5 + REGISTER_HASH(&md5_desc); +#endif +#ifdef LTC_SHA1 + REGISTER_HASH(&sha1_desc); +#endif +#ifdef LTC_SHA224 + REGISTER_HASH(&sha224_desc); +#endif +#ifdef LTC_SHA256 + REGISTER_HASH(&sha256_desc); +#endif +#ifdef LTC_SHA384 + REGISTER_HASH(&sha384_desc); +#endif +#ifdef LTC_SHA512 + REGISTER_HASH(&sha512_desc); +#endif +#ifdef LTC_SHA512_224 + REGISTER_HASH(&sha512_224_desc); +#endif +#ifdef LTC_SHA512_256 + REGISTER_HASH(&sha512_256_desc); +#endif +#ifdef LTC_SHA3 + REGISTER_HASH(&sha3_224_desc); + REGISTER_HASH(&sha3_256_desc); + REGISTER_HASH(&sha3_384_desc); + REGISTER_HASH(&sha3_512_desc); +#endif +#ifdef LTC_RIPEMD128 + REGISTER_HASH(&rmd128_desc); +#endif +#ifdef LTC_RIPEMD160 + REGISTER_HASH(&rmd160_desc); +#endif +#ifdef LTC_RIPEMD256 + REGISTER_HASH(&rmd256_desc); +#endif +#ifdef LTC_RIPEMD320 + REGISTER_HASH(&rmd320_desc); +#endif +#ifdef LTC_WHIRLPOOL + REGISTER_HASH(&whirlpool_desc); +#endif +#ifdef LTC_BLAKE2S + REGISTER_HASH(&blake2s_128_desc); + REGISTER_HASH(&blake2s_160_desc); + REGISTER_HASH(&blake2s_224_desc); + REGISTER_HASH(&blake2s_256_desc); +#endif +#ifdef LTC_BLAKE2S + REGISTER_HASH(&blake2b_160_desc); + REGISTER_HASH(&blake2b_256_desc); + REGISTER_HASH(&blake2b_384_desc); + REGISTER_HASH(&blake2b_512_desc); +#endif +#ifdef LTC_CHC_HASH + REGISTER_HASH(&chc_desc); + LTC_ARGCHK((err = chc_register(find_cipher_any("aes", 8, 16))) == CRYPT_OK); +#endif + return err; +} diff --git a/src/misc/crypt/crypt_register_all_prngs.c b/src/misc/crypt/crypt_register_all_prngs.c new file mode 100644 index 00000000..ccd8a8c7 --- /dev/null +++ b/src/misc/crypt/crypt_register_all_prngs.c @@ -0,0 +1,45 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +#include "tomcrypt.h" + +/** + @file crypt_register_all_prngs.c + + Steffen Jaeckel +*/ + +#define REGISTER_PRNG(h) do {\ + LTC_ARGCHK((err = register_prng(h) == -1 ? CRYPT_ERROR : CRYPT_OK) == CRYPT_OK); \ +} while(0) + +int register_all_prngs(void) +{ + int err = CRYPT_NOP; +#ifdef LTC_YARROW + REGISTER_PRNG(&yarrow_desc); +#endif +#ifdef LTC_FORTUNA + REGISTER_PRNG(&fortuna_desc); +#endif +#ifdef LTC_RC4 + REGISTER_PRNG(&rc4_desc); +#endif +#ifdef LTC_CHACHA20_PRNG + REGISTER_PRNG(&chacha20_prng_desc); +#endif +#ifdef LTC_SOBER128 + REGISTER_PRNG(&sober128_desc); +#endif +#ifdef LTC_SPRNG + REGISTER_PRNG(&sprng_desc); +#endif + + return err; +} diff --git a/src/misc/pkcs5/pkcs_5_test.c b/src/misc/pkcs5/pkcs_5_test.c index 46a8931e..c247fe8f 100644 --- a/src/misc/pkcs5/pkcs_5_test.c +++ b/src/misc/pkcs5/pkcs_5_test.c @@ -161,7 +161,9 @@ int pkcs_5_test (void) int hash = find_hash("sha1"); if (hash == -1) { +#ifdef LTC_TEST_DBG printf("PKCS#5 test failed: 'sha1' hash not found\n"); +#endif return CRYPT_ERROR; } @@ -173,27 +175,14 @@ int pkcs_5_test (void) (unsigned char*)cases_5_2[i].S, cases_5_2[i].S_len, cases_5_2[i].c, hash, DK, &dkLen)) != CRYPT_OK) { +#ifdef LTC_TEST_DBG printf("\nPKCS#5_2 test #%d: Failed/1\n", i); printf("err=%d\n", err); - ++failed; - } - else if (dkLen != cases_5_2[i].dkLen) { - printf("\nPKCS#5_2 test #%d: Failed/2\n", i); - printf("len is %d\n", (int)dkLen); - printf("len should %d\n", (int)cases_5_2[i].dkLen); - ++failed; - } - else if(XMEMCMP(DK, cases_5_2[i].DK, (size_t)cases_5_2[i].dkLen) != 0) { - printf("\nPKCS#5_2 test #%d: Failed/3\n", i); -#ifdef LTC_TEST_DBG - print_hex("is", DK, cases_5_2[i].dkLen); - print_hex("should", cases_5_2[i].DK, cases_5_2[i].dkLen); #endif ++failed; -#ifdef LTC_TEST_DBG - } else { - printf("PKCS#5_2 test #%d: Passed\n", i); -#endif + } + else if (compare_testvector(DK, dkLen, cases_5_2[i].DK, cases_5_2[i].dkLen, "PKCS#5_2", i)) { + ++failed; } } @@ -204,24 +193,15 @@ int pkcs_5_test (void) (unsigned char*)cases_5_1[i].S, cases_5_1[i].c, hash, DK, &dkLen)) != CRYPT_OK) { +#ifdef LTC_TEST_DBG printf("\nPKCS#5_1 test #%d: Failed/1\n", i); printf("err=%d\n", err); - ++failed; - } - else if (dkLen != cases_5_1[i].dkLen) { - printf("\nPKCS#5_1 test #%d: Failed/2\n", i); - printf("len is %d\n", (int)dkLen); - printf("len should %d\n", (int)cases_5_1[i].dkLen); - ++failed; - } - else if (XMEMCMP(DK, cases_5_1[i].DK, (size_t)cases_5_1[i].dkLen) != 0) { - printf("\nPKCS#5_1 test #%d: Failed/3\n", i); -#ifdef LTC_TEST_DBG - print_hex("is", DK, cases_5_1[i].dkLen); - print_hex("should", cases_5_1[i].DK, cases_5_1[i].dkLen); #endif ++failed; } + else if (compare_testvector(DK, dkLen, cases_5_1[i].DK, cases_5_1[i].dkLen, "PKCS#5_1", i)) { + ++failed; + } } /* testing alg 1_openssl */ @@ -231,24 +211,15 @@ int pkcs_5_test (void) (unsigned char*)cases_5_1o[i].S, cases_5_1o[i].c, hash, DK, &dkLen)) != CRYPT_OK) { +#ifdef LTC_TEST_DBG printf("\nPKCS#5_1o test #%d: Failed/1\n", i); printf("err=%d\n", err); - ++failed; - } - else if (dkLen != cases_5_1o[i].dkLen) { - printf("\nPKCS#5_1o test #%d: Failed/2\n", i); - printf("len is %d\n", (int)dkLen); - printf("len should %d\n", (int)cases_5_1o[i].dkLen); - ++failed; - } - else if (XMEMCMP(DK, cases_5_1o[i].DK, (size_t)cases_5_1o[i].dkLen) != 0) { - printf("\nPKCS#5_1o test #%d: Failed/3\n", i); -#ifdef LTC_TEST_DBG - print_hex("is", DK, cases_5_1o[i].dkLen); - print_hex("should", cases_5_1o[i].DK, cases_5_1o[i].dkLen); #endif ++failed; } + else if (compare_testvector(DK, dkLen, cases_5_1o[i].DK, cases_5_1o[i].dkLen, "PKCS#5_1o", i)) { + ++failed; + } } return (failed != 0) ? CRYPT_FAIL_TESTVECTOR : CRYPT_OK; diff --git a/src/modes/xts/xts_test.c b/src/modes/xts/xts_test.c index 7826d224..87c82b5b 100644 --- a/src/modes/xts/xts_test.c +++ b/src/modes/xts/xts_test.c @@ -262,15 +262,7 @@ int xts_test(void) } } - if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) { -#ifdef LTC_TEST_DBG - printf("\nTestcase #%d with original length %lu and half of it " - "%lu\n", - i, tests[i].PTLEN, len); - printf("\nencrypt\n"); - print_hex("should", tests[i].CTX, tests[i].PTLEN); - print_hex("is", OUT, tests[i].PTLEN); -#endif + if (compare_testvector(OUT, tests[i].PTLEN, tests[i].CTX, tests[i].PTLEN, "XTS encrypt", i)) { xts_done(&xts); return CRYPT_FAIL_TESTVECTOR; } @@ -295,12 +287,7 @@ int xts_test(void) } } - if (XMEMCMP(OUT, tests[i].PTX, tests[i].PTLEN)) { -#ifdef LTC_TEST_DBG - printf("\ndecrypt\n"); - print_hex("should", tests[i].PTX, tests[i].PTLEN); - print_hex("is", OUT, tests[i].PTLEN); -#endif + if (compare_testvector(OUT, tests[i].PTLEN, tests[i].PTX, tests[i].PTLEN, "XTS decrypt", i)) { xts_done(&xts); return CRYPT_FAIL_TESTVECTOR; } diff --git a/testprof/test_driver.c b/testprof/test_driver.c deleted file mode 100644 index b728f911..00000000 --- a/testprof/test_driver.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm) -{ - if (res != CRYPT_OK) { - fprintf(stderr, "%s (%d)%s%s\n%s:%d:%s\n", - error_to_string(res), res, - (algorithm ? " - " : ""), (algorithm ? algorithm : ""), - file, line, cmd); - if (res != CRYPT_NOP) { - exit(EXIT_FAILURE); - } - } -} - -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h deleted file mode 100644 index 48c6c07c..00000000 --- a/testprof/tomcrypt_test.h +++ /dev/null @@ -1,130 +0,0 @@ - -#ifndef __TEST_H_ -#define __TEST_H_ - -#include - -#ifdef USE_LTM -/* Use libtommath as MPI provider */ -#elif defined(USE_TFM) -/* Use tomsfastmath as MPI provider */ -#elif defined(USE_GMP) -/* Use GNU Multiple Precision Arithmetic Library as MPI provider */ -#else -/* The user must define his own MPI provider! */ -#ifndef EXT_MATH_LIB -/* - * Yes, you're right, you could also name your instance of the MPI provider - * "EXT_MATH_LIB" and you wouldn't need to define it, but most users won't do - * this and so it's treated as an error and you have to comment out the - * following statement :) - */ -#error EXT_MATH_LIB is required to be defined -#endif -#endif - -/* enable stack testing */ -/* #define STACK_TEST */ - -/* stack testing, define this if stack usage goes downwards [e.g. x86] */ -#define STACK_DOWN - -typedef struct { - char *name, *prov, *req; - int (*entry)(void); -} test_entry; - -extern prng_state yarrow_prng; - -void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm); - -#ifdef LTC_VERBOSE -#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0) -#define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0) -#else -#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0) -#define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0) -#endif - -/* TESTS */ -int cipher_hash_test(void); -int modes_test(void); -int mac_test(void); -int pkcs_1_test(void); -int pkcs_1_pss_test(void); -int pkcs_1_oaep_test(void); -int pkcs_1_emsa_test(void); -int pkcs_1_eme_test(void); -int store_test(void); -int rotate_test(void); -int rsa_test(void); -int dh_test(void); -int katja_test(void); -int ecc_tests(void); -int dsa_test(void); -int der_tests(void); -int misc_test(void); -int base64_test(void); -int file_test(void); -int multi_test(void); - -/* timing */ -#define KTIMES 25 -#define TIMES 100000 - -extern struct list { - int id; - ulong64 spd1, spd2, avg; -} results[]; - -extern int no_results; - -#ifdef LTC_PKCS_1 -extern const struct ltc_prng_descriptor no_prng_desc; -#endif - -void print_hex(const char* what, const void* v, const unsigned long l); -#ifndef compare_testvector -int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which); -#endif -int sorter(const void *a, const void *b); -void tally_results(int type); -ulong64 rdtsc (void); -ulong64 epoch_usec(void); - -void t_start(void); -ulong64 t_read(void); -void init_timer(void); - -/* register default algs */ -void reg_algs(void); -int time_keysched(void); -int time_cipher(void); -int time_cipher2(void); -int time_cipher3(void); -int time_cipher4(void); -int time_hash(void); -void time_mult(void); -void time_sqr(void); -void time_prng(void); -void time_rsa(void); -void time_dsa(void); -void time_katja(void); -void time_ecc(void); -void time_macs_(unsigned long MAC_SIZE); -void time_macs(void); -void time_encmacs(void); - - - -#if defined(_WIN32) - #define PRI64 "I64d" -#else - #define PRI64 "ll" -#endif - -#endif - -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c deleted file mode 100644 index 4ada14f3..00000000 --- a/testprof/x86_prof.c +++ /dev/null @@ -1,1781 +0,0 @@ -#include - -#if defined(_WIN32) - #include /* GetSystemTimeAsFileTime */ -#else - #include -#endif - -/* microseconds since 1970 (UNIX epoch) */ -ulong64 epoch_usec(void) -{ -#if defined(LTC_NO_TEST_TIMING) - return 0; -#elif defined(_WIN32) - FILETIME CurrentTime; - ulong64 cur_time; - ULARGE_INTEGER ul; - GetSystemTimeAsFileTime(&CurrentTime); - ul.LowPart = CurrentTime.dwLowDateTime; - ul.HighPart = CurrentTime.dwHighDateTime; - cur_time = ul.QuadPart; - cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */ - cur_time /= 10; /* nanoseconds > microseconds */ - return cur_time; -#else - struct timeval tv; - struct timezone tz; - gettimeofday(&tv, &tz); - return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */ -#endif -} - -prng_state yarrow_prng; - -void print_hex(const char* what, const void* v, const unsigned long l) -{ - const unsigned char* p = v; - unsigned long x, y = 0, z; - fprintf(stderr, "%s contents: \n", what); - for (x = 0; x < l; ) { - fprintf(stderr, "%02X ", p[x]); - if (!(++x % 16) || x == l) { - if((x % 16) != 0) { - z = 16 - (x % 16); - if(z >= 8) - fprintf(stderr, " "); - for (; z != 0; --z) { - fprintf(stderr, " "); - } - } - fprintf(stderr, " | "); - for(; y < x; y++) { - if((y % 8) == 0) - fprintf(stderr, " "); - if(isgraph(p[y])) - fprintf(stderr, "%c", p[y]); - else - fprintf(stderr, "."); - } - fprintf(stderr, "\n"); - } - else if((x % 8) == 0) { - fprintf(stderr, " "); - } - } -} - -#ifndef compare_testvector -int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which) -{ - int res = 0; - if(is_len != should_len) - res = is_len > should_len ? -1 : 1; - else - res = XMEMCMP(is, should, MAX(is_len, should_len)); - - if (res != 0) { - fprintf(stderr, "Testvector #%i of %s failed:\n", which, what); - print_hex("SHOULD", should, should_len); - print_hex("IS ", is, is_len); - } - - return res; -} -#endif - -struct list results[100]; -int no_results; -int sorter(const void *a, const void *b) -{ - const struct list *A, *B; - A = a; - B = b; - if (A->avg < B->avg) return -1; - if (A->avg > B->avg) return 1; - return 0; -} - -void tally_results(int type) -{ - int x; - - /* qsort the results */ - qsort(results, no_results, sizeof(struct list), &sorter); - - fprintf(stderr, "\n"); - if (type == 0) { - for (x = 0; x < no_results; x++) { - fprintf(stderr, "%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1); - } - } else if (type == 1) { - for (x = 0; x < no_results; x++) { - printf - ("%-20s[%3d]: Encrypt at %5"PRI64"u, Decrypt at %5"PRI64"u\n", cipher_descriptor[results[x].id].name, cipher_descriptor[results[x].id].ID, results[x].spd1, results[x].spd2); - } - } else { - for (x = 0; x < no_results; x++) { - printf - ("%-20s: Process at %5"PRI64"u\n", hash_descriptor[results[x].id].name, results[x].spd1 / 1000); - } - } -} - -/* RDTSC from Scott Duplichan */ -ulong64 rdtsc (void) - { - #if defined __GNUC__ && !defined(LTC_NO_ASM) - #if defined(__i386__) || defined(__x86_64__) - /* version from http://www.mcs.anl.gov/~kazutomo/rdtsc.html - * the old code always got a warning issued by gcc, clang did not complain... - */ - unsigned hi, lo; - __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); - return ((ulong64)lo)|( ((ulong64)hi)<<32); - #elif defined(LTC_PPC32) || defined(TFM_PPC32) - unsigned long a, b; - __asm__ __volatile__ ("mftbu %1 \nmftb %0\n":"=r"(a), "=r"(b)); - return (((ulong64)b) << 32ULL) | ((ulong64)a); - #elif defined(__ia64__) /* gcc-IA64 version */ - unsigned long result; - __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); - while (__builtin_expect ((int) result == -1, 0)) - __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); - return result; - #elif defined(__sparc__) - #if defined(__arch64__) - ulong64 a; - asm volatile("rd %%tick,%0" : "=r" (a)); - return a; - #else - register unsigned long x, y; - __asm__ __volatile__ ("rd %%tick, %0; clruw %0, %1; srlx %0, 32, %0" : "=r" (x), "=r" (y) : "0" (x), "1" (y)); - return ((unsigned long long) x << 32) | y; - #endif - #else - return XCLOCK(); - #endif - - /* Microsoft and Intel Windows compilers */ - #elif defined _M_IX86 && !defined(LTC_NO_ASM) - __asm rdtsc - #elif defined _M_AMD64 && !defined(LTC_NO_ASM) - return __rdtsc (); - #elif defined _M_IA64 && !defined(LTC_NO_ASM) - #if defined __INTEL_COMPILER - #include - #endif - return __getReg (3116); - #else - return XCLOCK(); - #endif - } - -static ulong64 timer, skew = 0; - -void t_start(void) -{ - timer = rdtsc(); -} - -ulong64 t_read(void) -{ - return rdtsc() - timer; -} - -void init_timer(void) -{ - ulong64 c1, c2, t1, t2; - unsigned long y1; - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < TIMES*100; y1++) { - t_start(); - t1 = t_read(); - t2 = (t_read() - t1)>>1; - - c1 = (t1 > c1) ? t1 : c1; - c2 = (t2 > c2) ? t2 : c2; - } - skew = c2 - c1; - fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew); -} - -/* - * unregister ciphers, hashes & prngs - */ -static void _unregister_all(void) -{ -#ifdef LTC_RIJNDAEL - unregister_cipher(&aes_desc); -#endif -#ifdef LTC_BLOWFISH - unregister_cipher(&blowfish_desc); -#endif -#ifdef LTC_XTEA - unregister_cipher(&xtea_desc); -#endif -#ifdef LTC_RC5 - unregister_cipher(&rc5_desc); -#endif -#ifdef LTC_RC6 - unregister_cipher(&rc6_desc); -#endif -#ifdef LTC_SAFERP - unregister_cipher(&saferp_desc); -#endif -#ifdef LTC_TWOFISH - unregister_cipher(&twofish_desc); -#endif -#ifdef LTC_SAFER - unregister_cipher(&safer_k64_desc); - unregister_cipher(&safer_sk64_desc); - unregister_cipher(&safer_k128_desc); - unregister_cipher(&safer_sk128_desc); -#endif -#ifdef LTC_RC2 - unregister_cipher(&rc2_desc); -#endif -#ifdef LTC_DES - unregister_cipher(&des_desc); - unregister_cipher(&des3_desc); -#endif -#ifdef LTC_CAST5 - unregister_cipher(&cast5_desc); -#endif -#ifdef LTC_NOEKEON - unregister_cipher(&noekeon_desc); -#endif -#ifdef LTC_SKIPJACK - unregister_cipher(&skipjack_desc); -#endif -#ifdef LTC_KHAZAD - unregister_cipher(&khazad_desc); -#endif -#ifdef LTC_ANUBIS - unregister_cipher(&anubis_desc); -#endif -#ifdef LTC_KSEED - unregister_cipher(&kseed_desc); -#endif -#ifdef LTC_KASUMI - unregister_cipher(&kasumi_desc); -#endif -#ifdef LTC_MULTI2 - unregister_cipher(&multi2_desc); -#endif -#ifdef LTC_CAMELLIA - unregister_cipher(&camellia_desc); -#endif - -#ifdef LTC_TIGER - unregister_hash(&tiger_desc); -#endif -#ifdef LTC_MD2 - unregister_hash(&md2_desc); -#endif -#ifdef LTC_MD4 - unregister_hash(&md4_desc); -#endif -#ifdef LTC_MD5 - unregister_hash(&md5_desc); -#endif -#ifdef LTC_SHA1 - unregister_hash(&sha1_desc); -#endif -#ifdef LTC_SHA224 - unregister_hash(&sha224_desc); -#endif -#ifdef LTC_SHA256 - unregister_hash(&sha256_desc); -#endif -#ifdef LTC_SHA384 - unregister_hash(&sha384_desc); -#endif -#ifdef LTC_SHA512 - unregister_hash(&sha512_desc); -#endif -#ifdef LTC_SHA512_224 - unregister_hash(&sha512_224_desc); -#endif -#ifdef LTC_SHA512_256 - unregister_hash(&sha512_256_desc); -#endif -#ifdef LTC_SHA3 - unregister_hash(&sha3_224_desc); - unregister_hash(&sha3_256_desc); - unregister_hash(&sha3_384_desc); - unregister_hash(&sha3_512_desc); -#endif -#ifdef LTC_RIPEMD128 - unregister_hash(&rmd128_desc); -#endif -#ifdef LTC_RIPEMD160 - unregister_hash(&rmd160_desc); -#endif -#ifdef LTC_RIPEMD256 - unregister_hash(&rmd256_desc); -#endif -#ifdef LTC_RIPEMD320 - unregister_hash(&rmd320_desc); -#endif -#ifdef LTC_WHIRLPOOL - unregister_hash(&whirlpool_desc); -#endif -#ifdef LTC_BLAKE2S - unregister_hash(&blake2s_128_desc); - unregister_hash(&blake2s_160_desc); - unregister_hash(&blake2s_224_desc); - unregister_hash(&blake2s_256_desc); -#endif -#ifdef LTC_BLAKE2B - unregister_hash(&blake2b_160_desc); - unregister_hash(&blake2b_256_desc); - unregister_hash(&blake2b_384_desc); - unregister_hash(&blake2b_512_desc); -#endif -#ifdef LTC_CHC_HASH - unregister_hash(&chc_desc); -#endif - - unregister_prng(&yarrow_desc); -#ifdef LTC_FORTUNA - unregister_prng(&fortuna_desc); -#endif -#ifdef LTC_RC4 - unregister_prng(&rc4_desc); -#endif -#ifdef LTC_CHACHA20_PRNG - unregister_prng(&chacha20_prng_desc); -#endif -#ifdef LTC_SOBER128 - unregister_prng(&sober128_desc); -#endif -} /* _cleanup() */ - -#ifdef LTC_PRNG_ENABLE_LTC_RNG - -static unsigned long my_test_rng_read; - -static unsigned long my_test_rng(unsigned char *buf, unsigned long len, - void (*callback)(void)) -{ - unsigned long n; - LTC_UNUSED_PARAM(callback); - for (n = 0; n < len; ++n) { - buf[n] = 4; - } - my_test_rng_read += n; - return n; -} - -#endif - -void reg_algs(void) -{ -#ifdef LTC_PRNG_ENABLE_LTC_RNG - unsigned long before; -#endif - int err; - - atexit(_unregister_all); - -#ifdef LTC_RIJNDAEL - register_cipher (&aes_desc); -#endif -#ifdef LTC_BLOWFISH - register_cipher (&blowfish_desc); -#endif -#ifdef LTC_XTEA - register_cipher (&xtea_desc); -#endif -#ifdef LTC_RC5 - register_cipher (&rc5_desc); -#endif -#ifdef LTC_RC6 - register_cipher (&rc6_desc); -#endif -#ifdef LTC_SAFERP - register_cipher (&saferp_desc); -#endif -#ifdef LTC_TWOFISH - register_cipher (&twofish_desc); -#endif -#ifdef LTC_SAFER - register_cipher (&safer_k64_desc); - register_cipher (&safer_sk64_desc); - register_cipher (&safer_k128_desc); - register_cipher (&safer_sk128_desc); -#endif -#ifdef LTC_RC2 - register_cipher (&rc2_desc); -#endif -#ifdef LTC_DES - register_cipher (&des_desc); - register_cipher (&des3_desc); -#endif -#ifdef LTC_CAST5 - register_cipher (&cast5_desc); -#endif -#ifdef LTC_NOEKEON - register_cipher (&noekeon_desc); -#endif -#ifdef LTC_SKIPJACK - register_cipher (&skipjack_desc); -#endif -#ifdef LTC_KHAZAD - register_cipher (&khazad_desc); -#endif -#ifdef LTC_ANUBIS - register_cipher (&anubis_desc); -#endif -#ifdef LTC_KSEED - register_cipher (&kseed_desc); -#endif -#ifdef LTC_KASUMI - register_cipher (&kasumi_desc); -#endif -#ifdef LTC_MULTI2 - register_cipher (&multi2_desc); -#endif -#ifdef LTC_CAMELLIA - register_cipher (&camellia_desc); -#endif - -#ifdef LTC_TIGER - register_hash (&tiger_desc); -#endif -#ifdef LTC_MD2 - register_hash (&md2_desc); -#endif -#ifdef LTC_MD4 - register_hash (&md4_desc); -#endif -#ifdef LTC_MD5 - register_hash (&md5_desc); -#endif -#ifdef LTC_SHA1 - register_hash (&sha1_desc); -#endif -#ifdef LTC_SHA224 - register_hash (&sha224_desc); -#endif -#ifdef LTC_SHA256 - register_hash (&sha256_desc); -#endif -#ifdef LTC_SHA384 - register_hash (&sha384_desc); -#endif -#ifdef LTC_SHA512 - register_hash (&sha512_desc); -#endif -#ifdef LTC_SHA512_224 - register_hash (&sha512_224_desc); -#endif -#ifdef LTC_SHA512_256 - register_hash (&sha512_256_desc); -#endif -#ifdef LTC_SHA3 - register_hash (&sha3_224_desc); - register_hash (&sha3_256_desc); - register_hash (&sha3_384_desc); - register_hash (&sha3_512_desc); -#endif -#ifdef LTC_RIPEMD128 - register_hash (&rmd128_desc); -#endif -#ifdef LTC_RIPEMD160 - register_hash (&rmd160_desc); -#endif -#ifdef LTC_RIPEMD256 - register_hash (&rmd256_desc); -#endif -#ifdef LTC_RIPEMD320 - register_hash (&rmd320_desc); -#endif -#ifdef LTC_WHIRLPOOL - register_hash (&whirlpool_desc); -#endif -#ifdef LTC_BLAKE2S - register_hash(&blake2s_128_desc); - register_hash(&blake2s_160_desc); - register_hash(&blake2s_224_desc); - register_hash(&blake2s_256_desc); -#endif -#ifdef LTC_BLAKE2S - register_hash(&blake2b_160_desc); - register_hash(&blake2b_256_desc); - register_hash(&blake2b_384_desc); - register_hash(&blake2b_512_desc); -#endif -#ifdef LTC_CHC_HASH - register_hash(&chc_desc); - if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) { - fprintf(stderr, "chc_register error: %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } -#endif - - -#ifndef LTC_YARROW - #error This demo requires Yarrow. -#endif -register_prng(&yarrow_desc); -#ifdef LTC_FORTUNA -register_prng(&fortuna_desc); -#endif -#ifdef LTC_RC4 -register_prng(&rc4_desc); -#endif -#ifdef LTC_CHACHA20_PRNG -register_prng(&chacha20_prng_desc); -#endif -#ifdef LTC_SOBER128 -register_prng(&sober128_desc); -#endif -#ifdef LTC_SPRNG -register_prng(&sprng_desc); -#endif - -#ifdef LTC_PRNG_ENABLE_LTC_RNG - ltc_rng = my_test_rng; - - before = my_test_rng_read; - if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { - fprintf(stderr, "rng_make_prng with 'my_test_rng' failed: %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - - if (before == my_test_rng_read) { - fprintf(stderr, "somehow there was no read from the ltc_rng! %lu == %lu\n", before, my_test_rng_read); - exit(EXIT_FAILURE); - } - - ltc_rng = NULL; -#endif - - if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { - fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - - if (strcmp("CRYPT_OK", error_to_string(err))) { - exit(EXIT_FAILURE); - } - -} - -int time_keysched(void) -{ - unsigned long x, y1; - ulong64 t1, c1; - symmetric_key skey; - int kl; - int (*func) (const unsigned char *, int , int , symmetric_key *); - unsigned char key[MAXBLOCKSIZE]; - - fprintf(stderr, "\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n"); - no_results = 0; - for (x = 0; cipher_descriptor[x].name != NULL; x++) { -#define DO1(k) func(k, kl, 0, &skey); - - func = cipher_descriptor[x].setup; - kl = cipher_descriptor[x].min_key_length; - c1 = (ulong64)-1; - for (y1 = 0; y1 < KTIMES; y1++) { - yarrow_read(key, kl, &yarrow_prng); - t_start(); - DO1(key); - t1 = t_read(); - c1 = (t1 > c1) ? c1 : t1; - } - t1 = c1 - skew; - results[no_results].spd1 = results[no_results].avg = t1; - results[no_results++].id = x; - fprintf(stderr, "."); fflush(stdout); - -#undef DO1 - } - tally_results(0); - - return 0; -} - -#ifdef LTC_ECB_MODE -int time_cipher(void) -{ - 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); - - /* sanity check on cipher */ - if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { - fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - -#define DO1 ecb_encrypt(pt, pt, sizeof(pt), &ecb); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a1 = c2 - c1 - skew; - -#undef DO1 -#undef DO2 -#define DO1 ecb_decrypt(pt, pt, sizeof(pt), &ecb); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a2 = c2 - c1 - skew; - ecb_done(&ecb); - - results[no_results].id = x; - results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; - ++no_results; - fprintf(stderr, "."); fflush(stdout); - -#undef DO2 -#undef DO1 - } - tally_results(1); - - return 0; -} -#else -int time_cipher(void) { fprintf(stderr, "NO ECB\n"); return 0; } -#endif - -#ifdef LTC_CBC_MODE -int time_cipher2(void) -{ - unsigned long x, y1; - ulong64 t1, t2, c1, c2, a1, a2; - symmetric_CBC cbc; - unsigned char key[MAXBLOCKSIZE], pt[4096]; - int err; - - fprintf(stderr, "\n\nCBC Time Trials for the Symmetric Ciphers:\n"); - no_results = 0; - for (x = 0; cipher_descriptor[x].name != NULL; x++) { - cbc_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &cbc); - - /* sanity check on cipher */ - if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { - fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - -#define DO1 cbc_encrypt(pt, pt, sizeof(pt), &cbc); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a1 = c2 - c1 - skew; - -#undef DO1 -#undef DO2 -#define DO1 cbc_decrypt(pt, pt, sizeof(pt), &cbc); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a2 = c2 - c1 - skew; - cbc_done(&cbc); - - results[no_results].id = x; - results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; - ++no_results; - fprintf(stderr, "."); fflush(stdout); - -#undef DO2 -#undef DO1 - } - tally_results(1); - - return 0; -} -#else -int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; } -#endif - -#ifdef LTC_CTR_MODE -int time_cipher3(void) -{ - unsigned long x, y1; - ulong64 t1, t2, c1, c2, a1, a2; - symmetric_CTR ctr; - unsigned char key[MAXBLOCKSIZE], pt[4096]; - int err; - - fprintf(stderr, "\n\nCTR Time Trials for the Symmetric Ciphers:\n"); - no_results = 0; - for (x = 0; cipher_descriptor[x].name != NULL; x++) { - ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr); - - /* sanity check on cipher */ - if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { - fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - -#define DO1 ctr_encrypt(pt, pt, sizeof(pt), &ctr); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a1 = c2 - c1 - skew; - -#undef DO1 -#undef DO2 -#define DO1 ctr_decrypt(pt, pt, sizeof(pt), &ctr); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a2 = c2 - c1 - skew; - ctr_done(&ctr); - - results[no_results].id = x; - results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; - ++no_results; - fprintf(stderr, "."); fflush(stdout); - -#undef DO2 -#undef DO1 - } - tally_results(1); - - return 0; -} -#else -int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; } -#endif - -#ifdef LTC_LRW_MODE -int time_cipher4(void) -{ - unsigned long x, y1; - ulong64 t1, t2, c1, c2, a1, a2; - symmetric_LRW lrw; - unsigned char key[MAXBLOCKSIZE], pt[4096]; - int err; - - fprintf(stderr, "\n\nLRW Time Trials for the Symmetric Ciphers:\n"); - no_results = 0; - for (x = 0; cipher_descriptor[x].name != NULL; x++) { - if (cipher_descriptor[x].block_length != 16) continue; - lrw_start(x, pt, key, cipher_descriptor[x].min_key_length, key, 0, &lrw); - - /* sanity check on cipher */ - if ((err = cipher_descriptor[x].test()) != CRYPT_OK) { - fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - -#define DO1 lrw_encrypt(pt, pt, sizeof(pt), &lrw); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a1 = c2 - c1 - skew; - -#undef DO1 -#undef DO2 -#define DO1 lrw_decrypt(pt, pt, sizeof(pt), &lrw); -#define DO2 DO1 DO1 - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < 100; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read(); - t2 -= t1; - - c1 = (t1 > c1 ? c1 : t1); - c2 = (t2 > c2 ? c2 : t2); - } - a2 = c2 - c1 - skew; - - lrw_done(&lrw); - - results[no_results].id = x; - results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length); - results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2; - ++no_results; - fprintf(stderr, "."); fflush(stdout); - -#undef DO2 -#undef DO1 - } - tally_results(1); - - return 0; -} -#else -int time_cipher4(void) { fprintf(stderr, "NO LRW\n"); return 0; } -#endif - - -int time_hash(void) -{ - unsigned long x, y1, len; - ulong64 t1, t2, c1, c2; - hash_state md; - int (*func)(hash_state *, const unsigned char *, unsigned long), err; - unsigned char pt[MAXBLOCKSIZE]; - - - fprintf(stderr, "\n\nHASH Time Trials for:\n"); - no_results = 0; - for (x = 0; hash_descriptor[x].name != NULL; x++) { - - /* sanity check on hash */ - if ((err = hash_descriptor[x].test()) != CRYPT_OK) { - fprintf(stderr, "\n\nERROR: Hash %s failed self-test %s\n", hash_descriptor[x].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - - hash_descriptor[x].init(&md); - -#define DO1 func(&md,pt,len); -#define DO2 DO1 DO1 - - func = hash_descriptor[x].process; - len = hash_descriptor[x].blocksize; - - c1 = c2 = (ulong64)-1; - for (y1 = 0; y1 < TIMES; y1++) { - t_start(); - DO1; - t1 = t_read(); - DO2; - t2 = t_read() - t1; - c1 = (t1 > c1) ? c1 : t1; - c2 = (t2 > c2) ? c2 : t2; - } - t1 = c2 - c1 - skew; - t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize); - results[no_results].id = x; - results[no_results].spd1 = results[no_results].avg = t1; - ++no_results; - fprintf(stderr, "."); fflush(stdout); -#undef DO2 -#undef DO1 - } - tally_results(2); - - return 0; -} - -/*#warning you need an mp_rand!!!*/ -#ifndef USE_LTM - #undef LTC_MPI -#endif - -#ifdef LTC_MPI -void time_mult(void) -{ - ulong64 t1, t2; - unsigned long x, y; - void *a, *b, *c; - - fprintf(stderr, "Timing Multiplying:\n"); - mp_init_multi(&a,&b,&c,NULL); - for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) { - mp_rand(a, x); - mp_rand(b, x); - -#define DO1 mp_mul(a, b, c); -#define DO2 DO1; DO1; - - t2 = -1; - for (y = 0; y < TIMES; y++) { - t_start(); - t1 = t_read(); - DO2; - t1 = (t_read() - t1)>>1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2); - } - mp_clear_multi(a,b,c,NULL); - -#undef DO1 -#undef DO2 -} - -void time_sqr(void) -{ - ulong64 t1, t2; - unsigned long x, y; - void *a, *b; - - fprintf(stderr, "Timing Squaring:\n"); - mp_init_multi(&a,&b,NULL); - for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) { - mp_rand(a, x); - -#define DO1 mp_sqr(a, b); -#define DO2 DO1; DO1; - - t2 = -1; - for (y = 0; y < TIMES; y++) { - t_start(); - t1 = t_read(); - DO2; - t1 = (t_read() - t1)>>1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2); - } - mp_clear_multi(a,b,NULL); - -#undef DO1 -#undef DO2 -} -#else -void time_mult(void) { fprintf(stderr, "NO MULT\n"); } -void time_sqr(void) { fprintf(stderr, "NO SQR\n"); } -#endif - -void time_prng(void) -{ - ulong64 t1, t2; - unsigned char buf[4096]; - prng_state tprng; - unsigned long x, y; - int err; - - fprintf(stderr, "Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n"); - for (x = 0; prng_descriptor[x].name != NULL; x++) { - - /* sanity check on prng */ - if ((err = prng_descriptor[x].test()) != CRYPT_OK) { - fprintf(stderr, "\n\nERROR: PRNG %s failed self-test %s\n", prng_descriptor[x].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - - prng_descriptor[x].start(&tprng); - zeromem(buf, 256); - prng_descriptor[x].add_entropy(buf, 256, &tprng); - prng_descriptor[x].ready(&tprng); - t2 = -1; - -#define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); } -#define DO2 DO1 DO1 - for (y = 0; y < 10000; y++) { - t_start(); - t1 = t_read(); - DO2; - t1 = (t_read() - t1)>>1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "%20s: %5"PRI64"u ", prng_descriptor[x].name, t2>>12); -#undef DO2 -#undef DO1 - -#define DO1 prng_descriptor[x].start(&tprng); prng_descriptor[x].add_entropy(buf, 32, &tprng); prng_descriptor[x].ready(&tprng); prng_descriptor[x].done(&tprng); -#define DO2 DO1 DO1 - for (y = 0; y < 10000; y++) { - t_start(); - t1 = t_read(); - DO2; - t1 = (t_read() - t1)>>1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "%5"PRI64"u\n", t2); -#undef DO2 -#undef DO1 - - } -} - -#ifdef LTC_MDSA -/* time various DSA operations */ -void time_dsa(void) -{ - dsa_key key; - ulong64 t1, t2; - unsigned long x, y; - int err; -static const struct { - int group, modulus; -} groups[] = { -{ 20, 96 }, -{ 20, 128 }, -{ 24, 192 }, -{ 28, 256 }, -{ 32, 512 } -}; - - for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) { - t2 = 0; - for (y = 0; y < 4; y++) { - t_start(); - t1 = t_read(); - if ((err = dsa_make_key(&yarrow_prng, find_prng("yarrow"), groups[x].group, groups[x].modulus, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\ndsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; - -#ifdef LTC_PROFILE - t2 <<= 2; - break; -#endif - if (y < 3) { - dsa_free(&key); - } - } - t2 >>= 2; - fprintf(stderr, "DSA-(%lu, %lu) make_key took %15"PRI64"u cycles\n", (unsigned long)groups[x].group*8, (unsigned long)groups[x].modulus*8, t2); - } -} -#endif - - -#ifdef LTC_MRSA -/* time various RSA operations */ -void time_rsa(void) -{ - rsa_key key; - ulong64 t1, t2; - unsigned char buf[2][2048]; - unsigned long x, y, z, zzz; - int err, zz, stat; - - for (x = 1024; x <= 2048; x += 256) { - t2 = 0; - for (y = 0; y < 4; y++) { - t_start(); - t1 = t_read(); - if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nrsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; - -#ifdef LTC_PROFILE - t2 <<= 2; - break; -#endif - - if (y < 3) { - rsa_free(&key); - } - } - t2 >>= 2; - fprintf(stderr, "RSA-%lu make_key took %15"PRI64"u cycles\n", x, t2); - - t2 = 0; - for (y = 0; y < 16; y++) { - t_start(); - t1 = t_read(); - z = sizeof(buf[1]); - if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, (const unsigned char *)"testprog", 8, &yarrow_prng, - find_prng("yarrow"), find_hash("sha1"), - &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 4; - break; -#endif - } - t2 >>= 4; - fprintf(stderr, "RSA-%lu encrypt_key took %15"PRI64"u cycles\n", x, t2); - - t2 = 0; - for (y = 0; y < 2048; y++) { - t_start(); - t1 = t_read(); - zzz = sizeof(buf[0]); - if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, (const unsigned char *)"testprog", 8, find_hash("sha1"), - &zz, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 11; - break; -#endif - } - t2 >>= 11; - fprintf(stderr, "RSA-%lu decrypt_key took %15"PRI64"u cycles\n", x, t2); - - t2 = 0; - for (y = 0; y < 256; y++) { - t_start(); - t1 = t_read(); - z = sizeof(buf[1]); - if ((err = rsa_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng, - find_prng("yarrow"), find_hash("sha1"), 8, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nrsa_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 8; - break; -#endif - } - t2 >>= 8; - fprintf(stderr, "RSA-%lu sign_hash took %15"PRI64"u cycles\n", x, t2); - - t2 = 0; - for (y = 0; y < 2048; y++) { - t_start(); - t1 = t_read(); - if ((err = rsa_verify_hash(buf[1], z, buf[0], 20, find_hash("sha1"), 8, &stat, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nrsa_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - if (stat == 0) { - fprintf(stderr, "\n\nrsa_verify_hash for RSA-%lu failed to verify signature(%lu)\n", x, y); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 11; - break; -#endif - } - t2 >>= 11; - fprintf(stderr, "RSA-%lu verify_hash took %15"PRI64"u cycles\n", x, t2); - fprintf(stderr, "\n\n"); - rsa_free(&key); - } -} -#else -void time_rsa(void) { fprintf(stderr, "NO RSA\n"); } -#endif - -#ifdef LTC_MKAT -/* time various KAT operations */ -void time_katja(void) -{ - katja_key key; - ulong64 t1, t2; - unsigned char buf[2][4096]; - unsigned long x, y, z, zzz; - int err, zz; - - for (x = 1024; x <= 2048; x += 256) { - t2 = 0; - for (y = 0; y < 4; y++) { - t_start(); - t1 = t_read(); - if ((err = katja_make_key(&yarrow_prng, find_prng("yarrow"), x/8, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nkatja_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; - - if (y < 3) { - katja_free(&key); - } - } - t2 >>= 2; - fprintf(stderr, "Katja-%lu make_key took %15"PRI64"u cycles\n", x, t2); - - t2 = 0; - for (y = 0; y < 16; y++) { - t_start(); - t1 = t_read(); - z = sizeof(buf[1]); - if ((err = katja_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng, - find_prng("yarrow"), find_hash("sha1"), - &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nkatja_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; - } - t2 >>= 4; - fprintf(stderr, "Katja-%lu encrypt_key took %15"PRI64"u cycles\n", x, t2); - - t2 = 0; - for (y = 0; y < 2048; y++) { - t_start(); - t1 = t_read(); - zzz = sizeof(buf[0]); - if ((err = katja_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8, find_hash("sha1"), - &zz, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\nkatja_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; - } - t2 >>= 11; - fprintf(stderr, "Katja-%lu decrypt_key took %15"PRI64"u cycles\n", x, t2); - - - katja_free(&key); - } -} -#else -void time_katja(void) { fprintf(stderr, "NO Katja\n"); } -#endif - -#ifdef LTC_MECC -/* time various ECC operations */ -void time_ecc(void) -{ - ecc_key key; - ulong64 t1, t2; - unsigned char buf[2][256]; - unsigned long i, w, x, y, z; - int err, stat; - static unsigned long sizes[] = { -#ifdef LTC_ECC112 -112/8, -#endif -#ifdef LTC_ECC128 -128/8, -#endif -#ifdef LTC_ECC160 -160/8, -#endif -#ifdef LTC_ECC192 -192/8, -#endif -#ifdef LTC_ECC224 -224/8, -#endif -#ifdef LTC_ECC256 -256/8, -#endif -#ifdef LTC_ECC384 -384/8, -#endif -#ifdef LTC_ECC521 -521/8, -#endif -100000}; - - for (x = sizes[i=0]; x < 100000; x = sizes[++i]) { - t2 = 0; - for (y = 0; y < 256; y++) { - t_start(); - t1 = t_read(); - if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; - -#ifdef LTC_PROFILE - t2 <<= 8; - break; -#endif - - if (y < 255) { - ecc_free(&key); - } - } - t2 >>= 8; - fprintf(stderr, "ECC-%lu make_key took %15"PRI64"u cycles\n", x*8, t2); - - t2 = 0; - for (y = 0; y < 256; y++) { - t_start(); - t1 = t_read(); - z = sizeof(buf[1]); - if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), - &key)) != CRYPT_OK) { - fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 8; - break; -#endif - } - t2 >>= 8; - fprintf(stderr, "ECC-%lu encrypt_key took %15"PRI64"u cycles\n", x*8, t2); - - t2 = 0; - for (y = 0; y < 256; y++) { - t_start(); - t1 = t_read(); - w = 20; - if ((err = ecc_decrypt_key(buf[1], z, buf[0], &w, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\necc_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 8; - break; -#endif - } - t2 >>= 8; - fprintf(stderr, "ECC-%lu decrypt_key took %15"PRI64"u cycles\n", x*8, t2); - - t2 = 0; - for (y = 0; y < 256; y++) { - t_start(); - t1 = t_read(); - z = sizeof(buf[1]); - if ((err = ecc_sign_hash(buf[0], 20, buf[1], &z, &yarrow_prng, - find_prng("yarrow"), &key)) != CRYPT_OK) { - fprintf(stderr, "\n\necc_sign_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 8; - break; -#endif - } - t2 >>= 8; - fprintf(stderr, "ECC-%lu sign_hash took %15"PRI64"u cycles\n", x*8, t2); - - t2 = 0; - for (y = 0; y < 256; y++) { - t_start(); - t1 = t_read(); - if ((err = ecc_verify_hash(buf[1], z, buf[0], 20, &stat, &key)) != CRYPT_OK) { - fprintf(stderr, "\n\necc_verify_hash says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK)); - exit(EXIT_FAILURE); - } - if (stat == 0) { - fprintf(stderr, "\n\necc_verify_hash for ECC-%lu failed to verify signature(%lu)\n", x*8, y); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - t2 += t1; -#ifdef LTC_PROFILE - t2 <<= 8; - break; -#endif - } - t2 >>= 8; - fprintf(stderr, "ECC-%lu verify_hash took %15"PRI64"u cycles\n", x*8, t2); - - fprintf(stderr, "\n\n"); - ecc_free(&key); - } -} -#else -void time_ecc(void) { fprintf(stderr, "NO ECC\n"); } -#endif - -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; - int err, cipher_idx, hash_idx; - - fprintf(stderr, "\nMAC Timings (cycles/byte on %luKB blocks):\n", MAC_SIZE); - - buf = XMALLOC(MAC_SIZE*1024); - if (buf == NULL) { - fprintf(stderr, "\n\nout of heap yo\n\n"); - exit(EXIT_FAILURE); - } - - cipher_idx = find_cipher("aes"); - hash_idx = find_hash("sha1"); - - if (cipher_idx == -1 || hash_idx == -1) { - fprintf(stderr, "Warning the MAC tests requires AES and SHA1 to operate... so sorry\n"); - exit(EXIT_FAILURE); - } - - yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); - yarrow_read(key, 16, &yarrow_prng); - -#ifdef LTC_OMAC - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = omac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\n\nomac-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "OMAC-%s\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_XCBC - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = xcbc_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\n\nxcbc-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "XCBC-%s\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_F9_MODE - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = f9_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\n\nF9-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "F9-%s\t\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_PMAC - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = pmac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\n\npmac-%s error... %s\n", cipher_descriptor[cipher_idx].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "PMAC-%s\t\t%9"PRI64"u\n", cipher_descriptor[cipher_idx].name, t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_PELICAN - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = pelican_memory(key, 16, buf, MAC_SIZE*1024, tag)) != CRYPT_OK) { - fprintf(stderr, "\n\npelican error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "PELICAN \t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_HMAC - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = hmac_memory(hash_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\n\nhmac-%s error... %s\n", hash_descriptor[hash_idx].name, error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "HMAC-%s\t\t%9"PRI64"u\n", hash_descriptor[hash_idx].name, t2/(ulong64)(MAC_SIZE*1024)); -#endif - - XFREE(buf); -#else - LTC_UNUSED_PARAM(MAC_SIZE); - fprintf(stderr, "NO MACs\n"); -#endif -} - -void time_macs(void) -{ - time_macs_(1); - time_macs_(4); - time_macs_(32); -} - -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; - int err, cipher_idx; - symmetric_key skey; - - fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE); - - buf = XMALLOC(MAC_SIZE*1024); - if (buf == NULL) { - fprintf(stderr, "\n\nout of heap yo\n\n"); - exit(EXIT_FAILURE); - } - - cipher_idx = find_cipher("aes"); - - yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng); - yarrow_read(key, 16, &yarrow_prng); - yarrow_read(IV, 16, &yarrow_prng); - -#ifdef LTC_EAX_MODE - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = eax_encrypt_authenticate_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\nEAX error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "EAX \t\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_OCB_MODE - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = ocb_encrypt_authenticate_memory(cipher_idx, key, 16, IV, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\nOCB error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "OCB \t\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_OCB3_MODE - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = ocb3_encrypt_authenticate_memory(cipher_idx, key, 16, IV, 16, (unsigned char*)"", 0, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\nOCB3 error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "OCB3 \t\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); -#endif - -#ifdef LTC_CCM_MODE - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = ccm_memory(cipher_idx, key, 16, NULL, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { - fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "CCM (no-precomp) \t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); - - cipher_descriptor[cipher_idx].setup(key, 16, 0, &skey); - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = ccm_memory(cipher_idx, key, 16, &skey, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) { - fprintf(stderr, "\nCCM error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "CCM (precomp) \t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); - cipher_descriptor[cipher_idx].done(&skey); -#endif - -#ifdef LTC_GCM_MODE - t2 = -1; - for (x = 0; x < 100; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = gcm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, GCM_ENCRYPT)) != CRYPT_OK) { - fprintf(stderr, "\nGCM error... %s\n", error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "GCM (no-precomp)\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); - - { - gcm_state gcm -#ifdef LTC_GCM_TABLES_SSE2 -__attribute__ ((aligned (16))) -#endif -; - - if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); } - t2 = -1; - for (x = 0; x < 10000; x++) { - t_start(); - t1 = t_read(); - z = 16; - if ((err = gcm_reset(&gcm)) != CRYPT_OK) { - fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); - exit(EXIT_FAILURE); - } - if ((err = gcm_add_iv(&gcm, IV, 16)) != CRYPT_OK) { - fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); - exit(EXIT_FAILURE); - } - if ((err = gcm_add_aad(&gcm, NULL, 0)) != CRYPT_OK) { - fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); - exit(EXIT_FAILURE); - } - if ((err = gcm_process(&gcm, buf, MAC_SIZE*1024, buf, GCM_ENCRYPT)) != CRYPT_OK) { - fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); - exit(EXIT_FAILURE); - } - - if ((err = gcm_done(&gcm, tag, &z)) != CRYPT_OK) { - fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err)); - exit(EXIT_FAILURE); - } - t1 = t_read() - t1; - if (t1 < t2) t2 = t1; - } - fprintf(stderr, "GCM (precomp)\t\t%9"PRI64"u\n", t2/(ulong64)(MAC_SIZE*1024)); - } - -#endif -#else - LTC_UNUSED_PARAM(MAC_SIZE); - fprintf(stderr, "NO ENCMACs\n"); -#endif - -} - -void time_encmacs(void) -{ - time_encmacs_(1); - time_encmacs_(4); - time_encmacs_(32); -} - -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ diff --git a/testprof/base64_test.c b/tests/base64_test.c similarity index 100% rename from testprof/base64_test.c rename to tests/base64_test.c diff --git a/testprof/cipher_hash_test.c b/tests/cipher_hash_test.c similarity index 100% rename from testprof/cipher_hash_test.c rename to tests/cipher_hash_test.c diff --git a/tests/common.c b/tests/common.c new file mode 100644 index 00000000..6fbab1fb --- /dev/null +++ b/tests/common.c @@ -0,0 +1,64 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +#include "common.h" + +/** + @file common.c + + Steffen Jaeckel +*/ + +void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm) +{ + if (res != CRYPT_OK) { + fprintf(stderr, "%s (%d)%s%s\n%s:%d:%s\n", + error_to_string(res), res, + (algorithm ? " - " : ""), (algorithm ? algorithm : ""), + file, line, cmd); + if (res != CRYPT_NOP) { + exit(EXIT_FAILURE); + } + } +} + +void print_hex(const char* what, const void* v, const unsigned long l) +{ + const unsigned char* p = v; + unsigned long x, y = 0, z; + fprintf(stderr, "%s contents: \n", what); + for (x = 0; x < l; ) { + fprintf(stderr, "%02X ", p[x]); + if (!(++x % 16) || x == l) { + if((x % 16) != 0) { + z = 16 - (x % 16); + if(z >= 8) + fprintf(stderr, " "); + for (; z != 0; --z) { + fprintf(stderr, " "); + } + } + fprintf(stderr, " | "); + for(; y < x; y++) { + if((y % 8) == 0) + fprintf(stderr, " "); + if(isgraph(p[y])) + fprintf(stderr, "%c", p[y]); + else + fprintf(stderr, "."); + } + fprintf(stderr, "\n"); + } + else if((x % 8) == 0) { + fprintf(stderr, " "); + } + } +} + +prng_state yarrow_prng; diff --git a/tests/common.h b/tests/common.h new file mode 100644 index 00000000..81672339 --- /dev/null +++ b/tests/common.h @@ -0,0 +1,20 @@ +#ifndef DEMOS_COMMON_H_ +#define DEMOS_COMMON_H_ + +#include + +extern prng_state yarrow_prng; + +#ifdef LTC_VERBOSE +#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0) +#define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0) +#else +#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0) +#define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0) +#endif + +void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm); + +void print_hex(const char* what, const void* v, const unsigned long l); + +#endif /* DEMOS_COMMON_H_ */ diff --git a/testprof/der_tests.c b/tests/der_test.c similarity index 99% rename from testprof/der_tests.c rename to tests/der_test.c index d165646c..63b45a8d 100644 --- a/testprof/der_tests.c +++ b/tests/der_test.c @@ -5,7 +5,7 @@ #ifndef LTC_DER -int der_tests(void) +int der_test(void) { return CRYPT_NOP; } @@ -1086,7 +1086,7 @@ static int der_choice_test(void) } -int der_tests(void) +int der_test(void) { unsigned long x, y, z, zz, oid[2][32]; unsigned char buf[3][2048]; diff --git a/testprof/dh_test.c b/tests/dh_test.c similarity index 100% rename from testprof/dh_test.c rename to tests/dh_test.c diff --git a/testprof/dsa_test.c b/tests/dsa_test.c similarity index 100% rename from testprof/dsa_test.c rename to tests/dsa_test.c diff --git a/testprof/ecc_test.c b/tests/ecc_test.c similarity index 100% rename from testprof/ecc_test.c rename to tests/ecc_test.c diff --git a/testprof/file_test.c b/tests/file_test.c similarity index 99% rename from testprof/file_test.c rename to tests/file_test.c index 3252e533..c2e4a381 100644 --- a/testprof/file_test.c +++ b/tests/file_test.c @@ -11,7 +11,7 @@ int file_test(void) 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; unsigned char buf[200]; unsigned long len; - char *fname = "testprof/test.key"; + char *fname = "tests/test.key"; FILE *in; int err, isha256, iaes; diff --git a/testprof/katja_test.c b/tests/katja_test.c similarity index 100% rename from testprof/katja_test.c rename to tests/katja_test.c diff --git a/testprof/mac_test.c b/tests/mac_test.c similarity index 100% rename from testprof/mac_test.c rename to tests/mac_test.c diff --git a/testprof/misc_test.c b/tests/misc_test.c similarity index 100% rename from testprof/misc_test.c rename to tests/misc_test.c diff --git a/testprof/modes_test.c b/tests/modes_test.c similarity index 100% rename from testprof/modes_test.c rename to tests/modes_test.c diff --git a/testprof/multi_test.c b/tests/multi_test.c similarity index 100% rename from testprof/multi_test.c rename to tests/multi_test.c diff --git a/testprof/no_prng.c b/tests/no_prng.c similarity index 100% rename from testprof/no_prng.c rename to tests/no_prng.c diff --git a/testprof/pkcs_1_eme_test.c b/tests/pkcs_1_eme_test.c similarity index 100% rename from testprof/pkcs_1_eme_test.c rename to tests/pkcs_1_eme_test.c diff --git a/testprof/pkcs_1_emsa_test.c b/tests/pkcs_1_emsa_test.c similarity index 100% rename from testprof/pkcs_1_emsa_test.c rename to tests/pkcs_1_emsa_test.c diff --git a/testprof/pkcs_1_oaep_test.c b/tests/pkcs_1_oaep_test.c similarity index 100% rename from testprof/pkcs_1_oaep_test.c rename to tests/pkcs_1_oaep_test.c diff --git a/testprof/pkcs_1_pss_test.c b/tests/pkcs_1_pss_test.c similarity index 100% rename from testprof/pkcs_1_pss_test.c rename to tests/pkcs_1_pss_test.c diff --git a/testprof/pkcs_1_test.c b/tests/pkcs_1_test.c similarity index 100% rename from testprof/pkcs_1_test.c rename to tests/pkcs_1_test.c diff --git a/tests/prng_test.c b/tests/prng_test.c new file mode 100644 index 00000000..15d953d4 --- /dev/null +++ b/tests/prng_test.c @@ -0,0 +1,45 @@ +#include + +#ifdef LTC_PRNG_ENABLE_LTC_RNG + +static unsigned long my_test_rng_read; + +static unsigned long my_test_rng(unsigned char *buf, unsigned long len, + void (*callback)(void)) +{ + unsigned long n; + LTC_UNUSED_PARAM(callback); + for (n = 0; n < len; ++n) { + buf[n] = 4; + } + my_test_rng_read += n; + return n; +} + +#endif + +int prng_test(void) +{ + int err = CRYPT_NOP; +#ifdef LTC_PRNG_ENABLE_LTC_RNG + unsigned long before; + + unsigned long (*previous)(unsigned char *, unsigned long , void (*)(void)) = ltc_rng; + ltc_rng = my_test_rng; + + before = my_test_rng_read; + + if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { + fprintf(stderr, "rng_make_prng with 'my_test_rng' failed: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + + if (before == my_test_rng_read) { + fprintf(stderr, "somehow there was no read from the ltc_rng! %lu == %lu\n", before, my_test_rng_read); + exit(EXIT_FAILURE); + } + + ltc_rng = previous; +#endif + return err; +} diff --git a/testprof/rotate_test.c b/tests/rotate_test.c similarity index 100% rename from testprof/rotate_test.c rename to tests/rotate_test.c diff --git a/testprof/rsa_test.c b/tests/rsa_test.c similarity index 96% rename from testprof/rsa_test.c rename to tests/rsa_test.c index 3540fd30..7154cf96 100644 --- a/testprof/rsa_test.c +++ b/tests/rsa_test.c @@ -274,29 +274,15 @@ int rsa_test(void) len = mp_unsigned_bin_size(key.N); mp_to_unsigned_bin(key.N, tmp); - fprintf(stderr, "N == \n"); -for (cnt = 0; cnt < len; ) { - fprintf(stderr, "%02x ", tmp[cnt]); - if (!(++cnt & 15)) fprintf(stderr, "\n"); -} +print_hex("N", tmp, len); len = mp_unsigned_bin_size(key.p); mp_to_unsigned_bin(key.p, tmp); - fprintf(stderr, "p == \n"); -for (cnt = 0; cnt < len; ) { - fprintf(stderr, "%02x ", tmp[cnt]); - if (!(++cnt & 15)) fprintf(stderr, "\n"); -} +print_hex("p", tmp, len); len = mp_unsigned_bin_size(key.q); mp_to_unsigned_bin(key.q, tmp); - fprintf(stderr, "\nq == \n"); -for (cnt = 0; cnt < len; ) { - fprintf(stderr, "%02x ", tmp[cnt]); - if (!(++cnt & 15)) fprintf(stderr, "\n"); -} - fprintf(stderr, "\n"); - +print_hex("q", tmp, len); return 1; } @@ -539,14 +525,8 @@ for (cnt = 0; cnt < len; ) { /* (3) */ DO(ltc_mp.rsa_me(p2, len2, p3, &len3, PK_PUBLIC, &key)); /* (4) */ -#ifdef LTC_TEST_DBG - cnt = rsa_get_size(&key); - printf("\nBefore:"); - for (cnt = 0; cnt < len3; ++cnt) { - if (cnt%32 == 0) - printf("\n%3lu:", cnt); - printf(" %02x", p3[cnt]); - } +#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1 + print_hex("Original signature", p3, len3); #endif /* (4.1) */ for (cnt = 0; cnt < len3; ++cnt) { @@ -563,14 +543,8 @@ for (cnt = 0; cnt < len; ) { for (cnt = cnt + len3-cnt2+i; cnt < len; ++cnt) { p3[cnt] = 0; } -#ifdef LTC_TEST_DBG - printf("\nAfter:"); - for (cnt = 0; cnt < len3; ++cnt) { - if (cnt%32 == 0) - printf("\n%3lu:", cnt); - printf(" %02x", p3[cnt]); - } - printf("\n"); +#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1 + print_hex("Forged signature", p3, len3); #endif len2 = sizeof(out); diff --git a/testprof/store_test.c b/tests/store_test.c similarity index 100% rename from testprof/store_test.c rename to tests/store_test.c diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 00000000..7ed1e185 --- /dev/null +++ b/tests/test.c @@ -0,0 +1,321 @@ +#include + +#ifndef GIT_VERSION +#define GIT_VERSION "Undefined version" +#endif + +#define LTC_TEST_FN(f) { f, #f } + +static const struct { + int (*fn)(void); + const char* name; +} test_functions[] = +{ + LTC_TEST_FN(store_test), + LTC_TEST_FN(rotate_test), + LTC_TEST_FN(misc_test), + LTC_TEST_FN(cipher_hash_test), + LTC_TEST_FN(mac_test), + LTC_TEST_FN(modes_test), + LTC_TEST_FN(der_test), + LTC_TEST_FN(pkcs_1_test), + LTC_TEST_FN(pkcs_1_pss_test), + LTC_TEST_FN(pkcs_1_oaep_test), + LTC_TEST_FN(pkcs_1_emsa_test), + LTC_TEST_FN(pkcs_1_eme_test), + LTC_TEST_FN(rsa_test), + LTC_TEST_FN(dh_test), + LTC_TEST_FN(ecc_tests), + LTC_TEST_FN(dsa_test), + LTC_TEST_FN(katja_test), + LTC_TEST_FN(file_test), + LTC_TEST_FN(multi_test), + LTC_TEST_FN(prng_test), +}; + +#if defined(_WIN32) + #include /* GetSystemTimeAsFileTime */ +#else + #include +#endif + +/* microseconds since 1970 (UNIX epoch) */ +static ulong64 epoch_usec(void) +{ +#if defined(LTC_NO_TEST_TIMING) + return 0; +#elif defined(_WIN32) + FILETIME CurrentTime; + ulong64 cur_time; + ULARGE_INTEGER ul; + GetSystemTimeAsFileTime(&CurrentTime); + ul.LowPart = CurrentTime.dwLowDateTime; + ul.HighPart = CurrentTime.dwHighDateTime; + cur_time = ul.QuadPart; + cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */ + cur_time /= 10; /* nanoseconds > microseconds */ + return cur_time; +#else + struct timeval tv; + struct timezone tz; + gettimeofday(&tv, &tz); + return (ulong64)(tv.tv_sec) * 1000000 + (ulong64)(tv.tv_usec); /* get microseconds */ +#endif +} + + +/* + * unregister ciphers, hashes & prngs + */ +static void _unregister_all(void) +{ +#ifdef LTC_RIJNDAEL + unregister_cipher(&aes_desc); +#endif +#ifdef LTC_BLOWFISH + unregister_cipher(&blowfish_desc); +#endif +#ifdef LTC_XTEA + unregister_cipher(&xtea_desc); +#endif +#ifdef LTC_RC5 + unregister_cipher(&rc5_desc); +#endif +#ifdef LTC_RC6 + unregister_cipher(&rc6_desc); +#endif +#ifdef LTC_SAFERP + unregister_cipher(&saferp_desc); +#endif +#ifdef LTC_TWOFISH + unregister_cipher(&twofish_desc); +#endif +#ifdef LTC_SAFER + unregister_cipher(&safer_k64_desc); + unregister_cipher(&safer_sk64_desc); + unregister_cipher(&safer_k128_desc); + unregister_cipher(&safer_sk128_desc); +#endif +#ifdef LTC_RC2 + unregister_cipher(&rc2_desc); +#endif +#ifdef LTC_DES + unregister_cipher(&des_desc); + unregister_cipher(&des3_desc); +#endif +#ifdef LTC_CAST5 + unregister_cipher(&cast5_desc); +#endif +#ifdef LTC_NOEKEON + unregister_cipher(&noekeon_desc); +#endif +#ifdef LTC_SKIPJACK + unregister_cipher(&skipjack_desc); +#endif +#ifdef LTC_KHAZAD + unregister_cipher(&khazad_desc); +#endif +#ifdef LTC_ANUBIS + unregister_cipher(&anubis_desc); +#endif +#ifdef LTC_KSEED + unregister_cipher(&kseed_desc); +#endif +#ifdef LTC_KASUMI + unregister_cipher(&kasumi_desc); +#endif +#ifdef LTC_MULTI2 + unregister_cipher(&multi2_desc); +#endif +#ifdef LTC_CAMELLIA + unregister_cipher(&camellia_desc); +#endif + +#ifdef LTC_TIGER + unregister_hash(&tiger_desc); +#endif +#ifdef LTC_MD2 + unregister_hash(&md2_desc); +#endif +#ifdef LTC_MD4 + unregister_hash(&md4_desc); +#endif +#ifdef LTC_MD5 + unregister_hash(&md5_desc); +#endif +#ifdef LTC_SHA1 + unregister_hash(&sha1_desc); +#endif +#ifdef LTC_SHA224 + unregister_hash(&sha224_desc); +#endif +#ifdef LTC_SHA256 + unregister_hash(&sha256_desc); +#endif +#ifdef LTC_SHA384 + unregister_hash(&sha384_desc); +#endif +#ifdef LTC_SHA512 + unregister_hash(&sha512_desc); +#endif +#ifdef LTC_SHA512_224 + unregister_hash(&sha512_224_desc); +#endif +#ifdef LTC_SHA512_256 + unregister_hash(&sha512_256_desc); +#endif +#ifdef LTC_SHA3 + unregister_hash(&sha3_224_desc); + unregister_hash(&sha3_256_desc); + unregister_hash(&sha3_384_desc); + unregister_hash(&sha3_512_desc); +#endif +#ifdef LTC_RIPEMD128 + unregister_hash(&rmd128_desc); +#endif +#ifdef LTC_RIPEMD160 + unregister_hash(&rmd160_desc); +#endif +#ifdef LTC_RIPEMD256 + unregister_hash(&rmd256_desc); +#endif +#ifdef LTC_RIPEMD320 + unregister_hash(&rmd320_desc); +#endif +#ifdef LTC_WHIRLPOOL + unregister_hash(&whirlpool_desc); +#endif +#ifdef LTC_BLAKE2S + unregister_hash(&blake2s_128_desc); + unregister_hash(&blake2s_160_desc); + unregister_hash(&blake2s_224_desc); + unregister_hash(&blake2s_256_desc); +#endif +#ifdef LTC_BLAKE2B + unregister_hash(&blake2b_160_desc); + unregister_hash(&blake2b_256_desc); + unregister_hash(&blake2b_384_desc); + unregister_hash(&blake2b_512_desc); +#endif +#ifdef LTC_CHC_HASH + unregister_hash(&chc_desc); +#endif + + unregister_prng(&yarrow_desc); +#ifdef LTC_FORTUNA + unregister_prng(&fortuna_desc); +#endif +#ifdef LTC_RC4 + unregister_prng(&rc4_desc); +#endif +#ifdef LTC_CHACHA20_PRNG + unregister_prng(&chacha20_prng_desc); +#endif +#ifdef LTC_SOBER128 + unregister_prng(&sober128_desc); +#endif +} /* _cleanup() */ + +static void register_algs(void) +{ + int err; + + atexit(_unregister_all); + +#ifndef LTC_YARROW + #error This demo requires Yarrow. +#endif + register_all_ciphers(); + register_all_hashes(); + register_all_prngs(); + + if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { + fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + + if (strcmp("CRYPT_OK", error_to_string(err))) { + exit(EXIT_FAILURE); + } +} + +int main(int argc, char **argv) +{ + int x, pass = 0, fail = 0, nop = 0; + size_t fn_len, i, dots; + char *single_test = NULL; + ulong64 ts; + long delta, dur = 0; + register_algs(); + + printf("build == %s\n%s\n", GIT_VERSION, crypt_build_settings); + +#ifdef USE_LTM + ltc_mp = ltm_desc; + printf("math provider = libtommath\n"); +#elif defined(USE_TFM) + ltc_mp = tfm_desc; + printf("math provider = tomsfastmath\n"); +#elif defined(USE_GMP) + ltc_mp = gmp_desc; + printf("math provider = gnump\n"); +#else + extern ltc_math_descriptor EXT_MATH_LIB; + ltc_mp = EXT_MATH_LIB; + printf("math provider = EXT_MATH_LIB\n"); +#endif + printf("MP_DIGIT_BIT = %d\n", MP_DIGIT_BIT); + + fn_len = 0; + for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) { + size_t len = strlen(test_functions[i].name); + if (fn_len < len) fn_len = len; + } + + fn_len = fn_len + (4 - (fn_len % 4)); + + /* single test name from commandline */ + if (argc > 1) single_test = argv[1]; + + for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) { + if (single_test && strcmp(test_functions[i].name, single_test)) { + continue; + } + dots = fn_len - strlen(test_functions[i].name); + + printf("\n%s", test_functions[i].name); + while(dots--) printf("."); + fflush(stdout); + + ts = epoch_usec(); + x = test_functions[i].fn(); + delta = (long)(epoch_usec() - ts); + dur += delta; + + if (x == CRYPT_OK) { + printf("passed %10.3fms", (double)(delta)/1000); + pass++; + } + else if (x == CRYPT_NOP) { + printf("nop"); + nop++; + } + else { + printf("failed %10.3fms", (double)(delta)/1000); + fail++; + } + } + + if (fail > 0 || fail+pass+nop == 0) { + printf("\n\nFAILURE: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000)); + return EXIT_FAILURE; + } + else { + printf("\n\nSUCCESS: passed=%d failed=%d nop=%d duration=%.1fsec\n", pass, fail, nop, (double)(dur)/(1000*1000)); + return EXIT_SUCCESS; + } +} + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/testprof/test.der b/tests/test.der similarity index 100% rename from testprof/test.der rename to tests/test.der diff --git a/testprof/test.key b/tests/test.key similarity index 100% rename from testprof/test.key rename to tests/test.key diff --git a/testprof/test_dsa.key b/tests/test_dsa.key similarity index 100% rename from testprof/test_dsa.key rename to tests/test_dsa.key diff --git a/tests/tomcrypt_test.h b/tests/tomcrypt_test.h new file mode 100644 index 00000000..77f33b35 --- /dev/null +++ b/tests/tomcrypt_test.h @@ -0,0 +1,64 @@ + +#ifndef __TEST_H_ +#define __TEST_H_ + +#include + +#include "common.h" + +#ifdef USE_LTM +/* Use libtommath as MPI provider */ +#elif defined(USE_TFM) +/* Use tomsfastmath as MPI provider */ +#elif defined(USE_GMP) +/* Use GNU Multiple Precision Arithmetic Library as MPI provider */ +#else +/* The user must define his own MPI provider! */ +#ifndef EXT_MATH_LIB +/* + * Yes, you're right, you could also name your instance of the MPI provider + * "EXT_MATH_LIB" and you wouldn't need to define it, but most users won't do + * this and so it's treated as an error and you have to comment out the + * following statement :) + */ +#error EXT_MATH_LIB is required to be defined +#endif +#endif + +typedef struct { + char *name, *prov, *req; + int (*entry)(void); +} test_entry; + +/* TESTS */ +int cipher_hash_test(void); +int modes_test(void); +int mac_test(void); +int pkcs_1_test(void); +int pkcs_1_pss_test(void); +int pkcs_1_oaep_test(void); +int pkcs_1_emsa_test(void); +int pkcs_1_eme_test(void); +int store_test(void); +int rotate_test(void); +int rsa_test(void); +int dh_test(void); +int katja_test(void); +int ecc_tests(void); +int dsa_test(void); +int der_test(void); +int misc_test(void); +int base64_test(void); +int file_test(void); +int multi_test(void); +int prng_test(void); + +#ifdef LTC_PKCS_1 +extern const struct ltc_prng_descriptor no_prng_desc; +#endif + +#endif + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */