blob: 7bea10ad64acaf64dd03d5c61dec1a4d2bc8da87 [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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +010068 psa_key_lifetime_t lifetime)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020069{
70 size_t i;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +010076 if (location == 0) {
77 return NULL;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020078 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +010088 const psa_se_drv_table_entry_t *driver)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020089{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +010094 psa_se_drv_table_entry_t *driver)
Gilles Peskinef989dbe2019-06-26 18:18:12 +020095{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010096 return &driver->u.context;
Gilles Peskinef989dbe2019-06-26 18:18:12 +020097}
98
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +0100121 psa_storage_uid_t *uid)
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200122{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100123 if (driver->location > PSA_MAX_SE_LOCATION) {
124 return PSA_ERROR_NOT_SUPPORTED;
125 }
Gilles Peskine573bbc12019-07-23 19:59:23 +0200126
127#if SIZE_MAX > UINT32_MAX
128 /* ITS file sizes are limited to 32 bits. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +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#endif
133
Gilles Peskine75c126b2019-07-24 15:56:01 +0200134 /* See the documentation of PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE. */
Gilles Peskine2b04f462020-05-10 00:44:04 +0200135 *uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->location;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100136 return PSA_SUCCESS;
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200137}
138
Gilles Peskine5243a202019-07-12 23:38:19 +0200139psa_status_t psa_load_se_persistent_data(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100140 const psa_se_drv_table_entry_t *driver)
Gilles Peskine5243a202019-07-12 23:38:19 +0200141{
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200142 psa_status_t status;
143 psa_storage_uid_t uid;
Gilles Peskine8b663892019-07-31 17:57:57 +0200144 size_t length;
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200145
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100146 status = psa_get_se_driver_its_file_uid(driver, &uid);
147 if (status != PSA_SUCCESS) {
148 return status;
149 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200150
Gilles Peskine8b663892019-07-31 17:57:57 +0200151 /* Read the amount of persistent data that the driver requests.
152 * If the data in storage is larger, it is truncated. If the data
153 * in storage is smaller, silently keep what is already at the end
154 * of the output buffer. */
Gilles Peskine75c126b2019-07-24 15:56:01 +0200155 /* psa_get_se_driver_its_file_uid ensures that the size_t
156 * persistent_data_size is in range, but compilers don't know that,
157 * so cast to reassure them. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100158 return psa_its_get(uid, 0,
159 (uint32_t) driver->u.internal.persistent_data_size,
160 driver->u.internal.persistent_data,
161 &length);
Gilles Peskine5243a202019-07-12 23:38:19 +0200162}
163
164psa_status_t psa_save_se_persistent_data(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100165 const psa_se_drv_table_entry_t *driver)
Gilles Peskine5243a202019-07-12 23:38:19 +0200166{
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200167 psa_status_t status;
168 psa_storage_uid_t uid;
169
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100170 status = psa_get_se_driver_its_file_uid(driver, &uid);
171 if (status != PSA_SUCCESS) {
172 return status;
173 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200174
Gilles Peskine75c126b2019-07-24 15:56:01 +0200175 /* psa_get_se_driver_its_file_uid ensures that the size_t
176 * persistent_data_size is in range, but compilers don't know that,
177 * so cast to reassure them. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100178 return psa_its_set(uid,
179 (uint32_t) driver->u.internal.persistent_data_size,
180 driver->u.internal.persistent_data,
181 0);
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200182}
183
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100184psa_status_t psa_destroy_se_persistent_data(psa_key_location_t location)
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200185{
186 psa_storage_uid_t uid;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100187 if (location > PSA_MAX_SE_LOCATION) {
188 return PSA_ERROR_NOT_SUPPORTED;
189 }
Gilles Peskine2b04f462020-05-10 00:44:04 +0200190 uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + location;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100191 return psa_its_remove(uid);
Gilles Peskine5243a202019-07-12 23:38:19 +0200192}
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200193
Gilles Peskinecbaff462019-07-12 23:46:04 +0200194psa_status_t psa_find_se_slot_for_key(
195 const psa_key_attributes_t *attributes,
Gilles Peskinee88c2c12019-08-05 16:44:14 +0200196 psa_key_creation_method_t method,
Gilles Peskinecbaff462019-07-12 23:46:04 +0200197 psa_se_drv_table_entry_t *driver,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100198 psa_key_slot_number_t *slot_number)
Gilles Peskinecbaff462019-07-12 23:46:04 +0200199{
200 psa_status_t status;
Gilles Peskine2b04f462020-05-10 00:44:04 +0200201 psa_key_location_t key_location =
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100202 PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
Gilles Peskinecbaff462019-07-12 23:46:04 +0200203
Gilles Peskine2b04f462020-05-10 00:44:04 +0200204 /* If the location is wrong, it's a bug in the library. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100205 if (driver->location != key_location) {
206 return PSA_ERROR_CORRUPTION_DETECTED;
207 }
Gilles Peskinecbaff462019-07-12 23:46:04 +0200208
209 /* If the driver doesn't support key creation in any way, give up now. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100210 if (driver->methods->key_management == NULL) {
211 return PSA_ERROR_NOT_SUPPORTED;
212 }
Gilles Peskinecbaff462019-07-12 23:46:04 +0200213
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100214 if (psa_get_key_slot_number(attributes, slot_number) == PSA_SUCCESS) {
Gilles Peskine46d94392019-08-05 14:55:50 +0200215 /* The application wants to use a specific slot. Allow it if
216 * the driver supports it. On a system with isolation,
217 * the crypto service must check that the application is
218 * permitted to request this slot. */
219 psa_drv_se_validate_slot_number_t p_validate_slot_number =
220 driver->methods->key_management->p_validate_slot_number;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100221 if (p_validate_slot_number == NULL) {
222 return PSA_ERROR_NOT_SUPPORTED;
223 }
224 status = p_validate_slot_number(&driver->u.context,
225 driver->u.internal.persistent_data,
226 attributes, method,
227 *slot_number);
228 } else if (method == PSA_KEY_CREATION_REGISTER) {
Gilles Peskine3efcebb2019-10-01 14:18:35 +0200229 /* The application didn't specify a slot number. This doesn't
230 * make sense when registering a slot. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100231 return PSA_ERROR_INVALID_ARGUMENT;
232 } else {
Gilles Peskine46d94392019-08-05 14:55:50 +0200233 /* The application didn't tell us which slot to use. Let the driver
234 * choose. This is the normal case. */
235 psa_drv_se_allocate_key_t p_allocate =
236 driver->methods->key_management->p_allocate;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100237 if (p_allocate == NULL) {
238 return PSA_ERROR_NOT_SUPPORTED;
239 }
240 status = p_allocate(&driver->u.context,
241 driver->u.internal.persistent_data,
242 attributes, method,
243 slot_number);
Gilles Peskine46d94392019-08-05 14:55:50 +0200244 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100245 return status;
Gilles Peskinecbaff462019-07-12 23:46:04 +0200246}
247
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100248psa_status_t psa_destroy_se_key(psa_se_drv_table_entry_t *driver,
249 psa_key_slot_number_t slot_number)
Gilles Peskine354f7672019-07-12 23:46:38 +0200250{
251 psa_status_t status;
252 psa_status_t storage_status;
Gilles Peskine340b1272019-07-25 14:13:24 +0200253 /* Normally a missing method would mean that the action is not
254 * supported. But psa_destroy_key() is not supposed to return
255 * PSA_ERROR_NOT_SUPPORTED: if you can create a key, you should
256 * be able to destroy it. The only use case for a driver that
257 * does not have a way to destroy keys at all is if the keys are
258 * locked in a read-only state: we can use the keys but not
259 * destroy them. Hence, if the driver doesn't support destroying
260 * keys, it's really a lack of permission. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100261 if (driver->methods->key_management == NULL ||
262 driver->methods->key_management->p_destroy == NULL) {
263 return PSA_ERROR_NOT_PERMITTED;
264 }
Gilles Peskine354f7672019-07-12 23:46:38 +0200265 status = driver->methods->key_management->p_destroy(
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200266 &driver->u.context,
267 driver->u.internal.persistent_data,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100268 slot_number);
269 storage_status = psa_save_se_persistent_data(driver);
270 return status == PSA_SUCCESS ? storage_status : status;
Gilles Peskine354f7672019-07-12 23:46:38 +0200271}
272
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100273psa_status_t psa_init_all_se_drivers(void)
Gilles Peskined9348f22019-10-01 15:22:29 +0200274{
275 size_t i;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100276 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200277 psa_se_drv_table_entry_t *driver = &driver_table[i];
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100278 if (driver->location == 0) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200279 continue; /* skipping unused entry */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100280 }
281 const psa_drv_se_t *methods = psa_get_se_driver_methods(driver);
282 if (methods->p_init != NULL) {
Gilles Peskined9348f22019-10-01 15:22:29 +0200283 psa_status_t status = methods->p_init(
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200284 &driver->u.context,
285 driver->u.internal.persistent_data,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100286 driver->location);
287 if (status != PSA_SUCCESS) {
288 return status;
289 }
290 status = psa_save_se_persistent_data(driver);
291 if (status != PSA_SUCCESS) {
292 return status;
293 }
Gilles Peskined9348f22019-10-01 15:22:29 +0200294 }
295 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100296 return PSA_SUCCESS;
Gilles Peskined9348f22019-10-01 15:22:29 +0200297}
298
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200299
300
301/****************************************************************/
302/* Driver registration */
303/****************************************************************/
Gilles Peskinea899a722019-06-24 14:06:43 +0200304
305psa_status_t psa_register_se_driver(
Gilles Peskine2b04f462020-05-10 00:44:04 +0200306 psa_key_location_t location,
Gilles Peskinea899a722019-06-24 14:06:43 +0200307 const psa_drv_se_t *methods)
308{
309 size_t i;
Gilles Peskine5243a202019-07-12 23:38:19 +0200310 psa_status_t status;
Gilles Peskinea899a722019-06-24 14:06:43 +0200311
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100312 if (methods->hal_version != PSA_DRV_SE_HAL_VERSION) {
313 return PSA_ERROR_NOT_SUPPORTED;
314 }
Gilles Peskine9717d102019-06-26 11:50:04 +0200315 /* Driver table entries are 0-initialized. 0 is not a valid driver
Gilles Peskine2b04f462020-05-10 00:44:04 +0200316 * location because it means a transparent key. */
Tom Cosgrovebdd01a72023-03-08 14:19:51 +0000317 MBEDTLS_STATIC_ASSERT(PSA_KEY_LOCATION_LOCAL_STORAGE == 0,
318 "Secure element support requires 0 to mean a local key");
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100319 if (location == PSA_KEY_LOCATION_LOCAL_STORAGE) {
320 return PSA_ERROR_INVALID_ARGUMENT;
321 }
322 if (location > PSA_MAX_SE_LOCATION) {
323 return PSA_ERROR_NOT_SUPPORTED;
324 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200325
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100326 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
327 if (driver_table[i].location == 0) {
Gilles Peskinea899a722019-06-24 14:06:43 +0200328 break;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100329 }
Gilles Peskine2b04f462020-05-10 00:44:04 +0200330 /* Check that location isn't already in use up to the first free
Gilles Peskinea899a722019-06-24 14:06:43 +0200331 * entry. Since entries are created in order and never deleted,
332 * there can't be a used entry after the first free entry. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100333 if (driver_table[i].location == location) {
334 return PSA_ERROR_ALREADY_EXISTS;
335 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200336 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100337 if (i == PSA_MAX_SE_DRIVERS) {
338 return PSA_ERROR_INSUFFICIENT_MEMORY;
339 }
Gilles Peskinea899a722019-06-24 14:06:43 +0200340
Gilles Peskine2b04f462020-05-10 00:44:04 +0200341 driver_table[i].location = location;
Gilles Peskinea899a722019-06-24 14:06:43 +0200342 driver_table[i].methods = methods;
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200343 driver_table[i].u.internal.persistent_data_size =
Gilles Peskined5536d82019-10-01 16:55:29 +0200344 methods->persistent_data_size;
Gilles Peskine5243a202019-07-12 23:38:19 +0200345
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100346 if (methods->persistent_data_size != 0) {
Gilles Peskine1a75d0c2020-04-14 19:33:25 +0200347 driver_table[i].u.internal.persistent_data =
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100348 mbedtls_calloc(1, methods->persistent_data_size);
349 if (driver_table[i].u.internal.persistent_data == NULL) {
Gilles Peskine5243a202019-07-12 23:38:19 +0200350 status = PSA_ERROR_INSUFFICIENT_MEMORY;
351 goto error;
352 }
Gilles Peskine8b96cad2019-07-23 17:38:08 +0200353 /* Load the driver's persistent data. On first use, the persistent
354 * data does not exist in storage, and is initialized to
355 * all-bits-zero by the calloc call just above. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100356 status = psa_load_se_persistent_data(&driver_table[i]);
357 if (status != PSA_SUCCESS && status != PSA_ERROR_DOES_NOT_EXIST) {
Gilles Peskine5243a202019-07-12 23:38:19 +0200358 goto error;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100359 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200360 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200361
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100362 return PSA_SUCCESS;
Gilles Peskine5243a202019-07-12 23:38:19 +0200363
364error:
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100365 memset(&driver_table[i], 0, sizeof(driver_table[i]));
366 return status;
Gilles Peskinea899a722019-06-24 14:06:43 +0200367}
368
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100369void psa_unregister_all_se_drivers(void)
Gilles Peskined0890212019-06-24 14:34:43 +0200370{
Gilles Peskine5243a202019-07-12 23:38:19 +0200371 size_t i;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100372 for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
373 if (driver_table[i].u.internal.persistent_data != NULL) {
374 mbedtls_free(driver_table[i].u.internal.persistent_data);
375 }
Gilles Peskine5243a202019-07-12 23:38:19 +0200376 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100377 memset(driver_table, 0, sizeof(driver_table));
Gilles Peskined0890212019-06-24 14:34:43 +0200378}
379
Gilles Peskinef989dbe2019-06-26 18:18:12 +0200380
381
382/****************************************************************/
383/* The end */
384/****************************************************************/
385
Gilles Peskinea8ade162019-06-26 11:24:49 +0200386#endif /* MBEDTLS_PSA_CRYPTO_SE_C */