Add implementation of psa_crypto_output_alloc()

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2023-11-08 15:19:43 +00:00
parent 70b82256b5
commit ba3c7d649c

View File

@ -8510,4 +8510,28 @@ void psa_crypto_input_copy_free(psa_crypto_input_copy_t *input_copy)
input_copy->len = 0;
}
psa_status_t psa_crypto_output_copy_alloc(uint8_t *output, size_t output_len,
psa_crypto_output_copy_t *output_copy)
{
output_copy->original = NULL;
output_copy->buffer = NULL;
output_copy->len = 0;
/* Treat NULL and zero-length input the same.
* This is simpler than potentially calling calloc(0). */
if (output == NULL || output_len == 0) {
return PSA_SUCCESS;
}
output_copy->buffer = mbedtls_calloc(output_len, 1);
if (output_copy->buffer == NULL) {
/* Since we dealt with the zero-length case above, we know that
* a NULL return value means a failure of allocation. */
return PSA_ERROR_INSUFFICIENT_MEMORY;
}
output_copy->len = output_len;
output_copy->original = output;
return PSA_SUCCESS;
}
#endif /* MBEDTLS_PSA_CRYPTO_C */