diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h index 9510c5fbe..3e356f9a8 100644 --- a/tests/include/test/psa_crypto_helpers.h +++ b/tests/include/test/psa_crypto_helpers.h @@ -43,6 +43,11 @@ int mbedtls_test_uses_key_id( mbedtls_svc_key_id_t key_id ); */ void mbedtls_test_psa_purge_key_storage( void ); +/** Purge the in-memory cache of persistent keys recorded with + * #TEST_USES_KEY_ID. + */ +void mbedtls_test_psa_purge_key_cache( void ); + /** \def TEST_USES_KEY_ID * * Call this macro in a test function before potentially creating a diff --git a/tests/src/psa_crypto_helpers.c b/tests/src/psa_crypto_helpers.c index 500451eb6..f2222cb28 100644 --- a/tests/src/psa_crypto_helpers.c +++ b/tests/src/psa_crypto_helpers.c @@ -63,6 +63,14 @@ void mbedtls_test_psa_purge_key_storage( void ) psa_destroy_persistent_key( key_ids_used_in_test[i] ); num_key_ids_used = 0; } + +void mbedtls_test_psa_purge_key_cache( void ) +{ + size_t i; + for( i = 0; i < num_key_ids_used; i++ ) + psa_purge_key( key_ids_used_in_test[i] ); +} + #endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */ const char *mbedtls_test_helper_is_psa_leaking( void ) diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 2be1a73e8..7c55c71e8 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -86,6 +86,7 @@ static int invalidate_psa( invalidate_method_t invalidate_method ) case INVALIDATE_BY_DESTROYING_WITH_SHUTDOWN: case INVALIDATE_BY_PURGING_WITH_SHUTDOWN: /* All keys must have been closed. */ + mbedtls_test_psa_purge_key_cache( ); PSA_DONE( ); break; case INVALIDATE_BY_SHUTDOWN: