From beec798d4d9a267259dde57df25f2c73a48a71b2 Mon Sep 17 00:00:00 2001 From: Shane Israel Date: Wed, 16 Jul 2014 13:20:16 -0600 Subject: [PATCH 1/3] Added a basic NTRU Encrypt and Decrypt benchmark --- ctaocrypt/benchmark/benchmark.c | 130 +++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index b2517f084..24a2eeb41 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -105,6 +105,7 @@ void bench_eccKeyGen(void); void bench_eccKeyAgree(void); #endif #ifdef HAVE_NTRU +void bench_ntru(void); void bench_ntruKeyGen(void); #endif @@ -216,6 +217,10 @@ int benchmark_test(void *args) printf("\n"); +#ifdef HAVE_NTRU + bench_ntru(); +#endif + #ifndef NO_RSA bench_rsa(); #endif @@ -1056,6 +1061,128 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out) return 0; } + +void bench_ntru(void) +{ + int i; + double start, total, each, milliEach; + + byte public_key[557]; + word16 public_key_len = sizeof(public_key); + byte private_key[607]; + word16 private_key_len = sizeof(private_key); + + byte ciphertext[552]; + word16 ciphertext_len; + byte plaintext[16]; + word16 plaintext_len; + + DRBG_HANDLE drbg; + static byte const aes_key[] = { + 0xf3, 0xe9, 0x87, 0xbb, 0x18, 0x08, 0x3c, 0xaa, + 0x7b, 0x12, 0x49, 0x88, 0xaf, 0xb3, 0x22, 0xd8 +}; + + static byte const cyasslStr[] = { + 'C', 'y', 'a', 'S', 'S', 'L', ' ', 'N', 'T', 'R', 'U' + }; + + word32 rc = ntru_crypto_drbg_instantiate(112, cyasslStr, sizeof(cyasslStr), + (ENTROPY_FN) GetEntropy, &drbg); + if(rc != DRBG_OK) { + printf("NTRU drbg instantiate failed\n"); + return; + } + + rc = ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, + &public_key_len, NULL, &private_key_len, NULL); + if (rc != NTRU_OK) { + ntru_crypto_drbg_uninstantiate(drbg); + printf("NTRU failed to get key lengths\n"); + return; + } + + rc = ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, &public_key_len, + public_key, &private_key_len, + private_key); + + ntru_crypto_drbg_uninstantiate(drbg); + + if (rc != NTRU_OK) { + ntru_crypto_drbg_uninstantiate(drbg); + printf("NTRU keygen failed\n"); + return; + } + + rc = ntru_crypto_drbg_instantiate(112, NULL, 0, (ENTROPY_FN)GetEntropy, &drbg); + + if (rc != DRBG_OK) { + printf("NTRU error occurred during DRBG instantiation\n"); + return; + } + + rc = ntru_crypto_ntru_encrypt(drbg, public_key_len, public_key, sizeof( + aes_key), aes_key, &ciphertext_len, NULL); + + if (rc != NTRU_OK) { + printf("NTRU error occurred requesting the buffer size needed\n"); + return; + } + start = current_time(1); + + for (i = 0; i < ntimes; i++) { + + rc = ntru_crypto_ntru_encrypt(drbg, public_key_len, public_key, sizeof( + aes_key), aes_key, &ciphertext_len, ciphertext); + + if (rc != NTRU_OK) { + printf("NTRU encrypt error\n"); + return; + } + + } + rc = ntru_crypto_drbg_uninstantiate(drbg); + + if (rc != DRBG_OK) { + printf("NTRU error occurred uninstantiating the DRBG\n"); + return; + } + + total = current_time(0) - start; + each = total / ntimes; /* per second */ + milliEach = each * 1000; /* milliseconds */ + + printf("NTRU %d encryption took %6.3f milliseconds, avg over %d" + " iterations\n", ciphertext_len, milliEach, ntimes); + + + rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len, ciphertext, &plaintext_len, NULL); + + if (rc != NTRU_OK) { + printf("NTRU decrypt error occurred requesting the buffer size needed\n"); + return; + } + + plaintext_len = sizeof(plaintext); + start = current_time(1); + + for (i = 0; i < ntimes; i++) { + rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len, ciphertext, &plaintext_len, plaintext); + + if (rc != NTRU_OK) { + printf("NTRU error occurred decrypting the key\n"); + return; + } + } + + total = current_time(0) - start; + each = total / ntimes; /* per second */ + milliEach = each * 1000; /* milliseconds */ + + printf("NTRU %d decryption took %6.3f milliseconds, avg over %d" + " iterations\n", ciphertext_len, milliEach, ntimes); +} + void bench_ntruKeyGen(void) { double start, total, each, milliEach; @@ -1082,7 +1209,8 @@ void bench_ntruKeyGen(void) for(i = 0; i < genTimes; i++) { ntru_crypto_ntru_encrypt_keygen(drbg, NTRU_EES401EP2, &public_key_len, - public_key, &private_key_len, private_key); + public_key, &private_key_len, + private_key); } total = current_time(0) - start; From cc72a50cee30c709345182f24a7a09feade84089 Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 21 Jul 2014 16:28:57 -0700 Subject: [PATCH 2/3] bump dev version --- configure.ac | 2 +- cyassl/version.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 13f1fdac5..180ef759d 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ # # -AC_INIT([cyassl],[3.1.0],[https://github.com/cyassl/cyassl/issues],[cyassl],[http://www.wolfssl.com]) +AC_INIT([cyassl],[3.1.1],[https://github.com/cyassl/cyassl/issues],[cyassl],[http://www.wolfssl.com]) AC_CONFIG_AUX_DIR([build-aux]) diff --git a/cyassl/version.h b/cyassl/version.h index a2d1dea9c..c6274891b 100644 --- a/cyassl/version.h +++ b/cyassl/version.h @@ -26,8 +26,8 @@ extern "C" { #endif -#define LIBCYASSL_VERSION_STRING "3.1.0" -#define LIBCYASSL_VERSION_HEX 0x03001000 +#define LIBCYASSL_VERSION_STRING "3.1.1" +#define LIBCYASSL_VERSION_HEX 0x03001001 #ifdef __cplusplus } From c214f0cc1b13b4cc70fc38795c2d804284562dff Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 21 Jul 2014 16:37:41 -0700 Subject: [PATCH 3/3] fixup ntru encrypt benchmark --- ctaocrypt/benchmark/benchmark.c | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index c91e66fe8..c1ec28109 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -227,14 +227,14 @@ int benchmark_test(void *args) printf("\n"); -#ifdef HAVE_NTRU - bench_ntru(); -#endif - #ifndef NO_RSA bench_rsa(); #endif +#ifdef HAVE_NTRU + bench_ntru(); +#endif + #ifndef NO_DH bench_dh(); #endif @@ -1159,9 +1159,9 @@ void bench_ntru(void) DRBG_HANDLE drbg; static byte const aes_key[] = { - 0xf3, 0xe9, 0x87, 0xbb, 0x18, 0x08, 0x3c, 0xaa, - 0x7b, 0x12, 0x49, 0x88, 0xaf, 0xb3, 0x22, 0xd8 -}; + 0xf3, 0xe9, 0x87, 0xbb, 0x18, 0x08, 0x3c, 0xaa, + 0x7b, 0x12, 0x49, 0x88, 0xaf, 0xb3, 0x22, 0xd8 + }; static byte const cyasslStr[] = { 'C', 'y', 'a', 'S', 'S', 'L', ' ', 'N', 'T', 'R', 'U' @@ -1194,8 +1194,8 @@ void bench_ntru(void) return; } - rc = ntru_crypto_drbg_instantiate(112, NULL, 0, (ENTROPY_FN)GetEntropy, &drbg); - + rc = ntru_crypto_drbg_instantiate(112, NULL, 0, (ENTROPY_FN)GetEntropy, + &drbg); if (rc != DRBG_OK) { printf("NTRU error occurred during DRBG instantiation\n"); return; @@ -1232,14 +1232,15 @@ void bench_ntru(void) each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ - printf("NTRU %d encryption took %6.3f milliseconds, avg over %d" - " iterations\n", ciphertext_len, milliEach, ntimes); + printf("NTRU 112 encryption took %6.3f milliseconds, avg over %d" + " iterations\n", milliEach, ntimes); - rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len, ciphertext, &plaintext_len, NULL); + rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len, + ciphertext, &plaintext_len, NULL); if (rc != NTRU_OK) { - printf("NTRU decrypt error occurred requesting the buffer size needed\n"); + printf("NTRU decrypt error occurred getting the buffer size needed\n"); return; } @@ -1247,7 +1248,9 @@ void bench_ntru(void) start = current_time(1); for (i = 0; i < ntimes; i++) { - rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, ciphertext_len, ciphertext, &plaintext_len, plaintext); + rc = ntru_crypto_ntru_decrypt(private_key_len, private_key, + ciphertext_len, ciphertext, + &plaintext_len, plaintext); if (rc != NTRU_OK) { printf("NTRU error occurred decrypting the key\n"); @@ -1259,8 +1262,8 @@ void bench_ntru(void) each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ - printf("NTRU %d decryption took %6.3f milliseconds, avg over %d" - " iterations\n", ciphertext_len, milliEach, ntimes); + printf("NTRU 112 decryption took %6.3f milliseconds, avg over %d" + " iterations\n", milliEach, ntimes); } void bench_ntruKeyGen(void)