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 | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 80 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 88 | * bytes placed in the `p_mac` 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 | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 101 | * \param[in,out] p_context A hardware-specific structure for the previously |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 120 | * \param[in,out] p_context A hardware-specific structure for the previously |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 129 | * \param[in] input_length The size in bytes of `p_input` |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 130 | * \param[in] key_slot The slot of the key to be used |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 131 | * \param[in] alg The algorithm to be used to underlie the MAC |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 288 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | * |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 313 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 314 | * previously started MAC operation to be |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 315 | * verified and finished |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | * |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 339 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 340 | * previously started MAC operation to be |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 341 | * aborted |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | * |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 478 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 479 | * previously started cipher operation |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 480 | * \param[out] p_output The caller-allocated buffer where the output |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | * |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 497 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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` |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 516 | * \param[out] p_output The caller-allocated buffer where the output will |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | * |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 675 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 702 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 771 | * \param[in,out] p_context A hardware-specific structure for the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 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 | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 778 | * \param[out] p_output_length The number of bytes placed in `p_output` after |
| 779 | * success |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 780 | * |
| 781 | * \retval PSA_SUCCESS |
| 782 | * Success. |
| 783 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 784 | typedef psa_status_t (*pcd_hash_finish_t)(struct pcd_hash_context_t *p_context, |
| 785 | uint8_t *p_output, |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 786 | size_t output_size, |
| 787 | size_t *p_output_length); |
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 | /** \brief The function prototype for the abort operation of a hash (message |
| 790 | * digest) operation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 791 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 792 | * Functions that implement the prototype should be named in the following |
| 793 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 794 | * ~~~~~~~~~~~~~{.c} |
| 795 | * pcd_hash_<ALGO>_abort |
| 796 | * ~~~~~~~~~~~~~ |
| 797 | * Where `ALGO` is the name of the underlying algorithm |
| 798 | * |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 799 | * \param[in,out] p_context A hardware-specific structure for the previously |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 800 | * started hash operation to be aborted |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 801 | */ |
| 802 | typedef void (*pcd_hash_abort_t)(struct pcd_hash_context_t *p_context); |
| 803 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 804 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 805 | |
| 806 | |
| 807 | /** \defgroup opaque_asymmetric Opaque Asymmetric Cryptography |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 808 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 809 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 810 | |
| 811 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 812 | * \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] | 813 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 814 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 815 | * \param[in] alg A signature algorithm that is compatible |
| 816 | * with the type of `key` |
| 817 | * \param[in] p_hash The hash or message to sign |
| 818 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 819 | * \param[out] p_signature Buffer where the signature is to be written |
Derek Miller | f3d0a56 | 2018-10-18 16:41:08 -0500 | [diff] [blame^] | 820 | * \param[in] signature_size Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 821 | * \param[out] p_signature_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 822 | * that make up the returned signature value |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 823 | * |
| 824 | * \retval PSA_SUCCESS |
| 825 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 826 | typedef psa_status_t (*pcd_asymmetric_opaque_sign_t)(psa_key_slot_t key_slot, |
| 827 | psa_algorithm_t alg, |
| 828 | const uint8_t *p_hash, |
| 829 | size_t hash_length, |
| 830 | uint8_t *p_signature, |
| 831 | size_t signature_size, |
| 832 | size_t *p_signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 833 | |
| 834 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 835 | * \brief A function that verifies the signature a hash or short message using |
| 836 | * a public key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 837 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 838 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 839 | * pair |
| 840 | * \param[in] alg A signature algorithm that is compatible with |
| 841 | * the type of `key` |
| 842 | * \param[in] p_hash The hash or message whose signature is to be |
| 843 | * verified |
| 844 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 845 | * \param[in] p_signature Buffer containing the signature to verify |
| 846 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 847 | * |
| 848 | * \retval PSA_SUCCESS |
| 849 | * The signature is valid. |
| 850 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 851 | typedef psa_status_t (*pcd_asymmetric_opaque_verify_t)(psa_key_slot_t key_slot, |
| 852 | psa_algorithm_t alg, |
| 853 | const uint8_t *p_hash, |
| 854 | size_t hash_length, |
| 855 | const uint8_t *p_signature, |
| 856 | size_t signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 857 | |
| 858 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 859 | * \brief A function that encrypts a short message with a public key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 860 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 861 | * \param[in] key_slot Key slot of a public key or an asymmetric key |
| 862 | * pair |
| 863 | * \param[in] alg An asymmetric encryption algorithm that is |
| 864 | * compatible with the type of `key` |
| 865 | * \param[in] p_input The message to encrypt |
| 866 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 867 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 868 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 869 | * If the algorithm does not support a |
| 870 | * salt, pass `NULL`. |
| 871 | * If the algorithm supports an optional |
| 872 | * salt and you do not want to pass a salt, |
| 873 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 874 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 875 | * supported. |
| 876 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 877 | * If `p_salt` is `NULL`, pass 0. |
| 878 | * \param[out] p_output Buffer where the encrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 879 | * be written |
| 880 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 881 | * \param[out] p_output_length On success, the number of bytes that make up |
| 882 | * the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 883 | * |
| 884 | * \retval PSA_SUCCESS |
| 885 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 886 | typedef psa_status_t (*pcd_asymmetric_opaque_encrypt_t)(psa_key_slot_t key_slot, |
| 887 | psa_algorithm_t alg, |
| 888 | const uint8_t *p_input, |
| 889 | size_t input_length, |
| 890 | const uint8_t *p_salt, |
| 891 | size_t salt_length, |
| 892 | uint8_t *p_output, |
| 893 | size_t output_size, |
| 894 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 895 | |
| 896 | /** |
| 897 | * \brief Decrypt a short message with a private key. |
| 898 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 899 | * \param[in] key_slot Key slot of an asymmetric key pair |
| 900 | * \param[in] alg An asymmetric encryption algorithm that is |
| 901 | * compatible with the type of `key` |
| 902 | * \param[in] p_input The message to decrypt |
| 903 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 904 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 905 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 906 | * If the algorithm does not support a |
| 907 | * salt, pass `NULL`. |
| 908 | * If the algorithm supports an optional |
| 909 | * salt and you do not want to pass a salt, |
| 910 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 911 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 912 | * supported. |
| 913 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 914 | * If `p_salt` is `NULL`, pass 0. |
| 915 | * \param[out] p_output Buffer where the decrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 916 | * be written |
| 917 | * \param[in] output_size Size of the `p_output` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 918 | * \param[out] p_output_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 919 | * that make up the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 920 | * |
| 921 | * \retval PSA_SUCCESS |
| 922 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 923 | typedef psa_status_t (*pcd_asymmetric_opaque_decrypt_t)(psa_key_slot_t key_slot, |
| 924 | psa_algorithm_t alg, |
| 925 | const uint8_t *p_input, |
| 926 | size_t input_length, |
| 927 | const uint8_t *p_salt, |
| 928 | size_t salt_length, |
| 929 | uint8_t *p_output, |
| 930 | size_t output_size, |
| 931 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 932 | |
| 933 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 934 | * \brief A struct containing all of the function pointers needed to implement |
| 935 | * asymmetric cryptographic operations using opaque keys. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 936 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 937 | * PSA Crypto API implementations should populate instances of the table as |
| 938 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 939 | * |
| 940 | * If one of the functions is not implemented, it should be set to NULL. |
| 941 | */ |
| 942 | struct pcd_asymmetric_opaque_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 943 | /** Function that performs the asymmetric sign operation */ |
| 944 | pcd_asymmetric_opaque_sign_t *p_sign; |
| 945 | /** Function that performs the asymmetric verify operation */ |
| 946 | pcd_asymmetric_opaque_verify_t *p_verify; |
| 947 | /** Function that performs the asymmetric encrypt operation */ |
| 948 | pcd_asymmetric_opaque_encrypt_t *p_encrypt; |
| 949 | /** Function that performs the asymmetric decrypt operation */ |
| 950 | pcd_asymmetric_opaque_decrypt_t *p_decrypt; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 951 | }; |
| 952 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 953 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 954 | |
| 955 | /** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 956 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 957 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 958 | |
| 959 | |
| 960 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 961 | * \brief A function that signs a hash or short message with a transparent |
| 962 | * private key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 963 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 964 | * Functions that implement the prototype should be named in the following |
| 965 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 966 | * ~~~~~~~~~~~~~{.c} |
| 967 | * pcd_asymmetric_<ALGO>_sign |
| 968 | * ~~~~~~~~~~~~~ |
| 969 | * Where `ALGO` is the name of the signing algorithm |
| 970 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 971 | * \param[in] p_key A buffer containing the private key |
| 972 | * material |
| 973 | * \param[in] key_size The size in bytes of the `p_key` data |
| 974 | * \param[in] alg A signature algorithm that is compatible |
| 975 | * with the type of `p_key` |
| 976 | * \param[in] p_hash The hash or message to sign |
| 977 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 978 | * \param[out] p_signature Buffer where the signature is to be written |
| 979 | * \param[in] signature_size Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 980 | * \param[out] p_signature_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 981 | * that make up the returned signature value |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 982 | * |
| 983 | * \retval PSA_SUCCESS |
| 984 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 985 | typedef psa_status_t (*pcd_asymmetric_transparent_sign_t)(const uint8_t *p_key, |
| 986 | size_t key_size, |
| 987 | psa_algorithm_t alg, |
| 988 | const uint8_t *p_hash, |
| 989 | size_t hash_length, |
| 990 | uint8_t *p_signature, |
| 991 | size_t signature_size, |
| 992 | size_t *p_signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 993 | |
| 994 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 995 | * \brief A function that verifies the signature a hash or short message using |
| 996 | * a transparent public key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 997 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 998 | * Functions that implement the prototype should be named in the following |
| 999 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1000 | * ~~~~~~~~~~~~~{.c} |
| 1001 | * pcd_asymmetric_<ALGO>_verify |
| 1002 | * ~~~~~~~~~~~~~ |
| 1003 | * Where `ALGO` is the name of the signing algorithm |
| 1004 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1005 | * \param[in] p_key A buffer containing the public key material |
| 1006 | * \param[in] key_size The size in bytes of the `p_key` data |
| 1007 | * \param[in] alg A signature algorithm that is compatible with |
| 1008 | * the type of `key` |
| 1009 | * \param[in] p_hash The hash or message whose signature is to be |
| 1010 | * verified |
| 1011 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 1012 | * \param[in] p_signature Buffer containing the signature to verify |
| 1013 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1014 | * |
| 1015 | * \retval PSA_SUCCESS |
| 1016 | * The signature is valid. |
| 1017 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1018 | typedef psa_status_t (*pcd_asymmetric_transparent_verify_t)(const uint8_t *p_key, |
| 1019 | size_t key_size, |
| 1020 | psa_algorithm_t alg, |
| 1021 | const uint8_t *p_hash, |
| 1022 | size_t hash_length, |
| 1023 | const uint8_t *p_signature, |
| 1024 | size_t signature_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1025 | |
| 1026 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1027 | * \brief A function that encrypts a short message with a transparent public |
| 1028 | * key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1029 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1030 | * Functions that implement the prototype should be named in the following |
| 1031 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1032 | * ~~~~~~~~~~~~~{.c} |
| 1033 | * pcd_asymmetric_<ALGO>_encrypt |
| 1034 | * ~~~~~~~~~~~~~ |
| 1035 | * Where `ALGO` is the name of the encryption algorithm |
| 1036 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1037 | * \param[in] p_key A buffer containing the public key material |
| 1038 | * \param[in] key_size The size in bytes of the `p_key` data |
| 1039 | * \param[in] alg An asymmetric encryption algorithm that is |
| 1040 | * compatible with the type of `key` |
| 1041 | * \param[in] p_input The message to encrypt |
| 1042 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1043 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1044 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1045 | * If the algorithm does not support a |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1046 | * salt, pass `NULL` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1047 | * If the algorithm supports an optional |
| 1048 | * salt and you do not want to pass a salt, |
| 1049 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1050 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 1051 | * supported. |
| 1052 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1053 | * If `p_salt` is `NULL`, pass 0. |
| 1054 | * \param[out] p_output Buffer where the encrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1055 | * be written |
| 1056 | * \param[in] output_size Size of the `p_output` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1057 | * \param[out] p_output_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1058 | * that make up the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1059 | * |
| 1060 | * \retval PSA_SUCCESS |
| 1061 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1062 | 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] | 1063 | size_t key_size, |
| 1064 | psa_algorithm_t alg, |
| 1065 | const uint8_t *p_input, |
| 1066 | size_t input_length, |
| 1067 | const uint8_t *p_salt, |
| 1068 | size_t salt_length, |
| 1069 | uint8_t *p_output, |
| 1070 | size_t output_size, |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1071 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1072 | |
| 1073 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1074 | * \brief Decrypt a short message with a transparent private key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1075 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1076 | * Functions that implement the prototype should be named in the following |
| 1077 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1078 | * ~~~~~~~~~~~~~{.c} |
| 1079 | * pcd_asymmetric_<ALGO>_decrypt |
| 1080 | * ~~~~~~~~~~~~~ |
| 1081 | * Where `ALGO` is the name of the encryption algorithm |
| 1082 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1083 | * \param[in] p_key A buffer containing the private key material |
| 1084 | * \param[in] key_size The size in bytes of the `p_key` data |
| 1085 | * \param[in] alg An asymmetric encryption algorithm that is |
| 1086 | * compatible with the type of `key` |
| 1087 | * \param[in] p_input The message to decrypt |
| 1088 | * \param[in] input_length Size of the `p_input` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1089 | * \param[in] p_salt A salt or label, if supported by the |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1090 | * encryption algorithm |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1091 | * If the algorithm does not support a |
| 1092 | * salt, pass `NULL`. |
| 1093 | * If the algorithm supports an optional |
| 1094 | * salt and you do not want to pass a salt, |
| 1095 | * pass `NULL`. |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1096 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 1097 | * supported |
| 1098 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 1099 | * If `p_salt` is `NULL`, pass 0 |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1100 | * \param[out] p_output Buffer where the decrypted message is to |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1101 | * be written |
| 1102 | * \param[in] output_size Size of the `p_output` buffer in bytes |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1103 | * \param[out] p_output_length On success, the number of bytes |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1104 | * that make up the returned output |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1105 | * |
| 1106 | * \retval PSA_SUCCESS |
| 1107 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1108 | typedef psa_status_t (*pcd_asymmetric_transparent_decrypt_t)(const uint8_t *p_key, |
| 1109 | size_t key_size, |
| 1110 | psa_algorithm_t alg, |
| 1111 | const uint8_t *p_input, |
| 1112 | size_t input_length, |
| 1113 | const uint8_t *p_salt, |
| 1114 | size_t salt_length, |
| 1115 | uint8_t *p_output, |
| 1116 | size_t output_size, |
| 1117 | size_t *p_output_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1118 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1119 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1120 | |
| 1121 | /** \defgroup aead_opaque AEAD Opaque |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1122 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1123 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1124 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1125 | /** \brief Process an authenticated encryption operation using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1126 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1127 | * \param[in] key_slot Slot containing the key to use. |
| 1128 | * \param[in] algorithm The AEAD algorithm to compute |
| 1129 | * (\c PSA_ALG_XXX value such that |
| 1130 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1131 | * \param[in] p_nonce Nonce or IV to use |
| 1132 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 1133 | * \param[in] p_additional_data Additional data that will be |
| 1134 | * authenticated but not encrypted |
| 1135 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 1136 | * \param[in] p_plaintext Data that will be authenticated and |
| 1137 | * encrypted |
| 1138 | * \param[in] plaintext_length Size of `p_plaintext` in bytes |
| 1139 | * \param[out] p_ciphertext Output buffer for the authenticated and |
| 1140 | * encrypted data. The additional data is |
| 1141 | * not part of this output. For algorithms |
| 1142 | * where the encrypted data and the |
| 1143 | * authentication tag are defined as |
| 1144 | * separate outputs, the authentication |
| 1145 | * tag is appended to the encrypted data. |
| 1146 | * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in |
| 1147 | * bytes |
| 1148 | * \param[out] p_ciphertext_length On success, the size of the output in |
| 1149 | * the `p_ciphertext` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1150 | * |
| 1151 | * \retval #PSA_SUCCESS |
| 1152 | * Success. |
| 1153 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1154 | 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] | 1155 | psa_algorithm_t algorithm, |
| 1156 | const uint8_t *p_nonce, |
| 1157 | size_t nonce_length, |
| 1158 | const uint8_t *p_additional_data, |
| 1159 | size_t additional_data_length, |
| 1160 | const uint8_t *p_plaintext, |
| 1161 | size_t plaintext_length, |
| 1162 | uint8_t *p_ciphertext, |
| 1163 | size_t ciphertext_size, |
| 1164 | size_t *p_ciphertext_length); |
| 1165 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1166 | /** Process an authenticated decryption operation using an opaque key |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1167 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1168 | * \param[in] key_slot Slot containing the key to use |
| 1169 | * \param[in] algorithm The AEAD algorithm to compute |
| 1170 | * (\c PSA_ALG_XXX value such that |
| 1171 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1172 | * \param[in] p_nonce Nonce or IV to use |
| 1173 | * \param[in] nonce_length Size of the `p_nonce` buffer in bytes |
| 1174 | * \param[in] p_additional_data Additional data that has been |
| 1175 | * authenticated but not encrypted |
| 1176 | * \param[in] additional_data_length Size of `p_additional_data` in bytes |
| 1177 | * \param[in] p_ciphertext Data that has been authenticated and |
| 1178 | * encrypted. |
| 1179 | * For algorithms where the encrypted data |
| 1180 | * and the authentication tag are defined |
| 1181 | * as separate inputs, the buffer must |
| 1182 | * contain the encrypted data followed by |
| 1183 | * the authentication tag. |
| 1184 | * \param[in] ciphertext_length Size of `p_ciphertext` in bytes |
| 1185 | * \param[out] p_plaintext Output buffer for the decrypted data |
| 1186 | * \param[in] plaintext_size Size of the `p_plaintext` buffer in |
| 1187 | * bytes |
| 1188 | * \param[out] p_plaintext_length On success, the size of the output in |
| 1189 | * the `p_plaintext` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1190 | * |
| 1191 | * \retval #PSA_SUCCESS |
| 1192 | * Success. |
| 1193 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1194 | typedef psa_status_t (*psa_aead_opaque_decrypt_t)(psa_key_slot_t key_slot, |
| 1195 | psa_algorithm_t algorithm, |
| 1196 | const uint8_t *p_nonce, |
| 1197 | size_t nonce_length, |
| 1198 | const uint8_t *p_additional_data, |
| 1199 | size_t additional_data_length, |
| 1200 | const uint8_t *p_ciphertext, |
| 1201 | size_t ciphertext_length, |
| 1202 | uint8_t *p_plaintext, |
| 1203 | size_t plaintext_size, |
| 1204 | size_t *p_plaintext_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1205 | |
| 1206 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1207 | * \brief A struct containing all of the function pointers needed to implement |
| 1208 | * Authenticated Encryption with Additional Data operations using opaque keys |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1209 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1210 | * PSA Crypto API implementations should populate instances of the table as |
| 1211 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1212 | * |
| 1213 | * If one of the functions is not implemented, it should be set to NULL. |
| 1214 | */ |
| 1215 | struct psa_aead_opaque_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1216 | /** Function that performs the AEAD encrypt operation */ |
| 1217 | psa_aead_opaque_encrypt_t *p_encrypt; |
| 1218 | /** Function that performs the AEAD decrypt operation */ |
| 1219 | psa_aead_opaque_decrypt_t *p_decrypt; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1220 | }; |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1221 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1222 | |
| 1223 | /** \defgroup aead_transparent AEAD Transparent |
| 1224 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1225 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1226 | |
| 1227 | /** Process an authenticated encryption operation. |
| 1228 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1229 | * Functions that implement the prototype should be named in the following |
| 1230 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1231 | * ~~~~~~~~~~~~~{.c} |
| 1232 | * pcd_aead_<ALGO>_encrypt |
| 1233 | * ~~~~~~~~~~~~~ |
| 1234 | * Where `ALGO` is the name of the AEAD algorithm |
| 1235 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1236 | * \param[in] p_key A pointer to the key material |
| 1237 | * \param[in] key_length The size in bytes of the key material |
| 1238 | * \param[in] alg The AEAD algorithm to compute |
| 1239 | * (\c PSA_ALG_XXX value such that |
| 1240 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1241 | * \param[in] nonce Nonce or IV to use |
| 1242 | * \param[in] nonce_length Size of the `nonce` buffer in bytes |
| 1243 | * \param[in] additional_data Additional data that will be MACed |
| 1244 | * but not encrypted. |
| 1245 | * \param[in] additional_data_length Size of `additional_data` in bytes |
| 1246 | * \param[in] plaintext Data that will be MACed and |
| 1247 | * encrypted. |
| 1248 | * \param[in] plaintext_length Size of `plaintext` in bytes |
| 1249 | * \param[out] ciphertext Output buffer for the authenticated and |
| 1250 | * encrypted data. The additional data is |
| 1251 | * not part of this output. For algorithms |
| 1252 | * where the encrypted data and the |
| 1253 | * authentication tag are defined as |
| 1254 | * separate outputs, the authentication |
| 1255 | * tag is appended to the encrypted data. |
| 1256 | * \param[in] ciphertext_size Size of the `ciphertext` buffer in |
| 1257 | * bytes |
| 1258 | * This must be at least |
| 1259 | * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`, |
| 1260 | * `plaintext_length`). |
| 1261 | * \param[out] ciphertext_length On success, the size of the output in |
| 1262 | * the `ciphertext` buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1263 | * |
| 1264 | * \retval #PSA_SUCCESS |
| 1265 | |
| 1266 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1267 | typedef psa_status_t (*psa_aead_transparent_encrypt_t)(const uint8_t *p_key, |
| 1268 | size_t key_length, |
| 1269 | psa_algorithm_t alg, |
| 1270 | const uint8_t *nonce, |
| 1271 | size_t nonce_length, |
| 1272 | const uint8_t *additional_data, |
| 1273 | size_t additional_data_length, |
| 1274 | const uint8_t *plaintext, |
| 1275 | size_t plaintext_length, |
| 1276 | uint8_t *ciphertext, |
| 1277 | size_t ciphertext_size, |
| 1278 | size_t *ciphertext_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1279 | |
| 1280 | /** Process an authenticated decryption operation. |
| 1281 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1282 | * Functions that implement the prototype should be named in the following |
| 1283 | * convention: |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1284 | * ~~~~~~~~~~~~~{.c} |
| 1285 | * pcd_aead_<ALGO>_decrypt |
| 1286 | * ~~~~~~~~~~~~~ |
| 1287 | * Where `ALGO` is the name of the AEAD algorithm |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1288 | * \param[in] p_key A pointer to the key material |
| 1289 | * \param[in] key_length The size in bytes of the key material |
| 1290 | * \param[in] alg The AEAD algorithm to compute |
| 1291 | * (\c PSA_ALG_XXX value such that |
| 1292 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 1293 | * \param[in] nonce Nonce or IV to use |
| 1294 | * \param[in] nonce_length Size of the `nonce` buffer in bytes |
| 1295 | * \param[in] additional_data Additional data that has been MACed |
| 1296 | * but not encrypted |
| 1297 | * \param[in] additional_data_length Size of `additional_data` in bytes |
| 1298 | * \param[in] ciphertext Data that has been MACed and |
| 1299 | * encrypted |
| 1300 | * For algorithms where the encrypted data |
| 1301 | * and the authentication tag are defined |
| 1302 | * as separate inputs, the buffer must |
| 1303 | * contain the encrypted data followed by |
| 1304 | * the authentication tag. |
| 1305 | * \param[in] ciphertext_length Size of `ciphertext` in bytes |
| 1306 | * \param[out] plaintext Output buffer for the decrypted data |
| 1307 | * \param[in] plaintext_size Size of the `plaintext` buffer in |
| 1308 | * bytes |
| 1309 | * This must be at least |
| 1310 | * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`, |
| 1311 | * `ciphertext_length`). |
| 1312 | * \param[out] plaintext_length On success, the size of the output |
| 1313 | * in the \b plaintext buffer |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1314 | * |
| 1315 | * \retval #PSA_SUCCESS |
| 1316 | * Success. |
| 1317 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1318 | typedef psa_status_t (*psa_aead_transparent_decrypt_t)(const uint8_t *p_key, |
| 1319 | size_t key_length, |
| 1320 | psa_algorithm_t alg, |
| 1321 | const uint8_t *nonce, |
| 1322 | size_t nonce_length, |
| 1323 | const uint8_t *additional_data, |
| 1324 | size_t additional_data_length, |
| 1325 | const uint8_t *ciphertext, |
| 1326 | size_t ciphertext_length, |
| 1327 | uint8_t *plaintext, |
| 1328 | size_t plaintext_size, |
| 1329 | size_t *plaintext_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1330 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1331 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1332 | |
| 1333 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1334 | /** \defgroup driver_rng Entropy Generation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1335 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1336 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1337 | |
| 1338 | /** \brief A hardware-specific structure for a entropy providing hardware |
| 1339 | */ |
| 1340 | struct pcd_entropy_context_t { |
| 1341 | // Implementation specific |
| 1342 | }; |
| 1343 | |
| 1344 | /** \brief Initialize an entropy driver |
| 1345 | * |
| 1346 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1347 | * \param[in,out] p_context A hardware-specific structure |
| 1348 | * containing any context information for |
| 1349 | * the implementation |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1350 | * |
| 1351 | * \retval PSA_SUCCESS |
| 1352 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1353 | 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] | 1354 | |
| 1355 | /** \brief Get a specified number of bytes from the entropy source |
| 1356 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1357 | * It retrives `buffer_size` bytes of data from the entropy source. The entropy |
| 1358 | * source will always fill the provided buffer to its full size, however, most |
| 1359 | * entropy sources have biases, and the actual amount of entropy contained in |
| 1360 | * the buffer will be less than the number of bytes. |
| 1361 | * The driver will return the actual number of bytes of entropy placed in the |
| 1362 | * buffer in `p_received_entropy_bytes`. |
| 1363 | * A PSA Crypto API implementation will likely feed the output of this function |
| 1364 | * into a Digital Random Bit Generator (DRBG), and typically has a minimum |
| 1365 | * amount of entropy that it needs. |
| 1366 | * To accomplish this, the PSA Crypto implementation should be designed to call |
| 1367 | * this function multiple times until it has received the required amount of |
| 1368 | * entropy from the entropy source. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1369 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1370 | * \param[in,out] p_context A hardware-specific structure |
| 1371 | * containing any context information |
| 1372 | * for the implementation |
| 1373 | * \param[out] p_buffer A caller-allocated buffer for the |
| 1374 | * retrieved bytes to be placed in |
| 1375 | * \param[in] buffer_size The allocated size of `p_buffer` |
| 1376 | * \param[out] p_received_entropy_bytes The amount of entropy (in bytes) |
| 1377 | * actually provided in `p_buffer` |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1378 | * |
| 1379 | * \retval PSA_SUCCESS |
| 1380 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1381 | typedef psa_status_t (*pcd_entropy_get_bytes_t)(struct pcd_entropy_context_t *p_context, |
| 1382 | uint8_t *p_buffer, |
| 1383 | uint32_t buffer_size, |
| 1384 | uint32_t *p_received_entropy_bytes); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1385 | |
| 1386 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1387 | * \brief A struct containing all of the function pointers needed to interface |
| 1388 | * to an entropy source |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1389 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1390 | * PSA Crypto API implementations should populate instances of the table as |
| 1391 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1392 | * |
| 1393 | * If one of the functions is not implemented, it should be set to NULL. |
| 1394 | */ |
| 1395 | struct pcd_entropy_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1396 | /** Function that performs initialization for the entropy source */ |
| 1397 | pcd_entropy_init_t *p_init; |
| 1398 | /** Function that performs the get_bytes operation for the entropy source |
| 1399 | */ |
| 1400 | pcd_entropy_get_bytes_t *p_get_bytes; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1401 | }; |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1402 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1403 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1404 | /** \defgroup driver_key_management Key Management |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1405 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1406 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1407 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1408 | /** \brief Import a key in binary format |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1409 | * |
| 1410 | * This function can support any output from psa_export_key(). Refer to the |
| 1411 | * documentation of psa_export_key() for the format for each key type. |
| 1412 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1413 | * \param[in] key_slot Slot where the key will be stored. This must be a |
| 1414 | * valid slot for a key of the chosen type. It must |
| 1415 | * be unoccupied. |
| 1416 | * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value). |
| 1417 | * \param[in] p_data Buffer containing the key data. |
| 1418 | * \param[in] data_length Size of the `data` buffer in bytes. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1419 | * |
| 1420 | * \retval #PSA_SUCCESS |
| 1421 | * Success. |
| 1422 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1423 | typedef psa_status_t (*pcd_opaque_import_key_t)(psa_key_slot_t key_slot, |
| 1424 | psa_key_type_t type, |
| 1425 | const uint8_t *p_data, |
| 1426 | size_t data_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1427 | |
| 1428 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1429 | * \brief Destroy a key and restore the slot to its default state |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1430 | * |
| 1431 | * This function destroys the content of the key slot from both volatile |
| 1432 | * memory and, if applicable, non-volatile storage. Implementations shall |
| 1433 | * make a best effort to ensure that any previous content of the slot is |
| 1434 | * unrecoverable. |
| 1435 | * |
| 1436 | * This function also erases any metadata such as policies. It returns the |
| 1437 | * specified slot to its default state. |
| 1438 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1439 | * \param[in] key_slot The key slot to erase. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1440 | * |
| 1441 | * \retval #PSA_SUCCESS |
| 1442 | * The slot's content, if any, has been erased. |
| 1443 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1444 | 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] | 1445 | |
| 1446 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1447 | * \brief Export a key in binary format |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1448 | * |
| 1449 | * The output of this function can be passed to psa_import_key() to |
| 1450 | * create an equivalent object. |
| 1451 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1452 | * 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] | 1453 | * this function, it is not guaranteed that the resulting data is |
| 1454 | * identical: the implementation may choose a different representation |
| 1455 | * of the same key if the format permits it. |
| 1456 | * |
| 1457 | * For standard key types, the output format is as follows: |
| 1458 | * |
| 1459 | * - For symmetric keys (including MAC keys), the format is the |
| 1460 | * raw bytes of the key. |
| 1461 | * - For DES, the key data consists of 8 bytes. The parity bits must be |
| 1462 | * correct. |
| 1463 | * - For Triple-DES, the format is the concatenation of the |
| 1464 | * two or three DES keys. |
| 1465 | * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format |
| 1466 | * is the non-encrypted DER representation defined by PKCS\#1 (RFC 8017) |
| 1467 | * as RSAPrivateKey. |
| 1468 | * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format |
| 1469 | * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo. |
| 1470 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1471 | * \param[in] key Slot whose content is to be exported. This must |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1472 | * be an occupied key slot. |
| 1473 | * \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] | 1474 | * \param[in] data_size Size of the `p_data` buffer in bytes. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1475 | * \param[out] p_data_length On success, the number of bytes |
| 1476 | * that make up the key data. |
| 1477 | * |
| 1478 | * \retval #PSA_SUCCESS |
| 1479 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 1480 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1481 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1482 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1483 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1484 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1485 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1486 | typedef psa_status_t (*pcd_export_key_t)(psa_key_slot_t key, |
| 1487 | uint8_t *p_data, |
| 1488 | size_t data_size, |
| 1489 | size_t *p_data_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1490 | |
| 1491 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1492 | * \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] | 1493 | * |
| 1494 | * The output of this function can be passed to psa_import_key() to |
| 1495 | * create an object that is equivalent to the public key. |
| 1496 | * |
| 1497 | * For standard key types, the output format is as follows: |
| 1498 | * |
| 1499 | * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY), |
| 1500 | * the format is the DER representation of the public key defined by RFC 5280 |
| 1501 | * as SubjectPublicKeyInfo. |
| 1502 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1503 | * \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] | 1504 | * be an occupied key slot. |
| 1505 | * \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] | 1506 | * \param[in] data_size Size of the `data` buffer in bytes. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1507 | * \param[out] p_data_length On success, the number of bytes |
| 1508 | * that make up the key data. |
| 1509 | * |
| 1510 | * \retval #PSA_SUCCESS |
| 1511 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1512 | typedef psa_status_t (*pcd_export_public_key_t)(psa_key_slot_t key, |
| 1513 | uint8_t *p_data, |
| 1514 | size_t data_size, |
| 1515 | size_t *p_data_length); |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1516 | |
| 1517 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1518 | * \brief A struct containing all of the function pointers needed to for key |
| 1519 | * management using opaque keys |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1520 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1521 | * PSA Crypto API implementations should populate instances of the table as |
| 1522 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1523 | * |
| 1524 | * If one of the functions is not implemented, it should be set to NULL. |
| 1525 | */ |
| 1526 | struct pcd_key_management_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1527 | /** Function that performs the key import operation */ |
| 1528 | pcd_opaque_import_key_t *p_import; |
| 1529 | /** Function that performs the key destroy operation */ |
| 1530 | pcd_destroy_key_t *p_destroy; |
| 1531 | /** Function that performs the key export operation */ |
| 1532 | pcd_export_key_t *p_export; |
| 1533 | /** Function that perforsm the public key export operation */ |
| 1534 | pcd_export_public_key_t *p_export_public; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1535 | }; |
| 1536 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1537 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1538 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1539 | /** \defgroup driver_derivation Key Derivation and Agreement |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1540 | */ |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1541 | /**@{*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1542 | |
| 1543 | /** |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1544 | * Key derivation is the process of generating new key material using an |
| 1545 | * existing key and additional parameters, iterating through a basic |
| 1546 | * cryptographic function, such as a hash. |
| 1547 | * Key agreement is a part of cryptographic protocols that allows two parties |
| 1548 | * to agree on the same key value, but starting from different original key |
| 1549 | * material. |
| 1550 | * The flows are similar, and the PSA Crypto Driver API uses the same functions |
| 1551 | * for both of the flows. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1552 | * |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1553 | * There are two different final functions for the flows, |
| 1554 | * `pcd_key_derivation_derive` and `pcd_key_derivation_export`. |
| 1555 | * `pcd_key_derivation_derive` is used when the key material should be placed |
| 1556 | * in a slot on the hardware and not exposed to the caller. |
| 1557 | * `pcd_key_derivation_export` is used when the key material should be returned |
| 1558 | * to the PSA Cryptographic API implementation. |
| 1559 | * |
| 1560 | * Different key derivation algorithms require a different number of inputs. |
| 1561 | * Instead of having an API that takes as input variable length arrays, which |
| 1562 | * can be problemmatic to manage on embedded platforms, the inputs are passed |
| 1563 | * to the driver via a function, `pcd_key_derivation_collateral`, that is |
| 1564 | * called multiple times with different `collateral_id`s. Thus, for a key |
| 1565 | * derivation algorithm that required 3 paramter inputs, the flow would look |
| 1566 | * something like: |
| 1567 | * ~~~~~~~~~~~~~{.c} |
| 1568 | * pcd_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes); |
| 1569 | * pcd_key_derivation_collateral(kdf_algorithm_collateral_id_0, |
| 1570 | * p_collateral_0, |
| 1571 | * collateral_0_size); |
| 1572 | * pcd_key_derivation_collateral(kdf_algorithm_collateral_id_1, |
| 1573 | * p_collateral_1, |
| 1574 | * collateral_1_size); |
| 1575 | * pcd_key_derivation_collateral(kdf_algorithm_collateral_id_2, |
| 1576 | * p_collateral_2, |
| 1577 | * collateral_2_size); |
| 1578 | * pcd_key_derivation_derive(); |
| 1579 | * ~~~~~~~~~~~~~ |
| 1580 | * |
| 1581 | * key agreement example: |
| 1582 | * ~~~~~~~~~~~~~{.c} |
| 1583 | * pcd_key_derivation_setup(alg, source_key. dest_key_size_bytes); |
| 1584 | * pcd_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size); |
| 1585 | * pcd_key_derivation_export(p_session_key, |
| 1586 | * session_key_size, |
| 1587 | * &session_key_length); |
| 1588 | * ~~~~~~~~~~~~~ |
| 1589 | */ |
| 1590 | |
| 1591 | struct pcd_key_derivation_context_t { |
| 1592 | // Implementation specific |
| 1593 | }; |
| 1594 | |
| 1595 | /** \brief Set up a key derivation operation by specifying the algorithm and |
| 1596 | * the source key sot |
| 1597 | * |
| 1598 | * \param[in,out] p_context A hardware-specific structure containing any |
| 1599 | * context information for the implementation |
| 1600 | * \param[in] kdf_alg The algorithm to be used for the key derivation |
| 1601 | * \param[in] souce_key The key to be used as the source material for the |
| 1602 | * key derivation |
| 1603 | * |
| 1604 | * \retval PSA_SUCCESS |
| 1605 | */ |
| 1606 | typedef psa_status_t (*pcd_key_derivation_setup_t)(struct pcd_key_derivation_context_t *p_context, |
| 1607 | psa_algorithm_t kdf_alg, |
| 1608 | psa_key_slot_t source_key); |
| 1609 | |
| 1610 | /** \brief Provide collateral (parameters) needed for a key derivation or key |
| 1611 | * agreement operation |
| 1612 | * |
| 1613 | * Since many key derivation algorithms require multiple parameters, it is |
| 1614 | * expeced that this function may be called multiple times for the same |
| 1615 | * operation, each with a different algorithm-specific `collateral_id` |
| 1616 | * |
| 1617 | * \param[in,out] p_context A hardware-specific structure containing any |
| 1618 | * context information for the implementation |
| 1619 | * \param[in] collateral_id An ID for the collateral being provided |
| 1620 | * \param[in] p_collateral A buffer containing the collateral data |
| 1621 | * \param[in] collateral_size The size in bytes of the collateral |
| 1622 | * |
| 1623 | * \retval PSA_SUCCESS |
| 1624 | */ |
| 1625 | typedef psa_status_t (*pcd_key_derivation_collateral_t)(struct pcd_key_derivation_context_t *p_context, |
| 1626 | uint32_t collateral_id, |
| 1627 | const uint8_t p_collateral, |
| 1628 | size_t collateral_size); |
| 1629 | |
| 1630 | /** \brief Perform the final key derivation step and place the generated key |
| 1631 | * material in a slot |
| 1632 | * \param[in,out] p_context A hardware-specific structure containing any |
| 1633 | * context information for the implementation |
| 1634 | * \param[in] dest_key The slot where the generated key material |
| 1635 | * should be placed |
| 1636 | * |
| 1637 | * \retval PSA_SUCCESS |
| 1638 | */ |
| 1639 | typedef psa_status_t (*pcd_key_derivation_derive_t)(struct pcd_key_derivation_context_t *p_context, |
| 1640 | psa_key_slot_t dest_key); |
| 1641 | |
| 1642 | /** \brief Perform the final step of a key agreement and place the generated |
| 1643 | * key material in a buffer |
| 1644 | * |
| 1645 | * \param[out] p_output Buffer in which to place the generated key |
| 1646 | * material |
| 1647 | * \param[in] output_size The size in bytes of `p_output` |
| 1648 | * \param[out] p_output_length Upon success, contains the number of bytes of |
| 1649 | * key material placed in `p_output` |
| 1650 | * |
| 1651 | * \retval PSA_SUCCESS |
| 1652 | */ |
| 1653 | typedef psa_status_t (*pcd_key_derivation_export_t)(uint8_t *p_output, |
| 1654 | size_t output_size, |
| 1655 | size_t *p_output_length); |
| 1656 | |
| 1657 | /** |
| 1658 | * \brief A struct containing all of the function pointers needed to for key |
| 1659 | * derivation and agreement |
| 1660 | * |
| 1661 | * PSA Crypto API implementations should populate instances of the table as |
| 1662 | * appropriate upon startup. |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1663 | * |
| 1664 | * If one of the functions is not implemented, it should be set to NULL. |
| 1665 | */ |
| 1666 | struct pcd_key_derivation_t { |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1667 | /** Function that performs the key derivation setup */ |
| 1668 | pcd_key_derivation_setup_t *p_setup; |
| 1669 | /** Function that sets the key derivation collateral */ |
| 1670 | pcd_key_derivation_collateral_t *p_collateral; |
| 1671 | /** Function that performs the final key derivation step */ |
| 1672 | pcd_key_derivation_derive_t *p_derive; |
| 1673 | /** Function that perforsm the final key derivation or agreement and |
| 1674 | * exports the key */ |
| 1675 | pcd_key_derivation_export_t *p_export; |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1676 | }; |
| 1677 | |
Derek Miller | 16e7229 | 2018-10-15 16:14:24 -0500 | [diff] [blame] | 1678 | /**@}*/ |
Derek Miller | 5b3417a | 2018-10-10 17:55:03 -0500 | [diff] [blame] | 1679 | |
| 1680 | #endif // __PSA_CRYPTO_DRIVER_H__ |