blob: 1af64cc39a71332fa661a78fc356d296959ef67b [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"
Summer Qinca6c1522022-06-17 14:25:55 +080014#include "crypto_check_config.h"
Raef Coles79809c72022-03-02 13:48:20 +000015#include "tfm_plat_crypto_keys.h"
Jamie Fox0e54ebc2019-04-09 14:21:04 +010016
17/*
18 * \brief This Mbed TLS include is needed to initialise the memory allocator
Antonio de Angelis202425a2022-04-06 11:13:15 +010019 * of the library used for internal allocations
Jamie Fox0e54ebc2019-04-09 14:21:04 +010020 */
21#include "mbedtls/memory_buffer_alloc.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010022
Sherry Zhange1524982022-06-08 16:57:59 +080023#include "mbedtls/platform.h"
24
Raef Coles618fc152021-06-18 09:26:46 +010025#ifdef CRYPTO_NV_SEED
26#include "tfm_plat_crypto_nv_seed.h"
27#endif /* CRYPTO_NV_SEED */
Summer Qina5448d62020-12-07 14:03:37 +080028
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010029#ifndef TFM_PSA_API
30#include "tfm_secure_api.h"
31#endif
32
Raef Colesd2485af2019-10-30 10:15:33 +000033#ifdef CRYPTO_HW_ACCELERATOR
34#include "crypto_hw.h"
Michel Jaouenf41c6422021-10-07 14:38:08 +020035#endif /* CRYPTO_HW_ACCELERATOR */
Raef Colesd2485af2019-10-30 10:15:33 +000036
Antonio de Angelis202425a2022-04-06 11:13:15 +010037#ifndef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
38#error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER must be selected in Mbed TLS config file"
39#endif
40
Antonio de Angelis4743e672019-04-11 11:38:48 +010041#ifdef TFM_PSA_API
Ken Liub671d682022-05-12 20:39:29 +080042#include <string.h>
Kevin Pengfe730cc2022-04-11 17:48:42 +080043#include "psa/framework_feature.h"
Jamie Foxcc31d402019-01-28 17:13:52 +000044#include "psa/service.h"
Edison Aicc4c6162019-06-21 13:52:49 +080045#include "psa_manifest/tfm_crypto.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010046
47/**
Antonio de Angelis4743e672019-04-11 11:38:48 +010048 * \brief Aligns a value x up to an alignment a.
49 */
50#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
51
52/**
53 * \brief Maximum alignment required by any iovec parameters to the TF-M Crypto
54 * partition.
55 */
56#define TFM_CRYPTO_IOVEC_ALIGNMENT (4u)
57
Kevin Pengfe730cc2022-04-11 17:48:42 +080058#if PSA_FRAMEWORK_HAS_MM_IOVEC == 1
59static int32_t g_client_id;
60
61static void tfm_crypto_set_caller_id(int32_t id)
62{
63 g_client_id = id;
64}
65
66psa_status_t tfm_crypto_get_caller_id(int32_t *id)
67{
68 *id = g_client_id;
69 return PSA_SUCCESS;
70}
71
72static psa_status_t tfm_crypto_init_iovecs(const psa_msg_t *msg,
73 psa_invec in_vec[],
74 size_t in_len,
75 psa_outvec out_vec[],
76 size_t out_len)
77{
78 uint32_t i;
79
80 /* Map from the second element as the first is read when parsing */
81 for (i = 1; i < in_len; i++) {
82 in_vec[i].len = msg->in_size[i];
83 if (in_vec[i].len != 0) {
84 in_vec[i].base = psa_map_invec(msg->handle, i);
85 } else {
86 in_vec[i].base = NULL;
87 }
88 }
89
90 for (i = 0; i < out_len; i++) {
91 out_vec[i].len = msg->out_size[i];
92 if (out_vec[i].len != 0) {
93 out_vec[i].base = psa_map_outvec(msg->handle, i);
94 } else {
95 out_vec[i].base = NULL;
96 }
97 }
98
99 return PSA_SUCCESS;
100}
101#else /* PSA_FRAMEWORK_HAS_MM_IOVEC == 1 */
Antonio de Angelis4743e672019-04-11 11:38:48 +0100102/**
103 * \brief Default size of the internal scratch buffer used for IOVec allocations
104 * in bytes
105 */
106#ifndef TFM_CRYPTO_IOVEC_BUFFER_SIZE
Soby Mathew7740b602020-10-07 12:08:28 +0100107#error TFM_CRYPTO_IOVEC_BUFFER_SIZE is not defined
Antonio de Angelis4743e672019-04-11 11:38:48 +0100108#endif
109
110/**
111 * \brief Internal scratch used for IOVec allocations
112 *
113 */
114static struct tfm_crypto_scratch {
115 __attribute__((__aligned__(TFM_CRYPTO_IOVEC_ALIGNMENT)))
116 uint8_t buf[TFM_CRYPTO_IOVEC_BUFFER_SIZE];
117 uint32_t alloc_index;
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100118 int32_t owner;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100119} scratch = {.buf = {0}, .alloc_index = 0};
120
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100121static psa_status_t tfm_crypto_set_scratch_owner(int32_t id)
122{
123 scratch.owner = id;
124 return PSA_SUCCESS;
125}
126
127static psa_status_t tfm_crypto_get_scratch_owner(int32_t *id)
128{
129 *id = scratch.owner;
130 return PSA_SUCCESS;
131}
132
Antonio de Angelis4743e672019-04-11 11:38:48 +0100133static psa_status_t tfm_crypto_alloc_scratch(size_t requested_size, void **buf)
134{
135 /* Ensure alloc_index remains aligned to the required iovec alignment */
136 requested_size = ALIGN(requested_size, TFM_CRYPTO_IOVEC_ALIGNMENT);
137
138 if (requested_size > (sizeof(scratch.buf) - scratch.alloc_index)) {
139 return PSA_ERROR_INSUFFICIENT_MEMORY;
140 }
141
142 /* Compute the pointer to the allocated space */
143 *buf = (void *)&scratch.buf[scratch.alloc_index];
144
145 /* Increase the allocated size */
146 scratch.alloc_index += requested_size;
147
148 return PSA_SUCCESS;
149}
150
Kevin Pengfe730cc2022-04-11 17:48:42 +0800151static void tfm_crypto_clear_scratch(void)
Antonio de Angelis4743e672019-04-11 11:38:48 +0100152{
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100153 scratch.owner = 0;
Ken Liub671d682022-05-12 20:39:29 +0800154 (void)memset(scratch.buf, 0, scratch.alloc_index);
Summer Qin0a9e5372020-11-27 16:04:05 +0800155 scratch.alloc_index = 0;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100156}
157
Kevin Pengfe730cc2022-04-11 17:48:42 +0800158static void tfm_crypto_set_caller_id(int32_t id)
159{
160 /* Set the owner of the data in the scratch */
161 (void)tfm_crypto_set_scratch_owner(id);
162}
163
164psa_status_t tfm_crypto_get_caller_id(int32_t *id)
165{
166 return tfm_crypto_get_scratch_owner(id);
167}
168
169static psa_status_t tfm_crypto_init_iovecs(const psa_msg_t *msg,
170 psa_invec in_vec[],
171 size_t in_len,
172 psa_outvec out_vec[],
173 size_t out_len)
174{
175 uint32_t i;
176 void *alloc_buf_ptr = NULL;
177 psa_status_t status;
178
179 /* Alloc/read from the second element as the first is read when parsing */
180 for (i = 1; i < in_len; i++) {
181 /* Allocate necessary space in the internal scratch */
182 status = tfm_crypto_alloc_scratch(msg->in_size[i], &alloc_buf_ptr);
183 if (status != PSA_SUCCESS) {
184 tfm_crypto_clear_scratch();
185 return status;
186 }
187 /* Read from the IPC framework inputs into the scratch */
188 in_vec[i].len =
189 psa_read(msg->handle, i, alloc_buf_ptr, msg->in_size[i]);
190 /* Populate the fields of the input to the secure function */
191 in_vec[i].base = alloc_buf_ptr;
192 }
193
194 for (i = 0; i < out_len; i++) {
195 /* Allocate necessary space for the output in the internal scratch */
196 status = tfm_crypto_alloc_scratch(msg->out_size[i], &alloc_buf_ptr);
197 if (status != PSA_SUCCESS) {
198 tfm_crypto_clear_scratch();
199 return status;
200 }
201 /* Populate the fields of the output to the secure function */
202 out_vec[i].base = alloc_buf_ptr;
203 out_vec[i].len = msg->out_size[i];
204 }
205
206 return PSA_SUCCESS;
207}
208#endif /* PSA_FRAMEWORK_HAS_MM_IOVEC == 1 */
209
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800210static psa_status_t tfm_crypto_call_srv(const psa_msg_t *msg)
Antonio de Angelis4743e672019-04-11 11:38:48 +0100211{
212 psa_status_t status = PSA_SUCCESS;
TTornblomfaf74f52020-03-04 17:56:27 +0100213 size_t in_len = PSA_MAX_IOVEC, out_len = PSA_MAX_IOVEC, i;
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100214 psa_invec in_vec[PSA_MAX_IOVEC] = { {NULL, 0} };
215 psa_outvec out_vec[PSA_MAX_IOVEC] = { {NULL, 0} };
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800216 struct tfm_crypto_pack_iovec iov = {0};
Antonio de Angelis4743e672019-04-11 11:38:48 +0100217
218 /* Check the number of in_vec filled */
Jamie Fox9a234e22019-04-30 11:12:05 +0100219 while ((in_len > 0) && (msg->in_size[in_len - 1] == 0)) {
220 in_len--;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100221 }
222
Kevin Pengfe730cc2022-04-11 17:48:42 +0800223 /* Check the number of out_vec filled */
224 while ((out_len > 0) && (msg->out_size[out_len - 1] == 0)) {
225 out_len--;
226 }
227
Antonio de Angelis4743e672019-04-11 11:38:48 +0100228 /* There will always be a tfm_crypto_pack_iovec in the first iovec */
229 if (in_len < 1) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100230 return PSA_ERROR_GENERIC_ERROR;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100231 }
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800232
233 if (psa_read(msg->handle, 0, &iov, sizeof(iov)) != sizeof(iov)) {
234 return PSA_ERROR_GENERIC_ERROR;
235 }
236
Antonio de Angelis4743e672019-04-11 11:38:48 +0100237 /* Initialise the first iovec with the IOV read when parsing */
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800238 in_vec[0].base = &iov;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100239 in_vec[0].len = sizeof(struct tfm_crypto_pack_iovec);
240
Kevin Pengfe730cc2022-04-11 17:48:42 +0800241 status = tfm_crypto_init_iovecs(msg, in_vec, in_len, out_vec, out_len);
242 if (status != PSA_SUCCESS) {
243 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100244 }
245
Kevin Pengfe730cc2022-04-11 17:48:42 +0800246 tfm_crypto_set_caller_id(msg->client_id);
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100247
Antonio de Angelis202425a2022-04-06 11:13:15 +0100248 /* Call the dispatcher to the functions that implement the PSA Crypto API */
249 status = tfm_crypto_api_dispatcher(in_vec, in_len, out_vec, out_len);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100250
Kevin Pengfe730cc2022-04-11 17:48:42 +0800251#if PSA_FRAMEWORK_HAS_MM_IOVEC == 1
252 for (i = 0; i < out_len; i++) {
253 if (out_vec[i].base != NULL) {
254 psa_unmap_outvec(msg->handle, i, out_vec[i].len);
255 }
256 }
257#else
Antonio de Angelis4743e672019-04-11 11:38:48 +0100258 /* Write into the IPC framework outputs from the scratch */
259 for (i = 0; i < out_len; i++) {
260 psa_write(msg->handle, i, out_vec[i].base, out_vec[i].len);
261 }
262
263 /* Clear the allocated internal scratch before returning */
Summer Qin0a9e5372020-11-27 16:04:05 +0800264 tfm_crypto_clear_scratch();
Kevin Pengfe730cc2022-04-11 17:48:42 +0800265#endif
Antonio de Angelis4743e672019-04-11 11:38:48 +0100266
267 return status;
268}
Kevin Pengfe730cc2022-04-11 17:48:42 +0800269#else /* TFM_PSA_API */
270psa_status_t tfm_crypto_get_caller_id(int32_t *id)
271{
272 int32_t res;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100273
Kevin Pengfe730cc2022-04-11 17:48:42 +0800274 res = tfm_core_get_caller_client_id(id);
275 if (res != TFM_SUCCESS) {
276 return PSA_ERROR_NOT_PERMITTED;
277 } else {
278 return PSA_SUCCESS;
279 }
280}
Antonio de Angelis4743e672019-04-11 11:38:48 +0100281#endif /* TFM_PSA_API */
282
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100283/**
284 * \brief Default value for the size of the static buffer used by Mbed
285 * Crypto for its dynamic allocations
286 */
287#ifndef TFM_CRYPTO_ENGINE_BUF_SIZE
Soby Mathew7740b602020-10-07 12:08:28 +0100288#error TFM_CRYPTO_ENGINE_BUF_SIZE is not defined
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100289#endif
290
291/**
292 * \brief Static buffer to be used by Mbed Crypto for memory allocations
293 *
294 */
295static uint8_t mbedtls_mem_buf[TFM_CRYPTO_ENGINE_BUF_SIZE] = {0};
296
297static psa_status_t tfm_crypto_engine_init(void)
298{
Raef Coles618fc152021-06-18 09:26:46 +0100299#ifdef CRYPTO_NV_SEED
Antonio de Angelis202425a2022-04-06 11:13:15 +0100300 LOG_INFFMT("[INF][Crypto] ");
Raef Coles618fc152021-06-18 09:26:46 +0100301#ifdef TFM_PSA_API
Antonio de Angelis202425a2022-04-06 11:13:15 +0100302 LOG_INFFMT("Provisioning entropy seed... ");
Raef Coles618fc152021-06-18 09:26:46 +0100303 if (tfm_plat_crypto_provision_entropy_seed() != TFM_CRYPTO_NV_SEED_SUCCESS) {
Summer Qina5448d62020-12-07 14:03:37 +0800304 return PSA_ERROR_GENERIC_ERROR;
305 }
Antonio de Angelis202425a2022-04-06 11:13:15 +0100306 LOG_INFFMT("\033[0;32mcomplete.\033[0m\r\n");
Raef Coles618fc152021-06-18 09:26:46 +0100307#else
Raef Coles618fc152021-06-18 09:26:46 +0100308 LOG_INFFMT("TF-M in library mode uses a dummy NV seed. ");
309 LOG_INFFMT("This is not suitable for production! ");
Antonio de Angelis202425a2022-04-06 11:13:15 +0100310 LOG_INFFMT("This device is \033[1;31mNOT SECURE\033[0m\r\n");
Raef Coles618fc152021-06-18 09:26:46 +0100311#endif /* TFM_PSA_API */
312#endif /* CRYPTO_NV_SEED */
Summer Qina5448d62020-12-07 14:03:37 +0800313
Antonio de Angelis202425a2022-04-06 11:13:15 +0100314 /* Initialise the Mbed Crypto memory allocator to use static memory
315 * allocation from the provided buffer instead of using the heap
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100316 */
317 mbedtls_memory_buffer_alloc_init(mbedtls_mem_buf,
318 TFM_CRYPTO_ENGINE_BUF_SIZE);
319
Sherry Zhange1524982022-06-08 16:57:59 +0800320 /* mbedtls_printf is used to print messages including error information. */
321#if (TFM_PARTITION_LOG_LEVEL >= TFM_PARTITION_LOG_LEVEL_ERROR)
322 mbedtls_platform_set_printf(tfm_sp_log_printf);
323#endif
324
Raef Colesd2485af2019-10-30 10:15:33 +0000325 /* Initialise the crypto accelerator if one is enabled */
326#ifdef CRYPTO_HW_ACCELERATOR
Antonio de Angelis202425a2022-04-06 11:13:15 +0100327 LOG_INFFMT("[INF][Crypto] Initialising HW accelerator... ");
Raef Colesd2485af2019-10-30 10:15:33 +0000328 if (crypto_hw_accelerator_init() != 0) {
329 return PSA_ERROR_HARDWARE_FAILURE;
330 }
Antonio de Angelis202425a2022-04-06 11:13:15 +0100331 LOG_INFFMT("\033[0;32mcomplete.\033[0m\r\n");
Raef Colesd2485af2019-10-30 10:15:33 +0000332#endif /* CRYPTO_HW_ACCELERATOR */
333
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100334 /* Previous function does not return any value, so just call the
335 * initialisation function of the Mbed Crypto layer
336 */
337 return psa_crypto_init();
338}
339
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000340static psa_status_t tfm_crypto_module_init(void)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100341{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100342 /* Init the Alloc module */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000343 return tfm_crypto_init_alloc();
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100344}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100345
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000346psa_status_t tfm_crypto_init(void)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100347{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100348 psa_status_t status;
Raef Coles79809c72022-03-02 13:48:20 +0000349 enum tfm_plat_err_t plat_err;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100350
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100351 /* Initialise other modules of the service */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000352 status = tfm_crypto_module_init();
353 if (status != PSA_SUCCESS) {
354 return status;
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100355 }
356
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100357 /* Initialise the engine layer */
Raef Coles79809c72022-03-02 13:48:20 +0000358 status = tfm_crypto_engine_init();
359 if (status != PSA_SUCCESS) {
360 return status;
361 }
362
363 plat_err = tfm_plat_load_builtin_keys();
364 if (plat_err != TFM_PLAT_ERR_SUCCESS) {
365 return PSA_ERROR_GENERIC_ERROR;
366 }
367
368 return PSA_SUCCESS;
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800369}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100370
Antonio de Angelis4743e672019-04-11 11:38:48 +0100371#ifdef TFM_PSA_API
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800372psa_status_t tfm_crypto_sfn(const psa_msg_t *msg)
373{
374 /* Process the message type */
375 switch (msg->type) {
376 case PSA_IPC_CALL:
377 return tfm_crypto_call_srv(msg);
378 default:
379 return PSA_ERROR_NOT_SUPPORTED;
380 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100381
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800382 return PSA_ERROR_GENERIC_ERROR;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100383}
Kevin Peng2d4bc2e2022-01-28 16:19:30 +0800384#endif
Antonio de Angelis202425a2022-04-06 11:13:15 +0100385
386psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[],
387 size_t in_len,
388 psa_outvec out_vec[],
389 size_t out_len)
390{
391 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
392 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
393 int32_t caller_id = 0;
394 mbedtls_svc_key_id_t encoded_key = MBEDTLS_SVC_KEY_ID_INIT;
395 bool is_key_required = false;
David Huc9679cc2022-06-21 13:09:34 +0800396 enum tfm_crypto_group_id group_id;
Antonio de Angelis202425a2022-04-06 11:13:15 +0100397
398 if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) {
399 return PSA_ERROR_PROGRAMMER_ERROR;
400 }
401
David Huc9679cc2022-06-21 13:09:34 +0800402 group_id = TFM_CRYPTO_GET_GROUP_ID(iov->function_id);
403
404 is_key_required = !((group_id == TFM_CRYPTO_GROUP_ID_HASH) ||
405 (group_id == TFM_CRYPTO_GROUP_ID_RANDOM));
Antonio de Angelis202425a2022-04-06 11:13:15 +0100406
407 if (is_key_required) {
408 status = tfm_crypto_get_caller_id(&caller_id);
409 if (status != PSA_SUCCESS) {
410 return status;
411 }
412 /* The caller_id being set in the owner field is the partition ID
413 * of the calling partition
414 */
415 encoded_key = mbedtls_svc_key_id_make(caller_id, iov->key_id);
416 }
417
418 /* Dispatch to each sub-module based on the Group ID */
David Huc9679cc2022-06-21 13:09:34 +0800419 switch (group_id) {
420 case TFM_CRYPTO_GROUP_ID_KEY_MANAGEMENT:
421 return tfm_crypto_key_management_interface(in_vec, out_vec,
422 &encoded_key);
423 case TFM_CRYPTO_GROUP_ID_HASH:
424 return tfm_crypto_hash_interface(in_vec, out_vec);
425 case TFM_CRYPTO_GROUP_ID_MAC:
426 return tfm_crypto_mac_interface(in_vec, out_vec, &encoded_key);
427 case TFM_CRYPTO_GROUP_ID_CIPHER:
428 return tfm_crypto_cipher_interface(in_vec, out_vec, &encoded_key);
429 case TFM_CRYPTO_GROUP_ID_AEAD:
430 return tfm_crypto_aead_interface(in_vec, out_vec, &encoded_key);
431 case TFM_CRYPTO_GROUP_ID_ASYM_SIGN:
432 return tfm_crypto_asymmetric_sign_interface(in_vec, out_vec,
433 &encoded_key);
434 case TFM_CRYPTO_GROUP_ID_ASYM_ENCRYPT:
435 return tfm_crypto_asymmetric_encrypt_interface(in_vec, out_vec,
436 &encoded_key);
437 case TFM_CRYPTO_GROUP_ID_KEY_DERIVATION:
438 return tfm_crypto_key_derivation_interface(in_vec, out_vec,
439 &encoded_key);
440 case TFM_CRYPTO_GROUP_ID_RANDOM:
441 return tfm_crypto_random_interface(in_vec, out_vec);
442 default:
Antonio de Angelis202425a2022-04-06 11:13:15 +0100443 LOG_ERRFMT("[ERR][Crypto] Unsupported request!\r\n");
David Huc9679cc2022-06-21 13:09:34 +0800444 return PSA_ERROR_NOT_SUPPORTED;
Antonio de Angelis202425a2022-04-06 11:13:15 +0100445 }
446
David Huc9679cc2022-06-21 13:09:34 +0800447 return PSA_ERROR_NOT_SUPPORTED;
Antonio de Angelis202425a2022-04-06 11:13:15 +0100448}