Rewrap some lines after the macro changes

Change the way some lines are wrapped to cut at a more logical place.
This commit mainly rewrites multi-line calls to TEST_EQUAL, and also a
few calls to PSA_ASSERT.
This commit is contained in:
Gilles Peskine 2018-12-18 00:33:25 +01:00
parent fe11b72b93
commit f812dcf4ae
4 changed files with 84 additions and 89 deletions

View File

@ -158,9 +158,8 @@ static int exercise_mac_key( psa_key_handle_t handle,
handle, alg ) ); handle, alg ) );
PSA_ASSERT( psa_mac_update( &operation, PSA_ASSERT( psa_mac_update( &operation,
input, sizeof( input ) ) ); input, sizeof( input ) ) );
TEST_EQUAL( psa_mac_verify_finish( &operation, TEST_EQUAL( psa_mac_verify_finish( &operation, mac, mac_length ),
mac, verify_status );
mac_length ), verify_status );
} }
return( 1 ); return( 1 );
@ -273,7 +272,8 @@ static int exercise_aead_key( psa_key_handle_t handle,
NULL, 0, NULL, 0,
ciphertext, ciphertext_length, ciphertext, ciphertext_length,
plaintext, sizeof( plaintext ), plaintext, sizeof( plaintext ),
&plaintext_length ), verify_status ); &plaintext_length ),
verify_status );
} }
return( 1 ); return( 1 );
@ -334,12 +334,11 @@ static int exercise_asymmetric_encryption_key( psa_key_handle_t handle,
if( usage & PSA_KEY_USAGE_ENCRYPT ) if( usage & PSA_KEY_USAGE_ENCRYPT )
{ {
PSA_ASSERT( PSA_ASSERT( psa_asymmetric_encrypt( handle, alg,
psa_asymmetric_encrypt( handle, alg, plaintext, plaintext_length,
plaintext, plaintext_length, NULL, 0,
NULL, 0, ciphertext, sizeof( ciphertext ),
ciphertext, sizeof( ciphertext ), &ciphertext_length ) );
&ciphertext_length ) );
} }
if( usage & PSA_KEY_USAGE_DECRYPT ) if( usage & PSA_KEY_USAGE_DECRYPT )
@ -496,7 +495,8 @@ static int asn1_skip_integer( unsigned char **p, const unsigned char *end,
size_t actual_bits; size_t actual_bits;
unsigned char msb; unsigned char msb;
TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len, TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len,
MBEDTLS_ASN1_INTEGER ), 0 ); MBEDTLS_ASN1_INTEGER ),
0 );
/* Tolerate a slight departure from DER encoding: /* Tolerate a slight departure from DER encoding:
* - 0 may be represented by an empty string or a 1-byte string. * - 0 may be represented by an empty string or a 1-byte string.
* - The sign bit may be used as a value bit. */ * - The sign bit may be used as a value bit. */
@ -646,7 +646,8 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits,
*/ */
TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len, TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len,
MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_SEQUENCE |
MBEDTLS_ASN1_CONSTRUCTED ), 0 ); MBEDTLS_ASN1_CONSTRUCTED ),
0 );
TEST_EQUAL( p + len, end ); TEST_EQUAL( p + len, end );
TEST_EQUAL( mbedtls_asn1_get_alg( &p, end, &alg, &params ), 0 ); TEST_EQUAL( mbedtls_asn1_get_alg( &p, end, &alg, &params ), 0 );
if( ! is_oid_of_key_type( type, alg.p, alg.len ) ) if( ! is_oid_of_key_type( type, alg.p, alg.len ) )
@ -664,7 +665,8 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits,
TEST_EQUAL( bitstring.unused_bits, 0 ); TEST_EQUAL( bitstring.unused_bits, 0 );
TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len, TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len,
MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_SEQUENCE |
MBEDTLS_ASN1_CONSTRUCTED ), 0 ); MBEDTLS_ASN1_CONSTRUCTED ),
0 );
TEST_EQUAL( p + len, end ); TEST_EQUAL( p + len, end );
if( ! asn1_skip_integer( &p, end, bits, bits, 1 ) ) if( ! asn1_skip_integer( &p, end, bits, bits, 1 ) )
goto exit; goto exit;
@ -756,8 +758,7 @@ static int exercise_export_public_key( psa_key_handle_t handle )
PSA_ASSERT( psa_get_key_information( handle, &type, &bits ) ); PSA_ASSERT( psa_get_key_information( handle, &type, &bits ) );
if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( type ) ) if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( type ) )
{ {
TEST_EQUAL( psa_export_public_key( handle, TEST_EQUAL( psa_export_public_key( handle, NULL, 0, &exported_length ),
NULL, 0, &exported_length ),
PSA_ERROR_INVALID_ARGUMENT ); PSA_ERROR_INVALID_ARGUMENT );
return( 1 ); return( 1 );
} }
@ -1014,8 +1015,8 @@ void import_export( data_t *data,
psa_key_policy_set_usage( &policy, usage_arg, alg ); psa_key_policy_set_usage( &policy, usage_arg, alg );
PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
TEST_EQUAL( psa_get_key_information( TEST_EQUAL( psa_get_key_information( handle, NULL, NULL ),
handle, NULL, NULL ), PSA_ERROR_EMPTY_SLOT ); PSA_ERROR_EMPTY_SLOT );
/* Import the key */ /* Import the key */
PSA_ASSERT( psa_import_key( handle, type, PSA_ASSERT( psa_import_key( handle, type,
@ -1075,8 +1076,8 @@ void import_export( data_t *data,
destroy: destroy:
/* Destroy the key */ /* Destroy the key */
PSA_ASSERT( psa_destroy_key( handle ) ); PSA_ASSERT( psa_destroy_key( handle ) );
TEST_EQUAL( psa_get_key_information( TEST_EQUAL( psa_get_key_information( handle, NULL, NULL ),
handle, NULL, NULL ), PSA_ERROR_INVALID_HANDLE ); PSA_ERROR_INVALID_HANDLE );
exit: exit:
mbedtls_free( exported ); mbedtls_free( exported );
@ -1826,14 +1827,12 @@ void hash_bad_order( )
/* psa_hash_update without calling psa_hash_setup beforehand */ /* psa_hash_update without calling psa_hash_setup beforehand */
memset( &operation, 0, sizeof( operation ) ); memset( &operation, 0, sizeof( operation ) );
TEST_EQUAL( psa_hash_update( &operation, TEST_EQUAL( psa_hash_update( &operation, input, sizeof( input ) ),
input, sizeof( input ) ),
PSA_ERROR_INVALID_ARGUMENT ); PSA_ERROR_INVALID_ARGUMENT );
/* psa_hash_verify without calling psa_hash_setup beforehand */ /* psa_hash_verify without calling psa_hash_setup beforehand */
memset( &operation, 0, sizeof( operation ) ); memset( &operation, 0, sizeof( operation ) );
TEST_EQUAL( psa_hash_verify( &operation, TEST_EQUAL( psa_hash_verify( &operation, hash, sizeof( hash ) ),
hash, sizeof( hash ) ),
PSA_ERROR_INVALID_ARGUMENT ); PSA_ERROR_INVALID_ARGUMENT );
/* psa_hash_finish without calling psa_hash_setup beforehand */ /* psa_hash_finish without calling psa_hash_setup beforehand */
@ -1864,20 +1863,17 @@ void hash_verify_bad_args( )
/* psa_hash_verify with a smaller hash than expected */ /* psa_hash_verify with a smaller hash than expected */
PSA_ASSERT( psa_hash_setup( &operation, alg ) ); PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_EQUAL( psa_hash_verify( &operation, TEST_EQUAL( psa_hash_verify( &operation, hash, expected_size - 1 ),
hash, expected_size - 1 ),
PSA_ERROR_INVALID_SIGNATURE ); PSA_ERROR_INVALID_SIGNATURE );
/* psa_hash_verify with a non-matching hash */ /* psa_hash_verify with a non-matching hash */
PSA_ASSERT( psa_hash_setup( &operation, alg ) ); PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_EQUAL( psa_hash_verify( &operation, TEST_EQUAL( psa_hash_verify( &operation, hash + 1, expected_size ),
hash + 1, expected_size ),
PSA_ERROR_INVALID_SIGNATURE ); PSA_ERROR_INVALID_SIGNATURE );
/* psa_hash_verify with a hash longer than expected */ /* psa_hash_verify with a hash longer than expected */
PSA_ASSERT( psa_hash_setup( &operation, alg ) ); PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_EQUAL( psa_hash_verify( &operation, TEST_EQUAL( psa_hash_verify( &operation, hash, sizeof( hash ) ),
hash, sizeof( hash ) ),
PSA_ERROR_INVALID_SIGNATURE ); PSA_ERROR_INVALID_SIGNATURE );
exit: exit:
@ -1899,8 +1895,8 @@ void hash_finish_bad_args( )
/* psa_hash_finish with a smaller hash buffer than expected */ /* psa_hash_finish with a smaller hash buffer than expected */
PSA_ASSERT( psa_hash_setup( &operation, alg ) ); PSA_ASSERT( psa_hash_setup( &operation, alg ) );
TEST_EQUAL( psa_hash_finish( &operation, TEST_EQUAL( psa_hash_finish( &operation,
hash, expected_size - 1, hash, expected_size - 1, &hash_len ),
&hash_len ), PSA_ERROR_BUFFER_TOO_SMALL ); PSA_ERROR_BUFFER_TOO_SMALL );
exit: exit:
mbedtls_psa_crypto_free( ); mbedtls_psa_crypto_free( );
@ -2645,7 +2641,8 @@ void aead_encrypt_decrypt( int key_type_arg, data_t *key_data,
additional_data->len, additional_data->len,
input_data->x, input_data->len, input_data->x, input_data->len,
output_data, output_size, output_data, output_size,
&output_length ), expected_result ); &output_length ),
expected_result );
if( PSA_SUCCESS == expected_result ) if( PSA_SUCCESS == expected_result )
{ {
@ -2657,7 +2654,8 @@ void aead_encrypt_decrypt( int key_type_arg, data_t *key_data,
additional_data->len, additional_data->len,
output_data, output_length, output_data, output_length,
output_data2, output_length, output_data2, output_length,
&output_length2 ), expected_result ); &output_length2 ),
expected_result );
ASSERT_COMPARE( input_data->x, input_data->len, ASSERT_COMPARE( input_data->x, input_data->len,
output_data2, output_length2 ); output_data2, output_length2 );
@ -2782,7 +2780,8 @@ void aead_decrypt( int key_type_arg, data_t *key_data,
additional_data->len, additional_data->len,
input_data->x, input_data->len, input_data->x, input_data->len,
output_data, output_size, output_data, output_size,
&output_length ), expected_result ); &output_length ),
expected_result );
if( expected_result == PSA_SUCCESS ) if( expected_result == PSA_SUCCESS )
ASSERT_COMPARE( expected_data->x, expected_data->len, ASSERT_COMPARE( expected_data->x, expected_data->len,
@ -2984,11 +2983,10 @@ void sign_verify( int key_type_arg, data_t *key_data,
* detected as invalid. Flip a bit at the beginning, not at the end, * detected as invalid. Flip a bit at the beginning, not at the end,
* because ECDSA may ignore the last few bits of the input. */ * because ECDSA may ignore the last few bits of the input. */
input_data->x[0] ^= 1; input_data->x[0] ^= 1;
TEST_EQUAL( psa_asymmetric_verify( TEST_EQUAL( psa_asymmetric_verify( handle, alg,
handle, alg, input_data->x, input_data->len,
input_data->x, input_data->len, signature, signature_length ),
signature, PSA_ERROR_INVALID_SIGNATURE );
signature_length ), PSA_ERROR_INVALID_SIGNATURE );
} }
exit: exit:
@ -3409,7 +3407,8 @@ void derive_setup( int key_type_arg,
TEST_EQUAL( psa_key_derivation( &generator, handle, alg, TEST_EQUAL( psa_key_derivation( &generator, handle, alg,
salt->x, salt->len, salt->x, salt->len,
label->x, label->len, label->x, label->len,
requested_capacity ), expected_status ); requested_capacity ),
expected_status );
exit: exit:
psa_generator_abort( &generator ); psa_generator_abort( &generator );
@ -3455,13 +3454,13 @@ void test_derive_invalid_generator_state( )
TEST_EQUAL( psa_key_derivation( &generator, handle, alg, TEST_EQUAL( psa_key_derivation( &generator, handle, alg,
NULL, 0, NULL, 0,
NULL, 0, NULL, 0,
capacity ), PSA_ERROR_BAD_STATE ); capacity ),
PSA_ERROR_BAD_STATE );
PSA_ASSERT( psa_generator_read( &generator, buffer, capacity ) PSA_ASSERT( psa_generator_read( &generator, buffer, capacity ) );
);
TEST_EQUAL( psa_generator_read( &generator, buffer, capacity ) TEST_EQUAL( psa_generator_read( &generator, buffer, capacity ),
, PSA_ERROR_INSUFFICIENT_CAPACITY ); PSA_ERROR_INSUFFICIENT_CAPACITY );
exit: exit:
psa_generator_abort( &generator ); psa_generator_abort( &generator );
@ -3649,9 +3648,8 @@ void derive_full( int alg_arg,
} }
/* Check that the generator refuses to go over capacity. */ /* Check that the generator refuses to go over capacity. */
TEST_EQUAL( psa_generator_read( &generator, TEST_EQUAL( psa_generator_read( &generator, output_buffer, 1 ),
output_buffer, PSA_ERROR_INSUFFICIENT_CAPACITY );
1 ), PSA_ERROR_INSUFFICIENT_CAPACITY );
PSA_ASSERT( psa_generator_abort( &generator ) ); PSA_ASSERT( psa_generator_abort( &generator ) );
@ -3847,7 +3845,8 @@ void key_agreement_setup( int alg_arg,
TEST_EQUAL( psa_key_agreement( &generator, TEST_EQUAL( psa_key_agreement( &generator,
our_key, our_key,
peer_key_data->x, peer_key_data->len, peer_key_data->x, peer_key_data->len,
alg ), expected_status_arg ); alg ),
expected_status_arg );
exit: exit:
psa_generator_abort( &generator ); psa_generator_abort( &generator );
@ -3946,18 +3945,16 @@ void key_agreement_output( int alg_arg,
peer_key_data->x, peer_key_data->len, peer_key_data->x, peer_key_data->len,
alg ) ); alg ) );
PSA_ASSERT( PSA_ASSERT( psa_generator_read( &generator,
psa_generator_read( &generator, actual_output,
actual_output, expected_output1->len ) );
expected_output1->len ) );
TEST_EQUAL( memcmp( actual_output, expected_output1->x, TEST_EQUAL( memcmp( actual_output, expected_output1->x,
expected_output1->len ), 0 ); expected_output1->len ), 0 );
if( expected_output2->len != 0 ) if( expected_output2->len != 0 )
{ {
PSA_ASSERT( PSA_ASSERT( psa_generator_read( &generator,
psa_generator_read( &generator, actual_output,
actual_output, expected_output2->len ) );
expected_output2->len ) );
TEST_EQUAL( memcmp( actual_output, expected_output2->x, TEST_EQUAL( memcmp( actual_output, expected_output2->x,
expected_output2->len ), 0 ); expected_output2->len ), 0 );
} }
@ -4047,13 +4044,12 @@ void generate_key( int type_arg,
PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
/* Generate a key */ /* Generate a key */
TEST_EQUAL( psa_generate_key( handle, type, bits, TEST_EQUAL( psa_generate_key( handle, type, bits, NULL, 0 ),
NULL, 0 ), expected_status ); expected_status );
/* Test the key information */ /* Test the key information */
TEST_EQUAL( psa_get_key_information( handle, TEST_EQUAL( psa_get_key_information( handle, &got_type, &got_bits ),
&got_type, expected_info_status );
&got_bits ), expected_info_status );
if( expected_info_status != PSA_SUCCESS ) if( expected_info_status != PSA_SUCCESS )
goto exit; goto exit;
TEST_EQUAL( got_type, type ); TEST_EQUAL( got_type, type );
@ -4144,8 +4140,10 @@ void persistent_key_load_key_from_storage( data_t *data, int type_arg,
} }
/* Export the key */ /* Export the key */
TEST_EQUAL( psa_export_key( handle, first_export, export_size, TEST_EQUAL( psa_export_key( handle,
&first_exported_length ), export_status ); first_export, export_size,
&first_exported_length ),
export_status );
/* Shutdown and restart */ /* Shutdown and restart */
mbedtls_psa_crypto_free(); mbedtls_psa_crypto_free();
@ -4160,14 +4158,14 @@ void persistent_key_load_key_from_storage( data_t *data, int type_arg,
TEST_EQUAL( bits_get, (size_t) bits ); TEST_EQUAL( bits_get, (size_t) bits );
PSA_ASSERT( psa_get_key_policy( handle, &policy_get ) ); PSA_ASSERT( psa_get_key_policy( handle, &policy_get ) );
TEST_EQUAL( psa_key_policy_get_usage( TEST_EQUAL( psa_key_policy_get_usage( &policy_get ), policy_usage );
&policy_get ), policy_usage ); TEST_EQUAL( psa_key_policy_get_algorithm( &policy_get ), policy_alg );
TEST_EQUAL( psa_key_policy_get_algorithm(
&policy_get ), policy_alg );
/* Export the key again */ /* Export the key again */
TEST_EQUAL( psa_export_key( handle, second_export, export_size, TEST_EQUAL( psa_export_key( handle,
&second_exported_length ), export_status ); second_export, export_size,
&second_exported_length ),
export_status );
if( export_status == PSA_SUCCESS ) if( export_status == PSA_SUCCESS )
{ {

View File

@ -287,20 +287,17 @@ void aead_algorithm( int alg_arg, int classification_flags,
{ {
psa_algorithm_t truncated_alg = PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, n ); psa_algorithm_t truncated_alg = PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, n );
aead_algorithm_core( truncated_alg, classification_flags, n ); aead_algorithm_core( truncated_alg, classification_flags, n );
TEST_EQUAL( TEST_EQUAL( PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( truncated_alg ),
PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( truncated_alg ), alg ); alg );
/* Check that calling PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH twice gives /* Check that calling PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH twice gives
* the length of the outer truncation (even if the outer length is * the length of the outer truncation (even if the outer length is
* smaller than the inner length). */ * smaller than the inner length). */
TEST_EQUAL( TEST_EQUAL( PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, 1 ),
PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, 1 ), PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, 1 ) );
PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, 1 ) ); TEST_EQUAL( PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length - 1 ),
TEST_EQUAL( PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, tag_length - 1) );
PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length - 1 ), TEST_EQUAL( PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length ),
PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, tag_length - 1) ); PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, tag_length ) );
TEST_EQUAL(
PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length ),
PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, tag_length ) );
} }
} }
/* END_CASE */ /* END_CASE */

