blob: 9db3dedce9dbad843c4393b0922670ae23656e06 [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 Peskine5243a202019-07-12 23:38:19 +020025#include <stdint.h>
Gilles Peskined0890212019-06-24 14:34:43 +020026#include <string.h>
27
Gilles Peskine5243a202019-07-12 23:38:19 +020028#include "psa/crypto_se_driver.h"
29
Gilles Peskinea899a722019-06-24 14:06:43 +020030#include "psa_crypto_se.h"
31
Gilles Peskine8b96cad2019-07-23 17:38:08 +020032#if defined(MBEDTLS_PSA_ITS_FILE_C)
33#include "psa_crypto_its.h"
34#else /* Native ITS implementation */
35#include "psa/error.h"
36#include "psa/internal_trusted_storage.h"
37#endif
38
Gilles Peskine5243a202019-07-12 23:38:19 +020039#include "mbedtls/platform.h"
Gilles Peskine5243a202019-07-12 23:38:19 +020040
41
42
Gilles Peskinef989dbe2019-06-26 18:18:12 +020043/****************************************************************/
44/* Driver lookup */
45/****************************************************************/
46
Gilles Peskine5243a202019-07-12 23:38:19 +020047/* This structure is identical to psa_drv_se_context_t declared in
48 * `crypto_se_driver.h`, except that some parts are writable here
49 * (non-const, or pointer to non-const). */
Gilles Peskine449bd832023-01-11 14:50:10 +010050typedef struct {
Gilles Peskine5243a202019-07-12 23:38:19 +020051 void *persistent_data;
52 size_t persistent_data_size;
53 uintptr_t transient_data;
54} psa_drv_se_internal_context_t;
55
Gilles Peskine449bd832023-01-11 14:50:10 +010056struct psa_se_drv_table_entry_s {
Gilles Peskine2b04f462020-05-10 00:44:04 +020057 psa_key_location_t location;
Gilles Peskinea899a722019-06-24 14:06:43 +020058 const psa_drv_se_t *methods;
Gilles Peskine449bd832023-01-11 14:50:10 +010059 union {
Gilles Peskine5243a202019-07-12 23:38:19 +020060 psa_drv_se_internal_context_t internal;
61 psa_drv_se_context_t context;
Gilles Peskine1a75d0c2020-04-14 19:33:25 +020062 } u;
Gilles Peskine01fd8752020-04-14 19:31:52 +020063};
Gilles Peskinea899a722019-06-24 14:06:43 +020064
Gilles Peskinef989dbe2019-06-26 18:18:12 +020065static psa_se_drv_table_entry_t driver_table[PSA_MAX_SE_DRIVERS];
66
Gilles Peskine5243a202019-07-12 23:38:19 +020067psa_se_drv_table_entry_t *psa_get_se_driver_entry(
Gilles Peskine449bd832023-01-11 14:50:10 +010068 psa_key_lifetime_t lifetime)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020069{
70 size_t i;
Gilles Peskine449bd832023-01-11 14:50:10 +010071 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
Gilles Peskine2b04f462020-05-10 00:44:04 +020072 /* In the driver table, location=0 means an entry that isn't used.
73 * No driver has a location of 0 because it's a reserved value
74 * (which designates transparent keys). Make sure we never return
75 * a driver entry for location 0. */
Gilles Peskine449bd832023-01-11 14:50:10 +010076 if (location == 0) {
77 return NULL;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020078 }
Gilles Peskine449bd832023-01-11 14:50:10 +010079 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
80 if (driver_table[i].location == location) {
81 return &driver_table[i];
82 }
83 }
84 return NULL;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020085}
86
87const psa_drv_se_t *psa_get_se_driver_methods(
Gilles Peskine449bd832023-01-11 14:50:10 +010088 const psa_se_drv_table_entry_t *driver)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020089{
Gilles Peskine449bd832023-01-11 14:50:10 +010090 return driver->methods;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020091}
92
Gilles Peskine5243a202019-07-12 23:38:19 +020093psa_drv_se_context_t *psa_get_se_driver_context(
Gilles Peskine449bd832023-01-11 14:50:10 +010094 psa_se_drv_table_entry_t *driver)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020095{
Gilles Peskine449bd832023-01-11 14:50:10 +010096 return &driver->u.context;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020097}
98
Gilles Peskine449bd832023-01-11 14:50:10 +010099int psa_get_se_driver(psa_key_lifetime_t lifetime,
100 const psa_drv_se_t **p_methods,
101 psa_drv_se_context_t **p_drv_context)
Gilles Peskine5243a202019-07-12 23:38:19 +0200102{
Gilles Peskine449bd832023-01-11 14:50:10 +0100103 psa_se_drv_table_entry_t *driver = psa_get_se_driver_entry(lifetime);
104 if (p_methods != NULL) {
105 *p_methods = (driver ? driver->methods : NULL);
106 }
107 if (p_drv_context != NULL) {
108 *p_drv_context = (driver ? &driver->u.context : NULL);
109 }
110 return driver != NULL;
Gilles Peskine5243a202019-07-12 23:38:19 +0200111}
112
113
114
115/****************************************************************/
116/* Persistent data management */
117/****************************************************************/
118
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200119static psa_status_t psa_get_se_driver_its_file_uid(
120 const psa_se_drv_table_entry_t *driver,
Gilles Peskine449bd832023-01-11 14:50:10 +0100121 psa_storage_uid_t *uid)
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200122{
Gilles Peskine449bd832023-01-11 14:50:10 +0100123 if (driver->location > PSA_MAX_SE_LOCATION) {
124 return PSA_ERROR_NOT_SUPPORTED;
125 }
Gilles Peskine573bbc12019-07-23 19:59:23 +0200126
Gilles Peskine573bbc12019-07-23 19:59:23 +0200127 /* ITS file sizes are limited to 32 bits. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100128 if (driver->u.internal.persistent_data_size > UINT32_MAX) {
129 return PSA_ERROR_NOT_SUPPORTED;
130 }
Gilles Peskine573bbc12019-07-23 19:59:23 +0200131
Gilles Peskine75c126b2019-07-24 15:56:01 +0200132 /* See the documentation of PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE. */
Gilles Peskine2b04f462020-05-10 00:44:04 +0200133 *uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->location;
Gilles Peskine449bd832023-01-11 14:50:10 +0100134 return PSA_SUCCESS;
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200135}
136
Gilles Peskine5243a202019-07-12 23:38:19 +0200137psa_status_t psa_load_se_persistent_data(
Gilles Peskine449bd832023-01-11 14:50:10 +0100138 const psa_se_drv_table_entry_t *driver)
Gilles Peskine5243a202019-07-12 23:38:19 +0200139{
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200140 psa_status_t status;
141 psa_storage_uid_t uid;
Gilles Peskine8b663892019-07-31 17:57:57 +0200142 size_t length;
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200143
Gilles Peskine449bd832023-01-11 14:50:10 +0100144 status = psa_get_se_driver_its_file_uid(driver, &uid);
145 if (status != PSA_SUCCESS) {
146 return status;
147 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200148
Gilles Peskine8b663892019-07-31 17:57:57 +0200149 /* Read the amount of persistent data that the driver requests.
150 * If the data in storage is larger, it is truncated. If the data
151 * in storage is smaller, silently keep what is already at the end
152 * of the output buffer. */
Gilles Peskine75c126b2019-07-24 15:56:01 +0200153 /* psa_get_se_driver_its_file_uid ensures that the size_t
154 * persistent_data_size is in range, but compilers don't know that,
155 * so cast to reassure them. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100156 return psa_its_get(uid, 0,
157 (uint32_t) driver->u.internal.persistent_data_size,
158 driver->u.internal.persistent_data,
159 &length);
Gilles Peskine5243a202019-07-12 23:38:19 +0200160}
161
162psa_status_t psa_save_se_persistent_data(
Gilles Peskine449bd832023-01-11 14:50:10 +0100163 const psa_se_drv_table_entry_t *driver)
Gilles Peskine5243a202019-07-12 23:38:19 +0200164{
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200165 psa_status_t status;
166 psa_storage_uid_t uid;
167
Gilles Peskine449bd832023-01-11 14:50:10 +0100168 status = psa_get_se_driver_its_file_uid(driver, &uid);
169 if (status != PSA_SUCCESS) {
170 return status;
171 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200172
Gilles Peskine75c126b2019-07-24 15:56:01 +0200173 /* psa_get_se_driver_its_file_uid ensures that the size_t
174 * persistent_data_size is in range, but compilers don't know that,
175 * so cast to reassure them. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100176 return psa_its_set(uid,
177 (uint32_t) driver->u.internal.persistent_data_size,
178 driver->u.internal.persistent_data,
179 0);
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200180}
181
Gilles Peskine449bd832023-01-11 14:50:10 +0100182psa_status_t psa_destroy_se_persistent_data(psa_key_location_t location)
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200183{
184 psa_storage_uid_t uid;
Gilles Peskine449bd832023-01-11 14:50:10 +0100185 if (location > PSA_MAX_SE_LOCATION) {
186 return PSA_ERROR_NOT_SUPPORTED;
187 }
Gilles Peskine2b04f462020-05-10 00:44:04 +0200188 uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + location;
Gilles Peskine449bd832023-01-11 14:50:10 +0100189 return psa_its_remove(uid);
Gilles Peskine5243a202019-07-12 23:38:19 +0200190}
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200191
Gilles Peskinecbaff462019-07-12 23:46:04 +0200192psa_status_t psa_find_se_slot_for_key(
193 const psa_key_attributes_t *attributes,
Gilles Peskinee88c2c12019-08-05 16:44:14 +0200194 psa_key_creation_method_t method,
Gilles Peskinecbaff462019-07-12 23:46:04 +0200195 psa_se_drv_table_entry_t *driver,
Gilles Peskine449bd832023-01-11 14:50:10 +0100196 psa_key_slot_number_t *slot_number)
Gilles Peskinecbaff462019-07-12 23:46:04 +0200197{
198 psa_status_t status;
Gilles Peskine2b04f462020-05-10 00:44:04 +0200199 psa_key_location_t key_location =
Gilles Peskine449bd832023-01-11 14:50:10 +0100200 PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
Gilles Peskinecbaff462019-07-12 23:46:04 +0200201
Gilles Peskine2b04f462020-05-10 00:44:04 +0200202 /* If the location is wrong, it's a bug in the library. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100203 if (driver->location != key_location) {
204 return PSA_ERROR_CORRUPTION_DETECTED;
205 }
Gilles Peskinecbaff462019-07-12 23:46:04 +0200206
207 /* If the driver doesn't support key creation in any way, give up now. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100208 if (driver->methods->key_management == NULL) {
209 return PSA_ERROR_NOT_SUPPORTED;
210 }
Gilles Peskinecbaff462019-07-12 23:46:04 +0200211
Gilles Peskine449bd832023-01-11 14:50:10 +0100212 if (psa_get_key_slot_number(attributes, slot_number) == PSA_SUCCESS) {
Gilles Peskine46d94392019-08-05 14:55:50 +0200213 /* The application wants to use a specific slot. Allow it if
214 * the driver supports it. On a system with isolation,
215 * the crypto service must check that the application is
216 * permitted to request this slot. */
217 psa_drv_se_validate_slot_number_t p_validate_slot_number =
218 driver->methods->key_management->p_validate_slot_number;
Gilles Peskine449bd832023-01-11 14:50:10 +0100219 if (p_validate_slot_number == NULL) {
220 return PSA_ERROR_NOT_SUPPORTED;
221 }
222 status = p_validate_slot_number(&driver->u.context,
223 driver->u.internal.persistent_data,
224 attributes, method,
225 *slot_number);
226 } else if (method == PSA_KEY_CREATION_REGISTER) {
Gilles Peskine3efcebb2019-10-01 14:18:35 +0200227 /* The application didn't specify a slot number. This doesn't
228 * make sense when registering a slot. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100229 return PSA_ERROR_INVALID_ARGUMENT;
230 } else {
Gilles Peskine46d94392019-08-05 14:55:50 +0200231 /* The application didn't tell us which slot to use. Let the driver
232 * choose. This is the normal case. */
233 psa_drv_se_allocate_key_t p_allocate =
234 driver->methods->key_management->p_allocate;
Gilles Peskine449bd832023-01-11 14:50:10 +0100235 if (p_allocate == NULL) {
236 return PSA_ERROR_NOT_SUPPORTED;
237 }
238 status = p_allocate(&driver->u.context,
239 driver->u.internal.persistent_data,
240 attributes, method,
241 slot_number);
Gilles Peskine46d94392019-08-05 14:55:50 +0200242 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100243 return status;
Gilles Peskinecbaff462019-07-12 23:46:04 +0200244}
245
Gilles Peskine449bd832023-01-11 14:50:10 +0100246psa_status_t psa_destroy_se_key(psa_se_drv_table_entry_t *driver,
247 psa_key_slot_number_t slot_number)
Gilles Peskine354f7672019-07-12 23:46:38 +0200248{
249 psa_status_t status;
250 psa_status_t storage_status;
Gilles Peskine340b1272019-07-25 14:13:24 +0200251 /* Normally a missing method would mean that the action is not
252 * supported. But psa_destroy_key() is not supposed to return
253 * PSA_ERROR_NOT_SUPPORTED: if you can create a key, you should
254 * be able to destroy it. The only use case for a driver that
255 * does not have a way to destroy keys at all is if the keys are
256 * locked in a read-only state: we can use the keys but not
257 * destroy them. Hence, if the driver doesn't support destroying
258 * keys, it's really a lack of permission. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100259 if (driver->methods->key_management == NULL ||
260 driver->methods->key_management->p_destroy == NULL) {
261 return PSA_ERROR_NOT_PERMITTED;
262 }
Gilles Peskine354f7672019-07-12 23:46:38 +0200263 status = driver->methods->key_management->p_destroy(
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200264 &driver->u.context,
265 driver->u.internal.persistent_data,
Gilles Peskine449bd832023-01-11 14:50:10 +0100266 slot_number);
267 storage_status = psa_save_se_persistent_data(driver);
268 return status == PSA_SUCCESS ? storage_status : status;
Gilles Peskine354f7672019-07-12 23:46:38 +0200269}
270
Gilles Peskine449bd832023-01-11 14:50:10 +0100271psa_status_t psa_init_all_se_drivers(void)
Gilles Peskined9348f22019-10-01 15:22:29 +0200272{
273 size_t i;
Gilles Peskine449bd832023-01-11 14:50:10 +0100274 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200275 psa_se_drv_table_entry_t *driver = &driver_table[i];
Gilles Peskine449bd832023-01-11 14:50:10 +0100276 if (driver->location == 0) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200277 continue; /* skipping unused entry */
Gilles Peskine449bd832023-01-11 14:50:10 +0100278 }
279 const psa_drv_se_t *methods = psa_get_se_driver_methods(driver);
280 if (methods->p_init != NULL) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200281 psa_status_t status = methods->p_init(
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200282 &driver->u.context,
283 driver->u.internal.persistent_data,
Gilles Peskine449bd832023-01-11 14:50:10 +0100284 driver->location);
285 if (status != PSA_SUCCESS) {
286 return status;
287 }
288 status = psa_save_se_persistent_data(driver);
289 if (status != PSA_SUCCESS) {
290 return status;
291 }
Gilles Peskined9348f22019-10-01 15:22:29 +0200292 }
293 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100294 return PSA_SUCCESS;
Gilles Peskined9348f22019-10-01 15:22:29 +0200295}
296
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200297
298
299/****************************************************************/
300/* Driver registration */
301/****************************************************************/
Gilles Peskinea899a722019-06-24 14:06:43 +0200302
303psa_status_t psa_register_se_driver(
Gilles Peskine2b04f462020-05-10 00:44:04 +0200304 psa_key_location_t location,
Gilles Peskinea899a722019-06-24 14:06:43 +0200305 const psa_drv_se_t *methods)
306{
307 size_t i;
Gilles Peskine5243a202019-07-12 23:38:19 +0200308 psa_status_t status;
Gilles Peskinea899a722019-06-24 14:06:43 +0200309
Gilles Peskine449bd832023-01-11 14:50:10 +0100310 if (methods->hal_version != PSA_DRV_SE_HAL_VERSION) {
311 return PSA_ERROR_NOT_SUPPORTED;
312 }
Gilles Peskine9717d102019-06-26 11:50:04 +0200313 /* Driver table entries are 0-initialized. 0 is not a valid driver
Gilles Peskine2b04f462020-05-10 00:44:04 +0200314 * location because it means a transparent key. */
Tom Cosgrove6ef9bb32023-03-08 14:19:51 +0000315 MBEDTLS_STATIC_ASSERT(PSA_KEY_LOCATION_LOCAL_STORAGE == 0,
316 "Secure element support requires 0 to mean a local key");
317
Gilles Peskine449bd832023-01-11 14:50:10 +0100318 if (location == PSA_KEY_LOCATION_LOCAL_STORAGE) {
319 return PSA_ERROR_INVALID_ARGUMENT;
320 }
321 if (location > PSA_MAX_SE_LOCATION) {
322 return PSA_ERROR_NOT_SUPPORTED;
323 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200324
Gilles Peskine449bd832023-01-11 14:50:10 +0100325 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
326 if (driver_table[i].location == 0) {
Gilles Peskinea899a722019-06-24 14:06:43 +0200327 break;
Gilles Peskine449bd832023-01-11 14:50:10 +0100328 }
Gilles Peskine2b04f462020-05-10 00:44:04 +0200329 /* Check that location isn't already in use up to the first free
Gilles Peskinea899a722019-06-24 14:06:43 +0200330 * entry. Since entries are created in order and never deleted,
331 * there can't be a used entry after the first free entry. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100332 if (driver_table[i].location == location) {
333 return PSA_ERROR_ALREADY_EXISTS;
334 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200335 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100336 if (i == PSA_MAX_SE_DRIVERS) {
337 return PSA_ERROR_INSUFFICIENT_MEMORY;
338 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200339
Gilles Peskine2b04f462020-05-10 00:44:04 +0200340 driver_table[i].location = location;
Gilles Peskinea899a722019-06-24 14:06:43 +0200341 driver_table[i].methods = methods;
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200342 driver_table[i].u.internal.persistent_data_size =
Gilles Peskined5536d82019-10-01 16:55:29 +0200343 methods->persistent_data_size;
Gilles Peskine5243a202019-07-12 23:38:19 +0200344
Gilles Peskine449bd832023-01-11 14:50:10 +0100345 if (methods->persistent_data_size != 0) {
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200346 driver_table[i].u.internal.persistent_data =
Gilles Peskine449bd832023-01-11 14:50:10 +0100347 mbedtls_calloc(1, methods->persistent_data_size);
348 if (driver_table[i].u.internal.persistent_data == NULL) {
Gilles Peskine5243a202019-07-12 23:38:19 +0200349 status = PSA_ERROR_INSUFFICIENT_MEMORY;
350 goto error;
351 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200352 /* Load the driver's persistent data. On first use, the persistent
353 * data does not exist in storage, and is initialized to
354 * all-bits-zero by the calloc call just above. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100355 status = psa_load_se_persistent_data(&driver_table[i]);
356 if (status != PSA_SUCCESS && status != PSA_ERROR_DOES_NOT_EXIST) {
Gilles Peskine5243a202019-07-12 23:38:19 +0200357 goto error;
Gilles Peskine449bd832023-01-11 14:50:10 +0100358 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200359 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200360
Gilles Peskine449bd832023-01-11 14:50:10 +0100361 return PSA_SUCCESS;
Gilles Peskine5243a202019-07-12 23:38:19 +0200362
363error:
Gilles Peskine449bd832023-01-11 14:50:10 +0100364 memset(&driver_table[i], 0, sizeof(driver_table[i]));
365 return status;
Gilles Peskinea899a722019-06-24 14:06:43 +0200366}
367
Gilles Peskine449bd832023-01-11 14:50:10 +0100368void psa_unregister_all_se_drivers(void)
Gilles Peskined0890212019-06-24 14:34:43 +0200369{
Gilles Peskine5243a202019-07-12 23:38:19 +0200370 size_t i;
Gilles Peskine449bd832023-01-11 14:50:10 +0100371 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
372 if (driver_table[i].u.internal.persistent_data != NULL) {
373 mbedtls_free(driver_table[i].u.internal.persistent_data);
374 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200375 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100376 memset(driver_table, 0, sizeof(driver_table));
Gilles Peskined0890212019-06-24 14:34:43 +0200377}
378
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200379
380
381/****************************************************************/
382/* The end */
383/****************************************************************/
384
Gilles Peskinea8ade162019-06-26 11:24:49 +0200385#endif /* MBEDTLS_PSA_CRYPTO_SE_C */