Crypto: Remove unnecessary multi-part operation clean-up
Remove unnecessary clean up steps from other multi-part operation
function. Otherwise, the PSA multi-part operation object content can be
cleaned before the underlying crypto library frees resouces specified
in the content, which may cause memory leakage.
The multi-part operation structure will be eventually cleaned in
psa_xxx_abort() when an error occurs during multi-part operations.
Change-Id: I9cd0fa3881e5c7c27b60883d04c186a3ea58bc9c
Signed-off-by: David Hu <david.hu@arm.com>
diff --git a/secure_fw/partitions/crypto/crypto_cipher.c b/secure_fw/partitions/crypto/crypto_cipher.c
index 03849df..5a318ef 100644
--- a/secure_fw/partitions/crypto/crypto_cipher.c
+++ b/secure_fw/partitions/crypto/crypto_cipher.c
@@ -57,14 +57,7 @@
*handle_out = handle;
- status = psa_cipher_generate_iv(operation, iv, iv_size, &out_vec[1].len);
- if (status != PSA_SUCCESS) {
- /* Release the operation context, ignore if the operation fails. */
- (void)tfm_crypto_operation_release(handle_out);
- return status;
- }
-
- return status;
+ return psa_cipher_generate_iv(operation, iv, iv_size, &out_vec[1].len);
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}
@@ -102,14 +95,7 @@
return status;
}
- status = psa_cipher_set_iv(operation, iv, iv_length);
- if (status != PSA_SUCCESS) {
- /* Release the operation context, ignore if the operation fails. */
- (void)tfm_crypto_operation_release(handle_out);
- return status;
- }
-
- return status;
+ return psa_cipher_set_iv(operation, iv, iv_length);
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}
@@ -153,17 +139,20 @@
status = tfm_crypto_encode_id_and_owner(key_id, &encoded_key);
if (status != PSA_SUCCESS) {
- return status;
+ goto exit;
}
status = psa_cipher_encrypt_setup(operation, encoded_key, alg);
if (status != PSA_SUCCESS) {
- /* Release the operation context, ignore if the operation fails. */
- (void)tfm_crypto_operation_release(handle_out);
- return status;
+ goto exit;
}
return status;
+
+exit:
+ /* Release the operation context, ignore if the operation fails. */
+ (void)tfm_crypto_operation_release(handle_out);
+ return status;
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}
@@ -207,17 +196,20 @@
*handle_out = handle;
status = tfm_crypto_encode_id_and_owner(key_id, &encoded_key);
if (status != PSA_SUCCESS) {
- return status;
+ goto exit;
}
status = psa_cipher_decrypt_setup(operation, encoded_key, alg);
if (status != PSA_SUCCESS) {
- /* Release the operation context, ignore if the operation fails. */
- (void)tfm_crypto_operation_release(handle_out);
- return status;
+ goto exit;
}
return status;
+
+exit:
+ /* Release the operation context, ignore if the operation fails. */
+ (void)tfm_crypto_operation_release(handle_out);
+ return status;
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}
@@ -261,15 +253,8 @@
return status;
}
- status = psa_cipher_update(operation, input, input_length,
- output, output_size, &out_vec[1].len);
- if (status != PSA_SUCCESS) {
- /* Release the operation context, ignore if the operation fails. */
- (void)tfm_crypto_operation_release(handle_out);
- return status;
- }
-
- return status;
+ return psa_cipher_update(operation, input, input_length,
+ output, output_size, &out_vec[1].len);
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}
@@ -311,14 +296,11 @@
}
status = psa_cipher_finish(operation, output, output_size, &out_vec[1].len);
- if (status != PSA_SUCCESS) {
+ if (status == PSA_SUCCESS) {
/* Release the operation context, ignore if the operation fails. */
(void)tfm_crypto_operation_release(handle_out);
- return status;
}
- status = tfm_crypto_operation_release(handle_out);
-
return status;
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}
@@ -364,9 +346,7 @@
return status;
}
- status = tfm_crypto_operation_release(handle_out);
-
- return status;
+ return tfm_crypto_operation_release(handle_out);
#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
}