blob: 077fcebafb65615a45f02cc495713c1a7637992b [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Kevin Peng6aa48952022-01-28 15:40:46 +08002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
Antonio de Angelis202425a2022-04-06 11:13:15 +01007#include <stdbool.h>
Antonio de Angelis8908f472018-08-31 15:44:25 +01008
Jamie Fox0e54ebc2019-04-09 14:21:04 +01009#include "tfm_mbedcrypto_include.h"
10
Antonio de Angelis8908f472018-08-31 15:44:25 +010011#include "tfm_crypto_api.h"
Jamie Fox0e54ebc2019-04-09 14:21:04 +010012#include "tfm_crypto_defs.h"
Summer Qinc737ece2020-08-28 10:47:26 +080013#include "tfm_sp_log.h"
Jamie Fox0e54ebc2019-04-09 14:21:04 +010014
15/*
16 * \brief This Mbed TLS include is needed to initialise the memory allocator
Antonio de Angelis202425a2022-04-06 11:13:15 +010017 * of the library used for internal allocations
Jamie Fox0e54ebc2019-04-09 14:21:04 +010018 */
19#include "mbedtls/memory_buffer_alloc.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010020
Raef Coles618fc152021-06-18 09:26:46 +010021#ifdef CRYPTO_NV_SEED
22#include "tfm_plat_crypto_nv_seed.h"
23#endif /* CRYPTO_NV_SEED */
Summer Qina5448d62020-12-07 14:03:37 +080024
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010025#ifndef TFM_PSA_API
26#include "tfm_secure_api.h"
27#endif
28
Raef Colesd2485af2019-10-30 10:15:33 +000029#ifdef CRYPTO_HW_ACCELERATOR
30#include "crypto_hw.h"
Michel Jaouenf41c6422021-10-07 14:38:08 +020031#endif /* CRYPTO_HW_ACCELERATOR */
Raef Colesd2485af2019-10-30 10:15:33 +000032
Antonio de Angelis202425a2022-04-06 11:13:15 +010033#ifndef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
34#error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER must be selected in Mbed TLS config file"
35#endif
36
37/**
38 * \brief Type describing the properties of each function identifier, i.e. the
39 * group ID and the function type
40 */
41struct tfm_crypto_api_descriptor {
42 uint8_t group_id : 6; /*!< Value from \ref tfm_crypto_group_id */
43 uint8_t function_type: 2; /*!< Value from \ref tfm_crypto_function_type */
44};
45
46/**
47 * \brief This table contains the description of each of the function IDs
48 * defined by \ref tfm_crypto_function_id
49 */
50#define X(_function_id, _group_id, _function_type) \
51 [_function_id] = {.group_id = _group_id, .function_type = _function_type},
52static const struct tfm_crypto_api_descriptor tfm_crypto_api_descriptor[] = {
53 TFM_CRYPTO_SERVICE_API_DESCRIPTION
54};
55#undef X
56
57enum tfm_crypto_function_type get_function_type_from_descriptor(enum tfm_crypto_function_id func)
58{
59 return tfm_crypto_api_descriptor[func].function_type;
60}
61
62enum tfm_crypto_group_id get_group_id_from_descriptor(enum tfm_crypto_function_id func)
63{
64 return tfm_crypto_api_descriptor[func].group_id;
65}
66
Antonio de Angelis4743e672019-04-11 11:38:48 +010067#ifdef TFM_PSA_API
Ken Liub671d682022-05-12 20:39:29 +080068#include <string.h>
Kevin Pengfe730cc2022-04-11 17:48:42 +080069#include "psa/framework_feature.h"
Jamie Foxcc31d402019-01-28 17:13:52 +000070#include "psa/service.h"
Edison Aicc4c6162019-06-21 13:52:49 +080071#include "psa_manifest/tfm_crypto.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010072
73/**
Antonio de Angelis4743e672019-04-11 11:38:48 +010074 * \brief Aligns a value x up to an alignment a.
75 */
76#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
77
78/**
79 * \brief Maximum alignment required by any iovec parameters to the TF-M Crypto
80 * partition.
81 */
82#define TFM_CRYPTO_IOVEC_ALIGNMENT (4u)
83
Kevin Pengfe730cc2022-04-11 17:48:42 +080084#if PSA_FRAMEWORK_HAS_MM_IOVEC == 1
85static int32_t g_client_id;
86
87static void tfm_crypto_set_caller_id(int32_t id)
88{
89 g_client_id = id;
90}
91
92psa_status_t tfm_crypto_get_caller_id(int32_t *id)
93{
94 *id = g_client_id;
95 return PSA_SUCCESS;
96}
97
98static psa_status_t tfm_crypto_init_iovecs(const psa_msg_t *msg,
99 psa_invec in_vec[],
100 size_t in_len,
101 psa_outvec out_vec[],
102 size_t out_len)
103{
104 uint32_t i;
105
106 /* Map from the second element as the first is read when parsing */
107 for (i = 1; i < in_len; i++) {
108 in_vec[i].len = msg->in_size[i];
109 if (in_vec[i].len != 0) {
110 in_vec[i].base = psa_map_invec(msg->handle, i);
111 } else {
112 in_vec[i].base = NULL;
113 }
114 }
115
116 for (i = 0; i < out_len; i++) {
117 out_vec[i].len = msg->out_size[i];
118 if (out_vec[i].len != 0) {
119 out_vec[i].base = psa_map_outvec(msg->handle, i);
120 } else {
121 out_vec[i].base = NULL;
122 }
123 }
124
125 return PSA_SUCCESS;
126}
127#else /* PSA_FRAMEWORK_HAS_MM_IOVEC == 1 */
Antonio de Angelis4743e672019-04-11 11:38:48 +0100128/**
129 * \brief Default size of the internal scratch buffer used for IOVec allocations
130 * in bytes
131 */
132#ifndef TFM_CRYPTO_IOVEC_BUFFER_SIZE
Soby Mathew7740b602020-10-07 12:08:28 +0100133#error TFM_CRYPTO_IOVEC_BUFFER_SIZE is not defined
Antonio de Angelis4743e672019-04-11 11:38:48 +0100134#endif
135
136/**
137 * \brief Internal scratch used for IOVec allocations
138 *
139 */
140static struct tfm_crypto_scratch {
141 __attribute__((__aligned__(TFM_CRYPTO_IOVEC_ALIGNMENT)))
142 uint8_t buf[TFM_CRYPTO_IOVEC_BUFFER_SIZE];
143 uint32_t alloc_index;
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100144 int32_t owner;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100145} scratch = {.buf = {0}, .alloc_index = 0};
146
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100147static psa_status_t tfm_crypto_set_scratch_owner(int32_t id)
148{
149 scratch.owner = id;
150 return PSA_SUCCESS;
151}
152
153static psa_status_t tfm_crypto_get_scratch_owner(int32_t *id)
154{
155 *id = scratch.owner;
156 return PSA_SUCCESS;
157}
158
Antonio de Angelis4743e672019-04-11 11:38:48 +0100159static psa_status_t tfm_crypto_alloc_scratch(size_t requested_size, void **buf)
160{
161 /* Ensure alloc_index remains aligned to the required iovec alignment */
162 requested_size = ALIGN(requested_size, TFM_CRYPTO_IOVEC_ALIGNMENT);
163
164 if (requested_size > (sizeof(scratch.buf) - scratch.alloc_index)) {
165 return PSA_ERROR_INSUFFICIENT_MEMORY;
166 }
167
168 /* Compute the pointer to the allocated space */
169 *buf = (void *)&scratch.buf[scratch.alloc_index];
170
171 /* Increase the allocated size */
172 scratch.alloc_index += requested_size;
173
174 return PSA_SUCCESS;
175}
176
Kevin Pengfe730cc2022-04-11 17:48:42 +0800177static void tfm_crypto_clear_scratch(void)
Antonio de Angelis4743e672019-04-11 11:38:48 +0100178{
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100179 scratch.owner = 0;
Ken Liub671d682022-05-12 20:39:29 +0800180 (void)memset(scratch.buf, 0, scratch.alloc_index);
Summer Qin0a9e5372020-11-27 16:04:05 +0800181 scratch.alloc_index = 0;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100182}
183
Kevin Pengfe730cc2022-04-11 17:48:42 +0800184static void tfm_crypto_set_caller_id(int32_t id)
185{
186 /* Set the owner of the data in the scratch */
187 (void)tfm_crypto_set_scratch_owner(id);
188}
189
190psa_status_t tfm_crypto_get_caller_id(int32_t *id)
191{
192 return tfm_crypto_get_scratch_owner(id);
193}
194
195static psa_status_t tfm_crypto_init_iovecs(const psa_msg_t *msg,
196 psa_invec in_vec[],
197 size_t in_len,
198 psa_outvec out_vec[],
199 size_t out_len)
200{
201 uint32_t i;
202 void *alloc_buf_ptr = NULL;
203 psa_status_t status;
204
205 /* Alloc/read from the second element as the first is read when parsing */
206 for (i = 1; i < in_len; i++) {
207 /* Allocate necessary space in the internal scratch */
208 status = tfm_crypto_alloc_scratch(msg->in_size[i], &alloc_buf_ptr);
209 if (status != PSA_SUCCESS) {
210 tfm_crypto_clear_scratch();
211 return status;
212 }
213 /* Read from the IPC framework inputs into the scratch */
214 in_vec[i].len =
215 psa_read(msg->handle, i, alloc_buf_ptr, msg->in_size[i]);
216 /* Populate the fields of the input to the secure function */
217 in_vec[i].base = alloc_buf_ptr;
218 }
219
220 for (i = 0; i < out_len; i++) {
221 /* Allocate necessary space for the output in the internal scratch */
222 status = tfm_crypto_alloc_scratch(msg->out_size[i], &alloc_buf_ptr);
223 if (status != PSA_SUCCESS) {
224 tfm_crypto_clear_scratch();
225 return status;
226 }
227 /* Populate the fields of the output to the secure function */
228 out_vec[i].base = alloc_buf_ptr;
229 out_vec[i].len = msg->out_size[i];
230 }
231
232 return PSA_SUCCESS;
233}
234#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC == 1 */
235
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800236static psa_status_t tfm_crypto_call_srv(const psa_msg_t *msg)
Antonio de Angelis4743e672019-04-11 11:38:48 +0100237{
238 psa_status_t status = PSA_SUCCESS;
TTornblomfaf74f52020-03-04 17:56:27 +0100239 size_t in_len = PSA_MAX_IOVEC, out_len = PSA_MAX_IOVEC, i;
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100240 psa_invec in_vec[PSA_MAX_IOVEC] = { {NULL, 0} };
241 psa_outvec out_vec[PSA_MAX_IOVEC] = { {NULL, 0} };
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800242 struct tfm_crypto_pack_iovec iov = {0};
Antonio de Angelis4743e672019-04-11 11:38:48 +0100243
244 /* Check the number of in_vec filled */
Jamie Fox9a234e22019-04-30 11:12:05 +0100245 while ((in_len > 0) && (msg->in_size[in_len - 1] == 0)) {
246 in_len--;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100247 }
248
Kevin Pengfe730cc2022-04-11 17:48:42 +0800249 /* Check the number of out_vec filled */
250 while ((out_len > 0) && (msg->out_size[out_len - 1] == 0)) {
251 out_len--;
252 }
253
Antonio de Angelis4743e672019-04-11 11:38:48 +0100254 /* There will always be a tfm_crypto_pack_iovec in the first iovec */
255 if (in_len < 1) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100256 return PSA_ERROR_GENERIC_ERROR;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100257 }
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800258
259 if (psa_read(msg->handle, 0, &iov, sizeof(iov)) != sizeof(iov)) {
260 return PSA_ERROR_GENERIC_ERROR;
261 }
262
Antonio de Angelis4743e672019-04-11 11:38:48 +0100263 /* Initialise the first iovec with the IOV read when parsing */
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800264 in_vec[0].base = &iov;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100265 in_vec[0].len = sizeof(struct tfm_crypto_pack_iovec);
266
Kevin Pengfe730cc2022-04-11 17:48:42 +0800267 status = tfm_crypto_init_iovecs(msg, in_vec, in_len, out_vec, out_len);
268 if (status != PSA_SUCCESS) {
269 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100270 }
271
Kevin Pengfe730cc2022-04-11 17:48:42 +0800272 tfm_crypto_set_caller_id(msg->client_id);
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100273
Antonio de Angelis202425a2022-04-06 11:13:15 +0100274 /* Call the dispatcher to the functions that implement the PSA Crypto API */
275 status = tfm_crypto_api_dispatcher(in_vec, in_len, out_vec, out_len);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100276
Kevin Pengfe730cc2022-04-11 17:48:42 +0800277#if PSA_FRAMEWORK_HAS_MM_IOVEC == 1
278 for (i = 0; i < out_len; i++) {
279 if (out_vec[i].base != NULL) {
280 psa_unmap_outvec(msg->handle, i, out_vec[i].len);
281 }
282 }
283#else
Antonio de Angelis4743e672019-04-11 11:38:48 +0100284 /* Write into the IPC framework outputs from the scratch */
285 for (i = 0; i < out_len; i++) {
286 psa_write(msg->handle, i, out_vec[i].base, out_vec[i].len);
287 }
288
289 /* Clear the allocated internal scratch before returning */
Summer Qin0a9e5372020-11-27 16:04:05 +0800290 tfm_crypto_clear_scratch();
Kevin Pengfe730cc2022-04-11 17:48:42 +0800291#endif
Antonio de Angelis4743e672019-04-11 11:38:48 +0100292
293 return status;
294}
Kevin Pengfe730cc2022-04-11 17:48:42 +0800295#else /* TFM_PSA_API */
296psa_status_t tfm_crypto_get_caller_id(int32_t *id)
297{
298 int32_t res;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100299
Kevin Pengfe730cc2022-04-11 17:48:42 +0800300 res = tfm_core_get_caller_client_id(id);
301 if (res != TFM_SUCCESS) {
302 return PSA_ERROR_NOT_PERMITTED;
303 } else {
304 return PSA_SUCCESS;
305 }
306}
Antonio de Angelis4743e672019-04-11 11:38:48 +0100307#endif /* TFM_PSA_API */
308
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100309/**
310 * \brief Default value for the size of the static buffer used by Mbed
311 * Crypto for its dynamic allocations
312 */
313#ifndef TFM_CRYPTO_ENGINE_BUF_SIZE
Soby Mathew7740b602020-10-07 12:08:28 +0100314#error TFM_CRYPTO_ENGINE_BUF_SIZE is not defined
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100315#endif
316
317/**
318 * \brief Static buffer to be used by Mbed Crypto for memory allocations
319 *
320 */
321static uint8_t mbedtls_mem_buf[TFM_CRYPTO_ENGINE_BUF_SIZE] = {0};
322
323static psa_status_t tfm_crypto_engine_init(void)
324{
Raef Coles618fc152021-06-18 09:26:46 +0100325#ifdef CRYPTO_NV_SEED
Antonio de Angelis202425a2022-04-06 11:13:15 +0100326 LOG_INFFMT("[INF][Crypto] ");
Raef Coles618fc152021-06-18 09:26:46 +0100327#ifdef TFM_PSA_API
Antonio de Angelis202425a2022-04-06 11:13:15 +0100328 LOG_INFFMT("Provisioning entropy seed... ");
Raef Coles618fc152021-06-18 09:26:46 +0100329 if (tfm_plat_crypto_provision_entropy_seed() != TFM_CRYPTO_NV_SEED_SUCCESS) {
Summer Qina5448d62020-12-07 14:03:37 +0800330 return PSA_ERROR_GENERIC_ERROR;
331 }
Antonio de Angelis202425a2022-04-06 11:13:15 +0100332 LOG_INFFMT("\033[0;32mcomplete.\033[0m\r\n");
Raef Coles618fc152021-06-18 09:26:46 +0100333#else
Raef Coles618fc152021-06-18 09:26:46 +0100334 LOG_INFFMT("TF-M in library mode uses a dummy NV seed. ");
335 LOG_INFFMT("This is not suitable for production! ");
Antonio de Angelis202425a2022-04-06 11:13:15 +0100336 LOG_INFFMT("This device is \033[1;31mNOT SECURE\033[0m\r\n");
Raef Coles618fc152021-06-18 09:26:46 +0100337#endif /* TFM_PSA_API */
338#endif /* CRYPTO_NV_SEED */
Summer Qina5448d62020-12-07 14:03:37 +0800339
Antonio de Angelis202425a2022-04-06 11:13:15 +0100340 /* Initialise the Mbed Crypto memory allocator to use static memory
341 * allocation from the provided buffer instead of using the heap
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100342 */
343 mbedtls_memory_buffer_alloc_init(mbedtls_mem_buf,
344 TFM_CRYPTO_ENGINE_BUF_SIZE);
345
Raef Colesd2485af2019-10-30 10:15:33 +0000346 /* Initialise the crypto accelerator if one is enabled */
347#ifdef CRYPTO_HW_ACCELERATOR
Antonio de Angelis202425a2022-04-06 11:13:15 +0100348 LOG_INFFMT("[INF][Crypto] Initialising HW accelerator... ");
Raef Colesd2485af2019-10-30 10:15:33 +0000349 if (crypto_hw_accelerator_init() != 0) {
350 return PSA_ERROR_HARDWARE_FAILURE;
351 }
Antonio de Angelis202425a2022-04-06 11:13:15 +0100352 LOG_INFFMT("\033[0;32mcomplete.\033[0m\r\n");
Raef Colesd2485af2019-10-30 10:15:33 +0000353#endif /* CRYPTO_HW_ACCELERATOR */
354
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100355 /* Previous function does not return any value, so just call the
356 * initialisation function of the Mbed Crypto layer
357 */
358 return psa_crypto_init();
359}
360
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000361static psa_status_t tfm_crypto_module_init(void)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100362{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100363 /* Init the Alloc module */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000364 return tfm_crypto_init_alloc();
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100365}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100366
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000367psa_status_t tfm_crypto_init(void)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100368{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100369 psa_status_t status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100370
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100371 /* Initialise other modules of the service */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000372 status = tfm_crypto_module_init();
373 if (status != PSA_SUCCESS) {
374 return status;
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100375 }
376
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100377 /* Initialise the engine layer */
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800378 return tfm_crypto_engine_init();
379}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100380
Antonio de Angelis4743e672019-04-11 11:38:48 +0100381#ifdef TFM_PSA_API
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800382psa_status_t tfm_crypto_sfn(const psa_msg_t *msg)
383{
384 /* Process the message type */
385 switch (msg->type) {
386 case PSA_IPC_CALL:
387 return tfm_crypto_call_srv(msg);
388 default:
389 return PSA_ERROR_NOT_SUPPORTED;
390 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100391
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800392 return PSA_ERROR_GENERIC_ERROR;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100393}
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800394#endif
Antonio de Angelis202425a2022-04-06 11:13:15 +0100395
396psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[],
397 size_t in_len,
398 psa_outvec out_vec[],
399 size_t out_len)
400{
401 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
402 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
403 int32_t caller_id = 0;
404 mbedtls_svc_key_id_t encoded_key = MBEDTLS_SVC_KEY_ID_INIT;
405 bool is_key_required = false;
406
407 if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) {
408 return PSA_ERROR_PROGRAMMER_ERROR;
409 }
410
411 is_key_required = !(TFM_CRYPTO_IS_GROUP_ID(
412 iov->function_id, TFM_CRYPTO_GROUP_ID_HASH) ||
413 (iov->function_id == TFM_CRYPTO_GENERATE_RANDOM_SID));
414
415 if (is_key_required) {
416 status = tfm_crypto_get_caller_id(&caller_id);
417 if (status != PSA_SUCCESS) {
418 return status;
419 }
420 /* The caller_id being set in the owner field is the partition ID
421 * of the calling partition
422 */
423 encoded_key = mbedtls_svc_key_id_make(caller_id, iov->key_id);
424 }
425
426 /* Dispatch to each sub-module based on the Group ID */
427 if (TFM_CRYPTO_IS_GROUP_ID(
428 iov->function_id, TFM_CRYPTO_GROUP_ID_KEY_MANAGEMENT)) {
429 status = tfm_crypto_key_management_interface(in_vec,
430 out_vec,
431 &encoded_key);
432 } else if (TFM_CRYPTO_IS_GROUP_ID(
433 iov->function_id, TFM_CRYPTO_GROUP_ID_HASH)) {
434 status = tfm_crypto_hash_interface(in_vec, out_vec);
435 } else if (TFM_CRYPTO_IS_GROUP_ID(
436 iov->function_id, TFM_CRYPTO_GROUP_ID_MAC)) {
437 status = tfm_crypto_mac_interface(in_vec,
438 out_vec,
439 &encoded_key);
440 } else if (TFM_CRYPTO_IS_GROUP_ID(
441 iov->function_id, TFM_CRYPTO_GROUP_ID_CIPHER)) {
442 status = tfm_crypto_cipher_interface(in_vec,
443 out_vec,
444 &encoded_key);
445 } else if (TFM_CRYPTO_IS_GROUP_ID(
446 iov->function_id, TFM_CRYPTO_GROUP_ID_AEAD)) {
447 status = tfm_crypto_aead_interface(in_vec,
448 out_vec,
449 &encoded_key);
450 } else if (TFM_CRYPTO_IS_GROUP_ID(
451 iov->function_id, TFM_CRYPTO_GROUP_ID_ASYM_SIGN) ||
452 TFM_CRYPTO_IS_GROUP_ID(
453 iov->function_id, TFM_CRYPTO_GROUP_ID_ASYM_ENCRYPT)) {
454 status = tfm_crypto_asymmetric_interface(in_vec,
455 out_vec,
456 &encoded_key);
457 } else if (TFM_CRYPTO_IS_GROUP_ID(
458 iov->function_id, TFM_CRYPTO_GROUP_ID_KEY_DERIVATION)) {
459 status = tfm_crypto_key_derivation_interface(in_vec,
460 out_vec,
461 &encoded_key);
462 } else if (iov->function_id == TFM_CRYPTO_GENERATE_RANDOM_SID) {
463 status = tfm_crypto_random_interface(in_vec, out_vec);
464 } else {
465 LOG_ERRFMT("[ERR][Crypto] Unsupported request!\r\n");
466 status = PSA_ERROR_NOT_SUPPORTED;
467 }
468
469 return status;
470}