mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 13:35:41 +01:00
pk_wrap: destroy key slot on errors with policy or key importing
This commit is contained in:
parent
c097b0fded
commit
2f69b1a059
@ -696,15 +696,16 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
key_len = mbedtls_pk_write_pubkey_der( &key, buf, buf_len );
|
||||
if( key_len <= 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
mbedtls_free( signature.p );
|
||||
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
if( mbedtls_psa_get_free_key_slot( &key_slot ) != PSA_SUCCESS )
|
||||
{
|
||||
ret = MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
|
||||
goto cleanup;
|
||||
mbedtls_free( signature.p );
|
||||
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
|
||||
}
|
||||
|
||||
psa_key_policy_init( &policy );
|
||||
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, psa_sig_md );
|
||||
if( psa_set_key_policy( key_slot, &policy ) != PSA_SUCCESS )
|
||||
@ -725,14 +726,13 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
signature.p, signature.len )
|
||||
!= PSA_SUCCESS )
|
||||
{
|
||||
psa_destroy_key( key_slot );
|
||||
ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
|
||||
goto cleanup;
|
||||
}
|
||||
ret = 0;
|
||||
psa_destroy_key( key_slot );
|
||||
|
||||
cleanup:
|
||||
psa_destroy_key( key_slot );
|
||||
mbedtls_free( signature.p );
|
||||
return( ret );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user