Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * PSA crypto support for secure element drivers |
| 3 | */ |
| 4 | /* Copyright (C) 2019, ARM Limited, All Rights Reserved |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * This file is part of Mbed TLS (https://tls.mbed.org) |
| 20 | */ |
| 21 | |
| 22 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 23 | #include "mbedtls/config.h" |
| 24 | #else |
| 25 | #include MBEDTLS_CONFIG_FILE |
| 26 | #endif |
| 27 | |
Gilles Peskine | a8ade16 | 2019-06-26 11:24:49 +0200 | [diff] [blame] | 28 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 29 | |
Gilles Peskine | 9717d10 | 2019-06-26 11:50:04 +0200 | [diff] [blame] | 30 | #include <assert.h> |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 31 | #include <stdint.h> |
Gilles Peskine | d089021 | 2019-06-24 14:34:43 +0200 | [diff] [blame] | 32 | #include <string.h> |
| 33 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 34 | #include "psa/crypto_se_driver.h" |
| 35 | |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 36 | #include "psa_crypto_se.h" |
| 37 | |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 38 | #if defined(MBEDTLS_PSA_ITS_FILE_C) |
| 39 | #include "psa_crypto_its.h" |
| 40 | #else /* Native ITS implementation */ |
| 41 | #include "psa/error.h" |
| 42 | #include "psa/internal_trusted_storage.h" |
| 43 | #endif |
| 44 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 45 | #include "mbedtls/platform.h" |
| 46 | #if !defined(MBEDTLS_PLATFORM_C) |
| 47 | #define mbedtls_calloc calloc |
| 48 | #define mbedtls_free free |
| 49 | #endif |
| 50 | |
| 51 | |
| 52 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 53 | /****************************************************************/ |
| 54 | /* Driver lookup */ |
| 55 | /****************************************************************/ |
| 56 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 57 | /* This structure is identical to psa_drv_se_context_t declared in |
| 58 | * `crypto_se_driver.h`, except that some parts are writable here |
| 59 | * (non-const, or pointer to non-const). */ |
| 60 | typedef struct |
| 61 | { |
| 62 | void *persistent_data; |
| 63 | size_t persistent_data_size; |
| 64 | uintptr_t transient_data; |
| 65 | } psa_drv_se_internal_context_t; |
| 66 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 67 | typedef struct psa_se_drv_table_entry_s |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 68 | { |
| 69 | psa_key_lifetime_t lifetime; |
| 70 | const psa_drv_se_t *methods; |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 71 | union |
| 72 | { |
| 73 | psa_drv_se_internal_context_t internal; |
| 74 | psa_drv_se_context_t context; |
| 75 | }; |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 76 | } psa_se_drv_table_entry_t; |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 77 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 78 | static psa_se_drv_table_entry_t driver_table[PSA_MAX_SE_DRIVERS]; |
| 79 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 80 | psa_se_drv_table_entry_t *psa_get_se_driver_entry( |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 81 | psa_key_lifetime_t lifetime ) |
| 82 | { |
| 83 | size_t i; |
Gilles Peskine | 75c126b | 2019-07-24 15:56:01 +0200 | [diff] [blame] | 84 | /* In the driver table, lifetime=0 means an entry that isn't used. |
| 85 | * No driver has a lifetime of 0 because it's a reserved value |
| 86 | * (which designates volatile keys). Make sure we never return |
| 87 | * a driver entry for lifetime 0. */ |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 88 | if( lifetime == 0 ) |
| 89 | return( NULL ); |
| 90 | for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ ) |
| 91 | { |
| 92 | if( driver_table[i].lifetime == lifetime ) |
| 93 | return( &driver_table[i] ); |
| 94 | } |
| 95 | return( NULL ); |
| 96 | } |
| 97 | |
| 98 | const psa_drv_se_t *psa_get_se_driver_methods( |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 99 | const psa_se_drv_table_entry_t *driver ) |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 100 | { |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 101 | return( driver->methods ); |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 104 | psa_drv_se_context_t *psa_get_se_driver_context( |
| 105 | psa_se_drv_table_entry_t *driver ) |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 106 | { |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 107 | return( &driver->context ); |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 110 | int psa_get_se_driver( psa_key_lifetime_t lifetime, |
| 111 | const psa_drv_se_t **p_methods, |
| 112 | psa_drv_se_context_t **p_drv_context) |
| 113 | { |
| 114 | psa_se_drv_table_entry_t *driver = psa_get_se_driver_entry( lifetime ); |
| 115 | if( p_methods != NULL ) |
| 116 | *p_methods = ( driver ? driver->methods : NULL ); |
| 117 | if( p_drv_context != NULL ) |
| 118 | *p_drv_context = ( driver ? &driver->context : NULL ); |
| 119 | return( driver != NULL ); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | |
| 124 | /****************************************************************/ |
| 125 | /* Persistent data management */ |
| 126 | /****************************************************************/ |
| 127 | |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 128 | static psa_status_t psa_get_se_driver_its_file_uid( |
| 129 | const psa_se_drv_table_entry_t *driver, |
| 130 | psa_storage_uid_t *uid ) |
| 131 | { |
| 132 | if( driver->lifetime > PSA_MAX_SE_LIFETIME ) |
| 133 | return( PSA_ERROR_NOT_SUPPORTED ); |
Gilles Peskine | 573bbc1 | 2019-07-23 19:59:23 +0200 | [diff] [blame] | 134 | |
| 135 | #if SIZE_MAX > UINT32_MAX |
| 136 | /* ITS file sizes are limited to 32 bits. */ |
| 137 | if( driver->internal.persistent_data_size > UINT32_MAX ) |
| 138 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 139 | #endif |
| 140 | |
Gilles Peskine | 75c126b | 2019-07-24 15:56:01 +0200 | [diff] [blame] | 141 | /* See the documentation of PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE. */ |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 142 | *uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->lifetime; |
| 143 | return( PSA_SUCCESS ); |
| 144 | } |
| 145 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 146 | psa_status_t psa_load_se_persistent_data( |
| 147 | const psa_se_drv_table_entry_t *driver ) |
| 148 | { |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 149 | psa_status_t status; |
| 150 | psa_storage_uid_t uid; |
Gilles Peskine | 8b66389 | 2019-07-31 17:57:57 +0200 | [diff] [blame] | 151 | size_t length; |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 152 | |
| 153 | status = psa_get_se_driver_its_file_uid( driver, &uid ); |
| 154 | if( status != PSA_SUCCESS ) |
| 155 | return( status ); |
| 156 | |
Gilles Peskine | 8b66389 | 2019-07-31 17:57:57 +0200 | [diff] [blame] | 157 | /* Read the amount of persistent data that the driver requests. |
| 158 | * If the data in storage is larger, it is truncated. If the data |
| 159 | * in storage is smaller, silently keep what is already at the end |
| 160 | * of the output buffer. */ |
Gilles Peskine | 75c126b | 2019-07-24 15:56:01 +0200 | [diff] [blame] | 161 | /* psa_get_se_driver_its_file_uid ensures that the size_t |
| 162 | * persistent_data_size is in range, but compilers don't know that, |
| 163 | * so cast to reassure them. */ |
Gilles Peskine | 573bbc1 | 2019-07-23 19:59:23 +0200 | [diff] [blame] | 164 | return( psa_its_get( uid, 0, |
| 165 | (uint32_t) driver->internal.persistent_data_size, |
Gilles Peskine | 8b66389 | 2019-07-31 17:57:57 +0200 | [diff] [blame] | 166 | driver->internal.persistent_data, |
| 167 | &length ) ); |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | psa_status_t psa_save_se_persistent_data( |
| 171 | const psa_se_drv_table_entry_t *driver ) |
| 172 | { |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 173 | psa_status_t status; |
| 174 | psa_storage_uid_t uid; |
| 175 | |
| 176 | status = psa_get_se_driver_its_file_uid( driver, &uid ); |
| 177 | if( status != PSA_SUCCESS ) |
| 178 | return( status ); |
| 179 | |
Gilles Peskine | 75c126b | 2019-07-24 15:56:01 +0200 | [diff] [blame] | 180 | /* psa_get_se_driver_its_file_uid ensures that the size_t |
| 181 | * persistent_data_size is in range, but compilers don't know that, |
| 182 | * so cast to reassure them. */ |
Gilles Peskine | 573bbc1 | 2019-07-23 19:59:23 +0200 | [diff] [blame] | 183 | return( psa_its_set( uid, |
| 184 | (uint32_t) driver->internal.persistent_data_size, |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 185 | driver->internal.persistent_data, |
| 186 | 0 ) ); |
| 187 | } |
| 188 | |
| 189 | psa_status_t psa_destroy_se_persistent_data( psa_key_lifetime_t lifetime ) |
| 190 | { |
| 191 | psa_storage_uid_t uid; |
| 192 | if( lifetime > PSA_MAX_SE_LIFETIME ) |
| 193 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 194 | uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + lifetime; |
| 195 | return( psa_its_remove( uid ) ); |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 196 | } |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 197 | |
Gilles Peskine | cbaff46 | 2019-07-12 23:46:04 +0200 | [diff] [blame] | 198 | psa_status_t psa_find_se_slot_for_key( |
| 199 | const psa_key_attributes_t *attributes, |
Gilles Peskine | e88c2c1 | 2019-08-05 16:44:14 +0200 | [diff] [blame^] | 200 | psa_key_creation_method_t method, |
Gilles Peskine | cbaff46 | 2019-07-12 23:46:04 +0200 | [diff] [blame] | 201 | psa_se_drv_table_entry_t *driver, |
| 202 | psa_key_slot_number_t *slot_number ) |
| 203 | { |
| 204 | psa_status_t status; |
Gilles Peskine | cbaff46 | 2019-07-12 23:46:04 +0200 | [diff] [blame] | 205 | |
| 206 | /* If the lifetime is wrong, it's a bug in the library. */ |
Gilles Peskine | 7e0cff9 | 2019-07-30 13:48:52 +0200 | [diff] [blame] | 207 | if( driver->lifetime != psa_get_key_lifetime( attributes ) ) |
Gilles Peskine | cbaff46 | 2019-07-12 23:46:04 +0200 | [diff] [blame] | 208 | return( PSA_ERROR_CORRUPTION_DETECTED ); |
| 209 | |
| 210 | /* If the driver doesn't support key creation in any way, give up now. */ |
| 211 | if( driver->methods->key_management == NULL ) |
| 212 | return( PSA_ERROR_NOT_SUPPORTED ); |
Gilles Peskine | cbaff46 | 2019-07-12 23:46:04 +0200 | [diff] [blame] | 213 | |
Gilles Peskine | 46d9439 | 2019-08-05 14:55:50 +0200 | [diff] [blame] | 214 | if( psa_get_key_slot_number( attributes, slot_number ) == PSA_SUCCESS ) |
| 215 | { |
| 216 | /* The application wants to use a specific slot. Allow it if |
| 217 | * the driver supports it. On a system with isolation, |
| 218 | * the crypto service must check that the application is |
| 219 | * permitted to request this slot. */ |
| 220 | psa_drv_se_validate_slot_number_t p_validate_slot_number = |
| 221 | driver->methods->key_management->p_validate_slot_number; |
| 222 | if( p_validate_slot_number == NULL ) |
| 223 | return( PSA_ERROR_NOT_SUPPORTED ); |
Gilles Peskine | e88c2c1 | 2019-08-05 16:44:14 +0200 | [diff] [blame^] | 224 | status = p_validate_slot_number( &driver->context, |
| 225 | attributes, method, |
Gilles Peskine | 46d9439 | 2019-08-05 14:55:50 +0200 | [diff] [blame] | 226 | *slot_number ); |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | /* The application didn't tell us which slot to use. Let the driver |
| 231 | * choose. This is the normal case. */ |
| 232 | psa_drv_se_allocate_key_t p_allocate = |
| 233 | driver->methods->key_management->p_allocate; |
| 234 | if( p_allocate == NULL ) |
| 235 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 236 | status = p_allocate( &driver->context, |
| 237 | driver->internal.persistent_data, |
Gilles Peskine | e88c2c1 | 2019-08-05 16:44:14 +0200 | [diff] [blame^] | 238 | attributes, method, |
Gilles Peskine | 46d9439 | 2019-08-05 14:55:50 +0200 | [diff] [blame] | 239 | slot_number ); |
| 240 | } |
Gilles Peskine | cbaff46 | 2019-07-12 23:46:04 +0200 | [diff] [blame] | 241 | return( status ); |
| 242 | } |
| 243 | |
Gilles Peskine | 354f767 | 2019-07-12 23:46:38 +0200 | [diff] [blame] | 244 | psa_status_t psa_destroy_se_key( psa_se_drv_table_entry_t *driver, |
| 245 | psa_key_slot_number_t slot_number ) |
| 246 | { |
| 247 | psa_status_t status; |
| 248 | psa_status_t storage_status; |
Gilles Peskine | 340b127 | 2019-07-25 14:13:24 +0200 | [diff] [blame] | 249 | /* Normally a missing method would mean that the action is not |
| 250 | * supported. But psa_destroy_key() is not supposed to return |
| 251 | * PSA_ERROR_NOT_SUPPORTED: if you can create a key, you should |
| 252 | * be able to destroy it. The only use case for a driver that |
| 253 | * does not have a way to destroy keys at all is if the keys are |
| 254 | * locked in a read-only state: we can use the keys but not |
| 255 | * destroy them. Hence, if the driver doesn't support destroying |
| 256 | * keys, it's really a lack of permission. */ |
Gilles Peskine | 354f767 | 2019-07-12 23:46:38 +0200 | [diff] [blame] | 257 | if( driver->methods->key_management == NULL || |
| 258 | driver->methods->key_management->p_destroy == NULL ) |
| 259 | return( PSA_ERROR_NOT_PERMITTED ); |
| 260 | status = driver->methods->key_management->p_destroy( |
| 261 | &driver->context, |
| 262 | driver->internal.persistent_data, |
| 263 | slot_number ); |
| 264 | storage_status = psa_save_se_persistent_data( driver ); |
| 265 | return( status == PSA_SUCCESS ? storage_status : status ); |
| 266 | } |
| 267 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 268 | |
| 269 | |
| 270 | /****************************************************************/ |
| 271 | /* Driver registration */ |
| 272 | /****************************************************************/ |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 273 | |
| 274 | psa_status_t psa_register_se_driver( |
| 275 | psa_key_lifetime_t lifetime, |
| 276 | const psa_drv_se_t *methods) |
| 277 | { |
| 278 | size_t i; |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 279 | psa_status_t status; |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 280 | |
| 281 | if( methods->hal_version != PSA_DRV_SE_HAL_VERSION ) |
| 282 | return( PSA_ERROR_NOT_SUPPORTED ); |
Gilles Peskine | 9717d10 | 2019-06-26 11:50:04 +0200 | [diff] [blame] | 283 | /* Driver table entries are 0-initialized. 0 is not a valid driver |
| 284 | * lifetime because it means a volatile key. */ |
| 285 | #if defined(static_assert) |
| 286 | static_assert( PSA_KEY_LIFETIME_VOLATILE == 0, |
| 287 | "Secure element support requires 0 to mean a volatile key" ); |
| 288 | #endif |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 289 | if( lifetime == PSA_KEY_LIFETIME_VOLATILE || |
| 290 | lifetime == PSA_KEY_LIFETIME_PERSISTENT ) |
| 291 | { |
| 292 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 293 | } |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 294 | if( lifetime > PSA_MAX_SE_LIFETIME ) |
| 295 | return( PSA_ERROR_NOT_SUPPORTED ); |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 296 | |
| 297 | for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ ) |
| 298 | { |
| 299 | if( driver_table[i].lifetime == 0 ) |
| 300 | break; |
| 301 | /* Check that lifetime isn't already in use up to the first free |
| 302 | * entry. Since entries are created in order and never deleted, |
| 303 | * there can't be a used entry after the first free entry. */ |
| 304 | if( driver_table[i].lifetime == lifetime ) |
| 305 | return( PSA_ERROR_ALREADY_EXISTS ); |
| 306 | } |
| 307 | if( i == PSA_MAX_SE_DRIVERS ) |
| 308 | return( PSA_ERROR_INSUFFICIENT_MEMORY ); |
| 309 | |
| 310 | driver_table[i].lifetime = lifetime; |
| 311 | driver_table[i].methods = methods; |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 312 | |
| 313 | if( methods->persistent_data_size != 0 ) |
| 314 | { |
| 315 | driver_table[i].internal.persistent_data = |
| 316 | mbedtls_calloc( 1, methods->persistent_data_size ); |
| 317 | if( driver_table[i].internal.persistent_data == NULL ) |
| 318 | { |
| 319 | status = PSA_ERROR_INSUFFICIENT_MEMORY; |
| 320 | goto error; |
| 321 | } |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 322 | /* Load the driver's persistent data. On first use, the persistent |
| 323 | * data does not exist in storage, and is initialized to |
| 324 | * all-bits-zero by the calloc call just above. */ |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 325 | status = psa_load_se_persistent_data( &driver_table[i] ); |
Gilles Peskine | 8b96cad | 2019-07-23 17:38:08 +0200 | [diff] [blame] | 326 | if( status != PSA_SUCCESS && status != PSA_ERROR_DOES_NOT_EXIST ) |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 327 | goto error; |
| 328 | } |
| 329 | driver_table[i].internal.persistent_data_size = |
| 330 | methods->persistent_data_size; |
| 331 | |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 332 | return( PSA_SUCCESS ); |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 333 | |
| 334 | error: |
| 335 | memset( &driver_table[i], 0, sizeof( driver_table[i] ) ); |
| 336 | return( status ); |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Gilles Peskine | d089021 | 2019-06-24 14:34:43 +0200 | [diff] [blame] | 339 | void psa_unregister_all_se_drivers( void ) |
| 340 | { |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 341 | size_t i; |
| 342 | for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ ) |
| 343 | { |
| 344 | if( driver_table[i].internal.persistent_data != NULL ) |
| 345 | mbedtls_free( driver_table[i].internal.persistent_data ); |
| 346 | } |
Gilles Peskine | d089021 | 2019-06-24 14:34:43 +0200 | [diff] [blame] | 347 | memset( driver_table, 0, sizeof( driver_table ) ); |
| 348 | } |
| 349 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 350 | |
| 351 | |
| 352 | /****************************************************************/ |
| 353 | /* The end */ |
| 354 | /****************************************************************/ |
| 355 | |
Gilles Peskine | a8ade16 | 2019-06-26 11:24:49 +0200 | [diff] [blame] | 356 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |