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