Skip to content

Commit 0c72f83

Browse files
committed
psa: Use psa_status_t in psa_key_agreement_ecdh()
Use the PSA-native status type in psa_key_agreement_ecdh() in preparation for us calling PSA functions (and not just Mbed TLS functions) and still being able to return a psa_status_t (without having to translate it to a Mbed TLS error and then back again).
1 parent 3a013ed commit 0c72f83

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

library/psa_crypto.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,46 +4043,49 @@ static psa_status_t psa_key_agreement_ecdh( const uint8_t *peer_key,
40434043
mbedtls_pk_context pk;
40444044
mbedtls_ecp_keypair *their_key = NULL;
40454045
mbedtls_ecdh_context ecdh;
4046-
int ret;
4046+
psa_status_t status;
40474047
mbedtls_ecdh_init( &ecdh );
40484048
mbedtls_pk_init( &pk );
40494049

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 )
40524053
goto exit;
40534054
switch( mbedtls_pk_get_type( &pk ) )
40544055
{
40554056
case MBEDTLS_PK_ECKEY:
40564057
case MBEDTLS_PK_ECKEY_DH:
40574058
break;
40584059
default:
4059-
ret = MBEDTLS_ERR_ECP_INVALID_KEY;
4060+
status = PSA_ERROR_INVALID_ARGUMENT;
40604061
goto exit;
40614062
}
40624063
their_key = mbedtls_pk_ec( pk );
40634064
if( their_key->grp.id != our_key->grp.id )
40644065
{
4065-
ret = MBEDTLS_ERR_ECP_INVALID_KEY;
4066+
status = PSA_ERROR_INVALID_ARGUMENT;
40664067
goto exit;
40674068
}
40684069

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 )
40714073
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 )
40744076
goto exit;
40754077

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 ) );
40814084

40824085
exit:
40834086
mbedtls_pk_free( &pk );
40844087
mbedtls_ecdh_free( &ecdh );
4085-
return( mbedtls_to_psa_error( ret ) );
4088+
return( status );
40864089
}
40874090
#endif /* MBEDTLS_ECDH_C */
40884091

0 commit comments

Comments
 (0)