Add testcases for psa_crypto_alloc_and_copy()

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2023-10-31 17:40:59 +00:00
parent 1d838b27b1
commit 24f11f9cc7
2 changed files with 53 additions and 0 deletions

View File

@ -7424,3 +7424,15 @@ psa_crypto_copy_output:10:20:PSA_SUCCESS
PSA output buffer copy: output buffer too small
psa_crypto_copy_output:20:10:PSA_ERROR_BUFFER_TOO_SMALL
PSA buffers alloc and copy
psa_crypto_alloc_and_copy:0:20:0:20:PSA_SUCCESS
PSA buffers alloc and copy: null input
psa_crypto_alloc_and_copy:1:0:0:20:PSA_SUCCESS
PSA buffers alloc and copy: null output
psa_crypto_alloc_and_copy:0:20:1:0:PSA_SUCCESS
PSA buffers alloc and copy: null input and output
psa_crypto_alloc_and_copy:1:0:1:0:PSA_SUCCESS

View File

@ -10363,3 +10363,44 @@ exit:
mbedtls_free(dst_buffer);
}
/* END_CASE */
/* BEGIN_CASE */
void psa_crypto_alloc_and_copy(int input_null, int input_len,
int output_null, int output_len,
int exp_ret)
{
uint8_t data[] = {0x12, 0x34, 0x56, 0x78};
uint8_t *input_buffer = NULL;
uint8_t *output_buffer = NULL;
psa_crypto_buffer_copy_t buffer_copies = { 0 };
psa_status_t ret;
if (!input_null) {
TEST_CALLOC(input_buffer, input_len);
for (int i = 0; i < input_len; i++) {
input_buffer[i] = data[i % sizeof(data)];
}
}
if (!output_null) {
TEST_CALLOC(output_buffer, output_len);
for (int i = 0; i < output_len; i++) {
output_buffer[i] = data[i % sizeof(data)];
}
}
ret = psa_crypto_alloc_and_copy(input_buffer, input_len,
output_buffer, output_len,
&buffer_copies);
TEST_EQUAL(exp_ret, (int) ret);
if (exp_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(input_buffer);
mbedtls_free(output_buffer);
mbedtls_free(buffer_copies.input);
mbedtls_free(buffer_copies.output);
}
/* END_CASE */