From 8817f6100735acf18dc35849335317a27c0a9b68 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 18 Dec 2018 00:18:46 +0100 Subject: [PATCH] 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 --- tests/suites/test_suite_psa_crypto.function | 1540 ++++++++--------- .../test_suite_psa_crypto_entropy.function | 12 +- .../test_suite_psa_crypto_hash.function | 49 +- .../test_suite_psa_crypto_init.function | 34 +- ...t_suite_psa_crypto_persistent_key.function | 85 +- ..._suite_psa_crypto_slot_management.function | 2 +- ...est_suite_psa_crypto_storage_file.function | 1 - 7 files changed, 850 insertions(+), 873 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index d6b5e5154..f665fb78f 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -139,13 +139,13 @@ static int exercise_mac_key( psa_key_handle_t handle, if( usage & PSA_KEY_USAGE_SIGN ) { - TEST_ASSERT( psa_mac_sign_setup( &operation, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_update( &operation, - input, sizeof( input ) ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_sign_finish( &operation, - mac, sizeof( mac ), - &mac_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_mac_sign_setup( &operation, + handle, alg ) ); + PSA_ASSERT( psa_mac_update( &operation, + input, sizeof( input ) ) ); + PSA_ASSERT( psa_mac_sign_finish( &operation, + mac, sizeof( mac ), + &mac_length ) ); } if( usage & PSA_KEY_USAGE_VERIFY ) @@ -154,10 +154,10 @@ static int exercise_mac_key( psa_key_handle_t handle, ( usage & PSA_KEY_USAGE_SIGN ? PSA_SUCCESS : PSA_ERROR_INVALID_SIGNATURE ); - TEST_ASSERT( psa_mac_verify_setup( &operation, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_update( &operation, - input, sizeof( input ) ) == PSA_SUCCESS ); + PSA_ASSERT( psa_mac_verify_setup( &operation, + handle, alg ) ); + PSA_ASSERT( psa_mac_update( &operation, + input, sizeof( input ) ) ); TEST_ASSERT( psa_mac_verify_finish( &operation, mac, mac_length ) == verify_status ); @@ -185,19 +185,19 @@ static int exercise_cipher_key( psa_key_handle_t handle, if( usage & PSA_KEY_USAGE_ENCRYPT ) { - TEST_ASSERT( psa_cipher_encrypt_setup( &operation, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_generate_iv( &operation, - iv, sizeof( iv ), - &iv_length ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_update( &operation, - plaintext, sizeof( plaintext ), - ciphertext, sizeof( ciphertext ), - &ciphertext_length ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_finish( &operation, - ciphertext + ciphertext_length, - sizeof( ciphertext ) - ciphertext_length, - &part_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_encrypt_setup( &operation, + handle, alg ) ); + PSA_ASSERT( psa_cipher_generate_iv( &operation, + iv, sizeof( iv ), + &iv_length ) ); + PSA_ASSERT( psa_cipher_update( &operation, + plaintext, sizeof( plaintext ), + ciphertext, sizeof( ciphertext ), + &ciphertext_length ) ); + PSA_ASSERT( psa_cipher_finish( &operation, + ciphertext + ciphertext_length, + sizeof( ciphertext ) - ciphertext_length, + &part_length ) ); ciphertext_length += part_length; } @@ -211,14 +211,14 @@ static int exercise_cipher_key( psa_key_handle_t handle, TEST_ASSERT( psa_get_key_information( handle, &type, &bits ) ); iv_length = PSA_BLOCK_CIPHER_BLOCK_SIZE( type ); } - TEST_ASSERT( psa_cipher_decrypt_setup( &operation, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_set_iv( &operation, - iv, iv_length ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_update( &operation, - ciphertext, ciphertext_length, - decrypted, sizeof( decrypted ), - &part_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_decrypt_setup( &operation, + handle, alg ) ); + PSA_ASSERT( psa_cipher_set_iv( &operation, + iv, iv_length ) ); + PSA_ASSERT( psa_cipher_update( &operation, + ciphertext, ciphertext_length, + decrypted, sizeof( decrypted ), + &part_length ) ); status = psa_cipher_finish( &operation, decrypted + part_length, sizeof( decrypted ) - part_length, @@ -228,7 +228,7 @@ static int exercise_cipher_key( psa_key_handle_t handle, ciphertext, a padding error is likely. */ if( ( usage & PSA_KEY_USAGE_ENCRYPT ) || PSA_BLOCK_CIPHER_BLOCK_SIZE( type ) == 1 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_SUCCESS || status == PSA_ERROR_INVALID_PADDING ); @@ -254,12 +254,12 @@ static int exercise_aead_key( psa_key_handle_t handle, if( usage & PSA_KEY_USAGE_ENCRYPT ) { - TEST_ASSERT( psa_aead_encrypt( handle, alg, - nonce, nonce_length, - NULL, 0, - plaintext, sizeof( plaintext ), - ciphertext, sizeof( ciphertext ), - &ciphertext_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_aead_encrypt( handle, alg, + nonce, nonce_length, + NULL, 0, + plaintext, sizeof( plaintext ), + ciphertext, sizeof( ciphertext ), + &ciphertext_length ) ); } if( usage & PSA_KEY_USAGE_DECRYPT ) @@ -299,10 +299,10 @@ static int exercise_signature_key( psa_key_handle_t handle, psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH( alg ); if( hash_alg != 0 ) payload_length = PSA_HASH_SIZE( hash_alg ); - TEST_ASSERT( psa_asymmetric_sign( handle, alg, - payload, payload_length, - signature, sizeof( signature ), - &signature_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_sign( handle, alg, + payload, payload_length, + signature, sizeof( signature ), + &signature_length ) ); } if( usage & PSA_KEY_USAGE_VERIFY ) @@ -334,12 +334,12 @@ static int exercise_asymmetric_encryption_key( psa_key_handle_t handle, if( usage & PSA_KEY_USAGE_ENCRYPT ) { - TEST_ASSERT( + PSA_ASSERT( psa_asymmetric_encrypt( handle, alg, plaintext, plaintext_length, NULL, 0, ciphertext, sizeof( ciphertext ), - &ciphertext_length ) == PSA_SUCCESS ); + &ciphertext_length ) ); } if( usage & PSA_KEY_USAGE_DECRYPT ) @@ -375,15 +375,15 @@ static int exercise_key_derivation_key( psa_key_handle_t handle, if( usage & PSA_KEY_USAGE_DERIVE ) { - TEST_ASSERT( psa_key_derivation( &generator, - handle, alg, - label, label_length, - seed, seed_length, - sizeof( output ) ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_read( &generator, - output, - sizeof( output ) ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_abort( &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, + handle, alg, + label, label_length, + seed, seed_length, + sizeof( output ) ) ); + PSA_ASSERT( psa_generator_read( &generator, + output, + sizeof( output ) ) ); + PSA_ASSERT( psa_generator_abort( &generator ) ); } return( 1 ); @@ -408,16 +408,16 @@ static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator, * good enough: callers will report it as a failed test anyway. */ psa_status_t status = PSA_ERROR_UNKNOWN_ERROR; - TEST_ASSERT( psa_get_key_information( handle, - &private_key_type, - &key_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, + &private_key_type, + &key_bits ) ); public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( private_key_type ); public_key_length = PSA_KEY_EXPORT_MAX_SIZE( public_key_type, key_bits ); ASSERT_ALLOC( public_key, public_key_length ); TEST_ASSERT( public_key != NULL ); - TEST_ASSERT( psa_export_public_key( handle, - public_key, public_key_length, - &public_key_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_export_public_key( handle, + public_key, public_key_length, + &public_key_length ) ); status = psa_key_agreement( generator, handle, public_key, public_key_length, @@ -439,12 +439,11 @@ static int exercise_key_agreement_key( psa_key_handle_t handle, { /* We need two keys to exercise key agreement. Exercise the * private key against its own public key. */ - TEST_ASSERT( key_agreement_with_self( &generator, handle, alg ) == - PSA_SUCCESS ); - TEST_ASSERT( psa_generator_read( &generator, - output, - sizeof( output ) ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_abort( &generator ) == PSA_SUCCESS ); + PSA_ASSERT( key_agreement_with_self( &generator, handle, alg ) ); + PSA_ASSERT( psa_generator_read( &generator, + output, + sizeof( output ) ) ); + PSA_ASSERT( psa_generator_abort( &generator ) ); } ok = 1; @@ -721,7 +720,7 @@ static int exercise_export_key( psa_key_handle_t handle, size_t exported_length = 0; int ok = 0; - TEST_ASSERT( psa_get_key_information( handle, &type, &bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, &type, &bits ) ); if( ( usage & PSA_KEY_USAGE_EXPORT ) == 0 && ! PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) ) @@ -734,9 +733,9 @@ static int exercise_export_key( psa_key_handle_t handle, exported_size = PSA_KEY_EXPORT_MAX_SIZE( type, bits ); ASSERT_ALLOC( exported, exported_size ); - TEST_ASSERT( psa_export_key( handle, - exported, exported_size, - &exported_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_export_key( handle, + exported, exported_size, + &exported_length ) ); ok = exported_key_sanity_check( type, bits, exported, exported_length ); exit: @@ -754,7 +753,7 @@ static int exercise_export_public_key( psa_key_handle_t handle ) size_t exported_length = 0; int ok = 0; - TEST_ASSERT( psa_get_key_information( handle, &type, &bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, &type, &bits ) ); if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( type ) ) { TEST_ASSERT( psa_export_public_key( handle, @@ -767,9 +766,9 @@ static int exercise_export_public_key( psa_key_handle_t handle ) exported_size = PSA_KEY_EXPORT_MAX_SIZE( public_type, bits ); ASSERT_ALLOC( exported, exported_size ); - TEST_ASSERT( psa_export_public_key( handle, - exported, exported_size, - &exported_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_export_public_key( handle, + exported, exported_size, + &exported_length ) ); ok = exported_key_sanity_check( public_type, bits, exported, exported_length ); @@ -885,14 +884,14 @@ void import( data_t *data, int type, int expected_status_arg ) TEST_ASSERT( data != NULL ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( data->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), - &handle ) == PSA_SUCCESS ); + 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 ); if( status == PSA_SUCCESS ) - TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_destroy_key( handle ) ); exit: mbedtls_psa_crypto_free( ); @@ -916,15 +915,15 @@ void import_twice( int alg_arg, int usage_arg, psa_key_policy_t policy; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type1, - MAX( KEY_BITS_FROM_DATA( type1, data1 ), - KEY_BITS_FROM_DATA( type2, data2 ) ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type1, + MAX( KEY_BITS_FROM_DATA( type1, data1 ), + KEY_BITS_FROM_DATA( type2, data2 ) ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, usage, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); status = psa_import_key( handle, type1, data1->x, data1->len ); TEST_ASSERT( status == expected_import1_status ); @@ -958,7 +957,7 @@ void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg ) int ret; size_t length; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); ASSERT_ALLOC( buffer, buffer_size ); TEST_ASSERT( ( ret = construct_fake_rsa_key( buffer, buffer_size, &p, @@ -966,11 +965,11 @@ void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg ) length = ret; /* Try importing the key */ - TEST_ASSERT( psa_allocate_key( type, bits, &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, bits, &handle ) ); status = psa_import_key( handle, type, p, length ); TEST_ASSERT( status == expected_status ); if( status == PSA_SUCCESS ) - TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_destroy_key( handle ) ); exit: mbedtls_free( buffer ); @@ -1008,25 +1007,24 @@ void import_export( data_t *data, ASSERT_ALLOC( exported, export_size ); if( ! canonical_input ) ASSERT_ALLOC( reexported, export_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, expected_bits, &handle ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, expected_bits, &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, usage_arg, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); TEST_ASSERT( psa_get_key_information( handle, NULL, NULL ) == PSA_ERROR_EMPTY_SLOT ); /* 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 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 ); @@ -1058,26 +1056,25 @@ void import_export( data_t *data, else { psa_key_handle_t handle2; - TEST_ASSERT( psa_allocate_key( type, expected_bits, &handle2 ) == - PSA_SUCCESS ); - TEST_ASSERT( psa_set_key_policy( handle2, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, expected_bits, &handle2 ) ); + PSA_ASSERT( psa_set_key_policy( handle2, &policy ) ); - TEST_ASSERT( psa_import_key( handle2, type, - exported, - exported_length ) == PSA_SUCCESS ); - TEST_ASSERT( psa_export_key( handle2, - reexported, - export_size, - &reexported_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle2, type, + exported, + exported_length ) ); + PSA_ASSERT( psa_export_key( handle2, + reexported, + export_size, + &reexported_length ) ); ASSERT_COMPARE( exported, exported_length, reexported, reexported_length ); - TEST_ASSERT( psa_close_key( handle2 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_close_key( handle2 ) ); } TEST_ASSERT( exported_length <= PSA_KEY_EXPORT_MAX_SIZE( type, got_bits ) ); destroy: /* Destroy the key */ - TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_destroy_key( handle ) ); TEST_ASSERT( psa_get_key_information( handle, NULL, NULL ) == PSA_ERROR_INVALID_HANDLE ); @@ -1095,14 +1092,14 @@ void import_key_nonempty_slot( ) psa_key_type_t type = PSA_KEY_TYPE_RAW_DATA; psa_status_t status; const uint8_t data[] = { 0x1, 0x2, 0x3, 0x4, 0x5 }; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, PSA_BYTES_TO_BITS( sizeof( data ) ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, PSA_BYTES_TO_BITS( sizeof( data ) ), + &handle ) ); /* Import the key */ - TEST_ASSERT( psa_import_key( handle, type, - data, sizeof( data ) ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, type, + data, sizeof( data ) ) ); /* Import the key again */ status = psa_import_key( handle, type, data, sizeof( data ) ); @@ -1122,7 +1119,7 @@ void export_invalid_handle( int handle, int expected_export_status_arg ) size_t exported_length = INVALID_EXPORT_LENGTH; psa_status_t expected_export_status = expected_export_status_arg; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); /* Export the key */ status = psa_export_key( (psa_key_handle_t) handle, @@ -1146,13 +1143,13 @@ void export_with_no_key_activity( ) size_t export_size = 0; size_t exported_length = INVALID_EXPORT_LENGTH; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, 0, - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, 0, + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); /* Export the key */ status = psa_export_key( handle, @@ -1174,13 +1171,13 @@ void cipher_with_no_key_activity( ) psa_cipher_operation_t operation; int exercise_alg = PSA_ALG_CTR; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, 0, - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, 0, + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, exercise_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); status = psa_cipher_encrypt_setup( &operation, handle, exercise_alg ); TEST_ASSERT( status == PSA_ERROR_EMPTY_SLOT ); @@ -1203,10 +1200,10 @@ void export_after_import_failure( data_t *data, int type_arg, psa_status_t expected_import_status = expected_import_status_arg; size_t exported_length = INVALID_EXPORT_LENGTH; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), + &handle ) ); /* Import the key - expect failure */ status = psa_import_key( handle, type, @@ -1235,10 +1232,10 @@ void cipher_after_import_failure( data_t *data, int type_arg, psa_status_t expected_import_status = expected_import_status_arg; int exercise_alg = PSA_ALG_CTR; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), + &handle ) ); /* Import the key - expect failure */ status = psa_import_key( handle, type, @@ -1266,25 +1263,25 @@ void export_after_destroy_key( data_t *data, int type_arg ) size_t export_size = 0; size_t exported_length = INVALID_EXPORT_LENGTH; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); export_size = (ptrdiff_t) data->len; ASSERT_ALLOC( exported, export_size ); /* 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_export_key( handle, exported, export_size, - &exported_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_export_key( handle, exported, export_size, + &exported_length ) ); /* Destroy the key */ - TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_destroy_key( handle ) ); /* Export the key */ status = psa_export_key( handle, exported, export_size, @@ -1315,17 +1312,17 @@ void import_export_public_key( data_t *data, size_t exported_length = INVALID_EXPORT_LENGTH; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT, alg ); - 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 ) ); /* Export the public key */ ASSERT_ALLOC( exported, export_size ); @@ -1337,8 +1334,7 @@ void import_export_public_key( data_t *data, { psa_key_type_t public_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( type ); size_t bits; - TEST_ASSERT( psa_get_key_information( handle, NULL, &bits ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, NULL, &bits ) ); TEST_ASSERT( expected_public_key->len <= PSA_KEY_EXPORT_MAX_SIZE( public_type, bits ) ); ASSERT_COMPARE( expected_public_key->x, expected_public_key->len, @@ -1368,22 +1364,22 @@ void import_and_exercise_key( data_t *data, size_t got_bits; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, KEY_BITS_FROM_DATA( type, data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, usage, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); /* Import the key */ status = psa_import_key( handle, type, data->x, data->len ); - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); /* 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 == bits ); @@ -1410,22 +1406,22 @@ void key_policy( int usage_arg, int alg_arg ) memset( key, 0x2a, sizeof( key ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( sizeof( key ) ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( sizeof( key ) ), + &handle ) ); psa_key_policy_init( &policy_set ); 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_ASSERT( psa_set_key_policy( handle, &policy_set ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy_set ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key, sizeof( key ) ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key, sizeof( key ) ) ); - TEST_ASSERT( psa_get_key_policy( handle, &policy_get ) == PSA_SUCCESS ); + 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 ); @@ -1449,22 +1445,22 @@ void mac_key_policy( int policy_usage, psa_status_t status; unsigned char mac[PSA_MAC_MAX_SIZE]; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); status = psa_mac_sign_setup( &operation, handle, exercise_alg ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_SIGN ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); psa_mac_abort( &operation ); @@ -1473,7 +1469,7 @@ void mac_key_policy( int policy_usage, status = psa_mac_verify_setup( &operation, handle, exercise_alg ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_VERIFY ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1496,22 +1492,22 @@ void cipher_key_policy( int policy_usage, psa_cipher_operation_t operation; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); status = psa_cipher_encrypt_setup( &operation, handle, exercise_alg ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); psa_cipher_abort( &operation ); @@ -1519,7 +1515,7 @@ void cipher_key_policy( int policy_usage, status = psa_cipher_decrypt_setup( &operation, handle, exercise_alg ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_DECRYPT ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1551,17 +1547,17 @@ void aead_key_policy( int policy_usage, TEST_ASSERT( nonce_length <= sizeof( nonce ) ); TEST_ASSERT( tag_length <= sizeof( tag ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); status = psa_aead_encrypt( handle, exercise_alg, nonce, nonce_length, @@ -1571,7 +1567,7 @@ void aead_key_policy( int policy_usage, &output_length ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1609,21 +1605,21 @@ void asymmetric_encryption_key_policy( int policy_usage, unsigned char *buffer = NULL; size_t output_length; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); - TEST_ASSERT( psa_get_key_information( handle, - NULL, - &key_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, + NULL, + &key_bits ) ); buffer_length = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, exercise_alg ); ASSERT_ALLOC( buffer, buffer_length ); @@ -1635,7 +1631,7 @@ void asymmetric_encryption_key_policy( int policy_usage, &output_length ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_ENCRYPT ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1674,17 +1670,17 @@ void asymmetric_signature_key_policy( int policy_usage, unsigned char signature[PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE] = {0}; size_t signature_length; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); status = psa_asymmetric_sign( handle, exercise_alg, payload, payload_length, @@ -1692,7 +1688,7 @@ void asymmetric_signature_key_policy( int policy_usage, &signature_length ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_SIGN ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1724,17 +1720,17 @@ void derive_key_policy( int policy_usage, psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); status = psa_key_derivation( &generator, handle, exercise_alg, @@ -1743,7 +1739,7 @@ void derive_key_policy( int policy_usage, 1 ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_DERIVE ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1767,23 +1763,23 @@ void agreement_key_policy( int policy_usage, psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, key_data->len ) ); status = key_agreement_with_self( &generator, handle, exercise_alg ); if( policy_alg == exercise_alg && ( policy_usage & PSA_KEY_USAGE_DERIVE ) != 0 ) - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); else TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED ); @@ -1803,7 +1799,7 @@ void hash_setup( int alg_arg, psa_hash_operation_t operation; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); status = psa_hash_setup( &operation, alg ); psa_hash_abort( &operation ); @@ -1826,7 +1822,7 @@ void hash_bad_order( ) size_t hash_len; psa_hash_operation_t operation; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); /* psa_hash_update without calling psa_hash_setup beforehand */ memset( &operation, 0, sizeof( operation ) ); @@ -1864,22 +1860,22 @@ void hash_verify_bad_args( ) size_t expected_size = PSA_HASH_SIZE( alg ); psa_hash_operation_t operation; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); /* psa_hash_verify with a smaller hash than expected */ - TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); TEST_ASSERT( psa_hash_verify( &operation, hash, expected_size - 1 ) == PSA_ERROR_INVALID_SIGNATURE ); /* psa_hash_verify with a non-matching hash */ - TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); TEST_ASSERT( psa_hash_verify( &operation, hash + 1, expected_size ) == PSA_ERROR_INVALID_SIGNATURE ); /* psa_hash_verify with a hash longer than expected */ - TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); TEST_ASSERT( psa_hash_verify( &operation, hash, sizeof( hash ) ) == PSA_ERROR_INVALID_SIGNATURE ); @@ -1898,10 +1894,10 @@ void hash_finish_bad_args( ) psa_hash_operation_t operation; size_t hash_len; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); /* psa_hash_finish with a smaller hash buffer than expected */ - TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); TEST_ASSERT( psa_hash_finish( &operation, hash, expected_size - 1, &hash_len ) == PSA_ERROR_BUFFER_TOO_SMALL ); @@ -1925,18 +1921,18 @@ void mac_setup( int key_type_arg, psa_key_policy_t policy; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); status = psa_mac_sign_setup( &operation, handle, alg ); psa_mac_abort( &operation ); @@ -1972,25 +1968,25 @@ void mac_sign( int key_type_arg, TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE ); TEST_ASSERT( expected_mac->len <= mac_buffer_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); /* Calculate the MAC. */ - TEST_ASSERT( psa_mac_sign_setup( &operation, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_update( &operation, - input->x, input->len ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_sign_finish( &operation, - actual_mac, mac_buffer_size, - &mac_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_mac_sign_setup( &operation, + handle, alg ) ); + PSA_ASSERT( psa_mac_update( &operation, + input->x, input->len ) ); + PSA_ASSERT( psa_mac_sign_finish( &operation, + actual_mac, mac_buffer_size, + &mac_length ) ); /* Compare with the expected value. */ TEST_ASSERT( mac_length == expected_mac->len ); @@ -2028,25 +2024,25 @@ void mac_verify( int key_type_arg, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( input->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( expected_mac->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_mac_verify_setup( &operation, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_destroy_key( handle ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_update( &operation, - input->x, input->len ) == PSA_SUCCESS ); - TEST_ASSERT( psa_mac_verify_finish( &operation, - expected_mac->x, - expected_mac->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_mac_verify_setup( &operation, + handle, alg ) ); + PSA_ASSERT( psa_destroy_key( handle ) ); + PSA_ASSERT( psa_mac_update( &operation, + input->x, input->len ) ); + PSA_ASSERT( psa_mac_verify_finish( &operation, + expected_mac->x, + expected_mac->len ) ); exit: psa_destroy_key( handle ); @@ -2068,16 +2064,16 @@ void cipher_setup( int key_type_arg, psa_key_policy_t policy; psa_status_t status; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); status = psa_cipher_encrypt_setup( &operation, handle, alg ); psa_cipher_abort( &operation ); @@ -2119,30 +2115,30 @@ void cipher_encrypt( int alg_arg, int key_type_arg, iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ); memset( iv, 0x2a, iv_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_cipher_encrypt_setup( &operation, - handle, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_encrypt_setup( &operation, + handle, alg ) ); - TEST_ASSERT( psa_cipher_set_iv( &operation, - iv, iv_size ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_set_iv( &operation, + iv, iv_size ) ); output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) ); ASSERT_ALLOC( output, output_buffer_size ); - TEST_ASSERT( psa_cipher_update( &operation, - input->x, input->len, - output, output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation, + input->x, input->len, + output, output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; status = psa_cipher_finish( &operation, output + function_output_length, @@ -2153,7 +2149,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg, TEST_ASSERT( status == expected_status ); if( expected_status == PSA_SUCCESS ) { - TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation ) ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); } @@ -2194,43 +2190,43 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg, iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ); memset( iv, 0x2a, iv_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_cipher_encrypt_setup( &operation, - handle, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_encrypt_setup( &operation, + handle, alg ) ); - TEST_ASSERT( psa_cipher_set_iv( &operation, - iv, sizeof( iv ) ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_set_iv( &operation, + iv, sizeof( iv ) ) ); output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) ); ASSERT_ALLOC( output, output_buffer_size ); TEST_ASSERT( (unsigned int) first_part_size < input->len ); - TEST_ASSERT( psa_cipher_update( &operation, input->x, first_part_size, - output, output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size, + output, output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; - TEST_ASSERT( psa_cipher_update( &operation, - input->x + first_part_size, - input->len - first_part_size, - output, output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation, + input->x + first_part_size, + input->len - first_part_size, + output, output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; - TEST_ASSERT( psa_cipher_finish( &operation, - output + function_output_length, - output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_finish( &operation, + output + function_output_length, + output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; - TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation ) ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); @@ -2272,45 +2268,45 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg, iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ); memset( iv, 0x2a, iv_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_cipher_decrypt_setup( &operation, - handle, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_decrypt_setup( &operation, + handle, alg ) ); - TEST_ASSERT( psa_cipher_set_iv( &operation, - iv, sizeof( iv ) ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_set_iv( &operation, + iv, sizeof( iv ) ) ); output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) ); ASSERT_ALLOC( output, output_buffer_size ); TEST_ASSERT( (unsigned int) first_part_size < input->len ); - TEST_ASSERT( psa_cipher_update( &operation, - input->x, first_part_size, - output, output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation, + input->x, first_part_size, + output, output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; - TEST_ASSERT( psa_cipher_update( &operation, - input->x + first_part_size, - input->len - first_part_size, - output, output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation, + input->x + first_part_size, + input->len - first_part_size, + output, output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; - TEST_ASSERT( psa_cipher_finish( &operation, - output + function_output_length, - output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_finish( &operation, + output + function_output_length, + output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; - TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation ) ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); @@ -2352,31 +2348,31 @@ void cipher_decrypt( int alg_arg, int key_type_arg, iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ); memset( iv, 0x2a, iv_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_cipher_decrypt_setup( &operation, - handle, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_decrypt_setup( &operation, + handle, alg ) ); - TEST_ASSERT( psa_cipher_set_iv( &operation, - iv, iv_size ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_set_iv( &operation, + iv, iv_size ) ); output_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) ); ASSERT_ALLOC( output, output_buffer_size ); - TEST_ASSERT( psa_cipher_update( &operation, - input->x, input->len, - output, output_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation, + input->x, input->len, + output, output_buffer_size, + &function_output_length ) ); total_output_length += function_output_length; status = psa_cipher_finish( &operation, output + function_output_length, @@ -2387,7 +2383,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg, if( expected_status == PSA_SUCCESS ) { - TEST_ASSERT( psa_cipher_abort( &operation ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation ) ); ASSERT_COMPARE( expected_output->x, expected_output->len, output, total_output_length ); } @@ -2426,57 +2422,57 @@ void cipher_verify_output( int alg_arg, int key_type_arg, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( key->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( input->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_cipher_encrypt_setup( &operation1, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_decrypt_setup( &operation2, - handle, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_encrypt_setup( &operation1, + handle, alg ) ); + PSA_ASSERT( psa_cipher_decrypt_setup( &operation2, + handle, alg ) ); - TEST_ASSERT( psa_cipher_generate_iv( &operation1, - iv, iv_size, - &iv_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_generate_iv( &operation1, + iv, iv_size, + &iv_length ) ); output1_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) ); ASSERT_ALLOC( output1, output1_size ); - TEST_ASSERT( psa_cipher_update( &operation1, input->x, input->len, - output1, output1_size, - &output1_length ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_finish( &operation1, - output1 + output1_length, output1_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation1, input->x, input->len, + output1, output1_size, + &output1_length ) ); + PSA_ASSERT( psa_cipher_finish( &operation1, + output1 + output1_length, output1_size, + &function_output_length ) ); output1_length += function_output_length; - TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation1 ) ); output2_size = output1_length; ASSERT_ALLOC( output2, output2_size ); - TEST_ASSERT( psa_cipher_set_iv( &operation2, - iv, iv_length ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_update( &operation2, output1, output1_length, - output2, output2_size, - &output2_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_set_iv( &operation2, + iv, iv_length ) ); + PSA_ASSERT( psa_cipher_update( &operation2, output1, output1_length, + output2, output2_size, + &output2_length ) ); function_output_length = 0; - TEST_ASSERT( psa_cipher_finish( &operation2, - output2 + output2_length, - output2_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_finish( &operation2, + output2 + output2_length, + output2_size, + &function_output_length ) ); output2_length += function_output_length; - TEST_ASSERT( psa_cipher_abort( &operation2 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation2 ) ); ASSERT_COMPARE( input->x, input->len, output2, output2_length ); @@ -2517,76 +2513,76 @@ void cipher_verify_output_multipart( int alg_arg, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( key->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( input->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key->x, key->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key->x, key->len ) ); - TEST_ASSERT( psa_cipher_encrypt_setup( &operation1, - handle, alg ) == PSA_SUCCESS ); - TEST_ASSERT( psa_cipher_decrypt_setup( &operation2, - handle, alg ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_encrypt_setup( &operation1, + handle, alg ) ); + PSA_ASSERT( psa_cipher_decrypt_setup( &operation2, + handle, alg ) ); - TEST_ASSERT( psa_cipher_generate_iv( &operation1, - iv, iv_size, - &iv_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_generate_iv( &operation1, + iv, iv_size, + &iv_length ) ); output1_buffer_size = ( (size_t) input->len + PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) ); ASSERT_ALLOC( output1, output1_buffer_size ); TEST_ASSERT( (unsigned int) first_part_size < input->len ); - TEST_ASSERT( psa_cipher_update( &operation1, input->x, first_part_size, - output1, output1_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation1, input->x, first_part_size, + output1, output1_buffer_size, + &function_output_length ) ); output1_length += function_output_length; - TEST_ASSERT( psa_cipher_update( &operation1, - input->x + first_part_size, - input->len - first_part_size, - output1, output1_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation1, + input->x + first_part_size, + input->len - first_part_size, + output1, output1_buffer_size, + &function_output_length ) ); output1_length += function_output_length; - TEST_ASSERT( psa_cipher_finish( &operation1, - output1 + output1_length, - output1_buffer_size - output1_length, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_finish( &operation1, + output1 + output1_length, + output1_buffer_size - output1_length, + &function_output_length ) ); output1_length += function_output_length; - TEST_ASSERT( psa_cipher_abort( &operation1 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation1 ) ); output2_buffer_size = output1_length; ASSERT_ALLOC( output2, output2_buffer_size ); - TEST_ASSERT( psa_cipher_set_iv( &operation2, - iv, iv_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_set_iv( &operation2, + iv, iv_length ) ); - TEST_ASSERT( psa_cipher_update( &operation2, output1, first_part_size, - output2, output2_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation2, output1, first_part_size, + output2, output2_buffer_size, + &function_output_length ) ); output2_length += function_output_length; - TEST_ASSERT( psa_cipher_update( &operation2, - output1 + first_part_size, - output1_length - first_part_size, - output2, output2_buffer_size, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_update( &operation2, + output1 + first_part_size, + output1_length - first_part_size, + output2, output2_buffer_size, + &function_output_length ) ); output2_length += function_output_length; - TEST_ASSERT( psa_cipher_finish( &operation2, - output2 + output2_length, - output2_buffer_size - output2_length, - &function_output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_finish( &operation2, + output2 + output2_length, + output2_buffer_size - output2_length, + &function_output_length ) ); output2_length += function_output_length; - TEST_ASSERT( psa_cipher_abort( &operation2 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_cipher_abort( &operation2 ) ); ASSERT_COMPARE( input->x, input->len, output2, output2_length ); @@ -2630,18 +2626,18 @@ void aead_encrypt_decrypt( int key_type_arg, data_t *key_data, output_size = input_data->len + tag_length; ASSERT_ALLOC( output_data, output_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, key_data->len ) == PSA_SUCCESS ); + 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, @@ -2706,24 +2702,24 @@ void aead_encrypt( int key_type_arg, data_t *key_data, output_size = input_data->len + tag_length; ASSERT_ALLOC( output_data, output_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT , alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + 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 ) == PSA_SUCCESS ); + PSA_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 ) ); ASSERT_COMPARE( expected_result->x, expected_result->len, output_data, output_length ); @@ -2768,17 +2764,17 @@ void aead_decrypt( int key_type_arg, data_t *key_data, output_size = input_data->len + tag_length; ASSERT_ALLOC( output_data, output_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT , alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); TEST_ASSERT( psa_aead_decrypt( handle, alg, nonce->x, nonce->len, @@ -2835,21 +2831,21 @@ void sign_deterministic( int key_type_arg, data_t *key_data, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( input_data->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( output_data->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); - TEST_ASSERT( psa_get_key_information( handle, - NULL, - &key_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); + PSA_ASSERT( psa_get_key_information( handle, + NULL, + &key_bits ) ); /* Allocate a buffer which has the size advertized by the * library. */ @@ -2860,10 +2856,10 @@ void sign_deterministic( int key_type_arg, data_t *key_data, ASSERT_ALLOC( signature, signature_size ); /* Perform the signature. */ - TEST_ASSERT( psa_asymmetric_sign( handle, alg, - input_data->x, input_data->len, - signature, signature_size, - &signature_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_sign( handle, alg, + input_data->x, input_data->len, + signature, signature_size, + &signature_length ) ); /* Verify that the signature is what is expected. */ ASSERT_COMPARE( output_data->x, output_data->len, signature, signature_length ); @@ -2897,18 +2893,18 @@ void sign_fail( int key_type_arg, data_t *key_data, ASSERT_ALLOC( signature, signature_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); actual_status = psa_asymmetric_sign( handle, alg, input_data->x, input_data->len, @@ -2941,23 +2937,23 @@ void sign_verify( int key_type_arg, data_t *key_data, size_t signature_length = 0xdeadbeef; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); - TEST_ASSERT( psa_get_key_information( handle, - NULL, - &key_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); + PSA_ASSERT( psa_get_key_information( handle, + NULL, + &key_bits ) ); /* Allocate a buffer which has the size advertized by the * library. */ @@ -2968,19 +2964,19 @@ void sign_verify( int key_type_arg, data_t *key_data, ASSERT_ALLOC( signature, signature_size ); /* Perform the signature. */ - TEST_ASSERT( psa_asymmetric_sign( handle, alg, - input_data->x, input_data->len, - signature, signature_size, - &signature_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_sign( handle, alg, + input_data->x, input_data->len, + signature, signature_size, + &signature_length ) ); /* Check that the signature length looks sensible. */ TEST_ASSERT( signature_length <= signature_size ); TEST_ASSERT( signature_length > 0 ); /* Use the library to verify that the signature is correct. */ - TEST_ASSERT( psa_asymmetric_verify( - handle, alg, - input_data->x, input_data->len, - signature, signature_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_verify( + handle, alg, + input_data->x, input_data->len, + signature, signature_length ) ); if( input_data->len != 0 ) { @@ -3021,23 +3017,23 @@ void asymmetric_verify( int key_type_arg, data_t *key_data, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( hash_data->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( signature_data->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); - TEST_ASSERT( psa_asymmetric_verify( handle, alg, - hash_data->x, hash_data->len, - signature_data->x, - signature_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_verify( handle, alg, + hash_data->x, hash_data->len, + signature_data->x, + signature_data->len ) ); exit: psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); @@ -3064,18 +3060,18 @@ void asymmetric_verify_fail( int key_type_arg, data_t *key_data, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( hash_data->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( signature_data->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); actual_status = psa_asymmetric_verify( handle, alg, hash_data->x, hash_data->len, @@ -3111,24 +3107,23 @@ void asymmetric_encrypt( int key_type_arg, psa_status_t expected_status = expected_status_arg; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); - + PSA_ASSERT( psa_crypto_init( ) ); /* Import the key */ - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); /* Determine the maximum output length */ - TEST_ASSERT( psa_get_key_information( handle, - NULL, - &key_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, + NULL, + &key_bits ) ); output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg ); ASSERT_ALLOC( output, output_size ); @@ -3188,26 +3183,25 @@ void asymmetric_encrypt_decrypt( int key_type_arg, TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( key_data->len ) ); TEST_ASSERT( PSA_CRYPTO_TEST_SIZE_T_RANGE( input_data->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); - - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); /* Determine the maximum ciphertext length */ - TEST_ASSERT( psa_get_key_information( handle, - NULL, - &key_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( handle, + NULL, + &key_bits ) ); output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE( key_type, key_bits, alg ); ASSERT_ALLOC( output, output_size ); output2_size = input_data->len; @@ -3216,20 +3210,20 @@ void asymmetric_encrypt_decrypt( int key_type_arg, /* We test encryption by checking that encrypt-then-decrypt gives back * the original plaintext because of the non-optional random * part of encryption process which prevents using fixed vectors. */ - TEST_ASSERT( psa_asymmetric_encrypt( handle, alg, - input_data->x, input_data->len, - label->x, label->len, - output, output_size, - &output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_encrypt( handle, alg, + input_data->x, input_data->len, + label->x, label->len, + output, output_size, + &output_length ) ); /* We don't know what ciphertext length to expect, but check that * it looks sensible. */ TEST_ASSERT( output_length <= output_size ); - TEST_ASSERT( psa_asymmetric_decrypt( handle, alg, - output, output_length, - label->x, label->len, - output2, output2_size, - &output2_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_decrypt( handle, alg, + output, output_length, + label->x, label->len, + output2, output2_size, + &output2_length ) ); ASSERT_COMPARE( input_data->x, input_data->len, output2, output2_length ); @@ -3267,25 +3261,25 @@ void asymmetric_decrypt( int key_type_arg, output_size = key_data->len; ASSERT_ALLOC( output, output_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); - TEST_ASSERT( psa_asymmetric_decrypt( handle, alg, - input_data->x, input_data->len, - label->x, label->len, - output, - output_size, - &output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_decrypt( handle, alg, + input_data->x, input_data->len, + label->x, label->len, + output, + output_size, + &output_length ) ); ASSERT_COMPARE( expected_data->x, expected_data->len, output, output_length ); @@ -3296,12 +3290,12 @@ void asymmetric_decrypt( int key_type_arg, output_length = ~0; if( output_size != 0 ) memset( output, 0, output_size ); - TEST_ASSERT( psa_asymmetric_decrypt( handle, alg, - input_data->x, input_data->len, - NULL, label->len, - output, - output_size, - &output_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_asymmetric_decrypt( handle, alg, + input_data->x, input_data->len, + NULL, label->len, + output, + output_size, + &output_length ) ); ASSERT_COMPARE( expected_data->x, expected_data->len, output, output_length ); } @@ -3339,18 +3333,18 @@ void asymmetric_decrypt_fail( int key_type_arg, output_size = key_data->len; ASSERT_ALLOC( output, output_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - KEY_BITS_FROM_DATA( key_type, key_data ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + KEY_BITS_FROM_DATA( key_type, key_data ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); actual_status = psa_asymmetric_decrypt( handle, alg, input_data->x, input_data->len, @@ -3400,17 +3394,17 @@ void derive_setup( int key_type_arg, psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, PSA_BYTES_TO_BITS( key_data->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data->x, + key_data->len ) ); TEST_ASSERT( psa_key_derivation( &generator, handle, alg, salt->x, salt->len, @@ -3438,24 +3432,24 @@ void test_derive_invalid_generator_state( ) 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( key_type, - PSA_BYTES_TO_BITS( sizeof( key_data ) ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( key_type, + PSA_BYTES_TO_BITS( sizeof( key_data ) ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, key_type, - key_data, - sizeof( key_data ) ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, key_type, + key_data, + sizeof( key_data ) ) ); /* valid key derivation */ - TEST_ASSERT( psa_key_derivation( &generator, handle, alg, - NULL, 0, - NULL, 0, - capacity ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, handle, alg, + NULL, 0, + NULL, 0, + capacity ) ); /* state of generator shouldn't allow additional generation */ TEST_ASSERT( psa_key_derivation( &generator, handle, alg, @@ -3463,13 +3457,12 @@ void test_derive_invalid_generator_state( ) NULL, 0, capacity ) == PSA_ERROR_BAD_STATE ); - TEST_ASSERT( psa_generator_read( &generator, buffer, capacity ) - == PSA_SUCCESS ); + PSA_ASSERT( psa_generator_read( &generator, buffer, capacity ) + ); TEST_ASSERT( psa_generator_read( &generator, buffer, capacity ) == PSA_ERROR_INSUFFICIENT_CAPACITY ); - exit: psa_generator_abort( &generator ); psa_destroy_key( handle ); @@ -3477,7 +3470,6 @@ exit: } /* END_CASE */ - /* BEGIN_CASE */ void test_derive_invalid_generator_tests( ) { @@ -3492,7 +3484,7 @@ void test_derive_invalid_generator_tests( ) TEST_ASSERT( psa_get_generator_capacity( &generator, &capacity ) == PSA_SUCCESS ); // should be PSA_ERROR_BAD_STATE:#183 - TEST_ASSERT( psa_generator_abort( &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_generator_abort( &generator ) ); TEST_ASSERT( psa_generator_read( &generator, output_buffer, buffer_size ) == PSA_ERROR_INSUFFICIENT_CAPACITY ); // should be PSA_ERROR_BAD_STATE:#183 @@ -3538,27 +3530,26 @@ void derive_output( int alg_arg, expected_outputs[i] = NULL; } ASSERT_ALLOC( output_buffer, output_buffer_size ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, - PSA_BYTES_TO_BITS( key_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, + PSA_BYTES_TO_BITS( key_data->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_DERIVE, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_DERIVE, + key_data->x, + key_data->len ) ); /* Extraction phase. */ - TEST_ASSERT( psa_key_derivation( &generator, handle, alg, - salt->x, salt->len, - label->x, label->len, - requested_capacity ) == PSA_SUCCESS ); - TEST_ASSERT( psa_get_generator_capacity( &generator, - ¤t_capacity ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, handle, alg, + salt->x, salt->len, + label->x, label->len, + requested_capacity ) ); + PSA_ASSERT( psa_get_generator_capacity( &generator, + ¤t_capacity ) ); TEST_ASSERT( current_capacity == requested_capacity ); expected_capacity = requested_capacity; @@ -3584,18 +3575,17 @@ void derive_output( int alg_arg, continue; } /* Success. Check the read data. */ - TEST_ASSERT( status == PSA_SUCCESS ); + PSA_ASSERT( status ); if( output_sizes[i] != 0 ) TEST_ASSERT( memcmp( output_buffer, expected_outputs[i], output_sizes[i] ) == 0 ); /* Check the generator status. */ expected_capacity -= output_sizes[i]; - TEST_ASSERT( psa_get_generator_capacity( &generator, - ¤t_capacity ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_get_generator_capacity( &generator, + ¤t_capacity ) ); TEST_ASSERT( expected_capacity == current_capacity ); } - TEST_ASSERT( psa_generator_abort( &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_generator_abort( &generator ) ); exit: mbedtls_free( output_buffer ); @@ -3621,27 +3611,26 @@ void derive_full( int alg_arg, size_t current_capacity; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, - PSA_BYTES_TO_BITS( key_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, + PSA_BYTES_TO_BITS( key_data->len ), + &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); - TEST_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_DERIVE, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_DERIVE, + key_data->x, + key_data->len ) ); /* Extraction phase. */ - TEST_ASSERT( psa_key_derivation( &generator, handle, alg, - salt->x, salt->len, - label->x, label->len, - requested_capacity ) == PSA_SUCCESS ); - TEST_ASSERT( psa_get_generator_capacity( &generator, - ¤t_capacity ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, handle, alg, + salt->x, salt->len, + label->x, label->len, + requested_capacity ) ); + PSA_ASSERT( psa_get_generator_capacity( &generator, + ¤t_capacity ) ); TEST_ASSERT( current_capacity == expected_capacity ); /* Expansion phase. */ @@ -3650,13 +3639,12 @@ void derive_full( int alg_arg, size_t read_size = sizeof( output_buffer ); if( read_size > current_capacity ) read_size = current_capacity; - TEST_ASSERT( psa_generator_read( &generator, - output_buffer, - read_size ) == PSA_SUCCESS ); + PSA_ASSERT( psa_generator_read( &generator, + output_buffer, + read_size ) ); expected_capacity -= read_size; - TEST_ASSERT( psa_get_generator_capacity( &generator, - ¤t_capacity ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_get_generator_capacity( &generator, + ¤t_capacity ) ); TEST_ASSERT( current_capacity == expected_capacity ); } @@ -3665,7 +3653,7 @@ void derive_full( int alg_arg, output_buffer, 1 ) == PSA_ERROR_INSUFFICIENT_CAPACITY ); - TEST_ASSERT( psa_generator_abort( &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_generator_abort( &generator ) ); exit: psa_generator_abort( &generator ); @@ -3697,36 +3685,36 @@ void derive_key_exercise( int alg_arg, psa_key_type_t got_type; size_t got_bits; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, - PSA_BYTES_TO_BITS( key_data->len ), - &base_handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, + PSA_BYTES_TO_BITS( key_data->len ), + &base_handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( base_handle, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( base_handle, PSA_KEY_TYPE_DERIVE, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( base_handle, &policy ) ); + PSA_ASSERT( psa_import_key( base_handle, PSA_KEY_TYPE_DERIVE, + key_data->x, + key_data->len ) ); /* Derive a key. */ - TEST_ASSERT( psa_key_derivation( &generator, base_handle, alg, - salt->x, salt->len, - label->x, label->len, - capacity ) == PSA_SUCCESS ); - TEST_ASSERT( psa_allocate_key( derived_type, derived_bits, - &derived_handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, base_handle, alg, + salt->x, salt->len, + label->x, label->len, + capacity ) ); + PSA_ASSERT( psa_allocate_key( derived_type, derived_bits, + &derived_handle ) ); psa_key_policy_set_usage( &policy, derived_usage, derived_alg ); - TEST_ASSERT( psa_set_key_policy( derived_handle, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_import_key( derived_handle, - derived_type, - derived_bits, - &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( derived_handle, &policy ) ); + PSA_ASSERT( psa_generator_import_key( derived_handle, + derived_type, + derived_bits, + &generator ) ); /* Test the key information */ - TEST_ASSERT( psa_get_key_information( derived_handle, - &got_type, - &got_bits ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_key_information( derived_handle, + &got_type, + &got_bits ) ); TEST_ASSERT( got_type == derived_type ); TEST_ASSERT( got_bits == derived_bits ); @@ -3765,57 +3753,57 @@ void derive_key_export( int alg_arg, ASSERT_ALLOC( output_buffer, capacity ); ASSERT_ALLOC( export_buffer, capacity ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, - PSA_BYTES_TO_BITS( key_data->len ), - &base_handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, + PSA_BYTES_TO_BITS( key_data->len ), + &base_handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( base_handle, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( base_handle, PSA_KEY_TYPE_DERIVE, - key_data->x, - key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( base_handle, &policy ) ); + PSA_ASSERT( psa_import_key( base_handle, PSA_KEY_TYPE_DERIVE, + key_data->x, + key_data->len ) ); /* Derive some material and output it. */ - TEST_ASSERT( psa_key_derivation( &generator, base_handle, alg, - salt->x, salt->len, - label->x, label->len, - capacity ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_read( &generator, - output_buffer, - capacity ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_abort( &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, base_handle, alg, + salt->x, salt->len, + label->x, label->len, + capacity ) ); + PSA_ASSERT( psa_generator_read( &generator, + output_buffer, + capacity ) ); + PSA_ASSERT( psa_generator_abort( &generator ) ); /* Derive the same output again, but this time store it in key objects. */ - TEST_ASSERT( psa_key_derivation( &generator, base_handle, alg, - salt->x, salt->len, - label->x, label->len, - capacity ) == PSA_SUCCESS ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, derived_bits, - &derived_handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, base_handle, alg, + salt->x, salt->len, + label->x, label->len, + capacity ) ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, derived_bits, + &derived_handle ) ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT, 0 ); - TEST_ASSERT( psa_set_key_policy( derived_handle, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_import_key( derived_handle, - PSA_KEY_TYPE_RAW_DATA, - derived_bits, - &generator ) == PSA_SUCCESS ); - TEST_ASSERT( psa_export_key( derived_handle, - export_buffer, bytes1, - &length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( derived_handle, &policy ) ); + PSA_ASSERT( psa_generator_import_key( derived_handle, + PSA_KEY_TYPE_RAW_DATA, + derived_bits, + &generator ) ); + PSA_ASSERT( psa_export_key( derived_handle, + export_buffer, bytes1, + &length ) ); TEST_ASSERT( length == bytes1 ); - TEST_ASSERT( psa_destroy_key( derived_handle ) == PSA_SUCCESS ); - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, - PSA_BYTES_TO_BITS( bytes2 ), - &derived_handle ) == PSA_SUCCESS ); - TEST_ASSERT( psa_set_key_policy( derived_handle, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_import_key( derived_handle, - PSA_KEY_TYPE_RAW_DATA, - PSA_BYTES_TO_BITS( bytes2 ), - &generator ) == PSA_SUCCESS ); - TEST_ASSERT( psa_export_key( derived_handle, - export_buffer + bytes1, bytes2, - &length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_destroy_key( derived_handle ) ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_RAW_DATA, + PSA_BYTES_TO_BITS( bytes2 ), + &derived_handle ) ); + PSA_ASSERT( psa_set_key_policy( derived_handle, &policy ) ); + PSA_ASSERT( psa_generator_import_key( derived_handle, + PSA_KEY_TYPE_RAW_DATA, + PSA_BYTES_TO_BITS( bytes2 ), + &generator ) ); + PSA_ASSERT( psa_export_key( derived_handle, + export_buffer + bytes1, bytes2, + &length ) ); TEST_ASSERT( length == bytes2 ); /* Compare the outputs from the two runs. */ @@ -3843,18 +3831,18 @@ void key_agreement_setup( int alg_arg, psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( our_key_type, - KEY_BITS_FROM_DATA( our_key_type, - our_key_data ), - &our_key ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( our_key_type, + KEY_BITS_FROM_DATA( our_key_type, + our_key_data ), + &our_key ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( our_key, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( our_key, our_key_type, - our_key_data->x, - our_key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( our_key, &policy ) ); + PSA_ASSERT( psa_import_key( our_key, our_key_type, + our_key_data->x, + our_key_data->len ) ); TEST_ASSERT( psa_key_agreement( &generator, our_key, @@ -3882,40 +3870,38 @@ void key_agreement_capacity( int alg_arg, size_t actual_capacity; unsigned char output[16]; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( our_key_type, - KEY_BITS_FROM_DATA( our_key_type, - our_key_data ), - &our_key ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( our_key_type, + KEY_BITS_FROM_DATA( our_key_type, + our_key_data ), + &our_key ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( our_key, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( our_key, our_key_type, - our_key_data->x, - our_key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( our_key, &policy ) ); + PSA_ASSERT( psa_import_key( our_key, our_key_type, + 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 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_agreement( &generator, + our_key, + peer_key_data->x, peer_key_data->len, + alg ) ); /* Test the advertized capacity. */ - TEST_ASSERT( psa_get_generator_capacity( - &generator, &actual_capacity ) == PSA_SUCCESS ); + PSA_ASSERT( psa_get_generator_capacity( + &generator, &actual_capacity ) ); TEST_ASSERT( actual_capacity == (size_t) expected_capacity_arg ); /* Test the actual capacity by reading the output. */ while( actual_capacity > sizeof( output ) ) { - TEST_ASSERT( psa_generator_read( &generator, - output, sizeof( output ) ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_generator_read( &generator, + output, sizeof( output ) ) ); actual_capacity -= sizeof( output ); } - TEST_ASSERT( psa_generator_read( &generator, - output, actual_capacity ) == - PSA_SUCCESS ); + PSA_ASSERT( psa_generator_read( &generator, + output, actual_capacity ) ); TEST_ASSERT( psa_generator_read( &generator, output, 1 ) == PSA_ERROR_INSUFFICIENT_CAPACITY ); @@ -3942,36 +3928,36 @@ void key_agreement_output( int alg_arg, ASSERT_ALLOC( actual_output, MAX( expected_output1->len, expected_output2->len ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( our_key_type, - KEY_BITS_FROM_DATA( our_key_type, - our_key_data ), - &our_key ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( our_key_type, + KEY_BITS_FROM_DATA( our_key_type, + our_key_data ), + &our_key ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg ); - TEST_ASSERT( psa_set_key_policy( our_key, &policy ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( our_key, our_key_type, - our_key_data->x, - our_key_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( our_key, &policy ) ); + PSA_ASSERT( psa_import_key( our_key, our_key_type, + 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 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_agreement( &generator, + our_key, + peer_key_data->x, peer_key_data->len, + alg ) ); - TEST_ASSERT( + PSA_ASSERT( psa_generator_read( &generator, actual_output, - expected_output1->len ) == PSA_SUCCESS ); + expected_output1->len ) ); TEST_ASSERT( memcmp( actual_output, expected_output1->x, expected_output1->len ) == 0 ); if( expected_output2->len != 0 ) { - TEST_ASSERT( + PSA_ASSERT( psa_generator_read( &generator, actual_output, - expected_output2->len ) == PSA_SUCCESS ); + expected_output2->len ) ); TEST_ASSERT( memcmp( actual_output, expected_output2->x, expected_output2->len ) == 0 ); } @@ -3998,7 +3984,7 @@ void generate_random( int bytes_arg ) ASSERT_ALLOC( changed, bytes ); memcpy( output + bytes, trail, sizeof( trail ) ); - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); /* Run several times, to ensure that every output byte will be * nonzero at least once with overwhelming probability @@ -4007,7 +3993,7 @@ void generate_random( int bytes_arg ) { if( bytes != 0 ) memset( output, 0, bytes ); - TEST_ASSERT( psa_generate_random( output, bytes ) == PSA_SUCCESS ); + 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 ); @@ -4053,12 +4039,12 @@ void generate_key( int type_arg, expected_status == PSA_SUCCESS ? PSA_SUCCESS : PSA_ERROR_EMPTY_SLOT; psa_key_policy_t policy; - TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init( ) ); - TEST_ASSERT( psa_allocate_key( type, bits, &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( type, bits, &handle ) ); psa_key_policy_init( &policy ); psa_key_policy_set_usage( &policy, usage, alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy ) ); /* Generate a key */ TEST_ASSERT( psa_generate_key( handle, type, bits, @@ -4110,50 +4096,50 @@ void persistent_key_load_key_from_storage( data_t *data, int type_arg, ASSERT_ALLOC( first_export, export_size ); ASSERT_ALLOC( second_export, export_size ); - TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init() ); - TEST_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, 1, - type, bits, - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, 1, + type, bits, + &handle ) ); psa_key_policy_init( &policy_set ); psa_key_policy_set_usage( &policy_set, policy_usage, policy_alg ); - TEST_ASSERT( psa_set_key_policy( handle, &policy_set ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( handle, &policy_set ) ); switch( generation_method ) { case IMPORT_KEY: /* 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 ) ); break; case GENERATE_KEY: /* Generate a key */ - TEST_ASSERT( psa_generate_key( handle, type, bits, - NULL, 0 ) == PSA_SUCCESS ); + PSA_ASSERT( psa_generate_key( handle, type, bits, + NULL, 0 ) ); break; case DERIVE_KEY: /* Create base key */ - TEST_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, - PSA_BYTES_TO_BITS( data->len ), - &base_key ) == PSA_SUCCESS ); + PSA_ASSERT( psa_allocate_key( PSA_KEY_TYPE_DERIVE, + PSA_BYTES_TO_BITS( data->len ), + &base_key ) ); psa_key_policy_init( &base_policy_set ); psa_key_policy_set_usage( &base_policy_set, PSA_KEY_USAGE_DERIVE, base_policy_alg ); - TEST_ASSERT( psa_set_key_policy( - base_key, &base_policy_set ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( base_key, PSA_KEY_TYPE_DERIVE, - data->x, data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_set_key_policy( + base_key, &base_policy_set ) ); + PSA_ASSERT( psa_import_key( base_key, PSA_KEY_TYPE_DERIVE, + data->x, data->len ) ); /* Derive a key. */ - TEST_ASSERT( psa_key_derivation( &generator, base_key, - base_policy_alg, - NULL, 0, NULL, 0, - export_size ) == PSA_SUCCESS ); - TEST_ASSERT( psa_generator_import_key( - handle, PSA_KEY_TYPE_RAW_DATA, - bits, &generator ) == PSA_SUCCESS ); + PSA_ASSERT( psa_key_derivation( &generator, base_key, + base_policy_alg, + NULL, 0, NULL, 0, + export_size ) ); + PSA_ASSERT( psa_generator_import_key( + handle, PSA_KEY_TYPE_RAW_DATA, + bits, &generator ) ); break; } @@ -4163,17 +4149,17 @@ void persistent_key_load_key_from_storage( data_t *data, int type_arg, /* Shutdown and restart */ mbedtls_psa_crypto_free(); - TEST_ASSERT( psa_crypto_init() == PSA_SUCCESS ); + PSA_ASSERT( psa_crypto_init() ); /* Check key slot still contains key data */ - TEST_ASSERT( psa_open_key( PSA_KEY_LIFETIME_PERSISTENT, 1, - &handle ) == PSA_SUCCESS ); - TEST_ASSERT( psa_get_key_information( - handle, &type_get, &bits_get ) == PSA_SUCCESS ); + PSA_ASSERT( psa_open_key( PSA_KEY_LIFETIME_PERSISTENT, 1, + &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_ASSERT( psa_get_key_policy( handle, &policy_get ) == PSA_SUCCESS ); + 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( diff --git a/tests/suites/test_suite_psa_crypto_entropy.function b/tests/suites/test_suite_psa_crypto_entropy.function index 46c77e97c..117184df2 100644 --- a/tests/suites/test_suite_psa_crypto_entropy.function +++ b/tests/suites/test_suite_psa_crypto_entropy.function @@ -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 ) ); diff --git a/tests/suites/test_suite_psa_crypto_hash.function b/tests/suites/test_suite_psa_crypto_hash.function index bed80e262..5931a2338 100644 --- a/tests/suites/test_suite_psa_crypto_hash.function +++ b/tests/suites/test_suite_psa_crypto_hash.function @@ -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, - actual_hash, sizeof( actual_hash ), - &actual_hash_length ) == PSA_SUCCESS ); + 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 ) ); 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, - input->x, - input->len ) == PSA_SUCCESS ); - TEST_ASSERT( psa_hash_verify( &operation, - expected_hash->x, - expected_hash->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + PSA_ASSERT( psa_hash_update( &operation, + input->x, + input->len ) ); + PSA_ASSERT( psa_hash_verify( &operation, + expected_hash->x, + 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, - actual_hash, sizeof( actual_hash ), - &actual_hash_length ) == PSA_SUCCESS ); + PSA_ASSERT( psa_hash_finish( &operation, + actual_hash, sizeof( actual_hash ), + &actual_hash_length ) ); ASSERT_COMPARE( expected_hash->x, expected_hash->len, actual_hash, actual_hash_length ); diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index 132fe82f8..f4da989db 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -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 ); diff --git a/tests/suites/test_suite_psa_crypto_persistent_key.function b/tests/suites/test_suite_psa_crypto_persistent_key.function index aa8fddd3a..bf7537641 100644 --- a/tests/suites/test_suite_psa_crypto_persistent_key.function +++ b/tests/suites/test_suite_psa_crypto_persistent_key.function @@ -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_KEY_TYPE_RAW_DATA, - PSA_BYTES_TO_BITS( data_length ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, + PSA_KEY_TYPE_RAW_DATA, + PSA_BYTES_TO_BITS( data_length ), + &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, - first_type, - PSA_BYTES_TO_BITS( first_data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, + first_type, + PSA_BYTES_TO_BITS( first_data->len ), + &handle ) ); if( should_store == 1 ) { - TEST_ASSERT( psa_import_key( - handle, first_type, - first_data->x, first_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_import_key( + handle, first_type, + 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, - second_type, - PSA_BYTES_TO_BITS( second_data->len ), - &handle ) == PSA_SUCCESS ); - TEST_ASSERT( psa_import_key( - handle, second_type, - second_data->x, second_data->len ) == PSA_SUCCESS ); + PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, + second_type, + PSA_BYTES_TO_BITS( second_data->len ), + &handle ) ); + PSA_ASSERT( psa_import_key( + handle, second_type, + 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, - type, - PSA_BYTES_TO_BITS( data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, + type, + 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 ); @@ -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, - type, - PSA_BYTES_TO_BITS( data->len ), - &handle ) == PSA_SUCCESS ); + PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id, + type, + PSA_BYTES_TO_BITS( data->len ), + &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: diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 407d24b1c..4584ceb94 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -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] ); diff --git a/tests/suites/test_suite_psa_crypto_storage_file.function b/tests/suites/test_suite_psa_crypto_storage_file.function index e753d7862..dabba2096 100644 --- a/tests/suites/test_suite_psa_crypto_storage_file.function +++ b/tests/suites/test_suite_psa_crypto_storage_file.function @@ -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 )