Use PSA_ASSERT(a) in preference to TEST_ASSERT(a==PSA_SUCCESS)

This commit is the result of the following command, followed by
reindenting (but not wrapping lines):

perl -00 -i -pe 's/^( *)TEST_ASSERT\(([^;=]*)(?: |\n *)==\s*PSA_SUCCESS\s*\);$/${1}PSA_ASSERT($2 );/gm' tests/suites/test_suite_psa_*.function
This commit is contained in:
Gilles Peskine 2018-12-18 00:18:46 +01:00
parent 0f915f1d2a
commit 8817f61007
7 changed files with 850 additions and 873 deletions

File diff suppressed because it is too large Load diff

View file

@ -55,9 +55,9 @@ void validate_entropy_seed_injection( int seed_length_a,
TEST_ASSERT( status == expected_status_a );
status = mbedtls_psa_inject_entropy( seed, seed_length_b );
TEST_ASSERT( status == expected_status_b );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_generate_random( output,
sizeof( output ) ) == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init( ) );
PSA_ASSERT( psa_generate_random( output,
sizeof( output ) ) );
TEST_ASSERT( memcmp( output, zeros, sizeof( output ) ) != 0 );
exit:
mbedtls_free( seed );
@ -82,15 +82,15 @@ void run_entropy_inject_with_crypto_init( )
TEST_ASSERT( ( its_status == PSA_ITS_SUCCESS ) ||
( its_status == PSA_ITS_ERROR_KEY_NOT_FOUND ) );
status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
its_status = psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID );
TEST_ASSERT( its_status == PSA_ITS_SUCCESS );
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_ERROR_INSUFFICIENT_ENTROPY );
status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
mbedtls_psa_crypto_free( );
/* The seed is written by nv_seed callback functions therefore the injection will fail */
status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) );

View file

