ECDSA verification: handle doubling of infinity

This commit is contained in:
Sean Parkinson
2020-10-29 12:12:01 +10:00
parent 931eea30f5
commit 32ea0910de
2 changed files with 28 additions and 4 deletions

View File

@ -5697,6 +5697,27 @@ int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B, ecc_point* R,
return err; return err;
} }
/* Handles when P is the infinity point.
*
* Double infinity -> infinity.
* Otherwise do normal double - which can't lead to infinity as odd order.
*/
int ecc_projective_dbl_point_safe(ecc_point *P, ecc_point *R, mp_int* a,
mp_int* modulus, mp_digit mp)
{
int err;
if (mp_iszero(P->x) && mp_iszero(P->y)) {
/* P is infinity. */
err = wc_ecc_copy_point(P, R);
}
else {
err = ecc_projective_dbl_point(P, R, a, modulus, mp);
}
return err;
}
#endif #endif
#if !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_ATECC508A) && \ #if !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_ATECC508A) && \
@ -5945,9 +5966,9 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
if (first == 0) { if (first == 0) {
/* double twice */ /* double twice */
if (err == MP_OKAY) if (err == MP_OKAY)
err = ecc_projective_dbl_point(C, C, a, modulus, mp); err = ecc_projective_dbl_point_safe(C, C, a, modulus, mp);
if (err == MP_OKAY) if (err == MP_OKAY)
err = ecc_projective_dbl_point(C, C, a, modulus, mp); err = ecc_projective_dbl_point_safe(C, C, a, modulus, mp);
else else
break; break;
} }
@ -9369,7 +9390,7 @@ static int accel_fp_mul(int idx, mp_int* k, ecc_point *R, mp_int* a,
/* double if not first */ /* double if not first */
if (!first) { if (!first) {
if ((err = ecc_projective_dbl_point(R, R, a, modulus, if ((err = ecc_projective_dbl_point_safe(R, R, a, modulus,
mp)) != MP_OKAY) { mp)) != MP_OKAY) {
break; break;
} }
@ -9582,7 +9603,7 @@ static int accel_fp_mul2add(int idx1, int idx2,
/* double if not first */ /* double if not first */
if (!first) { if (!first) {
if ((err = ecc_projective_dbl_point(R, R, a, modulus, if ((err = ecc_projective_dbl_point_safe(R, R, a, modulus,
mp)) != MP_OKAY) { mp)) != MP_OKAY) {
break; break;
} }

View File

@ -474,6 +474,9 @@ ECC_API int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* a,
WOLFSSL_LOCAL WOLFSSL_LOCAL
int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B, ecc_point* R, int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B, ecc_point* R,
mp_int* a, mp_int* modulus, mp_digit mp, int* infinity); mp_int* a, mp_int* modulus, mp_digit mp, int* infinity);
WOLFSSL_LOCAL
int ecc_projective_dbl_point_safe(ecc_point* P, ecc_point* R, mp_int* a,
mp_int* modulus, mp_digit mp);
#endif #endif