New test helper to purge persistent key from memory

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-02-14 13:46:39 +01:00
parent e09ef87364
commit aae718caca
3 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -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 )

View file

@ -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: