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/interface/src/tfm_crypto_ipc_api.c b/interface/src/tfm_crypto_ipc_api.c
index da5358a..cd1f7f5 100644
--- a/interface/src/tfm_crypto_ipc_api.c
+++ b/interface/src/tfm_crypto_ipc_api.c
@@ -7,19 +7,18 @@
 
 #include "tfm_crypto_defs.h"
 #include "psa/crypto.h"
-#include "tfm_ns_interface.h"
-#include "psa_manifest/sid.h"
 #include "psa/client.h"
+#include "psa_manifest/sid.h"
+#include "tfm_ns_interface.h"
 
-#define API_DISPATCH(srv_name, srv_id)                          \
-    psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL,                   \
-        in_vec, IOVEC_LEN(in_vec),                              \
-        out_vec, IOVEC_LEN(out_vec))
-
-#define API_DISPATCH_NO_OUTVEC(srv_name, srv_id)                \
-    psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL,                   \
-        in_vec, IOVEC_LEN(in_vec),                              \
-        (psa_outvec *)NULL, 0)
+#define API_DISPATCH(in_vec, out_vec)          \
+    psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL,  \
+             in_vec, IOVEC_LEN(in_vec),        \
+             out_vec, IOVEC_LEN(out_vec))
+#define API_DISPATCH_NO_OUTVEC(in_vec)         \
+    psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL,  \
+             in_vec, IOVEC_LEN(in_vec),        \
+             (psa_outvec *)NULL, 0)
 
 psa_status_t psa_crypto_init(void)
 {
@@ -32,39 +31,31 @@
 psa_status_t psa_open_key(psa_key_id_t id,
                           psa_key_id_t *key)
 {
-    psa_status_t status;
     const struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_OPEN_KEY_SID,
+        .function_id = TFM_CRYPTO_OPEN_KEY_SID,
+        .key_id = id,
     };
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
-        {.base = &id, .len = sizeof(psa_key_id_t)},
     };
     psa_outvec out_vec[] = {
         {.base = key, .len = sizeof(psa_key_id_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_open_key,
-                          TFM_CRYPTO_OPEN_KEY);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_close_key(psa_key_id_t key)
 {
-    psa_status_t status;
     const struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CLOSE_KEY_SID,
+        .function_id = TFM_CRYPTO_CLOSE_KEY_SID,
         .key_id = key,
     };
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_close_key,
-                                    TFM_CRYPTO_CLOSE_KEY);;
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
@@ -72,9 +63,8 @@
                             size_t data_length,
                             psa_key_id_t *key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_IMPORT_KEY_SID,
+        .function_id = TFM_CRYPTO_IMPORT_KEY_SID,
     };
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
@@ -85,35 +75,27 @@
         {.base = key, .len = sizeof(psa_key_id_t)}
     };
 
-    status = API_DISPATCH(tfm_crypto_import_key,
-                          TFM_CRYPTO_IMPORT_KEY);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_destroy_key(psa_key_id_t key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_DESTROY_KEY_SID,
+        .function_id = TFM_CRYPTO_DESTROY_KEY_SID,
         .key_id = key,
     };
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_destroy_key,
-                                    TFM_CRYPTO_DESTROY_KEY);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_get_key_attributes(psa_key_id_t key,
                                     psa_key_attributes_t *attributes)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_GET_KEY_ATTRIBUTES_SID,
+        .function_id = TFM_CRYPTO_GET_KEY_ATTRIBUTES_SID,
         .key_id = key,
     };
     psa_invec in_vec[] = {
@@ -123,15 +105,13 @@
         {.base = attributes, .len = sizeof(psa_key_attributes_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_get_key_attributes,
-                          TFM_CRYPTO_GET_KEY_ATTRIBUTES);
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 void psa_reset_key_attributes(psa_key_attributes_t *attributes)
 {
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_RESET_KEY_ATTRIBUTES_SID,
+        .function_id = TFM_CRYPTO_RESET_KEY_ATTRIBUTES_SID,
     };
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
@@ -140,8 +120,7 @@
         {.base = attributes, .len = sizeof(psa_key_attributes_t)},
     };
 
-    (void)API_DISPATCH(tfm_crypto_reset_key_attributes,
-                       TFM_CRYPTO_RESET_KEY_ATTRIBUTES);
+    (void)API_DISPATCH(in_vec, out_vec);
     return;
 }
 
@@ -152,7 +131,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_EXPORT_KEY_SID,
+        .function_id = TFM_CRYPTO_EXPORT_KEY_SID,
         .key_id = key,
     };
     psa_invec in_vec[] = {
@@ -162,8 +141,7 @@
         {.base = data, .len = data_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_export_key,
-                          TFM_CRYPTO_EXPORT_KEY);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *data_length = out_vec[0].len;
 
@@ -177,7 +155,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_EXPORT_PUBLIC_KEY_SID,
+        .function_id = TFM_CRYPTO_EXPORT_PUBLIC_KEY_SID,
         .key_id = key,
     };
 
@@ -188,8 +166,7 @@
         {.base = data, .len = data_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_export_public_key,
-                          TFM_CRYPTO_EXPORT_PUBLIC_KEY);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *data_length = out_vec[0].len;
 
@@ -198,27 +175,23 @@
 
 psa_status_t psa_purge_key(psa_key_id_t key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_PURGE_KEY_SID,
+        .function_id = TFM_CRYPTO_PURGE_KEY_SID,
         .key_id = key,
     };
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_purge_key,
-                                    TFM_CRYPTO_PURGE_KEY);
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_copy_key(psa_key_id_t source_key,
                           const psa_key_attributes_t *attributes,
                           psa_key_id_t *target_key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_COPY_KEY_SID,
+        .function_id = TFM_CRYPTO_COPY_KEY_SID,
         .key_id = source_key,
     };
 
@@ -231,10 +204,7 @@
         {.base = target_key, .len = sizeof(psa_key_id_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_copy_key,
-                          TFM_CRYPTO_COPY_KEY);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
@@ -244,7 +214,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_GENERATE_IV_SID,
+        .function_id = TFM_CRYPTO_CIPHER_GENERATE_IV_SID,
         .op_handle = operation->handle,
     };
 
@@ -252,14 +222,12 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
     psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
         {.base = iv, .len = iv_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_generate_iv,
-                          TFM_CRYPTO_CIPHER_GENERATE_IV);
+    status = API_DISPATCH(in_vec, out_vec);
 
-    *iv_length = out_vec[1].len;
+    *iv_length = out_vec[0].len;
 
     return status;
 }
@@ -268,9 +236,8 @@
                                const unsigned char *iv,
                                size_t iv_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_SET_IV_SID,
+        .function_id = TFM_CRYPTO_CIPHER_SET_IV_SID,
         .op_handle = operation->handle,
     };
 
@@ -278,23 +245,16 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
         {.base = iv, .len = iv_length},
     };
-    psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
-    };
 
-    status = API_DISPATCH(tfm_crypto_cipher_set_iv,
-                          TFM_CRYPTO_CIPHER_SET_IV);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
                                       psa_key_id_t key,
                                       psa_algorithm_t alg)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_ENCRYPT_SETUP_SID,
+        .function_id = TFM_CRYPTO_CIPHER_ENCRYPT_SETUP_SID,
         .key_id = key,
         .alg = alg,
         .op_handle = operation->handle,
@@ -307,19 +267,15 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_encrypt_setup,
-                          TFM_CRYPTO_CIPHER_ENCRYPT_SETUP);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
                                       psa_key_id_t key,
                                       psa_algorithm_t alg)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_DECRYPT_SETUP_SID,
+        .function_id = TFM_CRYPTO_CIPHER_DECRYPT_SETUP_SID,
         .key_id = key,
         .alg = alg,
         .op_handle = operation->handle,
@@ -332,10 +288,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_decrypt_setup,
-                          TFM_CRYPTO_CIPHER_DECRYPT_SETUP);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
@@ -347,7 +300,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_UPDATE_SID,
+        .function_id = TFM_CRYPTO_CIPHER_UPDATE_SID,
         .op_handle = operation->handle,
     };
 
@@ -356,23 +309,20 @@
         {.base = input, .len = input_length},
     };
     psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
         {.base = output, .len = output_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_update,
-                          TFM_CRYPTO_CIPHER_UPDATE);
+    status = API_DISPATCH(in_vec, out_vec);
 
-    *output_length = out_vec[1].len;
+    *output_length = out_vec[0].len;
 
     return status;
 }
 
 psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_ABORT_SID,
+        .function_id = TFM_CRYPTO_CIPHER_ABORT_SID,
         .op_handle = operation->handle,
     };
 
@@ -383,10 +333,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_abort,
-                          TFM_CRYPTO_CIPHER_ABORT);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
@@ -396,7 +343,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_FINISH_SID,
+        .function_id = TFM_CRYPTO_CIPHER_FINISH_SID,
         .op_handle = operation->handle,
     };
 
@@ -408,8 +355,7 @@
         {.base = output, .len = output_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_finish,
-                          TFM_CRYPTO_CIPHER_FINISH);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *output_length = out_vec[1].len;
 
@@ -419,9 +365,8 @@
 psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
                             psa_algorithm_t alg)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_SETUP_SID,
+        .function_id = TFM_CRYPTO_HASH_SETUP_SID,
         .alg = alg,
         .op_handle = operation->handle,
     };
@@ -433,19 +378,15 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_hash_setup,
-                          TFM_CRYPTO_HASH_SETUP);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_hash_update(psa_hash_operation_t *operation,
                              const uint8_t *input,
                              size_t input_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_UPDATE_SID,
+        .function_id = TFM_CRYPTO_HASH_UPDATE_SID,
         .op_handle = operation->handle,
     };
 
@@ -453,14 +394,8 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
         {.base = input, .len = input_length},
     };
-    psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
-    };
 
-    status = API_DISPATCH(tfm_crypto_hash_update,
-                          TFM_CRYPTO_HASH_UPDATE);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
@@ -470,7 +405,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_FINISH_SID,
+        .function_id = TFM_CRYPTO_HASH_FINISH_SID,
         .op_handle = operation->handle,
     };
 
@@ -482,8 +417,7 @@
         {.base = hash, .len = hash_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_hash_finish,
-                          TFM_CRYPTO_HASH_FINISH);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *hash_length = out_vec[1].len;
 
@@ -494,9 +428,8 @@
                              const uint8_t *hash,
                              size_t hash_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_VERIFY_SID,
+        .function_id = TFM_CRYPTO_HASH_VERIFY_SID,
         .op_handle = operation->handle,
     };
 
@@ -508,17 +441,13 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_hash_verify,
-                          TFM_CRYPTO_HASH_VERIFY);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_ABORT_SID,
+        .function_id = TFM_CRYPTO_HASH_ABORT_SID,
         .op_handle = operation->handle,
     };
 
@@ -529,18 +458,14 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_hash_abort,
-                          TFM_CRYPTO_HASH_ABORT);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation,
                             psa_hash_operation_t *target_operation)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_CLONE_SID,
+        .function_id = TFM_CRYPTO_HASH_CLONE_SID,
         .op_handle = source_operation->handle,
     };
 
@@ -555,10 +480,7 @@
         return PSA_ERROR_BAD_STATE;
     }
 
-    status = API_DISPATCH(tfm_crypto_hash_clone,
-                          TFM_CRYPTO_HASH_CLONE);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_hash_compute(psa_algorithm_t alg,
@@ -570,7 +492,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_COMPUTE_SID,
+        .function_id = TFM_CRYPTO_HASH_COMPUTE_SID,
         .alg = alg,
     };
 
@@ -583,8 +505,7 @@
         {.base = hash, .len = hash_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_hash_compute,
-                          TFM_CRYPTO_HASH_COMPUTE);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *hash_length = out_vec[0].len;
 
@@ -597,9 +518,8 @@
                               const uint8_t *hash,
                               size_t hash_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_HASH_COMPARE_SID,
+        .function_id = TFM_CRYPTO_HASH_COMPARE_SID,
         .alg = alg,
     };
 
@@ -609,19 +529,15 @@
         {.base = hash, .len = hash_length},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_hash_compare,
-                          TFM_CRYPTO_HASH_COMPARE);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
                                 psa_key_id_t key,
                                 psa_algorithm_t alg)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_SIGN_SETUP_SID,
+        .function_id = TFM_CRYPTO_MAC_SIGN_SETUP_SID,
         .key_id = key,
         .alg = alg,
         .op_handle = operation->handle,
@@ -634,19 +550,15 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_mac_sign_setup,
-                          TFM_CRYPTO_MAC_SIGN_SETUP);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation,
                                   psa_key_id_t key,
                                   psa_algorithm_t alg)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_VERIFY_SETUP_SID,
+        .function_id = TFM_CRYPTO_MAC_VERIFY_SETUP_SID,
         .key_id = key,
         .alg = alg,
         .op_handle = operation->handle,
@@ -659,19 +571,15 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_mac_verify_setup,
-                          TFM_CRYPTO_MAC_VERIFY_SETUP);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_mac_update(psa_mac_operation_t *operation,
                             const uint8_t *input,
                             size_t input_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_UPDATE_SID,
+        .function_id = TFM_CRYPTO_MAC_UPDATE_SID,
         .op_handle = operation->handle,
     };
 
@@ -679,14 +587,8 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
         {.base = input, .len = input_length},
     };
-    psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
-    };
 
-    status = API_DISPATCH(tfm_crypto_mac_update,
-                          TFM_CRYPTO_MAC_UPDATE);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
@@ -696,7 +598,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_SIGN_FINISH_SID,
+        .function_id = TFM_CRYPTO_MAC_SIGN_FINISH_SID,
         .op_handle = operation->handle,
     };
 
@@ -708,8 +610,7 @@
         {.base = mac, .len = mac_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_mac_sign_finish,
-                          TFM_CRYPTO_MAC_SIGN_FINISH);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *mac_length = out_vec[1].len;
 
@@ -720,9 +621,8 @@
                                    const uint8_t *mac,
                                    size_t mac_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_VERIFY_FINISH_SID,
+        .function_id = TFM_CRYPTO_MAC_VERIFY_FINISH_SID,
         .op_handle = operation->handle,
     };
 
@@ -734,17 +634,13 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_mac_verify_finish,
-                          TFM_CRYPTO_MAC_VERIFY_FINISH);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_mac_abort(psa_mac_operation_t *operation)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_ABORT_SID,
+        .function_id = TFM_CRYPTO_MAC_ABORT_SID,
         .op_handle = operation->handle,
     };
 
@@ -755,10 +651,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_mac_abort,
-                          TFM_CRYPTO_MAC_ABORT);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_aead_encrypt(psa_key_id_t key,
@@ -775,7 +668,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_ENCRYPT_SID,
+        .function_id = TFM_CRYPTO_AEAD_ENCRYPT_SID,
         .key_id = key,
         .alg = alg,
         .aead_in = {.nonce = {0}, .nonce_length = 0}
@@ -836,7 +729,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_DECRYPT_SID,
+        .function_id = TFM_CRYPTO_AEAD_DECRYPT_SID,
         .key_id = key,
         .alg = alg,
         .aead_in = {.nonce = {0}, .nonce_length = 0}
@@ -889,7 +782,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_ENCRYPT_SETUP_SID,
+        .function_id = TFM_CRYPTO_AEAD_ENCRYPT_SETUP_SID,
         .key_id = key,
         .alg = alg,
         .op_handle = operation->handle,
@@ -902,8 +795,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)}
     };
 
-    status = API_DISPATCH(tfm_crypto_aead_encrypt_setup,
-                          TFM_CRYPTO_AEAD_ENCRYPT_SETUP);
+    status = API_DISPATCH(in_vec, out_vec);
     return status;
 }
 
@@ -913,7 +805,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_DECRYPT_SETUP_SID,
+        .function_id = TFM_CRYPTO_AEAD_DECRYPT_SETUP_SID,
         .key_id = key,
         .alg = alg,
         .op_handle = operation->handle,
@@ -926,8 +818,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)}
     };
 
-    status = API_DISPATCH(tfm_crypto_aead_decrypt_setup,
-                          TFM_CRYPTO_AEAD_DECRYPT_SETUP);
+    status = API_DISPATCH(in_vec, out_vec);
     return status;
 }
 
@@ -938,7 +829,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_GENERATE_NONCE_SID,
+        .function_id = TFM_CRYPTO_AEAD_GENERATE_NONCE_SID,
         .op_handle = operation->handle,
     };
 
@@ -946,14 +837,12 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
     psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
         {.base = nonce, .len = nonce_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_aead_generate_nonce,
-                          TFM_CRYPTO_AEAD_GENERATE_NONCE);
+    status = API_DISPATCH(in_vec, out_vec);
 
-    *nonce_length = out_vec[1].len;
+    *nonce_length = out_vec[0].len;
     return status;
 }
 
@@ -963,7 +852,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_SET_NONCE_SID,
+        .function_id = TFM_CRYPTO_AEAD_SET_NONCE_SID,
         .op_handle = operation->handle,
     };
 
@@ -971,12 +860,8 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
         {.base = nonce, .len = nonce_length}
     };
-    psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)}
-    };
 
-    status = API_DISPATCH(tfm_crypto_aead_set_nonce,
-                          TFM_CRYPTO_AEAD_SET_NONCE);
+    status = API_DISPATCH_NO_OUTVEC(in_vec);
     return status;
 }
 
@@ -986,7 +871,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_SET_LENGTHS_SID,
+        .function_id = TFM_CRYPTO_AEAD_SET_LENGTHS_SID,
         .ad_length = ad_length,
         .plaintext_length = plaintext_length,
         .op_handle = operation->handle,
@@ -995,12 +880,8 @@
     psa_invec in_vec[] = {
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
-    psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)}
-    };
 
-    status = API_DISPATCH(tfm_crypto_aead_set_lengths,
-                          TFM_CRYPTO_AEAD_SET_LENGTHS);
+    status = API_DISPATCH_NO_OUTVEC(in_vec);
     return status;
 }
 
@@ -1010,7 +891,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_UPDATE_AD_SID,
+        .function_id = TFM_CRYPTO_AEAD_UPDATE_AD_SID,
         .op_handle = operation->handle,
     };
 
@@ -1023,9 +904,6 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
         {.base = input, .len = input_length}
     };
-    psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)}
-    };
 
     size_t in_len = IOVEC_LEN(in_vec);
 
@@ -1033,7 +911,7 @@
         in_len--;
     }
     status = psa_call(TFM_CRYPTO_HANDLE, PSA_IPC_CALL, in_vec, in_len,
-                      out_vec, IOVEC_LEN(out_vec));
+                      NULL, 0);
     return status;
 }
 
@@ -1046,7 +924,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_UPDATE_SID,
+        .function_id = TFM_CRYPTO_AEAD_UPDATE_SID,
         .op_handle = operation->handle,
     };
 
@@ -1060,7 +938,6 @@
         {.base = input, .len = input_length}
     };
     psa_outvec out_vec[] = {
-        {.base = &(operation->handle), .len = sizeof(uint32_t)},
         {.base = output, .len = output_size},
     };
 
@@ -1072,7 +949,7 @@
     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;
