blob: dea9cb5885e2854e0a8e003732d50e70a49dd174 [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
528 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200529 if( operation->ctx != NULL || operation->id != 0 )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200530 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200531
532 switch( location )
533 {
534 case PSA_KEY_LOCATION_LOCAL_STORAGE:
535 /* Key is stored in the slot in export representation, so
536 * cycle through all known transparent accelerators */
537#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200538 operation->ctx = mbedtls_calloc( 1, sizeof(test_transparent_cipher_operation_t) );
539 if( operation->ctx == NULL )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200540 return PSA_ERROR_INSUFFICIENT_MEMORY;
541
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200542 status = test_transparent_cipher_encrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200543 &attributes,
544 slot->data.key.data,
545 slot->data.key.bytes,
546 alg );
547 /* Declared with fallback == true */
548 if( status != PSA_ERROR_NOT_SUPPORTED )
549 {
550 if( status == PSA_SUCCESS )
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200551 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200552 else
553 {
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200554 mbedtls_free( operation->ctx );
555 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200556 }
557
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200558 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200559 }
560 else
561 {
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200562 mbedtls_free( operation->ctx );
563 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200564 }
565#endif /* PSA_CRYPTO_DRIVER_TEST */
566 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200567 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200568 /* Add cases for opaque driver here */
569#if defined(PSA_CRYPTO_DRIVER_TEST)
570 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200571 operation->ctx = mbedtls_calloc( 1, sizeof(test_opaque_cipher_operation_t) );
572 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200573 return( PSA_ERROR_INSUFFICIENT_MEMORY );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200574
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200575 status = test_opaque_cipher_encrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200576 &attributes,
577 slot->data.key.data,
578 slot->data.key.bytes,
579 alg );
580 if( status == PSA_SUCCESS )
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200581 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200582 else
583 {
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200584 mbedtls_free( operation->ctx );
585 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200586 }
587
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200588 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200589#endif /* PSA_CRYPTO_DRIVER_TEST */
590 default:
591 /* Key is declared with a lifetime not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200592 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200593 }
594#else /* PSA_CRYPTO_DRIVER_PRESENT */
595 (void)slot;
596 (void)alg;
597 (void)operation;
598
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200599 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200600#endif /* PSA_CRYPTO_DRIVER_PRESENT */
601}
602
603psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200604 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200605 psa_key_slot_t *slot,
606 psa_algorithm_t alg )
607{
608#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
609 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
610 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
611 psa_key_attributes_t attributes = {
612 .core = slot->attr
613 };
614
615 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200616 if( operation->ctx != NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200617 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200618
619 switch( location )
620 {
621 case PSA_KEY_LOCATION_LOCAL_STORAGE:
622 /* Key is stored in the slot in export representation, so
623 * cycle through all known transparent accelerators */
624#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200625 operation->ctx = mbedtls_calloc( 1, sizeof(test_transparent_cipher_operation_t) );
626 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200627 return( PSA_ERROR_INSUFFICIENT_MEMORY );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200628
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200629 status = test_transparent_cipher_decrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200630 &attributes,
631 slot->data.key.data,
632 slot->data.key.bytes,
633 alg );
634 /* Declared with fallback == true */
635 if( status != PSA_ERROR_NOT_SUPPORTED )
636 {
637 if( status == PSA_SUCCESS )
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200638 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200639 else
640 {
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200641 mbedtls_free( operation->ctx );
642 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200643 }
644
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200645 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200646 }
647 else
648 {
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200649 mbedtls_free( operation->ctx );
650 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200651 }
652#endif /* PSA_CRYPTO_DRIVER_TEST */
653 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200654 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200655 /* Add cases for opaque driver here */
656#if defined(PSA_CRYPTO_DRIVER_TEST)
657 case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200658 operation->ctx = mbedtls_calloc( 1, sizeof(test_opaque_cipher_operation_t) );
659 if( operation->ctx == NULL )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200660 return PSA_ERROR_INSUFFICIENT_MEMORY;
661
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200662 status = test_opaque_cipher_decrypt_setup( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200663 &attributes,
664 slot->data.key.data,
665 slot->data.key.bytes,
666 alg );
667 if( status == PSA_SUCCESS )
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200668 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200669 else
670 {
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200671 mbedtls_free( operation->ctx );
672 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200673 }
674
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200675 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200676#endif /* PSA_CRYPTO_DRIVER_TEST */
677 default:
678 /* Key is declared with a lifetime not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200679 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200680 }
681#else /* PSA_CRYPTO_DRIVER_PRESENT */
682 (void)slot;
683 (void)alg;
684 (void)operation;
685
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200686 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200687#endif /* PSA_CRYPTO_DRIVER_PRESENT */
688}
689
690psa_status_t psa_driver_wrapper_cipher_generate_iv(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200691 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200692 uint8_t *iv,
693 size_t iv_size,
694 size_t *iv_length )
695{
696#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
697 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200698 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200699 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200700
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200701 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200702 {
703#if defined(PSA_CRYPTO_DRIVER_TEST)
704 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200705 return( test_transparent_cipher_generate_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200706 iv,
707 iv_size,
708 iv_length ) );
709#endif /* PSA_CRYPTO_DRIVER_TEST */
710#if defined(PSA_CRYPTO_DRIVER_TEST)
711 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200712 return( test_opaque_cipher_generate_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200713 iv,
714 iv_size,
715 iv_length ) );
716#endif /* PSA_CRYPTO_DRIVER_TEST */
717 default:
718 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200719 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200720 }
721#else /* PSA_CRYPTO_DRIVER_PRESENT */
722 (void) operation;
723 (void) iv;
724 (void) iv_size;
725 (void) iv_length;
726
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200727 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200728#endif /* PSA_CRYPTO_DRIVER_PRESENT */
729}
730
731psa_status_t psa_driver_wrapper_cipher_set_iv(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200732 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200733 const uint8_t *iv,
734 size_t iv_length )
735{
736#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
737 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200738 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200739 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200740
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200741 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200742 {
743#if defined(PSA_CRYPTO_DRIVER_TEST)
744 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200745 return( test_transparent_cipher_set_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200746 iv,
747 iv_length ) );
748#endif /* PSA_CRYPTO_DRIVER_TEST */
749#if defined(PSA_CRYPTO_DRIVER_TEST)
750 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200751 return( test_opaque_cipher_set_iv( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200752 iv,
753 iv_length ) );
754#endif /* PSA_CRYPTO_DRIVER_TEST */
755 default:
756 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200757 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200758 }
759#else /* PSA_CRYPTO_DRIVER_PRESENT */
760 (void) operation;
761 (void) iv;
762 (void) iv_length;
763
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200764 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200765#endif /* PSA_CRYPTO_DRIVER_PRESENT */
766}
767
768psa_status_t psa_driver_wrapper_cipher_update(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200769 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200770 const uint8_t *input,
771 size_t input_length,
772 uint8_t *output,
773 size_t output_size,
774 size_t *output_length )
775{
776#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
777 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200778 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200779 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200780
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200781 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200782 {
783#if defined(PSA_CRYPTO_DRIVER_TEST)
784 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200785 return( test_transparent_cipher_update( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200786 input,
787 input_length,
788 output,
789 output_size,
790 output_length ) );
791#endif /* PSA_CRYPTO_DRIVER_TEST */
792#if defined(PSA_CRYPTO_DRIVER_TEST)
793 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200794 return( test_opaque_cipher_update( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200795 input,
796 input_length,
797 output,
798 output_size,
799 output_length ) );
800#endif /* PSA_CRYPTO_DRIVER_TEST */
801 default:
802 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200803 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200804 }
805#else /* PSA_CRYPTO_DRIVER_PRESENT */
806 (void) operation;
807 (void) input;
808 (void) input_length;
809 (void) output;
810 (void) output_length;
811 (void) output_size;
812
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200813 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200814#endif /* PSA_CRYPTO_DRIVER_PRESENT */
815}
816
817psa_status_t psa_driver_wrapper_cipher_finish(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200818 psa_operation_driver_context_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200819 uint8_t *output,
820 size_t output_size,
821 size_t *output_length )
822{
823#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
824 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200825 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200826 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200827
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200828 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200829 {
830#if defined(PSA_CRYPTO_DRIVER_TEST)
831 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200832 return( test_transparent_cipher_finish( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200833 output,
834 output_size,
835 output_length ) );
836#endif /* PSA_CRYPTO_DRIVER_TEST */
837#if defined(PSA_CRYPTO_DRIVER_TEST)
838 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200839 return( test_opaque_cipher_finish( operation->ctx,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200840 output,
841 output_size,
842 output_length ) );
843#endif /* PSA_CRYPTO_DRIVER_TEST */
844 default:
845 /* Key is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200846 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200847 }
848#else /* PSA_CRYPTO_DRIVER_PRESENT */
849 (void) operation;
850 (void) output;
851 (void) output_size;
852 (void) output_length;
853
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200854 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200855#endif /* PSA_CRYPTO_DRIVER_PRESENT */
856}
857
858psa_status_t psa_driver_wrapper_cipher_abort(
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200859 psa_operation_driver_context_t *operation )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200860{
861#if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
862 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
863 /* Check for operation already allocated */
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200864 if( operation->ctx == NULL )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200865 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200866
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200867 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +0200868 {
869#if defined(PSA_CRYPTO_DRIVER_TEST)
870 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200871 status = test_transparent_cipher_abort( operation->ctx );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200872
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200873 mbedtls_free( operation->ctx );
874 operation->ctx = NULL;
875 operation->id = 0;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200876
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200877 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200878#endif /* PSA_CRYPTO_DRIVER_TEST */
879#if defined(PSA_CRYPTO_DRIVER_TEST)
880 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanfb81aa52020-09-09 12:01:43 +0200881 status = test_opaque_cipher_abort( operation->ctx );
882 mbedtls_free( operation->ctx );
883 operation->ctx = NULL;
Steven Cooreman37941cb2020-07-28 18:49:51 +0200884
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200885 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200886#endif /* PSA_CRYPTO_DRIVER_TEST */
887 default:
888 /* Operation is attached to a driver not known to us */
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200889 return( PSA_ERROR_BAD_STATE );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200890 }
891#else /* PSA_CRYPTO_DRIVER_PRESENT */
892 (void)operation;
893
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200894 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200895#endif /* PSA_CRYPTO_DRIVER_PRESENT */
896}
897
Steven Cooremancd84cb42020-07-16 20:28:36 +0200898/* End of automatically generated file. */