diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index 03cc2ffe6..5b8a4eade 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -4020,3 +4020,12 @@ persistent_key_load_key_from_storage:"":PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY PSA derive persistent key: HKDF SHA-256, exportable persistent_key_load_key_from_storage:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_KEY_TYPE_RAW_DATA:1024:PSA_KEY_USAGE_EXPORT:0:DERIVE_KEY + +PSA input buffer copy: straightforward copy +psa_crypto_copy_input:20:20:PSA_SUCCESS + +PSA input buffer copy: copy buffer larger than required +psa_crypto_copy_input:10:20:PSA_SUCCESS + +PSA input buffer copy: copy buffer too small +psa_crypto_copy_input:20:10:PSA_ERROR_BUFFER_TOO_SMALL diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 0db5bff79..b9ebe6766 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -13,6 +13,9 @@ #include "psa/crypto.h" #include "psa_crypto_slot_management.h" +/* For psa_can_do_hash() and buffer copying functions */ +#include "psa_crypto_core.h" + #include "test/asn1_helpers.h" #include "test/psa_crypto_helpers.h" #include "test/psa_exercise_key.h" @@ -5639,3 +5642,32 @@ exit: PSA_DONE(); } /* END_CASE */ + +/* BEGIN_CASE */ +void psa_crypto_copy_input(int src_len, int dst_len, int exp_ret) +{ + uint8_t data[] = {0x12, 0x34, 0x56, 0x78}; + uint8_t *src_buffer = NULL; + uint8_t *dst_buffer = NULL; + psa_status_t ret; + + TEST_CALLOC(src_buffer, src_len); + TEST_CALLOC(dst_buffer, dst_len); + + for (int i = 0; i < src_len; i++) { + src_buffer[i] = data[i % sizeof(data)]; + } + + ret = psa_crypto_copy_input(src_buffer, src_len, dst_buffer, dst_len); + TEST_EQUAL((int) ret, exp_ret); + + if (exp_ret == (int) PSA_SUCCESS) { + /* Note: We compare the first src_len bytes of each buffer, as this is what was copied. */ + TEST_MEMORY_COMPARE(src_buffer, src_len, dst_buffer, src_len); + } + +exit: + mbedtls_free(src_buffer); + mbedtls_free(dst_buffer); +} +/* END_CASE */