Merge pull request #4177 from SparkiDev/ecc_exp_point_size

ECC: validate ordinate length before export
This commit is contained in:
David Garske
2021-07-01 17:07:35 -07:00
committed by GitHub

View File

@ -7605,6 +7605,12 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
return BUFFER_E;
}
/* Sanity check the ordinates' sizes. */
if (((word32)mp_unsigned_bin_size(point->x) > numlen) ||
((word32)mp_unsigned_bin_size(point->y) > numlen)) {
return ECC_BAD_ARG_E;
}
/* store byte point type */
out[0] = ECC_POINT_UNCOMP;
@ -7676,6 +7682,11 @@ int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
return BUFFER_E;
}
/* Sanity check the ordinate's size. */
if ((word32)mp_unsigned_bin_size(point->x) > numlen) {
return ECC_BAD_ARG_E;
}
/* store byte point type */
out[0] = mp_isodd(point->y) == MP_YES ? ECC_POINT_COMP_ODD :
ECC_POINT_COMP_EVEN;