Optimize error translation code size

Introducing an intermediate function
saves code size that's otherwise taken by excessive,
repeated arguments in each place that
was translating errors.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
Andrzej Kurek 2023-05-30 05:45:00 -04:00
parent 14f65a47c8
commit 0064484a70
12 changed files with 116 additions and 40 deletions

View file

@ -47,9 +47,15 @@
#include <string.h> #include <string.h>
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#endif #endif
/* /*

View file

@ -45,9 +45,15 @@
#include "psa/crypto.h" #include "psa/crypto.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_lms_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_lms_errors,
sizeof(psa_to_lms_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#define PUBLIC_KEY_TYPE_OFFSET (0) #define PUBLIC_KEY_TYPE_OFFSET (0)
#define PUBLIC_KEY_I_KEY_ID_OFFSET (PUBLIC_KEY_TYPE_OFFSET + \ #define PUBLIC_KEY_I_KEY_ID_OFFSET (PUBLIC_KEY_TYPE_OFFSET + \

View file

@ -46,9 +46,15 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_lms_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_lms_errors,
sizeof(psa_to_lms_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#define SIG_Q_LEAF_ID_OFFSET (0) #define SIG_Q_LEAF_ID_OFFSET (0)
#define SIG_OTS_SIG_OFFSET (SIG_Q_LEAF_ID_OFFSET + \ #define SIG_OTS_SIG_OFFSET (SIG_Q_LEAF_ID_OFFSET + \

View file

@ -37,9 +37,15 @@
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "md_psa.h" #include "md_psa.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#endif #endif
/* /*

View file

@ -49,9 +49,15 @@
#endif #endif
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#endif #endif
static uint32_t ssl_get_hs_total_len(mbedtls_ssl_context const *ssl); static uint32_t ssl_get_hs_total_len(mbedtls_ssl_context const *ssl);

View file

@ -31,9 +31,15 @@
#include <string.h> #include <string.h>
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#endif #endif
/* /*

View file

@ -51,12 +51,23 @@
#endif #endif
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define local translating functions to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
#define PSA_TO_MD_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ {
psa_to_md_errors, \ return psa_status_to_mbedtls(status, psa_to_ssl_errors,
psa_generic_status_to_mbedtls) sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
static int local_md_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_md_errors,
sizeof(psa_to_md_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MD_ERR(status) local_md_translation(status)
#endif #endif
#if defined(MBEDTLS_TEST_HOOKS) #if defined(MBEDTLS_TEST_HOOKS)

View file

@ -33,9 +33,15 @@
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "mbedtls/psa_util.h" #include "mbedtls/psa_util.h"
#include "psa/crypto.h" #include "psa/crypto.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#endif /* MBEDTLS_USE_PSA_CRYPTO */ #endif /* MBEDTLS_USE_PSA_CRYPTO */
#include <string.h> #include <string.h>

View file

@ -34,9 +34,15 @@
#include <string.h> #include <string.h>
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#endif #endif
#if defined(MBEDTLS_ECP_C) #if defined(MBEDTLS_ECP_C)

View file

@ -35,10 +35,15 @@
#include "ssl_debug_helpers.h" #include "ssl_debug_helpers.h"
#include "md_psa.h" #include "md_psa.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
/* Write extensions */ /* Write extensions */
/* /*

View file

@ -39,9 +39,15 @@
#include "psa/crypto.h" #include "psa/crypto.h"
#include "mbedtls/psa_util.h" #include "mbedtls/psa_util.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
const uint8_t mbedtls_ssl_tls13_hello_retry_request_magic[ const uint8_t mbedtls_ssl_tls13_hello_retry_request_magic[
MBEDTLS_SERVER_HELLO_RANDOM_LEN] = MBEDTLS_SERVER_HELLO_RANDOM_LEN] =

View file

@ -36,9 +36,15 @@
#include "psa/crypto.h" #include "psa/crypto.h"
#include "md_psa.h" #include "md_psa.h"
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \ /* Define a local translating function to save code size by not using too many
psa_to_ssl_errors, \ * arguments in each translating place. */
psa_generic_status_to_mbedtls) static int local_err_translation(psa_status_t status)
{
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
sizeof(psa_to_ssl_errors),
psa_generic_status_to_mbedtls);
}
#define PSA_TO_MBEDTLS_ERR(status) local_err_translation(status)
#define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \ #define MBEDTLS_SSL_TLS1_3_LABEL(name, string) \
.name = string, .name = string,