Crypto: Cover corner case for BAD_STATE error return
When starting a multipart operation using an handle for
a valid operation already in progress and not yet completed,
make sure to return BAD_STATE instead INVALID_HANDLE.
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I8c2598a6646fb3f7cf1ccd45b7b3fe0132f77721
diff --git a/secure_fw/partitions/crypto/crypto_alloc.c b/secure_fw/partitions/crypto/crypto_alloc.c
index b0fa4dc..1036a67 100644
--- a/secure_fw/partitions/crypto/crypto_alloc.c
+++ b/secure_fw/partitions/crypto/crypto_alloc.c
@@ -106,6 +106,13 @@
/* Handle must be initialised before calling a setup function */
if (*handle != TFM_CRYPTO_INVALID_HANDLE) {
+ if ((*handle <= TFM_CRYPTO_CONC_OPER_NUM) &&
+ (operation[*handle - 1].in_use == TFM_CRYPTO_IN_USE) &&
+ (operation[*handle - 1].owner == partition_id)) {
+ /* The handle is a valid one for already in progress operation */
+ return PSA_ERROR_BAD_STATE;
+ }
+
return PSA_ERROR_INVALID_HANDLE;
}