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