blob: 8d86478624cbf7a212caf6dfff8f90ef45c76c6a [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
Mateusz Starzyk2c09c9b2021-05-14 22:20:10 +020022#include "common.h"
Ronald Cronde822812021-03-17 16:08:20 +010023#include "psa_crypto_aead.h"
Ronald Cron0b805592020-12-14 18:08:20 +010024#include "psa_crypto_cipher.h"
Steven Cooremancd84cb42020-07-16 20:28:36 +020025#include "psa_crypto_core.h"
26#include "psa_crypto_driver_wrappers.h"
Steven Cooreman830aff22021-03-09 09:50:44 +010027#include "psa_crypto_hash.h"
Steven Cooremand13a70f2021-03-19 15:24:23 +010028#include "psa_crypto_mac.h"
Steven Cooreman830aff22021-03-09 09:50:44 +010029
Steven Cooreman2a1664c2020-07-20 15:33:08 +020030#include "mbedtls/platform.h"
31
Gilles Peskine1905a242021-04-24 13:19:45 +020032#if defined(MBEDTLS_PSA_CRYPTO_C)
33
Steven Cooreman2a1664c2020-07-20 15:33:08 +020034#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS)
Steven Cooremancd84cb42020-07-16 20:28:36 +020035
36/* Include test driver definition when running tests */
Steven Cooremanf1720ea2020-07-24 18:41:58 +020037#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman56250fd2020-09-04 13:07:15 +020038#ifndef PSA_CRYPTO_DRIVER_PRESENT
Steven Cooremanf1720ea2020-07-24 18:41:58 +020039#define PSA_CRYPTO_DRIVER_PRESENT
Steven Cooreman56250fd2020-09-04 13:07:15 +020040#endif
41#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
Steven Cooremanf1720ea2020-07-24 18:41:58 +020042#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
Steven Cooreman56250fd2020-09-04 13:07:15 +020043#endif
Ronald Cronce1d8d22021-04-30 17:00:34 +020044#include "test/drivers/test_driver.h"
Steven Cooremanf1720ea2020-07-24 18:41:58 +020045#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooremancd84cb42020-07-16 20:28:36 +020046
Steven Cooreman56250fd2020-09-04 13:07:15 +020047/* Repeat above block for each JSON-declared driver during autogeneration */
Steven Cooremanaa87fd02021-03-15 18:54:03 +010048#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */
Steven Cooreman56250fd2020-09-04 13:07:15 +020049
Steven Cooreman1e582352021-02-18 17:24:37 +010050/* Auto-generated values depending on which drivers are registered.
51 * ID 0 is reserved for unallocated operations.
52 * ID 1 is reserved for the Mbed TLS software driver. */
Steven Cooreman830aff22021-03-09 09:50:44 +010053#define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1)
54
Steven Cooreman37941cb2020-07-28 18:49:51 +020055#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman1e582352021-02-18 17:24:37 +010056#define PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID (2)
57#define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (3)
Steven Cooreman37941cb2020-07-28 18:49:51 +020058#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman2a1664c2020-07-20 15:33:08 +020059
60/* Support the 'old' SE interface when asked to */
Steven Cooreman7a250572020-07-17 16:43:05 +020061#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
Steven Cooreman56250fd2020-09-04 13:07:15 +020062/* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style
63 * SE driver is present, to avoid unused argument errors at compile time. */
64#ifndef PSA_CRYPTO_DRIVER_PRESENT
Steven Cooremanf1720ea2020-07-24 18:41:58 +020065#define PSA_CRYPTO_DRIVER_PRESENT
Steven Cooreman56250fd2020-09-04 13:07:15 +020066#endif
Steven Cooreman7a250572020-07-17 16:43:05 +020067#include "psa_crypto_se.h"
68#endif
69
Ronald Cron9ba76912021-04-10 16:57:30 +020070psa_status_t psa_driver_wrapper_init( void )
71{
72 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
73
74#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
75 status = psa_init_all_se_drivers( );
76 if( status != PSA_SUCCESS )
77 return( status );
78#endif
79
80#if defined(PSA_CRYPTO_DRIVER_TEST)
81 status = mbedtls_test_transparent_init( );
82 if( status != PSA_SUCCESS )
83 return( status );
84
85 status = mbedtls_test_opaque_init( );
86 if( status != PSA_SUCCESS )
87 return( status );
88#endif
89
90 (void) status;
91 return( PSA_SUCCESS );
92}
93
94void psa_driver_wrapper_free( void )
95{
96#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
97 /* Unregister all secure element drivers, so that we restart from
98 * a pristine state. */
99 psa_unregister_all_se_drivers( );
100#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
101
102#if defined(PSA_CRYPTO_DRIVER_TEST)
103 mbedtls_test_transparent_free( );
104 mbedtls_test_opaque_free( );
105#endif
106}
107
Steven Cooremancd84cb42020-07-16 20:28:36 +0200108/* Start delegation functions */
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200109psa_status_t psa_driver_wrapper_sign_message(
110 const psa_key_attributes_t *attributes,
111 const uint8_t *key_buffer,
112 size_t key_buffer_size,
113 psa_algorithm_t alg,
114 const uint8_t *input,
115 size_t input_length,
116 uint8_t *signature,
117 size_t signature_size,
118 size_t *signature_length )
119{
120 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200121 psa_key_location_t location =
122 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
123
124 switch( location )
125 {
126 case PSA_KEY_LOCATION_LOCAL_STORAGE:
127 /* Key is stored in the slot in export representation, so
128 * cycle through all known transparent accelerators */
129#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
130#if defined(PSA_CRYPTO_DRIVER_TEST)
131 status = mbedtls_test_transparent_signature_sign_message(
132 attributes,
133 key_buffer,
134 key_buffer_size,
135 alg,
136 input,
137 input_length,
138 signature,
139 signature_size,
140 signature_length );
141 /* Declared with fallback == true */
142 if( status != PSA_ERROR_NOT_SUPPORTED )
143 return( status );
144#endif /* PSA_CRYPTO_DRIVER_TEST */
145#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200146 break;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200147
148 /* Add cases for opaque driver here */
149#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
150#if defined(PSA_CRYPTO_DRIVER_TEST)
gabor-mezei-arm2522c0b2021-04-27 18:52:51 +0200151 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200152 status = mbedtls_test_opaque_signature_sign_message(
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200153 attributes,
154 key_buffer,
155 key_buffer_size,
156 alg,
157 input,
158 input_length,
159 signature,
160 signature_size,
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200161 signature_length );
162 if( status != PSA_ERROR_NOT_SUPPORTED )
163 return( status );
164 break;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200165#endif /* PSA_CRYPTO_DRIVER_TEST */
166#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
167 default:
168 /* Key is declared with a lifetime not known to us */
169 (void)status;
gabor-mezei-armd5218df2021-05-12 11:12:25 +0200170 break;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200171 }
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200172
173 return( psa_sign_message_builtin( attributes,
174 key_buffer,
175 key_buffer_size,
176 alg,
177 input,
178 input_length,
179 signature,
180 signature_size,
181 signature_length ) );
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200182}
183
184psa_status_t psa_driver_wrapper_verify_message(
185 const psa_key_attributes_t *attributes,
186 const uint8_t *key_buffer,
187 size_t key_buffer_size,
188 psa_algorithm_t alg,
189 const uint8_t *input,
190 size_t input_length,
191 const uint8_t *signature,
192 size_t signature_length )
193{
194 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200195 psa_key_location_t location =
196 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
197
198 switch( location )
199 {
200 case PSA_KEY_LOCATION_LOCAL_STORAGE:
201 /* Key is stored in the slot in export representation, so
202 * cycle through all known transparent accelerators */
203#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
204#if defined(PSA_CRYPTO_DRIVER_TEST)
205 status = mbedtls_test_transparent_signature_verify_message(
206 attributes,
207 key_buffer,
208 key_buffer_size,
209 alg,
210 input,
211 input_length,
212 signature,
213 signature_length );
214 /* Declared with fallback == true */
215 if( status != PSA_ERROR_NOT_SUPPORTED )
216 return( status );
217#endif /* PSA_CRYPTO_DRIVER_TEST */
218#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200219 break;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200220
221 /* Add cases for opaque driver here */
222#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
223#if defined(PSA_CRYPTO_DRIVER_TEST)
gabor-mezei-arm2522c0b2021-04-27 18:52:51 +0200224 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200225 return( mbedtls_test_opaque_signature_verify_message(
226 attributes,
227 key_buffer,
228 key_buffer_size,
229 alg,
230 input,
231 input_length,
232 signature,
233 signature_length ) );
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200234 if( status != PSA_ERROR_NOT_SUPPORTED )
235 return( status );
236 break;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200237#endif /* PSA_CRYPTO_DRIVER_TEST */
238#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
239 default:
240 /* Key is declared with a lifetime not known to us */
241 (void)status;
gabor-mezei-armd5218df2021-05-12 11:12:25 +0200242 break;
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200243 }
gabor-mezei-arm256443e2021-05-07 15:16:34 +0200244
245 return( psa_verify_message_builtin( attributes,
246 key_buffer,
247 key_buffer_size,
248 alg,
249 input,
250 input_length,
251 signature,
252 signature_length ) );
gabor-mezei-arm50eac352021-04-22 11:32:19 +0200253}
254
Ronald Cron9f17aa42020-12-08 17:07:25 +0100255psa_status_t psa_driver_wrapper_sign_hash(
256 const psa_key_attributes_t *attributes,
257 const uint8_t *key_buffer, size_t key_buffer_size,
258 psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
259 uint8_t *signature, size_t signature_size, size_t *signature_length )
Steven Cooremancd84cb42020-07-16 20:28:36 +0200260{
Steven Cooreman7a250572020-07-17 16:43:05 +0200261 /* Try dynamically-registered SE interface first */
262#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
263 const psa_drv_se_t *drv;
264 psa_drv_se_context_t *drv_context;
265
Ronald Cron9f17aa42020-12-08 17:07:25 +0100266 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
Steven Cooreman7a250572020-07-17 16:43:05 +0200267 {
268 if( drv->asymmetric == NULL ||
269 drv->asymmetric->p_sign == NULL )
270 {
271 /* Key is defined in SE, but we have no way to exercise it */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200272 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman7a250572020-07-17 16:43:05 +0200273 }
Ronald Cron9f17aa42020-12-08 17:07:25 +0100274 return( drv->asymmetric->p_sign(
275 drv_context, *( (psa_key_slot_number_t *)key_buffer ),
276 alg, hash, hash_length,
277 signature, signature_size, signature_length ) );
Steven Cooreman7a250572020-07-17 16:43:05 +0200278 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200279#endif /* PSA_CRYPTO_SE_C */
Steven Cooreman7a250572020-07-17 16:43:05 +0200280
Ronald Cronfce9df22020-12-08 18:06:03 +0100281 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Ronald Cron9f17aa42020-12-08 17:07:25 +0100282 psa_key_location_t location =
283 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Steven Cooremancd84cb42020-07-16 20:28:36 +0200284
285 switch( location )
286 {
287 case PSA_KEY_LOCATION_LOCAL_STORAGE:
288 /* Key is stored in the slot in export representation, so
289 * cycle through all known transparent accelerators */
Ronald Cronfce9df22020-12-08 18:06:03 +0100290#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200291#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +0200292 status = mbedtls_test_transparent_signature_sign_hash( attributes,
Ronald Cron9f17aa42020-12-08 17:07:25 +0100293 key_buffer,
294 key_buffer_size,
Steven Cooremancd84cb42020-07-16 20:28:36 +0200295 alg,
296 hash,
297 hash_length,
298 signature,
299 signature_size,
300 signature_length );
301 /* Declared with fallback == true */
302 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman56250fd2020-09-04 13:07:15 +0200303 return( status );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200304#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cronfce9df22020-12-08 18:06:03 +0100305#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooremancd84cb42020-07-16 20:28:36 +0200306 /* Fell through, meaning no accelerator supports this operation */
gabor-mezei-arm6883fd22021-05-05 14:18:36 +0200307 return( psa_sign_hash_builtin( attributes,
308 key_buffer,
309 key_buffer_size,
310 alg,
311 hash,
312 hash_length,
313 signature,
314 signature_size,
315 signature_length ) );
Ronald Cronfce9df22020-12-08 18:06:03 +0100316
Steven Cooremancd84cb42020-07-16 20:28:36 +0200317 /* Add cases for opaque driver here */
Ronald Cronfce9df22020-12-08 18:06:03 +0100318#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200319#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100320 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +0200321 return( mbedtls_test_opaque_signature_sign_hash( attributes,
322 key_buffer,
323 key_buffer_size,
324 alg,
325 hash,
326 hash_length,
327 signature,
328 signature_size,
329 signature_length ) );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200330#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cronfce9df22020-12-08 18:06:03 +0100331#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooremancd84cb42020-07-16 20:28:36 +0200332 default:
333 /* Key is declared with a lifetime not known to us */
Ronald Cronfce9df22020-12-08 18:06:03 +0100334 (void)status;
335 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooremancd84cb42020-07-16 20:28:36 +0200336 }
Steven Cooremancd84cb42020-07-16 20:28:36 +0200337}
338
Ronald Cron9f17aa42020-12-08 17:07:25 +0100339psa_status_t psa_driver_wrapper_verify_hash(
340 const psa_key_attributes_t *attributes,
341 const uint8_t *key_buffer, size_t key_buffer_size,
342 psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
343 const uint8_t *signature, size_t signature_length )
Steven Cooreman55ae2172020-07-17 19:46:15 +0200344{
Steven Cooreman55ae2172020-07-17 19:46:15 +0200345 /* Try dynamically-registered SE interface first */
346#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
347 const psa_drv_se_t *drv;
348 psa_drv_se_context_t *drv_context;
349
Ronald Cron9f17aa42020-12-08 17:07:25 +0100350 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
Steven Cooreman55ae2172020-07-17 19:46:15 +0200351 {
352 if( drv->asymmetric == NULL ||
353 drv->asymmetric->p_verify == NULL )
354 {
355 /* Key is defined in SE, but we have no way to exercise it */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200356 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200357 }
Ronald Cron9f17aa42020-12-08 17:07:25 +0100358 return( drv->asymmetric->p_verify(
359 drv_context, *( (psa_key_slot_number_t *)key_buffer ),
360 alg, hash, hash_length,
361 signature, signature_length ) );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200362 }
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200363#endif /* PSA_CRYPTO_SE_C */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200364
Ronald Cronfce9df22020-12-08 18:06:03 +0100365 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Ronald Cron9f17aa42020-12-08 17:07:25 +0100366 psa_key_location_t location =
367 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200368
369 switch( location )
370 {
371 case PSA_KEY_LOCATION_LOCAL_STORAGE:
372 /* Key is stored in the slot in export representation, so
373 * cycle through all known transparent accelerators */
Ronald Cronfce9df22020-12-08 18:06:03 +0100374#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200375#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +0200376 status = mbedtls_test_transparent_signature_verify_hash(
377 attributes,
378 key_buffer,
379 key_buffer_size,
380 alg,
381 hash,
382 hash_length,
383 signature,
384 signature_length );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200385 /* Declared with fallback == true */
386 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman56250fd2020-09-04 13:07:15 +0200387 return( status );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200388#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cronfce9df22020-12-08 18:06:03 +0100389#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
390
gabor-mezei-arm6883fd22021-05-05 14:18:36 +0200391 return( psa_verify_hash_builtin( attributes,
392 key_buffer,
393 key_buffer_size,
394 alg,
395 hash,
396 hash_length,
397 signature,
398 signature_length ) );
Ronald Cronfce9df22020-12-08 18:06:03 +0100399
Steven Cooreman55ae2172020-07-17 19:46:15 +0200400 /* Add cases for opaque driver here */
Ronald Cronfce9df22020-12-08 18:06:03 +0100401#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200402#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100403 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +0200404 return( mbedtls_test_opaque_signature_verify_hash( attributes,
405 key_buffer,
406 key_buffer_size,
407 alg,
408 hash,
409 hash_length,
410 signature,
411 signature_length ) );
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200412#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cronfce9df22020-12-08 18:06:03 +0100413#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooreman55ae2172020-07-17 19:46:15 +0200414 default:
415 /* Key is declared with a lifetime not known to us */
Ronald Cronfce9df22020-12-08 18:06:03 +0100416 (void)status;
417 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200418 }
Steven Cooreman55ae2172020-07-17 19:46:15 +0200419}
420
Archana449608b2021-09-08 15:36:05 +0530421/** Calculate the key buffer size required to store the key material of a key
Archanad8a83dc2021-06-14 10:04:16 +0530422 * associated with an opaque driver from input key data.
423 *
Archanad8a83dc2021-06-14 10:04:16 +0530424 * \param[in] attributes The key attributes
425 * \param[in] data The input key data.
426 * \param[in] data_length The input data length.
427 * \param[out] key_buffer_size Minimum buffer size to contain the key material.
428 *
429 * \retval #PSA_SUCCESS
430 * \retval #PSA_ERROR_INVALID_ARGUMENT
431 * \retval #PSA_ERROR_NOT_SUPPORTED
432 */
433psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data(
434 const psa_key_attributes_t *attributes,
435 const uint8_t *data,
436 size_t data_length,
437 size_t *key_buffer_size )
438{
Archana449608b2021-09-08 15:36:05 +0530439 psa_key_location_t location =
440 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Archanad8a83dc2021-06-14 10:04:16 +0530441 psa_key_type_t key_type = attributes->core.type;
442
443 *key_buffer_size = 0;
444 switch( location )
445 {
446#if defined(PSA_CRYPTO_DRIVER_TEST)
447 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
448 *key_buffer_size = mbedtls_test_opaque_size_function( key_type,
449 PSA_BYTES_TO_BITS( data_length ) );
450 return( ( *key_buffer_size != 0 ) ?
451 PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED );
452#endif /* PSA_CRYPTO_DRIVER_TEST */
453
454 default:
455 (void)key_type;
456 (void)data;
457 (void)data_length;
458 return( PSA_ERROR_INVALID_ARGUMENT );
459 }
460}
461
Steven Cooremanb938b0b2021-04-06 13:08:42 +0200462/** Get the key buffer size required to store the key material of a key
Archanad8a83dc2021-06-14 10:04:16 +0530463 * associated with an opaque driver.
Steven Cooreman56250fd2020-09-04 13:07:15 +0200464 *
Ronald Cron31216282020-12-05 18:47:56 +0100465 * \param[in] attributes The key attributes.
466 * \param[out] key_buffer_size Minimum buffer size to contain the key material
Steven Cooreman56250fd2020-09-04 13:07:15 +0200467 *
468 * \retval #PSA_SUCCESS
Ronald Cron31216282020-12-05 18:47:56 +0100469 * The minimum size for a buffer to contain the key material has been
470 * returned successfully.
Steven Cooreman56250fd2020-09-04 13:07:15 +0200471 * \retval #PSA_ERROR_NOT_SUPPORTED
Ronald Cron31216282020-12-05 18:47:56 +0100472 * The type and/or the size in bits of the key or the combination of
473 * the two is not supported.
Archanad8a83dc2021-06-14 10:04:16 +0530474 * \retval #PSA_ERROR_INVALID_ARGUMENT
475 * The key is declared with a lifetime not known to us.
Steven Cooreman56250fd2020-09-04 13:07:15 +0200476 */
Ronald Cron9df74be2020-12-05 19:15:23 +0100477psa_status_t psa_driver_wrapper_get_key_buffer_size(
Ronald Cron31216282020-12-05 18:47:56 +0100478 const psa_key_attributes_t *attributes,
479 size_t *key_buffer_size )
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200480{
John Durkop2c618352020-09-22 06:54:01 -0700481 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
482 psa_key_type_t key_type = attributes->core.type;
483 size_t key_bits = attributes->core.bits;
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200484
Ronald Cron31216282020-12-05 18:47:56 +0100485 *key_buffer_size = 0;
John Durkop2c618352020-09-22 06:54:01 -0700486 switch( location )
487 {
John Durkop2c618352020-09-22 06:54:01 -0700488#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100489 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Steven Cooremanf9a55ff2021-02-19 18:04:59 +0100490#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
491 /* Emulate property 'builtin_key_size' */
492 if( psa_key_id_is_builtin(
493 MBEDTLS_SVC_KEY_ID_GET_KEY_ID(
494 psa_get_key_id( attributes ) ) ) )
495 {
Steven Cooreman203bcbb2021-03-18 17:17:40 +0100496 *key_buffer_size = sizeof( psa_drv_slot_number_t );
Steven Cooremanf9a55ff2021-02-19 18:04:59 +0100497 return( PSA_SUCCESS );
498 }
499#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
Archana449608b2021-09-08 15:36:05 +0530500 *key_buffer_size = mbedtls_test_opaque_size_function( key_type,
501 key_bits );
Ronald Cron4607c822021-04-14 10:55:34 +0200502 return( ( *key_buffer_size != 0 ) ?
503 PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED );
John Durkop2c618352020-09-22 06:54:01 -0700504#endif /* PSA_CRYPTO_DRIVER_TEST */
505
506 default:
Ronald Cron9df74be2020-12-05 19:15:23 +0100507 (void)key_type;
508 (void)key_bits;
Archanad8a83dc2021-06-14 10:04:16 +0530509 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200510 }
511}
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200512
Ronald Cron977c2472020-10-13 08:32:21 +0200513psa_status_t psa_driver_wrapper_generate_key(
514 const psa_key_attributes_t *attributes,
515 uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
Steven Cooreman55ae2172020-07-17 19:46:15 +0200516{
Ronald Cron977c2472020-10-13 08:32:21 +0200517 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
518 psa_key_location_t location =
519 PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime);
520
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200521 /* Try dynamically-registered SE interface first */
522#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
523 const psa_drv_se_t *drv;
524 psa_drv_se_context_t *drv_context;
525
Ronald Cron977c2472020-10-13 08:32:21 +0200526 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200527 {
528 size_t pubkey_length = 0; /* We don't support this feature yet */
529 if( drv->key_management == NULL ||
530 drv->key_management->p_generate == NULL )
531 {
532 /* Key is defined as being in SE, but we have no way to generate it */
Steven Cooreman56250fd2020-09-04 13:07:15 +0200533 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200534 }
535 return( drv->key_management->p_generate(
Ronald Cron977c2472020-10-13 08:32:21 +0200536 drv_context,
537 *( (psa_key_slot_number_t *)key_buffer ),
Ronald Cronea0f8a62020-11-25 17:52:23 +0100538 attributes, NULL, 0, &pubkey_length ) );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200539 }
540#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
541
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200542 switch( location )
543 {
544 case PSA_KEY_LOCATION_LOCAL_STORAGE:
Ronald Cron977c2472020-10-13 08:32:21 +0200545#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200546 /* Transparent drivers are limited to generating asymmetric keys */
Ronald Cron977c2472020-10-13 08:32:21 +0200547 if( PSA_KEY_TYPE_IS_ASYMMETRIC( attributes->core.type ) )
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200548 {
Ronald Cron977c2472020-10-13 08:32:21 +0200549 /* Cycle through all known transparent accelerators */
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200550#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +0200551 status = mbedtls_test_transparent_generate_key(
Ronald Cron977c2472020-10-13 08:32:21 +0200552 attributes, key_buffer, key_buffer_size,
553 key_buffer_length );
554 /* Declared with fallback == true */
555 if( status != PSA_ERROR_NOT_SUPPORTED )
556 break;
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200557#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron977c2472020-10-13 08:32:21 +0200558 }
559#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
560
561 /* Software fallback */
562 status = psa_generate_key_internal(
563 attributes, key_buffer, key_buffer_size, key_buffer_length );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200564 break;
Ronald Cron977c2472020-10-13 08:32:21 +0200565
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200566 /* Add cases for opaque driver here */
Ronald Cron977c2472020-10-13 08:32:21 +0200567#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200568#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100569 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +0200570 status = mbedtls_test_opaque_generate_key(
Ronald Cron977c2472020-10-13 08:32:21 +0200571 attributes, key_buffer, key_buffer_size, key_buffer_length );
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200572 break;
Steven Cooremanf1720ea2020-07-24 18:41:58 +0200573#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron977c2472020-10-13 08:32:21 +0200574#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
575
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200576 default:
577 /* Key is declared with a lifetime not known to us */
578 status = PSA_ERROR_INVALID_ARGUMENT;
579 break;
580 }
581
Steven Cooreman2a1664c2020-07-20 15:33:08 +0200582 return( status );
Steven Cooreman55ae2172020-07-17 19:46:15 +0200583}
584
Ronald Cron83282872020-11-22 14:02:39 +0100585psa_status_t psa_driver_wrapper_import_key(
586 const psa_key_attributes_t *attributes,
587 const uint8_t *data,
588 size_t data_length,
589 uint8_t *key_buffer,
590 size_t key_buffer_size,
591 size_t *key_buffer_length,
592 size_t *bits )
Steven Cooreman04524762020-10-13 17:43:44 +0200593{
Steven Cooreman04524762020-10-13 17:43:44 +0200594 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Ronald Cronbf33c932020-11-28 18:06:53 +0100595 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
596 psa_get_key_lifetime( attributes ) );
Steven Cooreman04524762020-10-13 17:43:44 +0200597
Ronald Cronfb2ed5b2020-11-30 12:11:01 +0100598 /* Try dynamically-registered SE interface first */
599#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
600 const psa_drv_se_t *drv;
601 psa_drv_se_context_t *drv_context;
602
603 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
604 {
605 if( drv->key_management == NULL ||
606 drv->key_management->p_import == NULL )
607 return( PSA_ERROR_NOT_SUPPORTED );
608
609 /* The driver should set the number of key bits, however in
610 * case it doesn't, we initialize bits to an invalid value. */
611 *bits = PSA_MAX_KEY_BITS + 1;
612 status = drv->key_management->p_import(
613 drv_context,
614 *( (psa_key_slot_number_t *)key_buffer ),
615 attributes, data, data_length, bits );
616
617 if( status != PSA_SUCCESS )
618 return( status );
619
620 if( (*bits) > PSA_MAX_KEY_BITS )
621 return( PSA_ERROR_NOT_SUPPORTED );
622
623 return( PSA_SUCCESS );
624 }
625#endif /* PSA_CRYPTO_SE_C */
626
Ronald Cronbf33c932020-11-28 18:06:53 +0100627 switch( location )
628 {
629 case PSA_KEY_LOCATION_LOCAL_STORAGE:
630 /* Key is stored in the slot in export representation, so
631 * cycle through all known transparent accelerators */
632#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
633#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +0200634 status = mbedtls_test_transparent_import_key(
635 attributes,
636 data, data_length,
637 key_buffer, key_buffer_size,
638 key_buffer_length, bits );
Ronald Cronbf33c932020-11-28 18:06:53 +0100639 /* Declared with fallback == true */
640 if( status != PSA_ERROR_NOT_SUPPORTED )
641 return( status );
642#endif /* PSA_CRYPTO_DRIVER_TEST */
643#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
644 /* Fell through, meaning no accelerator supports this operation */
645 return( psa_import_key_into_slot( attributes,
646 data, data_length,
647 key_buffer, key_buffer_size,
648 key_buffer_length, bits ) );
Archana4d7ae1d2021-07-07 02:50:22 +0530649 /* Add cases for opaque driver here */
650#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
651#if defined(PSA_CRYPTO_DRIVER_TEST)
652 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
653 return( mbedtls_test_opaque_import_key(
654 attributes,
655 data, data_length,
656 key_buffer, key_buffer_size,
657 key_buffer_length, bits ) );
658#endif /* PSA_CRYPTO_DRIVER_TEST */
659#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cronbf33c932020-11-28 18:06:53 +0100660 default:
Ronald Cronbf33c932020-11-28 18:06:53 +0100661 (void)status;
Ronald Cronfb2ed5b2020-11-30 12:11:01 +0100662 return( PSA_ERROR_INVALID_ARGUMENT );
Ronald Cronbf33c932020-11-28 18:06:53 +0100663 }
664
Steven Cooreman04524762020-10-13 17:43:44 +0200665}
666
Ronald Cron67227982020-11-26 15:16:05 +0100667psa_status_t psa_driver_wrapper_export_key(
668 const psa_key_attributes_t *attributes,
669 const uint8_t *key_buffer, size_t key_buffer_size,
670 uint8_t *data, size_t data_size, size_t *data_length )
671
672{
673 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
674 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
675 psa_get_key_lifetime( attributes ) );
676
Ronald Cron152e3f82020-11-26 16:06:41 +0100677 /* Try dynamically-registered SE interface first */
678#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
679 const psa_drv_se_t *drv;
680 psa_drv_se_context_t *drv_context;
681
682 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
683 {
684 if( ( drv->key_management == NULL ) ||
685 ( drv->key_management->p_export == NULL ) )
Ronald Cron9cfdf6e2021-01-18 11:58:39 +0100686 {
Ronald Cron152e3f82020-11-26 16:06:41 +0100687 return( PSA_ERROR_NOT_SUPPORTED );
Ronald Cron9cfdf6e2021-01-18 11:58:39 +0100688 }
Ronald Cron152e3f82020-11-26 16:06:41 +0100689
690 return( drv->key_management->p_export(
691 drv_context,
692 *( (psa_key_slot_number_t *)key_buffer ),
693 data, data_size, data_length ) );
694 }
695#endif /* PSA_CRYPTO_SE_C */
696
Ronald Cron67227982020-11-26 15:16:05 +0100697 switch( location )
698 {
699 case PSA_KEY_LOCATION_LOCAL_STORAGE:
700 return( psa_export_key_internal( attributes,
701 key_buffer,
702 key_buffer_size,
703 data,
704 data_size,
705 data_length ) );
706
707 /* Add cases for opaque driver here */
708#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
709#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100710 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +0200711 return( mbedtls_test_opaque_export_key( attributes,
712 key_buffer,
713 key_buffer_size,
714 data,
715 data_size,
716 data_length ) );
Ronald Cron67227982020-11-26 15:16:05 +0100717#endif /* PSA_CRYPTO_DRIVER_TEST */
718#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
719 default:
720 /* Key is declared with a lifetime not known to us */
721 return( status );
722 }
723}
724
Ronald Cron84cc9942020-11-25 14:30:05 +0100725psa_status_t psa_driver_wrapper_export_public_key(
726 const psa_key_attributes_t *attributes,
727 const uint8_t *key_buffer, size_t key_buffer_size,
728 uint8_t *data, size_t data_size, size_t *data_length )
729
Steven Cooremanb9b84422020-10-14 14:39:20 +0200730{
Steven Cooremanb9b84422020-10-14 14:39:20 +0200731 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
Ronald Cron84cc9942020-11-25 14:30:05 +0100732 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
733 psa_get_key_lifetime( attributes ) );
Steven Cooremanb9b84422020-10-14 14:39:20 +0200734
Ronald Cron152e3f82020-11-26 16:06:41 +0100735 /* Try dynamically-registered SE interface first */
736#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
737 const psa_drv_se_t *drv;
738 psa_drv_se_context_t *drv_context;
739
740 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
741 {
742 if( ( drv->key_management == NULL ) ||
743 ( drv->key_management->p_export_public == NULL ) )
Ronald Cron9cfdf6e2021-01-18 11:58:39 +0100744 {
Ronald Cron152e3f82020-11-26 16:06:41 +0100745 return( PSA_ERROR_NOT_SUPPORTED );
Ronald Cron9cfdf6e2021-01-18 11:58:39 +0100746 }
Ronald Cron152e3f82020-11-26 16:06:41 +0100747
748 return( drv->key_management->p_export_public(
749 drv_context,
750 *( (psa_key_slot_number_t *)key_buffer ),
751 data, data_size, data_length ) );
752 }
753#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
754
Steven Cooremanb9b84422020-10-14 14:39:20 +0200755 switch( location )
756 {
757 case PSA_KEY_LOCATION_LOCAL_STORAGE:
758 /* Key is stored in the slot in export representation, so
759 * cycle through all known transparent accelerators */
Ronald Cron67227982020-11-26 15:16:05 +0100760#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanb9b84422020-10-14 14:39:20 +0200761#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +0200762 status = mbedtls_test_transparent_export_public_key(
763 attributes,
764 key_buffer,
765 key_buffer_size,
766 data,
767 data_size,
768 data_length );
Steven Cooremanb9b84422020-10-14 14:39:20 +0200769 /* Declared with fallback == true */
770 if( status != PSA_ERROR_NOT_SUPPORTED )
771 return( status );
772#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron67227982020-11-26 15:16:05 +0100773#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooremanb9b84422020-10-14 14:39:20 +0200774 /* Fell through, meaning no accelerator supports this operation */
Ronald Cron67227982020-11-26 15:16:05 +0100775 return( psa_export_public_key_internal( attributes,
776 key_buffer,
777 key_buffer_size,
778 data,
779 data_size,
780 data_length ) );
781
Steven Cooremanb9b84422020-10-14 14:39:20 +0200782 /* Add cases for opaque driver here */
Ronald Cron67227982020-11-26 15:16:05 +0100783#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooremanb9b84422020-10-14 14:39:20 +0200784#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100785 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +0200786 return( mbedtls_test_opaque_export_public_key( attributes,
787 key_buffer,
788 key_buffer_size,
789 data,
790 data_size,
791 data_length ) );
Steven Cooremanb9b84422020-10-14 14:39:20 +0200792#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron67227982020-11-26 15:16:05 +0100793#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooremanb9b84422020-10-14 14:39:20 +0200794 default:
795 /* Key is declared with a lifetime not known to us */
796 return( status );
797 }
Steven Cooremanb9b84422020-10-14 14:39:20 +0200798}
799
Steven Cooreman6801f082021-02-19 17:21:22 +0100800psa_status_t psa_driver_wrapper_get_builtin_key(
801 psa_drv_slot_number_t slot_number,
802 psa_key_attributes_t *attributes,
803 uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
804{
805 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
806 switch( location )
807 {
Steven Cooremanf9a55ff2021-02-19 18:04:59 +0100808#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100809 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +0200810 return( mbedtls_test_opaque_get_builtin_key(
Steven Cooremanf9a55ff2021-02-19 18:04:59 +0100811 slot_number,
812 attributes,
813 key_buffer, key_buffer_size, key_buffer_length ) );
Steven Cooremanf9a55ff2021-02-19 18:04:59 +0100814#endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooreman6801f082021-02-19 17:21:22 +0100815 default:
816 (void) slot_number;
817 (void) key_buffer;
818 (void) key_buffer_size;
819 (void) key_buffer_length;
820 return( PSA_ERROR_DOES_NOT_EXIST );
821 }
822}
823
Archana8a180362021-07-05 02:18:48 +0530824psa_status_t psa_driver_wrapper_copy_key(
825 psa_key_attributes_t *attributes,
Archana9d17bf42021-09-10 06:22:44 +0530826 const uint8_t *source_key, size_t source_key_length,
Archana449608b2021-09-08 15:36:05 +0530827 uint8_t *target_key_buffer, size_t target_key_buffer_size,
828 size_t *target_key_buffer_length )
Archana8a180362021-07-05 02:18:48 +0530829{
Archana449608b2021-09-08 15:36:05 +0530830 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
831 psa_key_location_t location =
832 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Archana8a180362021-07-05 02:18:48 +0530833
Archana9d17bf42021-09-10 06:22:44 +0530834#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
835 const psa_drv_se_t *drv;
836 psa_drv_se_context_t *drv_context;
837
838 if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
839 {
840 /* Copying to a secure element is not implemented yet. */
841 return( PSA_ERROR_NOT_SUPPORTED );
842 }
843#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
844
Archana8a180362021-07-05 02:18:48 +0530845 switch( location )
846 {
847#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
848#if defined(PSA_CRYPTO_DRIVER_TEST)
849 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
850 return( mbedtls_test_opaque_copy_key( attributes, source_key,
Archana9d17bf42021-09-10 06:22:44 +0530851 source_key_length,
Archana8a180362021-07-05 02:18:48 +0530852 target_key_buffer,
Archana449608b2021-09-08 15:36:05 +0530853 target_key_buffer_size,
854 target_key_buffer_length) );
Archana8a180362021-07-05 02:18:48 +0530855#endif /* PSA_CRYPTO_DRIVER_TEST */
856#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
857 default:
858 (void)source_key;
Archana9d17bf42021-09-10 06:22:44 +0530859 (void)source_key_length;
Archana8a180362021-07-05 02:18:48 +0530860 (void)target_key_buffer;
Archana449608b2021-09-08 15:36:05 +0530861 (void)target_key_buffer_size;
862 (void)target_key_buffer_length;
Archana8a180362021-07-05 02:18:48 +0530863 status = PSA_ERROR_INVALID_ARGUMENT;
864 }
865 return( status );
866}
867
Steven Cooreman37941cb2020-07-28 18:49:51 +0200868/*
869 * Cipher functions
870 */
871psa_status_t psa_driver_wrapper_cipher_encrypt(
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100872 const psa_key_attributes_t *attributes,
873 const uint8_t *key_buffer,
874 size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200875 psa_algorithm_t alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200876 const uint8_t *iv,
877 size_t iv_length,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200878 const uint8_t *input,
879 size_t input_length,
880 uint8_t *output,
881 size_t output_size,
882 size_t *output_length )
883{
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100884 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
885 psa_key_location_t location =
886 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200887
888 switch( location )
889 {
890 case PSA_KEY_LOCATION_LOCAL_STORAGE:
891 /* Key is stored in the slot in export representation, so
892 * cycle through all known transparent accelerators */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100893#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200894#if defined(PSA_CRYPTO_DRIVER_TEST)
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100895 status = mbedtls_test_transparent_cipher_encrypt( attributes,
896 key_buffer,
897 key_buffer_size,
Ronald Cron7f13fa22021-04-13 12:41:34 +0200898 alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200899 iv,
900 iv_length,
Ronald Cron7f13fa22021-04-13 12:41:34 +0200901 input,
902 input_length,
903 output,
904 output_size,
905 output_length );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200906 /* Declared with fallback == true */
907 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200908 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200909#endif /* PSA_CRYPTO_DRIVER_TEST */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100910#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
911
912#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
913 return( mbedtls_psa_cipher_encrypt( attributes,
914 key_buffer,
915 key_buffer_size,
916 alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200917 iv,
918 iv_length,
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100919 input,
920 input_length,
921 output,
922 output_size,
923 output_length ) );
gabor-mezei-arm0a93b662021-06-25 15:43:32 +0200924#else
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200925 return( PSA_ERROR_NOT_SUPPORTED );
gabor-mezei-arm0a93b662021-06-25 15:43:32 +0200926#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100927
Steven Cooreman37941cb2020-07-28 18:49:51 +0200928 /* Add cases for opaque driver here */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100929#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200930#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +0100931 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100932 return( mbedtls_test_opaque_cipher_encrypt( attributes,
933 key_buffer,
934 key_buffer_size,
Ronald Cron7f13fa22021-04-13 12:41:34 +0200935 alg,
Ronald Cron9b674282021-07-09 09:19:35 +0200936 iv,
937 iv_length,
Ronald Cron7f13fa22021-04-13 12:41:34 +0200938 input,
939 input_length,
940 output,
941 output_size,
942 output_length ) );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200943#endif /* PSA_CRYPTO_DRIVER_TEST */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100944#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
945
Steven Cooreman37941cb2020-07-28 18:49:51 +0200946 default:
947 /* Key is declared with a lifetime not known to us */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100948 (void)status;
949 (void)key_buffer;
950 (void)key_buffer_size;
951 (void)alg;
Ronald Cron9ed38732021-12-14 18:08:30 +0100952 (void)iv;
953 (void)iv_length;
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100954 (void)input;
955 (void)input_length;
956 (void)output;
957 (void)output_size;
958 (void)output_length;
959 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200960 }
Steven Cooreman37941cb2020-07-28 18:49:51 +0200961}
962
963psa_status_t psa_driver_wrapper_cipher_decrypt(
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100964 const psa_key_attributes_t *attributes,
965 const uint8_t *key_buffer,
966 size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +0200967 psa_algorithm_t alg,
968 const uint8_t *input,
969 size_t input_length,
970 uint8_t *output,
971 size_t output_size,
972 size_t *output_length )
973{
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100974 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
975 psa_key_location_t location =
976 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200977
978 switch( location )
979 {
980 case PSA_KEY_LOCATION_LOCAL_STORAGE:
981 /* Key is stored in the slot in export representation, so
982 * cycle through all known transparent accelerators */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100983#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +0200984#if defined(PSA_CRYPTO_DRIVER_TEST)
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100985 status = mbedtls_test_transparent_cipher_decrypt( attributes,
986 key_buffer,
987 key_buffer_size,
Ronald Cron7f13fa22021-04-13 12:41:34 +0200988 alg,
989 input,
990 input_length,
991 output,
992 output_size,
993 output_length );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200994 /* Declared with fallback == true */
995 if( status != PSA_ERROR_NOT_SUPPORTED )
Steven Cooreman5240e8b2020-09-09 11:51:45 +0200996 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +0200997#endif /* PSA_CRYPTO_DRIVER_TEST */
gabor-mezei-arma9449a02021-03-25 11:17:10 +0100998#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
999
1000#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
1001 return( mbedtls_psa_cipher_decrypt( attributes,
1002 key_buffer,
1003 key_buffer_size,
1004 alg,
1005 input,
1006 input_length,
1007 output,
1008 output_size,
1009 output_length ) );
gabor-mezei-arm0a93b662021-06-25 15:43:32 +02001010#else
Steven Cooreman5240e8b2020-09-09 11:51:45 +02001011 return( PSA_ERROR_NOT_SUPPORTED );
gabor-mezei-arm0a93b662021-06-25 15:43:32 +02001012#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
gabor-mezei-arma9449a02021-03-25 11:17:10 +01001013
Steven Cooreman37941cb2020-07-28 18:49:51 +02001014 /* Add cases for opaque driver here */
gabor-mezei-arma9449a02021-03-25 11:17:10 +01001015#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001016#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +01001017 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
gabor-mezei-arma9449a02021-03-25 11:17:10 +01001018 return( mbedtls_test_opaque_cipher_decrypt( attributes,
1019 key_buffer,
1020 key_buffer_size,
Ronald Cron7f13fa22021-04-13 12:41:34 +02001021 alg,
1022 input,
1023 input_length,
1024 output,
1025 output_size,
1026 output_length ) );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001027#endif /* PSA_CRYPTO_DRIVER_TEST */
gabor-mezei-arma9449a02021-03-25 11:17:10 +01001028#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1029
Steven Cooreman37941cb2020-07-28 18:49:51 +02001030 default:
1031 /* Key is declared with a lifetime not known to us */
gabor-mezei-arma9449a02021-03-25 11:17:10 +01001032 (void)status;
1033 (void)key_buffer;
1034 (void)key_buffer_size;
1035 (void)alg;
1036 (void)input;
1037 (void)input_length;
1038 (void)output;
1039 (void)output_size;
1040 (void)output_length;
1041 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001042 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001043}
1044
1045psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
Ronald Crona4af55f2020-12-14 14:36:06 +01001046 psa_cipher_operation_t *operation,
1047 const psa_key_attributes_t *attributes,
1048 const uint8_t *key_buffer, size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +02001049 psa_algorithm_t alg )
1050{
Ronald Cron0b805592020-12-14 18:08:20 +01001051 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Ronald Crona4af55f2020-12-14 14:36:06 +01001052 psa_key_location_t location =
1053 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001054
Steven Cooreman37941cb2020-07-28 18:49:51 +02001055 switch( location )
1056 {
1057 case PSA_KEY_LOCATION_LOCAL_STORAGE:
1058 /* Key is stored in the slot in export representation, so
1059 * cycle through all known transparent accelerators */
Ronald Cron0b805592020-12-14 18:08:20 +01001060#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001061#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +02001062 status = mbedtls_test_transparent_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001063 &operation->ctx.transparent_test_driver_ctx,
1064 attributes,
1065 key_buffer,
1066 key_buffer_size,
1067 alg );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001068 /* Declared with fallback == true */
Steven Cooreman150c99b2020-09-09 14:32:44 +02001069 if( status == PSA_SUCCESS )
Ronald Cron49fafa92021-03-10 08:34:23 +01001070 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Steven Cooreman150c99b2020-09-09 14:32:44 +02001071
Ronald Cron0b805592020-12-14 18:08:20 +01001072 if( status != PSA_ERROR_NOT_SUPPORTED )
1073 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001074#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron0b805592020-12-14 18:08:20 +01001075#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001076#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001077 /* Fell through, meaning no accelerator supports this operation */
Ronald Cron6e412a72021-03-10 09:58:47 +01001078 status = mbedtls_psa_cipher_encrypt_setup( &operation->ctx.mbedtls_ctx,
Ronald Cron49fafa92021-03-10 08:34:23 +01001079 attributes,
1080 key_buffer,
1081 key_buffer_size,
1082 alg );
1083 if( status == PSA_SUCCESS )
Ronald Cron6e412a72021-03-10 09:58:47 +01001084 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
Ronald Cron49fafa92021-03-10 08:34:23 +01001085
Ronald Cron7b4154d2021-03-19 14:49:41 +01001086 if( status != PSA_ERROR_NOT_SUPPORTED )
1087 return( status );
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001088#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
1089 return( PSA_ERROR_NOT_SUPPORTED );
Ronald Cron0b805592020-12-14 18:08:20 +01001090
Steven Cooreman37941cb2020-07-28 18:49:51 +02001091 /* Add cases for opaque driver here */
Ronald Cron0b805592020-12-14 18:08:20 +01001092#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001093#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +01001094 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001095 status = mbedtls_test_opaque_cipher_encrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001096 &operation->ctx.opaque_test_driver_ctx,
1097 attributes,
1098 key_buffer, key_buffer_size,
1099 alg );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001100
Steven Cooreman37941cb2020-07-28 18:49:51 +02001101 if( status == PSA_SUCCESS )
Ronald Cron49fafa92021-03-10 08:34:23 +01001102 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +02001103
Steven Cooreman5240e8b2020-09-09 11:51:45 +02001104 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001105#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron0b805592020-12-14 18:08:20 +01001106#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooreman37941cb2020-07-28 18:49:51 +02001107 default:
1108 /* Key is declared with a lifetime not known to us */
Ronald Cron0b805592020-12-14 18:08:20 +01001109 (void)status;
Ronald Cron7a55deb2021-04-28 14:29:00 +02001110 (void)operation;
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001111 (void)key_buffer;
1112 (void)key_buffer_size;
1113 (void)alg;
Ronald Cronc45b4af2020-09-29 16:18:05 +02001114 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001115 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001116}
1117
1118psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
Ronald Crona4af55f2020-12-14 14:36:06 +01001119 psa_cipher_operation_t *operation,
1120 const psa_key_attributes_t *attributes,
1121 const uint8_t *key_buffer, size_t key_buffer_size,
Steven Cooreman37941cb2020-07-28 18:49:51 +02001122 psa_algorithm_t alg )
1123{
Steven Cooreman37941cb2020-07-28 18:49:51 +02001124 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
Ronald Crona4af55f2020-12-14 14:36:06 +01001125 psa_key_location_t location =
1126 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001127
Steven Cooreman37941cb2020-07-28 18:49:51 +02001128 switch( location )
1129 {
1130 case PSA_KEY_LOCATION_LOCAL_STORAGE:
1131 /* Key is stored in the slot in export representation, so
1132 * cycle through all known transparent accelerators */
Ronald Cron0b805592020-12-14 18:08:20 +01001133#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001134#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +02001135 status = mbedtls_test_transparent_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001136 &operation->ctx.transparent_test_driver_ctx,
1137 attributes,
1138 key_buffer,
1139 key_buffer_size,
1140 alg );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001141 /* Declared with fallback == true */
Steven Cooreman150c99b2020-09-09 14:32:44 +02001142 if( status == PSA_SUCCESS )
Ronald Cron49fafa92021-03-10 08:34:23 +01001143 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Steven Cooreman150c99b2020-09-09 14:32:44 +02001144
Ronald Cron0b805592020-12-14 18:08:20 +01001145 if( status != PSA_ERROR_NOT_SUPPORTED )
1146 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001147#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron0b805592020-12-14 18:08:20 +01001148#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001149#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001150 /* Fell through, meaning no accelerator supports this operation */
Ronald Cron6e412a72021-03-10 09:58:47 +01001151 status = mbedtls_psa_cipher_decrypt_setup( &operation->ctx.mbedtls_ctx,
Ronald Cron49fafa92021-03-10 08:34:23 +01001152 attributes,
1153 key_buffer,
1154 key_buffer_size,
1155 alg );
1156 if( status == PSA_SUCCESS )
1157 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
1158
1159 return( status );
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001160#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
1161 return( PSA_ERROR_NOT_SUPPORTED );
Ronald Cron49fafa92021-03-10 08:34:23 +01001162
Steven Cooreman37941cb2020-07-28 18:49:51 +02001163 /* Add cases for opaque driver here */
Ronald Cron0b805592020-12-14 18:08:20 +01001164#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001165#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremana1ce2f22021-03-18 20:49:29 +01001166 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001167 status = mbedtls_test_opaque_cipher_decrypt_setup(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001168 &operation->ctx.opaque_test_driver_ctx,
1169 attributes,
1170 key_buffer, key_buffer_size,
1171 alg );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001172
Steven Cooreman37941cb2020-07-28 18:49:51 +02001173 if( status == PSA_SUCCESS )
Ronald Cron49fafa92021-03-10 08:34:23 +01001174 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
Steven Cooreman37941cb2020-07-28 18:49:51 +02001175
Steven Cooreman5240e8b2020-09-09 11:51:45 +02001176 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001177#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Cron0b805592020-12-14 18:08:20 +01001178#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Steven Cooreman37941cb2020-07-28 18:49:51 +02001179 default:
1180 /* Key is declared with a lifetime not known to us */
Ronald Cron0b805592020-12-14 18:08:20 +01001181 (void)status;
Ronald Cron17006702021-12-03 15:25:24 +01001182 (void)operation;
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001183 (void)key_buffer;
1184 (void)key_buffer_size;
1185 (void)alg;
Ronald Cronc45b4af2020-09-29 16:18:05 +02001186 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001187 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001188}
1189
Steven Cooreman37941cb2020-07-28 18:49:51 +02001190psa_status_t psa_driver_wrapper_cipher_set_iv(
Ronald Cron6056fe82020-12-15 13:58:07 +01001191 psa_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +02001192 const uint8_t *iv,
1193 size_t iv_length )
1194{
Ronald Cron49fafa92021-03-10 08:34:23 +01001195 switch( operation->id )
1196 {
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001197#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Ronald Cron49fafa92021-03-10 08:34:23 +01001198 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Ronald Cron6e412a72021-03-10 09:58:47 +01001199 return( mbedtls_psa_cipher_set_iv( &operation->ctx.mbedtls_ctx,
Ronald Cron49fafa92021-03-10 08:34:23 +01001200 iv,
1201 iv_length ) );
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001202#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
Ronald Crondd24c9b2020-12-15 14:10:01 +01001203
1204#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001205#if defined(PSA_CRYPTO_DRIVER_TEST)
1206 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001207 return( mbedtls_test_transparent_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001208 &operation->ctx.transparent_test_driver_ctx,
1209 iv, iv_length ) );
Ronald Cron49fafa92021-03-10 08:34:23 +01001210
Steven Cooreman37941cb2020-07-28 18:49:51 +02001211 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001212 return( mbedtls_test_opaque_cipher_set_iv(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001213 &operation->ctx.opaque_test_driver_ctx,
1214 iv, iv_length ) );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001215#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Crondd24c9b2020-12-15 14:10:01 +01001216#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cron49fafa92021-03-10 08:34:23 +01001217 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001218
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001219 (void)iv;
1220 (void)iv_length;
1221
Ronald Crondd24c9b2020-12-15 14:10:01 +01001222 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001223}
1224
1225psa_status_t psa_driver_wrapper_cipher_update(
Ronald Cron6056fe82020-12-15 13:58:07 +01001226 psa_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +02001227 const uint8_t *input,
1228 size_t input_length,
1229 uint8_t *output,
1230 size_t output_size,
1231 size_t *output_length )
1232{
Ronald Cron49fafa92021-03-10 08:34:23 +01001233 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +02001234 {
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001235#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Ronald Cron49fafa92021-03-10 08:34:23 +01001236 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Ronald Cron6e412a72021-03-10 09:58:47 +01001237 return( mbedtls_psa_cipher_update( &operation->ctx.mbedtls_ctx,
Ronald Cron49fafa92021-03-10 08:34:23 +01001238 input,
1239 input_length,
1240 output,
1241 output_size,
1242 output_length ) );
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001243#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
1244
Ronald Cron49fafa92021-03-10 08:34:23 +01001245#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001246#if defined(PSA_CRYPTO_DRIVER_TEST)
1247 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001248 return( mbedtls_test_transparent_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001249 &operation->ctx.transparent_test_driver_ctx,
1250 input, input_length,
1251 output, output_size, output_length ) );
1252
Steven Cooreman37941cb2020-07-28 18:49:51 +02001253 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001254 return( mbedtls_test_opaque_cipher_update(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001255 &operation->ctx.opaque_test_driver_ctx,
1256 input, input_length,
1257 output, output_size, output_length ) );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001258#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Crondd24c9b2020-12-15 14:10:01 +01001259#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cron49fafa92021-03-10 08:34:23 +01001260 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001261
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001262 (void)input;
1263 (void)input_length;
1264 (void)output;
1265 (void)output_size;
1266 (void)output_length;
1267
Ronald Crondd24c9b2020-12-15 14:10:01 +01001268 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001269}
1270
1271psa_status_t psa_driver_wrapper_cipher_finish(
Ronald Cron6056fe82020-12-15 13:58:07 +01001272 psa_cipher_operation_t *operation,
Steven Cooreman37941cb2020-07-28 18:49:51 +02001273 uint8_t *output,
1274 size_t output_size,
1275 size_t *output_length )
1276{
Ronald Cron49fafa92021-03-10 08:34:23 +01001277 switch( operation->id )
1278 {
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001279#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Ronald Cron49fafa92021-03-10 08:34:23 +01001280 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Ronald Cron6e412a72021-03-10 09:58:47 +01001281 return( mbedtls_psa_cipher_finish( &operation->ctx.mbedtls_ctx,
Ronald Cron49fafa92021-03-10 08:34:23 +01001282 output,
1283 output_size,
1284 output_length ) );
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001285#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
Ronald Crondd24c9b2020-12-15 14:10:01 +01001286
1287#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001288#if defined(PSA_CRYPTO_DRIVER_TEST)
1289 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001290 return( mbedtls_test_transparent_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001291 &operation->ctx.transparent_test_driver_ctx,
1292 output, output_size, output_length ) );
Ronald Cron49fafa92021-03-10 08:34:23 +01001293
Steven Cooreman37941cb2020-07-28 18:49:51 +02001294 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001295 return( mbedtls_test_opaque_cipher_finish(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001296 &operation->ctx.opaque_test_driver_ctx,
1297 output, output_size, output_length ) );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001298#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Crondd24c9b2020-12-15 14:10:01 +01001299#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cron49fafa92021-03-10 08:34:23 +01001300 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001301
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001302 (void)output;
1303 (void)output_size;
1304 (void)output_length;
1305
Ronald Crondd24c9b2020-12-15 14:10:01 +01001306 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001307}
1308
1309psa_status_t psa_driver_wrapper_cipher_abort(
Ronald Cron6056fe82020-12-15 13:58:07 +01001310 psa_cipher_operation_t *operation )
Steven Cooreman37941cb2020-07-28 18:49:51 +02001311{
Ronald Crondd24c9b2020-12-15 14:10:01 +01001312 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Steven Cooreman37941cb2020-07-28 18:49:51 +02001313
Ronald Cron49fafa92021-03-10 08:34:23 +01001314 switch( operation->id )
Steven Cooreman37941cb2020-07-28 18:49:51 +02001315 {
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001316#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
Ronald Cron49fafa92021-03-10 08:34:23 +01001317 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Ronald Cron6e412a72021-03-10 09:58:47 +01001318 return( mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) );
Ronald Cron5d9b00d2021-03-10 14:43:20 +01001319#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
Ronald Cron49fafa92021-03-10 08:34:23 +01001320
1321#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
Steven Cooreman37941cb2020-07-28 18:49:51 +02001322#if defined(PSA_CRYPTO_DRIVER_TEST)
1323 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001324 status = mbedtls_test_transparent_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001325 &operation->ctx.transparent_test_driver_ctx );
Steven Cooremancfeea8f2020-09-09 15:09:18 +02001326 mbedtls_platform_zeroize(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001327 &operation->ctx.transparent_test_driver_ctx,
1328 sizeof( operation->ctx.transparent_test_driver_ctx ) );
Steven Cooreman5240e8b2020-09-09 11:51:45 +02001329 return( status );
Ronald Cron49fafa92021-03-10 08:34:23 +01001330
Steven Cooreman37941cb2020-07-28 18:49:51 +02001331 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001332 status = mbedtls_test_opaque_cipher_abort(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001333 &operation->ctx.opaque_test_driver_ctx );
Steven Cooremancfeea8f2020-09-09 15:09:18 +02001334 mbedtls_platform_zeroize(
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001335 &operation->ctx.opaque_test_driver_ctx,
1336 sizeof( operation->ctx.opaque_test_driver_ctx ) );
Steven Cooreman5240e8b2020-09-09 11:51:45 +02001337 return( status );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001338#endif /* PSA_CRYPTO_DRIVER_TEST */
Ronald Crondd24c9b2020-12-15 14:10:01 +01001339#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
Ronald Cron49fafa92021-03-10 08:34:23 +01001340 }
Steven Cooreman37941cb2020-07-28 18:49:51 +02001341
Ronald Cron49fafa92021-03-10 08:34:23 +01001342 (void)status;
Ronald Crondd24c9b2020-12-15 14:10:01 +01001343 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooreman37941cb2020-07-28 18:49:51 +02001344}
1345
Steven Cooreman1e582352021-02-18 17:24:37 +01001346/*
1347 * Hashing functions
1348 */
1349psa_status_t psa_driver_wrapper_hash_compute(
1350 psa_algorithm_t alg,
1351 const uint8_t *input,
1352 size_t input_length,
1353 uint8_t *hash,
1354 size_t hash_size,
1355 size_t *hash_length)
1356{
Steven Cooreman0eeb7942021-03-08 12:13:21 +01001357 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Steven Cooreman1e582352021-02-18 17:24:37 +01001358
1359 /* Try accelerators first */
Steven Cooremanf8e45a42021-03-16 11:07:55 +01001360#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +02001361 status = mbedtls_test_transparent_hash_compute(
Steven Cooreman0f8ffa82021-03-15 11:56:33 +01001362 alg, input, input_length, hash, hash_size, hash_length );
Steven Cooremanf7638102021-03-04 15:14:36 +01001363 if( status != PSA_ERROR_NOT_SUPPORTED )
1364 return( status );
1365#endif
Steven Cooreman1e582352021-02-18 17:24:37 +01001366
1367 /* If software fallback is compiled in, try fallback */
1368#if defined(MBEDTLS_PSA_BUILTIN_HASH)
1369 status = mbedtls_psa_hash_compute( alg, input, input_length,
1370 hash, hash_size, hash_length );
1371 if( status != PSA_ERROR_NOT_SUPPORTED )
1372 return( status );
1373#endif
Steven Cooreman0eeb7942021-03-08 12:13:21 +01001374 (void) status;
1375 (void) alg;
1376 (void) input;
1377 (void) input_length;
1378 (void) hash;
1379 (void) hash_size;
1380 (void) hash_length;
Steven Cooreman1e582352021-02-18 17:24:37 +01001381
Steven Cooreman0eeb7942021-03-08 12:13:21 +01001382 return( PSA_ERROR_NOT_SUPPORTED );
Steven Cooreman1e582352021-02-18 17:24:37 +01001383}
1384
1385psa_status_t psa_driver_wrapper_hash_setup(
Steven Cooremandbf8ced2021-03-04 13:01:18 +01001386 psa_hash_operation_t *operation,
Steven Cooreman1e582352021-02-18 17:24:37 +01001387 psa_algorithm_t alg )
1388{
Steven Cooreman0eeb7942021-03-08 12:13:21 +01001389 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Steven Cooreman1e582352021-02-18 17:24:37 +01001390
Steven Cooreman1e582352021-02-18 17:24:37 +01001391 /* Try setup on accelerators first */
Steven Cooremanf8e45a42021-03-16 11:07:55 +01001392#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +02001393 status = mbedtls_test_transparent_hash_setup(
Steven Cooreman0f8ffa82021-03-15 11:56:33 +01001394 &operation->ctx.test_driver_ctx, alg );
Steven Cooremanf7638102021-03-04 15:14:36 +01001395 if( status == PSA_SUCCESS )
1396 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
1397
1398 if( status != PSA_ERROR_NOT_SUPPORTED )
1399 return( status );
1400#endif
Steven Cooreman1e582352021-02-18 17:24:37 +01001401
1402 /* If software fallback is compiled in, try fallback */
1403#if defined(MBEDTLS_PSA_BUILTIN_HASH)
Steven Cooremandbf8ced2021-03-04 13:01:18 +01001404 status = mbedtls_psa_hash_setup( &operation->ctx.mbedtls_ctx, alg );
Steven Cooreman1e582352021-02-18 17:24:37 +01001405 if( status == PSA_SUCCESS )
Steven Cooreman1e582352021-02-18 17:24:37 +01001406 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
Steven Cooreman1e582352021-02-18 17:24:37 +01001407
1408 if( status != PSA_ERROR_NOT_SUPPORTED )
1409 return( status );
1410#endif
1411 /* Nothing left to try if we fall through here */
1412 (void) status;
1413 (void) operation;
1414 (void) alg;
1415 return( PSA_ERROR_NOT_SUPPORTED );
1416}
1417
1418psa_status_t psa_driver_wrapper_hash_clone(
Steven Cooremandbf8ced2021-03-04 13:01:18 +01001419 const psa_hash_operation_t *source_operation,
1420 psa_hash_operation_t *target_operation )
Steven Cooreman1e582352021-02-18 17:24:37 +01001421{
Steven Cooreman1e582352021-02-18 17:24:37 +01001422 switch( source_operation->id )
1423 {
Steven Cooreman5e4c18f2021-03-15 12:26:07 +01001424#if defined(MBEDTLS_PSA_BUILTIN_HASH)
1425 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
1426 target_operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
1427 return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx,
1428 &target_operation->ctx.mbedtls_ctx ) );
1429#endif
Steven Cooremanf8e45a42021-03-16 11:07:55 +01001430#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanf7638102021-03-04 15:14:36 +01001431 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
1432 target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Ronald Cron7f13fa22021-04-13 12:41:34 +02001433 return( mbedtls_test_transparent_hash_clone(
Steven Cooreman0f8ffa82021-03-15 11:56:33 +01001434 &source_operation->ctx.test_driver_ctx,
1435 &target_operation->ctx.test_driver_ctx ) );
Steven Cooremanf7638102021-03-04 15:14:36 +01001436#endif
Steven Cooreman1e582352021-02-18 17:24:37 +01001437 default:
Steven Cooreman1e582352021-02-18 17:24:37 +01001438 (void) target_operation;
1439 return( PSA_ERROR_BAD_STATE );
1440 }
Steven Cooreman1e582352021-02-18 17:24:37 +01001441}
1442
1443psa_status_t psa_driver_wrapper_hash_update(
Steven Cooremandbf8ced2021-03-04 13:01:18 +01001444 psa_hash_operation_t *operation,
Steven Cooreman1e582352021-02-18 17:24:37 +01001445 const uint8_t *input,
1446 size_t input_length )
1447{
Steven Cooreman1e582352021-02-18 17:24:37 +01001448 switch( operation->id )
1449 {
Steven Cooreman5e4c18f2021-03-15 12:26:07 +01001450#if defined(MBEDTLS_PSA_BUILTIN_HASH)
1451 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
1452 return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx,
1453 input, input_length ) );
1454#endif
Steven Cooremanf8e45a42021-03-16 11:07:55 +01001455#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanf7638102021-03-04 15:14:36 +01001456 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001457 return( mbedtls_test_transparent_hash_update(
Steven Cooreman0f8ffa82021-03-15 11:56:33 +01001458 &operation->ctx.test_driver_ctx,
1459 input, input_length ) );
Steven Cooremanf7638102021-03-04 15:14:36 +01001460#endif
Steven Cooreman1e582352021-02-18 17:24:37 +01001461 default:
Steven Cooreman1e582352021-02-18 17:24:37 +01001462 (void) input;
1463 (void) input_length;
1464 return( PSA_ERROR_BAD_STATE );
1465 }
Steven Cooreman1e582352021-02-18 17:24:37 +01001466}
1467
1468psa_status_t psa_driver_wrapper_hash_finish(
Steven Cooremandbf8ced2021-03-04 13:01:18 +01001469 psa_hash_operation_t *operation,
Steven Cooreman1e582352021-02-18 17:24:37 +01001470 uint8_t *hash,
1471 size_t hash_size,
1472 size_t *hash_length )
1473{
Steven Cooreman1e582352021-02-18 17:24:37 +01001474 switch( operation->id )
1475 {
Steven Cooreman5e4c18f2021-03-15 12:26:07 +01001476#if defined(MBEDTLS_PSA_BUILTIN_HASH)
1477 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
1478 return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx,
1479 hash, hash_size, hash_length ) );
1480#endif
Steven Cooremanf8e45a42021-03-16 11:07:55 +01001481#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanf7638102021-03-04 15:14:36 +01001482 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001483 return( mbedtls_test_transparent_hash_finish(
Steven Cooreman0f8ffa82021-03-15 11:56:33 +01001484 &operation->ctx.test_driver_ctx,
1485 hash, hash_size, hash_length ) );
Steven Cooremanf7638102021-03-04 15:14:36 +01001486#endif
Steven Cooreman1e582352021-02-18 17:24:37 +01001487 default:
Steven Cooreman1e582352021-02-18 17:24:37 +01001488 (void) hash;
1489 (void) hash_size;
1490 (void) hash_length;
1491 return( PSA_ERROR_BAD_STATE );
1492 }
Steven Cooreman1e582352021-02-18 17:24:37 +01001493}
1494
1495psa_status_t psa_driver_wrapper_hash_abort(
Steven Cooremandbf8ced2021-03-04 13:01:18 +01001496 psa_hash_operation_t *operation )
Steven Cooreman1e582352021-02-18 17:24:37 +01001497{
Steven Cooreman1e582352021-02-18 17:24:37 +01001498 switch( operation->id )
1499 {
Steven Cooreman5e4c18f2021-03-15 12:26:07 +01001500#if defined(MBEDTLS_PSA_BUILTIN_HASH)
1501 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
1502 return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) );
1503#endif
Steven Cooremanf8e45a42021-03-16 11:07:55 +01001504#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanf7638102021-03-04 15:14:36 +01001505 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Ronald Cron7f13fa22021-04-13 12:41:34 +02001506 return( mbedtls_test_transparent_hash_abort(
Steven Cooreman0f8ffa82021-03-15 11:56:33 +01001507 &operation->ctx.test_driver_ctx ) );
Steven Cooremanf7638102021-03-04 15:14:36 +01001508#endif
Steven Cooreman1e582352021-02-18 17:24:37 +01001509 default:
Steven Cooreman1e582352021-02-18 17:24:37 +01001510 return( PSA_ERROR_BAD_STATE );
1511 }
1512}
1513
Ronald Cronde822812021-03-17 16:08:20 +01001514psa_status_t psa_driver_wrapper_aead_encrypt(
1515 const psa_key_attributes_t *attributes,
1516 const uint8_t *key_buffer, size_t key_buffer_size,
1517 psa_algorithm_t alg,
1518 const uint8_t *nonce, size_t nonce_length,
1519 const uint8_t *additional_data, size_t additional_data_length,
1520 const uint8_t *plaintext, size_t plaintext_length,
1521 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
1522{
1523 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1524 psa_key_location_t location =
1525 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
1526
1527 switch( location )
1528 {
1529 case PSA_KEY_LOCATION_LOCAL_STORAGE:
1530 /* Key is stored in the slot in export representation, so
1531 * cycle through all known transparent accelerators */
1532
1533#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1534#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +02001535 status = mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +01001536 attributes, key_buffer, key_buffer_size,
1537 alg,
1538 nonce, nonce_length,
1539 additional_data, additional_data_length,
1540 plaintext, plaintext_length,
1541 ciphertext, ciphertext_size, ciphertext_length );
1542 /* Declared with fallback == true */
1543 if( status != PSA_ERROR_NOT_SUPPORTED )
1544 return( status );
1545#endif /* PSA_CRYPTO_DRIVER_TEST */
1546#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1547
1548 /* Fell through, meaning no accelerator supports this operation */
1549 return( mbedtls_psa_aead_encrypt(
1550 attributes, key_buffer, key_buffer_size,
1551 alg,
1552 nonce, nonce_length,
1553 additional_data, additional_data_length,
1554 plaintext, plaintext_length,
1555 ciphertext, ciphertext_size, ciphertext_length ) );
1556
1557 /* Add cases for opaque driver here */
1558
1559 default:
1560 /* Key is declared with a lifetime not known to us */
1561 (void)status;
1562 return( PSA_ERROR_INVALID_ARGUMENT );
1563 }
1564}
1565
1566psa_status_t psa_driver_wrapper_aead_decrypt(
1567 const psa_key_attributes_t *attributes,
1568 const uint8_t *key_buffer, size_t key_buffer_size,
1569 psa_algorithm_t alg,
1570 const uint8_t *nonce, size_t nonce_length,
1571 const uint8_t *additional_data, size_t additional_data_length,
1572 const uint8_t *ciphertext, size_t ciphertext_length,
1573 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
1574{
1575 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1576 psa_key_location_t location =
1577 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
1578
1579 switch( location )
1580 {
1581 case PSA_KEY_LOCATION_LOCAL_STORAGE:
1582 /* Key is stored in the slot in export representation, so
1583 * cycle through all known transparent accelerators */
1584
1585#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1586#if defined(PSA_CRYPTO_DRIVER_TEST)
Ronald Cron7f13fa22021-04-13 12:41:34 +02001587 status = mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +01001588 attributes, key_buffer, key_buffer_size,
1589 alg,
1590 nonce, nonce_length,
1591 additional_data, additional_data_length,
1592 ciphertext, ciphertext_length,
1593 plaintext, plaintext_size, plaintext_length );
1594 /* Declared with fallback == true */
1595 if( status != PSA_ERROR_NOT_SUPPORTED )
1596 return( status );
1597#endif /* PSA_CRYPTO_DRIVER_TEST */
1598#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1599
1600 /* Fell through, meaning no accelerator supports this operation */
1601 return( mbedtls_psa_aead_decrypt(
1602 attributes, key_buffer, key_buffer_size,
1603 alg,
1604 nonce, nonce_length,
1605 additional_data, additional_data_length,
1606 ciphertext, ciphertext_length,
1607 plaintext, plaintext_size, plaintext_length ) );
1608
1609 /* Add cases for opaque driver here */
1610
1611 default:
1612 /* Key is declared with a lifetime not known to us */
1613 (void)status;
1614 return( PSA_ERROR_INVALID_ARGUMENT );
1615 }
1616}
Steven Cooremand13a70f2021-03-19 15:24:23 +01001617
Paul Elliott6504aa62021-04-20 17:09:36 +01001618psa_status_t psa_driver_wrapper_aead_encrypt_setup(
1619 psa_aead_operation_t *operation,
1620 const psa_key_attributes_t *attributes,
1621 const uint8_t *key_buffer, size_t key_buffer_size,
1622 psa_algorithm_t alg )
1623{
1624 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1625 psa_key_location_t location =
1626 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
1627
1628 switch( location )
1629 {
1630 case PSA_KEY_LOCATION_LOCAL_STORAGE:
1631 /* Key is stored in the slot in export representation, so
1632 * cycle through all known transparent accelerators */
1633
1634#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1635#if defined(PSA_CRYPTO_DRIVER_TEST)
Paul Elliottd7ab9f12021-06-23 09:52:19 +01001636 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Paul Elliotta218ceb2021-05-07 15:10:31 +01001637 status = mbedtls_test_transparent_aead_encrypt_setup(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001638 &operation->ctx.transparent_test_driver_ctx,
1639 attributes, key_buffer, key_buffer_size,
Paul Elliott4bbe82b2021-04-27 12:11:56 +01001640 alg );
Paul Elliott6504aa62021-04-20 17:09:36 +01001641
Paul Elliottd7ab9f12021-06-23 09:52:19 +01001642 /* Declared with fallback == true */
Paul Elliott6504aa62021-04-20 17:09:36 +01001643 if( status != PSA_ERROR_NOT_SUPPORTED )
1644 return( status );
1645#endif /* PSA_CRYPTO_DRIVER_TEST */
1646#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1647
1648 /* Fell through, meaning no accelerator supports this operation */
Paul Elliottd7ab9f12021-06-23 09:52:19 +01001649 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
Paul Elliott6504aa62021-04-20 17:09:36 +01001650 status = mbedtls_psa_aead_encrypt_setup(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001651 &operation->ctx.mbedtls_ctx, attributes,
Paul Elliott6504aa62021-04-20 17:09:36 +01001652 key_buffer, key_buffer_size,
1653 alg );
1654
Paul Elliott6504aa62021-04-20 17:09:36 +01001655 return( status );
1656
1657 /* Add cases for opaque driver here */
1658
1659 default:
1660 /* Key is declared with a lifetime not known to us */
1661 (void)status;
1662 return( PSA_ERROR_INVALID_ARGUMENT );
1663 }
1664}
1665
1666psa_status_t psa_driver_wrapper_aead_decrypt_setup(
1667 psa_aead_operation_t *operation,
1668 const psa_key_attributes_t *attributes,
1669 const uint8_t *key_buffer, size_t key_buffer_size,
1670 psa_algorithm_t alg )
1671{
1672 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1673 psa_key_location_t location =
1674 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
1675
1676 switch( location )
1677 {
1678 case PSA_KEY_LOCATION_LOCAL_STORAGE:
1679 /* Key is stored in the slot in export representation, so
1680 * cycle through all known transparent accelerators */
1681
1682#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1683#if defined(PSA_CRYPTO_DRIVER_TEST)
Paul Elliottd7ab9f12021-06-23 09:52:19 +01001684 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
Paul Elliotta218ceb2021-05-07 15:10:31 +01001685 status = mbedtls_test_transparent_aead_decrypt_setup(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001686 &operation->ctx.transparent_test_driver_ctx,
Paul Elliott5d3a3c32021-08-19 18:34:41 +01001687 attributes,
Paul Elliott4bbe82b2021-04-27 12:11:56 +01001688 key_buffer, key_buffer_size,
1689 alg );
Paul Elliott6504aa62021-04-20 17:09:36 +01001690
Paul Elliottd7ab9f12021-06-23 09:52:19 +01001691 /* Declared with fallback == true */
Paul Elliott6504aa62021-04-20 17:09:36 +01001692 if( status != PSA_ERROR_NOT_SUPPORTED )
1693 return( status );
1694#endif /* PSA_CRYPTO_DRIVER_TEST */
1695#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1696
1697 /* Fell through, meaning no accelerator supports this operation */
Paul Elliottd7ab9f12021-06-23 09:52:19 +01001698 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
Paul Elliott6504aa62021-04-20 17:09:36 +01001699 status = mbedtls_psa_aead_decrypt_setup(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001700 &operation->ctx.mbedtls_ctx,
Paul Elliott5d3a3c32021-08-19 18:34:41 +01001701 attributes,
Paul Elliott6504aa62021-04-20 17:09:36 +01001702 key_buffer, key_buffer_size,
1703 alg );
1704
Paul Elliott6504aa62021-04-20 17:09:36 +01001705 return( status );
1706
1707 /* Add cases for opaque driver here */
1708
1709 default:
1710 /* Key is declared with a lifetime not known to us */
1711 (void)status;
1712 return( PSA_ERROR_INVALID_ARGUMENT );
1713 }
1714}
1715
Paul Elliott6504aa62021-04-20 17:09:36 +01001716psa_status_t psa_driver_wrapper_aead_set_nonce(
1717 psa_aead_operation_t *operation,
1718 const uint8_t *nonce,
1719 size_t nonce_length )
1720{
1721 switch( operation->id )
1722 {
Paul Elliott5c656cb2021-05-19 14:15:01 +01001723#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001724 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001725 return( mbedtls_psa_aead_set_nonce( &operation->ctx.mbedtls_ctx,
1726 nonce,
Paul Elliotta218ceb2021-05-07 15:10:31 +01001727 nonce_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001728
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001729#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001730
1731#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1732#if defined(PSA_CRYPTO_DRIVER_TEST)
1733 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliotta218ceb2021-05-07 15:10:31 +01001734 return( mbedtls_test_transparent_aead_set_nonce(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001735 &operation->ctx.transparent_test_driver_ctx,
1736 nonce, nonce_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001737
1738 /* Add cases for opaque driver here */
1739
1740#endif /* PSA_CRYPTO_DRIVER_TEST */
1741#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1742 }
1743
1744 (void)nonce;
1745 (void)nonce_length;
1746
1747 return( PSA_ERROR_INVALID_ARGUMENT );
1748}
1749
1750psa_status_t psa_driver_wrapper_aead_set_lengths(
1751 psa_aead_operation_t *operation,
1752 size_t ad_length,
1753 size_t plaintext_length )
1754{
1755 switch( operation->id )
1756 {
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001757#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001758 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliottdff6c5d2021-09-28 11:00:20 +01001759 return( mbedtls_psa_aead_set_lengths( &operation->ctx.mbedtls_ctx,
1760 ad_length,
1761 plaintext_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001762
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001763#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001764
1765#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1766#if defined(PSA_CRYPTO_DRIVER_TEST)
1767 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliotta218ceb2021-05-07 15:10:31 +01001768 return( mbedtls_test_transparent_aead_set_lengths(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001769 &operation->ctx.transparent_test_driver_ctx,
1770 ad_length, plaintext_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001771
1772 /* Add cases for opaque driver here */
1773
1774#endif /* PSA_CRYPTO_DRIVER_TEST */
1775#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1776 }
1777
1778 (void)ad_length;
1779 (void)plaintext_length;
1780
1781 return( PSA_ERROR_INVALID_ARGUMENT );
1782}
1783
1784psa_status_t psa_driver_wrapper_aead_update_ad(
1785 psa_aead_operation_t *operation,
1786 const uint8_t *input,
1787 size_t input_length )
1788{
1789 switch( operation->id )
1790 {
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001791#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001792 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001793 return( mbedtls_psa_aead_update_ad( &operation->ctx.mbedtls_ctx,
1794 input,
Paul Elliotta218ceb2021-05-07 15:10:31 +01001795 input_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001796
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001797#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001798
1799#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1800#if defined(PSA_CRYPTO_DRIVER_TEST)
1801 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliotta218ceb2021-05-07 15:10:31 +01001802 return( mbedtls_test_transparent_aead_update_ad(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001803 &operation->ctx.transparent_test_driver_ctx,
1804 input, input_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001805
1806 /* Add cases for opaque driver here */
1807
1808#endif /* PSA_CRYPTO_DRIVER_TEST */
1809#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1810 }
1811
1812 (void)input;
1813 (void)input_length;
1814
1815 return( PSA_ERROR_INVALID_ARGUMENT );
1816}
1817
1818psa_status_t psa_driver_wrapper_aead_update(
1819 psa_aead_operation_t *operation,
1820 const uint8_t *input,
1821 size_t input_length,
1822 uint8_t *output,
1823 size_t output_size,
1824 size_t *output_length )
1825{
1826 switch( operation->id )
1827 {
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001828#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001829 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001830 return( mbedtls_psa_aead_update( &operation->ctx.mbedtls_ctx,
1831 input, input_length,
Paul Elliotta218ceb2021-05-07 15:10:31 +01001832 output, output_size,
1833 output_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001834
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001835#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001836
1837#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1838#if defined(PSA_CRYPTO_DRIVER_TEST)
1839 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliotta218ceb2021-05-07 15:10:31 +01001840 return( mbedtls_test_transparent_aead_update(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001841 &operation->ctx.transparent_test_driver_ctx,
1842 input, input_length, output, output_size,
Paul Elliott4bbe82b2021-04-27 12:11:56 +01001843 output_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001844
1845 /* Add cases for opaque driver here */
1846
1847#endif /* PSA_CRYPTO_DRIVER_TEST */
1848#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1849 }
1850
1851 (void)input;
1852 (void)input_length;
1853 (void)output;
1854 (void)output_size;
1855 (void)output_length;
1856
1857 return( PSA_ERROR_INVALID_ARGUMENT );
1858}
1859
1860psa_status_t psa_driver_wrapper_aead_finish(
1861 psa_aead_operation_t *operation,
1862 uint8_t *ciphertext,
1863 size_t ciphertext_size,
1864 size_t *ciphertext_length,
1865 uint8_t *tag,
1866 size_t tag_size,
1867 size_t *tag_length )
1868{
1869 switch( operation->id )
1870 {
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001871#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001872 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001873 return( mbedtls_psa_aead_finish( &operation->ctx.mbedtls_ctx,
1874 ciphertext,
Paul Elliotta218ceb2021-05-07 15:10:31 +01001875 ciphertext_size,
1876 ciphertext_length, tag,
1877 tag_size, tag_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001878
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001879#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001880
1881#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1882#if defined(PSA_CRYPTO_DRIVER_TEST)
1883 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliotta218ceb2021-05-07 15:10:31 +01001884 return( mbedtls_test_transparent_aead_finish(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001885 &operation->ctx.transparent_test_driver_ctx,
1886 ciphertext, ciphertext_size,
Paul Elliott4bbe82b2021-04-27 12:11:56 +01001887 ciphertext_length, tag, tag_size, tag_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001888
1889 /* Add cases for opaque driver here */
1890
1891#endif /* PSA_CRYPTO_DRIVER_TEST */
1892#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1893 }
1894
1895 (void)ciphertext;
1896 (void)ciphertext_size;
1897 (void)ciphertext_length;
1898 (void)tag;
1899 (void)tag_size;
1900 (void)tag_length;
1901
1902 return( PSA_ERROR_INVALID_ARGUMENT );
1903}
1904
1905psa_status_t psa_driver_wrapper_aead_verify(
1906 psa_aead_operation_t *operation,
1907 uint8_t *plaintext,
1908 size_t plaintext_size,
1909 size_t *plaintext_length,
1910 const uint8_t *tag,
1911 size_t tag_length )
1912{
1913 switch( operation->id )
1914 {
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001915#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001916 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliott315628d2021-07-20 18:25:54 +01001917 {
1918 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1919 uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE];
1920 size_t check_tag_length;
1921
1922 status = mbedtls_psa_aead_finish( &operation->ctx.mbedtls_ctx,
1923 plaintext,
1924 plaintext_size,
1925 plaintext_length,
1926 check_tag,
Paul Elliottb183d562021-09-13 19:02:57 +01001927 sizeof( check_tag ),
Paul Elliott315628d2021-07-20 18:25:54 +01001928 &check_tag_length );
1929
1930 if( status == PSA_SUCCESS )
1931 {
1932 if( tag_length != check_tag_length ||
1933 mbedtls_psa_safer_memcmp( tag, check_tag, tag_length )
1934 != 0 )
1935 status = PSA_ERROR_INVALID_SIGNATURE;
1936 }
1937
Paul Elliott06b6b8c2021-09-13 19:02:04 +01001938 mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) );
1939
Paul Elliott315628d2021-07-20 18:25:54 +01001940 return( status );
1941 }
Paul Elliott6504aa62021-04-20 17:09:36 +01001942
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001943#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001944
1945#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1946#if defined(PSA_CRYPTO_DRIVER_TEST)
1947 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliotta218ceb2021-05-07 15:10:31 +01001948 return( mbedtls_test_transparent_aead_verify(
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001949 &operation->ctx.transparent_test_driver_ctx,
1950 plaintext, plaintext_size,
Paul Elliott4bbe82b2021-04-27 12:11:56 +01001951 plaintext_length, tag, tag_length ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001952
1953 /* Add cases for opaque driver here */
1954
1955#endif /* PSA_CRYPTO_DRIVER_TEST */
1956#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1957 }
1958
1959 (void)plaintext;
1960 (void)plaintext_size;
1961 (void)plaintext_length;
1962 (void)tag;
1963 (void)tag_length;
1964
1965 return( PSA_ERROR_INVALID_ARGUMENT );
1966}
1967
1968psa_status_t psa_driver_wrapper_aead_abort(
1969 psa_aead_operation_t *operation )
1970{
1971 switch( operation->id )
1972 {
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001973#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott6504aa62021-04-20 17:09:36 +01001974 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001975 return( mbedtls_psa_aead_abort( &operation->ctx.mbedtls_ctx ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001976
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001977#endif /* MBEDTLS_PSA_BUILTIN_AEAD */
Paul Elliott6504aa62021-04-20 17:09:36 +01001978
1979#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
1980#if defined(PSA_CRYPTO_DRIVER_TEST)
1981 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Paul Elliottcbbde5f2021-05-10 18:19:46 +01001982 return( mbedtls_test_transparent_aead_abort(
1983 &operation->ctx.transparent_test_driver_ctx ) );
Paul Elliott6504aa62021-04-20 17:09:36 +01001984
1985 /* Add cases for opaque driver here */
1986
1987#endif /* PSA_CRYPTO_DRIVER_TEST */
1988#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
1989 }
1990
1991 return( PSA_ERROR_INVALID_ARGUMENT );
1992}
Steven Cooremand13a70f2021-03-19 15:24:23 +01001993
1994/*
1995 * MAC functions
1996 */
1997psa_status_t psa_driver_wrapper_mac_compute(
1998 const psa_key_attributes_t *attributes,
1999 const uint8_t *key_buffer,
2000 size_t key_buffer_size,
2001 psa_algorithm_t alg,
2002 const uint8_t *input,
2003 size_t input_length,
2004 uint8_t *mac,
2005 size_t mac_size,
2006 size_t *mac_length )
2007{
2008 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2009 psa_key_location_t location =
2010 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
2011
2012 switch( location )
2013 {
2014 case PSA_KEY_LOCATION_LOCAL_STORAGE:
2015 /* Key is stored in the slot in export representation, so
2016 * cycle through all known transparent accelerators */
2017#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2018#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002019 status = mbedtls_test_transparent_mac_compute(
Steven Cooremand13a70f2021-03-19 15:24:23 +01002020 attributes, key_buffer, key_buffer_size, alg,
2021 input, input_length,
2022 mac, mac_size, mac_length );
2023 /* Declared with fallback == true */
2024 if( status != PSA_ERROR_NOT_SUPPORTED )
2025 return( status );
2026#endif /* PSA_CRYPTO_DRIVER_TEST */
2027#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2028#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2029 /* Fell through, meaning no accelerator supports this operation */
2030 status = mbedtls_psa_mac_compute(
2031 attributes, key_buffer, key_buffer_size, alg,
2032 input, input_length,
2033 mac, mac_size, mac_length );
2034 if( status != PSA_ERROR_NOT_SUPPORTED )
2035 return( status );
2036#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2037 return( PSA_ERROR_NOT_SUPPORTED );
2038
2039 /* Add cases for opaque driver here */
2040#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2041#if defined(PSA_CRYPTO_DRIVER_TEST)
2042 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002043 status = mbedtls_test_opaque_mac_compute(
Steven Cooremand13a70f2021-03-19 15:24:23 +01002044 attributes, key_buffer, key_buffer_size, alg,
2045 input, input_length,
2046 mac, mac_size, mac_length );
2047 return( status );
2048#endif /* PSA_CRYPTO_DRIVER_TEST */
2049#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2050 default:
2051 /* Key is declared with a lifetime not known to us */
2052 (void) key_buffer;
2053 (void) key_buffer_size;
2054 (void) alg;
2055 (void) input;
2056 (void) input_length;
2057 (void) mac;
2058 (void) mac_size;
2059 (void) mac_length;
2060 (void) status;
2061 return( PSA_ERROR_INVALID_ARGUMENT );
2062 }
2063}
2064
2065psa_status_t psa_driver_wrapper_mac_sign_setup(
2066 psa_mac_operation_t *operation,
2067 const psa_key_attributes_t *attributes,
2068 const uint8_t *key_buffer,
2069 size_t key_buffer_size,
2070 psa_algorithm_t alg )
2071{
2072 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2073 psa_key_location_t location =
2074 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
2075
2076 switch( location )
2077 {
2078 case PSA_KEY_LOCATION_LOCAL_STORAGE:
2079 /* Key is stored in the slot in export representation, so
2080 * cycle through all known transparent accelerators */
2081#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2082#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002083 status = mbedtls_test_transparent_mac_sign_setup(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002084 &operation->ctx.transparent_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002085 attributes,
2086 key_buffer, key_buffer_size,
2087 alg );
2088 /* Declared with fallback == true */
2089 if( status == PSA_SUCCESS )
2090 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
2091
2092 if( status != PSA_ERROR_NOT_SUPPORTED )
2093 return( status );
2094#endif /* PSA_CRYPTO_DRIVER_TEST */
2095#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2096#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2097 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002098 status = mbedtls_psa_mac_sign_setup( &operation->ctx.mbedtls_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002099 attributes,
2100 key_buffer, key_buffer_size,
2101 alg );
2102 if( status == PSA_SUCCESS )
2103 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
2104
2105 if( status != PSA_ERROR_NOT_SUPPORTED )
2106 return( status );
2107#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2108 return( PSA_ERROR_NOT_SUPPORTED );
2109
2110 /* Add cases for opaque driver here */
2111#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2112#if defined(PSA_CRYPTO_DRIVER_TEST)
2113 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002114 status = mbedtls_test_opaque_mac_sign_setup(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002115 &operation->ctx.opaque_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002116 attributes,
2117 key_buffer, key_buffer_size,
2118 alg );
2119
2120 if( status == PSA_SUCCESS )
2121 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
2122
2123 return( status );
2124#endif /* PSA_CRYPTO_DRIVER_TEST */
2125#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2126 default:
2127 /* Key is declared with a lifetime not known to us */
2128 (void) status;
Ronald Cron7a55deb2021-04-28 14:29:00 +02002129 (void) operation;
Steven Cooremand13a70f2021-03-19 15:24:23 +01002130 (void) key_buffer;
2131 (void) key_buffer_size;
2132 (void) alg;
2133 return( PSA_ERROR_INVALID_ARGUMENT );
2134 }
2135}
2136
2137psa_status_t psa_driver_wrapper_mac_verify_setup(
2138 psa_mac_operation_t *operation,
2139 const psa_key_attributes_t *attributes,
2140 const uint8_t *key_buffer,
2141 size_t key_buffer_size,
2142 psa_algorithm_t alg )
2143{
2144 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2145 psa_key_location_t location =
2146 PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
2147
2148 switch( location )
2149 {
2150 case PSA_KEY_LOCATION_LOCAL_STORAGE:
2151 /* Key is stored in the slot in export representation, so
2152 * cycle through all known transparent accelerators */
2153#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2154#if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002155 status = mbedtls_test_transparent_mac_verify_setup(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002156 &operation->ctx.transparent_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002157 attributes,
2158 key_buffer, key_buffer_size,
2159 alg );
2160 /* Declared with fallback == true */
2161 if( status == PSA_SUCCESS )
2162 operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
2163
2164 if( status != PSA_ERROR_NOT_SUPPORTED )
2165 return( status );
2166#endif /* PSA_CRYPTO_DRIVER_TEST */
2167#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2168#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2169 /* Fell through, meaning no accelerator supports this operation */
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002170 status = mbedtls_psa_mac_verify_setup( &operation->ctx.mbedtls_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002171 attributes,
2172 key_buffer, key_buffer_size,
2173 alg );
2174 if( status == PSA_SUCCESS )
2175 operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
2176
2177 if( status != PSA_ERROR_NOT_SUPPORTED )
2178 return( status );
2179#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2180 return( PSA_ERROR_NOT_SUPPORTED );
2181
2182 /* Add cases for opaque driver here */
2183#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2184#if defined(PSA_CRYPTO_DRIVER_TEST)
2185 case PSA_CRYPTO_TEST_DRIVER_LOCATION:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002186 status = mbedtls_test_opaque_mac_verify_setup(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002187 &operation->ctx.opaque_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002188 attributes,
2189 key_buffer, key_buffer_size,
2190 alg );
2191
2192 if( status == PSA_SUCCESS )
2193 operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
2194
2195 return( status );
2196#endif /* PSA_CRYPTO_DRIVER_TEST */
2197#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2198 default:
2199 /* Key is declared with a lifetime not known to us */
2200 (void) status;
Ronald Cron7a55deb2021-04-28 14:29:00 +02002201 (void) operation;
Steven Cooremand13a70f2021-03-19 15:24:23 +01002202 (void) key_buffer;
2203 (void) key_buffer_size;
2204 (void) alg;
2205 return( PSA_ERROR_INVALID_ARGUMENT );
2206 }
2207}
2208
2209psa_status_t psa_driver_wrapper_mac_update(
2210 psa_mac_operation_t *operation,
2211 const uint8_t *input,
2212 size_t input_length )
2213{
2214 switch( operation->id )
2215 {
2216#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2217 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002218 return( mbedtls_psa_mac_update( &operation->ctx.mbedtls_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002219 input, input_length ) );
2220#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2221
2222#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2223#if defined(PSA_CRYPTO_DRIVER_TEST)
2224 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002225 return( mbedtls_test_transparent_mac_update(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002226 &operation->ctx.transparent_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002227 input, input_length ) );
2228
2229 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002230 return( mbedtls_test_opaque_mac_update(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002231 &operation->ctx.opaque_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002232 input, input_length ) );
2233#endif /* PSA_CRYPTO_DRIVER_TEST */
2234#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2235 default:
2236 (void) input;
2237 (void) input_length;
2238 return( PSA_ERROR_INVALID_ARGUMENT );
2239 }
2240}
2241
2242psa_status_t psa_driver_wrapper_mac_sign_finish(
2243 psa_mac_operation_t *operation,
2244 uint8_t *mac,
2245 size_t mac_size,
2246 size_t *mac_length )
2247{
2248 switch( operation->id )
2249 {
2250#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2251 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002252 return( mbedtls_psa_mac_sign_finish( &operation->ctx.mbedtls_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002253 mac, mac_size, mac_length ) );
2254#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2255
2256#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2257#if defined(PSA_CRYPTO_DRIVER_TEST)
2258 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002259 return( mbedtls_test_transparent_mac_sign_finish(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002260 &operation->ctx.transparent_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002261 mac, mac_size, mac_length ) );
2262
2263 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002264 return( mbedtls_test_opaque_mac_sign_finish(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002265 &operation->ctx.opaque_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002266 mac, mac_size, mac_length ) );
2267#endif /* PSA_CRYPTO_DRIVER_TEST */
2268#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2269 default:
2270 (void) mac;
2271 (void) mac_size;
2272 (void) mac_length;
2273 return( PSA_ERROR_INVALID_ARGUMENT );
2274 }
2275}
2276
2277psa_status_t psa_driver_wrapper_mac_verify_finish(
2278 psa_mac_operation_t *operation,
2279 const uint8_t *mac,
2280 size_t mac_length )
2281{
2282 switch( operation->id )
2283 {
2284#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2285 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002286 return( mbedtls_psa_mac_verify_finish( &operation->ctx.mbedtls_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002287 mac, mac_length ) );
2288#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2289
2290#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2291#if defined(PSA_CRYPTO_DRIVER_TEST)
2292 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002293 return( mbedtls_test_transparent_mac_verify_finish(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002294 &operation->ctx.transparent_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002295 mac, mac_length ) );
2296
2297 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002298 return( mbedtls_test_opaque_mac_verify_finish(
Steven Cooreman77e2cc52021-03-19 17:05:52 +01002299 &operation->ctx.opaque_test_driver_ctx,
Steven Cooremand13a70f2021-03-19 15:24:23 +01002300 mac, mac_length ) );
2301#endif /* PSA_CRYPTO_DRIVER_TEST */
2302#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2303 default:
2304 (void) mac;
2305 (void) mac_length;
2306 return( PSA_ERROR_INVALID_ARGUMENT );
2307 }
2308}
2309
2310psa_status_t psa_driver_wrapper_mac_abort(
2311 psa_mac_operation_t *operation )
2312{
Steven Cooremand13a70f2021-03-19 15:24:23 +01002313 switch( operation->id )
2314 {
2315#if defined(MBEDTLS_PSA_BUILTIN_MAC)
2316 case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
Steven Cooremane6804192021-03-19 18:28:56 +01002317 return( mbedtls_psa_mac_abort( &operation->ctx.mbedtls_ctx ) );
Steven Cooremand13a70f2021-03-19 15:24:23 +01002318#endif /* MBEDTLS_PSA_BUILTIN_MAC */
2319
2320#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
2321#if defined(PSA_CRYPTO_DRIVER_TEST)
2322 case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002323 return( mbedtls_test_transparent_mac_abort(
Steven Cooremane6804192021-03-19 18:28:56 +01002324 &operation->ctx.transparent_test_driver_ctx ) );
Steven Cooremand13a70f2021-03-19 15:24:23 +01002325 case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
Steven Cooremanc7f0a572021-04-29 21:10:11 +02002326 return( mbedtls_test_opaque_mac_abort(
Steven Cooremane6804192021-03-19 18:28:56 +01002327 &operation->ctx.opaque_test_driver_ctx ) );
Steven Cooremand13a70f2021-03-19 15:24:23 +01002328#endif /* PSA_CRYPTO_DRIVER_TEST */
2329#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
2330 default:
Steven Cooremane6804192021-03-19 18:28:56 +01002331 return( PSA_ERROR_INVALID_ARGUMENT );
Steven Cooremand13a70f2021-03-19 15:24:23 +01002332 }
Steven Cooremand13a70f2021-03-19 15:24:23 +01002333}
Gilles Peskine1905a242021-04-24 13:19:45 +02002334
2335#endif /* MBEDTLS_PSA_CRYPTO_C */