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