Use local variable instead of an ouput parameter
Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
diff --git a/library/psa_crypto_cipher.c b/library/psa_crypto_cipher.c
index 6c696df..ed43085 100644
--- a/library/psa_crypto_cipher.c
+++ b/library/psa_crypto_cipher.c
@@ -458,38 +458,39 @@
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
- size_t olength;
+ size_t olength, accumulated_length;
status = cipher_encrypt_setup( &operation, attributes,
key_buffer, key_buffer_size, alg );
if( status != PSA_SUCCESS )
goto exit;
- *output_length = 0;
+ accumulated_length = 0;
if( operation.iv_length > 0 )
{
status = cipher_set_iv( &operation, output, operation.iv_length );
if( status != PSA_SUCCESS )
goto exit;
- *output_length = operation.iv_length;
+ accumulated_length = operation.iv_length;
}
- olength = 0;
status = cipher_update( &operation, input, input_length,
- output + *output_length,output_size - *output_length,
+ output + operation.iv_length,
+ output_size - operation.iv_length,
&olength );
- *output_length += olength;
+ accumulated_length += olength;
if( status != PSA_SUCCESS )
goto exit;
- olength = 0;
- status = cipher_finish( &operation, output + *output_length,
- output_size - *output_length, &olength );
- *output_length += olength;
+ status = cipher_finish( &operation, output + accumulated_length,
+ output_size - accumulated_length, &olength );
+ accumulated_length += olength;
if( status != PSA_SUCCESS )
goto exit;
+ *output_length = accumulated_length;
+
exit:
if( status == PSA_SUCCESS )
status = cipher_abort( &operation );
@@ -510,7 +511,7 @@
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
- size_t olength;
+ size_t olength, accumulated_length;
status = cipher_decrypt_setup( &operation, attributes,
key_buffer, key_buffer_size, alg );
@@ -524,21 +525,21 @@
goto exit;
}
- olength = 0;
status = cipher_update( &operation, input + operation.iv_length,
input_length - operation.iv_length,
output, output_size, &olength );
- *output_length = olength;
+ accumulated_length = olength;
if( status != PSA_SUCCESS )
goto exit;
- olength = 0;
- status = cipher_finish( &operation, output + *output_length,
- output_size - *output_length, &olength );
- *output_length += olength;
+ status = cipher_finish( &operation, output + accumulated_length,
+ output_size - accumulated_length, &olength );
+ accumulated_length += olength;
if( status != PSA_SUCCESS )
goto exit;
+ *output_length = accumulated_length;
+
exit:
if ( status == PSA_SUCCESS )
status = cipher_abort( &operation );