mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Dynamic key store: make full-key-store tests work effectively
Add a practical way to fill the dynamic key store by artificially limiting the slice length through a test hook. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@ -138,6 +138,13 @@ static size_t slot_index_of_volatile_key_id(psa_key_id_t key_id)
|
||||
* indicate that the slice is full. */
|
||||
#define FREE_SLOT_INDEX_NONE ((size_t) -1)
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
size_t psa_key_slot_volatile_slice_count(void)
|
||||
{
|
||||
return KEY_SLOT_VOLATILE_SLICE_COUNT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else /* MBEDTLS_PSA_KEY_STORE_DYNAMIC */
|
||||
|
||||
/* Static key store.
|
||||
@ -227,11 +234,20 @@ static inline psa_key_slot_t *get_key_slot(size_t slice_idx, size_t slot_idx);
|
||||
|
||||
#if defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
size_t (*mbedtls_test_hook_psa_volatile_key_slice_length)(size_t slice_idx) = NULL;
|
||||
#endif
|
||||
|
||||
static inline size_t key_slice_length(size_t slice_idx)
|
||||
{
|
||||
if (slice_idx == KEY_SLOT_CACHE_SLICE_INDEX) {
|
||||
return PERSISTENT_KEY_CACHE_COUNT;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
if (mbedtls_test_hook_psa_volatile_key_slice_length != NULL) {
|
||||
return mbedtls_test_hook_psa_volatile_key_slice_length(slice_idx);
|
||||
}
|
||||
#endif
|
||||
return KEY_SLOT_VOLATILE_SLICE_BASE_LENGTH << slice_idx;
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,24 @@ psa_status_t psa_get_and_lock_key_slot(mbedtls_svc_key_id_t key,
|
||||
*/
|
||||
psa_status_t psa_initialize_key_slots(void);
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_KEY_STORE_DYNAMIC)
|
||||
/* Allow test code to customize the key slice length. We use this in tests
|
||||
* that exhaust the key store to reach a full key store in reasonable time
|
||||
* and memory.
|
||||
*
|
||||
* The length of each slice must be between 1 and
|
||||
* (1 << KEY_ID_SLOT_INDEX_WIDTH) inclusive.
|
||||
*
|
||||
* The length for a given slice index must not change while
|
||||
* the key store is initialized.
|
||||
*/
|
||||
extern size_t (*mbedtls_test_hook_psa_volatile_key_slice_length)(
|
||||
size_t slice_idx);
|
||||
|
||||
/* The number of volatile key slices. */
|
||||
size_t psa_key_slot_volatile_slice_count(void);
|
||||
#endif
|
||||
|
||||
/** Delete all data from key slots in memory.
|
||||
* This function is not thread safe, it wipes every key slot regardless of
|
||||
* state and reader count. It should only be called when no slot is in use.
|
||||
|
Reference in New Issue
Block a user