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