mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
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>
This commit is contained in:
@ -30,6 +30,12 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
|
||||
psa_to_ssl_errors, \
|
||||
psa_generic_status_to_mbedtls)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize context
|
||||
*/
|
||||
@ -91,7 +97,7 @@ static int ssl_ticket_gen_key(mbedtls_ssl_ticket_context *ctx,
|
||||
psa_set_key_type(&attributes, key->key_type);
|
||||
psa_set_key_bits(&attributes, key->key_bits);
|
||||
|
||||
ret = psa_ssl_status_to_mbedtls(
|
||||
ret = PSA_TO_MBEDTLS_ERR(
|
||||
psa_import_key(&attributes, buf,
|
||||
PSA_BITS_TO_BYTES(key->key_bits),
|
||||
&key->key));
|
||||
@ -133,7 +139,7 @@ static int ssl_ticket_update_keys(mbedtls_ssl_ticket_context *ctx)
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if ((status = psa_destroy_key(ctx->keys[ctx->active].key)) != PSA_SUCCESS) {
|
||||
return psa_ssl_status_to_mbedtls(status);
|
||||
return PSA_TO_MBEDTLS_ERR(status);
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
@ -169,7 +175,7 @@ int mbedtls_ssl_ticket_rotate(mbedtls_ssl_ticket_context *ctx,
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if ((status = psa_destroy_key(key->key)) != PSA_SUCCESS) {
|
||||
ret = psa_ssl_status_to_mbedtls(status);
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -182,7 +188,7 @@ int mbedtls_ssl_ticket_rotate(mbedtls_ssl_ticket_context *ctx,
|
||||
if ((status = psa_import_key(&attributes, k,
|
||||
PSA_BITS_TO_BYTES(key->key_bits),
|
||||
&key->key)) != PSA_SUCCESS) {
|
||||
ret = psa_ssl_status_to_mbedtls(status);
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
@ -355,7 +361,7 @@ int mbedtls_ssl_ticket_write(void *p_ticket,
|
||||
state, clear_len,
|
||||
state, end - state,
|
||||
&ciph_len)) != PSA_SUCCESS) {
|
||||
ret = psa_ssl_status_to_mbedtls(status);
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
goto cleanup;
|
||||
}
|
||||
#else
|
||||
@ -465,7 +471,7 @@ int mbedtls_ssl_ticket_parse(void *p_ticket,
|
||||
key_name, TICKET_ADD_DATA_LEN,
|
||||
ticket, enc_len + TICKET_AUTH_TAG_BYTES,
|
||||
ticket, enc_len, &clear_len)) != PSA_SUCCESS) {
|
||||
ret = psa_ssl_status_to_mbedtls(status);
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
goto cleanup;
|
||||
}
|
||||
#else
|
||||
|
Reference in New Issue
Block a user