@@ -219,9 +219,14 @@ int exercise_mac_setup( psa_key_type_t key_type,
219
219
PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
220
220
221
221
*status = psa_mac_sign_setup( operation, handle, alg );
222
- if( *status == PSA_SUCCESS )
222
+ /* Whether setup succeeded or failed, abort must succeed. */
223
+ PSA_ASSERT( psa_mac_abort( operation ) );
224
+ /* If setup failed, reproduce the failure, so that the caller can
225
+ * test the resulting state of the operation object. */
226
+ if( *status != PSA_SUCCESS )
223
227
{
224
- PSA_ASSERT( psa_mac_abort( operation ) );
228
+ TEST_EQUAL( psa_mac_sign_setup( operation, handle, alg ),
229
+ *status );
225
230
}
226
231
227
232
psa_destroy_key( handle );
@@ -248,9 +253,14 @@ int exercise_cipher_setup( psa_key_type_t key_type,
248
253
PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
249
254
250
255
*status = psa_cipher_encrypt_setup( operation, handle, alg );
251
- if( *status == PSA_SUCCESS )
256
+ /* Whether setup succeeded or failed, abort must succeed. */
257
+ PSA_ASSERT( psa_cipher_abort( operation ) );
258
+ /* If setup failed, reproduce the failure, so that the caller can
259
+ * test the resulting state of the operation object. */
260
+ if( *status != PSA_SUCCESS )
252
261
{
253
- PSA_ASSERT( psa_cipher_abort( operation ) );
262
+ TEST_EQUAL( psa_cipher_encrypt_setup( operation, handle, alg ),
263
+ *status );
254
264
}
255
265
256
266
psa_destroy_key( handle );
@@ -2118,8 +2128,14 @@ void hash_setup( int alg_arg,
2118
2128
status = psa_hash_setup( &operation, alg );
2119
2129
TEST_EQUAL( status, expected_status );
2120
2130
2121
- if( status == PSA_SUCCESS )
2122
- PSA_ASSERT( psa_hash_abort( &operation ) );
2131
+ /* Whether setup succeeded or failed, abort must succeed. */
2132
+ PSA_ASSERT( psa_hash_abort( &operation ) );
2133
+
2134
+ /* If setup failed, reproduce the failure, so as to
2135
+ * test the resulting state of the operation object. */
2136
+ if( status != PSA_SUCCESS )
2137
+ TEST_EQUAL( psa_hash_setup( &operation, alg ), status );
2138
+
2123
2139
/* Now the operation object should be reusable. */
2124
2140
#if defined(KNOWN_SUPPORTED_HASH_ALG)
2125
2141
PSA_ASSERT( psa_hash_setup( &operation, KNOWN_SUPPORTED_HASH_ALG ) );
0 commit comments