From ed96d687d773944666fe87f70d35485e8a10b8ae Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 31 Jan 2024 17:45:29 +0100 Subject: [PATCH] Move local buffer allocation just before usage Signed-off-by: Gabor Mezei --- library/psa_crypto.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index d745c46f7a..c6a0a8baa2 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -3776,9 +3776,6 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, LOCAL_INPUT_DECLARE(input_external, input); LOCAL_OUTPUT_DECLARE(output_external, output); - LOCAL_INPUT_ALLOC(input_external, input_length, input); - LOCAL_OUTPUT_ALLOC_WITH_COPY(output_external, output_size, output); - if (operation->id == 0) { status = PSA_ERROR_BAD_STATE; goto exit; @@ -3789,6 +3786,9 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, goto exit; } + LOCAL_INPUT_ALLOC(input_external, input_length, input); + LOCAL_OUTPUT_ALLOC_WITH_COPY(output_external, output_size, output); + status = psa_driver_wrapper_cipher_update(operation, input, input_length, @@ -3816,8 +3816,6 @@ psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, LOCAL_OUTPUT_DECLARE(output_external, output); - LOCAL_OUTPUT_ALLOC_WITH_COPY(output_external, output_size, output); - if (operation->id == 0) { status = PSA_ERROR_BAD_STATE; goto exit; @@ -3828,6 +3826,8 @@ psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, goto exit; } + LOCAL_OUTPUT_ALLOC_WITH_COPY(output_external, output_size, output); + status = psa_driver_wrapper_cipher_finish(operation, output, output_size, @@ -3882,9 +3882,6 @@ psa_status_t psa_cipher_encrypt(mbedtls_svc_key_id_t key, LOCAL_INPUT_DECLARE(input_external, input); LOCAL_OUTPUT_DECLARE(output_external, output); - LOCAL_INPUT_ALLOC(input_external, input_length, input); - LOCAL_OUTPUT_ALLOC(output_external, output_size, output); - if (!PSA_ALG_IS_CIPHER(alg)) { status = PSA_ERROR_INVALID_ARGUMENT; goto exit; @@ -3919,6 +3916,9 @@ psa_status_t psa_cipher_encrypt(mbedtls_svc_key_id_t key, } } + LOCAL_INPUT_ALLOC(input_external, input_length, input); + LOCAL_OUTPUT_ALLOC(output_external, output_size, output); + status = psa_driver_wrapper_cipher_encrypt( &attributes, slot->key.data, slot->key.bytes, alg, local_iv, default_iv_length, input, input_length, @@ -3962,9 +3962,6 @@ psa_status_t psa_cipher_decrypt(mbedtls_svc_key_id_t key, LOCAL_INPUT_DECLARE(input_external, input); LOCAL_OUTPUT_DECLARE(output_external, output); - LOCAL_INPUT_ALLOC(input_external, input_length, input); - LOCAL_OUTPUT_ALLOC(output_external, output_size, output); - if (!PSA_ALG_IS_CIPHER(alg)) { status = PSA_ERROR_INVALID_ARGUMENT; goto exit; @@ -3986,6 +3983,9 @@ psa_status_t psa_cipher_decrypt(mbedtls_svc_key_id_t key, goto exit; } + LOCAL_INPUT_ALLOC(input_external, input_length, input); + LOCAL_OUTPUT_ALLOC(output_external, output_size, output); + status = psa_driver_wrapper_cipher_decrypt( &attributes, slot->key.data, slot->key.bytes, alg, input, input_length,