+    *output_length = out_vec[0].len;
     return status;
 }
 
@@ -1086,7 +963,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_FINISH_SID,
+        .function_id = TFM_CRYPTO_AEAD_FINISH_SID,
         .op_handle = operation->handle,
     };
 
@@ -1117,13 +994,14 @@
                       in_vec, IOVEC_LEN(in_vec),
                       out_vec, out_len);
 
-    *tag_length = out_vec[1].len;
-
     if (out_len == 3) {
         *ciphertext_length = out_vec[2].len;
     } else {
         *ciphertext_length = 0;
     }
+
+    *tag_length = out_vec[1].len;
+
     return status;
 }
 
@@ -1136,7 +1014,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_VERIFY_SID,
+        .function_id = TFM_CRYPTO_AEAD_VERIFY_SID,
         .op_handle = operation->handle,
     };
 
@@ -1151,7 +1029,7 @@
     };
     psa_outvec out_vec[] = {
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
-        {.base = plaintext, .len = plaintext_size},
+        {.base = plaintext, .len = plaintext_size}
     };
 
     size_t out_len = IOVEC_LEN(out_vec);
@@ -1177,9 +1055,8 @@
 
 psa_status_t psa_aead_abort(psa_aead_operation_t *operation)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_AEAD_ABORT_SID,
+        .function_id = TFM_CRYPTO_AEAD_ABORT_SID,
         .op_handle = operation->handle,
     };
 
@@ -1190,9 +1067,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_aead_abort,
-                          TFM_CRYPTO_AEAD_ABORT);
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_sign_message(psa_key_id_t key,
@@ -1205,7 +1080,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_SIGN_MESSAGE_SID,
+        .function_id = TFM_CRYPTO_ASYMMETRIC_SIGN_MESSAGE_SID,
         .key_id = key,
         .alg = alg,
     };
@@ -1218,8 +1093,7 @@
         {.base = signature, .len = signature_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_sign_message,
-                          TFM_CRYPTO_SIGN_MESSAGE);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *signature_length = out_vec[0].len;
     return status;
@@ -1232,9 +1106,8 @@
                                 const uint8_t *signature,
                                 size_t signature_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_VERIFY_MESSAGE_SID,
+        .function_id = TFM_CRYPTO_ASYMMETRIC_VERIFY_MESSAGE_SID,
         .key_id = key,
         .alg = alg
     };
@@ -1245,10 +1118,7 @@
         {.base = signature, .len = signature_length}
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_verify_message,
-                                    TFM_CRYPTO_VERIFY_MESSAGE);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_sign_hash(psa_key_id_t key,
@@ -1261,7 +1131,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_SIGN_HASH_SID,
+        .function_id = TFM_CRYPTO_ASYMMETRIC_SIGN_HASH_SID,
         .key_id = key,
         .alg = alg,
     };
@@ -1274,8 +1144,7 @@
         {.base = signature, .len = signature_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_sign_hash,
-                          TFM_CRYPTO_SIGN_HASH);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *signature_length = out_vec[0].len;
 
@@ -1289,9 +1158,8 @@
                              const uint8_t *signature,
                              size_t signature_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_VERIFY_HASH_SID,
+        .function_id = TFM_CRYPTO_ASYMMETRIC_VERIFY_HASH_SID,
         .key_id = key,
         .alg = alg
     };
@@ -1302,10 +1170,7 @@
         {.base = signature, .len = signature_length}
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_verify_hash,
-                                    TFM_CRYPTO_VERIFY_HASH);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_asymmetric_encrypt(psa_key_id_t key,
@@ -1320,7 +1185,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_ASYMMETRIC_ENCRYPT_SID,
+        .function_id = TFM_CRYPTO_ASYMMETRIC_ENCRYPT_SID,
         .key_id = key,
         .alg = alg
     };
@@ -1365,7 +1230,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_ASYMMETRIC_DECRYPT_SID,
+        .function_id = TFM_CRYPTO_ASYMMETRIC_DECRYPT_SID,
         .key_id = key,
         .alg = alg
     };
@@ -1402,9 +1267,8 @@
                                 const psa_key_derivation_operation_t *operation,
                                 size_t *capacity)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_GET_CAPACITY_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_GET_CAPACITY_SID,
         .op_handle = operation->handle,
     };
 
@@ -1416,10 +1280,7 @@
         {.base = capacity, .len = sizeof(size_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_key_derivation_get_capacity,
-                          TFM_CRYPTO_KEY_DERIVATION_GET_CAPACITY);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_key_derivation_output_bytes(
@@ -1427,9 +1288,8 @@
                                       uint8_t *output,
                                       size_t output_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_SID,
         .op_handle = operation->handle,
     };
 
@@ -1441,10 +1301,7 @@
         {.base = output, .len = output_length},
     };
 
-    status = API_DISPATCH(tfm_crypto_key_derivation_output_bytes,
-                          TFM_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_key_derivation_input_key(
@@ -1452,9 +1309,8 @@
                                       psa_key_derivation_step_t step,
                                       psa_key_id_t key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_KEY_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_KEY_SID,
         .key_id = key,
         .step = step,
         .op_handle = operation->handle,
@@ -1464,17 +1320,13 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_input_key,
-                                    TFM_CRYPTO_KEY_DERIVATION_INPUT_KEY);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_key_derivation_abort(psa_key_derivation_operation_t *operation)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_ABORT_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_ABORT_SID,
         .op_handle = operation->handle,
     };
 
@@ -1486,10 +1338,7 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_key_derivation_abort,
-                          TFM_CRYPTO_KEY_DERIVATION_ABORT);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_key_derivation_key_agreement(
@@ -1499,9 +1348,8 @@
                                       const uint8_t *peer_key,
                                       size_t peer_key_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_SID,
         .key_id = private_key,
         .step = step,
         .op_handle = operation->handle,
@@ -1512,18 +1360,14 @@
         {.base = peer_key, .len = peer_key_length},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_key_agreement,
-                                    TFM_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_generate_random(uint8_t *output,
                                  size_t output_size)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_GENERATE_RANDOM_SID,
+        .function_id = TFM_CRYPTO_GENERATE_RANDOM_SID,
     };
 
     psa_invec in_vec[] = {
@@ -1538,18 +1382,14 @@
         return PSA_SUCCESS;
     }
 
-    status = API_DISPATCH(tfm_crypto_generate_random,
-                          TFM_CRYPTO_GENERATE_RANDOM);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_generate_key(const psa_key_attributes_t *attributes,
                               psa_key_id_t *key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_GENERATE_KEY_SID,
+        .function_id = TFM_CRYPTO_GENERATE_KEY_SID,
     };
 
     psa_invec in_vec[] = {
@@ -1561,10 +1401,7 @@
         {.base = key, .len = sizeof(psa_key_id_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_generate_key,
-                          TFM_CRYPTO_GENERATE_KEY);
-
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_mac_compute(psa_key_id_t key,
@@ -1577,7 +1414,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_COMPUTE_SID,
+        .function_id = TFM_CRYPTO_MAC_COMPUTE_SID,
         .key_id = key,
         .alg = alg,
     };
@@ -1590,8 +1427,7 @@
         {.base = mac, .len = mac_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_mac_compute,
-                          TFM_CRYPTO_MAC_COMPUTE);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *mac_length = out_vec[0].len;
     return status;
@@ -1604,9 +1440,8 @@
                             const uint8_t *mac,
                             const size_t mac_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_MAC_VERIFY_SID,
+        .function_id = TFM_CRYPTO_MAC_VERIFY_SID,
         .key_id = key,
         .alg = alg,
     };
@@ -1617,10 +1452,7 @@
         {.base = mac, .len = mac_length},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_mac_verify,
-                                    TFM_CRYPTO_MAC_VERIFY);
-
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_cipher_encrypt(psa_key_id_t key,
@@ -1633,7 +1465,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_ENCRYPT_SID,
+        .function_id = TFM_CRYPTO_CIPHER_ENCRYPT_SID,
         .key_id = key,
         .alg = alg,
     };
