add ifdefs to reduce size of mbedtls_to_psa_error
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
6f6820345a
commit
509b567911
1 changed files with 38 additions and 0 deletions
|
@ -152,9 +152,13 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
case 0:
|
case 0:
|
||||||
return PSA_SUCCESS;
|
return PSA_SUCCESS;
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||||
case MBEDTLS_ERR_AES_INVALID_KEY_LENGTH:
|
case MBEDTLS_ERR_AES_INVALID_KEY_LENGTH:
|
||||||
case MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH:
|
case MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ASN1_PARSE_C) || defined(MBEDTLS_ASN1_WRITE_C)
|
||||||
case MBEDTLS_ERR_ASN1_OUT_OF_DATA:
|
case MBEDTLS_ERR_ASN1_OUT_OF_DATA:
|
||||||
case MBEDTLS_ERR_ASN1_UNEXPECTED_TAG:
|
case MBEDTLS_ERR_ASN1_UNEXPECTED_TAG:
|
||||||
case MBEDTLS_ERR_ASN1_INVALID_LENGTH:
|
case MBEDTLS_ERR_ASN1_INVALID_LENGTH:
|
||||||
|
@ -165,26 +169,36 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||||
case MBEDTLS_ERR_ASN1_BUF_TOO_SMALL:
|
case MBEDTLS_ERR_ASN1_BUF_TOO_SMALL:
|
||||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||||
#if defined(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA)
|
#if defined(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA)
|
||||||
case MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA:
|
||||||
#endif
|
#endif
|
||||||
case MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH:
|
case MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_CCM)
|
||||||
case MBEDTLS_ERR_CCM_BAD_INPUT:
|
case MBEDTLS_ERR_CCM_BAD_INPUT:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
case MBEDTLS_ERR_CCM_AUTH_FAILED:
|
case MBEDTLS_ERR_CCM_AUTH_FAILED:
|
||||||
return PSA_ERROR_INVALID_SIGNATURE;
|
return PSA_ERROR_INVALID_SIGNATURE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_CHACHA20)
|
||||||
case MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_CHACHA20_POLY1305)
|
||||||
case MBEDTLS_ERR_CHACHAPOLY_BAD_STATE:
|
case MBEDTLS_ERR_CHACHAPOLY_BAD_STATE:
|
||||||
return PSA_ERROR_BAD_STATE;
|
return PSA_ERROR_BAD_STATE;
|
||||||
case MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED:
|
case MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED:
|
||||||
return PSA_ERROR_INVALID_SIGNATURE;
|
return PSA_ERROR_INVALID_SIGNATURE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_CIPHER_C)
|
||||||
case MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE:
|
case MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
case MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA:
|
||||||
|
@ -199,6 +213,7 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_INVALID_SIGNATURE;
|
return PSA_ERROR_INVALID_SIGNATURE;
|
||||||
case MBEDTLS_ERR_CIPHER_INVALID_CONTEXT:
|
case MBEDTLS_ERR_CIPHER_INVALID_CONTEXT:
|
||||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !(defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) || \
|
#if !(defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) || \
|
||||||
defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE))
|
defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE))
|
||||||
|
@ -213,20 +228,24 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_DES)
|
||||||
case MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH:
|
case MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
|
|
||||||
case MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED:
|
case MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED:
|
||||||
case MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE:
|
case MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE:
|
||||||
case MBEDTLS_ERR_ENTROPY_SOURCE_FAILED:
|
case MBEDTLS_ERR_ENTROPY_SOURCE_FAILED:
|
||||||
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_GCM)
|
||||||
case MBEDTLS_ERR_GCM_AUTH_FAILED:
|
case MBEDTLS_ERR_GCM_AUTH_FAILED:
|
||||||
return PSA_ERROR_INVALID_SIGNATURE;
|
return PSA_ERROR_INVALID_SIGNATURE;
|
||||||
case MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL:
|
case MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL:
|
||||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
case MBEDTLS_ERR_GCM_BAD_INPUT:
|
case MBEDTLS_ERR_GCM_BAD_INPUT:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) && \
|
#if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) && \
|
||||||
defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE)
|
defined(MBEDTLS_PSA_HMAC_DRBG_MD_TYPE)
|
||||||
|
@ -241,17 +260,24 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MD_C)
|
||||||
case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE:
|
case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
case MBEDTLS_ERR_MD_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_MD_BAD_INPUT_DATA:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
case MBEDTLS_ERR_MD_ALLOC_FAILED:
|
case MBEDTLS_ERR_MD_ALLOC_FAILED:
|
||||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||||
|
#if defined(MBEDTLS_FS_IO)
|
||||||
case MBEDTLS_ERR_MD_FILE_IO_ERROR:
|
case MBEDTLS_ERR_MD_FILE_IO_ERROR:
|
||||||
return PSA_ERROR_STORAGE_FAILURE;
|
return PSA_ERROR_STORAGE_FAILURE;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
|
#if defined(MBEDTLS_FS_IO)
|
||||||
case MBEDTLS_ERR_MPI_FILE_IO_ERROR:
|
case MBEDTLS_ERR_MPI_FILE_IO_ERROR:
|
||||||
return PSA_ERROR_STORAGE_FAILURE;
|
return PSA_ERROR_STORAGE_FAILURE;
|
||||||
|
#endif
|
||||||
case MBEDTLS_ERR_MPI_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_MPI_BAD_INPUT_DATA:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
case MBEDTLS_ERR_MPI_INVALID_CHARACTER:
|
case MBEDTLS_ERR_MPI_INVALID_CHARACTER:
|
||||||
|
@ -266,14 +292,19 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
case MBEDTLS_ERR_MPI_ALLOC_FAILED:
|
case MBEDTLS_ERR_MPI_ALLOC_FAILED:
|
||||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PK_C)
|
||||||
case MBEDTLS_ERR_PK_ALLOC_FAILED:
|
case MBEDTLS_ERR_PK_ALLOC_FAILED:
|
||||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||||
case MBEDTLS_ERR_PK_TYPE_MISMATCH:
|
case MBEDTLS_ERR_PK_TYPE_MISMATCH:
|
||||||
case MBEDTLS_ERR_PK_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_PK_BAD_INPUT_DATA:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
|
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || defined(MBEDTLS_FS_IO) || \
|
||||||
|
defined(MBEDTLS_PSA_ITS_FILE_C)
|
||||||
case MBEDTLS_ERR_PK_FILE_IO_ERROR:
|
case MBEDTLS_ERR_PK_FILE_IO_ERROR:
|
||||||
return PSA_ERROR_STORAGE_FAILURE;
|
return PSA_ERROR_STORAGE_FAILURE;
|
||||||
|
#endif
|
||||||
case MBEDTLS_ERR_PK_KEY_INVALID_VERSION:
|
case MBEDTLS_ERR_PK_KEY_INVALID_VERSION:
|
||||||
case MBEDTLS_ERR_PK_KEY_INVALID_FORMAT:
|
case MBEDTLS_ERR_PK_KEY_INVALID_FORMAT:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
|
@ -292,12 +323,14 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_INVALID_SIGNATURE;
|
return PSA_ERROR_INVALID_SIGNATURE;
|
||||||
case MBEDTLS_ERR_PK_BUFFER_TOO_SMALL:
|
case MBEDTLS_ERR_PK_BUFFER_TOO_SMALL:
|
||||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
|
#endif
|
||||||
|
|
||||||
case MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED:
|
case MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED:
|
||||||
return PSA_ERROR_HARDWARE_FAILURE;
|
return PSA_ERROR_HARDWARE_FAILURE;
|
||||||
case MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:
|
case MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_RSA_C)
|
||||||
case MBEDTLS_ERR_RSA_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_RSA_BAD_INPUT_DATA:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
case MBEDTLS_ERR_RSA_INVALID_PADDING:
|
case MBEDTLS_ERR_RSA_INVALID_PADDING:
|
||||||
|
@ -315,7 +348,9 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
case MBEDTLS_ERR_RSA_RNG_FAILED:
|
case MBEDTLS_ERR_RSA_RNG_FAILED:
|
||||||
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECP_C)
|
||||||
case MBEDTLS_ERR_ECP_BAD_INPUT_DATA:
|
case MBEDTLS_ERR_ECP_BAD_INPUT_DATA:
|
||||||
case MBEDTLS_ERR_ECP_INVALID_KEY:
|
case MBEDTLS_ERR_ECP_INVALID_KEY:
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
|
@ -331,8 +366,11 @@ psa_status_t mbedtls_to_psa_error(int ret)
|
||||||
case MBEDTLS_ERR_ECP_RANDOM_FAILED:
|
case MBEDTLS_ERR_ECP_RANDOM_FAILED:
|
||||||
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||||
case MBEDTLS_ERR_ECP_IN_PROGRESS:
|
case MBEDTLS_ERR_ECP_IN_PROGRESS:
|
||||||
return PSA_OPERATION_INCOMPLETE;
|
return PSA_OPERATION_INCOMPLETE;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED:
|
case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED:
|
||||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
Loading…
Reference in a new issue