Add MBEDTLS_PSA_COPY_CALLER_BUFFERS config option

This allows us to entirely remove copying code, where the convenience
macros are used for copying.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2023-11-29 17:24:08 +00:00
parent e9a88ab0d5
commit 513101b00f
2 changed files with 20 additions and 0 deletions

View File

@ -1468,6 +1468,19 @@
*/ */
//#define MBEDTLS_PSA_INJECT_ENTROPY //#define MBEDTLS_PSA_INJECT_ENTROPY
/**
* \def MBEDTLS_PSA_COPY_CALLER_BUFFERS
*
* Make local copies of buffers supplied by the callers of PSA functions.
*
* This should be enabled whenever caller-supplied buffers are owned by
* an untrusted party, for example where arguments to PSA calls are passed
* across a trust boundary.
*
* Note: Enabling this option increases memory usage and code size.
*/
#define MBEDTLS_PSA_COPY_CALLER_BUFFERS
/** /**
* \def MBEDTLS_RSA_NO_CRT * \def MBEDTLS_RSA_NO_CRT
* *

View File

@ -110,6 +110,7 @@ mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state =
if (global_data.initialized == 0) \ if (global_data.initialized == 0) \
return PSA_ERROR_BAD_STATE; return PSA_ERROR_BAD_STATE;
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
/* Substitute an input buffer for a local copy of itself. /* Substitute an input buffer for a local copy of itself.
* Assumptions: * Assumptions:
* - psa_status_t status exists * - psa_status_t status exists
@ -147,6 +148,12 @@ mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state =
if (local_output_free_status != PSA_SUCCESS) { \ if (local_output_free_status != PSA_SUCCESS) { \
status = local_output_free_status; \ status = local_output_free_status; \
} }
#else /* MBEDTLS_PSA_COPY_CALLER_BUFFERS */
#define SWAP_FOR_LOCAL_INPUT(input, length)
#define FREE_LOCAL_INPUT(input)
#define SWAP_FOR_LOCAL_OUTPUT(output, length)
#define FREE_LOCAL_OUTPUT(output)
#endif /* MBEDTLS_PSA_COPY_CALLER_BUFFERS */
int psa_can_do_hash(psa_algorithm_t hash_alg) int psa_can_do_hash(psa_algorithm_t hash_alg)