Add specialized PSA to mbedtls PK/ECDSA error mapping function

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
This commit is contained in:
Neil Armstrong 2022-02-21 10:41:39 +01:00
parent a3fdfb4925
commit cd501f406e
2 changed files with 30 additions and 0 deletions

View file

@ -86,6 +86,10 @@ extern "C" {
#if defined(MBEDTLS_USE_PSA_CRYPTO)
int mbedtls_pk_psa_err_translate( psa_status_t status );
#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
int mbedtls_pk_ecp_psa_err_translate( psa_status_t status );
#endif
#endif
/**

View file

@ -47,12 +47,38 @@
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
#if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "mbedtls/pk.h"
#endif
/* Parameter validation macros based on platform_util.h */
#define ECDSA_VALIDATE_RET( cond ) \
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA )
#define ECDSA_VALIDATE( cond ) \
MBEDTLS_INTERNAL_VALIDATE( cond )
#if defined(MBEDTLS_USE_PSA_CRYPTO)
int mbedtls_pk_ecp_psa_err_translate( psa_status_t status )
{
switch( status )
{
case PSA_ERROR_NOT_PERMITTED:
case PSA_ERROR_INVALID_ARGUMENT:
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
case PSA_ERROR_INVALID_HANDLE:
return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE );
case PSA_ERROR_BUFFER_TOO_SMALL:
return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
case PSA_ERROR_INSUFFICIENT_ENTROPY:
return( MBEDTLS_ERR_ECP_RANDOM_FAILED );
case PSA_ERROR_INVALID_SIGNATURE:
return( MBEDTLS_ERR_ECP_VERIFY_FAILED );
default:
return( mbedtls_pk_psa_err_translate( status ) );
}
}
#endif
#if defined(MBEDTLS_ECP_RESTARTABLE)
/*