| From 92987ec20beedb44d08d429947958c1c068d815c Mon Sep 17 00:00:00 2001 |
| From: Julian Hall <julian.hall@arm.com> |
| Date: Wed, 16 Feb 2022 11:36:09 +0000 |
| Subject: [PATCH] Abort AEAD operation if client provided buffer is too small |
| |
| To enable PSA Arch test c258 to pass, handling is added in the |
| PSA API client adaptor for AEAD (psa_aead.c) to abort an AEAD |
| operation if an update operation is performed but the client |
| provided buffer for the output is too small. |
| |
| Signed-off-by: Julian Hall <julian.hall@arm.com> |
| Change-Id: Ib4b26ebc0a83a8928e1b643fba4becd935f6deb0 |
| |
| Upstream-Status: Pending [Not submitted to upstream yet] |
| Signed-off-by: Emekcan Aras <Emekcan.Aras@arm.com> |
| |
| |
| --- |
| components/service/crypto/client/psa/psa_aead.c | 14 +++++++++++++- |
| 1 file changed, 13 insertions(+), 1 deletion(-) |
| |
| diff --git a/components/service/crypto/client/psa/psa_aead.c b/components/service/crypto/client/psa/psa_aead.c |
| index 559eb6a3..c820d222 100644 |
| --- a/components/service/crypto/client/psa/psa_aead.c |
| +++ b/components/service/crypto/client/psa/psa_aead.c |
| @@ -74,10 +74,22 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation, |
| size_t output_size, |
| size_t *output_length) |
| { |
| - return crypto_caller_aead_update(&psa_crypto_client_instance.base, |
| + psa_status_t status = crypto_caller_aead_update(&psa_crypto_client_instance.base, |
| operation->handle, |
| input, input_length, |
| output, output_size, output_length); |
| + |
| + /* |
| + * If too small a buffer has been provided for the output, the operation |
| + * state will have been updated but the result can't be put anywhere. This |
| + * is an unrecoveral condition so abort the operation. |
| + */ |
| + if (status == PSA_ERROR_BUFFER_TOO_SMALL) { |
| + |
| + psa_aead_abort(operation); |
| + } |
| + |
| + return status; |
| } |
| |
| psa_status_t psa_aead_finish(psa_aead_operation_t *operation, |