From 8b8e485961b3852cdea1b68c7f05ab2221e4ce55 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 beac5a88a8..8f89b6bc1b 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -4418,9 +4418,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; @@ -4431,6 +4428,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, @@ -4458,8 +4458,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; @@ -4470,6 +4468,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, @@ -4524,9 +4524,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; @@ -4561,6 +4558,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, @@ -4604,9 +4604,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; @@ -4632,6 +4629,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,