mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-26 23:51:08 +00:00
Close or destroy keys explicitly in tests
This commit is contained in:
parent
1153e7bd57
commit
76b29a77fb
|
@ -1291,6 +1291,7 @@ void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg )
|
||||||
psa_set_key_type( &attributes, type );
|
psa_set_key_type( &attributes, type );
|
||||||
status = psa_import_key( &attributes, p, length, &handle );
|
status = psa_import_key( &attributes, p, length, &handle );
|
||||||
TEST_EQUAL( status, expected_status );
|
TEST_EQUAL( status, expected_status );
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
PSA_ASSERT( psa_destroy_key( handle ) );
|
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||||
|
|
||||||
|
@ -2100,6 +2101,9 @@ void copy_fail( int source_usage_arg,
|
||||||
TEST_EQUAL( psa_copy_key( source_handle,
|
TEST_EQUAL( psa_copy_key( source_handle,
|
||||||
&target_attributes, &target_handle ),
|
&target_attributes, &target_handle ),
|
||||||
expected_status_arg );
|
expected_status_arg );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( source_handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
psa_reset_key_attributes( &source_attributes );
|
psa_reset_key_attributes( &source_attributes );
|
||||||
psa_reset_key_attributes( &target_attributes );
|
psa_reset_key_attributes( &target_attributes );
|
||||||
|
@ -2587,6 +2591,8 @@ void mac_bad_order( )
|
||||||
PSA_ERROR_BAD_STATE );
|
PSA_ERROR_BAD_STATE );
|
||||||
PSA_ASSERT( psa_mac_abort( &operation ) );
|
PSA_ASSERT( psa_mac_abort( &operation ) );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PSA_DONE( );
|
PSA_DONE( );
|
||||||
}
|
}
|
||||||
|
@ -2908,6 +2914,8 @@ void cipher_bad_order( )
|
||||||
PSA_ERROR_BAD_STATE );
|
PSA_ERROR_BAD_STATE );
|
||||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PSA_DONE( );
|
PSA_DONE( );
|
||||||
}
|
}
|
||||||
|
@ -5016,6 +5024,7 @@ void persistent_key_load_key_from_storage( data_t *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shutdown and restart */
|
/* Shutdown and restart */
|
||||||
|
PSA_ASSERT( psa_close_key( handle ) );
|
||||||
PSA_DONE();
|
PSA_DONE();
|
||||||
PSA_ASSERT( psa_crypto_init() );
|
PSA_ASSERT( psa_crypto_init() );
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,9 @@ void save_large_persistent_key( int data_too_large, int expected_status )
|
||||||
TEST_EQUAL( psa_import_key( &attributes, data, data_length, &handle ),
|
TEST_EQUAL( psa_import_key( &attributes, data, data_length, &handle ),
|
||||||
expected_status );
|
expected_status );
|
||||||
|
|
||||||
|
if( expected_status == PSA_SUCCESS )
|
||||||
|
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_free( data );
|
mbedtls_free( data );
|
||||||
PSA_DONE();
|
PSA_DONE();
|
||||||
|
@ -161,6 +164,8 @@ void persistent_key_destroy( int key_id_arg, int restart,
|
||||||
PSA_ASSERT( psa_import_key( &attributes, second_data->x, second_data->len,
|
PSA_ASSERT( psa_import_key( &attributes, second_data->x, second_data->len,
|
||||||
&handle ) );
|
&handle ) );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PSA_DONE();
|
PSA_DONE();
|
||||||
psa_destroy_persistent_key( key_id );
|
psa_destroy_persistent_key( key_id );
|
||||||
|
@ -206,6 +211,8 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
|
||||||
TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
|
TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
|
||||||
TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
|
TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
psa_reset_key_attributes( &attributes );
|
psa_reset_key_attributes( &attributes );
|
||||||
psa_destroy_persistent_key( key_id );
|
psa_destroy_persistent_key( key_id );
|
||||||
|
|
|
@ -228,6 +228,7 @@ void persistent_slot_lifecycle( int lifetime_arg, int id_arg,
|
||||||
&reexported_length ),
|
&reexported_length ),
|
||||||
PSA_ERROR_NOT_PERMITTED );
|
PSA_ERROR_NOT_PERMITTED );
|
||||||
}
|
}
|
||||||
|
PSA_ASSERT( psa_close_key( handle ) );
|
||||||
break;
|
break;
|
||||||
case CLOSE_BY_DESTROY:
|
case CLOSE_BY_DESTROY:
|
||||||
TEST_EQUAL( psa_open_key( id, &handle ),
|
TEST_EQUAL( psa_open_key( id, &handle ),
|
||||||
|
@ -302,6 +303,8 @@ void create_existent( int lifetime_arg, int id_arg,
|
||||||
ASSERT_COMPARE( material1, sizeof( material1 ),
|
ASSERT_COMPARE( material1, sizeof( material1 ),
|
||||||
reexported, reexported_length );
|
reexported, reexported_length );
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_close_key( handle1 ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PSA_DONE( );
|
PSA_DONE( );
|
||||||
psa_purge_key_storage( );
|
psa_purge_key_storage( );
|
||||||
|
@ -428,7 +431,7 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_id_arg,
|
||||||
* sure that the material is still alive. */
|
* sure that the material is still alive. */
|
||||||
if( target_lifetime != PSA_KEY_LIFETIME_VOLATILE )
|
if( target_lifetime != PSA_KEY_LIFETIME_VOLATILE )
|
||||||
{
|
{
|
||||||
PSA_DONE( );
|
mbedtls_psa_crypto_free( );
|
||||||
PSA_ASSERT( psa_crypto_init( ) );
|
PSA_ASSERT( psa_crypto_init( ) );
|
||||||
PSA_ASSERT( psa_open_key( target_id, &target_handle ) );
|
PSA_ASSERT( psa_open_key( target_id, &target_handle ) );
|
||||||
}
|
}
|
||||||
|
@ -463,6 +466,8 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_id_arg,
|
||||||
PSA_ERROR_NOT_PERMITTED );
|
PSA_ERROR_NOT_PERMITTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( target_handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PSA_DONE( );
|
PSA_DONE( );
|
||||||
mbedtls_free( export_buffer );
|
mbedtls_free( export_buffer );
|
||||||
|
@ -566,6 +571,10 @@ void copy_to_occupied( int source_lifetime_arg, int source_id_arg,
|
||||||
export_buffer, length );
|
export_buffer, length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PSA_ASSERT( psa_destroy_key( source_handle ) );
|
||||||
|
if( target_handle != source_handle )
|
||||||
|
PSA_ASSERT( psa_destroy_key( target_handle ) );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
PSA_DONE( );
|
PSA_DONE( );
|
||||||
mbedtls_free( export_buffer );
|
mbedtls_free( export_buffer );
|
||||||
|
|
Loading…
Reference in a new issue