blob: dee780f46e6e822bbafb8782e621943dc4eebf22 [file] [log] [blame]
Gilles Peskinea899a722019-06-24 14:06:43 +02001/*
2 * PSA crypto support for secure element drivers
3 */
Bence Szépkúti86974652020-06-15 11:59:37 +02004/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02005 * Copyright The Mbed TLS Contributors
Gilles Peskinea899a722019-06-24 14:06:43 +02006 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
Gilles Peskinea899a722019-06-24 14:06:43 +020019 */
20
Gilles Peskinedb09ef62020-06-03 01:43:33 +020021#include "common.h"
Gilles Peskinea899a722019-06-24 14:06:43 +020022
Gilles Peskinea8ade162019-06-26 11:24:49 +020023#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
Gilles Peskinea899a722019-06-24 14:06:43 +020024
Gilles Peskine9717d102019-06-26 11:50:04 +020025#include <assert.h>
Gilles Peskine5243a202019-07-12 23:38:19 +020026#include <stdint.h>
Gilles Peskined0890212019-06-24 14:34:43 +020027#include <string.h>
28
Gilles Peskine5243a202019-07-12 23:38:19 +020029#include "psa/crypto_se_driver.h"
30
Gilles Peskinea899a722019-06-24 14:06:43 +020031#include "psa_crypto_se.h"
32
Gilles Peskine8b96cad2019-07-23 17:38:08 +020033#if defined(MBEDTLS_PSA_ITS_FILE_C)
34#include "psa_crypto_its.h"
35#else /* Native ITS implementation */
36#include "psa/error.h"
37#include "psa/internal_trusted_storage.h"
38#endif
39
Gilles Peskine5243a202019-07-12 23:38:19 +020040#include "mbedtls/platform.h"
Gilles Peskine5243a202019-07-12 23:38:19 +020041
42
43
Gilles Peskinef989dbe2019-06-26 18:18:12 +020044/****************************************************************/
45/* Driver lookup */
46/****************************************************************/
47
Gilles Peskine5243a202019-07-12 23:38:19 +020048/* This structure is identical to psa_drv_se_context_t declared in
49 * `crypto_se_driver.h`, except that some parts are writable here
50 * (non-const, or pointer to non-const). */
Gilles Peskine449bd832023-01-11 14:50:10 +010051typedef struct {
Gilles Peskine5243a202019-07-12 23:38:19 +020052 void *persistent_data;
53 size_t persistent_data_size;
54 uintptr_t transient_data;
55} psa_drv_se_internal_context_t;
56
Gilles Peskine449bd832023-01-11 14:50:10 +010057struct psa_se_drv_table_entry_s {
Gilles Peskine2b04f462020-05-10 00:44:04 +020058 psa_key_location_t location;
Gilles Peskinea899a722019-06-24 14:06:43 +020059 const psa_drv_se_t *methods;
Gilles Peskine449bd832023-01-11 14:50:10 +010060 union {
Gilles Peskine5243a202019-07-12 23:38:19 +020061 psa_drv_se_internal_context_t internal;
62 psa_drv_se_context_t context;
Gilles Peskine1a75d0c2020-04-14 19:33:25 +020063 } u;
Gilles Peskine01fd8752020-04-14 19:31:52 +020064};
Gilles Peskinea899a722019-06-24 14:06:43 +020065
Gilles Peskinef989dbe2019-06-26 18:18:12 +020066static psa_se_drv_table_entry_t driver_table[PSA_MAX_SE_DRIVERS];
67
Gilles Peskine5243a202019-07-12 23:38:19 +020068psa_se_drv_table_entry_t *psa_get_se_driver_entry(
Gilles Peskine449bd832023-01-11 14:50:10 +010069 psa_key_lifetime_t lifetime)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020070{
71 size_t i;
Gilles Peskine449bd832023-01-11 14:50:10 +010072 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
Gilles Peskine2b04f462020-05-10 00:44:04 +020073 /* In the driver table, location=0 means an entry that isn't used.
74 * No driver has a location of 0 because it's a reserved value
75 * (which designates transparent keys). Make sure we never return
76 * a driver entry for location 0. */
Gilles Peskine449bd832023-01-11 14:50:10 +010077 if (location == 0) {
78 return NULL;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020079 }
Gilles Peskine449bd832023-01-11 14:50:10 +010080 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
81 if (driver_table[i].location == location) {
82 return &driver_table[i];
83 }
84 }
85 return NULL;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020086}
87
88const psa_drv_se_t *psa_get_se_driver_methods(
Gilles Peskine449bd832023-01-11 14:50:10 +010089 const psa_se_drv_table_entry_t *driver)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020090{
Gilles Peskine449bd832023-01-11 14:50:10 +010091 return driver->methods;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020092}
93
Gilles Peskine5243a202019-07-12 23:38:19 +020094psa_drv_se_context_t *psa_get_se_driver_context(
Gilles Peskine449bd832023-01-11 14:50:10 +010095 psa_se_drv_table_entry_t *driver)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020096{
Gilles Peskine449bd832023-01-11 14:50:10 +010097 return &driver->u.context;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020098}
99
Gilles Peskine449bd832023-01-11 14:50:10 +0100100int psa_get_se_driver(psa_key_lifetime_t lifetime,
101 const psa_drv_se_t **p_methods,
102 psa_drv_se_context_t **p_drv_context)
Gilles Peskine5243a202019-07-12 23:38:19 +0200103{
Gilles Peskine449bd832023-01-11 14:50:10 +0100104 psa_se_drv_table_entry_t *driver = psa_get_se_driver_entry(lifetime);
105 if (p_methods != NULL) {
106 *p_methods = (driver ? driver->methods : NULL);
107 }
108 if (p_drv_context != NULL) {
109 *p_drv_context = (driver ? &driver->u.context : NULL);
110 }
111 return driver != NULL;
Gilles Peskine5243a202019-07-12 23:38:19 +0200112}
113
114
115
116/****************************************************************/
117/* Persistent data management */
118/****************************************************************/
119
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200120static psa_status_t psa_get_se_driver_its_file_uid(
121 const psa_se_drv_table_entry_t *driver,
Gilles Peskine449bd832023-01-11 14:50:10 +0100122 psa_storage_uid_t *uid)
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200123{
Gilles Peskine449bd832023-01-11 14:50:10 +0100124 if (driver->location > PSA_MAX_SE_LOCATION) {
125 return PSA_ERROR_NOT_SUPPORTED;
126 }
Gilles Peskine573bbc12019-07-23 19:59:23 +0200127
Gilles Peskine573bbc12019-07-23 19:59:23 +0200128 /* ITS file sizes are limited to 32 bits. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100129 if (driver->u.internal.persistent_data_size > UINT32_MAX) {
130 return PSA_ERROR_NOT_SUPPORTED;
131 }
Gilles Peskine573bbc12019-07-23 19:59:23 +0200132
Gilles Peskine75c126b2019-07-24 15:56:01 +0200133 /* See the documentation of PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE. */
Gilles Peskine2b04f462020-05-10 00:44:04 +0200134 *uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->location;
Gilles Peskine449bd832023-01-11 14:50:10 +0100135 return PSA_SUCCESS;
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200136}
137
Gilles Peskine5243a202019-07-12 23:38:19 +0200138psa_status_t psa_load_se_persistent_data(
Gilles Peskine449bd832023-01-11 14:50:10 +0100139 const psa_se_drv_table_entry_t *driver)
Gilles Peskine5243a202019-07-12 23:38:19 +0200140{
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200141 psa_status_t status;
142 psa_storage_uid_t uid;
Gilles Peskine8b663892019-07-31 17:57:57 +0200143 size_t length;
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200144
Gilles Peskine449bd832023-01-11 14:50:10 +0100145 status = psa_get_se_driver_its_file_uid(driver, &uid);
146 if (status != PSA_SUCCESS) {
147 return status;
148 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200149
Gilles Peskine8b663892019-07-31 17:57:57 +0200150 /* Read the amount of persistent data that the driver requests.
151 * If the data in storage is larger, it is truncated. If the data
152 * in storage is smaller, silently keep what is already at the end
153 * of the output buffer. */
Gilles Peskine75c126b2019-07-24 15:56:01 +0200154 /* psa_get_se_driver_its_file_uid ensures that the size_t
155 * persistent_data_size is in range, but compilers don't know that,
156 * so cast to reassure them. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100157 return psa_its_get(uid, 0,
158 (uint32_t) driver->u.internal.persistent_data_size,
159 driver->u.internal.persistent_data,
160 &length);
Gilles Peskine5243a202019-07-12 23:38:19 +0200161}
162
163psa_status_t psa_save_se_persistent_data(
Gilles Peskine449bd832023-01-11 14:50:10 +0100164 const psa_se_drv_table_entry_t *driver)
Gilles Peskine5243a202019-07-12 23:38:19 +0200165{
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200166 psa_status_t status;
167 psa_storage_uid_t uid;
168
Gilles Peskine449bd832023-01-11 14:50:10 +0100169 status = psa_get_se_driver_its_file_uid(driver, &uid);
170 if (status != PSA_SUCCESS) {
171 return status;
172 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200173
Gilles Peskine75c126b2019-07-24 15:56:01 +0200174 /* psa_get_se_driver_its_file_uid ensures that the size_t
175 * persistent_data_size is in range, but compilers don't know that,
176 * so cast to reassure them. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100177 return psa_its_set(uid,
178 (uint32_t) driver->u.internal.persistent_data_size,
179 driver->u.internal.persistent_data,
180 0);
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200181}
182
Gilles Peskine449bd832023-01-11 14:50:10 +0100183psa_status_t psa_destroy_se_persistent_data(psa_key_location_t location)
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200184{
185 psa_storage_uid_t uid;
Gilles Peskine449bd832023-01-11 14:50:10 +0100186 if (location > PSA_MAX_SE_LOCATION) {
187 return PSA_ERROR_NOT_SUPPORTED;
188 }
Gilles Peskine2b04f462020-05-10 00:44:04 +0200189 uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + location;
Gilles Peskine449bd832023-01-11 14:50:10 +0100190 return psa_its_remove(uid);
Gilles Peskine5243a202019-07-12 23:38:19 +0200191}
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200192
Gilles Peskinecbaff462019-07-12 23:46:04 +0200193psa_status_t psa_find_se_slot_for_key(
194 const psa_key_attributes_t *attributes,
Gilles Peskinee88c2c12019-08-05 16:44:14 +0200195 psa_key_creation_method_t method,
Gilles Peskinecbaff462019-07-12 23:46:04 +0200196 psa_se_drv_table_entry_t *driver,
Gilles Peskine449bd832023-01-11 14:50:10 +0100197 psa_key_slot_number_t *slot_number)
Gilles Peskinecbaff462019-07-12 23:46:04 +0200198{
199 psa_status_t status;
Gilles Peskine2b04f462020-05-10 00:44:04 +0200200 psa_key_location_t key_location =
Gilles Peskine449bd832023-01-11 14:50:10 +0100201 PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
Gilles Peskinecbaff462019-07-12 23:46:04 +0200202
Gilles Peskine2b04f462020-05-10 00:44:04 +0200203 /* If the location is wrong, it's a bug in the library. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100204 if (driver->location != key_location) {
205 return PSA_ERROR_CORRUPTION_DETECTED;
206 }
Gilles Peskinecbaff462019-07-12 23:46:04 +0200207
208 /* If the driver doesn't support key creation in any way, give up now. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100209 if (driver->methods->key_management == NULL) {
210 return PSA_ERROR_NOT_SUPPORTED;
211 }
Gilles Peskinecbaff462019-07-12 23:46:04 +0200212
Gilles Peskine449bd832023-01-11 14:50:10 +0100213 if (psa_get_key_slot_number(attributes, slot_number) == PSA_SUCCESS) {
Gilles Peskine46d94392019-08-05 14:55:50 +0200214 /* The application wants to use a specific slot. Allow it if
215 * the driver supports it. On a system with isolation,
216 * the crypto service must check that the application is
217 * permitted to request this slot. */
218 psa_drv_se_validate_slot_number_t p_validate_slot_number =
219 driver->methods->key_management->p_validate_slot_number;
Gilles Peskine449bd832023-01-11 14:50:10 +0100220 if (p_validate_slot_number == NULL) {
221 return PSA_ERROR_NOT_SUPPORTED;
222 }
223 status = p_validate_slot_number(&driver->u.context,
224 driver->u.internal.persistent_data,
225 attributes, method,
226 *slot_number);
227 } else if (method == PSA_KEY_CREATION_REGISTER) {
Gilles Peskine3efcebb2019-10-01 14:18:35 +0200228 /* The application didn't specify a slot number. This doesn't
229 * make sense when registering a slot. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100230 return PSA_ERROR_INVALID_ARGUMENT;
231 } else {
Gilles Peskine46d94392019-08-05 14:55:50 +0200232 /* The application didn't tell us which slot to use. Let the driver
233 * choose. This is the normal case. */
234 psa_drv_se_allocate_key_t p_allocate =
235 driver->methods->key_management->p_allocate;
Gilles Peskine449bd832023-01-11 14:50:10 +0100236 if (p_allocate == NULL) {
237 return PSA_ERROR_NOT_SUPPORTED;
238 }
239 status = p_allocate(&driver->u.context,
240 driver->u.internal.persistent_data,
241 attributes, method,
242 slot_number);
Gilles Peskine46d94392019-08-05 14:55:50 +0200243 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100244 return status;
Gilles Peskinecbaff462019-07-12 23:46:04 +0200245}
246
Gilles Peskine449bd832023-01-11 14:50:10 +0100247psa_status_t psa_destroy_se_key(psa_se_drv_table_entry_t *driver,
248 psa_key_slot_number_t slot_number)
Gilles Peskine354f7672019-07-12 23:46:38 +0200249{
250 psa_status_t status;
251 psa_status_t storage_status;
Gilles Peskine340b1272019-07-25 14:13:24 +0200252 /* Normally a missing method would mean that the action is not
253 * supported. But psa_destroy_key() is not supposed to return
254 * PSA_ERROR_NOT_SUPPORTED: if you can create a key, you should
255 * be able to destroy it. The only use case for a driver that
256 * does not have a way to destroy keys at all is if the keys are
257 * locked in a read-only state: we can use the keys but not
258 * destroy them. Hence, if the driver doesn't support destroying
259 * keys, it's really a lack of permission. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100260 if (driver->methods->key_management == NULL ||
261 driver->methods->key_management->p_destroy == NULL) {
262 return PSA_ERROR_NOT_PERMITTED;
263 }
Gilles Peskine354f7672019-07-12 23:46:38 +0200264 status = driver->methods->key_management->p_destroy(
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200265 &driver->u.context,
266 driver->u.internal.persistent_data,
Gilles Peskine449bd832023-01-11 14:50:10 +0100267 slot_number);
268 storage_status = psa_save_se_persistent_data(driver);
269 return status == PSA_SUCCESS ? storage_status : status;
Gilles Peskine354f7672019-07-12 23:46:38 +0200270}
271
Gilles Peskine449bd832023-01-11 14:50:10 +0100272psa_status_t psa_init_all_se_drivers(void)
Gilles Peskined9348f22019-10-01 15:22:29 +0200273{
274 size_t i;
Gilles Peskine449bd832023-01-11 14:50:10 +0100275 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200276 psa_se_drv_table_entry_t *driver = &driver_table[i];
Gilles Peskine449bd832023-01-11 14:50:10 +0100277 if (driver->location == 0) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200278 continue; /* skipping unused entry */
Gilles Peskine449bd832023-01-11 14:50:10 +0100279 }
280 const psa_drv_se_t *methods = psa_get_se_driver_methods(driver);
281 if (methods->p_init != NULL) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200282 psa_status_t status = methods->p_init(
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200283 &driver->u.context,
284 driver->u.internal.persistent_data,
Gilles Peskine449bd832023-01-11 14:50:10 +0100285 driver->location);
286 if (status != PSA_SUCCESS) {
287 return status;
288 }
289 status = psa_save_se_persistent_data(driver);
290 if (status != PSA_SUCCESS) {
291 return status;
292 }
Gilles Peskined9348f22019-10-01 15:22:29 +0200293 }
294 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100295 return PSA_SUCCESS;
Gilles Peskined9348f22019-10-01 15:22:29 +0200296}
297
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200298
299
300/****************************************************************/
301/* Driver registration */
302/****************************************************************/
Gilles Peskinea899a722019-06-24 14:06:43 +0200303
304psa_status_t psa_register_se_driver(
Gilles Peskine2b04f462020-05-10 00:44:04 +0200305 psa_key_location_t location,
Gilles Peskinea899a722019-06-24 14:06:43 +0200306 const psa_drv_se_t *methods)
307{
308 size_t i;
Gilles Peskine5243a202019-07-12 23:38:19 +0200309 psa_status_t status;
Gilles Peskinea899a722019-06-24 14:06:43 +0200310
Gilles Peskine449bd832023-01-11 14:50:10 +0100311 if (methods->hal_version != PSA_DRV_SE_HAL_VERSION) {
312 return PSA_ERROR_NOT_SUPPORTED;
313 }
Gilles Peskine9717d102019-06-26 11:50:04 +0200314 /* Driver table entries are 0-initialized. 0 is not a valid driver
Gilles Peskine2b04f462020-05-10 00:44:04 +0200315 * location because it means a transparent key. */
Gilles Peskine9717d102019-06-26 11:50:04 +0200316#if defined(static_assert)
Gilles Peskine449bd832023-01-11 14:50:10 +0100317 static_assert(PSA_KEY_LOCATION_LOCAL_STORAGE == 0,
318 "Secure element support requires 0 to mean a local key");
Gilles Peskine9717d102019-06-26 11:50:04 +0200319#endif
Gilles Peskine449bd832023-01-11 14:50:10 +0100320 if (location == PSA_KEY_LOCATION_LOCAL_STORAGE) {
321 return PSA_ERROR_INVALID_ARGUMENT;
322 }
323 if (location > PSA_MAX_SE_LOCATION) {
324 return PSA_ERROR_NOT_SUPPORTED;
325 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200326
Gilles Peskine449bd832023-01-11 14:50:10 +0100327 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
328 if (driver_table[i].location == 0) {
Gilles Peskinea899a722019-06-24 14:06:43 +0200329 break;
Gilles Peskine449bd832023-01-11 14:50:10 +0100330 }
Gilles Peskine2b04f462020-05-10 00:44:04 +0200331 /* Check that location isn't already in use up to the first free
Gilles Peskinea899a722019-06-24 14:06:43 +0200332 * entry. Since entries are created in order and never deleted,
333 * there can't be a used entry after the first free entry. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100334 if (driver_table[i].location == location) {
335 return PSA_ERROR_ALREADY_EXISTS;
336 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200337 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100338 if (i == PSA_MAX_SE_DRIVERS) {
339 return PSA_ERROR_INSUFFICIENT_MEMORY;
340 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200341
Gilles Peskine2b04f462020-05-10 00:44:04 +0200342 driver_table[i].location = location;
Gilles Peskinea899a722019-06-24 14:06:43 +0200343 driver_table[i].methods = methods;
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200344 driver_table[i].u.internal.persistent_data_size =
Gilles Peskined5536d82019-10-01 16:55:29 +0200345 methods->persistent_data_size;
Gilles Peskine5243a202019-07-12 23:38:19 +0200346
Gilles Peskine449bd832023-01-11 14:50:10 +0100347 if (methods->persistent_data_size != 0) {
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200348 driver_table[i].u.internal.persistent_data =
Gilles Peskine449bd832023-01-11 14:50:10 +0100349 mbedtls_calloc(1, methods->persistent_data_size);
350 if (driver_table[i].u.internal.persistent_data == NULL) {
Gilles Peskine5243a202019-07-12 23:38:19 +0200351 status = PSA_ERROR_INSUFFICIENT_MEMORY;
352 goto error;
353 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200354 /* Load the driver's persistent data. On first use, the persistent
355 * data does not exist in storage, and is initialized to
356 * all-bits-zero by the calloc call just above. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100357 status = psa_load_se_persistent_data(&driver_table[i]);
358 if (status != PSA_SUCCESS && status != PSA_ERROR_DOES_NOT_EXIST) {
Gilles Peskine5243a202019-07-12 23:38:19 +0200359 goto error;
Gilles Peskine449bd832023-01-11 14:50:10 +0100360 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200361 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200362
Gilles Peskine449bd832023-01-11 14:50:10 +0100363 return PSA_SUCCESS;
Gilles Peskine5243a202019-07-12 23:38:19 +0200364
365error:
Gilles Peskine449bd832023-01-11 14:50:10 +0100366 memset(&driver_table[i], 0, sizeof(driver_table[i]));
367 return status;
Gilles Peskinea899a722019-06-24 14:06:43 +0200368}
369
Gilles Peskine449bd832023-01-11 14:50:10 +0100370void psa_unregister_all_se_drivers(void)
Gilles Peskined0890212019-06-24 14:34:43 +0200371{
Gilles Peskine5243a202019-07-12 23:38:19 +0200372 size_t i;
Gilles Peskine449bd832023-01-11 14:50:10 +0100373 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
374 if (driver_table[i].u.internal.persistent_data != NULL) {
375 mbedtls_free(driver_table[i].u.internal.persistent_data);
376 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200377 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100378 memset(driver_table, 0, sizeof(driver_table));
Gilles Peskined0890212019-06-24 14:34:43 +0200379}
380
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200381
382
383/****************************************************************/
384/* The end */
385/****************************************************************/
386
Gilles Peskinea8ade162019-06-26 11:24:49 +0200387#endif /* MBEDTLS_PSA_CRYPTO_SE_C */