View File

@ -102,7 +102,8 @@ void save_large_persistent_key( int data_too_large, int expected_status )
&handle ) ); &handle ) );
TEST_EQUAL( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA, TEST_EQUAL( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA,
data, data_length ), expected_status ); data, data_length ),
expected_status );
exit: exit:
mbedtls_free( data ); mbedtls_free( data );
@ -143,8 +144,8 @@ void persistent_key_destroy( int key_id_arg, int should_store,
/* Check key slot storage is removed */ /* Check key slot storage is removed */
TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 ); TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 );
TEST_EQUAL( psa_open_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, TEST_EQUAL( psa_open_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, &handle ),
&handle ), PSA_ERROR_EMPTY_SLOT ); PSA_ERROR_EMPTY_SLOT );
TEST_EQUAL( handle, 0 ); TEST_EQUAL( handle, 0 );
/* Shutdown and restart */ /* Shutdown and restart */
@ -183,8 +184,8 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
PSA_BYTES_TO_BITS( data->len ), PSA_BYTES_TO_BITS( data->len ),
&handle ) ); &handle ) );
psa_key_policy_init( &policy ); psa_key_policy_init( &policy );
TEST_EQUAL( psa_import_key( handle, type, TEST_EQUAL( psa_import_key( handle, type, data->x, data->len ),
data->x, data->len ), expected_status ); expected_status );
if( expected_status != PSA_SUCCESS ) if( expected_status != PSA_SUCCESS )
{ {

View File

@ -292,9 +292,8 @@ void create_fail( int lifetime_arg, int id_arg,
PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_crypto_init( ) );
TEST_EQUAL( psa_create_key( lifetime, id, TEST_EQUAL( psa_create_key( lifetime, id, type, max_bits, &handle ),
type, max_bits, expected_status );
&handle ), expected_status );
TEST_EQUAL( handle, 0 ); TEST_EQUAL( handle, 0 );
exit: exit: