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" |
| 27 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 28 | #include "mbedtls/platform.h" |
| 29 | |
| 30 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 31 | |
| 32 | /* Include test driver definition when running tests */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 33 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 34 | #ifndef PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 35 | #define PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 36 | #endif |
| 37 | #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 38 | #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 39 | #endif |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 40 | #include "test/drivers/mbedtls_test_driver.h" |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 41 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 42 | |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 43 | /* Repeat above block for each JSON-declared driver during autogeneration */ |
Steven Cooreman | aa87fd0 | 2021-03-15 18:54:03 +0100 | [diff] [blame] | 44 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */ |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 45 | |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 46 | /* Auto-generated values depending on which drivers are registered. |
| 47 | * ID 0 is reserved for unallocated operations. |
| 48 | * ID 1 is reserved for the Mbed TLS software driver. */ |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 49 | #define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1) |
| 50 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 51 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 52 | #define PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID (2) |
| 53 | #define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (3) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 54 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 55 | |
| 56 | /* Support the 'old' SE interface when asked to */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 57 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 58 | /* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style |
| 59 | * SE driver is present, to avoid unused argument errors at compile time. */ |
| 60 | #ifndef PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 61 | #define PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 62 | #endif |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 63 | #include "psa_crypto_se.h" |
| 64 | #endif |
| 65 | |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 66 | /* Start delegation functions */ |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 67 | psa_status_t psa_driver_wrapper_sign_hash( |
| 68 | const psa_key_attributes_t *attributes, |
| 69 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 70 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 71 | uint8_t *signature, size_t signature_size, size_t *signature_length ) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 72 | { |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 73 | /* Try dynamically-registered SE interface first */ |
| 74 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 75 | const psa_drv_se_t *drv; |
| 76 | psa_drv_se_context_t *drv_context; |
| 77 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 78 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 79 | { |
| 80 | if( drv->asymmetric == NULL || |
| 81 | drv->asymmetric->p_sign == NULL ) |
| 82 | { |
| 83 | /* 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] | 84 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 85 | } |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 86 | return( drv->asymmetric->p_sign( |
| 87 | drv_context, *( (psa_key_slot_number_t *)key_buffer ), |
| 88 | alg, hash, hash_length, |
| 89 | signature, signature_size, signature_length ) ); |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 90 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 91 | #endif /* PSA_CRYPTO_SE_C */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 92 | |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 93 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 94 | psa_key_location_t location = |
| 95 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 96 | |
| 97 | switch( location ) |
| 98 | { |
| 99 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 100 | /* Key is stored in the slot in export representation, so |
| 101 | * cycle through all known transparent accelerators */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 102 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 103 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 104 | status = mbedtls_test_transparent_signature_sign_hash( attributes, |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 105 | key_buffer, |
| 106 | key_buffer_size, |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 107 | alg, |
| 108 | hash, |
| 109 | hash_length, |
| 110 | signature, |
| 111 | signature_size, |
| 112 | signature_length ); |
| 113 | /* Declared with fallback == true */ |
| 114 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 115 | return( status ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 116 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 117 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 118 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 119 | return( psa_sign_hash_internal( attributes, |
| 120 | key_buffer, |
| 121 | key_buffer_size, |
| 122 | alg, |
| 123 | hash, |
| 124 | hash_length, |
| 125 | signature, |
| 126 | signature_size, |
| 127 | signature_length ) ); |
| 128 | |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 129 | /* Add cases for opaque driver here */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 130 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 131 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 132 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 133 | return( mbedtls_test_opaque_signature_sign_hash( attributes, |
| 134 | key_buffer, |
| 135 | key_buffer_size, |
| 136 | alg, |
| 137 | hash, |
| 138 | hash_length, |
| 139 | signature, |
| 140 | signature_size, |
| 141 | signature_length ) ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 142 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 143 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 144 | default: |
| 145 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 146 | (void)status; |
| 147 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 148 | } |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 151 | psa_status_t psa_driver_wrapper_verify_hash( |
| 152 | const psa_key_attributes_t *attributes, |
| 153 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 154 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 155 | const uint8_t *signature, size_t signature_length ) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 156 | { |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 157 | /* Try dynamically-registered SE interface first */ |
| 158 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 159 | const psa_drv_se_t *drv; |
| 160 | psa_drv_se_context_t *drv_context; |
| 161 | |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 162 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 163 | { |
| 164 | if( drv->asymmetric == NULL || |
| 165 | drv->asymmetric->p_verify == NULL ) |
| 166 | { |
| 167 | /* 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] | 168 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 169 | } |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 170 | return( drv->asymmetric->p_verify( |
| 171 | drv_context, *( (psa_key_slot_number_t *)key_buffer ), |
| 172 | alg, hash, hash_length, |
| 173 | signature, signature_length ) ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 174 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 175 | #endif /* PSA_CRYPTO_SE_C */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 176 | |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 177 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | 9f17aa4 | 2020-12-08 17:07:25 +0100 | [diff] [blame] | 178 | psa_key_location_t location = |
| 179 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 180 | |
| 181 | switch( location ) |
| 182 | { |
| 183 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 184 | /* Key is stored in the slot in export representation, so |
| 185 | * cycle through all known transparent accelerators */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 186 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 187 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 188 | status = mbedtls_test_transparent_signature_verify_hash( |
| 189 | attributes, |
| 190 | key_buffer, |
| 191 | key_buffer_size, |
| 192 | alg, |
| 193 | hash, |
| 194 | hash_length, |
| 195 | signature, |
| 196 | signature_length ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 197 | /* Declared with fallback == true */ |
| 198 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 199 | return( status ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 200 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 201 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 202 | |
| 203 | return( psa_verify_hash_internal( attributes, |
| 204 | key_buffer, |
| 205 | key_buffer_size, |
| 206 | alg, |
| 207 | hash, |
| 208 | hash_length, |
| 209 | signature, |
| 210 | signature_length ) ); |
| 211 | |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 212 | /* Add cases for opaque driver here */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 213 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 214 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 215 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 216 | return( mbedtls_test_opaque_signature_verify_hash( attributes, |
| 217 | key_buffer, |
| 218 | key_buffer_size, |
| 219 | alg, |
| 220 | hash, |
| 221 | hash_length, |
| 222 | signature, |
| 223 | signature_length ) ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 224 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 225 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 226 | default: |
| 227 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | fce9df2 | 2020-12-08 18:06:03 +0100 | [diff] [blame] | 228 | (void)status; |
| 229 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 230 | } |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Steven Cooreman | b938b0b | 2021-04-06 13:08:42 +0200 | [diff] [blame] | 233 | /** Get the key buffer size required to store the key material of a key |
| 234 | * associated with an opaque driver without storage. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 235 | * |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 236 | * \param[in] attributes The key attributes. |
| 237 | * \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] | 238 | * |
| 239 | * \retval #PSA_SUCCESS |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 240 | * The minimum size for a buffer to contain the key material has been |
| 241 | * returned successfully. |
| 242 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 243 | * The size in bits of the key is not valid. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 244 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 245 | * The type and/or the size in bits of the key or the combination of |
| 246 | * the two is not supported. |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 247 | */ |
Ronald Cron | 9df74be | 2020-12-05 19:15:23 +0100 | [diff] [blame] | 248 | psa_status_t psa_driver_wrapper_get_key_buffer_size( |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 249 | const psa_key_attributes_t *attributes, |
| 250 | size_t *key_buffer_size ) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 251 | { |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 252 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 253 | psa_key_type_t key_type = attributes->core.type; |
| 254 | size_t key_bits = attributes->core.bits; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 255 | |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 256 | *key_buffer_size = 0; |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 257 | switch( location ) |
| 258 | { |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 259 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 260 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 261 | #if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 262 | /* Emulate property 'builtin_key_size' */ |
| 263 | if( psa_key_id_is_builtin( |
| 264 | MBEDTLS_SVC_KEY_ID_GET_KEY_ID( |
| 265 | psa_get_key_id( attributes ) ) ) ) |
| 266 | { |
Steven Cooreman | 203bcbb | 2021-03-18 17:17:40 +0100 | [diff] [blame] | 267 | *key_buffer_size = sizeof( psa_drv_slot_number_t ); |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 268 | return( PSA_SUCCESS ); |
| 269 | } |
| 270 | #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 271 | #ifdef MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION |
| 272 | *key_buffer_size = mbedtls_test_size_function( key_type, key_bits ); |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 273 | return( PSA_SUCCESS ); |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 274 | #else /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 275 | if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) ) |
| 276 | { |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 277 | int public_key_overhead = |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 278 | ( ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) |
| 279 | ? PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 ); |
| 280 | *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + |
| 281 | MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE + |
| 282 | public_key_overhead; |
John Durkop | 135ce69 | 2020-10-19 07:12:28 -0700 | [diff] [blame] | 283 | } |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 284 | else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) ) |
John Durkop | 135ce69 | 2020-10-19 07:12:28 -0700 | [diff] [blame] | 285 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 286 | *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + |
| 287 | MBEDTLS_TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE; |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 288 | } |
John Durkop | 135ce69 | 2020-10-19 07:12:28 -0700 | [diff] [blame] | 289 | else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) && |
Ronald Cron | 3121628 | 2020-12-05 18:47:56 +0100 | [diff] [blame] | 290 | !PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) ) |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 291 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 292 | *key_buffer_size = MBEDTLS_TEST_DRIVER_KEY_CONTEXT_BASE_SIZE + |
| 293 | ( MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR * |
| 294 | ( ( key_bits + 7 ) / 8 ) ); |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 295 | } |
| 296 | else |
| 297 | { |
| 298 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 299 | } |
| 300 | return( PSA_SUCCESS ); |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 301 | #endif /* MBEDTLS_TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */ |
John Durkop | 2c61835 | 2020-09-22 06:54:01 -0700 | [diff] [blame] | 302 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 303 | |
| 304 | default: |
Ronald Cron | 9df74be | 2020-12-05 19:15:23 +0100 | [diff] [blame] | 305 | (void)key_type; |
| 306 | (void)key_bits; |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 307 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 308 | } |
| 309 | } |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 310 | |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 311 | psa_status_t psa_driver_wrapper_generate_key( |
| 312 | const psa_key_attributes_t *attributes, |
| 313 | 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] | 314 | { |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 315 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 316 | psa_key_location_t location = |
| 317 | PSA_KEY_LIFETIME_GET_LOCATION(attributes->core.lifetime); |
| 318 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 319 | /* Try dynamically-registered SE interface first */ |
| 320 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 321 | const psa_drv_se_t *drv; |
| 322 | psa_drv_se_context_t *drv_context; |
| 323 | |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 324 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 325 | { |
| 326 | size_t pubkey_length = 0; /* We don't support this feature yet */ |
| 327 | if( drv->key_management == NULL || |
| 328 | drv->key_management->p_generate == NULL ) |
| 329 | { |
| 330 | /* 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] | 331 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 332 | } |
| 333 | return( drv->key_management->p_generate( |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 334 | drv_context, |
| 335 | *( (psa_key_slot_number_t *)key_buffer ), |
Ronald Cron | ea0f8a6 | 2020-11-25 17:52:23 +0100 | [diff] [blame] | 336 | attributes, NULL, 0, &pubkey_length ) ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 337 | } |
| 338 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 339 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 340 | switch( location ) |
| 341 | { |
| 342 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 343 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 344 | /* Transparent drivers are limited to generating asymmetric keys */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 345 | if( PSA_KEY_TYPE_IS_ASYMMETRIC( attributes->core.type ) ) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 346 | { |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 347 | /* Cycle through all known transparent accelerators */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 348 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 349 | status = mbedtls_test_transparent_generate_key( |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 350 | attributes, key_buffer, key_buffer_size, |
| 351 | key_buffer_length ); |
| 352 | /* Declared with fallback == true */ |
| 353 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 354 | break; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 355 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 356 | } |
| 357 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 358 | |
| 359 | /* Software fallback */ |
| 360 | status = psa_generate_key_internal( |
| 361 | attributes, key_buffer, key_buffer_size, key_buffer_length ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 362 | break; |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 363 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 364 | /* Add cases for opaque driver here */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 365 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 366 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 367 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 368 | status = mbedtls_test_opaque_generate_key( |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 369 | attributes, key_buffer, key_buffer_size, key_buffer_length ); |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 370 | break; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 371 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 977c247 | 2020-10-13 08:32:21 +0200 | [diff] [blame] | 372 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 373 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 374 | default: |
| 375 | /* Key is declared with a lifetime not known to us */ |
| 376 | status = PSA_ERROR_INVALID_ARGUMENT; |
| 377 | break; |
| 378 | } |
| 379 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 380 | return( status ); |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 381 | } |
| 382 | |
Ronald Cron | 8328287 | 2020-11-22 14:02:39 +0100 | [diff] [blame] | 383 | psa_status_t psa_driver_wrapper_import_key( |
| 384 | const psa_key_attributes_t *attributes, |
| 385 | const uint8_t *data, |
| 386 | size_t data_length, |
| 387 | uint8_t *key_buffer, |
| 388 | size_t key_buffer_size, |
| 389 | size_t *key_buffer_length, |
| 390 | size_t *bits ) |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 391 | { |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 392 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 393 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( |
| 394 | psa_get_key_lifetime( attributes ) ); |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 395 | |
Ronald Cron | fb2ed5b | 2020-11-30 12:11:01 +0100 | [diff] [blame] | 396 | /* Try dynamically-registered SE interface first */ |
| 397 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 398 | const psa_drv_se_t *drv; |
| 399 | psa_drv_se_context_t *drv_context; |
| 400 | |
| 401 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 402 | { |
| 403 | if( drv->key_management == NULL || |
| 404 | drv->key_management->p_import == NULL ) |
| 405 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 406 | |
| 407 | /* The driver should set the number of key bits, however in |
| 408 | * case it doesn't, we initialize bits to an invalid value. */ |
| 409 | *bits = PSA_MAX_KEY_BITS + 1; |
| 410 | status = drv->key_management->p_import( |
| 411 | drv_context, |
| 412 | *( (psa_key_slot_number_t *)key_buffer ), |
| 413 | attributes, data, data_length, bits ); |
| 414 | |
| 415 | if( status != PSA_SUCCESS ) |
| 416 | return( status ); |
| 417 | |
| 418 | if( (*bits) > PSA_MAX_KEY_BITS ) |
| 419 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 420 | |
| 421 | return( PSA_SUCCESS ); |
| 422 | } |
| 423 | #endif /* PSA_CRYPTO_SE_C */ |
| 424 | |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 425 | switch( location ) |
| 426 | { |
| 427 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 428 | /* Key is stored in the slot in export representation, so |
| 429 | * cycle through all known transparent accelerators */ |
| 430 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 431 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 432 | status = mbedtls_test_transparent_import_key( |
| 433 | attributes, |
| 434 | data, data_length, |
| 435 | key_buffer, key_buffer_size, |
| 436 | key_buffer_length, bits ); |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 437 | /* Declared with fallback == true */ |
| 438 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 439 | return( status ); |
| 440 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 441 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 442 | /* Fell through, meaning no accelerator supports this operation */ |
| 443 | return( psa_import_key_into_slot( attributes, |
| 444 | data, data_length, |
| 445 | key_buffer, key_buffer_size, |
| 446 | key_buffer_length, bits ) ); |
| 447 | |
| 448 | default: |
Ronald Cron | fb2ed5b | 2020-11-30 12:11:01 +0100 | [diff] [blame] | 449 | /* Importing a key with external storage in not yet supported. |
| 450 | * Return in error indicating that the lifetime is not valid. */ |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 451 | (void)status; |
Ronald Cron | fb2ed5b | 2020-11-30 12:11:01 +0100 | [diff] [blame] | 452 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Ronald Cron | bf33c93 | 2020-11-28 18:06:53 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 457 | psa_status_t psa_driver_wrapper_export_key( |
| 458 | const psa_key_attributes_t *attributes, |
| 459 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 460 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 461 | |
| 462 | { |
| 463 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 464 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( |
| 465 | psa_get_key_lifetime( attributes ) ); |
| 466 | |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 467 | /* Try dynamically-registered SE interface first */ |
| 468 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 469 | const psa_drv_se_t *drv; |
| 470 | psa_drv_se_context_t *drv_context; |
| 471 | |
| 472 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 473 | { |
| 474 | if( ( drv->key_management == NULL ) || |
| 475 | ( drv->key_management->p_export == NULL ) ) |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 476 | { |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 477 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 478 | } |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 479 | |
| 480 | return( drv->key_management->p_export( |
| 481 | drv_context, |
| 482 | *( (psa_key_slot_number_t *)key_buffer ), |
| 483 | data, data_size, data_length ) ); |
| 484 | } |
| 485 | #endif /* PSA_CRYPTO_SE_C */ |
| 486 | |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 487 | switch( location ) |
| 488 | { |
| 489 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 490 | return( psa_export_key_internal( attributes, |
| 491 | key_buffer, |
| 492 | key_buffer_size, |
| 493 | data, |
| 494 | data_size, |
| 495 | data_length ) ); |
| 496 | |
| 497 | /* Add cases for opaque driver here */ |
| 498 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 499 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 500 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 501 | return( mbedtls_test_opaque_export_key( attributes, |
| 502 | key_buffer, |
| 503 | key_buffer_size, |
| 504 | data, |
| 505 | data_size, |
| 506 | data_length ) ); |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 507 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 508 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 509 | default: |
| 510 | /* Key is declared with a lifetime not known to us */ |
| 511 | return( status ); |
| 512 | } |
| 513 | } |
| 514 | |
Ronald Cron | 84cc994 | 2020-11-25 14:30:05 +0100 | [diff] [blame] | 515 | psa_status_t psa_driver_wrapper_export_public_key( |
| 516 | const psa_key_attributes_t *attributes, |
| 517 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 518 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 519 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 520 | { |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 521 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | 84cc994 | 2020-11-25 14:30:05 +0100 | [diff] [blame] | 522 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( |
| 523 | psa_get_key_lifetime( attributes ) ); |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 524 | |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 525 | /* Try dynamically-registered SE interface first */ |
| 526 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 527 | const psa_drv_se_t *drv; |
| 528 | psa_drv_se_context_t *drv_context; |
| 529 | |
| 530 | if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) ) |
| 531 | { |
| 532 | if( ( drv->key_management == NULL ) || |
| 533 | ( drv->key_management->p_export_public == NULL ) ) |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 534 | { |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 535 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 9cfdf6e | 2021-01-18 11:58:39 +0100 | [diff] [blame] | 536 | } |
Ronald Cron | 152e3f8 | 2020-11-26 16:06:41 +0100 | [diff] [blame] | 537 | |
| 538 | return( drv->key_management->p_export_public( |
| 539 | drv_context, |
| 540 | *( (psa_key_slot_number_t *)key_buffer ), |
| 541 | data, data_size, data_length ) ); |
| 542 | } |
| 543 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 544 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 545 | switch( location ) |
| 546 | { |
| 547 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 548 | /* Key is stored in the slot in export representation, so |
| 549 | * cycle through all known transparent accelerators */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 550 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 551 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 552 | status = mbedtls_test_transparent_export_public_key( |
| 553 | attributes, |
| 554 | key_buffer, |
| 555 | key_buffer_size, |
| 556 | data, |
| 557 | data_size, |
| 558 | data_length ); |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 559 | /* Declared with fallback == true */ |
| 560 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 561 | return( status ); |
| 562 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 563 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 564 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 565 | return( psa_export_public_key_internal( attributes, |
| 566 | key_buffer, |
| 567 | key_buffer_size, |
| 568 | data, |
| 569 | data_size, |
| 570 | data_length ) ); |
| 571 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 572 | /* Add cases for opaque driver here */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 573 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 574 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 575 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 576 | return( mbedtls_test_opaque_export_public_key( attributes, |
| 577 | key_buffer, |
| 578 | key_buffer_size, |
| 579 | data, |
| 580 | data_size, |
| 581 | data_length ) ); |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 582 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 583 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 584 | default: |
| 585 | /* Key is declared with a lifetime not known to us */ |
| 586 | return( status ); |
| 587 | } |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 590 | psa_status_t psa_driver_wrapper_get_builtin_key( |
| 591 | psa_drv_slot_number_t slot_number, |
| 592 | psa_key_attributes_t *attributes, |
| 593 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) |
| 594 | { |
| 595 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 596 | switch( location ) |
| 597 | { |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 598 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 599 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 600 | return( mbedtls_test_opaque_get_builtin_key( |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 601 | slot_number, |
| 602 | attributes, |
| 603 | key_buffer, key_buffer_size, key_buffer_length ) ); |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 604 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 605 | default: |
| 606 | (void) slot_number; |
| 607 | (void) key_buffer; |
| 608 | (void) key_buffer_size; |
| 609 | (void) key_buffer_length; |
| 610 | return( PSA_ERROR_DOES_NOT_EXIST ); |
| 611 | } |
| 612 | } |
| 613 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 614 | /* |
| 615 | * Cipher functions |
| 616 | */ |
| 617 | psa_status_t psa_driver_wrapper_cipher_encrypt( |
| 618 | psa_key_slot_t *slot, |
| 619 | psa_algorithm_t alg, |
| 620 | const uint8_t *input, |
| 621 | size_t input_length, |
| 622 | uint8_t *output, |
| 623 | size_t output_size, |
| 624 | size_t *output_length ) |
| 625 | { |
| 626 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 627 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 628 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 629 | psa_key_attributes_t attributes = { |
| 630 | .core = slot->attr |
| 631 | }; |
| 632 | |
| 633 | switch( location ) |
| 634 | { |
| 635 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 636 | /* Key is stored in the slot in export representation, so |
| 637 | * cycle through all known transparent accelerators */ |
| 638 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 639 | status = mbedtls_test_transparent_cipher_encrypt( &attributes, |
| 640 | slot->key.data, |
| 641 | slot->key.bytes, |
| 642 | alg, |
| 643 | input, |
| 644 | input_length, |
| 645 | output, |
| 646 | output_size, |
| 647 | output_length ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 648 | /* Declared with fallback == true */ |
| 649 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 650 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 651 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 652 | /* Fell through, meaning no accelerator supports this operation */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 653 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 654 | /* Add cases for opaque driver here */ |
| 655 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 656 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 657 | return( mbedtls_test_opaque_cipher_encrypt( &attributes, |
| 658 | slot->key.data, |
| 659 | slot->key.bytes, |
| 660 | alg, |
| 661 | input, |
| 662 | input_length, |
| 663 | output, |
| 664 | output_size, |
| 665 | output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 666 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 667 | default: |
| 668 | /* Key is declared with a lifetime not known to us */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 669 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 670 | } |
| 671 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 672 | (void) slot; |
| 673 | (void) alg; |
| 674 | (void) input; |
| 675 | (void) input_length; |
| 676 | (void) output; |
| 677 | (void) output_size; |
| 678 | (void) output_length; |
| 679 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 680 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 681 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 682 | } |
| 683 | |
| 684 | psa_status_t psa_driver_wrapper_cipher_decrypt( |
| 685 | psa_key_slot_t *slot, |
| 686 | psa_algorithm_t alg, |
| 687 | const uint8_t *input, |
| 688 | size_t input_length, |
| 689 | uint8_t *output, |
| 690 | size_t output_size, |
| 691 | size_t *output_length ) |
| 692 | { |
| 693 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) && defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 694 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 695 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 696 | psa_key_attributes_t attributes = { |
| 697 | .core = slot->attr |
| 698 | }; |
| 699 | |
| 700 | switch( location ) |
| 701 | { |
| 702 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 703 | /* Key is stored in the slot in export representation, so |
| 704 | * cycle through all known transparent accelerators */ |
| 705 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 706 | status = mbedtls_test_transparent_cipher_decrypt( &attributes, |
| 707 | slot->key.data, |
| 708 | slot->key.bytes, |
| 709 | alg, |
| 710 | input, |
| 711 | input_length, |
| 712 | output, |
| 713 | output_size, |
| 714 | output_length ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 715 | /* Declared with fallback == true */ |
| 716 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 717 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 718 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 719 | /* Fell through, meaning no accelerator supports this operation */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 720 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 721 | /* Add cases for opaque driver here */ |
| 722 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 723 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 724 | return( mbedtls_test_opaque_cipher_decrypt( &attributes, |
| 725 | slot->key.data, |
| 726 | slot->key.bytes, |
| 727 | alg, |
| 728 | input, |
| 729 | input_length, |
| 730 | output, |
| 731 | output_size, |
| 732 | output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 733 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 734 | default: |
| 735 | /* Key is declared with a lifetime not known to us */ |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 736 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 737 | } |
| 738 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 739 | (void) slot; |
| 740 | (void) alg; |
| 741 | (void) input; |
| 742 | (void) input_length; |
| 743 | (void) output; |
| 744 | (void) output_size; |
| 745 | (void) output_length; |
| 746 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 747 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 748 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
| 749 | } |
| 750 | |
| 751 | psa_status_t psa_driver_wrapper_cipher_encrypt_setup( |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 752 | psa_cipher_operation_t *operation, |
| 753 | const psa_key_attributes_t *attributes, |
| 754 | const uint8_t *key_buffer, size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 755 | psa_algorithm_t alg ) |
| 756 | { |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 757 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 758 | psa_key_location_t location = |
| 759 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 760 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 761 | switch( location ) |
| 762 | { |
| 763 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 764 | /* Key is stored in the slot in export representation, so |
| 765 | * cycle through all known transparent accelerators */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 766 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 767 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 768 | status = mbedtls_test_transparent_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 769 | &operation->ctx.transparent_test_driver_ctx, |
| 770 | attributes, |
| 771 | key_buffer, |
| 772 | key_buffer_size, |
| 773 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 774 | /* Declared with fallback == true */ |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 775 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 776 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 777 | |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 778 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 779 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 780 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 781 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 782 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 783 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 784 | status = mbedtls_psa_cipher_encrypt_setup( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 785 | attributes, |
| 786 | key_buffer, |
| 787 | key_buffer_size, |
| 788 | alg ); |
| 789 | if( status == PSA_SUCCESS ) |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 790 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 791 | |
Ronald Cron | 7b4154d | 2021-03-19 14:49:41 +0100 | [diff] [blame] | 792 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 793 | return( status ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 794 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 795 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 796 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 797 | /* Add cases for opaque driver here */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 798 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 799 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 800 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 801 | status = mbedtls_test_opaque_cipher_encrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 802 | &operation->ctx.opaque_test_driver_ctx, |
| 803 | attributes, |
| 804 | key_buffer, key_buffer_size, |
| 805 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 806 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 807 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 808 | operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 809 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 810 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 811 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 812 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 813 | default: |
| 814 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 815 | (void)status; |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 816 | (void)key_buffer; |
| 817 | (void)key_buffer_size; |
| 818 | (void)alg; |
Ronald Cron | c45b4af | 2020-09-29 16:18:05 +0200 | [diff] [blame] | 819 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 820 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | psa_status_t psa_driver_wrapper_cipher_decrypt_setup( |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 824 | psa_cipher_operation_t *operation, |
| 825 | const psa_key_attributes_t *attributes, |
| 826 | const uint8_t *key_buffer, size_t key_buffer_size, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 827 | psa_algorithm_t alg ) |
| 828 | { |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 829 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | a4af55f | 2020-12-14 14:36:06 +0100 | [diff] [blame] | 830 | psa_key_location_t location = |
| 831 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 832 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 833 | switch( location ) |
| 834 | { |
| 835 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 836 | /* Key is stored in the slot in export representation, so |
| 837 | * cycle through all known transparent accelerators */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 838 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 839 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 840 | status = mbedtls_test_transparent_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 841 | &operation->ctx.transparent_test_driver_ctx, |
| 842 | attributes, |
| 843 | key_buffer, |
| 844 | key_buffer_size, |
| 845 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 846 | /* Declared with fallback == true */ |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 847 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 848 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
Steven Cooreman | 150c99b | 2020-09-09 14:32:44 +0200 | [diff] [blame] | 849 | |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 850 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 851 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 852 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 853 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 854 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 855 | /* Fell through, meaning no accelerator supports this operation */ |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 856 | status = mbedtls_psa_cipher_decrypt_setup( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 857 | attributes, |
| 858 | key_buffer, |
| 859 | key_buffer_size, |
| 860 | alg ); |
| 861 | if( status == PSA_SUCCESS ) |
| 862 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 863 | |
| 864 | return( status ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 865 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 866 | return( PSA_ERROR_NOT_SUPPORTED ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 867 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 868 | /* Add cases for opaque driver here */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 869 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 870 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a1ce2f2 | 2021-03-18 20:49:29 +0100 | [diff] [blame] | 871 | case PSA_CRYPTO_TEST_DRIVER_LOCATION: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 872 | status = mbedtls_test_opaque_cipher_decrypt_setup( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 873 | &operation->ctx.opaque_test_driver_ctx, |
| 874 | attributes, |
| 875 | key_buffer, key_buffer_size, |
| 876 | alg ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 877 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 878 | if( status == PSA_SUCCESS ) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 879 | operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 880 | |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 881 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 882 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 883 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 884 | default: |
| 885 | /* Key is declared with a lifetime not known to us */ |
Ronald Cron | 0b80559 | 2020-12-14 18:08:20 +0100 | [diff] [blame] | 886 | (void)status; |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 887 | (void)key_buffer; |
| 888 | (void)key_buffer_size; |
| 889 | (void)alg; |
Ronald Cron | c45b4af | 2020-09-29 16:18:05 +0200 | [diff] [blame] | 890 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 891 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 894 | psa_status_t psa_driver_wrapper_cipher_set_iv( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 895 | psa_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 896 | const uint8_t *iv, |
| 897 | size_t iv_length ) |
| 898 | { |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 899 | switch( operation->id ) |
| 900 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 901 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 902 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 903 | return( mbedtls_psa_cipher_set_iv( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 904 | iv, |
| 905 | iv_length ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 906 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 907 | |
| 908 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 909 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 910 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 911 | return( mbedtls_test_transparent_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 912 | &operation->ctx.transparent_test_driver_ctx, |
| 913 | iv, iv_length ) ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 914 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 915 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 916 | return( mbedtls_test_opaque_cipher_set_iv( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 917 | &operation->ctx.opaque_test_driver_ctx, |
| 918 | iv, iv_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 919 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 920 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 921 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 922 | |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 923 | (void)iv; |
| 924 | (void)iv_length; |
| 925 | |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 926 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | psa_status_t psa_driver_wrapper_cipher_update( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 930 | psa_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 931 | const uint8_t *input, |
| 932 | size_t input_length, |
| 933 | uint8_t *output, |
| 934 | size_t output_size, |
| 935 | size_t *output_length ) |
| 936 | { |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 937 | switch( operation->id ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 938 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 939 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 940 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 941 | return( mbedtls_psa_cipher_update( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 942 | input, |
| 943 | input_length, |
| 944 | output, |
| 945 | output_size, |
| 946 | output_length ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 947 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
| 948 | |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +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) |
| 951 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 952 | return( mbedtls_test_transparent_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 953 | &operation->ctx.transparent_test_driver_ctx, |
| 954 | input, input_length, |
| 955 | output, output_size, output_length ) ); |
| 956 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 957 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 958 | return( mbedtls_test_opaque_cipher_update( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 959 | &operation->ctx.opaque_test_driver_ctx, |
| 960 | input, input_length, |
| 961 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 962 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 963 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 964 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 965 | |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 966 | (void)input; |
| 967 | (void)input_length; |
| 968 | (void)output; |
| 969 | (void)output_size; |
| 970 | (void)output_length; |
| 971 | |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 972 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | psa_status_t psa_driver_wrapper_cipher_finish( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 976 | psa_cipher_operation_t *operation, |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 977 | uint8_t *output, |
| 978 | size_t output_size, |
| 979 | size_t *output_length ) |
| 980 | { |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 981 | switch( operation->id ) |
| 982 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 983 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 984 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 985 | return( mbedtls_psa_cipher_finish( &operation->ctx.mbedtls_ctx, |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 986 | output, |
| 987 | output_size, |
| 988 | output_length ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 989 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 990 | |
| 991 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 992 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 993 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 994 | return( mbedtls_test_transparent_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 995 | &operation->ctx.transparent_test_driver_ctx, |
| 996 | output, output_size, output_length ) ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 997 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 998 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 999 | return( mbedtls_test_opaque_cipher_finish( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1000 | &operation->ctx.opaque_test_driver_ctx, |
| 1001 | output, output_size, output_length ) ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1002 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1003 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1004 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1005 | |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1006 | (void)output; |
| 1007 | (void)output_size; |
| 1008 | (void)output_length; |
| 1009 | |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1010 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | psa_status_t psa_driver_wrapper_cipher_abort( |
Ronald Cron | 6056fe8 | 2020-12-15 13:58:07 +0100 | [diff] [blame] | 1014 | psa_cipher_operation_t *operation ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1015 | { |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1016 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1017 | |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1018 | switch( operation->id ) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1019 | { |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1020 | #if defined(MBEDTLS_PSA_BUILTIN_CIPHER) |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1021 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
Ronald Cron | 6e412a7 | 2021-03-10 09:58:47 +0100 | [diff] [blame] | 1022 | return( mbedtls_psa_cipher_abort( &operation->ctx.mbedtls_ctx ) ); |
Ronald Cron | 5d9b00d | 2021-03-10 14:43:20 +0100 | [diff] [blame] | 1023 | #endif /* MBEDTLS_PSA_BUILTIN_CIPHER */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1024 | |
| 1025 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1026 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 1027 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1028 | status = mbedtls_test_transparent_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1029 | &operation->ctx.transparent_test_driver_ctx ); |
Steven Cooreman | cfeea8f | 2020-09-09 15:09:18 +0200 | [diff] [blame] | 1030 | mbedtls_platform_zeroize( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1031 | &operation->ctx.transparent_test_driver_ctx, |
| 1032 | sizeof( operation->ctx.transparent_test_driver_ctx ) ); |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 1033 | return( status ); |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1034 | |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1035 | case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1036 | status = mbedtls_test_opaque_cipher_abort( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1037 | &operation->ctx.opaque_test_driver_ctx ); |
Steven Cooreman | cfeea8f | 2020-09-09 15:09:18 +0200 | [diff] [blame] | 1038 | mbedtls_platform_zeroize( |
Ronald Cron | 7cb9c3d | 2021-03-10 12:21:48 +0100 | [diff] [blame] | 1039 | &operation->ctx.opaque_test_driver_ctx, |
| 1040 | sizeof( operation->ctx.opaque_test_driver_ctx ) ); |
Steven Cooreman | 5240e8b | 2020-09-09 11:51:45 +0200 | [diff] [blame] | 1041 | return( status ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1042 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1043 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1044 | } |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1045 | |
Ronald Cron | 49fafa9 | 2021-03-10 08:34:23 +0100 | [diff] [blame] | 1046 | (void)status; |
Ronald Cron | dd24c9b | 2020-12-15 14:10:01 +0100 | [diff] [blame] | 1047 | return( PSA_ERROR_INVALID_ARGUMENT ); |
Steven Cooreman | 37941cb | 2020-07-28 18:49:51 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1050 | /* |
| 1051 | * Hashing functions |
| 1052 | */ |
| 1053 | psa_status_t psa_driver_wrapper_hash_compute( |
| 1054 | psa_algorithm_t alg, |
| 1055 | const uint8_t *input, |
| 1056 | size_t input_length, |
| 1057 | uint8_t *hash, |
| 1058 | size_t hash_size, |
| 1059 | size_t *hash_length) |
| 1060 | { |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1061 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1062 | |
| 1063 | /* Try accelerators first */ |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1064 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1065 | status = mbedtls_test_transparent_hash_compute( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1066 | alg, input, input_length, hash, hash_size, hash_length ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1067 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1068 | return( status ); |
| 1069 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1070 | |
| 1071 | /* If software fallback is compiled in, try fallback */ |
| 1072 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1073 | status = mbedtls_psa_hash_compute( alg, input, input_length, |
| 1074 | hash, hash_size, hash_length ); |
| 1075 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1076 | return( status ); |
| 1077 | #endif |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1078 | (void) status; |
| 1079 | (void) alg; |
| 1080 | (void) input; |
| 1081 | (void) input_length; |
| 1082 | (void) hash; |
| 1083 | (void) hash_size; |
| 1084 | (void) hash_length; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1085 | |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1086 | return( PSA_ERROR_NOT_SUPPORTED ); |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | psa_status_t psa_driver_wrapper_hash_setup( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1090 | psa_hash_operation_t *operation, |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1091 | psa_algorithm_t alg ) |
| 1092 | { |
Steven Cooreman | 0eeb794 | 2021-03-08 12:13:21 +0100 | [diff] [blame] | 1093 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1094 | |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1095 | /* Try setup on accelerators first */ |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1096 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1097 | status = mbedtls_test_transparent_hash_setup( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1098 | &operation->ctx.test_driver_ctx, alg ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1099 | if( status == PSA_SUCCESS ) |
| 1100 | operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
| 1101 | |
| 1102 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1103 | return( status ); |
| 1104 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1105 | |
| 1106 | /* If software fallback is compiled in, try fallback */ |
| 1107 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1108 | status = mbedtls_psa_hash_setup( &operation->ctx.mbedtls_ctx, alg ); |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1109 | if( status == PSA_SUCCESS ) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1110 | operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1111 | |
| 1112 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1113 | return( status ); |
| 1114 | #endif |
| 1115 | /* Nothing left to try if we fall through here */ |
| 1116 | (void) status; |
| 1117 | (void) operation; |
| 1118 | (void) alg; |
| 1119 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 1120 | } |
| 1121 | |
| 1122 | psa_status_t psa_driver_wrapper_hash_clone( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1123 | const psa_hash_operation_t *source_operation, |
| 1124 | psa_hash_operation_t *target_operation ) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1125 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1126 | switch( source_operation->id ) |
| 1127 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1128 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1129 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1130 | target_operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; |
| 1131 | return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx, |
| 1132 | &target_operation->ctx.mbedtls_ctx ) ); |
| 1133 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1134 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1135 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
| 1136 | target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1137 | return( mbedtls_test_transparent_hash_clone( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1138 | &source_operation->ctx.test_driver_ctx, |
| 1139 | &target_operation->ctx.test_driver_ctx ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1140 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1141 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1142 | (void) target_operation; |
| 1143 | return( PSA_ERROR_BAD_STATE ); |
| 1144 | } |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | psa_status_t psa_driver_wrapper_hash_update( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1148 | psa_hash_operation_t *operation, |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1149 | const uint8_t *input, |
| 1150 | size_t input_length ) |
| 1151 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1152 | switch( operation->id ) |
| 1153 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1154 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1155 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1156 | return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx, |
| 1157 | input, input_length ) ); |
| 1158 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1159 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1160 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1161 | return( mbedtls_test_transparent_hash_update( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1162 | &operation->ctx.test_driver_ctx, |
| 1163 | input, input_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1164 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1165 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1166 | (void) input; |
| 1167 | (void) input_length; |
| 1168 | return( PSA_ERROR_BAD_STATE ); |
| 1169 | } |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | psa_status_t psa_driver_wrapper_hash_finish( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1173 | psa_hash_operation_t *operation, |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1174 | uint8_t *hash, |
| 1175 | size_t hash_size, |
| 1176 | size_t *hash_length ) |
| 1177 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1178 | switch( operation->id ) |
| 1179 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1180 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1181 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1182 | return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx, |
| 1183 | hash, hash_size, hash_length ) ); |
| 1184 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1185 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1186 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1187 | return( mbedtls_test_transparent_hash_finish( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1188 | &operation->ctx.test_driver_ctx, |
| 1189 | hash, hash_size, hash_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1190 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1191 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1192 | (void) hash; |
| 1193 | (void) hash_size; |
| 1194 | (void) hash_length; |
| 1195 | return( PSA_ERROR_BAD_STATE ); |
| 1196 | } |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | psa_status_t psa_driver_wrapper_hash_abort( |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 1200 | psa_hash_operation_t *operation ) |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1201 | { |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1202 | switch( operation->id ) |
| 1203 | { |
Steven Cooreman | 5e4c18f | 2021-03-15 12:26:07 +0100 | [diff] [blame] | 1204 | #if defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 1205 | case PSA_CRYPTO_MBED_TLS_DRIVER_ID: |
| 1206 | return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); |
| 1207 | #endif |
Steven Cooreman | f8e45a4 | 2021-03-16 11:07:55 +0100 | [diff] [blame] | 1208 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1209 | case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1210 | return( mbedtls_test_transparent_hash_abort( |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 1211 | &operation->ctx.test_driver_ctx ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 1212 | #endif |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1213 | default: |
Steven Cooreman | 1e58235 | 2021-02-18 17:24:37 +0100 | [diff] [blame] | 1214 | return( PSA_ERROR_BAD_STATE ); |
| 1215 | } |
| 1216 | } |
| 1217 | |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1218 | psa_status_t psa_driver_wrapper_aead_encrypt( |
| 1219 | const psa_key_attributes_t *attributes, |
| 1220 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 1221 | psa_algorithm_t alg, |
| 1222 | const uint8_t *nonce, size_t nonce_length, |
| 1223 | const uint8_t *additional_data, size_t additional_data_length, |
| 1224 | const uint8_t *plaintext, size_t plaintext_length, |
| 1225 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ) |
| 1226 | { |
| 1227 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1228 | psa_key_location_t location = |
| 1229 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1230 | |
| 1231 | switch( location ) |
| 1232 | { |
| 1233 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1234 | /* Key is stored in the slot in export representation, so |
| 1235 | * cycle through all known transparent accelerators */ |
| 1236 | |
| 1237 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1238 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1239 | status = mbedtls_test_transparent_aead_encrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1240 | attributes, key_buffer, key_buffer_size, |
| 1241 | alg, |
| 1242 | nonce, nonce_length, |
| 1243 | additional_data, additional_data_length, |
| 1244 | plaintext, plaintext_length, |
| 1245 | ciphertext, ciphertext_size, ciphertext_length ); |
| 1246 | /* Declared with fallback == true */ |
| 1247 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1248 | return( status ); |
| 1249 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1250 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1251 | |
| 1252 | /* Fell through, meaning no accelerator supports this operation */ |
| 1253 | return( mbedtls_psa_aead_encrypt( |
| 1254 | attributes, key_buffer, key_buffer_size, |
| 1255 | alg, |
| 1256 | nonce, nonce_length, |
| 1257 | additional_data, additional_data_length, |
| 1258 | plaintext, plaintext_length, |
| 1259 | ciphertext, ciphertext_size, ciphertext_length ) ); |
| 1260 | |
| 1261 | /* Add cases for opaque driver here */ |
| 1262 | |
| 1263 | default: |
| 1264 | /* Key is declared with a lifetime not known to us */ |
| 1265 | (void)status; |
| 1266 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | psa_status_t psa_driver_wrapper_aead_decrypt( |
| 1271 | const psa_key_attributes_t *attributes, |
| 1272 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 1273 | psa_algorithm_t alg, |
| 1274 | const uint8_t *nonce, size_t nonce_length, |
| 1275 | const uint8_t *additional_data, size_t additional_data_length, |
| 1276 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 1277 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ) |
| 1278 | { |
| 1279 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 1280 | psa_key_location_t location = |
| 1281 | PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ); |
| 1282 | |
| 1283 | switch( location ) |
| 1284 | { |
| 1285 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 1286 | /* Key is stored in the slot in export representation, so |
| 1287 | * cycle through all known transparent accelerators */ |
| 1288 | |
| 1289 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
| 1290 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame^] | 1291 | status = mbedtls_test_transparent_aead_decrypt( |
Ronald Cron | de82281 | 2021-03-17 16:08:20 +0100 | [diff] [blame] | 1292 | attributes, key_buffer, key_buffer_size, |
| 1293 | alg, |
| 1294 | nonce, nonce_length, |
| 1295 | additional_data, additional_data_length, |
| 1296 | ciphertext, ciphertext_length, |
| 1297 | plaintext, plaintext_size, plaintext_length ); |
| 1298 | /* Declared with fallback == true */ |
| 1299 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 1300 | return( status ); |
| 1301 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 1302 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 1303 | |
| 1304 | /* Fell through, meaning no accelerator supports this operation */ |
| 1305 | return( mbedtls_psa_aead_decrypt( |
| 1306 | attributes, key_buffer, key_buffer_size, |
| 1307 | alg, |
| 1308 | nonce, nonce_length, |
| 1309 | additional_data, additional_data_length, |
| 1310 | ciphertext, ciphertext_length, |
| 1311 | plaintext, plaintext_size, plaintext_length ) ); |
| 1312 | |
| 1313 | /* Add cases for opaque driver here */ |
| 1314 | |
| 1315 | default: |
| 1316 | /* Key is declared with a lifetime not known to us */ |
| 1317 | (void)status; |
| 1318 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 1319 | } |
| 1320 | } |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 1321 | /* End of automatically generated file. */ |