check prime is prime with ecc compressed keys

pull/3727/head
Jacob Barthelmeh 2021-02-06 01:54:25 +07:00
parent 714aa97490
commit c2be5dbe2b
1 changed files with 16 additions and 0 deletions

View File

@ -6931,6 +6931,14 @@ int wc_ecc_import_point_der_ex(byte* in, word32 inLen, const int curve_idx,
(ECC_CURVE_FIELD_PRIME | ECC_CURVE_FIELD_AF |
ECC_CURVE_FIELD_BF));
/* validate prime is prime */
if (err == MP_OKAY) {
int isPrime = MP_NO;
err = mp_prime_is_prime(curve->prime, 8, &isPrime);
if (err == MP_OKAY && isPrime == MP_NO)
err = MP_VAL;
}
/* compute x^3 */
if (err == MP_OKAY)
err = mp_sqr(point->x, &t1);
@ -7828,6 +7836,14 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
(ECC_CURVE_FIELD_PRIME | ECC_CURVE_FIELD_AF |
ECC_CURVE_FIELD_BF));
/* validate prime is prime */
if (err == MP_OKAY) {
int isPrime = MP_NO;
err = mp_prime_is_prime(curve->prime, 8, &isPrime);
if (err == MP_OKAY && isPrime == MP_NO)
err = MP_VAL;
}
/* compute x^3 */
if (err == MP_OKAY)
err = mp_sqr(key->pubkey.x, &t1);