mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 12:55:34 +00:00
Add negative tests for psa_abort in hash functions
Various functions for PSA hash operations call abort on failure; test that this is done. The PSA spec does not require this behaviour, but it makes our implementation more robust in case the user does not abort the operation as required by the PSA spec. Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
c88b0a57da
commit
ff8d52b398
|
@ -1606,15 +1606,28 @@ void hash_bad_order( )
|
|||
|
||||
/* Call setup twice in a row. */
|
||||
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
TEST_EQUAL( psa_hash_setup( &operation, alg ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_hash_abort( &operation ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
|
||||
/* Call update without calling setup beforehand. */
|
||||
TEST_EQUAL( psa_hash_update( &operation, input, sizeof( input ) ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
PSA_ASSERT( psa_hash_abort( &operation ) );
|
||||
|
||||
/* Check that update calls abort on error. */
|
||||
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
||||
operation.ctx.mbedtls_ctx.alg = PSA_ALG_XTS;
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
TEST_EQUAL( psa_hash_update( &operation, input, sizeof( input ) ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_hash_abort( &operation ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
|
||||
/* Call update after finish. */
|
||||
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
||||
PSA_ASSERT( psa_hash_finish( &operation,
|
||||
|
@ -1640,11 +1653,14 @@ void hash_bad_order( )
|
|||
|
||||
/* Call verify twice in a row. */
|
||||
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
PSA_ASSERT( psa_hash_verify( &operation,
|
||||
valid_hash, sizeof( valid_hash ) ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
TEST_EQUAL( psa_hash_verify( &operation,
|
||||
valid_hash, sizeof( valid_hash ) ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_hash_abort( &operation ) );
|
||||
|
||||
/* Call finish without calling setup beforehand. */
|
||||
|
@ -1693,8 +1709,12 @@ void hash_verify_bad_args( )
|
|||
|
||||
/* psa_hash_verify with a smaller hash than expected */
|
||||
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
TEST_EQUAL( psa_hash_verify( &operation, hash, expected_size - 1 ),
|
||||
PSA_ERROR_INVALID_SIGNATURE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_hash_abort( &operation ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
|
||||
/* psa_hash_verify with a non-matching hash */
|
||||
PSA_ASSERT( psa_hash_setup( &operation, alg ) );
|
||||
|
@ -1937,9 +1957,12 @@ void mac_bad_order( )
|
|||
|
||||
/* Call setup twice in a row. */
|
||||
PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
TEST_EQUAL( psa_mac_sign_setup( &operation, key, alg ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_mac_abort( &operation ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
|
||||
/* Call update after sign finish. */
|
||||
PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) );
|
||||
|
@ -2305,15 +2328,21 @@ void cipher_bad_order( )
|
|||
|
||||
/* Call encrypt setup twice in a row. */
|
||||
PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) );
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
TEST_EQUAL( psa_cipher_encrypt_setup( &operation, key, alg ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
|
||||
/* Call decrypt setup twice in a row. */
|
||||
PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) );
|
||||
ASSERT_OPERATION_IS_ACTIVE( operation );
|
||||
TEST_EQUAL( psa_cipher_decrypt_setup( &operation, key, alg ),
|
||||
PSA_ERROR_BAD_STATE );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
PSA_ASSERT( psa_cipher_abort( &operation ) );
|
||||
ASSERT_OPERATION_IS_INACTIVE( operation );
|
||||
|
||||
/* Generate an IV without calling setup beforehand. */
|
||||
TEST_EQUAL( psa_cipher_generate_iv( &operation,
|
||||
|
|
Loading…
Reference in a new issue