Make copy functions static-testable
This allows greater compiler optimisation.
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 4cea3a9..0cf1716 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -5523,6 +5523,19 @@
return status;
}
+/** Copy from an input buffer to a local copy.
+ *
+ * \param[in] input Pointer to input buffer.
+ * \param[in] input_len Length of the input buffer.
+ * \param[out] input_copy Pointer to a local copy in which to store the input data.
+ * \param[out] input_copy_len Length of the local copy buffer.
+ * \return #PSA_SUCCESS, if the buffer was successfully
+ * copied.
+ * \return #PSA_ERROR_CORRUPTION_DETECTED, if the local
+ * copy is too small to hold contents of the
+ * input buffer.
+ */
+MBEDTLS_STATIC_TESTABLE
psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len,
uint8_t *input_copy, size_t input_copy_len)
{
@@ -5535,6 +5548,19 @@
return PSA_SUCCESS;
}
+/** Copy from a local output buffer into a user-supplied one.
+ *
+ * \param[in] output_copy Pointer to a local buffer containing the output.
+ * \param[in] output_copy_len Length of the local buffer.
+ * \param[out] output Pointer to user-supplied output buffer.
+ * \param[out] output_len Length of the user-supplied output buffer.
+ * \return #PSA_SUCCESS, if the buffer was successfully
+ * copied.
+ * \return #PSA_ERROR_CORRUPTION_DETECTED, if the
+ * user-supplied output buffer is too small to
+ * hold the contents of the local buffer.
+ */
+MBEDTLS_STATIC_TESTABLE
psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_copy_len,
uint8_t *output, size_t output_len)
{
diff --git a/library/psa_crypto_core.h b/library/psa_crypto_core.h
index 25320fc..ca3d835 100644
--- a/library/psa_crypto_core.h
+++ b/library/psa_crypto_core.h
@@ -515,36 +515,6 @@
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
const uint8_t *signature, size_t signature_length);
-/** Copy from an input buffer to a local copy.
- *
- * \param[in] input Pointer to input buffer.
- * \param[in] input_len Length of the input buffer.
- * \param[out] input_copy Pointer to a local copy in which to store the input data.
- * \param[out] input_copy_len Length of the local copy buffer.
- * \return #PSA_SUCCESS, if the buffer was successfully
- * copied.
- * \return #PSA_ERROR_CORRUPTION_DETECTED, if the local
- * copy is too small to hold contents of the
- * input buffer.
- */
-psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len,
- uint8_t *input_copy, size_t input_copy_len);
-
-/** Copy from a local output buffer into a user-supplied one.
- *
- * \param[in] output_copy Pointer to a local buffer containing the output.
- * \param[in] output_copy_len Length of the local buffer.
- * \param[out] output Pointer to user-supplied output buffer.
- * \param[out] output_len Length of the user-supplied output buffer.
- * \return #PSA_SUCCESS, if the buffer was successfully
- * copied.
- * \return #PSA_ERROR_CORRUPTION_DETECTED, if the
- * user-supplied output buffer is too small to
- * hold the contents of the local buffer.
- */
-psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_copy_len,
- uint8_t *output, size_t output_len);
-
typedef struct psa_crypto_input_copy_s {
uint8_t *buffer;
size_t len;
diff --git a/library/psa_crypto_invasive.h b/library/psa_crypto_invasive.h
index 58e357e..ec7183d 100644
--- a/library/psa_crypto_invasive.h
+++ b/library/psa_crypto_invasive.h
@@ -81,6 +81,13 @@
psa_status_t psa_mac_key_can_do(
psa_algorithm_t algorithm,
psa_key_type_t key_type);
+
+psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len,
+ uint8_t *input_copy, size_t input_copy_len);
+
+psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_copy_len,
+ uint8_t *output, size_t output_len);
+
#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C */
#endif /* PSA_CRYPTO_INVASIVE_H */
diff --git a/tests/suites/test_suite_psa_crypto_memory.function b/tests/suites/test_suite_psa_crypto_memory.function
index df08bf4..29cb3ec 100644
--- a/tests/suites/test_suite_psa_crypto_memory.function
+++ b/tests/suites/test_suite_psa_crypto_memory.function
@@ -6,6 +6,7 @@
#include "psa/crypto.h"
#include "psa_crypto_core.h"
+#include "psa_crypto_invasive.h"
#include "test/psa_crypto_helpers.h"
@@ -23,7 +24,7 @@
/* END_HEADER */
/* BEGIN_DEPENDENCIES
- * depends_on:MBEDTLS_PSA_CRYPTO_C
+ * depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_TEST_HOOKS
* END_DEPENDENCIES
*/