mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-22 19:10:59 +00:00
Sanity check on elliptic curve keys: check that the group is known
This commit is contained in:
parent
8d36696e1f
commit
f02b984f86
|
@ -46,12 +46,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
#if defined(MBEDTLS_ECP_C)
|
#if defined(MBEDTLS_ECP_C)
|
||||||
if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY )
|
if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY )
|
||||||
{
|
{
|
||||||
mbedtls_ecp_keypair *ecp;
|
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pk );
|
||||||
|
mbedtls_ecp_group_id grp_id = ecp->grp.id;
|
||||||
|
const mbedtls_ecp_curve_info *curve_info =
|
||||||
|
mbedtls_ecp_curve_info_from_grp_id( grp_id );
|
||||||
|
|
||||||
ecp = mbedtls_pk_ec( pk );
|
/* If the curve is not supported, the key should not have been
|
||||||
if (ecp) {
|
* accepted. */
|
||||||
ret = 0;
|
if( curve_info == NULL )
|
||||||
}
|
abort( );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,13 +41,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
#if defined(MBEDTLS_ECP_C)
|
#if defined(MBEDTLS_ECP_C)
|
||||||
if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY )
|
if( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_ECKEY )
|
||||||
{
|
{
|
||||||
mbedtls_ecp_keypair *ecp;
|
mbedtls_ecp_keypair *ecp = mbedtls_pk_ec( pk );
|
||||||
|
mbedtls_ecp_group_id grp_id = ecp->grp.id;
|
||||||
|
const mbedtls_ecp_curve_info *curve_info =
|
||||||
|
mbedtls_ecp_curve_info_from_grp_id( grp_id );
|
||||||
|
|
||||||
ecp = mbedtls_pk_ec( pk );
|
/* If the curve is not supported, the key should not have been
|
||||||
//dummy use of value
|
* accepted. */
|
||||||
if (ecp) {
|
if( curve_info == NULL )
|
||||||
ret = 0;
|
abort( );
|
||||||
}
|
|
||||||
|
/* It's a public key, so the private value should not have
|
||||||
|
* been changed from its initialization to 0. */
|
||||||
|
if( mbedtls_mpi_cmp_int( &ecp->d, 0 ) != 0 )
|
||||||
|
abort( );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue