Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_extra.h |
| 3 | * |
| 4 | * \brief PSA cryptography module: Mbed TLS vendor extensions |
Gilles Peskine | 07c91f5 | 2018-06-28 18:02:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * \note This file may not be included directly. Applications must |
| 7 | * include psa/crypto.h. |
| 8 | * |
| 9 | * This file is reserved for vendor-specific definitions. |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 10 | */ |
| 11 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 12 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 13 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef PSA_CRYPTO_EXTRA_H |
| 17 | #define PSA_CRYPTO_EXTRA_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 18 | #include "mbedtls/private_access.h" |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 19 | |
Gilles Peskine | 09c02ee | 2021-11-25 20:30:47 +0100 | [diff] [blame] | 20 | #include "crypto_types.h" |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 21 | #include "crypto_compat.h" |
| 22 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 27 | /* UID for secure storage seed */ |
avolinski | 0d2c266 | 2018-11-21 17:31:07 +0200 | [diff] [blame] | 28 | #define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52 |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 29 | |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 30 | /* See mbedtls_config.h for definition */ |
Steven Cooreman | 863470a | 2021-02-15 14:03:19 +0100 | [diff] [blame] | 31 | #if !defined(MBEDTLS_PSA_KEY_SLOT_COUNT) |
| 32 | #define MBEDTLS_PSA_KEY_SLOT_COUNT 32 |
Steven Cooreman | 1f968fd | 2021-02-15 14:00:24 +0100 | [diff] [blame] | 33 | #endif |
Jaeden Amero | 5e6d24c | 2019-02-21 10:41:29 +0000 | [diff] [blame] | 34 | |
Valerio Setti | ce84921 | 2024-08-29 15:02:47 +0200 | [diff] [blame] | 35 | /* If the size of static key slots is not explicitly defined by the user, then |
| 36 | * set it to the maximum between PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE and |
| 37 | * PSA_CIPHER_MAX_KEY_LENGTH. |
| 38 | * See mbedtls_config.h for the definition. */ |
| 39 | #if !defined(MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE) |
| 40 | #define MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE \ |
| 41 | ((PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE > PSA_CIPHER_MAX_KEY_LENGTH) ? \ |
| 42 | PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE : PSA_CIPHER_MAX_KEY_LENGTH) |
| 43 | #endif /* !MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE*/ |
| 44 | |
Gilles Peskine | 96f0b3b | 2019-05-10 19:33:38 +0200 | [diff] [blame] | 45 | /** \addtogroup attributes |
| 46 | * @{ |
| 47 | */ |
| 48 | |
| 49 | /** \brief Declare the enrollment algorithm for a key. |
| 50 | * |
| 51 | * An operation on a key may indifferently use the algorithm set with |
| 52 | * psa_set_key_algorithm() or with this function. |
| 53 | * |
| 54 | * \param[out] attributes The attribute structure to write to. |
| 55 | * \param alg2 A second algorithm that the key may be used |
| 56 | * for, in addition to the algorithm set with |
| 57 | * psa_set_key_algorithm(). |
| 58 | * |
| 59 | * \warning Setting an enrollment algorithm is not recommended, because |
| 60 | * using the same key with different algorithms can allow some |
| 61 | * attacks based on arithmetic relations between different |
| 62 | * computations made with the same key, or can escalate harmless |
| 63 | * side channels into exploitable ones. Use this function only |
Gilles Peskine | f25c9ec | 2019-05-22 11:45:59 +0200 | [diff] [blame] | 64 | * if it is necessary to support a protocol for which it has been |
Gilles Peskine | 96f0b3b | 2019-05-10 19:33:38 +0200 | [diff] [blame] | 65 | * verified that the usage of the key with multiple algorithms |
| 66 | * is safe. |
| 67 | */ |
| 68 | static inline void psa_set_key_enrollment_algorithm( |
| 69 | psa_key_attributes_t *attributes, |
| 70 | psa_algorithm_t alg2) |
| 71 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 72 | attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2) = alg2; |
Gilles Peskine | 96f0b3b | 2019-05-10 19:33:38 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** Retrieve the enrollment algorithm policy from key attributes. |
| 76 | * |
| 77 | * \param[in] attributes The key attribute structure to query. |
| 78 | * |
| 79 | * \return The enrollment algorithm stored in the attribute structure. |
| 80 | */ |
| 81 | static inline psa_algorithm_t psa_get_key_enrollment_algorithm( |
| 82 | const psa_key_attributes_t *attributes) |
| 83 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 84 | return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2); |
Gilles Peskine | 96f0b3b | 2019-05-10 19:33:38 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 87 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 88 | |
| 89 | /** Retrieve the slot number where a key is stored. |
| 90 | * |
| 91 | * A slot number is only defined for keys that are stored in a secure |
| 92 | * element. |
| 93 | * |
| 94 | * This information is only useful if the secure element is not entirely |
| 95 | * managed through the PSA Cryptography API. It is up to the secure |
| 96 | * element driver to decide how PSA slot numbers map to any other interface |
| 97 | * that the secure element may have. |
| 98 | * |
| 99 | * \param[in] attributes The key attribute structure to query. |
| 100 | * \param[out] slot_number On success, the slot number containing the key. |
| 101 | * |
| 102 | * \retval #PSA_SUCCESS |
| 103 | * The key is located in a secure element, and \p *slot_number |
| 104 | * indicates the slot number that contains it. |
| 105 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 106 | * The caller is not permitted to query the slot number. |
Fredrik Hesse | cc207bc | 2021-09-28 21:06:08 +0200 | [diff] [blame] | 107 | * Mbed TLS currently does not return this error. |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 108 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 109 | * The key is not located in a secure element. |
| 110 | */ |
| 111 | psa_status_t psa_get_key_slot_number( |
| 112 | const psa_key_attributes_t *attributes, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 113 | psa_key_slot_number_t *slot_number); |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 114 | |
| 115 | /** Choose the slot number where a key is stored. |
| 116 | * |
| 117 | * This function declares a slot number in the specified attribute |
| 118 | * structure. |
| 119 | * |
| 120 | * A slot number is only meaningful for keys that are stored in a secure |
| 121 | * element. It is up to the secure element driver to decide how PSA slot |
| 122 | * numbers map to any other interface that the secure element may have. |
| 123 | * |
| 124 | * \note Setting a slot number in key attributes for a key creation can |
| 125 | * cause the following errors when creating the key: |
| 126 | * - #PSA_ERROR_NOT_SUPPORTED if the selected secure element does |
| 127 | * not support choosing a specific slot number. |
| 128 | * - #PSA_ERROR_NOT_PERMITTED if the caller is not permitted to |
| 129 | * choose slot numbers in general or to choose this specific slot. |
| 130 | * - #PSA_ERROR_INVALID_ARGUMENT if the chosen slot number is not |
| 131 | * valid in general or not valid for this specific key. |
| 132 | * - #PSA_ERROR_ALREADY_EXISTS if there is already a key in the |
| 133 | * selected slot. |
| 134 | * |
| 135 | * \param[out] attributes The attribute structure to write to. |
| 136 | * \param slot_number The slot number to set. |
| 137 | */ |
| 138 | static inline void psa_set_key_slot_number( |
| 139 | psa_key_attributes_t *attributes, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 140 | psa_key_slot_number_t slot_number) |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 141 | { |
Gilles Peskine | 972539c | 2024-02-28 01:49:45 +0100 | [diff] [blame] | 142 | attributes->MBEDTLS_PRIVATE(has_slot_number) = 1; |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 143 | attributes->MBEDTLS_PRIVATE(slot_number) = slot_number; |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Gilles Peskine | 5fe5e27 | 2019-08-02 20:30:01 +0200 | [diff] [blame] | 146 | /** Remove the slot number attribute from a key attribute structure. |
| 147 | * |
| 148 | * This function undoes the action of psa_set_key_slot_number(). |
| 149 | * |
| 150 | * \param[out] attributes The attribute structure to write to. |
| 151 | */ |
| 152 | static inline void psa_clear_key_slot_number( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 153 | psa_key_attributes_t *attributes) |
Gilles Peskine | 5fe5e27 | 2019-08-02 20:30:01 +0200 | [diff] [blame] | 154 | { |
Gilles Peskine | 972539c | 2024-02-28 01:49:45 +0100 | [diff] [blame] | 155 | attributes->MBEDTLS_PRIVATE(has_slot_number) = 0; |
Gilles Peskine | 5fe5e27 | 2019-08-02 20:30:01 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Gilles Peskine | d772958 | 2019-08-05 15:55:54 +0200 | [diff] [blame] | 158 | /** Register a key that is already present in a secure element. |
| 159 | * |
| 160 | * The key must be located in a secure element designated by the |
| 161 | * lifetime field in \p attributes, in the slot set with |
| 162 | * psa_set_key_slot_number() in the attribute structure. |
| 163 | * This function makes the key available through the key identifier |
| 164 | * specified in \p attributes. |
| 165 | * |
| 166 | * \param[in] attributes The attributes of the existing key. |
Gilles Peskine | d72ad73 | 2024-06-13 16:06:45 +0200 | [diff] [blame] | 167 | * - The lifetime must be a persistent lifetime |
| 168 | * in a secure element. Volatile lifetimes are |
| 169 | * not currently supported. |
| 170 | * - The key identifier must be in the valid |
| 171 | * range for persistent keys. |
| 172 | * - The key type and size must be specified and |
| 173 | * must be consistent with the key material |
| 174 | * in the secure element. |
Gilles Peskine | d772958 | 2019-08-05 15:55:54 +0200 | [diff] [blame] | 175 | * |
| 176 | * \retval #PSA_SUCCESS |
| 177 | * The key was successfully registered. |
| 178 | * Note that depending on the design of the driver, this may or may |
| 179 | * not guarantee that a key actually exists in the designated slot |
| 180 | * and is compatible with the specified attributes. |
| 181 | * \retval #PSA_ERROR_ALREADY_EXISTS |
| 182 | * There is already a key with the identifier specified in |
| 183 | * \p attributes. |
Gilles Peskine | 3efcebb | 2019-10-01 14:18:35 +0200 | [diff] [blame] | 184 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 185 | * The secure element driver for the specified lifetime does not |
| 186 | * support registering a key. |
Gilles Peskine | d772958 | 2019-08-05 15:55:54 +0200 | [diff] [blame] | 187 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Ronald Cron | d3b458c | 2021-03-31 17:51:29 +0200 | [diff] [blame] | 188 | * The identifier in \p attributes is invalid, namely the identifier is |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 189 | * not in the user range, or |
Gilles Peskine | d772958 | 2019-08-05 15:55:54 +0200 | [diff] [blame] | 190 | * \p attributes specifies a lifetime which is not located |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 191 | * in a secure element, or no slot number is specified in \p attributes, |
Gilles Peskine | d772958 | 2019-08-05 15:55:54 +0200 | [diff] [blame] | 192 | * or the specified slot number is not valid. |
| 193 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 194 | * The caller is not authorized to register the specified key slot. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 195 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 196 | * \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription |
| 197 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 198 | * \retval #PSA_ERROR_DATA_INVALID \emptydescription |
| 199 | * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription |
| 200 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Gilles Peskine | d772958 | 2019-08-05 15:55:54 +0200 | [diff] [blame] | 201 | * \retval #PSA_ERROR_BAD_STATE |
| 202 | * The library has not been previously initialized by psa_crypto_init(). |
| 203 | * It is implementation-dependent whether a failure to initialize |
| 204 | * results in this error code. |
| 205 | */ |
| 206 | psa_status_t mbedtls_psa_register_se_key( |
| 207 | const psa_key_attributes_t *attributes); |
| 208 | |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 209 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 210 | |
Gilles Peskine | 96f0b3b | 2019-05-10 19:33:38 +0200 | [diff] [blame] | 211 | /**@}*/ |
| 212 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 213 | /** |
| 214 | * \brief Library deinitialization. |
| 215 | * |
| 216 | * This function clears all data associated with the PSA layer, |
| 217 | * including the whole key store. |
Ryan Everett | 16abd59 | 2024-01-24 17:37:46 +0000 | [diff] [blame] | 218 | * This function is not thread safe, it wipes every key slot regardless of |
| 219 | * state and reader count. It should only be called when no slot is in use. |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 220 | * |
| 221 | * This is an Mbed TLS extension. |
| 222 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 223 | void mbedtls_psa_crypto_free(void); |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 224 | |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 225 | /** \brief Statistics about |
| 226 | * resource consumption related to the PSA keystore. |
| 227 | * |
| 228 | * \note The content of this structure is not part of the stable API and ABI |
Fredrik Hesse | cc207bc | 2021-09-28 21:06:08 +0200 | [diff] [blame] | 229 | * of Mbed TLS and may change arbitrarily from version to version. |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 230 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 231 | typedef struct mbedtls_psa_stats_s { |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 232 | /** Number of slots containing key material for a volatile key. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 233 | size_t MBEDTLS_PRIVATE(volatile_slots); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 234 | /** Number of slots containing key material for a key which is in |
| 235 | * internal persistent storage. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 236 | size_t MBEDTLS_PRIVATE(persistent_slots); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 237 | /** Number of slots containing a reference to a key in a |
| 238 | * secure element. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 239 | size_t MBEDTLS_PRIVATE(external_slots); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 240 | /** Number of slots which are occupied, but do not contain |
| 241 | * key material yet. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 242 | size_t MBEDTLS_PRIVATE(half_filled_slots); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 243 | /** Number of slots that contain cache data. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 244 | size_t MBEDTLS_PRIVATE(cache_slots); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 245 | /** Number of slots that are not used for anything. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 246 | size_t MBEDTLS_PRIVATE(empty_slots); |
Ronald Cron | 1ad1eee | 2020-11-15 14:21:04 +0100 | [diff] [blame] | 247 | /** Number of slots that are locked. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 248 | size_t MBEDTLS_PRIVATE(locked_slots); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 249 | /** Largest key id value among open keys in internal persistent storage. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 250 | psa_key_id_t MBEDTLS_PRIVATE(max_open_internal_key_id); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 251 | /** Largest key id value among open keys in secure elements. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 252 | psa_key_id_t MBEDTLS_PRIVATE(max_open_external_key_id); |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 253 | } mbedtls_psa_stats_t; |
| 254 | |
| 255 | /** \brief Get statistics about |
| 256 | * resource consumption related to the PSA keystore. |
| 257 | * |
Fredrik Hesse | cc207bc | 2021-09-28 21:06:08 +0200 | [diff] [blame] | 258 | * \note When Mbed TLS is built as part of a service, with isolation |
Gilles Peskine | 4bac9a4 | 2019-05-23 20:32:30 +0200 | [diff] [blame] | 259 | * between the application and the keystore, the service may or |
| 260 | * may not expose this function. |
| 261 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 262 | void mbedtls_psa_get_stats(mbedtls_psa_stats_t *stats); |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 263 | |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 264 | /** |
Gilles Peskine | ee2ffd3 | 2018-11-16 11:02:49 +0100 | [diff] [blame] | 265 | * \brief Inject an initial entropy seed for the random generator into |
| 266 | * secure storage. |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 267 | * |
| 268 | * This function injects data to be used as a seed for the random generator |
| 269 | * used by the PSA Crypto implementation. On devices that lack a trusted |
| 270 | * entropy source (preferably a hardware random number generator), |
| 271 | * the Mbed PSA Crypto implementation uses this value to seed its |
| 272 | * random generator. |
| 273 | * |
| 274 | * On devices without a trusted entropy source, this function must be |
| 275 | * called exactly once in the lifetime of the device. On devices with |
| 276 | * a trusted entropy source, calling this function is optional. |
| 277 | * In all cases, this function may only be called before calling any |
| 278 | * other function in the PSA Crypto API, including psa_crypto_init(). |
| 279 | * |
| 280 | * When this function returns successfully, it populates a file in |
| 281 | * persistent storage. Once the file has been created, this function |
| 282 | * can no longer succeed. |
Gilles Peskine | ee2ffd3 | 2018-11-16 11:02:49 +0100 | [diff] [blame] | 283 | * |
| 284 | * If any error occurs, this function does not change the system state. |
| 285 | * You can call this function again after correcting the reason for the |
| 286 | * error if possible. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 287 | * |
| 288 | * \warning This function **can** fail! Callers MUST check the return status. |
| 289 | * |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 290 | * \warning If you use this function, you should use it as part of a |
| 291 | * factory provisioning process. The value of the injected seed |
| 292 | * is critical to the security of the device. It must be |
| 293 | * *secret*, *unpredictable* and (statistically) *unique per device*. |
| 294 | * You should be generate it randomly using a cryptographically |
| 295 | * secure random generator seeded from trusted entropy sources. |
| 296 | * You should transmit it securely to the device and ensure |
| 297 | * that its value is not leaked or stored anywhere beyond the |
| 298 | * needs of transmitting it from the point of generation to |
| 299 | * the call of this function, and erase all copies of the value |
| 300 | * once this function returns. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 301 | * |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 302 | * This is an Mbed TLS extension. |
| 303 | * |
Netanel Gonen | 1d7195f | 2018-11-22 16:24:48 +0200 | [diff] [blame] | 304 | * \note This function is only available on the following platforms: |
Gilles Peskine | e3dbdd8 | 2019-02-25 11:04:06 +0100 | [diff] [blame] | 305 | * * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled. |
| 306 | * Note that you must provide compatible implementations of |
| 307 | * mbedtls_nv_seed_read and mbedtls_nv_seed_write. |
Gilles Peskine | 0cfaed1 | 2018-11-22 17:11:45 +0200 | [diff] [blame] | 308 | * * In a client-server integration of PSA Cryptography, on the client side, |
Netanel Gonen | 1d7195f | 2018-11-22 16:24:48 +0200 | [diff] [blame] | 309 | * if the server supports this feature. |
Netanel Gonen | 596e65e | 2018-11-22 18:41:43 +0200 | [diff] [blame] | 310 | * \param[in] seed Buffer containing the seed value to inject. |
Gilles Peskine | 0cfaed1 | 2018-11-22 17:11:45 +0200 | [diff] [blame] | 311 | * \param[in] seed_size Size of the \p seed buffer. |
Netanel Gonen | 596e65e | 2018-11-22 18:41:43 +0200 | [diff] [blame] | 312 | * The size of the seed in bytes must be greater |
Chris Jones | 3848e31 | 2021-03-11 16:17:59 +0000 | [diff] [blame] | 313 | * or equal to both #MBEDTLS_ENTROPY_BLOCK_SIZE |
| 314 | * and the value of \c MBEDTLS_ENTROPY_MIN_PLATFORM |
| 315 | * in `library/entropy_poll.h` in the Mbed TLS source |
| 316 | * code. |
Netanel Gonen | 596e65e | 2018-11-22 18:41:43 +0200 | [diff] [blame] | 317 | * It must be less or equal to |
| 318 | * #MBEDTLS_ENTROPY_MAX_SEED_SIZE. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 319 | * |
| 320 | * \retval #PSA_SUCCESS |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 321 | * The seed value was injected successfully. The random generator |
| 322 | * of the PSA Crypto implementation is now ready for use. |
| 323 | * You may now call psa_crypto_init() and use the PSA Crypto |
| 324 | * implementation. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 325 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | ee2ffd3 | 2018-11-16 11:02:49 +0100 | [diff] [blame] | 326 | * \p seed_size is out of range. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 327 | * \retval #PSA_ERROR_STORAGE_FAILURE |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 328 | * There was a failure reading or writing from storage. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 329 | * \retval #PSA_ERROR_NOT_PERMITTED |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 330 | * The library has already been initialized. It is no longer |
| 331 | * possible to call this function. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 332 | */ |
Jaeden Amero | c7529c9 | 2019-08-19 11:08:04 +0100 | [diff] [blame] | 333 | psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed, |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 334 | size_t seed_size); |
| 335 | |
Gilles Peskine | e38ab1a | 2019-05-16 13:51:50 +0200 | [diff] [blame] | 336 | /** \addtogroup crypto_types |
| 337 | * @{ |
| 338 | */ |
| 339 | |
Gilles Peskine | a130219 | 2019-05-16 13:58:24 +0200 | [diff] [blame] | 340 | /** DSA public key. |
| 341 | * |
| 342 | * The import and export format is the |
| 343 | * representation of the public key `y = g^x mod p` as a big-endian byte |
| 344 | * string. The length of the byte string is the length of the base prime `p` |
| 345 | * in bytes. |
| 346 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 347 | #define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t) 0x4002) |
Gilles Peskine | a130219 | 2019-05-16 13:58:24 +0200 | [diff] [blame] | 348 | |
| 349 | /** DSA key pair (private and public key). |
| 350 | * |
| 351 | * The import and export format is the |
| 352 | * representation of the private key `x` as a big-endian byte string. The |
| 353 | * length of the byte string is the private key size in bytes (leading zeroes |
| 354 | * are not stripped). |
| 355 | * |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 356 | * Deterministic DSA key derivation with psa_generate_derived_key follows |
Gilles Peskine | a130219 | 2019-05-16 13:58:24 +0200 | [diff] [blame] | 357 | * FIPS 186-4 §B.1.2: interpret the byte string as integer |
| 358 | * in big-endian order. Discard it if it is not in the range |
| 359 | * [0, *N* - 2] where *N* is the boundary of the private key domain |
| 360 | * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA, |
| 361 | * or the order of the curve's base point for ECC). |
| 362 | * Add 1 to the resulting integer and use this as the private key *x*. |
| 363 | * |
| 364 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 365 | #define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t) 0x7002) |
Gilles Peskine | a130219 | 2019-05-16 13:58:24 +0200 | [diff] [blame] | 366 | |
Tom Cosgrove | ce7f18c | 2022-07-28 05:50:56 +0100 | [diff] [blame] | 367 | /** Whether a key type is a DSA key (pair or public-only). */ |
Gilles Peskine | e38ab1a | 2019-05-16 13:51:50 +0200 | [diff] [blame] | 368 | #define PSA_KEY_TYPE_IS_DSA(type) \ |
Gilles Peskine | c93b80c | 2019-05-16 19:39:54 +0200 | [diff] [blame] | 369 | (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY) |
Gilles Peskine | e38ab1a | 2019-05-16 13:51:50 +0200 | [diff] [blame] | 370 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 371 | #define PSA_ALG_DSA_BASE ((psa_algorithm_t) 0x06000400) |
Gilles Peskine | e38ab1a | 2019-05-16 13:51:50 +0200 | [diff] [blame] | 372 | /** DSA signature with hashing. |
| 373 | * |
| 374 | * This is the signature scheme defined by FIPS 186-4, |
| 375 | * with a random per-message secret number (*k*). |
| 376 | * |
| 377 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that |
| 378 | * #PSA_ALG_IS_HASH(\p hash_alg) is true). |
| 379 | * This includes #PSA_ALG_ANY_HASH |
| 380 | * when specifying the algorithm in a usage policy. |
| 381 | * |
| 382 | * \return The corresponding DSA signature algorithm. |
| 383 | * \return Unspecified if \p hash_alg is not a supported |
| 384 | * hash algorithm. |
| 385 | */ |
| 386 | #define PSA_ALG_DSA(hash_alg) \ |
| 387 | (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 388 | #define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t) 0x06000500) |
Gilles Peskine | 972630e | 2019-11-29 11:55:48 +0100 | [diff] [blame] | 389 | #define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG |
Gilles Peskine | e38ab1a | 2019-05-16 13:51:50 +0200 | [diff] [blame] | 390 | /** Deterministic DSA signature with hashing. |
| 391 | * |
| 392 | * This is the deterministic variant defined by RFC 6979 of |
| 393 | * the signature scheme defined by FIPS 186-4. |
| 394 | * |
| 395 | * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that |
| 396 | * #PSA_ALG_IS_HASH(\p hash_alg) is true). |
| 397 | * This includes #PSA_ALG_ANY_HASH |
| 398 | * when specifying the algorithm in a usage policy. |
| 399 | * |
| 400 | * \return The corresponding DSA signature algorithm. |
| 401 | * \return Unspecified if \p hash_alg is not a supported |
| 402 | * hash algorithm. |
| 403 | */ |
| 404 | #define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \ |
| 405 | (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) |
| 406 | #define PSA_ALG_IS_DSA(alg) \ |
| 407 | (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \ |
| 408 | PSA_ALG_DSA_BASE) |
| 409 | #define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \ |
| 410 | (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0) |
| 411 | #define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \ |
| 412 | (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg)) |
| 413 | #define PSA_ALG_IS_RANDOMIZED_DSA(alg) \ |
| 414 | (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg)) |
| 415 | |
| 416 | |
| 417 | /* We need to expand the sample definition of this macro from |
| 418 | * the API definition. */ |
Gilles Peskine | 6d40085 | 2021-02-24 21:39:52 +0100 | [diff] [blame] | 419 | #undef PSA_ALG_IS_VENDOR_HASH_AND_SIGN |
| 420 | #define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) \ |
| 421 | PSA_ALG_IS_DSA(alg) |
Gilles Peskine | e38ab1a | 2019-05-16 13:51:50 +0200 | [diff] [blame] | 422 | |
| 423 | /**@}*/ |
| 424 | |
Gilles Peskine | 24f10f8 | 2019-05-16 12:18:32 +0200 | [diff] [blame] | 425 | /** \addtogroup attributes |
| 426 | * @{ |
| 427 | */ |
| 428 | |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 429 | /** PAKE operation stages. */ |
Przemek Stekiel | 1c3cfb4 | 2023-01-26 10:35:02 +0100 | [diff] [blame] | 430 | #define PSA_PAKE_OPERATION_STAGE_SETUP 0 |
| 431 | #define PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS 1 |
| 432 | #define PSA_PAKE_OPERATION_STAGE_COMPUTATION 2 |
Gilles Peskine | dcaefae | 2019-05-16 12:55:35 +0200 | [diff] [blame] | 433 | |
Gilles Peskine | 24f10f8 | 2019-05-16 12:18:32 +0200 | [diff] [blame] | 434 | /**@}*/ |
| 435 | |
Gilles Peskine | 5055b23 | 2019-12-12 17:49:31 +0100 | [diff] [blame] | 436 | |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 437 | /** \defgroup psa_external_rng External random generator |
| 438 | * @{ |
| 439 | */ |
| 440 | |
| 441 | #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
| 442 | /** External random generator function, implemented by the platform. |
| 443 | * |
| 444 | * When the compile-time option #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled, |
| 445 | * this function replaces Mbed TLS's entropy and DRBG modules for all |
| 446 | * random generation triggered via PSA crypto interfaces. |
| 447 | * |
Gilles Peskine | b663a60 | 2020-11-18 15:27:37 +0100 | [diff] [blame] | 448 | * \note This random generator must deliver random numbers with cryptographic |
| 449 | * quality and high performance. It must supply unpredictable numbers |
| 450 | * with a uniform distribution. The implementation of this function |
| 451 | * is responsible for ensuring that the random generator is seeded |
| 452 | * with sufficient entropy. If you have a hardware TRNG which is slow |
| 453 | * or delivers non-uniform output, declare it as an entropy source |
| 454 | * with mbedtls_entropy_add_source() instead of enabling this option. |
| 455 | * |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 456 | * \param[in,out] context Pointer to the random generator context. |
| 457 | * This is all-bits-zero on the first call |
| 458 | * and preserved between successive calls. |
| 459 | * \param[out] output Output buffer. On success, this buffer |
| 460 | * contains random data with a uniform |
| 461 | * distribution. |
| 462 | * \param output_size The size of the \p output buffer in bytes. |
| 463 | * \param[out] output_length On success, set this value to \p output_size. |
| 464 | * |
| 465 | * \retval #PSA_SUCCESS |
Gilles Peskine | e995b9b | 2020-11-30 12:08:00 +0100 | [diff] [blame] | 466 | * Success. The output buffer contains \p output_size bytes of |
| 467 | * cryptographic-quality random data, and \c *output_length is |
| 468 | * set to \p output_size. |
| 469 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
| 470 | * The random generator requires extra entropy and there is no |
| 471 | * way to obtain entropy under current environment conditions. |
| 472 | * This error should not happen under normal circumstances since |
| 473 | * this function is responsible for obtaining as much entropy as |
| 474 | * it needs. However implementations of this function may return |
| 475 | * #PSA_ERROR_INSUFFICIENT_ENTROPY if there is no way to obtain |
| 476 | * entropy without blocking indefinitely. |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 477 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
Gilles Peskine | e995b9b | 2020-11-30 12:08:00 +0100 | [diff] [blame] | 478 | * A failure of the random generator hardware that isn't covered |
| 479 | * by #PSA_ERROR_INSUFFICIENT_ENTROPY. |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 480 | */ |
| 481 | psa_status_t mbedtls_psa_external_get_random( |
| 482 | mbedtls_psa_external_random_context_t *context, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 483 | uint8_t *output, size_t output_size, size_t *output_length); |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 484 | #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ |
| 485 | |
| 486 | /**@}*/ |
| 487 | |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 488 | /** \defgroup psa_builtin_keys Built-in keys |
| 489 | * @{ |
| 490 | */ |
| 491 | |
| 492 | /** The minimum value for a key identifier that is built into the |
| 493 | * implementation. |
| 494 | * |
| 495 | * The range of key identifiers from #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN |
| 496 | * to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX within the range from |
| 497 | * #PSA_KEY_ID_VENDOR_MIN and #PSA_KEY_ID_VENDOR_MAX and must not intersect |
| 498 | * with any other set of implementation-chosen key identifiers. |
| 499 | * |
Gilles Peskine | 543909d | 2024-06-20 22:10:08 +0200 | [diff] [blame] | 500 | * This value is part of the library's API since changing it would invalidate |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 501 | * the values of built-in key identifiers in applications. |
| 502 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 503 | #define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t) 0x7fff0000) |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 504 | |
| 505 | /** The maximum value for a key identifier that is built into the |
| 506 | * implementation. |
| 507 | * |
| 508 | * See #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN for more information. |
| 509 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 510 | #define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t) 0x7fffefff) |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 511 | |
| 512 | /** A slot number identifying a key in a driver. |
| 513 | * |
| 514 | * Values of this type are used to identify built-in keys. |
| 515 | */ |
| 516 | typedef uint64_t psa_drv_slot_number_t; |
| 517 | |
| 518 | #if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 519 | /** Test whether a key identifier belongs to the builtin key range. |
| 520 | * |
| 521 | * \param key_id Key identifier to test. |
| 522 | * |
| 523 | * \retval 1 |
| 524 | * The key identifier is a builtin key identifier. |
| 525 | * \retval 0 |
| 526 | * The key identifier is not a builtin key identifier. |
| 527 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 528 | static inline int psa_key_id_is_builtin(psa_key_id_t key_id) |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 529 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 530 | return (key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN) && |
| 531 | (key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX); |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Steven Cooreman | b938b0b | 2021-04-06 13:08:42 +0200 | [diff] [blame] | 534 | /** Platform function to obtain the location and slot number of a built-in key. |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 535 | * |
| 536 | * An application-specific implementation of this function must be provided if |
Steven Cooreman | 203bcbb | 2021-03-18 17:17:40 +0100 | [diff] [blame] | 537 | * #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 538 | * as part of a platform's system image. |
| 539 | * |
Steven Cooreman | c8b9534 | 2021-03-18 20:48:06 +0100 | [diff] [blame] | 540 | * #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 541 | * #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX. |
| 542 | * |
| 543 | * In a multi-application configuration |
| 544 | * (\c MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined), |
| 545 | * this function should check that #MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(\p key_id) |
| 546 | * is allowed to use the given key. |
| 547 | * |
Steven Cooreman | c8b9534 | 2021-03-18 20:48:06 +0100 | [diff] [blame] | 548 | * \param key_id The key ID for which to retrieve the |
| 549 | * location and slot attributes. |
| 550 | * \param[out] lifetime On success, the lifetime associated with the key |
| 551 | * corresponding to \p key_id. Lifetime is a |
| 552 | * combination of which driver contains the key, |
Steven Cooreman | 31e27af | 2021-04-14 10:32:05 +0200 | [diff] [blame] | 553 | * and with what persistence level the key is |
| 554 | * intended to be used. If the platform |
| 555 | * implementation does not contain specific |
| 556 | * information about the intended key persistence |
| 557 | * level, the persistence level may be reported as |
| 558 | * #PSA_KEY_PERSISTENCE_DEFAULT. |
Steven Cooreman | c8b9534 | 2021-03-18 20:48:06 +0100 | [diff] [blame] | 559 | * \param[out] slot_number On success, the slot number known to the driver |
| 560 | * registered at the lifetime location reported |
Steven Cooreman | b938b0b | 2021-04-06 13:08:42 +0200 | [diff] [blame] | 561 | * through \p lifetime which corresponds to the |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 562 | * requested built-in key. |
| 563 | * |
| 564 | * \retval #PSA_SUCCESS |
| 565 | * The requested key identifier designates a built-in key. |
| 566 | * In a multi-application configuration, the requested owner |
| 567 | * is allowed to access it. |
| 568 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
| 569 | * The requested key identifier is not a built-in key which is known |
| 570 | * to this function. If a key exists in the key storage with this |
| 571 | * identifier, the data from the storage will be used. |
Steven Cooreman | 203bcbb | 2021-03-18 17:17:40 +0100 | [diff] [blame] | 572 | * \return (any other error) |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 573 | * Any other error is propagated to the function that requested the key. |
| 574 | * Common errors include: |
| 575 | * - #PSA_ERROR_NOT_PERMITTED: the key exists but the requested owner |
| 576 | * is not allowed to access it. |
| 577 | */ |
| 578 | psa_status_t mbedtls_psa_platform_get_builtin_key( |
Steven Cooreman | c8b9534 | 2021-03-18 20:48:06 +0100 | [diff] [blame] | 579 | mbedtls_svc_key_id_t key_id, |
| 580 | psa_key_lifetime_t *lifetime, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 581 | psa_drv_slot_number_t *slot_number); |
Steven Cooreman | 6801f08 | 2021-02-19 17:21:22 +0100 | [diff] [blame] | 582 | #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */ |
| 583 | |
| 584 | /** @} */ |
| 585 | |
Valerio Setti | 05b3835 | 2025-02-21 14:40:51 +0100 | [diff] [blame^] | 586 | /** \defgroup psa_crypto_client Functions defined by a client provider |
| 587 | * |
| 588 | * The functions in this group are meant to be implemented by providers of |
| 589 | * the PSA Crypto client interface. They are provided by the library when |
| 590 | * #MBEDTLS_PSA_CRYPTO_C is enabled. |
| 591 | * |
| 592 | * \note All functions in this group are experimental, as using |
| 593 | * alternative client interface providers is experimental. |
| 594 | * |
| 595 | * @{ |
| 596 | */ |
| 597 | |
| 598 | /** |
| 599 | * Tell if PSA is ready for this hash. |
| 600 | * |
| 601 | * \note For now, only checks the state of the driver subsystem, |
| 602 | * not the algorithm. Might do more in the future. |
| 603 | * |
| 604 | * \param hash_alg The hash algorithm (ignored for now). |
| 605 | * |
| 606 | * \return 1 if the driver subsytem is ready, 0 otherwise. |
| 607 | */ |
| 608 | int psa_can_do_hash(psa_algorithm_t hash_alg); |
| 609 | |
| 610 | /**@}*/ |
| 611 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 612 | /** \addtogroup crypto_types |
| 613 | * @{ |
| 614 | */ |
| 615 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 616 | #define PSA_ALG_CATEGORY_PAKE ((psa_algorithm_t) 0x0a000000) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 617 | |
| 618 | /** Whether the specified algorithm is a password-authenticated key exchange. |
| 619 | * |
| 620 | * \param alg An algorithm identifier (value of type #psa_algorithm_t). |
| 621 | * |
| 622 | * \return 1 if \p alg is a password-authenticated key exchange (PAKE) |
| 623 | * algorithm, 0 otherwise. |
| 624 | * This macro may return either 0 or 1 if \p alg is not a supported |
| 625 | * algorithm identifier. |
| 626 | */ |
| 627 | #define PSA_ALG_IS_PAKE(alg) \ |
| 628 | (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_PAKE) |
| 629 | |
| 630 | /** The Password-authenticated key exchange by juggling (J-PAKE) algorithm. |
| 631 | * |
| 632 | * This is J-PAKE as defined by RFC 8236, instantiated with the following |
| 633 | * parameters: |
| 634 | * |
| 635 | * - The group can be either an elliptic curve or defined over a finite field. |
| 636 | * - Schnorr NIZK proof as defined by RFC 8235 and using the same group as the |
| 637 | * J-PAKE algorithm. |
Janos Follath | 46c0237 | 2021-06-08 15:22:51 +0100 | [diff] [blame] | 638 | * - A cryptographic hash function. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 639 | * |
Janos Follath | 46c0237 | 2021-06-08 15:22:51 +0100 | [diff] [blame] | 640 | * To select these parameters and set up the cipher suite, call these functions |
| 641 | * in any order: |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 642 | * |
| 643 | * \code |
| 644 | * psa_pake_cs_set_algorithm(cipher_suite, PSA_ALG_JPAKE); |
| 645 | * psa_pake_cs_set_primitive(cipher_suite, |
| 646 | * PSA_PAKE_PRIMITIVE(type, family, bits)); |
| 647 | * psa_pake_cs_set_hash(cipher_suite, hash); |
| 648 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 649 | * |
| 650 | * For more information on how to set a specific curve or field, refer to the |
| 651 | * documentation of the individual \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants. |
| 652 | * |
| 653 | * After initializing a J-PAKE operation, call |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 654 | * |
| 655 | * \code |
| 656 | * psa_pake_setup(operation, cipher_suite); |
| 657 | * psa_pake_set_user(operation, ...); |
| 658 | * psa_pake_set_peer(operation, ...); |
| 659 | * psa_pake_set_password_key(operation, ...); |
| 660 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 661 | * |
Neil Armstrong | 1614537 | 2022-05-20 10:42:36 +0200 | [diff] [blame] | 662 | * The password is provided as a key. This can be the password text itself, |
| 663 | * in an agreed character encoding, or some value derived from the password |
| 664 | * as required by a higher level protocol. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 665 | * |
Neil Armstrong | 1614537 | 2022-05-20 10:42:36 +0200 | [diff] [blame] | 666 | * (The implementation converts the key material to a number as described in |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 667 | * Section 2.3.8 of _SEC 1: Elliptic Curve Cryptography_ |
| 668 | * (https://www.secg.org/sec1-v2.pdf), before reducing it modulo \c q. Here |
| 669 | * \c q is order of the group defined by the primitive set in the cipher suite. |
Neil Armstrong | 5892aa6 | 2022-05-27 09:44:47 +0200 | [diff] [blame] | 670 | * The \c psa_pake_set_password_key() function returns an error if the result |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 671 | * of the reduction is 0.) |
| 672 | * |
| 673 | * The key exchange flow for J-PAKE is as follows: |
| 674 | * -# To get the first round data that needs to be sent to the peer, call |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 675 | * \code |
| 676 | * // Get g1 |
| 677 | * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...); |
| 678 | * // Get the ZKP public key for x1 |
| 679 | * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...); |
| 680 | * // Get the ZKP proof for x1 |
| 681 | * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...); |
| 682 | * // Get g2 |
| 683 | * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...); |
| 684 | * // Get the ZKP public key for x2 |
| 685 | * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...); |
| 686 | * // Get the ZKP proof for x2 |
| 687 | * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...); |
| 688 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 689 | * -# To provide the first round data received from the peer to the operation, |
| 690 | * call |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 691 | * \code |
| 692 | * // Set g3 |
| 693 | * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...); |
| 694 | * // Set the ZKP public key for x3 |
| 695 | * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...); |
| 696 | * // Set the ZKP proof for x3 |
| 697 | * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...); |
| 698 | * // Set g4 |
| 699 | * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...); |
| 700 | * // Set the ZKP public key for x4 |
| 701 | * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...); |
| 702 | * // Set the ZKP proof for x4 |
| 703 | * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...); |
| 704 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 705 | * -# To get the second round data that needs to be sent to the peer, call |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 706 | * \code |
| 707 | * // Get A |
| 708 | * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...); |
| 709 | * // Get ZKP public key for x2*s |
| 710 | * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...); |
| 711 | * // Get ZKP proof for x2*s |
| 712 | * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...); |
| 713 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 714 | * -# To provide the second round data received from the peer to the operation, |
| 715 | * call |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 716 | * \code |
| 717 | * // Set B |
| 718 | * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...); |
| 719 | * // Set ZKP public key for x4*s |
| 720 | * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...); |
| 721 | * // Set ZKP proof for x4*s |
| 722 | * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...); |
| 723 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 724 | * -# To access the shared secret call |
Janos Follath | b384ec1 | 2021-06-03 14:48:51 +0100 | [diff] [blame] | 725 | * \code |
| 726 | * // Get Ka=Kb=K |
| 727 | * psa_pake_get_implicit_key() |
| 728 | * \endcode |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 729 | * |
| 730 | * For more information consult the documentation of the individual |
| 731 | * \c PSA_PAKE_STEP_XXX constants. |
| 732 | * |
| 733 | * At this point there is a cryptographic guarantee that only the authenticated |
| 734 | * party who used the same password is able to compute the key. But there is no |
Janos Follath | a46e28f | 2021-06-03 13:07:03 +0100 | [diff] [blame] | 735 | * guarantee that the peer is the party it claims to be and was able to do so. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 736 | * |
| 737 | * That is, the authentication is only implicit (the peer is not authenticated |
| 738 | * at this point, and no action should be taken that assume that they are - like |
| 739 | * for example accessing restricted files). |
| 740 | * |
| 741 | * To make the authentication explicit there are various methods, see Section 5 |
| 742 | * of RFC 8236 for two examples. |
| 743 | * |
| 744 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 745 | #define PSA_ALG_JPAKE ((psa_algorithm_t) 0x0a000100) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 746 | |
| 747 | /** @} */ |
| 748 | |
| 749 | /** \defgroup pake Password-authenticated key exchange (PAKE) |
Janos Follath | 7d69b3a | 2021-05-26 13:10:56 +0100 | [diff] [blame] | 750 | * |
| 751 | * This is a proposed PAKE interface for the PSA Crypto API. It is not part of |
| 752 | * the official PSA Crypto API yet. |
| 753 | * |
| 754 | * \note The content of this section is not part of the stable API and ABI |
Fredrik Hesse | cc207bc | 2021-09-28 21:06:08 +0200 | [diff] [blame] | 755 | * of Mbed TLS and may change arbitrarily from version to version. |
Janos Follath | 7d69b3a | 2021-05-26 13:10:56 +0100 | [diff] [blame] | 756 | * Same holds for the corresponding macros #PSA_ALG_CATEGORY_PAKE and |
| 757 | * #PSA_ALG_JPAKE. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 758 | * @{ |
| 759 | */ |
| 760 | |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 761 | /** \brief Encoding of the application role of PAKE |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 762 | * |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 763 | * Encodes the application's role in the algorithm is being executed. For more |
| 764 | * information see the documentation of individual \c PSA_PAKE_ROLE_XXX |
| 765 | * constants. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 766 | */ |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 767 | typedef uint8_t psa_pake_role_t; |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 768 | |
| 769 | /** Encoding of input and output indicators for PAKE. |
| 770 | * |
| 771 | * Some PAKE algorithms need to exchange more data than just a single key share. |
| 772 | * This type is for encoding additional input and output data for such |
| 773 | * algorithms. |
| 774 | */ |
| 775 | typedef uint8_t psa_pake_step_t; |
| 776 | |
| 777 | /** Encoding of the type of the PAKE's primitive. |
| 778 | * |
| 779 | * Values defined by this standard will never be in the range 0x80-0xff. |
| 780 | * Vendors who define additional types must use an encoding in this range. |
| 781 | * |
| 782 | * For more information see the documentation of individual |
| 783 | * \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants. |
| 784 | */ |
| 785 | typedef uint8_t psa_pake_primitive_type_t; |
| 786 | |
| 787 | /** \brief Encoding of the family of the primitive associated with the PAKE. |
| 788 | * |
| 789 | * For more information see the documentation of individual |
| 790 | * \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants. |
| 791 | */ |
| 792 | typedef uint8_t psa_pake_family_t; |
| 793 | |
| 794 | /** \brief Encoding of the primitive associated with the PAKE. |
| 795 | * |
| 796 | * For more information see the documentation of the #PSA_PAKE_PRIMITIVE macro. |
| 797 | */ |
| 798 | typedef uint32_t psa_pake_primitive_t; |
| 799 | |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 800 | /** A value to indicate no role in a PAKE algorithm. |
| 801 | * This value can be used in a call to psa_pake_set_role() for symmetric PAKE |
| 802 | * algorithms which do not assign roles. |
| 803 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 804 | #define PSA_PAKE_ROLE_NONE ((psa_pake_role_t) 0x00) |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 805 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 806 | /** The first peer in a balanced PAKE. |
| 807 | * |
| 808 | * Although balanced PAKE algorithms are symmetric, some of them needs an |
| 809 | * ordering of peers for the transcript calculations. If the algorithm does not |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 810 | * need this, both #PSA_PAKE_ROLE_FIRST and #PSA_PAKE_ROLE_SECOND are |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 811 | * accepted. |
| 812 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 813 | #define PSA_PAKE_ROLE_FIRST ((psa_pake_role_t) 0x01) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 814 | |
| 815 | /** The second peer in a balanced PAKE. |
| 816 | * |
| 817 | * Although balanced PAKE algorithms are symmetric, some of them needs an |
| 818 | * ordering of peers for the transcript calculations. If the algorithm does not |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 819 | * need this, either #PSA_PAKE_ROLE_FIRST or #PSA_PAKE_ROLE_SECOND are |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 820 | * accepted. |
| 821 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 822 | #define PSA_PAKE_ROLE_SECOND ((psa_pake_role_t) 0x02) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 823 | |
| 824 | /** The client in an augmented PAKE. |
| 825 | * |
| 826 | * Augmented PAKE algorithms need to differentiate between client and server. |
| 827 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 828 | #define PSA_PAKE_ROLE_CLIENT ((psa_pake_role_t) 0x11) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 829 | |
| 830 | /** The server in an augmented PAKE. |
| 831 | * |
| 832 | * Augmented PAKE algorithms need to differentiate between client and server. |
| 833 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 834 | #define PSA_PAKE_ROLE_SERVER ((psa_pake_role_t) 0x12) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 835 | |
| 836 | /** The PAKE primitive type indicating the use of elliptic curves. |
| 837 | * |
| 838 | * The values of the \c family and \c bits fields of the cipher suite identify a |
| 839 | * specific elliptic curve, using the same mapping that is used for ECC |
| 840 | * (::psa_ecc_family_t) keys. |
| 841 | * |
| 842 | * (Here \c family means the value returned by psa_pake_cs_get_family() and |
| 843 | * \c bits means the value returned by psa_pake_cs_get_bits().) |
| 844 | * |
| 845 | * Input and output during the operation can involve group elements and scalar |
| 846 | * values: |
| 847 | * -# The format for group elements is the same as for public keys on the |
| 848 | * specific curve would be. For more information, consult the documentation of |
| 849 | * psa_export_public_key(). |
| 850 | * -# The format for scalars is the same as for private keys on the specific |
| 851 | * curve would be. For more information, consult the documentation of |
| 852 | * psa_export_key(). |
| 853 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 854 | #define PSA_PAKE_PRIMITIVE_TYPE_ECC ((psa_pake_primitive_type_t) 0x01) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 855 | |
| 856 | /** The PAKE primitive type indicating the use of Diffie-Hellman groups. |
| 857 | * |
| 858 | * The values of the \c family and \c bits fields of the cipher suite identify |
| 859 | * a specific Diffie-Hellman group, using the same mapping that is used for |
| 860 | * Diffie-Hellman (::psa_dh_family_t) keys. |
| 861 | * |
| 862 | * (Here \c family means the value returned by psa_pake_cs_get_family() and |
| 863 | * \c bits means the value returned by psa_pake_cs_get_bits().) |
| 864 | * |
| 865 | * Input and output during the operation can involve group elements and scalar |
| 866 | * values: |
| 867 | * -# The format for group elements is the same as for public keys on the |
| 868 | * specific group would be. For more information, consult the documentation of |
| 869 | * psa_export_public_key(). |
| 870 | * -# The format for scalars is the same as for private keys on the specific |
| 871 | * group would be. For more information, consult the documentation of |
| 872 | * psa_export_key(). |
| 873 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 874 | #define PSA_PAKE_PRIMITIVE_TYPE_DH ((psa_pake_primitive_type_t) 0x02) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 875 | |
| 876 | /** Construct a PAKE primitive from type, family and bit-size. |
| 877 | * |
| 878 | * \param pake_type The type of the primitive |
| 879 | * (value of type ::psa_pake_primitive_type_t). |
| 880 | * \param pake_family The family of the primitive |
| 881 | * (the type and interpretation of this parameter depends |
Andrzej Kurek | 3bedb5b | 2022-02-17 14:39:00 -0500 | [diff] [blame] | 882 | * on \p pake_type, for more information consult the |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 883 | * documentation of individual ::psa_pake_primitive_type_t |
| 884 | * constants). |
| 885 | * \param pake_bits The bit-size of the primitive |
| 886 | * (Value of type \c size_t. The interpretation |
Andrzej Kurek | 3bedb5b | 2022-02-17 14:39:00 -0500 | [diff] [blame] | 887 | * of this parameter depends on \p pake_family, for more |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 888 | * information consult the documentation of individual |
| 889 | * ::psa_pake_primitive_type_t constants). |
| 890 | * |
| 891 | * \return The constructed primitive value of type ::psa_pake_primitive_t. |
| 892 | * Return 0 if the requested primitive can't be encoded as |
| 893 | * ::psa_pake_primitive_t. |
| 894 | */ |
| 895 | #define PSA_PAKE_PRIMITIVE(pake_type, pake_family, pake_bits) \ |
| 896 | ((pake_bits & 0xFFFF) != pake_bits) ? 0 : \ |
| 897 | ((psa_pake_primitive_t) (((pake_type) << 24 | \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 898 | (pake_family) << 16) | (pake_bits))) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 899 | |
| 900 | /** The key share being sent to or received from the peer. |
| 901 | * |
| 902 | * The format for both input and output at this step is the same as for public |
| 903 | * keys on the group determined by the primitive (::psa_pake_primitive_t) would |
| 904 | * be. |
| 905 | * |
| 906 | * For more information on the format, consult the documentation of |
| 907 | * psa_export_public_key(). |
| 908 | * |
| 909 | * For information regarding how the group is determined, consult the |
| 910 | * documentation #PSA_PAKE_PRIMITIVE. |
| 911 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 912 | #define PSA_PAKE_STEP_KEY_SHARE ((psa_pake_step_t) 0x01) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 913 | |
| 914 | /** A Schnorr NIZKP public key. |
| 915 | * |
Janos Follath | 55dd5dc | 2021-06-03 15:51:09 +0100 | [diff] [blame] | 916 | * This is the ephemeral public key in the Schnorr Non-Interactive |
| 917 | * Zero-Knowledge Proof (the value denoted by the letter 'V' in RFC 8235). |
| 918 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 919 | * The format for both input and output at this step is the same as for public |
| 920 | * keys on the group determined by the primitive (::psa_pake_primitive_t) would |
| 921 | * be. |
| 922 | * |
| 923 | * For more information on the format, consult the documentation of |
| 924 | * psa_export_public_key(). |
| 925 | * |
| 926 | * For information regarding how the group is determined, consult the |
| 927 | * documentation #PSA_PAKE_PRIMITIVE. |
| 928 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 929 | #define PSA_PAKE_STEP_ZK_PUBLIC ((psa_pake_step_t) 0x02) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 930 | |
| 931 | /** A Schnorr NIZKP proof. |
| 932 | * |
Janos Follath | 55dd5dc | 2021-06-03 15:51:09 +0100 | [diff] [blame] | 933 | * This is the proof in the Schnorr Non-Interactive Zero-Knowledge Proof (the |
| 934 | * value denoted by the letter 'r' in RFC 8235). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 935 | * |
Janos Follath | 1f01318 | 2021-06-08 15:30:48 +0100 | [diff] [blame] | 936 | * Both for input and output, the value at this step is an integer less than |
| 937 | * the order of the group selected in the cipher suite. The format depends on |
| 938 | * the group as well: |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 939 | * |
Janos Follath | 1f01318 | 2021-06-08 15:30:48 +0100 | [diff] [blame] | 940 | * - For Montgomery curves, the encoding is little endian. |
Janos Follath | 55dd5dc | 2021-06-03 15:51:09 +0100 | [diff] [blame] | 941 | * - For everything else the encoding is big endian (see Section 2.3.8 of |
| 942 | * _SEC 1: Elliptic Curve Cryptography_ at https://www.secg.org/sec1-v2.pdf). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 943 | * |
Janos Follath | 1f01318 | 2021-06-08 15:30:48 +0100 | [diff] [blame] | 944 | * In both cases leading zeroes are allowed as long as the length in bytes does |
| 945 | * not exceed the byte length of the group order. |
| 946 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 947 | * For information regarding how the group is determined, consult the |
| 948 | * documentation #PSA_PAKE_PRIMITIVE. |
| 949 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 950 | #define PSA_PAKE_STEP_ZK_PROOF ((psa_pake_step_t) 0x03) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 951 | |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 952 | /** The type of the data structure for PAKE cipher suites. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 953 | * |
| 954 | * This is an implementation-defined \c struct. Applications should not |
| 955 | * make any assumptions about the content of this structure. |
| 956 | * Implementation details can change in future versions without notice. |
| 957 | */ |
| 958 | typedef struct psa_pake_cipher_suite_s psa_pake_cipher_suite_t; |
| 959 | |
Neil Armstrong | 5ff6a7f | 2022-05-20 10:12:01 +0200 | [diff] [blame] | 960 | /** Return an initial value for a PAKE cipher suite object. |
| 961 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 962 | static psa_pake_cipher_suite_t psa_pake_cipher_suite_init(void); |
Neil Armstrong | 5ff6a7f | 2022-05-20 10:12:01 +0200 | [diff] [blame] | 963 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 964 | /** Retrieve the PAKE algorithm from a PAKE cipher suite. |
| 965 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 966 | * \param[in] cipher_suite The cipher suite structure to query. |
| 967 | * |
| 968 | * \return The PAKE algorithm stored in the cipher suite structure. |
| 969 | */ |
| 970 | static psa_algorithm_t psa_pake_cs_get_algorithm( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 971 | const psa_pake_cipher_suite_t *cipher_suite); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 972 | |
| 973 | /** Declare the PAKE algorithm for the cipher suite. |
| 974 | * |
| 975 | * This function overwrites any PAKE algorithm |
| 976 | * previously set in \p cipher_suite. |
| 977 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 978 | * \param[out] cipher_suite The cipher suite structure to write to. |
| 979 | * \param algorithm The PAKE algorithm to write. |
| 980 | * (`PSA_ALG_XXX` values of type ::psa_algorithm_t |
| 981 | * such that #PSA_ALG_IS_PAKE(\c alg) is true.) |
| 982 | * If this is 0, the PAKE algorithm in |
| 983 | * \p cipher_suite becomes unspecified. |
| 984 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 985 | static void psa_pake_cs_set_algorithm(psa_pake_cipher_suite_t *cipher_suite, |
| 986 | psa_algorithm_t algorithm); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 987 | |
| 988 | /** Retrieve the primitive from a PAKE cipher suite. |
| 989 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 990 | * \param[in] cipher_suite The cipher suite structure to query. |
| 991 | * |
| 992 | * \return The primitive stored in the cipher suite structure. |
| 993 | */ |
| 994 | static psa_pake_primitive_t psa_pake_cs_get_primitive( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 995 | const psa_pake_cipher_suite_t *cipher_suite); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 996 | |
| 997 | /** Declare the primitive for a PAKE cipher suite. |
| 998 | * |
| 999 | * This function overwrites any primitive previously set in \p cipher_suite. |
| 1000 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1001 | * \param[out] cipher_suite The cipher suite structure to write to. |
| 1002 | * \param primitive The primitive to write. If this is 0, the |
| 1003 | * primitive type in \p cipher_suite becomes |
| 1004 | * unspecified. |
| 1005 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1006 | static void psa_pake_cs_set_primitive(psa_pake_cipher_suite_t *cipher_suite, |
| 1007 | psa_pake_primitive_t primitive); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1008 | |
Neil Armstrong | ff9cac7 | 2022-05-20 10:25:15 +0200 | [diff] [blame] | 1009 | /** Retrieve the PAKE family from a PAKE cipher suite. |
| 1010 | * |
Neil Armstrong | ff9cac7 | 2022-05-20 10:25:15 +0200 | [diff] [blame] | 1011 | * \param[in] cipher_suite The cipher suite structure to query. |
| 1012 | * |
| 1013 | * \return The PAKE family stored in the cipher suite structure. |
| 1014 | */ |
| 1015 | static psa_pake_family_t psa_pake_cs_get_family( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1016 | const psa_pake_cipher_suite_t *cipher_suite); |
Neil Armstrong | ff9cac7 | 2022-05-20 10:25:15 +0200 | [diff] [blame] | 1017 | |
Neil Armstrong | d5a4825 | 2022-05-20 10:26:36 +0200 | [diff] [blame] | 1018 | /** Retrieve the PAKE primitive bit-size from a PAKE cipher suite. |
| 1019 | * |
Neil Armstrong | d5a4825 | 2022-05-20 10:26:36 +0200 | [diff] [blame] | 1020 | * \param[in] cipher_suite The cipher suite structure to query. |
| 1021 | * |
| 1022 | * \return The PAKE primitive bit-size stored in the cipher suite structure. |
| 1023 | */ |
| 1024 | static uint16_t psa_pake_cs_get_bits( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1025 | const psa_pake_cipher_suite_t *cipher_suite); |
Neil Armstrong | d5a4825 | 2022-05-20 10:26:36 +0200 | [diff] [blame] | 1026 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1027 | /** Retrieve the hash algorithm from a PAKE cipher suite. |
| 1028 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1029 | * \param[in] cipher_suite The cipher suite structure to query. |
| 1030 | * |
| 1031 | * \return The hash algorithm stored in the cipher suite structure. The return |
| 1032 | * value is 0 if the PAKE is not parametrised by a hash algorithm or if |
| 1033 | * the hash algorithm is not set. |
| 1034 | */ |
| 1035 | static psa_algorithm_t psa_pake_cs_get_hash( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1036 | const psa_pake_cipher_suite_t *cipher_suite); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1037 | |
| 1038 | /** Declare the hash algorithm for a PAKE cipher suite. |
| 1039 | * |
| 1040 | * This function overwrites any hash algorithm |
| 1041 | * previously set in \p cipher_suite. |
| 1042 | * |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1043 | * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` |
| 1044 | * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) |
| 1045 | * for more information. |
| 1046 | * |
| 1047 | * \param[out] cipher_suite The cipher suite structure to write to. |
| 1048 | * \param hash The hash involved in the cipher suite. |
| 1049 | * (`PSA_ALG_XXX` values of type ::psa_algorithm_t |
| 1050 | * such that #PSA_ALG_IS_HASH(\c alg) is true.) |
| 1051 | * If this is 0, the hash algorithm in |
| 1052 | * \p cipher_suite becomes unspecified. |
| 1053 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1054 | static void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite, |
| 1055 | psa_algorithm_t hash); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1056 | |
| 1057 | /** The type of the state data structure for PAKE operations. |
| 1058 | * |
| 1059 | * Before calling any function on a PAKE operation object, the application |
| 1060 | * must initialize it by any of the following means: |
| 1061 | * - Set the structure to all-bits-zero, for example: |
| 1062 | * \code |
| 1063 | * psa_pake_operation_t operation; |
| 1064 | * memset(&operation, 0, sizeof(operation)); |
| 1065 | * \endcode |
| 1066 | * - Initialize the structure to logical zero values, for example: |
| 1067 | * \code |
| 1068 | * psa_pake_operation_t operation = {0}; |
| 1069 | * \endcode |
| 1070 | * - Initialize the structure to the initializer #PSA_PAKE_OPERATION_INIT, |
| 1071 | * for example: |
| 1072 | * \code |
| 1073 | * psa_pake_operation_t operation = PSA_PAKE_OPERATION_INIT; |
| 1074 | * \endcode |
| 1075 | * - Assign the result of the function psa_pake_operation_init() |
| 1076 | * to the structure, for example: |
| 1077 | * \code |
| 1078 | * psa_pake_operation_t operation; |
| 1079 | * operation = psa_pake_operation_init(); |
| 1080 | * \endcode |
| 1081 | * |
| 1082 | * This is an implementation-defined \c struct. Applications should not |
| 1083 | * make any assumptions about the content of this structure. |
| 1084 | * Implementation details can change in future versions without notice. */ |
| 1085 | typedef struct psa_pake_operation_s psa_pake_operation_t; |
| 1086 | |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1087 | /** The type of input values for PAKE operations. */ |
| 1088 | typedef struct psa_crypto_driver_pake_inputs_s psa_crypto_driver_pake_inputs_t; |
| 1089 | |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 1090 | /** The type of computation stage for J-PAKE operations. */ |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 1091 | typedef struct psa_jpake_computation_stage_s psa_jpake_computation_stage_t; |
| 1092 | |
Tom Cosgrove | ce7f18c | 2022-07-28 05:50:56 +0100 | [diff] [blame] | 1093 | /** Return an initial value for a PAKE operation object. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1094 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1095 | static psa_pake_operation_t psa_pake_operation_init(void); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1096 | |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1097 | /** Get the length of the password in bytes from given inputs. |
Przemek Stekiel | ca8d2b2 | 2023-01-17 16:21:33 +0100 | [diff] [blame] | 1098 | * |
| 1099 | * \param[in] inputs Operation inputs. |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1100 | * \param[out] password_len Password length. |
Przemek Stekiel | ca8d2b2 | 2023-01-17 16:21:33 +0100 | [diff] [blame] | 1101 | * |
| 1102 | * \retval #PSA_SUCCESS |
| 1103 | * Success. |
| 1104 | * \retval #PSA_ERROR_BAD_STATE |
| 1105 | * Password hasn't been set yet. |
| 1106 | */ |
| 1107 | psa_status_t psa_crypto_driver_pake_get_password_len( |
| 1108 | const psa_crypto_driver_pake_inputs_t *inputs, |
| 1109 | size_t *password_len); |
| 1110 | |
| 1111 | /** Get the password from given inputs. |
| 1112 | * |
| 1113 | * \param[in] inputs Operation inputs. |
| 1114 | * \param[out] buffer Return buffer for password. |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 1115 | * \param buffer_size Size of the return buffer in bytes. |
| 1116 | * \param[out] buffer_length Actual size of the password in bytes. |
Przemek Stekiel | ca8d2b2 | 2023-01-17 16:21:33 +0100 | [diff] [blame] | 1117 | * |
| 1118 | * \retval #PSA_SUCCESS |
| 1119 | * Success. |
| 1120 | * \retval #PSA_ERROR_BAD_STATE |
| 1121 | * Password hasn't been set yet. |
| 1122 | */ |
| 1123 | psa_status_t psa_crypto_driver_pake_get_password( |
| 1124 | const psa_crypto_driver_pake_inputs_t *inputs, |
| 1125 | uint8_t *buffer, size_t buffer_size, size_t *buffer_length); |
| 1126 | |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1127 | /** Get the length of the user id in bytes from given inputs. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1128 | * |
| 1129 | * \param[in] inputs Operation inputs. |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1130 | * \param[out] user_len User id length. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1131 | * |
| 1132 | * \retval #PSA_SUCCESS |
| 1133 | * Success. |
| 1134 | * \retval #PSA_ERROR_BAD_STATE |
Przemek Stekiel | d7f6ad7 | 2023-03-06 13:39:52 +0100 | [diff] [blame] | 1135 | * User id hasn't been set yet. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1136 | */ |
| 1137 | psa_status_t psa_crypto_driver_pake_get_user_len( |
| 1138 | const psa_crypto_driver_pake_inputs_t *inputs, |
| 1139 | size_t *user_len); |
| 1140 | |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1141 | /** Get the length of the peer id in bytes from given inputs. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1142 | * |
| 1143 | * \param[in] inputs Operation inputs. |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1144 | * \param[out] peer_len Peer id length. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1145 | * |
| 1146 | * \retval #PSA_SUCCESS |
| 1147 | * Success. |
| 1148 | * \retval #PSA_ERROR_BAD_STATE |
Przemek Stekiel | d7f6ad7 | 2023-03-06 13:39:52 +0100 | [diff] [blame] | 1149 | * Peer id hasn't been set yet. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1150 | */ |
| 1151 | psa_status_t psa_crypto_driver_pake_get_peer_len( |
| 1152 | const psa_crypto_driver_pake_inputs_t *inputs, |
| 1153 | size_t *peer_len); |
| 1154 | |
Przemek Stekiel | d7f6ad7 | 2023-03-06 13:39:52 +0100 | [diff] [blame] | 1155 | /** Get the user id from given inputs. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1156 | * |
| 1157 | * \param[in] inputs Operation inputs. |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1158 | * \param[out] user_id User id. |
| 1159 | * \param user_id_size Size of \p user_id in bytes. |
| 1160 | * \param[out] user_id_len Size of the user id in bytes. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1161 | * |
| 1162 | * \retval #PSA_SUCCESS |
| 1163 | * Success. |
| 1164 | * \retval #PSA_ERROR_BAD_STATE |
Przemek Stekiel | d7f6ad7 | 2023-03-06 13:39:52 +0100 | [diff] [blame] | 1165 | * User id hasn't been set yet. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1166 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1167 | * The size of the \p user_id is too small. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1168 | */ |
| 1169 | psa_status_t psa_crypto_driver_pake_get_user( |
| 1170 | const psa_crypto_driver_pake_inputs_t *inputs, |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1171 | uint8_t *user_id, size_t user_id_size, size_t *user_id_len); |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1172 | |
Przemek Stekiel | d7f6ad7 | 2023-03-06 13:39:52 +0100 | [diff] [blame] | 1173 | /** Get the peer id from given inputs. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1174 | * |
| 1175 | * \param[in] inputs Operation inputs. |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1176 | * \param[out] peer_id Peer id. |
| 1177 | * \param peer_id_size Size of \p peer_id in bytes. |
| 1178 | * \param[out] peer_id_length Size of the peer id in bytes. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1179 | * |
| 1180 | * \retval #PSA_SUCCESS |
| 1181 | * Success. |
| 1182 | * \retval #PSA_ERROR_BAD_STATE |
Przemek Stekiel | d7f6ad7 | 2023-03-06 13:39:52 +0100 | [diff] [blame] | 1183 | * Peer id hasn't been set yet. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1184 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1185 | * The size of the \p peer_id is too small. |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1186 | */ |
| 1187 | psa_status_t psa_crypto_driver_pake_get_peer( |
| 1188 | const psa_crypto_driver_pake_inputs_t *inputs, |
Przemek Stekiel | c0e6250 | 2023-03-14 11:49:36 +0100 | [diff] [blame] | 1189 | uint8_t *peer_id, size_t peer_id_size, size_t *peer_id_length); |
Przemek Stekiel | 1e7a927 | 2023-02-28 14:38:58 +0100 | [diff] [blame] | 1190 | |
Przemek Stekiel | ca8d2b2 | 2023-01-17 16:21:33 +0100 | [diff] [blame] | 1191 | /** Get the cipher suite from given inputs. |
| 1192 | * |
| 1193 | * \param[in] inputs Operation inputs. |
| 1194 | * \param[out] cipher_suite Return buffer for role. |
| 1195 | * |
| 1196 | * \retval #PSA_SUCCESS |
| 1197 | * Success. |
| 1198 | * \retval #PSA_ERROR_BAD_STATE |
| 1199 | * Cipher_suite hasn't been set yet. |
| 1200 | */ |
| 1201 | psa_status_t psa_crypto_driver_pake_get_cipher_suite( |
| 1202 | const psa_crypto_driver_pake_inputs_t *inputs, |
| 1203 | psa_pake_cipher_suite_t *cipher_suite); |
| 1204 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1205 | /** Set the session information for a password-authenticated key exchange. |
| 1206 | * |
| 1207 | * The sequence of operations to set up a password-authenticated key exchange |
| 1208 | * is as follows: |
| 1209 | * -# Allocate an operation object which will be passed to all the functions |
| 1210 | * listed here. |
| 1211 | * -# Initialize the operation object with one of the methods described in the |
| 1212 | * documentation for #psa_pake_operation_t, e.g. |
| 1213 | * #PSA_PAKE_OPERATION_INIT. |
| 1214 | * -# Call psa_pake_setup() to specify the cipher suite. |
| 1215 | * -# Call \c psa_pake_set_xxx() functions on the operation to complete the |
| 1216 | * setup. The exact sequence of \c psa_pake_set_xxx() functions that needs |
| 1217 | * to be called depends on the algorithm in use. |
| 1218 | * |
| 1219 | * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` |
| 1220 | * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) |
| 1221 | * for more information. |
| 1222 | * |
| 1223 | * A typical sequence of calls to perform a password-authenticated key |
| 1224 | * exchange: |
| 1225 | * -# Call psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to get the |
| 1226 | * key share that needs to be sent to the peer. |
| 1227 | * -# Call psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to provide |
| 1228 | * the key share that was received from the peer. |
| 1229 | * -# Depending on the algorithm additional calls to psa_pake_output() and |
| 1230 | * psa_pake_input() might be necessary. |
| 1231 | * -# Call psa_pake_get_implicit_key() for accessing the shared secret. |
| 1232 | * |
| 1233 | * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` |
| 1234 | * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) |
| 1235 | * for more information. |
| 1236 | * |
| 1237 | * If an error occurs at any step after a call to psa_pake_setup(), |
| 1238 | * the operation will need to be reset by a call to psa_pake_abort(). The |
| 1239 | * application may call psa_pake_abort() at any time after the operation |
| 1240 | * has been initialized. |
| 1241 | * |
| 1242 | * After a successful call to psa_pake_setup(), the application must |
| 1243 | * eventually terminate the operation. The following events terminate an |
| 1244 | * operation: |
| 1245 | * - A call to psa_pake_abort(). |
| 1246 | * - A successful call to psa_pake_get_implicit_key(). |
| 1247 | * |
| 1248 | * \param[in,out] operation The operation object to set up. It must have |
Janos Follath | 3293dae | 2021-06-03 13:21:33 +0100 | [diff] [blame] | 1249 | * been initialized but not set up yet. |
Neil Armstrong | 47e700e | 2022-05-20 10:16:41 +0200 | [diff] [blame] | 1250 | * \param[in] cipher_suite The cipher suite to use. (A cipher suite fully |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1251 | * characterizes a PAKE algorithm and determines |
| 1252 | * the algorithm as well.) |
| 1253 | * |
| 1254 | * \retval #PSA_SUCCESS |
| 1255 | * Success. |
Neil Armstrong | 4721a6f | 2022-05-20 10:53:00 +0200 | [diff] [blame] | 1256 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 1257 | * The algorithm in \p cipher_suite is not a PAKE algorithm, or the |
| 1258 | * PAKE primitive in \p cipher_suite is not compatible with the |
| 1259 | * PAKE algorithm, or the hash algorithm in \p cipher_suite is invalid |
| 1260 | * or not compatible with the PAKE algorithm and primitive. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1261 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Neil Armstrong | 4721a6f | 2022-05-20 10:53:00 +0200 | [diff] [blame] | 1262 | * The algorithm in \p cipher_suite is not a supported PAKE algorithm, |
| 1263 | * or the PAKE primitive in \p cipher_suite is not supported or not |
| 1264 | * compatible with the PAKE algorithm, or the hash algorithm in |
| 1265 | * \p cipher_suite is not supported or not compatible with the PAKE |
| 1266 | * algorithm and primitive. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1267 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1268 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1269 | * \retval #PSA_ERROR_BAD_STATE |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1270 | * The operation state is not valid, or |
| 1271 | * the library has not been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1272 | * It is implementation-dependent whether a failure to initialize |
| 1273 | * results in this error code. |
| 1274 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1275 | psa_status_t psa_pake_setup(psa_pake_operation_t *operation, |
| 1276 | const psa_pake_cipher_suite_t *cipher_suite); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1277 | |
| 1278 | /** Set the password for a password-authenticated key exchange from key ID. |
| 1279 | * |
| 1280 | * Call this function when the password, or a value derived from the password, |
Janos Follath | 52f9efa | 2021-05-27 08:40:16 +0100 | [diff] [blame] | 1281 | * is already present in the key store. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1282 | * |
| 1283 | * \param[in,out] operation The operation object to set the password for. It |
| 1284 | * must have been set up by psa_pake_setup() and |
| 1285 | * not yet in use (neither psa_pake_output() nor |
| 1286 | * psa_pake_input() has been called yet). It must |
| 1287 | * be on operation for which the password hasn't |
Janos Follath | 52f9efa | 2021-05-27 08:40:16 +0100 | [diff] [blame] | 1288 | * been set yet (psa_pake_set_password_key() |
Janos Follath | 559f05e | 2021-05-26 15:44:30 +0100 | [diff] [blame] | 1289 | * hasn't been called yet). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1290 | * \param password Identifier of the key holding the password or a |
| 1291 | * value derived from the password (eg. by a |
| 1292 | * memory-hard function). It must remain valid |
| 1293 | * until the operation terminates. It must be of |
| 1294 | * type #PSA_KEY_TYPE_PASSWORD or |
| 1295 | * #PSA_KEY_TYPE_PASSWORD_HASH. It has to allow |
| 1296 | * the usage #PSA_KEY_USAGE_DERIVE. |
| 1297 | * |
| 1298 | * \retval #PSA_SUCCESS |
| 1299 | * Success. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1300 | * \retval #PSA_ERROR_INVALID_HANDLE |
Neil Armstrong | 71cae61 | 2022-05-20 11:00:49 +0200 | [diff] [blame] | 1301 | * \p password is not a valid key identifier. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1302 | * \retval #PSA_ERROR_NOT_PERMITTED |
Neil Armstrong | 71cae61 | 2022-05-20 11:00:49 +0200 | [diff] [blame] | 1303 | * The key does not have the #PSA_KEY_USAGE_DERIVE flag, or it does not |
| 1304 | * permit the \p operation's algorithm. |
| 1305 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 1306 | * The key type for \p password is not #PSA_KEY_TYPE_PASSWORD or |
| 1307 | * #PSA_KEY_TYPE_PASSWORD_HASH, or \p password is not compatible with |
| 1308 | * the \p operation's cipher suite. |
| 1309 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1310 | * The key type or key size of \p password is not supported with the |
| 1311 | * \p operation's cipher suite. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1312 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1313 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 1314 | * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription |
| 1315 | * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription |
| 1316 | * \retval #PSA_ERROR_DATA_INVALID \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1317 | * \retval #PSA_ERROR_BAD_STATE |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1318 | * The operation state is not valid (it must have been set up.), or |
| 1319 | * the library has not been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1320 | * It is implementation-dependent whether a failure to initialize |
| 1321 | * results in this error code. |
| 1322 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1323 | psa_status_t psa_pake_set_password_key(psa_pake_operation_t *operation, |
| 1324 | mbedtls_svc_key_id_t password); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1325 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1326 | /** Set the user ID for a password-authenticated key exchange. |
| 1327 | * |
| 1328 | * Call this function to set the user ID. For PAKE algorithms that associate a |
| 1329 | * user identifier with each side of the session you need to call |
| 1330 | * psa_pake_set_peer() as well. For PAKE algorithms that associate a single |
| 1331 | * user identifier with the session, call psa_pake_set_user() only. |
| 1332 | * |
| 1333 | * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` |
| 1334 | * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) |
| 1335 | * for more information. |
| 1336 | * |
| 1337 | * \param[in,out] operation The operation object to set the user ID for. It |
| 1338 | * must have been set up by psa_pake_setup() and |
| 1339 | * not yet in use (neither psa_pake_output() nor |
| 1340 | * psa_pake_input() has been called yet). It must |
| 1341 | * be on operation for which the user ID hasn't |
| 1342 | * been set (psa_pake_set_user() hasn't been |
| 1343 | * called yet). |
| 1344 | * \param[in] user_id The user ID to authenticate with. |
| 1345 | * \param user_id_len Size of the \p user_id buffer in bytes. |
| 1346 | * |
| 1347 | * \retval #PSA_SUCCESS |
| 1348 | * Success. |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1349 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Neil Armstrong | 3585168 | 2022-05-20 11:02:37 +0200 | [diff] [blame] | 1350 | * \p user_id is not valid for the \p operation's algorithm and cipher |
| 1351 | * suite. |
| 1352 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1353 | * The value of \p user_id is not supported by the implementation. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1354 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 1355 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1356 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1357 | * \retval #PSA_ERROR_BAD_STATE |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1358 | * The operation state is not valid, or |
| 1359 | * the library has not been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1360 | * It is implementation-dependent whether a failure to initialize |
| 1361 | * results in this error code. |
| 1362 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1363 | psa_status_t psa_pake_set_user(psa_pake_operation_t *operation, |
| 1364 | const uint8_t *user_id, |
| 1365 | size_t user_id_len); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1366 | |
| 1367 | /** Set the peer ID for a password-authenticated key exchange. |
| 1368 | * |
| 1369 | * Call this function in addition to psa_pake_set_user() for PAKE algorithms |
| 1370 | * that associate a user identifier with each side of the session. For PAKE |
| 1371 | * algorithms that associate a single user identifier with the session, call |
| 1372 | * psa_pake_set_user() only. |
| 1373 | * |
| 1374 | * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` |
| 1375 | * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) |
| 1376 | * for more information. |
| 1377 | * |
| 1378 | * \param[in,out] operation The operation object to set the peer ID for. It |
| 1379 | * must have been set up by psa_pake_setup() and |
| 1380 | * not yet in use (neither psa_pake_output() nor |
| 1381 | * psa_pake_input() has been called yet). It must |
| 1382 | * be on operation for which the peer ID hasn't |
| 1383 | * been set (psa_pake_set_peer() hasn't been |
| 1384 | * called yet). |
| 1385 | * \param[in] peer_id The peer's ID to authenticate. |
| 1386 | * \param peer_id_len Size of the \p peer_id buffer in bytes. |
| 1387 | * |
| 1388 | * \retval #PSA_SUCCESS |
| 1389 | * Success. |
Neil Armstrong | 16ff788 | 2022-05-20 11:04:20 +0200 | [diff] [blame] | 1390 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Andrzej Kurek | 00b54e6 | 2023-05-06 09:38:57 -0400 | [diff] [blame] | 1391 | * \p peer_id is not valid for the \p operation's algorithm and cipher |
Neil Armstrong | 16ff788 | 2022-05-20 11:04:20 +0200 | [diff] [blame] | 1392 | * suite. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1393 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1394 | * The algorithm doesn't associate a second identity with the session. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1395 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 1396 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1397 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1398 | * \retval #PSA_ERROR_BAD_STATE |
Neil Armstrong | 0d24575 | 2022-05-20 11:35:40 +0200 | [diff] [blame] | 1399 | * Calling psa_pake_set_peer() is invalid with the \p operation's |
| 1400 | * algorithm, the operation state is not valid, or the library has not |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1401 | * been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1402 | * It is implementation-dependent whether a failure to initialize |
| 1403 | * results in this error code. |
| 1404 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1405 | psa_status_t psa_pake_set_peer(psa_pake_operation_t *operation, |
| 1406 | const uint8_t *peer_id, |
| 1407 | size_t peer_id_len); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1408 | |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 1409 | /** Set the application role for a password-authenticated key exchange. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1410 | * |
| 1411 | * Not all PAKE algorithms need to differentiate the communicating entities. |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 1412 | * It is optional to call this function for PAKEs that don't require a role |
| 1413 | * to be specified. For such PAKEs the application role parameter is ignored, |
| 1414 | * or #PSA_PAKE_ROLE_NONE can be passed as \c role. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1415 | * |
| 1416 | * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` |
| 1417 | * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) |
| 1418 | * for more information. |
| 1419 | * |
Neil Armstrong | ef15751 | 2022-05-25 11:49:45 +0200 | [diff] [blame] | 1420 | * \param[in,out] operation The operation object to specify the |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 1421 | * application's role for. It must have been set up |
| 1422 | * by psa_pake_setup() and not yet in use (neither |
| 1423 | * psa_pake_output() nor psa_pake_input() has been |
| 1424 | * called yet). It must be on operation for which |
| 1425 | * the application's role hasn't been specified |
| 1426 | * (psa_pake_set_role() hasn't been called yet). |
| 1427 | * \param role A value of type ::psa_pake_role_t indicating the |
| 1428 | * application's role in the PAKE the algorithm |
| 1429 | * that is being set up. For more information see |
| 1430 | * the documentation of \c PSA_PAKE_ROLE_XXX |
| 1431 | * constants. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1432 | * |
| 1433 | * \retval #PSA_SUCCESS |
| 1434 | * Success. |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 1435 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 1436 | * The \p role is not a valid PAKE role in the \p operation’s algorithm. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1437 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Neil Armstrong | 2a6dd9c | 2022-05-20 11:17:10 +0200 | [diff] [blame] | 1438 | * The \p role for this algorithm is not supported or is not valid. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1439 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1440 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1441 | * \retval #PSA_ERROR_BAD_STATE |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1442 | * The operation state is not valid, or |
| 1443 | * the library has not been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1444 | * It is implementation-dependent whether a failure to initialize |
| 1445 | * results in this error code. |
| 1446 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1447 | psa_status_t psa_pake_set_role(psa_pake_operation_t *operation, |
| 1448 | psa_pake_role_t role); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1449 | |
| 1450 | /** Get output for a step of a password-authenticated key exchange. |
| 1451 | * |
| 1452 | * Depending on the algorithm being executed, you might need to call this |
| 1453 | * function several times or you might not need to call this at all. |
| 1454 | * |
| 1455 | * The exact sequence of calls to perform a password-authenticated key |
| 1456 | * exchange depends on the algorithm in use. Refer to the documentation of |
| 1457 | * individual PAKE algorithm types (`PSA_ALG_XXX` values of type |
| 1458 | * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more |
| 1459 | * information. |
| 1460 | * |
| 1461 | * If this function returns an error status, the operation enters an error |
| 1462 | * state and must be aborted by calling psa_pake_abort(). |
| 1463 | * |
| 1464 | * \param[in,out] operation Active PAKE operation. |
| 1465 | * \param step The step of the algorithm for which the output is |
| 1466 | * requested. |
| 1467 | * \param[out] output Buffer where the output is to be written in the |
| 1468 | * format appropriate for this \p step. Refer to |
| 1469 | * the documentation of the individual |
| 1470 | * \c PSA_PAKE_STEP_XXX constants for more |
| 1471 | * information. |
| 1472 | * \param output_size Size of the \p output buffer in bytes. This must |
Andrzej Kurek | 00b54e6 | 2023-05-06 09:38:57 -0400 | [diff] [blame] | 1473 | * be at least #PSA_PAKE_OUTPUT_SIZE(\c alg, \c |
| 1474 | * primitive, \p output_step) where \c alg and |
Neil Armstrong | 7bc71e9 | 2022-05-20 10:36:14 +0200 | [diff] [blame] | 1475 | * \p primitive are the PAKE algorithm and primitive |
| 1476 | * in the operation's cipher suite, and \p step is |
| 1477 | * the output step. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1478 | * |
| 1479 | * \param[out] output_length On success, the number of bytes of the returned |
| 1480 | * output. |
| 1481 | * |
| 1482 | * \retval #PSA_SUCCESS |
| 1483 | * Success. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1484 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 1485 | * The size of the \p output buffer is too small. |
Neil Armstrong | 664077e | 2022-05-20 11:24:41 +0200 | [diff] [blame] | 1486 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 1487 | * \p step is not compatible with the operation's algorithm. |
| 1488 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1489 | * \p step is not supported with the operation's algorithm. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1490 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription |
| 1491 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 1492 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1493 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 1494 | * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription |
| 1495 | * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription |
| 1496 | * \retval #PSA_ERROR_DATA_INVALID \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1497 | * \retval #PSA_ERROR_BAD_STATE |
Neil Armstrong | e9b4581 | 2022-05-20 11:39:09 +0200 | [diff] [blame] | 1498 | * The operation state is not valid (it must be active, and fully set |
| 1499 | * up, and this call must conform to the algorithm's requirements |
| 1500 | * for ordering of input and output steps), or |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1501 | * the library has not been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1502 | * It is implementation-dependent whether a failure to initialize |
| 1503 | * results in this error code. |
| 1504 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1505 | psa_status_t psa_pake_output(psa_pake_operation_t *operation, |
| 1506 | psa_pake_step_t step, |
| 1507 | uint8_t *output, |
| 1508 | size_t output_size, |
| 1509 | size_t *output_length); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1510 | |
| 1511 | /** Provide input for a step of a password-authenticated key exchange. |
| 1512 | * |
| 1513 | * Depending on the algorithm being executed, you might need to call this |
| 1514 | * function several times or you might not need to call this at all. |
| 1515 | * |
| 1516 | * The exact sequence of calls to perform a password-authenticated key |
| 1517 | * exchange depends on the algorithm in use. Refer to the documentation of |
| 1518 | * individual PAKE algorithm types (`PSA_ALG_XXX` values of type |
| 1519 | * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more |
| 1520 | * information. |
| 1521 | * |
| 1522 | * If this function returns an error status, the operation enters an error |
| 1523 | * state and must be aborted by calling psa_pake_abort(). |
| 1524 | * |
| 1525 | * \param[in,out] operation Active PAKE operation. |
| 1526 | * \param step The step for which the input is provided. |
Neil Armstrong | 799106b | 2022-05-20 10:18:53 +0200 | [diff] [blame] | 1527 | * \param[in] input Buffer containing the input in the format |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1528 | * appropriate for this \p step. Refer to the |
| 1529 | * documentation of the individual |
| 1530 | * \c PSA_PAKE_STEP_XXX constants for more |
| 1531 | * information. |
Neil Armstrong | 799106b | 2022-05-20 10:18:53 +0200 | [diff] [blame] | 1532 | * \param input_length Size of the \p input buffer in bytes. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1533 | * |
| 1534 | * \retval #PSA_SUCCESS |
| 1535 | * Success. |
Neil Armstrong | 407b27b | 2022-05-20 11:28:23 +0200 | [diff] [blame] | 1536 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
| 1537 | * The verification fails for a #PSA_PAKE_STEP_ZK_PROOF input step. |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1538 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Andrzej Kurek | 00b54e6 | 2023-05-06 09:38:57 -0400 | [diff] [blame] | 1539 | * \p input_length is not compatible with the \p operation’s algorithm, |
| 1540 | * or the \p input is not valid for the \p operation's algorithm, |
| 1541 | * cipher suite or \p step. |
Neil Armstrong | 407b27b | 2022-05-20 11:28:23 +0200 | [diff] [blame] | 1542 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1543 | * \p step p is not supported with the \p operation's algorithm, or the |
| 1544 | * \p input is not supported for the \p operation's algorithm, cipher |
| 1545 | * suite or \p step. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1546 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 1547 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1548 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 1549 | * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription |
| 1550 | * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription |
| 1551 | * \retval #PSA_ERROR_DATA_INVALID \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1552 | * \retval #PSA_ERROR_BAD_STATE |
Neil Armstrong | e9b4581 | 2022-05-20 11:39:09 +0200 | [diff] [blame] | 1553 | * The operation state is not valid (it must be active, and fully set |
| 1554 | * up, and this call must conform to the algorithm's requirements |
| 1555 | * for ordering of input and output steps), or |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1556 | * the library has not been previously initialized by psa_crypto_init(). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1557 | * It is implementation-dependent whether a failure to initialize |
| 1558 | * results in this error code. |
| 1559 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1560 | psa_status_t psa_pake_input(psa_pake_operation_t *operation, |
| 1561 | psa_pake_step_t step, |
| 1562 | const uint8_t *input, |
| 1563 | size_t input_length); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1564 | |
| 1565 | /** Get implicitly confirmed shared secret from a PAKE. |
| 1566 | * |
| 1567 | * At this point there is a cryptographic guarantee that only the authenticated |
| 1568 | * party who used the same password is able to compute the key. But there is no |
Janos Follath | a46e28f | 2021-06-03 13:07:03 +0100 | [diff] [blame] | 1569 | * guarantee that the peer is the party it claims to be and was able to do so. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1570 | * |
Janos Follath | b4db90f | 2021-06-03 13:17:09 +0100 | [diff] [blame] | 1571 | * That is, the authentication is only implicit. Since the peer is not |
| 1572 | * authenticated yet, no action should be taken yet that assumes that the peer |
| 1573 | * is who it claims to be. For example, do not access restricted files on the |
| 1574 | * peer's behalf until an explicit authentication has succeeded. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1575 | * |
| 1576 | * This function can be called after the key exchange phase of the operation |
| 1577 | * has completed. It imports the shared secret output of the PAKE into the |
| 1578 | * provided derivation operation. The input step |
| 1579 | * #PSA_KEY_DERIVATION_INPUT_SECRET is used when placing the shared key |
| 1580 | * material in the key derivation operation. |
| 1581 | * |
| 1582 | * The exact sequence of calls to perform a password-authenticated key |
| 1583 | * exchange depends on the algorithm in use. Refer to the documentation of |
| 1584 | * individual PAKE algorithm types (`PSA_ALG_XXX` values of type |
| 1585 | * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more |
| 1586 | * information. |
| 1587 | * |
| 1588 | * When this function returns successfully, \p operation becomes inactive. |
| 1589 | * If this function returns an error status, both \p operation |
Andrzej Kurek | 3bedb5b | 2022-02-17 14:39:00 -0500 | [diff] [blame] | 1590 | * and \c key_derivation operations enter an error state and must be aborted by |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1591 | * calling psa_pake_abort() and psa_key_derivation_abort() respectively. |
| 1592 | * |
| 1593 | * \param[in,out] operation Active PAKE operation. |
| 1594 | * \param[out] output A key derivation operation that is ready |
| 1595 | * for an input step of type |
| 1596 | * #PSA_KEY_DERIVATION_INPUT_SECRET. |
| 1597 | * |
| 1598 | * \retval #PSA_SUCCESS |
| 1599 | * Success. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1600 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Neil Armstrong | 97d74b8 | 2022-05-20 11:30:31 +0200 | [diff] [blame] | 1601 | * #PSA_KEY_DERIVATION_INPUT_SECRET is not compatible with the |
| 1602 | * algorithm in the \p output key derivation operation. |
| 1603 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1604 | * Input from a PAKE is not supported by the algorithm in the \p output |
| 1605 | * key derivation operation. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1606 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 1607 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1608 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 1609 | * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription |
| 1610 | * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription |
| 1611 | * \retval #PSA_ERROR_DATA_INVALID \emptydescription |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1612 | * \retval #PSA_ERROR_BAD_STATE |
Andrzej Kurek | f7c1f74 | 2022-02-03 11:30:54 -0500 | [diff] [blame] | 1613 | * The PAKE operation state is not valid (it must be active, but beyond |
| 1614 | * that validity is specific to the algorithm), or |
| 1615 | * the library has not been previously initialized by psa_crypto_init(), |
| 1616 | * or the state of \p output is not valid for |
| 1617 | * the #PSA_KEY_DERIVATION_INPUT_SECRET step. This can happen if the |
| 1618 | * step is out of order or the application has done this step already |
| 1619 | * and it may not be repeated. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1620 | * It is implementation-dependent whether a failure to initialize |
| 1621 | * results in this error code. |
| 1622 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1623 | psa_status_t psa_pake_get_implicit_key(psa_pake_operation_t *operation, |
| 1624 | psa_key_derivation_operation_t *output); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1625 | |
Neil Armstrong | 0c8ef93 | 2022-05-20 10:23:51 +0200 | [diff] [blame] | 1626 | /** Abort a PAKE operation. |
| 1627 | * |
| 1628 | * Aborting an operation frees all associated resources except for the \c |
| 1629 | * operation structure itself. Once aborted, the operation object can be reused |
| 1630 | * for another operation by calling psa_pake_setup() again. |
| 1631 | * |
| 1632 | * This function may be called at any time after the operation |
| 1633 | * object has been initialized as described in #psa_pake_operation_t. |
| 1634 | * |
| 1635 | * In particular, calling psa_pake_abort() after the operation has been |
| 1636 | * terminated by a call to psa_pake_abort() or psa_pake_get_implicit_key() |
| 1637 | * is safe and has no effect. |
| 1638 | * |
| 1639 | * \param[in,out] operation The operation to abort. |
| 1640 | * |
| 1641 | * \retval #PSA_SUCCESS |
Neil Armstrong | 59fa8ee | 2022-05-20 11:31:04 +0200 | [diff] [blame] | 1642 | * Success. |
Gilles Peskine | ed73355 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 1643 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 1644 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Neil Armstrong | 0c8ef93 | 2022-05-20 10:23:51 +0200 | [diff] [blame] | 1645 | * \retval #PSA_ERROR_BAD_STATE |
| 1646 | * The library has not been previously initialized by psa_crypto_init(). |
| 1647 | * It is implementation-dependent whether a failure to initialize |
| 1648 | * results in this error code. |
| 1649 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1650 | psa_status_t psa_pake_abort(psa_pake_operation_t *operation); |
Neil Armstrong | 0c8ef93 | 2022-05-20 10:23:51 +0200 | [diff] [blame] | 1651 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1652 | /**@}*/ |
| 1653 | |
| 1654 | /** A sufficient output buffer size for psa_pake_output(). |
| 1655 | * |
| 1656 | * If the size of the output buffer is at least this large, it is guaranteed |
| 1657 | * that psa_pake_output() will not fail due to an insufficient output buffer |
| 1658 | * size. The actual size of the output might be smaller in any given call. |
| 1659 | * |
| 1660 | * See also #PSA_PAKE_OUTPUT_MAX_SIZE |
| 1661 | * |
Janos Follath | 46c0237 | 2021-06-08 15:22:51 +0100 | [diff] [blame] | 1662 | * \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1663 | * #PSA_ALG_IS_PAKE(\p alg) is true). |
| 1664 | * \param primitive A primitive of type ::psa_pake_primitive_t that is |
| 1665 | * compatible with algorithm \p alg. |
| 1666 | * \param output_step A value of type ::psa_pake_step_t that is valid for the |
| 1667 | * algorithm \p alg. |
| 1668 | * \return A sufficient output buffer size for the specified |
Neil Armstrong | cd974d5 | 2022-05-20 10:30:12 +0200 | [diff] [blame] | 1669 | * PAKE algorithm, primitive, and output step. If the |
| 1670 | * PAKE algorithm, primitive, or output step is not |
| 1671 | * recognized, or the parameters are incompatible, |
| 1672 | * return 0. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1673 | */ |
Neil Armstrong | 7aaa34a | 2022-06-08 14:05:02 +0200 | [diff] [blame] | 1674 | #define PSA_PAKE_OUTPUT_SIZE(alg, primitive, output_step) \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1675 | (alg == PSA_ALG_JPAKE && \ |
| 1676 | primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \ |
| 1677 | PSA_ECC_FAMILY_SECP_R1, 256) ? \ |
| 1678 | ( \ |
| 1679 | output_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \ |
| 1680 | output_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \ |
| 1681 | 32 \ |
| 1682 | ) : \ |
| 1683 | 0) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1684 | |
| 1685 | /** A sufficient input buffer size for psa_pake_input(). |
| 1686 | * |
Janos Follath | b4db90f | 2021-06-03 13:17:09 +0100 | [diff] [blame] | 1687 | * The value returned by this macro is guaranteed to be large enough for any |
| 1688 | * valid input to psa_pake_input() in an operation with the specified |
| 1689 | * parameters. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1690 | * |
| 1691 | * See also #PSA_PAKE_INPUT_MAX_SIZE |
| 1692 | * |
Janos Follath | 46c0237 | 2021-06-08 15:22:51 +0100 | [diff] [blame] | 1693 | * \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1694 | * #PSA_ALG_IS_PAKE(\p alg) is true). |
| 1695 | * \param primitive A primitive of type ::psa_pake_primitive_t that is |
| 1696 | * compatible with algorithm \p alg. |
Janos Follath | ec83eb6 | 2021-05-27 08:41:59 +0100 | [diff] [blame] | 1697 | * \param input_step A value of type ::psa_pake_step_t that is valid for the |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1698 | * algorithm \p alg. |
Janos Follath | 38d29db | 2021-06-03 13:14:42 +0100 | [diff] [blame] | 1699 | * \return A sufficient input buffer size for the specified |
| 1700 | * input, cipher suite and algorithm. If the cipher suite, |
| 1701 | * the input type or PAKE algorithm is not recognized, or |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1702 | * the parameters are incompatible, return 0. |
| 1703 | */ |
Neil Armstrong | 7aaa34a | 2022-06-08 14:05:02 +0200 | [diff] [blame] | 1704 | #define PSA_PAKE_INPUT_SIZE(alg, primitive, input_step) \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1705 | (alg == PSA_ALG_JPAKE && \ |
| 1706 | primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \ |
| 1707 | PSA_ECC_FAMILY_SECP_R1, 256) ? \ |
| 1708 | ( \ |
| 1709 | input_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \ |
| 1710 | input_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \ |
| 1711 | 32 \ |
| 1712 | ) : \ |
| 1713 | 0) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1714 | |
Neil Armstrong | 2056ce5 | 2022-05-25 11:38:15 +0200 | [diff] [blame] | 1715 | /** Output buffer size for psa_pake_output() for any of the supported PAKE |
| 1716 | * algorithm and primitive suites and output step. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1717 | * |
| 1718 | * This macro must expand to a compile-time constant integer. |
| 1719 | * |
Przemek Stekiel | 7921a03 | 2023-04-14 14:29:57 +0200 | [diff] [blame] | 1720 | * The value of this macro must be at least as large as the largest value |
| 1721 | * returned by PSA_PAKE_OUTPUT_SIZE() |
| 1722 | * |
Andrzej Kurek | 00b54e6 | 2023-05-06 09:38:57 -0400 | [diff] [blame] | 1723 | * See also #PSA_PAKE_OUTPUT_SIZE(\p alg, \p primitive, \p output_step). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1724 | */ |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 1725 | #define PSA_PAKE_OUTPUT_MAX_SIZE 65 |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1726 | |
Neil Armstrong | 2056ce5 | 2022-05-25 11:38:15 +0200 | [diff] [blame] | 1727 | /** Input buffer size for psa_pake_input() for any of the supported PAKE |
| 1728 | * algorithm and primitive suites and input step. |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1729 | * |
| 1730 | * This macro must expand to a compile-time constant integer. |
| 1731 | * |
Przemek Stekiel | 7921a03 | 2023-04-14 14:29:57 +0200 | [diff] [blame] | 1732 | * The value of this macro must be at least as large as the largest value |
| 1733 | * returned by PSA_PAKE_INPUT_SIZE() |
| 1734 | * |
Andrzej Kurek | 00b54e6 | 2023-05-06 09:38:57 -0400 | [diff] [blame] | 1735 | * See also #PSA_PAKE_INPUT_SIZE(\p alg, \p primitive, \p output_step). |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1736 | */ |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 1737 | #define PSA_PAKE_INPUT_MAX_SIZE 65 |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1738 | |
Neil Armstrong | fb99302 | 2022-05-20 10:08:58 +0200 | [diff] [blame] | 1739 | /** Returns a suitable initializer for a PAKE cipher suite object of type |
| 1740 | * psa_pake_cipher_suite_t. |
| 1741 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1742 | #define PSA_PAKE_CIPHER_SUITE_INIT { PSA_ALG_NONE, 0, 0, 0, PSA_ALG_NONE } |
Neil Armstrong | fb99302 | 2022-05-20 10:08:58 +0200 | [diff] [blame] | 1743 | |
Neil Armstrong | 0151c55 | 2022-05-20 10:13:53 +0200 | [diff] [blame] | 1744 | /** Returns a suitable initializer for a PAKE operation object of type |
| 1745 | * psa_pake_operation_t. |
| 1746 | */ |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 1747 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 1748 | #define PSA_PAKE_OPERATION_INIT { 0 } |
| 1749 | #else |
Przemek Stekiel | 656b259 | 2023-03-22 13:15:33 +0100 | [diff] [blame] | 1750 | #define PSA_PAKE_OPERATION_INIT { 0, PSA_ALG_NONE, 0, PSA_PAKE_OPERATION_STAGE_SETUP, \ |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 1751 | { 0 }, { { 0 } } } |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 1752 | #endif |
Neil Armstrong | 0151c55 | 2022-05-20 10:13:53 +0200 | [diff] [blame] | 1753 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1754 | struct psa_pake_cipher_suite_s { |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1755 | psa_algorithm_t algorithm; |
| 1756 | psa_pake_primitive_type_t type; |
| 1757 | psa_pake_family_t family; |
| 1758 | uint16_t bits; |
| 1759 | psa_algorithm_t hash; |
| 1760 | }; |
| 1761 | |
| 1762 | static inline psa_algorithm_t psa_pake_cs_get_algorithm( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1763 | const psa_pake_cipher_suite_t *cipher_suite) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1764 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1765 | return cipher_suite->algorithm; |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | static inline void psa_pake_cs_set_algorithm( |
| 1769 | psa_pake_cipher_suite_t *cipher_suite, |
| 1770 | psa_algorithm_t algorithm) |
| 1771 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1772 | if (!PSA_ALG_IS_PAKE(algorithm)) { |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1773 | cipher_suite->algorithm = 0; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1774 | } else { |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1775 | cipher_suite->algorithm = algorithm; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1776 | } |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | static inline psa_pake_primitive_t psa_pake_cs_get_primitive( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1780 | const psa_pake_cipher_suite_t *cipher_suite) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1781 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1782 | return PSA_PAKE_PRIMITIVE(cipher_suite->type, cipher_suite->family, |
| 1783 | cipher_suite->bits); |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | static inline void psa_pake_cs_set_primitive( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1787 | psa_pake_cipher_suite_t *cipher_suite, |
| 1788 | psa_pake_primitive_t primitive) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1789 | { |
| 1790 | cipher_suite->type = (psa_pake_primitive_type_t) (primitive >> 24); |
| 1791 | cipher_suite->family = (psa_pake_family_t) (0xFF & (primitive >> 16)); |
| 1792 | cipher_suite->bits = (uint16_t) (0xFFFF & primitive); |
| 1793 | } |
| 1794 | |
Neil Armstrong | ff9cac7 | 2022-05-20 10:25:15 +0200 | [diff] [blame] | 1795 | static inline psa_pake_family_t psa_pake_cs_get_family( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1796 | const psa_pake_cipher_suite_t *cipher_suite) |
Neil Armstrong | ff9cac7 | 2022-05-20 10:25:15 +0200 | [diff] [blame] | 1797 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1798 | return cipher_suite->family; |
Neil Armstrong | ff9cac7 | 2022-05-20 10:25:15 +0200 | [diff] [blame] | 1799 | } |
| 1800 | |
Neil Armstrong | d5a4825 | 2022-05-20 10:26:36 +0200 | [diff] [blame] | 1801 | static inline uint16_t psa_pake_cs_get_bits( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1802 | const psa_pake_cipher_suite_t *cipher_suite) |
Neil Armstrong | d5a4825 | 2022-05-20 10:26:36 +0200 | [diff] [blame] | 1803 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1804 | return cipher_suite->bits; |
Neil Armstrong | d5a4825 | 2022-05-20 10:26:36 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1807 | static inline psa_algorithm_t psa_pake_cs_get_hash( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1808 | const psa_pake_cipher_suite_t *cipher_suite) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1809 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1810 | return cipher_suite->hash; |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1811 | } |
| 1812 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1813 | static inline void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite, |
| 1814 | psa_algorithm_t hash) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1815 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1816 | if (!PSA_ALG_IS_HASH(hash)) { |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1817 | cipher_suite->hash = 0; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1818 | } else { |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1819 | cipher_suite->hash = hash; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1820 | } |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1823 | struct psa_crypto_driver_pake_inputs_s { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1824 | uint8_t *MBEDTLS_PRIVATE(password); |
Przemek Stekiel | 152ae07 | 2022-11-17 13:24:36 +0100 | [diff] [blame] | 1825 | size_t MBEDTLS_PRIVATE(password_len); |
Przemek Stekiel | 26c909d | 2023-02-28 12:34:03 +0100 | [diff] [blame] | 1826 | uint8_t *MBEDTLS_PRIVATE(user); |
| 1827 | size_t MBEDTLS_PRIVATE(user_len); |
| 1828 | uint8_t *MBEDTLS_PRIVATE(peer); |
| 1829 | size_t MBEDTLS_PRIVATE(peer_len); |
Przemek Stekiel | 9dd2440 | 2023-01-26 15:06:09 +0100 | [diff] [blame] | 1830 | psa_key_attributes_t MBEDTLS_PRIVATE(attributes); |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1831 | psa_pake_cipher_suite_t MBEDTLS_PRIVATE(cipher_suite); |
| 1832 | }; |
| 1833 | |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 1834 | typedef enum psa_crypto_driver_pake_step { |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 1835 | PSA_JPAKE_STEP_INVALID = 0, /* Invalid step */ |
| 1836 | PSA_JPAKE_X1_STEP_KEY_SHARE = 1, /* Round 1: input/output key share (for ephemeral private key X1).*/ |
| 1837 | PSA_JPAKE_X1_STEP_ZK_PUBLIC = 2, /* Round 1: input/output Schnorr NIZKP public key for the X1 key */ |
| 1838 | PSA_JPAKE_X1_STEP_ZK_PROOF = 3, /* Round 1: input/output Schnorr NIZKP proof for the X1 key */ |
| 1839 | PSA_JPAKE_X2_STEP_KEY_SHARE = 4, /* Round 1: input/output key share (for ephemeral private key X2).*/ |
| 1840 | PSA_JPAKE_X2_STEP_ZK_PUBLIC = 5, /* Round 1: input/output Schnorr NIZKP public key for the X2 key */ |
| 1841 | PSA_JPAKE_X2_STEP_ZK_PROOF = 6, /* Round 1: input/output Schnorr NIZKP proof for the X2 key */ |
| 1842 | PSA_JPAKE_X2S_STEP_KEY_SHARE = 7, /* Round 2: output X2S key (our key) */ |
| 1843 | PSA_JPAKE_X2S_STEP_ZK_PUBLIC = 8, /* Round 2: output Schnorr NIZKP public key for the X2S key (our key) */ |
| 1844 | PSA_JPAKE_X2S_STEP_ZK_PROOF = 9, /* Round 2: output Schnorr NIZKP proof for the X2S key (our key) */ |
| 1845 | PSA_JPAKE_X4S_STEP_KEY_SHARE = 10, /* Round 2: input X4S key (from peer) */ |
| 1846 | PSA_JPAKE_X4S_STEP_ZK_PUBLIC = 11, /* Round 2: input Schnorr NIZKP public key for the X4S key (from peer) */ |
| 1847 | PSA_JPAKE_X4S_STEP_ZK_PROOF = 12 /* Round 2: input Schnorr NIZKP proof for the X4S key (from peer) */ |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 1848 | } psa_crypto_driver_pake_step_t; |
Przemek Stekiel | 5798003 | 2023-01-09 15:07:26 +0100 | [diff] [blame] | 1849 | |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1850 | typedef enum psa_jpake_round { |
David Horstmann | 5da9560 | 2023-06-08 15:37:12 +0100 | [diff] [blame] | 1851 | PSA_JPAKE_FIRST = 0, |
| 1852 | PSA_JPAKE_SECOND = 1, |
| 1853 | PSA_JPAKE_FINISHED = 2 |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1854 | } psa_jpake_round_t; |
| 1855 | |
| 1856 | typedef enum psa_jpake_io_mode { |
David Horstmann | 5da9560 | 2023-06-08 15:37:12 +0100 | [diff] [blame] | 1857 | PSA_JPAKE_INPUT = 0, |
| 1858 | PSA_JPAKE_OUTPUT = 1 |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1859 | } psa_jpake_io_mode_t; |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 1860 | |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 1861 | struct psa_jpake_computation_stage_s { |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1862 | /* The J-PAKE round we are currently on */ |
| 1863 | psa_jpake_round_t MBEDTLS_PRIVATE(round); |
| 1864 | /* The 'mode' we are currently in (inputting or outputting) */ |
David Horstmann | 024e5c5 | 2023-06-14 15:48:21 +0100 | [diff] [blame] | 1865 | psa_jpake_io_mode_t MBEDTLS_PRIVATE(io_mode); |
David Horstmann | 279d227 | 2023-06-14 17:13:56 +0100 | [diff] [blame] | 1866 | /* The number of completed inputs so far this round */ |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1867 | uint8_t MBEDTLS_PRIVATE(inputs); |
David Horstmann | 279d227 | 2023-06-14 17:13:56 +0100 | [diff] [blame] | 1868 | /* The number of completed outputs so far this round */ |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1869 | uint8_t MBEDTLS_PRIVATE(outputs); |
| 1870 | /* The next expected step (KEY_SHARE, ZK_PUBLIC or ZK_PROOF) */ |
| 1871 | psa_pake_step_t MBEDTLS_PRIVATE(step); |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 1872 | }; |
| 1873 | |
David Horstmann | 5dbe17d | 2023-06-27 10:30:28 +0100 | [diff] [blame] | 1874 | #define PSA_JPAKE_EXPECTED_INPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \ |
| 1875 | ((round) == PSA_JPAKE_FIRST ? 2 : 1)) |
| 1876 | #define PSA_JPAKE_EXPECTED_OUTPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \ |
| 1877 | ((round) == PSA_JPAKE_FIRST ? 2 : 1)) |
David Horstmann | e7f21e6 | 2023-05-12 18:17:21 +0100 | [diff] [blame] | 1878 | |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1879 | struct psa_pake_operation_s { |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 1880 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 1881 | mbedtls_psa_client_handle_t handle; |
| 1882 | #else |
Przemek Stekiel | d91bcb7 | 2022-11-22 14:00:51 +0100 | [diff] [blame] | 1883 | /** Unique ID indicating which driver got assigned to do the |
| 1884 | * operation. Since driver contexts are driver-specific, swapping |
| 1885 | * drivers halfway through the operation is not supported. |
| 1886 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 1887 | * ID value zero means the context is not valid or not assigned to |
| 1888 | * any driver (i.e. none of the driver contexts are active). */ |
| 1889 | unsigned int MBEDTLS_PRIVATE(id); |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 1890 | /* Algorithm of the PAKE operation */ |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 1891 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
Przemek Stekiel | 656b259 | 2023-03-22 13:15:33 +0100 | [diff] [blame] | 1892 | /* A primitive of type compatible with algorithm */ |
| 1893 | psa_pake_primitive_t MBEDTLS_PRIVATE(primitive); |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 1894 | /* Stage of the PAKE operation: waiting for the setup, collecting inputs |
| 1895 | * or computing. */ |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1896 | uint8_t MBEDTLS_PRIVATE(stage); |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 1897 | /* Holds computation stage of the PAKE algorithms. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1898 | union { |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 1899 | uint8_t MBEDTLS_PRIVATE(dummy); |
Przemek Stekiel | 4aa9940 | 2023-02-27 13:00:57 +0100 | [diff] [blame] | 1900 | #if defined(PSA_WANT_ALG_JPAKE) |
Przemek Stekiel | dde6a91 | 2023-01-26 08:46:37 +0100 | [diff] [blame] | 1901 | psa_jpake_computation_stage_t MBEDTLS_PRIVATE(jpake); |
Neil Armstrong | 35269d9 | 2022-05-25 11:26:31 +0200 | [diff] [blame] | 1902 | #endif |
Przemek Stekiel | dde6a91 | 2023-01-26 08:46:37 +0100 | [diff] [blame] | 1903 | } MBEDTLS_PRIVATE(computation_stage); |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1904 | union { |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1905 | psa_driver_pake_context_t MBEDTLS_PRIVATE(ctx); |
Przemek Stekiel | ac067d7 | 2023-01-26 16:31:03 +0100 | [diff] [blame] | 1906 | psa_crypto_driver_pake_inputs_t MBEDTLS_PRIVATE(inputs); |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 1907 | } MBEDTLS_PRIVATE(data); |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 1908 | #endif |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1909 | }; |
| 1910 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1911 | static inline struct psa_pake_cipher_suite_s psa_pake_cipher_suite_init(void) |
Neil Armstrong | 5ff6a7f | 2022-05-20 10:12:01 +0200 | [diff] [blame] | 1912 | { |
| 1913 | const struct psa_pake_cipher_suite_s v = PSA_PAKE_CIPHER_SUITE_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1914 | return v; |
Neil Armstrong | 5ff6a7f | 2022-05-20 10:12:01 +0200 | [diff] [blame] | 1915 | } |
| 1916 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1917 | static inline struct psa_pake_operation_s psa_pake_operation_init(void) |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1918 | { |
| 1919 | const struct psa_pake_operation_s v = PSA_PAKE_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1920 | return v; |
Janos Follath | 702cf09 | 2021-05-26 12:58:23 +0100 | [diff] [blame] | 1921 | } |
| 1922 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 1923 | #ifdef __cplusplus |
| 1924 | } |
| 1925 | #endif |
| 1926 | |
| 1927 | #endif /* PSA_CRYPTO_EXTRA_H */ |