@ -23,14 +23,14 @@ void hash_finish( int alg_arg, data_t *input, data_t *expected_hash )
size_t actual_hash_length;
psa_hash_operation_t operation;
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init( ) );
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_update( &operation,
input->x, input->len ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_finish( &operation,
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
PSA_ASSERT( psa_hash_update( &operation,
input->x, input->len ) );
PSA_ASSERT( psa_hash_finish( &operation,
actual_hash, sizeof( actual_hash ),
&actual_hash_length ) == PSA_SUCCESS );
&actual_hash_length ) );
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
actual_hash, actual_hash_length );
@ -45,15 +45,15 @@ void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
psa_algorithm_t alg = alg_arg;
psa_hash_operation_t operation;
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init( ) );
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_update( &operation,
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
PSA_ASSERT( psa_hash_update( &operation,
input->x,
input->len ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_verify( &operation,
input->len ) );
PSA_ASSERT( psa_hash_verify( &operation,
expected_hash->x,
expected_hash->len ) == PSA_SUCCESS );
expected_hash->len ) );
exit:
mbedtls_psa_crypto_free( );
@ -69,22 +69,21 @@ void hash_multi_part( int alg_arg, data_t *input, data_t *expected_hash )
psa_hash_operation_t operation;
uint32_t len = 0;
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init( ) );
do
{
memset( actual_hash, 0, sizeof( actual_hash ) );
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_ASSERT( psa_hash_update( &operation,
input->x, len ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_update( &operation,
input->x + len, input->len - len ) ==
PSA_SUCCESS );
PSA_ASSERT( psa_hash_update( &operation,
input->x, len ) );
PSA_ASSERT( psa_hash_update( &operation,
input->x + len, input->len - len ) );
TEST_ASSERT( psa_hash_finish( &operation,
PSA_ASSERT( psa_hash_finish( &operation,
actual_hash, sizeof( actual_hash ),
&actual_hash_length ) == PSA_SUCCESS );
&actual_hash_length ) );
ASSERT_COMPARE( expected_hash->x, expected_hash->len,
actual_hash, actual_hash_length );

View file

@ -142,9 +142,9 @@ void init_deinit( int count )
for( i = 0; i < count; i++ )
{
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
mbedtls_psa_crypto_free( );
}
}
@ -156,7 +156,7 @@ void deinit_without_init( int count )
int i;
for( i = 0; i < count; i++ )
{
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init( ) );
mbedtls_psa_crypto_free( );
}
mbedtls_psa_crypto_free( );
@ -172,7 +172,7 @@ void validate_module_init_generate_random( int count )
for( i = 0; i < count; i++ )
{
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
mbedtls_psa_crypto_free( );
}
status = psa_generate_random( random, sizeof( random ) );
@ -189,7 +189,7 @@ void validate_module_init_key_based( int count )
for( i = 0; i < count; i++ )
{
status = psa_crypto_init( );
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
mbedtls_psa_crypto_free( );
}
status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) );
@ -204,16 +204,14 @@ void custom_entropy_sources( int sources_arg, int expected_init_status_arg )
uint8_t random[10] = { 0 };
custom_entropy_sources_mask = sources_arg;
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
custom_entropy_init, mbedtls_entropy_free ) ==
PSA_SUCCESS );
PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
custom_entropy_init, mbedtls_entropy_free ) );
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
if( expected_init_status != PSA_SUCCESS )
goto exit;
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
PSA_SUCCESS );
PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
exit:
mbedtls_psa_crypto_free( );
@ -246,16 +244,14 @@ void fake_entropy_source( int threshold,
fake_entropy_state.length_sequence = lengths;
custom_entropy_sources_mask = ENTROPY_SOURCE_FAKE;
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
custom_entropy_init, mbedtls_entropy_free ) ==
PSA_SUCCESS );
PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
custom_entropy_init, mbedtls_entropy_free ) );
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
if( expected_init_status != PSA_SUCCESS )
goto exit;
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
PSA_SUCCESS );
PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
exit:
mbedtls_psa_crypto_free( );
@ -275,16 +271,14 @@ void entropy_from_nv_seed( int seed_size_arg,
TEST_ASSERT( mbedtls_nv_seed_write( seed, seed_size ) >= 0 );
custom_entropy_sources_mask = ENTROPY_SOURCE_NV_SEED;
TEST_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
custom_entropy_init, mbedtls_entropy_free ) ==
PSA_SUCCESS );
PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources(
custom_entropy_init, mbedtls_entropy_free ) );
TEST_ASSERT( psa_crypto_init( ) == expected_init_status );
if( expected_init_status != PSA_SUCCESS )
goto exit;
TEST_ASSERT( psa_generate_random( random, sizeof( random ) ) ==
PSA_SUCCESS );
PSA_ASSERT( psa_generate_random( random, sizeof( random ) ) );
exit:
mbedtls_free( seed );

View file

