ECC import and export fixes

On raw import, don't import ordinates that are larger than the curve
size.
On export of compressed point, don't export ordinate if it is larger
than the curve size.
pull/5335/head
Sean Parkinson 2022-07-08 08:54:53 +10:00
parent 4e1e1e922a
commit 70b9833e98
1 changed files with 9 additions and 0 deletions

View File

@ -10125,6 +10125,9 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
WOLFSSL_MSG("Invalid Qx");
err = BAD_FUNC_ARG;
}
if (mp_unsigned_bin_size(key->pubkey.y) > key->dp->size) {
err = BAD_FUNC_ARG;
}
}
/* read Qy */
@ -10139,6 +10142,9 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
WOLFSSL_MSG("Invalid Qy");
err = BAD_FUNC_ARG;
}
if (mp_unsigned_bin_size(key->pubkey.y) > key->dp->size) {
err = BAD_FUNC_ARG;
}
}
if (err == MP_OKAY) {
@ -13735,6 +13741,9 @@ static int wc_ecc_export_x963_compressed(ecc_key* key, byte* out, word32* outLen
if (out == NULL)
return BAD_FUNC_ARG;
if (mp_unsigned_bin_size(key->pubkey.x) > (int)numlen)
return ECC_BAD_ARG_E;
/* store first byte */
out[0] = mp_isodd(key->pubkey.y) == MP_YES ? ECC_POINT_COMP_ODD : ECC_POINT_COMP_EVEN;