Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1 | From 353e4dce10bf7957715320b38dd8f96a9e51d7f9 Mon Sep 17 00:00:00 2001 |
| 2 | From: Antonio de Angelis <Antonio.deAngelis@arm.com> |
| 3 | Date: Fri, 15 Jul 2022 12:41:34 +0100 |
| 4 | Subject: [PATCH 4/5] Driver wrapper entry points for CC3XX |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 5 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 6 | Manually hardcode PSA driver entry points for the CC3XX driver |
| 7 | into psa_crypto_driver_wrappers.c (and provide missing entry point |
| 8 | definitions if any). This is a temporary solution until the codegen |
| 9 | framework is available for automatic integration. |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 10 | |
| 11 | Signed-off-by: Summer Qin <summer.qin@arm.com> |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 12 | Signed-off-by: Salome Thirot <salome.thirot@arm.com> |
| 13 | Signed-off-by: Abbas Bracken Ziad <abbas.brackenziad@arm.com> |
| 14 | Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no> |
| 15 | Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com> |
| 16 | --- |
| 17 | .../psa/crypto_driver_contexts_composites.h | 9 + |
| 18 | .../psa/crypto_driver_contexts_primitives.h | 9 + |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 19 | library/psa_crypto.c | 21 +- |
| 20 | library/psa_crypto_driver_wrappers.c | 858 ++++++++++++++---- |
| 21 | library/psa_crypto_driver_wrappers.h | 14 + |
| 22 | 5 files changed, 708 insertions(+), 203 deletions(-) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 23 | |
| 24 | diff --git a/include/psa/crypto_driver_contexts_composites.h b/include/psa/crypto_driver_contexts_composites.h |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 25 | index 3f1c8af4b..2fdf9561f 100644 |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 26 | --- a/include/psa/crypto_driver_contexts_composites.h |
| 27 | +++ b/include/psa/crypto_driver_contexts_composites.h |
| 28 | @@ -41,6 +41,9 @@ |
| 29 | |
| 30 | /* Include the context structure definitions for those drivers that were |
| 31 | * declared during the autogeneration process. */ |
| 32 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 33 | +#include "cc3xx_crypto_primitives_private.h" |
| 34 | +#endif |
| 35 | |
| 36 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 37 | #include <libtestdriver1/include/psa/crypto.h> |
| 38 | @@ -104,6 +107,9 @@ typedef union { |
| 39 | mbedtls_transparent_test_driver_mac_operation_t transparent_test_driver_ctx; |
| 40 | mbedtls_opaque_test_driver_mac_operation_t opaque_test_driver_ctx; |
| 41 | #endif |
| 42 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 43 | + cc3xx_mac_operation_t cc3xx_driver_ctx; |
| 44 | +#endif |
| 45 | } psa_driver_mac_context_t; |
| 46 | |
| 47 | typedef union { |
| 48 | @@ -112,6 +118,9 @@ typedef union { |
| 49 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 50 | mbedtls_transparent_test_driver_aead_operation_t transparent_test_driver_ctx; |
| 51 | #endif |
| 52 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 53 | + cc3xx_aead_operation_t cc3xx_driver_ctx; |
| 54 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 55 | } psa_driver_aead_context_t; |
| 56 | |
| 57 | #endif /* PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H */ |
| 58 | diff --git a/include/psa/crypto_driver_contexts_primitives.h b/include/psa/crypto_driver_contexts_primitives.h |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 59 | index 2bb01ed43..2bc0bda70 100644 |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 60 | --- a/include/psa/crypto_driver_contexts_primitives.h |
| 61 | +++ b/include/psa/crypto_driver_contexts_primitives.h |
| 62 | @@ -40,6 +40,9 @@ |
| 63 | |
| 64 | /* Include the context structure definitions for those drivers that were |
| 65 | * declared during the autogeneration process. */ |
| 66 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 67 | +#include "cc3xx_crypto_primitives_private.h" |
| 68 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 69 | |
| 70 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 71 | #include <libtestdriver1/include/psa/crypto.h> |
| 72 | @@ -102,6 +105,9 @@ typedef union { |
| 73 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 74 | mbedtls_transparent_test_driver_hash_operation_t test_driver_ctx; |
| 75 | #endif |
| 76 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 77 | + cc3xx_hash_operation_t cc3xx_driver_ctx; |
| 78 | +#endif |
| 79 | } psa_driver_hash_context_t; |
| 80 | |
| 81 | typedef union { |
| 82 | @@ -111,6 +117,9 @@ typedef union { |
| 83 | mbedtls_transparent_test_driver_cipher_operation_t transparent_test_driver_ctx; |
| 84 | mbedtls_opaque_test_driver_cipher_operation_t opaque_test_driver_ctx; |
| 85 | #endif |
| 86 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 87 | + cc3xx_cipher_operation_t cc3xx_driver_ctx; |
| 88 | +#endif |
| 89 | } psa_driver_cipher_context_t; |
| 90 | |
| 91 | #endif /* PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H */ |
| 92 | diff --git a/library/psa_crypto.c b/library/psa_crypto.c |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 93 | index b0116ddfb..0e33f409c 100644 |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 94 | --- a/library/psa_crypto.c |
| 95 | +++ b/library/psa_crypto.c |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 96 | @@ -5862,11 +5862,24 @@ psa_status_t psa_raw_key_agreement( psa_algorithm_t alg, |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 97 | goto exit; |
| 98 | } |
| 99 | |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 100 | - status = psa_key_agreement_raw_internal( alg, slot, |
| 101 | - peer_key, peer_key_length, |
| 102 | - output, output_size, |
| 103 | - output_length ); |
| 104 | + psa_key_attributes_t attributes = { |
| 105 | + .core = slot->attr |
| 106 | + }; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 107 | + |
| 108 | + status = psa_driver_wrapper_key_agreement( alg, &attributes, |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 109 | + slot->key.data, |
| 110 | + slot->key.bytes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 111 | + peer_key, peer_key_length, |
| 112 | + output, output_size, |
| 113 | + output_length ); |
| 114 | |
| 115 | + if (status == PSA_ERROR_NOT_SUPPORTED) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 116 | + { |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 117 | + status = psa_key_agreement_raw_internal( alg, slot, |
| 118 | + peer_key, peer_key_length, |
| 119 | + output, output_size, |
| 120 | + output_length ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 121 | + } |
| 122 | exit: |
| 123 | if( status != PSA_SUCCESS ) |
| 124 | { |
| 125 | diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 126 | index a5ae6a29e..2097db0cb 100644 |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 127 | --- a/library/psa_crypto_driver_wrappers.c |
| 128 | +++ b/library/psa_crypto_driver_wrappers.c |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 129 | @@ -45,6 +45,16 @@ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 130 | #include "test/drivers/test_driver.h" |
| 131 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 132 | |
| 133 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 134 | +#ifndef PSA_CRYPTO_DRIVER_PRESENT |
| 135 | +#define PSA_CRYPTO_DRIVER_PRESENT |
| 136 | +#endif |
| 137 | +#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
| 138 | +#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
| 139 | +#endif |
| 140 | +#include "cc3xx.h" |
| 141 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 142 | + |
| 143 | /* Repeat above block for each JSON-declared driver during autogeneration */ |
| 144 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */ |
| 145 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 146 | @@ -58,6 +68,10 @@ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 147 | #define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (3) |
| 148 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 149 | |
| 150 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 151 | +#define PSA_CRYPTO_CC3XX_DRIVER_ID (4) |
| 152 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 153 | + |
| 154 | /* Support the 'old' SE interface when asked to */ |
| 155 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 156 | /* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 157 | @@ -128,6 +142,21 @@ psa_status_t psa_driver_wrapper_sign_message( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 158 | /* Key is stored in the slot in export representation, so |
| 159 | * cycle through all known transparent accelerators */ |
| 160 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 161 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 162 | + status = cc3xx_sign_message( |
| 163 | + attributes, |
| 164 | + key_buffer, |
| 165 | + key_buffer_size, |
| 166 | + alg, |
| 167 | + input, |
| 168 | + input_length, |
| 169 | + signature, |
| 170 | + signature_size, |
| 171 | + signature_length ); |
| 172 | + /* Declared with fallback == true */ |
| 173 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 174 | + return( status ); |
| 175 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 176 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 177 | status = mbedtls_test_transparent_signature_sign_message( |
| 178 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 179 | @@ -143,8 +172,19 @@ psa_status_t psa_driver_wrapper_sign_message( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 180 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 181 | return( status ); |
| 182 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 183 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 184 | break; |
| 185 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 186 | + /* Fell through, meaning no accelerator supports this operation */ |
| 187 | + return( psa_sign_message_builtin( attributes, |
| 188 | + key_buffer, |
| 189 | + key_buffer_size, |
| 190 | + alg, |
| 191 | + input, |
| 192 | + input_length, |
| 193 | + signature, |
| 194 | + signature_size, |
| 195 | + signature_length ) ); |
| 196 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 197 | |
| 198 | /* Add cases for opaque driver here */ |
| 199 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 200 | @@ -168,18 +208,9 @@ psa_status_t psa_driver_wrapper_sign_message( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 201 | default: |
| 202 | /* Key is declared with a lifetime not known to us */ |
| 203 | (void)status; |
| 204 | - break; |
| 205 | + return( PSA_ERROR_INVALID_ARGUMENT ); |
| 206 | } |
| 207 | - |
| 208 | - return( psa_sign_message_builtin( attributes, |
| 209 | - key_buffer, |
| 210 | - key_buffer_size, |
| 211 | - alg, |
| 212 | - input, |
| 213 | - input_length, |
| 214 | - signature, |
| 215 | - signature_size, |
| 216 | - signature_length ) ); |
| 217 | + return status; |
| 218 | } |
| 219 | |
| 220 | psa_status_t psa_driver_wrapper_verify_message( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 221 | @@ -202,6 +233,20 @@ psa_status_t psa_driver_wrapper_verify_message( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 222 | /* Key is stored in the slot in export representation, so |
| 223 | * cycle through all known transparent accelerators */ |
| 224 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 225 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 226 | + status = cc3xx_verify_message( |
| 227 | + attributes, |
| 228 | + key_buffer, |
| 229 | + key_buffer_size, |
| 230 | + alg, |
| 231 | + input, |
| 232 | + input_length, |
| 233 | + signature, |
| 234 | + signature_length ); |
| 235 | + /* Declared with fallback == true */ |
| 236 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 237 | + return( status ); |
| 238 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 239 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 240 | status = mbedtls_test_transparent_signature_verify_message( |
| 241 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 242 | @@ -216,8 +261,18 @@ psa_status_t psa_driver_wrapper_verify_message( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 243 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 244 | return( status ); |
| 245 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 246 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 247 | break; |
| 248 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 249 | + /* Fell through, meaning no accelerator supports this operation */ |
| 250 | + return( psa_verify_message_builtin( attributes, |
| 251 | + key_buffer, |
| 252 | + key_buffer_size, |
| 253 | + alg, |
| 254 | + input, |
| 255 | + input_length, |
| 256 | + signature, |
| 257 | + signature_length ) ); |
| 258 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 259 | |
| 260 | /* Add cases for opaque driver here */ |
| 261 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 262 | @@ -240,17 +295,9 @@ psa_status_t psa_driver_wrapper_verify_message( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 263 | default: |
| 264 | /* Key is declared with a lifetime not known to us */ |
| 265 | (void)status; |
| 266 | - break; |
| 267 | + return( PSA_ERROR_INVALID_ARGUMENT ); |
| 268 | } |
| 269 | - |
| 270 | - return( psa_verify_message_builtin( attributes, |
| 271 | - key_buffer, |
| 272 | - key_buffer_size, |
| 273 | - alg, |
| 274 | - input, |
| 275 | - input_length, |
| 276 | - signature, |
| 277 | - signature_length ) ); |
| 278 | + return status; |
| 279 | } |
| 280 | |
| 281 | psa_status_t psa_driver_wrapper_sign_hash( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 282 | @@ -289,6 +336,20 @@ psa_status_t psa_driver_wrapper_sign_hash( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 283 | /* Key is stored in the slot in export representation, so |
| 284 | * cycle through all known transparent accelerators */ |
| 285 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 286 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 287 | + status = cc3xx_sign_hash( attributes, |
| 288 | + key_buffer, |
| 289 | + key_buffer_size, |
| 290 | + alg, |
| 291 | + hash, |
| 292 | + hash_length, |
| 293 | + signature, |
| 294 | + signature_size, |
| 295 | + signature_length ); |
| 296 | + /* Declared with fallback == true */ |
| 297 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 298 | + return( status ); |
| 299 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 300 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 301 | status = mbedtls_test_transparent_signature_sign_hash( attributes, |
| 302 | key_buffer, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 303 | @@ -303,7 +364,8 @@ psa_status_t psa_driver_wrapper_sign_hash( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 304 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 305 | return( status ); |
| 306 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 307 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 308 | + break; |
| 309 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 310 | /* Fell through, meaning no accelerator supports this operation */ |
| 311 | return( psa_sign_hash_builtin( attributes, |
| 312 | key_buffer, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 313 | @@ -314,6 +376,7 @@ psa_status_t psa_driver_wrapper_sign_hash( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 314 | signature, |
| 315 | signature_size, |
| 316 | signature_length ) ); |
| 317 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 318 | |
| 319 | /* Add cases for opaque driver here */ |
| 320 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 321 | @@ -335,6 +398,7 @@ psa_status_t psa_driver_wrapper_sign_hash( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 322 | (void)status; |
| 323 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 324 | } |
| 325 | + return status; |
| 326 | } |
| 327 | |
| 328 | psa_status_t psa_driver_wrapper_verify_hash( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 329 | @@ -373,6 +437,19 @@ psa_status_t psa_driver_wrapper_verify_hash( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 330 | /* Key is stored in the slot in export representation, so |
| 331 | * cycle through all known transparent accelerators */ |
| 332 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 333 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 334 | + status = cc3xx_verify_hash( attributes, |
| 335 | + key_buffer, |
| 336 | + key_buffer_size, |
| 337 | + alg, |
| 338 | + hash, |
| 339 | + hash_length, |
| 340 | + signature, |
| 341 | + signature_length ); |
| 342 | + /* Declared with fallback == true */ |
| 343 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 344 | + return( status ); |
| 345 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 346 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 347 | status = mbedtls_test_transparent_signature_verify_hash( |
| 348 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 349 | @@ -387,8 +464,8 @@ psa_status_t psa_driver_wrapper_verify_hash( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 350 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 351 | return( status ); |
| 352 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 353 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 354 | - |
| 355 | + break; |
| 356 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 357 | return( psa_verify_hash_builtin( attributes, |
| 358 | key_buffer, |
| 359 | key_buffer_size, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 360 | @@ -397,6 +474,7 @@ psa_status_t psa_driver_wrapper_verify_hash( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 361 | hash_length, |
| 362 | signature, |
| 363 | signature_length ) ); |
| 364 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 365 | |
| 366 | /* Add cases for opaque driver here */ |
| 367 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 368 | @@ -417,6 +495,7 @@ psa_status_t psa_driver_wrapper_verify_hash( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 369 | (void)status; |
| 370 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 371 | } |
| 372 | + return status; |
| 373 | } |
| 374 | |
| 375 | /** Calculate the key buffer size required to store the key material of a key |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 376 | @@ -548,6 +627,14 @@ psa_status_t psa_driver_wrapper_generate_key( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 377 | if( PSA_KEY_TYPE_IS_ASYMMETRIC( attributes->core.type ) ) |
| 378 | { |
| 379 | /* Cycle through all known transparent accelerators */ |
| 380 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 381 | + status = cc3xx_generate_key( |
| 382 | + attributes, key_buffer, key_buffer_size, |
| 383 | + key_buffer_length ); |
| 384 | + /* Declared with fallback == true */ |
| 385 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 386 | + break; |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 387 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 388 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 389 | status = mbedtls_test_transparent_generate_key( |
| 390 | attributes, key_buffer, key_buffer_size, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 391 | @@ -759,6 +846,18 @@ psa_status_t psa_driver_wrapper_export_public_key( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 392 | /* Key is stored in the slot in export representation, so |
| 393 | * cycle through all known transparent accelerators */ |
| 394 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 395 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 396 | + status = cc3xx_export_public_key( |
| 397 | + attributes, |
| 398 | + key_buffer, |
| 399 | + key_buffer_size, |
| 400 | + data, |
| 401 | + data_size, |
| 402 | + data_length ); |
| 403 | + /* Declared with fallback == true */ |
| 404 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 405 | + return( status ); |
| 406 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 407 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 408 | status = mbedtls_test_transparent_export_public_key( |
| 409 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 410 | @@ -771,7 +870,8 @@ psa_status_t psa_driver_wrapper_export_public_key( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 411 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 412 | return( status ); |
| 413 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 414 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 415 | + break; |
| 416 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 417 | /* Fell through, meaning no accelerator supports this operation */ |
| 418 | return( psa_export_public_key_internal( attributes, |
| 419 | key_buffer, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 420 | @@ -779,6 +879,7 @@ psa_status_t psa_driver_wrapper_export_public_key( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 421 | data, |
| 422 | data_size, |
| 423 | data_length ) ); |
| 424 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 425 | |
| 426 | /* Add cases for opaque driver here */ |
| 427 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 428 | @@ -796,6 +897,7 @@ psa_status_t psa_driver_wrapper_export_public_key( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 429 | /* Key is declared with a lifetime not known to us */ |
| 430 | return( status ); |
| 431 | } |
| 432 | + return status; |
| 433 | } |
| 434 | |
| 435 | psa_status_t psa_driver_wrapper_get_builtin_key( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 436 | @@ -908,9 +1010,24 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 437 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 438 | return( status ); |
| 439 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 440 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 441 | - |
| 442 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 443 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 444 | + status = cc3xx_cipher_encrypt( attributes, |
| 445 | + key_buffer, |
| 446 | + key_buffer_size, |
| 447 | + alg, |
| 448 | + iv, |
| 449 | + iv_length, |
| 450 | + input, |
| 451 | + input_length, |
| 452 | + output, |
| 453 | + output_size, |
| 454 | + output_length ); |
| 455 | + /* Declared with fallback == true */ |
| 456 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 457 | + return( status ); |
| 458 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 459 | + break; |
| 460 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 461 | return( mbedtls_psa_cipher_encrypt( attributes, |
| 462 | key_buffer, |
| 463 | key_buffer_size, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 464 | @@ -959,6 +1076,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 465 | (void)output_length; |
| 466 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 467 | } |
| 468 | + return status; |
| 469 | } |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 470 | |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 471 | psa_status_t psa_driver_wrapper_cipher_decrypt( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 472 | @@ -996,9 +1114,22 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 473 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 474 | return( status ); |
| 475 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 476 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 477 | - |
| 478 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 479 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 480 | + status = cc3xx_cipher_decrypt( attributes, |
| 481 | + key_buffer, |
| 482 | + key_buffer_size, |
| 483 | + alg, |
| 484 | + input, |
| 485 | + input_length, |
| 486 | + output, |
| 487 | + output_size, |
| 488 | + output_length ); |
| 489 | + /* Declared with fallback == true */ |
| 490 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 491 | + return( status ); |
| 492 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 493 | + break; |
| 494 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 495 | return( mbedtls_psa_cipher_decrypt( attributes, |
| 496 | key_buffer, |
| 497 | key_buffer_size, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 498 | @@ -1041,6 +1172,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 499 | (void)output_length; |
| 500 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 501 | } |
| 502 | + return status; |
| 503 | } |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 504 | |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 505 | psa_status_t psa_driver_wrapper_cipher_encrypt_setup( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 506 | @@ -1073,8 +1205,22 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 507 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 508 | return( status ); |
| 509 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 510 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 511 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 512 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 513 | + status = cc3xx_cipher_encrypt_setup( |
| 514 | + &operation->ctx.cc3xx_driver_ctx, |
| 515 | + attributes, |
| 516 | + key_buffer, |
| 517 | + key_buffer_size, |
| 518 | + alg ); |
| 519 | + /* Declared with fallback == true */ |
| 520 | + if( status == PSA_SUCCESS ) |
| 521 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 522 | + |
| 523 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 524 | + return( status ); |
| 525 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 526 | + break; |
| 527 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 528 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 529 | status = mbedtls_psa_cipher_encrypt_setup( &operation->ctx.mbedtls_ctx, |
| 530 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 531 | @@ -1114,6 +1260,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 532 | (void)alg; |
| 533 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 534 | } |
| 535 | + return status; |
| 536 | } |
| 537 | |
| 538 | psa_status_t psa_driver_wrapper_cipher_decrypt_setup( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 539 | @@ -1146,8 +1293,22 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 540 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 541 | return( status ); |
| 542 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 543 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 544 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 545 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 546 | + status = cc3xx_cipher_decrypt_setup( |
| 547 | + &operation->ctx.cc3xx_driver_ctx, |
| 548 | + attributes, |
| 549 | + key_buffer, |
| 550 | + key_buffer_size, |
| 551 | + alg ); |
| 552 | + /* Declared with fallback == true */ |
| 553 | + if( status == PSA_SUCCESS ) |
| 554 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 555 | + |
| 556 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 557 | + return( status ); |
| 558 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 559 | + break; |
| 560 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 561 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 562 | status = mbedtls_psa_cipher_decrypt_setup( &operation->ctx.mbedtls_ctx, |
| 563 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 564 | @@ -1186,6 +1347,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 565 | (void)alg; |
| 566 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 567 | } |
| 568 | + return status; |
| 569 | } |
| 570 | |
| 571 | psa_status_t psa_driver_wrapper_cipher_set_iv( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 572 | @@ -1195,13 +1357,6 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 573 | { |
| 574 | switch( operation->id ) |
| 575 | { |
| 576 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 577 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 578 | - return( mbedtls_psa_cipher_set_iv( &operation->ctx.mbedtls_ctx, |
| 579 | - iv, |
| 580 | - iv_length ) ); |
| 581 | -#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 582 | - |
| 583 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 584 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 585 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 586 | @@ -1214,6 +1369,17 @@ psa_status_t psa_driver_wrapper_cipher_set_iv( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 587 | &operation->ctx.opaque_test_driver_ctx, |
| 588 | iv, iv_length ) ); |
| 589 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 590 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 591 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 592 | + return( cc3xx_cipher_set_iv( |
| 593 | + &operation->ctx.cc3xx_driver_ctx, |
| 594 | + iv, iv_length ) ); |
| 595 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 596 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 597 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 598 | + return( mbedtls_psa_cipher_set_iv( &operation->ctx.mbedtls_ctx, |
| 599 | + iv, |
| 600 | + iv_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 601 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 602 | } |
| 603 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 604 | @@ -1233,16 +1399,6 @@ psa_status_t psa_driver_wrapper_cipher_update( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 605 | { |
| 606 | switch( operation->id ) |
| 607 | { |
| 608 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 609 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 610 | - return( mbedtls_psa_cipher_update( &operation->ctx.mbedtls_ctx, |
| 611 | - input, |
| 612 | - input_length, |
| 613 | - output, |
| 614 | - output_size, |
| 615 | - output_length ) ); |
| 616 | -#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 617 | - |
| 618 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 619 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 620 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 621 | @@ -1257,6 +1413,21 @@ psa_status_t psa_driver_wrapper_cipher_update( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 622 | input, input_length, |
| 623 | output, output_size, output_length ) ); |
| 624 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 625 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 626 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 627 | + return( cc3xx_cipher_update( |
| 628 | + &operation->ctx.cc3xx_driver_ctx, |
| 629 | + input, input_length, |
| 630 | + output, output_size, output_length ) ); |
| 631 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 632 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 633 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 634 | + return( mbedtls_psa_cipher_update( &operation->ctx.mbedtls_ctx, |
| 635 | + input, |
| 636 | + input_length, |
| 637 | + output, |
| 638 | + output_size, |
| 639 | + output_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 640 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 641 | } |
| 642 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 643 | @@ -1277,14 +1448,6 @@ psa_status_t psa_driver_wrapper_cipher_finish( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 644 | { |
| 645 | switch( operation->id ) |
| 646 | { |
| 647 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 648 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 649 | - return( mbedtls_psa_cipher_finish( &operation->ctx.mbedtls_ctx, |
| 650 | - output, |
| 651 | - output_size, |
| 652 | - output_length ) ); |
| 653 | -#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 654 | - |
| 655 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 656 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 657 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 658 | @@ -1297,6 +1460,18 @@ psa_status_t psa_driver_wrapper_cipher_finish( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 659 | &operation->ctx.opaque_test_driver_ctx, |
| 660 | output, output_size, output_length ) ); |
| 661 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 662 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 663 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 664 | + return( cc3xx_cipher_finish( |
| 665 | + &operation->ctx.cc3xx_driver_ctx, |
| 666 | + output, output_size, output_length ) ); |
| 667 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX*/ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 668 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 669 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 670 | + return( mbedtls_psa_cipher_finish( &operation->ctx.mbedtls_ctx, |
| 671 | + output, |
| 672 | + output_size, |
| 673 | + output_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 674 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 675 | } |
| 676 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 677 | @@ -1314,11 +1489,6 @@ psa_status_t psa_driver_wrapper_cipher_abort( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 678 | |
| 679 | switch( operation->id ) |
| 680 | { |
| 681 | -#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 682 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 683 | - return( mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) ); |
| 684 | -#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 685 | - |
| 686 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 687 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 688 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 689 | @@ -1337,6 +1507,18 @@ psa_status_t psa_driver_wrapper_cipher_abort( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 690 | sizeof( operation->ctx.opaque_test_driver_ctx ) ); |
| 691 | return( status ); |
| 692 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 693 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 694 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 695 | + status = cc3xx_cipher_abort( |
| 696 | + &operation->ctx.cc3xx_driver_ctx ); |
| 697 | + mbedtls_platform_zeroize( |
| 698 | + &operation->ctx.cc3xx_driver_ctx, |
| 699 | + sizeof( operation->ctx.cc3xx_driver_ctx ) ); |
| 700 | + return( status ); |
| 701 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 702 | +#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
| 703 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 704 | + return( mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 705 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 706 | } |
| 707 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 708 | @@ -1358,15 +1540,21 @@ psa_status_t psa_driver_wrapper_hash_compute( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 709 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 710 | |
| 711 | /* Try accelerators first */ |
| 712 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 713 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 714 | status = mbedtls_test_transparent_hash_compute( |
| 715 | alg, input, input_length, hash, hash_size, hash_length ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 716 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 717 | return( status ); |
| 718 | #endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 719 | - |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 720 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 721 | + status = cc3xx_hash_compute(alg, input, input_length, hash, hash_size, |
| 722 | + hash_length); |
| 723 | + if (status != PSA_ERROR_NOT_SUPPORTED) |
| 724 | + return status; |
| 725 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 726 | +#elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 727 | /* If software fallback is compiled in, try fallback */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 728 | -#if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 729 | status = mbedtls_psa_hash_compute( alg, input, input_length, |
| 730 | hash, hash_size, hash_length ); |
| 731 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 732 | @@ -1390,6 +1578,7 @@ psa_status_t psa_driver_wrapper_hash_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 733 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 734 | |
| 735 | /* Try setup on accelerators first */ |
| 736 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 737 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 738 | status = mbedtls_test_transparent_hash_setup( |
| 739 | &operation->ctx.test_driver_ctx, alg ); |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 740 | @@ -1400,8 +1589,18 @@ psa_status_t psa_driver_wrapper_hash_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 741 | return( status ); |
| 742 | #endif |
| 743 | |
| 744 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 745 | + status = cc3xx_hash_setup(&operation->ctx.cc3xx_driver_ctx, alg); |
| 746 | + if( status == PSA_SUCCESS ) |
| 747 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 748 | + |
| 749 | + if( status != PSA_ERROR_NOT_SUPPORTED) { |
| 750 | + return( status ); |
| 751 | + } |
| 752 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 753 | + |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 754 | +#elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 755 | /* If software fallback is compiled in, try fallback */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 756 | -#if defined(MBEDTLS_PSA_BUILTIN_HASH) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 757 | status = mbedtls_psa_hash_setup( &operation->ctx.mbedtls_ctx, alg ); |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 758 | if( status == PSA_SUCCESS ) |
| 759 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 760 | @@ -1422,18 +1621,26 @@ psa_status_t psa_driver_wrapper_hash_clone( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 761 | { |
| 762 | switch( source_operation->id ) |
| 763 | { |
| 764 | -#if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 765 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 766 | - target_operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 767 | - return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx, |
| 768 | - &target_operation->ctx.mbedtls_ctx ) ); |
| 769 | -#endif |
| 770 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 771 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 772 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 773 | target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
| 774 | return( mbedtls_test_transparent_hash_clone( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 775 | &source_operation->ctx.test_driver_ctx, |
| 776 | &target_operation->ctx.test_driver_ctx ) ); |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 777 | +#endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 778 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 779 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 780 | + target_operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 781 | + return( cc3xx_hash_clone( |
| 782 | + &source_operation->ctx.cc3xx_driver_ctx, |
| 783 | + &target_operation->ctx.cc3xx_driver_ctx ) ); |
| 784 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 785 | +#elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 786 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 787 | + target_operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 788 | + return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx, |
| 789 | + &target_operation->ctx.mbedtls_ctx ) ); |
| 790 | #endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 791 | default: |
| 792 | (void) target_operation; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 793 | @@ -1448,16 +1655,23 @@ psa_status_t psa_driver_wrapper_hash_update( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 794 | { |
| 795 | switch( operation->id ) |
| 796 | { |
| 797 | -#if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 798 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 799 | - return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx, |
| 800 | - input, input_length ) ); |
| 801 | -#endif |
| 802 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 803 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 804 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 805 | return( mbedtls_test_transparent_hash_update( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 806 | &operation->ctx.test_driver_ctx, |
| 807 | input, input_length ) ); |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 808 | +#endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 809 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 810 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 811 | + return( cc3xx_hash_update( |
| 812 | + &operation->ctx.cc3xx_driver_ctx, |
| 813 | + input, input_length ) ); |
| 814 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 815 | +#elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 816 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 817 | + return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx, |
| 818 | + input, input_length ) ); |
| 819 | #endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 820 | default: |
| 821 | (void) input; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 822 | @@ -1474,16 +1688,23 @@ psa_status_t psa_driver_wrapper_hash_finish( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 823 | { |
| 824 | switch( operation->id ) |
| 825 | { |
| 826 | -#if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 827 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 828 | - return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx, |
| 829 | - hash, hash_size, hash_length ) ); |
| 830 | -#endif |
| 831 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 832 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 833 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 834 | return( mbedtls_test_transparent_hash_finish( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 835 | &operation->ctx.test_driver_ctx, |
| 836 | hash, hash_size, hash_length ) ); |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 837 | +#endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 838 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 839 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 840 | + return( cc3xx_hash_finish( |
| 841 | + &operation->ctx.cc3xx_driver_ctx, |
| 842 | + hash, hash_size, hash_length ) ); |
| 843 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 844 | +#elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 845 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 846 | + return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx, |
| 847 | + hash, hash_size, hash_length ) ); |
| 848 | #endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 849 | default: |
| 850 | (void) hash; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 851 | @@ -1498,14 +1719,20 @@ psa_status_t psa_driver_wrapper_hash_abort( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 852 | { |
| 853 | switch( operation->id ) |
| 854 | { |
| 855 | -#if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 856 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 857 | - return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); |
| 858 | -#endif |
| 859 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 860 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 861 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 862 | return( mbedtls_test_transparent_hash_abort( |
| 863 | &operation->ctx.test_driver_ctx ) ); |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 864 | +#endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 865 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 866 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 867 | + return( cc3xx_hash_abort( |
| 868 | + &operation->ctx.cc3xx_driver_ctx ) ); |
| 869 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 870 | +#elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 871 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 872 | + return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); |
| 873 | #endif |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 874 | default: |
| 875 | return( PSA_ERROR_BAD_STATE ); |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 876 | @@ -1544,7 +1771,20 @@ psa_status_t psa_driver_wrapper_aead_encrypt( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 877 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 878 | return( status ); |
| 879 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 880 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 881 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 882 | + status = cc3xx_aead_encrypt( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 883 | + attributes, key_buffer, key_buffer_size, |
| 884 | + alg, |
| 885 | + nonce, nonce_length, |
| 886 | + additional_data, additional_data_length, |
| 887 | + plaintext, plaintext_length, |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 888 | + ciphertext, ciphertext_size, ciphertext_length ); |
| 889 | + |
| 890 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 891 | + return( status ); |
| 892 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 893 | + break; |
| 894 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 895 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 896 | /* Fell through, meaning no accelerator supports this operation */ |
| 897 | return( mbedtls_psa_aead_encrypt( |
| 898 | @@ -1554,6 +1794,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( |
| 899 | additional_data, additional_data_length, |
| 900 | plaintext, plaintext_length, |
| 901 | ciphertext, ciphertext_size, ciphertext_length ) ); |
| 902 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 903 | |
| 904 | /* Add cases for opaque driver here */ |
| 905 | |
| 906 | @@ -1562,6 +1803,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 907 | (void)status; |
| 908 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 909 | } |
| 910 | + return status; |
| 911 | } |
| 912 | |
| 913 | psa_status_t psa_driver_wrapper_aead_decrypt( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 914 | @@ -1596,7 +1838,20 @@ psa_status_t psa_driver_wrapper_aead_decrypt( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 915 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 916 | return( status ); |
| 917 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 918 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 919 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 920 | + status = cc3xx_aead_decrypt( |
| 921 | + attributes, key_buffer, key_buffer_size, |
| 922 | + alg, |
| 923 | + nonce, nonce_length, |
| 924 | + additional_data, additional_data_length, |
| 925 | + ciphertext, ciphertext_length, |
| 926 | + plaintext, plaintext_size, plaintext_length ); |
| 927 | + |
| 928 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 929 | + return( status ); |
| 930 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 931 | + break; |
| 932 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 933 | |
| 934 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 935 | return( mbedtls_psa_aead_decrypt( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 936 | @@ -1606,6 +1861,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 937 | additional_data, additional_data_length, |
| 938 | ciphertext, ciphertext_length, |
| 939 | plaintext, plaintext_size, plaintext_length ) ); |
| 940 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 941 | |
| 942 | /* Add cases for opaque driver here */ |
| 943 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 944 | @@ -1614,6 +1870,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 945 | (void)status; |
| 946 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 947 | } |
| 948 | + return status; |
| 949 | } |
| 950 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 951 | psa_status_t psa_driver_get_tag_len( psa_aead_operation_t *operation, |
| 952 | @@ -1622,14 +1879,27 @@ psa_status_t psa_driver_get_tag_len( psa_aead_operation_t *operation, |
| 953 | if( operation == NULL || tag_len == NULL ) |
| 954 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 955 | |
| 956 | + switch( operation->id ) |
| 957 | + { |
| 958 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 959 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 960 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 961 | + *tag_len = operation->ctx.cc3xx_driver_ctx.tag_length; |
| 962 | + return ( PSA_SUCCESS ); |
| 963 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
| 964 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 965 | - *tag_len = operation->ctx.transparent_test_driver_ctx.tag_length; |
| 966 | - return ( PSA_SUCCESS ); |
| 967 | -#endif |
| 968 | + case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 969 | + *tag_len = operation->ctx.transparent_test_driver_ctx.tag_length; |
| 970 | + return ( PSA_SUCCESS ); |
| 971 | #endif |
| 972 | - *tag_len = operation->ctx.mbedtls_ctx.tag_length; |
| 973 | - return ( PSA_SUCCESS ); |
| 974 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 975 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 976 | + *tag_len = operation->ctx.mbedtls_ctx.tag_length; |
| 977 | + return ( PSA_SUCCESS ); |
| 978 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 979 | + } |
| 980 | + |
| 981 | + return( PSA_ERROR_INVALID_ARGUMENT ); |
| 982 | } |
| 983 | |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 984 | psa_status_t psa_driver_wrapper_aead_encrypt_setup( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 985 | @@ -1660,7 +1930,18 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 986 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 987 | return( status ); |
| 988 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 989 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 990 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 991 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 992 | + status = cc3xx_aead_encrypt_setup( |
| 993 | + &operation->ctx.cc3xx_driver_ctx, |
| 994 | + attributes, key_buffer, key_buffer_size, |
| 995 | + alg ); |
| 996 | + |
| 997 | + /* Declared with fallback == true */ |
| 998 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 999 | + return( status ); |
| 1000 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1001 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1002 | |
| 1003 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1004 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1005 | @@ -1668,9 +1949,8 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1006 | &operation->ctx.mbedtls_ctx, attributes, |
| 1007 | key_buffer, key_buffer_size, |
| 1008 | alg ); |
| 1009 | - |
| 1010 | - return( status ); |
| 1011 | - |
| 1012 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1013 | + break; |
| 1014 | /* Add cases for opaque driver here */ |
| 1015 | |
| 1016 | default: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1017 | @@ -1678,6 +1958,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1018 | (void)status; |
| 1019 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1020 | } |
| 1021 | + return status; |
| 1022 | } |
| 1023 | |
| 1024 | psa_status_t psa_driver_wrapper_aead_decrypt_setup( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1025 | @@ -1709,7 +1990,19 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1026 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1027 | return( status ); |
| 1028 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1029 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1030 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1031 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 1032 | + status = cc3xx_aead_decrypt_setup( |
| 1033 | + &operation->ctx.cc3xx_driver_ctx, |
| 1034 | + attributes, |
| 1035 | + key_buffer, key_buffer_size, |
| 1036 | + alg ); |
| 1037 | + |
| 1038 | + /* Declared with fallback == true */ |
| 1039 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1040 | + return( status ); |
| 1041 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1042 | +#else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1043 | |
| 1044 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1045 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1046 | @@ -1718,9 +2011,8 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1047 | attributes, |
| 1048 | key_buffer, key_buffer_size, |
| 1049 | alg ); |
| 1050 | - |
| 1051 | - return( status ); |
| 1052 | - |
| 1053 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1054 | + break; |
| 1055 | /* Add cases for opaque driver here */ |
| 1056 | |
| 1057 | default: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1058 | @@ -1728,6 +2020,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1059 | (void)status; |
| 1060 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1061 | } |
| 1062 | + return status; |
| 1063 | } |
| 1064 | |
| 1065 | psa_status_t psa_driver_wrapper_aead_set_nonce( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1066 | @@ -1737,14 +2030,6 @@ psa_status_t psa_driver_wrapper_aead_set_nonce( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1067 | { |
| 1068 | switch( operation->id ) |
| 1069 | { |
| 1070 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1071 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1072 | - return( mbedtls_psa_aead_set_nonce( &operation->ctx.mbedtls_ctx, |
| 1073 | - nonce, |
| 1074 | - nonce_length ) ); |
| 1075 | - |
| 1076 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1077 | - |
| 1078 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1079 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1080 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1081 | @@ -1755,6 +2040,20 @@ psa_status_t psa_driver_wrapper_aead_set_nonce( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1082 | /* Add cases for opaque driver here */ |
| 1083 | |
| 1084 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1085 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1086 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1087 | + return( cc3xx_aead_set_nonce( |
| 1088 | + &operation->ctx.cc3xx_driver_ctx, |
| 1089 | + nonce, nonce_length ) ); |
| 1090 | + |
| 1091 | + /* Add cases for opaque driver here */ |
| 1092 | + |
| 1093 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1094 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1095 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1096 | + return( mbedtls_psa_aead_set_nonce( &operation->ctx.mbedtls_ctx, |
| 1097 | + nonce, |
| 1098 | + nonce_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1099 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1100 | } |
| 1101 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1102 | @@ -1771,14 +2070,6 @@ psa_status_t psa_driver_wrapper_aead_set_lengths( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1103 | { |
| 1104 | switch( operation->id ) |
| 1105 | { |
| 1106 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1107 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1108 | - return( mbedtls_psa_aead_set_lengths( &operation->ctx.mbedtls_ctx, |
| 1109 | - ad_length, |
| 1110 | - plaintext_length ) ); |
| 1111 | - |
| 1112 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1113 | - |
| 1114 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1115 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1116 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1117 | @@ -1789,6 +2080,20 @@ psa_status_t psa_driver_wrapper_aead_set_lengths( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1118 | /* Add cases for opaque driver here */ |
| 1119 | |
| 1120 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1121 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1122 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1123 | + return( cc3xx_aead_set_lengths( |
| 1124 | + &operation->ctx.cc3xx_driver_ctx, |
| 1125 | + ad_length, plaintext_length ) ); |
| 1126 | + |
| 1127 | + /* Add cases for opaque driver here */ |
| 1128 | + |
| 1129 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1130 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1131 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1132 | + return( mbedtls_psa_aead_set_lengths( &operation->ctx.mbedtls_ctx, |
| 1133 | + ad_length, |
| 1134 | + plaintext_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1135 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1136 | } |
| 1137 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1138 | @@ -1805,14 +2110,6 @@ psa_status_t psa_driver_wrapper_aead_update_ad( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1139 | { |
| 1140 | switch( operation->id ) |
| 1141 | { |
| 1142 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1143 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1144 | - return( mbedtls_psa_aead_update_ad( &operation->ctx.mbedtls_ctx, |
| 1145 | - input, |
| 1146 | - input_length ) ); |
| 1147 | - |
| 1148 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1149 | - |
| 1150 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1151 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1152 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1153 | @@ -1823,6 +2120,20 @@ psa_status_t psa_driver_wrapper_aead_update_ad( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1154 | /* Add cases for opaque driver here */ |
| 1155 | |
| 1156 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1157 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1158 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1159 | + return( cc3xx_aead_update_ad( |
| 1160 | + &operation->ctx.cc3xx_driver_ctx, |
| 1161 | + input, input_length ) ); |
| 1162 | + |
| 1163 | + /* Add cases for opaque driver here */ |
| 1164 | + |
| 1165 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1166 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1167 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1168 | + return( mbedtls_psa_aead_update_ad( &operation->ctx.mbedtls_ctx, |
| 1169 | + input, |
| 1170 | + input_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1171 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1172 | } |
| 1173 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1174 | @@ -1842,15 +2153,6 @@ psa_status_t psa_driver_wrapper_aead_update( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1175 | { |
| 1176 | switch( operation->id ) |
| 1177 | { |
| 1178 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1179 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1180 | - return( mbedtls_psa_aead_update( &operation->ctx.mbedtls_ctx, |
| 1181 | - input, input_length, |
| 1182 | - output, output_size, |
| 1183 | - output_length ) ); |
| 1184 | - |
| 1185 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1186 | - |
| 1187 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1188 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1189 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1190 | @@ -1862,6 +2164,22 @@ psa_status_t psa_driver_wrapper_aead_update( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1191 | /* Add cases for opaque driver here */ |
| 1192 | |
| 1193 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1194 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1195 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1196 | + return( cc3xx_aead_update( |
| 1197 | + &operation->ctx.cc3xx_driver_ctx, |
| 1198 | + input, input_length, output, output_size, |
| 1199 | + output_length ) ); |
| 1200 | + |
| 1201 | + /* Add cases for opaque driver here */ |
| 1202 | + |
| 1203 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1204 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1205 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1206 | + return( mbedtls_psa_aead_update( &operation->ctx.mbedtls_ctx, |
| 1207 | + input, input_length, |
| 1208 | + output, output_size, |
| 1209 | + output_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1210 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1211 | } |
| 1212 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1213 | @@ -1885,16 +2203,6 @@ psa_status_t psa_driver_wrapper_aead_finish( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1214 | { |
| 1215 | switch( operation->id ) |
| 1216 | { |
| 1217 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1218 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1219 | - return( mbedtls_psa_aead_finish( &operation->ctx.mbedtls_ctx, |
| 1220 | - ciphertext, |
| 1221 | - ciphertext_size, |
| 1222 | - ciphertext_length, tag, |
| 1223 | - tag_size, tag_length ) ); |
| 1224 | - |
| 1225 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1226 | - |
| 1227 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1228 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1229 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1230 | @@ -1906,6 +2214,23 @@ psa_status_t psa_driver_wrapper_aead_finish( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1231 | /* Add cases for opaque driver here */ |
| 1232 | |
| 1233 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1234 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1235 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1236 | + return( cc3xx_aead_finish( |
| 1237 | + &operation->ctx.cc3xx_driver_ctx, |
| 1238 | + ciphertext, ciphertext_size, |
| 1239 | + ciphertext_length, tag, tag_size, tag_length ) ); |
| 1240 | + |
| 1241 | + /* Add cases for opaque driver here */ |
| 1242 | + |
| 1243 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1244 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1245 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1246 | + return( mbedtls_psa_aead_finish( &operation->ctx.mbedtls_ctx, |
| 1247 | + ciphertext, |
| 1248 | + ciphertext_size, |
| 1249 | + ciphertext_length, tag, |
| 1250 | + tag_size, tag_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1251 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1252 | } |
| 1253 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1254 | @@ -1929,7 +2254,28 @@ psa_status_t psa_driver_wrapper_aead_verify( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1255 | { |
| 1256 | switch( operation->id ) |
| 1257 | { |
| 1258 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1259 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1260 | +#if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1261 | + case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 1262 | + return( mbedtls_test_transparent_aead_verify( |
| 1263 | + &operation->ctx.transparent_test_driver_ctx, |
| 1264 | + plaintext, plaintext_size, |
| 1265 | + plaintext_length, tag, tag_length ) ); |
| 1266 | + |
| 1267 | + /* Add cases for opaque driver here */ |
| 1268 | + |
| 1269 | +#endif /* PSA_CRYPTO_DRIVER_TEST */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1270 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1271 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1272 | + return( cc3xx_aead_verify( |
| 1273 | + &operation->ctx.cc3xx_driver_ctx, |
| 1274 | + plaintext, plaintext_size, |
| 1275 | + plaintext_length, tag, tag_length ) ); |
| 1276 | + |
| 1277 | + /* Add cases for opaque driver here */ |
| 1278 | + |
| 1279 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1280 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1281 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1282 | { |
| 1283 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1284 | @@ -1956,20 +2302,6 @@ psa_status_t psa_driver_wrapper_aead_verify( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1285 | |
| 1286 | return( status ); |
| 1287 | } |
| 1288 | - |
| 1289 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1290 | - |
| 1291 | -#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1292 | -#if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1293 | - case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 1294 | - return( mbedtls_test_transparent_aead_verify( |
| 1295 | - &operation->ctx.transparent_test_driver_ctx, |
| 1296 | - plaintext, plaintext_size, |
| 1297 | - plaintext_length, tag, tag_length ) ); |
| 1298 | - |
| 1299 | - /* Add cases for opaque driver here */ |
| 1300 | - |
| 1301 | -#endif /* PSA_CRYPTO_DRIVER_TEST */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1302 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1303 | } |
| 1304 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1305 | @@ -1987,12 +2319,6 @@ psa_status_t psa_driver_wrapper_aead_abort( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1306 | { |
| 1307 | switch( operation->id ) |
| 1308 | { |
| 1309 | -#if defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1310 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1311 | - return( mbedtls_psa_aead_abort( &operation->ctx.mbedtls_ctx ) ); |
| 1312 | - |
| 1313 | -#endif /* MBEDTLS_PSA_BUILTIN_AEAD */ |
| 1314 | - |
| 1315 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1316 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1317 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1318 | @@ -2002,6 +2328,17 @@ psa_status_t psa_driver_wrapper_aead_abort( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1319 | /* Add cases for opaque driver here */ |
| 1320 | |
| 1321 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1322 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1323 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1324 | + return( cc3xx_aead_abort( |
| 1325 | + &operation->ctx.cc3xx_driver_ctx ) ); |
| 1326 | + |
| 1327 | + /* Add cases for opaque driver here */ |
| 1328 | + |
| 1329 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1330 | +#elif defined(MBEDTLS_PSA_BUILTIN_AEAD) |
| 1331 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1332 | + return( mbedtls_psa_aead_abort( &operation->ctx.mbedtls_ctx ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1333 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1334 | } |
| 1335 | |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1336 | @@ -2041,8 +2378,16 @@ psa_status_t psa_driver_wrapper_mac_compute( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1337 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1338 | return( status ); |
| 1339 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1340 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1341 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1342 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1343 | + status = cc3xx_mac_compute(attributes, key_buffer, key_buffer_size, alg, |
| 1344 | + input, input_length, |
| 1345 | + mac, mac_size, mac_length); |
| 1346 | + /* Declared with fallback == true */ |
| 1347 | + if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1348 | + return( status ); |
| 1349 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1350 | + break; |
| 1351 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1352 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1353 | status = mbedtls_psa_mac_compute( |
| 1354 | attributes, key_buffer, key_buffer_size, alg, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1355 | @@ -2077,6 +2422,7 @@ psa_status_t psa_driver_wrapper_mac_compute( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1356 | (void) status; |
| 1357 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1358 | } |
| 1359 | + return status; |
| 1360 | } |
| 1361 | |
| 1362 | psa_status_t psa_driver_wrapper_mac_sign_setup( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1363 | @@ -2109,8 +2455,19 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1364 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1365 | return( status ); |
| 1366 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1367 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1368 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1369 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1370 | + status = cc3xx_mac_sign_setup( |
| 1371 | + &operation->ctx.cc3xx_driver_ctx, |
| 1372 | + attributes, |
| 1373 | + key_buffer, key_buffer_size, |
| 1374 | + alg); |
| 1375 | + if (status == PSA_SUCCESS) |
| 1376 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 1377 | + if (status != PSA_ERROR_NOT_SUPPORTED) |
| 1378 | + return status; |
| 1379 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1380 | + break; |
| 1381 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1382 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1383 | status = mbedtls_psa_mac_sign_setup( &operation->ctx.mbedtls_ctx, |
| 1384 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1385 | @@ -2149,6 +2506,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1386 | (void) alg; |
| 1387 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1388 | } |
| 1389 | + return status; |
| 1390 | } |
| 1391 | |
| 1392 | psa_status_t psa_driver_wrapper_mac_verify_setup( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1393 | @@ -2181,8 +2539,19 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1394 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1395 | return( status ); |
| 1396 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1397 | -#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1398 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1399 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1400 | + status = cc3xx_mac_verify_setup( |
| 1401 | + &operation->ctx.cc3xx_driver_ctx, |
| 1402 | + attributes, |
| 1403 | + key_buffer, key_buffer_size, |
| 1404 | + alg); |
| 1405 | + if (status == PSA_SUCCESS) |
| 1406 | + operation->id = PSA_CRYPTO_CC3XX_DRIVER_ID; |
| 1407 | + if (status != PSA_ERROR_NOT_SUPPORTED) |
| 1408 | + return status; |
| 1409 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1410 | + break; |
| 1411 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1412 | /* Fell through, meaning no accelerator supports this operation */ |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1413 | status = mbedtls_psa_mac_verify_setup( &operation->ctx.mbedtls_ctx, |
| 1414 | attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1415 | @@ -2221,6 +2590,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1416 | (void) alg; |
| 1417 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1418 | } |
| 1419 | + return status; |
| 1420 | } |
| 1421 | |
| 1422 | psa_status_t psa_driver_wrapper_mac_update( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1423 | @@ -2230,12 +2600,6 @@ psa_status_t psa_driver_wrapper_mac_update( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1424 | { |
| 1425 | switch( operation->id ) |
| 1426 | { |
| 1427 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1428 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1429 | - return( mbedtls_psa_mac_update( &operation->ctx.mbedtls_ctx, |
| 1430 | - input, input_length ) ); |
| 1431 | -#endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1432 | - |
| 1433 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1434 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1435 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1436 | @@ -2248,6 +2612,14 @@ psa_status_t psa_driver_wrapper_mac_update( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1437 | &operation->ctx.opaque_test_driver_ctx, |
| 1438 | input, input_length ) ); |
| 1439 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1440 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1441 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1442 | + return(cc3xx_mac_update(&operation->ctx.cc3xx_driver_ctx, input, input_length)); |
| 1443 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1444 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1445 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1446 | + return( mbedtls_psa_mac_update( &operation->ctx.mbedtls_ctx, |
| 1447 | + input, input_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1448 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1449 | default: |
| 1450 | (void) input; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1451 | @@ -2264,12 +2636,6 @@ psa_status_t psa_driver_wrapper_mac_sign_finish( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1452 | { |
| 1453 | switch( operation->id ) |
| 1454 | { |
| 1455 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1456 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1457 | - return( mbedtls_psa_mac_sign_finish( &operation->ctx.mbedtls_ctx, |
| 1458 | - mac, mac_size, mac_length ) ); |
| 1459 | -#endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1460 | - |
| 1461 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1462 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1463 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1464 | @@ -2282,6 +2648,15 @@ psa_status_t psa_driver_wrapper_mac_sign_finish( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1465 | &operation->ctx.opaque_test_driver_ctx, |
| 1466 | mac, mac_size, mac_length ) ); |
| 1467 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1468 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1469 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1470 | + return(cc3xx_mac_sign_finish(&operation->ctx.cc3xx_driver_ctx, |
| 1471 | + mac, mac_size, mac_length)); |
| 1472 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1473 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1474 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1475 | + return( mbedtls_psa_mac_sign_finish( &operation->ctx.mbedtls_ctx, |
| 1476 | + mac, mac_size, mac_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1477 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1478 | default: |
| 1479 | (void) mac; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1480 | @@ -2298,12 +2673,6 @@ psa_status_t psa_driver_wrapper_mac_verify_finish( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1481 | { |
| 1482 | switch( operation->id ) |
| 1483 | { |
| 1484 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1485 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1486 | - return( mbedtls_psa_mac_verify_finish( &operation->ctx.mbedtls_ctx, |
| 1487 | - mac, mac_length ) ); |
| 1488 | -#endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1489 | - |
| 1490 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1491 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1492 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1493 | @@ -2316,6 +2685,16 @@ psa_status_t psa_driver_wrapper_mac_verify_finish( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1494 | &operation->ctx.opaque_test_driver_ctx, |
| 1495 | mac, mac_length ) ); |
| 1496 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1497 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1498 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1499 | + return(cc3xx_mac_verify_finish( |
| 1500 | + &operation->ctx.cc3xx_driver_ctx, |
| 1501 | + mac, mac_length)); |
| 1502 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1503 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1504 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1505 | + return( mbedtls_psa_mac_verify_finish( &operation->ctx.mbedtls_ctx, |
| 1506 | + mac, mac_length ) ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1507 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1508 | default: |
| 1509 | (void) mac; |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1510 | @@ -2329,11 +2708,6 @@ psa_status_t psa_driver_wrapper_mac_abort( |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1511 | { |
| 1512 | switch( operation->id ) |
| 1513 | { |
| 1514 | -#if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1515 | - case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1516 | - return( mbedtls_psa_mac_abort( &operation->ctx.mbedtls_ctx ) ); |
| 1517 | -#endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1518 | - |
| 1519 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1520 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1521 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1522 | @@ -2343,6 +2717,13 @@ psa_status_t psa_driver_wrapper_mac_abort( |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1523 | return( mbedtls_test_opaque_mac_abort( |
| 1524 | &operation->ctx.opaque_test_driver_ctx ) ); |
| 1525 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1526 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1527 | + case PSA_CRYPTO_CC3XX_DRIVER_ID: |
| 1528 | + return(cc3xx_mac_abort(&operation->ctx.cc3xx_driver_ctx)); |
| 1529 | +#endif |
Summer Qin | 36f79f7 | 2022-07-05 14:53:35 +0800 | [diff] [blame] | 1530 | +#elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1531 | + case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1532 | + return( mbedtls_psa_mac_abort( &operation->ctx.mbedtls_ctx ) ); |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1533 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1534 | default: |
| 1535 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1536 | @@ -2350,7 +2731,58 @@ psa_status_t psa_driver_wrapper_mac_abort( |
| 1537 | } |
| 1538 | |
| 1539 | /* |
| 1540 | - * Asymmetric cryptography |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1541 | + * Key agreement functions |
| 1542 | + */ |
| 1543 | +psa_status_t psa_driver_wrapper_key_agreement( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1544 | + psa_algorithm_t alg, |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1545 | + const psa_key_attributes_t *attributes, |
| 1546 | + const uint8_t *priv_key, size_t priv_key_size, |
| 1547 | + const uint8_t *publ_key, size_t publ_key_size, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1548 | + uint8_t *output, size_t output_size, size_t *output_length ) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1549 | +{ |
| 1550 | + psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1551 | + |
| 1552 | + psa_key_location_t location = |
| 1553 | + PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1554 | + |
| 1555 | + switch( location ) |
| 1556 | + { |
| 1557 | + case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1558 | + /* Key is stored in the slot in export representation, so |
| 1559 | + * cycle through all known transparent accelerators */ |
| 1560 | +#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1561 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1562 | + status = cc3xx_key_agreement( attributes, |
| 1563 | + priv_key, |
| 1564 | + priv_key_size, |
| 1565 | + publ_key, |
| 1566 | + publ_key_size, |
| 1567 | + output, |
| 1568 | + output_size, |
| 1569 | + output_length, |
| 1570 | + alg ); |
| 1571 | + return( status ); |
| 1572 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1573 | +#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1574 | + (void) status; |
| 1575 | + return ( PSA_ERROR_NOT_SUPPORTED ); |
| 1576 | + default: |
| 1577 | + /* Key is declared with a lifetime not known to us */ |
| 1578 | + (void) priv_key; |
| 1579 | + (void) priv_key_size; |
| 1580 | + (void) publ_key; |
| 1581 | + (void) publ_key_size; |
| 1582 | + (void) output; |
| 1583 | + (void) output_size; |
| 1584 | + (void) output_length; |
| 1585 | + (void) alg; |
| 1586 | + |
| 1587 | + return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1588 | + } |
| 1589 | +} |
| 1590 | + |
| 1591 | +/* |
| 1592 | + * Asymmetric operations |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1593 | */ |
| 1594 | psa_status_t psa_driver_wrapper_asymmetric_encrypt( |
| 1595 | const psa_key_attributes_t *attributes, const uint8_t *key_buffer, |
| 1596 | @@ -2368,6 +2800,20 @@ psa_status_t psa_driver_wrapper_asymmetric_encrypt( |
| 1597 | /* Key is stored in the slot in export representation, so |
| 1598 | * cycle through all known transparent accelerators */ |
| 1599 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1600 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1601 | + status = cc3xx_asymmetric_encrypt( attributes, |
| 1602 | + key_buffer, |
| 1603 | + key_buffer_size, |
| 1604 | + alg, |
| 1605 | + input, |
| 1606 | + input_length, |
| 1607 | + salt, |
| 1608 | + salt_length, |
| 1609 | + output, |
| 1610 | + output_size, |
| 1611 | + output_length ); |
| 1612 | + return( status ); |
| 1613 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1614 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1615 | status = mbedtls_test_transparent_asymmetric_encrypt( attributes, |
| 1616 | key_buffer, key_buffer_size, alg, input, input_length, |
| 1617 | @@ -2426,6 +2872,20 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt( |
| 1618 | /* Key is stored in the slot in export representation, so |
| 1619 | * cycle through all known transparent accelerators */ |
| 1620 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1621 | +#if defined(PSA_CRYPTO_DRIVER_CC3XX) |
| 1622 | + status = cc3xx_asymmetric_decrypt( attributes, |
| 1623 | + key_buffer, |
| 1624 | + key_buffer_size, |
| 1625 | + alg, |
| 1626 | + input, |
| 1627 | + input_length, |
| 1628 | + salt, |
| 1629 | + salt_length, |
| 1630 | + output, |
| 1631 | + output_size, |
| 1632 | + output_length ); |
| 1633 | + return( status ); |
| 1634 | +#endif /* PSA_CRYPTO_DRIVER_CC3XX */ |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1635 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1636 | status = mbedtls_test_transparent_asymmetric_decrypt( attributes, |
| 1637 | key_buffer, key_buffer_size, alg, input, input_length, |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1638 | diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1639 | index 12c649da3..ac0cd1d89 100644 |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1640 | --- a/library/psa_crypto_driver_wrappers.h |
| 1641 | +++ b/library/psa_crypto_driver_wrappers.h |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1642 | @@ -361,6 +361,20 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt( |
| 1643 | size_t output_size, |
| 1644 | size_t *output_length ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1645 | |
| 1646 | +/* |
| 1647 | + * Key agreement functions |
| 1648 | + */ |
| 1649 | +psa_status_t psa_driver_wrapper_key_agreement( |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1650 | + psa_algorithm_t alg, |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1651 | + const psa_key_attributes_t *attributes, |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1652 | + const uint8_t *priv_key, |
| 1653 | + size_t priv_key_size, |
| 1654 | + const uint8_t *publ_key, |
| 1655 | + size_t peer_key_size, |
| 1656 | + uint8_t *output, |
| 1657 | + size_t output_size, |
| 1658 | + size_t *output_length ); |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1659 | + |
| 1660 | #endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */ |
| 1661 | |
| 1662 | /* End of automatically generated file. */ |
| 1663 | -- |
Antonio de Angelis | 90bee0f | 2022-07-13 11:22:41 +0100 | [diff] [blame^] | 1664 | 2.25.1 |
Antonio de Angelis | 86b9831 | 2021-12-17 21:42:40 +0100 | [diff] [blame] | 1665 | |