blob: 5a318efd83a8f0328194a8f8fec952326da09110 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Maulik Patel28659c42021-01-06 14:09:22 +00002 * Copyright (c) 2018-2021, 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 Fox0e54ebc2019-04-09 14:21:04 +01008#include <stddef.h>
9#include <stdint.h>
Antonio de Angelis8908f472018-08-31 15:44:25 +010010
Jamie Fox0e54ebc2019-04-09 14:21:04 +010011#include "tfm_mbedcrypto_include.h"
Antonio de Angelis4743e672019-04-11 11:38:48 +010012
Jamie Fox0e54ebc2019-04-09 14:21:04 +010013#include "tfm_crypto_api.h"
14#include "tfm_crypto_defs.h"
Soby Mathewd8abdfd2020-10-14 10:28:01 +010015#include "tfm_crypto_private.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010016
17/*!
18 * \defgroup public_psa Public functions, PSA
19 *
20 */
21
22/*!@{*/
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010023psa_status_t tfm_crypto_cipher_generate_iv(psa_invec in_vec[],
24 size_t in_len,
25 psa_outvec out_vec[],
26 size_t out_len)
27{
Kevin Peng96f802e2019-12-26 16:10:25 +080028#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +010029 return PSA_ERROR_NOT_SUPPORTED;
30#else
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010031 psa_status_t status = PSA_SUCCESS;
32 psa_cipher_operation_t *operation = NULL;
33
Soby Mathewd8abdfd2020-10-14 10:28:01 +010034 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 2);
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010035
36 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
37 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +010038 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010039 }
40
41 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
42 uint32_t handle = iov->op_handle;
43 uint32_t *handle_out = out_vec[0].base;
44 unsigned char *iv = out_vec[1].base;
45 size_t iv_size = out_vec[1].len;
46
47 /* Init the handle in the operation with the one passed from the iov */
48 *handle_out = iov->op_handle;
49
50 /* Look up the corresponding operation context */
51 status = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
52 handle,
53 (void **)&operation);
54 if (status != PSA_SUCCESS) {
55 return status;
56 }
57
58 *handle_out = handle;
59
David Hu7e2e5232021-04-21 16:52:07 +080060 return psa_cipher_generate_iv(operation, iv, iv_size, &out_vec[1].len);
Antonio de Angelis7740b382019-07-16 10:59:25 +010061#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010062}
63
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000064psa_status_t tfm_crypto_cipher_set_iv(psa_invec in_vec[],
65 size_t in_len,
66 psa_outvec out_vec[],
67 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +010068{
Kevin Peng96f802e2019-12-26 16:10:25 +080069#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +010070 return PSA_ERROR_NOT_SUPPORTED;
71#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010072 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010073 psa_cipher_operation_t *operation = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +010074
Soby Mathewd8abdfd2020-10-14 10:28:01 +010075 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 1, 1);
Antonio de Angelis8908f472018-08-31 15:44:25 +010076
Antonio de Angelis4743e672019-04-11 11:38:48 +010077 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
Jamie Fox0e54ebc2019-04-09 14:21:04 +010078 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +010079 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000080 }
Antonio de Angelis4743e672019-04-11 11:38:48 +010081 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +010082 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +010083 uint32_t *handle_out = out_vec[0].base;
84 const unsigned char *iv = in_vec[1].base;
85 size_t iv_length = in_vec[1].len;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000086
Antonio de Angelis4743e672019-04-11 11:38:48 +010087 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +010088 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000089
Antonio de Angelis8908f472018-08-31 15:44:25 +010090 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000091 status = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +010092 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +010093 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +000094 if (status != PSA_SUCCESS) {
95 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +010096 }
97
David Hu7e2e5232021-04-21 16:52:07 +080098 return psa_cipher_set_iv(operation, iv, iv_length);
Antonio de Angelis7740b382019-07-16 10:59:25 +010099#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000100}
Antonio de Angelis4743e672019-04-11 11:38:48 +0100101
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000102psa_status_t tfm_crypto_cipher_encrypt_setup(psa_invec in_vec[],
103 size_t in_len,
104 psa_outvec out_vec[],
105 size_t out_len)
106{
Kevin Peng96f802e2019-12-26 16:10:25 +0800107#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100108 return PSA_ERROR_NOT_SUPPORTED;
109#else
Antonio de Angelis4743e672019-04-11 11:38:48 +0100110 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100111 psa_cipher_operation_t *operation = NULL;
112
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100113 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000114
Antonio de Angelis4743e672019-04-11 11:38:48 +0100115 if ((out_vec[0].len != sizeof(uint32_t)) ||
116 (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100117 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000118 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100119 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100120 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100121 uint32_t *handle_out = out_vec[0].base;
Maulik Patel28659c42021-01-06 14:09:22 +0000122 psa_key_id_t key_id = iov->key_id;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100123 psa_algorithm_t alg = iov->alg;
Maulik Patel28659c42021-01-06 14:09:22 +0000124 mbedtls_svc_key_id_t encoded_key;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000125
Maulik Patel28659c42021-01-06 14:09:22 +0000126 status = tfm_crypto_check_handle_owner(key_id, NULL);
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100127 if (status != PSA_SUCCESS) {
128 return status;
129 }
130
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100131 /* Allocate the operation context in the secure world */
132 status = tfm_crypto_operation_alloc(TFM_CRYPTO_CIPHER_OPERATION,
133 &handle,
134 (void **)&operation);
135 if (status != PSA_SUCCESS) {
136 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100137 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100138 *handle_out = handle;
139
Maulik Patel28659c42021-01-06 14:09:22 +0000140 status = tfm_crypto_encode_id_and_owner(key_id, &encoded_key);
141 if (status != PSA_SUCCESS) {
David Hu7e2e5232021-04-21 16:52:07 +0800142 goto exit;
Maulik Patel28659c42021-01-06 14:09:22 +0000143 }
144
145 status = psa_cipher_encrypt_setup(operation, encoded_key, alg);
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100146 if (status != PSA_SUCCESS) {
David Hu7e2e5232021-04-21 16:52:07 +0800147 goto exit;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100148 }
149
Antonio de Angelis4743e672019-04-11 11:38:48 +0100150 return status;
David Hu7e2e5232021-04-21 16:52:07 +0800151
152exit:
153 /* Release the operation context, ignore if the operation fails. */
154 (void)tfm_crypto_operation_release(handle_out);
155 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100156#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100157}
158
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000159psa_status_t tfm_crypto_cipher_decrypt_setup(psa_invec in_vec[],
160 size_t in_len,
161 psa_outvec out_vec[],
162 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100163{
Kevin Peng96f802e2019-12-26 16:10:25 +0800164#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100165 return PSA_ERROR_NOT_SUPPORTED;
166#else
Antonio de Angelis4743e672019-04-11 11:38:48 +0100167 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100168 psa_cipher_operation_t *operation = NULL;
169
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100170 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000171
Antonio de Angelis4743e672019-04-11 11:38:48 +0100172 if ((out_vec[0].len != sizeof(uint32_t)) ||
173 (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100174 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000175 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100176 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100177 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100178 uint32_t *handle_out = out_vec[0].base;
Maulik Patel28659c42021-01-06 14:09:22 +0000179 psa_key_id_t key_id = iov->key_id;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100180 psa_algorithm_t alg = iov->alg;
Maulik Patel28659c42021-01-06 14:09:22 +0000181 mbedtls_svc_key_id_t encoded_key;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000182
Maulik Patel28659c42021-01-06 14:09:22 +0000183 status = tfm_crypto_check_handle_owner(key_id, NULL);
Antonio de Angelis60a6fe62019-06-18 15:27:34 +0100184 if (status != PSA_SUCCESS) {
185 return status;
186 }
187
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100188 /* Allocate the operation context in the secure world */
189 status = tfm_crypto_operation_alloc(TFM_CRYPTO_CIPHER_OPERATION,
190 &handle,
191 (void **)&operation);
192 if (status != PSA_SUCCESS) {
193 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100194 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100195
196 *handle_out = handle;
Maulik Patel28659c42021-01-06 14:09:22 +0000197 status = tfm_crypto_encode_id_and_owner(key_id, &encoded_key);
198 if (status != PSA_SUCCESS) {
David Hu7e2e5232021-04-21 16:52:07 +0800199 goto exit;
Maulik Patel28659c42021-01-06 14:09:22 +0000200 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100201
Maulik Patel28659c42021-01-06 14:09:22 +0000202 status = psa_cipher_decrypt_setup(operation, encoded_key, alg);
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100203 if (status != PSA_SUCCESS) {
David Hu7e2e5232021-04-21 16:52:07 +0800204 goto exit;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100205 }
206
Antonio de Angelis4743e672019-04-11 11:38:48 +0100207 return status;
David Hu7e2e5232021-04-21 16:52:07 +0800208
209exit:
210 /* Release the operation context, ignore if the operation fails. */
211 (void)tfm_crypto_operation_release(handle_out);
212 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100213#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100214}
215
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000216psa_status_t tfm_crypto_cipher_update(psa_invec in_vec[],
217 size_t in_len,
218 psa_outvec out_vec[],
219 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100220{
Kevin Peng96f802e2019-12-26 16:10:25 +0800221#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100222 return PSA_ERROR_NOT_SUPPORTED;
223#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100224 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100225 psa_cipher_operation_t *operation = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100226
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100227 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 2, out_len, 1, 2);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100228
Antonio de Angelis4743e672019-04-11 11:38:48 +0100229 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
230 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100231 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000232 }
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100233
Antonio de Angelis4743e672019-04-11 11:38:48 +0100234 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100235 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100236 uint32_t *handle_out = out_vec[0].base;
237 const uint8_t *input = in_vec[1].base;
238 size_t input_length = in_vec[1].len;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000239 unsigned char *output = out_vec[1].base;
240 size_t output_size = out_vec[1].len;
241
Antonio de Angelis4743e672019-04-11 11:38:48 +0100242 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100243 *handle_out = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100244
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000245 /* Initialise the output_length to zero */
246 out_vec[1].len = 0;
Jamie Fox82b87ca2018-12-11 16:41:11 +0000247
Antonio de Angelis8908f472018-08-31 15:44:25 +0100248 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000249 status = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100250 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100251 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000252 if (status != PSA_SUCCESS) {
253 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100254 }
255
David Hu7e2e5232021-04-21 16:52:07 +0800256 return psa_cipher_update(operation, input, input_length,
257 output, output_size, &out_vec[1].len);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100258#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100259}
260
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000261psa_status_t tfm_crypto_cipher_finish(psa_invec in_vec[],
262 size_t in_len,
263 psa_outvec out_vec[],
264 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100265{
Kevin Peng96f802e2019-12-26 16:10:25 +0800266#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100267 return PSA_ERROR_NOT_SUPPORTED;
268#else
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100269 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100270 psa_cipher_operation_t *operation = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100271
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100272 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 2);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100273
Antonio de Angelis4743e672019-04-11 11:38:48 +0100274 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
275 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100276 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000277 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100278 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100279 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100280 uint32_t *handle_out = out_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000281 unsigned char *output = out_vec[1].base;
282 size_t output_size = out_vec[1].len;
283
Antonio de Angelis4743e672019-04-11 11:38:48 +0100284 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100285 *handle_out = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100286
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000287 /* Initialise the output_length to zero */
288 out_vec[1].len = 0;
289
Antonio de Angelis8908f472018-08-31 15:44:25 +0100290 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000291 status = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100292 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100293 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000294 if (status != PSA_SUCCESS) {
295 return status;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100296 }
297
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100298 status = psa_cipher_finish(operation, output, output_size, &out_vec[1].len);
David Hu7e2e5232021-04-21 16:52:07 +0800299 if (status == PSA_SUCCESS) {
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100300 /* Release the operation context, ignore if the operation fails. */
301 (void)tfm_crypto_operation_release(handle_out);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100302 }
303
Antonio de Angelis4743e672019-04-11 11:38:48 +0100304 return status;
Antonio de Angelis7740b382019-07-16 10:59:25 +0100305#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100306}
307
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000308psa_status_t tfm_crypto_cipher_abort(psa_invec in_vec[],
309 size_t in_len,
310 psa_outvec out_vec[],
311 size_t out_len)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100312{
Kevin Peng96f802e2019-12-26 16:10:25 +0800313#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED
Antonio de Angelis7740b382019-07-16 10:59:25 +0100314 return PSA_ERROR_NOT_SUPPORTED;
315#else
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000316 psa_status_t status = PSA_SUCCESS;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100317 psa_cipher_operation_t *operation = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100318
Soby Mathewd8abdfd2020-10-14 10:28:01 +0100319 CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 1, 1);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100320
Antonio de Angelis4743e672019-04-11 11:38:48 +0100321 if ((in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) ||
322 (out_vec[0].len != sizeof(uint32_t))) {
Soby Mathewc6e89362020-10-19 16:55:16 +0100323 return PSA_ERROR_PROGRAMMER_ERROR;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000324 }
Antonio de Angelis4743e672019-04-11 11:38:48 +0100325 const struct tfm_crypto_pack_iovec *iov = in_vec[0].base;
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100326 uint32_t handle = iov->op_handle;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100327 uint32_t *handle_out = out_vec[0].base;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000328
Antonio de Angelis4743e672019-04-11 11:38:48 +0100329 /* Init the handle in the operation with the one passed from the iov */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100330 *handle_out = iov->op_handle;
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000331
Antonio de Angelis8908f472018-08-31 15:44:25 +0100332 /* Look up the corresponding operation context */
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000333 status = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis4743e672019-04-11 11:38:48 +0100334 handle,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100335 (void **)&operation);
Antonio de Angelisab85ccd2019-03-25 15:14:29 +0000336 if (status != PSA_SUCCESS) {
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +0100337 /* Operation does not exist, so abort has no effect */
338 return PSA_SUCCESS;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100339 }
340
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100341 status = psa_cipher_abort(operation);
342
343 if (status != PSA_SUCCESS) {
344 /* Release the operation context, ignore if the operation fails. */
345 (void)tfm_crypto_operation_release(handle_out);
346 return status;
Antonio de Angelis4743e672019-04-11 11:38:48 +0100347 }
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100348
David Hu7e2e5232021-04-21 16:52:07 +0800349 return tfm_crypto_operation_release(handle_out);
Antonio de Angelis7740b382019-07-16 10:59:25 +0100350#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100351}
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100352
353psa_status_t tfm_crypto_cipher_encrypt(psa_invec in_vec[],
354 size_t in_len,
355 psa_outvec out_vec[],
356 size_t out_len)
357{
358 /* FixMe: To be implemented */
359 return PSA_ERROR_NOT_SUPPORTED;
360}
361
362psa_status_t tfm_crypto_cipher_decrypt(psa_invec in_vec[],
363 size_t in_len,
364 psa_outvec out_vec[],
365 size_t out_len)
366{
367 /* FixMe: To be implemented */
368 return PSA_ERROR_NOT_SUPPORTED;
369}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100370/*!@}*/