From fe11b72b93598532cedd198d7d42cfc1609d31e2 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 18 Dec 2018 00:24:04 +0100 Subject: [PATCH] Use TEST_EQUAL(a,b) in preference to TEST_ASSERT(a==b) This commit is the result of the following command, followed by reindenting (but not wrapping lines): perl -00 -i -pe 's/^( *)TEST_ASSERT\(([^;=]*)(?: |\n *)==([^;=]*)\);$/${1}TEST_EQUAL($2,$3);/gm' tests/suites/test_suite_psa_*.function --- tests/suites/test_suite_psa_crypto.function | 406 +++++++++--------- .../test_suite_psa_crypto_entropy.function | 10 +- .../test_suite_psa_crypto_init.function | 10 +- .../test_suite_psa_crypto_metadata.function | 100 ++--- ...t_suite_psa_crypto_persistent_key.function | 38 +- ..._suite_psa_crypto_slot_management.function | 62 +-- ...est_suite_psa_crypto_storage_file.function | 26 +- 7 files changed, 326 insertions(+), 326 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index f665fb78f..561136de2 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -158,9 +158,9 @@ static int exercise_mac_key( psa_key_handle_t handle, handle, alg ) ); PSA_ASSERT( psa_mac_update( &operation, input, sizeof( input ) ) ); - TEST_ASSERT( psa_mac_verify_finish( &operation, - mac, - mac_length ) == verify_status ); + TEST_EQUAL( psa_mac_verify_finish( &operation, + mac, + mac_length ), verify_status ); } return( 1 ); @@ -268,12 +268,12 @@ static int exercise_aead_key( psa_key_handle_t handle, ( usage & PSA_KEY_USAGE_ENCRYPT ? PSA_SUCCESS : PSA_ERROR_INVALID_SIGNATURE ); - TEST_ASSERT( psa_aead_decrypt( handle, alg, - nonce, nonce_length, - NULL, 0, - ciphertext, ciphertext_length, - plaintext, sizeof( plaintext ), - &plaintext_length ) == verify_status ); + TEST_EQUAL( psa_aead_decrypt( handle, alg, + nonce, nonce_length, + NULL, 0, + ciphertext, ciphertext_length, + plaintext, sizeof( plaintext ), + &plaintext_length ), verify_status ); } return( 1 ); @@ -311,10 +311,10 @@ static int exercise_signature_key( psa_key_handle_t handle, ( usage & PSA_KEY_USAGE_SIGN ? PSA_SUCCESS : PSA_ERROR_INVALID_SIGNATURE ); - TEST_ASSERT( psa_asymmetric_verify( handle, alg, - payload, payload_length, - signature, signature_length ) == - verify_status ); + TEST_EQUAL( psa_asymmetric_verify( handle, alg, + payload, payload_length, + signature, signature_length ), + verify_status ); } return( 1 ); @@ -495,8 +495,8 @@ static int asn1_skip_integer( unsigned char **p, const unsigned char *end, size_t len; size_t actual_bits; unsigned char msb; - TEST_ASSERT( mbedtls_asn1_get_tag( p, end, &len, - MBEDTLS_ASN1_INTEGER ) == 0 ); + TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len, + MBEDTLS_ASN1_INTEGER ), 0 ); /* Tolerate a slight departure from DER encoding: * - 0 may be represented by an empty string or a 1-byte string. * - The sign bit may be used as a value bit. */ @@ -549,7 +549,7 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, uint8_t *exported, size_t exported_length ) { if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ) - TEST_ASSERT( exported_length == ( bits + 7 ) / 8 ); + TEST_EQUAL( exported_length, ( bits + 7 ) / 8 ); else TEST_ASSERT( exported_length <= PSA_KEY_EXPORT_MAX_SIZE( type, bits ) ); @@ -591,10 +591,10 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, * coefficient INTEGER, -- (inverse of q) mod p * } */ - TEST_ASSERT( mbedtls_asn1_get_tag( &p, end, &len, - MBEDTLS_ASN1_SEQUENCE | - MBEDTLS_ASN1_CONSTRUCTED ) == 0 ); - TEST_ASSERT( p + len == end ); + TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_SEQUENCE | + MBEDTLS_ASN1_CONSTRUCTED ), 0 ); + TEST_EQUAL( p + len, end ); if( ! asn1_skip_integer( &p, end, 0, 0, 0 ) ) goto exit; if( ! asn1_skip_integer( &p, end, bits, bits, 1 ) ) @@ -615,7 +615,7 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, goto exit; if( ! asn1_skip_integer( &p, end, 1, bits / 2 + 1, 0 ) ) goto exit; - TEST_ASSERT( p == end ); + TEST_EQUAL( p, end ); } else #endif /* MBEDTLS_RSA_C */ @@ -624,7 +624,7 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, if( PSA_KEY_TYPE_IS_ECC_KEYPAIR( type ) ) { /* Just the secret value */ - TEST_ASSERT( exported_length == PSA_BITS_TO_BYTES( bits ) ); + TEST_EQUAL( exported_length, PSA_BITS_TO_BYTES( bits ) ); } else #endif /* MBEDTLS_ECP_C */ @@ -644,15 +644,15 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL } */ - TEST_ASSERT( mbedtls_asn1_get_tag( &p, end, &len, - MBEDTLS_ASN1_SEQUENCE | - MBEDTLS_ASN1_CONSTRUCTED ) == 0 ); - TEST_ASSERT( p + len == end ); - TEST_ASSERT( mbedtls_asn1_get_alg( &p, end, &alg, ¶ms ) == 0 ); + TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_SEQUENCE | + MBEDTLS_ASN1_CONSTRUCTED ), 0 ); + TEST_EQUAL( p + len, end ); + TEST_EQUAL( mbedtls_asn1_get_alg( &p, end, &alg, ¶ms ), 0 ); if( ! is_oid_of_key_type( type, alg.p, alg.len ) ) goto exit; - TEST_ASSERT( mbedtls_asn1_get_bitstring( &p, end, &bitstring ) == 0 ); - TEST_ASSERT( p == end ); + TEST_EQUAL( mbedtls_asn1_get_bitstring( &p, end, &bitstring ), 0 ); + TEST_EQUAL( p, end ); p = bitstring.p; #if defined(MBEDTLS_RSA_C) if( type == PSA_KEY_TYPE_RSA_PUBLIC_KEY ) @@ -661,16 +661,16 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, * modulus INTEGER, -- n * publicExponent INTEGER } -- e */ - TEST_ASSERT( bitstring.unused_bits == 0 ); - TEST_ASSERT( mbedtls_asn1_get_tag( &p, end, &len, - MBEDTLS_ASN1_SEQUENCE | - MBEDTLS_ASN1_CONSTRUCTED ) == 0 ); - TEST_ASSERT( p + len == end ); + TEST_EQUAL( bitstring.unused_bits, 0 ); + TEST_EQUAL( mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_SEQUENCE | + MBEDTLS_ASN1_CONSTRUCTED ), 0 ); + TEST_EQUAL( p + len, end ); if( ! asn1_skip_integer( &p, end, bits, bits, 1 ) ) goto exit; if( ! asn1_skip_integer( &p, end, 2, bits, 1 ) ) goto exit; - TEST_ASSERT( p == end ); + TEST_EQUAL( p, end ); } else #endif /* MBEDTLS_RSA_C */ @@ -683,9 +683,9 @@ static int exported_key_sanity_check( psa_key_type_t type, size_t bits, * -- then y_P as a n-bit string, big endian, * -- where n is the order of the curve. */ - TEST_ASSERT( bitstring.unused_bits == 0 ); - TEST_ASSERT( p + 1 + 2 * PSA_BITS_TO_BYTES( bits ) == end ); - TEST_ASSERT( p[0] == 4 ); + TEST_EQUAL( bitstring.unused_bits, 0 ); + TEST_EQUAL( p + 1 + 2 * PSA_BITS_TO_BYTES( bits ), end ); + TEST_EQUAL( p[0], 4 ); } else #endif /* MBEDTLS_ECP_C */ @@ -725,8 +725,8 @@ static int exercise_export_key( psa_key_handle_t handle, if( ( usage & PSA_KEY_USAGE_EXPORT ) == 0 && ! PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) { - TEST_ASSERT( psa_export_key( handle, NULL, 0, &exported_length ) == - PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( psa_export_key( handle, NULL, 0, &exported_length ), + PSA_ERROR_NOT_PERMITTED ); return( 1 ); } @@ -756,9 +756,9 @@ static int exercise_export_public_key( psa_key_handle_t handle ) PSA_ASSERT( psa_get_key_information( handle, &type, &bits ) ); if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( type ) ) { - TEST_ASSERT( psa_export_public_key( handle, - NULL, 0, &exported_length ) == - PSA_ERROR_INVALID_ARGUMENT ); + TEST_EQUAL( psa_export_public_key( handle, + NULL, 0, &exported_length ), + PSA_ERROR_INVALID_ARGUMENT ); return( 1 ); } @@ -889,7 +889,7 @@ void import( data_t *data, int type, int expected_status_arg ) PSA_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), &handle ) ); status = psa_import_key( handle, type, data->x, data->len ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( status == PSA_SUCCESS ) PSA_ASSERT( psa_destroy_key( handle ) ); @@ -926,9 +926,9 @@ void import_twice( int alg_arg, int usage_arg, PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); status = psa_import_key( handle, type1, data1->x, data1->len ); - TEST_ASSERT( status == expected_import1_status ); + TEST_EQUAL( status, expected_import1_status ); status = psa_import_key( handle, type2, data2->x, data2->len ); - TEST_ASSERT( status == expected_import2_status ); + TEST_EQUAL( status, expected_import2_status ); if( expected_import1_status == PSA_SUCCESS || expected_import2_status == PSA_SUCCESS ) @@ -967,7 +967,7 @@ void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg ) /* Try importing the key */ PSA_ASSERT( psa_allocate_key( type, bits, &handle ) ); status = psa_import_key( handle, type, p, length ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( status == PSA_SUCCESS ) PSA_ASSERT( psa_destroy_key( handle ) ); @@ -1014,8 +1014,8 @@ void import_export( data_t *data, psa_key_policy_set_usage( &policy, usage_arg, alg ); PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_get_key_information( - handle, NULL, NULL ) == PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( psa_get_key_information( + handle, NULL, NULL ), PSA_ERROR_EMPTY_SLOT ); /* Import the key */ PSA_ASSERT( psa_import_key( handle, type, @@ -1025,14 +1025,14 @@ void import_export( data_t *data, PSA_ASSERT( psa_get_key_information( handle, &got_type, &got_bits ) ); - TEST_ASSERT( got_type == type ); - TEST_ASSERT( got_bits == (size_t) expected_bits ); + TEST_EQUAL( got_type, type ); + TEST_EQUAL( got_bits, (size_t) expected_bits ); /* Export the key */ status = psa_export_key( handle, exported, export_size, &exported_length ); - TEST_ASSERT( status == expected_export_status ); + TEST_EQUAL( status, expected_export_status ); /* The exported length must be set by psa_export_key() to a value between 0 * and export_size. On errors, the exported length must be 0. */ @@ -1044,7 +1044,7 @@ void import_export( data_t *data, export_size - exported_length ) ); if( status != PSA_SUCCESS ) { - TEST_ASSERT( exported_length == 0 ); + TEST_EQUAL( exported_length, 0 ); goto destroy; } @@ -1075,8 +1075,8 @@ void import_export( data_t *data, destroy: /* Destroy the key */ PSA_ASSERT( psa_destroy_key( handle ) ); - TEST_ASSERT( psa_get_key_information( - handle, NULL, NULL ) == PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_get_key_information( + handle, NULL, NULL ), PSA_ERROR_INVALID_HANDLE ); exit: mbedtls_free( exported ); @@ -1103,7 +1103,7 @@ void import_key_nonempty_slot( ) /* Import the key again */ status = psa_import_key( handle, type, data, sizeof( data ) ); - TEST_ASSERT( status == PSA_ERROR_OCCUPIED_SLOT ); + TEST_EQUAL( status, PSA_ERROR_OCCUPIED_SLOT ); exit: mbedtls_psa_crypto_free( ); @@ -1125,7 +1125,7 @@ void export_invalid_handle( int handle, int expected_export_status_arg ) status = psa_export_key( (psa_key_handle_t) handle, exported, export_size, &exported_length ); - TEST_ASSERT( status == expected_export_status ); + TEST_EQUAL( status, expected_export_status ); exit: mbedtls_psa_crypto_free( ); @@ -1155,7 +1155,7 @@ void export_with_no_key_activity( ) status = psa_export_key( handle, exported, export_size, &exported_length ); - TEST_ASSERT( status == PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( status, PSA_ERROR_EMPTY_SLOT ); exit: mbedtls_psa_crypto_free( ); @@ -1180,7 +1180,7 @@ void cipher_with_no_key_activity( ) PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); status = psa_cipher_encrypt_setup( &operation, handle, exercise_alg ); - TEST_ASSERT( status == PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( status, PSA_ERROR_EMPTY_SLOT ); exit: psa_cipher_abort( &operation ); @@ -1208,13 +1208,13 @@ void export_after_import_failure( data_t *data, int type_arg, /* Import the key - expect failure */ status = psa_import_key( handle, type, data->x, data->len ); - TEST_ASSERT( status == expected_import_status ); + TEST_EQUAL( status, expected_import_status ); /* Export the key */ status = psa_export_key( handle, exported, export_size, &exported_length ); - TEST_ASSERT( status == PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( status, PSA_ERROR_EMPTY_SLOT ); exit: mbedtls_psa_crypto_free( ); @@ -1240,10 +1240,10 @@ void cipher_after_import_failure( data_t *data, int type_arg, /* Import the key - expect failure */ status = psa_import_key( handle, type, data->x, data->len ); - TEST_ASSERT( status == expected_import_status ); + TEST_EQUAL( status, expected_import_status ); status = psa_cipher_encrypt_setup( &operation, handle, exercise_alg ); - TEST_ASSERT( status == PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( status, PSA_ERROR_EMPTY_SLOT ); exit: psa_cipher_abort( &operation ); @@ -1286,7 +1286,7 @@ void export_after_destroy_key( data_t *data, int type_arg ) /* Export the key */ status = psa_export_key( handle, exported, export_size, &exported_length ); - TEST_ASSERT( status == PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( status, PSA_ERROR_INVALID_HANDLE ); exit: mbedtls_free( exported ); @@ -1329,7 +1329,7 @@ void import_export_public_key( data_t *data, status = psa_export_public_key( handle, exported, export_size, &exported_length ); - TEST_ASSERT( status == expected_export_status ); + TEST_EQUAL( status, expected_export_status ); if( status == PSA_SUCCESS ) { psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( type ); @@ -1380,8 +1380,8 @@ void import_and_exercise_key( data_t *data, PSA_ASSERT( psa_get_key_information( handle, &got_type, &got_bits ) ); - TEST_ASSERT( got_type == type ); - TEST_ASSERT( got_bits == bits ); + TEST_EQUAL( got_type, type ); + TEST_EQUAL( got_bits, bits ); /* Do something with the key according to its type and permitted usage. */ if( ! exercise_key( handle, usage, alg ) ) @@ -1414,8 +1414,8 @@ void key_policy( int usage_arg, int alg_arg ) psa_key_policy_init( &policy_get ); psa_key_policy_set_usage( &policy_set, usage, alg ); - TEST_ASSERT( psa_key_policy_get_usage( &policy_set ) == usage ); - TEST_ASSERT( psa_key_policy_get_algorithm( &policy_set ) == alg ); + TEST_EQUAL( psa_key_policy_get_usage( &policy_set ), usage ); + TEST_EQUAL( psa_key_policy_get_algorithm( &policy_set ), alg ); PSA_ASSERT( psa_set_key_policy( handle, &policy_set ) ); PSA_ASSERT( psa_import_key( handle, key_type, @@ -1423,8 +1423,8 @@ void key_policy( int usage_arg, int alg_arg ) PSA_ASSERT( psa_get_key_policy( handle, &policy_get ) ); - TEST_ASSERT( policy_get.usage == policy_set.usage ); - TEST_ASSERT( policy_get.alg == policy_set.alg ); + TEST_EQUAL( policy_get.usage, policy_set.usage ); + TEST_EQUAL( policy_get.alg, policy_set.alg ); exit: psa_destroy_key( handle ); @@ -1462,7 +1462,7 @@ void mac_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_SIGN ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); psa_mac_abort( &operation ); memset( mac, 0, sizeof( mac ) ); @@ -1471,7 +1471,7 @@ void mac_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_VERIFY ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_mac_abort( &operation ); @@ -1509,7 +1509,7 @@ void cipher_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); psa_cipher_abort( &operation ); status = psa_cipher_decrypt_setup( &operation, handle, exercise_alg ); @@ -1517,7 +1517,7 @@ void cipher_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_cipher_abort( &operation ); @@ -1569,7 +1569,7 @@ void aead_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); memset( tag, 0, sizeof( tag ) ); status = psa_aead_decrypt( handle, exercise_alg, @@ -1580,9 +1580,9 @@ void aead_key_policy( int policy_usage, &output_length ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 ) - TEST_ASSERT( status == PSA_ERROR_INVALID_SIGNATURE ); + TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_destroy_key( handle ); @@ -1633,7 +1633,7 @@ void asymmetric_encryption_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); if( buffer_length != 0 ) memset( buffer, 0, buffer_length ); @@ -1644,9 +1644,9 @@ void asymmetric_encryption_key_policy( int policy_usage, &output_length ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 ) - TEST_ASSERT( status == PSA_ERROR_INVALID_PADDING ); + TEST_EQUAL( status, PSA_ERROR_INVALID_PADDING ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_destroy_key( handle ); @@ -1690,7 +1690,7 @@ void asymmetric_signature_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_SIGN ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); memset( signature, 0, sizeof( signature ) ); status = psa_asymmetric_verify( handle, exercise_alg, @@ -1698,9 +1698,9 @@ void asymmetric_signature_key_policy( int policy_usage, signature, sizeof( signature ) ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_VERIFY ) != 0 ) - TEST_ASSERT( status == PSA_ERROR_INVALID_SIGNATURE ); + TEST_EQUAL( status, PSA_ERROR_INVALID_SIGNATURE ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_destroy_key( handle ); @@ -1741,7 +1741,7 @@ void derive_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_DERIVE ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_generator_abort( &generator ); @@ -1781,7 +1781,7 @@ void agreement_key_policy( int policy_usage, ( policy_usage & PSA_KEY_USAGE_DERIVE ) != 0 ) PSA_ASSERT( status ); else - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_generator_abort( &generator ); @@ -1803,7 +1803,7 @@ void hash_setup( int alg_arg, status = psa_hash_setup( &operation, alg ); psa_hash_abort( &operation ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); exit: mbedtls_psa_crypto_free( ); @@ -1826,21 +1826,21 @@ void hash_bad_order( ) /* psa_hash_update without calling psa_hash_setup beforehand */ memset( &operation, 0, sizeof( operation ) ); - TEST_ASSERT( psa_hash_update( &operation, - input, sizeof( input ) ) == - PSA_ERROR_INVALID_ARGUMENT ); + TEST_EQUAL( psa_hash_update( &operation, + input, sizeof( input ) ), + PSA_ERROR_INVALID_ARGUMENT ); /* psa_hash_verify without calling psa_hash_setup beforehand */ memset( &operation, 0, sizeof( operation ) ); - TEST_ASSERT( psa_hash_verify( &operation, - hash, sizeof( hash ) ) == - PSA_ERROR_INVALID_ARGUMENT ); + TEST_EQUAL( psa_hash_verify( &operation, + hash, sizeof( hash ) ), + PSA_ERROR_INVALID_ARGUMENT ); /* psa_hash_finish without calling psa_hash_setup beforehand */ memset( &operation, 0, sizeof( operation ) ); - TEST_ASSERT( psa_hash_finish( &operation, - hash, sizeof( hash ), &hash_len ) == - PSA_ERROR_INVALID_ARGUMENT ); + TEST_EQUAL( psa_hash_finish( &operation, + hash, sizeof( hash ), &hash_len ), + PSA_ERROR_INVALID_ARGUMENT ); exit: mbedtls_psa_crypto_free( ); @@ -1864,21 +1864,21 @@ void hash_verify_bad_args( ) /* psa_hash_verify with a smaller hash than expected */ PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_ASSERT( psa_hash_verify( &operation, - hash, expected_size - 1 ) == - PSA_ERROR_INVALID_SIGNATURE ); + TEST_EQUAL( psa_hash_verify( &operation, + hash, expected_size - 1 ), + PSA_ERROR_INVALID_SIGNATURE ); /* psa_hash_verify with a non-matching hash */ PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_ASSERT( psa_hash_verify( &operation, - hash + 1, expected_size ) == - PSA_ERROR_INVALID_SIGNATURE ); + TEST_EQUAL( psa_hash_verify( &operation, + hash + 1, expected_size ), + PSA_ERROR_INVALID_SIGNATURE ); /* psa_hash_verify with a hash longer than expected */ PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_ASSERT( psa_hash_verify( &operation, - hash, sizeof( hash ) ) == - PSA_ERROR_INVALID_SIGNATURE ); + TEST_EQUAL( psa_hash_verify( &operation, + hash, sizeof( hash ) ), + PSA_ERROR_INVALID_SIGNATURE ); exit: mbedtls_psa_crypto_free( ); @@ -1898,9 +1898,9 @@ void hash_finish_bad_args( ) /* psa_hash_finish with a smaller hash buffer than expected */ PSA_ASSERT( psa_hash_setup( &operation, alg ) ); - TEST_ASSERT( psa_hash_finish( &operation, - hash, expected_size - 1, - &hash_len ) == PSA_ERROR_BUFFER_TOO_SMALL ); + TEST_EQUAL( psa_hash_finish( &operation, + hash, expected_size - 1, + &hash_len ), PSA_ERROR_BUFFER_TOO_SMALL ); exit: mbedtls_psa_crypto_free( ); @@ -1936,7 +1936,7 @@ void mac_setup( int key_type_arg, status = psa_mac_sign_setup( &operation, handle, alg ); psa_mac_abort( &operation ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); exit: psa_destroy_key( handle ); @@ -1989,8 +1989,8 @@ void mac_sign( int key_type_arg, &mac_length ) ); /* Compare with the expected value. */ - TEST_ASSERT( mac_length == expected_mac->len ); - TEST_ASSERT( memcmp( actual_mac, expected_mac->x, mac_length ) == 0 ); + TEST_EQUAL( mac_length, expected_mac->len ); + TEST_EQUAL( memcmp( actual_mac, expected_mac->x, mac_length ), 0 ); /* Verify that the end of the buffer is untouched. */ TEST_ASSERT( mem_is_char( actual_mac + mac_length, '+', @@ -2077,7 +2077,7 @@ void cipher_setup( int key_type_arg, status = psa_cipher_encrypt_setup( &operation, handle, alg ); psa_cipher_abort( &operation ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); exit: psa_destroy_key( handle ); @@ -2146,7 +2146,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg, &function_output_length ); total_output_length += function_output_length; - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( expected_status == PSA_SUCCESS ) { PSA_ASSERT( psa_cipher_abort( &operation ) ); @@ -2379,7 +2379,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg, output_buffer_size, &function_output_length ); total_output_length += function_output_length; - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( expected_status == PSA_SUCCESS ) { @@ -2639,25 +2639,25 @@ void aead_encrypt_decrypt( int key_type_arg, data_t *key_data, PSA_ASSERT( psa_import_key( handle, key_type, key_data->x, key_data->len ) ); - TEST_ASSERT( psa_aead_encrypt( handle, alg, - nonce->x, nonce->len, - additional_data->x, - additional_data->len, - input_data->x, input_data->len, - output_data, output_size, - &output_length ) == expected_result ); + TEST_EQUAL( psa_aead_encrypt( handle, alg, + nonce->x, nonce->len, + additional_data->x, + additional_data->len, + input_data->x, input_data->len, + output_data, output_size, + &output_length ), expected_result ); if( PSA_SUCCESS == expected_result ) { ASSERT_ALLOC( output_data2, output_length ); - TEST_ASSERT( psa_aead_decrypt( handle, alg, - nonce->x, nonce->len, - additional_data->x, - additional_data->len, - output_data, output_length, - output_data2, output_length, - &output_length2 ) == expected_result ); + TEST_EQUAL( psa_aead_decrypt( handle, alg, + nonce->x, nonce->len, + additional_data->x, + additional_data->len, + output_data, output_length, + output_data2, output_length, + &output_length2 ), expected_result ); ASSERT_COMPARE( input_data->x, input_data->len, output_data2, output_length2 ); @@ -2776,13 +2776,13 @@ void aead_decrypt( int key_type_arg, data_t *key_data, key_data->x, key_data->len ) ); - TEST_ASSERT( psa_aead_decrypt( handle, alg, - nonce->x, nonce->len, - additional_data->x, - additional_data->len, - input_data->x, input_data->len, - output_data, output_size, - &output_length ) == expected_result ); + TEST_EQUAL( psa_aead_decrypt( handle, alg, + nonce->x, nonce->len, + additional_data->x, + additional_data->len, + input_data->x, input_data->len, + output_data, output_size, + &output_length ), expected_result ); if( expected_result == PSA_SUCCESS ) ASSERT_COMPARE( expected_data->x, expected_data->len, @@ -2804,7 +2804,7 @@ void signature_size( int type_arg, psa_key_type_t type = type_arg; psa_algorithm_t alg = alg_arg; size_t actual_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( type, bits, alg ); - TEST_ASSERT( actual_size == (size_t) expected_size_arg ); + TEST_EQUAL( actual_size, (size_t) expected_size_arg ); exit: ; } @@ -2910,7 +2910,7 @@ void sign_fail( int key_type_arg, data_t *key_data, input_data->x, input_data->len, signature, signature_size, &signature_length ); - TEST_ASSERT( actual_status == expected_status ); + TEST_EQUAL( actual_status, expected_status ); /* The value of *signature_length is unspecified on error, but * whatever it is, it should be less than signature_size, so that * if the caller tries to read *signature_length bytes without @@ -2984,11 +2984,11 @@ void sign_verify( int key_type_arg, data_t *key_data, * detected as invalid. Flip a bit at the beginning, not at the end, * because ECDSA may ignore the last few bits of the input. */ input_data->x[0] ^= 1; - TEST_ASSERT( psa_asymmetric_verify( - handle, alg, - input_data->x, input_data->len, - signature, - signature_length ) == PSA_ERROR_INVALID_SIGNATURE ); + TEST_EQUAL( psa_asymmetric_verify( + handle, alg, + input_data->x, input_data->len, + signature, + signature_length ), PSA_ERROR_INVALID_SIGNATURE ); } exit: @@ -3078,7 +3078,7 @@ void asymmetric_verify_fail( int key_type_arg, data_t *key_data, signature_data->x, signature_data->len ); - TEST_ASSERT( actual_status == expected_status ); + TEST_EQUAL( actual_status, expected_status ); exit: psa_destroy_key( handle ); @@ -3133,8 +3133,8 @@ void asymmetric_encrypt( int key_type_arg, label->x, label->len, output, output_size, &output_length ); - TEST_ASSERT( actual_status == expected_status ); - TEST_ASSERT( output_length == expected_output_length ); + TEST_EQUAL( actual_status, expected_status ); + TEST_EQUAL( output_length, expected_output_length ); /* If the label is empty, the test framework puts a non-null pointer * in label->x. Test that a null pointer works as well. */ @@ -3148,8 +3148,8 @@ void asymmetric_encrypt( int key_type_arg, NULL, label->len, output, output_size, &output_length ); - TEST_ASSERT( actual_status == expected_status ); - TEST_ASSERT( output_length == expected_output_length ); + TEST_EQUAL( actual_status, expected_status ); + TEST_EQUAL( output_length, expected_output_length ); } exit: @@ -3351,7 +3351,7 @@ void asymmetric_decrypt_fail( int key_type_arg, label->x, label->len, output, output_size, &output_length ); - TEST_ASSERT( actual_status == expected_status ); + TEST_EQUAL( actual_status, expected_status ); TEST_ASSERT( output_length <= output_size ); /* If the label is empty, the test framework puts a non-null pointer @@ -3366,7 +3366,7 @@ void asymmetric_decrypt_fail( int key_type_arg, NULL, label->len, output, output_size, &output_length ); - TEST_ASSERT( actual_status == expected_status ); + TEST_EQUAL( actual_status, expected_status ); TEST_ASSERT( output_length <= output_size ); } @@ -3406,10 +3406,10 @@ void derive_setup( int key_type_arg, key_data->x, key_data->len ) ); - TEST_ASSERT( psa_key_derivation( &generator, handle, alg, - salt->x, salt->len, - label->x, label->len, - requested_capacity ) == expected_status ); + TEST_EQUAL( psa_key_derivation( &generator, handle, alg, + salt->x, salt->len, + label->x, label->len, + requested_capacity ), expected_status ); exit: psa_generator_abort( &generator ); @@ -3452,16 +3452,16 @@ void test_derive_invalid_generator_state( ) capacity ) ); /* state of generator shouldn't allow additional generation */ - TEST_ASSERT( psa_key_derivation( &generator, handle, alg, - NULL, 0, - NULL, 0, - capacity ) == PSA_ERROR_BAD_STATE ); + TEST_EQUAL( psa_key_derivation( &generator, handle, alg, + NULL, 0, + NULL, 0, + capacity ), PSA_ERROR_BAD_STATE ); PSA_ASSERT( psa_generator_read( &generator, buffer, capacity ) ); - TEST_ASSERT( psa_generator_read( &generator, buffer, capacity ) - == PSA_ERROR_INSUFFICIENT_CAPACITY ); + TEST_EQUAL( psa_generator_read( &generator, buffer, capacity ) + , PSA_ERROR_INSUFFICIENT_CAPACITY ); exit: psa_generator_abort( &generator ); @@ -3550,7 +3550,7 @@ void derive_output( int alg_arg, requested_capacity ) ); PSA_ASSERT( psa_get_generator_capacity( &generator, ¤t_capacity ) ); - TEST_ASSERT( current_capacity == requested_capacity ); + TEST_EQUAL( current_capacity, requested_capacity ); expected_capacity = requested_capacity; /* Expansion phase. */ @@ -3570,20 +3570,20 @@ void derive_output( int alg_arg, output_sizes[i] > expected_capacity ) { /* Capacity exceeded. */ - TEST_ASSERT( status == PSA_ERROR_INSUFFICIENT_CAPACITY ); + TEST_EQUAL( status, PSA_ERROR_INSUFFICIENT_CAPACITY ); expected_capacity = 0; continue; } /* Success. Check the read data. */ PSA_ASSERT( status ); if( output_sizes[i] != 0 ) - TEST_ASSERT( memcmp( output_buffer, expected_outputs[i], - output_sizes[i] ) == 0 ); + TEST_EQUAL( memcmp( output_buffer, expected_outputs[i], + output_sizes[i] ), 0 ); /* Check the generator status. */ expected_capacity -= output_sizes[i]; PSA_ASSERT( psa_get_generator_capacity( &generator, ¤t_capacity ) ); - TEST_ASSERT( expected_capacity == current_capacity ); + TEST_EQUAL( expected_capacity, current_capacity ); } PSA_ASSERT( psa_generator_abort( &generator ) ); @@ -3631,7 +3631,7 @@ void derive_full( int alg_arg, requested_capacity ) ); PSA_ASSERT( psa_get_generator_capacity( &generator, ¤t_capacity ) ); - TEST_ASSERT( current_capacity == expected_capacity ); + TEST_EQUAL( current_capacity, expected_capacity ); /* Expansion phase. */ while( current_capacity > 0 ) @@ -3645,13 +3645,13 @@ void derive_full( int alg_arg, expected_capacity -= read_size; PSA_ASSERT( psa_get_generator_capacity( &generator, ¤t_capacity ) ); - TEST_ASSERT( current_capacity == expected_capacity ); + TEST_EQUAL( current_capacity, expected_capacity ); } /* Check that the generator refuses to go over capacity. */ - TEST_ASSERT( psa_generator_read( &generator, - output_buffer, - 1 ) == PSA_ERROR_INSUFFICIENT_CAPACITY ); + TEST_EQUAL( psa_generator_read( &generator, + output_buffer, + 1 ), PSA_ERROR_INSUFFICIENT_CAPACITY ); PSA_ASSERT( psa_generator_abort( &generator ) ); @@ -3715,8 +3715,8 @@ void derive_key_exercise( int alg_arg, PSA_ASSERT( psa_get_key_information( derived_handle, &got_type, &got_bits ) ); - TEST_ASSERT( got_type == derived_type ); - TEST_ASSERT( got_bits == derived_bits ); + TEST_EQUAL( got_type, derived_type ); + TEST_EQUAL( got_bits, derived_bits ); /* Exercise the derived key. */ if( ! exercise_key( derived_handle, derived_usage, derived_alg ) ) @@ -3791,7 +3791,7 @@ void derive_key_export( int alg_arg, PSA_ASSERT( psa_export_key( derived_handle, export_buffer, bytes1, &length ) ); - TEST_ASSERT( length == bytes1 ); + TEST_EQUAL( length, bytes1 ); PSA_ASSERT( psa_destroy_key( derived_handle ) ); PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, PSA_BYTES_TO_BITS( bytes2 ), @@ -3804,10 +3804,10 @@ void derive_key_export( int alg_arg, PSA_ASSERT( psa_export_key( derived_handle, export_buffer + bytes1, bytes2, &length ) ); - TEST_ASSERT( length == bytes2 ); + TEST_EQUAL( length, bytes2 ); /* Compare the outputs from the two runs. */ - TEST_ASSERT( memcmp( output_buffer, export_buffer, capacity ) == 0 ); + TEST_EQUAL( memcmp( output_buffer, export_buffer, capacity ), 0 ); exit: mbedtls_free( output_buffer ); @@ -3844,10 +3844,10 @@ void key_agreement_setup( int alg_arg, our_key_data->x, our_key_data->len ) ); - TEST_ASSERT( psa_key_agreement( &generator, - our_key, - peer_key_data->x, peer_key_data->len, - alg ) == expected_status_arg ); + TEST_EQUAL( psa_key_agreement( &generator, + our_key, + peer_key_data->x, peer_key_data->len, + alg ), expected_status_arg ); exit: psa_generator_abort( &generator ); @@ -3891,7 +3891,7 @@ void key_agreement_capacity( int alg_arg, /* Test the advertized capacity. */ PSA_ASSERT( psa_get_generator_capacity( &generator, &actual_capacity ) ); - TEST_ASSERT( actual_capacity == (size_t) expected_capacity_arg ); + TEST_EQUAL( actual_capacity, (size_t) expected_capacity_arg ); /* Test the actual capacity by reading the output. */ while( actual_capacity > sizeof( output ) ) @@ -3902,8 +3902,8 @@ void key_agreement_capacity( int alg_arg, } PSA_ASSERT( psa_generator_read( &generator, output, actual_capacity ) ); - TEST_ASSERT( psa_generator_read( &generator, output, 1 ) == - PSA_ERROR_INSUFFICIENT_CAPACITY ); + TEST_EQUAL( psa_generator_read( &generator, output, 1 ), + PSA_ERROR_INSUFFICIENT_CAPACITY ); exit: psa_generator_abort( &generator ); @@ -3950,16 +3950,16 @@ void key_agreement_output( int alg_arg, psa_generator_read( &generator, actual_output, expected_output1->len ) ); - TEST_ASSERT( memcmp( actual_output, expected_output1->x, - expected_output1->len ) == 0 ); + TEST_EQUAL( memcmp( actual_output, expected_output1->x, + expected_output1->len ), 0 ); if( expected_output2->len != 0 ) { PSA_ASSERT( psa_generator_read( &generator, actual_output, expected_output2->len ) ); - TEST_ASSERT( memcmp( actual_output, expected_output2->x, - expected_output2->len ) == 0 ); + TEST_EQUAL( memcmp( actual_output, expected_output2->x, + expected_output2->len ), 0 ); } exit: @@ -3996,7 +3996,7 @@ void generate_random( int bytes_arg ) PSA_ASSERT( psa_generate_random( output, bytes ) ); /* Check that no more than bytes have been overwritten */ - TEST_ASSERT( memcmp( output + bytes, trail, sizeof( trail ) ) == 0 ); + TEST_EQUAL( memcmp( output + bytes, trail, sizeof( trail ) ), 0 ); for( i = 0; i < bytes; i++ ) { @@ -4047,17 +4047,17 @@ void generate_key( int type_arg, PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); /* Generate a key */ - TEST_ASSERT( psa_generate_key( handle, type, bits, - NULL, 0 ) == expected_status ); + TEST_EQUAL( psa_generate_key( handle, type, bits, + NULL, 0 ), expected_status ); /* Test the key information */ - TEST_ASSERT( psa_get_key_information( handle, - &got_type, - &got_bits ) == expected_info_status ); + TEST_EQUAL( psa_get_key_information( handle, + &got_type, + &got_bits ), expected_info_status ); if( expected_info_status != PSA_SUCCESS ) goto exit; - TEST_ASSERT( got_type == type ); - TEST_ASSERT( got_bits == bits ); + TEST_EQUAL( got_type, type ); + TEST_EQUAL( got_bits, bits ); /* Do something with the key according to its type and permitted usage. */ if( ! exercise_key( handle, usage, alg ) ) @@ -4144,8 +4144,8 @@ void persistent_key_load_key_from_storage( data_t *data, int type_arg, } /* Export the key */ - TEST_ASSERT( psa_export_key( handle, first_export, export_size, - &first_exported_length ) == export_status ); + TEST_EQUAL( psa_export_key( handle, first_export, export_size, + &first_exported_length ), export_status ); /* Shutdown and restart */ mbedtls_psa_crypto_free(); @@ -4156,18 +4156,18 @@ void persistent_key_load_key_from_storage( data_t *data, int type_arg, &handle ) ); PSA_ASSERT( psa_get_key_information( handle, &type_get, &bits_get ) ); - TEST_ASSERT( type_get == type ); - TEST_ASSERT( bits_get == (size_t) bits ); + TEST_EQUAL( type_get, type ); + TEST_EQUAL( bits_get, (size_t) bits ); PSA_ASSERT( psa_get_key_policy( handle, &policy_get ) ); - TEST_ASSERT( psa_key_policy_get_usage( - &policy_get ) == policy_usage ); - TEST_ASSERT( psa_key_policy_get_algorithm( - &policy_get ) == policy_alg ); + TEST_EQUAL( psa_key_policy_get_usage( + &policy_get ), policy_usage ); + TEST_EQUAL( psa_key_policy_get_algorithm( + &policy_get ), policy_alg ); /* Export the key again */ - TEST_ASSERT( psa_export_key( handle, second_export, export_size, - &second_exported_length ) == export_status ); + TEST_EQUAL( psa_export_key( handle, second_export, export_size, + &second_exported_length ), export_status ); if( export_status == PSA_SUCCESS ) { diff --git a/tests/suites/test_suite_psa_crypto_entropy.function b/tests/suites/test_suite_psa_crypto_entropy.function index 117184df2..704fad913 100644 --- a/tests/suites/test_suite_psa_crypto_entropy.function +++ b/tests/suites/test_suite_psa_crypto_entropy.function @@ -52,9 +52,9 @@ void validate_entropy_seed_injection( int seed_length_a, TEST_ASSERT( ( its_status == PSA_ITS_SUCCESS ) || ( its_status == PSA_ITS_ERROR_KEY_NOT_FOUND ) ); status = mbedtls_psa_inject_entropy( seed, seed_length_a ); - TEST_ASSERT( status == expected_status_a ); + TEST_EQUAL( status, expected_status_a ); status = mbedtls_psa_inject_entropy( seed, seed_length_b ); - TEST_ASSERT( status == expected_status_b ); + TEST_EQUAL( status, expected_status_b ); PSA_ASSERT( psa_crypto_init( ) ); PSA_ASSERT( psa_generate_random( output, sizeof( output ) ) ); @@ -84,9 +84,9 @@ void run_entropy_inject_with_crypto_init( ) status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) ); PSA_ASSERT( status ); its_status = psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID ); - TEST_ASSERT( its_status == PSA_ITS_SUCCESS ); + TEST_EQUAL( its_status, PSA_ITS_SUCCESS ); status = psa_crypto_init( ); - TEST_ASSERT( status == PSA_ERROR_INSUFFICIENT_ENTROPY ); + TEST_EQUAL( status, PSA_ERROR_INSUFFICIENT_ENTROPY ); status = mbedtls_psa_inject_entropy( seed, sizeof( seed ) ); PSA_ASSERT( status ); status = psa_crypto_init( ); @@ -94,7 +94,7 @@ void run_entropy_inject_with_crypto_init( ) 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 ) ); - TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); + TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: psa_its_remove( PSA_CRYPTO_ITS_RANDOM_SEED_UID ); mbedtls_psa_crypto_free( ); diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index f4da989db..e04652fda 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -176,7 +176,7 @@ void validate_module_init_generate_random( int count ) mbedtls_psa_crypto_free( ); } status = psa_generate_random( random, sizeof( random ) ); - TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); + TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); } /* END_CASE */ @@ -193,7 +193,7 @@ void validate_module_init_key_based( int count ) mbedtls_psa_crypto_free( ); } status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) ); - TEST_ASSERT( status == PSA_ERROR_BAD_STATE ); + TEST_EQUAL( status, PSA_ERROR_BAD_STATE ); } /* END_CASE */ @@ -207,7 +207,7 @@ void custom_entropy_sources( int sources_arg, int expected_init_status_arg ) PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources( custom_entropy_init, mbedtls_entropy_free ) ); - TEST_ASSERT( psa_crypto_init( ) == expected_init_status ); + TEST_EQUAL( psa_crypto_init( ), expected_init_status ); if( expected_init_status != PSA_SUCCESS ) goto exit; @@ -247,7 +247,7 @@ void fake_entropy_source( int threshold, PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources( custom_entropy_init, mbedtls_entropy_free ) ); - TEST_ASSERT( psa_crypto_init( ) == expected_init_status ); + TEST_EQUAL( psa_crypto_init( ), expected_init_status ); if( expected_init_status != PSA_SUCCESS ) goto exit; @@ -274,7 +274,7 @@ void entropy_from_nv_seed( int seed_size_arg, PSA_ASSERT( mbedtls_psa_crypto_configure_entropy_sources( custom_entropy_init, mbedtls_entropy_free ) ); - TEST_ASSERT( psa_crypto_init( ) == expected_init_status ); + TEST_EQUAL( psa_crypto_init( ), expected_init_status ); if( expected_init_status != PSA_SUCCESS ) goto exit; diff --git a/tests/suites/test_suite_psa_crypto_metadata.function b/tests/suites/test_suite_psa_crypto_metadata.function index af11e7ae1..1748b205c 100644 --- a/tests/suites/test_suite_psa_crypto_metadata.function +++ b/tests/suites/test_suite_psa_crypto_metadata.function @@ -83,15 +83,15 @@ void key_type_classification( psa_key_type_t type, unsigned flags ) TEST_CLASSIFICATION_MACRO( KEY_TYPE_IS_ECC, type, flags ); /* Macros with derived semantics */ - TEST_ASSERT( PSA_KEY_TYPE_IS_ASYMMETRIC( type ) == - ( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) || - PSA_KEY_TYPE_IS_KEYPAIR( type ) ) ); - TEST_ASSERT( PSA_KEY_TYPE_IS_ECC_KEYPAIR( type ) == - ( PSA_KEY_TYPE_IS_ECC( type ) && - PSA_KEY_TYPE_IS_KEYPAIR( type ) ) ); - TEST_ASSERT( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( type ) == - ( PSA_KEY_TYPE_IS_ECC( type ) && - PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) ); + TEST_EQUAL( PSA_KEY_TYPE_IS_ASYMMETRIC( type ), + ( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) || + PSA_KEY_TYPE_IS_KEYPAIR( type ) ) ); + TEST_EQUAL( PSA_KEY_TYPE_IS_ECC_KEYPAIR( type ), + ( PSA_KEY_TYPE_IS_ECC( type ) && + PSA_KEY_TYPE_IS_KEYPAIR( type ) ) ); + TEST_EQUAL( PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY( type ), + ( PSA_KEY_TYPE_IS_ECC( type ) && + PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) ); exit: ; } @@ -113,7 +113,7 @@ void mac_algorithm_core( psa_algorithm_t alg, int classification_flags, algorithm_classification( alg, classification_flags ); /* Length */ - TEST_ASSERT( length == PSA_MAC_FINAL_SIZE( key_type, key_bits, alg ) ); + TEST_EQUAL( length, PSA_MAC_FINAL_SIZE( key_type, key_bits, alg ) ); exit: ; } @@ -134,7 +134,7 @@ void aead_algorithm_core( psa_algorithm_t alg, int classification_flags, algorithm_classification( alg, classification_flags ); /* Tag length */ - TEST_ASSERT( tag_length == PSA_AEAD_TAG_LENGTH( alg ) ); + TEST_EQUAL( tag_length, PSA_AEAD_TAG_LENGTH( alg ) ); exit: ; } @@ -174,18 +174,18 @@ void hash_algorithm( int alg_arg, int length_arg ) algorithm_classification( alg, 0 ); /* Dependent algorithms */ - TEST_ASSERT( PSA_ALG_HMAC_GET_HASH( hmac_alg ) == alg ); - TEST_ASSERT( PSA_ALG_SIGN_GET_HASH( rsa_pkcs1v15_sign_alg ) == alg ); - TEST_ASSERT( PSA_ALG_SIGN_GET_HASH( rsa_pss_alg ) == alg ); - TEST_ASSERT( PSA_ALG_SIGN_GET_HASH( dsa_alg ) == alg ); - TEST_ASSERT( PSA_ALG_SIGN_GET_HASH( deterministic_dsa_alg ) == alg ); - TEST_ASSERT( PSA_ALG_SIGN_GET_HASH( ecdsa_alg ) == alg ); - TEST_ASSERT( PSA_ALG_SIGN_GET_HASH( deterministic_ecdsa_alg ) == alg ); - TEST_ASSERT( PSA_ALG_RSA_OAEP_GET_HASH( rsa_oaep_alg ) == alg ); - TEST_ASSERT( PSA_ALG_HKDF_GET_HASH( hkdf_alg ) == alg ); + TEST_EQUAL( PSA_ALG_HMAC_GET_HASH( hmac_alg ), alg ); + TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( rsa_pkcs1v15_sign_alg ), alg ); + TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( rsa_pss_alg ), alg ); + TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( dsa_alg ), alg ); + TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( deterministic_dsa_alg ), alg ); + TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( ecdsa_alg ), alg ); + TEST_EQUAL( PSA_ALG_SIGN_GET_HASH( deterministic_ecdsa_alg ), alg ); + TEST_EQUAL( PSA_ALG_RSA_OAEP_GET_HASH( rsa_oaep_alg ), alg ); + TEST_EQUAL( PSA_ALG_HKDF_GET_HASH( hkdf_alg ), alg ); /* Hash length */ - TEST_ASSERT( length == PSA_HASH_SIZE( alg ) ); + TEST_EQUAL( length, PSA_HASH_SIZE( alg ) ); TEST_ASSERT( length <= PSA_HASH_MAX_SIZE ); } /* END_CASE */ @@ -203,7 +203,7 @@ void mac_algorithm( int alg_arg, int classification_flags, mac_algorithm_core( alg, classification_flags, key_type, key_bits, length ); - TEST_ASSERT( PSA_ALG_FULL_LENGTH_MAC( alg ) == alg ); + TEST_EQUAL( PSA_ALG_FULL_LENGTH_MAC( alg ), alg ); TEST_ASSERT( length <= PSA_MAC_MAX_SIZE ); /* Truncated versions */ @@ -212,16 +212,16 @@ void mac_algorithm( int alg_arg, int classification_flags, psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC( alg, n ); mac_algorithm_core( truncated_alg, classification_flags, key_type, key_bits, n ); - TEST_ASSERT( PSA_ALG_FULL_LENGTH_MAC( truncated_alg ) == alg ); + TEST_EQUAL( PSA_ALG_FULL_LENGTH_MAC( truncated_alg ), alg ); /* Check that calling PSA_ALG_TRUNCATED_MAC twice gives the length * of the outer truncation (even if the outer length is smaller than * the inner length). */ - TEST_ASSERT( PSA_ALG_TRUNCATED_MAC( truncated_alg, 1 ) == - PSA_ALG_TRUNCATED_MAC( alg, 1 ) ); - TEST_ASSERT( PSA_ALG_TRUNCATED_MAC( truncated_alg, length - 1 ) == - PSA_ALG_TRUNCATED_MAC( alg, length - 1) ); - TEST_ASSERT( PSA_ALG_TRUNCATED_MAC( truncated_alg, length ) == - PSA_ALG_TRUNCATED_MAC( alg, length ) ); + TEST_EQUAL( PSA_ALG_TRUNCATED_MAC( truncated_alg, 1 ), + PSA_ALG_TRUNCATED_MAC( alg, 1 ) ); + TEST_EQUAL( PSA_ALG_TRUNCATED_MAC( truncated_alg, length - 1 ), + PSA_ALG_TRUNCATED_MAC( alg, length - 1) ); + TEST_EQUAL( PSA_ALG_TRUNCATED_MAC( truncated_alg, length ), + PSA_ALG_TRUNCATED_MAC( alg, length ) ); } } /* END_CASE */ @@ -238,7 +238,7 @@ void hmac_algorithm( int alg_arg, size_t n; TEST_ASSERT( PSA_ALG_IS_HASH( hash_alg ) ); - TEST_ASSERT( PSA_ALG_HMAC( hash_alg ) == alg ); + TEST_EQUAL( PSA_ALG_HMAC( hash_alg ), alg ); TEST_ASSERT( block_size <= PSA_HMAC_MAX_HASH_BLOCK_SIZE ); @@ -248,7 +248,7 @@ void hmac_algorithm( int alg_arg, for( n = 1; n <= length; n++ ) { psa_algorithm_t truncated_alg = PSA_ALG_TRUNCATED_MAC( alg, n ); - TEST_ASSERT( PSA_ALG_HMAC_GET_HASH( truncated_alg ) == hash_alg ); + TEST_EQUAL( PSA_ALG_HMAC_GET_HASH( truncated_alg ), hash_alg ); } } /* END_CASE */ @@ -287,19 +287,19 @@ void aead_algorithm( int alg_arg, int classification_flags, { psa_algorithm_t truncated_alg = PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, n ); aead_algorithm_core( truncated_alg, classification_flags, n ); - TEST_ASSERT( - PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( truncated_alg ) == alg ); + TEST_EQUAL( + PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( truncated_alg ), alg ); /* Check that calling PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH twice gives * the length of the outer truncation (even if the outer length is * smaller than the inner length). */ - TEST_ASSERT( - PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, 1 ) == + TEST_EQUAL( + PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, 1 ), PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, 1 ) ); - TEST_ASSERT( - PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length - 1 ) == + TEST_EQUAL( + PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length - 1 ), PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, tag_length - 1) ); - TEST_ASSERT( - PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length ) == + TEST_EQUAL( + PSA_ALG_AEAD_WITH_TAG_LENGTH( truncated_alg, tag_length ), PSA_ALG_AEAD_WITH_TAG_LENGTH( alg, tag_length ) ); } } @@ -363,8 +363,8 @@ void key_derivation_algorithm( int alg_arg, int classification_flags ) /* Check combinations with key agreements */ TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( PSA_ALG_FFDH( alg ) ) ); TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( PSA_ALG_ECDH( alg ) ) ); - TEST_ASSERT( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_ECDH( alg ) ) == alg ); - TEST_ASSERT( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_FFDH( alg ) ) == alg ); + TEST_EQUAL( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_ECDH( alg ) ), alg ); + TEST_EQUAL( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_FFDH( alg ) ), alg ); } /* END_CASE */ @@ -388,8 +388,8 @@ void key_selection_algorithm( int alg_arg, int classification_flags ) /* Check combinations with key agreements */ TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( PSA_ALG_FFDH( alg ) ) ); TEST_ASSERT( PSA_ALG_IS_KEY_AGREEMENT( PSA_ALG_ECDH( alg ) ) ); - TEST_ASSERT( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_ECDH( alg ) ) == alg ); - TEST_ASSERT( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_FFDH( alg ) ) == alg ); + TEST_EQUAL( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_ECDH( alg ) ), alg ); + TEST_EQUAL( PSA_ALG_KEY_AGREEMENT_GET_KDF( PSA_ALG_FFDH( alg ) ), alg ); } /* END_CASE */ @@ -416,7 +416,7 @@ void key_agreement_algorithm( int alg_arg, int classification_flags, /* Shared secret derivation properties */ TEST_ASSERT( PSA_ALG_IS_KEY_DERIVATION( actual_post_alg ) || PSA_ALG_IS_KEY_SELECTION( actual_post_alg ) ); - TEST_ASSERT( actual_post_alg == expected_post_alg ); + TEST_EQUAL( actual_post_alg, expected_post_alg ); } /* END_CASE */ @@ -431,22 +431,22 @@ void key_type( int type_arg, int classification_flags ) if( classification_flags & KEY_TYPE_IS_PUBLIC_KEY ) { psa_key_type_t pair_type = PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY( type ); - TEST_ASSERT( PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( pair_type ) == type ); + TEST_EQUAL( PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( pair_type ), type ); key_type_classification( pair_type, ( classification_flags & ~KEY_TYPE_IS_PUBLIC_KEY ) | KEY_TYPE_IS_KEYPAIR ); - TEST_ASSERT( PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( type ) == type ); + TEST_EQUAL( PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( type ), type ); } if( classification_flags & KEY_TYPE_IS_KEYPAIR ) { psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( type ); - TEST_ASSERT( PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY( public_type ) == type ); + TEST_EQUAL( PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY( public_type ), type ); key_type_classification( public_type, ( classification_flags & ~KEY_TYPE_IS_KEYPAIR ) | KEY_TYPE_IS_PUBLIC_KEY ); - TEST_ASSERT( PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY( type ) == type ); + TEST_EQUAL( PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY( type ), type ); } } /* END_CASE */ @@ -462,8 +462,8 @@ void ecc_key_types( int curve_arg, int curve_bits_arg ) test_key_type( public_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_PUBLIC_KEY ); test_key_type( pair_type, KEY_TYPE_IS_ECC | KEY_TYPE_IS_KEYPAIR ); - TEST_ASSERT( PSA_KEY_TYPE_GET_CURVE( public_type ) == curve ); - TEST_ASSERT( PSA_KEY_TYPE_GET_CURVE( pair_type ) == curve ); + TEST_EQUAL( PSA_KEY_TYPE_GET_CURVE( public_type ), curve ); + TEST_EQUAL( PSA_KEY_TYPE_GET_CURVE( pair_type ), curve ); /* Validate that the bit size is less than the maximum ECC bit size * in this implementation. There's no parameter that should be equal diff --git a/tests/suites/test_suite_psa_crypto_persistent_key.function b/tests/suites/test_suite_psa_crypto_persistent_key.function index bf7537641..c467d1901 100644 --- a/tests/suites/test_suite_psa_crypto_persistent_key.function +++ b/tests/suites/test_suite_psa_crypto_persistent_key.function @@ -66,13 +66,13 @@ void parse_storage_data_check( data_t *file_data, &key_data, &key_data_length, &key_type, &key_policy ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( status != PSA_SUCCESS ) goto exit; - TEST_ASSERT( key_type == (psa_key_type_t) expected_key_type ); - TEST_ASSERT( key_policy.usage == (uint32_t) expected_key_usage ); - TEST_ASSERT( key_policy.alg == (uint32_t) expected_key_alg ); + TEST_EQUAL( key_type, (psa_key_type_t) expected_key_type ); + TEST_EQUAL( key_policy.usage, (uint32_t) expected_key_usage ); + TEST_EQUAL( key_policy.alg, (uint32_t) expected_key_alg ); ASSERT_COMPARE( expected_key_data->x, expected_key_data->len, key_data, key_data_length ); @@ -101,8 +101,8 @@ void save_large_persistent_key( int data_too_large, int expected_status ) PSA_BYTES_TO_BITS( data_length ), &handle ) ); - TEST_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA, - data, data_length ) == expected_status ); + TEST_EQUAL( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA, + data, data_length ), expected_status ); exit: mbedtls_free( data ); @@ -142,10 +142,10 @@ void persistent_key_destroy( int key_id_arg, int should_store, PSA_ASSERT( psa_destroy_key( handle ) ); /* Check key slot storage is removed */ - TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 ); - TEST_ASSERT( psa_open_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, - &handle ) == PSA_ERROR_EMPTY_SLOT ); - TEST_ASSERT( handle == 0 ); + TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 ); + TEST_EQUAL( psa_open_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, + &handle ), PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( handle, 0 ); /* Shutdown and restart */ mbedtls_psa_crypto_free(); @@ -183,17 +183,17 @@ void persistent_key_import( int key_id_arg, int type_arg, data_t *data, PSA_BYTES_TO_BITS( data->len ), &handle ) ); psa_key_policy_init( &policy ); - TEST_ASSERT( psa_import_key( handle, type, - data->x, data->len ) == expected_status ); + TEST_EQUAL( psa_import_key( handle, type, + data->x, data->len ), expected_status ); if( expected_status != PSA_SUCCESS ) { - TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 ); + TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 ); goto exit; } PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime ) ); - TEST_ASSERT( lifetime == PSA_KEY_LIFETIME_PERSISTENT ); + TEST_EQUAL( lifetime, PSA_KEY_LIFETIME_PERSISTENT ); exit: psa_destroy_persistent_key( key_id ); @@ -235,15 +235,15 @@ void import_export_persistent_key( data_t *data, int type_arg, data->x, data->len ) ); PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime_get ) ); - TEST_ASSERT( lifetime_get == PSA_KEY_LIFETIME_PERSISTENT ); + TEST_EQUAL( lifetime_get, PSA_KEY_LIFETIME_PERSISTENT ); /* Test the key information */ PSA_ASSERT( psa_get_key_information( handle, &got_type, &got_bits ) ); - TEST_ASSERT( got_type == type ); - TEST_ASSERT( got_bits == (size_t) expected_bits ); + TEST_EQUAL( got_type, type ); + TEST_EQUAL( got_bits, (size_t) expected_bits ); - TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 1 ); + TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 1 ); if( key_not_exist ) { @@ -257,7 +257,7 @@ void import_export_persistent_key( data_t *data, int type_arg, /* Destroy the key */ PSA_ASSERT( psa_destroy_key( handle ) ); - TEST_ASSERT( psa_is_key_present_in_storage( key_id ) == 0 ); + TEST_EQUAL( psa_is_key_present_in_storage( key_id ), 0 ); exit: mbedtls_free( exported ); diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 4584ceb94..30d44cc2a 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -89,7 +89,7 @@ void transient_slot_lifecycle( int type_arg, int max_bits_arg, PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); PSA_ASSERT( psa_import_key( handle, type, key_data->x, key_data->len ) ); PSA_ASSERT( psa_get_key_information( handle, &read_type, NULL ) ); - TEST_ASSERT( read_type == type ); + TEST_EQUAL( read_type, type ); /* Do something that invalidates the handle. */ switch( close_method ) @@ -106,9 +106,9 @@ void transient_slot_lifecycle( int type_arg, int max_bits_arg, break; } /* Test that the handle is now invalid. */ - TEST_ASSERT( psa_get_key_information( handle, &read_type, NULL ) == - PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_close_key( handle ) == PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_get_key_information( handle, &read_type, NULL ), + PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_close_key( handle ), PSA_ERROR_INVALID_HANDLE ); exit: mbedtls_psa_crypto_free( ); @@ -145,13 +145,13 @@ void persistent_slot_lifecycle( int lifetime_arg, int id_arg, PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); PSA_ASSERT( psa_import_key( handle, type, key_data->x, key_data->len ) ); PSA_ASSERT( psa_get_key_information( handle, &read_type, NULL ) ); - TEST_ASSERT( read_type == type ); + TEST_EQUAL( read_type, type ); /* Close the key and reopen it. */ PSA_ASSERT( psa_close_key( handle ) ); PSA_ASSERT( psa_open_key( lifetime, id, &handle ) ); PSA_ASSERT( psa_get_key_information( handle, &read_type, NULL ) ); - TEST_ASSERT( read_type == type ); + TEST_EQUAL( read_type, type ); /* Do something that invalidates the handle. */ switch( close_method ) @@ -168,9 +168,9 @@ void persistent_slot_lifecycle( int lifetime_arg, int id_arg, break; } /* Test that the handle is now invalid. */ - TEST_ASSERT( psa_get_key_information( handle, &read_type, NULL ) == - PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_close_key( handle ) == PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_get_key_information( handle, &read_type, NULL ), + PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_close_key( handle ), PSA_ERROR_INVALID_HANDLE ); /* Try to reopen the key. If we destroyed it, check that it doesn't * exist, otherwise check that it still exists. */ @@ -180,11 +180,11 @@ void persistent_slot_lifecycle( int lifetime_arg, int id_arg, case CLOSE_BY_SHUTDOWN: PSA_ASSERT( psa_open_key( lifetime, id, &handle ) ); PSA_ASSERT( psa_get_key_information( handle, &read_type, NULL ) ); - TEST_ASSERT( read_type == type ); + TEST_EQUAL( read_type, type ); break; case CLOSE_BY_DESTROY: - TEST_ASSERT( psa_open_key( lifetime, id, &handle ) == - PSA_ERROR_EMPTY_SLOT ); + TEST_EQUAL( psa_open_key( lifetime, id, &handle ), + PSA_ERROR_EMPTY_SLOT ); break; } @@ -230,9 +230,9 @@ void create_existent( int lifetime_arg, int id_arg, PSA_ASSERT( psa_close_key( handle1 ) ); /* Attempt to create a new key in the same slot. */ - TEST_ASSERT( psa_create_key( lifetime, id, type2, bits1, &handle2 ) == - PSA_ERROR_OCCUPIED_SLOT ); - TEST_ASSERT( handle2 == 0 ); + TEST_EQUAL( psa_create_key( lifetime, id, type2, bits1, &handle2 ), + PSA_ERROR_OCCUPIED_SLOT ); + TEST_EQUAL( handle2, 0 ); if( reopen_policy == CLOSE_AFTER ) PSA_ASSERT( psa_close_key( handle1 ) ); @@ -243,8 +243,8 @@ void create_existent( int lifetime_arg, int id_arg, PSA_ASSERT( psa_get_key_policy( handle1, &read_policy ) ); TEST_ASSERT( psa_key_policy_equal( &read_policy, &policy1 ) ); PSA_ASSERT( psa_get_key_information( handle1, &read_type, &read_bits ) ); - TEST_ASSERT( read_type == type1 ); - TEST_ASSERT( read_bits == bits1 ); + TEST_EQUAL( read_type, type1 ); + TEST_EQUAL( read_bits, bits1 ); PSA_ASSERT( psa_export_key( handle1, reexported, sizeof( reexported ), &reexported_length ) ); @@ -268,8 +268,8 @@ void open_fail( int lifetime_arg, int id_arg, PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_open_key( lifetime, id, &handle ) == expected_status ); - TEST_ASSERT( handle == 0 ); + TEST_EQUAL( psa_open_key( lifetime, id, &handle ), expected_status ); + TEST_EQUAL( handle, 0 ); exit: mbedtls_psa_crypto_free( ); @@ -292,10 +292,10 @@ void create_fail( int lifetime_arg, int id_arg, PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_create_key( lifetime, id, - type, max_bits, - &handle ) == expected_status ); - TEST_ASSERT( handle == 0 ); + TEST_EQUAL( psa_create_key( lifetime, id, + type, max_bits, + &handle ), expected_status ); + TEST_EQUAL( handle, 0 ); exit: mbedtls_psa_crypto_free( ); @@ -326,17 +326,17 @@ void invalid_handle( ) material, sizeof( material ) ) ); /* Attempt to close and destroy some invalid handles. */ - TEST_ASSERT( psa_close_key( 0 ) == PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_close_key( handle1 - 1 ) == PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_close_key( handle1 + 1 ) == PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_destroy_key( 0 ) == PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_destroy_key( handle1 - 1 ) == PSA_ERROR_INVALID_HANDLE ); - TEST_ASSERT( psa_destroy_key( handle1 + 1 ) == PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_close_key( 0 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_close_key( handle1 - 1 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_close_key( handle1 + 1 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_destroy_key( 0 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_destroy_key( handle1 - 1 ), PSA_ERROR_INVALID_HANDLE ); + TEST_EQUAL( psa_destroy_key( handle1 + 1 ), PSA_ERROR_INVALID_HANDLE ); /* After all this, check that the original handle is intact. */ PSA_ASSERT( psa_get_key_information( handle1, &read_type, &read_bits ) ); - TEST_ASSERT( read_type == PSA_KEY_TYPE_RAW_DATA ); - TEST_ASSERT( read_bits == PSA_BYTES_TO_BITS( sizeof( material ) ) ); + TEST_EQUAL( read_type, PSA_KEY_TYPE_RAW_DATA ); + TEST_EQUAL( read_bits, PSA_BYTES_TO_BITS( sizeof( material ) ) ); PSA_ASSERT( psa_close_key( handle1 ) ); exit: diff --git a/tests/suites/test_suite_psa_crypto_storage_file.function b/tests/suites/test_suite_psa_crypto_storage_file.function index dabba2096..bf86ebb4d 100644 --- a/tests/suites/test_suite_psa_crypto_storage_file.function +++ b/tests/suites/test_suite_psa_crypto_storage_file.function @@ -30,9 +30,9 @@ void load_data_from_file( int id_to_load_arg, file = fopen( slot_location, "wb+" ); TEST_ASSERT( file != NULL ); file_size = fwrite( data->x, 1, data->len, file ); - TEST_ASSERT( file_size == data->len ); + TEST_EQUAL( file_size, data->len ); ret = fclose( file ); - TEST_ASSERT( ret == 0 ); + TEST_EQUAL( ret, 0 ); } /* Read from the file with psa_crypto_storage_load. */ @@ -41,7 +41,7 @@ void load_data_from_file( int id_to_load_arg, status = psa_crypto_storage_load( id_to_load, loaded_data, file_size ); /* Check we get the expected status. */ - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( status != PSA_SUCCESS ) goto exit; @@ -69,7 +69,7 @@ void write_data_to_file( data_t *data, int expected_status ) status = psa_crypto_storage_store( 1, data->x, data->len ); /* Check that we got the expected status. */ - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( status != PSA_SUCCESS ) goto exit; @@ -79,17 +79,17 @@ void write_data_to_file( data_t *data, int expected_status ) fseek( file, 0, SEEK_END ); file_size = (size_t) ftell( file ); fseek( file, 0, SEEK_SET ); - TEST_ASSERT( file_size == data->len ); + TEST_EQUAL( file_size, data->len ); /* Check that the file contents are what we expect */ loaded_data = mbedtls_calloc( 1, data->len ); TEST_ASSERT( loaded_data != NULL ); num_read = fread( loaded_data, 1, file_size, file ); - TEST_ASSERT( num_read == file_size ); + TEST_EQUAL( num_read, file_size ); ASSERT_COMPARE( data->x, data->len, loaded_data, file_size ); ret = fclose( file ); - TEST_ASSERT( ret == 0 ); + TEST_EQUAL( ret, 0 ); exit: mbedtls_free( loaded_data ); @@ -113,16 +113,16 @@ void get_file_size( data_t *data, int expected_data_length, file = fopen( slot_location, "wb+" ); TEST_ASSERT( file != NULL ); file_size = fwrite( data->x, 1, data->len, file ); - TEST_ASSERT( file_size == data->len ); + TEST_EQUAL( file_size, data->len ); ret = fclose( file ); - TEST_ASSERT( ret == 0 ); + TEST_EQUAL( ret, 0 ); } /* Check get data size is what we expect */ status = psa_crypto_storage_get_data_length( 1, &file_size ); - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( expected_status == PSA_SUCCESS ) - TEST_ASSERT( file_size == (size_t)expected_data_length ); + TEST_EQUAL( file_size, (size_t)expected_data_length ); exit: remove( slot_location ); @@ -142,13 +142,13 @@ void write_data_to_prexisting_file( char *preexist_file_location, file = fopen( preexist_file_location, "wb" ); TEST_ASSERT( file != NULL ); ret = fclose( file ); - TEST_ASSERT( ret == 0 ); + TEST_EQUAL( ret, 0 ); /* Write data to file. */ status = psa_crypto_storage_store( 1, data->x, data->len ); /* Check that we got the expected status. */ - TEST_ASSERT( status == expected_status ); + TEST_EQUAL( status, expected_status ); if( status != PSA_SUCCESS ) goto exit;