Zero-length test for psa_crypto_alloc_and_copy()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index 9eee9be..3ced4f3 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -4062,3 +4062,12 @@
PSA buffers alloc and copy: null input and output
psa_crypto_alloc_and_copy:1:0:1:0:PSA_SUCCESS
+
+PSA buffers alloc and copy zero-length input
+psa_crypto_alloc_and_copy_zero_length:1:0
+
+PSA buffers alloc and copy zero-length output
+psa_crypto_alloc_and_copy_zero_length:0:1
+
+PSA buffers alloc and copy both zero length
+psa_crypto_alloc_and_copy_zero_length:1:1
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index bd8f80d..1fcb421 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -5749,3 +5749,29 @@
mbedtls_free(buffer_copies.output);
}
/* END_CASE */
+
+/* BEGIN_CASE */
+void psa_crypto_alloc_and_copy_zero_length(int input_zero_length,
+ int output_zero_length)
+{
+ uint8_t input_buffer[] = { 0x12 };
+ uint8_t output_buffer[] = { 0x34 };
+
+ psa_crypto_buffer_copy_t buffer_copies;
+
+ size_t input_len = input_zero_length ? 0 : 1;
+ size_t output_len = output_zero_length ? 0 : 1;
+
+ psa_status_t ret = psa_crypto_alloc_and_copy(input_buffer, input_len,
+ output_buffer, output_len,
+ &buffer_copies);
+ TEST_EQUAL(ret, PSA_SUCCESS);
+
+ TEST_MEMORY_COMPARE(input_buffer, input_len, buffer_copies.input, buffer_copies.input_len);
+ TEST_EQUAL(output_len, buffer_copies.output_len);
+
+exit:
+ mbedtls_free(buffer_copies.input);
+ mbedtls_free(buffer_copies.output);
+}
+/* END_CASE */