Skip to content

Commit 77057f4

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 6b19600 commit 77057f4

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
@@ -4044,46 +4044,49 @@ static psa_status_t psa_key_agreement_ecdh( const uint8_t *peer_key,
40444044
mbedtls_pk_context pk;
40454045
mbedtls_ecp_keypair *their_key = NULL;
40464046
mbedtls_ecdh_context ecdh;
4047-
int ret;
4047+
psa_status_t status;
40484048
mbedtls_ecdh_init( &ecdh );
40494049
mbedtls_pk_init( &pk );
40504050

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

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 )
40724074
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 )
40754077
goto exit;
40764078

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

40834086
exit:
40844087
mbedtls_pk_free( &pk );
40854088
mbedtls_ecdh_free( &ecdh );
4086-
return( mbedtls_to_psa_error( ret ) );
4089+
return( status );
40874090
}
40884091
#endif /* MBEDTLS_ECDH_C */
40894092

0 commit comments

Comments
 (0)