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