@ -81,7 +81,6 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE */
void save_large_persistent_key( int data_too_large, int expected_status )
{
@ -95,12 +94,12 @@ void save_large_persistent_key( int data_too_large, int expected_status )
ASSERT_ALLOC( data, data_length );
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init() );
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
PSA_KEY_TYPE_RAW_DATA,
PSA_BYTES_TO_BITS( data_length ),
&handle ) == PSA_SUCCESS );
&handle ) );
TEST_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA,
data, data_length ) == expected_status );
@ -123,24 +122,24 @@ void persistent_key_destroy( int key_id_arg, int should_store,
psa_key_type_t first_type = (psa_key_type_t) first_type_arg;
psa_key_type_t second_type = (psa_key_type_t) second_type_arg;
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init() );
psa_key_policy_init( &policy );
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
first_type,
PSA_BYTES_TO_BITS( first_data->len ),
&handle ) == PSA_SUCCESS );
&handle ) );
if( should_store == 1 )
{
TEST_ASSERT( psa_import_key(
PSA_ASSERT( psa_import_key(
handle, first_type,
first_data->x, first_data->len ) == PSA_SUCCESS );
first_data->x, first_data->len ) );
}
/* Destroy the key */
TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS );
PSA_ASSERT( psa_destroy_key( handle ) );
/* Check key slot storage is removed */
TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 );
@ -150,16 +149,16 @@ void persistent_key_destroy( int key_id_arg, int should_store,
/* Shutdown and restart */
mbedtls_psa_crypto_free();
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init() );
/* Create another key in the same slot */
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
second_type,
PSA_BYTES_TO_BITS( second_data->len ),
&handle ) == PSA_SUCCESS );
TEST_ASSERT( psa_import_key(
&handle ) );
PSA_ASSERT( psa_import_key(
handle, second_type,
second_data->x, second_data->len ) == PSA_SUCCESS );
second_data->x, second_data->len ) );
exit:
mbedtls_psa_crypto_free();
@ -177,12 +176,12 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
psa_key_type_t type = (psa_key_type_t) type_arg;
psa_key_handle_t handle = 0;
TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init() );
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
type,
PSA_BYTES_TO_BITS( data->len ),
&handle ) == PSA_SUCCESS );
&handle ) );
psa_key_policy_init( &policy );
TEST_ASSERT( psa_import_key( handle, type,
data->x, data->len ) == expected_status );
@ -193,7 +192,7 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
goto exit;
}
TEST_ASSERT( psa_get_key_lifetime( handle, &lifetime ) == PSA_SUCCESS );
PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime ) );
TEST_ASSERT( lifetime == PSA_KEY_LIFETIME_PERSISTENT );
exit:
@ -219,28 +218,28 @@ void import_export_persistent_key( data_t *data, int type_arg,
ASSERT_ALLOC( exported, export_size );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
PSA_ASSERT( psa_crypto_init( ) );
TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
type,
PSA_BYTES_TO_BITS( data->len ),
&handle ) == PSA_SUCCESS );
&handle ) );
psa_key_policy_init( &policy );
psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT,
PSA_ALG_VENDOR_FLAG );
TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS );
PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
/* Import the key */
TEST_ASSERT( psa_import_key( handle, type,
data->x, data->len ) == PSA_SUCCESS );
PSA_ASSERT( psa_import_key( handle, type,
data->x, data->len ) );
TEST_ASSERT( psa_get_key_lifetime( handle, &lifetime_get ) == PSA_SUCCESS );
PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime_get ) );
TEST_ASSERT( lifetime_get == PSA_KEY_LIFETIME_PERSISTENT );
/* Test the key information */
TEST_ASSERT( psa_get_key_information(
handle, &got_type, &got_bits ) == PSA_SUCCESS );
PSA_ASSERT( psa_get_key_information(
handle, &got_type, &got_bits ) );
TEST_ASSERT( got_type == type );
TEST_ASSERT( got_bits == (size_t) expected_bits );
@ -251,13 +250,13 @@ void import_export_persistent_key( data_t *data, int type_arg,
psa_destroy_persistent_key( key_id );
}
/* Export the key */
TEST_ASSERT( psa_export_key( handle, exported, export_size,
&exported_length ) == PSA_SUCCESS );
PSA_ASSERT( psa_export_key( handle, exported, export_size,
&exported_length ) );
ASSERT_COMPARE( data->x, data->len, exported, exported_length );
/* Destroy the key */
TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS );
PSA_ASSERT( psa_destroy_key( handle ) );
TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 );
exit:

View file

@ -367,7 +367,7 @@ void many_transient_handles( int max_handles_arg )
&handles[i] );
if( status == PSA_ERROR_INSUFFICIENT_MEMORY )
break;
TEST_ASSERT( status == PSA_SUCCESS );
PSA_ASSERT( status );
TEST_ASSERT( handles[i] != 0 );
for( j = 0; j < i; j++ )
TEST_ASSERT( handles[i] != handles[j] );

View file

@ -97,7 +97,6 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE */
void get_file_size( data_t *data, int expected_data_length,
int expected_status, int should_make_file )