@@ -1646,8 +1478,7 @@
         {.base = output, .len = output_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_encrypt,
-                          TFM_CRYPTO_CIPHER_ENCRYPT);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *output_length = out_vec[0].len;
     return status;
@@ -1663,7 +1494,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_CIPHER_DECRYPT_SID,
+        .function_id = TFM_CRYPTO_CIPHER_DECRYPT_SID,
         .key_id = key,
         .alg = alg,
     };
@@ -1676,8 +1507,7 @@
         {.base = output, .len = output_size}
     };
 
-    status = API_DISPATCH(tfm_crypto_cipher_decrypt,
-                          TFM_CRYPTO_CIPHER_DECRYPT);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *output_length = out_vec[0].len;
     return status;
@@ -1693,7 +1523,7 @@
 {
     psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_RAW_KEY_AGREEMENT_SID,
+        .function_id = TFM_CRYPTO_RAW_KEY_AGREEMENT_SID,
         .alg = alg,
         .key_id = private_key
     };
@@ -1707,8 +1537,7 @@
         {.base = output, .len = output_size},
     };
 
-    status = API_DISPATCH(tfm_crypto_raw_key_agreement,
-                          TFM_CRYPTO_RAW_KEY_AGREEMENT);
+    status = API_DISPATCH(in_vec, out_vec);
 
     *output_length = out_vec[0].len;
 
@@ -1718,9 +1547,8 @@
 psa_status_t psa_key_derivation_setup(psa_key_derivation_operation_t *operation,
                                       psa_algorithm_t alg)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_SETUP_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_SETUP_SID,
         .alg = alg,
         .op_handle = operation->handle,
     };
@@ -1732,18 +1560,15 @@
         {.base = &(operation->handle), .len = sizeof(uint32_t)},
     };
 
-    status = API_DISPATCH(tfm_crypto_key_derivation_setup,
-                          TFM_CRYPTO_KEY_DERIVATION_SETUP);
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }
 
 psa_status_t psa_key_derivation_set_capacity(
                                       psa_key_derivation_operation_t *operation,
                                       size_t capacity)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_SET_CAPACITY_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_SET_CAPACITY_SID,
         .capacity = capacity,
         .op_handle = operation->handle,
     };
@@ -1752,9 +1577,7 @@
         {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_set_capacity,
-                                    TFM_CRYPTO_KEY_DERIVATION_SET_CAPACITY);
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_key_derivation_input_bytes(
@@ -1763,9 +1586,8 @@
                                       const uint8_t *data,
                                       size_t data_length)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_BYTES_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_BYTES_SID,
         .step = step,
         .op_handle = operation->handle,
     };
@@ -1775,9 +1597,7 @@
         {.base = data, .len = data_length},
     };
 
-    status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_input_bytes,
-                                    TFM_CRYPTO_KEY_DERIVATION_INPUT_BYTES);
-    return status;
+    return API_DISPATCH_NO_OUTVEC(in_vec);
 }
 
 psa_status_t psa_key_derivation_output_key(
@@ -1785,9 +1605,8 @@
                                       psa_key_derivation_operation_t *operation,
                                       psa_key_id_t *key)
 {
-    psa_status_t status;
     struct tfm_crypto_pack_iovec iov = {
-        .srv_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_KEY_SID,
+        .function_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_KEY_SID,
         .op_handle = operation->handle,
     };
 
@@ -1800,7 +1619,5 @@
         {.base = key, .len = sizeof(psa_key_id_t)}
     };
 
-    status = API_DISPATCH(tfm_crypto_key_derivation_output_key,
-                          TFM_CRYPTO_KEY_DERIVATION_OUTPUT_KEY);
-    return status;
+    return API_DISPATCH(in_vec, out_vec);
 }