mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 20:54:41 +02:00
ecc shamir requires bigger LUT in fp mode
This commit is contained in:
@@ -785,7 +785,7 @@ static const char *certDHname = "certs/dh2048.der" ;
|
|||||||
|
|
||||||
void bench_dh(void)
|
void bench_dh(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i, ret;
|
||||||
byte tmp[1024];
|
byte tmp[1024];
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
word32 idx = 0, pubSz, privSz, pubSz2, privSz2, agreeSz;
|
word32 idx = 0, pubSz, privSz, pubSz2, privSz2, agreeSz;
|
||||||
@@ -816,6 +816,11 @@ void bench_dh(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = InitRng(&rng);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("InitRNG failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
bytes = fread(tmp, 1, sizeof(tmp), file);
|
bytes = fread(tmp, 1, sizeof(tmp), file);
|
||||||
#endif /* USE_CERT_BUFFERS */
|
#endif /* USE_CERT_BUFFERS */
|
||||||
|
|
||||||
@@ -908,9 +913,14 @@ void bench_eccKeyGen(void)
|
|||||||
{
|
{
|
||||||
ecc_key genKey;
|
ecc_key genKey;
|
||||||
double start, total, each, milliEach;
|
double start, total, each, milliEach;
|
||||||
int i;
|
int i, ret;
|
||||||
const int genTimes = 100;
|
const int genTimes = 100;
|
||||||
|
|
||||||
|
ret = InitRng(&rng);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("InitRNG failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
/* 256 bit */
|
/* 256 bit */
|
||||||
start = current_time(1);
|
start = current_time(1);
|
||||||
|
|
||||||
@@ -942,6 +952,12 @@ void bench_eccKeyAgree(void)
|
|||||||
ecc_init(&genKey);
|
ecc_init(&genKey);
|
||||||
ecc_init(&genKey2);
|
ecc_init(&genKey2);
|
||||||
|
|
||||||
|
ret = InitRng(&rng);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("InitRNG failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ret = ecc_make_key(&rng, 32, &genKey);
|
ret = ecc_make_key(&rng, 32, &genKey);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("ecc_make_key failed\n");
|
printf("ecc_make_key failed\n");
|
||||||
@@ -958,7 +974,11 @@ void bench_eccKeyAgree(void)
|
|||||||
|
|
||||||
for(i = 0; i < agreeTimes; i++) {
|
for(i = 0; i < agreeTimes; i++) {
|
||||||
x = sizeof(shared);
|
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;
|
total = current_time(0) - start;
|
||||||
@@ -976,7 +996,11 @@ void bench_eccKeyAgree(void)
|
|||||||
|
|
||||||
for(i = 0; i < agreeTimes; i++) {
|
for(i = 0; i < agreeTimes; i++) {
|
||||||
x = sizeof(sig);
|
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;
|
total = current_time(0) - start;
|
||||||
@@ -989,7 +1013,11 @@ void bench_eccKeyAgree(void)
|
|||||||
|
|
||||||
for(i = 0; i < agreeTimes; i++) {
|
for(i = 0; i < agreeTimes; i++) {
|
||||||
int verify = 0;
|
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;
|
total = current_time(0) - start;
|
||||||
|
@@ -159,8 +159,10 @@ int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* modulus,
|
|||||||
mp_digit* mp);
|
mp_digit* mp);
|
||||||
static int ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus,
|
static int ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus,
|
||||||
int map);
|
int map);
|
||||||
|
#ifdef ECC_SHAMIR
|
||||||
static int ecc_mul2add(ecc_point* A, mp_int* kA, ecc_point* B, mp_int* kB,
|
static int ecc_mul2add(ecc_point* A, mp_int* kA, ecc_point* B, mp_int* kB,
|
||||||
ecc_point* C, mp_int* modulus);
|
ecc_point* C, mp_int* modulus);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* helper for either lib */
|
/* helper for either lib */
|
||||||
@@ -1514,14 +1516,14 @@ void ecc_free(ecc_key* key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef ECC_SHAMIR
|
|
||||||
|
|
||||||
#ifdef USE_FAST_MATH
|
#ifdef USE_FAST_MATH
|
||||||
#define GEN_MEM_ERR FP_MEM
|
#define GEN_MEM_ERR FP_MEM
|
||||||
#else
|
#else
|
||||||
#define GEN_MEM_ERR MP_MEM
|
#define GEN_MEM_ERR MP_MEM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ECC_SHAMIR
|
||||||
|
|
||||||
/** Computes kA*A + kB*B = C using Shamir's Trick
|
/** Computes kA*A + kB*B = C using Shamir's Trick
|
||||||
A First point to multiply
|
A First point to multiply
|
||||||
kA What to multiple A by
|
kA What to multiple A by
|
||||||
@@ -2124,10 +2126,18 @@ int ecc_sig_size(ecc_key* key)
|
|||||||
#define FP_LUT 8U
|
#define FP_LUT 8U
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (FP_LUT > 12) || (FP_LUT < 2)
|
#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
|
#error FP_LUT must be between 2 and 12 inclusively
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** Our FP cache */
|
/** Our FP cache */
|
||||||
static struct {
|
static struct {
|
||||||
ecc_point* g; /* cached COPY of base point */
|
ecc_point* g; /* cached COPY of base point */
|
||||||
|
Reference in New Issue
Block a user