@@ -1471,9 +1471,14 @@ int ecc_gen_privkey(unsigned int curve_id, unsigned int ndigits, u64 *privkey)
const struct ecc_curve *curve = ecc_get_curve(curve_id);
u64 priv[ECC_MAX_DIGITS];
unsigned int nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT;
- unsigned int nbits = vli_num_bits(curve->n, ndigits);
+ unsigned int nbits;
int err;
+ if (!curve)
+ return -EINVAL;
+
+ nbits = vli_num_bits(curve->n, ndigits);
+
/* Check that N is included in Table 1 of FIPS 186-4, section 6.1.1 */
if (nbits < 160 || ndigits > ARRAY_SIZE(priv))
return -EINVAL;