From 582c2337595dc905843bc89f63da381afdb36dac Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 2 Nov 2023 17:14:01 +0100 Subject: [PATCH 01/46] New files for memory-related test functions Signed-off-by: Gilles Peskine --- include/test/memory.h | 18 ++++++++++++++++++ src/test_memory.c | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 include/test/memory.h create mode 100644 src/test_memory.c diff --git a/include/test/memory.h b/include/test/memory.h new file mode 100644 index 000000000..ef05112f2 --- /dev/null +++ b/include/test/memory.h @@ -0,0 +1,18 @@ +/** + * \file memory.h + * + * \brief Helper macros and functions related to testing memory management. + */ + +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#ifndef TEST_MEMORY_H +#define TEST_MEMORY_H + +#include "mbedtls/build_info.h" +#include "mbedtls/platform.h" + +#endif /* TEST_MEMORY_H */ diff --git a/src/test_memory.c b/src/test_memory.c new file mode 100644 index 000000000..cda91e5ea --- /dev/null +++ b/src/test_memory.c @@ -0,0 +1,15 @@ +/** + * \file memory.c + * + * \brief Helper functions related to testing memory management. + */ + +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#include +#include +#include + From 24138fd0c2f3a9300392d449ba79faa784da4a7a Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 2 Nov 2023 20:49:34 +0100 Subject: [PATCH 02/46] Add memory poisoning framework While an area of memory is poisoned, reading or writing from it triggers a sanitizer violation. Implemented for ASan. Signed-off-by: Gilles Peskine --- include/test/memory.h | 75 +++++++++++++++++++++++++++++++++++++++++++ src/test_memory.c | 22 +++++++++++++ 2 files changed, 97 insertions(+) diff --git a/include/test/memory.h b/include/test/memory.h index ef05112f2..27baf7a1d 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -15,4 +15,79 @@ #include "mbedtls/build_info.h" #include "mbedtls/platform.h" +/** \def MBEDTLS_TEST_MEMORY_CAN_POISON + * + * This macro is defined if the tests are compiled with a method to mark + * memory as poisoned, which can be used to enforce some memory access + * policies. + * + * Currently, only Asan (Address Sanitizer) is supported. + */ +#if defined(__SANITIZE_ADDRESS__) +# define MBEDTLS_TEST_HAVE_ASAN +#endif +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +# define MBEDTLS_TEST_HAVE_ASAN +# endif +#endif +#if defined(MBEDTLS_TEST_HAVE_ASAN) +# define MBEDTLS_TEST_MEMORY_CAN_POISON +#endif + +/** \def MBEDTLS_TEST_MEMORY_POISON(buf, size) + * + * Poison a memory area so that any attempt to read or write from it will + * cause a runtime failure. + * + * The behavior is undefined if any part of the memory area is invalid. + * + * This is a no-op in builds without a poisoning method. + * See #MBEDTLS_TEST_MEMORY_CAN_POISON. + * + * \param buf Pointer to the beginning of the memory area to poison. + * \param size Size of the memory area in bytes. + */ + +/** \def MBEDTLS_TEST_MEMORY_UNPOISON(buf, size) + * + * Undo the effect of #MBEDTLS_TEST_MEMORY_POISON. + * + * The behavior is undefined if any part of the memory area is invalid, + * or if the memory area contains a mixture of poisoned and unpoisoned parts. + * + * This is a no-op in builds without a poisoning method. + * See #MBEDTLS_TEST_MEMORY_CAN_POISON. + * + * \param buf Pointer to the beginning of the memory area to unpoison. + * \param size Size of the memory area in bytes. + */ + +#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON) + +/** Poison a memory area so that any attempt to read or write from it will + * cause a runtime failure. + * + * The behavior is undefined if any part of the memory area is invalid. + */ +void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size); +#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) \ + mbedtls_test_memory_poison(ptr, size) + +/** Undo the effect of mbedtls_test_memory_poison(). + * + * This is a no-op if the given area is entirely valid, unpoisoned memory. + * + * The behavior is undefined if any part of the memory area is invalid, + * or if the memory area contains a mixture of poisoned and unpoisoned parts. + */ +void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size); +#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \ + mbedtls_test_memory_unpoison(ptr, size) + +#else /* MBEDTLS_TEST_MEMORY_CAN_POISON */ +#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) ((void) 0) +#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) ((void) 0) +#endif /* MBEDTLS_TEST_MEMORY_CAN_POISON */ + #endif /* TEST_MEMORY_H */ diff --git a/src/test_memory.c b/src/test_memory.c index cda91e5ea..6b1404bc3 100644 --- a/src/test_memory.c +++ b/src/test_memory.c @@ -13,3 +13,25 @@ #include #include +#if defined(MBEDTLS_TEST_HAVE_ASAN) +#include +#include +#endif + +#if defined(MBEDTLS_TEST_HAVE_ASAN) +void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size) +{ + if (size == 0) { + return; + } + __asan_poison_memory_region(ptr, size); +} + +void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size) +{ + if (size == 0) { + return; + } + __asan_unpoison_memory_region(ptr, size); +} +#endif /* Asan */ From 34ea221c60570e6b6fc232bf6e737c01b2bdb860 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 2 Nov 2023 22:44:32 +0100 Subject: [PATCH 03/46] Fix memory poisoning with Asan on arbitrary byte boundaries Asan poisons memory with an 8-byte granularity. We want to make sure that the whole specified region is poisoned (our typical use case is a heap-allocated object, and we want to poison the whole object, and we don't care about the bytes after the end of the object and up to the beginning of the next object). So align the start and end of the region to (un)poison to an 8-byte boundary. Signed-off-by: Gilles Peskine --- include/test/memory.h | 4 ++++ src/test_memory.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/test/memory.h b/include/test/memory.h index 27baf7a1d..f610a97a4 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -40,6 +40,10 @@ * Poison a memory area so that any attempt to read or write from it will * cause a runtime failure. * + * Depending on the implementation, this may poison a few bytes beyond the + * indicated region, but will never poison a separate object on the heap + * or a separate object with more than the alignment of a long long. + * * The behavior is undefined if any part of the memory area is invalid. * * This is a no-op in builds without a poisoning method. diff --git a/src/test_memory.c b/src/test_memory.c index 6b1404bc3..c277be85a 100644 --- a/src/test_memory.c +++ b/src/test_memory.c @@ -19,11 +19,27 @@ #endif #if defined(MBEDTLS_TEST_HAVE_ASAN) +static void align_for_asan(const unsigned char **p_ptr, size_t *p_size) +{ + uintptr_t start = (uintptr_t) *p_ptr; + uintptr_t end = start + (uintptr_t) *p_size; + /* ASan can only poison regions with 8-byte alignment, and only poisons a + * region if it's fully within the requested range. We want to poison the + * whole requested region and don't mind a few extra bytes. Therefore, + * align start down to an 8-byte boundary, and end up to an 8-byte + * boundary. */ + start = start & ~(uintptr_t) 7; + end = (end + 7) & ~(uintptr_t) 7; + *p_ptr = (const unsigned char *) start; + *p_size = end - start; +} + void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size) { if (size == 0) { return; } + align_for_asan(&ptr, &size); __asan_poison_memory_region(ptr, size); } @@ -32,6 +48,7 @@ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size) if (size == 0) { return; } + align_for_asan(&ptr, &size); __asan_unpoison_memory_region(ptr, size); } #endif /* Asan */ From 5dbd9d1618da7758104ef8c8269d39797c576180 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 22 Nov 2023 18:13:23 +0100 Subject: [PATCH 04/46] Use the existing definition of MBEDTLS_TEST_HAVE_ASAN A definition now exists in tests/helpers.h, which is a better place. Signed-off-by: Gilles Peskine --- include/test/memory.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/include/test/memory.h b/include/test/memory.h index f610a97a4..fdf7a06c1 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -14,6 +14,7 @@ #include "mbedtls/build_info.h" #include "mbedtls/platform.h" +#include "test/helpers.h" /** \def MBEDTLS_TEST_MEMORY_CAN_POISON * @@ -23,14 +24,6 @@ * * Currently, only Asan (Address Sanitizer) is supported. */ -#if defined(__SANITIZE_ADDRESS__) -# define MBEDTLS_TEST_HAVE_ASAN -#endif -#if defined(__has_feature) -# if __has_feature(address_sanitizer) -# define MBEDTLS_TEST_HAVE_ASAN -# endif -#endif #if defined(MBEDTLS_TEST_HAVE_ASAN) # define MBEDTLS_TEST_MEMORY_CAN_POISON #endif From 660dee3579ad0ab9146e2ca64698ea85e809b84c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 22 Nov 2023 18:13:46 +0100 Subject: [PATCH 05/46] Avoid unused variable warnings in some plausible usage Signed-off-by: Gilles Peskine --- include/test/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/test/memory.h b/include/test/memory.h index fdf7a06c1..c22ef53f7 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -83,8 +83,8 @@ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size); mbedtls_test_memory_unpoison(ptr, size) #else /* MBEDTLS_TEST_MEMORY_CAN_POISON */ -#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) ((void) 0) -#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) ((void) 0) +#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) ((void) (ptr), (void) (size)) +#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) ((void) (ptr), (void) (size)) #endif /* MBEDTLS_TEST_MEMORY_CAN_POISON */ #endif /* TEST_MEMORY_H */ From ce64ce80bc5c4ee12ffa9f2a942d2a02a2f88c4a Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 27 Nov 2023 17:32:47 +0000 Subject: [PATCH 06/46] Create memory poisoning wrapper for cipher encrypt Use the preprocessor to wrap psa_cipher_encrypt in a wrapper that poisons the input and output buffers. Signed-off-by: David Horstmann --- include/test/psa_memory_poisoning_wrappers.h | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/test/psa_memory_poisoning_wrappers.h diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h new file mode 100644 index 000000000..08234b494 --- /dev/null +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -0,0 +1,27 @@ +#include "psa/crypto.h" + +#include "test/memory.h" + +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_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); + return status; +} + +#define psa_cipher_encrypt(...) wrap_psa_cipher_encrypt(__VA_ARGS__) From 015f979b3adad5df1a70fb0c54e8a2e1391d3c4a Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 28 Nov 2023 15:21:56 +0000 Subject: [PATCH 07/46] 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 --- include/test/psa_memory_poisoning_wrappers.h | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h index 08234b494..e1642d2c1 100644 --- a/include/test/psa_memory_poisoning_wrappers.h +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -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 */ From 7126ccbe3f886e34cf0deffd841928c21deaf4f9 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 7 Dec 2023 18:34:49 +0000 Subject: [PATCH 08/46] Add missing license header Signed-off-by: David Horstmann --- include/test/psa_memory_poisoning_wrappers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h index e1642d2c1..3422339fd 100644 --- a/include/test/psa_memory_poisoning_wrappers.h +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -1,3 +1,8 @@ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + #include "psa/crypto.h" #include "test/memory.h" From 3a3a7ca30345b53a16514030ab28d1eab210a34a Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 8 Dec 2023 12:09:04 +0000 Subject: [PATCH 09/46] Add comment explaining the purpose of header Explain why we have the wrappers in psa_memory_poisoning_wrappers.h Signed-off-by: David Horstmann --- include/test/psa_memory_poisoning_wrappers.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h index 3422339fd..5192597a3 100644 --- a/include/test/psa_memory_poisoning_wrappers.h +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -1,3 +1,9 @@ +/** Memory poisoning wrappers for PSA functions. + * + * These wrappers poison the input and output buffers of each function + * before calling it, to ensure that it does not access the buffers + * except by calling the approved buffer-copying functions. + */ /* * Copyright The Mbed TLS Contributors * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later From 978c08e429804893b5c185d3dba59409d47c05ca Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 13 Dec 2023 17:07:23 +0000 Subject: [PATCH 10/46] Move test hook setup functions into a C file Signed-off-by: David Horstmann --- include/test/psa_memory_poisoning_wrappers.h | 55 +++++++------------- src/psa_memory_poisoning_wrappers.c | 53 +++++++++++++++++++ 2 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 src/psa_memory_poisoning_wrappers.c diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h index 5192597a3..8b2dcfa04 100644 --- a/include/test/psa_memory_poisoning_wrappers.h +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -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 */ \ No newline at end of file diff --git a/src/psa_memory_poisoning_wrappers.c b/src/psa_memory_poisoning_wrappers.c new file mode 100644 index 000000000..7af84dd76 --- /dev/null +++ b/src/psa_memory_poisoning_wrappers.c @@ -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 */ From 155d5344ffa80a5912f4e65f9094652b851ffa8c Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 14 Dec 2023 14:17:04 +0000 Subject: [PATCH 11/46] Move test hook setup and teardown to helpers.c Setup and teardown test hooks during full test platform setup. Signed-off-by: David Horstmann --- src/helpers.c | 12 ++++++++++++ src/psa_memory_poisoning_wrappers.c | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index eb28919b8..53a17abda 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -13,6 +13,10 @@ #include #endif +#if defined(MBEDTLS_TEST_HOOKS) +#include +#endif + /*----------------------------------------------------------------------------*/ /* Static global variables */ @@ -29,6 +33,10 @@ int mbedtls_test_platform_setup(void) { int ret = 0; +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) + mbedtls_poison_test_hooks_setup(); +#endif + #if defined(MBEDTLS_PSA_INJECT_ENTROPY) /* Make sure that injected entropy is present. Otherwise * psa_crypto_init() will fail. This is not necessary for test suites @@ -49,6 +57,10 @@ int mbedtls_test_platform_setup(void) void mbedtls_test_platform_teardown(void) { +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) + mbedtls_poison_test_hooks_teardown(); +#endif + #if defined(MBEDTLS_PLATFORM_C) mbedtls_platform_teardown(&platform_ctx); #endif /* MBEDTLS_PLATFORM_C */ diff --git a/src/psa_memory_poisoning_wrappers.c b/src/psa_memory_poisoning_wrappers.c index 7af84dd76..c865d1f90 100644 --- a/src/psa_memory_poisoning_wrappers.c +++ b/src/psa_memory_poisoning_wrappers.c @@ -34,7 +34,6 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key, 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, @@ -46,7 +45,6 @@ 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); - mbedtls_poison_test_hooks_teardown(); return status; } From 5e32dba4134c05c3cfe49fdc1f31ac5aadc056ee Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 14 Dec 2023 14:27:50 +0000 Subject: [PATCH 12/46] Move wrapper include to psa_crypto_helpers.h This makes memory poisoning wrappers available to (almost) all tests. Signed-off-by: David Horstmann --- include/test/psa_crypto_helpers.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/test/psa_crypto_helpers.h b/include/test/psa_crypto_helpers.h index 04b90b923..935e07181 100644 --- a/include/test/psa_crypto_helpers.h +++ b/include/test/psa_crypto_helpers.h @@ -16,6 +16,9 @@ #include #endif +#if defined(MBEDTLS_TEST_HOOKS) +#include "test/psa_memory_poisoning_wrappers.h" +#endif #if defined(MBEDTLS_PSA_CRYPTO_C) /** Initialize the PSA Crypto subsystem. */ From 24157cff5e25cd8dee574b504ebc3ae314d0a391 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 14 Dec 2023 17:17:20 +0000 Subject: [PATCH 13/46] Add missing newline at end of file Signed-off-by: David Horstmann --- include/test/psa_memory_poisoning_wrappers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h index 8b2dcfa04..0052c2fae 100644 --- a/include/test/psa_memory_poisoning_wrappers.h +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -44,4 +44,4 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key, #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_TEST_MEMORY_CAN_POISON */ -#endif /* PSA_MEMORY_POISONING_WRAPPERS_H */ \ No newline at end of file +#endif /* PSA_MEMORY_POISONING_WRAPPERS_H */ From a41e3cea942a39959bffae28511719594aaaad2c Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 15 Dec 2023 18:29:54 +0000 Subject: [PATCH 14/46] Improve guards around memory poisoning setup We should not setup or teardown test hooks when we do not have MBEDTLS_PSA_CRYPTO_C. Signed-off-by: David Horstmann --- src/helpers.c | 6 ++++-- src/psa_memory_poisoning_wrappers.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index 53a17abda..1c58faefa 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -33,7 +33,8 @@ int mbedtls_test_platform_setup(void) { int ret = 0; -#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ + && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) mbedtls_poison_test_hooks_setup(); #endif @@ -57,7 +58,8 @@ int mbedtls_test_platform_setup(void) void mbedtls_test_platform_teardown(void) { -#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ + && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) mbedtls_poison_test_hooks_teardown(); #endif diff --git a/src/psa_memory_poisoning_wrappers.c b/src/psa_memory_poisoning_wrappers.c index c865d1f90..89830a596 100644 --- a/src/psa_memory_poisoning_wrappers.c +++ b/src/psa_memory_poisoning_wrappers.c @@ -8,7 +8,8 @@ #include "psa_crypto_invasive.h" -#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ + && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) void mbedtls_poison_test_hooks_setup(void) { @@ -48,4 +49,5 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key, return status; } -#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_TEST_MEMORY_CAN_POISON */ +#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C && + MBEDTLS_TEST_MEMORY_CAN_POISON */ \ No newline at end of file From c62ece8979fa7926e8953092ea02e02de96b5232 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 18 Dec 2023 15:30:46 +0000 Subject: [PATCH 15/46] Add extra MBEDTLS_PSA_CRYPTO_C guard for header Do not include psa_memory_poisoning_wrappers.h unless MBEDTLS_PSA_CRYPTO_C is set. Signed-off-by: David Horstmann --- include/test/psa_crypto_helpers.h | 2 +- src/helpers.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/test/psa_crypto_helpers.h b/include/test/psa_crypto_helpers.h index 935e07181..3d421d7fe 100644 --- a/include/test/psa_crypto_helpers.h +++ b/include/test/psa_crypto_helpers.h @@ -16,7 +16,7 @@ #include #endif -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) #include "test/psa_memory_poisoning_wrappers.h" #endif diff --git a/src/helpers.c b/src/helpers.c index 1c58faefa..843a9d414 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -13,7 +13,7 @@ #include #endif -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) #include #endif From 2602db9398a3d3dd9aca4d3a0060ba9d3e229cfd Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 18 Dec 2023 15:58:17 +0000 Subject: [PATCH 16/46] Add missing newline at end of file Signed-off-by: David Horstmann --- src/psa_memory_poisoning_wrappers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psa_memory_poisoning_wrappers.c b/src/psa_memory_poisoning_wrappers.c index 89830a596..a53e875d4 100644 --- a/src/psa_memory_poisoning_wrappers.c +++ b/src/psa_memory_poisoning_wrappers.c @@ -50,4 +50,4 @@ psa_status_t wrap_psa_cipher_encrypt(mbedtls_svc_key_id_t key, } #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C && - MBEDTLS_TEST_MEMORY_CAN_POISON */ \ No newline at end of file + MBEDTLS_TEST_MEMORY_CAN_POISON */ From e73af470838d9401670937bef91999d50ae1aedd Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 20 Dec 2023 11:26:40 +0000 Subject: [PATCH 17/46] Only poison memory when buffer copying is enabled Make sure that we don't enable memory poisoning when MBEDTLS_PSA_COPY_CALLER_BUFFERS is disabled. Signed-off-by: David Horstmann --- include/test/psa_crypto_helpers.h | 3 ++- src/helpers.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/test/psa_crypto_helpers.h b/include/test/psa_crypto_helpers.h index 3d421d7fe..41b7752be 100644 --- a/include/test/psa_crypto_helpers.h +++ b/include/test/psa_crypto_helpers.h @@ -16,7 +16,8 @@ #include #endif -#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) +#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ + && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) #include "test/psa_memory_poisoning_wrappers.h" #endif diff --git a/src/helpers.c b/src/helpers.c index 843a9d414..36564fe29 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -34,6 +34,7 @@ int mbedtls_test_platform_setup(void) int ret = 0; #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ + && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) \ && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) mbedtls_poison_test_hooks_setup(); #endif @@ -59,6 +60,7 @@ int mbedtls_test_platform_setup(void) void mbedtls_test_platform_teardown(void) { #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ + && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) \ && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) mbedtls_poison_test_hooks_teardown(); #endif From c1b3b451a154896787f7dfe22f130eea1cdb7676 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 10 Jan 2024 14:33:17 +0000 Subject: [PATCH 18/46] Use thread-local flag to enable memory poisoning Allow memory poisoning to be enabled and disabled at runtime using a thread-local flag. This allows poisoning to be disabled whenever a PSA function is called but not through the test wrappers, removing false positive use-after-poisons. Signed-off-by: David Horstmann --- include/test/memory.h | 21 ++++++++++++++++++--- src/test_memory.c | 12 +++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/test/memory.h b/include/test/memory.h index c22ef53f7..e0437517d 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -22,9 +22,12 @@ * memory as poisoned, which can be used to enforce some memory access * policies. * + * Support for the C11 thread_local keyword is also required. + * * Currently, only Asan (Address Sanitizer) is supported. */ -#if defined(MBEDTLS_TEST_HAVE_ASAN) +#if defined(MBEDTLS_TEST_HAVE_ASAN) && \ + (__STDC_VERSION__ >= 201112L) # define MBEDTLS_TEST_MEMORY_CAN_POISON #endif @@ -62,6 +65,12 @@ #if defined(MBEDTLS_TEST_MEMORY_CAN_POISON) +/** Thread-local variable used to enable memory poisoning. This is set and + * unset in the test wrappers so that calls to PSA functions from the library + * do not poison memory. + */ +extern _Thread_local int mbedtls_test_memory_poisoning_enabled; + /** Poison a memory area so that any attempt to read or write from it will * cause a runtime failure. * @@ -69,7 +78,10 @@ */ void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size); #define MBEDTLS_TEST_MEMORY_POISON(ptr, size) \ - mbedtls_test_memory_poison(ptr, size) + do { \ + mbedtls_test_memory_poisoning_enabled = 1; \ + mbedtls_test_memory_poison(ptr, size); \ + } while (0) /** Undo the effect of mbedtls_test_memory_poison(). * @@ -80,7 +92,10 @@ void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size); */ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size); #define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \ - mbedtls_test_memory_unpoison(ptr, size) + do { \ + mbedtls_test_memory_unpoison(ptr, size); \ + mbedtls_test_memory_poisoning_enabled = 0; \ + } while (0) #else /* MBEDTLS_TEST_MEMORY_CAN_POISON */ #define MBEDTLS_TEST_MEMORY_POISON(ptr, size) ((void) (ptr), (void) (size)) diff --git a/src/test_memory.c b/src/test_memory.c index c277be85a..dbb7b20de 100644 --- a/src/test_memory.c +++ b/src/test_memory.c @@ -13,12 +13,15 @@ #include #include -#if defined(MBEDTLS_TEST_HAVE_ASAN) +#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON) #include #include #endif -#if defined(MBEDTLS_TEST_HAVE_ASAN) +#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON) + +_Thread_local int mbedtls_test_memory_poisoning_enabled = 0; + static void align_for_asan(const unsigned char **p_ptr, size_t *p_size) { uintptr_t start = (uintptr_t) *p_ptr; @@ -36,6 +39,9 @@ static void align_for_asan(const unsigned char **p_ptr, size_t *p_size) void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size) { + if (!mbedtls_test_memory_poisoning_enabled) { + return; + } if (size == 0) { return; } @@ -51,4 +57,4 @@ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size) align_for_asan(&ptr, &size); __asan_unpoison_memory_region(ptr, size); } -#endif /* Asan */ +#endif /* Memory poisoning */ From 8aa0e565578c712eb74a6839877c8653b9d37083 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Jan 2024 16:42:40 +0100 Subject: [PATCH 19/46] Commit generated PSA wrappers Commit files generated by `tests/scripts/generate_psa_wrappers.py`. As of this commit, the new code is neither useful (the wrappers just call the underlying functions) nor used (the wrapper functions are not called from anywhere). This will change in subsequent commits. This is a deviation from our normal practice of generating configuration-independent platform-independent files as part of the build in the development branch. The PSA test wrappers will be committed to the repository for some time for two reasons: * In the short term, we will review the generated code but not fully review the generator script. * The build scripts cannot yet accommodate a generated header file. Signed-off-by: Gilles Peskine --- include/test/psa_test_wrappers.h | 719 +++++++++++++++++++++++ src/psa_test_wrappers.c | 973 +++++++++++++++++++++++++++++++ 2 files changed, 1692 insertions(+) create mode 100644 include/test/psa_test_wrappers.h create mode 100644 src/psa_test_wrappers.c diff --git a/include/test/psa_test_wrappers.h b/include/test/psa_test_wrappers.h new file mode 100644 index 000000000..18417800c --- /dev/null +++ b/include/test/psa_test_wrappers.h @@ -0,0 +1,719 @@ +/* Automatically generated by generate_psa_wrappers.py, do not edit! */ + +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#ifndef TEST_PSA_TEST_WRAPPERS_H +#define TEST_PSA_TEST_WRAPPERS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) + +#include + +#include +#include + +#if defined(MBEDTLS_PSA_INJECT_ENTROPY) +psa_status_t mbedtls_test_wrap_mbedtls_psa_inject_entropy( + const uint8_t *arg0_seed, + size_t arg1_seed_size); +#define mbedtls_psa_inject_entropy(arg0_seed, arg1_seed_size) \ + mbedtls_test_wrap_mbedtls_psa_inject_entropy(arg0_seed, arg1_seed_size) +#endif /* defined(MBEDTLS_PSA_INJECT_ENTROPY) */ + +#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) +psa_status_t mbedtls_test_wrap_mbedtls_psa_platform_get_builtin_key( + mbedtls_svc_key_id_t arg0_key_id, + psa_key_lifetime_t *arg1_lifetime, + psa_drv_slot_number_t *arg2_slot_number); +#define mbedtls_psa_platform_get_builtin_key(arg0_key_id, arg1_lifetime, arg2_slot_number) \ + mbedtls_test_wrap_mbedtls_psa_platform_get_builtin_key(arg0_key_id, arg1_lifetime, arg2_slot_number) +#endif /* defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) */ + +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) +psa_status_t mbedtls_test_wrap_mbedtls_psa_register_se_key( + const psa_key_attributes_t *arg0_attributes); +#define mbedtls_psa_register_se_key(arg0_attributes) \ + mbedtls_test_wrap_mbedtls_psa_register_se_key(arg0_attributes) +#endif /* defined(MBEDTLS_PSA_CRYPTO_SE_C) */ + +psa_status_t mbedtls_test_wrap_psa_aead_abort( + psa_aead_operation_t *arg0_operation); +#define psa_aead_abort(arg0_operation) \ + mbedtls_test_wrap_psa_aead_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_aead_decrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_nonce, + size_t arg3_nonce_length, + const uint8_t *arg4_additional_data, + size_t arg5_additional_data_length, + const uint8_t *arg6_ciphertext, + size_t arg7_ciphertext_length, + uint8_t *arg8_plaintext, + size_t arg9_plaintext_size, + size_t *arg10_plaintext_length); +#define psa_aead_decrypt(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_ciphertext, arg7_ciphertext_length, arg8_plaintext, arg9_plaintext_size, arg10_plaintext_length) \ + mbedtls_test_wrap_psa_aead_decrypt(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_ciphertext, arg7_ciphertext_length, arg8_plaintext, arg9_plaintext_size, arg10_plaintext_length) + +psa_status_t mbedtls_test_wrap_psa_aead_decrypt_setup( + psa_aead_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg); +#define psa_aead_decrypt_setup(arg0_operation, arg1_key, arg2_alg) \ + mbedtls_test_wrap_psa_aead_decrypt_setup(arg0_operation, arg1_key, arg2_alg) + +psa_status_t mbedtls_test_wrap_psa_aead_encrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_nonce, + size_t arg3_nonce_length, + const uint8_t *arg4_additional_data, + size_t arg5_additional_data_length, + const uint8_t *arg6_plaintext, + size_t arg7_plaintext_length, + uint8_t *arg8_ciphertext, + size_t arg9_ciphertext_size, + size_t *arg10_ciphertext_length); +#define psa_aead_encrypt(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_plaintext, arg7_plaintext_length, arg8_ciphertext, arg9_ciphertext_size, arg10_ciphertext_length) \ + mbedtls_test_wrap_psa_aead_encrypt(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_plaintext, arg7_plaintext_length, arg8_ciphertext, arg9_ciphertext_size, arg10_ciphertext_length) + +psa_status_t mbedtls_test_wrap_psa_aead_encrypt_setup( + psa_aead_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg); +#define psa_aead_encrypt_setup(arg0_operation, arg1_key, arg2_alg) \ + mbedtls_test_wrap_psa_aead_encrypt_setup(arg0_operation, arg1_key, arg2_alg) + +psa_status_t mbedtls_test_wrap_psa_aead_finish( + psa_aead_operation_t *arg0_operation, + uint8_t *arg1_ciphertext, + size_t arg2_ciphertext_size, + size_t *arg3_ciphertext_length, + uint8_t *arg4_tag, + size_t arg5_tag_size, + size_t *arg6_tag_length); +#define psa_aead_finish(arg0_operation, arg1_ciphertext, arg2_ciphertext_size, arg3_ciphertext_length, arg4_tag, arg5_tag_size, arg6_tag_length) \ + mbedtls_test_wrap_psa_aead_finish(arg0_operation, arg1_ciphertext, arg2_ciphertext_size, arg3_ciphertext_length, arg4_tag, arg5_tag_size, arg6_tag_length) + +psa_status_t mbedtls_test_wrap_psa_aead_generate_nonce( + psa_aead_operation_t *arg0_operation, + uint8_t *arg1_nonce, + size_t arg2_nonce_size, + size_t *arg3_nonce_length); +#define psa_aead_generate_nonce(arg0_operation, arg1_nonce, arg2_nonce_size, arg3_nonce_length) \ + mbedtls_test_wrap_psa_aead_generate_nonce(arg0_operation, arg1_nonce, arg2_nonce_size, arg3_nonce_length) + +psa_status_t mbedtls_test_wrap_psa_aead_set_lengths( + psa_aead_operation_t *arg0_operation, + size_t arg1_ad_length, + size_t arg2_plaintext_length); +#define psa_aead_set_lengths(arg0_operation, arg1_ad_length, arg2_plaintext_length) \ + mbedtls_test_wrap_psa_aead_set_lengths(arg0_operation, arg1_ad_length, arg2_plaintext_length) + +psa_status_t mbedtls_test_wrap_psa_aead_set_nonce( + psa_aead_operation_t *arg0_operation, + const uint8_t *arg1_nonce, + size_t arg2_nonce_length); +#define psa_aead_set_nonce(arg0_operation, arg1_nonce, arg2_nonce_length) \ + mbedtls_test_wrap_psa_aead_set_nonce(arg0_operation, arg1_nonce, arg2_nonce_length) + +psa_status_t mbedtls_test_wrap_psa_aead_update( + psa_aead_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length, + uint8_t *arg3_output, + size_t arg4_output_size, + size_t *arg5_output_length); +#define psa_aead_update(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length) \ + mbedtls_test_wrap_psa_aead_update(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length) + +psa_status_t mbedtls_test_wrap_psa_aead_update_ad( + psa_aead_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length); +#define psa_aead_update_ad(arg0_operation, arg1_input, arg2_input_length) \ + mbedtls_test_wrap_psa_aead_update_ad(arg0_operation, arg1_input, arg2_input_length) + +psa_status_t mbedtls_test_wrap_psa_aead_verify( + psa_aead_operation_t *arg0_operation, + uint8_t *arg1_plaintext, + size_t arg2_plaintext_size, + size_t *arg3_plaintext_length, + const uint8_t *arg4_tag, + size_t arg5_tag_length); +#define psa_aead_verify(arg0_operation, arg1_plaintext, arg2_plaintext_size, arg3_plaintext_length, arg4_tag, arg5_tag_length) \ + mbedtls_test_wrap_psa_aead_verify(arg0_operation, arg1_plaintext, arg2_plaintext_size, arg3_plaintext_length, arg4_tag, arg5_tag_length) + +psa_status_t mbedtls_test_wrap_psa_asymmetric_decrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_salt, + size_t arg5_salt_length, + uint8_t *arg6_output, + size_t arg7_output_size, + size_t *arg8_output_length); +#define psa_asymmetric_decrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length) \ + mbedtls_test_wrap_psa_asymmetric_decrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length) + +psa_status_t mbedtls_test_wrap_psa_asymmetric_encrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_salt, + size_t arg5_salt_length, + uint8_t *arg6_output, + size_t arg7_output_size, + size_t *arg8_output_length); +#define psa_asymmetric_encrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length) \ + mbedtls_test_wrap_psa_asymmetric_encrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length) + +psa_status_t mbedtls_test_wrap_psa_cipher_abort( + psa_cipher_operation_t *arg0_operation); +#define psa_cipher_abort(arg0_operation) \ + mbedtls_test_wrap_psa_cipher_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_cipher_decrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_output, + size_t arg5_output_size, + size_t *arg6_output_length); +#define psa_cipher_decrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length) \ + mbedtls_test_wrap_psa_cipher_decrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length) + +psa_status_t mbedtls_test_wrap_psa_cipher_decrypt_setup( + psa_cipher_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg); +#define psa_cipher_decrypt_setup(arg0_operation, arg1_key, arg2_alg) \ + mbedtls_test_wrap_psa_cipher_decrypt_setup(arg0_operation, arg1_key, arg2_alg) + +psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_output, + size_t arg5_output_size, + size_t *arg6_output_length); +#define psa_cipher_encrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length) \ + mbedtls_test_wrap_psa_cipher_encrypt(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length) + +psa_status_t mbedtls_test_wrap_psa_cipher_encrypt_setup( + psa_cipher_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg); +#define psa_cipher_encrypt_setup(arg0_operation, arg1_key, arg2_alg) \ + mbedtls_test_wrap_psa_cipher_encrypt_setup(arg0_operation, arg1_key, arg2_alg) + +psa_status_t mbedtls_test_wrap_psa_cipher_finish( + psa_cipher_operation_t *arg0_operation, + uint8_t *arg1_output, + size_t arg2_output_size, + size_t *arg3_output_length); +#define psa_cipher_finish(arg0_operation, arg1_output, arg2_output_size, arg3_output_length) \ + mbedtls_test_wrap_psa_cipher_finish(arg0_operation, arg1_output, arg2_output_size, arg3_output_length) + +psa_status_t mbedtls_test_wrap_psa_cipher_generate_iv( + psa_cipher_operation_t *arg0_operation, + uint8_t *arg1_iv, + size_t arg2_iv_size, + size_t *arg3_iv_length); +#define psa_cipher_generate_iv(arg0_operation, arg1_iv, arg2_iv_size, arg3_iv_length) \ + mbedtls_test_wrap_psa_cipher_generate_iv(arg0_operation, arg1_iv, arg2_iv_size, arg3_iv_length) + +psa_status_t mbedtls_test_wrap_psa_cipher_set_iv( + psa_cipher_operation_t *arg0_operation, + const uint8_t *arg1_iv, + size_t arg2_iv_length); +#define psa_cipher_set_iv(arg0_operation, arg1_iv, arg2_iv_length) \ + mbedtls_test_wrap_psa_cipher_set_iv(arg0_operation, arg1_iv, arg2_iv_length) + +psa_status_t mbedtls_test_wrap_psa_cipher_update( + psa_cipher_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length, + uint8_t *arg3_output, + size_t arg4_output_size, + size_t *arg5_output_length); +#define psa_cipher_update(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length) \ + mbedtls_test_wrap_psa_cipher_update(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length) + +psa_status_t mbedtls_test_wrap_psa_copy_key( + mbedtls_svc_key_id_t arg0_source_key, + const psa_key_attributes_t *arg1_attributes, + mbedtls_svc_key_id_t *arg2_target_key); +#define psa_copy_key(arg0_source_key, arg1_attributes, arg2_target_key) \ + mbedtls_test_wrap_psa_copy_key(arg0_source_key, arg1_attributes, arg2_target_key) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_cipher_suite( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + psa_pake_cipher_suite_t *arg1_cipher_suite); +#define psa_crypto_driver_pake_get_cipher_suite(arg0_inputs, arg1_cipher_suite) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_cipher_suite(arg0_inputs, arg1_cipher_suite) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_password( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + uint8_t *arg1_buffer, + size_t arg2_buffer_size, + size_t *arg3_buffer_length); +#define psa_crypto_driver_pake_get_password(arg0_inputs, arg1_buffer, arg2_buffer_size, arg3_buffer_length) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_password(arg0_inputs, arg1_buffer, arg2_buffer_size, arg3_buffer_length) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_password_len( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + size_t *arg1_password_len); +#define psa_crypto_driver_pake_get_password_len(arg0_inputs, arg1_password_len) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_password_len(arg0_inputs, arg1_password_len) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_peer( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + uint8_t *arg1_peer_id, + size_t arg2_peer_id_size, + size_t *arg3_peer_id_length); +#define psa_crypto_driver_pake_get_peer(arg0_inputs, arg1_peer_id, arg2_peer_id_size, arg3_peer_id_length) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_peer(arg0_inputs, arg1_peer_id, arg2_peer_id_size, arg3_peer_id_length) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_peer_len( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + size_t *arg1_peer_len); +#define psa_crypto_driver_pake_get_peer_len(arg0_inputs, arg1_peer_len) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_peer_len(arg0_inputs, arg1_peer_len) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_user( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + uint8_t *arg1_user_id, + size_t arg2_user_id_size, + size_t *arg3_user_id_len); +#define psa_crypto_driver_pake_get_user(arg0_inputs, arg1_user_id, arg2_user_id_size, arg3_user_id_len) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_user(arg0_inputs, arg1_user_id, arg2_user_id_size, arg3_user_id_len) + +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_user_len( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + size_t *arg1_user_len); +#define psa_crypto_driver_pake_get_user_len(arg0_inputs, arg1_user_len) \ + mbedtls_test_wrap_psa_crypto_driver_pake_get_user_len(arg0_inputs, arg1_user_len) + +psa_status_t mbedtls_test_wrap_psa_crypto_init(void); +#define psa_crypto_init() \ + mbedtls_test_wrap_psa_crypto_init() + +psa_status_t mbedtls_test_wrap_psa_destroy_key( + mbedtls_svc_key_id_t arg0_key); +#define psa_destroy_key(arg0_key) \ + mbedtls_test_wrap_psa_destroy_key(arg0_key) + +psa_status_t mbedtls_test_wrap_psa_export_key( + mbedtls_svc_key_id_t arg0_key, + uint8_t *arg1_data, + size_t arg2_data_size, + size_t *arg3_data_length); +#define psa_export_key(arg0_key, arg1_data, arg2_data_size, arg3_data_length) \ + mbedtls_test_wrap_psa_export_key(arg0_key, arg1_data, arg2_data_size, arg3_data_length) + +psa_status_t mbedtls_test_wrap_psa_export_public_key( + mbedtls_svc_key_id_t arg0_key, + uint8_t *arg1_data, + size_t arg2_data_size, + size_t *arg3_data_length); +#define psa_export_public_key(arg0_key, arg1_data, arg2_data_size, arg3_data_length) \ + mbedtls_test_wrap_psa_export_public_key(arg0_key, arg1_data, arg2_data_size, arg3_data_length) + +psa_status_t mbedtls_test_wrap_psa_generate_key( + const psa_key_attributes_t *arg0_attributes, + mbedtls_svc_key_id_t *arg1_key); +#define psa_generate_key(arg0_attributes, arg1_key) \ + mbedtls_test_wrap_psa_generate_key(arg0_attributes, arg1_key) + +psa_status_t mbedtls_test_wrap_psa_generate_random( + uint8_t *arg0_output, + size_t arg1_output_size); +#define psa_generate_random(arg0_output, arg1_output_size) \ + mbedtls_test_wrap_psa_generate_random(arg0_output, arg1_output_size) + +psa_status_t mbedtls_test_wrap_psa_get_key_attributes( + mbedtls_svc_key_id_t arg0_key, + psa_key_attributes_t *arg1_attributes); +#define psa_get_key_attributes(arg0_key, arg1_attributes) \ + mbedtls_test_wrap_psa_get_key_attributes(arg0_key, arg1_attributes) + +psa_status_t mbedtls_test_wrap_psa_hash_abort( + psa_hash_operation_t *arg0_operation); +#define psa_hash_abort(arg0_operation) \ + mbedtls_test_wrap_psa_hash_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_hash_clone( + const psa_hash_operation_t *arg0_source_operation, + psa_hash_operation_t *arg1_target_operation); +#define psa_hash_clone(arg0_source_operation, arg1_target_operation) \ + mbedtls_test_wrap_psa_hash_clone(arg0_source_operation, arg1_target_operation) + +psa_status_t mbedtls_test_wrap_psa_hash_compare( + psa_algorithm_t arg0_alg, + const uint8_t *arg1_input, + size_t arg2_input_length, + const uint8_t *arg3_hash, + size_t arg4_hash_length); +#define psa_hash_compare(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_length) \ + mbedtls_test_wrap_psa_hash_compare(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_length) + +psa_status_t mbedtls_test_wrap_psa_hash_compute( + psa_algorithm_t arg0_alg, + const uint8_t *arg1_input, + size_t arg2_input_length, + uint8_t *arg3_hash, + size_t arg4_hash_size, + size_t *arg5_hash_length); +#define psa_hash_compute(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_size, arg5_hash_length) \ + mbedtls_test_wrap_psa_hash_compute(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_size, arg5_hash_length) + +psa_status_t mbedtls_test_wrap_psa_hash_finish( + psa_hash_operation_t *arg0_operation, + uint8_t *arg1_hash, + size_t arg2_hash_size, + size_t *arg3_hash_length); +#define psa_hash_finish(arg0_operation, arg1_hash, arg2_hash_size, arg3_hash_length) \ + mbedtls_test_wrap_psa_hash_finish(arg0_operation, arg1_hash, arg2_hash_size, arg3_hash_length) + +psa_status_t mbedtls_test_wrap_psa_hash_setup( + psa_hash_operation_t *arg0_operation, + psa_algorithm_t arg1_alg); +#define psa_hash_setup(arg0_operation, arg1_alg) \ + mbedtls_test_wrap_psa_hash_setup(arg0_operation, arg1_alg) + +psa_status_t mbedtls_test_wrap_psa_hash_update( + psa_hash_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length); +#define psa_hash_update(arg0_operation, arg1_input, arg2_input_length) \ + mbedtls_test_wrap_psa_hash_update(arg0_operation, arg1_input, arg2_input_length) + +psa_status_t mbedtls_test_wrap_psa_hash_verify( + psa_hash_operation_t *arg0_operation, + const uint8_t *arg1_hash, + size_t arg2_hash_length); +#define psa_hash_verify(arg0_operation, arg1_hash, arg2_hash_length) \ + mbedtls_test_wrap_psa_hash_verify(arg0_operation, arg1_hash, arg2_hash_length) + +psa_status_t mbedtls_test_wrap_psa_import_key( + const psa_key_attributes_t *arg0_attributes, + const uint8_t *arg1_data, + size_t arg2_data_length, + mbedtls_svc_key_id_t *arg3_key); +#define psa_import_key(arg0_attributes, arg1_data, arg2_data_length, arg3_key) \ + mbedtls_test_wrap_psa_import_key(arg0_attributes, arg1_data, arg2_data_length, arg3_key) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_abort( + psa_key_derivation_operation_t *arg0_operation); +#define psa_key_derivation_abort(arg0_operation) \ + mbedtls_test_wrap_psa_key_derivation_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_get_capacity( + const psa_key_derivation_operation_t *arg0_operation, + size_t *arg1_capacity); +#define psa_key_derivation_get_capacity(arg0_operation, arg1_capacity) \ + mbedtls_test_wrap_psa_key_derivation_get_capacity(arg0_operation, arg1_capacity) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_input_bytes( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + const uint8_t *arg2_data, + size_t arg3_data_length); +#define psa_key_derivation_input_bytes(arg0_operation, arg1_step, arg2_data, arg3_data_length) \ + mbedtls_test_wrap_psa_key_derivation_input_bytes(arg0_operation, arg1_step, arg2_data, arg3_data_length) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_input_integer( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + uint64_t arg2_value); +#define psa_key_derivation_input_integer(arg0_operation, arg1_step, arg2_value) \ + mbedtls_test_wrap_psa_key_derivation_input_integer(arg0_operation, arg1_step, arg2_value) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_input_key( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + mbedtls_svc_key_id_t arg2_key); +#define psa_key_derivation_input_key(arg0_operation, arg1_step, arg2_key) \ + mbedtls_test_wrap_psa_key_derivation_input_key(arg0_operation, arg1_step, arg2_key) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_key_agreement( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + mbedtls_svc_key_id_t arg2_private_key, + const uint8_t *arg3_peer_key, + size_t arg4_peer_key_length); +#define psa_key_derivation_key_agreement(arg0_operation, arg1_step, arg2_private_key, arg3_peer_key, arg4_peer_key_length) \ + mbedtls_test_wrap_psa_key_derivation_key_agreement(arg0_operation, arg1_step, arg2_private_key, arg3_peer_key, arg4_peer_key_length) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_output_bytes( + psa_key_derivation_operation_t *arg0_operation, + uint8_t *arg1_output, + size_t arg2_output_length); +#define psa_key_derivation_output_bytes(arg0_operation, arg1_output, arg2_output_length) \ + mbedtls_test_wrap_psa_key_derivation_output_bytes(arg0_operation, arg1_output, arg2_output_length) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_output_key( + const psa_key_attributes_t *arg0_attributes, + psa_key_derivation_operation_t *arg1_operation, + mbedtls_svc_key_id_t *arg2_key); +#define psa_key_derivation_output_key(arg0_attributes, arg1_operation, arg2_key) \ + mbedtls_test_wrap_psa_key_derivation_output_key(arg0_attributes, arg1_operation, arg2_key) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_set_capacity( + psa_key_derivation_operation_t *arg0_operation, + size_t arg1_capacity); +#define psa_key_derivation_set_capacity(arg0_operation, arg1_capacity) \ + mbedtls_test_wrap_psa_key_derivation_set_capacity(arg0_operation, arg1_capacity) + +psa_status_t mbedtls_test_wrap_psa_key_derivation_setup( + psa_key_derivation_operation_t *arg0_operation, + psa_algorithm_t arg1_alg); +#define psa_key_derivation_setup(arg0_operation, arg1_alg) \ + mbedtls_test_wrap_psa_key_derivation_setup(arg0_operation, arg1_alg) + +psa_status_t mbedtls_test_wrap_psa_mac_abort( + psa_mac_operation_t *arg0_operation); +#define psa_mac_abort(arg0_operation) \ + mbedtls_test_wrap_psa_mac_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_mac_compute( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_mac, + size_t arg5_mac_size, + size_t *arg6_mac_length); +#define psa_mac_compute(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_size, arg6_mac_length) \ + mbedtls_test_wrap_psa_mac_compute(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_size, arg6_mac_length) + +psa_status_t mbedtls_test_wrap_psa_mac_sign_finish( + psa_mac_operation_t *arg0_operation, + uint8_t *arg1_mac, + size_t arg2_mac_size, + size_t *arg3_mac_length); +#define psa_mac_sign_finish(arg0_operation, arg1_mac, arg2_mac_size, arg3_mac_length) \ + mbedtls_test_wrap_psa_mac_sign_finish(arg0_operation, arg1_mac, arg2_mac_size, arg3_mac_length) + +psa_status_t mbedtls_test_wrap_psa_mac_sign_setup( + psa_mac_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg); +#define psa_mac_sign_setup(arg0_operation, arg1_key, arg2_alg) \ + mbedtls_test_wrap_psa_mac_sign_setup(arg0_operation, arg1_key, arg2_alg) + +psa_status_t mbedtls_test_wrap_psa_mac_update( + psa_mac_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length); +#define psa_mac_update(arg0_operation, arg1_input, arg2_input_length) \ + mbedtls_test_wrap_psa_mac_update(arg0_operation, arg1_input, arg2_input_length) + +psa_status_t mbedtls_test_wrap_psa_mac_verify( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_mac, + size_t arg5_mac_length); +#define psa_mac_verify(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_length) \ + mbedtls_test_wrap_psa_mac_verify(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_length) + +psa_status_t mbedtls_test_wrap_psa_mac_verify_finish( + psa_mac_operation_t *arg0_operation, + const uint8_t *arg1_mac, + size_t arg2_mac_length); +#define psa_mac_verify_finish(arg0_operation, arg1_mac, arg2_mac_length) \ + mbedtls_test_wrap_psa_mac_verify_finish(arg0_operation, arg1_mac, arg2_mac_length) + +psa_status_t mbedtls_test_wrap_psa_mac_verify_setup( + psa_mac_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg); +#define psa_mac_verify_setup(arg0_operation, arg1_key, arg2_alg) \ + mbedtls_test_wrap_psa_mac_verify_setup(arg0_operation, arg1_key, arg2_alg) + +psa_status_t mbedtls_test_wrap_psa_pake_abort( + psa_pake_operation_t *arg0_operation); +#define psa_pake_abort(arg0_operation) \ + mbedtls_test_wrap_psa_pake_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_pake_get_implicit_key( + psa_pake_operation_t *arg0_operation, + psa_key_derivation_operation_t *arg1_output); +#define psa_pake_get_implicit_key(arg0_operation, arg1_output) \ + mbedtls_test_wrap_psa_pake_get_implicit_key(arg0_operation, arg1_output) + +psa_status_t mbedtls_test_wrap_psa_pake_input( + psa_pake_operation_t *arg0_operation, + psa_pake_step_t arg1_step, + const uint8_t *arg2_input, + size_t arg3_input_length); +#define psa_pake_input(arg0_operation, arg1_step, arg2_input, arg3_input_length) \ + mbedtls_test_wrap_psa_pake_input(arg0_operation, arg1_step, arg2_input, arg3_input_length) + +psa_status_t mbedtls_test_wrap_psa_pake_output( + psa_pake_operation_t *arg0_operation, + psa_pake_step_t arg1_step, + uint8_t *arg2_output, + size_t arg3_output_size, + size_t *arg4_output_length); +#define psa_pake_output(arg0_operation, arg1_step, arg2_output, arg3_output_size, arg4_output_length) \ + mbedtls_test_wrap_psa_pake_output(arg0_operation, arg1_step, arg2_output, arg3_output_size, arg4_output_length) + +psa_status_t mbedtls_test_wrap_psa_pake_set_password_key( + psa_pake_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_password); +#define psa_pake_set_password_key(arg0_operation, arg1_password) \ + mbedtls_test_wrap_psa_pake_set_password_key(arg0_operation, arg1_password) + +psa_status_t mbedtls_test_wrap_psa_pake_set_peer( + psa_pake_operation_t *arg0_operation, + const uint8_t *arg1_peer_id, + size_t arg2_peer_id_len); +#define psa_pake_set_peer(arg0_operation, arg1_peer_id, arg2_peer_id_len) \ + mbedtls_test_wrap_psa_pake_set_peer(arg0_operation, arg1_peer_id, arg2_peer_id_len) + +psa_status_t mbedtls_test_wrap_psa_pake_set_role( + psa_pake_operation_t *arg0_operation, + psa_pake_role_t arg1_role); +#define psa_pake_set_role(arg0_operation, arg1_role) \ + mbedtls_test_wrap_psa_pake_set_role(arg0_operation, arg1_role) + +psa_status_t mbedtls_test_wrap_psa_pake_set_user( + psa_pake_operation_t *arg0_operation, + const uint8_t *arg1_user_id, + size_t arg2_user_id_len); +#define psa_pake_set_user(arg0_operation, arg1_user_id, arg2_user_id_len) \ + mbedtls_test_wrap_psa_pake_set_user(arg0_operation, arg1_user_id, arg2_user_id_len) + +psa_status_t mbedtls_test_wrap_psa_pake_setup( + psa_pake_operation_t *arg0_operation, + const psa_pake_cipher_suite_t *arg1_cipher_suite); +#define psa_pake_setup(arg0_operation, arg1_cipher_suite) \ + mbedtls_test_wrap_psa_pake_setup(arg0_operation, arg1_cipher_suite) + +psa_status_t mbedtls_test_wrap_psa_purge_key( + mbedtls_svc_key_id_t arg0_key); +#define psa_purge_key(arg0_key) \ + mbedtls_test_wrap_psa_purge_key(arg0_key) + +psa_status_t mbedtls_test_wrap_psa_raw_key_agreement( + psa_algorithm_t arg0_alg, + mbedtls_svc_key_id_t arg1_private_key, + const uint8_t *arg2_peer_key, + size_t arg3_peer_key_length, + uint8_t *arg4_output, + size_t arg5_output_size, + size_t *arg6_output_length); +#define psa_raw_key_agreement(arg0_alg, arg1_private_key, arg2_peer_key, arg3_peer_key_length, arg4_output, arg5_output_size, arg6_output_length) \ + mbedtls_test_wrap_psa_raw_key_agreement(arg0_alg, arg1_private_key, arg2_peer_key, arg3_peer_key_length, arg4_output, arg5_output_size, arg6_output_length) + +psa_status_t mbedtls_test_wrap_psa_sign_hash( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_hash, + size_t arg3_hash_length, + uint8_t *arg4_signature, + size_t arg5_signature_size, + size_t *arg6_signature_length); +#define psa_sign_hash(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_size, arg6_signature_length) \ + mbedtls_test_wrap_psa_sign_hash(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_size, arg6_signature_length) + +psa_status_t mbedtls_test_wrap_psa_sign_hash_abort( + psa_sign_hash_interruptible_operation_t *arg0_operation); +#define psa_sign_hash_abort(arg0_operation) \ + mbedtls_test_wrap_psa_sign_hash_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_sign_hash_complete( + psa_sign_hash_interruptible_operation_t *arg0_operation, + uint8_t *arg1_signature, + size_t arg2_signature_size, + size_t *arg3_signature_length); +#define psa_sign_hash_complete(arg0_operation, arg1_signature, arg2_signature_size, arg3_signature_length) \ + mbedtls_test_wrap_psa_sign_hash_complete(arg0_operation, arg1_signature, arg2_signature_size, arg3_signature_length) + +psa_status_t mbedtls_test_wrap_psa_sign_hash_start( + psa_sign_hash_interruptible_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg, + const uint8_t *arg3_hash, + size_t arg4_hash_length); +#define psa_sign_hash_start(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length) \ + mbedtls_test_wrap_psa_sign_hash_start(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length) + +psa_status_t mbedtls_test_wrap_psa_sign_message( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_signature, + size_t arg5_signature_size, + size_t *arg6_signature_length); +#define psa_sign_message(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_size, arg6_signature_length) \ + mbedtls_test_wrap_psa_sign_message(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_size, arg6_signature_length) + +psa_status_t mbedtls_test_wrap_psa_verify_hash( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_hash, + size_t arg3_hash_length, + const uint8_t *arg4_signature, + size_t arg5_signature_length); +#define psa_verify_hash(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_length) \ + mbedtls_test_wrap_psa_verify_hash(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_length) + +psa_status_t mbedtls_test_wrap_psa_verify_hash_abort( + psa_verify_hash_interruptible_operation_t *arg0_operation); +#define psa_verify_hash_abort(arg0_operation) \ + mbedtls_test_wrap_psa_verify_hash_abort(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_verify_hash_complete( + psa_verify_hash_interruptible_operation_t *arg0_operation); +#define psa_verify_hash_complete(arg0_operation) \ + mbedtls_test_wrap_psa_verify_hash_complete(arg0_operation) + +psa_status_t mbedtls_test_wrap_psa_verify_hash_start( + psa_verify_hash_interruptible_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg, + const uint8_t *arg3_hash, + size_t arg4_hash_length, + const uint8_t *arg5_signature, + size_t arg6_signature_length); +#define psa_verify_hash_start(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length, arg5_signature, arg6_signature_length) \ + mbedtls_test_wrap_psa_verify_hash_start(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length, arg5_signature, arg6_signature_length) + +psa_status_t mbedtls_test_wrap_psa_verify_message( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_signature, + size_t arg5_signature_length); +#define psa_verify_message(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length) \ + mbedtls_test_wrap_psa_verify_message(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length) + +#endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) */ + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_PSA_TEST_WRAPPERS_H */ + +/* End of automatically generated file. */ diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c new file mode 100644 index 000000000..f25f1aa9b --- /dev/null +++ b/src/psa_test_wrappers.c @@ -0,0 +1,973 @@ +/* Automatically generated by generate_psa_wrappers.py, do not edit! */ + +/* Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#include + +#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) + +#include + +#include +#include + +/* Wrapper for mbedtls_psa_inject_entropy */ +#if defined(MBEDTLS_PSA_INJECT_ENTROPY) +psa_status_t mbedtls_test_wrap_mbedtls_psa_inject_entropy( + const uint8_t *arg0_seed, + size_t arg1_seed_size) +{ + psa_status_t status = (mbedtls_psa_inject_entropy)(arg0_seed, arg1_seed_size); + return status; +} +#endif /* defined(MBEDTLS_PSA_INJECT_ENTROPY) */ + +/* Wrapper for mbedtls_psa_platform_get_builtin_key */ +#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) +psa_status_t mbedtls_test_wrap_mbedtls_psa_platform_get_builtin_key( + mbedtls_svc_key_id_t arg0_key_id, + psa_key_lifetime_t *arg1_lifetime, + psa_drv_slot_number_t *arg2_slot_number) +{ + psa_status_t status = (mbedtls_psa_platform_get_builtin_key)(arg0_key_id, arg1_lifetime, arg2_slot_number); + return status; +} +#endif /* defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) */ + +/* Wrapper for mbedtls_psa_register_se_key */ +#if defined(MBEDTLS_PSA_CRYPTO_SE_C) +psa_status_t mbedtls_test_wrap_mbedtls_psa_register_se_key( + const psa_key_attributes_t *arg0_attributes) +{ + psa_status_t status = (mbedtls_psa_register_se_key)(arg0_attributes); + return status; +} +#endif /* defined(MBEDTLS_PSA_CRYPTO_SE_C) */ + +/* Wrapper for psa_aead_abort */ +psa_status_t mbedtls_test_wrap_psa_aead_abort( + psa_aead_operation_t *arg0_operation) +{ + psa_status_t status = (psa_aead_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_aead_decrypt */ +psa_status_t mbedtls_test_wrap_psa_aead_decrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_nonce, + size_t arg3_nonce_length, + const uint8_t *arg4_additional_data, + size_t arg5_additional_data_length, + const uint8_t *arg6_ciphertext, + size_t arg7_ciphertext_length, + uint8_t *arg8_plaintext, + size_t arg9_plaintext_size, + size_t *arg10_plaintext_length) +{ + psa_status_t status = (psa_aead_decrypt)(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_ciphertext, arg7_ciphertext_length, arg8_plaintext, arg9_plaintext_size, arg10_plaintext_length); + return status; +} + +/* Wrapper for psa_aead_decrypt_setup */ +psa_status_t mbedtls_test_wrap_psa_aead_decrypt_setup( + psa_aead_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg) +{ + psa_status_t status = (psa_aead_decrypt_setup)(arg0_operation, arg1_key, arg2_alg); + return status; +} + +/* Wrapper for psa_aead_encrypt */ +psa_status_t mbedtls_test_wrap_psa_aead_encrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_nonce, + size_t arg3_nonce_length, + const uint8_t *arg4_additional_data, + size_t arg5_additional_data_length, + const uint8_t *arg6_plaintext, + size_t arg7_plaintext_length, + uint8_t *arg8_ciphertext, + size_t arg9_ciphertext_size, + size_t *arg10_ciphertext_length) +{ + psa_status_t status = (psa_aead_encrypt)(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_plaintext, arg7_plaintext_length, arg8_ciphertext, arg9_ciphertext_size, arg10_ciphertext_length); + return status; +} + +/* Wrapper for psa_aead_encrypt_setup */ +psa_status_t mbedtls_test_wrap_psa_aead_encrypt_setup( + psa_aead_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg) +{ + psa_status_t status = (psa_aead_encrypt_setup)(arg0_operation, arg1_key, arg2_alg); + return status; +} + +/* Wrapper for psa_aead_finish */ +psa_status_t mbedtls_test_wrap_psa_aead_finish( + psa_aead_operation_t *arg0_operation, + uint8_t *arg1_ciphertext, + size_t arg2_ciphertext_size, + size_t *arg3_ciphertext_length, + uint8_t *arg4_tag, + size_t arg5_tag_size, + size_t *arg6_tag_length) +{ + psa_status_t status = (psa_aead_finish)(arg0_operation, arg1_ciphertext, arg2_ciphertext_size, arg3_ciphertext_length, arg4_tag, arg5_tag_size, arg6_tag_length); + return status; +} + +/* Wrapper for psa_aead_generate_nonce */ +psa_status_t mbedtls_test_wrap_psa_aead_generate_nonce( + psa_aead_operation_t *arg0_operation, + uint8_t *arg1_nonce, + size_t arg2_nonce_size, + size_t *arg3_nonce_length) +{ + psa_status_t status = (psa_aead_generate_nonce)(arg0_operation, arg1_nonce, arg2_nonce_size, arg3_nonce_length); + return status; +} + +/* Wrapper for psa_aead_set_lengths */ +psa_status_t mbedtls_test_wrap_psa_aead_set_lengths( + psa_aead_operation_t *arg0_operation, + size_t arg1_ad_length, + size_t arg2_plaintext_length) +{ + psa_status_t status = (psa_aead_set_lengths)(arg0_operation, arg1_ad_length, arg2_plaintext_length); + return status; +} + +/* Wrapper for psa_aead_set_nonce */ +psa_status_t mbedtls_test_wrap_psa_aead_set_nonce( + psa_aead_operation_t *arg0_operation, + const uint8_t *arg1_nonce, + size_t arg2_nonce_length) +{ + psa_status_t status = (psa_aead_set_nonce)(arg0_operation, arg1_nonce, arg2_nonce_length); + return status; +} + +/* Wrapper for psa_aead_update */ +psa_status_t mbedtls_test_wrap_psa_aead_update( + psa_aead_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length, + uint8_t *arg3_output, + size_t arg4_output_size, + size_t *arg5_output_length) +{ + psa_status_t status = (psa_aead_update)(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length); + return status; +} + +/* Wrapper for psa_aead_update_ad */ +psa_status_t mbedtls_test_wrap_psa_aead_update_ad( + psa_aead_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length) +{ + psa_status_t status = (psa_aead_update_ad)(arg0_operation, arg1_input, arg2_input_length); + return status; +} + +/* Wrapper for psa_aead_verify */ +psa_status_t mbedtls_test_wrap_psa_aead_verify( + psa_aead_operation_t *arg0_operation, + uint8_t *arg1_plaintext, + size_t arg2_plaintext_size, + size_t *arg3_plaintext_length, + const uint8_t *arg4_tag, + size_t arg5_tag_length) +{ + psa_status_t status = (psa_aead_verify)(arg0_operation, arg1_plaintext, arg2_plaintext_size, arg3_plaintext_length, arg4_tag, arg5_tag_length); + return status; +} + +/* Wrapper for psa_asymmetric_decrypt */ +psa_status_t mbedtls_test_wrap_psa_asymmetric_decrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_salt, + size_t arg5_salt_length, + uint8_t *arg6_output, + size_t arg7_output_size, + size_t *arg8_output_length) +{ + psa_status_t status = (psa_asymmetric_decrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length); + return status; +} + +/* Wrapper for psa_asymmetric_encrypt */ +psa_status_t mbedtls_test_wrap_psa_asymmetric_encrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_salt, + size_t arg5_salt_length, + uint8_t *arg6_output, + size_t arg7_output_size, + size_t *arg8_output_length) +{ + psa_status_t status = (psa_asymmetric_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length); + return status; +} + +/* Wrapper for psa_cipher_abort */ +psa_status_t mbedtls_test_wrap_psa_cipher_abort( + psa_cipher_operation_t *arg0_operation) +{ + psa_status_t status = (psa_cipher_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_cipher_decrypt */ +psa_status_t mbedtls_test_wrap_psa_cipher_decrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_output, + size_t arg5_output_size, + size_t *arg6_output_length) +{ + psa_status_t status = (psa_cipher_decrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); + return status; +} + +/* Wrapper for psa_cipher_decrypt_setup */ +psa_status_t mbedtls_test_wrap_psa_cipher_decrypt_setup( + psa_cipher_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg) +{ + psa_status_t status = (psa_cipher_decrypt_setup)(arg0_operation, arg1_key, arg2_alg); + return status; +} + +/* Wrapper for psa_cipher_encrypt */ +psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_output, + size_t arg5_output_size, + size_t *arg6_output_length) +{ + psa_status_t status = (psa_cipher_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); + return status; +} + +/* Wrapper for psa_cipher_encrypt_setup */ +psa_status_t mbedtls_test_wrap_psa_cipher_encrypt_setup( + psa_cipher_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg) +{ + psa_status_t status = (psa_cipher_encrypt_setup)(arg0_operation, arg1_key, arg2_alg); + return status; +} + +/* Wrapper for psa_cipher_finish */ +psa_status_t mbedtls_test_wrap_psa_cipher_finish( + psa_cipher_operation_t *arg0_operation, + uint8_t *arg1_output, + size_t arg2_output_size, + size_t *arg3_output_length) +{ + psa_status_t status = (psa_cipher_finish)(arg0_operation, arg1_output, arg2_output_size, arg3_output_length); + return status; +} + +/* Wrapper for psa_cipher_generate_iv */ +psa_status_t mbedtls_test_wrap_psa_cipher_generate_iv( + psa_cipher_operation_t *arg0_operation, + uint8_t *arg1_iv, + size_t arg2_iv_size, + size_t *arg3_iv_length) +{ + psa_status_t status = (psa_cipher_generate_iv)(arg0_operation, arg1_iv, arg2_iv_size, arg3_iv_length); + return status; +} + +/* Wrapper for psa_cipher_set_iv */ +psa_status_t mbedtls_test_wrap_psa_cipher_set_iv( + psa_cipher_operation_t *arg0_operation, + const uint8_t *arg1_iv, + size_t arg2_iv_length) +{ + psa_status_t status = (psa_cipher_set_iv)(arg0_operation, arg1_iv, arg2_iv_length); + return status; +} + +/* Wrapper for psa_cipher_update */ +psa_status_t mbedtls_test_wrap_psa_cipher_update( + psa_cipher_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length, + uint8_t *arg3_output, + size_t arg4_output_size, + size_t *arg5_output_length) +{ + psa_status_t status = (psa_cipher_update)(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length); + return status; +} + +/* Wrapper for psa_copy_key */ +psa_status_t mbedtls_test_wrap_psa_copy_key( + mbedtls_svc_key_id_t arg0_source_key, + const psa_key_attributes_t *arg1_attributes, + mbedtls_svc_key_id_t *arg2_target_key) +{ + psa_status_t status = (psa_copy_key)(arg0_source_key, arg1_attributes, arg2_target_key); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_cipher_suite */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_cipher_suite( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + psa_pake_cipher_suite_t *arg1_cipher_suite) +{ + psa_status_t status = (psa_crypto_driver_pake_get_cipher_suite)(arg0_inputs, arg1_cipher_suite); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_password */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_password( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + uint8_t *arg1_buffer, + size_t arg2_buffer_size, + size_t *arg3_buffer_length) +{ + psa_status_t status = (psa_crypto_driver_pake_get_password)(arg0_inputs, arg1_buffer, arg2_buffer_size, arg3_buffer_length); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_password_len */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_password_len( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + size_t *arg1_password_len) +{ + psa_status_t status = (psa_crypto_driver_pake_get_password_len)(arg0_inputs, arg1_password_len); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_peer */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_peer( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + uint8_t *arg1_peer_id, + size_t arg2_peer_id_size, + size_t *arg3_peer_id_length) +{ + psa_status_t status = (psa_crypto_driver_pake_get_peer)(arg0_inputs, arg1_peer_id, arg2_peer_id_size, arg3_peer_id_length); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_peer_len */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_peer_len( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + size_t *arg1_peer_len) +{ + psa_status_t status = (psa_crypto_driver_pake_get_peer_len)(arg0_inputs, arg1_peer_len); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_user */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_user( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + uint8_t *arg1_user_id, + size_t arg2_user_id_size, + size_t *arg3_user_id_len) +{ + psa_status_t status = (psa_crypto_driver_pake_get_user)(arg0_inputs, arg1_user_id, arg2_user_id_size, arg3_user_id_len); + return status; +} + +/* Wrapper for psa_crypto_driver_pake_get_user_len */ +psa_status_t mbedtls_test_wrap_psa_crypto_driver_pake_get_user_len( + const psa_crypto_driver_pake_inputs_t *arg0_inputs, + size_t *arg1_user_len) +{ + psa_status_t status = (psa_crypto_driver_pake_get_user_len)(arg0_inputs, arg1_user_len); + return status; +} + +/* Wrapper for psa_crypto_init */ +psa_status_t mbedtls_test_wrap_psa_crypto_init(void) +{ + psa_status_t status = (psa_crypto_init)(); + return status; +} + +/* Wrapper for psa_destroy_key */ +psa_status_t mbedtls_test_wrap_psa_destroy_key( + mbedtls_svc_key_id_t arg0_key) +{ + psa_status_t status = (psa_destroy_key)(arg0_key); + return status; +} + +/* Wrapper for psa_export_key */ +psa_status_t mbedtls_test_wrap_psa_export_key( + mbedtls_svc_key_id_t arg0_key, + uint8_t *arg1_data, + size_t arg2_data_size, + size_t *arg3_data_length) +{ + psa_status_t status = (psa_export_key)(arg0_key, arg1_data, arg2_data_size, arg3_data_length); + return status; +} + +/* Wrapper for psa_export_public_key */ +psa_status_t mbedtls_test_wrap_psa_export_public_key( + mbedtls_svc_key_id_t arg0_key, + uint8_t *arg1_data, + size_t arg2_data_size, + size_t *arg3_data_length) +{ + psa_status_t status = (psa_export_public_key)(arg0_key, arg1_data, arg2_data_size, arg3_data_length); + return status; +} + +/* Wrapper for psa_generate_key */ +psa_status_t mbedtls_test_wrap_psa_generate_key( + const psa_key_attributes_t *arg0_attributes, + mbedtls_svc_key_id_t *arg1_key) +{ + psa_status_t status = (psa_generate_key)(arg0_attributes, arg1_key); + return status; +} + +/* Wrapper for psa_generate_random */ +psa_status_t mbedtls_test_wrap_psa_generate_random( + uint8_t *arg0_output, + size_t arg1_output_size) +{ + psa_status_t status = (psa_generate_random)(arg0_output, arg1_output_size); + return status; +} + +/* Wrapper for psa_get_key_attributes */ +psa_status_t mbedtls_test_wrap_psa_get_key_attributes( + mbedtls_svc_key_id_t arg0_key, + psa_key_attributes_t *arg1_attributes) +{ + psa_status_t status = (psa_get_key_attributes)(arg0_key, arg1_attributes); + return status; +} + +/* Wrapper for psa_hash_abort */ +psa_status_t mbedtls_test_wrap_psa_hash_abort( + psa_hash_operation_t *arg0_operation) +{ + psa_status_t status = (psa_hash_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_hash_clone */ +psa_status_t mbedtls_test_wrap_psa_hash_clone( + const psa_hash_operation_t *arg0_source_operation, + psa_hash_operation_t *arg1_target_operation) +{ + psa_status_t status = (psa_hash_clone)(arg0_source_operation, arg1_target_operation); + return status; +} + +/* Wrapper for psa_hash_compare */ +psa_status_t mbedtls_test_wrap_psa_hash_compare( + psa_algorithm_t arg0_alg, + const uint8_t *arg1_input, + size_t arg2_input_length, + const uint8_t *arg3_hash, + size_t arg4_hash_length) +{ + psa_status_t status = (psa_hash_compare)(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_length); + return status; +} + +/* Wrapper for psa_hash_compute */ +psa_status_t mbedtls_test_wrap_psa_hash_compute( + psa_algorithm_t arg0_alg, + const uint8_t *arg1_input, + size_t arg2_input_length, + uint8_t *arg3_hash, + size_t arg4_hash_size, + size_t *arg5_hash_length) +{ + psa_status_t status = (psa_hash_compute)(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_size, arg5_hash_length); + return status; +} + +/* Wrapper for psa_hash_finish */ +psa_status_t mbedtls_test_wrap_psa_hash_finish( + psa_hash_operation_t *arg0_operation, + uint8_t *arg1_hash, + size_t arg2_hash_size, + size_t *arg3_hash_length) +{ + psa_status_t status = (psa_hash_finish)(arg0_operation, arg1_hash, arg2_hash_size, arg3_hash_length); + return status; +} + +/* Wrapper for psa_hash_setup */ +psa_status_t mbedtls_test_wrap_psa_hash_setup( + psa_hash_operation_t *arg0_operation, + psa_algorithm_t arg1_alg) +{ + psa_status_t status = (psa_hash_setup)(arg0_operation, arg1_alg); + return status; +} + +/* Wrapper for psa_hash_update */ +psa_status_t mbedtls_test_wrap_psa_hash_update( + psa_hash_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length) +{ + psa_status_t status = (psa_hash_update)(arg0_operation, arg1_input, arg2_input_length); + return status; +} + +/* Wrapper for psa_hash_verify */ +psa_status_t mbedtls_test_wrap_psa_hash_verify( + psa_hash_operation_t *arg0_operation, + const uint8_t *arg1_hash, + size_t arg2_hash_length) +{ + psa_status_t status = (psa_hash_verify)(arg0_operation, arg1_hash, arg2_hash_length); + return status; +} + +/* Wrapper for psa_import_key */ +psa_status_t mbedtls_test_wrap_psa_import_key( + const psa_key_attributes_t *arg0_attributes, + const uint8_t *arg1_data, + size_t arg2_data_length, + mbedtls_svc_key_id_t *arg3_key) +{ + psa_status_t status = (psa_import_key)(arg0_attributes, arg1_data, arg2_data_length, arg3_key); + return status; +} + +/* Wrapper for psa_key_derivation_abort */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_abort( + psa_key_derivation_operation_t *arg0_operation) +{ + psa_status_t status = (psa_key_derivation_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_key_derivation_get_capacity */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_get_capacity( + const psa_key_derivation_operation_t *arg0_operation, + size_t *arg1_capacity) +{ + psa_status_t status = (psa_key_derivation_get_capacity)(arg0_operation, arg1_capacity); + return status; +} + +/* Wrapper for psa_key_derivation_input_bytes */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_input_bytes( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + const uint8_t *arg2_data, + size_t arg3_data_length) +{ + psa_status_t status = (psa_key_derivation_input_bytes)(arg0_operation, arg1_step, arg2_data, arg3_data_length); + return status; +} + +/* Wrapper for psa_key_derivation_input_integer */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_input_integer( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + uint64_t arg2_value) +{ + psa_status_t status = (psa_key_derivation_input_integer)(arg0_operation, arg1_step, arg2_value); + return status; +} + +/* Wrapper for psa_key_derivation_input_key */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_input_key( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + mbedtls_svc_key_id_t arg2_key) +{ + psa_status_t status = (psa_key_derivation_input_key)(arg0_operation, arg1_step, arg2_key); + return status; +} + +/* Wrapper for psa_key_derivation_key_agreement */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_key_agreement( + psa_key_derivation_operation_t *arg0_operation, + psa_key_derivation_step_t arg1_step, + mbedtls_svc_key_id_t arg2_private_key, + const uint8_t *arg3_peer_key, + size_t arg4_peer_key_length) +{ + psa_status_t status = (psa_key_derivation_key_agreement)(arg0_operation, arg1_step, arg2_private_key, arg3_peer_key, arg4_peer_key_length); + return status; +} + +/* Wrapper for psa_key_derivation_output_bytes */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_output_bytes( + psa_key_derivation_operation_t *arg0_operation, + uint8_t *arg1_output, + size_t arg2_output_length) +{ + psa_status_t status = (psa_key_derivation_output_bytes)(arg0_operation, arg1_output, arg2_output_length); + return status; +} + +/* Wrapper for psa_key_derivation_output_key */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_output_key( + const psa_key_attributes_t *arg0_attributes, + psa_key_derivation_operation_t *arg1_operation, + mbedtls_svc_key_id_t *arg2_key) +{ + psa_status_t status = (psa_key_derivation_output_key)(arg0_attributes, arg1_operation, arg2_key); + return status; +} + +/* Wrapper for psa_key_derivation_set_capacity */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_set_capacity( + psa_key_derivation_operation_t *arg0_operation, + size_t arg1_capacity) +{ + psa_status_t status = (psa_key_derivation_set_capacity)(arg0_operation, arg1_capacity); + return status; +} + +/* Wrapper for psa_key_derivation_setup */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_setup( + psa_key_derivation_operation_t *arg0_operation, + psa_algorithm_t arg1_alg) +{ + psa_status_t status = (psa_key_derivation_setup)(arg0_operation, arg1_alg); + return status; +} + +/* Wrapper for psa_mac_abort */ +psa_status_t mbedtls_test_wrap_psa_mac_abort( + psa_mac_operation_t *arg0_operation) +{ + psa_status_t status = (psa_mac_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_mac_compute */ +psa_status_t mbedtls_test_wrap_psa_mac_compute( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_mac, + size_t arg5_mac_size, + size_t *arg6_mac_length) +{ + psa_status_t status = (psa_mac_compute)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_size, arg6_mac_length); + return status; +} + +/* Wrapper for psa_mac_sign_finish */ +psa_status_t mbedtls_test_wrap_psa_mac_sign_finish( + psa_mac_operation_t *arg0_operation, + uint8_t *arg1_mac, + size_t arg2_mac_size, + size_t *arg3_mac_length) +{ + psa_status_t status = (psa_mac_sign_finish)(arg0_operation, arg1_mac, arg2_mac_size, arg3_mac_length); + return status; +} + +/* Wrapper for psa_mac_sign_setup */ +psa_status_t mbedtls_test_wrap_psa_mac_sign_setup( + psa_mac_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg) +{ + psa_status_t status = (psa_mac_sign_setup)(arg0_operation, arg1_key, arg2_alg); + return status; +} + +/* Wrapper for psa_mac_update */ +psa_status_t mbedtls_test_wrap_psa_mac_update( + psa_mac_operation_t *arg0_operation, + const uint8_t *arg1_input, + size_t arg2_input_length) +{ + psa_status_t status = (psa_mac_update)(arg0_operation, arg1_input, arg2_input_length); + return status; +} + +/* Wrapper for psa_mac_verify */ +psa_status_t mbedtls_test_wrap_psa_mac_verify( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_mac, + size_t arg5_mac_length) +{ + psa_status_t status = (psa_mac_verify)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_length); + return status; +} + +/* Wrapper for psa_mac_verify_finish */ +psa_status_t mbedtls_test_wrap_psa_mac_verify_finish( + psa_mac_operation_t *arg0_operation, + const uint8_t *arg1_mac, + size_t arg2_mac_length) +{ + psa_status_t status = (psa_mac_verify_finish)(arg0_operation, arg1_mac, arg2_mac_length); + return status; +} + +/* Wrapper for psa_mac_verify_setup */ +psa_status_t mbedtls_test_wrap_psa_mac_verify_setup( + psa_mac_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg) +{ + psa_status_t status = (psa_mac_verify_setup)(arg0_operation, arg1_key, arg2_alg); + return status; +} + +/* Wrapper for psa_pake_abort */ +psa_status_t mbedtls_test_wrap_psa_pake_abort( + psa_pake_operation_t *arg0_operation) +{ + psa_status_t status = (psa_pake_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_pake_get_implicit_key */ +psa_status_t mbedtls_test_wrap_psa_pake_get_implicit_key( + psa_pake_operation_t *arg0_operation, + psa_key_derivation_operation_t *arg1_output) +{ + psa_status_t status = (psa_pake_get_implicit_key)(arg0_operation, arg1_output); + return status; +} + +/* Wrapper for psa_pake_input */ +psa_status_t mbedtls_test_wrap_psa_pake_input( + psa_pake_operation_t *arg0_operation, + psa_pake_step_t arg1_step, + const uint8_t *arg2_input, + size_t arg3_input_length) +{ + psa_status_t status = (psa_pake_input)(arg0_operation, arg1_step, arg2_input, arg3_input_length); + return status; +} + +/* Wrapper for psa_pake_output */ +psa_status_t mbedtls_test_wrap_psa_pake_output( + psa_pake_operation_t *arg0_operation, + psa_pake_step_t arg1_step, + uint8_t *arg2_output, + size_t arg3_output_size, + size_t *arg4_output_length) +{ + psa_status_t status = (psa_pake_output)(arg0_operation, arg1_step, arg2_output, arg3_output_size, arg4_output_length); + return status; +} + +/* Wrapper for psa_pake_set_password_key */ +psa_status_t mbedtls_test_wrap_psa_pake_set_password_key( + psa_pake_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_password) +{ + psa_status_t status = (psa_pake_set_password_key)(arg0_operation, arg1_password); + return status; +} + +/* Wrapper for psa_pake_set_peer */ +psa_status_t mbedtls_test_wrap_psa_pake_set_peer( + psa_pake_operation_t *arg0_operation, + const uint8_t *arg1_peer_id, + size_t arg2_peer_id_len) +{ + psa_status_t status = (psa_pake_set_peer)(arg0_operation, arg1_peer_id, arg2_peer_id_len); + return status; +} + +/* Wrapper for psa_pake_set_role */ +psa_status_t mbedtls_test_wrap_psa_pake_set_role( + psa_pake_operation_t *arg0_operation, + psa_pake_role_t arg1_role) +{ + psa_status_t status = (psa_pake_set_role)(arg0_operation, arg1_role); + return status; +} + +/* Wrapper for psa_pake_set_user */ +psa_status_t mbedtls_test_wrap_psa_pake_set_user( + psa_pake_operation_t *arg0_operation, + const uint8_t *arg1_user_id, + size_t arg2_user_id_len) +{ + psa_status_t status = (psa_pake_set_user)(arg0_operation, arg1_user_id, arg2_user_id_len); + return status; +} + +/* Wrapper for psa_pake_setup */ +psa_status_t mbedtls_test_wrap_psa_pake_setup( + psa_pake_operation_t *arg0_operation, + const psa_pake_cipher_suite_t *arg1_cipher_suite) +{ + psa_status_t status = (psa_pake_setup)(arg0_operation, arg1_cipher_suite); + return status; +} + +/* Wrapper for psa_purge_key */ +psa_status_t mbedtls_test_wrap_psa_purge_key( + mbedtls_svc_key_id_t arg0_key) +{ + psa_status_t status = (psa_purge_key)(arg0_key); + return status; +} + +/* Wrapper for psa_raw_key_agreement */ +psa_status_t mbedtls_test_wrap_psa_raw_key_agreement( + psa_algorithm_t arg0_alg, + mbedtls_svc_key_id_t arg1_private_key, + const uint8_t *arg2_peer_key, + size_t arg3_peer_key_length, + uint8_t *arg4_output, + size_t arg5_output_size, + size_t *arg6_output_length) +{ + psa_status_t status = (psa_raw_key_agreement)(arg0_alg, arg1_private_key, arg2_peer_key, arg3_peer_key_length, arg4_output, arg5_output_size, arg6_output_length); + return status; +} + +/* Wrapper for psa_sign_hash */ +psa_status_t mbedtls_test_wrap_psa_sign_hash( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_hash, + size_t arg3_hash_length, + uint8_t *arg4_signature, + size_t arg5_signature_size, + size_t *arg6_signature_length) +{ + psa_status_t status = (psa_sign_hash)(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_size, arg6_signature_length); + return status; +} + +/* Wrapper for psa_sign_hash_abort */ +psa_status_t mbedtls_test_wrap_psa_sign_hash_abort( + psa_sign_hash_interruptible_operation_t *arg0_operation) +{ + psa_status_t status = (psa_sign_hash_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_sign_hash_complete */ +psa_status_t mbedtls_test_wrap_psa_sign_hash_complete( + psa_sign_hash_interruptible_operation_t *arg0_operation, + uint8_t *arg1_signature, + size_t arg2_signature_size, + size_t *arg3_signature_length) +{ + psa_status_t status = (psa_sign_hash_complete)(arg0_operation, arg1_signature, arg2_signature_size, arg3_signature_length); + return status; +} + +/* Wrapper for psa_sign_hash_start */ +psa_status_t mbedtls_test_wrap_psa_sign_hash_start( + psa_sign_hash_interruptible_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg, + const uint8_t *arg3_hash, + size_t arg4_hash_length) +{ + psa_status_t status = (psa_sign_hash_start)(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length); + return status; +} + +/* Wrapper for psa_sign_message */ +psa_status_t mbedtls_test_wrap_psa_sign_message( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + uint8_t *arg4_signature, + size_t arg5_signature_size, + size_t *arg6_signature_length) +{ + psa_status_t status = (psa_sign_message)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_size, arg6_signature_length); + return status; +} + +/* Wrapper for psa_verify_hash */ +psa_status_t mbedtls_test_wrap_psa_verify_hash( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_hash, + size_t arg3_hash_length, + const uint8_t *arg4_signature, + size_t arg5_signature_length) +{ + psa_status_t status = (psa_verify_hash)(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_length); + return status; +} + +/* Wrapper for psa_verify_hash_abort */ +psa_status_t mbedtls_test_wrap_psa_verify_hash_abort( + psa_verify_hash_interruptible_operation_t *arg0_operation) +{ + psa_status_t status = (psa_verify_hash_abort)(arg0_operation); + return status; +} + +/* Wrapper for psa_verify_hash_complete */ +psa_status_t mbedtls_test_wrap_psa_verify_hash_complete( + psa_verify_hash_interruptible_operation_t *arg0_operation) +{ + psa_status_t status = (psa_verify_hash_complete)(arg0_operation); + return status; +} + +/* Wrapper for psa_verify_hash_start */ +psa_status_t mbedtls_test_wrap_psa_verify_hash_start( + psa_verify_hash_interruptible_operation_t *arg0_operation, + mbedtls_svc_key_id_t arg1_key, + psa_algorithm_t arg2_alg, + const uint8_t *arg3_hash, + size_t arg4_hash_length, + const uint8_t *arg5_signature, + size_t arg6_signature_length) +{ + psa_status_t status = (psa_verify_hash_start)(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length, arg5_signature, arg6_signature_length); + return status; +} + +/* Wrapper for psa_verify_message */ +psa_status_t mbedtls_test_wrap_psa_verify_message( + mbedtls_svc_key_id_t arg0_key, + psa_algorithm_t arg1_alg, + const uint8_t *arg2_input, + size_t arg3_input_length, + const uint8_t *arg4_signature, + size_t arg5_signature_length) +{ + psa_status_t status = (psa_verify_message)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length); + return status; +} + +#endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) */ + +/* End of automatically generated file. */ From e106e87d9b42aa1d0d55df7c414721f6a513d54d Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Jan 2024 16:44:16 +0100 Subject: [PATCH 20/46] Enable generated PSA wrappers Code in unit tests (`tests/suites/*.function`) and in test support code (`tests/src/**.c`) will now go through the wrapper functions when they call a PSA API function and `MBEDTLS_TEST_HOOKS` is enabled. Signed-off-by: Gilles Peskine --- include/test/psa_crypto_helpers.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/test/psa_crypto_helpers.h b/include/test/psa_crypto_helpers.h index 41b7752be..96a8c1c82 100644 --- a/include/test/psa_crypto_helpers.h +++ b/include/test/psa_crypto_helpers.h @@ -16,6 +16,8 @@ #include #endif +#include "test/psa_test_wrappers.h" + #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) #include "test/psa_memory_poisoning_wrappers.h" From 1539fb25514ecae2c0e797912963ff929560b197 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Jan 2024 16:59:28 +0100 Subject: [PATCH 21/46] Update generated PSA wrappers Signed-off-by: Gilles Peskine --- include/test/psa_test_wrappers.h | 1 + src/psa_test_wrappers.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/test/psa_test_wrappers.h b/include/test/psa_test_wrappers.h index 18417800c..bd673b80b 100644 --- a/include/test/psa_test_wrappers.h +++ b/include/test/psa_test_wrappers.h @@ -17,6 +17,7 @@ extern "C" { #include +#include #include #include diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index f25f1aa9b..c26835fbf 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -10,6 +10,7 @@ #include +#include #include #include @@ -265,7 +266,11 @@ psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( size_t arg5_output_size, size_t *arg6_output_length) { + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); psa_status_t status = (psa_cipher_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); return status; } From f438c616cb818c9d84a0196612c6684c4a912b92 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Jan 2024 17:11:54 +0100 Subject: [PATCH 22/46] Remove the manually written poisoning wrapper This fixes the build with ASan + MBEDTLS_TEST_HOOKS. Signed-off-by: Gilles Peskine --- include/test/psa_memory_poisoning_wrappers.h | 17 +++++---------- src/psa_memory_poisoning_wrappers.c | 22 -------------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/include/test/psa_memory_poisoning_wrappers.h b/include/test/psa_memory_poisoning_wrappers.h index 0052c2fae..3f30b65c0 100644 --- a/include/test/psa_memory_poisoning_wrappers.h +++ b/include/test/psa_memory_poisoning_wrappers.h @@ -1,8 +1,11 @@ -/** Memory poisoning wrappers for PSA functions. +/** Support for memory poisoning wrappers for PSA functions. * - * These wrappers poison the input and output buffers of each function + * The wrappers poison the input and output buffers of each function * before calling it, to ensure that it does not access the buffers * except by calling the approved buffer-copying functions. + * + * This header declares support functions. The wrappers themselves are + * decalred in the automatically generated file `test/psa_test_wrappers.h`. */ /* * Copyright The Mbed TLS Contributors @@ -32,16 +35,6 @@ void mbedtls_poison_test_hooks_setup(void); */ void mbedtls_poison_test_hooks_teardown(void); -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); - -#define psa_cipher_encrypt(...) wrap_psa_cipher_encrypt(__VA_ARGS__) - #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_TEST_MEMORY_CAN_POISON */ #endif /* PSA_MEMORY_POISONING_WRAPPERS_H */ diff --git a/src/psa_memory_poisoning_wrappers.c b/src/psa_memory_poisoning_wrappers.c index a53e875d4..05cba18ee 100644 --- a/src/psa_memory_poisoning_wrappers.c +++ b/src/psa_memory_poisoning_wrappers.c @@ -27,27 +27,5 @@ void mbedtls_poison_test_hooks_teardown(void) 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_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); - return status; -} - #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C && MBEDTLS_TEST_MEMORY_CAN_POISON */ From 0da9436691760f9e84505d515a4188427a03cd53 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Jan 2024 20:33:29 +0100 Subject: [PATCH 23/46] PSA wrappers: don't poison buffers when buffer copying is disabled Signed-off-by: Gilles Peskine --- src/psa_test_wrappers.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index c26835fbf..f3fb852e1 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -266,11 +266,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( size_t arg5_output_size, size_t *arg6_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 1636b34b78bb37354dcf16f123a793130d132dfa Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 4 Jan 2024 20:51:38 +0100 Subject: [PATCH 24/46] Disable PSA wrappers psa_collect_statuses builds `psa_collect_statuses.py` runs `make RECORD_PSA_STATUS_COVERAGE_LOG=1`, which builds with `RECORD_PSA_STATUS_COVERAGE_LOG`. In this mode, the build includes wrappers for PSA functions, which conflict with the newly introduced wrappers that are enabled whenever `MBEDTLS_TEST_HOOKS` is enabled. In the future, the collect-statuses mechanism should use the new generic wrapper mechanism. For the time being, keep the old wrappers and avoid the new wrappers when doing the collect-statuses build. Signed-off-by: Gilles Peskine --- include/test/psa_test_wrappers.h | 6 ++++-- src/psa_test_wrappers.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/test/psa_test_wrappers.h b/include/test/psa_test_wrappers.h index bd673b80b..86ead0a12 100644 --- a/include/test/psa_test_wrappers.h +++ b/include/test/psa_test_wrappers.h @@ -13,7 +13,8 @@ extern "C" { #include -#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) && \ + !defined(RECORD_PSA_STATUS_COVERAGE_LOG) #include @@ -709,7 +710,8 @@ psa_status_t mbedtls_test_wrap_psa_verify_message( #define psa_verify_message(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length) \ mbedtls_test_wrap_psa_verify_message(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length) -#endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) */ +#endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) && \ + !defined(RECORD_PSA_STATUS_COVERAGE_LOG) */ #ifdef __cplusplus } diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index f3fb852e1..3a3aaade9 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -6,7 +6,8 @@ #include -#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) && \ + !defined(RECORD_PSA_STATUS_COVERAGE_LOG) #include @@ -977,6 +978,7 @@ psa_status_t mbedtls_test_wrap_psa_verify_message( return status; } -#endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) */ +#endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_TEST_HOOKS) && \ + !defined(RECORD_PSA_STATUS_COVERAGE_LOG) */ /* End of automatically generated file. */ From a984c043eb7abb47c9fae1873969f04a05ee8e6a Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 17 Jan 2024 14:23:20 +0000 Subject: [PATCH 25/46] Change memory poisoning flag to a count This allows unusually-nested memory poisoning to work correctly, since it keeps track of whether any buffers are still poisoned, rather than just disabling poisoning at the first call to the UNPOISON() macro. Signed-off-by: David Horstmann --- include/test/memory.h | 6 +++--- src/test_memory.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/test/memory.h b/include/test/memory.h index e0437517d..181280f26 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -69,7 +69,7 @@ * unset in the test wrappers so that calls to PSA functions from the library * do not poison memory. */ -extern _Thread_local int mbedtls_test_memory_poisoning_enabled; +extern _Thread_local unsigned int mbedtls_test_memory_poisoning_count; /** Poison a memory area so that any attempt to read or write from it will * cause a runtime failure. @@ -79,7 +79,7 @@ extern _Thread_local int mbedtls_test_memory_poisoning_enabled; void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size); #define MBEDTLS_TEST_MEMORY_POISON(ptr, size) \ do { \ - mbedtls_test_memory_poisoning_enabled = 1; \ + mbedtls_test_memory_poisoning_count++; \ mbedtls_test_memory_poison(ptr, size); \ } while (0) @@ -94,7 +94,7 @@ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size); #define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \ do { \ mbedtls_test_memory_unpoison(ptr, size); \ - mbedtls_test_memory_poisoning_enabled = 0; \ + mbedtls_test_memory_poisoning_count--; \ } while (0) #else /* MBEDTLS_TEST_MEMORY_CAN_POISON */ diff --git a/src/test_memory.c b/src/test_memory.c index dbb7b20de..ac9dde616 100644 --- a/src/test_memory.c +++ b/src/test_memory.c @@ -20,7 +20,7 @@ #if defined(MBEDTLS_TEST_MEMORY_CAN_POISON) -_Thread_local int mbedtls_test_memory_poisoning_enabled = 0; +_Thread_local unsigned int mbedtls_test_memory_poisoning_count = 0; static void align_for_asan(const unsigned char **p_ptr, size_t *p_size) { @@ -39,7 +39,7 @@ static void align_for_asan(const unsigned char **p_ptr, size_t *p_size) void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size) { - if (!mbedtls_test_memory_poisoning_enabled) { + if (mbedtls_test_memory_poisoning_count == 0) { return; } if (size == 0) { From 0c7b149a7ac9da082fe3ac3df9419af41942ace6 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 17 Jan 2024 15:27:50 +0000 Subject: [PATCH 26/46] Add underflow check to UNPOISON counter decrement Make sure that extra UNPOISON calls do not cause the poisoning counter to underflow and wrap around. Memory that is unpoisoned multiple times should remain unpoisoned. Signed-off-by: David Horstmann --- include/test/memory.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/test/memory.h b/include/test/memory.h index 181280f26..20fd8d30a 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -94,7 +94,9 @@ void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size); #define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \ do { \ mbedtls_test_memory_unpoison(ptr, size); \ - mbedtls_test_memory_poisoning_count--; \ + if (mbedtls_test_memory_poisoning_count != 0) { \ + mbedtls_test_memory_poisoning_count--; \ + } \ } while (0) #else /* MBEDTLS_TEST_MEMORY_CAN_POISON */ From 1ec0fde9039dd2b3346c02a4aab49fdb0f53da36 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 23 Jan 2024 15:28:51 +0000 Subject: [PATCH 27/46] Generate poisoning in PAKE test wrappers Enable memory poisoning for all functions whose names start with 'psa_pake'. Regenerate the wrappers and commit the result. Signed-off-by: David Horstmann --- src/psa_test_wrappers.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 3a3aaade9..615a1b042 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -778,7 +778,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_input( const uint8_t *arg2_input, size_t arg3_input_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_pake_input)(arg0_operation, arg1_step, arg2_input, arg3_input_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -790,7 +796,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_output( size_t arg3_output_size, size_t *arg4_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_output, arg3_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_pake_output)(arg0_operation, arg1_step, arg2_output, arg3_output_size, arg4_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_output, arg3_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -809,7 +821,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_set_peer( const uint8_t *arg1_peer_id, size_t arg2_peer_id_len) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_peer_id, arg2_peer_id_len); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_pake_set_peer)(arg0_operation, arg1_peer_id, arg2_peer_id_len); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_peer_id, arg2_peer_id_len); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -828,7 +846,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_set_user( const uint8_t *arg1_user_id, size_t arg2_user_id_len) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_user_id, arg2_user_id_len); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_pake_set_user)(arg0_operation, arg1_user_id, arg2_user_id_len); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_user_id, arg2_user_id_len); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 0c8b658186505414ccb0512b275cee78ccf26d74 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 30 Jan 2024 12:25:35 +0000 Subject: [PATCH 28/46] Generate test wrappers Signed-off-by: Thomas Daubney --- src/psa_test_wrappers.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 3a3aaade9..460d4535f 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -873,7 +873,15 @@ psa_status_t mbedtls_test_wrap_psa_sign_hash( size_t arg5_signature_size, size_t *arg6_signature_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_hash, arg3_hash_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_sign_hash)(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_size, arg6_signature_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_hash, arg3_hash_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -918,7 +926,15 @@ psa_status_t mbedtls_test_wrap_psa_sign_message( size_t arg5_signature_size, size_t *arg6_signature_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_sign_message)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_size, arg6_signature_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -931,7 +947,15 @@ psa_status_t mbedtls_test_wrap_psa_verify_hash( const uint8_t *arg4_signature, size_t arg5_signature_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_hash, arg3_hash_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_verify_hash)(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_hash, arg3_hash_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -974,7 +998,15 @@ psa_status_t mbedtls_test_wrap_psa_verify_message( const uint8_t *arg4_signature, size_t arg5_signature_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_verify_message)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 5f18b3fd9d03ca8ac99d5a10d783c663aa41ea56 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 31 Jan 2024 14:38:15 +0000 Subject: [PATCH 29/46] Disable poisoning with PSA_CRYPTO_DRIVER_TEST This option causes nested calls to PSA functions, so is not compatible with memory poisoning as it currently stands. Signed-off-by: David Horstmann --- include/test/memory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/test/memory.h b/include/test/memory.h index 20fd8d30a..940d9e6ba 100644 --- a/include/test/memory.h +++ b/include/test/memory.h @@ -27,7 +27,8 @@ * Currently, only Asan (Address Sanitizer) is supported. */ #if defined(MBEDTLS_TEST_HAVE_ASAN) && \ - (__STDC_VERSION__ >= 201112L) + (__STDC_VERSION__ >= 201112L) && \ + !defined(PSA_CRYPTO_DRIVER_TEST) # define MBEDTLS_TEST_MEMORY_CAN_POISON #endif From 039ee99a2d7520ecc9d256bb6f728ca7606a1056 Mon Sep 17 00:00:00 2001 From: Ryan Everett Date: Thu, 25 Jan 2024 10:58:06 +0000 Subject: [PATCH 30/46] Generate test wrappers for key management Signed-off-by: Ryan Everett --- src/psa_test_wrappers.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 460d4535f..de3714d2c 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -267,15 +267,7 @@ psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( size_t arg5_output_size, size_t *arg6_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) - MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); - MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) - MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); - MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -435,7 +427,13 @@ psa_status_t mbedtls_test_wrap_psa_export_key( size_t arg2_data_size, size_t *arg3_data_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_data, arg2_data_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_export_key)(arg0_key, arg1_data, arg2_data_size, arg3_data_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_data, arg2_data_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -446,7 +444,13 @@ psa_status_t mbedtls_test_wrap_psa_export_public_key( size_t arg2_data_size, size_t *arg3_data_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_data, arg2_data_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_export_public_key)(arg0_key, arg1_data, arg2_data_size, arg3_data_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_data, arg2_data_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -566,7 +570,13 @@ psa_status_t mbedtls_test_wrap_psa_import_key( size_t arg2_data_length, mbedtls_svc_key_id_t *arg3_key) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_data, arg2_data_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_import_key)(arg0_attributes, arg1_data, arg2_data_length, arg3_key); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_data, arg2_data_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From d6a91795a8185669d8ab8b8dd0f2ca2a33a25d8f Mon Sep 17 00:00:00 2001 From: Ryan Everett Date: Thu, 25 Jan 2024 12:00:02 +0000 Subject: [PATCH 31/46] Re-add cipher_encrypt to test wrapper script Signed-off-by: Ryan Everett --- src/psa_test_wrappers.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index de3714d2c..bb1409e10 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -267,7 +267,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( size_t arg5_output_size, size_t *arg6_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 075b1119ac7d0a88782ae81268b3af298ed3f384 Mon Sep 17 00:00:00 2001 From: Ryan Everett Date: Thu, 1 Feb 2024 17:52:13 +0000 Subject: [PATCH 32/46] Remove unnecessary dependencies from psa_crypto_helpers.h The psa_test_wrappers.h inclusion was breaking the examples in programs/ on functions with poisoning added Signed-off-by: Ryan Everett --- include/test/psa_crypto_helpers.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/test/psa_crypto_helpers.h b/include/test/psa_crypto_helpers.h index 96a8c1c82..8e790cbab 100644 --- a/include/test/psa_crypto_helpers.h +++ b/include/test/psa_crypto_helpers.h @@ -16,13 +16,6 @@ #include #endif -#include "test/psa_test_wrappers.h" - -#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ - && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) -#include "test/psa_memory_poisoning_wrappers.h" -#endif - #if defined(MBEDTLS_PSA_CRYPTO_C) /** Initialize the PSA Crypto subsystem. */ #define PSA_INIT() PSA_ASSERT(psa_crypto_init()) From da3051d7e25ced24ffadd140f7fd6c78313611c8 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 22 Jan 2024 14:36:01 +0000 Subject: [PATCH 33/46] Generate poisoning wrappers for AEAD Modify wrapper generation script to generate poisoning calls and regenerate wrappers. Signed-off-by: David Horstmann --- src/psa_test_wrappers.c | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index bb1409e10..8c2dcf2b4 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -70,7 +70,19 @@ psa_status_t mbedtls_test_wrap_psa_aead_decrypt( size_t arg9_plaintext_size, size_t *arg10_plaintext_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_nonce, arg3_nonce_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_additional_data, arg5_additional_data_length); + MBEDTLS_TEST_MEMORY_POISON(arg6_ciphertext, arg7_ciphertext_length); + MBEDTLS_TEST_MEMORY_POISON(arg8_plaintext, arg9_plaintext_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_decrypt)(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_ciphertext, arg7_ciphertext_length, arg8_plaintext, arg9_plaintext_size, arg10_plaintext_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_nonce, arg3_nonce_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_additional_data, arg5_additional_data_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg6_ciphertext, arg7_ciphertext_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg8_plaintext, arg9_plaintext_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -98,7 +110,19 @@ psa_status_t mbedtls_test_wrap_psa_aead_encrypt( size_t arg9_ciphertext_size, size_t *arg10_ciphertext_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_nonce, arg3_nonce_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_additional_data, arg5_additional_data_length); + MBEDTLS_TEST_MEMORY_POISON(arg6_plaintext, arg7_plaintext_length); + MBEDTLS_TEST_MEMORY_POISON(arg8_ciphertext, arg9_ciphertext_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_encrypt)(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_plaintext, arg7_plaintext_length, arg8_ciphertext, arg9_ciphertext_size, arg10_ciphertext_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_nonce, arg3_nonce_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_additional_data, arg5_additional_data_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg6_plaintext, arg7_plaintext_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg8_ciphertext, arg9_ciphertext_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -122,7 +146,15 @@ psa_status_t mbedtls_test_wrap_psa_aead_finish( size_t arg5_tag_size, size_t *arg6_tag_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_ciphertext, arg2_ciphertext_size); + MBEDTLS_TEST_MEMORY_POISON(arg4_tag, arg5_tag_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_finish)(arg0_operation, arg1_ciphertext, arg2_ciphertext_size, arg3_ciphertext_length, arg4_tag, arg5_tag_size, arg6_tag_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_ciphertext, arg2_ciphertext_size); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_tag, arg5_tag_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -133,7 +165,13 @@ psa_status_t mbedtls_test_wrap_psa_aead_generate_nonce( size_t arg2_nonce_size, size_t *arg3_nonce_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_nonce, arg2_nonce_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_generate_nonce)(arg0_operation, arg1_nonce, arg2_nonce_size, arg3_nonce_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_nonce, arg2_nonce_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -153,7 +191,13 @@ psa_status_t mbedtls_test_wrap_psa_aead_set_nonce( const uint8_t *arg1_nonce, size_t arg2_nonce_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_nonce, arg2_nonce_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_set_nonce)(arg0_operation, arg1_nonce, arg2_nonce_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_nonce, arg2_nonce_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -166,7 +210,15 @@ psa_status_t mbedtls_test_wrap_psa_aead_update( size_t arg4_output_size, size_t *arg5_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg3_output, arg4_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_update)(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_output, arg4_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -176,7 +228,13 @@ psa_status_t mbedtls_test_wrap_psa_aead_update_ad( const uint8_t *arg1_input, size_t arg2_input_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_update_ad)(arg0_operation, arg1_input, arg2_input_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -189,7 +247,15 @@ psa_status_t mbedtls_test_wrap_psa_aead_verify( const uint8_t *arg4_tag, size_t arg5_tag_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_plaintext, arg2_plaintext_size); + MBEDTLS_TEST_MEMORY_POISON(arg4_tag, arg5_tag_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_aead_verify)(arg0_operation, arg1_plaintext, arg2_plaintext_size, arg3_plaintext_length, arg4_tag, arg5_tag_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_plaintext, arg2_plaintext_size); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_tag, arg5_tag_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 06275bbe8282fbb5eb14780e1bcc5dc108249706 Mon Sep 17 00:00:00 2001 From: Ryan Everett Date: Thu, 25 Jan 2024 11:44:56 +0000 Subject: [PATCH 34/46] Generate test wrappers for key derivation Signed-off-by: Ryan Everett --- src/psa_test_wrappers.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index bb1409e10..31aa92b2c 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -612,7 +612,13 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_input_bytes( const uint8_t *arg2_data, size_t arg3_data_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_data, arg3_data_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_key_derivation_input_bytes)(arg0_operation, arg1_step, arg2_data, arg3_data_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_data, arg3_data_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -654,7 +660,13 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_output_bytes( uint8_t *arg1_output, size_t arg2_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_output, arg2_output_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_key_derivation_output_bytes)(arg0_operation, arg1_output, arg2_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_output, arg2_output_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From fec3ee14d219f6b56ee9fe610eb8de46e698570b Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 25 Jan 2024 16:48:09 +0000 Subject: [PATCH 35/46] Generate test wrappers for hash functions Signed-off-by: Thomas Daubney --- src/psa_test_wrappers.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index bb1409e10..14da8ad44 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -514,7 +514,15 @@ psa_status_t mbedtls_test_wrap_psa_hash_compare( const uint8_t *arg3_hash, size_t arg4_hash_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_hash_compare)(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -527,7 +535,15 @@ psa_status_t mbedtls_test_wrap_psa_hash_compute( size_t arg4_hash_size, size_t *arg5_hash_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_hash_compute)(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_size, arg5_hash_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -538,7 +554,13 @@ psa_status_t mbedtls_test_wrap_psa_hash_finish( size_t arg2_hash_size, size_t *arg3_hash_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_hash, arg2_hash_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_hash_finish)(arg0_operation, arg1_hash, arg2_hash_size, arg3_hash_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_hash, arg2_hash_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -557,7 +579,13 @@ psa_status_t mbedtls_test_wrap_psa_hash_update( const uint8_t *arg1_input, size_t arg2_input_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_hash_update)(arg0_operation, arg1_input, arg2_input_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -567,7 +595,13 @@ psa_status_t mbedtls_test_wrap_psa_hash_verify( const uint8_t *arg1_hash, size_t arg2_hash_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_hash, arg2_hash_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_hash_verify)(arg0_operation, arg1_hash, arg2_hash_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_hash, arg2_hash_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 72a123c4b785917b5573b0067078c9b28e243a72 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 30 Jan 2024 11:18:54 +0000 Subject: [PATCH 36/46] Generate test wrappers for mac functions Signed-off-by: Thomas Daubney --- src/psa_test_wrappers.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index bb1409e10..333a85c5c 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -704,7 +704,15 @@ psa_status_t mbedtls_test_wrap_psa_mac_compute( size_t arg5_mac_size, size_t *arg6_mac_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_mac, arg5_mac_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_mac_compute)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_size, arg6_mac_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_mac, arg5_mac_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -715,7 +723,13 @@ psa_status_t mbedtls_test_wrap_psa_mac_sign_finish( size_t arg2_mac_size, size_t *arg3_mac_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_mac, arg2_mac_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_mac_sign_finish)(arg0_operation, arg1_mac, arg2_mac_size, arg3_mac_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_mac, arg2_mac_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -735,7 +749,13 @@ psa_status_t mbedtls_test_wrap_psa_mac_update( const uint8_t *arg1_input, size_t arg2_input_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_mac_update)(arg0_operation, arg1_input, arg2_input_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -748,7 +768,15 @@ psa_status_t mbedtls_test_wrap_psa_mac_verify( const uint8_t *arg4_mac, size_t arg5_mac_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_mac, arg5_mac_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_mac_verify)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_mac, arg5_mac_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -758,7 +786,13 @@ psa_status_t mbedtls_test_wrap_psa_mac_verify_finish( const uint8_t *arg1_mac, size_t arg2_mac_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_mac, arg2_mac_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_mac_verify_finish)(arg0_operation, arg1_mac, arg2_mac_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_mac, arg2_mac_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 3b14880b75ebcd8dfe6126a2ac1b5cdd75942307 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Tue, 30 Jan 2024 14:04:47 +0000 Subject: [PATCH 37/46] Generate test wrappers Signed-off-by: Thomas Daubney --- src/psa_test_wrappers.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index bb1409e10..c6b084fe4 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -221,7 +221,17 @@ psa_status_t mbedtls_test_wrap_psa_asymmetric_encrypt( size_t arg7_output_size, size_t *arg8_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_salt, arg5_salt_length); + MBEDTLS_TEST_MEMORY_POISON(arg6_output, arg7_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_asymmetric_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_salt, arg5_salt_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg6_output, arg7_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 8eee3a3dbabc944931c2f92fa5b5b4e7a7401332 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Wed, 31 Jan 2024 16:56:17 +0000 Subject: [PATCH 38/46] Generate all test wrappers One was missed due to a typo Signed-off-by: Thomas Daubney --- src/psa_test_wrappers.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index c6b084fe4..440650063 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -205,7 +205,17 @@ psa_status_t mbedtls_test_wrap_psa_asymmetric_decrypt( size_t arg7_output_size, size_t *arg8_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_salt, arg5_salt_length); + MBEDTLS_TEST_MEMORY_POISON(arg6_output, arg7_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_asymmetric_decrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_salt, arg5_salt_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg6_output, arg7_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From cf16573898bbe1ae569a3b289993be046247393e Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 15 Feb 2024 13:35:06 +0000 Subject: [PATCH 39/46] Generate test wrappers Signed-off-by: Thomas Daubney --- src/psa_test_wrappers.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 728afed3d..35500b597 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -684,7 +684,13 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_key_agreement( const uint8_t *arg3_peer_key, size_t arg4_peer_key_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg3_peer_key, arg4_peer_key_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_key_derivation_key_agreement)(arg0_operation, arg1_step, arg2_private_key, arg3_peer_key, arg4_peer_key_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_peer_key, arg4_peer_key_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -923,7 +929,15 @@ psa_status_t mbedtls_test_wrap_psa_raw_key_agreement( size_t arg5_output_size, size_t *arg6_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_peer_key, arg3_peer_key_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_raw_key_agreement)(arg0_alg, arg1_private_key, arg2_peer_key, arg3_peer_key_length, arg4_output, arg5_output_size, arg6_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_peer_key, arg3_peer_key_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From ecfc9734ef2804f85e9369587cbdc242a4e0682e Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 6 Feb 2024 15:44:08 +0000 Subject: [PATCH 40/46] Generate test wrappers for psa_generate_random() Signed-off-by: David Horstmann --- src/psa_test_wrappers.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 5f0a3dd08..fa9a8d6f0 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -542,7 +542,13 @@ psa_status_t mbedtls_test_wrap_psa_generate_random( uint8_t *arg0_output, size_t arg1_output_size) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg0_output, arg1_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_generate_random)(arg0_output, arg1_output_size); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg0_output, arg1_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 2540a4ecaf8c2f0cd1e5b1dc730d734698b088a8 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 24 Jan 2024 16:58:40 +0100 Subject: [PATCH 41/46] Add test wrapper functions for cipher buffer protection Signed-off-by: Gabor Mezei --- src/psa_test_wrappers.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 4824e3806..5a7be9be8 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -309,7 +309,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_decrypt( size_t arg5_output_size, size_t *arg6_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_decrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -362,7 +370,13 @@ psa_status_t mbedtls_test_wrap_psa_cipher_finish( size_t arg2_output_size, size_t *arg3_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_output, arg2_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_finish)(arg0_operation, arg1_output, arg2_output_size, arg3_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_output, arg2_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -396,7 +410,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_update( size_t arg4_output_size, size_t *arg5_output_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_POISON(arg3_output, arg4_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_update)(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_output, arg4_output_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 14fdcb78aa6ab1050fb7f60443e7069506b3c650 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Thu, 1 Feb 2024 10:39:56 +0100 Subject: [PATCH 42/46] Update test wrapper functions for ciper buffer protection Signed-off-by: Gabor Mezei --- src/psa_test_wrappers.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 5a7be9be8..f41bcc079 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -387,7 +387,13 @@ psa_status_t mbedtls_test_wrap_psa_cipher_generate_iv( size_t arg2_iv_size, size_t *arg3_iv_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_iv, arg2_iv_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_generate_iv)(arg0_operation, arg1_iv, arg2_iv_size, arg3_iv_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_iv, arg2_iv_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -397,7 +403,13 @@ psa_status_t mbedtls_test_wrap_psa_cipher_set_iv( const uint8_t *arg1_iv, size_t arg2_iv_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_iv, arg2_iv_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_cipher_set_iv)(arg0_operation, arg1_iv, arg2_iv_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_iv, arg2_iv_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From 40af74bb651f63cd50f8b2313fcf54c73265081b Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Mon, 11 Mar 2024 13:58:07 +0000 Subject: [PATCH 43/46] Generate memory poisoning in wrappers Generate memory poisoning code in test wrappers for: * psa_sign_hash_start() * psa_sign_hash_complete() * psa_verify_hash_start() Signed-off-by: David Horstmann --- src/psa_test_wrappers.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index 71ea09c44..f303af833 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -1162,7 +1162,13 @@ psa_status_t mbedtls_test_wrap_psa_sign_hash_complete( size_t arg2_signature_size, size_t *arg3_signature_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg1_signature, arg2_signature_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_sign_hash_complete)(arg0_operation, arg1_signature, arg2_signature_size, arg3_signature_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg1_signature, arg2_signature_size); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -1174,7 +1180,13 @@ psa_status_t mbedtls_test_wrap_psa_sign_hash_start( const uint8_t *arg3_hash, size_t arg4_hash_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_sign_hash_start)(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } @@ -1247,7 +1259,15 @@ psa_status_t mbedtls_test_wrap_psa_verify_hash_start( const uint8_t *arg5_signature, size_t arg6_signature_length) { +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_length); + MBEDTLS_TEST_MEMORY_POISON(arg5_signature, arg6_signature_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ psa_status_t status = (psa_verify_hash_start)(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length, arg5_signature, arg6_signature_length); +#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) + MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_length); + MBEDTLS_TEST_MEMORY_UNPOISON(arg5_signature, arg6_signature_length); +#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ return status; } From a0010d16dd683a06d384342d060dcb6dd849a0ac Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Tue, 12 Mar 2024 17:02:48 +0000 Subject: [PATCH 44/46] Regenerate PSA wrappers for new PSA functions Signed-off-by: David Horstmann --- include/test/psa_test_wrappers.h | 17 +++++++++++++++++ src/psa_test_wrappers.c | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/test/psa_test_wrappers.h b/include/test/psa_test_wrappers.h index 86ead0a12..ecf926eb0 100644 --- a/include/test/psa_test_wrappers.h +++ b/include/test/psa_test_wrappers.h @@ -341,6 +341,14 @@ psa_status_t mbedtls_test_wrap_psa_generate_key( #define psa_generate_key(arg0_attributes, arg1_key) \ mbedtls_test_wrap_psa_generate_key(arg0_attributes, arg1_key) +psa_status_t mbedtls_test_wrap_psa_generate_key_ext( + const psa_key_attributes_t *arg0_attributes, + const psa_key_production_parameters_t *arg1_params, + size_t arg2_params_data_length, + mbedtls_svc_key_id_t *arg3_key); +#define psa_generate_key_ext(arg0_attributes, arg1_params, arg2_params_data_length, arg3_key) \ + mbedtls_test_wrap_psa_generate_key_ext(arg0_attributes, arg1_params, arg2_params_data_length, arg3_key) + psa_status_t mbedtls_test_wrap_psa_generate_random( uint8_t *arg0_output, size_t arg1_output_size); @@ -475,6 +483,15 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_output_key( #define psa_key_derivation_output_key(arg0_attributes, arg1_operation, arg2_key) \ mbedtls_test_wrap_psa_key_derivation_output_key(arg0_attributes, arg1_operation, arg2_key) +psa_status_t mbedtls_test_wrap_psa_key_derivation_output_key_ext( + const psa_key_attributes_t *arg0_attributes, + psa_key_derivation_operation_t *arg1_operation, + const psa_key_production_parameters_t *arg2_params, + size_t arg3_params_data_length, + mbedtls_svc_key_id_t *arg4_key); +#define psa_key_derivation_output_key_ext(arg0_attributes, arg1_operation, arg2_params, arg3_params_data_length, arg4_key) \ + mbedtls_test_wrap_psa_key_derivation_output_key_ext(arg0_attributes, arg1_operation, arg2_params, arg3_params_data_length, arg4_key) + psa_status_t mbedtls_test_wrap_psa_key_derivation_set_capacity( psa_key_derivation_operation_t *arg0_operation, size_t arg1_capacity); diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index f303af833..b03043129 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -591,6 +591,17 @@ psa_status_t mbedtls_test_wrap_psa_generate_key( return status; } +/* Wrapper for psa_generate_key_ext */ +psa_status_t mbedtls_test_wrap_psa_generate_key_ext( + const psa_key_attributes_t *arg0_attributes, + const psa_key_production_parameters_t *arg1_params, + size_t arg2_params_data_length, + mbedtls_svc_key_id_t *arg3_key) +{ + psa_status_t status = (psa_generate_key_ext)(arg0_attributes, arg1_params, arg2_params_data_length, arg3_key); + return status; +} + /* Wrapper for psa_generate_random */ psa_status_t mbedtls_test_wrap_psa_generate_random( uint8_t *arg0_output, @@ -846,6 +857,18 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_output_key( return status; } +/* Wrapper for psa_key_derivation_output_key_ext */ +psa_status_t mbedtls_test_wrap_psa_key_derivation_output_key_ext( + const psa_key_attributes_t *arg0_attributes, + psa_key_derivation_operation_t *arg1_operation, + const psa_key_production_parameters_t *arg2_params, + size_t arg3_params_data_length, + mbedtls_svc_key_id_t *arg4_key) +{ + psa_status_t status = (psa_key_derivation_output_key_ext)(arg0_attributes, arg1_operation, arg2_params, arg3_params_data_length, arg4_key); + return status; +} + /* Wrapper for psa_key_derivation_set_capacity */ psa_status_t mbedtls_test_wrap_psa_key_derivation_set_capacity( psa_key_derivation_operation_t *arg0_operation, From 7cd6992c1caf362f699199e336e998b550e724d6 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 13 Mar 2024 15:42:31 +0000 Subject: [PATCH 45/46] Invert and rename config option Replace MBEDTLS_PSA_COPY_CALLER_BUFFERS with inverse: !MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS. This ensures that buffer protection is enabled by default without any change to the Mbed TLS config file. Signed-off-by: David Horstmann --- src/helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index be9155c66..065d17d3e 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -318,7 +318,7 @@ int mbedtls_test_platform_setup(void) int ret = 0; #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ - && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) \ + && !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) \ && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) mbedtls_poison_test_hooks_setup(); #endif @@ -348,7 +348,7 @@ int mbedtls_test_platform_setup(void) void mbedtls_test_platform_teardown(void) { #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \ - && defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) \ + && !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) \ && defined(MBEDTLS_TEST_MEMORY_CAN_POISON) mbedtls_poison_test_hooks_teardown(); #endif From 34beef6cc5376c60bdbeb2d285cfbc6bebc54221 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 13 Mar 2024 15:57:46 +0000 Subject: [PATCH 46/46] Update wrapper generation script and regenerate Update the guards generated by the wrapper generation script to use !MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS and regenerate the PSA test wrappers. Signed-off-by: David Horstmann --- src/psa_test_wrappers.c | 360 ++++++++++++++++++++-------------------- 1 file changed, 180 insertions(+), 180 deletions(-) diff --git a/src/psa_test_wrappers.c b/src/psa_test_wrappers.c index b03043129..809f1cd6f 100644 --- a/src/psa_test_wrappers.c +++ b/src/psa_test_wrappers.c @@ -70,19 +70,19 @@ psa_status_t mbedtls_test_wrap_psa_aead_decrypt( size_t arg9_plaintext_size, size_t *arg10_plaintext_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_nonce, arg3_nonce_length); MBEDTLS_TEST_MEMORY_POISON(arg4_additional_data, arg5_additional_data_length); MBEDTLS_TEST_MEMORY_POISON(arg6_ciphertext, arg7_ciphertext_length); MBEDTLS_TEST_MEMORY_POISON(arg8_plaintext, arg9_plaintext_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_decrypt)(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_ciphertext, arg7_ciphertext_length, arg8_plaintext, arg9_plaintext_size, arg10_plaintext_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_nonce, arg3_nonce_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_additional_data, arg5_additional_data_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg6_ciphertext, arg7_ciphertext_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg8_plaintext, arg9_plaintext_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -110,19 +110,19 @@ psa_status_t mbedtls_test_wrap_psa_aead_encrypt( size_t arg9_ciphertext_size, size_t *arg10_ciphertext_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_nonce, arg3_nonce_length); MBEDTLS_TEST_MEMORY_POISON(arg4_additional_data, arg5_additional_data_length); MBEDTLS_TEST_MEMORY_POISON(arg6_plaintext, arg7_plaintext_length); MBEDTLS_TEST_MEMORY_POISON(arg8_ciphertext, arg9_ciphertext_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_encrypt)(arg0_key, arg1_alg, arg2_nonce, arg3_nonce_length, arg4_additional_data, arg5_additional_data_length, arg6_plaintext, arg7_plaintext_length, arg8_ciphertext, arg9_ciphertext_size, arg10_ciphertext_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_nonce, arg3_nonce_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_additional_data, arg5_additional_data_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg6_plaintext, arg7_plaintext_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg8_ciphertext, arg9_ciphertext_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -146,15 +146,15 @@ psa_status_t mbedtls_test_wrap_psa_aead_finish( size_t arg5_tag_size, size_t *arg6_tag_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_ciphertext, arg2_ciphertext_size); MBEDTLS_TEST_MEMORY_POISON(arg4_tag, arg5_tag_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_finish)(arg0_operation, arg1_ciphertext, arg2_ciphertext_size, arg3_ciphertext_length, arg4_tag, arg5_tag_size, arg6_tag_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_ciphertext, arg2_ciphertext_size); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_tag, arg5_tag_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -165,13 +165,13 @@ psa_status_t mbedtls_test_wrap_psa_aead_generate_nonce( size_t arg2_nonce_size, size_t *arg3_nonce_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_nonce, arg2_nonce_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_generate_nonce)(arg0_operation, arg1_nonce, arg2_nonce_size, arg3_nonce_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_nonce, arg2_nonce_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -191,13 +191,13 @@ psa_status_t mbedtls_test_wrap_psa_aead_set_nonce( const uint8_t *arg1_nonce, size_t arg2_nonce_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_nonce, arg2_nonce_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_set_nonce)(arg0_operation, arg1_nonce, arg2_nonce_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_nonce, arg2_nonce_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -210,15 +210,15 @@ psa_status_t mbedtls_test_wrap_psa_aead_update( size_t arg4_output_size, size_t *arg5_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_POISON(arg3_output, arg4_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_update)(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg3_output, arg4_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -228,13 +228,13 @@ psa_status_t mbedtls_test_wrap_psa_aead_update_ad( const uint8_t *arg1_input, size_t arg2_input_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_update_ad)(arg0_operation, arg1_input, arg2_input_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -247,15 +247,15 @@ psa_status_t mbedtls_test_wrap_psa_aead_verify( const uint8_t *arg4_tag, size_t arg5_tag_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_plaintext, arg2_plaintext_size); MBEDTLS_TEST_MEMORY_POISON(arg4_tag, arg5_tag_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_aead_verify)(arg0_operation, arg1_plaintext, arg2_plaintext_size, arg3_plaintext_length, arg4_tag, arg5_tag_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_plaintext, arg2_plaintext_size); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_tag, arg5_tag_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -271,17 +271,17 @@ psa_status_t mbedtls_test_wrap_psa_asymmetric_decrypt( size_t arg7_output_size, size_t *arg8_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_salt, arg5_salt_length); MBEDTLS_TEST_MEMORY_POISON(arg6_output, arg7_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_asymmetric_decrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_salt, arg5_salt_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg6_output, arg7_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -297,17 +297,17 @@ psa_status_t mbedtls_test_wrap_psa_asymmetric_encrypt( size_t arg7_output_size, size_t *arg8_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_salt, arg5_salt_length); MBEDTLS_TEST_MEMORY_POISON(arg6_output, arg7_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_asymmetric_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_salt, arg5_salt_length, arg6_output, arg7_output_size, arg8_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_salt, arg5_salt_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg6_output, arg7_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -329,15 +329,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_decrypt( size_t arg5_output_size, size_t *arg6_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_cipher_decrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -361,15 +361,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_encrypt( size_t arg5_output_size, size_t *arg6_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_cipher_encrypt)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_output, arg5_output_size, arg6_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -390,13 +390,13 @@ psa_status_t mbedtls_test_wrap_psa_cipher_finish( size_t arg2_output_size, size_t *arg3_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_output, arg2_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_cipher_finish)(arg0_operation, arg1_output, arg2_output_size, arg3_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_output, arg2_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -407,13 +407,13 @@ psa_status_t mbedtls_test_wrap_psa_cipher_generate_iv( size_t arg2_iv_size, size_t *arg3_iv_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_iv, arg2_iv_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_cipher_generate_iv)(arg0_operation, arg1_iv, arg2_iv_size, arg3_iv_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_iv, arg2_iv_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -423,13 +423,13 @@ psa_status_t mbedtls_test_wrap_psa_cipher_set_iv( const uint8_t *arg1_iv, size_t arg2_iv_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_iv, arg2_iv_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_cipher_set_iv)(arg0_operation, arg1_iv, arg2_iv_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_iv, arg2_iv_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -442,15 +442,15 @@ psa_status_t mbedtls_test_wrap_psa_cipher_update( size_t arg4_output_size, size_t *arg5_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_POISON(arg3_output, arg4_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_cipher_update)(arg0_operation, arg1_input, arg2_input_length, arg3_output, arg4_output_size, arg5_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg3_output, arg4_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -555,13 +555,13 @@ psa_status_t mbedtls_test_wrap_psa_export_key( size_t arg2_data_size, size_t *arg3_data_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_data, arg2_data_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_export_key)(arg0_key, arg1_data, arg2_data_size, arg3_data_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_data, arg2_data_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -572,13 +572,13 @@ psa_status_t mbedtls_test_wrap_psa_export_public_key( size_t arg2_data_size, size_t *arg3_data_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_data, arg2_data_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_export_public_key)(arg0_key, arg1_data, arg2_data_size, arg3_data_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_data, arg2_data_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -607,13 +607,13 @@ psa_status_t mbedtls_test_wrap_psa_generate_random( uint8_t *arg0_output, size_t arg1_output_size) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg0_output, arg1_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_generate_random)(arg0_output, arg1_output_size); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg0_output, arg1_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -651,15 +651,15 @@ psa_status_t mbedtls_test_wrap_psa_hash_compare( const uint8_t *arg3_hash, size_t arg4_hash_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_hash_compare)(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -672,15 +672,15 @@ psa_status_t mbedtls_test_wrap_psa_hash_compute( size_t arg4_hash_size, size_t *arg5_hash_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_hash_compute)(arg0_alg, arg1_input, arg2_input_length, arg3_hash, arg4_hash_size, arg5_hash_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -691,13 +691,13 @@ psa_status_t mbedtls_test_wrap_psa_hash_finish( size_t arg2_hash_size, size_t *arg3_hash_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_hash, arg2_hash_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_hash_finish)(arg0_operation, arg1_hash, arg2_hash_size, arg3_hash_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_hash, arg2_hash_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -716,13 +716,13 @@ psa_status_t mbedtls_test_wrap_psa_hash_update( const uint8_t *arg1_input, size_t arg2_input_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_hash_update)(arg0_operation, arg1_input, arg2_input_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -732,13 +732,13 @@ psa_status_t mbedtls_test_wrap_psa_hash_verify( const uint8_t *arg1_hash, size_t arg2_hash_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_hash, arg2_hash_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_hash_verify)(arg0_operation, arg1_hash, arg2_hash_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_hash, arg2_hash_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -749,13 +749,13 @@ psa_status_t mbedtls_test_wrap_psa_import_key( size_t arg2_data_length, mbedtls_svc_key_id_t *arg3_key) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_data, arg2_data_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_import_key)(arg0_attributes, arg1_data, arg2_data_length, arg3_key); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_data, arg2_data_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -783,13 +783,13 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_input_bytes( const uint8_t *arg2_data, size_t arg3_data_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_data, arg3_data_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_key_derivation_input_bytes)(arg0_operation, arg1_step, arg2_data, arg3_data_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_data, arg3_data_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -821,13 +821,13 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_key_agreement( const uint8_t *arg3_peer_key, size_t arg4_peer_key_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg3_peer_key, arg4_peer_key_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_key_derivation_key_agreement)(arg0_operation, arg1_step, arg2_private_key, arg3_peer_key, arg4_peer_key_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg3_peer_key, arg4_peer_key_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -837,13 +837,13 @@ psa_status_t mbedtls_test_wrap_psa_key_derivation_output_bytes( uint8_t *arg1_output, size_t arg2_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_output, arg2_output_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_key_derivation_output_bytes)(arg0_operation, arg1_output, arg2_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_output, arg2_output_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -905,15 +905,15 @@ psa_status_t mbedtls_test_wrap_psa_mac_compute( size_t arg5_mac_size, size_t *arg6_mac_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_mac, arg5_mac_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_mac_compute)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_size, arg6_mac_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_mac, arg5_mac_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -924,13 +924,13 @@ psa_status_t mbedtls_test_wrap_psa_mac_sign_finish( size_t arg2_mac_size, size_t *arg3_mac_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_mac, arg2_mac_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_mac_sign_finish)(arg0_operation, arg1_mac, arg2_mac_size, arg3_mac_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_mac, arg2_mac_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -950,13 +950,13 @@ psa_status_t mbedtls_test_wrap_psa_mac_update( const uint8_t *arg1_input, size_t arg2_input_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_input, arg2_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_mac_update)(arg0_operation, arg1_input, arg2_input_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_input, arg2_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -969,15 +969,15 @@ psa_status_t mbedtls_test_wrap_psa_mac_verify( const uint8_t *arg4_mac, size_t arg5_mac_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_mac, arg5_mac_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_mac_verify)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_mac, arg5_mac_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_mac, arg5_mac_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -987,13 +987,13 @@ psa_status_t mbedtls_test_wrap_psa_mac_verify_finish( const uint8_t *arg1_mac, size_t arg2_mac_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_mac, arg2_mac_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_mac_verify_finish)(arg0_operation, arg1_mac, arg2_mac_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_mac, arg2_mac_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1031,13 +1031,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_input( const uint8_t *arg2_input, size_t arg3_input_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_pake_input)(arg0_operation, arg1_step, arg2_input, arg3_input_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1049,13 +1049,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_output( size_t arg3_output_size, size_t *arg4_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_output, arg3_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_pake_output)(arg0_operation, arg1_step, arg2_output, arg3_output_size, arg4_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_output, arg3_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1074,13 +1074,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_set_peer( const uint8_t *arg1_peer_id, size_t arg2_peer_id_len) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_peer_id, arg2_peer_id_len); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_pake_set_peer)(arg0_operation, arg1_peer_id, arg2_peer_id_len); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_peer_id, arg2_peer_id_len); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1099,13 +1099,13 @@ psa_status_t mbedtls_test_wrap_psa_pake_set_user( const uint8_t *arg1_user_id, size_t arg2_user_id_len) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_user_id, arg2_user_id_len); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_pake_set_user)(arg0_operation, arg1_user_id, arg2_user_id_len); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_user_id, arg2_user_id_len); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1136,15 +1136,15 @@ psa_status_t mbedtls_test_wrap_psa_raw_key_agreement( size_t arg5_output_size, size_t *arg6_output_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_peer_key, arg3_peer_key_length); MBEDTLS_TEST_MEMORY_POISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_raw_key_agreement)(arg0_alg, arg1_private_key, arg2_peer_key, arg3_peer_key_length, arg4_output, arg5_output_size, arg6_output_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_peer_key, arg3_peer_key_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_output, arg5_output_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1158,15 +1158,15 @@ psa_status_t mbedtls_test_wrap_psa_sign_hash( size_t arg5_signature_size, size_t *arg6_signature_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_hash, arg3_hash_length); MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_sign_hash)(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_size, arg6_signature_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_hash, arg3_hash_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1185,13 +1185,13 @@ psa_status_t mbedtls_test_wrap_psa_sign_hash_complete( size_t arg2_signature_size, size_t *arg3_signature_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg1_signature, arg2_signature_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_sign_hash_complete)(arg0_operation, arg1_signature, arg2_signature_size, arg3_signature_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg1_signature, arg2_signature_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1203,13 +1203,13 @@ psa_status_t mbedtls_test_wrap_psa_sign_hash_start( const uint8_t *arg3_hash, size_t arg4_hash_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_sign_hash_start)(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1223,15 +1223,15 @@ psa_status_t mbedtls_test_wrap_psa_sign_message( size_t arg5_signature_size, size_t *arg6_signature_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_sign_message)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_size, arg6_signature_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_size); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1244,15 +1244,15 @@ psa_status_t mbedtls_test_wrap_psa_verify_hash( const uint8_t *arg4_signature, size_t arg5_signature_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_hash, arg3_hash_length); MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_verify_hash)(arg0_key, arg1_alg, arg2_hash, arg3_hash_length, arg4_signature, arg5_signature_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_hash, arg3_hash_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1282,15 +1282,15 @@ psa_status_t mbedtls_test_wrap_psa_verify_hash_start( const uint8_t *arg5_signature, size_t arg6_signature_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg3_hash, arg4_hash_length); MBEDTLS_TEST_MEMORY_POISON(arg5_signature, arg6_signature_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_verify_hash_start)(arg0_operation, arg1_key, arg2_alg, arg3_hash, arg4_hash_length, arg5_signature, arg6_signature_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg3_hash, arg4_hash_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg5_signature, arg6_signature_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; } @@ -1303,15 +1303,15 @@ psa_status_t mbedtls_test_wrap_psa_verify_message( const uint8_t *arg4_signature, size_t arg5_signature_length) { -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_POISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_POISON(arg4_signature, arg5_signature_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ psa_status_t status = (psa_verify_message)(arg0_key, arg1_alg, arg2_input, arg3_input_length, arg4_signature, arg5_signature_length); -#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) +#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) MBEDTLS_TEST_MEMORY_UNPOISON(arg2_input, arg3_input_length); MBEDTLS_TEST_MEMORY_UNPOISON(arg4_signature, arg5_signature_length); -#endif /* defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) */ +#endif /* !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) */ return status; }