@@ -4043,46 +4043,49 @@ static psa_status_t psa_key_agreement_ecdh( const uint8_t *peer_key,
4043
4043
mbedtls_pk_context pk ;
4044
4044
mbedtls_ecp_keypair * their_key = NULL ;
4045
4045
mbedtls_ecdh_context ecdh ;
4046
- int ret ;
4046
+ psa_status_t status ;
4047
4047
mbedtls_ecdh_init ( & ecdh );
4048
4048
mbedtls_pk_init ( & pk );
4049
4049
4050
- ret = mbedtls_pk_parse_public_key ( & pk , peer_key , peer_key_length );
4051
- if ( ret != 0 )
4050
+ status = mbedtls_to_psa_error (
4051
+ mbedtls_pk_parse_public_key ( & pk , peer_key , peer_key_length ) );
4052
+ if ( status != PSA_SUCCESS )
4052
4053
goto exit ;
4053
4054
switch ( mbedtls_pk_get_type ( & pk ) )
4054
4055
{
4055
4056
case MBEDTLS_PK_ECKEY :
4056
4057
case MBEDTLS_PK_ECKEY_DH :
4057
4058
break ;
4058
4059
default :
4059
- ret = MBEDTLS_ERR_ECP_INVALID_KEY ;
4060
+ status = PSA_ERROR_INVALID_ARGUMENT ;
4060
4061
goto exit ;
4061
4062
}
4062
4063
their_key = mbedtls_pk_ec ( pk );
4063
4064
if ( their_key -> grp .id != our_key -> grp .id )
4064
4065
{
4065
- ret = MBEDTLS_ERR_ECP_INVALID_KEY ;
4066
+ status = PSA_ERROR_INVALID_ARGUMENT ;
4066
4067
goto exit ;
4067
4068
}
4068
4069
4069
- ret = mbedtls_ecdh_get_params ( & ecdh , their_key , MBEDTLS_ECDH_THEIRS );
4070
- if ( ret != 0 )
4070
+ status = mbedtls_to_psa_error (
4071
+ mbedtls_ecdh_get_params ( & ecdh , their_key , MBEDTLS_ECDH_THEIRS ) );
4072
+ if ( status != PSA_SUCCESS )
4071
4073
goto exit ;
4072
- ret = mbedtls_ecdh_get_params ( & ecdh , our_key , MBEDTLS_ECDH_OURS );
4073
- if ( ret != 0 )
4074
+ status = mbedtls_ecdh_get_params ( & ecdh , our_key , MBEDTLS_ECDH_OURS );
4075
+ if ( status != PSA_SUCCESS )
4074
4076
goto exit ;
4075
4077
4076
- ret = mbedtls_ecdh_calc_secret ( & ecdh ,
4077
- shared_secret_length ,
4078
- shared_secret , shared_secret_size ,
4079
- mbedtls_ctr_drbg_random ,
4080
- & global_data .ctr_drbg );
4078
+ status = mbedtls_to_psa_error (
4079
+ mbedtls_ecdh_calc_secret ( & ecdh ,
4080
+ shared_secret_length ,
4081
+ shared_secret , shared_secret_size ,
4082
+ mbedtls_ctr_drbg_random ,
4083
+ & global_data .ctr_drbg ) );
4081
4084
4082
4085
exit :
4083
4086
mbedtls_pk_free ( & pk );
4084
4087
mbedtls_ecdh_free ( & ecdh );
4085
- return ( mbedtls_to_psa_error ( ret ) );
4088
+ return ( status );
4086
4089
}
4087
4090
#endif /* MBEDTLS_ECDH_C */
4088
4091
0 commit comments