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