mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-24 15:02:55 +00:00
Rename error translation functions and move them to library/pk_wrap.*
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
This commit is contained in:
parent
3f9cef4547
commit
19915c2c00
@ -84,18 +84,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
|
|
||||||
int mbedtls_pk_rsa_psa_err_translate( psa_status_t status );
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Public key types
|
* \brief Public key types
|
||||||
*/
|
*/
|
||||||
|
@ -47,38 +47,12 @@
|
|||||||
#include "mbedtls/platform_util.h"
|
#include "mbedtls/platform_util.h"
|
||||||
#include "mbedtls/error.h"
|
#include "mbedtls/error.h"
|
||||||
|
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
||||||
#include "mbedtls/pk.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Parameter validation macros based on platform_util.h */
|
/* Parameter validation macros based on platform_util.h */
|
||||||
#define ECDSA_VALIDATE_RET( cond ) \
|
#define ECDSA_VALIDATE_RET( cond ) \
|
||||||
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA )
|
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA )
|
||||||
#define ECDSA_VALIDATE( cond ) \
|
#define ECDSA_VALIDATE( cond ) \
|
||||||
MBEDTLS_INTERNAL_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)
|
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
38
library/pk.c
38
library/pk.c
@ -147,40 +147,6 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
#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
|
* Initialise a PSA-wrapping context
|
||||||
*/
|
*/
|
||||||
@ -440,7 +406,7 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
|
|||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
{
|
{
|
||||||
psa_destroy_key( key_id );
|
psa_destroy_key( key_id );
|
||||||
return( mbedtls_pk_psa_err_translate( status ) );
|
return( mbedtls_pk_error_from_psa( status ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function requires returning MBEDTLS_ERR_PK_SIG_LEN_MISMATCH
|
/* This function requires returning MBEDTLS_ERR_PK_SIG_LEN_MISMATCH
|
||||||
@ -460,7 +426,7 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
|
|||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
status = destruction_status;
|
status = destruction_status;
|
||||||
|
|
||||||
return( mbedtls_pk_rsa_psa_err_translate( status ) );
|
return( mbedtls_pk_error_from_psa_rsa( status ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,6 +61,87 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
|
int mbedtls_pk_error_from_psa( 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||||
|
int mbedtls_pk_error_from_psa_ecdca( 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_error_from_psa( status ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||||
|
int mbedtls_pk_error_from_psa_rsa( psa_status_t status )
|
||||||
|
{
|
||||||
|
switch( status )
|
||||||
|
{
|
||||||
|
case PSA_ERROR_NOT_PERMITTED:
|
||||||
|
case PSA_ERROR_INVALID_ARGUMENT:
|
||||||
|
case PSA_ERROR_INVALID_HANDLE:
|
||||||
|
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
||||||
|
case PSA_ERROR_BUFFER_TOO_SMALL:
|
||||||
|
return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE );
|
||||||
|
case PSA_ERROR_INSUFFICIENT_ENTROPY:
|
||||||
|
return( MBEDTLS_ERR_RSA_RNG_FAILED );
|
||||||
|
case PSA_ERROR_INVALID_SIGNATURE:
|
||||||
|
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
|
||||||
|
case PSA_ERROR_INVALID_PADDING:
|
||||||
|
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
|
||||||
|
default:
|
||||||
|
return( mbedtls_pk_error_from_psa( status ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
static int rsa_can_do( mbedtls_pk_type_t type )
|
static int rsa_can_do( mbedtls_pk_type_t type )
|
||||||
{
|
{
|
||||||
@ -596,7 +677,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg,
|
|||||||
&key_id );
|
&key_id );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
{
|
{
|
||||||
ret = mbedtls_pk_psa_err_translate( status );
|
ret = mbedtls_pk_error_from_psa( status );
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,7 +701,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg,
|
|||||||
buf, 2 * signature_part_size );
|
buf, 2 * signature_part_size );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
{
|
{
|
||||||
ret = mbedtls_pk_ecp_psa_err_translate( status );
|
ret = mbedtls_pk_error_from_psa_ecdca( status );
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1045,7 +1126,7 @@ static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
|||||||
status = psa_sign_hash( *key, alg, hash, hash_len,
|
status = psa_sign_hash( *key, alg, hash, hash_len,
|
||||||
sig, sig_size, sig_len );
|
sig, sig_size, sig_len );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
return( mbedtls_pk_ecp_psa_err_translate( status ) );
|
return( mbedtls_pk_error_from_psa_ecdca( status ) );
|
||||||
|
|
||||||
/* transcode it to ASN.1 sequence */
|
/* transcode it to ASN.1 sequence */
|
||||||
return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, sig_size ) );
|
return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, sig_size ) );
|
||||||
|
@ -135,4 +135,16 @@ extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
|
|||||||
extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
|
extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
|
int mbedtls_pk_error_from_psa( psa_status_t status );
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||||
|
int mbedtls_pk_error_from_psa_ecdca( psa_status_t status );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||||
|
int mbedtls_pk_error_from_psa_rsa( psa_status_t status );
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* MBEDTLS_PK_WRAP_H */
|
#endif /* MBEDTLS_PK_WRAP_H */
|
||||||
|
@ -66,33 +66,6 @@
|
|||||||
#define mbedtls_free free
|
#define mbedtls_free free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
||||||
#include "mbedtls/pk.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
||||||
int mbedtls_pk_rsa_psa_err_translate( psa_status_t status )
|
|
||||||
{
|
|
||||||
switch( status )
|
|
||||||
{
|
|
||||||
case PSA_ERROR_NOT_PERMITTED:
|
|
||||||
case PSA_ERROR_INVALID_ARGUMENT:
|
|
||||||
case PSA_ERROR_INVALID_HANDLE:
|
|
||||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
|
|
||||||
case PSA_ERROR_BUFFER_TOO_SMALL:
|
|
||||||
return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE );
|
|
||||||
case PSA_ERROR_INSUFFICIENT_ENTROPY:
|
|
||||||
return( MBEDTLS_ERR_RSA_RNG_FAILED );
|
|
||||||
case PSA_ERROR_INVALID_SIGNATURE:
|
|
||||||
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
|
|
||||||
case PSA_ERROR_INVALID_PADDING:
|
|
||||||
return( MBEDTLS_ERR_RSA_INVALID_PADDING );
|
|
||||||
default:
|
|
||||||
return( mbedtls_pk_psa_err_translate( status ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_RSA_ALT)
|
#if !defined(MBEDTLS_RSA_ALT)
|
||||||
|
|
||||||
/* Parameter validation macros */
|
/* Parameter validation macros */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user