blob: 6ed1f6c43a170cbbd3d3bdd42cf96b295f0a1b87 [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
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020035/** \addtogroup attributes
36 * @{
37 */
38
39/** \brief Declare the enrollment algorithm for a key.
40 *
41 * An operation on a key may indifferently use the algorithm set with
42 * psa_set_key_algorithm() or with this function.
43 *
44 * \param[out] attributes The attribute structure to write to.
45 * \param alg2 A second algorithm that the key may be used
46 * for, in addition to the algorithm set with
47 * psa_set_key_algorithm().
48 *
49 * \warning Setting an enrollment algorithm is not recommended, because
50 * using the same key with different algorithms can allow some
51 * attacks based on arithmetic relations between different
52 * computations made with the same key, or can escalate harmless
53 * side channels into exploitable ones. Use this function only
Gilles Peskinef25c9ec2019-05-22 11:45:59 +020054 * if it is necessary to support a protocol for which it has been
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020055 * verified that the usage of the key with multiple algorithms
56 * is safe.
57 */
58static inline void psa_set_key_enrollment_algorithm(
59 psa_key_attributes_t *attributes,
60 psa_algorithm_t alg2)
61{
Gilles Peskine2f107ae2024-02-28 01:26:46 +010062 attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2) = alg2;
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020063}
64
65/** Retrieve the enrollment algorithm policy from key attributes.
66 *
67 * \param[in] attributes The key attribute structure to query.
68 *
69 * \return The enrollment algorithm stored in the attribute structure.
70 */
71static inline psa_algorithm_t psa_get_key_enrollment_algorithm(
72 const psa_key_attributes_t *attributes)
73{
Gilles Peskine2f107ae2024-02-28 01:26:46 +010074 return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2);
Gilles Peskine96f0b3b2019-05-10 19:33:38 +020075}
76
Gilles Peskinec8000c02019-08-02 20:15:51 +020077#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
78
79/** Retrieve the slot number where a key is stored.
80 *
81 * A slot number is only defined for keys that are stored in a secure
82 * element.
83 *
84 * This information is only useful if the secure element is not entirely
85 * managed through the PSA Cryptography API. It is up to the secure
86 * element driver to decide how PSA slot numbers map to any other interface
87 * that the secure element may have.
88 *
89 * \param[in] attributes The key attribute structure to query.
90 * \param[out] slot_number On success, the slot number containing the key.
91 *
92 * \retval #PSA_SUCCESS
93 * The key is located in a secure element, and \p *slot_number
94 * indicates the slot number that contains it.
95 * \retval #PSA_ERROR_NOT_PERMITTED
96 * The caller is not permitted to query the slot number.
Fredrik Hessecc207bc2021-09-28 21:06:08 +020097 * Mbed TLS currently does not return this error.
Gilles Peskinec8000c02019-08-02 20:15:51 +020098 * \retval #PSA_ERROR_INVALID_ARGUMENT
99 * The key is not located in a secure element.
100 */
101psa_status_t psa_get_key_slot_number(
102 const psa_key_attributes_t *attributes,
Gilles Peskine449bd832023-01-11 14:50:10 +0100103 psa_key_slot_number_t *slot_number);
Gilles Peskinec8000c02019-08-02 20:15:51 +0200104
105/** Choose the slot number where a key is stored.
106 *
107 * This function declares a slot number in the specified attribute
108 * structure.
109 *
110 * A slot number is only meaningful for keys that are stored in a secure
111 * element. It is up to the secure element driver to decide how PSA slot
112 * numbers map to any other interface that the secure element may have.
113 *
114 * \note Setting a slot number in key attributes for a key creation can
115 * cause the following errors when creating the key:
116 * - #PSA_ERROR_NOT_SUPPORTED if the selected secure element does
117 * not support choosing a specific slot number.
118 * - #PSA_ERROR_NOT_PERMITTED if the caller is not permitted to
119 * choose slot numbers in general or to choose this specific slot.
120 * - #PSA_ERROR_INVALID_ARGUMENT if the chosen slot number is not
121 * valid in general or not valid for this specific key.
122 * - #PSA_ERROR_ALREADY_EXISTS if there is already a key in the
123 * selected slot.
124 *
125 * \param[out] attributes The attribute structure to write to.
126 * \param slot_number The slot number to set.
127 */
128static inline void psa_set_key_slot_number(
129 psa_key_attributes_t *attributes,
Gilles Peskine449bd832023-01-11 14:50:10 +0100130 psa_key_slot_number_t slot_number)
Gilles Peskinec8000c02019-08-02 20:15:51 +0200131{
Gilles Peskine972539c2024-02-28 01:49:45 +0100132 attributes->MBEDTLS_PRIVATE(has_slot_number) = 1;
Gilles Peskine2f107ae2024-02-28 01:26:46 +0100133 attributes->MBEDTLS_PRIVATE(slot_number) = slot_number;
Gilles Peskinec8000c02019-08-02 20:15:51 +0200134}
135
Gilles Peskine5fe5e272019-08-02 20:30:01 +0200136/** Remove the slot number attribute from a key attribute structure.
137 *
138 * This function undoes the action of psa_set_key_slot_number().
139 *
140 * \param[out] attributes The attribute structure to write to.
141 */
142static inline void psa_clear_key_slot_number(
Gilles Peskine449bd832023-01-11 14:50:10 +0100143 psa_key_attributes_t *attributes)
Gilles Peskine5fe5e272019-08-02 20:30:01 +0200144{
Gilles Peskine972539c2024-02-28 01:49:45 +0100145 attributes->MBEDTLS_PRIVATE(has_slot_number) = 0;
Gilles Peskine5fe5e272019-08-02 20:30:01 +0200146}
147
Gilles Peskined7729582019-08-05 15:55:54 +0200148/** Register a key that is already present in a secure element.
149 *
150 * The key must be located in a secure element designated by the
151 * lifetime field in \p attributes, in the slot set with
152 * psa_set_key_slot_number() in the attribute structure.
153 * This function makes the key available through the key identifier
154 * specified in \p attributes.
155 *
156 * \param[in] attributes The attributes of the existing key.
157 *
158 * \retval #PSA_SUCCESS
159 * The key was successfully registered.
160 * Note that depending on the design of the driver, this may or may
161 * not guarantee that a key actually exists in the designated slot
162 * and is compatible with the specified attributes.
163 * \retval #PSA_ERROR_ALREADY_EXISTS
164 * There is already a key with the identifier specified in
165 * \p attributes.
Gilles Peskine3efcebb2019-10-01 14:18:35 +0200166 * \retval #PSA_ERROR_NOT_SUPPORTED
167 * The secure element driver for the specified lifetime does not
168 * support registering a key.
Gilles Peskined7729582019-08-05 15:55:54 +0200169 * \retval #PSA_ERROR_INVALID_ARGUMENT
Ronald Crond3b458c2021-03-31 17:51:29 +0200170 * The identifier in \p attributes is invalid, namely the identifier is
Andrzej Kurekf7c1f742022-02-03 11:30:54 -0500171 * not in the user range, or
Gilles Peskined7729582019-08-05 15:55:54 +0200172 * \p attributes specifies a lifetime which is not located
Andrzej Kurekf7c1f742022-02-03 11:30:54 -0500173 * in a secure element, or no slot number is specified in \p attributes,
Gilles Peskined7729582019-08-05 15:55:54 +0200174 * or the specified slot number is not valid.
175 * \retval #PSA_ERROR_NOT_PERMITTED
176 * The caller is not authorized to register the specified key slot.
Gilles Peskineed733552023-02-14 19:21:09 +0100177 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
178 * \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription
179 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
180 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
181 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
182 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Gilles Peskined7729582019-08-05 15:55:54 +0200183 * \retval #PSA_ERROR_BAD_STATE
184 * The library has not been previously initialized by psa_crypto_init().
185 * It is implementation-dependent whether a failure to initialize
186 * results in this error code.
187 */
188psa_status_t mbedtls_psa_register_se_key(
189 const psa_key_attributes_t *attributes);
190
Gilles Peskinec8000c02019-08-02 20:15:51 +0200191#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
192
Gilles Peskine96f0b3b2019-05-10 19:33:38 +0200193/**@}*/
194
Gilles Peskinee59236f2018-01-27 23:32:46 +0100195/**
196 * \brief Library deinitialization.
197 *
198 * This function clears all data associated with the PSA layer,
199 * including the whole key store.
Ryan Everett16abd592024-01-24 17:37:46 +0000200 * This function is not thread safe, it wipes every key slot regardless of
201 * state and reader count. It should only be called when no slot is in use.
Gilles Peskinee59236f2018-01-27 23:32:46 +0100202 *
203 * This is an Mbed TLS extension.
204 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100205void mbedtls_psa_crypto_free(void);
Gilles Peskinee59236f2018-01-27 23:32:46 +0100206
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200207/** \brief Statistics about
208 * resource consumption related to the PSA keystore.
209 *
210 * \note The content of this structure is not part of the stable API and ABI
Fredrik Hessecc207bc2021-09-28 21:06:08 +0200211 * of Mbed TLS and may change arbitrarily from version to version.
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200212 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100213typedef struct mbedtls_psa_stats_s {
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200214 /** Number of slots containing key material for a volatile key. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200215 size_t MBEDTLS_PRIVATE(volatile_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200216 /** Number of slots containing key material for a key which is in
217 * internal persistent storage. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200218 size_t MBEDTLS_PRIVATE(persistent_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200219 /** Number of slots containing a reference to a key in a
220 * secure element. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200221 size_t MBEDTLS_PRIVATE(external_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200222 /** Number of slots which are occupied, but do not contain
223 * key material yet. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200224 size_t MBEDTLS_PRIVATE(half_filled_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200225 /** Number of slots that contain cache data. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200226 size_t MBEDTLS_PRIVATE(cache_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200227 /** Number of slots that are not used for anything. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200228 size_t MBEDTLS_PRIVATE(empty_slots);
Ronald Cron1ad1eee2020-11-15 14:21:04 +0100229 /** Number of slots that are locked. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200230 size_t MBEDTLS_PRIVATE(locked_slots);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200231 /** Largest key id value among open keys in internal persistent storage. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200232 psa_key_id_t MBEDTLS_PRIVATE(max_open_internal_key_id);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200233 /** Largest key id value among open keys in secure elements. */
Mateusz Starzyk846f0212021-05-19 19:44:07 +0200234 psa_key_id_t MBEDTLS_PRIVATE(max_open_external_key_id);
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200235} mbedtls_psa_stats_t;
236
237/** \brief Get statistics about
238 * resource consumption related to the PSA keystore.
239 *
Fredrik Hessecc207bc2021-09-28 21:06:08 +0200240 * \note When Mbed TLS is built as part of a service, with isolation
Gilles Peskine4bac9a42019-05-23 20:32:30 +0200241 * between the application and the keystore, the service may or
242 * may not expose this function.
243 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100244void mbedtls_psa_get_stats(mbedtls_psa_stats_t *stats);
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200245
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200246/**
Gilles Peskineee2ffd32018-11-16 11:02:49 +0100247 * \brief Inject an initial entropy seed for the random generator into
248 * secure storage.
Gilles Peskine0338ded2018-11-15 18:19:27 +0100249 *
250 * This function injects data to be used as a seed for the random generator
251 * used by the PSA Crypto implementation. On devices that lack a trusted
252 * entropy source (preferably a hardware random number generator),
253 * the Mbed PSA Crypto implementation uses this value to seed its
254 * random generator.
255 *
256 * On devices without a trusted entropy source, this function must be
257 * called exactly once in the lifetime of the device. On devices with
258 * a trusted entropy source, calling this function is optional.
259 * In all cases, this function may only be called before calling any
260 * other function in the PSA Crypto API, including psa_crypto_init().
261 *
262 * When this function returns successfully, it populates a file in
263 * persistent storage. Once the file has been created, this function
264 * can no longer succeed.
Gilles Peskineee2ffd32018-11-16 11:02:49 +0100265 *
266 * If any error occurs, this function does not change the system state.
267 * You can call this function again after correcting the reason for the
268 * error if possible.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200269 *
270 * \warning This function **can** fail! Callers MUST check the return status.
271 *
Gilles Peskine0338ded2018-11-15 18:19:27 +0100272 * \warning If you use this function, you should use it as part of a
273 * factory provisioning process. The value of the injected seed
274 * is critical to the security of the device. It must be
275 * *secret*, *unpredictable* and (statistically) *unique per device*.
276 * You should be generate it randomly using a cryptographically
277 * secure random generator seeded from trusted entropy sources.
278 * You should transmit it securely to the device and ensure
279 * that its value is not leaked or stored anywhere beyond the
280 * needs of transmitting it from the point of generation to
281 * the call of this function, and erase all copies of the value
282 * once this function returns.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200283 *
Gilles Peskine0338ded2018-11-15 18:19:27 +0100284 * This is an Mbed TLS extension.
285 *
Netanel Gonen1d7195f2018-11-22 16:24:48 +0200286 * \note This function is only available on the following platforms:
Gilles Peskinee3dbdd82019-02-25 11:04:06 +0100287 * * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled.
288 * Note that you must provide compatible implementations of
289 * mbedtls_nv_seed_read and mbedtls_nv_seed_write.
Gilles Peskine0cfaed12018-11-22 17:11:45 +0200290 * * In a client-server integration of PSA Cryptography, on the client side,
Netanel Gonen1d7195f2018-11-22 16:24:48 +0200291 * if the server supports this feature.
Netanel Gonen596e65e2018-11-22 18:41:43 +0200292 * \param[in] seed Buffer containing the seed value to inject.
Gilles Peskine0cfaed12018-11-22 17:11:45 +0200293 * \param[in] seed_size Size of the \p seed buffer.
Netanel Gonen596e65e2018-11-22 18:41:43 +0200294 * The size of the seed in bytes must be greater
Chris Jones3848e312021-03-11 16:17:59 +0000295 * or equal to both #MBEDTLS_ENTROPY_BLOCK_SIZE
296 * and the value of \c MBEDTLS_ENTROPY_MIN_PLATFORM
297 * in `library/entropy_poll.h` in the Mbed TLS source
298 * code.
Netanel Gonen596e65e2018-11-22 18:41:43 +0200299 * It must be less or equal to
300 * #MBEDTLS_ENTROPY_MAX_SEED_SIZE.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200301 *
302 * \retval #PSA_SUCCESS
Gilles Peskine0338ded2018-11-15 18:19:27 +0100303 * The seed value was injected successfully. The random generator
304 * of the PSA Crypto implementation is now ready for use.
305 * You may now call psa_crypto_init() and use the PSA Crypto
306 * implementation.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200307 * \retval #PSA_ERROR_INVALID_ARGUMENT
Gilles Peskineee2ffd32018-11-16 11:02:49 +0100308 * \p seed_size is out of range.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200309 * \retval #PSA_ERROR_STORAGE_FAILURE
Gilles Peskine0338ded2018-11-15 18:19:27 +0100310 * There was a failure reading or writing from storage.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200311 * \retval #PSA_ERROR_NOT_PERMITTED
Gilles Peskine0338ded2018-11-15 18:19:27 +0100312 * The library has already been initialized. It is no longer
313 * possible to call this function.
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200314 */
Jaeden Ameroc7529c92019-08-19 11:08:04 +0100315psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
Netanel Gonen2bcd3122018-11-19 11:53:02 +0200316 size_t seed_size);
317
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200318/** \addtogroup crypto_types
319 * @{
320 */
321
Gilles Peskinea1302192019-05-16 13:58:24 +0200322/** DSA public key.
323 *
324 * The import and export format is the
325 * representation of the public key `y = g^x mod p` as a big-endian byte
326 * string. The length of the byte string is the length of the base prime `p`
327 * in bytes.
328 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100329#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t) 0x4002)
Gilles Peskinea1302192019-05-16 13:58:24 +0200330
331/** DSA key pair (private and public key).
332 *
333 * The import and export format is the
334 * representation of the private key `x` as a big-endian byte string. The
335 * length of the byte string is the private key size in bytes (leading zeroes
336 * are not stripped).
337 *
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800338 * Deterministic DSA key derivation with psa_generate_derived_key follows
Gilles Peskinea1302192019-05-16 13:58:24 +0200339 * FIPS 186-4 §B.1.2: interpret the byte string as integer
340 * in big-endian order. Discard it if it is not in the range
341 * [0, *N* - 2] where *N* is the boundary of the private key domain
342 * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA,
343 * or the order of the curve's base point for ECC).
344 * Add 1 to the resulting integer and use this as the private key *x*.
345 *
346 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100347#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t) 0x7002)
Gilles Peskinea1302192019-05-16 13:58:24 +0200348
Tom Cosgrovece7f18c2022-07-28 05:50:56 +0100349/** Whether a key type is a DSA key (pair or public-only). */
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200350#define PSA_KEY_TYPE_IS_DSA(type) \
Gilles Peskinec93b80c2019-05-16 19:39:54 +0200351 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200352
Gilles Peskine449bd832023-01-11 14:50:10 +0100353#define PSA_ALG_DSA_BASE ((psa_algorithm_t) 0x06000400)
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200354/** DSA signature with hashing.
355 *
356 * This is the signature scheme defined by FIPS 186-4,
357 * with a random per-message secret number (*k*).
358 *
359 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
360 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
361 * This includes #PSA_ALG_ANY_HASH
362 * when specifying the algorithm in a usage policy.
363 *
364 * \return The corresponding DSA signature algorithm.
365 * \return Unspecified if \p hash_alg is not a supported
366 * hash algorithm.
367 */
368#define PSA_ALG_DSA(hash_alg) \
369 (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
Gilles Peskine449bd832023-01-11 14:50:10 +0100370#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t) 0x06000500)
Gilles Peskine972630e2019-11-29 11:55:48 +0100371#define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200372/** Deterministic DSA signature with hashing.
373 *
374 * This is the deterministic variant defined by RFC 6979 of
375 * the signature scheme defined by FIPS 186-4.
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_DETERMINISTIC_DSA(hash_alg) \
387 (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
388#define PSA_ALG_IS_DSA(alg) \
389 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
390 PSA_ALG_DSA_BASE)
391#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
392 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
393#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
394 (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))
395#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \
396 (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))
397
398
399/* We need to expand the sample definition of this macro from
400 * the API definition. */
Gilles Peskine6d400852021-02-24 21:39:52 +0100401#undef PSA_ALG_IS_VENDOR_HASH_AND_SIGN
402#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) \
403 PSA_ALG_IS_DSA(alg)
Gilles Peskinee38ab1a2019-05-16 13:51:50 +0200404
405/**@}*/
406
Gilles Peskine24f10f82019-05-16 12:18:32 +0200407/** \addtogroup attributes
408 * @{
409 */
410
Przemek Stekiel251e86a2023-02-17 14:30:50 +0100411/** PAKE operation stages. */
Przemek Stekiel1c3cfb42023-01-26 10:35:02 +0100412#define PSA_PAKE_OPERATION_STAGE_SETUP 0
413#define PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS 1
414#define PSA_PAKE_OPERATION_STAGE_COMPUTATION 2
Gilles Peskinedcaefae2019-05-16 12:55:35 +0200415
Gilles Peskine24f10f82019-05-16 12:18:32 +0200416/**@}*/
417
Gilles Peskine5055b232019-12-12 17:49:31 +0100418
Gilles Peskineb8af2282020-11-13 18:00:34 +0100419/** \defgroup psa_external_rng External random generator
420 * @{
421 */
422
423#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
424/** External random generator function, implemented by the platform.
425 *
426 * When the compile-time option #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled,
427 * this function replaces Mbed TLS's entropy and DRBG modules for all
428 * random generation triggered via PSA crypto interfaces.
429 *
Gilles Peskineb663a602020-11-18 15:27:37 +0100430 * \note This random generator must deliver random numbers with cryptographic
431 * quality and high performance. It must supply unpredictable numbers
432 * with a uniform distribution. The implementation of this function
433 * is responsible for ensuring that the random generator is seeded
434 * with sufficient entropy. If you have a hardware TRNG which is slow
435 * or delivers non-uniform output, declare it as an entropy source
436 * with mbedtls_entropy_add_source() instead of enabling this option.
437 *
Gilles Peskineb8af2282020-11-13 18:00:34 +0100438 * \param[in,out] context Pointer to the random generator context.
439 * This is all-bits-zero on the first call
440 * and preserved between successive calls.
441 * \param[out] output Output buffer. On success, this buffer
442 * contains random data with a uniform
443 * distribution.
444 * \param output_size The size of the \p output buffer in bytes.
445 * \param[out] output_length On success, set this value to \p output_size.
446 *
447 * \retval #PSA_SUCCESS
Gilles Peskinee995b9b2020-11-30 12:08:00 +0100448 * Success. The output buffer contains \p output_size bytes of
449 * cryptographic-quality random data, and \c *output_length is
450 * set to \p output_size.
451 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
452 * The random generator requires extra entropy and there is no
453 * way to obtain entropy under current environment conditions.
454 * This error should not happen under normal circumstances since
455 * this function is responsible for obtaining as much entropy as
456 * it needs. However implementations of this function may return
457 * #PSA_ERROR_INSUFFICIENT_ENTROPY if there is no way to obtain
458 * entropy without blocking indefinitely.
Gilles Peskineb8af2282020-11-13 18:00:34 +0100459 * \retval #PSA_ERROR_HARDWARE_FAILURE
Gilles Peskinee995b9b2020-11-30 12:08:00 +0100460 * A failure of the random generator hardware that isn't covered
461 * by #PSA_ERROR_INSUFFICIENT_ENTROPY.
Gilles Peskineb8af2282020-11-13 18:00:34 +0100462 */
463psa_status_t mbedtls_psa_external_get_random(
464 mbedtls_psa_external_random_context_t *context,
Gilles Peskine449bd832023-01-11 14:50:10 +0100465 uint8_t *output, size_t output_size, size_t *output_length);
Gilles Peskineb8af2282020-11-13 18:00:34 +0100466#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
467
468/**@}*/
469
Steven Cooreman6801f082021-02-19 17:21:22 +0100470/** \defgroup psa_builtin_keys Built-in keys
471 * @{
472 */
473
474/** The minimum value for a key identifier that is built into the
475 * implementation.
476 *
477 * The range of key identifiers from #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN
478 * to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX within the range from
479 * #PSA_KEY_ID_VENDOR_MIN and #PSA_KEY_ID_VENDOR_MAX and must not intersect
480 * with any other set of implementation-chosen key identifiers.
481 *
482 * This value is part of the library's ABI since changing it would invalidate
483 * the values of built-in key identifiers in applications.
484 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100485#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t) 0x7fff0000)
Steven Cooreman6801f082021-02-19 17:21:22 +0100486
487/** The maximum value for a key identifier that is built into the
488 * implementation.
489 *
490 * See #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN for more information.
491 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100492#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t) 0x7fffefff)
Steven Cooreman6801f082021-02-19 17:21:22 +0100493
494/** A slot number identifying a key in a driver.
495 *
496 * Values of this type are used to identify built-in keys.
497 */
498typedef uint64_t psa_drv_slot_number_t;
499
500#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
501/** Test whether a key identifier belongs to the builtin key range.
502 *
503 * \param key_id Key identifier to test.
504 *
505 * \retval 1
506 * The key identifier is a builtin key identifier.
507 * \retval 0
508 * The key identifier is not a builtin key identifier.
509 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100510static inline int psa_key_id_is_builtin(psa_key_id_t key_id)
Steven Cooreman6801f082021-02-19 17:21:22 +0100511{
Gilles Peskine449bd832023-01-11 14:50:10 +0100512 return (key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN) &&
513 (key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX);
Steven Cooreman6801f082021-02-19 17:21:22 +0100514}
515
Steven Cooremanb938b0b2021-04-06 13:08:42 +0200516/** Platform function to obtain the location and slot number of a built-in key.
Steven Cooreman6801f082021-02-19 17:21:22 +0100517 *
518 * An application-specific implementation of this function must be provided if
Steven Cooreman203bcbb2021-03-18 17:17:40 +0100519 * #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided
Steven Cooreman6801f082021-02-19 17:21:22 +0100520 * as part of a platform's system image.
521 *
Steven Cooremanc8b95342021-03-18 20:48:06 +0100522 * #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from
Steven Cooreman6801f082021-02-19 17:21:22 +0100523 * #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX.
524 *
525 * In a multi-application configuration
526 * (\c MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined),
527 * this function should check that #MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(\p key_id)
528 * is allowed to use the given key.
529 *
Steven Cooremanc8b95342021-03-18 20:48:06 +0100530 * \param key_id The key ID for which to retrieve the
531 * location and slot attributes.
532 * \param[out] lifetime On success, the lifetime associated with the key
533 * corresponding to \p key_id. Lifetime is a
534 * combination of which driver contains the key,
Steven Cooreman31e27af2021-04-14 10:32:05 +0200535 * and with what persistence level the key is
536 * intended to be used. If the platform
537 * implementation does not contain specific
538 * information about the intended key persistence
539 * level, the persistence level may be reported as
540 * #PSA_KEY_PERSISTENCE_DEFAULT.
Steven Cooremanc8b95342021-03-18 20:48:06 +0100541 * \param[out] slot_number On success, the slot number known to the driver
542 * registered at the lifetime location reported
Steven Cooremanb938b0b2021-04-06 13:08:42 +0200543 * through \p lifetime which corresponds to the
Steven Cooreman6801f082021-02-19 17:21:22 +0100544 * requested built-in key.
545 *
546 * \retval #PSA_SUCCESS
547 * The requested key identifier designates a built-in key.
548 * In a multi-application configuration, the requested owner
549 * is allowed to access it.
550 * \retval #PSA_ERROR_DOES_NOT_EXIST
551 * The requested key identifier is not a built-in key which is known
552 * to this function. If a key exists in the key storage with this
553 * identifier, the data from the storage will be used.
Steven Cooreman203bcbb2021-03-18 17:17:40 +0100554 * \return (any other error)
Steven Cooreman6801f082021-02-19 17:21:22 +0100555 * Any other error is propagated to the function that requested the key.
556 * Common errors include:
557 * - #PSA_ERROR_NOT_PERMITTED: the key exists but the requested owner
558 * is not allowed to access it.
559 */
560psa_status_t mbedtls_psa_platform_get_builtin_key(
Steven Cooremanc8b95342021-03-18 20:48:06 +0100561 mbedtls_svc_key_id_t key_id,
562 psa_key_lifetime_t *lifetime,
Gilles Peskine449bd832023-01-11 14:50:10 +0100563 psa_drv_slot_number_t *slot_number);
Steven Cooreman6801f082021-02-19 17:21:22 +0100564#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
565
566/** @} */
567
Janos Follath702cf092021-05-26 12:58:23 +0100568/** \addtogroup crypto_types
569 * @{
570 */
571
Gilles Peskine449bd832023-01-11 14:50:10 +0100572#define PSA_ALG_CATEGORY_PAKE ((psa_algorithm_t) 0x0a000000)
Janos Follath702cf092021-05-26 12:58:23 +0100573
574/** Whether the specified algorithm is a password-authenticated key exchange.
575 *
576 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
577 *
578 * \return 1 if \p alg is a password-authenticated key exchange (PAKE)
579 * algorithm, 0 otherwise.
580 * This macro may return either 0 or 1 if \p alg is not a supported
581 * algorithm identifier.
582 */
583#define PSA_ALG_IS_PAKE(alg) \
584 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_PAKE)
585
586/** The Password-authenticated key exchange by juggling (J-PAKE) algorithm.
587 *
588 * This is J-PAKE as defined by RFC 8236, instantiated with the following
589 * parameters:
590 *
591 * - The group can be either an elliptic curve or defined over a finite field.
592 * - Schnorr NIZK proof as defined by RFC 8235 and using the same group as the
593 * J-PAKE algorithm.
Janos Follath46c02372021-06-08 15:22:51 +0100594 * - A cryptographic hash function.
Janos Follath702cf092021-05-26 12:58:23 +0100595 *
Janos Follath46c02372021-06-08 15:22:51 +0100596 * To select these parameters and set up the cipher suite, call these functions
597 * in any order:
Janos Follathb384ec12021-06-03 14:48:51 +0100598 *
599 * \code
600 * psa_pake_cs_set_algorithm(cipher_suite, PSA_ALG_JPAKE);
601 * psa_pake_cs_set_primitive(cipher_suite,
602 * PSA_PAKE_PRIMITIVE(type, family, bits));
603 * psa_pake_cs_set_hash(cipher_suite, hash);
604 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100605 *
606 * For more information on how to set a specific curve or field, refer to the
607 * documentation of the individual \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.
608 *
609 * After initializing a J-PAKE operation, call
Janos Follathb384ec12021-06-03 14:48:51 +0100610 *
611 * \code
612 * psa_pake_setup(operation, cipher_suite);
613 * psa_pake_set_user(operation, ...);
614 * psa_pake_set_peer(operation, ...);
615 * psa_pake_set_password_key(operation, ...);
616 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100617 *
Neil Armstrong16145372022-05-20 10:42:36 +0200618 * The password is provided as a key. This can be the password text itself,
619 * in an agreed character encoding, or some value derived from the password
620 * as required by a higher level protocol.
Janos Follath702cf092021-05-26 12:58:23 +0100621 *
Neil Armstrong16145372022-05-20 10:42:36 +0200622 * (The implementation converts the key material to a number as described in
Janos Follath702cf092021-05-26 12:58:23 +0100623 * Section 2.3.8 of _SEC 1: Elliptic Curve Cryptography_
624 * (https://www.secg.org/sec1-v2.pdf), before reducing it modulo \c q. Here
625 * \c q is order of the group defined by the primitive set in the cipher suite.
Neil Armstrong5892aa62022-05-27 09:44:47 +0200626 * The \c psa_pake_set_password_key() function returns an error if the result
Janos Follath702cf092021-05-26 12:58:23 +0100627 * of the reduction is 0.)
628 *
629 * The key exchange flow for J-PAKE is as follows:
630 * -# To get the first round data that needs to be sent to the peer, call
Janos Follathb384ec12021-06-03 14:48:51 +0100631 * \code
632 * // Get g1
633 * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
634 * // Get the ZKP public key for x1
635 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
636 * // Get the ZKP proof for x1
637 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
638 * // Get g2
639 * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
640 * // Get the ZKP public key for x2
641 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
642 * // Get the ZKP proof for x2
643 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
644 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100645 * -# To provide the first round data received from the peer to the operation,
646 * call
Janos Follathb384ec12021-06-03 14:48:51 +0100647 * \code
648 * // Set g3
649 * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
650 * // Set the ZKP public key for x3
651 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
652 * // Set the ZKP proof for x3
653 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
654 * // Set g4
655 * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
656 * // Set the ZKP public key for x4
657 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
658 * // Set the ZKP proof for x4
659 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
660 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100661 * -# To get the second round data that needs to be sent to the peer, call
Janos Follathb384ec12021-06-03 14:48:51 +0100662 * \code
663 * // Get A
664 * psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
665 * // Get ZKP public key for x2*s
666 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
667 * // Get ZKP proof for x2*s
668 * psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
669 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100670 * -# To provide the second round data received from the peer to the operation,
671 * call
Janos Follathb384ec12021-06-03 14:48:51 +0100672 * \code
673 * // Set B
674 * psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);
675 * // Set ZKP public key for x4*s
676 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);
677 * // Set ZKP proof for x4*s
678 * psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);
679 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100680 * -# To access the shared secret call
Janos Follathb384ec12021-06-03 14:48:51 +0100681 * \code
682 * // Get Ka=Kb=K
683 * psa_pake_get_implicit_key()
684 * \endcode
Janos Follath702cf092021-05-26 12:58:23 +0100685 *
686 * For more information consult the documentation of the individual
687 * \c PSA_PAKE_STEP_XXX constants.
688 *
689 * At this point there is a cryptographic guarantee that only the authenticated
690 * party who used the same password is able to compute the key. But there is no
Janos Follatha46e28f2021-06-03 13:07:03 +0100691 * guarantee that the peer is the party it claims to be and was able to do so.
Janos Follath702cf092021-05-26 12:58:23 +0100692 *
693 * That is, the authentication is only implicit (the peer is not authenticated
694 * at this point, and no action should be taken that assume that they are - like
695 * for example accessing restricted files).
696 *
697 * To make the authentication explicit there are various methods, see Section 5
698 * of RFC 8236 for two examples.
699 *
700 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100701#define PSA_ALG_JPAKE ((psa_algorithm_t) 0x0a000100)
Janos Follath702cf092021-05-26 12:58:23 +0100702
703/** @} */
704
705/** \defgroup pake Password-authenticated key exchange (PAKE)
Janos Follath7d69b3a2021-05-26 13:10:56 +0100706 *
707 * This is a proposed PAKE interface for the PSA Crypto API. It is not part of
708 * the official PSA Crypto API yet.
709 *
710 * \note The content of this section is not part of the stable API and ABI
Fredrik Hessecc207bc2021-09-28 21:06:08 +0200711 * of Mbed TLS and may change arbitrarily from version to version.
Janos Follath7d69b3a2021-05-26 13:10:56 +0100712 * Same holds for the corresponding macros #PSA_ALG_CATEGORY_PAKE and
713 * #PSA_ALG_JPAKE.
Janos Follath702cf092021-05-26 12:58:23 +0100714 * @{
715 */
716
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200717/** \brief Encoding of the application role of PAKE
Janos Follath702cf092021-05-26 12:58:23 +0100718 *
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200719 * Encodes the application's role in the algorithm is being executed. For more
720 * information see the documentation of individual \c PSA_PAKE_ROLE_XXX
721 * constants.
Janos Follath702cf092021-05-26 12:58:23 +0100722 */
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200723typedef uint8_t psa_pake_role_t;
Janos Follath702cf092021-05-26 12:58:23 +0100724
725/** Encoding of input and output indicators for PAKE.
726 *
727 * Some PAKE algorithms need to exchange more data than just a single key share.
728 * This type is for encoding additional input and output data for such
729 * algorithms.
730 */
731typedef uint8_t psa_pake_step_t;
732
733/** Encoding of the type of the PAKE's primitive.
734 *
735 * Values defined by this standard will never be in the range 0x80-0xff.
736 * Vendors who define additional types must use an encoding in this range.
737 *
738 * For more information see the documentation of individual
739 * \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.
740 */
741typedef uint8_t psa_pake_primitive_type_t;
742
743/** \brief Encoding of the family of the primitive associated with the PAKE.
744 *
745 * For more information see the documentation of individual
746 * \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.
747 */
748typedef uint8_t psa_pake_family_t;
749
750/** \brief Encoding of the primitive associated with the PAKE.
751 *
752 * For more information see the documentation of the #PSA_PAKE_PRIMITIVE macro.
753 */
754typedef uint32_t psa_pake_primitive_t;
755
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200756/** A value to indicate no role in a PAKE algorithm.
757 * This value can be used in a call to psa_pake_set_role() for symmetric PAKE
758 * algorithms which do not assign roles.
759 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100760#define PSA_PAKE_ROLE_NONE ((psa_pake_role_t) 0x00)
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200761
Janos Follath702cf092021-05-26 12:58:23 +0100762/** The first peer in a balanced PAKE.
763 *
764 * Although balanced PAKE algorithms are symmetric, some of them needs an
765 * ordering of peers for the transcript calculations. If the algorithm does not
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200766 * need this, both #PSA_PAKE_ROLE_FIRST and #PSA_PAKE_ROLE_SECOND are
Janos Follath702cf092021-05-26 12:58:23 +0100767 * accepted.
768 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100769#define PSA_PAKE_ROLE_FIRST ((psa_pake_role_t) 0x01)
Janos Follath702cf092021-05-26 12:58:23 +0100770
771/** The second peer in a balanced PAKE.
772 *
773 * Although balanced PAKE algorithms are symmetric, some of them needs an
774 * ordering of peers for the transcript calculations. If the algorithm does not
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +0200775 * need this, either #PSA_PAKE_ROLE_FIRST or #PSA_PAKE_ROLE_SECOND are
Janos Follath702cf092021-05-26 12:58:23 +0100776 * accepted.
777 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100778#define PSA_PAKE_ROLE_SECOND ((psa_pake_role_t) 0x02)
Janos Follath702cf092021-05-26 12:58:23 +0100779
780/** The client in an augmented PAKE.
781 *
782 * Augmented PAKE algorithms need to differentiate between client and server.
783 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100784#define PSA_PAKE_ROLE_CLIENT ((psa_pake_role_t) 0x11)
Janos Follath702cf092021-05-26 12:58:23 +0100785
786/** The server in an augmented PAKE.
787 *
788 * Augmented PAKE algorithms need to differentiate between client and server.
789 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100790#define PSA_PAKE_ROLE_SERVER ((psa_pake_role_t) 0x12)
Janos Follath702cf092021-05-26 12:58:23 +0100791
792/** The PAKE primitive type indicating the use of elliptic curves.
793 *
794 * The values of the \c family and \c bits fields of the cipher suite identify a
795 * specific elliptic curve, using the same mapping that is used for ECC
796 * (::psa_ecc_family_t) keys.
797 *
798 * (Here \c family means the value returned by psa_pake_cs_get_family() and
799 * \c bits means the value returned by psa_pake_cs_get_bits().)
800 *
801 * Input and output during the operation can involve group elements and scalar
802 * values:
803 * -# The format for group elements is the same as for public keys on the
804 * specific curve would be. For more information, consult the documentation of
805 * psa_export_public_key().
806 * -# The format for scalars is the same as for private keys on the specific
807 * curve would be. For more information, consult the documentation of
808 * psa_export_key().
809 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100810#define PSA_PAKE_PRIMITIVE_TYPE_ECC ((psa_pake_primitive_type_t) 0x01)
Janos Follath702cf092021-05-26 12:58:23 +0100811
812/** The PAKE primitive type indicating the use of Diffie-Hellman groups.
813 *
814 * The values of the \c family and \c bits fields of the cipher suite identify
815 * a specific Diffie-Hellman group, using the same mapping that is used for
816 * Diffie-Hellman (::psa_dh_family_t) keys.
817 *
818 * (Here \c family means the value returned by psa_pake_cs_get_family() and
819 * \c bits means the value returned by psa_pake_cs_get_bits().)
820 *
821 * Input and output during the operation can involve group elements and scalar
822 * values:
823 * -# The format for group elements is the same as for public keys on the
824 * specific group would be. For more information, consult the documentation of
825 * psa_export_public_key().
826 * -# The format for scalars is the same as for private keys on the specific
827 * group would be. For more information, consult the documentation of
828 * psa_export_key().
829 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100830#define PSA_PAKE_PRIMITIVE_TYPE_DH ((psa_pake_primitive_type_t) 0x02)
Janos Follath702cf092021-05-26 12:58:23 +0100831
832/** Construct a PAKE primitive from type, family and bit-size.
833 *
834 * \param pake_type The type of the primitive
835 * (value of type ::psa_pake_primitive_type_t).
836 * \param pake_family The family of the primitive
837 * (the type and interpretation of this parameter depends
Andrzej Kurek3bedb5b2022-02-17 14:39:00 -0500838 * on \p pake_type, for more information consult the
Janos Follath702cf092021-05-26 12:58:23 +0100839 * documentation of individual ::psa_pake_primitive_type_t
840 * constants).
841 * \param pake_bits The bit-size of the primitive
842 * (Value of type \c size_t. The interpretation
Andrzej Kurek3bedb5b2022-02-17 14:39:00 -0500843 * of this parameter depends on \p pake_family, for more
Janos Follath702cf092021-05-26 12:58:23 +0100844 * information consult the documentation of individual
845 * ::psa_pake_primitive_type_t constants).
846 *
847 * \return The constructed primitive value of type ::psa_pake_primitive_t.
848 * Return 0 if the requested primitive can't be encoded as
849 * ::psa_pake_primitive_t.
850 */
851#define PSA_PAKE_PRIMITIVE(pake_type, pake_family, pake_bits) \
852 ((pake_bits & 0xFFFF) != pake_bits) ? 0 : \
853 ((psa_pake_primitive_t) (((pake_type) << 24 | \
Gilles Peskine449bd832023-01-11 14:50:10 +0100854 (pake_family) << 16) | (pake_bits)))
Janos Follath702cf092021-05-26 12:58:23 +0100855
856/** The key share being sent to or received from the peer.
857 *
858 * The format for both input and output at this step is the same as for public
859 * keys on the group determined by the primitive (::psa_pake_primitive_t) would
860 * be.
861 *
862 * For more information on the format, consult the documentation of
863 * psa_export_public_key().
864 *
865 * For information regarding how the group is determined, consult the
866 * documentation #PSA_PAKE_PRIMITIVE.
867 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100868#define PSA_PAKE_STEP_KEY_SHARE ((psa_pake_step_t) 0x01)
Janos Follath702cf092021-05-26 12:58:23 +0100869
870/** A Schnorr NIZKP public key.
871 *
Janos Follath55dd5dc2021-06-03 15:51:09 +0100872 * This is the ephemeral public key in the Schnorr Non-Interactive
873 * Zero-Knowledge Proof (the value denoted by the letter 'V' in RFC 8235).
874 *
Janos Follath702cf092021-05-26 12:58:23 +0100875 * The format for both input and output at this step is the same as for public
876 * keys on the group determined by the primitive (::psa_pake_primitive_t) would
877 * be.
878 *
879 * For more information on the format, consult the documentation of
880 * psa_export_public_key().
881 *
882 * For information regarding how the group is determined, consult the
883 * documentation #PSA_PAKE_PRIMITIVE.
884 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100885#define PSA_PAKE_STEP_ZK_PUBLIC ((psa_pake_step_t) 0x02)
Janos Follath702cf092021-05-26 12:58:23 +0100886
887/** A Schnorr NIZKP proof.
888 *
Janos Follath55dd5dc2021-06-03 15:51:09 +0100889 * This is the proof in the Schnorr Non-Interactive Zero-Knowledge Proof (the
890 * value denoted by the letter 'r' in RFC 8235).
Janos Follath702cf092021-05-26 12:58:23 +0100891 *
Janos Follath1f013182021-06-08 15:30:48 +0100892 * Both for input and output, the value at this step is an integer less than
893 * the order of the group selected in the cipher suite. The format depends on
894 * the group as well:
Janos Follath702cf092021-05-26 12:58:23 +0100895 *
Janos Follath1f013182021-06-08 15:30:48 +0100896 * - For Montgomery curves, the encoding is little endian.
Janos Follath55dd5dc2021-06-03 15:51:09 +0100897 * - For everything else the encoding is big endian (see Section 2.3.8 of
898 * _SEC 1: Elliptic Curve Cryptography_ at https://www.secg.org/sec1-v2.pdf).
Janos Follath702cf092021-05-26 12:58:23 +0100899 *
Janos Follath1f013182021-06-08 15:30:48 +0100900 * In both cases leading zeroes are allowed as long as the length in bytes does
901 * not exceed the byte length of the group order.
902 *
Janos Follath702cf092021-05-26 12:58:23 +0100903 * For information regarding how the group is determined, consult the
904 * documentation #PSA_PAKE_PRIMITIVE.
905 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100906#define PSA_PAKE_STEP_ZK_PROOF ((psa_pake_step_t) 0x03)
Janos Follath702cf092021-05-26 12:58:23 +0100907
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800908/** The type of the data structure for PAKE cipher suites.
Janos Follath702cf092021-05-26 12:58:23 +0100909 *
910 * This is an implementation-defined \c struct. Applications should not
911 * make any assumptions about the content of this structure.
912 * Implementation details can change in future versions without notice.
913 */
914typedef struct psa_pake_cipher_suite_s psa_pake_cipher_suite_t;
915
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +0200916/** Return an initial value for a PAKE cipher suite object.
917 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100918static psa_pake_cipher_suite_t psa_pake_cipher_suite_init(void);
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +0200919
Janos Follath702cf092021-05-26 12:58:23 +0100920/** Retrieve the PAKE algorithm from a PAKE cipher suite.
921 *
Janos Follath702cf092021-05-26 12:58:23 +0100922 * \param[in] cipher_suite The cipher suite structure to query.
923 *
924 * \return The PAKE algorithm stored in the cipher suite structure.
925 */
926static psa_algorithm_t psa_pake_cs_get_algorithm(
Gilles Peskine449bd832023-01-11 14:50:10 +0100927 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +0100928
929/** Declare the PAKE algorithm for the cipher suite.
930 *
931 * This function overwrites any PAKE algorithm
932 * previously set in \p cipher_suite.
933 *
Janos Follath702cf092021-05-26 12:58:23 +0100934 * \param[out] cipher_suite The cipher suite structure to write to.
935 * \param algorithm The PAKE algorithm to write.
936 * (`PSA_ALG_XXX` values of type ::psa_algorithm_t
937 * such that #PSA_ALG_IS_PAKE(\c alg) is true.)
938 * If this is 0, the PAKE algorithm in
939 * \p cipher_suite becomes unspecified.
940 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100941static void psa_pake_cs_set_algorithm(psa_pake_cipher_suite_t *cipher_suite,
942 psa_algorithm_t algorithm);
Janos Follath702cf092021-05-26 12:58:23 +0100943
944/** Retrieve the primitive from a PAKE cipher suite.
945 *
Janos Follath702cf092021-05-26 12:58:23 +0100946 * \param[in] cipher_suite The cipher suite structure to query.
947 *
948 * \return The primitive stored in the cipher suite structure.
949 */
950static psa_pake_primitive_t psa_pake_cs_get_primitive(
Gilles Peskine449bd832023-01-11 14:50:10 +0100951 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +0100952
953/** Declare the primitive for a PAKE cipher suite.
954 *
955 * This function overwrites any primitive previously set in \p cipher_suite.
956 *
Janos Follath702cf092021-05-26 12:58:23 +0100957 * \param[out] cipher_suite The cipher suite structure to write to.
958 * \param primitive The primitive to write. If this is 0, the
959 * primitive type in \p cipher_suite becomes
960 * unspecified.
961 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100962static void psa_pake_cs_set_primitive(psa_pake_cipher_suite_t *cipher_suite,
963 psa_pake_primitive_t primitive);
Janos Follath702cf092021-05-26 12:58:23 +0100964
Neil Armstrongff9cac72022-05-20 10:25:15 +0200965/** Retrieve the PAKE family from a PAKE cipher suite.
966 *
Neil Armstrongff9cac72022-05-20 10:25:15 +0200967 * \param[in] cipher_suite The cipher suite structure to query.
968 *
969 * \return The PAKE family stored in the cipher suite structure.
970 */
971static psa_pake_family_t psa_pake_cs_get_family(
Gilles Peskine449bd832023-01-11 14:50:10 +0100972 const psa_pake_cipher_suite_t *cipher_suite);
Neil Armstrongff9cac72022-05-20 10:25:15 +0200973
Neil Armstrongd5a48252022-05-20 10:26:36 +0200974/** Retrieve the PAKE primitive bit-size from a PAKE cipher suite.
975 *
Neil Armstrongd5a48252022-05-20 10:26:36 +0200976 * \param[in] cipher_suite The cipher suite structure to query.
977 *
978 * \return The PAKE primitive bit-size stored in the cipher suite structure.
979 */
980static uint16_t psa_pake_cs_get_bits(
Gilles Peskine449bd832023-01-11 14:50:10 +0100981 const psa_pake_cipher_suite_t *cipher_suite);
Neil Armstrongd5a48252022-05-20 10:26:36 +0200982
Janos Follath702cf092021-05-26 12:58:23 +0100983/** Retrieve the hash algorithm from a PAKE cipher suite.
984 *
Janos Follath702cf092021-05-26 12:58:23 +0100985 * \param[in] cipher_suite The cipher suite structure to query.
986 *
987 * \return The hash algorithm stored in the cipher suite structure. The return
988 * value is 0 if the PAKE is not parametrised by a hash algorithm or if
989 * the hash algorithm is not set.
990 */
991static psa_algorithm_t psa_pake_cs_get_hash(
Gilles Peskine449bd832023-01-11 14:50:10 +0100992 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +0100993
994/** Declare the hash algorithm for a PAKE cipher suite.
995 *
996 * This function overwrites any hash algorithm
997 * previously set in \p cipher_suite.
998 *
Janos Follath702cf092021-05-26 12:58:23 +0100999 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1000 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1001 * for more information.
1002 *
1003 * \param[out] cipher_suite The cipher suite structure to write to.
1004 * \param hash The hash involved in the cipher suite.
1005 * (`PSA_ALG_XXX` values of type ::psa_algorithm_t
1006 * such that #PSA_ALG_IS_HASH(\c alg) is true.)
1007 * If this is 0, the hash algorithm in
1008 * \p cipher_suite becomes unspecified.
1009 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001010static void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite,
1011 psa_algorithm_t hash);
Janos Follath702cf092021-05-26 12:58:23 +01001012
1013/** The type of the state data structure for PAKE operations.
1014 *
1015 * Before calling any function on a PAKE operation object, the application
1016 * must initialize it by any of the following means:
1017 * - Set the structure to all-bits-zero, for example:
1018 * \code
1019 * psa_pake_operation_t operation;
1020 * memset(&operation, 0, sizeof(operation));
1021 * \endcode
1022 * - Initialize the structure to logical zero values, for example:
1023 * \code
1024 * psa_pake_operation_t operation = {0};
1025 * \endcode
1026 * - Initialize the structure to the initializer #PSA_PAKE_OPERATION_INIT,
1027 * for example:
1028 * \code
1029 * psa_pake_operation_t operation = PSA_PAKE_OPERATION_INIT;
1030 * \endcode
1031 * - Assign the result of the function psa_pake_operation_init()
1032 * to the structure, for example:
1033 * \code
1034 * psa_pake_operation_t operation;
1035 * operation = psa_pake_operation_init();
1036 * \endcode
1037 *
1038 * This is an implementation-defined \c struct. Applications should not
1039 * make any assumptions about the content of this structure.
1040 * Implementation details can change in future versions without notice. */
1041typedef struct psa_pake_operation_s psa_pake_operation_t;
1042
Przemek Stekiel51eac532022-12-07 11:04:51 +01001043/** The type of input values for PAKE operations. */
1044typedef struct psa_crypto_driver_pake_inputs_s psa_crypto_driver_pake_inputs_t;
1045
Przemek Stekielb09c4872023-01-17 12:05:38 +01001046/** The type of computation stage for J-PAKE operations. */
Przemek Stekiele12ed362022-12-21 12:54:46 +01001047typedef struct psa_jpake_computation_stage_s psa_jpake_computation_stage_t;
1048
Tom Cosgrovece7f18c2022-07-28 05:50:56 +01001049/** Return an initial value for a PAKE operation object.
Janos Follath702cf092021-05-26 12:58:23 +01001050 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001051static psa_pake_operation_t psa_pake_operation_init(void);
Janos Follath702cf092021-05-26 12:58:23 +01001052
Przemek Stekielc0e62502023-03-14 11:49:36 +01001053/** Get the length of the password in bytes from given inputs.
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001054 *
1055 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001056 * \param[out] password_len Password length.
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001057 *
1058 * \retval #PSA_SUCCESS
1059 * Success.
1060 * \retval #PSA_ERROR_BAD_STATE
1061 * Password hasn't been set yet.
1062 */
1063psa_status_t psa_crypto_driver_pake_get_password_len(
1064 const psa_crypto_driver_pake_inputs_t *inputs,
1065 size_t *password_len);
1066
1067/** Get the password from given inputs.
1068 *
1069 * \param[in] inputs Operation inputs.
1070 * \param[out] buffer Return buffer for password.
Przemek Stekiel6b648622023-02-19 22:55:33 +01001071 * \param buffer_size Size of the return buffer in bytes.
1072 * \param[out] buffer_length Actual size of the password in bytes.
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001073 *
1074 * \retval #PSA_SUCCESS
1075 * Success.
1076 * \retval #PSA_ERROR_BAD_STATE
1077 * Password hasn't been set yet.
1078 */
1079psa_status_t psa_crypto_driver_pake_get_password(
1080 const psa_crypto_driver_pake_inputs_t *inputs,
1081 uint8_t *buffer, size_t buffer_size, size_t *buffer_length);
1082
Przemek Stekielc0e62502023-03-14 11:49:36 +01001083/** Get the length of the user id in bytes from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001084 *
1085 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001086 * \param[out] user_len User id length.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001087 *
1088 * \retval #PSA_SUCCESS
1089 * Success.
1090 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001091 * User id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001092 */
1093psa_status_t psa_crypto_driver_pake_get_user_len(
1094 const psa_crypto_driver_pake_inputs_t *inputs,
1095 size_t *user_len);
1096
Przemek Stekielc0e62502023-03-14 11:49:36 +01001097/** Get the length of the peer id in bytes from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001098 *
1099 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001100 * \param[out] peer_len Peer id length.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001101 *
1102 * \retval #PSA_SUCCESS
1103 * Success.
1104 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001105 * Peer id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001106 */
1107psa_status_t psa_crypto_driver_pake_get_peer_len(
1108 const psa_crypto_driver_pake_inputs_t *inputs,
1109 size_t *peer_len);
1110
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001111/** Get the user id from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001112 *
1113 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001114 * \param[out] user_id User id.
1115 * \param user_id_size Size of \p user_id in bytes.
1116 * \param[out] user_id_len Size of the user id in bytes.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001117 *
1118 * \retval #PSA_SUCCESS
1119 * Success.
1120 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001121 * User id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001122 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
Przemek Stekielc0e62502023-03-14 11:49:36 +01001123 * The size of the \p user_id is too small.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001124 */
1125psa_status_t psa_crypto_driver_pake_get_user(
1126 const psa_crypto_driver_pake_inputs_t *inputs,
Przemek Stekielc0e62502023-03-14 11:49:36 +01001127 uint8_t *user_id, size_t user_id_size, size_t *user_id_len);
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001128
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001129/** Get the peer id from given inputs.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001130 *
1131 * \param[in] inputs Operation inputs.
Przemek Stekielc0e62502023-03-14 11:49:36 +01001132 * \param[out] peer_id Peer id.
1133 * \param peer_id_size Size of \p peer_id in bytes.
1134 * \param[out] peer_id_length Size of the peer id in bytes.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001135 *
1136 * \retval #PSA_SUCCESS
1137 * Success.
1138 * \retval #PSA_ERROR_BAD_STATE
Przemek Stekield7f6ad72023-03-06 13:39:52 +01001139 * Peer id hasn't been set yet.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001140 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
Przemek Stekielc0e62502023-03-14 11:49:36 +01001141 * The size of the \p peer_id is too small.
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001142 */
1143psa_status_t psa_crypto_driver_pake_get_peer(
1144 const psa_crypto_driver_pake_inputs_t *inputs,
Przemek Stekielc0e62502023-03-14 11:49:36 +01001145 uint8_t *peer_id, size_t peer_id_size, size_t *peer_id_length);
Przemek Stekiel1e7a9272023-02-28 14:38:58 +01001146
Przemek Stekielca8d2b22023-01-17 16:21:33 +01001147/** Get the cipher suite from given inputs.
1148 *
1149 * \param[in] inputs Operation inputs.
1150 * \param[out] cipher_suite Return buffer for role.
1151 *
1152 * \retval #PSA_SUCCESS
1153 * Success.
1154 * \retval #PSA_ERROR_BAD_STATE
1155 * Cipher_suite hasn't been set yet.
1156 */
1157psa_status_t psa_crypto_driver_pake_get_cipher_suite(
1158 const psa_crypto_driver_pake_inputs_t *inputs,
1159 psa_pake_cipher_suite_t *cipher_suite);
1160
Janos Follath702cf092021-05-26 12:58:23 +01001161/** Set the session information for a password-authenticated key exchange.
1162 *
1163 * The sequence of operations to set up a password-authenticated key exchange
1164 * is as follows:
1165 * -# Allocate an operation object which will be passed to all the functions
1166 * listed here.
1167 * -# Initialize the operation object with one of the methods described in the
1168 * documentation for #psa_pake_operation_t, e.g.
1169 * #PSA_PAKE_OPERATION_INIT.
1170 * -# Call psa_pake_setup() to specify the cipher suite.
1171 * -# Call \c psa_pake_set_xxx() functions on the operation to complete the
1172 * setup. The exact sequence of \c psa_pake_set_xxx() functions that needs
1173 * to be called depends on the algorithm in use.
1174 *
1175 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1176 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1177 * for more information.
1178 *
1179 * A typical sequence of calls to perform a password-authenticated key
1180 * exchange:
1181 * -# Call psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to get the
1182 * key share that needs to be sent to the peer.
1183 * -# Call psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to provide
1184 * the key share that was received from the peer.
1185 * -# Depending on the algorithm additional calls to psa_pake_output() and
1186 * psa_pake_input() might be necessary.
1187 * -# Call psa_pake_get_implicit_key() for accessing the shared secret.
1188 *
1189 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1190 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1191 * for more information.
1192 *
1193 * If an error occurs at any step after a call to psa_pake_setup(),
1194 * the operation will need to be reset by a call to psa_pake_abort(). The
1195 * application may call psa_pake_abort() at any time after the operation
1196 * has been initialized.
1197 *
1198 * After a successful call to psa_pake_setup(), the application must
1199 * eventually terminate the operation. The following events terminate an
1200 * operation:
1201 * - A call to psa_pake_abort().
1202 * - A successful call to psa_pake_get_implicit_key().
1203 *
1204 * \param[in,out] operation The operation object to set up. It must have
Janos Follath3293dae2021-06-03 13:21:33 +01001205 * been initialized but not set up yet.
Neil Armstrong47e700e2022-05-20 10:16:41 +02001206 * \param[in] cipher_suite The cipher suite to use. (A cipher suite fully
Janos Follath702cf092021-05-26 12:58:23 +01001207 * characterizes a PAKE algorithm and determines
1208 * the algorithm as well.)
1209 *
1210 * \retval #PSA_SUCCESS
1211 * Success.
Neil Armstrong4721a6f2022-05-20 10:53:00 +02001212 * \retval #PSA_ERROR_INVALID_ARGUMENT
1213 * The algorithm in \p cipher_suite is not a PAKE algorithm, or the
1214 * PAKE primitive in \p cipher_suite is not compatible with the
1215 * PAKE algorithm, or the hash algorithm in \p cipher_suite is invalid
1216 * or not compatible with the PAKE algorithm and primitive.
Janos Follath702cf092021-05-26 12:58:23 +01001217 * \retval #PSA_ERROR_NOT_SUPPORTED
Neil Armstrong4721a6f2022-05-20 10:53:00 +02001218 * The algorithm in \p cipher_suite is not a supported PAKE algorithm,
1219 * or the PAKE primitive in \p cipher_suite is not supported or not
1220 * compatible with the PAKE algorithm, or the hash algorithm in
1221 * \p cipher_suite is not supported or not compatible with the PAKE
1222 * algorithm and primitive.
Gilles Peskineed733552023-02-14 19:21:09 +01001223 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1224 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001225 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001226 * The operation state is not valid, or
1227 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001228 * It is implementation-dependent whether a failure to initialize
1229 * results in this error code.
1230 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001231psa_status_t psa_pake_setup(psa_pake_operation_t *operation,
1232 const psa_pake_cipher_suite_t *cipher_suite);
Janos Follath702cf092021-05-26 12:58:23 +01001233
1234/** Set the password for a password-authenticated key exchange from key ID.
1235 *
1236 * Call this function when the password, or a value derived from the password,
Janos Follath52f9efa2021-05-27 08:40:16 +01001237 * is already present in the key store.
Janos Follath702cf092021-05-26 12:58:23 +01001238 *
1239 * \param[in,out] operation The operation object to set the password for. It
1240 * must have been set up by psa_pake_setup() and
1241 * not yet in use (neither psa_pake_output() nor
1242 * psa_pake_input() has been called yet). It must
1243 * be on operation for which the password hasn't
Janos Follath52f9efa2021-05-27 08:40:16 +01001244 * been set yet (psa_pake_set_password_key()
Janos Follath559f05e2021-05-26 15:44:30 +01001245 * hasn't been called yet).
Janos Follath702cf092021-05-26 12:58:23 +01001246 * \param password Identifier of the key holding the password or a
1247 * value derived from the password (eg. by a
1248 * memory-hard function). It must remain valid
1249 * until the operation terminates. It must be of
1250 * type #PSA_KEY_TYPE_PASSWORD or
1251 * #PSA_KEY_TYPE_PASSWORD_HASH. It has to allow
1252 * the usage #PSA_KEY_USAGE_DERIVE.
1253 *
1254 * \retval #PSA_SUCCESS
1255 * Success.
Janos Follath702cf092021-05-26 12:58:23 +01001256 * \retval #PSA_ERROR_INVALID_HANDLE
Neil Armstrong71cae612022-05-20 11:00:49 +02001257 * \p password is not a valid key identifier.
Janos Follath702cf092021-05-26 12:58:23 +01001258 * \retval #PSA_ERROR_NOT_PERMITTED
Neil Armstrong71cae612022-05-20 11:00:49 +02001259 * The key does not have the #PSA_KEY_USAGE_DERIVE flag, or it does not
1260 * permit the \p operation's algorithm.
1261 * \retval #PSA_ERROR_INVALID_ARGUMENT
1262 * The key type for \p password is not #PSA_KEY_TYPE_PASSWORD or
1263 * #PSA_KEY_TYPE_PASSWORD_HASH, or \p password is not compatible with
1264 * the \p operation's cipher suite.
1265 * \retval #PSA_ERROR_NOT_SUPPORTED
1266 * The key type or key size of \p password is not supported with the
1267 * \p operation's cipher suite.
Gilles Peskineed733552023-02-14 19:21:09 +01001268 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1269 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1270 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1271 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1272 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001273 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001274 * The operation state is not valid (it must have been set up.), or
1275 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001276 * It is implementation-dependent whether a failure to initialize
1277 * results in this error code.
1278 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001279psa_status_t psa_pake_set_password_key(psa_pake_operation_t *operation,
1280 mbedtls_svc_key_id_t password);
Janos Follath702cf092021-05-26 12:58:23 +01001281
Janos Follath702cf092021-05-26 12:58:23 +01001282/** Set the user ID for a password-authenticated key exchange.
1283 *
1284 * Call this function to set the user ID. For PAKE algorithms that associate a
1285 * user identifier with each side of the session you need to call
1286 * psa_pake_set_peer() as well. For PAKE algorithms that associate a single
1287 * user identifier with the session, call psa_pake_set_user() only.
1288 *
1289 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1290 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1291 * for more information.
1292 *
1293 * \param[in,out] operation The operation object to set the user ID for. It
1294 * must have been set up by psa_pake_setup() and
1295 * not yet in use (neither psa_pake_output() nor
1296 * psa_pake_input() has been called yet). It must
1297 * be on operation for which the user ID hasn't
1298 * been set (psa_pake_set_user() hasn't been
1299 * called yet).
1300 * \param[in] user_id The user ID to authenticate with.
1301 * \param user_id_len Size of the \p user_id buffer in bytes.
1302 *
1303 * \retval #PSA_SUCCESS
1304 * Success.
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001305 * \retval #PSA_ERROR_INVALID_ARGUMENT
Neil Armstrong35851682022-05-20 11:02:37 +02001306 * \p user_id is not valid for the \p operation's algorithm and cipher
1307 * suite.
1308 * \retval #PSA_ERROR_NOT_SUPPORTED
1309 * The value of \p user_id is not supported by the implementation.
Gilles Peskineed733552023-02-14 19:21:09 +01001310 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1311 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1312 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001313 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001314 * The operation state is not valid, or
1315 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001316 * It is implementation-dependent whether a failure to initialize
1317 * results in this error code.
1318 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001319psa_status_t psa_pake_set_user(psa_pake_operation_t *operation,
1320 const uint8_t *user_id,
1321 size_t user_id_len);
Janos Follath702cf092021-05-26 12:58:23 +01001322
1323/** Set the peer ID for a password-authenticated key exchange.
1324 *
1325 * Call this function in addition to psa_pake_set_user() for PAKE algorithms
1326 * that associate a user identifier with each side of the session. For PAKE
1327 * algorithms that associate a single user identifier with the session, call
1328 * psa_pake_set_user() only.
1329 *
1330 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1331 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1332 * for more information.
1333 *
1334 * \param[in,out] operation The operation object to set the peer ID for. It
1335 * must have been set up by psa_pake_setup() and
1336 * not yet in use (neither psa_pake_output() nor
1337 * psa_pake_input() has been called yet). It must
1338 * be on operation for which the peer ID hasn't
1339 * been set (psa_pake_set_peer() hasn't been
1340 * called yet).
1341 * \param[in] peer_id The peer's ID to authenticate.
1342 * \param peer_id_len Size of the \p peer_id buffer in bytes.
1343 *
1344 * \retval #PSA_SUCCESS
1345 * Success.
Neil Armstrong16ff7882022-05-20 11:04:20 +02001346 * \retval #PSA_ERROR_INVALID_ARGUMENT
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001347 * \p peer_id is not valid for the \p operation's algorithm and cipher
Neil Armstrong16ff7882022-05-20 11:04:20 +02001348 * suite.
Janos Follath702cf092021-05-26 12:58:23 +01001349 * \retval #PSA_ERROR_NOT_SUPPORTED
1350 * The algorithm doesn't associate a second identity with the session.
Gilles Peskineed733552023-02-14 19:21:09 +01001351 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1352 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1353 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001354 * \retval #PSA_ERROR_BAD_STATE
Neil Armstrong0d245752022-05-20 11:35:40 +02001355 * Calling psa_pake_set_peer() is invalid with the \p operation's
1356 * algorithm, the operation state is not valid, or the library has not
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001357 * been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001358 * It is implementation-dependent whether a failure to initialize
1359 * results in this error code.
1360 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001361psa_status_t psa_pake_set_peer(psa_pake_operation_t *operation,
1362 const uint8_t *peer_id,
1363 size_t peer_id_len);
Janos Follath702cf092021-05-26 12:58:23 +01001364
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001365/** Set the application role for a password-authenticated key exchange.
Janos Follath702cf092021-05-26 12:58:23 +01001366 *
1367 * Not all PAKE algorithms need to differentiate the communicating entities.
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001368 * It is optional to call this function for PAKEs that don't require a role
1369 * to be specified. For such PAKEs the application role parameter is ignored,
1370 * or #PSA_PAKE_ROLE_NONE can be passed as \c role.
Janos Follath702cf092021-05-26 12:58:23 +01001371 *
1372 * Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`
1373 * values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)
1374 * for more information.
1375 *
Neil Armstrongef157512022-05-25 11:49:45 +02001376 * \param[in,out] operation The operation object to specify the
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001377 * application's role for. It must have been set up
1378 * by psa_pake_setup() and not yet in use (neither
1379 * psa_pake_output() nor psa_pake_input() has been
1380 * called yet). It must be on operation for which
1381 * the application's role hasn't been specified
1382 * (psa_pake_set_role() hasn't been called yet).
1383 * \param role A value of type ::psa_pake_role_t indicating the
1384 * application's role in the PAKE the algorithm
1385 * that is being set up. For more information see
1386 * the documentation of \c PSA_PAKE_ROLE_XXX
1387 * constants.
Janos Follath702cf092021-05-26 12:58:23 +01001388 *
1389 * \retval #PSA_SUCCESS
1390 * Success.
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001391 * \retval #PSA_ERROR_INVALID_ARGUMENT
1392 * The \p role is not a valid PAKE role in the \p operation’s algorithm.
Janos Follath702cf092021-05-26 12:58:23 +01001393 * \retval #PSA_ERROR_NOT_SUPPORTED
Neil Armstrong2a6dd9c2022-05-20 11:17:10 +02001394 * The \p role for this algorithm is not supported or is not valid.
Gilles Peskineed733552023-02-14 19:21:09 +01001395 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1396 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001397 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001398 * The operation state is not valid, or
1399 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001400 * It is implementation-dependent whether a failure to initialize
1401 * results in this error code.
1402 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001403psa_status_t psa_pake_set_role(psa_pake_operation_t *operation,
1404 psa_pake_role_t role);
Janos Follath702cf092021-05-26 12:58:23 +01001405
1406/** Get output for a step of a password-authenticated key exchange.
1407 *
1408 * Depending on the algorithm being executed, you might need to call this
1409 * function several times or you might not need to call this at all.
1410 *
1411 * The exact sequence of calls to perform a password-authenticated key
1412 * exchange depends on the algorithm in use. Refer to the documentation of
1413 * individual PAKE algorithm types (`PSA_ALG_XXX` values of type
1414 * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more
1415 * information.
1416 *
1417 * If this function returns an error status, the operation enters an error
1418 * state and must be aborted by calling psa_pake_abort().
1419 *
1420 * \param[in,out] operation Active PAKE operation.
1421 * \param step The step of the algorithm for which the output is
1422 * requested.
1423 * \param[out] output Buffer where the output is to be written in the
1424 * format appropriate for this \p step. Refer to
1425 * the documentation of the individual
1426 * \c PSA_PAKE_STEP_XXX constants for more
1427 * information.
1428 * \param output_size Size of the \p output buffer in bytes. This must
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001429 * be at least #PSA_PAKE_OUTPUT_SIZE(\c alg, \c
1430 * primitive, \p output_step) where \c alg and
Neil Armstrong7bc71e92022-05-20 10:36:14 +02001431 * \p primitive are the PAKE algorithm and primitive
1432 * in the operation's cipher suite, and \p step is
1433 * the output step.
Janos Follath702cf092021-05-26 12:58:23 +01001434 *
1435 * \param[out] output_length On success, the number of bytes of the returned
1436 * output.
1437 *
1438 * \retval #PSA_SUCCESS
1439 * Success.
Janos Follath702cf092021-05-26 12:58:23 +01001440 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
1441 * The size of the \p output buffer is too small.
Neil Armstrong664077e2022-05-20 11:24:41 +02001442 * \retval #PSA_ERROR_INVALID_ARGUMENT
1443 * \p step is not compatible with the operation's algorithm.
1444 * \retval #PSA_ERROR_NOT_SUPPORTED
1445 * \p step is not supported with the operation's algorithm.
Gilles Peskineed733552023-02-14 19:21:09 +01001446 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
1447 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1448 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1449 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1450 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1451 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1452 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001453 * \retval #PSA_ERROR_BAD_STATE
Neil Armstronge9b45812022-05-20 11:39:09 +02001454 * The operation state is not valid (it must be active, and fully set
1455 * up, and this call must conform to the algorithm's requirements
1456 * for ordering of input and output steps), or
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001457 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001458 * It is implementation-dependent whether a failure to initialize
1459 * results in this error code.
1460 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001461psa_status_t psa_pake_output(psa_pake_operation_t *operation,
1462 psa_pake_step_t step,
1463 uint8_t *output,
1464 size_t output_size,
1465 size_t *output_length);
Janos Follath702cf092021-05-26 12:58:23 +01001466
1467/** Provide input for a step of a password-authenticated key exchange.
1468 *
1469 * Depending on the algorithm being executed, you might need to call this
1470 * function several times or you might not need to call this at all.
1471 *
1472 * The exact sequence of calls to perform a password-authenticated key
1473 * exchange depends on the algorithm in use. Refer to the documentation of
1474 * individual PAKE algorithm types (`PSA_ALG_XXX` values of type
1475 * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more
1476 * information.
1477 *
1478 * If this function returns an error status, the operation enters an error
1479 * state and must be aborted by calling psa_pake_abort().
1480 *
1481 * \param[in,out] operation Active PAKE operation.
1482 * \param step The step for which the input is provided.
Neil Armstrong799106b2022-05-20 10:18:53 +02001483 * \param[in] input Buffer containing the input in the format
Janos Follath702cf092021-05-26 12:58:23 +01001484 * appropriate for this \p step. Refer to the
1485 * documentation of the individual
1486 * \c PSA_PAKE_STEP_XXX constants for more
1487 * information.
Neil Armstrong799106b2022-05-20 10:18:53 +02001488 * \param input_length Size of the \p input buffer in bytes.
Janos Follath702cf092021-05-26 12:58:23 +01001489 *
1490 * \retval #PSA_SUCCESS
1491 * Success.
Neil Armstrong407b27b2022-05-20 11:28:23 +02001492 * \retval #PSA_ERROR_INVALID_SIGNATURE
1493 * The verification fails for a #PSA_PAKE_STEP_ZK_PROOF input step.
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001494 * \retval #PSA_ERROR_INVALID_ARGUMENT
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001495 * \p input_length is not compatible with the \p operation’s algorithm,
1496 * or the \p input is not valid for the \p operation's algorithm,
1497 * cipher suite or \p step.
Neil Armstrong407b27b2022-05-20 11:28:23 +02001498 * \retval #PSA_ERROR_NOT_SUPPORTED
1499 * \p step p is not supported with the \p operation's algorithm, or the
1500 * \p input is not supported for the \p operation's algorithm, cipher
1501 * suite or \p step.
Gilles Peskineed733552023-02-14 19:21:09 +01001502 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1503 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1504 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1505 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1506 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1507 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001508 * \retval #PSA_ERROR_BAD_STATE
Neil Armstronge9b45812022-05-20 11:39:09 +02001509 * The operation state is not valid (it must be active, and fully set
1510 * up, and this call must conform to the algorithm's requirements
1511 * for ordering of input and output steps), or
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001512 * the library has not been previously initialized by psa_crypto_init().
Janos Follath702cf092021-05-26 12:58:23 +01001513 * It is implementation-dependent whether a failure to initialize
1514 * results in this error code.
1515 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001516psa_status_t psa_pake_input(psa_pake_operation_t *operation,
1517 psa_pake_step_t step,
1518 const uint8_t *input,
1519 size_t input_length);
Janos Follath702cf092021-05-26 12:58:23 +01001520
1521/** Get implicitly confirmed shared secret from a PAKE.
1522 *
1523 * At this point there is a cryptographic guarantee that only the authenticated
1524 * party who used the same password is able to compute the key. But there is no
Janos Follatha46e28f2021-06-03 13:07:03 +01001525 * guarantee that the peer is the party it claims to be and was able to do so.
Janos Follath702cf092021-05-26 12:58:23 +01001526 *
Janos Follathb4db90f2021-06-03 13:17:09 +01001527 * That is, the authentication is only implicit. Since the peer is not
1528 * authenticated yet, no action should be taken yet that assumes that the peer
1529 * is who it claims to be. For example, do not access restricted files on the
1530 * peer's behalf until an explicit authentication has succeeded.
Janos Follath702cf092021-05-26 12:58:23 +01001531 *
1532 * This function can be called after the key exchange phase of the operation
1533 * has completed. It imports the shared secret output of the PAKE into the
1534 * provided derivation operation. The input step
1535 * #PSA_KEY_DERIVATION_INPUT_SECRET is used when placing the shared key
1536 * material in the key derivation operation.
1537 *
1538 * The exact sequence of calls to perform a password-authenticated key
1539 * exchange depends on the algorithm in use. Refer to the documentation of
1540 * individual PAKE algorithm types (`PSA_ALG_XXX` values of type
1541 * ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more
1542 * information.
1543 *
1544 * When this function returns successfully, \p operation becomes inactive.
1545 * If this function returns an error status, both \p operation
Andrzej Kurek3bedb5b2022-02-17 14:39:00 -05001546 * and \c key_derivation operations enter an error state and must be aborted by
Janos Follath702cf092021-05-26 12:58:23 +01001547 * calling psa_pake_abort() and psa_key_derivation_abort() respectively.
1548 *
1549 * \param[in,out] operation Active PAKE operation.
1550 * \param[out] output A key derivation operation that is ready
1551 * for an input step of type
1552 * #PSA_KEY_DERIVATION_INPUT_SECRET.
1553 *
1554 * \retval #PSA_SUCCESS
1555 * Success.
Janos Follath702cf092021-05-26 12:58:23 +01001556 * \retval #PSA_ERROR_INVALID_ARGUMENT
Neil Armstrong97d74b82022-05-20 11:30:31 +02001557 * #PSA_KEY_DERIVATION_INPUT_SECRET is not compatible with the
1558 * algorithm in the \p output key derivation operation.
1559 * \retval #PSA_ERROR_NOT_SUPPORTED
1560 * Input from a PAKE is not supported by the algorithm in the \p output
1561 * key derivation operation.
Gilles Peskineed733552023-02-14 19:21:09 +01001562 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
1563 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1564 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
1565 * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
1566 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
1567 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Janos Follath702cf092021-05-26 12:58:23 +01001568 * \retval #PSA_ERROR_BAD_STATE
Andrzej Kurekf7c1f742022-02-03 11:30:54 -05001569 * The PAKE operation state is not valid (it must be active, but beyond
1570 * that validity is specific to the algorithm), or
1571 * the library has not been previously initialized by psa_crypto_init(),
1572 * or the state of \p output is not valid for
1573 * the #PSA_KEY_DERIVATION_INPUT_SECRET step. This can happen if the
1574 * step is out of order or the application has done this step already
1575 * and it may not be repeated.
Janos Follath702cf092021-05-26 12:58:23 +01001576 * It is implementation-dependent whether a failure to initialize
1577 * results in this error code.
1578 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001579psa_status_t psa_pake_get_implicit_key(psa_pake_operation_t *operation,
1580 psa_key_derivation_operation_t *output);
Janos Follath702cf092021-05-26 12:58:23 +01001581
Neil Armstrong0c8ef932022-05-20 10:23:51 +02001582/** Abort a PAKE operation.
1583 *
1584 * Aborting an operation frees all associated resources except for the \c
1585 * operation structure itself. Once aborted, the operation object can be reused
1586 * for another operation by calling psa_pake_setup() again.
1587 *
1588 * This function may be called at any time after the operation
1589 * object has been initialized as described in #psa_pake_operation_t.
1590 *
1591 * In particular, calling psa_pake_abort() after the operation has been
1592 * terminated by a call to psa_pake_abort() or psa_pake_get_implicit_key()
1593 * is safe and has no effect.
1594 *
1595 * \param[in,out] operation The operation to abort.
1596 *
1597 * \retval #PSA_SUCCESS
Neil Armstrong59fa8ee2022-05-20 11:31:04 +02001598 * Success.
Gilles Peskineed733552023-02-14 19:21:09 +01001599 * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
1600 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Neil Armstrong0c8ef932022-05-20 10:23:51 +02001601 * \retval #PSA_ERROR_BAD_STATE
1602 * The library has not been previously initialized by psa_crypto_init().
1603 * It is implementation-dependent whether a failure to initialize
1604 * results in this error code.
1605 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001606psa_status_t psa_pake_abort(psa_pake_operation_t *operation);
Neil Armstrong0c8ef932022-05-20 10:23:51 +02001607
Janos Follath702cf092021-05-26 12:58:23 +01001608/**@}*/
1609
1610/** A sufficient output buffer size for psa_pake_output().
1611 *
1612 * If the size of the output buffer is at least this large, it is guaranteed
1613 * that psa_pake_output() will not fail due to an insufficient output buffer
1614 * size. The actual size of the output might be smaller in any given call.
1615 *
1616 * See also #PSA_PAKE_OUTPUT_MAX_SIZE
1617 *
Janos Follath46c02372021-06-08 15:22:51 +01001618 * \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that
Janos Follath702cf092021-05-26 12:58:23 +01001619 * #PSA_ALG_IS_PAKE(\p alg) is true).
1620 * \param primitive A primitive of type ::psa_pake_primitive_t that is
1621 * compatible with algorithm \p alg.
1622 * \param output_step A value of type ::psa_pake_step_t that is valid for the
1623 * algorithm \p alg.
1624 * \return A sufficient output buffer size for the specified
Neil Armstrongcd974d52022-05-20 10:30:12 +02001625 * PAKE algorithm, primitive, and output step. If the
1626 * PAKE algorithm, primitive, or output step is not
1627 * recognized, or the parameters are incompatible,
1628 * return 0.
Janos Follath702cf092021-05-26 12:58:23 +01001629 */
Neil Armstrong7aaa34a2022-06-08 14:05:02 +02001630#define PSA_PAKE_OUTPUT_SIZE(alg, primitive, output_step) \
Gilles Peskine449bd832023-01-11 14:50:10 +01001631 (alg == PSA_ALG_JPAKE && \
1632 primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \
1633 PSA_ECC_FAMILY_SECP_R1, 256) ? \
1634 ( \
1635 output_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \
1636 output_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \
1637 32 \
1638 ) : \
1639 0)
Janos Follath702cf092021-05-26 12:58:23 +01001640
1641/** A sufficient input buffer size for psa_pake_input().
1642 *
Janos Follathb4db90f2021-06-03 13:17:09 +01001643 * The value returned by this macro is guaranteed to be large enough for any
1644 * valid input to psa_pake_input() in an operation with the specified
1645 * parameters.
Janos Follath702cf092021-05-26 12:58:23 +01001646 *
1647 * See also #PSA_PAKE_INPUT_MAX_SIZE
1648 *
Janos Follath46c02372021-06-08 15:22:51 +01001649 * \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that
Janos Follath702cf092021-05-26 12:58:23 +01001650 * #PSA_ALG_IS_PAKE(\p alg) is true).
1651 * \param primitive A primitive of type ::psa_pake_primitive_t that is
1652 * compatible with algorithm \p alg.
Janos Follathec83eb62021-05-27 08:41:59 +01001653 * \param input_step A value of type ::psa_pake_step_t that is valid for the
Janos Follath702cf092021-05-26 12:58:23 +01001654 * algorithm \p alg.
Janos Follath38d29db2021-06-03 13:14:42 +01001655 * \return A sufficient input buffer size for the specified
1656 * input, cipher suite and algorithm. If the cipher suite,
1657 * the input type or PAKE algorithm is not recognized, or
Janos Follath702cf092021-05-26 12:58:23 +01001658 * the parameters are incompatible, return 0.
1659 */
Neil Armstrong7aaa34a2022-06-08 14:05:02 +02001660#define PSA_PAKE_INPUT_SIZE(alg, primitive, input_step) \
Gilles Peskine449bd832023-01-11 14:50:10 +01001661 (alg == PSA_ALG_JPAKE && \
1662 primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \
1663 PSA_ECC_FAMILY_SECP_R1, 256) ? \
1664 ( \
1665 input_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \
1666 input_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \
1667 32 \
1668 ) : \
1669 0)
Janos Follath702cf092021-05-26 12:58:23 +01001670
Neil Armstrong2056ce52022-05-25 11:38:15 +02001671/** Output buffer size for psa_pake_output() for any of the supported PAKE
1672 * algorithm and primitive suites and output step.
Janos Follath702cf092021-05-26 12:58:23 +01001673 *
1674 * This macro must expand to a compile-time constant integer.
1675 *
Przemek Stekiel7921a032023-04-14 14:29:57 +02001676 * The value of this macro must be at least as large as the largest value
1677 * returned by PSA_PAKE_OUTPUT_SIZE()
1678 *
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001679 * See also #PSA_PAKE_OUTPUT_SIZE(\p alg, \p primitive, \p output_step).
Janos Follath702cf092021-05-26 12:58:23 +01001680 */
Manuel Pégourié-Gonnardec7012d2022-10-05 12:17:34 +02001681#define PSA_PAKE_OUTPUT_MAX_SIZE 65
Janos Follath702cf092021-05-26 12:58:23 +01001682
Neil Armstrong2056ce52022-05-25 11:38:15 +02001683/** Input buffer size for psa_pake_input() for any of the supported PAKE
1684 * algorithm and primitive suites and input step.
Janos Follath702cf092021-05-26 12:58:23 +01001685 *
1686 * This macro must expand to a compile-time constant integer.
1687 *
Przemek Stekiel7921a032023-04-14 14:29:57 +02001688 * The value of this macro must be at least as large as the largest value
1689 * returned by PSA_PAKE_INPUT_SIZE()
1690 *
Andrzej Kurek00b54e62023-05-06 09:38:57 -04001691 * See also #PSA_PAKE_INPUT_SIZE(\p alg, \p primitive, \p output_step).
Janos Follath702cf092021-05-26 12:58:23 +01001692 */
Manuel Pégourié-Gonnardec7012d2022-10-05 12:17:34 +02001693#define PSA_PAKE_INPUT_MAX_SIZE 65
Janos Follath702cf092021-05-26 12:58:23 +01001694
Neil Armstrongfb993022022-05-20 10:08:58 +02001695/** Returns a suitable initializer for a PAKE cipher suite object of type
1696 * psa_pake_cipher_suite_t.
1697 */
Gilles Peskine449bd832023-01-11 14:50:10 +01001698#define PSA_PAKE_CIPHER_SUITE_INIT { PSA_ALG_NONE, 0, 0, 0, PSA_ALG_NONE }
Neil Armstrongfb993022022-05-20 10:08:58 +02001699
Neil Armstrong0151c552022-05-20 10:13:53 +02001700/** Returns a suitable initializer for a PAKE operation object of type
1701 * psa_pake_operation_t.
1702 */
Antonio de Angelis4380a332024-02-02 14:21:24 +00001703#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
1704#define PSA_PAKE_OPERATION_INIT { 0 }
1705#else
Przemek Stekiel656b2592023-03-22 13:15:33 +01001706#define PSA_PAKE_OPERATION_INIT { 0, PSA_ALG_NONE, 0, PSA_PAKE_OPERATION_STAGE_SETUP, \
Przemek Stekiel251e86a2023-02-17 14:30:50 +01001707 { 0 }, { { 0 } } }
Antonio de Angelis4380a332024-02-02 14:21:24 +00001708#endif
Neil Armstrong0151c552022-05-20 10:13:53 +02001709
Gilles Peskine449bd832023-01-11 14:50:10 +01001710struct psa_pake_cipher_suite_s {
Janos Follath702cf092021-05-26 12:58:23 +01001711 psa_algorithm_t algorithm;
1712 psa_pake_primitive_type_t type;
1713 psa_pake_family_t family;
1714 uint16_t bits;
1715 psa_algorithm_t hash;
1716};
1717
1718static inline psa_algorithm_t psa_pake_cs_get_algorithm(
Gilles Peskine449bd832023-01-11 14:50:10 +01001719 const psa_pake_cipher_suite_t *cipher_suite)
Janos Follath702cf092021-05-26 12:58:23 +01001720{
Gilles Peskine449bd832023-01-11 14:50:10 +01001721 return cipher_suite->algorithm;
Janos Follath702cf092021-05-26 12:58:23 +01001722}
1723
1724static inline void psa_pake_cs_set_algorithm(
1725 psa_pake_cipher_suite_t *cipher_suite,
1726 psa_algorithm_t algorithm)
1727{
Gilles Peskine449bd832023-01-11 14:50:10 +01001728 if (!PSA_ALG_IS_PAKE(algorithm)) {
Janos Follath702cf092021-05-26 12:58:23 +01001729 cipher_suite->algorithm = 0;
Gilles Peskine449bd832023-01-11 14:50:10 +01001730 } else {
Janos Follath702cf092021-05-26 12:58:23 +01001731 cipher_suite->algorithm = algorithm;
Gilles Peskine449bd832023-01-11 14:50:10 +01001732 }
Janos Follath702cf092021-05-26 12:58:23 +01001733}
1734
1735static inline psa_pake_primitive_t psa_pake_cs_get_primitive(
Gilles Peskine449bd832023-01-11 14:50:10 +01001736 const psa_pake_cipher_suite_t *cipher_suite)
Janos Follath702cf092021-05-26 12:58:23 +01001737{
Gilles Peskine449bd832023-01-11 14:50:10 +01001738 return PSA_PAKE_PRIMITIVE(cipher_suite->type, cipher_suite->family,
1739 cipher_suite->bits);
Janos Follath702cf092021-05-26 12:58:23 +01001740}
1741
1742static inline void psa_pake_cs_set_primitive(
Gilles Peskine449bd832023-01-11 14:50:10 +01001743 psa_pake_cipher_suite_t *cipher_suite,
1744 psa_pake_primitive_t primitive)
Janos Follath702cf092021-05-26 12:58:23 +01001745{
1746 cipher_suite->type = (psa_pake_primitive_type_t) (primitive >> 24);
1747 cipher_suite->family = (psa_pake_family_t) (0xFF & (primitive >> 16));
1748 cipher_suite->bits = (uint16_t) (0xFFFF & primitive);
1749}
1750
Neil Armstrongff9cac72022-05-20 10:25:15 +02001751static inline psa_pake_family_t psa_pake_cs_get_family(
Gilles Peskine449bd832023-01-11 14:50:10 +01001752 const psa_pake_cipher_suite_t *cipher_suite)
Neil Armstrongff9cac72022-05-20 10:25:15 +02001753{
Gilles Peskine449bd832023-01-11 14:50:10 +01001754 return cipher_suite->family;
Neil Armstrongff9cac72022-05-20 10:25:15 +02001755}
1756
Neil Armstrongd5a48252022-05-20 10:26:36 +02001757static inline uint16_t psa_pake_cs_get_bits(
Gilles Peskine449bd832023-01-11 14:50:10 +01001758 const psa_pake_cipher_suite_t *cipher_suite)
Neil Armstrongd5a48252022-05-20 10:26:36 +02001759{
Gilles Peskine449bd832023-01-11 14:50:10 +01001760 return cipher_suite->bits;
Neil Armstrongd5a48252022-05-20 10:26:36 +02001761}
1762
Janos Follath702cf092021-05-26 12:58:23 +01001763static inline psa_algorithm_t psa_pake_cs_get_hash(
Gilles Peskine449bd832023-01-11 14:50:10 +01001764 const psa_pake_cipher_suite_t *cipher_suite)
Janos Follath702cf092021-05-26 12:58:23 +01001765{
Gilles Peskine449bd832023-01-11 14:50:10 +01001766 return cipher_suite->hash;
Janos Follath702cf092021-05-26 12:58:23 +01001767}
1768
Gilles Peskine449bd832023-01-11 14:50:10 +01001769static inline void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite,
1770 psa_algorithm_t hash)
Janos Follath702cf092021-05-26 12:58:23 +01001771{
Gilles Peskine449bd832023-01-11 14:50:10 +01001772 if (!PSA_ALG_IS_HASH(hash)) {
Janos Follath702cf092021-05-26 12:58:23 +01001773 cipher_suite->hash = 0;
Gilles Peskine449bd832023-01-11 14:50:10 +01001774 } else {
Janos Follath702cf092021-05-26 12:58:23 +01001775 cipher_suite->hash = hash;
Gilles Peskine449bd832023-01-11 14:50:10 +01001776 }
Janos Follath702cf092021-05-26 12:58:23 +01001777}
1778
Przemek Stekiel51eac532022-12-07 11:04:51 +01001779struct psa_crypto_driver_pake_inputs_s {
Gilles Peskine449bd832023-01-11 14:50:10 +01001780 uint8_t *MBEDTLS_PRIVATE(password);
Przemek Stekiel152ae072022-11-17 13:24:36 +01001781 size_t MBEDTLS_PRIVATE(password_len);
Przemek Stekiel26c909d2023-02-28 12:34:03 +01001782 uint8_t *MBEDTLS_PRIVATE(user);
1783 size_t MBEDTLS_PRIVATE(user_len);
1784 uint8_t *MBEDTLS_PRIVATE(peer);
1785 size_t MBEDTLS_PRIVATE(peer_len);
Przemek Stekiel9dd24402023-01-26 15:06:09 +01001786 psa_key_attributes_t MBEDTLS_PRIVATE(attributes);
Przemek Stekiel51eac532022-12-07 11:04:51 +01001787 psa_pake_cipher_suite_t MBEDTLS_PRIVATE(cipher_suite);
1788};
1789
Przemek Stekiel251e86a2023-02-17 14:30:50 +01001790typedef enum psa_crypto_driver_pake_step {
Przemek Stekielb09c4872023-01-17 12:05:38 +01001791 PSA_JPAKE_STEP_INVALID = 0, /* Invalid step */
1792 PSA_JPAKE_X1_STEP_KEY_SHARE = 1, /* Round 1: input/output key share (for ephemeral private key X1).*/
1793 PSA_JPAKE_X1_STEP_ZK_PUBLIC = 2, /* Round 1: input/output Schnorr NIZKP public key for the X1 key */
1794 PSA_JPAKE_X1_STEP_ZK_PROOF = 3, /* Round 1: input/output Schnorr NIZKP proof for the X1 key */
1795 PSA_JPAKE_X2_STEP_KEY_SHARE = 4, /* Round 1: input/output key share (for ephemeral private key X2).*/
1796 PSA_JPAKE_X2_STEP_ZK_PUBLIC = 5, /* Round 1: input/output Schnorr NIZKP public key for the X2 key */
1797 PSA_JPAKE_X2_STEP_ZK_PROOF = 6, /* Round 1: input/output Schnorr NIZKP proof for the X2 key */
1798 PSA_JPAKE_X2S_STEP_KEY_SHARE = 7, /* Round 2: output X2S key (our key) */
1799 PSA_JPAKE_X2S_STEP_ZK_PUBLIC = 8, /* Round 2: output Schnorr NIZKP public key for the X2S key (our key) */
1800 PSA_JPAKE_X2S_STEP_ZK_PROOF = 9, /* Round 2: output Schnorr NIZKP proof for the X2S key (our key) */
1801 PSA_JPAKE_X4S_STEP_KEY_SHARE = 10, /* Round 2: input X4S key (from peer) */
1802 PSA_JPAKE_X4S_STEP_ZK_PUBLIC = 11, /* Round 2: input Schnorr NIZKP public key for the X4S key (from peer) */
1803 PSA_JPAKE_X4S_STEP_ZK_PROOF = 12 /* Round 2: input Schnorr NIZKP proof for the X4S key (from peer) */
Przemek Stekiel251e86a2023-02-17 14:30:50 +01001804} psa_crypto_driver_pake_step_t;
Przemek Stekiel57980032023-01-09 15:07:26 +01001805
David Horstmanne7f21e62023-05-12 18:17:21 +01001806typedef enum psa_jpake_round {
David Horstmann5da95602023-06-08 15:37:12 +01001807 PSA_JPAKE_FIRST = 0,
1808 PSA_JPAKE_SECOND = 1,
1809 PSA_JPAKE_FINISHED = 2
David Horstmanne7f21e62023-05-12 18:17:21 +01001810} psa_jpake_round_t;
1811
1812typedef enum psa_jpake_io_mode {
David Horstmann5da95602023-06-08 15:37:12 +01001813 PSA_JPAKE_INPUT = 0,
1814 PSA_JPAKE_OUTPUT = 1
David Horstmanne7f21e62023-05-12 18:17:21 +01001815} psa_jpake_io_mode_t;
Przemek Stekielb09c4872023-01-17 12:05:38 +01001816
Przemek Stekiele12ed362022-12-21 12:54:46 +01001817struct psa_jpake_computation_stage_s {
David Horstmanne7f21e62023-05-12 18:17:21 +01001818 /* The J-PAKE round we are currently on */
1819 psa_jpake_round_t MBEDTLS_PRIVATE(round);
1820 /* The 'mode' we are currently in (inputting or outputting) */
David Horstmann024e5c52023-06-14 15:48:21 +01001821 psa_jpake_io_mode_t MBEDTLS_PRIVATE(io_mode);
David Horstmann279d2272023-06-14 17:13:56 +01001822 /* The number of completed inputs so far this round */
David Horstmanne7f21e62023-05-12 18:17:21 +01001823 uint8_t MBEDTLS_PRIVATE(inputs);
David Horstmann279d2272023-06-14 17:13:56 +01001824 /* The number of completed outputs so far this round */
David Horstmanne7f21e62023-05-12 18:17:21 +01001825 uint8_t MBEDTLS_PRIVATE(outputs);
1826 /* The next expected step (KEY_SHARE, ZK_PUBLIC or ZK_PROOF) */
1827 psa_pake_step_t MBEDTLS_PRIVATE(step);
Przemek Stekiele12ed362022-12-21 12:54:46 +01001828};
1829
David Horstmann5dbe17d2023-06-27 10:30:28 +01001830#define PSA_JPAKE_EXPECTED_INPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \
1831 ((round) == PSA_JPAKE_FIRST ? 2 : 1))
1832#define PSA_JPAKE_EXPECTED_OUTPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \
1833 ((round) == PSA_JPAKE_FIRST ? 2 : 1))
David Horstmanne7f21e62023-05-12 18:17:21 +01001834
Janos Follath702cf092021-05-26 12:58:23 +01001835struct psa_pake_operation_s {
Antonio de Angelis4380a332024-02-02 14:21:24 +00001836#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
1837 mbedtls_psa_client_handle_t handle;
1838#else
Przemek Stekield91bcb72022-11-22 14:00:51 +01001839 /** Unique ID indicating which driver got assigned to do the
1840 * operation. Since driver contexts are driver-specific, swapping
1841 * drivers halfway through the operation is not supported.
1842 * ID values are auto-generated in psa_crypto_driver_wrappers.h
1843 * ID value zero means the context is not valid or not assigned to
1844 * any driver (i.e. none of the driver contexts are active). */
1845 unsigned int MBEDTLS_PRIVATE(id);
Przemek Stekiel6b648622023-02-19 22:55:33 +01001846 /* Algorithm of the PAKE operation */
Przemek Stekiele12ed362022-12-21 12:54:46 +01001847 psa_algorithm_t MBEDTLS_PRIVATE(alg);
Przemek Stekiel656b2592023-03-22 13:15:33 +01001848 /* A primitive of type compatible with algorithm */
1849 psa_pake_primitive_t MBEDTLS_PRIVATE(primitive);
Przemek Stekiel6b648622023-02-19 22:55:33 +01001850 /* Stage of the PAKE operation: waiting for the setup, collecting inputs
1851 * or computing. */
Przemek Stekiel51eac532022-12-07 11:04:51 +01001852 uint8_t MBEDTLS_PRIVATE(stage);
Przemek Stekiele12ed362022-12-21 12:54:46 +01001853 /* Holds computation stage of the PAKE algorithms. */
Gilles Peskine449bd832023-01-11 14:50:10 +01001854 union {
Przemek Stekiel251e86a2023-02-17 14:30:50 +01001855 uint8_t MBEDTLS_PRIVATE(dummy);
Przemek Stekiel4aa99402023-02-27 13:00:57 +01001856#if defined(PSA_WANT_ALG_JPAKE)
Przemek Stekieldde6a912023-01-26 08:46:37 +01001857 psa_jpake_computation_stage_t MBEDTLS_PRIVATE(jpake);
Neil Armstrong35269d92022-05-25 11:26:31 +02001858#endif
Przemek Stekieldde6a912023-01-26 08:46:37 +01001859 } MBEDTLS_PRIVATE(computation_stage);
Przemek Stekiel51eac532022-12-07 11:04:51 +01001860 union {
Przemek Stekiel51eac532022-12-07 11:04:51 +01001861 psa_driver_pake_context_t MBEDTLS_PRIVATE(ctx);
Przemek Stekielac067d72023-01-26 16:31:03 +01001862 psa_crypto_driver_pake_inputs_t MBEDTLS_PRIVATE(inputs);
Przemek Stekiel51eac532022-12-07 11:04:51 +01001863 } MBEDTLS_PRIVATE(data);
Antonio de Angelis4380a332024-02-02 14:21:24 +00001864#endif
Janos Follath702cf092021-05-26 12:58:23 +01001865};
1866
Gilles Peskine449bd832023-01-11 14:50:10 +01001867static inline struct psa_pake_cipher_suite_s psa_pake_cipher_suite_init(void)
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +02001868{
1869 const struct psa_pake_cipher_suite_s v = PSA_PAKE_CIPHER_SUITE_INIT;
Gilles Peskine449bd832023-01-11 14:50:10 +01001870 return v;
Neil Armstrong5ff6a7f2022-05-20 10:12:01 +02001871}
1872
Gilles Peskine449bd832023-01-11 14:50:10 +01001873static inline struct psa_pake_operation_s psa_pake_operation_init(void)
Janos Follath702cf092021-05-26 12:58:23 +01001874{
1875 const struct psa_pake_operation_s v = PSA_PAKE_OPERATION_INIT;
Gilles Peskine449bd832023-01-11 14:50:10 +01001876 return v;
Janos Follath702cf092021-05-26 12:58:23 +01001877}
1878
Gilles Peskinee59236f2018-01-27 23:32:46 +01001879#ifdef __cplusplus
1880}
1881#endif
1882
1883#endif /* PSA_CRYPTO_EXTRA_H */