diff --git a/tests/api.c b/tests/api.c index 3c291b928..91f391d6a 100644 --- a/tests/api.c +++ b/tests/api.c @@ -1789,7 +1789,7 @@ static int test_wolfSSL_SetMinVersion(void) # if defined(OPENSSL_EXTRA) static void test_wolfSSL_EC(void) { -#if defined(HAVE_ECC) && defined(ECC_SHAMIR) +#if defined(HAVE_ECC) BN_CTX *ctx; EC_GROUP *group; EC_POINT *Gxy, *new_point, *set_point; @@ -1853,14 +1853,23 @@ static void test_wolfSSL_EC(void) #ifndef HAVE_SELFTEST /* perform point multiplication */ AssertIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), WOLFSSL_SUCCESS); + AssertIntEQ(BN_is_zero(new_point->X), 0); + AssertIntEQ(BN_is_zero(new_point->Y), 0); + AssertIntEQ(BN_is_zero(new_point->Z), 0); AssertIntEQ(EC_POINT_mul(group, new_point, NULL, Gxy, k, ctx), WOLFSSL_SUCCESS); + AssertIntEQ(BN_is_zero(new_point->X), 0); + AssertIntEQ(BN_is_zero(new_point->Y), 0); + AssertIntEQ(BN_is_zero(new_point->Z), 0); AssertIntEQ(EC_POINT_mul(group, new_point, Gx, NULL, NULL, ctx), WOLFSSL_SUCCESS); + AssertIntEQ(BN_is_zero(new_point->X), 0); + AssertIntEQ(BN_is_zero(new_point->Y), 0); + AssertIntEQ(BN_is_zero(new_point->Z), 0); #else AssertIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy, ctx), WOLFSSL_SUCCESS); -#endif - - /* check if point X coordinate is zero */ AssertIntEQ(BN_is_zero(new_point->X), 0); + AssertIntEQ(BN_is_zero(new_point->Y), 0); + AssertIntEQ(BN_is_zero(new_point->Z), 0); +#endif /* Force non-affine coordinates */ AssertIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(), diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 22db7f167..5c561a1ee 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -8092,6 +8092,7 @@ int wc_ecc_sig_size(ecc_key* key) typedef struct { ecc_point* g; /* cached COPY of base point */ ecc_point* LUT[1U<= 0 && fp_cache[idx1].lru_count == 2) { + /* if it's >=2 build the LUT, if it's higher just use the LUT */ + if (idx1 >= 0 && fp_cache[idx1].lru_count >= 2 && !fp_cache[idx1].LUT_set) { /* compute mp */ err = mp_montgomery_setup(modulus, &mp); @@ -9443,8 +9449,8 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, } if (err == MP_OKAY) { - /* if it's 2 build the LUT, if it's higher just use the LUT */ - if (idx2 >= 0 && fp_cache[idx2].lru_count == 2) { + /* if it's >=2 build the LUT, if it's higher just use the LUT */ + if (idx2 >= 0 && fp_cache[idx2].lru_count >= 2 && !fp_cache[idx2].LUT_set) { if (mpInit == 0) { /* compute mp */ err = mp_montgomery_setup(modulus, &mp); @@ -9462,8 +9468,8 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, if (err == MP_OKAY) { - if (idx1 >=0 && idx2 >= 0 && fp_cache[idx1].lru_count >= 2 && - fp_cache[idx2].lru_count >= 2) { + if (idx1 >=0 && idx2 >= 0 && fp_cache[idx1].LUT_set && + fp_cache[idx2].LUT_set) { if (mpInit == 0) { /* compute mp */ err = mp_montgomery_setup(modulus, &mp); @@ -9540,7 +9546,7 @@ int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, if (err == MP_OKAY) { /* if it's 2 build the LUT, if it's higher just use the LUT */ - if (idx >= 0 && fp_cache[idx].lru_count == 2) { + if (idx >= 0 && fp_cache[idx].lru_count >= 2 && !fp_cache[idx].LUT_set) { /* compute mp */ err = mp_montgomery_setup(modulus, &mp); @@ -9557,7 +9563,7 @@ int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, } if (err == MP_OKAY) { - if (idx >= 0 && fp_cache[idx].lru_count >= 2) { + if (idx >= 0 && fp_cache[idx].LUT_set) { if (mpSetup == 0) { /* compute mp */ err = mp_montgomery_setup(modulus, &mp); @@ -9609,6 +9615,7 @@ static void wc_ecc_fp_free_cache(void) wc_ecc_del_point(fp_cache[x].g); fp_cache[x].g = NULL; mp_clear(&fp_cache[x].mu); + fp_cache[x].LUT_set = 0; fp_cache[x].lru_count = 0; fp_cache[x].lock = 0; }