2019-06-24 14:06:43 +02:00
|
|
|
/*
|
|
|
|
* PSA crypto support for secure element drivers
|
|
|
|
*/
|
2020-06-15 11:59:37 +02:00
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2019-06-24 14:06:43 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-06-03 01:43:33 +02:00
|
|
|
#include "common.h"
|
2019-06-24 14:06:43 +02:00
|
|
|
|
2019-06-26 11:24:49 +02:00
|
|
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
2019-06-24 14:06:43 +02:00
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
#include <stdint.h>
|
2019-06-24 14:34:43 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
#include "psa/crypto_se_driver.h"
|
|
|
|
|
2019-06-24 14:06:43 +02:00
|
|
|
#include "psa_crypto_se.h"
|
|
|
|
|
2019-07-23 17:38:08 +02:00
|
|
|
#if defined(MBEDTLS_PSA_ITS_FILE_C)
|
|
|
|
#include "psa_crypto_its.h"
|
|
|
|
#else /* Native ITS implementation */
|
|
|
|
#include "psa/error.h"
|
|
|
|
#include "psa/internal_trusted_storage.h"
|
|
|
|
#endif
|
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
#include "mbedtls/platform.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-26 18:18:12 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* Driver lookup */
|
|
|
|
/****************************************************************/
|
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
/* This structure is identical to psa_drv_se_context_t declared in
|
|
|
|
* `crypto_se_driver.h`, except that some parts are writable here
|
|
|
|
* (non-const, or pointer to non-const). */
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2019-07-12 23:38:19 +02:00
|
|
|
void *persistent_data;
|
|
|
|
size_t persistent_data_size;
|
|
|
|
uintptr_t transient_data;
|
|
|
|
} psa_drv_se_internal_context_t;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
struct psa_se_drv_table_entry_s {
|
2020-05-10 00:44:04 +02:00
|
|
|
psa_key_location_t location;
|
2019-06-24 14:06:43 +02:00
|
|
|
const psa_drv_se_t *methods;
|
2023-01-11 14:50:10 +01:00
|
|
|
union {
|
2019-07-12 23:38:19 +02:00
|
|
|
psa_drv_se_internal_context_t internal;
|
|
|
|
psa_drv_se_context_t context;
|
2020-04-14 19:33:25 +02:00
|
|
|
} u;
|
2020-04-14 19:31:52 +02:00
|
|
|
};
|
2019-06-26 18:18:12 +02:00
|
|
|
|
|
|
|
static psa_se_drv_table_entry_t driver_table[PSA_MAX_SE_DRIVERS];
|
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
psa_se_drv_table_entry_t *psa_get_se_driver_entry(
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_key_lifetime_t lifetime)
|
2019-06-26 18:18:12 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(lifetime);
|
2020-05-10 00:44:04 +02:00
|
|
|
/* In the driver table, location=0 means an entry that isn't used.
|
|
|
|
* No driver has a location of 0 because it's a reserved value
|
|
|
|
* (which designates transparent keys). Make sure we never return
|
|
|
|
* a driver entry for location 0. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (location == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
|
|
|
|
if (driver_table[i].location == location) {
|
|
|
|
return &driver_table[i];
|
|
|
|
}
|
2019-06-26 18:18:12 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return NULL;
|
2019-06-26 18:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const psa_drv_se_t *psa_get_se_driver_methods(
|
2023-01-11 14:50:10 +01:00
|
|
|
const psa_se_drv_table_entry_t *driver)
|
2019-06-26 18:18:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return driver->methods;
|
2019-06-26 18:18:12 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
psa_drv_se_context_t *psa_get_se_driver_context(
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_se_drv_table_entry_t *driver)
|
2019-06-26 18:18:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return &driver->u.context;
|
2019-06-26 18:18:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
int psa_get_se_driver(psa_key_lifetime_t lifetime,
|
|
|
|
const psa_drv_se_t **p_methods,
|
|
|
|
psa_drv_se_context_t **p_drv_context)
|
2019-07-12 23:38:19 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_se_drv_table_entry_t *driver = psa_get_se_driver_entry(lifetime);
|
|
|
|
if (p_methods != NULL) {
|
|
|
|
*p_methods = (driver ? driver->methods : NULL);
|
|
|
|
}
|
|
|
|
if (p_drv_context != NULL) {
|
|
|
|
*p_drv_context = (driver ? &driver->u.context : NULL);
|
|
|
|
}
|
|
|
|
return driver != NULL;
|
2019-07-12 23:38:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
/* Persistent data management */
|
|
|
|
/****************************************************************/
|
|
|
|
|
2019-07-23 17:38:08 +02:00
|
|
|
static psa_status_t psa_get_se_driver_its_file_uid(
|
|
|
|
const psa_se_drv_table_entry_t *driver,
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_storage_uid_t *uid)
|
2019-07-23 17:38:08 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver->location > PSA_MAX_SE_LOCATION) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2019-07-23 19:59:23 +02:00
|
|
|
|
|
|
|
/* ITS file sizes are limited to 32 bits. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver->u.internal.persistent_data_size > UINT32_MAX) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2019-07-23 19:59:23 +02:00
|
|
|
|
2019-07-24 15:56:01 +02:00
|
|
|
/* See the documentation of PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE. */
|
2020-05-10 00:44:04 +02:00
|
|
|
*uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->location;
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2019-07-23 17:38:08 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 23:38:19 +02:00
|
|
|
psa_status_t psa_load_se_persistent_data(
|
2023-01-11 14:50:10 +01:00
|
|
|
const psa_se_drv_table_entry_t *driver)
|
2019-07-12 23:38:19 +02:00
|
|
|
{
|
2019-07-23 17:38:08 +02:00
|
|
|
psa_status_t status;
|
|
|
|
psa_storage_uid_t uid;
|
2019-07-31 17:57:57 +02:00
|
|
|
size_t length;
|
2019-07-23 17:38:08 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_get_se_driver_its_file_uid(driver, &uid);
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
2019-07-23 17:38:08 +02:00
|
|
|
|
2019-07-31 17:57:57 +02:00
|
|
|
/* Read the amount of persistent data that the driver requests.
|
|
|
|
* If the data in storage is larger, it is truncated. If the data
|
|
|
|
* in storage is smaller, silently keep what is already at the end
|
|
|
|
* of the output buffer. */
|
2019-07-24 15:56:01 +02:00
|
|
|
/* psa_get_se_driver_its_file_uid ensures that the size_t
|
|
|
|
* persistent_data_size is in range, but compilers don't know that,
|
|
|
|
* so cast to reassure them. */
|
2023-01-11 14:50:10 +01:00
|
|
|
return psa_its_get(uid, 0,
|
|
|
|
(uint32_t) driver->u.internal.persistent_data_size,
|
|
|
|
driver->u.internal.persistent_data,
|
|
|
|
&length);
|
2019-07-12 23:38:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
psa_status_t psa_save_se_persistent_data(
|
2023-01-11 14:50:10 +01:00
|
|
|
const psa_se_drv_table_entry_t *driver)
|
2019-07-12 23:38:19 +02:00
|
|
|
{
|
2019-07-23 17:38:08 +02:00
|
|
|
psa_status_t status;
|
|
|
|
psa_storage_uid_t uid;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_get_se_driver_its_file_uid(driver, &uid);
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
2019-07-23 17:38:08 +02:00
|
|
|
|
2019-07-24 15:56:01 +02:00
|
|
|
/* psa_get_se_driver_its_file_uid ensures that the size_t
|
|
|
|
* persistent_data_size is in range, but compilers don't know that,
|
|
|
|
* so cast to reassure them. */
|
2023-01-11 14:50:10 +01:00
|
|
|
return psa_its_set(uid,
|
|
|
|
(uint32_t) driver->u.internal.persistent_data_size,
|
|
|
|
driver->u.internal.persistent_data,
|
|
|
|
0);
|
2019-07-23 17:38:08 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_destroy_se_persistent_data(psa_key_location_t location)
|
2019-07-23 17:38:08 +02:00
|
|
|
{
|
|
|
|
psa_storage_uid_t uid;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (location > PSA_MAX_SE_LOCATION) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2020-05-10 00:44:04 +02:00
|
|
|
uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + location;
|
2023-01-11 14:50:10 +01:00
|
|
|
return psa_its_remove(uid);
|
2019-07-12 23:38:19 +02:00
|
|
|
}
|
2019-06-24 14:06:43 +02:00
|
|
|
|
2019-07-12 23:46:04 +02:00
|
|
|
psa_status_t psa_find_se_slot_for_key(
|
|
|
|
const psa_key_attributes_t *attributes,
|
2019-08-05 16:44:14 +02:00
|
|
|
psa_key_creation_method_t method,
|
2019-07-12 23:46:04 +02:00
|
|
|
psa_se_drv_table_entry_t *driver,
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_key_slot_number_t *slot_number)
|
2019-07-12 23:46:04 +02:00
|
|
|
{
|
|
|
|
psa_status_t status;
|
2020-05-10 00:44:04 +02:00
|
|
|
psa_key_location_t key_location =
|
2023-01-11 14:50:10 +01:00
|
|
|
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
|
2019-07-12 23:46:04 +02:00
|
|
|
|
2020-05-10 00:44:04 +02:00
|
|
|
/* If the location is wrong, it's a bug in the library. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver->location != key_location) {
|
|
|
|
return PSA_ERROR_CORRUPTION_DETECTED;
|
|
|
|
}
|
2019-07-12 23:46:04 +02:00
|
|
|
|
|
|
|
/* If the driver doesn't support key creation in any way, give up now. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver->methods->key_management == NULL) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2019-07-12 23:46:04 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (psa_get_key_slot_number(attributes, slot_number) == PSA_SUCCESS) {
|
2019-08-05 14:55:50 +02:00
|
|
|
/* The application wants to use a specific slot. Allow it if
|
|
|
|
* the driver supports it. On a system with isolation,
|
|
|
|
* the crypto service must check that the application is
|
|
|
|
* permitted to request this slot. */
|
|
|
|
psa_drv_se_validate_slot_number_t p_validate_slot_number =
|
|
|
|
driver->methods->key_management->p_validate_slot_number;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (p_validate_slot_number == NULL) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
status = p_validate_slot_number(&driver->u.context,
|
|
|
|
driver->u.internal.persistent_data,
|
|
|
|
attributes, method,
|
|
|
|
*slot_number);
|
|
|
|
} else if (method == PSA_KEY_CREATION_REGISTER) {
|
2019-10-01 14:18:35 +02:00
|
|
|
/* The application didn't specify a slot number. This doesn't
|
|
|
|
* make sense when registering a slot. */
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_INVALID_ARGUMENT;
|
|
|
|
} else {
|
2019-08-05 14:55:50 +02:00
|
|
|
/* The application didn't tell us which slot to use. Let the driver
|
|
|
|
* choose. This is the normal case. */
|
|
|
|
psa_drv_se_allocate_key_t p_allocate =
|
|
|
|
driver->methods->key_management->p_allocate;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (p_allocate == NULL) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
status = p_allocate(&driver->u.context,
|
|
|
|
driver->u.internal.persistent_data,
|
|
|
|
attributes, method,
|
|
|
|
slot_number);
|
2019-08-05 14:55:50 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2019-07-12 23:46:04 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_destroy_se_key(psa_se_drv_table_entry_t *driver,
|
|
|
|
psa_key_slot_number_t slot_number)
|
2019-07-12 23:46:38 +02:00
|
|
|
{
|
|
|
|
psa_status_t status;
|
|
|
|
psa_status_t storage_status;
|
2019-07-25 14:13:24 +02:00
|
|
|
/* Normally a missing method would mean that the action is not
|
|
|
|
* supported. But psa_destroy_key() is not supposed to return
|
|
|
|
* PSA_ERROR_NOT_SUPPORTED: if you can create a key, you should
|
|
|
|
* be able to destroy it. The only use case for a driver that
|
|
|
|
* does not have a way to destroy keys at all is if the keys are
|
|
|
|
* locked in a read-only state: we can use the keys but not
|
|
|
|
* destroy them. Hence, if the driver doesn't support destroying
|
|
|
|
* keys, it's really a lack of permission. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver->methods->key_management == NULL ||
|
|
|
|
driver->methods->key_management->p_destroy == NULL) {
|
|
|
|
return PSA_ERROR_NOT_PERMITTED;
|
|
|
|
}
|
2019-07-12 23:46:38 +02:00
|
|
|
status = driver->methods->key_management->p_destroy(
|
2020-04-14 19:33:25 +02:00
|
|
|
&driver->u.context,
|
|
|
|
driver->u.internal.persistent_data,
|
2023-01-11 14:50:10 +01:00
|
|
|
slot_number);
|
|
|
|
storage_status = psa_save_se_persistent_data(driver);
|
|
|
|
return status == PSA_SUCCESS ? storage_status : status;
|
2019-07-12 23:46:38 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_init_all_se_drivers(void)
|
2019-10-01 15:22:29 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
|
2019-10-01 15:22:29 +02:00
|
|
|
psa_se_drv_table_entry_t *driver = &driver_table[i];
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver->location == 0) {
|
2019-10-01 15:22:29 +02:00
|
|
|
continue; /* skipping unused entry */
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
const psa_drv_se_t *methods = psa_get_se_driver_methods(driver);
|
|
|
|
if (methods->p_init != NULL) {
|
2019-10-01 15:22:29 +02:00
|
|
|
psa_status_t status = methods->p_init(
|
2020-04-14 19:33:25 +02:00
|
|
|
&driver->u.context,
|
|
|
|
driver->u.internal.persistent_data,
|
2023-01-11 14:50:10 +01:00
|
|
|
driver->location);
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
status = psa_save_se_persistent_data(driver);
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
2019-10-01 15:22:29 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2019-10-01 15:22:29 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 18:18:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
/* Driver registration */
|
|
|
|
/****************************************************************/
|
2019-06-24 14:06:43 +02:00
|
|
|
|
|
|
|
psa_status_t psa_register_se_driver(
|
2020-05-10 00:44:04 +02:00
|
|
|
psa_key_location_t location,
|
2019-06-24 14:06:43 +02:00
|
|
|
const psa_drv_se_t *methods)
|
|
|
|
{
|
|
|
|
size_t i;
|
2019-07-12 23:38:19 +02:00
|
|
|
psa_status_t status;
|
2019-06-24 14:06:43 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (methods->hal_version != PSA_DRV_SE_HAL_VERSION) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2019-06-26 11:50:04 +02:00
|
|
|
/* Driver table entries are 0-initialized. 0 is not a valid driver
|
2020-05-10 00:44:04 +02:00
|
|
|
* location because it means a transparent key. */
|
2023-03-08 15:19:51 +01:00
|
|
|
MBEDTLS_STATIC_ASSERT(PSA_KEY_LOCATION_LOCAL_STORAGE == 0,
|
|
|
|
"Secure element support requires 0 to mean a local key");
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (location == PSA_KEY_LOCATION_LOCAL_STORAGE) {
|
|
|
|
return PSA_ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
|
|
|
if (location > PSA_MAX_SE_LOCATION) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
|
|
|
|
if (driver_table[i].location == 0) {
|
2019-06-24 14:06:43 +02:00
|
|
|
break;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2020-05-10 00:44:04 +02:00
|
|
|
/* Check that location isn't already in use up to the first free
|
2019-06-24 14:06:43 +02:00
|
|
|
* entry. Since entries are created in order and never deleted,
|
|
|
|
* there can't be a used entry after the first free entry. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (driver_table[i].location == location) {
|
|
|
|
return PSA_ERROR_ALREADY_EXISTS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == PSA_MAX_SE_DRIVERS) {
|
|
|
|
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
2019-06-24 14:06:43 +02:00
|
|
|
}
|
|
|
|
|
2020-05-10 00:44:04 +02:00
|
|
|
driver_table[i].location = location;
|
2019-06-24 14:06:43 +02:00
|
|
|
driver_table[i].methods = methods;
|
2020-04-14 19:33:25 +02:00
|
|
|
driver_table[i].u.internal.persistent_data_size =
|
2019-10-01 16:55:29 +02:00
|
|
|
methods->persistent_data_size;
|
2019-07-12 23:38:19 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (methods->persistent_data_size != 0) {
|
2020-04-14 19:33:25 +02:00
|
|
|
driver_table[i].u.internal.persistent_data =
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_calloc(1, methods->persistent_data_size);
|
|
|
|
if (driver_table[i].u.internal.persistent_data == NULL) {
|
2019-07-12 23:38:19 +02:00
|
|
|
status = PSA_ERROR_INSUFFICIENT_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
2019-07-23 17:38:08 +02:00
|
|
|
/* Load the driver's persistent data. On first use, the persistent
|
|
|
|
* data does not exist in storage, and is initialized to
|
|
|
|
* all-bits-zero by the calloc call just above. */
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_load_se_persistent_data(&driver_table[i]);
|
|
|
|
if (status != PSA_SUCCESS && status != PSA_ERROR_DOES_NOT_EXIST) {
|
2019-07-12 23:38:19 +02:00
|
|
|
goto error;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2019-07-12 23:38:19 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2019-07-12 23:38:19 +02:00
|
|
|
|
|
|
|
error:
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(&driver_table[i], 0, sizeof(driver_table[i]));
|
|
|
|
return status;
|
2019-06-24 14:06:43 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void psa_unregister_all_se_drivers(void)
|
2019-06-24 14:34:43 +02:00
|
|
|
{
|
2019-07-12 23:38:19 +02:00
|
|
|
size_t i;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (i = 0; i < PSA_MAX_SE_DRIVERS; i++) {
|
|
|
|
if (driver_table[i].u.internal.persistent_data != NULL) {
|
|
|
|
mbedtls_free(driver_table[i].u.internal.persistent_data);
|
|
|
|
}
|
2019-07-12 23:38:19 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(driver_table, 0, sizeof(driver_table));
|
2019-06-24 14:34:43 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 18:18:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
/* The end */
|
|
|
|
/****************************************************************/
|
|
|
|
|
2019-06-26 11:24:49 +02:00
|
|
|
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|