Crypto: Improve alloc module interface
The interface of the alloc module in the Crypto service
is amended to be more robust. Also, the context allocation
API is modified to return the allocated context in order
to save an additional look-up operation.
Change-Id: Ida5d2913d3565eb288e2ff9ac90dad029d5a2f04
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
diff --git a/secure_fw/services/crypto/crypto_cipher.c b/secure_fw/services/crypto/crypto_cipher.c
index b53ace0..85fe892 100644
--- a/secure_fw/services/crypto/crypto_cipher.c
+++ b/secure_fw/services/crypto/crypto_cipher.c
@@ -50,7 +50,7 @@
}
/* Release the operation context */
- err = tfm_crypto_operation_release(&(operation->handle));
+ err = tfm_crypto_operation_release(TFM_CRYPTO_CIPHER_OPERATION, operation);
if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
return err;
}
@@ -113,21 +113,12 @@
/* Allocate the operation context in the secure world */
err = tfm_crypto_operation_alloc(TFM_CRYPTO_CIPHER_OPERATION,
- &(operation->handle));
+ operation,
+ (void **)&ctx);
if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
return err;
}
- /* Look up the corresponding operation context */
- err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
- operation->handle,
- (void **)&ctx);
- if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
- /* Release the operation context */
- (void)tfm_crypto_operation_release(&(operation->handle));
- return err;
- }
-
/* Set the proper cipher mode (encrypt/decrypt) in the operation context */
ctx->cipher_mode = (uint8_t) c_mode;
@@ -222,7 +213,7 @@
/* Look up the corresponding operation context */
err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
- operation->handle,
+ operation,
(void **)&ctx);
if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
return err;
@@ -318,7 +309,7 @@
/* Look up the corresponding operation context */
err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
- operation->handle,
+ operation,
(void **)&ctx);
if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
return err;
@@ -396,7 +387,7 @@
/* Look up the corresponding operation context */
err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
- operation->handle,
+ operation,
(void **)&ctx);
if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
return err;
@@ -438,7 +429,7 @@
/* Look up the corresponding operation context */
err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
- operation->handle,
+ operation,
(void **)&ctx);
if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
return err;