blob: 166e051e9a1e4431eab3a35ee7c48419ac99a8af [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis04debbd2019-10-14 12:12:52 +01002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Antonio de Angelisab85ccd2019-03-25 15:14:29 +00008#include "tfm_crypto_defs.h"
Jamie Foxcc31d402019-01-28 17:13:52 +00009#include "psa/crypto.h"
Antonio de Angelis05b24192019-07-04 15:28:46 +010010#include "tfm_ns_interface.h"
Edison Aicc4c6162019-06-21 13:52:49 +080011#include "psa_manifest/sid.h"
Kevin Peng9449a362019-07-29 16:05:42 +080012#include "psa/client.h"
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000013
Antonio de Angelis4743e672019-04-11 11:38:48 +010014#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000015
Jamie Fox0e54ebc2019-04-09 14:21:04 +010016#define PSA_CONNECT(service) \
17 psa_handle_t ipc_handle; \
Edison Aicc4c6162019-06-21 13:52:49 +080018 ipc_handle = psa_connect(service##_SID, service##_VERSION); \
Summer Qinb207a152019-07-03 16:36:49 +080019 if (!PSA_HANDLE_IS_VALID(ipc_handle)) { \
Jamie Fox0e54ebc2019-04-09 14:21:04 +010020 return PSA_ERROR_GENERIC_ERROR; \
21 } \
Antonio de Angelis4743e672019-04-11 11:38:48 +010022
Jamie Fox0e54ebc2019-04-09 14:21:04 +010023#define PSA_CLOSE() psa_close(ipc_handle)
Antonio de Angelis4743e672019-04-11 11:38:48 +010024
Jamie Fox0e54ebc2019-04-09 14:21:04 +010025#define API_DISPATCH(sfn_name, sfn_id) \
Summer Qin4b1d03b2019-07-02 14:56:08 +080026 psa_call(ipc_handle, PSA_IPC_CALL, \
Jamie Fox0e54ebc2019-04-09 14:21:04 +010027 in_vec, ARRAY_SIZE(in_vec), \
Antonio de Angelis4743e672019-04-11 11:38:48 +010028 out_vec, ARRAY_SIZE(out_vec))
29
Jamie Fox0e54ebc2019-04-09 14:21:04 +010030#define API_DISPATCH_NO_OUTVEC(sfn_name, sfn_id) \
Summer Qin4b1d03b2019-07-02 14:56:08 +080031 psa_call(ipc_handle, PSA_IPC_CALL, \
Jamie Fox0e54ebc2019-04-09 14:21:04 +010032 in_vec, ARRAY_SIZE(in_vec), \
Antonio de Angelis4743e672019-04-11 11:38:48 +010033 (psa_outvec *)NULL, 0)
Antonio de Angelis8908f472018-08-31 15:44:25 +010034
35psa_status_t psa_crypto_init(void)
36{
37 /* Service init is performed during TFM boot up,
38 * so application level initialisation is empty
39 */
40 return PSA_SUCCESS;
41}
42
Antonio de Angelis04debbd2019-10-14 12:12:52 +010043psa_status_t psa_open_key(psa_key_id_t id,
Jamie Fox0e54ebc2019-04-09 14:21:04 +010044 psa_key_handle_t *handle)
45{
Jamie Foxdadb4e82019-09-03 17:59:41 +010046 psa_status_t status;
47 const struct tfm_crypto_pack_iovec iov = {
48 .sfn_id = TFM_CRYPTO_OPEN_KEY_SID,
Jamie Foxdadb4e82019-09-03 17:59:41 +010049 };
50 psa_invec in_vec[] = {
51 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
52 {.base = &id, .len = sizeof(psa_key_id_t)},
53 };
54 psa_outvec out_vec[] = {
55 {.base = handle, .len = sizeof(psa_key_handle_t)},
56 };
Jamie Fox0e54ebc2019-04-09 14:21:04 +010057
Jamie Foxdadb4e82019-09-03 17:59:41 +010058 PSA_CONNECT(TFM_CRYPTO);
59
60 status = API_DISPATCH(tfm_crypto_open_key,
61 TFM_CRYPTO_OPEN_KEY);
62
63 PSA_CLOSE();
64
65 return status;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010066}
67
Jamie Fox0e54ebc2019-04-09 14:21:04 +010068psa_status_t psa_close_key(psa_key_handle_t handle)
69{
Jamie Foxdadb4e82019-09-03 17:59:41 +010070 psa_status_t status;
71 const struct tfm_crypto_pack_iovec iov = {
72 .sfn_id = TFM_CRYPTO_CLOSE_KEY_SID,
73 .key_handle = handle,
74 };
75 psa_invec in_vec[] = {
76 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
77 };
Jamie Fox0e54ebc2019-04-09 14:21:04 +010078
Jamie Foxdadb4e82019-09-03 17:59:41 +010079 PSA_CONNECT(TFM_CRYPTO);
80
81 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_close_key,
82 TFM_CRYPTO_CLOSE_KEY);;
83
84 PSA_CLOSE();
85
86 return status;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010087}
88
Antonio de Angelis04debbd2019-10-14 12:12:52 +010089psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
Antonio de Angelis8908f472018-08-31 15:44:25 +010090 const uint8_t *data,
Antonio de Angelis04debbd2019-10-14 12:12:52 +010091 size_t data_length,
92 psa_key_handle_t *handle)
Antonio de Angelis8908f472018-08-31 15:44:25 +010093{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000094 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +010095 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +080096 .sfn_id = TFM_CRYPTO_IMPORT_KEY_SID,
Antonio de Angelis4743e672019-04-11 11:38:48 +010097 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000098 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +010099 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100100 {.base = attributes, .len = sizeof(psa_key_attributes_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000101 {.base = data, .len = data_length}
102 };
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100103 psa_outvec out_vec[] = {
104 {.base = handle, .len = sizeof(psa_key_handle_t)}
105 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100106
Antonio de Angelis4743e672019-04-11 11:38:48 +0100107 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100108
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100109 status = API_DISPATCH(tfm_crypto_import_key,
110 TFM_CRYPTO_IMPORT_KEY);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100111 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100112
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000113 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100114}
115
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100116psa_status_t psa_destroy_key(psa_key_handle_t handle)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100117{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000118 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100119 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800120 .sfn_id = TFM_CRYPTO_DESTROY_KEY_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100121 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100122 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000123 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100124 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000125 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100126
Antonio de Angelis4743e672019-04-11 11:38:48 +0100127 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100128
129 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_destroy_key,
130 TFM_CRYPTO_DESTROY_KEY);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100131 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100132
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000133 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100134}
135
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100136psa_status_t psa_get_key_attributes(psa_key_handle_t handle,
137 psa_key_attributes_t *attributes)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100138{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000139 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100140 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100141 .sfn_id = TFM_CRYPTO_GET_KEY_ATTRIBUTES_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100142 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100143 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000144 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100145 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000146 };
147 psa_outvec out_vec[] = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100148 {.base = attributes, .len = sizeof(psa_key_attributes_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000149 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100150
Antonio de Angelis4743e672019-04-11 11:38:48 +0100151 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100152
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100153 status = API_DISPATCH(tfm_crypto_get_key_attributes,
154 TFM_CRYPTO_GET_KEY_ATTRIBUTES);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100155 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100156
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000157 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100158}
159
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100160void psa_reset_key_attributes(psa_key_attributes_t *attributes)
161{
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100162 struct tfm_crypto_pack_iovec iov = {
163 .sfn_id = TFM_CRYPTO_RESET_KEY_ATTRIBUTES_SID,
164 };
165 psa_invec in_vec[] = {
166 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
167 };
168 psa_outvec out_vec[] = {
169 {.base = attributes, .len = sizeof(psa_key_attributes_t)},
170 };
171
172 psa_handle_t ipc_handle;
173 ipc_handle = psa_connect(TFM_CRYPTO_SID, TFM_CRYPTO_VERSION);
174 if (!PSA_HANDLE_IS_VALID(ipc_handle)) {
175 return;
176 }
177
178 (void)API_DISPATCH(tfm_crypto_reset_key_attributes,
179 TFM_CRYPTO_RESET_KEY_ATTRIBUTES);
180 PSA_CLOSE();
181
182 return;
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100183}
184
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100185psa_status_t psa_export_key(psa_key_handle_t handle,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100186 uint8_t *data,
187 size_t data_size,
188 size_t *data_length)
189{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000190 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100191 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800192 .sfn_id = TFM_CRYPTO_EXPORT_KEY_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100193 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100194 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000195 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100196 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000197 };
198 psa_outvec out_vec[] = {
199 {.base = data, .len = data_size}
200 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100201
Antonio de Angelis4743e672019-04-11 11:38:48 +0100202 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100203
204 status = API_DISPATCH(tfm_crypto_export_key,
205 TFM_CRYPTO_EXPORT_KEY);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100206
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000207 *data_length = out_vec[0].len;
208
Antonio de Angelis4743e672019-04-11 11:38:48 +0100209 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +0100210
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000211 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100212}
213
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100214psa_status_t psa_export_public_key(psa_key_handle_t handle,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100215 uint8_t *data,
216 size_t data_size,
217 size_t *data_length)
218{
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100219 psa_status_t status;
220 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800221 .sfn_id = TFM_CRYPTO_EXPORT_PUBLIC_KEY_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100222 .key_handle = handle,
223 };
Hugues de Valon8b442442019-02-19 14:30:52 +0000224
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100225 psa_invec in_vec[] = {
226 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
227 };
228 psa_outvec out_vec[] = {
229 {.base = data, .len = data_size}
230 };
231
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100232 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100233
234 status = API_DISPATCH(tfm_crypto_export_public_key,
235 TFM_CRYPTO_EXPORT_PUBLIC_KEY);
236
237 *data_length = out_vec[0].len;
238
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100239 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100240
241 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100242}
243
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100244psa_status_t psa_copy_key(psa_key_handle_t source_handle,
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100245 const psa_key_attributes_t *attributes,
246 psa_key_handle_t *target_handle)
Jamie Foxefd82732018-11-26 10:34:32 +0000247{
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100248 psa_status_t status;
249 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800250 .sfn_id = TFM_CRYPTO_COPY_KEY_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100251 .key_handle = source_handle,
252 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000253
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100254 psa_invec in_vec[] = {
255 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100256 {.base = attributes, .len = sizeof(psa_key_attributes_t)},
257
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100258 };
259
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000260 psa_outvec out_vec[] = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100261 {.base = target_handle, .len = sizeof(psa_key_handle_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000262 };
Jamie Foxefd82732018-11-26 10:34:32 +0000263
Antonio de Angelis4743e672019-04-11 11:38:48 +0100264 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100265
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100266 status = API_DISPATCH(tfm_crypto_copy_key,
267 TFM_CRYPTO_COPY_KEY);
Kevin Peng9449a362019-07-29 16:05:42 +0800268
Antonio de Angelis4743e672019-04-11 11:38:48 +0100269 PSA_CLOSE();
Jamie Foxefd82732018-11-26 10:34:32 +0000270
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000271 return status;
Jamie Foxefd82732018-11-26 10:34:32 +0000272}
273
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100274psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
275 unsigned char *iv,
276 size_t iv_size,
277 size_t *iv_length)
278{
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100279 psa_status_t status;
280 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800281 .sfn_id = TFM_CRYPTO_CIPHER_GENERATE_IV_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100282 .op_handle = operation->handle,
283 };
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100284
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100285 psa_invec in_vec[] = {
286 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
287 };
288 psa_outvec out_vec[] = {
289 {.base = &(operation->handle), .len = sizeof(uint32_t)},
290 {.base = iv, .len = iv_size},
291 };
292
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100293 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100294
295 status = API_DISPATCH(tfm_crypto_cipher_generate_iv,
296 TFM_CRYPTO_CIPHER_GENERATE_IV);
297
298 *iv_length = out_vec[1].len;
299
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100300 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100301
302 return status;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100303}
304
Antonio de Angelis377a1552018-11-22 17:02:40 +0000305psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
306 const unsigned char *iv,
307 size_t iv_length)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100308{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000309 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100310 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800311 .sfn_id = TFM_CRYPTO_CIPHER_SET_IV_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100312 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100313 };
314
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000315 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100316 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000317 {.base = iv, .len = iv_length},
318 };
319 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100320 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000321 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100322
Antonio de Angelis4743e672019-04-11 11:38:48 +0100323 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100324
325 status = API_DISPATCH(tfm_crypto_cipher_set_iv,
326 TFM_CRYPTO_CIPHER_SET_IV);
Kevin Peng9449a362019-07-29 16:05:42 +0800327
Antonio de Angelis4743e672019-04-11 11:38:48 +0100328 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100329
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000330 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100331}
332
Antonio de Angelis377a1552018-11-22 17:02:40 +0000333psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100334 psa_key_handle_t handle,
Antonio de Angelis377a1552018-11-22 17:02:40 +0000335 psa_algorithm_t alg)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100336{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000337 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100338 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800339 .sfn_id = TFM_CRYPTO_CIPHER_ENCRYPT_SETUP_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100340 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100341 .alg = alg,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100342 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000343 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100344
Antonio de Angelis4743e672019-04-11 11:38:48 +0100345 psa_invec in_vec[] = {
346 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
347 };
348 psa_outvec out_vec[] = {
349 {.base = &(operation->handle), .len = sizeof(uint32_t)},
350 };
351
Antonio de Angelis4743e672019-04-11 11:38:48 +0100352 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100353
354 status = API_DISPATCH(tfm_crypto_cipher_encrypt_setup,
355 TFM_CRYPTO_CIPHER_ENCRYPT_SETUP);
Kevin Peng9449a362019-07-29 16:05:42 +0800356
Antonio de Angelis4743e672019-04-11 11:38:48 +0100357 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100358
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000359 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100360}
361
Antonio de Angelis377a1552018-11-22 17:02:40 +0000362psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100363 psa_key_handle_t handle,
Antonio de Angelis377a1552018-11-22 17:02:40 +0000364 psa_algorithm_t alg)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100365{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000366 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100367 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800368 .sfn_id = TFM_CRYPTO_CIPHER_DECRYPT_SETUP_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100369 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100370 .alg = alg,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100371 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000372 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100373
Antonio de Angelis4743e672019-04-11 11:38:48 +0100374 psa_invec in_vec[] = {
375 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
376 };
377 psa_outvec out_vec[] = {
378 {.base = &(operation->handle), .len = sizeof(uint32_t)},
379 };
380
Antonio de Angelis4743e672019-04-11 11:38:48 +0100381 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100382
383 status = API_DISPATCH(tfm_crypto_cipher_decrypt_setup,
384 TFM_CRYPTO_CIPHER_DECRYPT_SETUP);
Kevin Peng9449a362019-07-29 16:05:42 +0800385
Antonio de Angelis4743e672019-04-11 11:38:48 +0100386 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100387
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000388 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100389}
390
391psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
392 const uint8_t *input,
393 size_t input_length,
394 unsigned char *output,
395 size_t output_size,
396 size_t *output_length)
397{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000398 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100399 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800400 .sfn_id = TFM_CRYPTO_CIPHER_UPDATE_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100401 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100402 };
403
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000404 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100405 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000406 {.base = input, .len = input_length},
407 };
408 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100409 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000410 {.base = output, .len = output_size}
411 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100412
Antonio de Angelis4743e672019-04-11 11:38:48 +0100413 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100414
415 status = API_DISPATCH(tfm_crypto_cipher_update,
416 TFM_CRYPTO_CIPHER_UPDATE);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100417
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000418 *output_length = out_vec[1].len;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100419
Antonio de Angelis4743e672019-04-11 11:38:48 +0100420 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +0100421
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000422 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100423}
424
425psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
426{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000427 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100428 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800429 .sfn_id = TFM_CRYPTO_CIPHER_ABORT_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100430 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000431 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100432
Antonio de Angelis4743e672019-04-11 11:38:48 +0100433 psa_invec in_vec[] = {
434 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
435 };
436 psa_outvec out_vec[] = {
437 {.base = &(operation->handle), .len = sizeof(uint32_t)},
438 };
439
Antonio de Angelis4743e672019-04-11 11:38:48 +0100440 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100441
442 status = API_DISPATCH(tfm_crypto_cipher_abort,
443 TFM_CRYPTO_CIPHER_ABORT);
Kevin Peng9449a362019-07-29 16:05:42 +0800444
Antonio de Angelis4743e672019-04-11 11:38:48 +0100445 PSA_CLOSE();
Antonio de Angelis8908f472018-08-31 15:44:25 +0100446
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000447 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100448}
449
450psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
451 uint8_t *output,
452 size_t output_size,
453 size_t *output_length)
454{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000455 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100456 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800457 .sfn_id = TFM_CRYPTO_CIPHER_FINISH_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100458 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100459 };
460
461 psa_invec in_vec[] = {
462 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
463 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000464 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100465 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000466 {.base = output, .len = output_size},
467 };
Antonio de Angelis8908f472018-08-31 15:44:25 +0100468
Antonio de Angelis4743e672019-04-11 11:38:48 +0100469 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100470
471 status = API_DISPATCH(tfm_crypto_cipher_finish,
472 TFM_CRYPTO_CIPHER_FINISH);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100473
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000474 *output_length = out_vec[1].len;
475
Antonio de Angelis4743e672019-04-11 11:38:48 +0100476 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +0100477
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000478 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100479}
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100480
Antonio de Angelis377a1552018-11-22 17:02:40 +0000481psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100482 psa_algorithm_t alg)
483{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000484 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100485 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800486 .sfn_id = TFM_CRYPTO_HASH_SETUP_SID,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100487 .alg = alg,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100488 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000489 };
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100490
Antonio de Angelis4743e672019-04-11 11:38:48 +0100491 psa_invec in_vec[] = {
492 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
493 };
494 psa_outvec out_vec[] = {
495 {.base = &(operation->handle), .len = sizeof(uint32_t)},
496 };
497
Antonio de Angelis4743e672019-04-11 11:38:48 +0100498 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100499
500 status = API_DISPATCH(tfm_crypto_hash_setup,
501 TFM_CRYPTO_HASH_SETUP);
502
Antonio de Angelis4743e672019-04-11 11:38:48 +0100503 PSA_CLOSE();
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100504
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000505 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100506}
507
508psa_status_t psa_hash_update(psa_hash_operation_t *operation,
509 const uint8_t *input,
510 size_t input_length)
511{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000512 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100513 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800514 .sfn_id = TFM_CRYPTO_HASH_UPDATE_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100515 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100516 };
517
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000518 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100519 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000520 {.base = input, .len = input_length},
521 };
522 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100523 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000524 };
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100525
Antonio de Angelis4743e672019-04-11 11:38:48 +0100526 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100527
528 status = API_DISPATCH(tfm_crypto_hash_update,
529 TFM_CRYPTO_HASH_UPDATE);
530
Antonio de Angelis4743e672019-04-11 11:38:48 +0100531 PSA_CLOSE();
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100532
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000533 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100534}
535
536psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
537 uint8_t *hash,
538 size_t hash_size,
539 size_t *hash_length)
540{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000541 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100542 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800543 .sfn_id = TFM_CRYPTO_HASH_FINISH_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100544 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100545 };
546
547 psa_invec in_vec[] = {
548 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
549 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000550 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100551 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000552 {.base = hash, .len = hash_size},
553 };
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100554
Antonio de Angelis4743e672019-04-11 11:38:48 +0100555 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100556
557 status = API_DISPATCH(tfm_crypto_hash_finish,
558 TFM_CRYPTO_HASH_FINISH);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100559
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000560 *hash_length = out_vec[1].len;
561
Antonio de Angelis4743e672019-04-11 11:38:48 +0100562 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +0100563
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000564 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100565}
566
567psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
568 const uint8_t *hash,
569 size_t hash_length)
570{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000571 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100572 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800573 .sfn_id = TFM_CRYPTO_HASH_VERIFY_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100574 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100575 };
576
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000577 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100578 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000579 {.base = hash, .len = hash_length},
580 };
581 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100582 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000583 };
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100584
Antonio de Angelis4743e672019-04-11 11:38:48 +0100585 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100586
587 status = API_DISPATCH(tfm_crypto_hash_verify,
588 TFM_CRYPTO_HASH_VERIFY);
Kevin Peng9449a362019-07-29 16:05:42 +0800589
Antonio de Angelis4743e672019-04-11 11:38:48 +0100590 PSA_CLOSE();
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100591
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000592 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100593}
594
595psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
596{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000597 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100598 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800599 .sfn_id = TFM_CRYPTO_HASH_ABORT_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100600 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000601 };
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100602
Antonio de Angelis4743e672019-04-11 11:38:48 +0100603 psa_invec in_vec[] = {
604 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
605 };
606 psa_outvec out_vec[] = {
607 {.base = &(operation->handle), .len = sizeof(uint32_t)},
608 };
609
Antonio de Angelis4743e672019-04-11 11:38:48 +0100610 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100611
612 status = API_DISPATCH(tfm_crypto_hash_abort,
613 TFM_CRYPTO_HASH_ABORT);
Kevin Peng9449a362019-07-29 16:05:42 +0800614
Antonio de Angelis4743e672019-04-11 11:38:48 +0100615 PSA_CLOSE();
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100616
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000617 return status;
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100618}
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100619
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100620psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation,
621 psa_hash_operation_t *target_operation)
622{
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100623 psa_status_t status;
624 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800625 .sfn_id = TFM_CRYPTO_HASH_CLONE_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100626 .op_handle = source_operation->handle,
627 };
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100628
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100629 psa_invec in_vec[] = {
630 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
631 };
632 psa_outvec out_vec[] = {
633 {.base = target_operation, .len = sizeof(psa_hash_operation_t)},
634 };
635
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100636 if (target_operation && (target_operation->handle != 0)) {
637 return PSA_ERROR_BAD_STATE;
638 }
639
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100640 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100641
642 status = API_DISPATCH(tfm_crypto_hash_clone,
643 TFM_CRYPTO_HASH_CLONE);
Kevin Peng9449a362019-07-29 16:05:42 +0800644
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100645 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100646
647 return status;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100648}
649
Soby Mathew07ef6e42020-07-20 21:09:23 +0100650psa_status_t psa_hash_compute(psa_algorithm_t alg,
651 const uint8_t *input,
652 size_t input_length,
653 uint8_t *hash,
654 size_t hash_size,
655 size_t *hash_length)
656{
Soby Mathew07ef6e42020-07-20 21:09:23 +0100657 psa_status_t status;
658 struct tfm_crypto_pack_iovec iov = {
659 .sfn_id = TFM_CRYPTO_HASH_COMPUTE_SID,
660 .alg = alg,
661 };
662
663 psa_invec in_vec[] = {
664 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
665 {.base = input, .len = input_length},
666 };
667
668 psa_outvec out_vec[] = {
669 {.base = hash, .len = hash_size}
670 };
671
672 PSA_CONNECT(TFM_CRYPTO);
673
674 status = API_DISPATCH(tfm_crypto_hash_compute,
675 TFM_CRYPTO_HASH_COMPUTE);
676
677 *hash_length = out_vec[0].len;
678
679 PSA_CLOSE();
680
681 return status;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100682}
683
684psa_status_t psa_hash_compare(psa_algorithm_t alg,
685 const uint8_t *input,
686 size_t input_length,
687 const uint8_t *hash,
688 size_t hash_length)
689{
Soby Mathew07ef6e42020-07-20 21:09:23 +0100690 psa_status_t status;
691 struct tfm_crypto_pack_iovec iov = {
692 .sfn_id = TFM_CRYPTO_HASH_COMPARE_SID,
693 .alg = alg,
694 };
695
696 psa_invec in_vec[] = {
697 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
698 {.base = input, .len = input_length},
699 {.base = hash, .len = hash_length},
700 };
701
702 PSA_CONNECT(TFM_CRYPTO);
703
704 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_hash_compare,
705 TFM_CRYPTO_HASH_COMPARE);
706
707 PSA_CLOSE();
708
709 return status;
Soby Mathew07ef6e42020-07-20 21:09:23 +0100710}
711
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100712psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100713 psa_key_handle_t handle,
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100714 psa_algorithm_t alg)
715{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000716 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100717 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800718 .sfn_id = TFM_CRYPTO_MAC_SIGN_SETUP_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100719 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100720 .alg = alg,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100721 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000722 };
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100723
Antonio de Angelis4743e672019-04-11 11:38:48 +0100724 psa_invec in_vec[] = {
725 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
726 };
727 psa_outvec out_vec[] = {
728 {.base = &(operation->handle), .len = sizeof(uint32_t)},
729 };
730
Antonio de Angelis4743e672019-04-11 11:38:48 +0100731 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100732
733 status = API_DISPATCH(tfm_crypto_mac_sign_setup,
734 TFM_CRYPTO_MAC_SIGN_SETUP);
Kevin Peng9449a362019-07-29 16:05:42 +0800735
Antonio de Angelis4743e672019-04-11 11:38:48 +0100736 PSA_CLOSE();
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100737
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000738 return status;
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100739}
740
741psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100742 psa_key_handle_t handle,
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100743 psa_algorithm_t alg)
744{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000745 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100746 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800747 .sfn_id = TFM_CRYPTO_MAC_VERIFY_SETUP_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100748 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100749 .alg = alg,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100750 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000751 };
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100752
Antonio de Angelis4743e672019-04-11 11:38:48 +0100753 psa_invec in_vec[] = {
754 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
755 };
756 psa_outvec out_vec[] = {
757 {.base = &(operation->handle), .len = sizeof(uint32_t)},
758 };
759
Antonio de Angelis4743e672019-04-11 11:38:48 +0100760 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100761
762 status = API_DISPATCH(tfm_crypto_mac_verify_setup,
763 TFM_CRYPTO_MAC_VERIFY_SETUP);
Kevin Peng9449a362019-07-29 16:05:42 +0800764
Antonio de Angelis4743e672019-04-11 11:38:48 +0100765 PSA_CLOSE();
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100766
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000767 return status;
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100768}
769
770psa_status_t psa_mac_update(psa_mac_operation_t *operation,
771 const uint8_t *input,
772 size_t input_length)
773{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000774 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100775 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800776 .sfn_id = TFM_CRYPTO_MAC_UPDATE_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100777 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100778 };
779
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000780 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100781 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000782 {.base = input, .len = input_length},
783 };
784 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100785 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000786 };
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100787
Antonio de Angelis4743e672019-04-11 11:38:48 +0100788 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100789
790 status = API_DISPATCH(tfm_crypto_mac_update,
791 TFM_CRYPTO_MAC_UPDATE);
Kevin Peng9449a362019-07-29 16:05:42 +0800792
Antonio de Angelis4743e672019-04-11 11:38:48 +0100793 PSA_CLOSE();
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100794
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000795 return status;
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100796}
797
798psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
799 uint8_t *mac,
800 size_t mac_size,
801 size_t *mac_length)
802{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000803 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100804 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800805 .sfn_id = TFM_CRYPTO_MAC_SIGN_FINISH_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100806 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100807 };
808
809 psa_invec in_vec[] = {
810 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
811 };
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000812 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100813 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000814 {.base = mac, .len = mac_size},
815 };
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100816
Antonio de Angelis4743e672019-04-11 11:38:48 +0100817 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100818
819 status = API_DISPATCH(tfm_crypto_mac_sign_finish,
820 TFM_CRYPTO_MAC_SIGN_FINISH);
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100821
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000822 *mac_length = out_vec[1].len;
823
Antonio de Angelis4743e672019-04-11 11:38:48 +0100824 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +0100825
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000826 return status;
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100827}
828
829psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation,
830 const uint8_t *mac,
831 size_t mac_length)
832{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000833 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100834 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800835 .sfn_id = TFM_CRYPTO_MAC_VERIFY_FINISH_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100836 .op_handle = operation->handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100837 };
838
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000839 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100840 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000841 {.base = mac, .len = mac_length},
842 };
843 psa_outvec out_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100844 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000845 };
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100846
Antonio de Angelis4743e672019-04-11 11:38:48 +0100847 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100848
849 status = API_DISPATCH(tfm_crypto_mac_verify_finish,
850 TFM_CRYPTO_MAC_VERIFY_FINISH);
851
Antonio de Angelis4743e672019-04-11 11:38:48 +0100852 PSA_CLOSE();
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100853
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000854 return status;
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100855}
856
857psa_status_t psa_mac_abort(psa_mac_operation_t *operation)
858{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000859 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100860 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800861 .sfn_id = TFM_CRYPTO_MAC_ABORT_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100862 .op_handle = operation->handle,
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000863 };
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100864
Antonio de Angelis4743e672019-04-11 11:38:48 +0100865 psa_invec in_vec[] = {
866 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
867 };
868 psa_outvec out_vec[] = {
869 {.base = &(operation->handle), .len = sizeof(uint32_t)},
870 };
871
Antonio de Angelis4743e672019-04-11 11:38:48 +0100872 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100873
874 status = API_DISPATCH(tfm_crypto_mac_abort,
875 TFM_CRYPTO_MAC_ABORT);
Kevin Peng9449a362019-07-29 16:05:42 +0800876
Antonio de Angelis4743e672019-04-11 11:38:48 +0100877 PSA_CLOSE();
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100878
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000879 return status;
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100880}
Antonio de Angelis3a480992018-11-07 11:53:28 +0000881
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100882psa_status_t psa_aead_encrypt(psa_key_handle_t handle,
Antonio de Angelis3a480992018-11-07 11:53:28 +0000883 psa_algorithm_t alg,
884 const uint8_t *nonce,
885 size_t nonce_length,
886 const uint8_t *additional_data,
887 size_t additional_data_length,
888 const uint8_t *plaintext,
889 size_t plaintext_length,
890 uint8_t *ciphertext,
891 size_t ciphertext_size,
892 size_t *ciphertext_length)
893{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000894 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100895 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800896 .sfn_id = TFM_CRYPTO_AEAD_ENCRYPT_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100897 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100898 .alg = alg,
899 .aead_in = {.nonce = {0}, .nonce_length = nonce_length}
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000900 };
Antonio de Angelis4743e672019-04-11 11:38:48 +0100901
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100902 /* Sanitize the optional input */
903 if ((additional_data == NULL) && (additional_data_length != 0)) {
904 return PSA_ERROR_INVALID_ARGUMENT;
905 }
906
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000907 size_t idx = 0;
908 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100909 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000910 {.base = plaintext, .len = plaintext_length},
Antonio de Angelis4743e672019-04-11 11:38:48 +0100911 {.base = additional_data, .len = additional_data_length},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000912 };
913 psa_outvec out_vec[] = {
914 {.base = ciphertext, .len = ciphertext_size},
915 };
Antonio de Angelis3a480992018-11-07 11:53:28 +0000916
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000917 if (nonce_length > TFM_CRYPTO_MAX_NONCE_LENGTH) {
918 return PSA_ERROR_INVALID_ARGUMENT;
919 }
Antonio de Angelis3a480992018-11-07 11:53:28 +0000920
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000921 if (nonce != NULL) {
922 for (idx = 0; idx < nonce_length; idx++) {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100923 iov.aead_in.nonce[idx] = nonce[idx];
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000924 }
925 }
Antonio de Angelis3a480992018-11-07 11:53:28 +0000926
Antonio de Angelis4743e672019-04-11 11:38:48 +0100927 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100928
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100929 size_t in_len = ARRAY_SIZE(in_vec);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100930 if (additional_data == NULL) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100931 in_len--;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100932 }
Summer Qin4b1d03b2019-07-02 14:56:08 +0800933 status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100934 out_vec, ARRAY_SIZE(out_vec));
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000935
936 *ciphertext_length = out_vec[0].len;
937
Antonio de Angelis4743e672019-04-11 11:38:48 +0100938 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +0100939
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000940 return status;
Antonio de Angelis3a480992018-11-07 11:53:28 +0000941}
942
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100943psa_status_t psa_aead_decrypt(psa_key_handle_t handle,
Antonio de Angelis3a480992018-11-07 11:53:28 +0000944 psa_algorithm_t alg,
945 const uint8_t *nonce,
946 size_t nonce_length,
947 const uint8_t *additional_data,
948 size_t additional_data_length,
949 const uint8_t *ciphertext,
950 size_t ciphertext_length,
951 uint8_t *plaintext,
952 size_t plaintext_size,
953 size_t *plaintext_length)
954{
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000955 psa_status_t status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100956 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +0800957 .sfn_id = TFM_CRYPTO_AEAD_DECRYPT_SID,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100958 .key_handle = handle,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100959 .alg = alg,
960 .aead_in = {.nonce = {0}, .nonce_length = nonce_length}
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000961 };
Antonio de Angelis4743e672019-04-11 11:38:48 +0100962
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100963 /* Sanitize the optional input */
964 if ((additional_data == NULL) && (additional_data_length != 0)) {
965 return PSA_ERROR_INVALID_ARGUMENT;
966 }
967
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000968 size_t idx = 0;
969 psa_invec in_vec[] = {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100970 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000971 {.base = ciphertext, .len = ciphertext_length},
Antonio de Angelis4743e672019-04-11 11:38:48 +0100972 {.base = additional_data, .len = additional_data_length},
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000973 };
974 psa_outvec out_vec[] = {
975 {.base = plaintext, .len = plaintext_size},
976 };
Antonio de Angelis3a480992018-11-07 11:53:28 +0000977
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000978 if (nonce_length > TFM_CRYPTO_MAX_NONCE_LENGTH) {
979 return PSA_ERROR_INVALID_ARGUMENT;
980 }
Antonio de Angelis3a480992018-11-07 11:53:28 +0000981
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000982 if (nonce != NULL) {
983 for (idx = 0; idx < nonce_length; idx++) {
Antonio de Angelis4743e672019-04-11 11:38:48 +0100984 iov.aead_in.nonce[idx] = nonce[idx];
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000985 }
986 }
Antonio de Angelis3a480992018-11-07 11:53:28 +0000987
Antonio de Angelis4743e672019-04-11 11:38:48 +0100988 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100989
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100990 size_t in_len = ARRAY_SIZE(in_vec);
Antonio de Angelis4743e672019-04-11 11:38:48 +0100991 if (additional_data == NULL) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100992 in_len--;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100993 }
Summer Qin4b1d03b2019-07-02 14:56:08 +0800994 status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100995 out_vec, ARRAY_SIZE(out_vec));
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000996
997 *plaintext_length = out_vec[0].len;
998
Antonio de Angelis4743e672019-04-11 11:38:48 +0100999 PSA_CLOSE();
Antonio de Angelis4743e672019-04-11 11:38:48 +01001000
Antonio de Angelisab85ccd2019-03-25 15:14:29 +00001001 return status;
Antonio de Angelis3a480992018-11-07 11:53:28 +00001002}
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001003
1004psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
1005 psa_algorithm_t alg,
1006 const uint8_t *hash,
1007 size_t hash_length,
1008 uint8_t *signature,
1009 size_t signature_size,
1010 size_t *signature_length)
1011{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001012 return psa_sign_hash(handle, alg, hash, hash_length, signature, signature_size, signature_length);
1013}
1014
1015psa_status_t psa_sign_hash(psa_key_handle_t handle,
1016 psa_algorithm_t alg,
1017 const uint8_t *hash,
1018 size_t hash_length,
1019 uint8_t *signature,
1020 size_t signature_size,
1021 size_t *signature_length)
1022{
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001023 psa_status_t status;
1024 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001025 .sfn_id = TFM_CRYPTO_SIGN_HASH_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001026 .key_handle = handle,
1027 .alg = alg,
1028 };
1029
1030 psa_invec in_vec[] = {
1031 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1032 {.base = hash, .len = hash_length},
1033 };
1034 psa_outvec out_vec[] = {
1035 {.base = signature, .len = signature_size},
1036 };
1037
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001038 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001039
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001040 status = API_DISPATCH(tfm_crypto_sign_hash,
1041 TFM_CRYPTO_SIGN_HASH);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001042
1043 *signature_length = out_vec[0].len;
1044
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001045 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001046
1047 return status;
1048}
1049
1050psa_status_t psa_asymmetric_verify(psa_key_handle_t handle,
1051 psa_algorithm_t alg,
1052 const uint8_t *hash,
1053 size_t hash_length,
1054 const uint8_t *signature,
1055 size_t signature_length)
1056{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001057 return psa_verify_hash(handle, alg, hash, hash_length, signature, signature_length);
1058}
1059
1060psa_status_t psa_verify_hash(psa_key_handle_t handle,
1061 psa_algorithm_t alg,
1062 const uint8_t *hash,
1063 size_t hash_length,
1064 const uint8_t *signature,
1065 size_t signature_length)
1066{
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001067 psa_status_t status;
1068 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001069 .sfn_id = TFM_CRYPTO_VERIFY_HASH_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001070 .key_handle = handle,
1071 .alg = alg
1072 };
1073
1074 psa_invec in_vec[] = {
1075 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1076 {.base = hash, .len = hash_length},
1077 {.base = signature, .len = signature_length}
1078 };
1079
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001080 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001081
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001082 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_verify_hash,
1083 TFM_CRYPTO_VERIFY_HASH);
Kevin Peng9449a362019-07-29 16:05:42 +08001084
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001085 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001086
1087 return status;
1088}
1089
1090psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle,
1091 psa_algorithm_t alg,
1092 const uint8_t *input,
1093 size_t input_length,
1094 const uint8_t *salt,
1095 size_t salt_length,
1096 uint8_t *output,
1097 size_t output_size,
1098 size_t *output_length)
1099{
1100 psa_status_t status;
1101 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +08001102 .sfn_id = TFM_CRYPTO_ASYMMETRIC_ENCRYPT_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001103 .key_handle = handle,
1104 .alg = alg
1105 };
1106
1107 /* Sanitize the optional input */
1108 if ((salt == NULL) && (salt_length != 0)) {
1109 return PSA_ERROR_INVALID_ARGUMENT;
1110 }
1111
1112 psa_invec in_vec[] = {
1113 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1114 {.base = input, .len = input_length},
1115 {.base = salt, .len = salt_length}
1116 };
1117
1118 psa_outvec out_vec[] = {
1119 {.base = output, .len = output_size},
1120 };
1121
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001122 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001123
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001124 size_t in_len = ARRAY_SIZE(in_vec);
1125 if (salt == NULL) {
1126 in_len--;
1127 }
Summer Qin4b1d03b2019-07-02 14:56:08 +08001128 status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001129 out_vec, ARRAY_SIZE(out_vec));
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001130
1131 *output_length = out_vec[0].len;
1132
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001133 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001134
1135 return status;
1136}
1137
1138psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle,
1139 psa_algorithm_t alg,
1140 const uint8_t *input,
1141 size_t input_length,
1142 const uint8_t *salt,
1143 size_t salt_length,
1144 uint8_t *output,
1145 size_t output_size,
1146 size_t *output_length)
1147{
1148 psa_status_t status;
1149 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +08001150 .sfn_id = TFM_CRYPTO_ASYMMETRIC_DECRYPT_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001151 .key_handle = handle,
1152 .alg = alg
1153 };
1154
1155 /* Sanitize the optional input */
1156 if ((salt == NULL) && (salt_length != 0)) {
1157 return PSA_ERROR_INVALID_ARGUMENT;
1158 }
1159
1160 psa_invec in_vec[] = {
1161 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1162 {.base = input, .len = input_length},
1163 {.base = salt, .len = salt_length}
1164 };
1165
1166 psa_outvec out_vec[] = {
1167 {.base = output, .len = output_size},
1168 };
1169
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001170 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001171
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001172 size_t in_len = ARRAY_SIZE(in_vec);
1173 if (salt == NULL) {
1174 in_len--;
1175 }
Summer Qin4b1d03b2019-07-02 14:56:08 +08001176 status = psa_call(ipc_handle, PSA_IPC_CALL, in_vec, in_len,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001177 out_vec, ARRAY_SIZE(out_vec));
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001178
1179 *output_length = out_vec[0].len;
1180
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001181 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001182
1183 return status;
1184}
1185
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001186psa_status_t psa_key_derivation_get_capacity(
1187 const psa_key_derivation_operation_t *operation,
1188 size_t *capacity)
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001189{
1190 psa_status_t status;
1191 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001192 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_GET_CAPACITY_SID,
1193 .op_handle = operation->handle,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001194 };
1195
1196 psa_invec in_vec[] = {
1197 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1198 };
1199
1200 psa_outvec out_vec[] = {
1201 {.base = capacity, .len = sizeof(size_t)},
1202 };
1203
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001204 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001205
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001206 status = API_DISPATCH(tfm_crypto_key_derivation_get_capacity,
1207 TFM_CRYPTO_KEY_DERIVATION_GET_CAPACITY);
Kevin Peng9449a362019-07-29 16:05:42 +08001208
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001209 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001210
1211 return status;
1212}
1213
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001214psa_status_t psa_key_derivation_output_bytes(
1215 psa_key_derivation_operation_t *operation,
1216 uint8_t *output,
1217 size_t output_length)
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001218{
1219 psa_status_t status;
1220 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001221 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_SID,
1222 .op_handle = operation->handle,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001223 };
1224
1225 psa_invec in_vec[] = {
1226 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1227 };
1228
1229 psa_outvec out_vec[] = {
1230 {.base = output, .len = output_length},
1231 };
1232
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001233 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001234
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001235 status = API_DISPATCH(tfm_crypto_key_derivation_output_bytes,
1236 TFM_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES);
Kevin Peng9449a362019-07-29 16:05:42 +08001237
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001238 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001239
1240 return status;
1241}
1242
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001243psa_status_t psa_key_derivation_input_key(
1244 psa_key_derivation_operation_t *operation,
1245 psa_key_derivation_step_t step,
1246 psa_key_handle_t handle)
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001247{
1248 psa_status_t status;
1249 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001250 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_KEY_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001251 .key_handle = handle,
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001252 .step = step,
1253 .op_handle = operation->handle,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001254 };
1255
1256 psa_invec in_vec[] = {
1257 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001258 };
1259
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001260 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001261
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001262 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_input_key,
1263 TFM_CRYPTO_KEY_DERIVATION_INPUT_KEY);
Kevin Peng9449a362019-07-29 16:05:42 +08001264
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001265 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001266
1267 return status;
1268}
1269
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001270psa_status_t psa_key_derivation_abort(
1271 psa_key_derivation_operation_t *operation)
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001272{
1273 psa_status_t status;
1274 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001275 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_ABORT_SID,
1276 .op_handle = operation->handle,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001277 };
1278
1279 psa_invec in_vec[] = {
1280 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1281 };
1282
1283 psa_outvec out_vec[] = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001284 {.base = &(operation->handle), .len = sizeof(uint32_t)},
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001285 };
1286
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001287 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001288
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001289 status = API_DISPATCH(tfm_crypto_key_derivation_abort,
1290 TFM_CRYPTO_KEY_DERIVATION_ABORT);
Kevin Peng9449a362019-07-29 16:05:42 +08001291
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001292 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001293
1294 return status;
1295}
1296
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001297psa_status_t psa_key_derivation_key_agreement(
1298 psa_key_derivation_operation_t *operation,
1299 psa_key_derivation_step_t step,
1300 psa_key_handle_t private_key,
1301 const uint8_t *peer_key,
1302 size_t peer_key_length)
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001303{
1304 psa_status_t status;
1305 struct tfm_crypto_pack_iovec iov = {
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001306 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001307 .key_handle = private_key,
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001308 .step = step,
1309 .op_handle = operation->handle,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001310 };
1311
1312 psa_invec in_vec[] = {
1313 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1314 {.base = peer_key, .len = peer_key_length},
1315 };
1316
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001317 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001318
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001319 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_key_agreement,
1320 TFM_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001321
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001322 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001323
1324 return status;
1325}
1326
1327psa_status_t psa_generate_random(uint8_t *output,
1328 size_t output_size)
1329{
1330 psa_status_t status;
1331 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +08001332 .sfn_id = TFM_CRYPTO_GENERATE_RANDOM_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001333 };
1334
1335 psa_invec in_vec[] = {
1336 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1337 };
1338
1339 psa_outvec out_vec[] = {
1340 {.base = output, .len = output_size},
1341 };
1342
1343 if (output_size == 0) {
1344 return PSA_SUCCESS;
1345 }
1346
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001347 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001348
1349 status = API_DISPATCH(tfm_crypto_generate_random,
1350 TFM_CRYPTO_GENERATE_RANDOM);
1351
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001352 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001353
1354 return status;
1355}
1356
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001357psa_status_t psa_generate_key(const psa_key_attributes_t *attributes,
1358 psa_key_handle_t *handle)
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001359{
1360 psa_status_t status;
1361 struct tfm_crypto_pack_iovec iov = {
Edison Ai080b2e22019-04-17 16:27:21 +08001362 .sfn_id = TFM_CRYPTO_GENERATE_KEY_SID,
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001363 };
1364
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001365 psa_invec in_vec[] = {
1366 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001367 {.base = attributes, .len = sizeof(psa_key_attributes_t)},
1368 };
1369
1370 psa_outvec out_vec[] = {
1371 {.base = handle, .len = sizeof(psa_key_handle_t)},
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001372 };
1373
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001374 PSA_CONNECT(TFM_CRYPTO);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001375
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001376 status = API_DISPATCH(tfm_crypto_generate_key,
1377 TFM_CRYPTO_GENERATE_KEY);
1378 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001379
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001380 return status;
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001381}
1382
1383psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
1384 psa_key_type_t type,
1385 const uint8_t *data,
1386 size_t data_length)
1387{
1388 psa_status_t status;
1389
1390 status = PSA_ERROR_NOT_SUPPORTED;
1391
1392 return status;
1393}
1394
1395psa_status_t psa_get_key_domain_parameters(
1396 const psa_key_attributes_t *attributes,
1397 uint8_t *data,
1398 size_t data_size,
1399 size_t *data_length)
1400{
1401 psa_status_t status;
1402
1403 status = PSA_ERROR_NOT_SUPPORTED;
1404
1405 return status;
1406}
1407
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001408psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
1409 const uint8_t *input,
1410 size_t input_length)
1411{
1412 psa_status_t status;
1413
1414 status = PSA_ERROR_NOT_SUPPORTED;
1415
1416 return status;
1417}
1418
1419psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
1420 uint8_t *ciphertext,
1421 size_t ciphertext_size,
1422 size_t *ciphertext_length,
1423 uint8_t *tag,
1424 size_t tag_size,
1425 size_t *tag_length)
1426{
1427 psa_status_t status;
1428
1429 status = PSA_ERROR_NOT_SUPPORTED;
1430
1431 return status;
1432}
1433
1434psa_status_t psa_aead_verify(psa_aead_operation_t *operation,
1435 uint8_t *plaintext,
1436 size_t plaintext_size,
1437 size_t *plaintext_length,
1438 const uint8_t *tag,
1439 size_t tag_length)
1440{
1441 psa_status_t status;
1442
1443 status = PSA_ERROR_NOT_SUPPORTED;
1444
1445 return status;
1446}
1447
1448psa_status_t psa_aead_abort(psa_aead_operation_t *operation)
1449{
1450 psa_status_t status;
1451
1452 status = PSA_ERROR_NOT_SUPPORTED;
1453
1454 return status;
1455}
1456
1457psa_status_t psa_mac_compute(psa_key_handle_t handle,
1458 psa_algorithm_t alg,
1459 const uint8_t *input,
1460 size_t input_length,
1461 uint8_t *mac,
1462 size_t mac_size,
1463 size_t *mac_length)
1464{
1465 psa_status_t status;
1466
1467 status = PSA_ERROR_NOT_SUPPORTED;
1468
1469 return status;
1470}
1471
1472psa_status_t psa_mac_verify(psa_key_handle_t handle,
1473 psa_algorithm_t alg,
1474 const uint8_t *input,
1475 size_t input_length,
1476 const uint8_t *mac,
1477 const size_t mac_length)
1478{
1479 psa_status_t status;
1480
1481 status = PSA_ERROR_NOT_SUPPORTED;
1482
1483 return status;
1484}
1485
1486psa_status_t psa_cipher_encrypt(psa_key_handle_t handle,
1487 psa_algorithm_t alg,
1488 const uint8_t *input,
1489 size_t input_length,
1490 uint8_t *output,
1491 size_t output_size,
1492 size_t *output_length)
1493{
1494 psa_status_t status;
1495
1496 status = PSA_ERROR_NOT_SUPPORTED;
1497
1498 return status;
1499}
1500
1501psa_status_t psa_cipher_decrypt(psa_key_handle_t handle,
1502 psa_algorithm_t alg,
1503 const uint8_t *input,
1504 size_t input_length,
1505 uint8_t *output,
1506 size_t output_size,
1507 size_t *output_length)
1508{
1509 psa_status_t status;
1510
1511 status = PSA_ERROR_NOT_SUPPORTED;
1512
1513 return status;
1514}
1515
1516psa_status_t psa_raw_key_agreement(psa_algorithm_t alg,
1517 psa_key_handle_t private_key,
1518 const uint8_t *peer_key,
1519 size_t peer_key_length,
1520 uint8_t *output,
1521 size_t output_size,
1522 size_t *output_length)
1523{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001524 psa_status_t status;
1525 struct tfm_crypto_pack_iovec iov = {
1526 .sfn_id = TFM_CRYPTO_RAW_KEY_AGREEMENT_SID,
1527 .alg = alg,
1528 .key_handle = private_key
1529 };
1530
1531 psa_invec in_vec[] = {
1532 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1533 {.base = peer_key, .len = peer_key_length},
1534 };
1535
1536 psa_outvec out_vec[] = {
1537 {.base = output, .len = output_size},
1538 };
1539
1540 PSA_CONNECT(TFM_CRYPTO);
1541
1542 status = API_DISPATCH(tfm_crypto_raw_key_agreement,
1543 TFM_CRYPTO_RAW_KEY_AGREEMENT);
1544
1545 *output_length = out_vec[0].len;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001546
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001547 PSA_CLOSE();
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +01001548
1549 return status;
1550}
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001551
1552psa_status_t psa_key_derivation_setup(psa_key_derivation_operation_t *operation,
1553 psa_algorithm_t alg)
1554{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001555 psa_status_t status;
1556 struct tfm_crypto_pack_iovec iov = {
1557 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_SETUP_SID,
1558 .alg = alg,
1559 .op_handle = operation->handle,
1560 };
1561
1562 psa_invec in_vec[] = {
1563 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1564 };
1565 psa_outvec out_vec[] = {
1566 {.base = &(operation->handle), .len = sizeof(uint32_t)},
1567 };
1568
1569 PSA_CONNECT(TFM_CRYPTO);
1570
1571 status = API_DISPATCH(tfm_crypto_key_derivation_setup,
1572 TFM_CRYPTO_KEY_DERIVATION_SETUP);
1573 PSA_CLOSE();
1574
1575 return status;
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001576}
1577
1578psa_status_t psa_key_derivation_set_capacity(
1579 psa_key_derivation_operation_t *operation,
1580 size_t capacity)
1581{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001582 psa_status_t status;
1583 struct tfm_crypto_pack_iovec iov = {
1584 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_SET_CAPACITY_SID,
1585 .capacity = capacity,
1586 .op_handle = operation->handle,
1587 };
1588
1589 psa_invec in_vec[] = {
1590 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1591 };
1592
1593 PSA_CONNECT(TFM_CRYPTO);
1594
1595 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_set_capacity,
1596 TFM_CRYPTO_KEY_DERIVATION_SET_CAPACITY);
1597 PSA_CLOSE();
1598
1599 return status;
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001600}
1601
1602psa_status_t psa_key_derivation_input_bytes(
1603 psa_key_derivation_operation_t *operation,
1604 psa_key_derivation_step_t step,
1605 const uint8_t *data,
1606 size_t data_length)
1607{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001608 psa_status_t status;
1609 struct tfm_crypto_pack_iovec iov = {
1610 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_BYTES_SID,
1611 .step = step,
1612 .op_handle = operation->handle,
1613 };
1614
1615 psa_invec in_vec[] = {
1616 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1617 {.base = data, .len = data_length},
1618 };
1619
1620 PSA_CONNECT(TFM_CRYPTO);
1621
1622 status = API_DISPATCH_NO_OUTVEC(tfm_crypto_key_derivation_input_bytes,
1623 TFM_CRYPTO_KEY_DERIVATION_INPUT_BYTES);
1624 PSA_CLOSE();
1625
1626 return status;
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001627}
1628
1629psa_status_t psa_key_derivation_output_key(
1630 const psa_key_attributes_t *attributes,
1631 psa_key_derivation_operation_t *operation,
1632 psa_key_handle_t *handle)
1633{
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001634 psa_status_t status;
1635 struct tfm_crypto_pack_iovec iov = {
1636 .sfn_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_KEY_SID,
1637 .op_handle = operation->handle,
1638 };
1639
1640 psa_invec in_vec[] = {
1641 {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)},
1642 {.base = attributes, .len = sizeof(psa_key_attributes_t)},
1643 };
1644
1645 psa_outvec out_vec[] = {
1646 {.base = handle, .len = sizeof(psa_key_handle_t)}
1647 };
1648
1649 PSA_CONNECT(TFM_CRYPTO);
1650
1651 status = API_DISPATCH(tfm_crypto_key_derivation_output_key,
1652 TFM_CRYPTO_KEY_DERIVATION_OUTPUT_KEY);
1653 PSA_CLOSE();
1654
1655 return status;
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001656}
1657
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001658psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation,
1659 psa_key_handle_t handle,
1660 psa_algorithm_t alg)
1661{
1662 psa_status_t status;
1663
1664 status = PSA_ERROR_NOT_SUPPORTED;
1665
1666 return status;
1667}
1668
1669psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation,
1670 psa_key_handle_t handle,
1671 psa_algorithm_t alg)
1672{
1673 psa_status_t status;
1674
1675 status = PSA_ERROR_NOT_SUPPORTED;
1676
1677 return status;
1678}
1679
1680psa_status_t psa_aead_generate_nonce(psa_aead_operation_t *operation,
1681 uint8_t *nonce,
1682 size_t nonce_size,
1683 size_t *nonce_length)
1684{
1685 psa_status_t status;
1686
1687 status = PSA_ERROR_NOT_SUPPORTED;
1688
1689 return status;
1690}
1691
1692psa_status_t psa_aead_set_nonce(psa_aead_operation_t *operation,
1693 const uint8_t *nonce,
1694 size_t nonce_length)
1695{
1696 psa_status_t status;
1697
1698 status = PSA_ERROR_NOT_SUPPORTED;
1699
1700 return status;
1701}
1702
1703psa_status_t psa_aead_set_lengths(psa_aead_operation_t *operation,
1704 size_t ad_length,
1705 size_t plaintext_length)
1706{
1707 psa_status_t status;
1708
1709 status = PSA_ERROR_NOT_SUPPORTED;
1710
1711 return status;
1712}
1713
1714psa_status_t psa_aead_update(psa_aead_operation_t *operation,
1715 const uint8_t *input,
1716 size_t input_length,
1717 uint8_t *output,
1718 size_t output_size,
1719 size_t *output_length)
1720{
1721 psa_status_t status;
1722
1723 status = PSA_ERROR_NOT_SUPPORTED;
1724
1725 return status;
1726}