blob: d41209bbfb49429fcf0b890f79b77243f97e49e0 [file] [log] [blame]
Steven Cooremancd84cb42020-07-16 20:28:36 +02001/*
2 * Functions to delegate cryptographic operations to an available
3 * and appropriate accelerator.
Steven Cooreman56250fd2020-09-04 13:07:15 +02004 * Warning: This file will be auto-generated in the future.
Steven Cooremancd84cb42020-07-16 20:28:36 +02005 */
Steven Cooreman2c7b2f82020-09-02 13:43:46 +02006/* Copyright The Mbed TLS Contributors
Steven Cooremancd84cb42020-07-16 20:28:36 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Steven Cooremancd84cb42020-07-16 20:28:36 +020020 */
21
22#include "psa_crypto_core.h"
23#include "psa_crypto_driver_wrappers.h"
Steven Cooreman2a1664c2020-07-20 15:33:08 +020024#include "mbedtls/platform.h"
25
26#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS)
Steven Cooremancd84cb42020-07-16 20:28:36 +020027
28/* Include test driver definition when running tests */
Steven Cooremanf1720ea2020-07-24 18:41:58 +020029#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman56250fd2020-09-04 13:07:15 +020030#ifndef PSA_CRYPTO_DRIVER_PRESENT
Steven Cooremanf1720ea2020-07-24 18:41:58 +020031#define PSA_CRYPTO_DRIVER_PRESENT
Steven Cooreman56250fd2020-09-04 13:07:15 +020032#endif
33#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
Steven Cooremanf1720ea2020-07-24 18:41:58 +020034#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
Steven Cooreman56250fd2020-09-04 13:07:15 +020035#endif
Steven Cooreman0d7c64d2020-09-07 16:17:55 +020036#include "test/drivers/test_driver.h"
Steven Cooremanf1720ea2020-07-24 18:41:58 +020037#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooremancd84cb42020-07-16 20:28:36 +020038
Steven Cooreman56250fd2020-09-04 13:07:15 +020039/* Repeat above block for each JSON-declared driver during autogeneration */
40
Steven Cooremanfb81aa52020-09-09 12:01:43 +020041/* Auto-generated values depending on which drivers are registered. ID 0 is
42 * reserved for unallocated operations. */
Steven Cooreman37941cb2020-07-28 18:49:51 +020043#if defined(PSA_CRYPTO_DRIVER_TEST)
44#define PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID (1)
45#define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (2)
46#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman2a1664c2020-07-20 15:33:08 +020047#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */
48
49/* Support the 'old' SE interface when asked to */
Steven Cooreman7a250572020-07-17 16:43:05 +020050#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
Steven Cooreman56250fd2020-09-04 13:07:15 +020051/* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style
52 * SE driver is present, to avoid unused argument errors at compile time. */
53#ifndef PSA_CRYPTO_DRIVER_PRESENT
Steven Cooremanf1720ea2020-07-24 18:41:58 +020054#define PSA_CRYPTO_DRIVER_PRESENT
Steven Cooreman56250fd2020-09-04 13:07:15 +020055#endif
Steven Cooreman7a250572020-07-17 16:43:05 +020056#include "psa_crypto_se.h"
57#endif
58
Steven Cooremancd84cb42020-07-16 20:28:36 +020059/* Start delegation functions */
60psa_status_t psa_driver_wrapper_sign_hash( psa_key_slot_t *slot,
61 psa_algorithm_t alg,
62 const uint8_t *hash,
63 size_t hash_length,
64 uint8_t *signature,
65 size_t signature_size,
66 size_t *signature_length )
67{
Steven Cooremanf1720ea2020-07-24 18:41:58 +020068#if defined(PSA_CRYPTO_DRIVER_PRESENT)
Steven Cooreman7a250572020-07-17 16:43:05 +020069 /* Try dynamically-registered SE interface first */
70#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
71 const psa_drv_se_t *drv;
72 psa_drv_se_context_t *drv_context;
73
74 if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) )
75 {
76 if( drv->asymmetric == NULL ||
77 drv->asymmetric->p_sign == NULL )
78 {
79 /* Key is defined in SE, but we have no way to exercise it */
Steven Cooreman56250fd2020-09-04 13:07:15 +020080 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman7a250572020-07-17 16:43:05 +020081 }
82 return( drv->asymmetric->p_sign( drv_context,
83 slot->data.se.slot_number,
84 alg,
85 hash, hash_length,
86 signature, signature_size,
87 signature_length ) );
88 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +020089#endif /* PSA_CRYPTO_SE_C */
Steven Cooreman7a250572020-07-17 16:43:05 +020090
91 /* Then try accelerator API */
Steven Cooremanf1720ea2020-07-24 18:41:58 +020092#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremancd84cb42020-07-16 20:28:36 +020093 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
94 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
95 psa_key_attributes_t attributes = {
96 .core = slot->attr
97 };
98
99 switch( location )
100 {
101 case PSA_KEY_LOCATION_LOCAL_STORAGE:
102 /* Key is stored in the slot in export representation, so
103 * cycle through all known transparent accelerators */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200104#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremancd84cb42020-07-16 20:28:36 +0200105 status = test_transparent_signature_sign_hash( &attributes,
106 slot->data.key.data,
107 slot->data.key.bytes,
108 alg,
109 hash,
110 hash_length,
111 signature,
112 signature_size,
113 signature_length );
114 /* Declared with fallback == true */
115 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman56250fd2020-09-04 13:07:15 +0200116 return( status );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200117#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooremancd84cb42020-07-16 20:28:36 +0200118 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200119 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremancd84cb42020-07-16 20:28:36 +0200120 /* Add cases for opaque driver here */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200121#if defined(PSA_CRYPTO_DRIVER_TEST)
122 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooremancd84cb42020-07-16 20:28:36 +0200123 return( test_opaque_signature_sign_hash( &attributes,
124 slot->data.key.data,
125 slot->data.key.bytes,
126 alg,
127 hash,
128 hash_length,
129 signature,
130 signature_size,
131 signature_length ) );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200132#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooremancd84cb42020-07-16 20:28:36 +0200133 default:
134 /* Key is declared with a lifetime not known to us */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200135 return( status );
Steven Cooremancd84cb42020-07-16 20:28:36 +0200136 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200137#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200138 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200139#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
140#else /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooremancd84cb42020-07-16 20:28:36 +0200141 (void)slot;
142 (void)alg;
143 (void)hash;
144 (void)hash_length;
145 (void)signature;
146 (void)signature_size;
147 (void)signature_length;
148
Steven Cooreman56250fd2020-09-04 13:07:15 +0200149 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200150#endif /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooremancd84cb42020-07-16 20:28:36 +0200151}
152
Steven Cooreman55ae2172020-07-17 19:46:15 +0200153psa_status_t psa_driver_wrapper_verify_hash( psa_key_slot_t *slot,
154 psa_algorithm_t alg,
155 const uint8_t *hash,
156 size_t hash_length,
157 const uint8_t *signature,
158 size_t signature_length )
159{
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200160#if defined(PSA_CRYPTO_DRIVER_PRESENT)
Steven Cooreman55ae2172020-07-17 19:46:15 +0200161 /* Try dynamically-registered SE interface first */
162#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
163 const psa_drv_se_t *drv;
164 psa_drv_se_context_t *drv_context;
165
166 if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) )
167 {
168 if( drv->asymmetric == NULL ||
169 drv->asymmetric->p_verify == NULL )
170 {
171 /* Key is defined in SE, but we have no way to exercise it */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200172 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200173 }
174 return( drv->asymmetric->p_verify( drv_context,
175 slot->data.se.slot_number,
176 alg,
177 hash, hash_length,
178 signature, signature_length ) );
179 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200180#endif /* PSA_CRYPTO_SE_C */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200181
182 /* Then try accelerator API */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200183#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman55ae2172020-07-17 19:46:15 +0200184 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
185 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
186 psa_key_attributes_t attributes = {
187 .core = slot->attr
188 };
189
190 switch( location )
191 {
192 case PSA_KEY_LOCATION_LOCAL_STORAGE:
193 /* Key is stored in the slot in export representation, so
194 * cycle through all known transparent accelerators */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200195#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman55ae2172020-07-17 19:46:15 +0200196 status = test_transparent_signature_verify_hash( &attributes,
197 slot->data.key.data,
198 slot->data.key.bytes,
199 alg,
200 hash,
201 hash_length,
202 signature,
203 signature_length );
204 /* Declared with fallback == true */
205 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman56250fd2020-09-04 13:07:15 +0200206 return( status );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200207#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200208 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200209 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200210 /* Add cases for opaque driver here */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200211#if defined(PSA_CRYPTO_DRIVER_TEST)
212 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooreman55ae2172020-07-17 19:46:15 +0200213 return( test_opaque_signature_verify_hash( &attributes,
214 slot->data.key.data,
215 slot->data.key.bytes,
216 alg,
217 hash,
218 hash_length,
219 signature,
220 signature_length ) );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200221#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200222 default:
223 /* Key is declared with a lifetime not known to us */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200224 return( status );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200225 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200226#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200227 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200228#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
229#else /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200230 (void)slot;
231 (void)alg;
232 (void)hash;
233 (void)hash_length;
234 (void)signature;
235 (void)signature_length;
236
Steven Cooreman56250fd2020-09-04 13:07:15 +0200237 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200238#endif /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200239}
240
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200241#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman56250fd2020-09-04 13:07:15 +0200242/** Calculate the size to allocate for buffering a key with given attributes.
243 *
244 * This function provides a way to get the expected size for storing a key with
245 * the given attributes. This will be the size of the export representation for
246 * cleartext keys, and a driver-defined size for keys stored by opaque drivers.
247 *
248 * \param[in] attributes The key attribute structure of the key to store.
249 * \param[out] expected_size On success, a byte size large enough to contain
250 * the declared key.
251 *
252 * \retval #PSA_SUCCESS
253 * \retval #PSA_ERROR_NOT_SUPPORTED
254 */
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200255static psa_status_t get_expected_key_size( const psa_key_attributes_t *attributes,
256 size_t *expected_size )
257{
Steven Cooreman56250fd2020-09-04 13:07:15 +0200258 size_t buffer_size = 0;
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200259 if( PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ) == PSA_KEY_LOCATION_LOCAL_STORAGE )
260 {
Steven Cooreman56250fd2020-09-04 13:07:15 +0200261 buffer_size = PSA_KEY_EXPORT_MAX_SIZE( attributes->core.type,
262 attributes->core.bits );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200263
Steven Cooreman56250fd2020-09-04 13:07:15 +0200264 if( buffer_size == 0 )
265 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200266
Steven Cooreman56250fd2020-09-04 13:07:15 +0200267 *expected_size = buffer_size;
268 return( PSA_SUCCESS );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200269 }
270 else
271 {
Steven Cooreman56250fd2020-09-04 13:07:15 +0200272 /* TBD: opaque driver support: need to calculate size through a
273 * driver-defined size function, since the size of an opaque (wrapped)
274 * key will be different for each implementation. */
275 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200276 }
277}
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200278#endif /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200279
Steven Cooreman55ae2172020-07-17 19:46:15 +0200280psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes,
281 psa_key_slot_t *slot )
282{
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200283#if defined(PSA_CRYPTO_DRIVER_PRESENT)
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200284 /* Try dynamically-registered SE interface first */
285#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
286 const psa_drv_se_t *drv;
287 psa_drv_se_context_t *drv_context;
288
289 if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) )
290 {
291 size_t pubkey_length = 0; /* We don't support this feature yet */
292 if( drv->key_management == NULL ||
293 drv->key_management->p_generate == NULL )
294 {
295 /* Key is defined as being in SE, but we have no way to generate it */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200296 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200297 }
298 return( drv->key_management->p_generate(
299 drv_context,
300 slot->data.se.slot_number, attributes,
301 NULL, 0, &pubkey_length ) );
302 }
303#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
304
305 /* Then try accelerator API */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200306#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200307 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
308 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
309 size_t export_size = 0;
310
311 status = get_expected_key_size( attributes, &export_size );
312 if( status != PSA_SUCCESS )
Steven Cooreman56250fd2020-09-04 13:07:15 +0200313 return( status );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200314
315 slot->data.key.data = mbedtls_calloc(1, export_size);
316 if( slot->data.key.data == NULL )
Steven Cooreman56250fd2020-09-04 13:07:15 +0200317 return( PSA_ERROR_INSUFFICIENT_MEMORY );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200318 slot->data.key.bytes = export_size;
319
320 switch( location )
321 {
322 case PSA_KEY_LOCATION_LOCAL_STORAGE:
323 /* Key is stored in the slot in export representation, so
324 * cycle through all known transparent accelerators */
325
326 /* Transparent drivers are limited to generating asymmetric keys */
327 if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( slot->attr.type ) )
328 {
329 status = PSA_ERROR_NOT_SUPPORTED;
330 break;
331 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200332#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200333 status = test_transparent_generate_key( attributes,
334 slot->data.key.data,
335 slot->data.key.bytes,
336 &slot->data.key.bytes );
337 /* Declared with fallback == true */
338 if( status != PSA_ERROR_NOT_SUPPORTED )
339 break;
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200340#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200341 /* Fell through, meaning no accelerator supports this operation */
342 status = PSA_ERROR_NOT_SUPPORTED;
343 break;
344 /* Add cases for opaque driver here */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200345#if defined(PSA_CRYPTO_DRIVER_TEST)
346 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200347 status = test_opaque_generate_key( attributes,
348 slot->data.key.data,
349 slot->data.key.bytes,
350 &slot->data.key.bytes );
351 break;
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200352#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200353 default:
354 /* Key is declared with a lifetime not known to us */
355 status = PSA_ERROR_INVALID_ARGUMENT;
356 break;
357 }
358
359 if( status != PSA_SUCCESS )
360 {
361 /* free allocated buffer */
362 mbedtls_free( slot->data.key.data );
363 slot->data.key.data = NULL;
364 slot->data.key.bytes = 0;
365 }
366
367 return( status );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200368#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200369 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200370#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
371#else /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200372 (void) attributes;
373 (void) slot;
374
Steven Cooreman56250fd2020-09-04 13:07:15 +0200375 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200376#endif /* PSA_CRYPTO_DRIVER_PRESENT */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200377}
378
Steven Cooreman37941cb2020-07-28 18:49:51 +0200379/*
380 * Cipher functions
381 */
382psa_status_t psa_driver_wrapper_cipher_encrypt(
383 psa_key_slot_t *slot,
384 psa_algorithm_t alg,
385 const uint8_t *input,
386 size_t input_length,
387 uint8_t *output,
388 size_t output_size,
389 size_t *output_length )
390{
391#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
392 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
393 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
394 psa_key_attributes_t attributes = {
395 .core = slot->attr
396 };
397
398 switch( location )
399 {
400 case PSA_KEY_LOCATION_LOCAL_STORAGE:
401 /* Key is stored in the slot in export representation, so
402 * cycle through all known transparent accelerators */
403#if defined(PSA_CRYPTO_DRIVER_TEST)
404 status = test_transparent_cipher_encrypt( &attributes,
405 slot->data.key.data,
406 slot->data.key.bytes,
407 alg,
408 input,
409 input_length,
410 output,
411 output_size,
412 output_length );
413 /* Declared with fallback == true */
414 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200415 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200416#endif /* PSA_CRYPTO_DRIVER_TEST */
417 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200418 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200419 /* Add cases for opaque driver here */
420#if defined(PSA_CRYPTO_DRIVER_TEST)
421 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
422 return( test_opaque_cipher_encrypt( &attributes,
423 slot->data.key.data,
424 slot->data.key.bytes,
425 alg,
426 input,
427 input_length,
428 output,
429 output_size,
430 output_length ) );
431#endif /* PSA_CRYPTO_DRIVER_TEST */
432 default:
433 /* Key is declared with a lifetime not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200434 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200435 }
436#else /* PSA_CRYPTO_DRIVER_PRESENT */
437 (void) slot;
438 (void) alg;
439 (void) input;
440 (void) input_length;
441 (void) output;
442 (void) output_size;
443 (void) output_length;
444
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200445 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200446#endif /* PSA_CRYPTO_DRIVER_PRESENT */
447}
448
449psa_status_t psa_driver_wrapper_cipher_decrypt(
450 psa_key_slot_t *slot,
451 psa_algorithm_t alg,
452 const uint8_t *input,
453 size_t input_length,
454 uint8_t *output,
455 size_t output_size,
456 size_t *output_length )
457{
458#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
459 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
460 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
461 psa_key_attributes_t attributes = {
462 .core = slot->attr
463 };
464
465 switch( location )
466 {
467 case PSA_KEY_LOCATION_LOCAL_STORAGE:
468 /* Key is stored in the slot in export representation, so
469 * cycle through all known transparent accelerators */
470#if defined(PSA_CRYPTO_DRIVER_TEST)
471 status = test_transparent_cipher_decrypt( &attributes,
472 slot->data.key.data,
473 slot->data.key.bytes,
474 alg,
475 input,
476 input_length,
477 output,
478 output_size,
479 output_length );
480 /* Declared with fallback == true */
481 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200482 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200483#endif /* PSA_CRYPTO_DRIVER_TEST */
484 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200485 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200486 /* Add cases for opaque driver here */
487#if defined(PSA_CRYPTO_DRIVER_TEST)
488 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
489 return( test_opaque_cipher_decrypt( &attributes,
490 slot->data.key.data,
491 slot->data.key.bytes,
492 alg,
493 input,
494 input_length,
495 output,
496 output_size,
497 output_length ) );
498#endif /* PSA_CRYPTO_DRIVER_TEST */
499 default:
500 /* Key is declared with a lifetime not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200501 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200502 }
503#else /* PSA_CRYPTO_DRIVER_PRESENT */
504 (void) slot;
505 (void) alg;
506 (void) input;
507 (void) input_length;
508 (void) output;
509 (void) output_size;
510 (void) output_length;
511
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200512 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200513#endif /* PSA_CRYPTO_DRIVER_PRESENT */
514}
515
516psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200517 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200518 psa_key_slot_t *slot,
519 psa_algorithm_t alg )
520{
521#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
522 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
523 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
524 psa_key_attributes_t attributes = {
525 .core = slot->attr
526 };
527
Steven Cooreman37941cb2020-07-28 18:49:51 +0200528 switch( location )
529 {
530 case PSA_KEY_LOCATION_LOCAL_STORAGE:
531 /* Key is stored in the slot in export representation, so
532 * cycle through all known transparent accelerators */
533#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200534 operation->ctx = mbedtls_calloc( 1, sizeof(test_transparent_cipher_operation_t) );
535 if( operation->ctx == NULL )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200536 return PSA_ERROR_INSUFFICIENT_MEMORY;
537
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200538 status = test_transparent_cipher_encrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200539 &attributes,
540 slot->data.key.data,
541 slot->data.key.bytes,
542 alg );
543 /* Declared with fallback == true */
Steven Cooreman150c99b2020-09-09 14:32:44 +0200544 if( status == PSA_SUCCESS )
545 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200546 else
547 {
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200548 mbedtls_platform_zeroize(
549 operation->ctx,
550 sizeof( test_transparent_cipher_operation_t ) );
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200551 mbedtls_free( operation->ctx );
552 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200553 }
Steven Cooreman150c99b2020-09-09 14:32:44 +0200554
555 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200556#endif /* PSA_CRYPTO_DRIVER_TEST */
557 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200558 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200559 /* Add cases for opaque driver here */
560#if defined(PSA_CRYPTO_DRIVER_TEST)
561 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200562 operation->ctx = mbedtls_calloc( 1, sizeof(test_opaque_cipher_operation_t) );
563 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200564 return( PSA_ERROR_INSUFFICIENT_MEMORY );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200565
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200566 status = test_opaque_cipher_encrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200567 &attributes,
568 slot->data.key.data,
569 slot->data.key.bytes,
570 alg );
571 if( status == PSA_SUCCESS )
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200572 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200573 else
574 {
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200575 mbedtls_platform_zeroize(
576 operation->ctx,
577 sizeof( test_opaque_cipher_operation_t ) );
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200578 mbedtls_free( operation->ctx );
579 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200580 }
581
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200582 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200583#endif /* PSA_CRYPTO_DRIVER_TEST */
584 default:
585 /* Key is declared with a lifetime not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200586 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200587 }
588#else /* PSA_CRYPTO_DRIVER_PRESENT */
589 (void)slot;
590 (void)alg;
591 (void)operation;
592
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200593 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200594#endif /* PSA_CRYPTO_DRIVER_PRESENT */
595}
596
597psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200598 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200599 psa_key_slot_t *slot,
600 psa_algorithm_t alg )
601{
602#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
603 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
604 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
605 psa_key_attributes_t attributes = {
606 .core = slot->attr
607 };
608
Steven Cooreman37941cb2020-07-28 18:49:51 +0200609 switch( location )
610 {
611 case PSA_KEY_LOCATION_LOCAL_STORAGE:
612 /* Key is stored in the slot in export representation, so
613 * cycle through all known transparent accelerators */
614#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200615 operation->ctx = mbedtls_calloc( 1, sizeof(test_transparent_cipher_operation_t) );
616 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200617 return( PSA_ERROR_INSUFFICIENT_MEMORY );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200618
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200619 status = test_transparent_cipher_decrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200620 &attributes,
621 slot->data.key.data,
622 slot->data.key.bytes,
623 alg );
624 /* Declared with fallback == true */
Steven Cooreman150c99b2020-09-09 14:32:44 +0200625 if( status == PSA_SUCCESS )
626 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200627 else
628 {
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200629 mbedtls_platform_zeroize(
630 operation->ctx,
631 sizeof( test_transparent_cipher_operation_t ) );
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200632 mbedtls_free( operation->ctx );
633 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200634 }
Steven Cooreman150c99b2020-09-09 14:32:44 +0200635
636 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200637#endif /* PSA_CRYPTO_DRIVER_TEST */
638 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200639 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200640 /* Add cases for opaque driver here */
641#if defined(PSA_CRYPTO_DRIVER_TEST)
642 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200643 operation->ctx = mbedtls_calloc( 1, sizeof(test_opaque_cipher_operation_t) );
644 if( operation->ctx == NULL )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200645 return PSA_ERROR_INSUFFICIENT_MEMORY;
646
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200647 status = test_opaque_cipher_decrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200648 &attributes,
649 slot->data.key.data,
650 slot->data.key.bytes,
651 alg );
652 if( status == PSA_SUCCESS )
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200653 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200654 else
655 {
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200656 mbedtls_platform_zeroize(
657 operation->ctx,
658 sizeof( test_opaque_cipher_operation_t ) );
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200659 mbedtls_free( operation->ctx );
660 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200661 }
662
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200663 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200664#endif /* PSA_CRYPTO_DRIVER_TEST */
665 default:
666 /* Key is declared with a lifetime not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200667 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200668 }
669#else /* PSA_CRYPTO_DRIVER_PRESENT */
670 (void)slot;
671 (void)alg;
672 (void)operation;
673
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200674 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200675#endif /* PSA_CRYPTO_DRIVER_PRESENT */
676}
677
678psa_status_t psa_driver_wrapper_cipher_generate_iv(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200679 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200680 uint8_t *iv,
681 size_t iv_size,
682 size_t *iv_length )
683{
684#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200685 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200686 {
687#if defined(PSA_CRYPTO_DRIVER_TEST)
688 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200689 return( test_transparent_cipher_generate_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200690 iv,
691 iv_size,
692 iv_length ) );
693#endif /* PSA_CRYPTO_DRIVER_TEST */
694#if defined(PSA_CRYPTO_DRIVER_TEST)
695 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200696 return( test_opaque_cipher_generate_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200697 iv,
698 iv_size,
699 iv_length ) );
700#endif /* PSA_CRYPTO_DRIVER_TEST */
701 default:
702 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200703 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200704 }
705#else /* PSA_CRYPTO_DRIVER_PRESENT */
706 (void) operation;
707 (void) iv;
708 (void) iv_size;
709 (void) iv_length;
710
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200711 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200712#endif /* PSA_CRYPTO_DRIVER_PRESENT */
713}
714
715psa_status_t psa_driver_wrapper_cipher_set_iv(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200716 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200717 const uint8_t *iv,
718 size_t iv_length )
719{
720#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200721 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200722 {
723#if defined(PSA_CRYPTO_DRIVER_TEST)
724 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200725 return( test_transparent_cipher_set_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200726 iv,
727 iv_length ) );
728#endif /* PSA_CRYPTO_DRIVER_TEST */
729#if defined(PSA_CRYPTO_DRIVER_TEST)
730 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200731 return( test_opaque_cipher_set_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200732 iv,
733 iv_length ) );
734#endif /* PSA_CRYPTO_DRIVER_TEST */
735 default:
736 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200737 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200738 }
739#else /* PSA_CRYPTO_DRIVER_PRESENT */
740 (void) operation;
741 (void) iv;
742 (void) iv_length;
743
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200744 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200745#endif /* PSA_CRYPTO_DRIVER_PRESENT */
746}
747
748psa_status_t psa_driver_wrapper_cipher_update(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200749 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200750 const uint8_t *input,
751 size_t input_length,
752 uint8_t *output,
753 size_t output_size,
754 size_t *output_length )
755{
756#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200757 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200758 {
759#if defined(PSA_CRYPTO_DRIVER_TEST)
760 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200761 return( test_transparent_cipher_update( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200762 input,
763 input_length,
764 output,
765 output_size,
766 output_length ) );
767#endif /* PSA_CRYPTO_DRIVER_TEST */
768#if defined(PSA_CRYPTO_DRIVER_TEST)
769 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200770 return( test_opaque_cipher_update( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200771 input,
772 input_length,
773 output,
774 output_size,
775 output_length ) );
776#endif /* PSA_CRYPTO_DRIVER_TEST */
777 default:
778 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200779 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200780 }
781#else /* PSA_CRYPTO_DRIVER_PRESENT */
782 (void) operation;
783 (void) input;
784 (void) input_length;
785 (void) output;
786 (void) output_length;
787 (void) output_size;
788
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200789 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200790#endif /* PSA_CRYPTO_DRIVER_PRESENT */
791}
792
793psa_status_t psa_driver_wrapper_cipher_finish(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200794 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200795 uint8_t *output,
796 size_t output_size,
797 size_t *output_length )
798{
799#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200800 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200801 {
802#if defined(PSA_CRYPTO_DRIVER_TEST)
803 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200804 return( test_transparent_cipher_finish( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200805 output,
806 output_size,
807 output_length ) );
808#endif /* PSA_CRYPTO_DRIVER_TEST */
809#if defined(PSA_CRYPTO_DRIVER_TEST)
810 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200811 return( test_opaque_cipher_finish( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200812 output,
813 output_size,
814 output_length ) );
815#endif /* PSA_CRYPTO_DRIVER_TEST */
816 default:
817 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200818 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200819 }
820#else /* PSA_CRYPTO_DRIVER_PRESENT */
821 (void) operation;
822 (void) output;
823 (void) output_size;
824 (void) output_length;
825
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200826 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200827#endif /* PSA_CRYPTO_DRIVER_PRESENT */
828}
829
830psa_status_t psa_driver_wrapper_cipher_abort(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200831 psa_operation_driver_context_t *operation )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200832{
833#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
834 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200835
836 /* The object has (apparently) been initialized but it is not in use. It's
837 * ok to call abort on such an object, and there's nothing to do. */
838 if( operation->ctx == NULL && operation->id == 0 )
839 return( PSA_SUCCESS );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200840
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200841 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200842 {
843#if defined(PSA_CRYPTO_DRIVER_TEST)
844 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200845 status = test_transparent_cipher_abort( operation->ctx );
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200846 mbedtls_platform_zeroize(
847 operation->ctx,
848 sizeof( test_transparent_cipher_operation_t ) );
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200849 mbedtls_free( operation->ctx );
850 operation->ctx = NULL;
851 operation->id = 0;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200852
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200853 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200854#endif /* PSA_CRYPTO_DRIVER_TEST */
855#if defined(PSA_CRYPTO_DRIVER_TEST)
856 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200857 status = test_opaque_cipher_abort( operation->ctx );
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200858 mbedtls_platform_zeroize(
859 operation->ctx,
860 sizeof( test_opaque_cipher_operation_t ) );
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200861 mbedtls_free( operation->ctx );
862 operation->ctx = NULL;
Steven Cooremancfeea8f2020-09-09 15:09:18 +0200863 operation->id = 0;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200864
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200865 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200866#endif /* PSA_CRYPTO_DRIVER_TEST */
867 default:
868 /* Operation is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200869 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200870 }
871#else /* PSA_CRYPTO_DRIVER_PRESENT */
872 (void)operation;
873
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200874 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200875#endif /* PSA_CRYPTO_DRIVER_PRESENT */
876}
877
Steven Cooremancd84cb42020-07-16 20:28:36 +0200878/* End of automatically generated file. */