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. |
| 4 | * Warning: auto-generated file. |
| 5 | */ |
| 6 | /* Copyright (C) 2020, ARM Limited, All Rights Reserved |
| 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. |
| 20 | * |
| 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 22 | */ |
| 23 | |
| 24 | #include "psa_crypto_core.h" |
| 25 | #include "psa_crypto_driver_wrappers.h" |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 26 | #include "mbedtls/platform.h" |
| 27 | |
| 28 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 29 | |
| 30 | /* Include test driver definition when running tests */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 31 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 32 | #undef PSA_CRYPTO_DRIVER_PRESENT |
| 33 | #define PSA_CRYPTO_DRIVER_PRESENT |
| 34 | #undef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
| 35 | #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 36 | #include "drivers/test_driver.h" |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 37 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 38 | |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 39 | /* Include driver definition file for each registered driver here */ |
| 40 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */ |
| 41 | |
| 42 | /* Support the 'old' SE interface when asked to */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 43 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 44 | #undef PSA_CRYPTO_DRIVER_PRESENT |
| 45 | #define PSA_CRYPTO_DRIVER_PRESENT |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 46 | #include "psa_crypto_se.h" |
| 47 | #endif |
| 48 | |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 49 | /* Start delegation functions */ |
| 50 | psa_status_t psa_driver_wrapper_sign_hash( psa_key_slot_t *slot, |
| 51 | psa_algorithm_t alg, |
| 52 | const uint8_t *hash, |
| 53 | size_t hash_length, |
| 54 | uint8_t *signature, |
| 55 | size_t signature_size, |
| 56 | size_t *signature_length ) |
| 57 | { |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 58 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 59 | /* Try dynamically-registered SE interface first */ |
| 60 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 61 | const psa_drv_se_t *drv; |
| 62 | psa_drv_se_context_t *drv_context; |
| 63 | |
| 64 | if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) ) |
| 65 | { |
| 66 | if( drv->asymmetric == NULL || |
| 67 | drv->asymmetric->p_sign == NULL ) |
| 68 | { |
| 69 | /* Key is defined in SE, but we have no way to exercise it */ |
| 70 | return PSA_ERROR_INVALID_ARGUMENT; |
| 71 | } |
| 72 | return( drv->asymmetric->p_sign( drv_context, |
| 73 | slot->data.se.slot_number, |
| 74 | alg, |
| 75 | hash, hash_length, |
| 76 | signature, signature_size, |
| 77 | signature_length ) ); |
| 78 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 79 | #endif /* PSA_CRYPTO_SE_C */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 80 | |
| 81 | /* Then try accelerator API */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 82 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 83 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 84 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 85 | psa_key_attributes_t attributes = { |
| 86 | .core = slot->attr |
| 87 | }; |
| 88 | |
| 89 | switch( location ) |
| 90 | { |
| 91 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 92 | /* Key is stored in the slot in export representation, so |
| 93 | * cycle through all known transparent accelerators */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 94 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 95 | status = test_transparent_signature_sign_hash( &attributes, |
| 96 | slot->data.key.data, |
| 97 | slot->data.key.bytes, |
| 98 | alg, |
| 99 | hash, |
| 100 | hash_length, |
| 101 | signature, |
| 102 | signature_size, |
| 103 | signature_length ); |
| 104 | /* Declared with fallback == true */ |
| 105 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 106 | return status; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 107 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 108 | /* Fell through, meaning no accelerator supports this operation */ |
| 109 | return PSA_ERROR_NOT_SUPPORTED; |
| 110 | /* Add cases for opaque driver here */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 111 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 112 | case PSA_CRYPTO_TEST_DRIVER_LIFETIME: |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 113 | return( test_opaque_signature_sign_hash( &attributes, |
| 114 | slot->data.key.data, |
| 115 | slot->data.key.bytes, |
| 116 | alg, |
| 117 | hash, |
| 118 | hash_length, |
| 119 | signature, |
| 120 | signature_size, |
| 121 | signature_length ) ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 122 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 123 | default: |
| 124 | /* Key is declared with a lifetime not known to us */ |
| 125 | return status; |
| 126 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 127 | #else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 7a25057 | 2020-07-17 16:43:05 +0200 | [diff] [blame] | 128 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 129 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 130 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 131 | (void)slot; |
| 132 | (void)alg; |
| 133 | (void)hash; |
| 134 | (void)hash_length; |
| 135 | (void)signature; |
| 136 | (void)signature_size; |
| 137 | (void)signature_length; |
| 138 | |
| 139 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 140 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 143 | psa_status_t psa_driver_wrapper_verify_hash( psa_key_slot_t *slot, |
| 144 | psa_algorithm_t alg, |
| 145 | const uint8_t *hash, |
| 146 | size_t hash_length, |
| 147 | const uint8_t *signature, |
| 148 | size_t signature_length ) |
| 149 | { |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 150 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 151 | /* Try dynamically-registered SE interface first */ |
| 152 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 153 | const psa_drv_se_t *drv; |
| 154 | psa_drv_se_context_t *drv_context; |
| 155 | |
| 156 | if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) ) |
| 157 | { |
| 158 | if( drv->asymmetric == NULL || |
| 159 | drv->asymmetric->p_verify == NULL ) |
| 160 | { |
| 161 | /* Key is defined in SE, but we have no way to exercise it */ |
| 162 | return PSA_ERROR_INVALID_ARGUMENT; |
| 163 | } |
| 164 | return( drv->asymmetric->p_verify( drv_context, |
| 165 | slot->data.se.slot_number, |
| 166 | alg, |
| 167 | hash, hash_length, |
| 168 | signature, signature_length ) ); |
| 169 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 170 | #endif /* PSA_CRYPTO_SE_C */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 171 | |
| 172 | /* Then try accelerator API */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 173 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 174 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 175 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 176 | psa_key_attributes_t attributes = { |
| 177 | .core = slot->attr |
| 178 | }; |
| 179 | |
| 180 | switch( location ) |
| 181 | { |
| 182 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 183 | /* Key is stored in the slot in export representation, so |
| 184 | * cycle through all known transparent accelerators */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 185 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 186 | status = test_transparent_signature_verify_hash( &attributes, |
| 187 | slot->data.key.data, |
| 188 | slot->data.key.bytes, |
| 189 | alg, |
| 190 | hash, |
| 191 | hash_length, |
| 192 | signature, |
| 193 | signature_length ); |
| 194 | /* Declared with fallback == true */ |
| 195 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 196 | return status; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 197 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 198 | /* Fell through, meaning no accelerator supports this operation */ |
| 199 | return PSA_ERROR_NOT_SUPPORTED; |
| 200 | /* Add cases for opaque driver here */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 201 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 202 | case PSA_CRYPTO_TEST_DRIVER_LIFETIME: |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 203 | return( test_opaque_signature_verify_hash( &attributes, |
| 204 | slot->data.key.data, |
| 205 | slot->data.key.bytes, |
| 206 | alg, |
| 207 | hash, |
| 208 | hash_length, |
| 209 | signature, |
| 210 | signature_length ) ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 211 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 212 | default: |
| 213 | /* Key is declared with a lifetime not known to us */ |
| 214 | return status; |
| 215 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 216 | #else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 217 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 218 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 219 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 220 | (void)slot; |
| 221 | (void)alg; |
| 222 | (void)hash; |
| 223 | (void)hash_length; |
| 224 | (void)signature; |
| 225 | (void)signature_length; |
| 226 | |
| 227 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 228 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 231 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 232 | static psa_status_t get_expected_key_size( const psa_key_attributes_t *attributes, |
| 233 | size_t *expected_size ) |
| 234 | { |
| 235 | if( PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ) == PSA_KEY_LOCATION_LOCAL_STORAGE ) |
| 236 | { |
| 237 | if( PSA_KEY_TYPE_IS_UNSTRUCTURED( attributes->core.type ) ) |
| 238 | { |
| 239 | *expected_size = PSA_BITS_TO_BYTES( attributes->core.bits ); |
| 240 | return PSA_SUCCESS; |
| 241 | } |
| 242 | |
| 243 | if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) ) |
| 244 | { |
| 245 | if( PSA_KEY_TYPE_IS_KEY_PAIR( attributes->core.type ) ) |
| 246 | { |
| 247 | *expected_size = PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE( attributes->core.bits ); |
| 248 | return PSA_SUCCESS; |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | *expected_size = PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE( attributes->core.bits ); |
| 253 | return PSA_SUCCESS; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | if( PSA_KEY_TYPE_IS_RSA( attributes->core.type ) ) |
| 258 | { |
| 259 | if( PSA_KEY_TYPE_IS_KEY_PAIR( attributes->core.type ) ) |
| 260 | { |
| 261 | *expected_size = PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE( attributes->core.bits ); |
| 262 | return PSA_SUCCESS; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | *expected_size = PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE( attributes->core.bits ); |
| 267 | return PSA_SUCCESS; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return PSA_ERROR_NOT_SUPPORTED; |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | /* TBD: opaque driver support, need to calculate size through driver-defined size function */ |
| 276 | return PSA_ERROR_NOT_SUPPORTED; |
| 277 | } |
| 278 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 279 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 280 | |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 281 | psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attributes, |
| 282 | psa_key_slot_t *slot ) |
| 283 | { |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 284 | #if defined(PSA_CRYPTO_DRIVER_PRESENT) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 285 | /* Try dynamically-registered SE interface first */ |
| 286 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 287 | const psa_drv_se_t *drv; |
| 288 | psa_drv_se_context_t *drv_context; |
| 289 | |
| 290 | if( psa_get_se_driver( slot->attr.lifetime, &drv, &drv_context ) ) |
| 291 | { |
| 292 | size_t pubkey_length = 0; /* We don't support this feature yet */ |
| 293 | if( drv->key_management == NULL || |
| 294 | drv->key_management->p_generate == NULL ) |
| 295 | { |
| 296 | /* Key is defined as being in SE, but we have no way to generate it */ |
| 297 | return PSA_ERROR_NOT_SUPPORTED; |
| 298 | } |
| 299 | return( drv->key_management->p_generate( |
| 300 | drv_context, |
| 301 | slot->data.se.slot_number, attributes, |
| 302 | NULL, 0, &pubkey_length ) ); |
| 303 | } |
| 304 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 305 | |
| 306 | /* Then try accelerator API */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 307 | #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 308 | psa_status_t status = PSA_ERROR_INVALID_ARGUMENT; |
| 309 | psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime); |
| 310 | size_t export_size = 0; |
| 311 | |
| 312 | status = get_expected_key_size( attributes, &export_size ); |
| 313 | if( status != PSA_SUCCESS ) |
| 314 | return status; |
| 315 | |
| 316 | slot->data.key.data = mbedtls_calloc(1, export_size); |
| 317 | if( slot->data.key.data == NULL ) |
| 318 | return PSA_ERROR_INSUFFICIENT_MEMORY; |
| 319 | slot->data.key.bytes = export_size; |
| 320 | |
| 321 | switch( location ) |
| 322 | { |
| 323 | case PSA_KEY_LOCATION_LOCAL_STORAGE: |
| 324 | /* Key is stored in the slot in export representation, so |
| 325 | * cycle through all known transparent accelerators */ |
| 326 | |
| 327 | /* Transparent drivers are limited to generating asymmetric keys */ |
| 328 | if( ! PSA_KEY_TYPE_IS_ASYMMETRIC( slot->attr.type ) ) |
| 329 | { |
| 330 | status = PSA_ERROR_NOT_SUPPORTED; |
| 331 | break; |
| 332 | } |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 333 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 334 | status = test_transparent_generate_key( attributes, |
| 335 | slot->data.key.data, |
| 336 | slot->data.key.bytes, |
| 337 | &slot->data.key.bytes ); |
| 338 | /* Declared with fallback == true */ |
| 339 | if( status != PSA_ERROR_NOT_SUPPORTED ) |
| 340 | break; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 341 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 342 | /* Fell through, meaning no accelerator supports this operation */ |
| 343 | status = PSA_ERROR_NOT_SUPPORTED; |
| 344 | break; |
| 345 | /* Add cases for opaque driver here */ |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 346 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 347 | case PSA_CRYPTO_TEST_DRIVER_LIFETIME: |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 348 | status = test_opaque_generate_key( attributes, |
| 349 | slot->data.key.data, |
| 350 | slot->data.key.bytes, |
| 351 | &slot->data.key.bytes ); |
| 352 | break; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 353 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 354 | default: |
| 355 | /* Key is declared with a lifetime not known to us */ |
| 356 | status = PSA_ERROR_INVALID_ARGUMENT; |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | if( status != PSA_SUCCESS ) |
| 361 | { |
| 362 | /* free allocated buffer */ |
| 363 | mbedtls_free( slot->data.key.data ); |
| 364 | slot->data.key.data = NULL; |
| 365 | slot->data.key.bytes = 0; |
| 366 | } |
| 367 | |
| 368 | return( status ); |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 369 | #else /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 370 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 371 | #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ |
| 372 | #else /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 373 | (void) attributes; |
| 374 | (void) slot; |
| 375 | |
| 376 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame^] | 377 | #endif /* PSA_CRYPTO_DRIVER_PRESENT */ |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 378 | } |
| 379 | |
Steven Cooreman | cd84cb4 | 2020-07-16 20:28:36 +0200 | [diff] [blame] | 380 | /* End of automatically generated file. */ |