Fix driver_wrappers test

These were assuming that psa_crypto_init() doesn't call hashes, which is
not always correct.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2023-02-08 13:05:59 +01:00
parent 5cd4b6403b
commit 2334d3a9b1

View File

@ -2241,12 +2241,14 @@ void hash_compute(int alg_arg,
unsigned char *output = NULL;
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
PSA_ASSERT(psa_crypto_init());
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
TEST_EQUAL(psa_hash_compute(alg, input->x, input->len,
output, PSA_HASH_LENGTH(alg),
&output_length), expected_status);
@ -2277,12 +2279,14 @@ void hash_multipart_setup(int alg_arg,
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
PSA_ASSERT(psa_crypto_init());
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
mbedtls_test_driver_hash_hooks.forced_status = forced_status;
TEST_EQUAL(psa_hash_setup(&operation, alg), expected_status);
TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 1);
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
@ -2322,10 +2326,12 @@ void hash_multipart_update(int alg_arg,
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
PSA_ASSERT(psa_crypto_init());
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
/*
* Update inactive operation, the driver shouldn't be called.
@ -2377,10 +2383,11 @@ void hash_multipart_finish(int alg_arg,
psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
PSA_ASSERT(psa_crypto_init());
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
PSA_ASSERT(psa_crypto_init());
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
/*
* Finish inactive operation, the driver shouldn't be called.
@ -2431,10 +2438,11 @@ void hash_clone(int alg_arg,
psa_hash_operation_t target_operation = PSA_HASH_OPERATION_INIT;
size_t output_length;
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
PSA_ASSERT(psa_crypto_init());
ASSERT_ALLOC(output, PSA_HASH_LENGTH(alg));
PSA_ASSERT(psa_crypto_init());
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
/*
* Clone inactive operation, the driver shouldn't be called.