blob: 19f11c477dddff6a213575ef71a72545cdc99240 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis377a1552018-11-22 17:02:40 +00002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Jamie Foxefd82732018-11-26 10:34:32 +00008#include <stddef.h>
Jamie Fox0e54ebc2019-04-09 14:21:04 +01009#include <stdint.h>
Antonio de Angelis8908f472018-08-31 15:44:25 +010010
Summer Qin4b1d03b2019-07-02 14:56:08 +080011/* FixMe: Use PSA_ERROR_CONNECTION_REFUSED when performing parameter
Antonio de Angelis4743e672019-04-11 11:38:48 +010012 * integrity checks but this will have to be revised
13 * when the full set of error codes mandated by PSA FF
14 * is available.
15 */
Jamie Fox0e54ebc2019-04-09 14:21:04 +010016#include "tfm_mbedcrypto_include.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010017
Jamie Fox0e54ebc2019-04-09 14:21:04 +010018#include "tfm_crypto_api.h"
19#include "tfm_crypto_defs.h"
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010020#include <stdbool.h>
Jamie Fox82b87ca2018-12-11 16:41:11 +000021
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010022#ifndef TFM_CRYPTO_MAX_KEY_HANDLES
23#define TFM_CRYPTO_MAX_KEY_HANDLES (16)
24#endif
25struct tfm_crypto_handle_owner_s {
26 int32_t owner; /*!< Owner of the allocated handle */
27 psa_key_handle_t handle; /*!< Allocated handle */
28 uint8_t in_use; /*!< Flag to indicate if this in use */
29};
30
Antonio de Angelis7740b382019-07-16 10:59:25 +010031#if (TFM_CRYPTO_KEY_MODULE_DISABLED == 0)
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010032static struct tfm_crypto_handle_owner_s
33 handle_owner[TFM_CRYPTO_MAX_KEY_HANDLES] = {0};
Antonio de Angelis7740b382019-07-16 10:59:25 +010034#endif
Antonio de Angelis8908f472018-08-31 15:44:25 +010035/*!
36 * \defgroup public Public functions
37 *
38 */
39
40/*!@{*/
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010041psa_status_t tfm_crypto_check_handle_owner(psa_key_handle_t handle,
42 uint32_t *index)
43{
Antonio de Angelis7740b382019-07-16 10:59:25 +010044#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
45 return PSA_ERROR_NOT_SUPPORTED;
46#else
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010047 int32_t partition_id = 0;
48 uint32_t i = 0;
49 psa_status_t status;
50
51 status = tfm_crypto_get_caller_id(&partition_id);
52 if (status != PSA_SUCCESS) {
53 return status;
54 }
55
56 for (i = 0; i < TFM_CRYPTO_MAX_KEY_HANDLES; i++) {
57 if (handle_owner[i].in_use && handle_owner[i].handle == handle) {
58 if (handle_owner[i].owner == partition_id) {
59 if (index != NULL) {
60 *index = i;
61 }
62 return PSA_SUCCESS;
63 } else {
64 return PSA_ERROR_NOT_PERMITTED;
65 }
66 }
67 }
68
69 return PSA_ERROR_INVALID_HANDLE;
Antonio de Angelis7740b382019-07-16 10:59:25 +010070#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010071}
72
Jamie Fox0e54ebc2019-04-09 14:21:04 +010073psa_status_t tfm_crypto_allocate_key(psa_invec in_vec[],
74 size_t in_len,
75 psa_outvec out_vec[],
76 size_t out_len)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010077{
Antonio de Angelis7740b382019-07-16 10:59:25 +010078#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
79 return PSA_ERROR_NOT_SUPPORTED;
80#else
Jamie Fox0e54ebc2019-04-09 14:21:04 +010081 if ((in_len != 1) || (out_len != 1)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +080082 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +000083 }
84
Jamie Fox0e54ebc2019-04-09 14:21:04 +010085 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
86 (out_vec[0].len != sizeof(psa_key_handle_t))) {
Summer Qin4b1d03b2019-07-02 14:56:08 +080087 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +000088 }
89
Jamie Fox0e54ebc2019-04-09 14:21:04 +010090 psa_key_handle_t *key_handle = out_vec[0].base;
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010091 uint32_t i = 0;
92 int32_t partition_id = 0;
93 bool empty_found = false;
94 psa_status_t status;
Jamie Foxefd82732018-11-26 10:34:32 +000095
Antonio de Angelis60a6fe62019-06-18 15:27:34 +010096 for (i = 0; i < TFM_CRYPTO_MAX_KEY_HANDLES; i++) {
97 if (handle_owner[i].in_use == TFM_CRYPTO_NOT_IN_USE) {
98 empty_found = true;
99 break;
100 }
101 }
102
103 if (!empty_found) {
104 return PSA_ERROR_INSUFFICIENT_MEMORY;
105 }
106
107 status = tfm_crypto_get_caller_id(&partition_id);
108 if (status != PSA_SUCCESS) {
109 return status;
110 }
111
112 status = psa_allocate_key(key_handle);
113
114 if (status == PSA_SUCCESS) {
115 handle_owner[i].owner = partition_id;
116 handle_owner[i].handle = *key_handle;
117 handle_owner[i].in_use = TFM_CRYPTO_IN_USE;
118 }
119
120 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100121#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Jamie Foxefd82732018-11-26 10:34:32 +0000122}
123
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000124psa_status_t tfm_crypto_import_key(psa_invec in_vec[],
125 size_t in_len,
126 psa_outvec out_vec[],
127 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100128{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100129#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
130 return PSA_ERROR_NOT_SUPPORTED;
131#else
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100132 (void)out_vec;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100133
Antonio de Angelis4743e672019-04-11 11:38:48 +0100134 if ((in_len != 2) || (out_len != 0)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800135 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +0000136 }
137
Antonio de Angelis4743e672019-04-11 11:38:48 +0100138 if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800139 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000140 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100141 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000142
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100143 psa_key_handle_t key = iov->key_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100144 psa_key_type_t type = iov->type;
145 const uint8_t *data = in_vec[1].base;
146 size_t data_length = in_vec[1].len;
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100147 psa_status_t status = tfm_crypto_check_handle_owner(key, NULL);
148
149 if (status != PSA_SUCCESS) {
150 return status;
151 }
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000152
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100153 return psa_import_key(key, type, data, data_length);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100154#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100155}
156
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000157psa_status_t tfm_crypto_destroy_key(psa_invec in_vec[],
158 size_t in_len,
159 psa_outvec out_vec[],
160 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100161{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100162#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
163 return PSA_ERROR_NOT_SUPPORTED;
164#else
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100165 (void)out_vec;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100166
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000167 if ((in_len != 1) || (out_len != 0)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800168 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000169 }
170
Antonio de Angelis4743e672019-04-11 11:38:48 +0100171 if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800172 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000173 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100174 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000175
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100176 psa_key_handle_t key = iov->key_handle;
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100177 uint32_t index;
178 psa_status_t status = tfm_crypto_check_handle_owner(key, &index);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000179
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100180 if (status != PSA_SUCCESS) {
181 return status;
182 }
183
184 status = psa_destroy_key(key);
185
186 if (status == PSA_SUCCESS) {
187 handle_owner[index].owner = 0;
188 handle_owner[index].handle = 0;
189 handle_owner[index].in_use = TFM_CRYPTO_NOT_IN_USE;
190 }
191
192 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100193#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100194}
195
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000196psa_status_t tfm_crypto_get_key_information(psa_invec in_vec[],
197 size_t in_len,
198 psa_outvec out_vec[],
199 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100200{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100201#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
202 return PSA_ERROR_NOT_SUPPORTED;
203#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000204 if ((in_len != 1) || (out_len != 2)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800205 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +0000206 }
207
Antonio de Angelis4743e672019-04-11 11:38:48 +0100208 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000209 (out_vec[0].len != sizeof(psa_key_type_t)) ||
210 (out_vec[1].len != sizeof(size_t))) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800211 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +0000212 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100213 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Foxefd82732018-11-26 10:34:32 +0000214
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100215 psa_key_handle_t key = iov->key_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000216 psa_key_type_t *type = out_vec[0].base;
217 size_t *bits = out_vec[1].base;
218
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100219 return psa_get_key_information(key, type, bits);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100220#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100221}
222
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000223psa_status_t tfm_crypto_export_key(psa_invec in_vec[],
224 size_t in_len,
225 psa_outvec out_vec[],
226 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100227{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100228#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
229 return PSA_ERROR_NOT_SUPPORTED;
230#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000231 if ((in_len != 1) || (out_len != 1)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800232 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100233 }
234
Antonio de Angelis4743e672019-04-11 11:38:48 +0100235 if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800236 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100237 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100238 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100239
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100240 psa_key_handle_t key = iov->key_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000241 uint8_t *data = out_vec[0].base;
242 size_t data_size = out_vec[0].len;
243
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100244 return psa_export_key(key, data, data_size, &(out_vec[0].len));
Antonio de Angelis7740b382019-07-16 10:59:25 +0100245#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100246}
247
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000248psa_status_t tfm_crypto_export_public_key(psa_invec in_vec[],
249 size_t in_len,
250 psa_outvec out_vec[],
251 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100252{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100253#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
254 return PSA_ERROR_NOT_SUPPORTED;
255#else
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100256 if ((in_len != 1) || (out_len != 1)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800257 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100258 }
Hugues de Valon8b442442019-02-19 14:30:52 +0000259
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100260 if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800261 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100262 }
263 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
264
265 psa_key_handle_t key = iov->key_handle;
266 uint8_t *data = out_vec[0].base;
267 size_t data_size = out_vec[0].len;
268
269 return psa_export_public_key(key, data, data_size, &(out_vec[0].len));
Antonio de Angelis7740b382019-07-16 10:59:25 +0100270#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100271}
272
273psa_status_t tfm_crypto_copy_key(psa_invec in_vec[],
274 size_t in_len,
275 psa_outvec out_vec[],
276 size_t out_len)
277{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100278#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
279 return PSA_ERROR_NOT_SUPPORTED;
280#else
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100281 (void)out_vec;
282
283 if ((in_len != 3) || (out_len != 0)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800284 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100285 }
286
287 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
288 (in_vec[1].len != sizeof(psa_key_handle_t)) ||
289 (in_vec[2].len != sizeof(psa_key_policy_t))) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800290 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100291 }
292 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
293
294 psa_key_handle_t source_handle = iov->key_handle;
295 psa_key_handle_t target_handle = *((psa_key_handle_t *)in_vec[1].base);
296 const psa_key_policy_t *policy = in_vec[2].base;
297
298 return psa_copy_key(source_handle, target_handle, policy);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100299#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100300}
Jamie Foxefd82732018-11-26 10:34:32 +0000301
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000302psa_status_t tfm_crypto_set_key_policy(psa_invec in_vec[],
303 size_t in_len,
304 psa_outvec out_vec[],
305 size_t out_len)
Jamie Foxefd82732018-11-26 10:34:32 +0000306{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100307#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
308 return PSA_ERROR_NOT_SUPPORTED;
309#else
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100310 (void)out_vec;
Jamie Foxefd82732018-11-26 10:34:32 +0000311
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000312 if ((in_len != 2) || (out_len != 0)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800313 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +0000314 }
315
Antonio de Angelis4743e672019-04-11 11:38:48 +0100316 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000317 (in_vec[1].len != sizeof(psa_key_policy_t))) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800318 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000319 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100320 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000321
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100322 psa_key_handle_t key = iov->key_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000323 const psa_key_policy_t *policy = in_vec[1].base;
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100324 psa_status_t status = tfm_crypto_check_handle_owner(key, NULL);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000325
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100326 if (status == PSA_SUCCESS) {
327 return psa_set_key_policy(key, policy);
328 } else {
329 return status;
330 }
Antonio de Angelis7740b382019-07-16 10:59:25 +0100331#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Jamie Foxefd82732018-11-26 10:34:32 +0000332}
333
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000334psa_status_t tfm_crypto_get_key_policy(psa_invec in_vec[],
335 size_t in_len,
336 psa_outvec out_vec[],
337 size_t out_len)
Jamie Foxefd82732018-11-26 10:34:32 +0000338{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100339#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
340 return PSA_ERROR_NOT_SUPPORTED;
341#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000342 if ((in_len != 1) || (out_len != 1)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800343 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +0000344 }
345
Antonio de Angelis4743e672019-04-11 11:38:48 +0100346 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000347 (out_vec[0].len != sizeof(psa_key_policy_t))) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800348 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000349 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100350 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000351
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100352 psa_key_handle_t key = iov->key_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000353 psa_key_policy_t *policy = out_vec[0].base;
354
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100355 return psa_get_key_policy(key, policy);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100356#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Jamie Foxefd82732018-11-26 10:34:32 +0000357}
358
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000359psa_status_t tfm_crypto_get_key_lifetime(psa_invec in_vec[],
360 size_t in_len,
361 psa_outvec out_vec[],
362 size_t out_len)
Jamie Foxefd82732018-11-26 10:34:32 +0000363{
Antonio de Angelis7740b382019-07-16 10:59:25 +0100364#if (TFM_CRYPTO_KEY_MODULE_DISABLED != 0)
365 return PSA_ERROR_NOT_SUPPORTED;
366#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000367 if ((in_len != 1) || (out_len != 1)) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800368 return PSA_ERROR_CONNECTION_REFUSED;
Jamie Foxefd82732018-11-26 10:34:32 +0000369 }
370
Antonio de Angelis4743e672019-04-11 11:38:48 +0100371 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000372 (out_vec[0].len != sizeof(psa_key_lifetime_t))) {
Summer Qin4b1d03b2019-07-02 14:56:08 +0800373 return PSA_ERROR_CONNECTION_REFUSED;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000374 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100375 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000376
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100377 psa_key_handle_t key = iov->key_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000378 psa_key_lifetime_t *lifetime = out_vec[0].base;
379
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100380 return psa_get_key_lifetime(key, lifetime);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100381#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
Jamie Foxefd82732018-11-26 10:34:32 +0000382}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100383/*!@}*/