Test that deinit deactivates random generation and key slots

This commit is contained in:
Gilles Peskine 2018-11-20 21:00:42 +01:00
parent b309eec4a5
commit 445e225745
2 changed files with 29 additions and 9 deletions

View File

@ -1,8 +1,14 @@
PSA init/deinit PSA init/deinit
init_deinit: init_deinit:2
PSA validate module initialization: random No random without init
validate_module_init_generate_random: validate_module_init_generate_random:0
PSA validate module initialization: key based No key slot access without init
validate_module_init_key_based: validate_module_init_key_based:0
No random after deinit
validate_module_init_generate_random:1
No key slot access after deinit
validate_module_init_key_based:1

View File

@ -14,11 +14,11 @@
*/ */
/* BEGIN_CASE */ /* BEGIN_CASE */
void init_deinit( ) void init_deinit( int count )
{ {
psa_status_t status; psa_status_t status;
int i; int i;
for( i = 0; i <= 1; i++ ) for( i = 0; i < count; i++ )
{ {
status = psa_crypto_init( ); status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS ); TEST_ASSERT( status == PSA_SUCCESS );
@ -30,20 +30,34 @@ void init_deinit( )
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE */
void validate_module_init_generate_random( ) void validate_module_init_generate_random( int count )
{ {
psa_status_t status; psa_status_t status;
uint8_t random[10] = { 0 }; uint8_t random[10] = { 0 };
int i;
for( i = 0; i < count; i++ )
{
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
mbedtls_psa_crypto_free( );
}
status = psa_generate_random( random, sizeof( random ) ); status = psa_generate_random( random, sizeof( random ) );
TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); TEST_ASSERT( status == PSA_ERROR_BAD_STATE );
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE */ /* BEGIN_CASE */
void validate_module_init_key_based( ) void validate_module_init_key_based( int count )
{ {
psa_status_t status; psa_status_t status;
uint8_t data[10] = { 0 }; uint8_t data[10] = { 0 };
int i;
for( i = 0; i < count; i++ )
{
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
mbedtls_psa_crypto_free( );
}
status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) ); status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) );
TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); TEST_ASSERT( status == PSA_ERROR_BAD_STATE );
} }