Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Functions to delegate cryptographic operations to an available |
| 3 | * and appropriate accelerator. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 4 | * Warning: This file will be auto-generated in the future. |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 5 | */ |
Steven Cooreman | 2c7b2f8 | 2020-09-02 13:43:46 +0200 | [diff] [blame] | 6 | /* Copyright The Mbed TLS Contributors |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: Apache-2.0 |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | * not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 22 | #include "psa_crypto_aead.h" |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 23 | #include "psa_crypto_cipher.h" |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 24 | #include "psa_crypto_core.h" |
| 25 | #include "psa_crypto_driver_wrappers.h" |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 26 | #include "psa_crypto_hash.h" |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 27 | #include "psa_crypto_mac.h" |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 28 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 29 | #include "mbedtls/platform.h" |
| 30 | |
| 31 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 32 | |
| 33 | /* Include test driver definition when running tests */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 34 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 35 | #ifndef PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 36 | #define PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 37 | #endif |
| 38 | #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 39 | #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 40 | #endif |
Ronald Cron | ce1d8d2 | 2021-04-30 17:00:34 +0200 | [diff] [blame] | 41 | #include "test/drivers/test_driver.h" |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 42 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 43 | |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 44 | /* Repeat above block for each JSON-declared driver during autogeneration */ |
Steven Cooreman | aa87fd0 | 2021-03-15 18:54:03 +0100 | [diff] [blame] | 45 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */ |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 46 | |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 47 | /* Auto-generated values depending on which drivers are registered. |
| 48 | * ID 0 is reserved for unallocated operations. |
| 49 | * ID 1 is reserved for the Mbed TLS software driver. */ |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 50 | #define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1) |
| 51 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 52 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 53 | #define PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID (2) |
| 54 | #define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (3) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 55 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 56 | |
| 57 | /* Support the 'old' SE interface when asked to */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 58 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 59 | /* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style |
| 60 | * SE driver is present, to avoid unused argument errors at compile time. */ |
| 61 | #ifndef PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 62 | #define PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 63 | #endif |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 64 | #include "psa_crypto_se.h" |
| 65 | #endif |
| 66 | |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 67 | /* Start delegation functions */ |
gabor-mezei-arm | 50eac35 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 68 | psa_status_t psa_driver_wrapper_sign_message( |
| 69 | const psa_key_attributes_t *attributes, |
| 70 | const uint8_t *key_buffer, |
| 71 | size_t key_buffer_size, |
| 72 | psa_algorithm_t alg, |
| 73 | const uint8_t *input, |
| 74 | size_t input_length, |
| 75 | uint8_t *signature, |
| 76 | size_t signature_size, |
| 77 | size_t *signature_length ) |
| 78 | { |
| 79 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 80 | |
| 81 | /* Try dynamically-registered SE interface first */ |
| 82 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 83 | const psa_drv_se_t *drv; |
| 84 | psa_drv_se_context_t *drv_context; |
| 85 | |
| 86 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 87 | { |
| 88 | if( drv->asymmetric == NULL || |
| 89 | drv->asymmetric->p_sign == NULL ) |
| 90 | { |
| 91 | /* Key is defined in SE, but we have no way to exercise it */ |
| 92 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 93 | } |
| 94 | |
| 95 | size_t hash_length; |
| 96 | uint8_t hash[PSA_HASH_MAX_SIZE]; |
| 97 | |
| 98 | status = psa_driver_wrapper_hash_compute( PSA_ALG_SIGN_GET_HASH( alg ), |
| 99 | input, input_length, |
| 100 | hash, sizeof( hash ), |
| 101 | &hash_length ); |
| 102 | |
| 103 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 104 | return( status ); |
| 105 | |
| 106 | return( drv->asymmetric->p_sign( |
| 107 | drv_context, *( (psa_key_slot_number_t *)key_buffer ), |
| 108 | alg, hash, hash_length, |
| 109 | signature, signature_size, signature_length ) ); |
| 110 | } |
| 111 | #endif /* PSA_CRYPTO_SE_C */ |
| 112 | |
| 113 | psa_key_location_t location = |
| 114 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 115 | |
| 116 | switch( location ) |
| 117 | { |
| 118 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 119 | /* Key is stored in the slot in export representation, so |
| 120 | * cycle through all known transparent accelerators */ |
| 121 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 122 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 123 | status = mbedtls_test_transparent_signature_sign_message( |
| 124 | attributes, |
| 125 | key_buffer, |
| 126 | key_buffer_size, |
| 127 | alg, |
| 128 | input, |
| 129 | input_length, |
| 130 | signature, |
| 131 | signature_size, |
| 132 | signature_length ); |
| 133 | /* Declared with fallback == true */ |
| 134 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 135 | return( status ); |
| 136 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 137 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 138 | /* Fell through, meaning no accelerator supports this operation */ |
| 139 | return( psa_sign_message_internal( attributes, |
| 140 | key_buffer, |
| 141 | key_buffer_size, |
| 142 | alg, |
| 143 | input, |
| 144 | input_length, |
| 145 | signature, |
| 146 | signature_size, |
| 147 | signature_length ) ); |
| 148 | |
| 149 | /* Add cases for opaque driver here */ |
| 150 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 151 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
gabor-mezei-arm | 2522c0b | 2021-04-27 18:52:51 +0200 | [diff] [blame^] | 152 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
gabor-mezei-arm | 50eac35 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 153 | return( mbedtls_test_opaque_signature_sign_message( |
| 154 | attributes, |
| 155 | key_buffer, |
| 156 | key_buffer_size, |
| 157 | alg, |
| 158 | input, |
| 159 | input_length, |
| 160 | signature, |
| 161 | signature_size, |
| 162 | signature_length ) ); |
| 163 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 164 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 165 | default: |
| 166 | /* Key is declared with a lifetime not known to us */ |
| 167 | (void)status; |
| 168 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | psa_status_t psa_driver_wrapper_verify_message( |
| 173 | const psa_key_attributes_t *attributes, |
| 174 | const uint8_t *key_buffer, |
| 175 | size_t key_buffer_size, |
| 176 | psa_algorithm_t alg, |
| 177 | const uint8_t *input, |
| 178 | size_t input_length, |
| 179 | const uint8_t *signature, |
| 180 | size_t signature_length ) |
| 181 | { |
| 182 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 183 | |
| 184 | /* Try dynamically-registered SE interface first */ |
| 185 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 186 | const psa_drv_se_t *drv; |
| 187 | psa_drv_se_context_t *drv_context; |
| 188 | |
| 189 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 190 | { |
| 191 | if( drv->asymmetric == NULL || |
| 192 | drv->asymmetric->p_verify == NULL ) |
| 193 | { |
| 194 | /* Key is defined in SE, but we have no way to exercise it */ |
| 195 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 196 | } |
| 197 | |
| 198 | size_t hash_length; |
| 199 | uint8_t hash[PSA_HASH_MAX_SIZE]; |
| 200 | |
| 201 | status = psa_driver_wrapper_hash_compute( PSA_ALG_SIGN_GET_HASH( alg ), |
| 202 | input, input_length, |
| 203 | hash, sizeof( hash ), |
| 204 | &hash_length ); |
| 205 | |
| 206 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 207 | return( status ); |
| 208 | |
| 209 | return( drv->asymmetric->p_verify( |
| 210 | drv_context, *( (psa_key_slot_number_t *)key_buffer ), |
| 211 | alg, hash, hash_length, |
| 212 | signature, signature_length ) ); |
| 213 | } |
| 214 | #endif /* PSA_CRYPTO_SE_C */ |
| 215 | |
| 216 | psa_key_location_t location = |
| 217 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 218 | |
| 219 | switch( location ) |
| 220 | { |
| 221 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 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_TEST) |
| 226 | status = mbedtls_test_transparent_signature_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_TEST */ |
| 239 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 240 | |
| 241 | return( psa_verify_message_internal( attributes, |
| 242 | key_buffer, |
| 243 | key_buffer_size, |
| 244 | alg, |
| 245 | input, |
| 246 | input_length, |
| 247 | signature, |
| 248 | signature_length ) ); |
| 249 | |
| 250 | /* Add cases for opaque driver here */ |
| 251 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 252 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
gabor-mezei-arm | 2522c0b | 2021-04-27 18:52:51 +0200 | [diff] [blame^] | 253 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
gabor-mezei-arm | 50eac35 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 254 | return( mbedtls_test_opaque_signature_verify_message( |
| 255 | attributes, |
| 256 | key_buffer, |
| 257 | key_buffer_size, |
| 258 | alg, |
| 259 | input, |
| 260 | input_length, |
| 261 | signature, |
| 262 | signature_length ) ); |
| 263 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 264 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 265 | default: |
| 266 | /* Key is declared with a lifetime not known to us */ |
| 267 | (void)status; |
| 268 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 269 | } |
| 270 | } |
| 271 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 272 | psa_status_t psa_driver_wrapper_sign_hash( |
| 273 | const psa_key_attributes_t *attributes, |
| 274 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 275 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 276 | uint8_t *signature, size_t signature_size, size_t *signature_length ) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 277 | { |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 278 | /* Try dynamically-registered SE interface first */ |
| 279 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 280 | const psa_drv_se_t *drv; |
| 281 | psa_drv_se_context_t *drv_context; |
| 282 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 283 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 284 | { |
| 285 | if( drv->asymmetric == NULL || |
| 286 | drv->asymmetric->p_sign == NULL ) |
| 287 | { |
| 288 | /* Key is defined in SE, but we have no way to exercise it */ |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 289 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 290 | } |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 291 | return( drv->asymmetric->p_sign( |
| 292 | drv_context, *( (psa_key_slot_number_t *)key_buffer ), |
| 293 | alg, hash, hash_length, |
| 294 | signature, signature_size, signature_length ) ); |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 295 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 296 | #endif /* PSA_CRYPTO_SE_C */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 297 | |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 298 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 299 | psa_key_location_t location = |
| 300 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 301 | |
| 302 | switch( location ) |
| 303 | { |
| 304 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 305 | /* Key is stored in the slot in export representation, so |
| 306 | * cycle through all known transparent accelerators */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 307 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 308 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 309 | status = mbedtls_test_transparent_signature_sign_hash( attributes, |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 310 | key_buffer, |
| 311 | key_buffer_size, |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 312 | alg, |
| 313 | hash, |
| 314 | hash_length, |
| 315 | signature, |
| 316 | signature_size, |
| 317 | signature_length ); |
| 318 | /* Declared with fallback == true */ |
| 319 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 320 | return( status ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 321 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 322 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 323 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 324 | return( psa_sign_hash_internal( attributes, |
| 325 | key_buffer, |
| 326 | key_buffer_size, |
| 327 | alg, |
| 328 | hash, |
| 329 | hash_length, |
| 330 | signature, |
| 331 | signature_size, |
| 332 | signature_length ) ); |
| 333 | |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 334 | /* Add cases for opaque driver here */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 335 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 336 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 337 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 338 | return( mbedtls_test_opaque_signature_sign_hash( attributes, |
| 339 | key_buffer, |
| 340 | key_buffer_size, |
| 341 | alg, |
| 342 | hash, |
| 343 | hash_length, |
| 344 | signature, |
| 345 | signature_size, |
| 346 | signature_length ) ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 347 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 348 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 349 | default: |
| 350 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 351 | (void)status; |
| 352 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 353 | } |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 356 | psa_status_t psa_driver_wrapper_verify_hash( |
| 357 | const psa_key_attributes_t *attributes, |
| 358 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 359 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 360 | const uint8_t *signature, size_t signature_length ) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 361 | { |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 362 | /* Try dynamically-registered SE interface first */ |
| 363 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 364 | const psa_drv_se_t *drv; |
| 365 | psa_drv_se_context_t *drv_context; |
| 366 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 367 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 368 | { |
| 369 | if( drv->asymmetric == NULL || |
| 370 | drv->asymmetric->p_verify == NULL ) |
| 371 | { |
| 372 | /* Key is defined in SE, but we have no way to exercise it */ |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 373 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 374 | } |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 375 | return( drv->asymmetric->p_verify( |
| 376 | drv_context, *( (psa_key_slot_number_t *)key_buffer ), |
| 377 | alg, hash, hash_length, |
| 378 | signature, signature_length ) ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 379 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 380 | #endif /* PSA_CRYPTO_SE_C */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 381 | |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 382 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 383 | psa_key_location_t location = |
| 384 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 385 | |
| 386 | switch( location ) |
| 387 | { |
| 388 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 389 | /* Key is stored in the slot in export representation, so |
| 390 | * cycle through all known transparent accelerators */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 391 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 392 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 393 | status = mbedtls_test_transparent_signature_verify_hash( |
| 394 | attributes, |
| 395 | key_buffer, |
| 396 | key_buffer_size, |
| 397 | alg, |
| 398 | hash, |
| 399 | hash_length, |
| 400 | signature, |
| 401 | signature_length ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 402 | /* Declared with fallback == true */ |
| 403 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 404 | return( status ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 405 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 406 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 407 | |
| 408 | return( psa_verify_hash_internal( attributes, |
| 409 | key_buffer, |
| 410 | key_buffer_size, |
| 411 | alg, |
| 412 | hash, |
| 413 | hash_length, |
| 414 | signature, |
| 415 | signature_length ) ); |
| 416 | |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 417 | /* Add cases for opaque driver here */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 418 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 419 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 420 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 421 | return( mbedtls_test_opaque_signature_verify_hash( attributes, |
| 422 | key_buffer, |
| 423 | key_buffer_size, |
| 424 | alg, |
| 425 | hash, |
| 426 | hash_length, |
| 427 | signature, |
| 428 | signature_length ) ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 429 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 430 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 431 | default: |
| 432 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 433 | (void)status; |
| 434 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 435 | } |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Steven Cooreman | b938b0b | 2021-04-06 13:08:42 +0200 | [diff] [blame] | 438 | /** Get the key buffer size required to store the key material of a key |
| 439 | * associated with an opaque driver without storage. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 440 | * |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 441 | * \param[in] attributes The key attributes. |
| 442 | * \param[out] key_buffer_size Minimum buffer size to contain the key material |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 443 | * |
| 444 | * \retval #PSA_SUCCESS |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 445 | * The minimum size for a buffer to contain the key material has been |
| 446 | * returned successfully. |
| 447 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 448 | * The size in bits of the key is not valid. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 449 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 450 | * The type and/or the size in bits of the key or the combination of |
| 451 | * the two is not supported. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 452 | */ |
Ronald Cron | 9df74be | 2020-12-05 19:15:23 +0100 | [diff] [blame] | 453 | psa_status_t psa_driver_wrapper_get_key_buffer_size( |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 454 | const psa_key_attributes_t *attributes, |
| 455 | size_t *key_buffer_size ) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 456 | { |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 457 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 458 | psa_key_type_t key_type = attributes->core.type; |
| 459 | size_t key_bits = attributes->core.bits; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 460 | |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 461 | *key_buffer_size = 0; |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 462 | switch( location ) |
| 463 | { |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 464 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 465 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 466 | #if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 467 | /* Emulate property 'builtin_key_size' */ |
| 468 | if( psa_key_id_is_builtin( |
| 469 | MBEDTLS_SVC_KEY_ID_GET_KEY_ID( |
| 470 | psa_get_key_id( attributes ) ) ) ) |
| 471 | { |
Steven Cooreman | 203bcbb | 2021-03-18 17:17:40 +0100 | [diff] [blame] | 472 | *key_buffer_size = sizeof( psa_drv_slot_number_t ); |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 473 | return( PSA_SUCCESS ); |
| 474 | } |
| 475 | #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 476 | *key_buffer_size = mbedtls_test_size_function( key_type, key_bits ); |
Ronald Cron | 4607c82 | 2021-04-14 10:55:34 +0200 | [diff] [blame] | 477 | return( ( *key_buffer_size != 0 ) ? |
| 478 | PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED ); |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 479 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 480 | |
| 481 | default: |
Ronald Cron | 9df74be | 2020-12-05 19:15:23 +0100 | [diff] [blame] | 482 | (void)key_type; |
| 483 | (void)key_bits; |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 484 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 485 | } |
| 486 | } |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 487 | |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 488 | psa_status_t psa_driver_wrapper_generate_key( |
| 489 | const psa_key_attributes_t *attributes, |
| 490 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 491 | { |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 492 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 493 | psa_key_location_t location = |
| 494 | PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime); |
| 495 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 496 | /* Try dynamically-registered SE interface first */ |
| 497 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 498 | const psa_drv_se_t *drv; |
| 499 | psa_drv_se_context_t *drv_context; |
| 500 | |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 501 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 502 | { |
| 503 | size_t pubkey_length = 0; /* We don't support this feature yet */ |
| 504 | if( drv->key_management == NULL || |
| 505 | drv->key_management->p_generate == NULL ) |
| 506 | { |
| 507 | /* Key is defined as being in SE, but we have no way to generate it */ |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 508 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 509 | } |
| 510 | return( drv->key_management->p_generate( |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 511 | drv_context, |
| 512 | *( (psa_key_slot_number_t *)key_buffer ), |
Ronald Cron | ea0f8a6 | 2020-11-25 17:52:23 +0100 | [diff] [blame] | 513 | attributes, NULL, 0, &pubkey_length ) ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 514 | } |
| 515 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 516 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 517 | switch( location ) |
| 518 | { |
| 519 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 520 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 521 | /* Transparent drivers are limited to generating asymmetric keys */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 522 | if( PSA_KEY_TYPE_IS_ASYMMETRIC( attributes->core.type ) ) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 523 | { |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 524 | /* Cycle through all known transparent accelerators */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 525 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 526 | status = mbedtls_test_transparent_generate_key( |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 527 | attributes, key_buffer, key_buffer_size, |
| 528 | key_buffer_length ); |
| 529 | /* Declared with fallback == true */ |
| 530 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 531 | break; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 532 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 533 | } |
| 534 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 535 | |
| 536 | /* Software fallback */ |
| 537 | status = psa_generate_key_internal( |
| 538 | attributes, key_buffer, key_buffer_size, key_buffer_length ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 539 | break; |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 540 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 541 | /* Add cases for opaque driver here */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 542 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 543 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 544 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 545 | status = mbedtls_test_opaque_generate_key( |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 546 | attributes, key_buffer, key_buffer_size, key_buffer_length ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 547 | break; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 548 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 549 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 550 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 551 | default: |
| 552 | /* Key is declared with a lifetime not known to us */ |
| 553 | status = PSA_ERROR_INVALID_ARGUMENT; |
| 554 | break; |
| 555 | } |
| 556 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 557 | return( status ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 558 | } |
| 559 | |
Ronald Cron | 8328287 | 2020-11-22 14:02:39 +0100 | [diff] [blame] | 560 | psa_status_t psa_driver_wrapper_import_key( |
| 561 | const psa_key_attributes_t *attributes, |
| 562 | const uint8_t *data, |
| 563 | size_t data_length, |
| 564 | uint8_t *key_buffer, |
| 565 | size_t key_buffer_size, |
| 566 | size_t *key_buffer_length, |
| 567 | size_t *bits ) |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 568 | { |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 569 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 570 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( |
| 571 | psa_get_key_lifetime( attributes ) ); |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 572 | |
Ronald Cron | fb2ed5b | 2020-11-30 12:11:01 +0100 | [diff] [blame] | 573 | /* Try dynamically-registered SE interface first */ |
| 574 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 575 | const psa_drv_se_t *drv; |
| 576 | psa_drv_se_context_t *drv_context; |
| 577 | |
| 578 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 579 | { |
| 580 | if( drv->key_management == NULL || |
| 581 | drv->key_management->p_import == NULL ) |
| 582 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 583 | |
| 584 | /* The driver should set the number of key bits, however in |
| 585 | * case it doesn't, we initialize bits to an invalid value. */ |
| 586 | *bits = PSA_MAX_KEY_BITS + 1; |
| 587 | status = drv->key_management->p_import( |
| 588 | drv_context, |
| 589 | *( (psa_key_slot_number_t *)key_buffer ), |
| 590 | attributes, data, data_length, bits ); |
| 591 | |
| 592 | if( status != PSA_SUCCESS ) |
| 593 | return( status ); |
| 594 | |
| 595 | if( (*bits) > PSA_MAX_KEY_BITS ) |
| 596 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 597 | |
| 598 | return( PSA_SUCCESS ); |
| 599 | } |
| 600 | #endif /* PSA_CRYPTO_SE_C */ |
| 601 | |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 602 | switch( location ) |
| 603 | { |
| 604 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 605 | /* Key is stored in the slot in export representation, so |
| 606 | * cycle through all known transparent accelerators */ |
| 607 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 608 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 609 | status = mbedtls_test_transparent_import_key( |
| 610 | attributes, |
| 611 | data, data_length, |
| 612 | key_buffer, key_buffer_size, |
| 613 | key_buffer_length, bits ); |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 614 | /* Declared with fallback == true */ |
| 615 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 616 | return( status ); |
| 617 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 618 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 619 | /* Fell through, meaning no accelerator supports this operation */ |
| 620 | return( psa_import_key_into_slot( attributes, |
| 621 | data, data_length, |
| 622 | key_buffer, key_buffer_size, |
| 623 | key_buffer_length, bits ) ); |
| 624 | |
| 625 | default: |
Ronald Cron | fb2ed5b | 2020-11-30 12:11:01 +0100 | [diff] [blame] | 626 | /* Importing a key with external storage in not yet supported. |
| 627 | * Return in error indicating that the lifetime is not valid. */ |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 628 | (void)status; |
Ronald Cron | fb2ed5b | 2020-11-30 12:11:01 +0100 | [diff] [blame] | 629 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 632 | } |
| 633 | |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 634 | psa_status_t psa_driver_wrapper_export_key( |
| 635 | const psa_key_attributes_t *attributes, |
| 636 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 637 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 638 | |
| 639 | { |
| 640 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 641 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( |
| 642 | psa_get_key_lifetime( attributes ) ); |
| 643 | |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 644 | /* Try dynamically-registered SE interface first */ |
| 645 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 646 | const psa_drv_se_t *drv; |
| 647 | psa_drv_se_context_t *drv_context; |
| 648 | |
| 649 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 650 | { |
| 651 | if( ( drv->key_management == NULL ) || |
| 652 | ( drv->key_management->p_export == NULL ) ) |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 653 | { |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 654 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 655 | } |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 656 | |
| 657 | return( drv->key_management->p_export( |
| 658 | drv_context, |
| 659 | *( (psa_key_slot_number_t *)key_buffer ), |
| 660 | data, data_size, data_length ) ); |
| 661 | } |
| 662 | #endif /* PSA_CRYPTO_SE_C */ |
| 663 | |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 664 | switch( location ) |
| 665 | { |
| 666 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 667 | return( psa_export_key_internal( attributes, |
| 668 | key_buffer, |
| 669 | key_buffer_size, |
| 670 | data, |
| 671 | data_size, |
| 672 | data_length ) ); |
| 673 | |
| 674 | /* Add cases for opaque driver here */ |
| 675 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 676 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 677 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 678 | return( mbedtls_test_opaque_export_key( attributes, |
| 679 | key_buffer, |
| 680 | key_buffer_size, |
| 681 | data, |
| 682 | data_size, |
| 683 | data_length ) ); |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 684 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 685 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 686 | default: |
| 687 | /* Key is declared with a lifetime not known to us */ |
| 688 | return( status ); |
| 689 | } |
| 690 | } |
| 691 | |
Ronald Cron | 84cc994 | 2020-11-25 14:30:05 +0100 | [diff] [blame] | 692 | psa_status_t psa_driver_wrapper_export_public_key( |
| 693 | const psa_key_attributes_t *attributes, |
| 694 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 695 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 696 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 697 | { |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 698 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | 84cc994 | 2020-11-25 14:30:05 +0100 | [diff] [blame] | 699 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( |
| 700 | psa_get_key_lifetime( attributes ) ); |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 701 | |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 702 | /* Try dynamically-registered SE interface first */ |
| 703 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 704 | const psa_drv_se_t *drv; |
| 705 | psa_drv_se_context_t *drv_context; |
| 706 | |
| 707 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 708 | { |
| 709 | if( ( drv->key_management == NULL ) || |
| 710 | ( drv->key_management->p_export_public == NULL ) ) |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 711 | { |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 712 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 713 | } |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 714 | |
| 715 | return( drv->key_management->p_export_public( |
| 716 | drv_context, |
| 717 | *( (psa_key_slot_number_t *)key_buffer ), |
| 718 | data, data_size, data_length ) ); |
| 719 | } |
| 720 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 721 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 722 | switch( location ) |
| 723 | { |
| 724 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 725 | /* Key is stored in the slot in export representation, so |
| 726 | * cycle through all known transparent accelerators */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 727 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 728 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 729 | status = mbedtls_test_transparent_export_public_key( |
| 730 | attributes, |
| 731 | key_buffer, |
| 732 | key_buffer_size, |
| 733 | data, |
| 734 | data_size, |
| 735 | data_length ); |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 736 | /* Declared with fallback == true */ |
| 737 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 738 | return( status ); |
| 739 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 740 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 741 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 742 | return( psa_export_public_key_internal( attributes, |
| 743 | key_buffer, |
| 744 | key_buffer_size, |
| 745 | data, |
| 746 | data_size, |
| 747 | data_length ) ); |
| 748 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 749 | /* Add cases for opaque driver here */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 750 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 751 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 752 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 753 | return( mbedtls_test_opaque_export_public_key( attributes, |
| 754 | key_buffer, |
| 755 | key_buffer_size, |
| 756 | data, |
| 757 | data_size, |
| 758 | data_length ) ); |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 759 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 760 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 761 | default: |
| 762 | /* Key is declared with a lifetime not known to us */ |
| 763 | return( status ); |
| 764 | } |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 767 | psa_status_t psa_driver_wrapper_get_builtin_key( |
| 768 | psa_drv_slot_number_t slot_number, |
| 769 | psa_key_attributes_t *attributes, |
| 770 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) |
| 771 | { |
| 772 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 773 | switch( location ) |
| 774 | { |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 775 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 776 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 777 | return( mbedtls_test_opaque_get_builtin_key( |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 778 | slot_number, |
| 779 | attributes, |
| 780 | key_buffer, key_buffer_size, key_buffer_length ) ); |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 781 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 782 | default: |
| 783 | (void) slot_number; |
| 784 | (void) key_buffer; |
| 785 | (void) key_buffer_size; |
| 786 | (void) key_buffer_length; |
| 787 | return( PSA_ERROR_DOES_NOT_EXIST ); |
| 788 | } |
| 789 | } |
| 790 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 791 | /* |
| 792 | * Cipher functions |
| 793 | */ |
| 794 | psa_status_t psa_driver_wrapper_cipher_encrypt( |
| 795 | psa_key_slot_t *slot, |
| 796 | psa_algorithm_t alg, |
| 797 | const uint8_t *input, |
| 798 | size_t input_length, |
| 799 | uint8_t *output, |
| 800 | size_t output_size, |
| 801 | size_t *output_length ) |
| 802 | { |
| 803 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 804 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 805 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 806 | psa_key_attributes_t attributes = { |
| 807 | .core = slot->attr |
| 808 | }; |
| 809 | |
| 810 | switch( location ) |
| 811 | { |
| 812 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 813 | /* Key is stored in the slot in export representation, so |
| 814 | * cycle through all known transparent accelerators */ |
| 815 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 816 | status = mbedtls_test_transparent_cipher_encrypt( &attributes, |
| 817 | slot->key.data, |
| 818 | slot->key.bytes, |
| 819 | alg, |
| 820 | input, |
| 821 | input_length, |
| 822 | output, |
| 823 | output_size, |
| 824 | output_length ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 825 | /* Declared with fallback == true */ |
| 826 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 827 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 828 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 829 | /* Fell through, meaning no accelerator supports this operation */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 830 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 831 | /* Add cases for opaque driver here */ |
| 832 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 833 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 834 | return( mbedtls_test_opaque_cipher_encrypt( &attributes, |
| 835 | slot->key.data, |
| 836 | slot->key.bytes, |
| 837 | alg, |
| 838 | input, |
| 839 | input_length, |
| 840 | output, |
| 841 | output_size, |
| 842 | output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 843 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 844 | default: |
| 845 | /* Key is declared with a lifetime not known to us */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 846 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 847 | } |
| 848 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 849 | (void) slot; |
| 850 | (void) alg; |
| 851 | (void) input; |
| 852 | (void) input_length; |
| 853 | (void) output; |
| 854 | (void) output_size; |
| 855 | (void) output_length; |
| 856 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 857 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 858 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 859 | } |
| 860 | |
| 861 | psa_status_t psa_driver_wrapper_cipher_decrypt( |
| 862 | psa_key_slot_t *slot, |
| 863 | psa_algorithm_t alg, |
| 864 | const uint8_t *input, |
| 865 | size_t input_length, |
| 866 | uint8_t *output, |
| 867 | size_t output_size, |
| 868 | size_t *output_length ) |
| 869 | { |
| 870 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 871 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 872 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 873 | psa_key_attributes_t attributes = { |
| 874 | .core = slot->attr |
| 875 | }; |
| 876 | |
| 877 | switch( location ) |
| 878 | { |
| 879 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 880 | /* Key is stored in the slot in export representation, so |
| 881 | * cycle through all known transparent accelerators */ |
| 882 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 883 | status = mbedtls_test_transparent_cipher_decrypt( &attributes, |
| 884 | slot->key.data, |
| 885 | slot->key.bytes, |
| 886 | alg, |
| 887 | input, |
| 888 | input_length, |
| 889 | output, |
| 890 | output_size, |
| 891 | output_length ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 892 | /* Declared with fallback == true */ |
| 893 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 894 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 895 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 896 | /* Fell through, meaning no accelerator supports this operation */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 897 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 898 | /* Add cases for opaque driver here */ |
| 899 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 900 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 901 | return( mbedtls_test_opaque_cipher_decrypt( &attributes, |
| 902 | slot->key.data, |
| 903 | slot->key.bytes, |
| 904 | alg, |
| 905 | input, |
| 906 | input_length, |
| 907 | output, |
| 908 | output_size, |
| 909 | output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 910 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 911 | default: |
| 912 | /* Key is declared with a lifetime not known to us */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 913 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 914 | } |
| 915 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 916 | (void) slot; |
| 917 | (void) alg; |
| 918 | (void) input; |
| 919 | (void) input_length; |
| 920 | (void) output; |
| 921 | (void) output_size; |
| 922 | (void) output_length; |
| 923 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 924 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 925 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 926 | } |
| 927 | |
| 928 | psa_status_t psa_driver_wrapper_cipher_encrypt_setup( |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 929 | psa_cipher_operation_t *operation, |
| 930 | const psa_key_attributes_t *attributes, |
| 931 | const uint8_t *key_buffer, size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 932 | psa_algorithm_t alg ) |
| 933 | { |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 934 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 935 | psa_key_location_t location = |
| 936 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 937 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 938 | switch( location ) |
| 939 | { |
| 940 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 941 | /* Key is stored in the slot in export representation, so |
| 942 | * cycle through all known transparent accelerators */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 943 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 944 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 945 | status = mbedtls_test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 946 | &operation->ctx.transparent_test_driver_ctx, |
| 947 | attributes, |
| 948 | key_buffer, |
| 949 | key_buffer_size, |
| 950 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 951 | /* Declared with fallback == true */ |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 952 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 953 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 954 | |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 955 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 956 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 957 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 958 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 959 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 960 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 961 | status = mbedtls_psa_cipher_encrypt_setup( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 962 | attributes, |
| 963 | key_buffer, |
| 964 | key_buffer_size, |
| 965 | alg ); |
| 966 | if( status == PSA_SUCCESS ) |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 967 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 968 | |
Ronald Cron | 7b4154d | 2021-03-19 14:49:41 +0100 | [diff] [blame] | 969 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 970 | return( status ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 971 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 972 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 973 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 974 | /* Add cases for opaque driver here */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 975 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 976 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 977 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 978 | status = mbedtls_test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 979 | &operation->ctx.opaque_test_driver_ctx, |
| 980 | attributes, |
| 981 | key_buffer, key_buffer_size, |
| 982 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 983 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 984 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 985 | operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 986 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 987 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 988 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 989 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 990 | default: |
| 991 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 992 | (void)status; |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 993 | (void)key_buffer; |
| 994 | (void)key_buffer_size; |
| 995 | (void)alg; |
Ronald Cron | c45b4af | 2020-09-29 16:18:05 +0200 | [diff] [blame] | 996 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 997 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | psa_status_t psa_driver_wrapper_cipher_decrypt_setup( |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 1001 | psa_cipher_operation_t *operation, |
| 1002 | const psa_key_attributes_t *attributes, |
| 1003 | const uint8_t *key_buffer, size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1004 | psa_algorithm_t alg ) |
| 1005 | { |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1006 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 1007 | psa_key_location_t location = |
| 1008 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1009 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1010 | switch( location ) |
| 1011 | { |
| 1012 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1013 | /* Key is stored in the slot in export representation, so |
| 1014 | * cycle through all known transparent accelerators */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 1015 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1016 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1017 | status = mbedtls_test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1018 | &operation->ctx.transparent_test_driver_ctx, |
| 1019 | attributes, |
| 1020 | key_buffer, |
| 1021 | key_buffer_size, |
| 1022 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1023 | /* Declared with fallback == true */ |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 1024 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1025 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 1026 | |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 1027 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1028 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1029 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 1030 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1031 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1032 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 1033 | status = mbedtls_psa_cipher_decrypt_setup( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1034 | attributes, |
| 1035 | key_buffer, |
| 1036 | key_buffer_size, |
| 1037 | alg ); |
| 1038 | if( status == PSA_SUCCESS ) |
| 1039 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 1040 | |
| 1041 | return( status ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1042 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 1043 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1044 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1045 | /* Add cases for opaque driver here */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 1046 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1047 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 1048 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1049 | status = mbedtls_test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1050 | &operation->ctx.opaque_test_driver_ctx, |
| 1051 | attributes, |
| 1052 | key_buffer, key_buffer_size, |
| 1053 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1054 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1055 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1056 | operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1057 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 1058 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1059 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 1060 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1061 | default: |
| 1062 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 1063 | (void)status; |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1064 | (void)key_buffer; |
| 1065 | (void)key_buffer_size; |
| 1066 | (void)alg; |
Ronald Cron | c45b4af | 2020-09-29 16:18:05 +0200 | [diff] [blame] | 1067 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1068 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1071 | psa_status_t psa_driver_wrapper_cipher_set_iv( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 1072 | psa_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1073 | const uint8_t *iv, |
| 1074 | size_t iv_length ) |
| 1075 | { |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1076 | switch( operation->id ) |
| 1077 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1078 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1079 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 1080 | return( mbedtls_psa_cipher_set_iv( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1081 | iv, |
| 1082 | iv_length ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1083 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1084 | |
| 1085 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1086 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1087 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1088 | return( mbedtls_test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1089 | &operation->ctx.transparent_test_driver_ctx, |
| 1090 | iv, iv_length ) ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1091 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1092 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1093 | return( mbedtls_test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1094 | &operation->ctx.opaque_test_driver_ctx, |
| 1095 | iv, iv_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1096 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1097 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1098 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1099 | |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1100 | (void)iv; |
| 1101 | (void)iv_length; |
| 1102 | |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1103 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | psa_status_t psa_driver_wrapper_cipher_update( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 1107 | psa_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1108 | const uint8_t *input, |
| 1109 | size_t input_length, |
| 1110 | uint8_t *output, |
| 1111 | size_t output_size, |
| 1112 | size_t *output_length ) |
| 1113 | { |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1114 | switch( operation->id ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1115 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1116 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1117 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 1118 | return( mbedtls_psa_cipher_update( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1119 | input, |
| 1120 | input_length, |
| 1121 | output, |
| 1122 | output_size, |
| 1123 | output_length ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1124 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 1125 | |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1126 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1127 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1128 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1129 | return( mbedtls_test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1130 | &operation->ctx.transparent_test_driver_ctx, |
| 1131 | input, input_length, |
| 1132 | output, output_size, output_length ) ); |
| 1133 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1134 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1135 | return( mbedtls_test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1136 | &operation->ctx.opaque_test_driver_ctx, |
| 1137 | input, input_length, |
| 1138 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1139 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1140 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1141 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1142 | |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1143 | (void)input; |
| 1144 | (void)input_length; |
| 1145 | (void)output; |
| 1146 | (void)output_size; |
| 1147 | (void)output_length; |
| 1148 | |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1149 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | psa_status_t psa_driver_wrapper_cipher_finish( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 1153 | psa_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1154 | uint8_t *output, |
| 1155 | size_t output_size, |
| 1156 | size_t *output_length ) |
| 1157 | { |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1158 | switch( operation->id ) |
| 1159 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1160 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1161 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 1162 | return( mbedtls_psa_cipher_finish( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1163 | output, |
| 1164 | output_size, |
| 1165 | output_length ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1166 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1167 | |
| 1168 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1169 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1170 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1171 | return( mbedtls_test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1172 | &operation->ctx.transparent_test_driver_ctx, |
| 1173 | output, output_size, output_length ) ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1174 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1175 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1176 | return( mbedtls_test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1177 | &operation->ctx.opaque_test_driver_ctx, |
| 1178 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1179 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1180 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1181 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1182 | |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1183 | (void)output; |
| 1184 | (void)output_size; |
| 1185 | (void)output_length; |
| 1186 | |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1187 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | psa_status_t psa_driver_wrapper_cipher_abort( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 1191 | psa_cipher_operation_t *operation ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1192 | { |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1193 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1194 | |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1195 | switch( operation->id ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1196 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1197 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1198 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 1199 | return( mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1200 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1201 | |
| 1202 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1203 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1204 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1205 | status = mbedtls_test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1206 | &operation->ctx.transparent_test_driver_ctx ); |
Steven Cooreman | cfeea8f | 2020-09-09 15:09:18 +0200 | [diff] [blame] | 1207 | mbedtls_platform_zeroize( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1208 | &operation->ctx.transparent_test_driver_ctx, |
| 1209 | sizeof( operation->ctx.transparent_test_driver_ctx ) ); |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 1210 | return( status ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1211 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1212 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1213 | status = mbedtls_test_opaque_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1214 | &operation->ctx.opaque_test_driver_ctx ); |
Steven Cooreman | cfeea8f | 2020-09-09 15:09:18 +0200 | [diff] [blame] | 1215 | mbedtls_platform_zeroize( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1216 | &operation->ctx.opaque_test_driver_ctx, |
| 1217 | sizeof( operation->ctx.opaque_test_driver_ctx ) ); |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 1218 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1219 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1220 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1221 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1222 | |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1223 | (void)status; |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1224 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1227 | /* |
| 1228 | * Hashing functions |
| 1229 | */ |
| 1230 | psa_status_t psa_driver_wrapper_hash_compute( |
| 1231 | psa_algorithm_t alg, |
| 1232 | const uint8_t *input, |
| 1233 | size_t input_length, |
| 1234 | uint8_t *hash, |
| 1235 | size_t hash_size, |
| 1236 | size_t *hash_length) |
| 1237 | { |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1238 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1239 | |
| 1240 | /* Try accelerators first */ |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1241 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1242 | status = mbedtls_test_transparent_hash_compute( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1243 | alg, input, input_length, hash, hash_size, hash_length ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1244 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1245 | return( status ); |
| 1246 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1247 | |
| 1248 | /* If software fallback is compiled in, try fallback */ |
| 1249 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1250 | status = mbedtls_psa_hash_compute( alg, input, input_length, |
| 1251 | hash, hash_size, hash_length ); |
| 1252 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1253 | return( status ); |
| 1254 | #endif |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1255 | (void) status; |
| 1256 | (void) alg; |
| 1257 | (void) input; |
| 1258 | (void) input_length; |
| 1259 | (void) hash; |
| 1260 | (void) hash_size; |
| 1261 | (void) hash_length; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1262 | |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1263 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | psa_status_t psa_driver_wrapper_hash_setup( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1267 | psa_hash_operation_t *operation, |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1268 | psa_algorithm_t alg ) |
| 1269 | { |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1270 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1271 | |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1272 | /* Try setup on accelerators first */ |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1273 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1274 | status = mbedtls_test_transparent_hash_setup( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1275 | &operation->ctx.test_driver_ctx, alg ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1276 | if( status == PSA_SUCCESS ) |
| 1277 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
| 1278 | |
| 1279 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1280 | return( status ); |
| 1281 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1282 | |
| 1283 | /* If software fallback is compiled in, try fallback */ |
| 1284 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1285 | status = mbedtls_psa_hash_setup( &operation->ctx.mbedtls_ctx, alg ); |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1286 | if( status == PSA_SUCCESS ) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1287 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1288 | |
| 1289 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1290 | return( status ); |
| 1291 | #endif |
| 1292 | /* Nothing left to try if we fall through here */ |
| 1293 | (void) status; |
| 1294 | (void) operation; |
| 1295 | (void) alg; |
| 1296 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 1297 | } |
| 1298 | |
| 1299 | psa_status_t psa_driver_wrapper_hash_clone( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1300 | const psa_hash_operation_t *source_operation, |
| 1301 | psa_hash_operation_t *target_operation ) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1302 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1303 | switch( source_operation->id ) |
| 1304 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1305 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1306 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1307 | target_operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 1308 | return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx, |
| 1309 | &target_operation->ctx.mbedtls_ctx ) ); |
| 1310 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1311 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1312 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 1313 | target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1314 | return( mbedtls_test_transparent_hash_clone( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1315 | &source_operation->ctx.test_driver_ctx, |
| 1316 | &target_operation->ctx.test_driver_ctx ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1317 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1318 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1319 | (void) target_operation; |
| 1320 | return( PSA_ERROR_BAD_STATE ); |
| 1321 | } |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | psa_status_t psa_driver_wrapper_hash_update( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1325 | psa_hash_operation_t *operation, |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1326 | const uint8_t *input, |
| 1327 | size_t input_length ) |
| 1328 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1329 | switch( operation->id ) |
| 1330 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1331 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1332 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1333 | return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx, |
| 1334 | input, input_length ) ); |
| 1335 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1336 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1337 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1338 | return( mbedtls_test_transparent_hash_update( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1339 | &operation->ctx.test_driver_ctx, |
| 1340 | input, input_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1341 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1342 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1343 | (void) input; |
| 1344 | (void) input_length; |
| 1345 | return( PSA_ERROR_BAD_STATE ); |
| 1346 | } |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | psa_status_t psa_driver_wrapper_hash_finish( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1350 | psa_hash_operation_t *operation, |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1351 | uint8_t *hash, |
| 1352 | size_t hash_size, |
| 1353 | size_t *hash_length ) |
| 1354 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1355 | switch( operation->id ) |
| 1356 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1357 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1358 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1359 | return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx, |
| 1360 | hash, hash_size, hash_length ) ); |
| 1361 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1362 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1363 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1364 | return( mbedtls_test_transparent_hash_finish( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1365 | &operation->ctx.test_driver_ctx, |
| 1366 | hash, hash_size, hash_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1367 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1368 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1369 | (void) hash; |
| 1370 | (void) hash_size; |
| 1371 | (void) hash_length; |
| 1372 | return( PSA_ERROR_BAD_STATE ); |
| 1373 | } |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | psa_status_t psa_driver_wrapper_hash_abort( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1377 | psa_hash_operation_t *operation ) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1378 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1379 | switch( operation->id ) |
| 1380 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1381 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1382 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1383 | return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); |
| 1384 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1385 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1386 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1387 | return( mbedtls_test_transparent_hash_abort( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1388 | &operation->ctx.test_driver_ctx ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1389 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1390 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1391 | return( PSA_ERROR_BAD_STATE ); |
| 1392 | } |
| 1393 | } |
| 1394 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1395 | psa_status_t psa_driver_wrapper_aead_encrypt( |
| 1396 | const psa_key_attributes_t *attributes, |
| 1397 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 1398 | psa_algorithm_t alg, |
| 1399 | const uint8_t *nonce, size_t nonce_length, |
| 1400 | const uint8_t *additional_data, size_t additional_data_length, |
| 1401 | const uint8_t *plaintext, size_t plaintext_length, |
| 1402 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) |
| 1403 | { |
| 1404 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1405 | psa_key_location_t location = |
| 1406 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1407 | |
| 1408 | switch( location ) |
| 1409 | { |
| 1410 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1411 | /* Key is stored in the slot in export representation, so |
| 1412 | * cycle through all known transparent accelerators */ |
| 1413 | |
| 1414 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1415 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1416 | status = mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1417 | attributes, key_buffer, key_buffer_size, |
| 1418 | alg, |
| 1419 | nonce, nonce_length, |
| 1420 | additional_data, additional_data_length, |
| 1421 | plaintext, plaintext_length, |
| 1422 | ciphertext, ciphertext_size, ciphertext_length ); |
| 1423 | /* Declared with fallback == true */ |
| 1424 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1425 | return( status ); |
| 1426 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1427 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1428 | |
| 1429 | /* Fell through, meaning no accelerator supports this operation */ |
| 1430 | return( mbedtls_psa_aead_encrypt( |
| 1431 | attributes, key_buffer, key_buffer_size, |
| 1432 | alg, |
| 1433 | nonce, nonce_length, |
| 1434 | additional_data, additional_data_length, |
| 1435 | plaintext, plaintext_length, |
| 1436 | ciphertext, ciphertext_size, ciphertext_length ) ); |
| 1437 | |
| 1438 | /* Add cases for opaque driver here */ |
| 1439 | |
| 1440 | default: |
| 1441 | /* Key is declared with a lifetime not known to us */ |
| 1442 | (void)status; |
| 1443 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | psa_status_t psa_driver_wrapper_aead_decrypt( |
| 1448 | const psa_key_attributes_t *attributes, |
| 1449 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 1450 | psa_algorithm_t alg, |
| 1451 | const uint8_t *nonce, size_t nonce_length, |
| 1452 | const uint8_t *additional_data, size_t additional_data_length, |
| 1453 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 1454 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) |
| 1455 | { |
| 1456 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1457 | psa_key_location_t location = |
| 1458 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1459 | |
| 1460 | switch( location ) |
| 1461 | { |
| 1462 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1463 | /* Key is stored in the slot in export representation, so |
| 1464 | * cycle through all known transparent accelerators */ |
| 1465 | |
| 1466 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1467 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 1468 | status = mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1469 | attributes, key_buffer, key_buffer_size, |
| 1470 | alg, |
| 1471 | nonce, nonce_length, |
| 1472 | additional_data, additional_data_length, |
| 1473 | ciphertext, ciphertext_length, |
| 1474 | plaintext, plaintext_size, plaintext_length ); |
| 1475 | /* Declared with fallback == true */ |
| 1476 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1477 | return( status ); |
| 1478 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1479 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1480 | |
| 1481 | /* Fell through, meaning no accelerator supports this operation */ |
| 1482 | return( mbedtls_psa_aead_decrypt( |
| 1483 | attributes, key_buffer, key_buffer_size, |
| 1484 | alg, |
| 1485 | nonce, nonce_length, |
| 1486 | additional_data, additional_data_length, |
| 1487 | ciphertext, ciphertext_length, |
| 1488 | plaintext, plaintext_size, plaintext_length ) ); |
| 1489 | |
| 1490 | /* Add cases for opaque driver here */ |
| 1491 | |
| 1492 | default: |
| 1493 | /* Key is declared with a lifetime not known to us */ |
| 1494 | (void)status; |
| 1495 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1496 | } |
| 1497 | } |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1498 | |
| 1499 | |
| 1500 | /* |
| 1501 | * MAC functions |
| 1502 | */ |
| 1503 | psa_status_t psa_driver_wrapper_mac_compute( |
| 1504 | const psa_key_attributes_t *attributes, |
| 1505 | const uint8_t *key_buffer, |
| 1506 | size_t key_buffer_size, |
| 1507 | psa_algorithm_t alg, |
| 1508 | const uint8_t *input, |
| 1509 | size_t input_length, |
| 1510 | uint8_t *mac, |
| 1511 | size_t mac_size, |
| 1512 | size_t *mac_length ) |
| 1513 | { |
| 1514 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1515 | psa_key_location_t location = |
| 1516 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1517 | |
| 1518 | switch( location ) |
| 1519 | { |
| 1520 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1521 | /* Key is stored in the slot in export representation, so |
| 1522 | * cycle through all known transparent accelerators */ |
| 1523 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1524 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1525 | status = mbedtls_test_transparent_mac_compute( |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1526 | attributes, key_buffer, key_buffer_size, alg, |
| 1527 | input, input_length, |
| 1528 | mac, mac_size, mac_length ); |
| 1529 | /* Declared with fallback == true */ |
| 1530 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1531 | return( status ); |
| 1532 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1533 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1534 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1535 | /* Fell through, meaning no accelerator supports this operation */ |
| 1536 | status = mbedtls_psa_mac_compute( |
| 1537 | attributes, key_buffer, key_buffer_size, alg, |
| 1538 | input, input_length, |
| 1539 | mac, mac_size, mac_length ); |
| 1540 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1541 | return( status ); |
| 1542 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1543 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 1544 | |
| 1545 | /* Add cases for opaque driver here */ |
| 1546 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1547 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1548 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1549 | status = mbedtls_test_opaque_mac_compute( |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1550 | attributes, key_buffer, key_buffer_size, alg, |
| 1551 | input, input_length, |
| 1552 | mac, mac_size, mac_length ); |
| 1553 | return( status ); |
| 1554 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1555 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1556 | default: |
| 1557 | /* Key is declared with a lifetime not known to us */ |
| 1558 | (void) key_buffer; |
| 1559 | (void) key_buffer_size; |
| 1560 | (void) alg; |
| 1561 | (void) input; |
| 1562 | (void) input_length; |
| 1563 | (void) mac; |
| 1564 | (void) mac_size; |
| 1565 | (void) mac_length; |
| 1566 | (void) status; |
| 1567 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | psa_status_t psa_driver_wrapper_mac_sign_setup( |
| 1572 | psa_mac_operation_t *operation, |
| 1573 | const psa_key_attributes_t *attributes, |
| 1574 | const uint8_t *key_buffer, |
| 1575 | size_t key_buffer_size, |
| 1576 | psa_algorithm_t alg ) |
| 1577 | { |
| 1578 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1579 | psa_key_location_t location = |
| 1580 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1581 | |
| 1582 | switch( location ) |
| 1583 | { |
| 1584 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1585 | /* Key is stored in the slot in export representation, so |
| 1586 | * cycle through all known transparent accelerators */ |
| 1587 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1588 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1589 | status = mbedtls_test_transparent_mac_sign_setup( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1590 | &operation->ctx.transparent_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1591 | attributes, |
| 1592 | key_buffer, key_buffer_size, |
| 1593 | alg ); |
| 1594 | /* Declared with fallback == true */ |
| 1595 | if( status == PSA_SUCCESS ) |
| 1596 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
| 1597 | |
| 1598 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1599 | return( status ); |
| 1600 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1601 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1602 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1603 | /* Fell through, meaning no accelerator supports this operation */ |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1604 | status = mbedtls_psa_mac_sign_setup( &operation->ctx.mbedtls_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1605 | attributes, |
| 1606 | key_buffer, key_buffer_size, |
| 1607 | alg ); |
| 1608 | if( status == PSA_SUCCESS ) |
| 1609 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 1610 | |
| 1611 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1612 | return( status ); |
| 1613 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1614 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 1615 | |
| 1616 | /* Add cases for opaque driver here */ |
| 1617 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1618 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1619 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1620 | status = mbedtls_test_opaque_mac_sign_setup( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1621 | &operation->ctx.opaque_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1622 | attributes, |
| 1623 | key_buffer, key_buffer_size, |
| 1624 | alg ); |
| 1625 | |
| 1626 | if( status == PSA_SUCCESS ) |
| 1627 | operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; |
| 1628 | |
| 1629 | return( status ); |
| 1630 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1631 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1632 | default: |
| 1633 | /* Key is declared with a lifetime not known to us */ |
| 1634 | (void) status; |
| 1635 | (void) key_buffer; |
| 1636 | (void) key_buffer_size; |
| 1637 | (void) alg; |
| 1638 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | psa_status_t psa_driver_wrapper_mac_verify_setup( |
| 1643 | psa_mac_operation_t *operation, |
| 1644 | const psa_key_attributes_t *attributes, |
| 1645 | const uint8_t *key_buffer, |
| 1646 | size_t key_buffer_size, |
| 1647 | psa_algorithm_t alg ) |
| 1648 | { |
| 1649 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1650 | psa_key_location_t location = |
| 1651 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1652 | |
| 1653 | switch( location ) |
| 1654 | { |
| 1655 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1656 | /* Key is stored in the slot in export representation, so |
| 1657 | * cycle through all known transparent accelerators */ |
| 1658 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1659 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1660 | status = mbedtls_test_transparent_mac_verify_setup( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1661 | &operation->ctx.transparent_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1662 | attributes, |
| 1663 | key_buffer, key_buffer_size, |
| 1664 | alg ); |
| 1665 | /* Declared with fallback == true */ |
| 1666 | if( status == PSA_SUCCESS ) |
| 1667 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
| 1668 | |
| 1669 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1670 | return( status ); |
| 1671 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1672 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1673 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1674 | /* Fell through, meaning no accelerator supports this operation */ |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1675 | status = mbedtls_psa_mac_verify_setup( &operation->ctx.mbedtls_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1676 | attributes, |
| 1677 | key_buffer, key_buffer_size, |
| 1678 | alg ); |
| 1679 | if( status == PSA_SUCCESS ) |
| 1680 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 1681 | |
| 1682 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1683 | return( status ); |
| 1684 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1685 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 1686 | |
| 1687 | /* Add cases for opaque driver here */ |
| 1688 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1689 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1690 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1691 | status = mbedtls_test_opaque_mac_verify_setup( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1692 | &operation->ctx.opaque_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1693 | attributes, |
| 1694 | key_buffer, key_buffer_size, |
| 1695 | alg ); |
| 1696 | |
| 1697 | if( status == PSA_SUCCESS ) |
| 1698 | operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; |
| 1699 | |
| 1700 | return( status ); |
| 1701 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1702 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1703 | default: |
| 1704 | /* Key is declared with a lifetime not known to us */ |
| 1705 | (void) status; |
| 1706 | (void) key_buffer; |
| 1707 | (void) key_buffer_size; |
| 1708 | (void) alg; |
| 1709 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | psa_status_t psa_driver_wrapper_mac_update( |
| 1714 | psa_mac_operation_t *operation, |
| 1715 | const uint8_t *input, |
| 1716 | size_t input_length ) |
| 1717 | { |
| 1718 | switch( operation->id ) |
| 1719 | { |
| 1720 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1721 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1722 | return( mbedtls_psa_mac_update( &operation->ctx.mbedtls_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1723 | input, input_length ) ); |
| 1724 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1725 | |
| 1726 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1727 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1728 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1729 | return( mbedtls_test_transparent_mac_update( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1730 | &operation->ctx.transparent_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1731 | input, input_length ) ); |
| 1732 | |
| 1733 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1734 | return( mbedtls_test_opaque_mac_update( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1735 | &operation->ctx.opaque_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1736 | input, input_length ) ); |
| 1737 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1738 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1739 | default: |
| 1740 | (void) input; |
| 1741 | (void) input_length; |
| 1742 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | psa_status_t psa_driver_wrapper_mac_sign_finish( |
| 1747 | psa_mac_operation_t *operation, |
| 1748 | uint8_t *mac, |
| 1749 | size_t mac_size, |
| 1750 | size_t *mac_length ) |
| 1751 | { |
| 1752 | switch( operation->id ) |
| 1753 | { |
| 1754 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1755 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1756 | return( mbedtls_psa_mac_sign_finish( &operation->ctx.mbedtls_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1757 | mac, mac_size, mac_length ) ); |
| 1758 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1759 | |
| 1760 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1761 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1762 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1763 | return( mbedtls_test_transparent_mac_sign_finish( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1764 | &operation->ctx.transparent_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1765 | mac, mac_size, mac_length ) ); |
| 1766 | |
| 1767 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1768 | return( mbedtls_test_opaque_mac_sign_finish( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1769 | &operation->ctx.opaque_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1770 | mac, mac_size, mac_length ) ); |
| 1771 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1772 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1773 | default: |
| 1774 | (void) mac; |
| 1775 | (void) mac_size; |
| 1776 | (void) mac_length; |
| 1777 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | psa_status_t psa_driver_wrapper_mac_verify_finish( |
| 1782 | psa_mac_operation_t *operation, |
| 1783 | const uint8_t *mac, |
| 1784 | size_t mac_length ) |
| 1785 | { |
| 1786 | switch( operation->id ) |
| 1787 | { |
| 1788 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1789 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1790 | return( mbedtls_psa_mac_verify_finish( &operation->ctx.mbedtls_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1791 | mac, mac_length ) ); |
| 1792 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1793 | |
| 1794 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1795 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1796 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1797 | return( mbedtls_test_transparent_mac_verify_finish( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1798 | &operation->ctx.transparent_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1799 | mac, mac_length ) ); |
| 1800 | |
| 1801 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1802 | return( mbedtls_test_opaque_mac_verify_finish( |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 1803 | &operation->ctx.opaque_test_driver_ctx, |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1804 | mac, mac_length ) ); |
| 1805 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1806 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1807 | default: |
| 1808 | (void) mac; |
| 1809 | (void) mac_length; |
| 1810 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | psa_status_t psa_driver_wrapper_mac_abort( |
| 1815 | psa_mac_operation_t *operation ) |
| 1816 | { |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1817 | switch( operation->id ) |
| 1818 | { |
| 1819 | #if defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 1820 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Steven Cooreman | e680419 | 2021-03-19 18:28:56 +0100 | [diff] [blame] | 1821 | return( mbedtls_psa_mac_abort( &operation->ctx.mbedtls_ctx ) ); |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1822 | #endif /* MBEDTLS_PSA_BUILTIN_MAC */ |
| 1823 | |
| 1824 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1825 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1826 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1827 | return( mbedtls_test_transparent_mac_abort( |
Steven Cooreman | e680419 | 2021-03-19 18:28:56 +0100 | [diff] [blame] | 1828 | &operation->ctx.transparent_test_driver_ctx ) ); |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1829 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Steven Cooreman | c7f0a57 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1830 | return( mbedtls_test_opaque_mac_abort( |
Steven Cooreman | e680419 | 2021-03-19 18:28:56 +0100 | [diff] [blame] | 1831 | &operation->ctx.opaque_test_driver_ctx ) ); |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1832 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1833 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1834 | default: |
Steven Cooreman | e680419 | 2021-03-19 18:28:56 +0100 | [diff] [blame] | 1835 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1836 | } |
Steven Cooreman | d13a70f | 2021-03-19 15:24:23 +0100 | [diff] [blame] | 1837 | } |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 1838 | /* End of automatically generated file. */ |