Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_se_driver.h |
| 3 | * \brief PSA external cryptoprocessor driver module |
| 4 | * |
| 5 | * This header declares types and function signatures for cryptography |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 6 | * drivers that access key material via opaque references. |
| 7 | * This is meant for cryptoprocessors that have a separate key storage from the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 8 | * space in which the PSA Crypto implementation runs, typically secure |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 9 | * elements (SEs). |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 10 | * |
Gilles Peskine | b6cadea | 2019-06-24 13:46:37 +0200 | [diff] [blame] | 11 | * This file is part of the PSA Crypto Driver HAL (hardware abstraction layer), |
| 12 | * containing functions for driver developers to implement to enable hardware |
| 13 | * to be called in a standardized way by a PSA Cryptography API |
| 14 | * implementation. The functions comprising the driver HAL, which driver |
| 15 | * authors implement, are not intended to be called by application developers. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
| 20 | * SPDX-License-Identifier: Apache-2.0 |
| 21 | * |
| 22 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 23 | * not use this file except in compliance with the License. |
| 24 | * You may obtain a copy of the License at |
| 25 | * |
| 26 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 27 | * |
| 28 | * Unless required by applicable law or agreed to in writing, software |
| 29 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 30 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 31 | * See the License for the specific language governing permissions and |
| 32 | * limitations under the License. |
| 33 | */ |
| 34 | #ifndef PSA_CRYPTO_SE_DRIVER_H |
| 35 | #define PSA_CRYPTO_SE_DRIVER_H |
| 36 | |
| 37 | #include "crypto_driver_common.h" |
| 38 | |
| 39 | #ifdef __cplusplus |
| 40 | extern "C" { |
| 41 | #endif |
| 42 | |
Gilles Peskine | 7a86da1 | 2019-07-12 23:25:38 +0200 | [diff] [blame] | 43 | /** \defgroup se_init Secure element driver initialization |
| 44 | */ |
| 45 | /**@{*/ |
| 46 | |
| 47 | /** \brief Driver context structure |
| 48 | * |
| 49 | * Driver functions receive a pointer to this structure. |
| 50 | * Each registered driver has one instance of this structure. |
| 51 | * |
| 52 | * Implementations must include the fields specified here and |
| 53 | * may include other fields. |
| 54 | */ |
| 55 | typedef struct { |
| 56 | /** A read-only pointer to the driver's persistent data. |
| 57 | * |
| 58 | * The PSA Cryptography core saves the persistent data from one |
| 59 | * session to the next. |
| 60 | * |
| 61 | * The core allocates a memory buffer for the persistent data. |
| 62 | * The pointer is guaranteed to be suitably alignedfor any data type, |
| 63 | * like a pointer returned by `malloc` (but the core can use any |
| 64 | * method to allocate the buffer, not necessarily `malloc`). |
| 65 | * |
| 66 | * The size of this buffer is given by psa_drv_se_t::persistent_data_size |
| 67 | * when the driver is registered, and this value is also recorded in the |
| 68 | * ::persistent_data_size field of this structure. |
| 69 | * |
| 70 | * Before the driver is initialized for the first time, the content of |
| 71 | * the persistent data is all-bits-zero. After a driver upgrade, if the |
| 72 | * size of the persistent data has increased, the original data is padded |
| 73 | * on the right with zeros; if the size has decreased, the original data |
| 74 | * is truncated to the new size. |
| 75 | * |
| 76 | * This pointer is to read-only data. Only a few driver functions are |
| 77 | * allowed to modify the persistent data. These functions receive a |
| 78 | * writable pointer. |
| 79 | */ |
| 80 | const void *const persistent_data; |
| 81 | |
| 82 | /** The size of \c persistent_data in bytes. |
| 83 | * |
| 84 | * This is always equal to the value of |
| 85 | * psa_drv_se_t::persistent_data_size when the driver is registered. |
| 86 | */ |
| 87 | const size_t persistent_data_size; |
| 88 | |
| 89 | /** Driver transient data. |
| 90 | * |
| 91 | * The core initializes this value to 0 and does not read or modify it |
| 92 | * afterwards. The driver may store whatever it wants in this field. |
| 93 | */ |
| 94 | uintptr_t transient_data; |
| 95 | } psa_drv_se_context_t; |
| 96 | |
| 97 | /** \brief A driver initialization function. |
| 98 | * |
| 99 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 94cc42c | 2019-07-12 23:34:20 +0200 | [diff] [blame^] | 100 | * \param[in,out] persistent_data A pointer to the persistent data |
| 101 | * that allows writing. |
Gilles Peskine | 7a86da1 | 2019-07-12 23:25:38 +0200 | [diff] [blame] | 102 | * \param lifetime The lifetime value for which this driver |
| 103 | * is registered. |
| 104 | * |
| 105 | * \retval #PSA_SUCCESS |
| 106 | * The driver is operational. |
| 107 | * The core will update the persistent data in storage. |
| 108 | * \return |
| 109 | * Any other return value prevents the driver from being used in |
| 110 | * this session. |
| 111 | * The core will NOT update the persistent data in storage. |
| 112 | */ |
| 113 | typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context, |
Gilles Peskine | 94cc42c | 2019-07-12 23:34:20 +0200 | [diff] [blame^] | 114 | void *persistent_data, |
Gilles Peskine | 7a86da1 | 2019-07-12 23:25:38 +0200 | [diff] [blame] | 115 | psa_key_lifetime_t lifetime); |
| 116 | |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 117 | /** An internal designation of a key slot between the core part of the |
| 118 | * PSA Crypto implementation and the driver. The meaning of this value |
| 119 | * is driver-dependent. */ |
Gilles Peskine | f03143a | 2019-07-12 23:18:29 +0200 | [diff] [blame] | 120 | typedef uint64_t psa_key_slot_number_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 121 | |
Gilles Peskine | 7a86da1 | 2019-07-12 23:25:38 +0200 | [diff] [blame] | 122 | /**@}*/ |
| 123 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 124 | /** \defgroup se_mac Secure Element Message Authentication Codes |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 125 | * Generation and authentication of Message Authentication Codes (MACs) using |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 126 | * a secure element can be done either as a single function call (via the |
| 127 | * `psa_drv_se_mac_generate_t` or `psa_drv_se_mac_verify_t` functions), or in |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 128 | * parts using the following sequence: |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 129 | * - `psa_drv_se_mac_setup_t` |
| 130 | * - `psa_drv_se_mac_update_t` |
| 131 | * - `psa_drv_se_mac_update_t` |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 132 | * - ... |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 133 | * - `psa_drv_se_mac_finish_t` or `psa_drv_se_mac_finish_verify_t` |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 134 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 135 | * If a previously started secure element MAC operation needs to be terminated, |
| 136 | * it should be done so by the `psa_drv_se_mac_abort_t`. Failure to do so may |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 137 | * result in allocated resources not being freed or in other undefined |
| 138 | * behavior. |
| 139 | */ |
| 140 | /**@{*/ |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 141 | /** \brief A function that starts a secure element MAC operation for a PSA |
| 142 | * Crypto Driver implementation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 143 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 144 | * \param[in,out] drv_context The driver context structure. |
| 145 | * \param[in,out] op_context A structure that will contain the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 146 | * hardware-specific MAC context |
| 147 | * \param[in] key_slot The slot of the key to be used for the |
| 148 | * operation |
| 149 | * \param[in] algorithm The algorithm to be used to underly the MAC |
| 150 | * operation |
| 151 | * |
| 152 | * \retval PSA_SUCCESS |
| 153 | * Success. |
| 154 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 155 | typedef psa_status_t (*psa_drv_se_mac_setup_t)(psa_drv_se_context_t *drv_context, |
| 156 | void *op_context, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 157 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 158 | psa_algorithm_t algorithm); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 159 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 160 | /** \brief A function that continues a previously started secure element MAC |
| 161 | * operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 162 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 163 | * \param[in,out] op_context A hardware-specific structure for the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 164 | * previously-established MAC operation to be |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 165 | * updated |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 166 | * \param[in] p_input A buffer containing the message to be appended |
| 167 | * to the MAC operation |
| 168 | * \param[in] input_length The size in bytes of the input message buffer |
| 169 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 170 | typedef psa_status_t (*psa_drv_se_mac_update_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 171 | const uint8_t *p_input, |
| 172 | size_t input_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 173 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 174 | /** \brief a function that completes a previously started secure element MAC |
| 175 | * operation by returning the resulting MAC. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 176 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 177 | * \param[in,out] op_context A hardware-specific structure for the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 178 | * previously started MAC operation to be |
| 179 | * finished |
| 180 | * \param[out] p_mac A buffer where the generated MAC will be |
| 181 | * placed |
| 182 | * \param[in] mac_size The size in bytes of the buffer that has been |
| 183 | * allocated for the `output` buffer |
| 184 | * \param[out] p_mac_length After completion, will contain the number of |
| 185 | * bytes placed in the `p_mac` buffer |
| 186 | * |
| 187 | * \retval PSA_SUCCESS |
| 188 | * Success. |
| 189 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 190 | typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 191 | uint8_t *p_mac, |
| 192 | size_t mac_size, |
| 193 | size_t *p_mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 194 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 195 | /** \brief A function that completes a previously started secure element MAC |
| 196 | * operation by comparing the resulting MAC against a provided value |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 197 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 198 | * \param[in,out] op_context A hardware-specific structure for the previously |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 199 | * started MAC operation to be fiinished |
| 200 | * \param[in] p_mac The MAC value against which the resulting MAC will |
| 201 | * be compared against |
| 202 | * \param[in] mac_length The size in bytes of the value stored in `p_mac` |
| 203 | * |
| 204 | * \retval PSA_SUCCESS |
| 205 | * The operation completed successfully and the MACs matched each |
| 206 | * other |
| 207 | * \retval PSA_ERROR_INVALID_SIGNATURE |
| 208 | * The operation completed successfully, but the calculated MAC did |
| 209 | * not match the provided MAC |
| 210 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 211 | typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 212 | const uint8_t *p_mac, |
| 213 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 214 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 215 | /** \brief A function that aborts a previous started secure element MAC |
| 216 | * operation |
Gilles Peskine | 32668ce | 2019-03-06 18:29:57 +0100 | [diff] [blame] | 217 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 218 | * \param[in,out] op_context A hardware-specific structure for the previously |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 219 | * started MAC operation to be aborted |
| 220 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 221 | typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *op_context); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 222 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 223 | /** \brief A function that performs a secure element MAC operation in one |
| 224 | * command and returns the calculated MAC |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 225 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 226 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 227 | * \param[in] p_input A buffer containing the message to be MACed |
| 228 | * \param[in] input_length The size in bytes of `p_input` |
| 229 | * \param[in] key_slot The slot of the key to be used |
| 230 | * \param[in] alg The algorithm to be used to underlie the MAC |
| 231 | * operation |
| 232 | * \param[out] p_mac A buffer where the generated MAC will be |
| 233 | * placed |
| 234 | * \param[in] mac_size The size in bytes of the `p_mac` buffer |
| 235 | * \param[out] p_mac_length After completion, will contain the number of |
| 236 | * bytes placed in the `output` buffer |
| 237 | * |
| 238 | * \retval PSA_SUCCESS |
| 239 | * Success. |
| 240 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 241 | typedef psa_status_t (*psa_drv_se_mac_generate_t)(psa_drv_se_context_t *drv_context, |
| 242 | const uint8_t *p_input, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 243 | size_t input_length, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 244 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 245 | psa_algorithm_t alg, |
| 246 | uint8_t *p_mac, |
| 247 | size_t mac_size, |
| 248 | size_t *p_mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 249 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 250 | /** \brief A function that performs a secure element MAC operation in one |
| 251 | * command and compares the resulting MAC against a provided value |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 252 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 253 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 254 | * \param[in] p_input A buffer containing the message to be MACed |
| 255 | * \param[in] input_length The size in bytes of `input` |
| 256 | * \param[in] key_slot The slot of the key to be used |
| 257 | * \param[in] alg The algorithm to be used to underlie the MAC |
| 258 | * operation |
| 259 | * \param[in] p_mac The MAC value against which the resulting MAC will |
| 260 | * be compared against |
| 261 | * \param[in] mac_length The size in bytes of `mac` |
| 262 | * |
| 263 | * \retval PSA_SUCCESS |
| 264 | * The operation completed successfully and the MACs matched each |
| 265 | * other |
| 266 | * \retval PSA_ERROR_INVALID_SIGNATURE |
| 267 | * The operation completed successfully, but the calculated MAC did |
| 268 | * not match the provided MAC |
| 269 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 270 | typedef psa_status_t (*psa_drv_se_mac_verify_t)(psa_drv_se_context_t *drv_context, |
| 271 | const uint8_t *p_input, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 272 | size_t input_length, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 273 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 274 | psa_algorithm_t alg, |
| 275 | const uint8_t *p_mac, |
| 276 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 277 | |
| 278 | /** \brief A struct containing all of the function pointers needed to |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 279 | * perform secure element MAC operations |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 280 | * |
| 281 | * PSA Crypto API implementations should populate the table as appropriate |
| 282 | * upon startup. |
| 283 | * |
| 284 | * If one of the functions is not implemented (such as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 285 | * `psa_drv_se_mac_generate_t`), it should be set to NULL. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 286 | * |
| 287 | * Driver implementers should ensure that they implement all of the functions |
| 288 | * that make sense for their hardware, and that they provide a full solution |
| 289 | * (for example, if they support `p_setup`, they should also support |
| 290 | * `p_update` and at least one of `p_finish` or `p_finish_verify`). |
| 291 | * |
| 292 | */ |
| 293 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 294 | /**The size in bytes of the hardware-specific secure element MAC context |
| 295 | * structure |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 296 | */ |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 297 | size_t context_size; |
| 298 | /** Function that performs a MAC setup operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 299 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 300 | psa_drv_se_mac_setup_t p_setup; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 301 | /** Function that performs a MAC update operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 302 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 303 | psa_drv_se_mac_update_t p_update; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 304 | /** Function that completes a MAC operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 305 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 306 | psa_drv_se_mac_finish_t p_finish; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 307 | /** Function that completes a MAC operation with a verify check |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 308 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 309 | psa_drv_se_mac_finish_verify_t p_finish_verify; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 310 | /** Function that aborts a previoustly started MAC operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 311 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 312 | psa_drv_se_mac_abort_t p_abort; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 313 | /** Function that performs a MAC operation in one call |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 314 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 315 | psa_drv_se_mac_generate_t p_mac; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 316 | /** Function that performs a MAC and verify operation in one call |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 317 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 318 | psa_drv_se_mac_verify_t p_mac_verify; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 319 | } psa_drv_se_mac_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 320 | /**@}*/ |
| 321 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 322 | /** \defgroup se_cipher Secure Element Symmetric Ciphers |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 323 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 324 | * Encryption and Decryption using secure element keys in block modes other |
| 325 | * than ECB must be done in multiple parts, using the following flow: |
| 326 | * - `psa_drv_se_cipher_setup_t` |
| 327 | * - `psa_drv_se_cipher_set_iv_t` (optional depending upon block mode) |
| 328 | * - `psa_drv_se_cipher_update_t` |
| 329 | * - `psa_drv_se_cipher_update_t` |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 330 | * - ... |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 331 | * - `psa_drv_se_cipher_finish_t` |
Gilles Peskine | 32668ce | 2019-03-06 18:29:57 +0100 | [diff] [blame] | 332 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 333 | * If a previously started secure element Cipher operation needs to be |
| 334 | * terminated, it should be done so by the `psa_drv_se_cipher_abort_t`. Failure |
| 335 | * to do so may result in allocated resources not being freed or in other |
| 336 | * undefined behavior. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 337 | * |
| 338 | * In situations where a PSA Cryptographic API implementation is using a block |
| 339 | * mode not-supported by the underlying hardware or driver, it can construct |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 340 | * the block mode itself, while calling the `psa_drv_se_cipher_ecb_t` function |
| 341 | * for the cipher operations. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 342 | */ |
| 343 | /**@{*/ |
| 344 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 345 | /** \brief A function that provides the cipher setup function for a |
| 346 | * secure element driver |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 347 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 348 | * \param[in,out] drv_context The driver context structure. |
| 349 | * \param[in,out] op_context A structure that will contain the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 350 | * hardware-specific cipher context. |
| 351 | * \param[in] key_slot The slot of the key to be used for the |
| 352 | * operation |
| 353 | * \param[in] algorithm The algorithm to be used in the cipher |
| 354 | * operation |
| 355 | * \param[in] direction Indicates whether the operation is an encrypt |
| 356 | * or decrypt |
| 357 | * |
| 358 | * \retval PSA_SUCCESS |
| 359 | * \retval PSA_ERROR_NOT_SUPPORTED |
| 360 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 361 | typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context, |
| 362 | void *op_context, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 363 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 364 | psa_algorithm_t algorithm, |
| 365 | psa_encrypt_or_decrypt_t direction); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 366 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 367 | /** \brief A function that sets the initialization vector (if |
| 368 | * necessary) for an secure element cipher operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 369 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 370 | * Rationale: The `psa_se_cipher_*` operation in the PSA Cryptographic API has |
| 371 | * two IV functions: one to set the IV, and one to generate it internally. The |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 372 | * generate function is not necessary for the drivers to implement as the PSA |
| 373 | * Crypto implementation can do the generation using its RNG features. |
| 374 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 375 | * \param[in,out] op_context A structure that contains the previously set up |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 376 | * hardware-specific cipher context |
| 377 | * \param[in] p_iv A buffer containing the initialization vector |
| 378 | * \param[in] iv_length The size (in bytes) of the `p_iv` buffer |
| 379 | * |
| 380 | * \retval PSA_SUCCESS |
| 381 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 382 | typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 383 | const uint8_t *p_iv, |
| 384 | size_t iv_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 385 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 386 | /** \brief A function that continues a previously started secure element cipher |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 387 | * operation |
| 388 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 389 | * \param[in,out] op_context A hardware-specific structure for the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 390 | * previously started cipher operation |
| 391 | * \param[in] p_input A buffer containing the data to be |
| 392 | * encrypted/decrypted |
| 393 | * \param[in] input_size The size in bytes of the buffer pointed to |
| 394 | * by `p_input` |
| 395 | * \param[out] p_output The caller-allocated buffer where the |
| 396 | * output will be placed |
| 397 | * \param[in] output_size The allocated size in bytes of the |
| 398 | * `p_output` buffer |
| 399 | * \param[out] p_output_length After completion, will contain the number |
| 400 | * of bytes placed in the `p_output` buffer |
| 401 | * |
| 402 | * \retval PSA_SUCCESS |
| 403 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 404 | typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 405 | const uint8_t *p_input, |
| 406 | size_t input_size, |
| 407 | uint8_t *p_output, |
| 408 | size_t output_size, |
| 409 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 410 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 411 | /** \brief A function that completes a previously started secure element cipher |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 412 | * operation |
| 413 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 414 | * \param[in,out] op_context A hardware-specific structure for the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 415 | * previously started cipher operation |
| 416 | * \param[out] p_output The caller-allocated buffer where the output |
| 417 | * will be placed |
| 418 | * \param[in] output_size The allocated size in bytes of the `p_output` |
| 419 | * buffer |
| 420 | * \param[out] p_output_length After completion, will contain the number of |
| 421 | * bytes placed in the `p_output` buffer |
| 422 | * |
| 423 | * \retval PSA_SUCCESS |
| 424 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 425 | typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 426 | uint8_t *p_output, |
| 427 | size_t output_size, |
| 428 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 429 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 430 | /** \brief A function that aborts a previously started secure element cipher |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 431 | * operation |
| 432 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 433 | * \param[in,out] op_context A hardware-specific structure for the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 434 | * previously started cipher operation |
| 435 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 436 | typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 437 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 438 | /** \brief A function that performs the ECB block mode for secure element |
| 439 | * cipher operations |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 440 | * |
| 441 | * Note: this function should only be used with implementations that do not |
| 442 | * provide a needed higher-level operation. |
| 443 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 444 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 445 | * \param[in] key_slot The slot of the key to be used for the operation |
| 446 | * \param[in] algorithm The algorithm to be used in the cipher operation |
| 447 | * \param[in] direction Indicates whether the operation is an encrypt or |
| 448 | * decrypt |
| 449 | * \param[in] p_input A buffer containing the data to be |
| 450 | * encrypted/decrypted |
| 451 | * \param[in] input_size The size in bytes of the buffer pointed to by |
| 452 | * `p_input` |
| 453 | * \param[out] p_output The caller-allocated buffer where the output will |
| 454 | * be placed |
| 455 | * \param[in] output_size The allocated size in bytes of the `p_output` |
| 456 | * buffer |
| 457 | * |
| 458 | * \retval PSA_SUCCESS |
| 459 | * \retval PSA_ERROR_NOT_SUPPORTED |
| 460 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 461 | typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context, |
| 462 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 463 | psa_algorithm_t algorithm, |
| 464 | psa_encrypt_or_decrypt_t direction, |
| 465 | const uint8_t *p_input, |
| 466 | size_t input_size, |
| 467 | uint8_t *p_output, |
| 468 | size_t output_size); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 469 | |
| 470 | /** |
| 471 | * \brief A struct containing all of the function pointers needed to implement |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 472 | * cipher operations using secure elements. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 473 | * |
| 474 | * PSA Crypto API implementations should populate instances of the table as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 475 | * appropriate upon startup or at build time. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 476 | * |
| 477 | * If one of the functions is not implemented (such as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 478 | * `psa_drv_se_cipher_ecb_t`), it should be set to NULL. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 479 | */ |
| 480 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 481 | /** The size in bytes of the hardware-specific secure element cipher |
| 482 | * context structure |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 483 | */ |
Derek Miller | 34b33f1 | 2019-02-15 17:13:54 -0600 | [diff] [blame] | 484 | size_t context_size; |
| 485 | /** Function that performs a cipher setup operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 486 | psa_drv_se_cipher_setup_t p_setup; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 487 | /** Function that sets a cipher IV (if necessary) */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 488 | psa_drv_se_cipher_set_iv_t p_set_iv; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 489 | /** Function that performs a cipher update operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 490 | psa_drv_se_cipher_update_t p_update; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 491 | /** Function that completes a cipher operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 492 | psa_drv_se_cipher_finish_t p_finish; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 493 | /** Function that aborts a cipher operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 494 | psa_drv_se_cipher_abort_t p_abort; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 495 | /** Function that performs ECB mode for a cipher operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 496 | * (Danger: ECB mode should not be used directly by clients of the PSA |
| 497 | * Crypto Client API) |
| 498 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 499 | psa_drv_se_cipher_ecb_t p_ecb; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 500 | } psa_drv_se_cipher_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 501 | |
| 502 | /**@}*/ |
| 503 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 504 | /** \defgroup se_asymmetric Secure Element Asymmetric Cryptography |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 505 | * |
| 506 | * Since the amount of data that can (or should) be encrypted or signed using |
| 507 | * asymmetric keys is limited by the key size, asymmetric key operations using |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 508 | * keys in a secure element must be done in single function calls. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 509 | */ |
| 510 | /**@{*/ |
| 511 | |
| 512 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 513 | * \brief A function that signs a hash or short message with a private key in |
| 514 | * a secure element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 515 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 516 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 517 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 518 | * \param[in] alg A signature algorithm that is compatible |
| 519 | * with the type of `key` |
| 520 | * \param[in] p_hash The hash to sign |
| 521 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 522 | * \param[out] p_signature Buffer where the signature is to be written |
| 523 | * \param[in] signature_size Size of the `p_signature` buffer in bytes |
| 524 | * \param[out] p_signature_length On success, the number of bytes |
| 525 | * that make up the returned signature value |
| 526 | * |
| 527 | * \retval PSA_SUCCESS |
| 528 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 529 | typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context, |
| 530 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 531 | psa_algorithm_t alg, |
| 532 | const uint8_t *p_hash, |
| 533 | size_t hash_length, |
| 534 | uint8_t *p_signature, |
| 535 | size_t signature_size, |
| 536 | size_t *p_signature_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 537 | |
| 538 | /** |
| 539 | * \brief A function that verifies the signature a hash or short message using |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 540 | * an asymmetric public key in a secure element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 541 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 542 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 543 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 544 | * pair |
| 545 | * \param[in] alg A signature algorithm that is compatible with |
| 546 | * the type of `key` |
| 547 | * \param[in] p_hash The hash whose signature is to be verified |
| 548 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 549 | * \param[in] p_signature Buffer containing the signature to verify |
| 550 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
| 551 | * |
| 552 | * \retval PSA_SUCCESS |
| 553 | * The signature is valid. |
| 554 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 555 | typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv_context, |
| 556 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 557 | psa_algorithm_t alg, |
| 558 | const uint8_t *p_hash, |
| 559 | size_t hash_length, |
| 560 | const uint8_t *p_signature, |
| 561 | size_t signature_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 562 | |
| 563 | /** |
| 564 | * \brief A function that encrypts a short message with an asymmetric public |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 565 | * key in a secure element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 566 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 567 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 568 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 569 | * pair |
| 570 | * \param[in] alg An asymmetric encryption algorithm that is |
| 571 | * compatible with the type of `key` |
| 572 | * \param[in] p_input The message to encrypt |
| 573 | * \param[in] input_length Size of the `p_input` buffer in bytes |
| 574 | * \param[in] p_salt A salt or label, if supported by the |
| 575 | * encryption algorithm |
| 576 | * If the algorithm does not support a |
| 577 | * salt, pass `NULL`. |
| 578 | * If the algorithm supports an optional |
| 579 | * salt and you do not want to pass a salt, |
| 580 | * pass `NULL`. |
| 581 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 582 | * supported. |
| 583 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 584 | * If `p_salt` is `NULL`, pass 0. |
| 585 | * \param[out] p_output Buffer where the encrypted message is to |
| 586 | * be written |
| 587 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 588 | * \param[out] p_output_length On success, the number of bytes that make up |
| 589 | * the returned output |
| 590 | * |
| 591 | * \retval PSA_SUCCESS |
| 592 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 593 | typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context, |
| 594 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 595 | psa_algorithm_t alg, |
| 596 | const uint8_t *p_input, |
| 597 | size_t input_length, |
| 598 | const uint8_t *p_salt, |
| 599 | size_t salt_length, |
| 600 | uint8_t *p_output, |
| 601 | size_t output_size, |
| 602 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 603 | |
| 604 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 605 | * \brief A function that decrypts a short message with an asymmetric private |
| 606 | * key in a secure element. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 607 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 608 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 609 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 610 | * \param[in] alg An asymmetric encryption algorithm that is |
| 611 | * compatible with the type of `key` |
| 612 | * \param[in] p_input The message to decrypt |
| 613 | * \param[in] input_length Size of the `p_input` buffer in bytes |
| 614 | * \param[in] p_salt A salt or label, if supported by the |
| 615 | * encryption algorithm |
| 616 | * If the algorithm does not support a |
| 617 | * salt, pass `NULL`. |
| 618 | * If the algorithm supports an optional |
| 619 | * salt and you do not want to pass a salt, |
| 620 | * pass `NULL`. |
| 621 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 622 | * supported. |
| 623 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 624 | * If `p_salt` is `NULL`, pass 0. |
| 625 | * \param[out] p_output Buffer where the decrypted message is to |
| 626 | * be written |
| 627 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 628 | * \param[out] p_output_length On success, the number of bytes |
| 629 | * that make up the returned output |
| 630 | * |
| 631 | * \retval PSA_SUCCESS |
| 632 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 633 | typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context, |
| 634 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 635 | psa_algorithm_t alg, |
| 636 | const uint8_t *p_input, |
| 637 | size_t input_length, |
| 638 | const uint8_t *p_salt, |
| 639 | size_t salt_length, |
| 640 | uint8_t *p_output, |
| 641 | size_t output_size, |
| 642 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 643 | |
| 644 | /** |
| 645 | * \brief A struct containing all of the function pointers needed to implement |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 646 | * asymmetric cryptographic operations using secure elements. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 647 | * |
| 648 | * PSA Crypto API implementations should populate instances of the table as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 649 | * appropriate upon startup or at build time. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 650 | * |
| 651 | * If one of the functions is not implemented, it should be set to NULL. |
| 652 | */ |
| 653 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 654 | /** Function that performs an asymmetric sign operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 655 | psa_drv_se_asymmetric_sign_t p_sign; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 656 | /** Function that performs an asymmetric verify operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 657 | psa_drv_se_asymmetric_verify_t p_verify; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 658 | /** Function that performs an asymmetric encrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 659 | psa_drv_se_asymmetric_encrypt_t p_encrypt; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 660 | /** Function that performs an asymmetric decrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 661 | psa_drv_se_asymmetric_decrypt_t p_decrypt; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 662 | } psa_drv_se_asymmetric_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 663 | |
| 664 | /**@}*/ |
| 665 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 666 | /** \defgroup se_aead Secure Element Authenticated Encryption with Additional Data |
| 667 | * Authenticated Encryption with Additional Data (AEAD) operations with secure |
| 668 | * elements must be done in one function call. While this creates a burden for |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 669 | * implementers as there must be sufficient space in memory for the entire |
| 670 | * message, it prevents decrypted data from being made available before the |
| 671 | * authentication operation is complete and the data is known to be authentic. |
| 672 | */ |
| 673 | /**@{*/ |
| 674 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 675 | /** \brief A function that performs a secure element authenticated encryption |
| 676 | * operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 677 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 678 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 679 | * \param[in] key_slot Slot containing the key to use. |
| 680 | * \param[in] algorithm The AEAD algorithm to compute |
| 681 | * (\c PSA_ALG_XXX value such that |
| 682 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 683 | * \param[in] p_nonce Nonce or IV to use |
| 684 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 685 | * \param[in] p_additional_data Additional data that will be |
| 686 | * authenticated but not encrypted |
| 687 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 688 | * \param[in] p_plaintext Data that will be authenticated and |
| 689 | * encrypted |
| 690 | * \param[in] plaintext_length Size of `p_plaintext` in bytes |
| 691 | * \param[out] p_ciphertext Output buffer for the authenticated and |
| 692 | * encrypted data. The additional data is |
| 693 | * not part of this output. For algorithms |
| 694 | * where the encrypted data and the |
| 695 | * authentication tag are defined as |
| 696 | * separate outputs, the authentication |
| 697 | * tag is appended to the encrypted data. |
| 698 | * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in |
| 699 | * bytes |
| 700 | * \param[out] p_ciphertext_length On success, the size of the output in |
| 701 | * the `p_ciphertext` buffer |
| 702 | * |
| 703 | * \retval #PSA_SUCCESS |
| 704 | * Success. |
| 705 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 706 | typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t *drv_context, |
| 707 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 708 | psa_algorithm_t algorithm, |
| 709 | const uint8_t *p_nonce, |
| 710 | size_t nonce_length, |
| 711 | const uint8_t *p_additional_data, |
| 712 | size_t additional_data_length, |
| 713 | const uint8_t *p_plaintext, |
| 714 | size_t plaintext_length, |
| 715 | uint8_t *p_ciphertext, |
| 716 | size_t ciphertext_size, |
| 717 | size_t *p_ciphertext_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 718 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 719 | /** A function that peforms a secure element authenticated decryption operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 720 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 721 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 722 | * \param[in] key_slot Slot containing the key to use |
| 723 | * \param[in] algorithm The AEAD algorithm to compute |
| 724 | * (\c PSA_ALG_XXX value such that |
| 725 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 726 | * \param[in] p_nonce Nonce or IV to use |
| 727 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 728 | * \param[in] p_additional_data Additional data that has been |
| 729 | * authenticated but not encrypted |
| 730 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 731 | * \param[in] p_ciphertext Data that has been authenticated and |
| 732 | * encrypted. |
| 733 | * For algorithms where the encrypted data |
| 734 | * and the authentication tag are defined |
| 735 | * as separate inputs, the buffer must |
| 736 | * contain the encrypted data followed by |
| 737 | * the authentication tag. |
| 738 | * \param[in] ciphertext_length Size of `p_ciphertext` in bytes |
| 739 | * \param[out] p_plaintext Output buffer for the decrypted data |
| 740 | * \param[in] plaintext_size Size of the `p_plaintext` buffer in |
| 741 | * bytes |
| 742 | * \param[out] p_plaintext_length On success, the size of the output in |
| 743 | * the `p_plaintext` buffer |
| 744 | * |
| 745 | * \retval #PSA_SUCCESS |
| 746 | * Success. |
| 747 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 748 | typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t *drv_context, |
| 749 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 750 | psa_algorithm_t algorithm, |
| 751 | const uint8_t *p_nonce, |
| 752 | size_t nonce_length, |
| 753 | const uint8_t *p_additional_data, |
| 754 | size_t additional_data_length, |
| 755 | const uint8_t *p_ciphertext, |
| 756 | size_t ciphertext_length, |
| 757 | uint8_t *p_plaintext, |
| 758 | size_t plaintext_size, |
| 759 | size_t *p_plaintext_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 760 | |
| 761 | /** |
| 762 | * \brief A struct containing all of the function pointers needed to implement |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 763 | * secure element Authenticated Encryption with Additional Data operations |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 764 | * |
| 765 | * PSA Crypto API implementations should populate instances of the table as |
| 766 | * appropriate upon startup. |
| 767 | * |
| 768 | * If one of the functions is not implemented, it should be set to NULL. |
| 769 | */ |
| 770 | typedef struct { |
| 771 | /** Function that performs the AEAD encrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 772 | psa_drv_se_aead_encrypt_t p_encrypt; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 773 | /** Function that performs the AEAD decrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 774 | psa_drv_se_aead_decrypt_t p_decrypt; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 775 | } psa_drv_se_aead_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 776 | /**@}*/ |
| 777 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 778 | /** \defgroup se_key_management Secure Element Key Management |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 779 | * Currently, key management is limited to importing keys in the clear, |
| 780 | * destroying keys, and exporting keys in the clear. |
| 781 | * Whether a key may be exported is determined by the key policies in place |
| 782 | * on the key slot. |
| 783 | */ |
| 784 | /**@{*/ |
| 785 | |
Gilles Peskine | f2223c8 | 2019-07-12 23:33:02 +0200 | [diff] [blame] | 786 | /* This type is documented in crypto.h. As far as drivers are concerned, |
| 787 | * this is an opaque type. */ |
| 788 | typedef struct psa_key_attributes_s psa_key_attributes_t; |
| 789 | |
| 790 | /** \brief A function that allocates a slot for a key. |
| 791 | * |
| 792 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 94cc42c | 2019-07-12 23:34:20 +0200 | [diff] [blame^] | 793 | * \param[in,out] persistent_data A pointer to the persistent data |
| 794 | * that allows writing. |
Gilles Peskine | f2223c8 | 2019-07-12 23:33:02 +0200 | [diff] [blame] | 795 | * \param[in] attributes Attributes of the key. |
| 796 | * \param[out] key_slot Slot where the key will be stored. |
| 797 | * This must be a valid slot for a key of the |
| 798 | * chosen type. It must be unoccupied. |
| 799 | * |
| 800 | * \retval #PSA_SUCCESS |
| 801 | * Success. |
| 802 | * The core will record \c *key_slot as the key slot where the key |
| 803 | * is stored and will update the persistent data in storage. |
| 804 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 805 | * \retval #PSA_ERROR_INSUFFICIENT_STORAGE |
| 806 | */ |
| 807 | typedef psa_status_t (*psa_drv_se_allocate_key_t)( |
| 808 | psa_drv_se_context_t *drv_context, |
Gilles Peskine | 94cc42c | 2019-07-12 23:34:20 +0200 | [diff] [blame^] | 809 | void *persistent_data, |
Gilles Peskine | f2223c8 | 2019-07-12 23:33:02 +0200 | [diff] [blame] | 810 | const psa_key_attributes_t *attributes, |
| 811 | psa_key_slot_number_t *key_slot); |
| 812 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 813 | /** \brief A function that imports a key into a secure element in binary format |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 814 | * |
| 815 | * This function can support any output from psa_export_key(). Refer to the |
| 816 | * documentation of psa_export_key() for the format for each key type. |
| 817 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 818 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 819 | * \param[in] key_slot Slot where the key will be stored |
| 820 | * This must be a valid slot for a key of the chosen |
| 821 | * type. It must be unoccupied. |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 822 | * \param[in] lifetime The required lifetime of the key storage |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 823 | * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value) |
| 824 | * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value) |
| 825 | * \param[in] usage The allowed uses of the key |
| 826 | * \param[in] p_data Buffer containing the key data |
| 827 | * \param[in] data_length Size of the `data` buffer in bytes |
| 828 | * |
| 829 | * \retval #PSA_SUCCESS |
| 830 | * Success. |
| 831 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 832 | typedef psa_status_t (*psa_drv_se_import_key_t)(psa_drv_se_context_t *drv_context, |
| 833 | psa_key_slot_number_t key_slot, |
Derek Miller | 0972fe5 | 2019-02-15 17:08:27 -0600 | [diff] [blame] | 834 | psa_key_lifetime_t lifetime, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 835 | psa_key_type_t type, |
| 836 | psa_algorithm_t algorithm, |
| 837 | psa_key_usage_t usage, |
| 838 | const uint8_t *p_data, |
| 839 | size_t data_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 840 | |
| 841 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 842 | * \brief A function that destroys a secure element key and restore the slot to |
| 843 | * its default state |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 844 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 845 | * This function destroys the content of the key from a secure element. |
| 846 | * Implementations shall make a best effort to ensure that any previous content |
| 847 | * of the slot is unrecoverable. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 848 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 849 | * This function returns the specified slot to its default state. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 850 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 851 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 94cc42c | 2019-07-12 23:34:20 +0200 | [diff] [blame^] | 852 | * \param[in,out] persistent_data A pointer to the persistent data |
| 853 | * that allows writing. |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 854 | * \param key_slot The key slot to erase. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 855 | * |
| 856 | * \retval #PSA_SUCCESS |
| 857 | * The slot's content, if any, has been erased. |
| 858 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 859 | typedef psa_status_t (*psa_drv_se_destroy_key_t)( |
| 860 | psa_drv_se_context_t *drv_context, |
Gilles Peskine | 94cc42c | 2019-07-12 23:34:20 +0200 | [diff] [blame^] | 861 | void *persistent_data, |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 862 | psa_key_slot_number_t key_slot); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 863 | |
| 864 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 865 | * \brief A function that exports a secure element key in binary format |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 866 | * |
| 867 | * The output of this function can be passed to psa_import_key() to |
| 868 | * create an equivalent object. |
| 869 | * |
| 870 | * If a key is created with `psa_import_key()` and then exported with |
| 871 | * this function, it is not guaranteed that the resulting data is |
| 872 | * identical: the implementation may choose a different representation |
| 873 | * of the same key if the format permits it. |
| 874 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 875 | * This function should generate output in the same format that |
| 876 | * `psa_export_key()` does. Refer to the |
| 877 | * documentation of `psa_export_key()` for the format for each key type. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 878 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 879 | * \param[in,out] drv_context The driver context structure. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 880 | * \param[in] key Slot whose content is to be exported. This must |
| 881 | * be an occupied key slot. |
| 882 | * \param[out] p_data Buffer where the key data is to be written. |
| 883 | * \param[in] data_size Size of the `p_data` buffer in bytes. |
| 884 | * \param[out] p_data_length On success, the number of bytes |
| 885 | * that make up the key data. |
| 886 | * |
| 887 | * \retval #PSA_SUCCESS |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 888 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 889 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 890 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 891 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 892 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
Gilles Peskine | 4b3eb69 | 2019-05-16 21:35:18 +0200 | [diff] [blame] | 893 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 894 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 895 | typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context, |
| 896 | psa_key_slot_number_t key, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 897 | uint8_t *p_data, |
| 898 | size_t data_size, |
| 899 | size_t *p_data_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 900 | |
| 901 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 902 | * \brief A function that generates a symmetric or asymmetric key on a secure |
| 903 | * element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 904 | * |
Gilles Peskine | e5c025c | 2019-03-06 18:01:43 +0100 | [diff] [blame] | 905 | * If \p type is asymmetric (`#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) == 1`), |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 906 | * the public component of the generated key will be placed in `p_pubkey_out`. |
| 907 | * The format of the public key information will match the format specified for |
Gilles Peskine | e5c025c | 2019-03-06 18:01:43 +0100 | [diff] [blame] | 908 | * the psa_export_key() function for the key type. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 909 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 910 | * \param[in,out] drv_context The driver context structure. |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 911 | * \param[in] key_slot Slot where the generated key will be placed |
| 912 | * \param[in] type The type of the key to be generated |
| 913 | * \param[in] usage The prescribed usage of the generated key |
Gilles Peskine | c3044a6 | 2019-03-06 17:56:28 +0100 | [diff] [blame] | 914 | * Note: Not all Secure Elements support the same |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 915 | * restrictions that PSA Crypto does (and vice versa). |
| 916 | * Driver developers should endeavor to match the |
| 917 | * usages as close as possible. |
| 918 | * \param[in] bits The size in bits of the key to be generated. |
| 919 | * \param[in] extra Extra parameters for key generation. The |
| 920 | * interpretation of this parameter should match the |
| 921 | * interpretation in the `extra` parameter is the |
Gilles Peskine | 35ef36b | 2019-05-16 19:42:05 +0200 | [diff] [blame] | 922 | * `psa_generate_key` function |
Gilles Peskine | e5c025c | 2019-03-06 18:01:43 +0100 | [diff] [blame] | 923 | * \param[in] extra_size The size in bytes of the \p extra buffer |
Gilles Peskine | c3044a6 | 2019-03-06 17:56:28 +0100 | [diff] [blame] | 924 | * \param[out] p_pubkey_out The buffer where the public key information will |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 925 | * be placed |
| 926 | * \param[in] pubkey_out_size The size in bytes of the `p_pubkey_out` buffer |
| 927 | * \param[out] p_pubkey_length Upon successful completion, will contain the |
| 928 | * size of the data placed in `p_pubkey_out`. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 929 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 930 | typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_drv_se_context_t *drv_context, |
| 931 | psa_key_slot_number_t key_slot, |
Gilles Peskine | 32668ce | 2019-03-06 18:29:57 +0100 | [diff] [blame] | 932 | psa_key_type_t type, |
| 933 | psa_key_usage_t usage, |
| 934 | size_t bits, |
| 935 | const void *extra, |
| 936 | size_t extra_size, |
| 937 | uint8_t *p_pubkey_out, |
| 938 | size_t pubkey_out_size, |
| 939 | size_t *p_pubkey_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 940 | |
| 941 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 942 | * \brief A struct containing all of the function pointers needed to for secure |
| 943 | * element key management |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 944 | * |
| 945 | * PSA Crypto API implementations should populate instances of the table as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 946 | * appropriate upon startup or at build time. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 947 | * |
| 948 | * If one of the functions is not implemented, it should be set to NULL. |
| 949 | */ |
| 950 | typedef struct { |
Gilles Peskine | f2223c8 | 2019-07-12 23:33:02 +0200 | [diff] [blame] | 951 | /** Function that allocates a slot. */ |
| 952 | psa_drv_se_allocate_key_t p_allocate; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 953 | /** Function that performs a key import operation */ |
| 954 | psa_drv_se_import_key_t p_import; |
| 955 | /** Function that performs a generation */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 956 | psa_drv_se_generate_key_t p_generate; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 957 | /** Function that performs a key destroy operation */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 958 | psa_drv_se_destroy_key_t p_destroy; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 959 | /** Function that performs a key export operation */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 960 | psa_drv_se_export_key_t p_export; |
Gilles Peskine | e62b74e | 2019-06-25 15:25:09 +0200 | [diff] [blame] | 961 | /** Function that performs a public key export operation */ |
| 962 | psa_drv_se_export_key_t p_export_public; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 963 | } psa_drv_se_key_management_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 964 | |
| 965 | /**@}*/ |
| 966 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 967 | /** \defgroup driver_derivation Secure Element Key Derivation and Agreement |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 968 | * Key derivation is the process of generating new key material using an |
| 969 | * existing key and additional parameters, iterating through a basic |
| 970 | * cryptographic function, such as a hash. |
| 971 | * Key agreement is a part of cryptographic protocols that allows two parties |
| 972 | * to agree on the same key value, but starting from different original key |
| 973 | * material. |
| 974 | * The flows are similar, and the PSA Crypto Driver Model uses the same functions |
| 975 | * for both of the flows. |
| 976 | * |
| 977 | * There are two different final functions for the flows, |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 978 | * `psa_drv_se_key_derivation_derive` and `psa_drv_se_key_derivation_export`. |
| 979 | * `psa_drv_se_key_derivation_derive` is used when the key material should be |
| 980 | * placed in a slot on the hardware and not exposed to the caller. |
| 981 | * `psa_drv_se_key_derivation_export` is used when the key material should be |
| 982 | * returned to the PSA Cryptographic API implementation. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 983 | * |
| 984 | * Different key derivation algorithms require a different number of inputs. |
| 985 | * Instead of having an API that takes as input variable length arrays, which |
| 986 | * can be problemmatic to manage on embedded platforms, the inputs are passed |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 987 | * to the driver via a function, `psa_drv_se_key_derivation_collateral`, that |
| 988 | * is called multiple times with different `collateral_id`s. Thus, for a key |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 989 | * derivation algorithm that required 3 paramter inputs, the flow would look |
| 990 | * something like: |
| 991 | * ~~~~~~~~~~~~~{.c} |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 992 | * psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes); |
| 993 | * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_0, |
| 994 | * p_collateral_0, |
| 995 | * collateral_0_size); |
| 996 | * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_1, |
| 997 | * p_collateral_1, |
| 998 | * collateral_1_size); |
| 999 | * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_2, |
| 1000 | * p_collateral_2, |
| 1001 | * collateral_2_size); |
| 1002 | * psa_drv_se_key_derivation_derive(); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1003 | * ~~~~~~~~~~~~~ |
| 1004 | * |
| 1005 | * key agreement example: |
| 1006 | * ~~~~~~~~~~~~~{.c} |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1007 | * psa_drv_se_key_derivation_setup(alg, source_key. dest_key_size_bytes); |
| 1008 | * psa_drv_se_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size); |
| 1009 | * psa_drv_se_key_derivation_export(p_session_key, |
| 1010 | * session_key_size, |
| 1011 | * &session_key_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1012 | * ~~~~~~~~~~~~~ |
| 1013 | */ |
| 1014 | /**@{*/ |
| 1015 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1016 | /** \brief A function that Sets up a secure element key derivation operation by |
| 1017 | * specifying the algorithm and the source key sot |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1018 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1019 | * \param[in,out] drv_context The driver context structure. |
| 1020 | * \param[in,out] op_context A hardware-specific structure containing any |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1021 | * context information for the implementation |
| 1022 | * \param[in] kdf_alg The algorithm to be used for the key derivation |
Gilles Peskine | 45a8ca3 | 2019-06-24 15:08:56 +0200 | [diff] [blame] | 1023 | * \param[in] source_key The key to be used as the source material for the |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1024 | * key derivation |
| 1025 | * |
| 1026 | * \retval PSA_SUCCESS |
| 1027 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1028 | typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context, |
| 1029 | void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 1030 | psa_algorithm_t kdf_alg, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 1031 | psa_key_slot_number_t source_key); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1032 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1033 | /** \brief A function that provides collateral (parameters) needed for a secure |
| 1034 | * element key derivation or key agreement operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1035 | * |
| 1036 | * Since many key derivation algorithms require multiple parameters, it is |
| 1037 | * expeced that this function may be called multiple times for the same |
| 1038 | * operation, each with a different algorithm-specific `collateral_id` |
| 1039 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1040 | * \param[in,out] op_context A hardware-specific structure containing any |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1041 | * context information for the implementation |
| 1042 | * \param[in] collateral_id An ID for the collateral being provided |
| 1043 | * \param[in] p_collateral A buffer containing the collateral data |
| 1044 | * \param[in] collateral_size The size in bytes of the collateral |
| 1045 | * |
| 1046 | * \retval PSA_SUCCESS |
| 1047 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1048 | typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 1049 | uint32_t collateral_id, |
| 1050 | const uint8_t *p_collateral, |
| 1051 | size_t collateral_size); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1052 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1053 | /** \brief A function that performs the final secure element key derivation |
| 1054 | * step and place the generated key material in a slot |
Gilles Peskine | c3044a6 | 2019-03-06 17:56:28 +0100 | [diff] [blame] | 1055 | * |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1056 | * \param[in,out] op_context A hardware-specific structure containing any |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1057 | * context information for the implementation |
| 1058 | * \param[in] dest_key The slot where the generated key material |
| 1059 | * should be placed |
| 1060 | * |
| 1061 | * \retval PSA_SUCCESS |
| 1062 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1063 | typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context, |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 1064 | psa_key_slot_number_t dest_key); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1065 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1066 | /** \brief A function that performs the final step of a secure element key |
| 1067 | * agreement and place the generated key material in a buffer |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1068 | * |
| 1069 | * \param[out] p_output Buffer in which to place the generated key |
| 1070 | * material |
| 1071 | * \param[in] output_size The size in bytes of `p_output` |
| 1072 | * \param[out] p_output_length Upon success, contains the number of bytes of |
| 1073 | * key material placed in `p_output` |
| 1074 | * |
| 1075 | * \retval PSA_SUCCESS |
| 1076 | */ |
Gilles Peskine | 8597bc1 | 2019-07-12 23:28:46 +0200 | [diff] [blame] | 1077 | typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context, |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 1078 | uint8_t *p_output, |
| 1079 | size_t output_size, |
| 1080 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1081 | |
| 1082 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1083 | * \brief A struct containing all of the function pointers needed to for secure |
| 1084 | * element key derivation and agreement |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1085 | * |
| 1086 | * PSA Crypto API implementations should populate instances of the table as |
| 1087 | * appropriate upon startup. |
| 1088 | * |
| 1089 | * If one of the functions is not implemented, it should be set to NULL. |
| 1090 | */ |
| 1091 | typedef struct { |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 1092 | /** The driver-specific size of the key derivation context */ |
| 1093 | size_t context_size; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1094 | /** Function that performs a key derivation setup */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 1095 | psa_drv_se_key_derivation_setup_t p_setup; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1096 | /** Function that sets key derivation collateral */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 1097 | psa_drv_se_key_derivation_collateral_t p_collateral; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1098 | /** Function that performs a final key derivation step */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 1099 | psa_drv_se_key_derivation_derive_t p_derive; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame] | 1100 | /** Function that perforsm a final key derivation or agreement and |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1101 | * exports the key */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 1102 | psa_drv_se_key_derivation_export_t p_export; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 1103 | } psa_drv_se_key_derivation_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1104 | |
| 1105 | /**@}*/ |
| 1106 | |
Gilles Peskine | b6cadea | 2019-06-24 13:46:37 +0200 | [diff] [blame] | 1107 | /** \defgroup se_registration Secure element driver registration |
| 1108 | */ |
| 1109 | /**@{*/ |
| 1110 | |
| 1111 | /** A structure containing pointers to all the entry points of a |
| 1112 | * secure element driver. |
| 1113 | * |
| 1114 | * Future versions of this specification may add extra substructures at |
| 1115 | * the end of this structure. |
| 1116 | */ |
| 1117 | typedef struct { |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1118 | /** The version of the driver HAL that this driver implements. |
| 1119 | * This is a protection against loading driver binaries built against |
Gilles Peskine | b6cadea | 2019-06-24 13:46:37 +0200 | [diff] [blame] | 1120 | * a different version of this specification. |
| 1121 | * Use #PSA_DRV_SE_HAL_VERSION. |
| 1122 | */ |
| 1123 | uint32_t hal_version; |
Gilles Peskine | 7a86da1 | 2019-07-12 23:25:38 +0200 | [diff] [blame] | 1124 | |
| 1125 | /** The size of the driver's persistent data in bytes. */ |
| 1126 | size_t persistent_data_size; |
| 1127 | |
| 1128 | /** The driver initialization function. |
| 1129 | * |
| 1130 | * This function is called once during the initialization of the |
| 1131 | * PSA Cryptography subsystem, before any other function of the |
| 1132 | * driver is called. If this function returns a failure status, |
| 1133 | * the driver will be unusable, at least until the next system reset. |
| 1134 | * |
| 1135 | * If this field is \c NULL, it is equivalent to a function that does |
| 1136 | * nothing and returns #PSA_SUCCESS. |
| 1137 | */ |
| 1138 | psa_drv_se_init_t p_init; |
| 1139 | |
Gilles Peskine | 6e59c42 | 2019-06-26 19:06:52 +0200 | [diff] [blame] | 1140 | const psa_drv_se_key_management_t *key_management; |
| 1141 | const psa_drv_se_mac_t *mac; |
| 1142 | const psa_drv_se_cipher_t *cipher; |
| 1143 | const psa_drv_se_aead_t *aead; |
| 1144 | const psa_drv_se_asymmetric_t *asymmetric; |
| 1145 | const psa_drv_se_key_derivation_t *derivation; |
Gilles Peskine | b6cadea | 2019-06-24 13:46:37 +0200 | [diff] [blame] | 1146 | } psa_drv_se_t; |
| 1147 | |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1148 | /** The current version of the secure element driver HAL. |
Gilles Peskine | b6cadea | 2019-06-24 13:46:37 +0200 | [diff] [blame] | 1149 | */ |
| 1150 | /* 0.0.0 patchlevel 5 */ |
| 1151 | #define PSA_DRV_SE_HAL_VERSION 0x00000005 |
| 1152 | |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1153 | /** Register an external cryptoprocessor (secure element) driver. |
Gilles Peskine | d910e92 | 2019-06-24 13:47:07 +0200 | [diff] [blame] | 1154 | * |
| 1155 | * This function is only intended to be used by driver code, not by |
| 1156 | * application code. In implementations with separation between the |
| 1157 | * PSA cryptography module and applications, this function should |
| 1158 | * only be available to callers that run in the same memory space as |
| 1159 | * the cryptography module, and should not be exposed to applications |
| 1160 | * running in a different memory space. |
| 1161 | * |
| 1162 | * This function may be called before psa_crypto_init(). It is |
| 1163 | * implementation-defined whether this function may be called |
| 1164 | * after psa_crypto_init(). |
| 1165 | * |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1166 | * \note Implementations store metadata about keys including the lifetime |
| 1167 | * value. Therefore, from one instantiation of the PSA Cryptography |
| 1168 | * library to the next one, if there is a key in storage with a certain |
| 1169 | * lifetime value, you must always register the same driver (or an |
| 1170 | * updated version that communicates with the same secure element) |
| 1171 | * with the same lifetime value. |
| 1172 | * |
Gilles Peskine | d910e92 | 2019-06-24 13:47:07 +0200 | [diff] [blame] | 1173 | * \param lifetime The lifetime value through which this driver will |
| 1174 | * be exposed to applications. |
| 1175 | * The values #PSA_KEY_LIFETIME_VOLATILE and |
| 1176 | * #PSA_KEY_LIFETIME_PERSISTENT are reserved and |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1177 | * may not be used for drivers. Implementations |
Gilles Peskine | d910e92 | 2019-06-24 13:47:07 +0200 | [diff] [blame] | 1178 | * may reserve other values. |
| 1179 | * \param[in] methods The method table of the driver. This structure must |
| 1180 | * remain valid for as long as the cryptography |
| 1181 | * module keeps running. It is typically a global |
| 1182 | * constant. |
| 1183 | * |
| 1184 | * \return PSA_SUCCESS |
| 1185 | * The driver was successfully registered. Applications can now |
| 1186 | * use \p lifetime to access keys through the methods passed to |
| 1187 | * this function. |
| 1188 | * \return PSA_ERROR_BAD_STATE |
| 1189 | * This function was called after the initialization of the |
| 1190 | * cryptography module, and this implementation does not support |
| 1191 | * driver registration at this stage. |
| 1192 | * \return PSA_ERROR_ALREADY_EXISTS |
| 1193 | * There is already a registered driver for this value of \p lifetime. |
| 1194 | * \return PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1195 | * \p lifetime is a reserved value. |
Gilles Peskine | d910e92 | 2019-06-24 13:47:07 +0200 | [diff] [blame] | 1196 | * \return PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | c93a43b | 2019-06-26 11:21:41 +0200 | [diff] [blame] | 1197 | * `methods->hal_version` is not supported by this implementation. |
Gilles Peskine | d910e92 | 2019-06-24 13:47:07 +0200 | [diff] [blame] | 1198 | * \return PSA_ERROR_INSUFFICIENT_MEMORY |
| 1199 | * \return PSA_ERROR_NOT_PERMITTED |
| 1200 | */ |
| 1201 | psa_status_t psa_register_se_driver( |
| 1202 | psa_key_lifetime_t lifetime, |
| 1203 | const psa_drv_se_t *methods); |
| 1204 | |
Gilles Peskine | b6cadea | 2019-06-24 13:46:37 +0200 | [diff] [blame] | 1205 | /**@}*/ |
| 1206 | |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1207 | #ifdef __cplusplus |
| 1208 | } |
| 1209 | #endif |
| 1210 | |
| 1211 | #endif /* PSA_CRYPTO_SE_DRIVER_H */ |