blob: 84b5b7828c993a362d840ae22e1c9e107f466ba7 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis377a1552018-11-22 17:02:40 +00002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <limits.h>
9
10#include "tfm_crypto_defs.h"
11
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010012#include "crypto_engine.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010013
14#include "psa_crypto.h"
15
Antonio de Angelis377a1552018-11-22 17:02:40 +000016#include "tfm_crypto_struct.h"
Antonio de Angelis8908f472018-08-31 15:44:25 +010017
18#include "tfm_crypto_api.h"
19#include "crypto_utils.h"
20
Antonio de Angelis8908f472018-08-31 15:44:25 +010021static enum tfm_crypto_err_t tfm_crypto_cipher_setup(
Antonio de Angelis377a1552018-11-22 17:02:40 +000022 psa_cipher_operation_t *operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +010023 psa_key_slot_t key,
24 psa_algorithm_t alg,
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010025 enum engine_cipher_mode_t c_mode)
Antonio de Angelis8908f472018-08-31 15:44:25 +010026{
Antonio de Angelis8908f472018-08-31 15:44:25 +010027 uint8_t key_data[TFM_CRYPTO_MAX_KEY_LENGTH];
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010028 size_t key_size;
29 psa_key_type_t key_type = PSA_KEY_TYPE_NONE;
30 psa_status_t status = PSA_SUCCESS;
31 enum tfm_crypto_err_t err;
Antonio de Angelis377a1552018-11-22 17:02:40 +000032 struct tfm_cipher_operation_s *ctx = NULL;
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010033 struct cipher_engine_info engine_info;
Jamie Foxefd82732018-11-26 10:34:32 +000034 psa_key_usage_t usage;
Antonio de Angelis8908f472018-08-31 15:44:25 +010035
36 /* Validate pointers */
Antonio de Angelis377a1552018-11-22 17:02:40 +000037 err = tfm_crypto_memory_check(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +010038 sizeof(psa_cipher_operation_t),
39 TFM_MEMORY_ACCESS_RW);
40 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
41 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
42 }
43
44 if (!PSA_ALG_IS_CIPHER(alg)) {
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010045 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
Antonio de Angelis8908f472018-08-31 15:44:25 +010046 }
47
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010048 /* Access the key module to retrieve key related information */
Antonio de Angelis8908f472018-08-31 15:44:25 +010049 err = tfm_crypto_get_key_information(key, &key_type, &key_size);
50 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010051 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
Antonio de Angelis8908f472018-08-31 15:44:25 +010052 }
53
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010054 /* Setup the algorithm on the crypto engine */
55 status = tfm_crypto_engine_cipher_setup(alg,
56 (const psa_key_type_t)key_type,
57 (const uint32_t)key_size,
58 c_mode,
59 &engine_info);
60 if (status != PSA_SUCCESS) {
61 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
Antonio de Angelis8908f472018-08-31 15:44:25 +010062 }
63
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010064 /* Allocate the operation context in the secure world */
Antonio de Angelis377a1552018-11-22 17:02:40 +000065 err = tfm_crypto_operation_alloc(TFM_CRYPTO_CIPHER_OPERATION,
66 &(operation->handle));
Antonio de Angelis8908f472018-08-31 15:44:25 +010067 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
68 return err;
69 }
70
Antonio de Angelis8908f472018-08-31 15:44:25 +010071 /* Look up the corresponding operation context */
72 err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis377a1552018-11-22 17:02:40 +000073 operation->handle,
74 (void **)&ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +010075 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010076 /* Release the operation context */
77 tfm_crypto_operation_release(&(operation->handle));
Antonio de Angelis8908f472018-08-31 15:44:25 +010078 return err;
79 }
80
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010081 /* Set the proper cipher mode (encrypt/decrypt) in the operation context */
82 ctx->cipher_mode = (uint8_t) c_mode;
83
Antonio de Angelis8908f472018-08-31 15:44:25 +010084 /* Bind the algorithm to the cipher operation */
Antonio de Angelis377a1552018-11-22 17:02:40 +000085 ctx->alg = alg;
Antonio de Angelis8908f472018-08-31 15:44:25 +010086
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010087 /* Start the crypto engine */
88 status = tfm_crypto_engine_cipher_start(&(ctx->engine_ctx), &engine_info);
89 if (status != PSA_SUCCESS) {
Antonio de Angelis8908f472018-08-31 15:44:25 +010090 /* Release the operation context */
Antonio de Angelis377a1552018-11-22 17:02:40 +000091 tfm_crypto_operation_release(&(operation->handle));
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010092 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
Antonio de Angelis8908f472018-08-31 15:44:25 +010093 }
94
Jamie Foxefd82732018-11-26 10:34:32 +000095 /* Set the key usage based on the cipher mode */
96 usage = (c_mode == ENGINE_CIPHER_MODE_DECRYPT) ? PSA_KEY_USAGE_DECRYPT
97 : PSA_KEY_USAGE_ENCRYPT;
98
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010099 /* Access the crypto service key module to retrieve key data */
Jamie Foxefd82732018-11-26 10:34:32 +0000100 err = tfm_crypto_get_key(key,
101 usage,
102 alg,
103 key_data,
104 TFM_CRYPTO_MAX_KEY_LENGTH,
105 &key_size);
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100106 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
107 /* Release the operation context */
108 tfm_crypto_operation_release(&(operation->handle));
109 return err;
110 }
111
112 /* Set the key on the engine */
113 status = tfm_crypto_engine_cipher_set_key(&(ctx->engine_ctx),
114 key_data,
115 key_size,
116 &engine_info);
117 if (status != PSA_SUCCESS) {
118 /* Release the operation context */
119 tfm_crypto_operation_release(&(operation->handle));
120 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
121 }
Antonio de Angelis8908f472018-08-31 15:44:25 +0100122
123 /* Bind the key to the cipher operation */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000124 ctx->key = key;
125 ctx->key_set = 1;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100126
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100127 /* Set padding mode on engine in case of CBC */
Antonio de Angelis8908f472018-08-31 15:44:25 +0100128 if ((alg & ~PSA_ALG_BLOCK_CIPHER_PADDING_MASK) == PSA_ALG_CBC_BASE) {
129
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100130 status = tfm_crypto_engine_cipher_set_padding_mode(&(ctx->engine_ctx),
131 &engine_info);
132 if (status != PSA_SUCCESS) {
Antonio de Angelis8908f472018-08-31 15:44:25 +0100133 /* Release the operation context */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000134 tfm_crypto_operation_release(&(operation->handle));
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100135 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100136 }
137 }
138
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100139 /* FIXME: Check based on the algorithm, if we need to have an IV */
140 ctx->iv_required = 1;
141 ctx->block_size = PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type);
142
Antonio de Angelis8908f472018-08-31 15:44:25 +0100143 return TFM_CRYPTO_ERR_PSA_SUCCESS;
144}
145
146/*!
147 * \defgroup public_psa Public functions, PSA
148 *
149 */
150
151/*!@{*/
Antonio de Angelis377a1552018-11-22 17:02:40 +0000152enum tfm_crypto_err_t tfm_crypto_cipher_set_iv(
153 psa_cipher_operation_t *operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100154 const unsigned char *iv,
155 size_t iv_length)
156{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100157 psa_status_t status = PSA_SUCCESS;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100158 enum tfm_crypto_err_t err;
Antonio de Angelis377a1552018-11-22 17:02:40 +0000159 struct tfm_cipher_operation_s *ctx = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100160
161 /* Validate pointers */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000162 err = tfm_crypto_memory_check(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100163 sizeof(psa_cipher_operation_t),
164 TFM_MEMORY_ACCESS_RW);
165 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
166 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
167 }
168 err = tfm_crypto_memory_check((void *)iv, iv_length, TFM_MEMORY_ACCESS_RO);
169 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
170 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
171 }
172
173 /* Look up the corresponding operation context */
174 err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis377a1552018-11-22 17:02:40 +0000175 operation->handle,
176 (void **)&ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100177 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
178 return err;
179 }
180
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100181 if ((iv_length != ctx->block_size) || (iv_length > TFM_CIPHER_IV_MAX_SIZE)){
182 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100183 }
184
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100185 if ((ctx->iv_set == 1) || (ctx->iv_required == 0)) {
186 return TFM_CRYPTO_ERR_PSA_ERROR_BAD_STATE;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100187 }
188
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100189 /* Set the IV on the crypto engine */
190 status = tfm_crypto_engine_cipher_set_iv(&(ctx->engine_ctx),
191 iv,
192 iv_length);
193 if (status != PSA_SUCCESS) {
194 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100195 }
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100196
Antonio de Angelis377a1552018-11-22 17:02:40 +0000197 ctx->iv_set = 1;
198 ctx->iv_size = iv_length;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100199
Antonio de Angelis8908f472018-08-31 15:44:25 +0100200 return TFM_CRYPTO_ERR_PSA_SUCCESS;
201}
202
Antonio de Angelis377a1552018-11-22 17:02:40 +0000203enum tfm_crypto_err_t tfm_crypto_cipher_encrypt_setup(
204 psa_cipher_operation_t *operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100205 psa_key_slot_t key,
206 psa_algorithm_t alg)
207{
Antonio de Angelis377a1552018-11-22 17:02:40 +0000208 return tfm_crypto_cipher_setup(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100209 key,
210 alg,
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100211 ENGINE_CIPHER_MODE_ENCRYPT);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100212}
213
Antonio de Angelis377a1552018-11-22 17:02:40 +0000214enum tfm_crypto_err_t tfm_crypto_cipher_decrypt_setup(
215 psa_cipher_operation_t *operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100216 psa_key_slot_t key,
217 psa_algorithm_t alg)
218{
Antonio de Angelis377a1552018-11-22 17:02:40 +0000219 return tfm_crypto_cipher_setup(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100220 key,
221 alg,
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100222 ENGINE_CIPHER_MODE_DECRYPT);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100223}
224
225enum tfm_crypto_err_t tfm_crypto_cipher_update(
Antonio de Angelis377a1552018-11-22 17:02:40 +0000226 psa_cipher_operation_t *operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100227 const uint8_t *input,
228 size_t input_length,
229 unsigned char *output,
230 size_t output_size,
231 size_t *output_length)
232{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100233 psa_status_t status = PSA_SUCCESS;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100234 enum tfm_crypto_err_t err;
Antonio de Angelis377a1552018-11-22 17:02:40 +0000235 struct tfm_cipher_operation_s *ctx = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100236
237 /* Validate pointers */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000238 err = tfm_crypto_memory_check(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100239 sizeof(psa_cipher_operation_t),
240 TFM_MEMORY_ACCESS_RW);
241 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
242 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
243 }
244 err = tfm_crypto_memory_check((void *)input,
245 input_length,
246 TFM_MEMORY_ACCESS_RO);
247 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
248 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
249 }
250 err = tfm_crypto_memory_check(output,
251 output_size,
252 TFM_MEMORY_ACCESS_RW);
253 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
254 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
255 }
256 err = tfm_crypto_memory_check(output_length,
257 sizeof(size_t),
258 TFM_MEMORY_ACCESS_RW);
259 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
260 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
261 }
262
263 /* Look up the corresponding operation context */
264 err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis377a1552018-11-22 17:02:40 +0000265 operation->handle,
266 (void **)&ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100267 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
268 return err;
269 }
270
271 /* If the IV is required and it's not been set yet */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000272 if ((ctx->iv_required == 1) && (ctx->iv_set == 0)) {
Antonio de Angelis8908f472018-08-31 15:44:25 +0100273
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100274 if (ctx->cipher_mode != ENGINE_CIPHER_MODE_DECRYPT) {
Antonio de Angelis8908f472018-08-31 15:44:25 +0100275 return TFM_CRYPTO_ERR_PSA_ERROR_BAD_STATE;
276 }
277
278 /* This call is used to set the IV on the object */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000279 err = tfm_crypto_cipher_set_iv(operation, input, input_length);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100280
281 *output_length = 0;
282
283 return err;
284 }
285
286 /* If the key is not set, setup phase has not been completed */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000287 if (ctx->key_set == 0) {
Antonio de Angelis8908f472018-08-31 15:44:25 +0100288 return TFM_CRYPTO_ERR_PSA_ERROR_BAD_STATE;
289 }
290
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100291 /* Update the cipher output with the input chunk on the engine */
292 status = tfm_crypto_engine_cipher_update(&(ctx->engine_ctx),
293 input,
294 input_length,
295 output,
296 (uint32_t *)output_length);
297 if (status != PSA_SUCCESS) {
298 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100299 }
300
Antonio de Angelis8908f472018-08-31 15:44:25 +0100301 return TFM_CRYPTO_ERR_PSA_SUCCESS;
302}
303
304enum tfm_crypto_err_t tfm_crypto_cipher_finish(
Antonio de Angelis377a1552018-11-22 17:02:40 +0000305 psa_cipher_operation_t *operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100306 uint8_t *output,
307 size_t output_size,
308 size_t *output_length)
309{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100310 psa_status_t status = PSA_SUCCESS;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100311 enum tfm_crypto_err_t err;
Antonio de Angelis377a1552018-11-22 17:02:40 +0000312 struct tfm_cipher_operation_s *ctx = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100313
314 /* Validate pointers */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000315 err = tfm_crypto_memory_check(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100316 sizeof(psa_cipher_operation_t),
317 TFM_MEMORY_ACCESS_RW);
318 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
319 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
320 }
321 err = tfm_crypto_memory_check(output,
322 output_size,
323 TFM_MEMORY_ACCESS_RW);
324 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
325 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
326 }
327 err = tfm_crypto_memory_check(output_length,
328 sizeof(size_t),
329 TFM_MEMORY_ACCESS_RW);
330 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
331 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
332 }
333
Antonio de Angelis8908f472018-08-31 15:44:25 +0100334 /* Look up the corresponding operation context */
335 err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis377a1552018-11-22 17:02:40 +0000336 operation->handle,
337 (void **)&ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100338 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
339 return err;
340 }
341
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100342 /* Finalise the operation on the crypto engine */
343 status = tfm_crypto_engine_cipher_finish(&(ctx->engine_ctx),
344 output,
345 (uint32_t *)output_length);
346 if (status != PSA_SUCCESS) {
347 *output_length = 0;
348 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100349 }
350
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100351 /* Release resources on the crypto engine */
352 status = tfm_crypto_engine_cipher_release(&(ctx->engine_ctx));
353 if (status != PSA_SUCCESS) {
354 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
355 }
Antonio de Angelis8908f472018-08-31 15:44:25 +0100356
357 /* Release the operation context */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000358 err = tfm_crypto_operation_release(&(operation->handle));
Antonio de Angelis8908f472018-08-31 15:44:25 +0100359 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
360 return err;
361 }
362
363 return TFM_CRYPTO_ERR_PSA_SUCCESS;
364}
365
Antonio de Angelis377a1552018-11-22 17:02:40 +0000366enum tfm_crypto_err_t tfm_crypto_cipher_abort(psa_cipher_operation_t *operation)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100367{
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100368 psa_status_t status = PSA_SUCCESS;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100369 enum tfm_crypto_err_t err;
Antonio de Angelis377a1552018-11-22 17:02:40 +0000370 struct tfm_cipher_operation_s *ctx = NULL;
Antonio de Angelis8908f472018-08-31 15:44:25 +0100371
372 /* Validate pointers */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000373 err = tfm_crypto_memory_check(operation,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100374 sizeof(psa_cipher_operation_t),
375 TFM_MEMORY_ACCESS_RW);
376 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
377 return TFM_CRYPTO_ERR_PSA_ERROR_INVALID_ARGUMENT;
378 }
379
380 /* Look up the corresponding operation context */
381 err = tfm_crypto_operation_lookup(TFM_CRYPTO_CIPHER_OPERATION,
Antonio de Angelis377a1552018-11-22 17:02:40 +0000382 operation->handle,
383 (void **)&ctx);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100384 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
385 return err;
386 }
387
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100388 /* Release resources on the engine */
389 status = tfm_crypto_engine_cipher_release(&(ctx->engine_ctx));
390 if (status != PSA_SUCCESS) {
391 return PSA_STATUS_TO_TFM_CRYPTO_ERR(status);
392 }
Antonio de Angelis8908f472018-08-31 15:44:25 +0100393
394 /* Release the operation context */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000395 err = tfm_crypto_operation_release(&(operation->handle));
Antonio de Angelis8908f472018-08-31 15:44:25 +0100396 if (err != TFM_CRYPTO_ERR_PSA_SUCCESS) {
397 return err;
398 }
399
400 return TFM_CRYPTO_ERR_PSA_SUCCESS;
401}
402/*!@}*/