mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Change to use test-hook-based approach
Since we are applying hooks transparently to all tests, we cannot setup and teardown test hooks in the tests. Instead we must do this in the test wrappers which are used to pre-poison and unpoison memory. Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
@ -2,6 +2,26 @@
|
||||
|
||||
#include "test/memory.h"
|
||||
|
||||
#include "psa_crypto_invasive.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
|
||||
static void setup_test_hooks(void)
|
||||
{
|
||||
psa_input_pre_copy_hook = mbedtls_test_memory_unpoison;
|
||||
psa_input_post_copy_hook = mbedtls_test_memory_poison;
|
||||
psa_output_pre_copy_hook = mbedtls_test_memory_unpoison;
|
||||
psa_output_post_copy_hook = mbedtls_test_memory_poison;
|
||||
}
|
||||
|
||||
static void teardown_test_hooks(void)
|
||||
{
|
||||
psa_input_pre_copy_hook = NULL;
|
||||
psa_input_post_copy_hook = NULL;
|
||||
psa_output_pre_copy_hook = NULL;
|
||||
psa_output_post_copy_hook = NULL;
|
||||
}
|
||||
|
||||
psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input,
|
||||
@ -10,6 +30,7 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
size_t output_size,
|
||||
size_t *output_length)
|
||||
{
|
||||
setup_test_hooks();
|
||||
MBEDTLS_TEST_MEMORY_POISON(input, input_length);
|
||||
MBEDTLS_TEST_MEMORY_POISON(output, output_size);
|
||||
psa_status_t status = psa_cipher_encrypt(key,
|
||||
@ -21,7 +42,10 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
output_length);
|
||||
MBEDTLS_TEST_MEMORY_UNPOISON(input, input_length);
|
||||
MBEDTLS_TEST_MEMORY_UNPOISON(output, output_size);
|
||||
teardown_test_hooks();
|
||||
return status;
|
||||
}
|
||||
|
||||
#define psa_cipher_encrypt(...) wrap_psa_cipher_encrypt(__VA_ARGS__)
|
||||
|
||||
#endif /* MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
|
Reference in New Issue
Block a user