diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index 5923191e8..7b36dab51 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -785,7 +785,7 @@ static const char *certDHname = "certs/dh2048.der" ; void bench_dh(void) { - int i; + int i, ret; byte tmp[1024]; size_t bytes; word32 idx = 0, pubSz, privSz, pubSz2, privSz2, agreeSz; @@ -816,6 +816,11 @@ void bench_dh(void) return; } + ret = InitRng(&rng); + if (ret < 0) { + printf("InitRNG failed\n"); + return; + } bytes = fread(tmp, 1, sizeof(tmp), file); #endif /* USE_CERT_BUFFERS */ @@ -908,9 +913,14 @@ void bench_eccKeyGen(void) { ecc_key genKey; double start, total, each, milliEach; - int i; + int i, ret; const int genTimes = 100; + ret = InitRng(&rng); + if (ret < 0) { + printf("InitRNG failed\n"); + return; + } /* 256 bit */ start = current_time(1); @@ -942,6 +952,12 @@ void bench_eccKeyAgree(void) ecc_init(&genKey); ecc_init(&genKey2); + ret = InitRng(&rng); + if (ret < 0) { + printf("InitRNG failed\n"); + return; + } + ret = ecc_make_key(&rng, 32, &genKey); if (ret != 0) { printf("ecc_make_key failed\n"); @@ -958,7 +974,11 @@ void bench_eccKeyAgree(void) for(i = 0; i < agreeTimes; i++) { x = sizeof(shared); - ecc_shared_secret(&genKey, &genKey2, shared, &x); + ret = ecc_shared_secret(&genKey, &genKey2, shared, &x); + if (ret != 0) { + printf("ecc_shared_secret failed\n"); + return; + } } total = current_time(0) - start; @@ -976,7 +996,11 @@ void bench_eccKeyAgree(void) for(i = 0; i < agreeTimes; i++) { x = sizeof(sig); - ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &genKey); + ret = ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &genKey); + if (ret != 0) { + printf("ecc_sign_hash failed\n"); + return; + } } total = current_time(0) - start; @@ -989,7 +1013,11 @@ void bench_eccKeyAgree(void) for(i = 0; i < agreeTimes; i++) { int verify = 0; - ecc_verify_hash(sig, x, digest, sizeof(digest), &verify, &genKey); + ret = ecc_verify_hash(sig, x, digest, sizeof(digest), &verify, &genKey); + if (ret != 0) { + printf("ecc_verify_hash failed\n"); + return; + } } total = current_time(0) - start; diff --git a/ctaocrypt/src/ecc.c b/ctaocrypt/src/ecc.c index 4190630d1..e67679aef 100644 --- a/ctaocrypt/src/ecc.c +++ b/ctaocrypt/src/ecc.c @@ -159,8 +159,10 @@ int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* modulus, mp_digit* mp); static int ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map); +#ifdef ECC_SHAMIR static int ecc_mul2add(ecc_point* A, mp_int* kA, ecc_point* B, mp_int* kB, ecc_point* C, mp_int* modulus); +#endif /* helper for either lib */ @@ -1514,14 +1516,14 @@ void ecc_free(ecc_key* key) } -#ifdef ECC_SHAMIR - #ifdef USE_FAST_MATH #define GEN_MEM_ERR FP_MEM #else #define GEN_MEM_ERR MP_MEM #endif +#ifdef ECC_SHAMIR + /** Computes kA*A + kB*B = C using Shamir's Trick A First point to multiply kA What to multiple A by @@ -2124,9 +2126,17 @@ int ecc_sig_size(ecc_key* key) #define FP_LUT 8U #endif -#if (FP_LUT > 12) || (FP_LUT < 2) - #error FP_LUT must be between 2 and 12 inclusively -#endif +#ifdef ECC_SHAMIR + /* Sharmir requires a bigger LUT, TAO */ + #if (FP_LUT > 12) || (FP_LUT < 4) + #error FP_LUT must be between 4 and 12 inclusively + #endif +#else + #if (FP_LUT > 12) || (FP_LUT < 2) + #error FP_LUT must be between 2 and 12 inclusively + #endif +#endif + /** Our FP cache */ static struct {