Crypto: Refactor the API dispatcher interface to reduce code size

This patch restructures the way the underlying APIs that
implements the PSA Crypto APIs are interfaced to the TF-M
Crypto service through a thin shim layer. The size of this
layer is reduced by nearly 45% on the default configuration.
Also, it removes the check for parameter number and size on
each function call as that is a redundant check as per the
overall threat model of the interaction between the crypto
service and the partition manager.

Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I07165bad00346cd12cf63620532f55da0c5d1262
diff --git a/secure_fw/partitions/crypto/crypto_alloc.c b/secure_fw/partitions/crypto/crypto_alloc.c
index 76fa8c2..7e3afe0 100644
--- a/secure_fw/partitions/crypto/crypto_alloc.c
+++ b/secure_fw/partitions/crypto/crypto_alloc.c
@@ -83,8 +83,9 @@
 }
 
 /*!
- * \defgroup public Public functions
- *
+ * \defgroup alloc Function that implement allocation and deallocation of
+ *                 contexts to be stored in the secure world for multipart
+ *                 operations
  */
 
 /*!@{*/
@@ -191,4 +192,35 @@
 
     return PSA_ERROR_BAD_STATE;
 }
+
+psa_status_t tfm_crypto_operation_handling(enum tfm_crypto_operation_type type,
+                                    enum tfm_crypto_function_type function_type,
+                                    uint32_t *handle,
+                                    void **ctx)
+{
+    psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
+
+    /* Multipart context retrieving and handling if required */
+    switch (function_type) {
+    case TFM_CRYPTO_FUNCTION_TYPE_SETUP:
+        /* Allocate the operation context in the secure world */
+        status = tfm_crypto_operation_alloc(type,
+                                            handle,
+                                            ctx);
+        break;
+    case TFM_CRYPTO_FUNCTION_TYPE_LOOKUP:
+        /* Look up the corresponding operation context */
+        status = tfm_crypto_operation_lookup(type,
+                                             *handle,
+                                             ctx);
+        break;
+    /* All the other APIs don't deal with multipart */
+    case TFM_CRYPTO_FUNCTION_TYPE_NON_MULTIPART:
+        status = PSA_ERROR_INVALID_ARGUMENT;
+    default:
+        break;
+    }
+
+    return status;
+}
 /*!@}*/