blob: 0e7898983baea1d5ade9db67bf8391714ca25acd [file] [log] [blame]
Gilles Peskinee59236f2018-01-27 23:32:46 +01001/**
2 * \file psa/crypto_extra.h
3 *
4 * \brief PSA cryptography module: Mbed TLS vendor extensions
Gilles Peskine07c91f52018-06-28 18:02:53 +02005 *
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 Peskinee59236f2018-01-27 23:32:46 +010010 */
11/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020012 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +000013 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskinee59236f2018-01-27 23:32:46 +010014 */
15
16#ifndef PSA_CRYPTO_EXTRA_H
17#define PSA_CRYPTO_EXTRA_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020018#include "mbedtls/private_access.h"
Gilles Peskinee59236f2018-01-27 23:32:46 +010019
Gilles Peskine09c02ee2021-11-25 20:30:47 +010020#include "crypto_types.h"
Gilles Peskine7a894f22019-11-26 16:06:46 +010021#include "crypto_compat.h"
22
Gilles Peskinee59236f2018-01-27 23:32:46 +010023#ifdef __cplusplus
24extern "C" {
25#endif
26
Netanel Gonen2bcd3122018-11-19 11:53:02 +020027/* UID for secure storage seed */
avolinski0d2c2662018-11-21 17:31:07 +020028#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
Netanel Gonen2bcd3122018-11-19 11:53:02 +020029
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020030/* See mbedtls_config.h for definition */
Steven Cooreman863470a2021-02-15 14:03:19 +010031#if !defined(MBEDTLS_PSA_KEY_SLOT_COUNT)
32#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
Steven Cooreman1f968fd2021-02-15 14:00:24 +010033#endif
Jaeden Amero5e6d24c2019-02-21 10:41:29 +000034
Valerio Settice849212024-08-29 15:02:47 +020035/* 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 Peskine96f0b3b2019-05-10 19:33:38 +020045/** \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 Peskinef25c9ec2019-05-22 11:45:59 +020064 * if it is necessary to support a protocol for which it has been
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020065 * verified that the usage of the key with multiple algorithms
66 * is safe.
67 */
68static inline void psa_set_key_enrollment_algorithm(
69 psa_key_attributes_t *attributes,
70 psa_algorithm_t alg2)
71{
Gilles Peskine2f107ae2024-02-28 01:26:46 +010072 attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2) = alg2;
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020073}
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 */
81static inline psa_algorithm_t psa_get_key_enrollment_algorithm(
82 const psa_key_attributes_t *attributes)
83{
Gilles Peskine2f107ae2024-02-28 01:26:46 +010084 return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2);
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020085}
86
Gilles Peskinec8000c02019-08-02 20:15:51 +020087#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 Hessecc207bc2021-09-28 21:06:08 +0200107 * Mbed TLS currently does not return this error.
Gilles Peskinec8000c02019-08-02 20:15:51 +0200108 * \retval #PSA_ERROR_INVALID_ARGUMENT
109 * The key is not located in a secure element.
110 */
111psa_status_t psa_get_key_slot_number(
112 const psa_key_attributes_t *attributes,
Gilles Peskine449bd832023-01-11 14:50:10 +0100113 psa_key_slot_number_t *slot_number);
Gilles Peskinec8000c02019-08-02 20:15:51 +0200114
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 */
138static inline void psa_set_key_slot_number(
139 psa_key_attributes_t *attributes,
Gilles Peskine449bd832023-01-11 14:50:10 +0100140 psa_key_slot_number_t slot_number)
Gilles Peskinec8000c02019-08-02 20:15:51 +0200141{
Gilles Peskine972539c2024-02-28 01:49:45 +0100142 attributes->MBEDTLS_PRIVATE(has_slot_number) = 1;
Gilles Peskine2f107ae2024-02-28 01:26:46 +0100143 attributes->MBEDTLS_PRIVATE(slot_number) = slot_number;
Gilles Peskinec8000c02019-08-02 20:15:51 +0200144}
145
Gilles Peskine5fe5e272019-08-02 20:30:01 +0200146/** 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 */
152static inline void psa_clear_key_slot_number(
Gilles Peskine449bd832023-01-11 14:50:10 +0100153 psa_key_attributes_t *attributes)
Gilles Peskine5fe5e272019-08-02 20:30:01 +0200154{
Gilles Peskine972539c2024-02-28 01:49:45 +0100155 attributes->MBEDTLS_PRIVATE(has_slot_number) = 0;
Gilles Peskine5fe5e272019-08-02 20:30:01 +0200156}
157
Gilles Peskined7729582019-08-05 15:55:54 +0200158/** 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 Peskined72ad732024-06-13 16:06:45 +0200167 * - 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 Peskined7729582019-08-05 15:55:54 +0200175 *
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 Peskine3efcebb2019-10-01 14:18:35 +0200184 * \retval #PSA_ERROR_NOT_SUPPORTED
185 * The secure element driver for the specified lifetime does not
186 * support registering a key.
Gilles Peskined7729582019-08-05 15:55:54 +0200187 * \retval #PSA_ERROR_INVALID_ARGUMENT
Ronald Crond3b458c2021-03-31 17:51:29 +0200188 * The identifier in \p attributes is invalid, namely the identifier is
Andrzej Kurekf7c1f742022-02-03 11:30:54 -0500189 * not in the user range, or
Gilles Peskined7729582019-08-05 15:55:54 +0200190 * \p attributes specifies a lifetime which is not located
Andrzej Kurekf7c1f742022-02-03 11:30:54 -0500191 * in a secure element, or no slot number is specified in \p attributes,
Gilles Peskined7729582019-08-05 15:55:54 +0200192 * 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 Peskineed733552023-02-14 19:21:09 +0100195 * \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 Peskined7729582019-08-05 15:55:54 +0200201 * \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 */
206psa_status_t mbedtls_psa_register_se_key(
207 const psa_key_attributes_t *attributes);
208
Gilles Peskinec8000c02019-08-02 20:15:51 +0200209#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
210
Gilles Peskine96f0b3b2019-05-10 19:33:38 +0200211/**@}*/
212
Gilles Peskinee59236f2018-01-27 23:32:46 +0100213/**
214 * \brief Library deinitialization.
215 *
216 * This function clears all data associated with the PSA layer,
217 * including the whole key store.
Ryan Everett16abd592024-01-24 17:37:46 +0000218 * 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 Peskinee59236f2018-01-27 23:32:46 +0100220 *
221 * This is an Mbed TLS extension.
222 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100223void mbedtls_psa_crypto_free(void);
Gilles Peskinee59236f2018-01-27 23:32:46 +0100224
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200225/** \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 Hessecc207bc2021-09-28 21:06:08 +0200229 * of Mbed TLS and may change arbitrarily from version to version.
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200230 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100231typedef struct mbedtls_psa_stats_s {
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200232 /** Number of slots containing key material for a volatile key. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200233 size_t MBEDTLS_PRIVATE(volatile_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200234 /** Number of slots containing key material for a key which is in
235 * internal persistent storage. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200236 size_t MBEDTLS_PRIVATE(persistent_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200237 /** Number of slots containing a reference to a key in a
238 * secure element. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200239 size_t MBEDTLS_PRIVATE(external_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200240 /** Number of slots which are occupied, but do not contain
241 * key material yet. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200242 size_t MBEDTLS_PRIVATE(half_filled_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200243 /** Number of slots that contain cache data. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200244 size_t MBEDTLS_PRIVATE(cache_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200245 /** Number of slots that are not used for anything. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200246 size_t MBEDTLS_PRIVATE(empty_slots);
Ronald Cron1ad1eee2020-11-15 14:21:04 +0100247 /** Number of slots that are locked. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200248 size_t MBEDTLS_PRIVATE(locked_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200249 /** Largest key id value among open keys in internal persistent storage. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200250 psa_key_id_t MBEDTLS_PRIVATE(max_open_internal_key_id);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200251 /** Largest key id value among open keys in secure elements. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200252 psa_key_id_t MBEDTLS_PRIVATE(max_open_external_key_id);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200253} mbedtls_psa_stats_t;
254
255/** \brief Get statistics about
256 * resource consumption related to the PSA keystore.
257 *
Fredrik Hessecc207bc2021-09-28 21:06:08 +0200258 * \note When Mbed TLS is built as part of a service, with isolation
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200259 * between the application and the keystore, the service may or
260 * may not expose this function.
261 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100262void mbedtls_psa_get_stats(mbedtls_psa_stats_t *stats);
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200263
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200264/**
Gilles Peskineee2ffd32018-11-16 11:02:49 +0100265 * \brief Inject an initial entropy seed for the random generator into
266 * secure storage.
Gilles Peskine0338ded2018-11-15 18:19:27 +0100267 *
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 Peskineee2ffd32018-11-16 11:02:49 +0100283 *
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 Gonen2bcd3122018-11-19 11:53:02 +0200287 *
288 * \warning This function **can** fail! Callers MUST check the return status.
289 *
Gilles Peskine0338ded2018-11-15 18:19:27 +0100290 * \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 Gonen2bcd3122018-11-19 11:53:02 +0200301 *
Gilles Peskine0338ded2018-11-15 18:19:27 +0100302 * This is an Mbed TLS extension.
303 *
Netanel Gonen1d7195f2018-11-22 16:24:48 +0200304 * \note This function is only available on the following platforms:
Gilles Peskinee3dbdd82019-02-25 11:04:06 +0100305 * * 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 Peskine0cfaed12018-11-22 17:11:45 +0200308 * * In a client-server integration of PSA Cryptography, on the client side,
Netanel Gonen1d7195f2018-11-22 16:24:48 +0200309 * if the server supports this feature.
Netanel Gonen596e65e2018-11-22 18:41:43 +0200310 * \param[in] seed Buffer containing the seed value to inject.
Gilles Peskine0cfaed12018-11-22 17:11:45 +0200311 * \param[in] seed_size Size of the \p seed buffer.
Netanel Gonen596e65e2018-11-22 18:41:43 +0200312 * The size of the seed in bytes must be greater
Chris Jones3848e312021-03-11 16:17:59 +0000313 * 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 Gonen596e65e2018-11-22 18:41:43 +0200317 * It must be less or equal to
318 * #MBEDTLS_ENTROPY_MAX_SEED_SIZE.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200319 *
320 * \retval #PSA_SUCCESS
Gilles Peskine0338ded2018-11-15 18:19:27 +0100321 * 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 Gonen2bcd3122018-11-19 11:53:02 +0200325 * \retval #PSA_ERROR_INVALID_ARGUMENT
Gilles Peskineee2ffd32018-11-16 11:02:49 +0100326 * \p seed_size is out of range.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200327 * \retval #PSA_ERROR_STORAGE_FAILURE
Gilles Peskine0338ded2018-11-15 18:19:27 +0100328 * There was a failure reading or writing from storage.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200329 * \retval #PSA_ERROR_NOT_PERMITTED
Gilles Peskine0338ded2018-11-15 18:19:27 +0100330 * The library has already been initialized. It is no longer
331 * possible to call this function.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200332 */
Jaeden Ameroc7529c92019-08-19 11:08:04 +0100333psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200334 size_t seed_size);
335
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200336/** \addtogroup crypto_types
337 * @{
338 */
339
Gilles Peskinea1302192019-05-16 13:58:24 +0200340/** 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 Peskine449bd832023-01-11 14:50:10 +0100347#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t) 0x4002)
Gilles Peskinea1302192019-05-16 13:58:24 +0200348
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 Case8b0ecbc2021-12-20 21:14:10 -0800356 * Deterministic DSA key derivation with psa_generate_derived_key follows
Gilles Peskinea1302192019-05-16 13:58:24 +0200357 * 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 Peskine449bd832023-01-11 14:50:10 +0100365#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t) 0x7002)
Gilles Peskinea1302192019-05-16 13:58:24 +0200366
Tom Cosgrovece7f18c2022-07-28 05:50:56 +0100367/** Whether a key type is a DSA key (pair or public-only). */
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200368#define PSA_KEY_TYPE_IS_DSA(type) \
Gilles Peskinec93b80c2019-05-16 19:39:54 +0200369 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200370
Gilles Peskine449bd832023-01-11 14:50:10 +0100371#define PSA_ALG_DSA_BASE ((psa_algorithm_t) 0x06000400)
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200372/** 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 Peskine449bd832023-01-11 14:50:10 +0100388#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t) 0x06000500)
Gilles Peskine972630e2019-11-29 11:55:48 +0100389#define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200390/** 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 Peskine6d400852021-02-24 21:39:52 +0100419#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 Peskinee38ab1a2019-05-16 13:51:50 +0200422
423/**@}*/
424
Gilles Peskine24f10f82019-05-16 12:18:32 +0200425/** \addtogroup attributes
426 * @{
427 */
428
Przemek Stekiel251e86a2023-02-17 14:30:50 +0100429/** PAKE operation stages. */
Przemek Stekiel1c3cfb42023-01-26 10:35:02 +0100430#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 Peskinedcaefae2019-05-16 12:55:35 +0200433
Gilles Peskine24f10f82019-05-16 12:18:32 +0200434/**@}*/
435
Gilles Peskine5055b232019-12-12 17:49:31 +0100436
Gilles Peskineb8af2282020-11-13 18:00:34 +0100437/** \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 Peskineb663a602020-11-18 15:27:37 +0100448 * \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 Peskineb8af2282020-11-13 18:00:34 +0100456 * \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 Peskinee995b9b2020-11-30 12:08:00 +0100466 * 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 Peskineb8af2282020-11-13 18:00:34 +0100477 * \retval #PSA_ERROR_HARDWARE_FAILURE
Gilles Peskinee995b9b2020-11-30 12:08:00 +0100478 * A failure of the random generator hardware that isn't covered
479 * by #PSA_ERROR_INSUFFICIENT_ENTROPY.
Gilles Peskineb8af2282020-11-13 18:00:34 +0100480 */
481psa_status_t mbedtls_psa_external_get_random(
482 mbedtls_psa_external_random_context_t *context,
Gilles Peskine449bd832023-01-11 14:50:10 +0100483 uint8_t *output, size_t output_size, size_t *output_length);
Gilles Peskineb8af2282020-11-13 18:00:34 +0100484#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
485
486/**@}*/
487
Steven Cooreman6801f082021-02-19 17:21:22 +0100488/** \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 Peskine543909d2024-06-20 22:10:08 +0200500 * This value is part of the library's API since changing it would invalidate
Steven Cooreman6801f082021-02-19 17:21:22 +0100501 * the values of built-in key identifiers in applications.
502 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100503#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t) 0x7fff0000)
Steven Cooreman6801f082021-02-19 17:21:22 +0100504
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 Peskine449bd832023-01-11 14:50:10 +0100510#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t) 0x7fffefff)
Steven Cooreman6801f082021-02-19 17:21:22 +0100511
512/** A slot number identifying a key in a driver.
513 *
514 * Values of this type are used to identify built-in keys.
515 */
516typedef 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 Peskine449bd832023-01-11 14:50:10 +0100528static inline int psa_key_id_is_builtin(psa_key_id_t key_id)
Steven Cooreman6801f082021-02-19 17:21:22 +0100529{
Gilles Peskine449bd832023-01-11 14:50:10 +0100530 return (key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN) &&
531 (key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX);
Steven Cooreman6801f082021-02-19 17:21:22 +0100532}
533
Steven Cooremanb938b0b2021-04-06 13:08:42 +0200534/** Platform function to obtain the location and slot number of a built-in key.
Steven Cooreman6801f082021-02-19 17:21:22 +0100535 *
536 * An application-specific implementation of this function must be provided if
Steven Cooreman203bcbb2021-03-18 17:17:40 +0100537 * #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided
Steven Cooreman6801f082021-02-19 17:21:22 +0100538 * as part of a platform's system image.
539 *
Steven Cooremanc8b95342021-03-18 20:48:06 +0100540 * #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from
Steven Cooreman6801f082021-02-19 17:21:22 +0100541 * #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 Cooremanc8b95342021-03-18 20:48:06 +0100548 * \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 Cooreman31e27af2021-04-14 10:32:05 +0200553 * 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 Cooremanc8b95342021-03-18 20:48:06 +0100559 * \param[out] slot_number On success, the slot number known to the driver
560 * registered at the lifetime location reported
Steven Cooremanb938b0b2021-04-06 13:08:42 +0200561 * through \p lifetime which corresponds to the
Steven Cooreman6801f082021-02-19 17:21:22 +0100562 * 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 Cooreman203bcbb2021-03-18 17:17:40 +0100572 * \return (any other error)
Steven Cooreman6801f082021-02-19 17:21:22 +0100573 * 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 */
578psa_status_t mbedtls_psa_platform_get_builtin_key(
Steven Cooremanc8b95342021-03-18 20:48:06 +0100579 mbedtls_svc_key_id_t key_id,
580 psa_key_lifetime_t *lifetime,
Gilles Peskine449bd832023-01-11 14:50:10 +0100581 psa_drv_slot_number_t *slot_number);
Steven Cooreman6801f082021-02-19 17:21:22 +0100582#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
583
584/** @} */
585
Valerio Setti05b38352025-02-21 14:40:51 +0100586/** \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
Valerio Setti79a98bd2025-02-21 15:00:11 +0100598/** Check if PSA is capable of handling the specified hash algorithm.
Valerio Setti05b38352025-02-21 14:40:51 +0100599 *
Valerio Setti79a98bd2025-02-21 15:00:11 +0100600 * This means that PSA core was built with the corresponding PSA_WANT_ALG_xxx
601 * set and that psa_crypto_init has already been called.
Valerio Setti05b38352025-02-21 14:40:51 +0100602 *
Gilles Peskine6e1b6632025-09-11 18:34:29 +0200603 * \note When using the built-in version of the PSA core (i.e.
604 * #MBEDTLS_PSA_CRYPTO_C is set), for now, this function only checks
605 * the state of the driver subsystem, not the algorithm.
606 * This might be improved in the future.
Valerio Setti05b38352025-02-21 14:40:51 +0100607 *
Valerio Setti79a98bd2025-02-21 15:00:11 +0100608 * \param hash_alg The hash algorithm.
609 *
610 * \return 1 if the PSA can handle \p hash_alg, 0 otherwise.
Valerio Setti05b38352025-02-21 14:40:51 +0100611 */
612int psa_can_do_hash(psa_algorithm_t hash_alg);
613
Gilles Peskine3aee15b2025-09-11 17:04:44 +0200614/**
615 * Tell if PSA is ready for this cipher.
616 *
Gilles Peskine6e1b6632025-09-11 18:34:29 +0200617 * \note When using the built-in version of the PSA core (i.e.
618 * #MBEDTLS_PSA_CRYPTO_C is set), for now, this function only checks
619 * the state of the driver subsystem, not the key type and algorithm.
620 * This might be improved in the future.
Gilles Peskine3aee15b2025-09-11 17:04:44 +0200621 *
Gilles Peskine6e1b6632025-09-11 18:34:29 +0200622 * \param key_type The key type.
623 * \param cipher_alg The cipher algorithm.
Gilles Peskine3aee15b2025-09-11 17:04:44 +0200624 *
Gilles Peskine9a5444a2025-09-12 11:24:12 +0200625 * \return 1 if the PSA can handle \p cipher_alg, 0 otherwise.
Gilles Peskine3aee15b2025-09-11 17:04:44 +0200626 */
627int psa_can_do_cipher(psa_key_type_t key_type, psa_algorithm_t cipher_alg);
628
Valerio Setti05b38352025-02-21 14:40:51 +0100629/**@}*/
630
Janos Follath702cf092021-05-26 12:58:23 +0100631/** \addtogroup crypto_types
632 * @{
633 */
634
Gilles Peskine449bd832023-01-11 14:50:10 +0100635#define PSA_ALG_CATEGORY_PAKE ((psa_algorithm_t) 0x0a000000)
Janos Follath702cf092021-05-26 12:58:23 +0100636
637/** Whether the specified algorithm is a password-authenticated key exchange.
638 *
639 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
640 *
641 * \return 1 if \p alg is a password-authenticated key exchange (PAKE)
642 * algorithm, 0 otherwise.
643 * This macro may return either 0 or 1 if \p alg is not a supported
644 * algorithm identifier.
645 */
646#define PSA_ALG_IS_PAKE(alg) \
647 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_PAKE)
648
649/** The Password-authenticated key exchange by juggling (J-PAKE) algorithm.
650 *
651 * This is J-PAKE as defined by RFC 8236, instantiated with the following
652 * parameters:
653 *
654 * - The group can be either an elliptic curve or defined over a finite field.
655 * - Schnorr NIZK proof as defined by RFC 8235 and using the same group as the
656 * J-PAKE algorithm.
Janos Follath46c02372021-06-08 15:22:51 +0100657 * - A cryptographic hash function.
Janos Follath702cf092021-05-26 12:58:23 +0100658 *
Janos Follath46c02372021-06-08 15:22:51 +0100659 * To select these parameters and set up the cipher suite, call these functions
660 * in any order:
Janos Follathb384ec12021-06-03 14:48:51 +0100661 *
662 * \code
663 * psa_pake_cs_set_algorithm(cipher_suite, PSA_ALG_JPAKE);
664 * psa_pake_cs_set_primitive(cipher_suite,
665 * PSA_PAKE_PRIMITIVE(type, family, bits));
666 * psa_pake_cs_set_hash(cipher_suite, hash);
667 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100668 *
669 * For more information on how to set a specific curve or field, refer to the
670 * documentation of the individual \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.
671 *
672 * After initializing a J-PAKE operation, call
Janos Follathb384ec12021-06-03 14:48:51 +0100673 *
674 * \code
675 * psa_pake_setup(operation, cipher_suite);
676 * psa_pake_set_user(operation, ...);
677 * psa_pake_set_peer(operation, ...);
678 * psa_pake_set_password_key(operation, ...);
679 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100680 *
Neil Armstrong16145372022-05-20 10:42:36 +0200681 * The password is provided as a key. This can be the password text itself,
682 * in an agreed character encoding, or some value derived from the password
683 * as required by a higher level protocol.
Janos Follath702cf092021-05-26 12:58:23 +0100684 *
Neil Armstrong16145372022-05-20 10:42:36 +0200685 * (The implementation converts the key material to a number as described in
Janos Follath702cf092021-05-26 12:58:23 +0100686 * Section 2.3.8 of _SEC 1: Elliptic Curve Cryptography_
687 * (https://www.secg.org/sec1-v2.pdf), before reducing it modulo \c q. Here
688 * \c q is order of the group defined by the primitive set in the cipher suite.
Neil Armstrong5892aa62022-05-27 09:44:47 +0200689 * The \c psa_pake_set_password_key() function returns an error if the result
Janos Follath702cf092021-05-26 12:58:23 +0100690 * of the reduction is 0.)
691 *
692 * The key exchange flow for J-PAKE is as follows:
693 * -# To get the first round data that needs to be sent to the peer, call
Janos Follathb384ec12021-06-03 14:48:51 +0100694 * \code
695 * // Get g1
696 * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
697 * // Get the ZKP public key for x1
698 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
699 * // Get the ZKP proof for x1
700 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
701 * // Get g2
702 * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
703 * // Get the ZKP public key for x2
704 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
705 * // Get the ZKP proof for x2
706 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
707 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100708 * -# To provide the first round data received from the peer to the operation,
709 * call
Janos Follathb384ec12021-06-03 14:48:51 +0100710 * \code
711 * // Set g3
712 * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
713 * // Set the ZKP public key for x3
714 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
715 * // Set the ZKP proof for x3
716 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
717 * // Set g4
718 * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
719 * // Set the ZKP public key for x4
720 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
721 * // Set the ZKP proof for x4
722 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
723 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100724 * -# To get the second round data that needs to be sent to the peer, call
Janos Follathb384ec12021-06-03 14:48:51 +0100725 * \code
726 * // Get A
727 * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
728 * // Get ZKP public key for x2*s
729 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
730 * // Get ZKP proof for x2*s
731 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
732 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100733 * -# To provide the second round data received from the peer to the operation,
734 * call
Janos Follathb384ec12021-06-03 14:48:51 +0100735 * \code
736 * // Set B
737 * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
738 * // Set ZKP public key for x4*s
739 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
740 * // Set ZKP proof for x4*s
741 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
742 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100743 * -# To access the shared secret call
Janos Follathb384ec12021-06-03 14:48:51 +0100744 * \code
745 * // Get Ka=Kb=K
746 * psa_pake_get_implicit_key()
747 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100748 *
749 * For more information consult the documentation of the individual
750 * \c PSA_PAKE_STEP_XXX constants.
751 *
752 * At this point there is a cryptographic guarantee that only the authenticated
753 * party who used the same password is able to compute the key. But there is no
Janos Follatha46e28f2021-06-03 13:07:03 +0100754 * guarantee that the peer is the party it claims to be and was able to do so.
Janos Follath702cf092021-05-26 12:58:23 +0100755 *
756 * That is, the authentication is only implicit (the peer is not authenticated
757 * at this point, and no action should be taken that assume that they are - like
758 * for example accessing restricted files).
759 *
760 * To make the authentication explicit there are various methods, see Section 5
761 * of RFC 8236 for two examples.
762 *
763 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100764#define PSA_ALG_JPAKE ((psa_algorithm_t) 0x0a000100)
Janos Follath702cf092021-05-26 12:58:23 +0100765
766/** @} */
767
768/** \defgroup pake Password-authenticated key exchange (PAKE)
Janos Follath7d69b3a2021-05-26 13:10:56 +0100769 *
770 * This is a proposed PAKE interface for the PSA Crypto API. It is not part of
771 * the official PSA Crypto API yet.
772 *
773 * \note The content of this section is not part of the stable API and ABI
Fredrik Hessecc207bc2021-09-28 21:06:08 +0200774 * of Mbed TLS and may change arbitrarily from version to version.
Janos Follath7d69b3a2021-05-26 13:10:56 +0100775 * Same holds for the corresponding macros #PSA_ALG_CATEGORY_PAKE and
776 * #PSA_ALG_JPAKE.
Janos Follath702cf092021-05-26 12:58:23 +0100777 * @{
778 */
779
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200780/** \brief Encoding of the application role of PAKE
Janos Follath702cf092021-05-26 12:58:23 +0100781 *
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200782 * Encodes the application's role in the algorithm is being executed. For more
783 * information see the documentation of individual \c PSA_PAKE_ROLE_XXX
784 * constants.
Janos Follath702cf092021-05-26 12:58:23 +0100785 */
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200786typedef uint8_t psa_pake_role_t;
Janos Follath702cf092021-05-26 12:58:23 +0100787
788/** Encoding of input and output indicators for PAKE.
789 *
790 * Some PAKE algorithms need to exchange more data than just a single key share.
791 * This type is for encoding additional input and output data for such
792 * algorithms.
793 */
794typedef uint8_t psa_pake_step_t;
795
796/** Encoding of the type of the PAKE's primitive.
797 *
798 * Values defined by this standard will never be in the range 0x80-0xff.
799 * Vendors who define additional types must use an encoding in this range.
800 *
801 * For more information see the documentation of individual
802 * \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.
803 */
804typedef uint8_t psa_pake_primitive_type_t;
805
806/** \brief Encoding of the family of the primitive associated with the PAKE.
807 *
808 * For more information see the documentation of individual
809 * \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.
810 */
811typedef uint8_t psa_pake_family_t;
812
813/** \brief Encoding of the primitive associated with the PAKE.
814 *
815 * For more information see the documentation of the #PSA_PAKE_PRIMITIVE macro.
816 */
817typedef uint32_t psa_pake_primitive_t;
818
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200819/** A value to indicate no role in a PAKE algorithm.
820 * This value can be used in a call to psa_pake_set_role() for symmetric PAKE
821 * algorithms which do not assign roles.
822 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100823#define PSA_PAKE_ROLE_NONE ((psa_pake_role_t) 0x00)
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200824
Janos Follath702cf092021-05-26 12:58:23 +0100825/** The first peer in a balanced PAKE.
826 *
827 * Although balanced PAKE algorithms are symmetric, some of them needs an
828 * ordering of peers for the transcript calculations. If the algorithm does not
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200829 * need this, both #PSA_PAKE_ROLE_FIRST and #PSA_PAKE_ROLE_SECOND are
Janos Follath702cf092021-05-26 12:58:23 +0100830 * accepted.
831 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100832#define PSA_PAKE_ROLE_FIRST ((psa_pake_role_t) 0x01)
Janos Follath702cf092021-05-26 12:58:23 +0100833
834/** The second peer in a balanced PAKE.
835 *
836 * Although balanced PAKE algorithms are symmetric, some of them needs an
837 * ordering of peers for the transcript calculations. If the algorithm does not
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200838 * need this, either #PSA_PAKE_ROLE_FIRST or #PSA_PAKE_ROLE_SECOND are
Janos Follath702cf092021-05-26 12:58:23 +0100839 * accepted.
840 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100841#define PSA_PAKE_ROLE_SECOND ((psa_pake_role_t) 0x02)
Janos Follath702cf092021-05-26 12:58:23 +0100842
843/** The client in an augmented PAKE.
844 *
845 * Augmented PAKE algorithms need to differentiate between client and server.
846 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100847#define PSA_PAKE_ROLE_CLIENT ((psa_pake_role_t) 0x11)
Janos Follath702cf092021-05-26 12:58:23 +0100848
849/** The server in an augmented PAKE.
850 *
851 * Augmented PAKE algorithms need to differentiate between client and server.
852 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100853#define PSA_PAKE_ROLE_SERVER ((psa_pake_role_t) 0x12)
Janos Follath702cf092021-05-26 12:58:23 +0100854
855/** The PAKE primitive type indicating the use of elliptic curves.
856 *
857 * The values of the \c family and \c bits fields of the cipher suite identify a
858 * specific elliptic curve, using the same mapping that is used for ECC
859 * (::psa_ecc_family_t) keys.
860 *
861 * (Here \c family means the value returned by psa_pake_cs_get_family() and
862 * \c bits means the value returned by psa_pake_cs_get_bits().)
863 *
864 * Input and output during the operation can involve group elements and scalar
865 * values:
866 * -# The format for group elements is the same as for public keys on the
867 * specific curve would be. For more information, consult the documentation of
868 * psa_export_public_key().
869 * -# The format for scalars is the same as for private keys on the specific
870 * curve would be. For more information, consult the documentation of
871 * psa_export_key().
872 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100873#define PSA_PAKE_PRIMITIVE_TYPE_ECC ((psa_pake_primitive_type_t) 0x01)
Janos Follath702cf092021-05-26 12:58:23 +0100874
875/** The PAKE primitive type indicating the use of Diffie-Hellman groups.
876 *
877 * The values of the \c family and \c bits fields of the cipher suite identify
878 * a specific Diffie-Hellman group, using the same mapping that is used for
879 * Diffie-Hellman (::psa_dh_family_t) keys.
880 *
881 * (Here \c family means the value returned by psa_pake_cs_get_family() and
882 * \c bits means the value returned by psa_pake_cs_get_bits().)
883 *
884 * Input and output during the operation can involve group elements and scalar
885 * values:
886 * -# The format for group elements is the same as for public keys on the
887 * specific group would be. For more information, consult the documentation of
888 * psa_export_public_key().
889 * -# The format for scalars is the same as for private keys on the specific
890 * group would be. For more information, consult the documentation of
891 * psa_export_key().
892 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100893#define PSA_PAKE_PRIMITIVE_TYPE_DH ((psa_pake_primitive_type_t) 0x02)
Janos Follath702cf092021-05-26 12:58:23 +0100894
895/** Construct a PAKE primitive from type, family and bit-size.
896 *
897 * \param pake_type The type of the primitive
898 * (value of type ::psa_pake_primitive_type_t).
899 * \param pake_family The family of the primitive
900 * (the type and interpretation of this parameter depends
Andrzej Kurek3bedb5b2022-02-17 14:39:00 -0500901 * on \p pake_type, for more information consult the
Janos Follath702cf092021-05-26 12:58:23 +0100902 * documentation of individual ::psa_pake_primitive_type_t
903 * constants).
904 * \param pake_bits The bit-size of the primitive
905 * (Value of type \c size_t. The interpretation
Andrzej Kurek3bedb5b2022-02-17 14:39:00 -0500906 * of this parameter depends on \p pake_family, for more
Janos Follath702cf092021-05-26 12:58:23 +0100907 * information consult the documentation of individual
908 * ::psa_pake_primitive_type_t constants).
909 *
910 * \return The constructed primitive value of type ::psa_pake_primitive_t.
911 * Return 0 if the requested primitive can't be encoded as
912 * ::psa_pake_primitive_t.
913 */
914#define PSA_PAKE_PRIMITIVE(pake_type, pake_family, pake_bits) \
915 ((pake_bits & 0xFFFF) != pake_bits) ? 0 : \
916 ((psa_pake_primitive_t) (((pake_type) << 24 | \
Gilles Peskine449bd832023-01-11 14:50:10 +0100917 (pake_family) << 16) | (pake_bits)))
Janos Follath702cf092021-05-26 12:58:23 +0100918
919/** The key share being sent to or received from the peer.
920 *
921 * The format for both input and output at this step is the same as for public
922 * keys on the group determined by the primitive (::psa_pake_primitive_t) would
923 * be.
924 *
925 * For more information on the format, consult the documentation of
926 * psa_export_public_key().
927 *
928 * For information regarding how the group is determined, consult the
929 * documentation #PSA_PAKE_PRIMITIVE.
930 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100931#define PSA_PAKE_STEP_KEY_SHARE ((psa_pake_step_t) 0x01)
Janos Follath702cf092021-05-26 12:58:23 +0100932
933/** A Schnorr NIZKP public key.
934 *
Janos Follath55dd5dc2021-06-03 15:51:09 +0100935 * This is the ephemeral public key in the Schnorr Non-Interactive
936 * Zero-Knowledge Proof (the value denoted by the letter 'V' in RFC 8235).
937 *
Janos Follath702cf092021-05-26 12:58:23 +0100938 * The format for both input and output at this step is the same as for public
939 * keys on the group determined by the primitive (::psa_pake_primitive_t) would
940 * be.
941 *
942 * For more information on the format, consult the documentation of
943 * psa_export_public_key().
944 *
945 * For information regarding how the group is determined, consult the
946 * documentation #PSA_PAKE_PRIMITIVE.
947 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100948#define PSA_PAKE_STEP_ZK_PUBLIC ((psa_pake_step_t) 0x02)
Janos Follath702cf092021-05-26 12:58:23 +0100949
950/** A Schnorr NIZKP proof.
951 *
Janos Follath55dd5dc2021-06-03 15:51:09 +0100952 * This is the proof in the Schnorr Non-Interactive Zero-Knowledge Proof (the
953 * value denoted by the letter 'r' in RFC 8235).
Janos Follath702cf092021-05-26 12:58:23 +0100954 *
Janos Follath1f013182021-06-08 15:30:48 +0100955 * Both for input and output, the value at this step is an integer less than
956 * the order of the group selected in the cipher suite. The format depends on
957 * the group as well:
Janos Follath702cf092021-05-26 12:58:23 +0100958 *
Janos Follath1f013182021-06-08 15:30:48 +0100959 * - For Montgomery curves, the encoding is little endian.
Janos Follath55dd5dc2021-06-03 15:51:09 +0100960 * - For everything else the encoding is big endian (see Section 2.3.8 of
961 * _SEC 1: Elliptic Curve Cryptography_ at https://www.secg.org/sec1-v2.pdf).
Janos Follath702cf092021-05-26 12:58:23 +0100962 *
Janos Follath1f013182021-06-08 15:30:48 +0100963 * In both cases leading zeroes are allowed as long as the length in bytes does
964 * not exceed the byte length of the group order.
965 *
Janos Follath702cf092021-05-26 12:58:23 +0100966 * For information regarding how the group is determined, consult the
967 * documentation #PSA_PAKE_PRIMITIVE.
968 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100969#define PSA_PAKE_STEP_ZK_PROOF ((psa_pake_step_t) 0x03)
Janos Follath702cf092021-05-26 12:58:23 +0100970
Ronald Crond3324fd2025-06-02 11:14:57 +0200971/**@}*/
972
973/** A sufficient output buffer size for psa_pake_output().
974 *
975 * If the size of the output buffer is at least this large, it is guaranteed
976 * that psa_pake_output() will not fail due to an insufficient output buffer
977 * size. The actual size of the output might be smaller in any given call.
978 *
979 * See also #PSA_PAKE_OUTPUT_MAX_SIZE
980 *
981 * \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that
982 * #PSA_ALG_IS_PAKE(\p alg) is true).
983 * \param primitive A primitive of type ::psa_pake_primitive_t that is
984 * compatible with algorithm \p alg.
985 * \param output_step A value of type ::psa_pake_step_t that is valid for the
986 * algorithm \p alg.
987 * \return A sufficient output buffer size for the specified
988 * PAKE algorithm, primitive, and output step. If the
989 * PAKE algorithm, primitive, or output step is not
990 * recognized, or the parameters are incompatible,
991 * return 0.
992 */
993#define PSA_PAKE_OUTPUT_SIZE(alg, primitive, output_step) \
994 (alg == PSA_ALG_JPAKE && \
995 primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \
996 PSA_ECC_FAMILY_SECP_R1, 256) ? \
997 ( \
998 output_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \
999 output_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \
1000 32 \
1001 ) : \
1002 0)
1003
1004/** A sufficient input buffer size for psa_pake_input().
1005 *
1006 * The value returned by this macro is guaranteed to be large enough for any
1007 * valid input to psa_pake_input() in an operation with the specified
1008 * parameters.
1009 *
1010 * See also #PSA_PAKE_INPUT_MAX_SIZE
1011 *
1012 * \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that
1013 * #PSA_ALG_IS_PAKE(\p alg) is true).
1014 * \param primitive A primitive of type ::psa_pake_primitive_t that is
1015 * compatible with algorithm \p alg.
1016 * \param input_step A value of type ::psa_pake_step_t that is valid for the
1017 * algorithm \p alg.
1018 * \return A sufficient input buffer size for the specified
1019 * input, cipher suite and algorithm. If the cipher suite,
1020 * the input type or PAKE algorithm is not recognized, or
1021 * the parameters are incompatible, return 0.
1022 */
1023#define PSA_PAKE_INPUT_SIZE(alg, primitive, input_step) \
1024 (alg == PSA_ALG_JPAKE && \
1025 primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \
1026 PSA_ECC_FAMILY_SECP_R1, 256) ? \
1027 ( \
1028 input_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \
1029 input_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \
1030 32 \
1031 ) : \
1032 0)
1033
1034/** Output buffer size for psa_pake_output() for any of the supported PAKE
1035 * algorithm and primitive suites and output step.
1036 *
1037 * This macro must expand to a compile-time constant integer.
1038 *
1039 * The value of this macro must be at least as large as the largest value
1040 * returned by PSA_PAKE_OUTPUT_SIZE()
1041 *
1042 * See also #PSA_PAKE_OUTPUT_SIZE(\p alg, \p primitive, \p output_step).
1043 */
1044#define PSA_PAKE_OUTPUT_MAX_SIZE 65
1045
1046/** Input buffer size for psa_pake_input() for any of the supported PAKE
1047 * algorithm and primitive suites and input step.
1048 *
1049 * This macro must expand to a compile-time constant integer.
1050 *
1051 * The value of this macro must be at least as large as the largest value
1052 * returned by PSA_PAKE_INPUT_SIZE()
1053 *
1054 * See also #PSA_PAKE_INPUT_SIZE(\p alg, \p primitive, \p output_step).
1055 */
1056#define PSA_PAKE_INPUT_MAX_SIZE 65
1057
1058/** Returns a suitable initializer for a PAKE cipher suite object of type
1059 * psa_pake_cipher_suite_t.
1060 */
1061#define PSA_PAKE_CIPHER_SUITE_INIT { PSA_ALG_NONE, 0, 0, 0, PSA_ALG_NONE }
1062
1063/** Returns a suitable initializer for a PAKE operation object of type
1064 * psa_pake_operation_t.
1065 */
1066#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
1067#define PSA_PAKE_OPERATION_INIT { 0 }
1068#else
1069#define PSA_PAKE_OPERATION_INIT { 0, PSA_ALG_NONE, 0, PSA_PAKE_OPERATION_STAGE_SETUP, \
1070 { 0 }, { { 0 } } }
1071#endif
1072
1073struct psa_pake_cipher_suite_s {
1074 psa_algorithm_t algorithm;
1075 psa_pake_primitive_type_t type;
1076 psa_pake_family_t family;
1077 uint16_t bits;
1078 psa_algorithm_t hash;
1079};
1080
1081struct psa_crypto_driver_pake_inputs_s {
1082 uint8_t *MBEDTLS_PRIVATE(password);
1083 size_t MBEDTLS_PRIVATE(password_len);
1084 uint8_t *MBEDTLS_PRIVATE(user);
1085 size_t MBEDTLS_PRIVATE(user_len);
1086 uint8_t *MBEDTLS_PRIVATE(peer);
1087 size_t MBEDTLS_PRIVATE(peer_len);
1088 psa_key_attributes_t MBEDTLS_PRIVATE(attributes);
Ronald Cron38190052025-06-02 11:25:41 +02001089 struct psa_pake_cipher_suite_s MBEDTLS_PRIVATE(cipher_suite);
Ronald Crond3324fd2025-06-02 11:14:57 +02001090};
1091
1092typedef enum psa_crypto_driver_pake_step {
1093 PSA_JPAKE_STEP_INVALID = 0, /* Invalid step */
1094 PSA_JPAKE_X1_STEP_KEY_SHARE = 1, /* Round 1: input/output key share (for ephemeral private key X1).*/
1095 PSA_JPAKE_X1_STEP_ZK_PUBLIC = 2, /* Round 1: input/output Schnorr NIZKP public key for the X1 key */
1096 PSA_JPAKE_X1_STEP_ZK_PROOF = 3, /* Round 1: input/output Schnorr NIZKP proof for the X1 key */
1097 PSA_JPAKE_X2_STEP_KEY_SHARE = 4, /* Round 1: input/output key share (for ephemeral private key X2).*/
1098 PSA_JPAKE_X2_STEP_ZK_PUBLIC = 5, /* Round 1: input/output Schnorr NIZKP public key for the X2 key */
1099 PSA_JPAKE_X2_STEP_ZK_PROOF = 6, /* Round 1: input/output Schnorr NIZKP proof for the X2 key */
1100 PSA_JPAKE_X2S_STEP_KEY_SHARE = 7, /* Round 2: output X2S key (our key) */
1101 PSA_JPAKE_X2S_STEP_ZK_PUBLIC = 8, /* Round 2: output Schnorr NIZKP public key for the X2S key (our key) */
1102 PSA_JPAKE_X2S_STEP_ZK_PROOF = 9, /* Round 2: output Schnorr NIZKP proof for the X2S key (our key) */
1103 PSA_JPAKE_X4S_STEP_KEY_SHARE = 10, /* Round 2: input X4S key (from peer) */
1104 PSA_JPAKE_X4S_STEP_ZK_PUBLIC = 11, /* Round 2: input Schnorr NIZKP public key for the X4S key (from peer) */
1105 PSA_JPAKE_X4S_STEP_ZK_PROOF = 12 /* Round 2: input Schnorr NIZKP proof for the X4S key (from peer) */
1106} psa_crypto_driver_pake_step_t;
1107
1108typedef enum psa_jpake_round {
1109 PSA_JPAKE_FIRST = 0,
1110 PSA_JPAKE_SECOND = 1,
1111 PSA_JPAKE_FINISHED = 2
1112} psa_jpake_round_t;
1113
1114typedef enum psa_jpake_io_mode {
1115 PSA_JPAKE_INPUT = 0,
1116 PSA_JPAKE_OUTPUT = 1
1117} psa_jpake_io_mode_t;
1118
1119struct psa_jpake_computation_stage_s {
1120 /* The J-PAKE round we are currently on */
1121 psa_jpake_round_t MBEDTLS_PRIVATE(round);
1122 /* The 'mode' we are currently in (inputting or outputting) */
1123 psa_jpake_io_mode_t MBEDTLS_PRIVATE(io_mode);
1124 /* The number of completed inputs so far this round */
1125 uint8_t MBEDTLS_PRIVATE(inputs);
1126 /* The number of completed outputs so far this round */
1127 uint8_t MBEDTLS_PRIVATE(outputs);
1128 /* The next expected step (KEY_SHARE, ZK_PUBLIC or ZK_PROOF) */
1129 psa_pake_step_t MBEDTLS_PRIVATE(step);
1130};
1131
1132#define PSA_JPAKE_EXPECTED_INPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \
1133 ((round) == PSA_JPAKE_FIRST ? 2 : 1))
1134#define PSA_JPAKE_EXPECTED_OUTPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \
1135 ((round) == PSA_JPAKE_FIRST ? 2 : 1))
1136
1137struct psa_pake_operation_s {
1138#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
1139 mbedtls_psa_client_handle_t handle;
1140#else
1141 /** Unique ID indicating which driver got assigned to do the
1142 * operation. Since driver contexts are driver-specific, swapping
1143 * drivers halfway through the operation is not supported.
1144 * ID values are auto-generated in psa_crypto_driver_wrappers.h
1145 * ID value zero means the context is not valid or not assigned to
1146 * any driver (i.e. none of the driver contexts are active). */
1147 unsigned int MBEDTLS_PRIVATE(id);
1148 /* Algorithm of the PAKE operation */
1149 psa_algorithm_t MBEDTLS_PRIVATE(alg);
1150 /* A primitive of type compatible with algorithm */
1151 psa_pake_primitive_t MBEDTLS_PRIVATE(primitive);
1152 /* Stage of the PAKE operation: waiting for the setup, collecting inputs
1153 * or computing. */
1154 uint8_t MBEDTLS_PRIVATE(stage);
1155 /* Holds computation stage of the PAKE algorithms. */
1156 union {
1157 uint8_t MBEDTLS_PRIVATE(dummy);
1158#if defined(PSA_WANT_ALG_JPAKE)
Ronald Cron38190052025-06-02 11:25:41 +02001159 struct psa_jpake_computation_stage_s MBEDTLS_PRIVATE(jpake);
Ronald Crond3324fd2025-06-02 11:14:57 +02001160#endif
1161 } MBEDTLS_PRIVATE(computation_stage);
1162 union {
1163 psa_driver_pake_context_t MBEDTLS_PRIVATE(ctx);
Ronald Cron38190052025-06-02 11:25:41 +02001164 struct psa_crypto_driver_pake_inputs_s MBEDTLS_PRIVATE(inputs);
Ronald Crond3324fd2025-06-02 11:14:57 +02001165 } MBEDTLS_PRIVATE(data);
1166#endif
1167};
1168
1169/** \addtogroup pake
1170 * @{
1171 */
1172
Shaun Case8b0ecbc2021-12-20 21:14:10 -08001173/** The type of the data structure for PAKE cipher suites.
Janos Follath702cf092021-05-26 12:58:23 +01001174 *
1175 * This is an implementation-defined \c struct. Applications should not
1176 * make any assumptions about the content of this structure.
1177 * Implementation details can change in future versions without notice.
1178 */
1179typedef struct psa_pake_cipher_suite_s psa_pake_cipher_suite_t;
1180
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +02001181/** Return an initial value for a PAKE cipher suite object.
1182 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001183static psa_pake_cipher_suite_t psa_pake_cipher_suite_init(void);
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +02001184
Janos Follath702cf092021-05-26 12:58:23 +01001185/** Retrieve the PAKE algorithm from a PAKE cipher suite.
1186 *
Janos Follath702cf092021-05-26 12:58:23 +01001187 * \param[in] cipher_suite The cipher suite structure to query.
1188 *
1189 * \return The PAKE algorithm stored in the cipher suite structure.
1190 */
1191static psa_algorithm_t psa_pake_cs_get_algorithm(
Gilles Peskine449bd832023-01-11 14:50:10 +01001192 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +01001193
1194/** Declare the PAKE algorithm for the cipher suite.
1195 *
1196 * This function overwrites any PAKE algorithm
1197 * previously set in \p cipher_suite.
1198 *
Janos Follath702cf092021-05-26 12:58:23 +01001199 * \param[out] cipher_suite The cipher suite structure to write to.
1200 * \param algorithm The PAKE algorithm to write.
1201 * (`PSA_ALG_XXX` values of type ::psa_algorithm_t
1202 * such that #PSA_ALG_IS_PAKE(\c alg) is true.)
1203 * If this is 0, the PAKE algorithm in
1204 * \p cipher_suite becomes unspecified.
1205 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001206static void psa_pake_cs_set_algorithm(psa_pake_cipher_suite_t *cipher_suite,
1207 psa_algorithm_t algorithm);
Janos Follath702cf092021-05-26 12:58:23 +01001208
1209/** Retrieve the primitive from a PAKE cipher suite.
1210 *
Janos Follath702cf092021-05-26 12:58:23 +01001211 * \param[in] cipher_suite The cipher suite structure to query.
1212 *
1213 * \return The primitive stored in the cipher suite structure.
1214 */
1215static psa_pake_primitive_t psa_pake_cs_get_primitive(
Gilles Peskine449bd832023-01-11 14:50:10 +01001216 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +01001217
1218/** Declare the primitive for a PAKE cipher suite.
1219 *
1220 * This function overwrites any primitive previously set in \p cipher_suite.
1221 *
Janos Follath702cf092021-05-26 12:58:23 +01001222 * \param[out] cipher_suite The cipher suite structure to write to.
1223 * \param primitive The primitive to write. If this is 0, the
1224 * primitive type in \p cipher_suite becomes
1225 * unspecified.
1226 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001227static void psa_pake_cs_set_primitive(psa_pake_cipher_suite_t *cipher_suite,
1228 psa_pake_primitive_t primitive);
Janos Follath702cf092021-05-26 12:58:23 +01001229
Neil Armstrongff9cac72022-05-20 10:25:15 +02001230/** Retrieve the PAKE family from a PAKE cipher suite.
1231 *
Neil Armstrongff9cac72022-05-20 10:25:15 +02001232 * \param[in] cipher_suite The cipher suite structure to query.
1233 *
1234 * \return The PAKE family stored in the cipher suite structure.
1235 */
1236static psa_pake_family_t psa_pake_cs_get_family(
Gilles Peskine449bd832023-01-11 14:50:10 +01001237 const psa_pake_cipher_suite_t *cipher_suite);
Neil Armstrongff9cac72022-05-20 10:25:15 +02001238
Neil Armstrongd5a48252022-05-20 10:26:36 +02001239/** Retrieve the PAKE primitive bit-size from a PAKE cipher suite.
1240 *
Neil Armstrongd5a48252022-05-20 10:26:36 +02001241 * \param[in] cipher_suite The cipher suite structure to query.
1242 *
1243 * \return The PAKE primitive bit-size stored in the cipher suite structure.
1244 */
1245static uint16_t psa_pake_cs_get_bits(
Gilles Peskine449bd832023-01-11 14:50:10 +01001246 const psa_pake_cipher_suite_t *cipher_suite);
Neil Armstrongd5a48252022-05-20 10:26:36 +02001247
Janos Follath702cf092021-05-26 12:58:23 +01001248/** Retrieve the hash algorithm from a PAKE cipher suite.
1249 *
Janos Follath702cf092021-05-26 12:58:23 +01001250 * \param[in] cipher_suite The cipher suite structure to query.
1251 *
1252 * \return The hash algorithm stored in the cipher suite structure. The return
1253 * value is 0 if the PAKE is not parametrised by a hash algorithm or if
1254 * the hash algorithm is not set.
1255 */
1256static psa_algorithm_t psa_pake_cs_get_hash(
Gilles Peskine449bd832023-01-11 14:50:10 +01001257 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +01001258
1259/** Declare the hash algorithm for a PAKE cipher suite.
1260 *
1261 * This function overwrites any hash algorithm
1262 * previously set in \p cipher_suite.
1263 *
Janos Follath702cf092021-05-26 12:58:23 +01001264 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1265 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1266 * for more information.
1267 *
1268 * \param[out] cipher_suite The cipher suite structure to write to.
1269 * \param hash The hash involved in the cipher suite.
1270 * (`PSA_ALG_XXX` values of type ::psa_algorithm_t
1271 * such that #PSA_ALG_IS_HASH(\c alg) is true.)
1272 * If this is 0, the hash algorithm in
1273 * \p cipher_suite becomes unspecified.
1274 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001275static void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite,
1276 psa_algorithm_t hash);
Janos Follath702cf092021-05-26 12:58:23 +01001277
1278/** The type of the state data structure for PAKE operations.
1279 *
1280 * Before calling any function on a PAKE operation object, the application
1281 * must initialize it by any of the following means:
1282 * - Set the structure to all-bits-zero, for example:
1283 * \code
1284 * psa_pake_operation_t operation;
1285 * memset(&operation, 0, sizeof(operation));
1286 * \endcode
1287 * - Initialize the structure to logical zero values, for example:
1288 * \code
1289 * psa_pake_operation_t operation = {0};
1290 * \endcode
1291 * - Initialize the structure to the initializer #PSA_PAKE_OPERATION_INIT,
1292 * for example:
1293 * \code
1294 * psa_pake_operation_t operation = PSA_PAKE_OPERATION_INIT;
1295 * \endcode
1296 * - Assign the result of the function psa_pake_operation_init()
1297 * to the structure, for example:
1298 * \code
1299 * psa_pake_operation_t operation;
1300 * operation = psa_pake_operation_init();
1301 * \endcode
1302 *
1303 * This is an implementation-defined \c struct. Applications should not
1304 * make any assumptions about the content of this structure.
1305 * Implementation details can change in future versions without notice. */
1306typedef struct psa_pake_operation_s psa_pake_operation_t;
1307
Przemek Stekiel51eac532022-12-07 11:04:51 +01001308/** The type of input values for PAKE operations. */
1309typedef struct psa_crypto_driver_pake_inputs_s psa_crypto_driver_pake_inputs_t;
1310
Przemek Stekielb09c4872023-01-17 12:05:38 +01001311/** The type of computation stage for J-PAKE operations. */
Przemek Stekiele12ed362022-12-21 12:54:46 +01001312typedef struct psa_jpake_computation_stage_s psa_jpake_computation_stage_t;
1313
Tom Cosgrovece7f18c2022-07-28 05:50:56 +01001314/** Return an initial value for a PAKE operation object.
Janos Follath702cf092021-05-26 12:58:23 +01001315 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001316static psa_pake_operation_t psa_pake_operation_init(void);
Janos Follath702cf092021-05-26 12:58:23 +01001317
Przemek Stekielc0e62502023-03-14 11:49:36 +01001318/** Get the length of the password in bytes from given inputs.
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001319 *
1320 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001321 * \param[out] password_len Password length.
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001322 *
1323 * \retval #PSA_SUCCESS
1324 * Success.
1325 * \retval #PSA_ERROR_BAD_STATE
1326 * Password hasn't been set yet.
1327 */
1328psa_status_t psa_crypto_driver_pake_get_password_len(
1329 const psa_crypto_driver_pake_inputs_t *inputs,
1330 size_t *password_len);
1331
1332/** Get the password from given inputs.
1333 *
1334 * \param[in] inputs Operation inputs.
1335 * \param[out] buffer Return buffer for password.
Przemek Stekiel6b648622023-02-19 22:55:33 +01001336 * \param buffer_size Size of the return buffer in bytes.
1337 * \param[out] buffer_length Actual size of the password in bytes.
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001338 *
1339 * \retval #PSA_SUCCESS
1340 * Success.
1341 * \retval #PSA_ERROR_BAD_STATE
1342 * Password hasn't been set yet.
1343 */
1344psa_status_t psa_crypto_driver_pake_get_password(
1345 const psa_crypto_driver_pake_inputs_t *inputs,
1346 uint8_t *buffer, size_t buffer_size, size_t *buffer_length);
1347
Przemek Stekielc0e62502023-03-14 11:49:36 +01001348/** Get the length of the user id in bytes from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001349 *
1350 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001351 * \param[out] user_len User id length.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001352 *
1353 * \retval #PSA_SUCCESS
1354 * Success.
1355 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001356 * User id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001357 */
1358psa_status_t psa_crypto_driver_pake_get_user_len(
1359 const psa_crypto_driver_pake_inputs_t *inputs,
1360 size_t *user_len);
1361
Przemek Stekielc0e62502023-03-14 11:49:36 +01001362/** Get the length of the peer id in bytes from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001363 *
1364 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001365 * \param[out] peer_len Peer id length.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001366 *
1367 * \retval #PSA_SUCCESS
1368 * Success.
1369 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001370 * Peer id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001371 */
1372psa_status_t psa_crypto_driver_pake_get_peer_len(
1373 const psa_crypto_driver_pake_inputs_t *inputs,
1374 size_t *peer_len);
1375
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001376/** Get the user id from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001377 *
1378 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001379 * \param[out] user_id User id.
1380 * \param user_id_size Size of \p user_id in bytes.
1381 * \param[out] user_id_len Size of the user id in bytes.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001382 *
1383 * \retval #PSA_SUCCESS
1384 * Success.
1385 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001386 * User id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001387 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
Przemek Stekielc0e62502023-03-14 11:49:36 +01001388 * The size of the \p user_id is too small.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001389 */
1390psa_status_t psa_crypto_driver_pake_get_user(
1391 const psa_crypto_driver_pake_inputs_t *inputs,
Przemek Stekielc0e62502023-03-14 11:49:36 +01001392 uint8_t *user_id, size_t user_id_size, size_t *user_id_len);
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001393
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001394/** Get the peer id from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001395 *
1396 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001397 * \param[out] peer_id Peer id.
1398 * \param peer_id_size Size of \p peer_id in bytes.
1399 * \param[out] peer_id_length Size of the peer id in bytes.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001400 *
1401 * \retval #PSA_SUCCESS
1402 * Success.
1403 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001404 * Peer id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001405 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
Przemek Stekielc0e62502023-03-14 11:49:36 +01001406 * The size of the \p peer_id is too small.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001407 */
1408psa_status_t psa_crypto_driver_pake_get_peer(
1409 const psa_crypto_driver_pake_inputs_t *inputs,
Przemek Stekielc0e62502023-03-14 11:49:36 +01001410 uint8_t *peer_id, size_t peer_id_size, size_t *peer_id_length);
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001411
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001412/** Get the cipher suite from given inputs.
1413 *
1414 * \param[in] inputs Operation inputs.
1415 * \param[out] cipher_suite Return buffer for role.
1416 *
1417 * \retval #PSA_SUCCESS
1418 * Success.
1419 * \retval #PSA_ERROR_BAD_STATE
1420 * Cipher_suite hasn't been set yet.
1421 */
1422psa_status_t psa_crypto_driver_pake_get_cipher_suite(
1423 const psa_crypto_driver_pake_inputs_t *inputs,
1424 psa_pake_cipher_suite_t *cipher_suite);
1425
Janos Follath702cf092021-05-26 12:58:23 +01001426/** Set the session information for a password-authenticated key exchange.
1427 *
1428 * The sequence of operations to set up a password-authenticated key exchange
1429 * is as follows:
1430 * -# Allocate an operation object which will be passed to all the functions
1431 * listed here.
1432 * -# Initialize the operation object with one of the methods described in the
1433 * documentation for #psa_pake_operation_t, e.g.
1434 * #PSA_PAKE_OPERATION_INIT.
1435 * -# Call psa_pake_setup() to specify the cipher suite.
1436 * -# Call \c psa_pake_set_xxx() functions on the operation to complete the
1437 * setup. The exact sequence of \c psa_pake_set_xxx() functions that needs
1438 * to be called depends on the algorithm in use.
1439 *
1440 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1441 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1442 * for more information.
1443 *
1444 * A typical sequence of calls to perform a password-authenticated key
1445 * exchange:
1446 * -# Call psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to get the
1447 * key share that needs to be sent to the peer.
1448 * -# Call psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to provide
1449 * the key share that was received from the peer.
1450 * -# Depending on the algorithm additional calls to psa_pake_output() and
1451 * psa_pake_input() might be necessary.
1452 * -# Call psa_pake_get_implicit_key() for accessing the shared secret.
1453 *
1454 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1455 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1456 * for more information.
1457 *
1458 * If an error occurs at any step after a call to psa_pake_setup(),
1459 * the operation will need to be reset by a call to psa_pake_abort(). The
1460 * application may call psa_pake_abort() at any time after the operation
1461 * has been initialized.
1462 *
1463 * After a successful call to psa_pake_setup(), the application must
1464 * eventually terminate the operation. The following events terminate an
1465 * operation:
1466 * - A call to psa_pake_abort().
1467 * - A successful call to psa_pake_get_implicit_key().
1468 *
1469 * \param[in,out] operation The operation object to set up. It must have
Janos Follath3293dae2021-06-03 13:21:33 +01001470 * been initialized but not set up yet.
Neil Armstrong47e700e2022-05-20 10:16:41 +02001471 * \param[in] cipher_suite The cipher suite to use. (A cipher suite fully
Janos Follath702cf092021-05-26 12:58:23 +01001472 * characterizes a PAKE algorithm and determines
1473 * the algorithm as well.)
1474 *
1475 * \retval #PSA_SUCCESS
1476 * Success.
Neil Armstrong4721a6f2022-05-20 10:53:00 +02001477 * \retval #PSA_ERROR_INVALID_ARGUMENT
1478 * The algorithm in \p cipher_suite is not a PAKE algorithm, or the
1479 * PAKE primitive in \p cipher_suite is not compatible with the
1480 * PAKE algorithm, or the hash algorithm in \p cipher_suite is invalid
1481 * or not compatible with the PAKE algorithm and primitive.
Janos Follath702cf092021-05-26 12:58:23 +01001482 * \retval #PSA_ERROR_NOT_SUPPORTED
Neil Armstrong4721a6f2022-05-20 10:53:00 +02001483 * The algorithm in \p cipher_suite is not a supported PAKE algorithm,
1484 * or the PAKE primitive in \p cipher_suite is not supported or not
1485 * compatible with the PAKE algorithm, or the hash algorithm in
1486 * \p cipher_suite is not supported or not compatible with the PAKE
1487 * algorithm and primitive.
Gilles Peskineed733552023-02-14 19:21:09 +01001488 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1489 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001490 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001491 * The operation state is not valid, or
1492 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001493 * It is implementation-dependent whether a failure to initialize
1494 * results in this error code.
1495 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001496psa_status_t psa_pake_setup(psa_pake_operation_t *operation,
1497 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +01001498
1499/** Set the password for a password-authenticated key exchange from key ID.
1500 *
1501 * Call this function when the password, or a value derived from the password,
Janos Follath52f9efa2021-05-27 08:40:16 +01001502 * is already present in the key store.
Janos Follath702cf092021-05-26 12:58:23 +01001503 *
1504 * \param[in,out] operation The operation object to set the password for. It
1505 * must have been set up by psa_pake_setup() and
1506 * not yet in use (neither psa_pake_output() nor
1507 * psa_pake_input() has been called yet). It must
1508 * be on operation for which the password hasn't
Janos Follath52f9efa2021-05-27 08:40:16 +01001509 * been set yet (psa_pake_set_password_key()
Janos Follath559f05e2021-05-26 15:44:30 +01001510 * hasn't been called yet).
Janos Follath702cf092021-05-26 12:58:23 +01001511 * \param password Identifier of the key holding the password or a
1512 * value derived from the password (eg. by a
1513 * memory-hard function). It must remain valid
1514 * until the operation terminates. It must be of
1515 * type #PSA_KEY_TYPE_PASSWORD or
1516 * #PSA_KEY_TYPE_PASSWORD_HASH. It has to allow
1517 * the usage #PSA_KEY_USAGE_DERIVE.
1518 *
1519 * \retval #PSA_SUCCESS
1520 * Success.
Janos Follath702cf092021-05-26 12:58:23 +01001521 * \retval #PSA_ERROR_INVALID_HANDLE
Neil Armstrong71cae612022-05-20 11:00:49 +02001522 * \p password is not a valid key identifier.
Janos Follath702cf092021-05-26 12:58:23 +01001523 * \retval #PSA_ERROR_NOT_PERMITTED
Neil Armstrong71cae612022-05-20 11:00:49 +02001524 * The key does not have the #PSA_KEY_USAGE_DERIVE flag, or it does not
1525 * permit the \p operation's algorithm.
1526 * \retval #PSA_ERROR_INVALID_ARGUMENT
1527 * The key type for \p password is not #PSA_KEY_TYPE_PASSWORD or
1528 * #PSA_KEY_TYPE_PASSWORD_HASH, or \p password is not compatible with
1529 * the \p operation's cipher suite.
1530 * \retval #PSA_ERROR_NOT_SUPPORTED
1531 * The key type or key size of \p password is not supported with the
1532 * \p operation's cipher suite.
Gilles Peskineed733552023-02-14 19:21:09 +01001533 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1534 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1535 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1536 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1537 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001538 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001539 * The operation state is not valid (it must have been set up.), or
1540 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001541 * It is implementation-dependent whether a failure to initialize
1542 * results in this error code.
1543 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001544psa_status_t psa_pake_set_password_key(psa_pake_operation_t *operation,
1545 mbedtls_svc_key_id_t password);
Janos Follath702cf092021-05-26 12:58:23 +01001546
Janos Follath702cf092021-05-26 12:58:23 +01001547/** Set the user ID for a password-authenticated key exchange.
1548 *
1549 * Call this function to set the user ID. For PAKE algorithms that associate a
1550 * user identifier with each side of the session you need to call
1551 * psa_pake_set_peer() as well. For PAKE algorithms that associate a single
1552 * user identifier with the session, call psa_pake_set_user() only.
1553 *
1554 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1555 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1556 * for more information.
1557 *
1558 * \param[in,out] operation The operation object to set the user ID for. It
1559 * must have been set up by psa_pake_setup() and
1560 * not yet in use (neither psa_pake_output() nor
1561 * psa_pake_input() has been called yet). It must
1562 * be on operation for which the user ID hasn't
1563 * been set (psa_pake_set_user() hasn't been
1564 * called yet).
1565 * \param[in] user_id The user ID to authenticate with.
1566 * \param user_id_len Size of the \p user_id buffer in bytes.
1567 *
1568 * \retval #PSA_SUCCESS
1569 * Success.
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001570 * \retval #PSA_ERROR_INVALID_ARGUMENT
Neil Armstrong35851682022-05-20 11:02:37 +02001571 * \p user_id is not valid for the \p operation's algorithm and cipher
1572 * suite.
1573 * \retval #PSA_ERROR_NOT_SUPPORTED
1574 * The value of \p user_id is not supported by the implementation.
Gilles Peskineed733552023-02-14 19:21:09 +01001575 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1576 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1577 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001578 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001579 * The operation state is not valid, or
1580 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001581 * It is implementation-dependent whether a failure to initialize
1582 * results in this error code.
1583 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001584psa_status_t psa_pake_set_user(psa_pake_operation_t *operation,
1585 const uint8_t *user_id,
1586 size_t user_id_len);
Janos Follath702cf092021-05-26 12:58:23 +01001587
1588/** Set the peer ID for a password-authenticated key exchange.
1589 *
1590 * Call this function in addition to psa_pake_set_user() for PAKE algorithms
1591 * that associate a user identifier with each side of the session. For PAKE
1592 * algorithms that associate a single user identifier with the session, call
1593 * psa_pake_set_user() only.
1594 *
1595 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1596 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1597 * for more information.
1598 *
1599 * \param[in,out] operation The operation object to set the peer ID for. It
1600 * must have been set up by psa_pake_setup() and
1601 * not yet in use (neither psa_pake_output() nor
1602 * psa_pake_input() has been called yet). It must
1603 * be on operation for which the peer ID hasn't
1604 * been set (psa_pake_set_peer() hasn't been
1605 * called yet).
1606 * \param[in] peer_id The peer's ID to authenticate.
1607 * \param peer_id_len Size of the \p peer_id buffer in bytes.
1608 *
1609 * \retval #PSA_SUCCESS
1610 * Success.
Neil Armstrong16ff7882022-05-20 11:04:20 +02001611 * \retval #PSA_ERROR_INVALID_ARGUMENT
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001612 * \p peer_id is not valid for the \p operation's algorithm and cipher
Neil Armstrong16ff7882022-05-20 11:04:20 +02001613 * suite.
Janos Follath702cf092021-05-26 12:58:23 +01001614 * \retval #PSA_ERROR_NOT_SUPPORTED
1615 * The algorithm doesn't associate a second identity with the session.
Gilles Peskineed733552023-02-14 19:21:09 +01001616 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1617 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1618 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001619 * \retval #PSA_ERROR_BAD_STATE
Neil Armstrong0d245752022-05-20 11:35:40 +02001620 * Calling psa_pake_set_peer() is invalid with the \p operation's
1621 * algorithm, the operation state is not valid, or the library has not
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001622 * been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001623 * It is implementation-dependent whether a failure to initialize
1624 * results in this error code.
1625 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001626psa_status_t psa_pake_set_peer(psa_pake_operation_t *operation,
1627 const uint8_t *peer_id,
1628 size_t peer_id_len);
Janos Follath702cf092021-05-26 12:58:23 +01001629
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001630/** Set the application role for a password-authenticated key exchange.
Janos Follath702cf092021-05-26 12:58:23 +01001631 *
1632 * Not all PAKE algorithms need to differentiate the communicating entities.
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001633 * It is optional to call this function for PAKEs that don't require a role
1634 * to be specified. For such PAKEs the application role parameter is ignored,
1635 * or #PSA_PAKE_ROLE_NONE can be passed as \c role.
Janos Follath702cf092021-05-26 12:58:23 +01001636 *
1637 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1638 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1639 * for more information.
1640 *
Neil Armstrongef157512022-05-25 11:49:45 +02001641 * \param[in,out] operation The operation object to specify the
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001642 * application's role for. It must have been set up
1643 * by psa_pake_setup() and not yet in use (neither
1644 * psa_pake_output() nor psa_pake_input() has been
1645 * called yet). It must be on operation for which
1646 * the application's role hasn't been specified
1647 * (psa_pake_set_role() hasn't been called yet).
1648 * \param role A value of type ::psa_pake_role_t indicating the
1649 * application's role in the PAKE the algorithm
1650 * that is being set up. For more information see
1651 * the documentation of \c PSA_PAKE_ROLE_XXX
1652 * constants.
Janos Follath702cf092021-05-26 12:58:23 +01001653 *
1654 * \retval #PSA_SUCCESS
1655 * Success.
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001656 * \retval #PSA_ERROR_INVALID_ARGUMENT
1657 * The \p role is not a valid PAKE role in the \p operation’s algorithm.
Janos Follath702cf092021-05-26 12:58:23 +01001658 * \retval #PSA_ERROR_NOT_SUPPORTED
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001659 * The \p role for this algorithm is not supported or is not valid.
Gilles Peskineed733552023-02-14 19:21:09 +01001660 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1661 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001662 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001663 * The operation state is not valid, or
1664 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001665 * It is implementation-dependent whether a failure to initialize
1666 * results in this error code.
1667 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001668psa_status_t psa_pake_set_role(psa_pake_operation_t *operation,
1669 psa_pake_role_t role);
Janos Follath702cf092021-05-26 12:58:23 +01001670
1671/** Get output for a step of a password-authenticated key exchange.
1672 *
1673 * Depending on the algorithm being executed, you might need to call this
1674 * function several times or you might not need to call this at all.
1675 *
1676 * The exact sequence of calls to perform a password-authenticated key
1677 * exchange depends on the algorithm in use. Refer to the documentation of
1678 * individual PAKE algorithm types (`PSA_ALG_XXX` values of type
1679 * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more
1680 * information.
1681 *
1682 * If this function returns an error status, the operation enters an error
1683 * state and must be aborted by calling psa_pake_abort().
1684 *
1685 * \param[in,out] operation Active PAKE operation.
1686 * \param step The step of the algorithm for which the output is
1687 * requested.
1688 * \param[out] output Buffer where the output is to be written in the
1689 * format appropriate for this \p step. Refer to
1690 * the documentation of the individual
1691 * \c PSA_PAKE_STEP_XXX constants for more
1692 * information.
1693 * \param output_size Size of the \p output buffer in bytes. This must
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001694 * be at least #PSA_PAKE_OUTPUT_SIZE(\c alg, \c
1695 * primitive, \p output_step) where \c alg and
Neil Armstrong7bc71e92022-05-20 10:36:14 +02001696 * \p primitive are the PAKE algorithm and primitive
1697 * in the operation's cipher suite, and \p step is
1698 * the output step.
Janos Follath702cf092021-05-26 12:58:23 +01001699 *
1700 * \param[out] output_length On success, the number of bytes of the returned
1701 * output.
1702 *
1703 * \retval #PSA_SUCCESS
1704 * Success.
Janos Follath702cf092021-05-26 12:58:23 +01001705 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
1706 * The size of the \p output buffer is too small.
Neil Armstrong664077e2022-05-20 11:24:41 +02001707 * \retval #PSA_ERROR_INVALID_ARGUMENT
1708 * \p step is not compatible with the operation's algorithm.
1709 * \retval #PSA_ERROR_NOT_SUPPORTED
1710 * \p step is not supported with the operation's algorithm.
Gilles Peskineed733552023-02-14 19:21:09 +01001711 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
1712 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1713 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1714 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1715 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1716 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1717 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001718 * \retval #PSA_ERROR_BAD_STATE
Neil Armstronge9b45812022-05-20 11:39:09 +02001719 * The operation state is not valid (it must be active, and fully set
1720 * up, and this call must conform to the algorithm's requirements
1721 * for ordering of input and output steps), or
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001722 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001723 * It is implementation-dependent whether a failure to initialize
1724 * results in this error code.
1725 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001726psa_status_t psa_pake_output(psa_pake_operation_t *operation,
1727 psa_pake_step_t step,
1728 uint8_t *output,
1729 size_t output_size,
1730 size_t *output_length);
Janos Follath702cf092021-05-26 12:58:23 +01001731
1732/** Provide input for a step of a password-authenticated key exchange.
1733 *
1734 * Depending on the algorithm being executed, you might need to call this
1735 * function several times or you might not need to call this at all.
1736 *
1737 * The exact sequence of calls to perform a password-authenticated key
1738 * exchange depends on the algorithm in use. Refer to the documentation of
1739 * individual PAKE algorithm types (`PSA_ALG_XXX` values of type
1740 * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more
1741 * information.
1742 *
1743 * If this function returns an error status, the operation enters an error
1744 * state and must be aborted by calling psa_pake_abort().
1745 *
1746 * \param[in,out] operation Active PAKE operation.
1747 * \param step The step for which the input is provided.
Neil Armstrong799106b2022-05-20 10:18:53 +02001748 * \param[in] input Buffer containing the input in the format
Janos Follath702cf092021-05-26 12:58:23 +01001749 * appropriate for this \p step. Refer to the
1750 * documentation of the individual
1751 * \c PSA_PAKE_STEP_XXX constants for more
1752 * information.
Neil Armstrong799106b2022-05-20 10:18:53 +02001753 * \param input_length Size of the \p input buffer in bytes.
Janos Follath702cf092021-05-26 12:58:23 +01001754 *
1755 * \retval #PSA_SUCCESS
1756 * Success.
Neil Armstrong407b27b2022-05-20 11:28:23 +02001757 * \retval #PSA_ERROR_INVALID_SIGNATURE
1758 * The verification fails for a #PSA_PAKE_STEP_ZK_PROOF input step.
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001759 * \retval #PSA_ERROR_INVALID_ARGUMENT
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001760 * \p input_length is not compatible with the \p operation’s algorithm,
1761 * or the \p input is not valid for the \p operation's algorithm,
1762 * cipher suite or \p step.
Neil Armstrong407b27b2022-05-20 11:28:23 +02001763 * \retval #PSA_ERROR_NOT_SUPPORTED
1764 * \p step p is not supported with the \p operation's algorithm, or the
1765 * \p input is not supported for the \p operation's algorithm, cipher
1766 * suite or \p step.
Gilles Peskineed733552023-02-14 19:21:09 +01001767 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1768 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1769 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1770 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1771 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1772 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001773 * \retval #PSA_ERROR_BAD_STATE
Neil Armstronge9b45812022-05-20 11:39:09 +02001774 * The operation state is not valid (it must be active, and fully set
1775 * up, and this call must conform to the algorithm's requirements
1776 * for ordering of input and output steps), or
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001777 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001778 * It is implementation-dependent whether a failure to initialize
1779 * results in this error code.
1780 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001781psa_status_t psa_pake_input(psa_pake_operation_t *operation,
1782 psa_pake_step_t step,
1783 const uint8_t *input,
1784 size_t input_length);
Janos Follath702cf092021-05-26 12:58:23 +01001785
1786/** Get implicitly confirmed shared secret from a PAKE.
1787 *
1788 * At this point there is a cryptographic guarantee that only the authenticated
1789 * party who used the same password is able to compute the key. But there is no
Janos Follatha46e28f2021-06-03 13:07:03 +01001790 * guarantee that the peer is the party it claims to be and was able to do so.
Janos Follath702cf092021-05-26 12:58:23 +01001791 *
Janos Follathb4db90f2021-06-03 13:17:09 +01001792 * That is, the authentication is only implicit. Since the peer is not
1793 * authenticated yet, no action should be taken yet that assumes that the peer
1794 * is who it claims to be. For example, do not access restricted files on the
1795 * peer's behalf until an explicit authentication has succeeded.
Janos Follath702cf092021-05-26 12:58:23 +01001796 *
1797 * This function can be called after the key exchange phase of the operation
1798 * has completed. It imports the shared secret output of the PAKE into the
1799 * provided derivation operation. The input step
1800 * #PSA_KEY_DERIVATION_INPUT_SECRET is used when placing the shared key
1801 * material in the key derivation operation.
1802 *
1803 * The exact sequence of calls to perform a password-authenticated key
1804 * exchange depends on the algorithm in use. Refer to the documentation of
1805 * individual PAKE algorithm types (`PSA_ALG_XXX` values of type
1806 * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more
1807 * information.
1808 *
1809 * When this function returns successfully, \p operation becomes inactive.
1810 * If this function returns an error status, both \p operation
Andrzej Kurek3bedb5b2022-02-17 14:39:00 -05001811 * and \c key_derivation operations enter an error state and must be aborted by
Janos Follath702cf092021-05-26 12:58:23 +01001812 * calling psa_pake_abort() and psa_key_derivation_abort() respectively.
1813 *
1814 * \param[in,out] operation Active PAKE operation.
1815 * \param[out] output A key derivation operation that is ready
1816 * for an input step of type
1817 * #PSA_KEY_DERIVATION_INPUT_SECRET.
1818 *
1819 * \retval #PSA_SUCCESS
1820 * Success.
Janos Follath702cf092021-05-26 12:58:23 +01001821 * \retval #PSA_ERROR_INVALID_ARGUMENT
Neil Armstrong97d74b82022-05-20 11:30:31 +02001822 * #PSA_KEY_DERIVATION_INPUT_SECRET is not compatible with the
1823 * algorithm in the \p output key derivation operation.
1824 * \retval #PSA_ERROR_NOT_SUPPORTED
1825 * Input from a PAKE is not supported by the algorithm in the \p output
1826 * key derivation operation.
Gilles Peskineed733552023-02-14 19:21:09 +01001827 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1828 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1829 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1830 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1831 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1832 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001833 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001834 * The PAKE operation state is not valid (it must be active, but beyond
1835 * that validity is specific to the algorithm), or
1836 * the library has not been previously initialized by psa_crypto_init(),
1837 * or the state of \p output is not valid for
1838 * the #PSA_KEY_DERIVATION_INPUT_SECRET step. This can happen if the
1839 * step is out of order or the application has done this step already
1840 * and it may not be repeated.
Janos Follath702cf092021-05-26 12:58:23 +01001841 * It is implementation-dependent whether a failure to initialize
1842 * results in this error code.
1843 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001844psa_status_t psa_pake_get_implicit_key(psa_pake_operation_t *operation,
1845 psa_key_derivation_operation_t *output);
Janos Follath702cf092021-05-26 12:58:23 +01001846
Neil Armstrong0c8ef932022-05-20 10:23:51 +02001847/** Abort a PAKE operation.
1848 *
1849 * Aborting an operation frees all associated resources except for the \c
1850 * operation structure itself. Once aborted, the operation object can be reused
1851 * for another operation by calling psa_pake_setup() again.
1852 *
1853 * This function may be called at any time after the operation
1854 * object has been initialized as described in #psa_pake_operation_t.
1855 *
1856 * In particular, calling psa_pake_abort() after the operation has been
1857 * terminated by a call to psa_pake_abort() or psa_pake_get_implicit_key()
1858 * is safe and has no effect.
1859 *
1860 * \param[in,out] operation The operation to abort.
1861 *
1862 * \retval #PSA_SUCCESS
Neil Armstrong59fa8ee2022-05-20 11:31:04 +02001863 * Success.
Gilles Peskineed733552023-02-14 19:21:09 +01001864 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1865 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Neil Armstrong0c8ef932022-05-20 10:23:51 +02001866 * \retval #PSA_ERROR_BAD_STATE
1867 * The library has not been previously initialized by psa_crypto_init().
1868 * It is implementation-dependent whether a failure to initialize
1869 * results in this error code.
1870 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001871psa_status_t psa_pake_abort(psa_pake_operation_t *operation);
Neil Armstrong0c8ef932022-05-20 10:23:51 +02001872
Janos Follath702cf092021-05-26 12:58:23 +01001873/**@}*/
1874
Janos Follath702cf092021-05-26 12:58:23 +01001875static inline psa_algorithm_t psa_pake_cs_get_algorithm(
Gilles Peskine449bd832023-01-11 14:50:10 +01001876 const psa_pake_cipher_suite_t *cipher_suite)
Janos Follath702cf092021-05-26 12:58:23 +01001877{
Gilles Peskine449bd832023-01-11 14:50:10 +01001878 return cipher_suite->algorithm;
Janos Follath702cf092021-05-26 12:58:23 +01001879}
1880
1881static inline void psa_pake_cs_set_algorithm(
1882 psa_pake_cipher_suite_t *cipher_suite,
1883 psa_algorithm_t algorithm)
1884{
Gilles Peskine449bd832023-01-11 14:50:10 +01001885 if (!PSA_ALG_IS_PAKE(algorithm)) {
Janos Follath702cf092021-05-26 12:58:23 +01001886 cipher_suite->algorithm = 0;
Gilles Peskine449bd832023-01-11 14:50:10 +01001887 } else {
Janos Follath702cf092021-05-26 12:58:23 +01001888 cipher_suite->algorithm = algorithm;
Gilles Peskine449bd832023-01-11 14:50:10 +01001889 }
Janos Follath702cf092021-05-26 12:58:23 +01001890}
1891
1892static inline psa_pake_primitive_t psa_pake_cs_get_primitive(
Gilles Peskine449bd832023-01-11 14:50:10 +01001893 const psa_pake_cipher_suite_t *cipher_suite)
Janos Follath702cf092021-05-26 12:58:23 +01001894{
Gilles Peskine449bd832023-01-11 14:50:10 +01001895 return PSA_PAKE_PRIMITIVE(cipher_suite->type, cipher_suite->family,
1896 cipher_suite->bits);
Janos Follath702cf092021-05-26 12:58:23 +01001897}
1898
1899static inline void psa_pake_cs_set_primitive(
Gilles Peskine449bd832023-01-11 14:50:10 +01001900 psa_pake_cipher_suite_t *cipher_suite,
1901 psa_pake_primitive_t primitive)
Janos Follath702cf092021-05-26 12:58:23 +01001902{
1903 cipher_suite->type = (psa_pake_primitive_type_t) (primitive >> 24);
1904 cipher_suite->family = (psa_pake_family_t) (0xFF & (primitive >> 16));
1905 cipher_suite->bits = (uint16_t) (0xFFFF & primitive);
1906}
1907
Neil Armstrongff9cac72022-05-20 10:25:15 +02001908static inline psa_pake_family_t psa_pake_cs_get_family(
Gilles Peskine449bd832023-01-11 14:50:10 +01001909 const psa_pake_cipher_suite_t *cipher_suite)
Neil Armstrongff9cac72022-05-20 10:25:15 +02001910{
Gilles Peskine449bd832023-01-11 14:50:10 +01001911 return cipher_suite->family;
Neil Armstrongff9cac72022-05-20 10:25:15 +02001912}
1913
Neil Armstrongd5a48252022-05-20 10:26:36 +02001914static inline uint16_t psa_pake_cs_get_bits(
Gilles Peskine449bd832023-01-11 14:50:10 +01001915 const psa_pake_cipher_suite_t *cipher_suite)
Neil Armstrongd5a48252022-05-20 10:26:36 +02001916{
Gilles Peskine449bd832023-01-11 14:50:10 +01001917 return cipher_suite->bits;
Neil Armstrongd5a48252022-05-20 10:26:36 +02001918}
1919
Janos Follath702cf092021-05-26 12:58:23 +01001920static inline psa_algorithm_t psa_pake_cs_get_hash(
Gilles Peskine449bd832023-01-11 14:50:10 +01001921 const psa_pake_cipher_suite_t *cipher_suite)
Janos Follath702cf092021-05-26 12:58:23 +01001922{
Gilles Peskine449bd832023-01-11 14:50:10 +01001923 return cipher_suite->hash;
Janos Follath702cf092021-05-26 12:58:23 +01001924}
1925
Gilles Peskine449bd832023-01-11 14:50:10 +01001926static inline void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite,
1927 psa_algorithm_t hash)
Janos Follath702cf092021-05-26 12:58:23 +01001928{
Gilles Peskine449bd832023-01-11 14:50:10 +01001929 if (!PSA_ALG_IS_HASH(hash)) {
Janos Follath702cf092021-05-26 12:58:23 +01001930 cipher_suite->hash = 0;
Gilles Peskine449bd832023-01-11 14:50:10 +01001931 } else {
Janos Follath702cf092021-05-26 12:58:23 +01001932 cipher_suite->hash = hash;
Gilles Peskine449bd832023-01-11 14:50:10 +01001933 }
Janos Follath702cf092021-05-26 12:58:23 +01001934}
1935
Gilles Peskine449bd832023-01-11 14:50:10 +01001936static inline struct psa_pake_cipher_suite_s psa_pake_cipher_suite_init(void)
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +02001937{
1938 const struct psa_pake_cipher_suite_s v = PSA_PAKE_CIPHER_SUITE_INIT;
Gilles Peskine449bd832023-01-11 14:50:10 +01001939 return v;
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +02001940}
1941
Gilles Peskine449bd832023-01-11 14:50:10 +01001942static inline struct psa_pake_operation_s psa_pake_operation_init(void)
Janos Follath702cf092021-05-26 12:58:23 +01001943{
1944 const struct psa_pake_operation_s v = PSA_PAKE_OPERATION_INIT;
Gilles Peskine449bd832023-01-11 14:50:10 +01001945 return v;
Janos Follath702cf092021-05-26 12:58:23 +01001946}
1947
Gilles Peskinee59236f2018-01-27 23:32:46 +01001948#ifdef __cplusplus
1949}
1950#endif
1951
1952#endif /* PSA_CRYPTO_EXTRA_H */