diff options
author | Andrzej Kurek <andrzej.kurek@arm.com> | 2022-12-23 11:00:06 -0500 |
---|---|---|
committer | Andrzej Kurek <andrzej.kurek@arm.com> | 2023-03-03 05:23:44 -0500 |
commit | 8a045ce5e669045c8ef374374d4d3f19ecd5def5 (patch) | |
tree | e207b45b4238b8d791f9c619c88ee336a5eeb314 /include | |
parent | 05b80a4eeeb1c614dcee55ace40f81e93e27e9ad (diff) | |
download | mbedtls-8a045ce5e669045c8ef374374d4d3f19ecd5def5.zip mbedtls-8a045ce5e669045c8ef374374d4d3f19ecd5def5.tar.gz mbedtls-8a045ce5e669045c8ef374374d4d3f19ecd5def5.tar.bz2 |
Unify PSA to Mbed TLS error translation
Move all error translation utilities to psa_util.c.
Introduce macros and functions to avoid having
a local copy of the error translating function in
each place.
Identify overlapping errors and introduce a
generic function.
Provide a single macro for all error translations
(unless one file needs a couple of different ones).
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/mbedtls/psa_util.h | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/include/mbedtls/psa_util.h b/include/mbedtls/psa_util.h index f6070dc..b0ad310 100644 --- a/include/mbedtls/psa_util.h +++ b/include/mbedtls/psa_util.h @@ -344,6 +344,41 @@ extern mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state; #endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */ -#endif /* MBEDTLS_PSA_CRYPTO_C */ +/* PSA errors use int32_t, while Mbed TLS ones use int16_t. psa_status_t + * is enough to store either of them. */ +#if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_MD5_C) +extern psa_status_t psa_to_md_errors[8]; +#endif + +#if defined(MBEDTLS_LMS_C) +extern psa_status_t psa_to_lms_errors[6]; +#endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3) +extern psa_status_t psa_to_ssl_errors[14]; +#endif + +#if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) || \ + defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR) +extern psa_status_t psa_to_pk_rsa_errors[16]; +#endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) && \ + defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) +extern psa_status_t psa_to_pk_ecdsa_errors[14]; +#endif + +int psa_generic_status_to_mbedtls(psa_status_t status); + +int psa_status_to_mbedtls(psa_status_t status, + psa_status_t *local_translations, + size_t local_errors_num, + int (*fallback_f)(psa_status_t)); + +int psa_pk_status_to_mbedtls(psa_status_t status); + +#define PSA_TO_MBEDTLS_ERR_LIST(status, error_list, fallback_f) \ + psa_status_to_mbedtls(status, error_list, sizeof(error_list), fallback_f) + +#endif /* MBEDTLS_PSA_CRYPTO_C */ #endif /* MBEDTLS_PSA_UTIL_H */ |