From 2bfd749e862a7a437722bb338693c79a20aaea02 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 31 May 2024 18:38:36 +0200 Subject: [PATCH] Dynamic key store: new compilation option Create a new compilation option for a dynamically resized key store. The implementation will follow in subsequent commits. This option is off by default with custom configuration files, which is best for typical deployments on highly constrained platforms. This option is on by default with the provided configuration file, which is best for typical deployments on relatively high-end platforms. Signed-off-by: Gilles Peskine --- include/mbedtls/mbedtls_config.h | 23 ++++++++++++++++++- ...test_suite_psa_crypto_slot_management.data | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index b7515f3a8c..7ed1a433ba 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -1414,6 +1414,23 @@ */ //#define MBEDTLS_PSA_CRYPTO_SPM +/** + * \def MBEDTLS_PSA_KEY_STORE_DYNAMIC + * + * Dynamically resize the PSA key store to accommodate any number of + * volatile keys (until the heap memory is exhausted). + * + * If this option is disabled, the key store has a fixed size + * #MBEDTLS_PSA_KEY_SLOT_COUNT for volatile keys and loaded persistent keys + * together. + * + * This option has no effect when #MBEDTLS_PSA_CRYPTO_C is disabled. + * + * Module: library/psa_crypto.c + * Requires: MBEDTLS_PSA_CRYPTO_C + */ +#define MBEDTLS_PSA_KEY_STORE_DYNAMIC + /** * Uncomment to enable p256-m. This is an alternative implementation of * key generation, ECDH and (randomized) ECDSA on the curve SECP256R1. @@ -4026,9 +4043,13 @@ /** \def MBEDTLS_PSA_KEY_SLOT_COUNT * - * The maximum amount of PSA keys simultaneously in memory. This counts all + * When #MBEDTLS_PSA_KEY_STORE_DYNAMIC is disabled, + * the maximum amount of PSA keys simultaneously in memory. This counts all * volatile keys, plus loaded persistent keys. * + * When #MBEDTLS_PSA_KEY_STORE_DYNAMIC is enabled, + * the maximum number of loaded persistent keys. + * * Currently, persistent keys do not need to be loaded all the time while * a multipart operation is in progress, only while the operation is being * set up. This may change in future versions of the library. diff --git a/tests/suites/test_suite_psa_crypto_slot_management.data b/tests/suites/test_suite_psa_crypto_slot_management.data index af3b946754..1bf300ade6 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.data +++ b/tests/suites/test_suite_psa_crypto_slot_management.data @@ -129,9 +129,9 @@ depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C # writing, this happens in builds where AES uses a PSA driver and the # PSA RNG uses AES-CTR_DRBG through the PSA AES. # Pick a key id that's in the middle of the volatile key ID range. -# That works out both when MBEDTLS_PSA_KEY_SLOT_DYNAMIC is enabled and +# That works out both when MBEDTLS_PSA_KEY_STORE_DYNAMIC is enabled and # volatile key IDs are assigned starting with the lowest value, and when -# MBEDTLS_PSA_KEY_SLOT_DYNAMIC is disabled and volatile key IDs are assigned +# MBEDTLS_PSA_KEY_STORE_DYNAMIC is disabled and volatile key IDs are assigned # starting with the highest values. open_fail:(PSA_KEY_ID_VOLATILE_MIN + PSA_KEY_ID_VOLATILE_MAX) / 2:PSA_ERROR_DOES_NOT_EXIST