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 | * |
| 11 | * This file is part of the PSA Crypto Driver Model, containing functions for |
| 12 | * driver developers to implement to enable hardware to be called in a |
| 13 | * standardized way by a PSA Cryptographic API implementation. The functions |
| 14 | * comprising the driver model, which driver authors implement, are not |
| 15 | * intended to be called by application developers. |
| 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 | |
| 43 | /** An internal designation of a key slot between the core part of the |
| 44 | * PSA Crypto implementation and the driver. The meaning of this value |
| 45 | * is driver-dependent. */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 46 | typedef uint32_t psa_key_slot_number_t; // TODO: Change this to psa_key_slot_t after psa_key_slot_t is removed from Mbed crypto |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 47 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 48 | /** \defgroup se_mac Secure Element Message Authentication Codes |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 49 | * Generation and authentication of Message Authentication Codes (MACs) using |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 50 | * a secure element can be done either as a single function call (via the |
| 51 | * `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] | 52 | * parts using the following sequence: |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 53 | * - `psa_drv_se_mac_setup_t` |
| 54 | * - `psa_drv_se_mac_update_t` |
| 55 | * - `psa_drv_se_mac_update_t` |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 56 | * - ... |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 57 | * - `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] | 58 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 59 | * If a previously started secure element MAC operation needs to be terminated, |
| 60 | * 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] | 61 | * result in allocated resources not being freed or in other undefined |
| 62 | * behavior. |
| 63 | */ |
| 64 | /**@{*/ |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 65 | /** \brief A function that starts a secure element MAC operation for a PSA |
| 66 | * Crypto Driver implementation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 67 | * |
| 68 | * \param[in,out] p_context A structure that will contain the |
| 69 | * hardware-specific MAC context |
| 70 | * \param[in] key_slot The slot of the key to be used for the |
| 71 | * operation |
| 72 | * \param[in] algorithm The algorithm to be used to underly the MAC |
| 73 | * operation |
| 74 | * |
| 75 | * \retval PSA_SUCCESS |
| 76 | * Success. |
| 77 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 78 | typedef psa_status_t (*psa_drv_se_mac_setup_t)(void *p_context, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 79 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 80 | psa_algorithm_t algorithm); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 81 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 82 | /** \brief A function that continues a previously started secure element MAC |
| 83 | * operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 84 | * |
| 85 | * \param[in,out] p_context A hardware-specific structure for the |
| 86 | * previously-established MAC operation to be |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 87 | * updated |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 88 | * \param[in] p_input A buffer containing the message to be appended |
| 89 | * to the MAC operation |
| 90 | * \param[in] input_length The size in bytes of the input message buffer |
| 91 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 92 | typedef psa_status_t (*psa_drv_se_mac_update_t)(void *p_context, |
| 93 | const uint8_t *p_input, |
| 94 | size_t input_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 95 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 96 | /** \brief a function that completes a previously started secure element MAC |
| 97 | * operation by returning the resulting MAC. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 98 | * |
| 99 | * \param[in,out] p_context A hardware-specific structure for the |
| 100 | * previously started MAC operation to be |
| 101 | * finished |
| 102 | * \param[out] p_mac A buffer where the generated MAC will be |
| 103 | * placed |
| 104 | * \param[in] mac_size The size in bytes of the buffer that has been |
| 105 | * allocated for the `output` buffer |
| 106 | * \param[out] p_mac_length After completion, will contain the number of |
| 107 | * bytes placed in the `p_mac` buffer |
| 108 | * |
| 109 | * \retval PSA_SUCCESS |
| 110 | * Success. |
| 111 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 112 | typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *p_context, |
| 113 | uint8_t *p_mac, |
| 114 | size_t mac_size, |
| 115 | size_t *p_mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 116 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 117 | /** \brief A function that completes a previously started secure element MAC |
| 118 | * operation by comparing the resulting MAC against a provided value |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 119 | * |
| 120 | * \param[in,out] p_context A hardware-specific structure for the previously |
| 121 | * started MAC operation to be fiinished |
| 122 | * \param[in] p_mac The MAC value against which the resulting MAC will |
| 123 | * be compared against |
| 124 | * \param[in] mac_length The size in bytes of the value stored in `p_mac` |
| 125 | * |
| 126 | * \retval PSA_SUCCESS |
| 127 | * The operation completed successfully and the MACs matched each |
| 128 | * other |
| 129 | * \retval PSA_ERROR_INVALID_SIGNATURE |
| 130 | * The operation completed successfully, but the calculated MAC did |
| 131 | * not match the provided MAC |
| 132 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 133 | typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *p_context, |
| 134 | const uint8_t *p_mac, |
| 135 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 136 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 137 | /** \brief A function that aborts a previous started secure element MAC |
| 138 | * operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 139 | |
| 140 | * \param[in,out] p_context A hardware-specific structure for the previously |
| 141 | * started MAC operation to be aborted |
| 142 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 143 | typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *p_context); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 144 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 145 | /** \brief A function that performs a secure element MAC operation in one |
| 146 | * command and returns the calculated MAC |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 147 | * |
| 148 | * \param[in] p_input A buffer containing the message to be MACed |
| 149 | * \param[in] input_length The size in bytes of `p_input` |
| 150 | * \param[in] key_slot The slot of the key to be used |
| 151 | * \param[in] alg The algorithm to be used to underlie the MAC |
| 152 | * operation |
| 153 | * \param[out] p_mac A buffer where the generated MAC will be |
| 154 | * placed |
| 155 | * \param[in] mac_size The size in bytes of the `p_mac` buffer |
| 156 | * \param[out] p_mac_length After completion, will contain the number of |
| 157 | * bytes placed in the `output` buffer |
| 158 | * |
| 159 | * \retval PSA_SUCCESS |
| 160 | * Success. |
| 161 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 162 | typedef psa_status_t (*psa_drv_se_mac_generate_t)(const uint8_t *p_input, |
| 163 | size_t input_length, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 164 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 165 | psa_algorithm_t alg, |
| 166 | uint8_t *p_mac, |
| 167 | size_t mac_size, |
| 168 | size_t *p_mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 169 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 170 | /** \brief A function that performs a secure element MAC operation in one |
| 171 | * command and compares the resulting MAC against a provided value |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 172 | * |
| 173 | * \param[in] p_input A buffer containing the message to be MACed |
| 174 | * \param[in] input_length The size in bytes of `input` |
| 175 | * \param[in] key_slot The slot of the key to be used |
| 176 | * \param[in] alg The algorithm to be used to underlie the MAC |
| 177 | * operation |
| 178 | * \param[in] p_mac The MAC value against which the resulting MAC will |
| 179 | * be compared against |
| 180 | * \param[in] mac_length The size in bytes of `mac` |
| 181 | * |
| 182 | * \retval PSA_SUCCESS |
| 183 | * The operation completed successfully and the MACs matched each |
| 184 | * other |
| 185 | * \retval PSA_ERROR_INVALID_SIGNATURE |
| 186 | * The operation completed successfully, but the calculated MAC did |
| 187 | * not match the provided MAC |
| 188 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 189 | typedef psa_status_t (*psa_drv_se_mac_verify_t)(const uint8_t *p_input, |
| 190 | size_t input_length, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 191 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 192 | psa_algorithm_t alg, |
| 193 | const uint8_t *p_mac, |
| 194 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 195 | |
| 196 | /** \brief A struct containing all of the function pointers needed to |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 197 | * perform secure element MAC operations |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 198 | * |
| 199 | * PSA Crypto API implementations should populate the table as appropriate |
| 200 | * upon startup. |
| 201 | * |
| 202 | * If one of the functions is not implemented (such as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 203 | * `psa_drv_se_mac_generate_t`), it should be set to NULL. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 204 | * |
| 205 | * Driver implementers should ensure that they implement all of the functions |
| 206 | * that make sense for their hardware, and that they provide a full solution |
| 207 | * (for example, if they support `p_setup`, they should also support |
| 208 | * `p_update` and at least one of `p_finish` or `p_finish_verify`). |
| 209 | * |
| 210 | */ |
| 211 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 212 | /**The size in bytes of the hardware-specific secure element MAC context |
| 213 | * structure |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 214 | */ |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 215 | size_t context_size; |
| 216 | /** Function that performs a MAC setup operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 217 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 218 | psa_drv_se_mac_setup_t p_setup; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 219 | /** Function that performs a MAC update operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 220 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 221 | psa_drv_se_mac_update_t p_update; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 222 | /** Function that completes a MAC operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 223 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 224 | psa_drv_se_mac_finish_t p_finish; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 225 | /** Function that completes a MAC operation with a verify check |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 226 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 227 | psa_drv_se_mac_finish_verify_t p_finish_verify; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 228 | /** Function that aborts a previoustly started MAC operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 229 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 230 | psa_drv_se_mac_abort_t p_abort; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 231 | /** Function that performs a MAC operation in one call |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 232 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 233 | psa_drv_se_mac_generate_t p_mac; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 234 | /** Function that performs a MAC and verify operation in one call |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 235 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 236 | psa_drv_se_mac_verify_t p_mac_verify; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 237 | } psa_drv_se_mac_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 238 | /**@}*/ |
| 239 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 240 | /** \defgroup se_cipher Secure Element Symmetric Ciphers |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 241 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 242 | * Encryption and Decryption using secure element keys in block modes other |
| 243 | * than ECB must be done in multiple parts, using the following flow: |
| 244 | * - `psa_drv_se_cipher_setup_t` |
| 245 | * - `psa_drv_se_cipher_set_iv_t` (optional depending upon block mode) |
| 246 | * - `psa_drv_se_cipher_update_t` |
| 247 | * - `psa_drv_se_cipher_update_t` |
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 | * - `psa_drv_se_cipher_finish_t` |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 250 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 251 | * If a previously started secure element Cipher operation needs to be |
| 252 | * terminated, it should be done so by the `psa_drv_se_cipher_abort_t`. Failure |
| 253 | * to do so may result in allocated resources not being freed or in other |
| 254 | * undefined behavior. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 255 | * |
| 256 | * In situations where a PSA Cryptographic API implementation is using a block |
| 257 | * mode not-supported by the underlying hardware or driver, it can construct |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 258 | * the block mode itself, while calling the `psa_drv_se_cipher_ecb_t` function |
| 259 | * for the cipher operations. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 260 | */ |
| 261 | /**@{*/ |
| 262 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 263 | /** \brief A function that provides the cipher setup function for a |
| 264 | * secure element driver |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 265 | * |
| 266 | * \param[in,out] p_context A structure that will contain the |
| 267 | * hardware-specific cipher context. |
| 268 | * \param[in] key_slot The slot of the key to be used for the |
| 269 | * operation |
| 270 | * \param[in] algorithm The algorithm to be used in the cipher |
| 271 | * operation |
| 272 | * \param[in] direction Indicates whether the operation is an encrypt |
| 273 | * or decrypt |
| 274 | * |
| 275 | * \retval PSA_SUCCESS |
| 276 | * \retval PSA_ERROR_NOT_SUPPORTED |
| 277 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 278 | typedef psa_status_t (*psa_drv_se_cipher_setup_t)(void *p_context, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 279 | psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 280 | psa_algorithm_t algorithm, |
| 281 | psa_encrypt_or_decrypt_t direction); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 282 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 283 | /** \brief A function that sets the initialization vector (if |
| 284 | * necessary) for an secure element cipher operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 285 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 286 | * Rationale: The `psa_se_cipher_*` operation in the PSA Cryptographic API has |
| 287 | * 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] | 288 | * generate function is not necessary for the drivers to implement as the PSA |
| 289 | * Crypto implementation can do the generation using its RNG features. |
| 290 | * |
| 291 | * \param[in,out] p_context A structure that contains the previously set up |
| 292 | * hardware-specific cipher context |
| 293 | * \param[in] p_iv A buffer containing the initialization vector |
| 294 | * \param[in] iv_length The size (in bytes) of the `p_iv` buffer |
| 295 | * |
| 296 | * \retval PSA_SUCCESS |
| 297 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 298 | typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *p_context, |
| 299 | const uint8_t *p_iv, |
| 300 | size_t iv_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 301 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 302 | /** \brief A function that continues a previously started secure element cipher |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 303 | * operation |
| 304 | * |
| 305 | * \param[in,out] p_context A hardware-specific structure for the |
| 306 | * previously started cipher operation |
| 307 | * \param[in] p_input A buffer containing the data to be |
| 308 | * encrypted/decrypted |
| 309 | * \param[in] input_size The size in bytes of the buffer pointed to |
| 310 | * by `p_input` |
| 311 | * \param[out] p_output The caller-allocated buffer where the |
| 312 | * output will be placed |
| 313 | * \param[in] output_size The allocated size in bytes of the |
| 314 | * `p_output` buffer |
| 315 | * \param[out] p_output_length After completion, will contain the number |
| 316 | * of bytes placed in the `p_output` buffer |
| 317 | * |
| 318 | * \retval PSA_SUCCESS |
| 319 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 320 | typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *p_context, |
| 321 | const uint8_t *p_input, |
| 322 | size_t input_size, |
| 323 | uint8_t *p_output, |
| 324 | size_t output_size, |
| 325 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 326 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 327 | /** \brief A function that completes a previously started secure element cipher |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 328 | * operation |
| 329 | * |
| 330 | * \param[in,out] p_context A hardware-specific structure for the |
| 331 | * previously started cipher operation |
| 332 | * \param[out] p_output The caller-allocated buffer where the output |
| 333 | * will be placed |
| 334 | * \param[in] output_size The allocated size in bytes of the `p_output` |
| 335 | * buffer |
| 336 | * \param[out] p_output_length After completion, will contain the number of |
| 337 | * bytes placed in the `p_output` buffer |
| 338 | * |
| 339 | * \retval PSA_SUCCESS |
| 340 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 341 | typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *p_context, |
| 342 | uint8_t *p_output, |
| 343 | size_t output_size, |
| 344 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 345 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 346 | /** \brief A function that aborts a previously started secure element cipher |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 347 | * operation |
| 348 | * |
| 349 | * \param[in,out] p_context A hardware-specific structure for the |
| 350 | * previously started cipher operation |
| 351 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 352 | typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *p_context); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 353 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 354 | /** \brief A function that performs the ECB block mode for secure element |
| 355 | * cipher operations |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 356 | * |
| 357 | * Note: this function should only be used with implementations that do not |
| 358 | * provide a needed higher-level operation. |
| 359 | * |
| 360 | * \param[in] key_slot The slot of the key to be used for the operation |
| 361 | * \param[in] algorithm The algorithm to be used in the cipher operation |
| 362 | * \param[in] direction Indicates whether the operation is an encrypt or |
| 363 | * decrypt |
| 364 | * \param[in] p_input A buffer containing the data to be |
| 365 | * encrypted/decrypted |
| 366 | * \param[in] input_size The size in bytes of the buffer pointed to by |
| 367 | * `p_input` |
| 368 | * \param[out] p_output The caller-allocated buffer where the output will |
| 369 | * be placed |
| 370 | * \param[in] output_size The allocated size in bytes of the `p_output` |
| 371 | * buffer |
| 372 | * |
| 373 | * \retval PSA_SUCCESS |
| 374 | * \retval PSA_ERROR_NOT_SUPPORTED |
| 375 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 376 | typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 377 | psa_algorithm_t algorithm, |
| 378 | psa_encrypt_or_decrypt_t direction, |
| 379 | const uint8_t *p_input, |
| 380 | size_t input_size, |
| 381 | uint8_t *p_output, |
| 382 | size_t output_size); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * \brief A struct containing all of the function pointers needed to implement |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 386 | * cipher operations using secure elements. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 387 | * |
| 388 | * PSA Crypto API implementations should populate instances of the table as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 389 | * appropriate upon startup or at build time. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 390 | * |
| 391 | * If one of the functions is not implemented (such as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 392 | * `psa_drv_se_cipher_ecb_t`), it should be set to NULL. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 393 | */ |
| 394 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 395 | /** The size in bytes of the hardware-specific secure element cipher |
| 396 | * context structure |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 397 | */ |
Derek Miller | 34b33f1 | 2019-02-15 17:13:54 -0600 | [diff] [blame] | 398 | size_t context_size; |
| 399 | /** Function that performs a cipher setup operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 400 | psa_drv_se_cipher_setup_t p_setup; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 401 | /** Function that sets a cipher IV (if necessary) */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 402 | psa_drv_se_cipher_set_iv_t p_set_iv; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 403 | /** Function that performs a cipher update operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 404 | psa_drv_se_cipher_update_t p_update; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 405 | /** Function that completes a cipher operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 406 | psa_drv_se_cipher_finish_t p_finish; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 407 | /** Function that aborts a cipher operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 408 | psa_drv_se_cipher_abort_t p_abort; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 409 | /** Function that performs ECB mode for a cipher operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 410 | * (Danger: ECB mode should not be used directly by clients of the PSA |
| 411 | * Crypto Client API) |
| 412 | */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 413 | psa_drv_se_cipher_ecb_t p_ecb; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 414 | } psa_drv_se_cipher_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 415 | |
| 416 | /**@}*/ |
| 417 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 418 | /** \defgroup se_asymmetric Secure Element Asymmetric Cryptography |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 419 | * |
| 420 | * Since the amount of data that can (or should) be encrypted or signed using |
| 421 | * asymmetric keys is limited by the key size, asymmetric key operations using |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 422 | * keys in a secure element must be done in single function calls. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 423 | */ |
| 424 | /**@{*/ |
| 425 | |
| 426 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 427 | * \brief A function that signs a hash or short message with a private key in |
| 428 | * a secure element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 429 | * |
| 430 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 431 | * \param[in] alg A signature algorithm that is compatible |
| 432 | * with the type of `key` |
| 433 | * \param[in] p_hash The hash to sign |
| 434 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 435 | * \param[out] p_signature Buffer where the signature is to be written |
| 436 | * \param[in] signature_size Size of the `p_signature` buffer in bytes |
| 437 | * \param[out] p_signature_length On success, the number of bytes |
| 438 | * that make up the returned signature value |
| 439 | * |
| 440 | * \retval PSA_SUCCESS |
| 441 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 442 | typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 443 | psa_algorithm_t alg, |
| 444 | const uint8_t *p_hash, |
| 445 | size_t hash_length, |
| 446 | uint8_t *p_signature, |
| 447 | size_t signature_size, |
| 448 | size_t *p_signature_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 449 | |
| 450 | /** |
| 451 | * \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^] | 452 | * an asymmetric public key in a secure element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 453 | * |
| 454 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 455 | * pair |
| 456 | * \param[in] alg A signature algorithm that is compatible with |
| 457 | * the type of `key` |
| 458 | * \param[in] p_hash The hash whose signature is to be verified |
| 459 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 460 | * \param[in] p_signature Buffer containing the signature to verify |
| 461 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
| 462 | * |
| 463 | * \retval PSA_SUCCESS |
| 464 | * The signature is valid. |
| 465 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 466 | typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 467 | psa_algorithm_t alg, |
| 468 | const uint8_t *p_hash, |
| 469 | size_t hash_length, |
| 470 | const uint8_t *p_signature, |
| 471 | size_t signature_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 472 | |
| 473 | /** |
| 474 | * \brief A function that encrypts a short message with an asymmetric public |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 475 | * key in a secure element |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 476 | * |
| 477 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 478 | * pair |
| 479 | * \param[in] alg An asymmetric encryption algorithm that is |
| 480 | * compatible with the type of `key` |
| 481 | * \param[in] p_input The message to encrypt |
| 482 | * \param[in] input_length Size of the `p_input` buffer in bytes |
| 483 | * \param[in] p_salt A salt or label, if supported by the |
| 484 | * encryption algorithm |
| 485 | * If the algorithm does not support a |
| 486 | * salt, pass `NULL`. |
| 487 | * If the algorithm supports an optional |
| 488 | * salt and you do not want to pass a salt, |
| 489 | * pass `NULL`. |
| 490 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 491 | * supported. |
| 492 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 493 | * If `p_salt` is `NULL`, pass 0. |
| 494 | * \param[out] p_output Buffer where the encrypted message is to |
| 495 | * be written |
| 496 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 497 | * \param[out] p_output_length On success, the number of bytes that make up |
| 498 | * the returned output |
| 499 | * |
| 500 | * \retval PSA_SUCCESS |
| 501 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 502 | typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 503 | psa_algorithm_t alg, |
| 504 | const uint8_t *p_input, |
| 505 | size_t input_length, |
| 506 | const uint8_t *p_salt, |
| 507 | size_t salt_length, |
| 508 | uint8_t *p_output, |
| 509 | size_t output_size, |
| 510 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 511 | |
| 512 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 513 | * \brief A function that decrypts a short message with an asymmetric private |
| 514 | * key in a secure element. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 515 | * |
| 516 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 517 | * \param[in] alg An asymmetric encryption algorithm that is |
| 518 | * compatible with the type of `key` |
| 519 | * \param[in] p_input The message to decrypt |
| 520 | * \param[in] input_length Size of the `p_input` buffer in bytes |
| 521 | * \param[in] p_salt A salt or label, if supported by the |
| 522 | * encryption algorithm |
| 523 | * If the algorithm does not support a |
| 524 | * salt, pass `NULL`. |
| 525 | * If the algorithm supports an optional |
| 526 | * salt and you do not want to pass a salt, |
| 527 | * pass `NULL`. |
| 528 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 529 | * supported. |
| 530 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 531 | * If `p_salt` is `NULL`, pass 0. |
| 532 | * \param[out] p_output Buffer where the decrypted message is to |
| 533 | * be written |
| 534 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 535 | * \param[out] p_output_length On success, the number of bytes |
| 536 | * that make up the returned output |
| 537 | * |
| 538 | * \retval PSA_SUCCESS |
| 539 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 540 | typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 541 | psa_algorithm_t alg, |
| 542 | const uint8_t *p_input, |
| 543 | size_t input_length, |
| 544 | const uint8_t *p_salt, |
| 545 | size_t salt_length, |
| 546 | uint8_t *p_output, |
| 547 | size_t output_size, |
| 548 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 549 | |
| 550 | /** |
| 551 | * \brief A struct containing all of the function pointers needed to implement |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 552 | * asymmetric cryptographic operations using secure elements. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 553 | * |
| 554 | * PSA Crypto API implementations should populate instances of the table as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 555 | * appropriate upon startup or at build time. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 556 | * |
| 557 | * If one of the functions is not implemented, it should be set to NULL. |
| 558 | */ |
| 559 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 560 | /** Function that performs an asymmetric sign operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 561 | psa_drv_se_asymmetric_sign_t p_sign; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 562 | /** Function that performs an asymmetric verify operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 563 | psa_drv_se_asymmetric_verify_t p_verify; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 564 | /** Function that performs an asymmetric encrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 565 | psa_drv_se_asymmetric_encrypt_t p_encrypt; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 566 | /** Function that performs an asymmetric decrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 567 | psa_drv_se_asymmetric_decrypt_t p_decrypt; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 568 | } psa_drv_se_asymmetric_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 569 | |
| 570 | /**@}*/ |
| 571 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 572 | /** \defgroup se_aead Secure Element Authenticated Encryption with Additional Data |
| 573 | * Authenticated Encryption with Additional Data (AEAD) operations with secure |
| 574 | * 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] | 575 | * implementers as there must be sufficient space in memory for the entire |
| 576 | * message, it prevents decrypted data from being made available before the |
| 577 | * authentication operation is complete and the data is known to be authentic. |
| 578 | */ |
| 579 | /**@{*/ |
| 580 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 581 | /** \brief A function that performs a secure element authenticated encryption |
| 582 | * operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 583 | * |
| 584 | * \param[in] key_slot Slot containing the key to use. |
| 585 | * \param[in] algorithm The AEAD algorithm to compute |
| 586 | * (\c PSA_ALG_XXX value such that |
| 587 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 588 | * \param[in] p_nonce Nonce or IV to use |
| 589 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 590 | * \param[in] p_additional_data Additional data that will be |
| 591 | * authenticated but not encrypted |
| 592 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 593 | * \param[in] p_plaintext Data that will be authenticated and |
| 594 | * encrypted |
| 595 | * \param[in] plaintext_length Size of `p_plaintext` in bytes |
| 596 | * \param[out] p_ciphertext Output buffer for the authenticated and |
| 597 | * encrypted data. The additional data is |
| 598 | * not part of this output. For algorithms |
| 599 | * where the encrypted data and the |
| 600 | * authentication tag are defined as |
| 601 | * separate outputs, the authentication |
| 602 | * tag is appended to the encrypted data. |
| 603 | * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in |
| 604 | * bytes |
| 605 | * \param[out] p_ciphertext_length On success, the size of the output in |
| 606 | * the `p_ciphertext` buffer |
| 607 | * |
| 608 | * \retval #PSA_SUCCESS |
| 609 | * Success. |
| 610 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 611 | typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 612 | psa_algorithm_t algorithm, |
| 613 | const uint8_t *p_nonce, |
| 614 | size_t nonce_length, |
| 615 | const uint8_t *p_additional_data, |
| 616 | size_t additional_data_length, |
| 617 | const uint8_t *p_plaintext, |
| 618 | size_t plaintext_length, |
| 619 | uint8_t *p_ciphertext, |
| 620 | size_t ciphertext_size, |
| 621 | size_t *p_ciphertext_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 622 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 623 | /** A function that peforms a secure element authenticated decryption operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 624 | * |
| 625 | * \param[in] key_slot Slot containing the key to use |
| 626 | * \param[in] algorithm The AEAD algorithm to compute |
| 627 | * (\c PSA_ALG_XXX value such that |
| 628 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 629 | * \param[in] p_nonce Nonce or IV to use |
| 630 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 631 | * \param[in] p_additional_data Additional data that has been |
| 632 | * authenticated but not encrypted |
| 633 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 634 | * \param[in] p_ciphertext Data that has been authenticated and |
| 635 | * encrypted. |
| 636 | * For algorithms where the encrypted data |
| 637 | * and the authentication tag are defined |
| 638 | * as separate inputs, the buffer must |
| 639 | * contain the encrypted data followed by |
| 640 | * the authentication tag. |
| 641 | * \param[in] ciphertext_length Size of `p_ciphertext` in bytes |
| 642 | * \param[out] p_plaintext Output buffer for the decrypted data |
| 643 | * \param[in] plaintext_size Size of the `p_plaintext` buffer in |
| 644 | * bytes |
| 645 | * \param[out] p_plaintext_length On success, the size of the output in |
| 646 | * the `p_plaintext` buffer |
| 647 | * |
| 648 | * \retval #PSA_SUCCESS |
| 649 | * Success. |
| 650 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 651 | typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 652 | psa_algorithm_t algorithm, |
| 653 | const uint8_t *p_nonce, |
| 654 | size_t nonce_length, |
| 655 | const uint8_t *p_additional_data, |
| 656 | size_t additional_data_length, |
| 657 | const uint8_t *p_ciphertext, |
| 658 | size_t ciphertext_length, |
| 659 | uint8_t *p_plaintext, |
| 660 | size_t plaintext_size, |
| 661 | size_t *p_plaintext_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 662 | |
| 663 | /** |
| 664 | * \brief A struct containing all of the function pointers needed to implement |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 665 | * secure element Authenticated Encryption with Additional Data operations |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 666 | * |
| 667 | * PSA Crypto API implementations should populate instances of the table as |
| 668 | * appropriate upon startup. |
| 669 | * |
| 670 | * If one of the functions is not implemented, it should be set to NULL. |
| 671 | */ |
| 672 | typedef struct { |
| 673 | /** Function that performs the AEAD encrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 674 | psa_drv_se_aead_encrypt_t p_encrypt; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 675 | /** Function that performs the AEAD decrypt operation */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 676 | psa_drv_se_aead_decrypt_t p_decrypt; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 677 | } psa_drv_se_aead_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 678 | /**@}*/ |
| 679 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 680 | /** \defgroup se_key_management Secure Element Key Management |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 681 | * Currently, key management is limited to importing keys in the clear, |
| 682 | * destroying keys, and exporting keys in the clear. |
| 683 | * Whether a key may be exported is determined by the key policies in place |
| 684 | * on the key slot. |
| 685 | */ |
| 686 | /**@{*/ |
| 687 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 688 | /** \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] | 689 | * |
| 690 | * This function can support any output from psa_export_key(). Refer to the |
| 691 | * documentation of psa_export_key() for the format for each key type. |
| 692 | * |
| 693 | * \param[in] key_slot Slot where the key will be stored |
| 694 | * This must be a valid slot for a key of the chosen |
| 695 | * type. It must be unoccupied. |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 696 | * \param[in] lifetime The required lifetime of the key storage |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 697 | * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value) |
| 698 | * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value) |
| 699 | * \param[in] usage The allowed uses of the key |
| 700 | * \param[in] p_data Buffer containing the key data |
| 701 | * \param[in] data_length Size of the `data` buffer in bytes |
| 702 | * |
| 703 | * \retval #PSA_SUCCESS |
| 704 | * Success. |
| 705 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 706 | typedef psa_status_t (*psa_drv_se_import_key_t)(psa_key_slot_number_t key_slot, |
Derek Miller | 0972fe5 | 2019-02-15 17:08:27 -0600 | [diff] [blame] | 707 | psa_key_lifetime_t lifetime, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 708 | psa_key_type_t type, |
| 709 | psa_algorithm_t algorithm, |
| 710 | psa_key_usage_t usage, |
| 711 | const uint8_t *p_data, |
| 712 | size_t data_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 713 | |
| 714 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 715 | * \brief A function that destroys a secure element key and restore the slot to |
| 716 | * its default state |
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 | * This function destroys the content of the key from a secure element. |
| 719 | * Implementations shall make a best effort to ensure that any previous content |
| 720 | * of the slot is unrecoverable. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 721 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 722 | * This function returns the specified slot to its default state. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 723 | * |
| 724 | * \param[in] key_slot The key slot to erase. |
| 725 | * |
| 726 | * \retval #PSA_SUCCESS |
| 727 | * The slot's content, if any, has been erased. |
| 728 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 729 | typedef psa_status_t (*psa_drv_se_destroy_key_t)(psa_key_slot_number_t key); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 730 | |
| 731 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 732 | * \brief A function that exports a secure element key in binary format |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 733 | * |
| 734 | * The output of this function can be passed to psa_import_key() to |
| 735 | * create an equivalent object. |
| 736 | * |
| 737 | * If a key is created with `psa_import_key()` and then exported with |
| 738 | * this function, it is not guaranteed that the resulting data is |
| 739 | * identical: the implementation may choose a different representation |
| 740 | * of the same key if the format permits it. |
| 741 | * |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 742 | * This function should generate output in the same format that |
| 743 | * `psa_export_key()` does. Refer to the |
| 744 | * documentation of `psa_export_key()` for the format for each key type. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 745 | * |
| 746 | * \param[in] key Slot whose content is to be exported. This must |
| 747 | * be an occupied key slot. |
| 748 | * \param[out] p_data Buffer where the key data is to be written. |
| 749 | * \param[in] data_size Size of the `p_data` buffer in bytes. |
| 750 | * \param[out] p_data_length On success, the number of bytes |
| 751 | * that make up the key data. |
| 752 | * |
| 753 | * \retval #PSA_SUCCESS |
| 754 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 755 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 756 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 757 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 758 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 759 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 760 | */ |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 761 | typedef psa_status_t (*psa_drv_se_export_key_t)(psa_key_slot_number_t key, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 762 | uint8_t *p_data, |
| 763 | size_t data_size, |
| 764 | size_t *p_data_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 765 | |
| 766 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 767 | * \brief A function that generates a symmetric or asymmetric key on a secure |
| 768 | * element |
| 769 | * |
| 770 | * If `type` is asymmetric (`#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) == 1`), |
| 771 | * the public component of the generated key will be placed in `p_pubkey_out`. |
| 772 | * The format of the public key information will match the format specified for |
| 773 | * the `psa_export_key()` function for the key type. |
| 774 | * |
| 775 | * \param[in] key_slot Slot where the generated key will be placed |
| 776 | * \param[in] type The type of the key to be generated |
| 777 | * \param[in] usage The prescribed usage of the generated key |
| 778 | * Note: Not all Secure Elements support the same |
| 779 | * restrictions that PSA Crypto does (and vice versa). |
| 780 | * Driver developers should endeavor to match the |
| 781 | * usages as close as possible. |
| 782 | * \param[in] bits The size in bits of the key to be generated. |
| 783 | * \param[in] extra Extra parameters for key generation. The |
| 784 | * interpretation of this parameter should match the |
| 785 | * interpretation in the `extra` parameter is the |
| 786 | * `psa_generate_key` function |
| 787 | * \param[in] extra_size The size in bytes of the \ref extra buffer |
| 788 | * \param[out] p_pubkey_out The buffer where the public key information will |
| 789 | * be placed |
| 790 | * \param[in] pubkey_out_size The size in bytes of the `p_pubkey_out` buffer |
| 791 | * \param[out] p_pubkey_length Upon successful completion, will contain the |
| 792 | * size of the data placed in `p_pubkey_out`. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 793 | */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 794 | typedef psa_status_t (*psa_drv_se_generate_key_t) (psa_key_slot_number_t key_slot, |
| 795 | psa_key_type_t type, |
| 796 | psa_key_usage_t usage, |
| 797 | size_t bits, |
| 798 | const void *extra, |
| 799 | size_t extra_size, |
| 800 | uint8_t *p_pubkey_out, |
| 801 | size_t pubkey_out_size, |
| 802 | size_t *p_pubkey_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 803 | |
| 804 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 805 | * \brief A struct containing all of the function pointers needed to for secure |
| 806 | * element key management |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 807 | * |
| 808 | * PSA Crypto API implementations should populate instances of the table as |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 809 | * appropriate upon startup or at build time. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 810 | * |
| 811 | * If one of the functions is not implemented, it should be set to NULL. |
| 812 | */ |
| 813 | typedef struct { |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 814 | /** Function that performs a key import operation */ |
| 815 | psa_drv_se_import_key_t p_import; |
| 816 | /** Function that performs a generation */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 817 | psa_drv_se_generate_key_t p_generate; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 818 | /** Function that performs a key destroy operation */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 819 | psa_drv_se_destroy_key_t p_destroy; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 820 | /** Function that performs a key export operation */ |
Derek Miller | 0b3098a | 2019-02-15 17:10:49 -0600 | [diff] [blame] | 821 | psa_drv_se_export_key_t p_export; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 822 | } psa_drv_se_key_management_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 823 | |
| 824 | /**@}*/ |
| 825 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 826 | /** \defgroup driver_derivation Secure Element Key Derivation and Agreement |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 827 | * Key derivation is the process of generating new key material using an |
| 828 | * existing key and additional parameters, iterating through a basic |
| 829 | * cryptographic function, such as a hash. |
| 830 | * Key agreement is a part of cryptographic protocols that allows two parties |
| 831 | * to agree on the same key value, but starting from different original key |
| 832 | * material. |
| 833 | * The flows are similar, and the PSA Crypto Driver Model uses the same functions |
| 834 | * for both of the flows. |
| 835 | * |
| 836 | * There are two different final functions for the flows, |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 837 | * `psa_drv_se_key_derivation_derive` and `psa_drv_se_key_derivation_export`. |
| 838 | * `psa_drv_se_key_derivation_derive` is used when the key material should be |
| 839 | * placed in a slot on the hardware and not exposed to the caller. |
| 840 | * `psa_drv_se_key_derivation_export` is used when the key material should be |
| 841 | * returned to the PSA Cryptographic API implementation. |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 842 | * |
| 843 | * Different key derivation algorithms require a different number of inputs. |
| 844 | * Instead of having an API that takes as input variable length arrays, which |
| 845 | * can be problemmatic to manage on embedded platforms, the inputs are passed |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 846 | * to the driver via a function, `psa_drv_se_key_derivation_collateral`, that |
| 847 | * 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] | 848 | * derivation algorithm that required 3 paramter inputs, the flow would look |
| 849 | * something like: |
| 850 | * ~~~~~~~~~~~~~{.c} |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 851 | * psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes); |
| 852 | * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_0, |
| 853 | * p_collateral_0, |
| 854 | * collateral_0_size); |
| 855 | * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_1, |
| 856 | * p_collateral_1, |
| 857 | * collateral_1_size); |
| 858 | * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_2, |
| 859 | * p_collateral_2, |
| 860 | * collateral_2_size); |
| 861 | * psa_drv_se_key_derivation_derive(); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 862 | * ~~~~~~~~~~~~~ |
| 863 | * |
| 864 | * key agreement example: |
| 865 | * ~~~~~~~~~~~~~{.c} |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 866 | * psa_drv_se_key_derivation_setup(alg, source_key. dest_key_size_bytes); |
| 867 | * psa_drv_se_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size); |
| 868 | * psa_drv_se_key_derivation_export(p_session_key, |
| 869 | * session_key_size, |
| 870 | * &session_key_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 871 | * ~~~~~~~~~~~~~ |
| 872 | */ |
| 873 | /**@{*/ |
| 874 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 875 | /** \brief A function that Sets up a secure element key derivation operation by |
| 876 | * specifying the algorithm and the source key sot |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 877 | * |
| 878 | * \param[in,out] p_context A hardware-specific structure containing any |
| 879 | * context information for the implementation |
| 880 | * \param[in] kdf_alg The algorithm to be used for the key derivation |
| 881 | * \param[in] souce_key The key to be used as the source material for the |
| 882 | * key derivation |
| 883 | * |
| 884 | * \retval PSA_SUCCESS |
| 885 | */ |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 886 | typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(void *p_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 887 | psa_algorithm_t kdf_alg, |
Derek Miller | b2a1cce | 2019-02-15 17:03:42 -0600 | [diff] [blame] | 888 | psa_key_slot_number_t source_key); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 889 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 890 | /** \brief A function that provides collateral (parameters) needed for a secure |
| 891 | * element key derivation or key agreement operation |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 892 | * |
| 893 | * Since many key derivation algorithms require multiple parameters, it is |
| 894 | * expeced that this function may be called multiple times for the same |
| 895 | * operation, each with a different algorithm-specific `collateral_id` |
| 896 | * |
| 897 | * \param[in,out] p_context A hardware-specific structure containing any |
| 898 | * context information for the implementation |
| 899 | * \param[in] collateral_id An ID for the collateral being provided |
| 900 | * \param[in] p_collateral A buffer containing the collateral data |
| 901 | * \param[in] collateral_size The size in bytes of the collateral |
| 902 | * |
| 903 | * \retval PSA_SUCCESS |
| 904 | */ |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 905 | typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *p_context, |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 906 | uint32_t collateral_id, |
| 907 | const uint8_t *p_collateral, |
| 908 | size_t collateral_size); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 909 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 910 | /** \brief A function that performs the final secure element key derivation |
| 911 | * step and place the generated key material in a slot |
| 912 | * |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 913 | * \param[in,out] p_context A hardware-specific structure containing any |
| 914 | * context information for the implementation |
| 915 | * \param[in] dest_key The slot where the generated key material |
| 916 | * should be placed |
| 917 | * |
| 918 | * \retval PSA_SUCCESS |
| 919 | */ |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 920 | typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *p_context, |
| 921 | psa_key_slot_number_t dest_key); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 922 | |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 923 | /** \brief A function that performs the final step of a secure element key |
| 924 | * agreement and place the generated key material in a buffer |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 925 | * |
| 926 | * \param[out] p_output Buffer in which to place the generated key |
| 927 | * material |
| 928 | * \param[in] output_size The size in bytes of `p_output` |
| 929 | * \param[out] p_output_length Upon success, contains the number of bytes of |
| 930 | * key material placed in `p_output` |
| 931 | * |
| 932 | * \retval PSA_SUCCESS |
| 933 | */ |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 934 | typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *p_context, |
| 935 | uint8_t *p_output, |
| 936 | size_t output_size, |
| 937 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 938 | |
| 939 | /** |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 940 | * \brief A struct containing all of the function pointers needed to for secure |
| 941 | * element key derivation and agreement |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 942 | * |
| 943 | * PSA Crypto API implementations should populate instances of the table as |
| 944 | * appropriate upon startup. |
| 945 | * |
| 946 | * If one of the functions is not implemented, it should be set to NULL. |
| 947 | */ |
| 948 | typedef struct { |
Derek Miller | 6211726 | 2019-02-15 17:12:26 -0600 | [diff] [blame] | 949 | /** The driver-specific size of the key derivation context */ |
| 950 | size_t context_size; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 951 | /** Function that performs a key derivation setup */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 952 | psa_drv_se_key_derivation_setup_t p_setup; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 953 | /** Function that sets key derivation collateral */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 954 | psa_drv_se_key_derivation_collateral_t p_collateral; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 955 | /** Function that performs a final key derivation step */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 956 | psa_drv_se_key_derivation_derive_t p_derive; |
Derek Miller | f0c1d0d | 2019-02-15 17:23:42 -0600 | [diff] [blame^] | 957 | /** Function that perforsm a final key derivation or agreement and |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 958 | * exports the key */ |
Derek Miller | ea743cf | 2019-02-15 17:06:29 -0600 | [diff] [blame] | 959 | psa_drv_se_key_derivation_export_t p_export; |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 960 | } psa_drv_se_key_derivation_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 961 | |
| 962 | /**@}*/ |
| 963 | |
| 964 | #ifdef __cplusplus |
| 965 | } |
| 966 | #endif |
| 967 | |
| 968 | #endif /* PSA_CRYPTO_SE_DRIVER_H */ |