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 | #ifndef PSA_CRYPTO_SE_H |
| 23 | #define PSA_CRYPTO_SE_H |
| 24 | |
| 25 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 26 | #include "mbedtls/config.h" |
| 27 | #else |
| 28 | #include MBEDTLS_CONFIG_FILE |
| 29 | #endif |
| 30 | |
| 31 | #include "psa/crypto.h" |
| 32 | #include "psa/crypto_se_driver.h" |
| 33 | |
| 34 | /** The maximum number of registered secure element driver lifetimes. */ |
| 35 | #define PSA_MAX_SE_DRIVERS 4 |
| 36 | |
Gilles Peskine | d089021 | 2019-06-24 14:34:43 +0200 | [diff] [blame] | 37 | /** Unregister all secure element drivers. |
| 38 | * |
| 39 | * \warning Do not call this function while the library is in the initialized |
| 40 | * state. This function is only intended to be called at the end |
| 41 | * of mbedtls_psa_crypto_free(). |
| 42 | */ |
| 43 | void psa_unregister_all_se_drivers( void ); |
| 44 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 45 | /** A structure that describes a registered secure element driver. |
| 46 | * |
| 47 | * A secure element driver table entry contains a pointer to the |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 48 | * driver's method table as well as the driver context structure. |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 49 | */ |
| 50 | typedef struct psa_se_drv_table_entry_s psa_se_drv_table_entry_t; |
| 51 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 52 | /** Return the secure element driver information for a lifetime value. |
| 53 | * |
| 54 | * \param lifetime The lifetime value to query. |
| 55 | * \param[out] p_methods On output, if there is a driver, |
| 56 | * \c *methods points to its method table. |
| 57 | * Otherwise \c *methods is \c NULL. |
| 58 | * \param[out] p_drv_context On output, if there is a driver, |
| 59 | * \c *drv_context points to its context |
| 60 | * structure. |
| 61 | * Otherwise \c *drv_context is \c NULL. |
| 62 | * |
| 63 | * \retval 1 |
| 64 | * \p lifetime corresponds to a registered driver. |
| 65 | * \retval 0 |
| 66 | * \p lifetime does not correspond to a registered driver. |
| 67 | */ |
| 68 | int psa_get_se_driver( psa_key_lifetime_t lifetime, |
| 69 | const psa_drv_se_t **p_methods, |
| 70 | psa_drv_se_context_t **p_drv_context); |
| 71 | |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 72 | /** Return the secure element driver table entry for a lifetime value. |
| 73 | * |
| 74 | * \param lifetime The lifetime value to query. |
| 75 | * |
| 76 | * \return The driver table entry for \p lifetime, or |
| 77 | * \p NULL if \p lifetime does not correspond to a registered driver. |
| 78 | */ |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 79 | psa_se_drv_table_entry_t *psa_get_se_driver_entry( |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 80 | psa_key_lifetime_t lifetime ); |
| 81 | |
| 82 | /** Return the method table for a secure element driver. |
| 83 | * |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 84 | * \param[in] driver The driver table entry to access, or \c NULL. |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 85 | * |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 86 | * \return The driver's method table. |
| 87 | * \c NULL if \p driver is \c NULL. |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 88 | */ |
| 89 | const psa_drv_se_t *psa_get_se_driver_methods( |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 90 | const psa_se_drv_table_entry_t *driver ); |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 91 | |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 92 | /** Return the context of a secure element driver. |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 93 | * |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 94 | * \param[in] driver The driver table entry to access, or \c NULL. |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 95 | * |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 96 | * \return A pointer to the driver context. |
| 97 | * \c NULL if \p driver is \c NULL. |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 98 | */ |
Gilles Peskine | 5243a20 | 2019-07-12 23:38:19 +0200 | [diff] [blame] | 99 | psa_drv_se_context_t *psa_get_se_driver_context( |
| 100 | psa_se_drv_table_entry_t *driver ); |
| 101 | |
| 102 | /** Load the persistent data of a secure element driver. |
| 103 | * |
| 104 | * \param driver The driver table entry containing the persistent |
| 105 | * data to load from storage. |
| 106 | */ |
| 107 | psa_status_t psa_load_se_persistent_data( |
| 108 | const psa_se_drv_table_entry_t *driver ); |
| 109 | |
| 110 | /** Save the persistent data of a secure element driver. |
| 111 | * |
| 112 | * \param[in] driver The driver table entry containing the persistent |
| 113 | * data to save to storage. |
| 114 | */ |
| 115 | psa_status_t psa_save_se_persistent_data( |
| 116 | const psa_se_drv_table_entry_t *driver ); |
Gilles Peskine | f989dbe | 2019-06-26 18:18:12 +0200 | [diff] [blame] | 117 | |
Gilles Peskine | a899a72 | 2019-06-24 14:06:43 +0200 | [diff] [blame] | 118 | #endif /* PSA_CRYPTO_SE_H */ |