Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1 | /** |
| 2 | * \file psa/crypto_driver.h |
| 3 | * \brief Platform Security Architecture cryptographic driver module |
| 4 | * |
| 5 | * This file describes an API for driver developers to implement to enable |
| 6 | * hardware to be called in a standardized way by a PSA Cryptographic API |
| 7 | * implementation. The API described is not intended to be called by |
| 8 | * application developers. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
| 13 | * SPDX-License-Identifier: Apache-2.0 |
| 14 | * |
| 15 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 16 | * not use this file except in compliance with the License. |
| 17 | * You may obtain a copy of the License at |
| 18 | * |
| 19 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | * |
| 21 | * Unless required by applicable law or agreed to in writing, software |
| 22 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 23 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | * See the License for the specific language governing permissions and |
| 25 | * limitations under the License. |
| 26 | */ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 27 | #ifndef __PSA_CRYPTO_DRIVER_H__ |
| 28 | #define __PSA_CRYPTO_DRIVER_H__ |
| 29 | |
| 30 | #include <stddef.h> |
| 31 | #include <stdint.h> |
| 32 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 33 | /** The following types are redefinitions from the psa/crypto.h file. |
| 34 | * It is intended that these will be moved to a new common header file to |
| 35 | * avoid duplication. They are included here for expediency in publication. |
| 36 | */ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 37 | typedef uint32_t psa_status_t; |
| 38 | typedef uint32_t psa_algorithm_t; |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 39 | typedef uint8_t encrypt_or_decrypt_t; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 40 | typedef uint32_t psa_key_slot_t; |
| 41 | typedef uint32_t psa_key_type_t; |
| 42 | |
| 43 | /** \defgroup opaque_mac Opaque Message Authentication Code |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 44 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 45 | /**@{*/ |
| 46 | /** \brief A function that starts a MAC operation for a PSA Crypto Driver |
| 47 | * implementation using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 48 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 49 | * \param[in,out] p_context A structure that will contain the |
| 50 | * hardware-specific MAC context |
| 51 | * \param[in] key_slot The slot of the key to be used for the |
| 52 | * operation |
| 53 | * \param[in] algorithm The algorithm to be used to underly the MAC |
| 54 | * operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 55 | * |
| 56 | * \retval PSA_SUCCESS |
| 57 | * Success. |
| 58 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 59 | typedef psa_status_t (*pcd_mac_opaque_setup_t)(void *p_context, |
| 60 | psa_key_slot_t key_slot, |
| 61 | psa_algorithm_t algorithm); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 62 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 63 | /** \brief A function that continues a previously started MAC operation using |
| 64 | * an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 65 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 66 | * \param[in,out] p_context A hardware-specific structure for the |
| 67 | * previously-established MAC operation to be |
| 68 | * continued |
| 69 | * \param[in] p_input A buffer containing the message to be appended |
| 70 | * to the MAC operation |
| 71 | * \param[in] input_length The size in bytes of the input message buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 72 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 73 | typedef psa_status_t (*pcd_mac_opaque_update_t)(void *p_context, |
| 74 | const uint8_t *p_input, |
| 75 | size_t input_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 76 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 77 | /** \brief a function that completes a previously started MAC operation by |
| 78 | * returning the resulting MAC using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 79 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 80 | * \param[in] p_context A hardware-specific structure for the |
| 81 | * previously started MAC operation to be |
| 82 | * finished |
| 83 | * \param[out] p_mac A buffer where the generated MAC will be |
| 84 | * placed |
| 85 | * \param[in] mac_size The size in bytes of the buffer that has been |
| 86 | * allocated for the `output` buffer |
| 87 | * \param[out] p_mac_length After completion, will contain the number of |
| 88 | * bytes placed in the `p_output` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 89 | * |
| 90 | * \retval PSA_SUCCESS |
| 91 | * Success. |
| 92 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 93 | typedef psa_status_t (*pcd_mac_opaque_finish_t)(void *p_context, |
| 94 | uint8_t *p_mac, |
| 95 | size_t mac_size, |
| 96 | size_t *p_mac_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 97 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 98 | /** \brief A function that completes a previously started MAC operation by |
| 99 | * comparing the resulting MAC against a known value using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 100 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 101 | * \param[in] p_context A hardware-specific structure for the previously |
| 102 | * started MAC operation to be fiinished |
| 103 | * \param[in] p_mac The MAC value against which the resulting MAC will |
| 104 | * be compared against |
| 105 | * \param[in] mac_length The size in bytes of the value stored in `p_mac` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 106 | * |
| 107 | * \retval PSA_SUCCESS |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 108 | * The operation completed successfully and the MACs matched each |
| 109 | * other |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 110 | * \retval PSA_ERROR_INVALID_SIGNATURE |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 111 | * The operation completed successfully, but the calculated MAC did |
| 112 | * not match the provided MAC |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 113 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 114 | typedef psa_status_t (*pcd_mac_opaque_finish_verify_t)(void *p_context, |
| 115 | const uint8_t *p_mac, |
| 116 | size_t mac_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 117 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 118 | /** \brief A function that aborts a previous started opaque-key MAC operation |
| 119 | |
| 120 | * \param[in] p_context A hardware-specific structure for the previously |
| 121 | * started MAC operation to be aborted |
| 122 | */ |
| 123 | typedef psa_status_t (*pcd_mac_opaque_abort_t)(void *p_context); |
| 124 | |
| 125 | /** \brief A funciton that performs a MAC operation in one command and return |
| 126 | * the calculated MAC using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 127 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 128 | * \param[in] p_input A buffer containing the message to be MACed |
| 129 | * \param[in] input_length The size in bytes of `input` |
| 130 | * \param[in] key_slot The slot of the key to be used |
| 131 | * \param[in] alg The algorithm to be used to underlie the MA |
| 132 | * operation |
| 133 | * \param[out] p_mac A buffer where the generated MAC will be |
| 134 | * placed |
| 135 | * \param[in] mac_size The size in bytes of the `output` buffer |
| 136 | * \param[out] p_mac_length After completion, will contain the number of |
| 137 | * bytes placed in the `output` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 138 | * |
| 139 | * \retval PSA_SUCCESS |
| 140 | * Success. |
| 141 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 142 | typedef psa_status_t (*pcd_mac_opaque_generate_t)(const uint8_t *p_input, |
| 143 | size_t input_length, |
| 144 | psa_key_slot_t key_slot, |
| 145 | psa_algorithm_t alg, |
| 146 | uint8_t *p_mac, |
| 147 | size_t mac_size, |
| 148 | size_t *p_mac_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 149 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 150 | /** \brief A function that performs an MAC operation in one command and |
| 151 | * compare the resulting MAC against a known value using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 152 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 153 | * \param[in] p_input A buffer containing the message to be MACed |
| 154 | * \param[in] input_length The size in bytes of `input` |
| 155 | * \param[in] key_slot The slot of the key to be used |
| 156 | * \param[in] alg The algorithm to be used to underlie the MAC |
| 157 | * operation |
| 158 | * \param[in] p_mac The MAC value against which the resulting MAC will |
| 159 | * be compared against |
| 160 | * \param[in] mac_length The size in bytes of `mac` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 161 | * |
| 162 | * \retval PSA_SUCCESS |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 163 | * The operation completed successfully and the MACs matched each |
| 164 | * other |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 165 | * \retval PSA_ERROR_INVALID_SIGNATURE |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 166 | * The operation completed successfully, but the calculated MAC did |
| 167 | * not match the provided MAC |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 168 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 169 | typedef psa_status_t (*pcd_mac_opaque_verify_t)(const uint8_t *p_input, |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 170 | size_t input_length, |
| 171 | psa_key_slot_t key_slot, |
| 172 | psa_algorithm_t alg, |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 173 | const uint8_t *p_mac, |
| 174 | size_t mac_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 175 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 176 | /** \brief A struct containing all of the function pointers needed to |
| 177 | * implement MAC operations using opaque keys. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 178 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 179 | * PSA Crypto API implementations should populate the table as appropriate |
| 180 | * upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 181 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 182 | * If one of the functions is not implemented (such as `pcd_mac_opaque_t`), |
| 183 | * it should be set to NULL. |
| 184 | * |
| 185 | * Driver implementers should ensure that they implement all of the functions |
| 186 | * that make sense for their hardware, and that they provide a full solution |
| 187 | * (for example, if they support `p_setup`, they should also support |
| 188 | * `p_update` and at least one of `p_finish` or `p_finish_verify`). |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 189 | * |
| 190 | */ |
| 191 | struct pcd_mac_opaque_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 192 | /**The size in bytes of the hardware-specific Opaque-MAC Context structure |
| 193 | */ |
| 194 | size_t context_size; |
| 195 | /** Function that performs the setup operation |
| 196 | */ |
| 197 | pcd_mac_opaque_setup_t *p_setup; |
| 198 | /** Function that performs the update operation |
| 199 | */ |
| 200 | pcd_mac_opaque_update_t *p_update; |
| 201 | /** Function that completes the operation |
| 202 | */ |
| 203 | pcd_mac_opaque_finish_t *p_finish; |
| 204 | /** Function that completed a MAC operation with a verify check |
| 205 | */ |
| 206 | pcd_mac_opaque_finish_verify_t *p_finish_verify; |
| 207 | /** Function that aborts a previoustly started operation |
| 208 | */ |
| 209 | pcd_mac_opaque_abort_t *p_abort; |
| 210 | /** Function that performs the MAC operation in one call |
| 211 | */ |
| 212 | pcd_mac_opaque_generate_t *p_mac; |
| 213 | /** Function that performs the MAC and verify operation in one call |
| 214 | */ |
| 215 | pcd_mac_opaque_verify_t *p_mac_verify; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 216 | }; |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 217 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 218 | |
| 219 | /** \defgroup transparent_mac Transparent Message Authentication Code |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 220 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 221 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 222 | |
| 223 | /** \brief The hardware-specific transparent-key MAC context structure |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 224 | * The contents of this structure are implementation dependent and are |
| 225 | * therefore not described here. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 226 | */ |
| 227 | struct pcd_mac_transparent_context_t { |
| 228 | // Implementation specific |
| 229 | }; |
| 230 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 231 | /** \brief The function prototype for the setup operation of a |
| 232 | * transparent-key MAC operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 233 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 234 | * Functions that implement the prototype should be named in the following |
| 235 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 236 | * ~~~~~~~~~~~~~{.c} |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 237 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT>_setup |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 238 | * ~~~~~~~~~~~~~ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 239 | * Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT` |
| 240 | * is the specific variant of a MAC operation (such as HMAC or CMAC) |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 241 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 242 | * \param[in,out] p_context A structure that will contain the |
| 243 | * hardware-specific MAC context |
| 244 | * \param[in] p_key A buffer containing the cleartext key material |
| 245 | * to be used in the operation |
| 246 | * \param[in] key_length The size in bytes of the key material |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 247 | * |
| 248 | * \retval PSA_SUCCESS |
| 249 | * Success. |
| 250 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 251 | typedef psa_status_t (*pcd_mac_transparent_setup_t)(struct pcd_mac_transparent_context_t *p_context, |
| 252 | const uint8_t *p_key, |
| 253 | size_t key_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 254 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 255 | /** \brief The function prototype for the update operation of a |
| 256 | * transparent-key MAC operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 257 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 258 | * Functions that implement the prototype should be named in the following |
| 259 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 260 | * ~~~~~~~~~~~~~{.c} |
| 261 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT>_update |
| 262 | * ~~~~~~~~~~~~~ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 263 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` |
| 264 | * is the specific variant of a MAC operation (such as HMAC or CMAC) |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 265 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 266 | * \param[in,out] p_context A hardware-specific structure for the |
| 267 | * previously-established MAC operation to be |
| 268 | * continued |
| 269 | * \param[in] p_input A buffer containing the message to be appended |
| 270 | * to the MAC operation |
| 271 | * \param[in] input_length The size in bytes of the input message buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 272 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 273 | typedef psa_status_t (*pcd_mac_transparent_update_t)(struct pcd_mac_transparent_context_t *p_context, |
| 274 | const uint8_t *p_input, |
| 275 | size_t input_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 276 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 277 | /** \brief The function prototype for the finish operation of a |
| 278 | * transparent-key MAC operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 279 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 280 | * Functions that implement the prototype should be named in the following |
| 281 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 282 | * ~~~~~~~~~~~~~{.c} |
| 283 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT>_finish |
| 284 | * ~~~~~~~~~~~~~ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 285 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 286 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 287 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 288 | * \param[in] p_context A hardware-specific structure for the |
| 289 | * previously started MAC operation to be |
| 290 | * finished |
| 291 | * \param[out] p_mac A buffer where the generated MAC will be placed |
| 292 | * \param[in] mac_length The size in bytes of the buffer that has been |
| 293 | * allocated for the `p_mac` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 294 | * |
| 295 | * \retval PSA_SUCCESS |
| 296 | * Success. |
| 297 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 298 | typedef psa_status_t (*pcd_mac_transparent_finish_t)(struct pcd_mac_transparent_context_t *p_context, |
| 299 | uint8_t *p_mac, |
| 300 | size_t mac_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 301 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 302 | /** \brief The function prototype for the finish and verify operation of a |
| 303 | * transparent-key MAC operation |
| 304 | * |
| 305 | * Functions that implement the prototype should be named in the following |
| 306 | * convention: |
| 307 | * ~~~~~~~~~~~~~{.c} |
| 308 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT>_finish_verify |
| 309 | * ~~~~~~~~~~~~~ |
| 310 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 311 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 312 | * |
| 313 | * \param[in] p_context A hardware-specific structure for the |
| 314 | * previously started MAC operation to be |
| 315 | * fiinished |
| 316 | * \param[in] p_mac A buffer containing the MAC that will be used |
| 317 | * for verification |
| 318 | * \param[in] mac_length The size in bytes of the data in the `p_mac` |
| 319 | * buffer |
| 320 | * |
| 321 | * \retval PSA_SUCCESS |
| 322 | * The operation completed successfully and the comparison matched |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 323 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 324 | typedef psa_status_t (*pcd_mac_transparent_verify_finish_t)(struct pcd_mac_transparent_context_t *p_context, |
| 325 | const uint8_t *p_mac, |
| 326 | size_t mac_length); |
| 327 | |
| 328 | /** \brief The function prototype for the abort operation for a previously |
| 329 | * started transparent-key MAC operation |
| 330 | * |
| 331 | * Functions that implement the prototype should be named in the following |
| 332 | * convention: |
| 333 | * ~~~~~~~~~~~~~{.c} |
| 334 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT>_abort |
| 335 | * ~~~~~~~~~~~~~ |
| 336 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 337 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 338 | * |
| 339 | * \param[in] p_context A hardware-specific structure for the |
| 340 | * previously started MAC operation to be |
| 341 | * fiinished |
| 342 | * |
| 343 | */ |
| 344 | typedef psa_status_t (*pcd_mac_transparent_abort_t)(struct pcd_mac_transparent_context_t *p_context); |
| 345 | |
| 346 | /** \brief The function prototype for a one-shot operation of a transparent-key |
| 347 | * MAC operation |
| 348 | * |
| 349 | * Functions that implement the prototype should be named in the following |
| 350 | * convention: |
| 351 | * ~~~~~~~~~~~~~{.c} |
| 352 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT> |
| 353 | * ~~~~~~~~~~~~~ |
| 354 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 355 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 356 | * |
| 357 | * \param[in] p_input A buffer containing the data to be MACed |
| 358 | * \param[in] input_length The length in bytes of the `p_input` data |
| 359 | * \param[in] p_key A buffer containing the key material to be used |
| 360 | * for the MAC operation |
| 361 | * \param[in] key_length The length in bytes of the `p_key` data |
| 362 | * \param[in] alg The algorithm to be performed |
| 363 | * \param[out] p_mac The buffer where the resulting MAC will be placed |
| 364 | * upon success |
| 365 | * \param[in] mac_length The length in bytes of the `p_mac` buffer |
| 366 | */ |
| 367 | typedef psa_status_t (*pcd_mac_transparent_t)(const uint8_t *p_input, |
| 368 | size_t input_length, |
| 369 | const uint8_t *p_key, |
| 370 | size_t key_length, |
| 371 | psa_algorithm_t alg, |
| 372 | uint8_t *p_mac, |
| 373 | size_t mac_length); |
| 374 | |
| 375 | /** \brief The function prototype for a one-shot operation of a transparent-key |
| 376 | * MAC Verify operation |
| 377 | * |
| 378 | * Functions that implement the prototype should be named in the following |
| 379 | * convention: |
| 380 | * ~~~~~~~~~~~~~{.c} |
| 381 | * pcd_mac_transparent_<ALGO>_<MAC_VARIANT>_verify |
| 382 | * ~~~~~~~~~~~~~ |
| 383 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 384 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 385 | * |
| 386 | * \param[in] p_input A buffer containing the data to be MACed |
| 387 | * \param[in] input_length The length in bytes of the `p_input` data |
| 388 | * \param[in] p_key A buffer containing the key material to be used |
| 389 | * for the MAC operation |
| 390 | * \param[in] key_length The length in bytes of the `p_key` data |
| 391 | * \param[in] alg The algorithm to be performed |
| 392 | * \param[in] p_mac The MAC data to be compared |
| 393 | * \param[in] mac_length The length in bytes of the `p_mac` buffer |
| 394 | * |
| 395 | * \retval PSA_SUCCESS |
| 396 | * The operation completed successfully and the comparison matched |
| 397 | */ |
| 398 | typedef psa_status_t (*pcd_mac_transparent_verify_t)(const uint8_t *p_input, |
| 399 | size_t input_length, |
| 400 | const uint8_t *p_key, |
| 401 | size_t key_length, |
| 402 | psa_algorithm_t alg, |
| 403 | const uint8_t *p_mac, |
| 404 | size_t mac_length); |
| 405 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 406 | |
| 407 | /** \defgroup opaque_cipher Opaque Symmetric Ciphers |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 408 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 409 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 410 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 411 | /** \brief A function pointer that provides the cipher setup function for |
| 412 | * opaque-key operations |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 413 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 414 | * \param[in,out] p_context A structure that will contain the |
| 415 | * hardware-specific cipher context. |
| 416 | * \param[in] key_slot The slot of the key to be used for the |
| 417 | * operation |
| 418 | * \param[in] algorithm The algorithm to be used in the cipher |
| 419 | * operation |
| 420 | * \param[in] direction Indicates whether the operation is an encrypt |
| 421 | * or decrypt |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 422 | * |
| 423 | * \retval PSA_SUCCESS |
| 424 | * \retval PSA_ERROR_NOT_SUPPORTED |
| 425 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 426 | typedef psa_status_t (*pcd_cipher_opaque_setup_t)(void *p_context, |
| 427 | psa_key_slot_t key_slot, |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 428 | psa_algorithm_t algorithm, |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 429 | encrypt_or_decrypt_t direction); |
| 430 | |
| 431 | /** \brief A function pointer that sets the initialization vector (if |
| 432 | * necessary) for an opaque cipher operation |
| 433 | * |
| 434 | * Rationale: that the psa_cipher_* function set has two IV functions: one to |
| 435 | * set the IV, and one to generate it internally. the generate function is not |
| 436 | * necessary for the driver API as the PSA Crypto implementation can do the |
| 437 | * generation using its RNG features. |
| 438 | * |
| 439 | * \param[in,out] p_context A structure that contains the previously set up |
| 440 | * hardware-specific cipher context |
| 441 | * \param[in] p_iv A buffer containing the initialization vector |
| 442 | * \param[in] iv_length The size (in bytes) of the `p_iv` buffer |
| 443 | * |
| 444 | * \retval PSA_SUCCESS |
| 445 | */ |
| 446 | typedef psa_status_t (*pcd_cipher_opaque_set_iv_t)(void *p_context, |
| 447 | const uint8_t *p_iv, |
| 448 | size_t iv_length); |
| 449 | |
| 450 | /** \brief A function that continues a previously started opaque-key cipher |
| 451 | * operation |
| 452 | * |
| 453 | * \param[in,out] p_context A hardware-specific structure for the |
| 454 | * previously started cipher operation |
| 455 | * \param[in] p_input A buffer containing the data to be |
| 456 | * encrypted/decrypted |
| 457 | * \param[in] input_size The size in bytes of the buffer pointed to |
| 458 | * by `p_input` |
| 459 | * \param[out] p_output The caller-allocated buffer where the |
| 460 | * output will be placed |
| 461 | * \param[in] output_size The allocated size in bytes of the |
| 462 | * `p_output` buffer |
| 463 | * \param[out] p_output_length After completion, will contain the number |
| 464 | * of bytes placed in the `p_output` buffer |
| 465 | * |
| 466 | * \retval PSA_SUCCESS |
| 467 | */ |
| 468 | typedef psa_status_t (*pcd_cipher_opaque_update_t)(void *p_context, |
| 469 | const uint8_t *p_input, |
| 470 | size_t input_size, |
| 471 | uint8_t *p_output, |
| 472 | size_t output_size, |
| 473 | size_t *p_output_length); |
| 474 | |
| 475 | /** \brief A function that completes a previously started opaque-key cipher |
| 476 | * operation |
| 477 | * |
| 478 | * \param[in] p_context A hardware-specific structure for the |
| 479 | * previously started cipher operation |
| 480 | * \param[out] p_output The caller-callocated buffer where the output |
| 481 | * will be placed |
| 482 | * \param[in] output_size The allocated size in bytes of the `p_output` |
| 483 | * buffer |
| 484 | * \param[out] p_output_length After completion, will contain the number of |
| 485 | * bytes placed in the `p_output` buffer |
| 486 | * |
| 487 | * \retval PSA_SUCCESS |
| 488 | */ |
| 489 | typedef psa_status_t (*pcd_cipher_opaque_finish_t)(void *p_context, |
| 490 | uint8_t *p_output, |
| 491 | size_t output_size, |
| 492 | size_t *p_output_length); |
| 493 | |
| 494 | /** \brief A function that aborts a previously started opaque-key cipher |
| 495 | * operation |
| 496 | * |
| 497 | * \param[in] p_context A hardware-specific structure for the |
| 498 | * previously started cipher operation |
| 499 | */ |
| 500 | typedef psa_status_t (*pcd_cipher_opaque_abort_t)(void *p_context); |
| 501 | |
| 502 | /** \brief A function that performs the ECB block mode for opaque-key cipher |
| 503 | * operations |
| 504 | * |
| 505 | * Note: this function should only be used with implementations that do not |
| 506 | * provide a needed higher-level operation. |
| 507 | * |
| 508 | * \param[in] key_slot The slot of the key to be used for the operation |
| 509 | * \param[in] algorithm The algorithm to be used in the cipher operation |
| 510 | * \param[in] direction Indicates whether the operation is an encrypt or |
| 511 | * decrypt |
| 512 | * \param[in] p_input A buffer containing the data to be |
| 513 | * encrypted/decrypted |
| 514 | * \param[in] input_size The size in bytes of the buffer pointed to by |
| 515 | * `p_input` |
| 516 | * \param[out] p_output The caller-allocated byffer where the output will |
| 517 | * be placed |
| 518 | * \param[in] output_size The allocated size in bytes of the `p_output` |
| 519 | * buffer |
| 520 | * |
| 521 | * \retval PSA_SUCCESS |
| 522 | * \retval PSA_ERROR_NOT_SUPPORTED |
| 523 | */ |
| 524 | typedef psa_status_t (*pcd_cipher_opaque_ecb_t)(psa_key_slot_t key_slot, |
| 525 | psa_algorithm_t algorithm, |
| 526 | encrypt_or_decrypt_t direction, |
| 527 | const uint8_t *p_input, |
| 528 | size_t input_size, |
| 529 | uint8_t *p_output, |
| 530 | size_t output_size); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 531 | |
| 532 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 533 | * \brief A struct containing all of the function pointers needed to implement |
| 534 | * cipher operations using opaque keys. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 535 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 536 | * PSA Crypto API implementations should populate instances of the table as |
| 537 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 538 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 539 | * If one of the functions is not implemented (such as |
| 540 | * `pcd_cipher_opaque_ecb_t`), it should be set to NULL. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 541 | */ |
| 542 | struct pcd_cipher_opaque_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 543 | /** The size in bytes of the hardware-specific Opaque Cipher context |
| 544 | * structure |
| 545 | */ |
| 546 | size_t size; |
| 547 | /** Function that performs the setup operation */ |
| 548 | pcd_cipher_opaque_setup_t *p_setup; |
| 549 | /** Function that sets the IV (if necessary) */ |
| 550 | pcd_cipher_opaque_set_iv_t *p_set_iv; |
| 551 | /** Function that performs the update operation */ |
| 552 | pcd_cipher_opaque_update_t *p_update; |
| 553 | /** Function that completes the operation */ |
| 554 | pcd_cipher_opaque_finish_t *p_finish; |
| 555 | /** Function that aborts the operation */ |
| 556 | pcd_cipher_opaque_abort_t *p_abort; |
| 557 | /** Function that performs ECB mode for the cipher |
| 558 | * (Danger: ECB mode should not be used directly by clients of the PSA |
| 559 | * Crypto Client API) |
| 560 | */ |
| 561 | pcd_cipher_opaque_ecb_t *p_ecb; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 562 | }; |
| 563 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 564 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 565 | |
| 566 | /** \defgroup transparent_cipher Transparent Block Cipher |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 567 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 568 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 569 | |
| 570 | /** \brief The hardware-specific transparent-key Cipher context structure |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 571 | * The contents of this structure are implementation dependent and are |
| 572 | * therefore not described here. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 573 | */ |
| 574 | struct pcd_cipher_transparent_context_t { |
| 575 | // Implementation specific |
| 576 | }; |
| 577 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 578 | /** \brief The function prototype for the setup operation of transparent-key |
| 579 | * block cipher operations. |
| 580 | * Functions that implement the prototype should be named in the following |
| 581 | * conventions: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 582 | * ~~~~~~~~~~~~~{.c} |
| 583 | * pcd_cipher_transparent_setup_<CIPHER_NAME>_<MODE> |
| 584 | * ~~~~~~~~~~~~~ |
| 585 | * Where |
| 586 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 587 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 588 | * or for stream ciphers: |
| 589 | * ~~~~~~~~~~~~~{.c} |
| 590 | * pcd_cipher_transparent_setup_<CIPHER_NAME> |
| 591 | * ~~~~~~~~~~~~~ |
| 592 | * Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4) |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 593 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 594 | * \param[in,out] p_context A structure that will contain the |
| 595 | * hardware-specific cipher context |
| 596 | * \param[in] direction Indicates if the operation is an encrypt or a |
| 597 | * decrypt |
| 598 | * \param[in] p_key_data A buffer containing the cleartext key material |
| 599 | * to be used in the operation |
| 600 | * \param[in] key_data_size The size in bytes of the key material |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 601 | * |
| 602 | * \retval PSA_SUCCESS |
| 603 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 604 | typedef psa_status_t (*pcd_cipher_transparent_setup_t)(struct pcd_cipher_transparent_context_t *p_context, |
| 605 | encrypt_or_decrypt_t direction, |
| 606 | const uint8_t *p_key_data, |
| 607 | size_t key_data_size); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 608 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 609 | /** \brief The function prototype for the set initialization vector operation |
| 610 | * of transparent-key block cipher operations |
| 611 | * Functions that implement the prototype should be named in the following |
| 612 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 613 | * ~~~~~~~~~~~~~{.c} |
| 614 | * pcd_cipher_transparent_set_iv_<CIPHER_NAME>_<MODE> |
| 615 | * ~~~~~~~~~~~~~ |
| 616 | * Where |
| 617 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 618 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 619 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 620 | * \param[in,out] p_context A structure that contains the previously setup |
| 621 | * hardware-specific cipher context |
| 622 | * \param[in] p_iv A buffer containing the initialization vecotr |
| 623 | * \param[in] iv_length The size in bytes of the contents of `p_iv` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 624 | * |
| 625 | * \retval PSA_SUCCESS |
| 626 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 627 | typedef psa_status_t (*pcd_cipher_transparent_set_iv_t)(struct pcd_cipher_transparent_context_t *p_context, |
| 628 | const uint8_t *p_iv, |
| 629 | size_t iv_length); |
| 630 | |
| 631 | /** \brief The function prototype for the update operation of transparent-key |
| 632 | * block cipher operations. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 633 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 634 | * Functions that implement the prototype should be named in the following |
| 635 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 636 | * ~~~~~~~~~~~~~{.c} |
| 637 | * pcd_cipher_transparent_update_<CIPHER_NAME>_<MODE> |
| 638 | * ~~~~~~~~~~~~~ |
| 639 | * Where |
| 640 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 641 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 642 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 643 | * \param[in,out] p_context A hardware-specific structure for the |
| 644 | * previously started cipher operation |
| 645 | * \param[in] p_input A buffer containing the data to be |
| 646 | * encrypted or decrypted |
| 647 | * \param[in] input_size The size in bytes of the `p_input` buffer |
| 648 | * \param[out] p_output A caller-allocated buffer where the |
| 649 | * generated output will be placed |
| 650 | * \param[in] output_size The size in bytes of the `p_output` buffer |
| 651 | * \param[out] p_output_length After completion, will contain the number |
| 652 | * of bytes placed in the `p_output` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 653 | * |
| 654 | * \retval PSA_SUCCESS |
| 655 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 656 | typedef psa_status_t (*pcd_cipher_transparent_update_t)(struct pcd_cipher_transparent_context_t *p_context, |
| 657 | const uint8_t *p_input, |
| 658 | size_t input_size, |
| 659 | uint8_t *p_output, |
| 660 | size_t output_size, |
| 661 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 662 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 663 | /** \brief The function prototype for the finish operation of transparent-key |
| 664 | * block cipher operations. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 665 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 666 | * Functions that implement the prototype should be named in the following |
| 667 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 668 | * ~~~~~~~~~~~~~{.c} |
| 669 | * pcd_cipher_transparent_finish_<CIPHER_NAME>_<MODE> |
| 670 | * ~~~~~~~~~~~~~ |
| 671 | * Where |
| 672 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 673 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 674 | * |
| 675 | * \param[in] p_context A hardware-specific structure for the |
| 676 | * previously started cipher operation |
| 677 | * \param[out] p_output A caller-allocated buffer where the generated |
| 678 | * output will be placed |
| 679 | * \param[in] output_size The size in bytes of the `p_output` buffer |
| 680 | * \param[out] p_output_length After completion, will contain the number of |
| 681 | * bytes placed in the `p_output` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 682 | * |
| 683 | * \retval PSA_SUCCESS |
| 684 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 685 | typedef psa_status_t (*pcd_cipher_transparent_finish_t)(struct pcd_cipher_transparent_context_t *p_context, |
| 686 | uint8_t *p_output, |
| 687 | size_t output_size, |
| 688 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 689 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 690 | /** \brief The function prototype for the abort operation of transparent-key |
| 691 | * block cipher operations. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 692 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 693 | * Functions that implement the following prototype should be named in the |
| 694 | * following convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 695 | * ~~~~~~~~~~~~~{.c} |
| 696 | * pcd_cipher_transparent_abort_<CIPHER_NAME>_<MODE> |
| 697 | * ~~~~~~~~~~~~~ |
| 698 | * Where |
| 699 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 700 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 701 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 702 | * \param[in] p_context A hardware-specific structure for the |
| 703 | * previously started cipher operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 704 | * |
| 705 | * \retval PSA_SUCCESS |
| 706 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 707 | typedef psa_status_t (*pcd_cipher_transparent_abort_t)(struct pcd_cipher_transparent_context_t *p_context); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 708 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 709 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 710 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 711 | /** \defgroup driver_digest Message Digests |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 712 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 713 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 714 | |
| 715 | /** \brief The hardware-specific hash context structure |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 716 | * The contents of this structure are implementation dependent and are |
| 717 | * therefore not described here |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 718 | */ |
| 719 | struct pcd_hash_context_t { |
| 720 | // Implementation specific |
| 721 | }; |
| 722 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 723 | /** \brief The function prototype for the start operation of a hash (message |
| 724 | * digest) operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 725 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 726 | * Functions that implement the prototype should be named in the following |
| 727 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 728 | * ~~~~~~~~~~~~~{.c} |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 729 | * pcd_hash_<ALGO>_setup |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 730 | * ~~~~~~~~~~~~~ |
| 731 | * Where `ALGO` is the name of the underlying hash function |
| 732 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 733 | * \param[in,out] p_context A structure that will contain the |
| 734 | * hardware-specific hash context |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 735 | * |
| 736 | * \retval PSA_SUCCESS Success. |
| 737 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 738 | typedef psa_status_t (*pcd_hash_setup_t)(struct pcd_hash_context_t *p_context); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 739 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 740 | /** \brief The function prototype for the update operation of a hash (message |
| 741 | * digest) operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 742 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 743 | * Functions that implement the prototype should be named in the following |
| 744 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 745 | * ~~~~~~~~~~~~~{.c} |
| 746 | * pcd_hash_<ALGO>_update |
| 747 | * ~~~~~~~~~~~~~ |
| 748 | * Where `ALGO` is the name of the underlying algorithm |
| 749 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 750 | * \param[in,out] p_context A hardware-specific structure for the |
| 751 | * previously-established hash operation to be |
| 752 | * continued |
| 753 | * \param[in] p_input A buffer containing the message to be appended |
| 754 | * to the hash operation |
| 755 | * \param[in] input_length The size in bytes of the input message buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 756 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 757 | typedef psa_status_t (*pcd_hash_update_t)(struct pcd_hash_context_t *p_context, |
| 758 | const uint8_t *p_input, |
| 759 | size_t input_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 760 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 761 | /** \brief The prototype for the finish operation of a hash (message digest) |
| 762 | * operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 763 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 764 | * Functions that implement the prototype should be named in the following |
| 765 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 766 | * ~~~~~~~~~~~~~{.c} |
| 767 | * pcd_hash_<ALGO>_finish |
| 768 | * ~~~~~~~~~~~~~ |
| 769 | * Where `ALGO` is the name of the underlying algorithm |
| 770 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 771 | * \param[in] p_context A hardware-specific structure for the |
| 772 | * previously started hash operation to be |
| 773 | * fiinished |
| 774 | * \param[out] p_output A buffer where the generated digest will be |
| 775 | * placed |
| 776 | * \param[in] output_size The size in bytes of the buffer that has been |
| 777 | * allocated for the `p_output` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 778 | * |
| 779 | * \retval PSA_SUCCESS |
| 780 | * Success. |
| 781 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 782 | typedef psa_status_t (*pcd_hash_finish_t)(struct pcd_hash_context_t *p_context, |
| 783 | uint8_t *p_output, |
| 784 | size_t output_size); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 785 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 786 | /** \brief The function prototype for the abort operation of a hash (message |
| 787 | * digest) operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 788 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 789 | * Functions that implement the prototype should be named in the following |
| 790 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 791 | * ~~~~~~~~~~~~~{.c} |
| 792 | * pcd_hash_<ALGO>_abort |
| 793 | * ~~~~~~~~~~~~~ |
| 794 | * Where `ALGO` is the name of the underlying algorithm |
| 795 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 796 | * \param[in] p_context A hardware-specific structure for the previously |
| 797 | * started hash operation to be aborted |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 798 | */ |
| 799 | typedef void (*pcd_hash_abort_t)(struct pcd_hash_context_t *p_context); |
| 800 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 801 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 802 | |
| 803 | |
| 804 | /** \defgroup opaque_asymmetric Opaque Asymmetric Cryptography |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 805 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 806 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 807 | |
| 808 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 809 | * \brief A function that signs a hash or short message with a private key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 810 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 811 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 812 | * \param[in] alg A signature algorithm that is compatible |
| 813 | * with the type of `key` |
| 814 | * \param[in] p_hash The hash or message to sign |
| 815 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 816 | * \param[out] p_signature Buffer where the signature is to be written |
| 817 | * \param signature_size Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 818 | * \param[out] p_signature_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 819 | * that make up the returned signature value |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 820 | * |
| 821 | * \retval PSA_SUCCESS |
| 822 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 823 | typedef psa_status_t (*pcd_asymmetric_opaque_sign_t)(psa_key_slot_t key_slot, |
| 824 | psa_algorithm_t alg, |
| 825 | const uint8_t *p_hash, |
| 826 | size_t hash_length, |
| 827 | uint8_t *p_signature, |
| 828 | size_t signature_size, |
| 829 | size_t *p_signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 830 | |
| 831 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 832 | * \brief A function that verifies the signature a hash or short message using |
| 833 | * a public key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 834 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 835 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 836 | * pair |
| 837 | * \param[in] alg A signature algorithm that is compatible with |
| 838 | * the type of `key` |
| 839 | * \param[in] p_hash The hash or message whose signature is to be |
| 840 | * verified |
| 841 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 842 | * \param[in] p_signature Buffer containing the signature to verify |
| 843 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 844 | * |
| 845 | * \retval PSA_SUCCESS |
| 846 | * The signature is valid. |
| 847 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 848 | typedef psa_status_t (*pcd_asymmetric_opaque_verify_t)(psa_key_slot_t key_slot, |
| 849 | psa_algorithm_t alg, |
| 850 | const uint8_t *p_hash, |
| 851 | size_t hash_length, |
| 852 | const uint8_t *p_signature, |
| 853 | size_t signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 854 | |
| 855 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 856 | * \brief A function that encrypts a short message with a public key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 857 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 858 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 859 | * pair |
| 860 | * \param[in] alg An asymmetric encryption algorithm that is |
| 861 | * compatible with the type of `key` |
| 862 | * \param[in] p_input The message to encrypt |
| 863 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 864 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 865 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 866 | * If the algorithm does not support a |
| 867 | * salt, pass `NULL`. |
| 868 | * If the algorithm supports an optional |
| 869 | * salt and you do not want to pass a salt, |
| 870 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 871 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 872 | * supported. |
| 873 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 874 | * If `p_salt` is `NULL`, pass 0. |
| 875 | * \param[out] p_output Buffer where the encrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 876 | * be written |
| 877 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 878 | * \param[out] p_output_length On success, the number of bytes that make up |
| 879 | * the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 880 | * |
| 881 | * \retval PSA_SUCCESS |
| 882 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 883 | typedef psa_status_t (*pcd_asymmetric_opaque_encrypt_t)(psa_key_slot_t key_slot, |
| 884 | psa_algorithm_t alg, |
| 885 | const uint8_t *p_input, |
| 886 | size_t input_length, |
| 887 | const uint8_t *p_salt, |
| 888 | size_t salt_length, |
| 889 | uint8_t *p_output, |
| 890 | size_t output_size, |
| 891 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 892 | |
| 893 | /** |
| 894 | * \brief Decrypt a short message with a private key. |
| 895 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 896 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 897 | * \param[in] alg An asymmetric encryption algorithm that is |
| 898 | * compatible with the type of `key` |
| 899 | * \param[in] p_input The message to decrypt |
| 900 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 901 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 902 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 903 | * If the algorithm does not support a |
| 904 | * salt, pass `NULL`. |
| 905 | * If the algorithm supports an optional |
| 906 | * salt and you do not want to pass a salt, |
| 907 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 908 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 909 | * supported. |
| 910 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 911 | * If `p_salt` is `NULL`, pass 0. |
| 912 | * \param[out] p_output Buffer where the decrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 913 | * be written |
| 914 | * \param[in] output_size Size of the `p_output` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 915 | * \param[out] p_output_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 916 | * that make up the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 917 | * |
| 918 | * \retval PSA_SUCCESS |
| 919 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 920 | typedef psa_status_t (*pcd_asymmetric_opaque_decrypt_t)(psa_key_slot_t key_slot, |
| 921 | psa_algorithm_t alg, |
| 922 | const uint8_t *p_input, |
| 923 | size_t input_length, |
| 924 | const uint8_t *p_salt, |
| 925 | size_t salt_length, |
| 926 | uint8_t *p_output, |
| 927 | size_t output_size, |
| 928 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 929 | |
| 930 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 931 | * \brief A struct containing all of the function pointers needed to implement |
| 932 | * asymmetric cryptographic operations using opaque keys. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 933 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 934 | * PSA Crypto API implementations should populate instances of the table as |
| 935 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 936 | * |
| 937 | * If one of the functions is not implemented, it should be set to NULL. |
| 938 | */ |
| 939 | struct pcd_asymmetric_opaque_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 940 | /** Function that performs the asymmetric sign operation */ |
| 941 | pcd_asymmetric_opaque_sign_t *p_sign; |
| 942 | /** Function that performs the asymmetric verify operation */ |
| 943 | pcd_asymmetric_opaque_verify_t *p_verify; |
| 944 | /** Function that performs the asymmetric encrypt operation */ |
| 945 | pcd_asymmetric_opaque_encrypt_t *p_encrypt; |
| 946 | /** Function that performs the asymmetric decrypt operation */ |
| 947 | pcd_asymmetric_opaque_decrypt_t *p_decrypt; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 948 | }; |
| 949 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 950 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 951 | |
| 952 | /** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 953 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 954 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 955 | |
| 956 | |
| 957 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 958 | * \brief A function that signs a hash or short message with a transparent |
| 959 | * private key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 960 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 961 | * Functions that implement the prototype should be named in the following |
| 962 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 963 | * ~~~~~~~~~~~~~{.c} |
| 964 | * pcd_asymmetric_<ALGO>_sign |
| 965 | * ~~~~~~~~~~~~~ |
| 966 | * Where `ALGO` is the name of the signing algorithm |
| 967 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 968 | * \param[in] p_key A buffer containing the private key |
| 969 | * material |
| 970 | * \param[in] key_size The size in bytes of the `p_key` data |
| 971 | * \param[in] alg A signature algorithm that is compatible |
| 972 | * with the type of `p_key` |
| 973 | * \param[in] p_hash The hash or message to sign |
| 974 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 975 | * \param[out] p_signature Buffer where the signature is to be written |
| 976 | * \param[in] signature_size Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 977 | * \param[out] p_signature_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 978 | * that make up the returned signature value |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 979 | * |
| 980 | * \retval PSA_SUCCESS |
| 981 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 982 | typedef psa_status_t (*pcd_asymmetric_transparent_sign_t)(const uint8_t *p_key, |
| 983 | size_t key_size, |
| 984 | psa_algorithm_t alg, |
| 985 | const uint8_t *p_hash, |
| 986 | size_t hash_length, |
| 987 | uint8_t *p_signature, |
| 988 | size_t signature_size, |
| 989 | size_t *p_signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 990 | |
| 991 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 992 | * \brief A function that verifies the signature a hash or short message using |
| 993 | * a transparent public key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 994 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 995 | * Functions that implement the prototype should be named in the following |
| 996 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 997 | * ~~~~~~~~~~~~~{.c} |
| 998 | * pcd_asymmetric_<ALGO>_verify |
| 999 | * ~~~~~~~~~~~~~ |
| 1000 | * Where `ALGO` is the name of the signing algorithm |
| 1001 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1002 | * \param[in] p_key A buffer containing the public key material |
| 1003 | * \param[in] key_size The size in bytes of the `p_key` data |
| 1004 | * \param[in] alg A signature algorithm that is compatible with |
| 1005 | * the type of `key` |
| 1006 | * \param[in] p_hash The hash or message whose signature is to be |
| 1007 | * verified |
| 1008 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 1009 | * \param[in] p_signature Buffer containing the signature to verify |
| 1010 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1011 | * |
| 1012 | * \retval PSA_SUCCESS |
| 1013 | * The signature is valid. |
| 1014 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1015 | typedef psa_status_t (*pcd_asymmetric_transparent_verify_t)(const uint8_t *p_key, |
| 1016 | size_t key_size, |
| 1017 | psa_algorithm_t alg, |
| 1018 | const uint8_t *p_hash, |
| 1019 | size_t hash_length, |
| 1020 | const uint8_t *p_signature, |
| 1021 | size_t signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1022 | |
| 1023 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1024 | * \brief A function that encrypts a short message with a transparent public |
| 1025 | * key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1026 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1027 | * Functions that implement the prototype should be named in the following |
| 1028 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1029 | * ~~~~~~~~~~~~~{.c} |
| 1030 | * pcd_asymmetric_<ALGO>_encrypt |
| 1031 | * ~~~~~~~~~~~~~ |
| 1032 | * Where `ALGO` is the name of the encryption algorithm |
| 1033 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1034 | * \param[in] p_key A buffer containing the public key material |
| 1035 | * \param[in] key_size The size in bytes of the `p_key` data |
| 1036 | * \param[in] alg An asymmetric encryption algorithm that is |
| 1037 | * compatible with the type of `key` |
| 1038 | * \param[in] p_input The message to encrypt |
| 1039 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1040 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1041 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1042 | * If the algorithm does not support a |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1043 | * salt, pass `NULL` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1044 | * If the algorithm supports an optional |
| 1045 | * salt and you do not want to pass a salt, |
| 1046 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1047 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 1048 | * supported. |
| 1049 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1050 | * If `p_salt` is `NULL`, pass 0. |
| 1051 | * \param[out] p_output Buffer where the encrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1052 | * be written |
| 1053 | * \param[in] output_size Size of the `p_output` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1054 | * \param[out] p_output_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1055 | * that make up the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1056 | * |
| 1057 | * \retval PSA_SUCCESS |
| 1058 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1059 | typedef psa_status_t (*pcd_asymmetric_transparent_encrypt_t)(const uint8_t *p_key, |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1060 | size_t key_size, |
| 1061 | psa_algorithm_t alg, |
| 1062 | const uint8_t *p_input, |
| 1063 | size_t input_length, |
| 1064 | const uint8_t *p_salt, |
| 1065 | size_t salt_length, |
| 1066 | uint8_t *p_output, |
| 1067 | size_t output_size, |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1068 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1069 | |
| 1070 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1071 | * \brief Decrypt a short message with a transparent private key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1072 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1073 | * Functions that implement the prototype should be named in the following |
| 1074 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1075 | * ~~~~~~~~~~~~~{.c} |
| 1076 | * pcd_asymmetric_<ALGO>_decrypt |
| 1077 | * ~~~~~~~~~~~~~ |
| 1078 | * Where `ALGO` is the name of the encryption algorithm |
| 1079 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1080 | * \param[in] p_key A buffer containing the private key material |
| 1081 | * \param[in] key_size The size in bytes of the `p_key` data |
| 1082 | * \param[in] alg An asymmetric encryption algorithm that is |
| 1083 | * compatible with the type of `key` |
| 1084 | * \param[in] p_input The message to decrypt |
| 1085 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1086 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1087 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1088 | * If the algorithm does not support a |
| 1089 | * salt, pass `NULL`. |
| 1090 | * If the algorithm supports an optional |
| 1091 | * salt and you do not want to pass a salt, |
| 1092 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1093 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 1094 | * supported |
| 1095 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 1096 | * If `p_salt` is `NULL`, pass 0 |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1097 | * \param[out] p_output Buffer where the decrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1098 | * be written |
| 1099 | * \param[in] output_size Size of the `p_output` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1100 | * \param[out] p_output_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1101 | * that make up the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1102 | * |
| 1103 | * \retval PSA_SUCCESS |
| 1104 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1105 | typedef psa_status_t (*pcd_asymmetric_transparent_decrypt_t)(const uint8_t *p_key, |
| 1106 | size_t key_size, |
| 1107 | psa_algorithm_t alg, |
| 1108 | const uint8_t *p_input, |
| 1109 | size_t input_length, |
| 1110 | const uint8_t *p_salt, |
| 1111 | size_t salt_length, |
| 1112 | uint8_t *p_output, |
| 1113 | size_t output_size, |
| 1114 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1115 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1116 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1117 | |
| 1118 | /** \defgroup aead_opaque AEAD Opaque |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1119 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1120 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1121 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1122 | /** \brief Process an authenticated encryption operation using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1123 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1124 | * \param[in] key_slot Slot containing the key to use. |
| 1125 | * \param[in] algorithm The AEAD algorithm to compute |
| 1126 | * (\c PSA_ALG_XXX value such that |
| 1127 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1128 | * \param[in] p_nonce Nonce or IV to use |
| 1129 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 1130 | * \param[in] p_additional_data Additional data that will be |
| 1131 | * authenticated but not encrypted |
| 1132 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 1133 | * \param[in] p_plaintext Data that will be authenticated and |
| 1134 | * encrypted |
| 1135 | * \param[in] plaintext_length Size of `p_plaintext` in bytes |
| 1136 | * \param[out] p_ciphertext Output buffer for the authenticated and |
| 1137 | * encrypted data. The additional data is |
| 1138 | * not part of this output. For algorithms |
| 1139 | * where the encrypted data and the |
| 1140 | * authentication tag are defined as |
| 1141 | * separate outputs, the authentication |
| 1142 | * tag is appended to the encrypted data. |
| 1143 | * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in |
| 1144 | * bytes |
| 1145 | * \param[out] p_ciphertext_length On success, the size of the output in |
| 1146 | * the `p_ciphertext` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1147 | * |
| 1148 | * \retval #PSA_SUCCESS |
| 1149 | * Success. |
| 1150 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1151 | typedef psa_status_t (*psa_aead_opaque_encrypt_t)(psa_key_slot_t key_slot, |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1152 | psa_algorithm_t algorithm, |
| 1153 | const uint8_t *p_nonce, |
| 1154 | size_t nonce_length, |
| 1155 | const uint8_t *p_additional_data, |
| 1156 | size_t additional_data_length, |
| 1157 | const uint8_t *p_plaintext, |
| 1158 | size_t plaintext_length, |
| 1159 | uint8_t *p_ciphertext, |
| 1160 | size_t ciphertext_size, |
| 1161 | size_t *p_ciphertext_length); |
| 1162 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1163 | /** Process an authenticated decryption operation using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1164 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1165 | * \param[in] key_slot Slot containing the key to use |
| 1166 | * \param[in] algorithm The AEAD algorithm to compute |
| 1167 | * (\c PSA_ALG_XXX value such that |
| 1168 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1169 | * \param[in] p_nonce Nonce or IV to use |
| 1170 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 1171 | * \param[in] p_additional_data Additional data that has been |
| 1172 | * authenticated but not encrypted |
| 1173 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 1174 | * \param[in] p_ciphertext Data that has been authenticated and |
| 1175 | * encrypted. |
| 1176 | * For algorithms where the encrypted data |
| 1177 | * and the authentication tag are defined |
| 1178 | * as separate inputs, the buffer must |
| 1179 | * contain the encrypted data followed by |
| 1180 | * the authentication tag. |
| 1181 | * \param[in] ciphertext_length Size of `p_ciphertext` in bytes |
| 1182 | * \param[out] p_plaintext Output buffer for the decrypted data |
| 1183 | * \param[in] plaintext_size Size of the `p_plaintext` buffer in |
| 1184 | * bytes |
| 1185 | * \param[out] p_plaintext_length On success, the size of the output in |
| 1186 | * the `p_plaintext` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1187 | * |
| 1188 | * \retval #PSA_SUCCESS |
| 1189 | * Success. |
| 1190 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1191 | typedef psa_status_t (*psa_aead_opaque_decrypt_t)(psa_key_slot_t key_slot, |
| 1192 | psa_algorithm_t algorithm, |
| 1193 | const uint8_t *p_nonce, |
| 1194 | size_t nonce_length, |
| 1195 | const uint8_t *p_additional_data, |
| 1196 | size_t additional_data_length, |
| 1197 | const uint8_t *p_ciphertext, |
| 1198 | size_t ciphertext_length, |
| 1199 | uint8_t *p_plaintext, |
| 1200 | size_t plaintext_size, |
| 1201 | size_t *p_plaintext_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1202 | |
| 1203 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1204 | * \brief A struct containing all of the function pointers needed to implement |
| 1205 | * Authenticated Encryption with Additional Data operations using opaque keys |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1206 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1207 | * PSA Crypto API implementations should populate instances of the table as |
| 1208 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1209 | * |
| 1210 | * If one of the functions is not implemented, it should be set to NULL. |
| 1211 | */ |
| 1212 | struct psa_aead_opaque_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1213 | /** Function that performs the AEAD encrypt operation */ |
| 1214 | psa_aead_opaque_encrypt_t *p_encrypt; |
| 1215 | /** Function that performs the AEAD decrypt operation */ |
| 1216 | psa_aead_opaque_decrypt_t *p_decrypt; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1217 | }; |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1218 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1219 | |
| 1220 | /** \defgroup aead_transparent AEAD Transparent |
| 1221 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1222 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1223 | |
| 1224 | /** Process an authenticated encryption operation. |
| 1225 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1226 | * Functions that implement the prototype should be named in the following |
| 1227 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1228 | * ~~~~~~~~~~~~~{.c} |
| 1229 | * pcd_aead_<ALGO>_encrypt |
| 1230 | * ~~~~~~~~~~~~~ |
| 1231 | * Where `ALGO` is the name of the AEAD algorithm |
| 1232 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1233 | * \param[in] p_key A pointer to the key material |
| 1234 | * \param[in] key_length The size in bytes of the key material |
| 1235 | * \param[in] alg The AEAD algorithm to compute |
| 1236 | * (\c PSA_ALG_XXX value such that |
| 1237 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1238 | * \param[in] nonce Nonce or IV to use |
| 1239 | * \param[in] nonce_length Size of the `nonce` buffer in bytes |
| 1240 | * \param[in] additional_data Additional data that will be MACed |
| 1241 | * but not encrypted. |
| 1242 | * \param[in] additional_data_length Size of `additional_data` in bytes |
| 1243 | * \param[in] plaintext Data that will be MACed and |
| 1244 | * encrypted. |
| 1245 | * \param[in] plaintext_length Size of `plaintext` in bytes |
| 1246 | * \param[out] ciphertext Output buffer for the authenticated and |
| 1247 | * encrypted data. The additional data is |
| 1248 | * not part of this output. For algorithms |
| 1249 | * where the encrypted data and the |
| 1250 | * authentication tag are defined as |
| 1251 | * separate outputs, the authentication |
| 1252 | * tag is appended to the encrypted data. |
| 1253 | * \param[in] ciphertext_size Size of the `ciphertext` buffer in |
| 1254 | * bytes |
| 1255 | * This must be at least |
| 1256 | * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`, |
| 1257 | * `plaintext_length`). |
| 1258 | * \param[out] ciphertext_length On success, the size of the output in |
| 1259 | * the `ciphertext` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1260 | * |
| 1261 | * \retval #PSA_SUCCESS |
| 1262 | |
| 1263 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1264 | typedef psa_status_t (*psa_aead_transparent_encrypt_t)(const uint8_t *p_key, |
| 1265 | size_t key_length, |
| 1266 | psa_algorithm_t alg, |
| 1267 | const uint8_t *nonce, |
| 1268 | size_t nonce_length, |
| 1269 | const uint8_t *additional_data, |
| 1270 | size_t additional_data_length, |
| 1271 | const uint8_t *plaintext, |
| 1272 | size_t plaintext_length, |
| 1273 | uint8_t *ciphertext, |
| 1274 | size_t ciphertext_size, |
| 1275 | size_t *ciphertext_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1276 | |
| 1277 | /** Process an authenticated decryption operation. |
| 1278 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1279 | * Functions that implement the prototype should be named in the following |
| 1280 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1281 | * ~~~~~~~~~~~~~{.c} |
| 1282 | * pcd_aead_<ALGO>_decrypt |
| 1283 | * ~~~~~~~~~~~~~ |
| 1284 | * Where `ALGO` is the name of the AEAD algorithm |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1285 | * \param[in] p_key A pointer to the key material |
| 1286 | * \param[in] key_length The size in bytes of the key material |
| 1287 | * \param[in] alg The AEAD algorithm to compute |
| 1288 | * (\c PSA_ALG_XXX value such that |
| 1289 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1290 | * \param[in] nonce Nonce or IV to use |
| 1291 | * \param[in] nonce_length Size of the `nonce` buffer in bytes |
| 1292 | * \param[in] additional_data Additional data that has been MACed |
| 1293 | * but not encrypted |
| 1294 | * \param[in] additional_data_length Size of `additional_data` in bytes |
| 1295 | * \param[in] ciphertext Data that has been MACed and |
| 1296 | * encrypted |
| 1297 | * For algorithms where the encrypted data |
| 1298 | * and the authentication tag are defined |
| 1299 | * as separate inputs, the buffer must |
| 1300 | * contain the encrypted data followed by |
| 1301 | * the authentication tag. |
| 1302 | * \param[in] ciphertext_length Size of `ciphertext` in bytes |
| 1303 | * \param[out] plaintext Output buffer for the decrypted data |
| 1304 | * \param[in] plaintext_size Size of the `plaintext` buffer in |
| 1305 | * bytes |
| 1306 | * This must be at least |
| 1307 | * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`, |
| 1308 | * `ciphertext_length`). |
| 1309 | * \param[out] plaintext_length On success, the size of the output |
| 1310 | * in the \b plaintext buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1311 | * |
| 1312 | * \retval #PSA_SUCCESS |
| 1313 | * Success. |
| 1314 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1315 | typedef psa_status_t (*psa_aead_transparent_decrypt_t)(const uint8_t *p_key, |
| 1316 | size_t key_length, |
| 1317 | psa_algorithm_t alg, |
| 1318 | const uint8_t *nonce, |
| 1319 | size_t nonce_length, |
| 1320 | const uint8_t *additional_data, |
| 1321 | size_t additional_data_length, |
| 1322 | const uint8_t *ciphertext, |
| 1323 | size_t ciphertext_length, |
| 1324 | uint8_t *plaintext, |
| 1325 | size_t plaintext_size, |
| 1326 | size_t *plaintext_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1327 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1328 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1329 | |
| 1330 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1331 | /** \defgroup driver_rng Entropy Generation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1332 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1333 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1334 | |
| 1335 | /** \brief A hardware-specific structure for a entropy providing hardware |
| 1336 | */ |
| 1337 | struct pcd_entropy_context_t { |
| 1338 | // Implementation specific |
| 1339 | }; |
| 1340 | |
| 1341 | /** \brief Initialize an entropy driver |
| 1342 | * |
| 1343 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1344 | * \param[in,out] p_context A hardware-specific structure |
| 1345 | * containing any context information for |
| 1346 | * the implementation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1347 | * |
| 1348 | * \retval PSA_SUCCESS |
| 1349 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1350 | typedef psa_status_t (*pcd_entropy_init_t)(struct pcd_entropy_context_t *p_context); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1351 | |
| 1352 | /** \brief Get a specified number of bytes from the entropy source |
| 1353 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1354 | * It retrives `buffer_size` bytes of data from the entropy source. The entropy |
| 1355 | * source will always fill the provided buffer to its full size, however, most |
| 1356 | * entropy sources have biases, and the actual amount of entropy contained in |
| 1357 | * the buffer will be less than the number of bytes. |
| 1358 | * The driver will return the actual number of bytes of entropy placed in the |
| 1359 | * buffer in `p_received_entropy_bytes`. |
| 1360 | * A PSA Crypto API implementation will likely feed the output of this function |
| 1361 | * into a Digital Random Bit Generator (DRBG), and typically has a minimum |
| 1362 | * amount of entropy that it needs. |
| 1363 | * To accomplish this, the PSA Crypto implementation should be designed to call |
| 1364 | * this function multiple times until it has received the required amount of |
| 1365 | * entropy from the entropy source. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1366 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1367 | * \param[in,out] p_context A hardware-specific structure |
| 1368 | * containing any context information |
| 1369 | * for the implementation |
| 1370 | * \param[out] p_buffer A caller-allocated buffer for the |
| 1371 | * retrieved bytes to be placed in |
| 1372 | * \param[in] buffer_size The allocated size of `p_buffer` |
| 1373 | * \param[out] p_received_entropy_bytes The amount of entropy (in bytes) |
| 1374 | * actually provided in `p_buffer` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1375 | * |
| 1376 | * \retval PSA_SUCCESS |
| 1377 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1378 | typedef psa_status_t (*pcd_entropy_get_bytes_t)(struct pcd_entropy_context_t *p_context, |
| 1379 | uint8_t *p_buffer, |
| 1380 | uint32_t buffer_size, |
| 1381 | uint32_t *p_received_entropy_bytes); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1382 | |
| 1383 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1384 | * \brief A struct containing all of the function pointers needed to interface |
| 1385 | * to an entropy source |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1386 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1387 | * PSA Crypto API implementations should populate instances of the table as |
| 1388 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1389 | * |
| 1390 | * If one of the functions is not implemented, it should be set to NULL. |
| 1391 | */ |
| 1392 | struct pcd_entropy_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1393 | /** Function that performs initialization for the entropy source */ |
| 1394 | pcd_entropy_init_t *p_init; |
| 1395 | /** Function that performs the get_bytes operation for the entropy source |
| 1396 | */ |
| 1397 | pcd_entropy_get_bytes_t *p_get_bytes; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1398 | }; |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1399 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1400 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1401 | /** \defgroup driver_key_management Key Management |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1402 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1403 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1404 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1405 | /** \brief Import a key in binary format |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1406 | * |
| 1407 | * This function can support any output from psa_export_key(). Refer to the |
| 1408 | * documentation of psa_export_key() for the format for each key type. |
| 1409 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1410 | * \param[in] key_slot Slot where the key will be stored. This must be a |
| 1411 | * valid slot for a key of the chosen type. It must |
| 1412 | * be unoccupied. |
| 1413 | * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value). |
| 1414 | * \param[in] p_data Buffer containing the key data. |
| 1415 | * \param[in] data_length Size of the `data` buffer in bytes. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1416 | * |
| 1417 | * \retval #PSA_SUCCESS |
| 1418 | * Success. |
| 1419 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1420 | typedef psa_status_t (*pcd_opaque_import_key_t)(psa_key_slot_t key_slot, |
| 1421 | psa_key_type_t type, |
| 1422 | const uint8_t *p_data, |
| 1423 | size_t data_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1424 | |
| 1425 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1426 | * \brief Destroy a key and restore the slot to its default state |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1427 | * |
| 1428 | * This function destroys the content of the key slot from both volatile |
| 1429 | * memory and, if applicable, non-volatile storage. Implementations shall |
| 1430 | * make a best effort to ensure that any previous content of the slot is |
| 1431 | * unrecoverable. |
| 1432 | * |
| 1433 | * This function also erases any metadata such as policies. It returns the |
| 1434 | * specified slot to its default state. |
| 1435 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1436 | * \param[in] key_slot The key slot to erase. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1437 | * |
| 1438 | * \retval #PSA_SUCCESS |
| 1439 | * The slot's content, if any, has been erased. |
| 1440 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1441 | typedef psa_status_t (*pcd_destroy_key_t)(psa_key_slot_t key); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1442 | |
| 1443 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1444 | * \brief Export a key in binary format |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1445 | * |
| 1446 | * The output of this function can be passed to psa_import_key() to |
| 1447 | * create an equivalent object. |
| 1448 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1449 | * If a key is created with `psa_import_key()` and then exported with |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1450 | * this function, it is not guaranteed that the resulting data is |
| 1451 | * identical: the implementation may choose a different representation |
| 1452 | * of the same key if the format permits it. |
| 1453 | * |
| 1454 | * For standard key types, the output format is as follows: |
| 1455 | * |
| 1456 | * - For symmetric keys (including MAC keys), the format is the |
| 1457 | * raw bytes of the key. |
| 1458 | * - For DES, the key data consists of 8 bytes. The parity bits must be |
| 1459 | * correct. |
| 1460 | * - For Triple-DES, the format is the concatenation of the |
| 1461 | * two or three DES keys. |
| 1462 | * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format |
| 1463 | * is the non-encrypted DER representation defined by PKCS\#1 (RFC 8017) |
| 1464 | * as RSAPrivateKey. |
| 1465 | * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format |
| 1466 | * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo. |
| 1467 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1468 | * \param[in] key Slot whose content is to be exported. This must |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1469 | * be an occupied key slot. |
| 1470 | * \param[out] p_data Buffer where the key data is to be written. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1471 | * \param[in] data_size Size of the `p_data` buffer in bytes. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1472 | * \param[out] p_data_length On success, the number of bytes |
| 1473 | * that make up the key data. |
| 1474 | * |
| 1475 | * \retval #PSA_SUCCESS |
| 1476 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 1477 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1478 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1479 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1480 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1481 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1482 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1483 | typedef psa_status_t (*pcd_export_key_t)(psa_key_slot_t key, |
| 1484 | uint8_t *p_data, |
| 1485 | size_t data_size, |
| 1486 | size_t *p_data_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1487 | |
| 1488 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1489 | * \brief Export a public key or the public part of a key pair in binary format |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1490 | * |
| 1491 | * The output of this function can be passed to psa_import_key() to |
| 1492 | * create an object that is equivalent to the public key. |
| 1493 | * |
| 1494 | * For standard key types, the output format is as follows: |
| 1495 | * |
| 1496 | * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY), |
| 1497 | * the format is the DER representation of the public key defined by RFC 5280 |
| 1498 | * as SubjectPublicKeyInfo. |
| 1499 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1500 | * \param[in] key_slot Slot whose content is to be exported. This must |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1501 | * be an occupied key slot. |
| 1502 | * \param[out] p_data Buffer where the key data is to be written. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1503 | * \param[in] data_size Size of the `data` buffer in bytes. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1504 | * \param[out] p_data_length On success, the number of bytes |
| 1505 | * that make up the key data. |
| 1506 | * |
| 1507 | * \retval #PSA_SUCCESS |
| 1508 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1509 | typedef psa_status_t (*pcd_export_public_key_t)(psa_key_slot_t key, |
| 1510 | uint8_t *p_data, |
| 1511 | size_t data_size, |
| 1512 | size_t *p_data_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1513 | |
| 1514 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1515 | * \brief A struct containing all of the function pointers needed to for key |
| 1516 | * management using opaque keys |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1517 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1518 | * PSA Crypto API implementations should populate instances of the table as |
| 1519 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1520 | * |
| 1521 | * If one of the functions is not implemented, it should be set to NULL. |
| 1522 | */ |
| 1523 | struct pcd_key_management_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1524 | /** Function that performs the key import operation */ |
| 1525 | pcd_opaque_import_key_t *p_import; |
| 1526 | /** Function that performs the key destroy operation */ |
| 1527 | pcd_destroy_key_t *p_destroy; |
| 1528 | /** Function that performs the key export operation */ |
| 1529 | pcd_export_key_t *p_export; |
| 1530 | /** Function that perforsm the public key export operation */ |
| 1531 | pcd_export_public_key_t *p_export_public; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1532 | }; |
| 1533 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1534 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1535 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1536 | /** \defgroup driver_derivation Key Derivation and Agreement |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1537 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1538 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1539 | |
| 1540 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1541 | * Key derivation is the process of generating new key material using an |
| 1542 | * existing key and additional parameters, iterating through a basic |
| 1543 | * cryptographic function, such as a hash. |
| 1544 | * Key agreement is a part of cryptographic protocols that allows two parties |
| 1545 | * to agree on the same key value, but starting from different original key |
| 1546 | * material. |
| 1547 | * The flows are similar, and the PSA Crypto Driver API uses the same functions |
| 1548 | * for both of the flows. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1549 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1550 | * There are two different final functions for the flows, |
| 1551 | * `pcd_key_derivation_derive` and `pcd_key_derivation_export`. |
| 1552 | * `pcd_key_derivation_derive` is used when the key material should be placed |
| 1553 | * in a slot on the hardware and not exposed to the caller. |
| 1554 | * `pcd_key_derivation_export` is used when the key material should be returned |
| 1555 | * to the PSA Cryptographic API implementation. |
| 1556 | * |
| 1557 | * Different key derivation algorithms require a different number of inputs. |
| 1558 | * Instead of having an API that takes as input variable length arrays, which |
| 1559 | * can be problemmatic to manage on embedded platforms, the inputs are passed |
| 1560 | * to the driver via a function, `pcd_key_derivation_collateral`, that is |
| 1561 | * called multiple times with different `collateral_id`s. Thus, for a key |
| 1562 | * derivation algorithm that required 3 paramter inputs, the flow would look |
| 1563 | * something like: |
| 1564 | * ~~~~~~~~~~~~~{.c} |
| 1565 | * pcd_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes); |
| 1566 | * pcd_key_derivation_collateral(kdf_algorithm_collateral_id_0, |
| 1567 | * p_collateral_0, |
| 1568 | * collateral_0_size); |
| 1569 | * pcd_key_derivation_collateral(kdf_algorithm_collateral_id_1, |
| 1570 | * p_collateral_1, |
| 1571 | * collateral_1_size); |
| 1572 | * pcd_key_derivation_collateral(kdf_algorithm_collateral_id_2, |
| 1573 | * p_collateral_2, |
| 1574 | * collateral_2_size); |
| 1575 | * pcd_key_derivation_derive(); |
| 1576 | * ~~~~~~~~~~~~~ |
| 1577 | * |
| 1578 | * key agreement example: |
| 1579 | * ~~~~~~~~~~~~~{.c} |
| 1580 | * pcd_key_derivation_setup(alg, source_key. dest_key_size_bytes); |
| 1581 | * pcd_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size); |
| 1582 | * pcd_key_derivation_export(p_session_key, |
| 1583 | * session_key_size, |
| 1584 | * &session_key_length); |
| 1585 | * ~~~~~~~~~~~~~ |
| 1586 | */ |
| 1587 | |
| 1588 | struct pcd_key_derivation_context_t { |
| 1589 | // Implementation specific |
| 1590 | }; |
| 1591 | |
| 1592 | /** \brief Set up a key derivation operation by specifying the algorithm and |
| 1593 | * the source key sot |
| 1594 | * |
| 1595 | * \param[in,out] p_context A hardware-specific structure containing any |
| 1596 | * context information for the implementation |
| 1597 | * \param[in] kdf_alg The algorithm to be used for the key derivation |
| 1598 | * \param[in] souce_key The key to be used as the source material for the |
| 1599 | * key derivation |
| 1600 | * |
| 1601 | * \retval PSA_SUCCESS |
| 1602 | */ |
| 1603 | typedef psa_status_t (*pcd_key_derivation_setup_t)(struct pcd_key_derivation_context_t *p_context, |
| 1604 | psa_algorithm_t kdf_alg, |
| 1605 | psa_key_slot_t source_key); |
| 1606 | |
| 1607 | /** \brief Provide collateral (parameters) needed for a key derivation or key |
| 1608 | * agreement operation |
| 1609 | * |
| 1610 | * Since many key derivation algorithms require multiple parameters, it is |
| 1611 | * expeced that this function may be called multiple times for the same |
| 1612 | * operation, each with a different algorithm-specific `collateral_id` |
| 1613 | * |
| 1614 | * \param[in,out] p_context A hardware-specific structure containing any |
| 1615 | * context information for the implementation |
| 1616 | * \param[in] collateral_id An ID for the collateral being provided |
| 1617 | * \param[in] p_collateral A buffer containing the collateral data |
| 1618 | * \param[in] collateral_size The size in bytes of the collateral |
| 1619 | * |
| 1620 | * \retval PSA_SUCCESS |
| 1621 | */ |
| 1622 | typedef psa_status_t (*pcd_key_derivation_collateral_t)(struct pcd_key_derivation_context_t *p_context, |
| 1623 | uint32_t collateral_id, |
| 1624 | const uint8_t p_collateral, |
| 1625 | size_t collateral_size); |
| 1626 | |
| 1627 | /** \brief Perform the final key derivation step and place the generated key |
| 1628 | * material in a slot |
| 1629 | * \param[in,out] p_context A hardware-specific structure containing any |
| 1630 | * context information for the implementation |
| 1631 | * \param[in] dest_key The slot where the generated key material |
| 1632 | * should be placed |
| 1633 | * |
| 1634 | * \retval PSA_SUCCESS |
| 1635 | */ |
| 1636 | typedef psa_status_t (*pcd_key_derivation_derive_t)(struct pcd_key_derivation_context_t *p_context, |
| 1637 | psa_key_slot_t dest_key); |
| 1638 | |
| 1639 | /** \brief Perform the final step of a key agreement and place the generated |
| 1640 | * key material in a buffer |
| 1641 | * |
| 1642 | * \param[out] p_output Buffer in which to place the generated key |
| 1643 | * material |
| 1644 | * \param[in] output_size The size in bytes of `p_output` |
| 1645 | * \param[out] p_output_length Upon success, contains the number of bytes of |
| 1646 | * key material placed in `p_output` |
| 1647 | * |
| 1648 | * \retval PSA_SUCCESS |
| 1649 | */ |
| 1650 | typedef psa_status_t (*pcd_key_derivation_export_t)(uint8_t *p_output, |
| 1651 | size_t output_size, |
| 1652 | size_t *p_output_length); |
| 1653 | |
| 1654 | /** |
| 1655 | * \brief A struct containing all of the function pointers needed to for key |
| 1656 | * derivation and agreement |
| 1657 | * |
| 1658 | * PSA Crypto API implementations should populate instances of the table as |
| 1659 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1660 | * |
| 1661 | * If one of the functions is not implemented, it should be set to NULL. |
| 1662 | */ |
| 1663 | struct pcd_key_derivation_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1664 | /** Function that performs the key derivation setup */ |
| 1665 | pcd_key_derivation_setup_t *p_setup; |
| 1666 | /** Function that sets the key derivation collateral */ |
| 1667 | pcd_key_derivation_collateral_t *p_collateral; |
| 1668 | /** Function that performs the final key derivation step */ |
| 1669 | pcd_key_derivation_derive_t *p_derive; |
| 1670 | /** Function that perforsm the final key derivation or agreement and |
| 1671 | * exports the key */ |
| 1672 | pcd_key_derivation_export_t *p_export; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1673 | }; |
| 1674 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame^] | 1675 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1676 | |
| 1677 | #endif // __PSA_CRYPTO_DRIVER_H__ |