Introduce new PSA to mbedtls PK error mapping function
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
This commit is contained in:
parent
4579a972bf
commit
a3fdfb4925
@ -84,6 +84,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int mbedtls_pk_psa_err_translate( psa_status_t status );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Public key types
|
||||
*/
|
||||
|
34
library/pk.c
34
library/pk.c
@ -147,6 +147,40 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info )
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int mbedtls_pk_psa_err_translate( psa_status_t status )
|
||||
{
|
||||
switch( status )
|
||||
{
|
||||
case PSA_SUCCESS:
|
||||
return( 0 );
|
||||
case PSA_ERROR_INVALID_HANDLE:
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT );
|
||||
case PSA_ERROR_NOT_PERMITTED:
|
||||
return( MBEDTLS_ERR_ERROR_GENERIC_ERROR );
|
||||
case PSA_ERROR_BUFFER_TOO_SMALL:
|
||||
return( MBEDTLS_ERR_PK_BUFFER_TOO_SMALL );
|
||||
case PSA_ERROR_NOT_SUPPORTED:
|
||||
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
|
||||
case PSA_ERROR_INVALID_ARGUMENT:
|
||||
return( MBEDTLS_ERR_PK_INVALID_ALG );
|
||||
case PSA_ERROR_INSUFFICIENT_MEMORY:
|
||||
return( MBEDTLS_ERR_PK_ALLOC_FAILED );
|
||||
case PSA_ERROR_BAD_STATE:
|
||||
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
case PSA_ERROR_COMMUNICATION_FAILURE:
|
||||
case PSA_ERROR_HARDWARE_FAILURE:
|
||||
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
||||
case PSA_ERROR_DATA_CORRUPT:
|
||||
case PSA_ERROR_DATA_INVALID:
|
||||
case PSA_ERROR_STORAGE_FAILURE:
|
||||
return( MBEDTLS_ERR_PK_FILE_IO_ERROR );
|
||||
case PSA_ERROR_CORRUPTION_DETECTED:
|
||||
return( MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED );
|
||||
default:
|
||||
return( MBEDTLS_ERR_ERROR_GENERIC_ERROR );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialise a PSA-wrapping context
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user