diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 56f4d1d5b3..5105ef5673 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -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.