Skip to content

Commit

Permalink
New test helper to purge persistent key from memory
Browse files Browse the repository at this point in the history
Signed-off-by: Gilles Peskine <[email protected]>
  • Loading branch information
gilles-peskine-arm committed Feb 23, 2021
1 parent e09ef87 commit aae718c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/include/test/psa_crypto_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/src/psa_crypto_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit aae718c

Please sign in to comment.