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