From e3d9c9d99bbb7536b75557ed190c2e18d30d9471 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 8 Nov 2021 22:12:47 +0100 Subject: [PATCH] PSA operation structures: move less-used fields to the end Move fields around to have fewer accesses outside the 128-element Thumb direct access window. In psa_hkdf_key_derivation_t, move the large fields (output_block, prk, hmac) after the state bit-fields. Experimentally, it's slightly better to put hmac last. Other operations structures don't go outside the window, at least when not considering nested structures. Results (arm-none-eabi-gcc 7.3.1, build_arm_none_eabi_gcc_m0plus build): library/psa_crypto.o: 16510 -> 16434 (diff: 76) Signed-off-by: Gilles Peskine --- include/psa/crypto_struct.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index 9b696ca329..2c61e53cf9 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -186,9 +186,6 @@ typedef struct { uint8_t *MBEDTLS_PRIVATE(info); size_t MBEDTLS_PRIVATE(info_length); - struct psa_mac_operation_s MBEDTLS_PRIVATE(hmac); - uint8_t MBEDTLS_PRIVATE(prk)[PSA_HASH_MAX_SIZE]; - uint8_t MBEDTLS_PRIVATE(output_block)[PSA_HASH_MAX_SIZE]; #if PSA_HASH_MAX_SIZE > 0xff #error "PSA_HASH_MAX_SIZE does not fit in uint8_t" #endif @@ -196,6 +193,9 @@ typedef struct uint8_t MBEDTLS_PRIVATE(block_number); unsigned int MBEDTLS_PRIVATE(state) : 2; unsigned int MBEDTLS_PRIVATE(info_set) : 1; + uint8_t MBEDTLS_PRIVATE(output_block)[PSA_HASH_MAX_SIZE]; + uint8_t MBEDTLS_PRIVATE(prk)[PSA_HASH_MAX_SIZE]; + struct psa_mac_operation_s MBEDTLS_PRIVATE(hmac); } psa_hkdf_key_derivation_t; #endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF */