mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-14 07:20:52 +00:00
Move test hook setup functions into a C file
Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
parent
36df4b24d4
commit
a7cde5d296
@ -9,29 +9,28 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef PSA_MEMORY_POISONING_WRAPPERS_H
|
||||
#define PSA_MEMORY_POISONING_WRAPPERS_H
|
||||
|
||||
#include "psa/crypto.h"
|
||||
|
||||
#include "test/memory.h"
|
||||
|
||||
#include "psa_crypto_invasive.h"
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
|
||||
#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
/**
|
||||
* \brief Setup the memory poisoning test hooks used by
|
||||
* psa_crypto_copy_input() and psa_crypto_copy_output() for
|
||||
* memory poisoning.
|
||||
*/
|
||||
void mbedtls_poison_test_hooks_setup(void);
|
||||
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* \brief Teardown the memory poisoning test hooks used by
|
||||
* psa_crypto_copy_input() and psa_crypto_copy_output() for
|
||||
* memory poisoning.
|
||||
*/
|
||||
void mbedtls_poison_test_hooks_teardown(void);
|
||||
|
||||
psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
@ -39,24 +38,10 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
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,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length);
|
||||
MBEDTLS_TEST_MEMORY_UNPOISON(input, input_length);
|
||||
MBEDTLS_TEST_MEMORY_UNPOISON(output, output_size);
|
||||
teardown_test_hooks();
|
||||
return status;
|
||||
}
|
||||
size_t *output_length);
|
||||
|
||||
#define psa_cipher_encrypt(...) wrap_psa_cipher_encrypt(__VA_ARGS__)
|
||||
|
||||
#endif /* MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
|
||||
#endif /* PSA_MEMORY_POISONING_WRAPPERS_H */
|
53
tests/src/psa_memory_poisoning_wrappers.c
Normal file
53
tests/src/psa_memory_poisoning_wrappers.c
Normal file
@ -0,0 +1,53 @@
|
||||
/** Helper functions for memory poisoning in tests.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
#include "test/memory.h"
|
||||
|
||||
#include "psa_crypto_invasive.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
|
||||
void mbedtls_poison_test_hooks_setup(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;
|
||||
}
|
||||
|
||||
void mbedtls_poison_test_hooks_teardown(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,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length)
|
||||
{
|
||||
mbedtls_poison_test_hooks_setup();
|
||||
MBEDTLS_TEST_MEMORY_POISON(input, input_length);
|
||||
MBEDTLS_TEST_MEMORY_POISON(output, output_size);
|
||||
psa_status_t status = psa_cipher_encrypt(key,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length);
|
||||
MBEDTLS_TEST_MEMORY_UNPOISON(input, input_length);
|
||||
MBEDTLS_TEST_MEMORY_UNPOISON(output, output_size);
|
||||
mbedtls_poison_test_hooks_teardown();
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_TEST_MEMORY_CAN_POISON */
|
Loading…
x
Reference in New Issue
Block a user