diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 66bb3eef9..4ee4dd12f 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -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);