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