diff options
author | Matt Johnston <matt@ucc.asn.au> | 2007-01-11 02:41:05 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2007-01-11 02:41:05 +0000 |
commit | a938f4cfe140e8561d9dbf108b896492a662a893 (patch) | |
tree | f2a74322f959ff6a505ba5e87274ebe3d17d5e74 /libtomcrypt/demos | |
parent | 692d737a821c5e401c227d936b8f0d76b955650f (diff) | |
parent | 28ad393b008b34bc3cdbaa192440b8cc615329f0 (diff) |
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f)
to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
--HG--
extra : convert_revision : 52ccb0ad0587a62bc64aecb939adbb76546aac16
Diffstat (limited to 'libtomcrypt/demos')
-rw-r--r-- | libtomcrypt/demos/encrypt.c | 8 | ||||
-rw-r--r-- | libtomcrypt/demos/multi.c | 36 | ||||
-rw-r--r-- | libtomcrypt/demos/small.c | 6 | ||||
-rw-r--r-- | libtomcrypt/demos/test.c | 20 | ||||
-rw-r--r-- | libtomcrypt/demos/timing.c | 22 | ||||
-rw-r--r-- | libtomcrypt/demos/tv_gen.c | 154 |
6 files changed, 195 insertions, 51 deletions
diff --git a/libtomcrypt/demos/encrypt.c b/libtomcrypt/demos/encrypt.c index d8eb293..f38440d 100644 --- a/libtomcrypt/demos/encrypt.c +++ b/libtomcrypt/demos/encrypt.c @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) exit(-1); } - if ((errno = ctr_start(cipher_idx,IV,key,ks,0,&ctr)) != CRYPT_OK) { + if ((errno = ctr_start(cipher_idx,IV,key,ks,0,CTR_COUNTER_LITTLE_ENDIAN,&ctr)) != CRYPT_OK) { printf("ctr_start error: %s\n",error_to_string(errno)); exit(-1); } @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) exit(-1); } - if ((errno = ctr_start(cipher_idx,IV,key,ks,0,&ctr)) != CRYPT_OK) { + if ((errno = ctr_start(cipher_idx,IV,key,ks,0,CTR_COUNTER_LITTLE_ENDIAN,&ctr)) != CRYPT_OK) { printf("ctr_start error: %s\n",error_to_string(errno)); exit(-1); } @@ -237,5 +237,5 @@ int main(int argc, char *argv[]) } /* $Source: /cvs/libtom/libtomcrypt/demos/encrypt.c,v $ */ -/* $Revision: 1.2 $ */ -/* $Date: 2005/05/05 14:35:56 $ */ +/* $Revision: 1.3 $ */ +/* $Date: 2005/08/04 20:43:50 $ */ diff --git a/libtomcrypt/demos/multi.c b/libtomcrypt/demos/multi.c index af4d6b6..2520de9 100644 --- a/libtomcrypt/demos/multi.c +++ b/libtomcrypt/demos/multi.c @@ -13,21 +13,21 @@ int main(void) /* HASH testing */ len = sizeof(buf[0]); - hash_memory(find_hash("sha256"), "hello", 5, buf[0], &len); + hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len); len2 = sizeof(buf[0]); - hash_memory_multi(find_hash("sha256"), buf[1], &len2, "hello", 5, NULL); + hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - hash_memory_multi(find_hash("sha256"), buf[1], &len2, "he", 2, "llo", 3, NULL); + hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - hash_memory_multi(find_hash("sha256"), buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); + hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; @@ -35,21 +35,21 @@ int main(void) /* HMAC */ len = sizeof(buf[0]); - hmac_memory(find_hash("sha256"), key, 16, "hello", 5, buf[0], &len); + hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); len2 = sizeof(buf[0]); - hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "hello", 5, NULL); + hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL); + hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); + hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; @@ -57,21 +57,21 @@ int main(void) /* OMAC */ len = sizeof(buf[0]); - omac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len); + omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); len2 = sizeof(buf[0]); - omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL); + omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL); + omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); + omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; @@ -79,21 +79,21 @@ int main(void) /* PMAC */ len = sizeof(buf[0]); - pmac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len); + pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); len2 = sizeof(buf[0]); - pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL); + pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL); + pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; } len2 = sizeof(buf[0]); - pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL); + pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); if (len != len2 || memcmp(buf[0], buf[1], len)) { printf("Failed: %d %lu %lu\n", __LINE__, len, len2); return EXIT_FAILURE; @@ -106,5 +106,5 @@ int main(void) /* $Source: /cvs/libtom/libtomcrypt/demos/multi.c,v $ */ -/* $Revision: 1.2 $ */ -/* $Date: 2005/05/05 14:35:56 $ */ +/* $Revision: 1.3 $ */ +/* $Date: 2006/06/07 22:25:09 $ */ diff --git a/libtomcrypt/demos/small.c b/libtomcrypt/demos/small.c index 6bdd842..3019745 100644 --- a/libtomcrypt/demos/small.c +++ b/libtomcrypt/demos/small.c @@ -1,4 +1,4 @@ -// small demo app that just includes a cipher/hash/prng +/* small demo app that just includes a cipher/hash/prng */ #include <tomcrypt.h> int main(void) @@ -10,5 +10,5 @@ int main(void) } /* $Source: /cvs/libtom/libtomcrypt/demos/small.c,v $ */ -/* $Revision: 1.2 $ */ -/* $Date: 2005/05/05 14:35:56 $ */ +/* $Revision: 1.3 $ */ +/* $Date: 2006/06/07 22:25:09 $ */ diff --git a/libtomcrypt/demos/test.c b/libtomcrypt/demos/test.c index f6c7170..16a2110 100644 --- a/libtomcrypt/demos/test.c +++ b/libtomcrypt/demos/test.c @@ -4,6 +4,18 @@ int main(void) { int x; reg_algs(); + +#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 + printf("build == \n%s\n", crypt_build_settings); printf("\nstore_test...."); fflush(stdout); x = store_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\ncipher_test..."); fflush(stdout); x = cipher_hash_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); @@ -12,13 +24,13 @@ int main(void) printf("\nmac_test......"); fflush(stdout); x = mac_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\npkcs_1_test..."); fflush(stdout); x = pkcs_1_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nrsa_test......"); fflush(stdout); x = rsa_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); - printf("\necc_test......"); fflush(stdout); x = ecc_tests(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); + printf("\necc_test......"); fflush(stdout); x = ecc_tests(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\ndsa_test......"); fflush(stdout); x = dsa_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); - printf("\ndh_test......."); fflush(stdout); x = dh_tests(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); + printf("\nkatja_test...."); fflush(stdout); x = katja_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\n"); return EXIT_SUCCESS; } /* $Source: /cvs/libtom/libtomcrypt/demos/test.c,v $ */ -/* $Revision: 1.12 $ */ -/* $Date: 2005/06/19 12:06:58 $ */ +/* $Revision: 1.28 $ */ +/* $Date: 2006/05/25 10:50:08 $ */ diff --git a/libtomcrypt/demos/timing.c b/libtomcrypt/demos/timing.c index 368d6e4..becc7c0 100644 --- a/libtomcrypt/demos/timing.c +++ b/libtomcrypt/demos/timing.c @@ -2,12 +2,26 @@ int main(void) { + init_timer(); reg_algs(); + +#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 + time_keysched(); time_cipher(); time_cipher2(); time_cipher3(); +time_cipher4(); time_hash(); time_macs(); time_encmacs(); @@ -16,11 +30,13 @@ time_mult(); time_sqr(); time_rsa(); time_ecc(); -time_dh(); +#ifdef USE_LTM +time_katja(); +#endif return EXIT_SUCCESS; } /* $Source: /cvs/libtom/libtomcrypt/demos/timing.c,v $ */ -/* $Revision: 1.17 $ */ -/* $Date: 2005/06/23 02:16:26 $ */ +/* $Revision: 1.61 $ */ +/* $Date: 2006/12/03 03:08:35 $ */ diff --git a/libtomcrypt/demos/tv_gen.c b/libtomcrypt/demos/tv_gen.c index edaae3e..97c61a8 100644 --- a/libtomcrypt/demos/tv_gen.c +++ b/libtomcrypt/demos/tv_gen.c @@ -98,6 +98,18 @@ void reg_algs(void) } #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) @@ -541,7 +553,7 @@ void ccm_gen(void) plaintext[z] = (unsigned char)(z & 255); } len = sizeof(tag); - if ((err = ccm_memory(x, key, kl, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) { + if ((err = ccm_memory(x, key, kl, NULL, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) { printf("Error CCM'ing: %s\n", error_to_string(err)); exit(EXIT_FAILURE); } @@ -641,30 +653,134 @@ void base64_gen(void) fclose(out); } +void math_gen(void) +{ +} + +void ecc_gen(void) +{ + FILE *out; + unsigned char str[512]; + void *k, *order, *modulus; + ecc_point *G, *R; + int x; + + out = fopen("ecc_tv.txt", "w"); + fprintf(out, "ecc vectors. These are for kG for k=1,3,9,27,...,3**n until k > order of the curve outputs are <k,x,y> triplets\n\n"); + G = ltc_ecc_new_point(); + R = ltc_ecc_new_point(); + mp_init(&k); + mp_init(&order); + mp_init(&modulus); + + for (x = 0; ltc_ecc_sets[x].size != 0; x++) { + fprintf(out, "ECC-%d\n", ltc_ecc_sets[x].size*8); + mp_set(k, 1); + + mp_read_radix(order, (char *)ltc_ecc_sets[x].order, 16); + mp_read_radix(modulus, (char *)ltc_ecc_sets[x].prime, 16); + mp_read_radix(G->x, (char *)ltc_ecc_sets[x].Gx, 16); + mp_read_radix(G->y, (char *)ltc_ecc_sets[x].Gy, 16); + mp_set(G->z, 1); + + while (mp_cmp(k, order) == LTC_MP_LT) { + ltc_mp.ecc_ptmul(k, G, R, modulus, 1); + mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str); + mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str); + mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str); + mp_mul_d(k, 3, k); + } + } + mp_clear_multi(k, order, modulus, NULL); + ltc_ecc_del_point(G); + ltc_ecc_del_point(R); + fclose(out); +} + +void lrw_gen(void) +{ + FILE *out; + unsigned char tweak[16], key[16], iv[16], buf[1024]; + int x, y, err; + symmetric_LRW lrw; + + /* initialize default key and tweak */ + for (x = 0; x < 16; x++) { + tweak[x] = key[x] = iv[x] = x; + } + + out = fopen("lrw_tv.txt", "w"); + for (x = 16; x < (int)(sizeof(buf)); x += 16) { + if ((err = lrw_start(find_cipher("aes"), iv, key, 16, tweak, 0, &lrw)) != CRYPT_OK) { + fprintf(stderr, "Error starting LRW-AES: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + + /* encrypt incremental */ + for (y = 0; y < x; y++) { + buf[y] = y & 255; + } + + if ((err = lrw_encrypt(buf, buf, x, &lrw)) != CRYPT_OK) { + fprintf(stderr, "Error encrypting with LRW-AES: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + + /* display it */ + fprintf(out, "%d:", x); + for (y = 0; y < x; y++) { + fprintf(out, "%02x", buf[y]); + } + fprintf(out, "\n"); + + /* reset IV */ + if ((err = lrw_setiv(iv, 16, &lrw)) != CRYPT_OK) { + fprintf(stderr, "Error setting IV: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + + /* copy new tweak, iv and key */ + for (y = 0; y < 16; y++) { + key[y] = buf[y]; + iv[y] = buf[(y+16)%x]; + tweak[y] = buf[(y+32)%x]; + } + + if ((err = lrw_decrypt(buf, buf, x, &lrw)) != CRYPT_OK) { + fprintf(stderr, "Error decrypting with LRW-AES: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); + } + + /* display it */ + fprintf(out, "%d:", x); + for (y = 0; y < x; y++) { + fprintf(out, "%02x", buf[y]); + } + fprintf(out, "\n"); + lrw_done(&lrw); + } + fclose(out); +} + int main(void) { reg_algs(); - printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); + 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"); - printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); - printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); - printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); - printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); - printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); - printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); + printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); + printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); + printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); + printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); + printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); + printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); + printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); + printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n"); + printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n"); + printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n"); return 0; } - - - - - - - - /* $Source: /cvs/libtom/libtomcrypt/demos/tv_gen.c,v $ */ -/* $Revision: 1.4 $ */ -/* $Date: 2005/05/05 14:35:56 $ */ +/* $Revision: 1.15 $ */ +/* $Date: 2006/06/09 22:10:27 $ */ |