Check the return status of the functions first

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 3701f72..6206237 100644
--- a/library/psa_crypto_cipher.c
+++ b/library/psa_crypto_cipher.c
@@ -482,16 +482,17 @@
                             output + operation.iv_length,
                             output_size - operation.iv_length,
                             &olength );
-    accumulated_length += olength;
     if( status != PSA_SUCCESS )
         goto exit;
 
+    accumulated_length += olength;
+
     status = cipher_finish( &operation, output + accumulated_length,
                             output_size - accumulated_length, &olength );
-    accumulated_length += olength;
     if( status != PSA_SUCCESS )
         goto exit;
 
+    accumulated_length += olength;
     *output_length = accumulated_length;
 
 exit:
@@ -531,17 +532,17 @@
     status = cipher_update( &operation, input + operation.iv_length,
                             input_length - operation.iv_length,
                             output, output_size, &olength );
-    accumulated_length = olength;
     if( status != PSA_SUCCESS )
         goto exit;
 
+    accumulated_length = olength;
 
     status = cipher_finish( &operation, output + accumulated_length,
                             output_size - accumulated_length, &olength );
-    accumulated_length += olength;
     if( status != PSA_SUCCESS )
         goto exit;
 
+    accumulated_length += olength;
     *output_length = accumulated_length;
 
 exit: