1From 49e1f6ec6bc1a5a52a82b0cbb423db7c361f2896 Mon Sep 17 00:00:00 2001
2From: Antonio de Angelis <Antonio.deAngelis@arm.com>
3Date: Thu, 21 Mar 2024 12:58:37 +0000
4Subject: [PATCH 5/6] Hardcode CC3XX entry points
5
6Manually hardcode PSA driver entry points for the CC3XX driver
7into psa crypto driver wrappers file (and provide missing entry point
8definitions if any). This is a temporary solution until the codegen
9framework is available for automatic integration.
10
11Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
12---
13 .../psa/crypto_driver_contexts_composites.h   |  10 +
14 .../psa/crypto_driver_contexts_primitives.h   |  10 +
15 library/psa_crypto_driver_wrappers.h          | 426 ++++++++++++++++--
16 .../psa_crypto_driver_wrappers_no_static.c    |  24 +
17 4 files changed, 441 insertions(+), 29 deletions(-)
18
19diff --git a/include/psa/crypto_driver_contexts_composites.h b/include/psa/crypto_driver_contexts_composites.h
20index d717c5190..f6a54aefd 100644
21--- a/include/psa/crypto_driver_contexts_composites.h
22+++ b/include/psa/crypto_driver_contexts_composites.h
23@@ -30,6 +30,10 @@
24 /* Include the context structure definitions for those drivers that were
25  * declared during the autogeneration process. */
26
27+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
28+#include "cc3xx_crypto_primitives_private.h"
29+#endif
30+
31 #if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
32 #include <libtestdriver1/include/psa/crypto.h>
33 #endif
34@@ -118,6 +122,9 @@ typedef union {
35     mbedtls_transparent_test_driver_mac_operation_t transparent_test_driver_ctx;
36     mbedtls_opaque_test_driver_mac_operation_t opaque_test_driver_ctx;
37 #endif
38+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
39+    cc3xx_mac_operation_t cc3xx_driver_ctx;
40+#endif
41 } psa_driver_mac_context_t;
42
43 typedef union {
44@@ -126,6 +133,9 @@ typedef union {
45 #if defined(PSA_CRYPTO_DRIVER_TEST)
46     mbedtls_transparent_test_driver_aead_operation_t transparent_test_driver_ctx;
47 #endif
48+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
49+    cc3xx_aead_operation_t cc3xx_driver_ctx;
50+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
51 } psa_driver_aead_context_t;
52
53 typedef union {
54diff --git a/include/psa/crypto_driver_contexts_primitives.h b/include/psa/crypto_driver_contexts_primitives.h
55index c90a5fbe7..3f00006f8 100644
56--- a/include/psa/crypto_driver_contexts_primitives.h
57+++ b/include/psa/crypto_driver_contexts_primitives.h
58@@ -29,6 +29,10 @@
59 /* Include the context structure definitions for those drivers that were
60  * declared during the autogeneration process. */
61
62+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
63+#include "cc3xx_crypto_primitives_private.h"
64+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
65+
66 #if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
67 #include <libtestdriver1/include/psa/crypto.h>
68 #endif
69@@ -90,6 +94,9 @@ typedef union {
70 #if defined(PSA_CRYPTO_DRIVER_TEST)
71     mbedtls_transparent_test_driver_hash_operation_t test_driver_ctx;
72 #endif
73+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
74+    cc3xx_hash_operation_t cc3xx_driver_ctx;
75+#endif
76 } psa_driver_hash_context_t;
77
78 typedef union {
79@@ -99,6 +106,9 @@ typedef union {
80     mbedtls_transparent_test_driver_cipher_operation_t transparent_test_driver_ctx;
81     mbedtls_opaque_test_driver_cipher_operation_t opaque_test_driver_ctx;
82 #endif
83+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
84+    cc3xx_cipher_operation_t cc3xx_driver_ctx;
85+#endif
86 } psa_driver_cipher_context_t;
87
88 #endif /* PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H */
89diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h
90index 2e828115f..3a8f3a0f9 100644
91--- a/library/psa_crypto_driver_wrappers.h
92+++ b/library/psa_crypto_driver_wrappers.h
93@@ -53,6 +53,16 @@
94 #include "tfm_builtin_key_loader.h"
95 #endif /* PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER */
96
97+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
98+#ifndef PSA_CRYPTO_DRIVER_PRESENT
99+#define PSA_CRYPTO_DRIVER_PRESENT
100+#endif
101+#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
102+#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
103+#endif
104+#include "cc3xx.h"
105+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
106+
107 /* END-driver headers */
108
109 /* Auto-generated values depending on which drivers are registered.
110@@ -67,6 +77,9 @@ enum {
111 #if defined(PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER)
112     PSA_CRYPTO_TFM_BUILTIN_KEY_LOADER_DRIVER_ID,
113 #endif /* PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER */
114+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
115+    PSA_CRYPTO_CC3XX_DRIVER_ID,
116+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
117 };
118
119 /* END-driver id */
120@@ -111,6 +124,12 @@ static inline psa_status_t psa_driver_wrapper_init( void )
121         return( status );
122 #endif
123
124+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
125+    status = cc3xx_init();
126+    if (status != PSA_SUCCESS)
127+        return ( status );
128+#endif
129+
130     (void) status;
131     return( PSA_SUCCESS );
132 }
133@@ -127,6 +146,10 @@ static inline void psa_driver_wrapper_free( void )
134     mbedtls_test_transparent_free( );
135     mbedtls_test_opaque_free( );
136 #endif
137+
138+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
139+    (void)cc3xx_free();
140+#endif
141 }
142
143 /* Start delegation functions */
144@@ -169,7 +192,29 @@ static inline psa_status_t psa_driver_wrapper_sign_message(
145             if( status != PSA_ERROR_NOT_SUPPORTED )
146                 return( status );
147 #endif /* PSA_CRYPTO_DRIVER_TEST */
148-#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
149+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
150+            status = cc3xx_sign_message(
151+                        attributes,
152+                        key_buffer,
153+                        key_buffer_size,
154+                        alg,
155+                        input,
156+                        input_length,
157+                        signature,
158+                        signature_size,
159+                        signature_length );
160+            return( status );
161+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
162+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
163+            return( psa_sign_message_builtin( attributes,
164+                                              key_buffer,
165+                                              key_buffer_size,
166+                                              alg,
167+                                              input,
168+                                              input_length,
169+                                              signature,
170+                                              signature_size,
171+                                              signature_length ) );
172             break;
173
174         /* Add cases for opaque driver here */
175@@ -194,18 +239,8 @@ static inline psa_status_t psa_driver_wrapper_sign_message(
176         default:
177             /* Key is declared with a lifetime not known to us */
178             (void)status;
179-            break;
180+            return( PSA_ERROR_INVALID_ARGUMENT );
181     }
182-
183-    return( psa_sign_message_builtin( attributes,
184-                                      key_buffer,
185-                                      key_buffer_size,
186-                                      alg,
187-                                      input,
188-                                      input_length,
189-                                      signature,
190-                                      signature_size,
191-                                      signature_length ) );
192 }
193
194 static inline psa_status_t psa_driver_wrapper_verify_message(
195@@ -245,8 +280,27 @@ static inline psa_status_t psa_driver_wrapper_verify_message(
196             if( status != PSA_ERROR_NOT_SUPPORTED )
197                 return( status );
198 #endif /* PSA_CRYPTO_DRIVER_TEST */
199+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
200+            status = cc3xx_verify_message(
201+                        attributes,
202+                        key_buffer,
203+                        key_buffer_size,
204+                        alg,
205+                        input,
206+                        input_length,
207+                        signature,
208+                        signature_length );
209+            return( status );
210+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
211 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
212-            break;
213+            return( psa_verify_message_builtin( attributes,
214+                                                key_buffer,
215+                                                key_buffer_size,
216+                                                alg,
217+                                                input,
218+                                                input_length,
219+                                                signature,
220+                                                signature_length ) );
221
222         /* Add cases for opaque driver here */
223 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
224@@ -269,17 +323,8 @@ static inline psa_status_t psa_driver_wrapper_verify_message(
225         default:
226             /* Key is declared with a lifetime not known to us */
227             (void)status;
228-            break;
229+            return( PSA_ERROR_INVALID_ARGUMENT );
230     }
231-
232-    return( psa_verify_message_builtin( attributes,
233-                                        key_buffer,
234-                                        key_buffer_size,
235-                                        alg,
236-                                        input,
237-                                        input_length,
238-                                        signature,
239-                                        signature_length ) );
240 }
241
242 static inline psa_status_t psa_driver_wrapper_sign_hash(
243@@ -335,6 +380,18 @@ static inline psa_status_t psa_driver_wrapper_sign_hash(
244             if( status != PSA_ERROR_NOT_SUPPORTED )
245                 return( status );
246 #endif /* PSA_CRYPTO_DRIVER_TEST */
247+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
248+            status = cc3xx_sign_hash( attributes,
249+                                      key_buffer,
250+                                      key_buffer_size,
251+                                      alg,
252+                                      hash,
253+                                      hash_length,
254+                                      signature,
255+                                      signature_size,
256+                                      signature_length );
257+            return( status );
258+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
259 #if defined (MBEDTLS_PSA_P256M_DRIVER_ENABLED)
260             if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) &&
261                 PSA_ALG_IS_ECDSA(alg) &&
262@@ -442,6 +499,17 @@ static inline psa_status_t psa_driver_wrapper_verify_hash(
263             if( status != PSA_ERROR_NOT_SUPPORTED )
264                 return( status );
265 #endif /* PSA_CRYPTO_DRIVER_TEST */
266+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
267+            status = cc3xx_verify_hash( attributes,
268+                                        key_buffer,
269+                                        key_buffer_size,
270+                                        alg,
271+                                        hash,
272+                                        hash_length,
273+                                        signature,
274+                                        signature_length );
275+            return( status );
276+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
277 #if defined (MBEDTLS_PSA_P256M_DRIVER_ENABLED)
278             if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) &&
279                 PSA_ALG_IS_ECDSA(alg) &&
280@@ -835,6 +903,12 @@ static inline psa_status_t psa_driver_wrapper_generate_key(
281                 if( status != PSA_ERROR_NOT_SUPPORTED )
282                     break;
283 #endif /* PSA_CRYPTO_DRIVER_TEST */
284+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
285+                status = cc3xx_generate_key(
286+                    attributes, key_buffer, key_buffer_size,
287+                    key_buffer_length );
288+                break;
289+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
290 #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED)
291                 if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) &&
292                     psa_get_key_type(attributes) == PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1) &&
293@@ -1158,6 +1232,20 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt(
294             if( status != PSA_ERROR_NOT_SUPPORTED )
295                 return( status );
296 #endif /* PSA_CRYPTO_DRIVER_TEST */
297+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
298+            status = cc3xx_cipher_encrypt( attributes,
299+                                           key_buffer,
300+                                           key_buffer_size,
301+                                           alg,
302+                                           iv,
303+                                           iv_length,
304+                                           input,
305+                                           input_length,
306+                                           output,
307+                                           output_size,
308+                                           output_length );
309+            return( status );
310+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
311 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
312
313 #if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
314@@ -1249,6 +1337,18 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt(
315             if( status != PSA_ERROR_NOT_SUPPORTED )
316                 return( status );
317 #endif /* PSA_CRYPTO_DRIVER_TEST */
318+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
319+            status = cc3xx_cipher_decrypt( attributes,
320+                                           key_buffer,
321+                                           key_buffer_size,
322+                                           alg,
323+                                           input,
324+                                           input_length,
325+                                           output,
326+                                           output_size,
327+                                           output_length );
328+            return( status );
329+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
330 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
331
332 #if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
333@@ -1329,6 +1429,16 @@ static inline psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
334             if( status != PSA_ERROR_NOT_SUPPORTED )
335                 return( status );
336 #endif /* PSA_CRYPTO_DRIVER_TEST */
337+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
338+            status = cc3xx_cipher_encrypt_setup(
339+                &operation->ctx.cc3xx_driver_ctx,
340+                attributes,
341+                key_buffer,
342+                key_buffer_size,
343+                alg );
344+            operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
345+            return( status );
346+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
347 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
348 #if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
349             /* Fell through, meaning no accelerator supports this operation */
350@@ -1405,6 +1515,16 @@ static inline psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
351             if( status != PSA_ERROR_NOT_SUPPORTED )
352                 return( status );
353 #endif /* PSA_CRYPTO_DRIVER_TEST */
354+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
355+            status = cc3xx_cipher_decrypt_setup(
356+                &operation->ctx.cc3xx_driver_ctx,
357+                attributes,
358+                key_buffer,
359+                key_buffer_size,
360+                alg );
361+            operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
362+            return( status );
363+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
364 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
365 #if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
366             /* Fell through, meaning no accelerator supports this operation */
367@@ -1474,6 +1594,12 @@ static inline psa_status_t psa_driver_wrapper_cipher_set_iv(
368                         &operation->ctx.opaque_test_driver_ctx,
369                         iv, iv_length ) );
370 #endif /* PSA_CRYPTO_DRIVER_TEST */
371+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
372+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
373+            return( cc3xx_cipher_set_iv(
374+                        &operation->ctx.cc3xx_driver_ctx,
375+                        iv, iv_length ) );
376+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
377 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
378     }
379
380@@ -1517,6 +1643,13 @@ static inline psa_status_t psa_driver_wrapper_cipher_update(
381                         input, input_length,
382                         output, output_size, output_length ) );
383 #endif /* PSA_CRYPTO_DRIVER_TEST */
384+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
385+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
386+            return( cc3xx_cipher_update(
387+                        &operation->ctx.cc3xx_driver_ctx,
388+                        input, input_length,
389+                        output, output_size, output_length ) );
390+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
391 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
392     }
393
394@@ -1557,6 +1690,12 @@ static inline psa_status_t psa_driver_wrapper_cipher_finish(
395                         &operation->ctx.opaque_test_driver_ctx,
396                         output, output_size, output_length ) );
397 #endif /* PSA_CRYPTO_DRIVER_TEST */
398+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
399+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
400+            return( cc3xx_cipher_finish(
401+                        &operation->ctx.cc3xx_driver_ctx,
402+                        output, output_size, output_length ) );
403+#endif /* PSA_CRYPTO_DRIVER_CC3XX*/
404 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
405     }
406
407@@ -1597,6 +1736,15 @@ static inline psa_status_t psa_driver_wrapper_cipher_abort(
408                 sizeof( operation->ctx.opaque_test_driver_ctx ) );
409             return( status );
410 #endif /* PSA_CRYPTO_DRIVER_TEST */
411+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
412+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
413+            status = cc3xx_cipher_abort(
414+                         &operation->ctx.cc3xx_driver_ctx );
415+            mbedtls_platform_zeroize(
416+                &operation->ctx.cc3xx_driver_ctx,
417+                sizeof( operation->ctx.cc3xx_driver_ctx ) );
418+            return( status );
419+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
420 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
421     }
422
423@@ -1618,12 +1766,19 @@ static inline psa_status_t psa_driver_wrapper_hash_compute(
424     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
425
426     /* Try accelerators first */
427+#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
428 #if defined(PSA_CRYPTO_DRIVER_TEST)
429     status = mbedtls_test_transparent_hash_compute(
430                 alg, input, input_length, hash, hash_size, hash_length );
431     if( status != PSA_ERROR_NOT_SUPPORTED )
432         return( status );
433-#endif
434+#endif /* PSA_CRYPTO_DRIVER_TEST */
435+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
436+    status = cc3xx_hash_compute(alg, input, input_length, hash, hash_size,
437+            hash_length);
438+    return status;
439+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
440+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
441
442     /* If software fallback is compiled in, try fallback */
443 #if defined(MBEDTLS_PSA_BUILTIN_HASH)
444@@ -1650,6 +1805,7 @@ static inline psa_status_t psa_driver_wrapper_hash_setup(
445     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
446
447     /* Try setup on accelerators first */
448+#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
449 #if defined(PSA_CRYPTO_DRIVER_TEST)
450     status = mbedtls_test_transparent_hash_setup(
451                 &operation->ctx.test_driver_ctx, alg );
452@@ -1658,7 +1814,18 @@ static inline psa_status_t psa_driver_wrapper_hash_setup(
453
454     if( status != PSA_ERROR_NOT_SUPPORTED )
455         return( status );
456-#endif
457+#endif /* PSA_CRYPTO_DRIVER_TEST */
458+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
459+    status = cc3xx_hash_setup(&operation->ctx.cc3xx_driver_ctx, alg);
460+    operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
461+#if defined(PSA_WANT_ALG_SHA_384) || defined(PSA_WANT_ALG_SHA_512)
462+    if( status != PSA_ERROR_NOT_SUPPORTED )
463+        return( status );
464+#else
465+    return( status );
466+#endif /* defined(PSA_WANT_ALG_SHA_384) || defined(PSA_WANT_ALG_SHA_512) */
467+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
468+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
469
470     /* If software fallback is compiled in, try fallback */
471 #if defined(MBEDTLS_PSA_BUILTIN_HASH)
472@@ -1688,13 +1855,23 @@ static inline psa_status_t psa_driver_wrapper_hash_clone(
473             return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx,
474                                             &target_operation->ctx.mbedtls_ctx ) );
475 #endif
476+#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
477 #if defined(PSA_CRYPTO_DRIVER_TEST)
478         case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
479             target_operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
480             return( mbedtls_test_transparent_hash_clone(
481                         &source_operation->ctx.test_driver_ctx,
482                         &target_operation->ctx.test_driver_ctx ) );
483-#endif
484+#endif /* PSA_CRYPTO_DRIVER_TEST */
485+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
486+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
487+            target_operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
488+            return( cc3xx_hash_clone(
489+                        &source_operation->ctx.cc3xx_driver_ctx,
490+                        &target_operation->ctx.cc3xx_driver_ctx ) );
491+
492+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
493+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
494         default:
495             (void) target_operation;
496             return( PSA_ERROR_BAD_STATE );
497@@ -1713,12 +1890,20 @@ static inline psa_status_t psa_driver_wrapper_hash_update(
498             return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx,
499                                              input, input_length ) );
500 #endif
501+#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
502 #if defined(PSA_CRYPTO_DRIVER_TEST)
503         case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
504             return( mbedtls_test_transparent_hash_update(
505                         &operation->ctx.test_driver_ctx,
506                         input, input_length ) );
507-#endif
508+#endif /* PSA_CRYPTO_DRIVER_TEST */
509+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
510+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
511+            return( cc3xx_hash_update(
512+                        &operation->ctx.cc3xx_driver_ctx,
513+                        input, input_length ) );
514+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
515+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
516         default:
517             (void) input;
518             (void) input_length;
519@@ -1739,12 +1924,20 @@ static inline psa_status_t psa_driver_wrapper_hash_finish(
520             return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx,
521                                              hash, hash_size, hash_length ) );
522 #endif
523+#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
524 #if defined(PSA_CRYPTO_DRIVER_TEST)
525         case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
526             return( mbedtls_test_transparent_hash_finish(
527                         &operation->ctx.test_driver_ctx,
528                         hash, hash_size, hash_length ) );
529-#endif
530+#endif /* PSA_CRYPTO_DRIVER_TEST */
531+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
532+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
533+            return( cc3xx_hash_finish(
534+                        &operation->ctx.cc3xx_driver_ctx,
535+                        hash, hash_size, hash_length ) );
536+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
537+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
538         default:
539             (void) hash;
540             (void) hash_size;
541@@ -1762,11 +1955,18 @@ static inline psa_status_t psa_driver_wrapper_hash_abort(
542         case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
543             return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) );
544 #endif
545+#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
546 #if defined(PSA_CRYPTO_DRIVER_TEST)
547         case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
548             return( mbedtls_test_transparent_hash_abort(
549                         &operation->ctx.test_driver_ctx ) );
550-#endif
551+#endif /* PSA_CRYPTO_DRIVER_TEST */
552+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
553+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
554+            return( cc3xx_hash_abort(
555+                        &operation->ctx.cc3xx_driver_ctx ) );
556+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
557+#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
558         default:
559             return( PSA_ERROR_BAD_STATE );
560     }
561@@ -1807,6 +2007,17 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt(
562             if( status != PSA_ERROR_NOT_SUPPORTED )
563                 return( status );
564 #endif /* PSA_CRYPTO_DRIVER_TEST */
565+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
566+            status = cc3xx_aead_encrypt(
567+                        attributes, key_buffer, key_buffer_size,
568+                        alg,
569+                        nonce, nonce_length,
570+                        additional_data, additional_data_length,
571+                        plaintext, plaintext_length,
572+                        ciphertext, ciphertext_size, ciphertext_length );
573+
574+            return( status );
575+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
576 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
577
578             /* Fell through, meaning no accelerator supports this operation */
579@@ -1862,6 +2073,17 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt(
580             if( status != PSA_ERROR_NOT_SUPPORTED )
581                 return( status );
582 #endif /* PSA_CRYPTO_DRIVER_TEST */
583+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
584+            status = cc3xx_aead_decrypt(
585+                        attributes, key_buffer, key_buffer_size,
586+                        alg,
587+                        nonce, nonce_length,
588+                        additional_data, additional_data_length,
589+                        ciphertext, ciphertext_length,
590+                        plaintext, plaintext_size, plaintext_length );
591+
592+            return( status );
593+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
594 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
595
596             /* Fell through, meaning no accelerator supports this operation */
597@@ -1913,6 +2135,15 @@ static inline psa_status_t psa_driver_wrapper_aead_encrypt_setup(
598             if( status != PSA_ERROR_NOT_SUPPORTED )
599                 return( status );
600 #endif /* PSA_CRYPTO_DRIVER_TEST */
601+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
602+            operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
603+            status = cc3xx_aead_encrypt_setup(
604+                    &operation->ctx.cc3xx_driver_ctx,
605+                    attributes, key_buffer, key_buffer_size,
606+                    alg );
607+
608+            return( status );
609+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
610 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
611
612             /* Fell through, meaning no accelerator supports this operation */
613@@ -1965,6 +2196,16 @@ static inline psa_status_t psa_driver_wrapper_aead_decrypt_setup(
614             if( status != PSA_ERROR_NOT_SUPPORTED )
615                 return( status );
616 #endif /* PSA_CRYPTO_DRIVER_TEST */
617+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
618+            operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
619+            status = cc3xx_aead_decrypt_setup(
620+                    &operation->ctx.cc3xx_driver_ctx,
621+                    attributes,
622+                    key_buffer, key_buffer_size,
623+                    alg );
624+
625+            return( status );
626+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
627 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
628
629             /* Fell through, meaning no accelerator supports this operation */
630@@ -2011,6 +2252,12 @@ static inline psa_status_t psa_driver_wrapper_aead_set_nonce(
631         /* Add cases for opaque driver here */
632
633 #endif /* PSA_CRYPTO_DRIVER_TEST */
634+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
635+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
636+            return( cc3xx_aead_set_nonce(
637+                        &operation->ctx.cc3xx_driver_ctx,
638+                        nonce, nonce_length ) );
639+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
640 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
641     }
642
643@@ -2045,6 +2292,12 @@ static inline psa_status_t psa_driver_wrapper_aead_set_lengths(
644         /* Add cases for opaque driver here */
645
646 #endif /* PSA_CRYPTO_DRIVER_TEST */
647+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
648+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
649+            return( cc3xx_aead_set_lengths(
650+                    &operation->ctx.cc3xx_driver_ctx,
651+                    ad_length, plaintext_length ) );
652+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
653 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
654     }
655
656@@ -2079,6 +2332,12 @@ static inline psa_status_t psa_driver_wrapper_aead_update_ad(
657         /* Add cases for opaque driver here */
658
659 #endif /* PSA_CRYPTO_DRIVER_TEST */
660+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
661+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
662+            return( cc3xx_aead_update_ad(
663+                    &operation->ctx.cc3xx_driver_ctx,
664+                    input, input_length ) );
665+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
666 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
667     }
668
669@@ -2118,6 +2377,13 @@ static inline psa_status_t psa_driver_wrapper_aead_update(
670         /* Add cases for opaque driver here */
671
672 #endif /* PSA_CRYPTO_DRIVER_TEST */
673+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
674+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
675+            return( cc3xx_aead_update(
676+                    &operation->ctx.cc3xx_driver_ctx,
677+                    input, input_length, output, output_size,
678+                    output_length ) );
679+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
680 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
681     }
682
683@@ -2162,6 +2428,13 @@ static inline psa_status_t psa_driver_wrapper_aead_finish(
684         /* Add cases for opaque driver here */
685
686 #endif /* PSA_CRYPTO_DRIVER_TEST */
687+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
688+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
689+            return( cc3xx_aead_finish(
690+                    &operation->ctx.cc3xx_driver_ctx,
691+                    ciphertext, ciphertext_size,
692+                    ciphertext_length, tag, tag_size, tag_length ) );
693+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
694 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
695     }
696
697@@ -2226,6 +2499,13 @@ static inline psa_status_t psa_driver_wrapper_aead_verify(
698         /* Add cases for opaque driver here */
699
700 #endif /* PSA_CRYPTO_DRIVER_TEST */
701+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
702+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
703+            return( cc3xx_aead_verify(
704+                    &operation->ctx.cc3xx_driver_ctx,
705+                    plaintext, plaintext_size,
706+                    plaintext_length, tag, tag_length ) );
707+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
708 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
709     }
710
711@@ -2258,6 +2538,11 @@ static inline psa_status_t psa_driver_wrapper_aead_abort(
712         /* Add cases for opaque driver here */
713
714 #endif /* PSA_CRYPTO_DRIVER_TEST */
715+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
716+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
717+            return( cc3xx_aead_abort(
718+                    &operation->ctx.cc3xx_driver_ctx ) );
719+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
720 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
721     }
722
723@@ -2300,6 +2585,12 @@ static inline psa_status_t psa_driver_wrapper_mac_compute(
724             if( status != PSA_ERROR_NOT_SUPPORTED )
725                 return( status );
726 #endif /* PSA_CRYPTO_DRIVER_TEST */
727+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
728+            status = cc3xx_mac_compute(attributes, key_buffer, key_buffer_size, alg,
729+                input, input_length,
730+                mac, mac_size, mac_length);
731+            return( status );
732+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
733 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
734 #if defined(MBEDTLS_PSA_BUILTIN_MAC)
735             /* Fell through, meaning no accelerator supports this operation */
736@@ -2371,6 +2662,15 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_setup(
737             if( status != PSA_ERROR_NOT_SUPPORTED )
738                 return( status );
739 #endif /* PSA_CRYPTO_DRIVER_TEST */
740+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
741+            status = cc3xx_mac_sign_setup(
742+                    &operation->ctx.cc3xx_driver_ctx,
743+                    attributes,
744+                    key_buffer, key_buffer_size,
745+                    alg);
746+            operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
747+            return status;
748+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
749 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
750 #if defined(MBEDTLS_PSA_BUILTIN_MAC)
751             /* Fell through, meaning no accelerator supports this operation */
752@@ -2446,6 +2746,15 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_setup(
753             if( status != PSA_ERROR_NOT_SUPPORTED )
754                 return( status );
755 #endif /* PSA_CRYPTO_DRIVER_TEST */
756+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
757+            status = cc3xx_mac_verify_setup(
758+                &operation->ctx.cc3xx_driver_ctx,
759+                attributes,
760+                key_buffer, key_buffer_size,
761+                alg);
762+            operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID;
763+            return status;
764+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
765 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
766 #if defined(MBEDTLS_PSA_BUILTIN_MAC)
767             /* Fell through, meaning no accelerator supports this operation */
768@@ -2513,6 +2822,10 @@ static inline psa_status_t psa_driver_wrapper_mac_update(
769                         &operation->ctx.opaque_test_driver_ctx,
770                         input, input_length ) );
771 #endif /* PSA_CRYPTO_DRIVER_TEST */
772+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
773+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
774+            return(cc3xx_mac_update(&operation->ctx.cc3xx_driver_ctx, input, input_length));
775+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
776 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
777         default:
778             (void) input;
779@@ -2547,6 +2860,11 @@ static inline psa_status_t psa_driver_wrapper_mac_sign_finish(
780                         &operation->ctx.opaque_test_driver_ctx,
781                         mac, mac_size, mac_length ) );
782 #endif /* PSA_CRYPTO_DRIVER_TEST */
783+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
784+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
785+            return(cc3xx_mac_sign_finish(&operation->ctx.cc3xx_driver_ctx,
786+                        mac, mac_size, mac_length));
787+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
788 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
789         default:
790             (void) mac;
791@@ -2581,6 +2899,12 @@ static inline psa_status_t psa_driver_wrapper_mac_verify_finish(
792                         &operation->ctx.opaque_test_driver_ctx,
793                         mac, mac_length ) );
794 #endif /* PSA_CRYPTO_DRIVER_TEST */
795+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
796+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
797+            return(cc3xx_mac_verify_finish(
798+                        &operation->ctx.cc3xx_driver_ctx,
799+                        mac, mac_length));
800+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
801 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
802         default:
803             (void) mac;
804@@ -2608,6 +2932,10 @@ static inline psa_status_t psa_driver_wrapper_mac_abort(
805             return( mbedtls_test_opaque_mac_abort(
806                         &operation->ctx.opaque_test_driver_ctx ) );
807 #endif /* PSA_CRYPTO_DRIVER_TEST */
808+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
809+        case PSA_CRYPTO_CC3XX_DRIVER_ID:
810+            return(cc3xx_mac_abort(&operation->ctx.cc3xx_driver_ctx));
811+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
812 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
813         default:
814             return( PSA_ERROR_INVALID_ARGUMENT );
815@@ -2645,6 +2973,20 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_encrypt(
816             if( status != PSA_ERROR_NOT_SUPPORTED )
817                 return( status );
818 #endif /* PSA_CRYPTO_DRIVER_TEST */
819+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
820+            status = cc3xx_asymmetric_encrypt( attributes,
821+                                               key_buffer,
822+                                               key_buffer_size,
823+                                               alg,
824+                                               input,
825+                                               input_length,
826+                                               salt,
827+                                               salt_length,
828+                                               output,
829+                                               output_size,
830+                                               output_length );
831+            return( status );
832+#endif  /* PSA_CRYPTO_DRIVER_CC3XX */
833 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
834             return( mbedtls_psa_asymmetric_encrypt( attributes,
835                         key_buffer, key_buffer_size, alg, input, input_length,
836@@ -2706,6 +3048,20 @@ static inline psa_status_t psa_driver_wrapper_asymmetric_decrypt(
837             if( status != PSA_ERROR_NOT_SUPPORTED )
838                 return( status );
839 #endif /* PSA_CRYPTO_DRIVER_TEST */
840+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
841+            status = cc3xx_asymmetric_decrypt( attributes,
842+                                               key_buffer,
843+                                               key_buffer_size,
844+                                               alg,
845+                                               input,
846+                                               input_length,
847+                                               salt,
848+                                               salt_length,
849+                                               output,
850+                                               output_size,
851+                                               output_length );
852+            return( status );
853+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
854 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
855             return( mbedtls_psa_asymmetric_decrypt( attributes,
856                         key_buffer, key_buffer_size, alg,input, input_length,
857@@ -2773,6 +3129,18 @@ static inline psa_status_t psa_driver_wrapper_key_agreement(
858             if( status != PSA_ERROR_NOT_SUPPORTED )
859                 return( status );
860 #endif /* PSA_CRYPTO_DRIVER_TEST */
861+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
862+            status = cc3xx_key_agreement( attributes,
863+                                          key_buffer,
864+                                          key_buffer_size,
865+                                          peer_key,
866+                                          peer_key_length,
867+                                          shared_secret,
868+                                          shared_secret_size,
869+                                          shared_secret_length,
870+                                          alg );
871+            return( status );
872+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
873 #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED)
874             if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type(attributes) ) &&
875                 PSA_ALG_IS_ECDH(alg) &&
876diff --git a/library/psa_crypto_driver_wrappers_no_static.c b/library/psa_crypto_driver_wrappers_no_static.c
877index 436a650fc..bc65e2c7f 100644
878--- a/library/psa_crypto_driver_wrappers_no_static.c
879+++ b/library/psa_crypto_driver_wrappers_no_static.c
880@@ -52,6 +52,16 @@
881 #include "tfm_builtin_key_loader.h"
882 #endif /* PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER */
883
884+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
885+#ifndef PSA_CRYPTO_DRIVER_PRESENT
886+#define PSA_CRYPTO_DRIVER_PRESENT
887+#endif
888+#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
889+#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
890+#endif
891+#include "cc3xx.h"
892+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
893+
894 /* END-driver headers */
895
896 /* Auto-generated values depending on which drivers are registered.
897@@ -66,6 +76,9 @@ enum {
898 #if defined(PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER)
899     PSA_CRYPTO_TFM_BUILTIN_KEY_LOADER_DRIVER_ID,
900 #endif /* PSA_CRYPTO_DRIVER_TFM_BUILTIN_KEY_LOADER */
901+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
902+    PSA_CRYPTO_CC3XX_DRIVER_ID,
903+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
904 };
905
906 /* END-driver id */
907@@ -196,6 +209,17 @@ psa_status_t psa_driver_wrapper_export_public_key(
908                 return( status );
909 #endif
910
911+#if defined(PSA_CRYPTO_DRIVER_CC3XX)
912+            status = cc3xx_export_public_key(
913+                         attributes,
914+                         key_buffer,
915+                         key_buffer_size,
916+                         data,
917+                         data_size,
918+                         data_length );
919+            return( status );
920+#endif /* PSA_CRYPTO_DRIVER_CC3XX */
921+
922 #if (defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) )
923             status = p256_transparent_export_public_key
924                 (attributes,
925--
9262.34.1
927
928