From 3f9cef454742d2e130a66563bb2d3a8b592cdb78 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Mon, 21 Feb 2022 10:43:18 +0100 Subject: [PATCH] Remove actual and use new PSA to mbedtls PK errors mapping functions Signed-off-by: Neil Armstrong --- include/mbedtls/psa_util.h | 28 ---------------------------- library/pk.c | 7 ++----- library/pk_wrap.c | 14 +++++++------- 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/include/mbedtls/psa_util.h b/include/mbedtls/psa_util.h index e38e2e346..a70ee9684 100644 --- a/include/mbedtls/psa_util.h +++ b/include/mbedtls/psa_util.h @@ -277,34 +277,6 @@ static inline psa_key_type_t mbedtls_psa_parse_tls_ecc_group( } #endif /* MBEDTLS_ECP_C */ -/* Translations for PK layer */ - -static inline int mbedtls_psa_err_translate_pk( psa_status_t status ) -{ - switch( status ) - { - case PSA_SUCCESS: - return( 0 ); - case PSA_ERROR_NOT_SUPPORTED: - return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); - case PSA_ERROR_INSUFFICIENT_MEMORY: - return( MBEDTLS_ERR_PK_ALLOC_FAILED ); - case PSA_ERROR_INSUFFICIENT_ENTROPY: - return( MBEDTLS_ERR_ECP_RANDOM_FAILED ); - case PSA_ERROR_BAD_STATE: - return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - /* All other failures */ - case PSA_ERROR_COMMUNICATION_FAILURE: - case PSA_ERROR_HARDWARE_FAILURE: - case PSA_ERROR_CORRUPTION_DETECTED: - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); - default: /* We return the same as for the 'other failures', - * but list them separately nonetheless to indicate - * which failure conditions we have considered. */ - return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); - } -} - #endif /* MBEDTLS_USE_PSA_CRYPTO */ /* Expose whatever RNG the PSA subsystem uses to applications using the diff --git a/library/pk.c b/library/pk.c index 7c5c40bbd..e9eff0a5a 100644 --- a/library/pk.c +++ b/library/pk.c @@ -440,7 +440,7 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, if( status != PSA_SUCCESS ) { psa_destroy_key( key_id ); - return( mbedtls_psa_err_translate_pk( status ) ); + return( mbedtls_pk_psa_err_translate( status ) ); } /* This function requires returning MBEDTLS_ERR_PK_SIG_LEN_MISMATCH @@ -457,13 +457,10 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, if( status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len( ctx ) ) return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); - if( status == PSA_ERROR_INVALID_SIGNATURE ) - return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); - if( status == PSA_SUCCESS ) status = destruction_status; - return( mbedtls_psa_err_translate_pk( status ) ); + return( mbedtls_pk_rsa_psa_err_translate( status ) ); } else #endif diff --git a/library/pk_wrap.c b/library/pk_wrap.c index 0bb87a491..9e14fbca6 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -596,7 +596,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, &key_id ); if( status != PSA_SUCCESS ) { - ret = mbedtls_psa_err_translate_pk( status ); + ret = mbedtls_pk_psa_err_translate( status ); goto cleanup; } @@ -615,12 +615,12 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, goto cleanup; } - if( psa_verify_hash( key_id, psa_sig_md, - hash, hash_len, - buf, 2 * signature_part_size ) - != PSA_SUCCESS ) + status = psa_verify_hash( key_id, psa_sig_md, + hash, hash_len, + buf, 2 * signature_part_size ); + if( status != PSA_SUCCESS ) { - ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; + ret = mbedtls_pk_ecp_psa_err_translate( status ); goto cleanup; } @@ -1045,7 +1045,7 @@ static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, status = psa_sign_hash( *key, alg, hash, hash_len, sig, sig_size, sig_len ); if( status != PSA_SUCCESS ) - return( mbedtls_psa_err_translate_pk( status ) ); + return( mbedtls_pk_ecp_psa_err_translate( status ) ); /* transcode it to ASN.1 sequence */ return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, sig_size ) );