Crypto: Support optional inputs in aead_update and aead_update_ad
The PSA APIs psa_aead_update_ad() and psa_aead_update() support
the inputs as optional values (i.e. NULL/zero-length buffers),
hence make sure this case is handled correctly in IPC mode.
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I1ec39359557921769ca475e6c69fab26cb6ca901
diff --git a/interface/src/tfm_crypto_ipc_api.c b/interface/src/tfm_crypto_ipc_api.c
index 29fbf95..cd43112 100644
--- a/interface/src/tfm_crypto_ipc_api.c
+++ b/interface/src/tfm_crypto_ipc_api.c
@@ -1012,6 +1012,11 @@
.op_handle = operation->handle,
};
+ /* Sanitize the optional input */
+ if ((input == NULL) && (input_length != 0)) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+
psa_invec in_vec[] = {
{.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
{.base = input, .len = input_length}
@@ -1020,8 +1025,12 @@
{.base = &(operation->handle), .len = sizeof(uint32_t)}
};
- status = API_DISPATCH(tfm_crypto_aead_update_ad,
- TFM_CRYPTO_AEAD_UPDATE_AD);
+ size_t in_len = IOVEC_LEN(in_vec);
+ if (input == NULL) {
+ in_len--;
+ }
+ status = psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL, in_vec, in_len,
+ out_vec, IOVEC_LEN(out_vec));
return status;
}
@@ -1038,6 +1047,11 @@
.op_handle = operation->handle,
};
+ /* Sanitize the optional input */
+ if ((input == NULL) && (input_length != 0)) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+
psa_invec in_vec[] = {
{.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
{.base = input, .len = input_length}
@@ -1047,8 +1061,12 @@
{.base = output, .len = output_size},
};
- status = API_DISPATCH(tfm_crypto_aead_update,
- TFM_CRYPTO_AEAD_UPDATE);
+ size_t in_len = IOVEC_LEN(in_vec);
+ if (input == NULL) {
+ in_len--;
+ }
+ status = psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL, in_vec, in_len,
+ out_vec, IOVEC_LEN(out_vec));
*output_length = out_vec[1].len;
return status;