Path: blob/master/thirdparty/mbedtls/include/psa/crypto_extra.h
9904 views
/**1* \file psa/crypto_extra.h2*3* \brief PSA cryptography module: Mbed TLS vendor extensions4*5* \note This file may not be included directly. Applications must6* include psa/crypto.h.7*8* This file is reserved for vendor-specific definitions.9*/10/*11* Copyright The Mbed TLS Contributors12* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later13*/1415#ifndef PSA_CRYPTO_EXTRA_H16#define PSA_CRYPTO_EXTRA_H17#include "mbedtls/private_access.h"1819#include "crypto_types.h"20#include "crypto_compat.h"2122#ifdef __cplusplus23extern "C" {24#endif2526/* UID for secure storage seed */27#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF522829/* See mbedtls_config.h for definition */30#if !defined(MBEDTLS_PSA_KEY_SLOT_COUNT)31#define MBEDTLS_PSA_KEY_SLOT_COUNT 3232#endif3334/* If the size of static key slots is not explicitly defined by the user, then35* set it to the maximum between PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE and36* PSA_CIPHER_MAX_KEY_LENGTH.37* See mbedtls_config.h for the definition. */38#if !defined(MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE)39#define MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE \40((PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE > PSA_CIPHER_MAX_KEY_LENGTH) ? \41PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE : PSA_CIPHER_MAX_KEY_LENGTH)42#endif /* !MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE*/4344/** \addtogroup attributes45* @{46*/4748/** \brief Declare the enrollment algorithm for a key.49*50* An operation on a key may indifferently use the algorithm set with51* psa_set_key_algorithm() or with this function.52*53* \param[out] attributes The attribute structure to write to.54* \param alg2 A second algorithm that the key may be used55* for, in addition to the algorithm set with56* psa_set_key_algorithm().57*58* \warning Setting an enrollment algorithm is not recommended, because59* using the same key with different algorithms can allow some60* attacks based on arithmetic relations between different61* computations made with the same key, or can escalate harmless62* side channels into exploitable ones. Use this function only63* if it is necessary to support a protocol for which it has been64* verified that the usage of the key with multiple algorithms65* is safe.66*/67static inline void psa_set_key_enrollment_algorithm(68psa_key_attributes_t *attributes,69psa_algorithm_t alg2)70{71attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2) = alg2;72}7374/** Retrieve the enrollment algorithm policy from key attributes.75*76* \param[in] attributes The key attribute structure to query.77*78* \return The enrollment algorithm stored in the attribute structure.79*/80static inline psa_algorithm_t psa_get_key_enrollment_algorithm(81const psa_key_attributes_t *attributes)82{83return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg2);84}8586#if defined(MBEDTLS_PSA_CRYPTO_SE_C)8788/** Retrieve the slot number where a key is stored.89*90* A slot number is only defined for keys that are stored in a secure91* element.92*93* This information is only useful if the secure element is not entirely94* managed through the PSA Cryptography API. It is up to the secure95* element driver to decide how PSA slot numbers map to any other interface96* that the secure element may have.97*98* \param[in] attributes The key attribute structure to query.99* \param[out] slot_number On success, the slot number containing the key.100*101* \retval #PSA_SUCCESS102* The key is located in a secure element, and \p *slot_number103* indicates the slot number that contains it.104* \retval #PSA_ERROR_NOT_PERMITTED105* The caller is not permitted to query the slot number.106* Mbed TLS currently does not return this error.107* \retval #PSA_ERROR_INVALID_ARGUMENT108* The key is not located in a secure element.109*/110psa_status_t psa_get_key_slot_number(111const psa_key_attributes_t *attributes,112psa_key_slot_number_t *slot_number);113114/** Choose the slot number where a key is stored.115*116* This function declares a slot number in the specified attribute117* structure.118*119* A slot number is only meaningful for keys that are stored in a secure120* element. It is up to the secure element driver to decide how PSA slot121* numbers map to any other interface that the secure element may have.122*123* \note Setting a slot number in key attributes for a key creation can124* cause the following errors when creating the key:125* - #PSA_ERROR_NOT_SUPPORTED if the selected secure element does126* not support choosing a specific slot number.127* - #PSA_ERROR_NOT_PERMITTED if the caller is not permitted to128* choose slot numbers in general or to choose this specific slot.129* - #PSA_ERROR_INVALID_ARGUMENT if the chosen slot number is not130* valid in general or not valid for this specific key.131* - #PSA_ERROR_ALREADY_EXISTS if there is already a key in the132* selected slot.133*134* \param[out] attributes The attribute structure to write to.135* \param slot_number The slot number to set.136*/137static inline void psa_set_key_slot_number(138psa_key_attributes_t *attributes,139psa_key_slot_number_t slot_number)140{141attributes->MBEDTLS_PRIVATE(has_slot_number) = 1;142attributes->MBEDTLS_PRIVATE(slot_number) = slot_number;143}144145/** Remove the slot number attribute from a key attribute structure.146*147* This function undoes the action of psa_set_key_slot_number().148*149* \param[out] attributes The attribute structure to write to.150*/151static inline void psa_clear_key_slot_number(152psa_key_attributes_t *attributes)153{154attributes->MBEDTLS_PRIVATE(has_slot_number) = 0;155}156157/** Register a key that is already present in a secure element.158*159* The key must be located in a secure element designated by the160* lifetime field in \p attributes, in the slot set with161* psa_set_key_slot_number() in the attribute structure.162* This function makes the key available through the key identifier163* specified in \p attributes.164*165* \param[in] attributes The attributes of the existing key.166* - The lifetime must be a persistent lifetime167* in a secure element. Volatile lifetimes are168* not currently supported.169* - The key identifier must be in the valid170* range for persistent keys.171* - The key type and size must be specified and172* must be consistent with the key material173* in the secure element.174*175* \retval #PSA_SUCCESS176* The key was successfully registered.177* Note that depending on the design of the driver, this may or may178* not guarantee that a key actually exists in the designated slot179* and is compatible with the specified attributes.180* \retval #PSA_ERROR_ALREADY_EXISTS181* There is already a key with the identifier specified in182* \p attributes.183* \retval #PSA_ERROR_NOT_SUPPORTED184* The secure element driver for the specified lifetime does not185* support registering a key.186* \retval #PSA_ERROR_INVALID_ARGUMENT187* The identifier in \p attributes is invalid, namely the identifier is188* not in the user range, or189* \p attributes specifies a lifetime which is not located190* in a secure element, or no slot number is specified in \p attributes,191* or the specified slot number is not valid.192* \retval #PSA_ERROR_NOT_PERMITTED193* The caller is not authorized to register the specified key slot.194* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription195* \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription196* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription197* \retval #PSA_ERROR_DATA_INVALID \emptydescription198* \retval #PSA_ERROR_DATA_CORRUPT \emptydescription199* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription200* \retval #PSA_ERROR_BAD_STATE201* The library has not been previously initialized by psa_crypto_init().202* It is implementation-dependent whether a failure to initialize203* results in this error code.204*/205psa_status_t mbedtls_psa_register_se_key(206const psa_key_attributes_t *attributes);207208#endif /* MBEDTLS_PSA_CRYPTO_SE_C */209210/**@}*/211212/**213* \brief Library deinitialization.214*215* This function clears all data associated with the PSA layer,216* including the whole key store.217* This function is not thread safe, it wipes every key slot regardless of218* state and reader count. It should only be called when no slot is in use.219*220* This is an Mbed TLS extension.221*/222void mbedtls_psa_crypto_free(void);223224/** \brief Statistics about225* resource consumption related to the PSA keystore.226*227* \note The content of this structure is not part of the stable API and ABI228* of Mbed TLS and may change arbitrarily from version to version.229*/230typedef struct mbedtls_psa_stats_s {231/** Number of slots containing key material for a volatile key. */232size_t MBEDTLS_PRIVATE(volatile_slots);233/** Number of slots containing key material for a key which is in234* internal persistent storage. */235size_t MBEDTLS_PRIVATE(persistent_slots);236/** Number of slots containing a reference to a key in a237* secure element. */238size_t MBEDTLS_PRIVATE(external_slots);239/** Number of slots which are occupied, but do not contain240* key material yet. */241size_t MBEDTLS_PRIVATE(half_filled_slots);242/** Number of slots that contain cache data. */243size_t MBEDTLS_PRIVATE(cache_slots);244/** Number of slots that are not used for anything. */245size_t MBEDTLS_PRIVATE(empty_slots);246/** Number of slots that are locked. */247size_t MBEDTLS_PRIVATE(locked_slots);248/** Largest key id value among open keys in internal persistent storage. */249psa_key_id_t MBEDTLS_PRIVATE(max_open_internal_key_id);250/** Largest key id value among open keys in secure elements. */251psa_key_id_t MBEDTLS_PRIVATE(max_open_external_key_id);252} mbedtls_psa_stats_t;253254/** \brief Get statistics about255* resource consumption related to the PSA keystore.256*257* \note When Mbed TLS is built as part of a service, with isolation258* between the application and the keystore, the service may or259* may not expose this function.260*/261void mbedtls_psa_get_stats(mbedtls_psa_stats_t *stats);262263/**264* \brief Inject an initial entropy seed for the random generator into265* secure storage.266*267* This function injects data to be used as a seed for the random generator268* used by the PSA Crypto implementation. On devices that lack a trusted269* entropy source (preferably a hardware random number generator),270* the Mbed PSA Crypto implementation uses this value to seed its271* random generator.272*273* On devices without a trusted entropy source, this function must be274* called exactly once in the lifetime of the device. On devices with275* a trusted entropy source, calling this function is optional.276* In all cases, this function may only be called before calling any277* other function in the PSA Crypto API, including psa_crypto_init().278*279* When this function returns successfully, it populates a file in280* persistent storage. Once the file has been created, this function281* can no longer succeed.282*283* If any error occurs, this function does not change the system state.284* You can call this function again after correcting the reason for the285* error if possible.286*287* \warning This function **can** fail! Callers MUST check the return status.288*289* \warning If you use this function, you should use it as part of a290* factory provisioning process. The value of the injected seed291* is critical to the security of the device. It must be292* *secret*, *unpredictable* and (statistically) *unique per device*.293* You should be generate it randomly using a cryptographically294* secure random generator seeded from trusted entropy sources.295* You should transmit it securely to the device and ensure296* that its value is not leaked or stored anywhere beyond the297* needs of transmitting it from the point of generation to298* the call of this function, and erase all copies of the value299* once this function returns.300*301* This is an Mbed TLS extension.302*303* \note This function is only available on the following platforms:304* * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled.305* Note that you must provide compatible implementations of306* mbedtls_nv_seed_read and mbedtls_nv_seed_write.307* * In a client-server integration of PSA Cryptography, on the client side,308* if the server supports this feature.309* \param[in] seed Buffer containing the seed value to inject.310* \param[in] seed_size Size of the \p seed buffer.311* The size of the seed in bytes must be greater312* or equal to both #MBEDTLS_ENTROPY_BLOCK_SIZE313* and the value of \c MBEDTLS_ENTROPY_MIN_PLATFORM314* in `library/entropy_poll.h` in the Mbed TLS source315* code.316* It must be less or equal to317* #MBEDTLS_ENTROPY_MAX_SEED_SIZE.318*319* \retval #PSA_SUCCESS320* The seed value was injected successfully. The random generator321* of the PSA Crypto implementation is now ready for use.322* You may now call psa_crypto_init() and use the PSA Crypto323* implementation.324* \retval #PSA_ERROR_INVALID_ARGUMENT325* \p seed_size is out of range.326* \retval #PSA_ERROR_STORAGE_FAILURE327* There was a failure reading or writing from storage.328* \retval #PSA_ERROR_NOT_PERMITTED329* The library has already been initialized. It is no longer330* possible to call this function.331*/332psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,333size_t seed_size);334335/** \addtogroup crypto_types336* @{337*/338339/** DSA public key.340*341* The import and export format is the342* representation of the public key `y = g^x mod p` as a big-endian byte343* string. The length of the byte string is the length of the base prime `p`344* in bytes.345*/346#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t) 0x4002)347348/** DSA key pair (private and public key).349*350* The import and export format is the351* representation of the private key `x` as a big-endian byte string. The352* length of the byte string is the private key size in bytes (leading zeroes353* are not stripped).354*355* Deterministic DSA key derivation with psa_generate_derived_key follows356* FIPS 186-4 §B.1.2: interpret the byte string as integer357* in big-endian order. Discard it if it is not in the range358* [0, *N* - 2] where *N* is the boundary of the private key domain359* (the prime *p* for Diffie-Hellman, the subprime *q* for DSA,360* or the order of the curve's base point for ECC).361* Add 1 to the resulting integer and use this as the private key *x*.362*363*/364#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t) 0x7002)365366/** Whether a key type is a DSA key (pair or public-only). */367#define PSA_KEY_TYPE_IS_DSA(type) \368(PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)369370#define PSA_ALG_DSA_BASE ((psa_algorithm_t) 0x06000400)371/** DSA signature with hashing.372*373* This is the signature scheme defined by FIPS 186-4,374* with a random per-message secret number (*k*).375*376* \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that377* #PSA_ALG_IS_HASH(\p hash_alg) is true).378* This includes #PSA_ALG_ANY_HASH379* when specifying the algorithm in a usage policy.380*381* \return The corresponding DSA signature algorithm.382* \return Unspecified if \p hash_alg is not a supported383* hash algorithm.384*/385#define PSA_ALG_DSA(hash_alg) \386(PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))387#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t) 0x06000500)388#define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG389/** Deterministic DSA signature with hashing.390*391* This is the deterministic variant defined by RFC 6979 of392* the signature scheme defined by FIPS 186-4.393*394* \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that395* #PSA_ALG_IS_HASH(\p hash_alg) is true).396* This includes #PSA_ALG_ANY_HASH397* when specifying the algorithm in a usage policy.398*399* \return The corresponding DSA signature algorithm.400* \return Unspecified if \p hash_alg is not a supported401* hash algorithm.402*/403#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \404(PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))405#define PSA_ALG_IS_DSA(alg) \406(((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \407PSA_ALG_DSA_BASE)408#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \409(((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)410#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \411(PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))412#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \413(PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))414415416/* We need to expand the sample definition of this macro from417* the API definition. */418#undef PSA_ALG_IS_VENDOR_HASH_AND_SIGN419#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) \420PSA_ALG_IS_DSA(alg)421422/**@}*/423424/** \addtogroup attributes425* @{426*/427428/** PAKE operation stages. */429#define PSA_PAKE_OPERATION_STAGE_SETUP 0430#define PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS 1431#define PSA_PAKE_OPERATION_STAGE_COMPUTATION 2432433/**@}*/434435436/** \defgroup psa_external_rng External random generator437* @{438*/439440#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)441/** External random generator function, implemented by the platform.442*443* When the compile-time option #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled,444* this function replaces Mbed TLS's entropy and DRBG modules for all445* random generation triggered via PSA crypto interfaces.446*447* \note This random generator must deliver random numbers with cryptographic448* quality and high performance. It must supply unpredictable numbers449* with a uniform distribution. The implementation of this function450* is responsible for ensuring that the random generator is seeded451* with sufficient entropy. If you have a hardware TRNG which is slow452* or delivers non-uniform output, declare it as an entropy source453* with mbedtls_entropy_add_source() instead of enabling this option.454*455* \param[in,out] context Pointer to the random generator context.456* This is all-bits-zero on the first call457* and preserved between successive calls.458* \param[out] output Output buffer. On success, this buffer459* contains random data with a uniform460* distribution.461* \param output_size The size of the \p output buffer in bytes.462* \param[out] output_length On success, set this value to \p output_size.463*464* \retval #PSA_SUCCESS465* Success. The output buffer contains \p output_size bytes of466* cryptographic-quality random data, and \c *output_length is467* set to \p output_size.468* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY469* The random generator requires extra entropy and there is no470* way to obtain entropy under current environment conditions.471* This error should not happen under normal circumstances since472* this function is responsible for obtaining as much entropy as473* it needs. However implementations of this function may return474* #PSA_ERROR_INSUFFICIENT_ENTROPY if there is no way to obtain475* entropy without blocking indefinitely.476* \retval #PSA_ERROR_HARDWARE_FAILURE477* A failure of the random generator hardware that isn't covered478* by #PSA_ERROR_INSUFFICIENT_ENTROPY.479*/480psa_status_t mbedtls_psa_external_get_random(481mbedtls_psa_external_random_context_t *context,482uint8_t *output, size_t output_size, size_t *output_length);483#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */484485/**@}*/486487/** \defgroup psa_builtin_keys Built-in keys488* @{489*/490491/** The minimum value for a key identifier that is built into the492* implementation.493*494* The range of key identifiers from #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN495* to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX within the range from496* #PSA_KEY_ID_VENDOR_MIN and #PSA_KEY_ID_VENDOR_MAX and must not intersect497* with any other set of implementation-chosen key identifiers.498*499* This value is part of the library's API since changing it would invalidate500* the values of built-in key identifiers in applications.501*/502#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t) 0x7fff0000)503504/** The maximum value for a key identifier that is built into the505* implementation.506*507* See #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN for more information.508*/509#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t) 0x7fffefff)510511/** A slot number identifying a key in a driver.512*513* Values of this type are used to identify built-in keys.514*/515typedef uint64_t psa_drv_slot_number_t;516517#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)518/** Test whether a key identifier belongs to the builtin key range.519*520* \param key_id Key identifier to test.521*522* \retval 1523* The key identifier is a builtin key identifier.524* \retval 0525* The key identifier is not a builtin key identifier.526*/527static inline int psa_key_id_is_builtin(psa_key_id_t key_id)528{529return (key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN) &&530(key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX);531}532533/** Platform function to obtain the location and slot number of a built-in key.534*535* An application-specific implementation of this function must be provided if536* #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided537* as part of a platform's system image.538*539* #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from540* #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX.541*542* In a multi-application configuration543* (\c MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined),544* this function should check that #MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(\p key_id)545* is allowed to use the given key.546*547* \param key_id The key ID for which to retrieve the548* location and slot attributes.549* \param[out] lifetime On success, the lifetime associated with the key550* corresponding to \p key_id. Lifetime is a551* combination of which driver contains the key,552* and with what persistence level the key is553* intended to be used. If the platform554* implementation does not contain specific555* information about the intended key persistence556* level, the persistence level may be reported as557* #PSA_KEY_PERSISTENCE_DEFAULT.558* \param[out] slot_number On success, the slot number known to the driver559* registered at the lifetime location reported560* through \p lifetime which corresponds to the561* requested built-in key.562*563* \retval #PSA_SUCCESS564* The requested key identifier designates a built-in key.565* In a multi-application configuration, the requested owner566* is allowed to access it.567* \retval #PSA_ERROR_DOES_NOT_EXIST568* The requested key identifier is not a built-in key which is known569* to this function. If a key exists in the key storage with this570* identifier, the data from the storage will be used.571* \return (any other error)572* Any other error is propagated to the function that requested the key.573* Common errors include:574* - #PSA_ERROR_NOT_PERMITTED: the key exists but the requested owner575* is not allowed to access it.576*/577psa_status_t mbedtls_psa_platform_get_builtin_key(578mbedtls_svc_key_id_t key_id,579psa_key_lifetime_t *lifetime,580psa_drv_slot_number_t *slot_number);581#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */582583/** @} */584585/** \defgroup psa_crypto_client Functions defined by a client provider586*587* The functions in this group are meant to be implemented by providers of588* the PSA Crypto client interface. They are provided by the library when589* #MBEDTLS_PSA_CRYPTO_C is enabled.590*591* \note All functions in this group are experimental, as using592* alternative client interface providers is experimental.593*594* @{595*/596597/** Check if PSA is capable of handling the specified hash algorithm.598*599* This means that PSA core was built with the corresponding PSA_WANT_ALG_xxx600* set and that psa_crypto_init has already been called.601*602* \note When using Mbed TLS version of PSA core (i.e. MBEDTLS_PSA_CRYPTO_C is603* set) for now this function only checks the state of the driver604* subsystem, not the algorithm. This might be improved in the future.605*606* \param hash_alg The hash algorithm.607*608* \return 1 if the PSA can handle \p hash_alg, 0 otherwise.609*/610int psa_can_do_hash(psa_algorithm_t hash_alg);611612/**@}*/613614/** \addtogroup crypto_types615* @{616*/617618#define PSA_ALG_CATEGORY_PAKE ((psa_algorithm_t) 0x0a000000)619620/** Whether the specified algorithm is a password-authenticated key exchange.621*622* \param alg An algorithm identifier (value of type #psa_algorithm_t).623*624* \return 1 if \p alg is a password-authenticated key exchange (PAKE)625* algorithm, 0 otherwise.626* This macro may return either 0 or 1 if \p alg is not a supported627* algorithm identifier.628*/629#define PSA_ALG_IS_PAKE(alg) \630(((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_PAKE)631632/** The Password-authenticated key exchange by juggling (J-PAKE) algorithm.633*634* This is J-PAKE as defined by RFC 8236, instantiated with the following635* parameters:636*637* - The group can be either an elliptic curve or defined over a finite field.638* - Schnorr NIZK proof as defined by RFC 8235 and using the same group as the639* J-PAKE algorithm.640* - A cryptographic hash function.641*642* To select these parameters and set up the cipher suite, call these functions643* in any order:644*645* \code646* psa_pake_cs_set_algorithm(cipher_suite, PSA_ALG_JPAKE);647* psa_pake_cs_set_primitive(cipher_suite,648* PSA_PAKE_PRIMITIVE(type, family, bits));649* psa_pake_cs_set_hash(cipher_suite, hash);650* \endcode651*652* For more information on how to set a specific curve or field, refer to the653* documentation of the individual \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.654*655* After initializing a J-PAKE operation, call656*657* \code658* psa_pake_setup(operation, cipher_suite);659* psa_pake_set_user(operation, ...);660* psa_pake_set_peer(operation, ...);661* psa_pake_set_password_key(operation, ...);662* \endcode663*664* The password is provided as a key. This can be the password text itself,665* in an agreed character encoding, or some value derived from the password666* as required by a higher level protocol.667*668* (The implementation converts the key material to a number as described in669* Section 2.3.8 of _SEC 1: Elliptic Curve Cryptography_670* (https://www.secg.org/sec1-v2.pdf), before reducing it modulo \c q. Here671* \c q is order of the group defined by the primitive set in the cipher suite.672* The \c psa_pake_set_password_key() function returns an error if the result673* of the reduction is 0.)674*675* The key exchange flow for J-PAKE is as follows:676* -# To get the first round data that needs to be sent to the peer, call677* \code678* // Get g1679* psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);680* // Get the ZKP public key for x1681* psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);682* // Get the ZKP proof for x1683* psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);684* // Get g2685* psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);686* // Get the ZKP public key for x2687* psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);688* // Get the ZKP proof for x2689* psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);690* \endcode691* -# To provide the first round data received from the peer to the operation,692* call693* \code694* // Set g3695* psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);696* // Set the ZKP public key for x3697* psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);698* // Set the ZKP proof for x3699* psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);700* // Set g4701* psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);702* // Set the ZKP public key for x4703* psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);704* // Set the ZKP proof for x4705* psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);706* \endcode707* -# To get the second round data that needs to be sent to the peer, call708* \code709* // Get A710* psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);711* // Get ZKP public key for x2*s712* psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);713* // Get ZKP proof for x2*s714* psa_pake_output(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);715* \endcode716* -# To provide the second round data received from the peer to the operation,717* call718* \code719* // Set B720* psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...);721* // Set ZKP public key for x4*s722* psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PUBLIC, ...);723* // Set ZKP proof for x4*s724* psa_pake_input(operation, #PSA_PAKE_STEP_ZK_PROOF, ...);725* \endcode726* -# To access the shared secret call727* \code728* // Get Ka=Kb=K729* psa_pake_get_implicit_key()730* \endcode731*732* For more information consult the documentation of the individual733* \c PSA_PAKE_STEP_XXX constants.734*735* At this point there is a cryptographic guarantee that only the authenticated736* party who used the same password is able to compute the key. But there is no737* guarantee that the peer is the party it claims to be and was able to do so.738*739* That is, the authentication is only implicit (the peer is not authenticated740* at this point, and no action should be taken that assume that they are - like741* for example accessing restricted files).742*743* To make the authentication explicit there are various methods, see Section 5744* of RFC 8236 for two examples.745*746*/747#define PSA_ALG_JPAKE ((psa_algorithm_t) 0x0a000100)748749/** @} */750751/** \defgroup pake Password-authenticated key exchange (PAKE)752*753* This is a proposed PAKE interface for the PSA Crypto API. It is not part of754* the official PSA Crypto API yet.755*756* \note The content of this section is not part of the stable API and ABI757* of Mbed TLS and may change arbitrarily from version to version.758* Same holds for the corresponding macros #PSA_ALG_CATEGORY_PAKE and759* #PSA_ALG_JPAKE.760* @{761*/762763/** \brief Encoding of the application role of PAKE764*765* Encodes the application's role in the algorithm is being executed. For more766* information see the documentation of individual \c PSA_PAKE_ROLE_XXX767* constants.768*/769typedef uint8_t psa_pake_role_t;770771/** Encoding of input and output indicators for PAKE.772*773* Some PAKE algorithms need to exchange more data than just a single key share.774* This type is for encoding additional input and output data for such775* algorithms.776*/777typedef uint8_t psa_pake_step_t;778779/** Encoding of the type of the PAKE's primitive.780*781* Values defined by this standard will never be in the range 0x80-0xff.782* Vendors who define additional types must use an encoding in this range.783*784* For more information see the documentation of individual785* \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.786*/787typedef uint8_t psa_pake_primitive_type_t;788789/** \brief Encoding of the family of the primitive associated with the PAKE.790*791* For more information see the documentation of individual792* \c PSA_PAKE_PRIMITIVE_TYPE_XXX constants.793*/794typedef uint8_t psa_pake_family_t;795796/** \brief Encoding of the primitive associated with the PAKE.797*798* For more information see the documentation of the #PSA_PAKE_PRIMITIVE macro.799*/800typedef uint32_t psa_pake_primitive_t;801802/** A value to indicate no role in a PAKE algorithm.803* This value can be used in a call to psa_pake_set_role() for symmetric PAKE804* algorithms which do not assign roles.805*/806#define PSA_PAKE_ROLE_NONE ((psa_pake_role_t) 0x00)807808/** The first peer in a balanced PAKE.809*810* Although balanced PAKE algorithms are symmetric, some of them needs an811* ordering of peers for the transcript calculations. If the algorithm does not812* need this, both #PSA_PAKE_ROLE_FIRST and #PSA_PAKE_ROLE_SECOND are813* accepted.814*/815#define PSA_PAKE_ROLE_FIRST ((psa_pake_role_t) 0x01)816817/** The second peer in a balanced PAKE.818*819* Although balanced PAKE algorithms are symmetric, some of them needs an820* ordering of peers for the transcript calculations. If the algorithm does not821* need this, either #PSA_PAKE_ROLE_FIRST or #PSA_PAKE_ROLE_SECOND are822* accepted.823*/824#define PSA_PAKE_ROLE_SECOND ((psa_pake_role_t) 0x02)825826/** The client in an augmented PAKE.827*828* Augmented PAKE algorithms need to differentiate between client and server.829*/830#define PSA_PAKE_ROLE_CLIENT ((psa_pake_role_t) 0x11)831832/** The server in an augmented PAKE.833*834* Augmented PAKE algorithms need to differentiate between client and server.835*/836#define PSA_PAKE_ROLE_SERVER ((psa_pake_role_t) 0x12)837838/** The PAKE primitive type indicating the use of elliptic curves.839*840* The values of the \c family and \c bits fields of the cipher suite identify a841* specific elliptic curve, using the same mapping that is used for ECC842* (::psa_ecc_family_t) keys.843*844* (Here \c family means the value returned by psa_pake_cs_get_family() and845* \c bits means the value returned by psa_pake_cs_get_bits().)846*847* Input and output during the operation can involve group elements and scalar848* values:849* -# The format for group elements is the same as for public keys on the850* specific curve would be. For more information, consult the documentation of851* psa_export_public_key().852* -# The format for scalars is the same as for private keys on the specific853* curve would be. For more information, consult the documentation of854* psa_export_key().855*/856#define PSA_PAKE_PRIMITIVE_TYPE_ECC ((psa_pake_primitive_type_t) 0x01)857858/** The PAKE primitive type indicating the use of Diffie-Hellman groups.859*860* The values of the \c family and \c bits fields of the cipher suite identify861* a specific Diffie-Hellman group, using the same mapping that is used for862* Diffie-Hellman (::psa_dh_family_t) keys.863*864* (Here \c family means the value returned by psa_pake_cs_get_family() and865* \c bits means the value returned by psa_pake_cs_get_bits().)866*867* Input and output during the operation can involve group elements and scalar868* values:869* -# The format for group elements is the same as for public keys on the870* specific group would be. For more information, consult the documentation of871* psa_export_public_key().872* -# The format for scalars is the same as for private keys on the specific873* group would be. For more information, consult the documentation of874* psa_export_key().875*/876#define PSA_PAKE_PRIMITIVE_TYPE_DH ((psa_pake_primitive_type_t) 0x02)877878/** Construct a PAKE primitive from type, family and bit-size.879*880* \param pake_type The type of the primitive881* (value of type ::psa_pake_primitive_type_t).882* \param pake_family The family of the primitive883* (the type and interpretation of this parameter depends884* on \p pake_type, for more information consult the885* documentation of individual ::psa_pake_primitive_type_t886* constants).887* \param pake_bits The bit-size of the primitive888* (Value of type \c size_t. The interpretation889* of this parameter depends on \p pake_family, for more890* information consult the documentation of individual891* ::psa_pake_primitive_type_t constants).892*893* \return The constructed primitive value of type ::psa_pake_primitive_t.894* Return 0 if the requested primitive can't be encoded as895* ::psa_pake_primitive_t.896*/897#define PSA_PAKE_PRIMITIVE(pake_type, pake_family, pake_bits) \898((pake_bits & 0xFFFF) != pake_bits) ? 0 : \899((psa_pake_primitive_t) (((pake_type) << 24 | \900(pake_family) << 16) | (pake_bits)))901902/** The key share being sent to or received from the peer.903*904* The format for both input and output at this step is the same as for public905* keys on the group determined by the primitive (::psa_pake_primitive_t) would906* be.907*908* For more information on the format, consult the documentation of909* psa_export_public_key().910*911* For information regarding how the group is determined, consult the912* documentation #PSA_PAKE_PRIMITIVE.913*/914#define PSA_PAKE_STEP_KEY_SHARE ((psa_pake_step_t) 0x01)915916/** A Schnorr NIZKP public key.917*918* This is the ephemeral public key in the Schnorr Non-Interactive919* Zero-Knowledge Proof (the value denoted by the letter 'V' in RFC 8235).920*921* The format for both input and output at this step is the same as for public922* keys on the group determined by the primitive (::psa_pake_primitive_t) would923* be.924*925* For more information on the format, consult the documentation of926* psa_export_public_key().927*928* For information regarding how the group is determined, consult the929* documentation #PSA_PAKE_PRIMITIVE.930*/931#define PSA_PAKE_STEP_ZK_PUBLIC ((psa_pake_step_t) 0x02)932933/** A Schnorr NIZKP proof.934*935* This is the proof in the Schnorr Non-Interactive Zero-Knowledge Proof (the936* value denoted by the letter 'r' in RFC 8235).937*938* Both for input and output, the value at this step is an integer less than939* the order of the group selected in the cipher suite. The format depends on940* the group as well:941*942* - For Montgomery curves, the encoding is little endian.943* - For everything else the encoding is big endian (see Section 2.3.8 of944* _SEC 1: Elliptic Curve Cryptography_ at https://www.secg.org/sec1-v2.pdf).945*946* In both cases leading zeroes are allowed as long as the length in bytes does947* not exceed the byte length of the group order.948*949* For information regarding how the group is determined, consult the950* documentation #PSA_PAKE_PRIMITIVE.951*/952#define PSA_PAKE_STEP_ZK_PROOF ((psa_pake_step_t) 0x03)953954/**@}*/955956/** A sufficient output buffer size for psa_pake_output().957*958* If the size of the output buffer is at least this large, it is guaranteed959* that psa_pake_output() will not fail due to an insufficient output buffer960* size. The actual size of the output might be smaller in any given call.961*962* See also #PSA_PAKE_OUTPUT_MAX_SIZE963*964* \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that965* #PSA_ALG_IS_PAKE(\p alg) is true).966* \param primitive A primitive of type ::psa_pake_primitive_t that is967* compatible with algorithm \p alg.968* \param output_step A value of type ::psa_pake_step_t that is valid for the969* algorithm \p alg.970* \return A sufficient output buffer size for the specified971* PAKE algorithm, primitive, and output step. If the972* PAKE algorithm, primitive, or output step is not973* recognized, or the parameters are incompatible,974* return 0.975*/976#define PSA_PAKE_OUTPUT_SIZE(alg, primitive, output_step) \977(alg == PSA_ALG_JPAKE && \978primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \979PSA_ECC_FAMILY_SECP_R1, 256) ? \980( \981output_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \982output_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \98332 \984) : \9850)986987/** A sufficient input buffer size for psa_pake_input().988*989* The value returned by this macro is guaranteed to be large enough for any990* valid input to psa_pake_input() in an operation with the specified991* parameters.992*993* See also #PSA_PAKE_INPUT_MAX_SIZE994*995* \param alg A PAKE algorithm (\c PSA_ALG_XXX value such that996* #PSA_ALG_IS_PAKE(\p alg) is true).997* \param primitive A primitive of type ::psa_pake_primitive_t that is998* compatible with algorithm \p alg.999* \param input_step A value of type ::psa_pake_step_t that is valid for the1000* algorithm \p alg.1001* \return A sufficient input buffer size for the specified1002* input, cipher suite and algorithm. If the cipher suite,1003* the input type or PAKE algorithm is not recognized, or1004* the parameters are incompatible, return 0.1005*/1006#define PSA_PAKE_INPUT_SIZE(alg, primitive, input_step) \1007(alg == PSA_ALG_JPAKE && \1008primitive == PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, \1009PSA_ECC_FAMILY_SECP_R1, 256) ? \1010( \1011input_step == PSA_PAKE_STEP_KEY_SHARE ? 65 : \1012input_step == PSA_PAKE_STEP_ZK_PUBLIC ? 65 : \101332 \1014) : \10150)10161017/** Output buffer size for psa_pake_output() for any of the supported PAKE1018* algorithm and primitive suites and output step.1019*1020* This macro must expand to a compile-time constant integer.1021*1022* The value of this macro must be at least as large as the largest value1023* returned by PSA_PAKE_OUTPUT_SIZE()1024*1025* See also #PSA_PAKE_OUTPUT_SIZE(\p alg, \p primitive, \p output_step).1026*/1027#define PSA_PAKE_OUTPUT_MAX_SIZE 6510281029/** Input buffer size for psa_pake_input() for any of the supported PAKE1030* algorithm and primitive suites and input step.1031*1032* This macro must expand to a compile-time constant integer.1033*1034* The value of this macro must be at least as large as the largest value1035* returned by PSA_PAKE_INPUT_SIZE()1036*1037* See also #PSA_PAKE_INPUT_SIZE(\p alg, \p primitive, \p output_step).1038*/1039#define PSA_PAKE_INPUT_MAX_SIZE 6510401041/** Returns a suitable initializer for a PAKE cipher suite object of type1042* psa_pake_cipher_suite_t.1043*/1044#define PSA_PAKE_CIPHER_SUITE_INIT { PSA_ALG_NONE, 0, 0, 0, PSA_ALG_NONE }10451046/** Returns a suitable initializer for a PAKE operation object of type1047* psa_pake_operation_t.1048*/1049#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)1050#define PSA_PAKE_OPERATION_INIT { 0 }1051#else1052#define PSA_PAKE_OPERATION_INIT { 0, PSA_ALG_NONE, 0, PSA_PAKE_OPERATION_STAGE_SETUP, \1053{ 0 }, { { 0 } } }1054#endif10551056struct psa_pake_cipher_suite_s {1057psa_algorithm_t algorithm;1058psa_pake_primitive_type_t type;1059psa_pake_family_t family;1060uint16_t bits;1061psa_algorithm_t hash;1062};10631064struct psa_crypto_driver_pake_inputs_s {1065uint8_t *MBEDTLS_PRIVATE(password);1066size_t MBEDTLS_PRIVATE(password_len);1067uint8_t *MBEDTLS_PRIVATE(user);1068size_t MBEDTLS_PRIVATE(user_len);1069uint8_t *MBEDTLS_PRIVATE(peer);1070size_t MBEDTLS_PRIVATE(peer_len);1071psa_key_attributes_t MBEDTLS_PRIVATE(attributes);1072struct psa_pake_cipher_suite_s MBEDTLS_PRIVATE(cipher_suite);1073};10741075typedef enum psa_crypto_driver_pake_step {1076PSA_JPAKE_STEP_INVALID = 0, /* Invalid step */1077PSA_JPAKE_X1_STEP_KEY_SHARE = 1, /* Round 1: input/output key share (for ephemeral private key X1).*/1078PSA_JPAKE_X1_STEP_ZK_PUBLIC = 2, /* Round 1: input/output Schnorr NIZKP public key for the X1 key */1079PSA_JPAKE_X1_STEP_ZK_PROOF = 3, /* Round 1: input/output Schnorr NIZKP proof for the X1 key */1080PSA_JPAKE_X2_STEP_KEY_SHARE = 4, /* Round 1: input/output key share (for ephemeral private key X2).*/1081PSA_JPAKE_X2_STEP_ZK_PUBLIC = 5, /* Round 1: input/output Schnorr NIZKP public key for the X2 key */1082PSA_JPAKE_X2_STEP_ZK_PROOF = 6, /* Round 1: input/output Schnorr NIZKP proof for the X2 key */1083PSA_JPAKE_X2S_STEP_KEY_SHARE = 7, /* Round 2: output X2S key (our key) */1084PSA_JPAKE_X2S_STEP_ZK_PUBLIC = 8, /* Round 2: output Schnorr NIZKP public key for the X2S key (our key) */1085PSA_JPAKE_X2S_STEP_ZK_PROOF = 9, /* Round 2: output Schnorr NIZKP proof for the X2S key (our key) */1086PSA_JPAKE_X4S_STEP_KEY_SHARE = 10, /* Round 2: input X4S key (from peer) */1087PSA_JPAKE_X4S_STEP_ZK_PUBLIC = 11, /* Round 2: input Schnorr NIZKP public key for the X4S key (from peer) */1088PSA_JPAKE_X4S_STEP_ZK_PROOF = 12 /* Round 2: input Schnorr NIZKP proof for the X4S key (from peer) */1089} psa_crypto_driver_pake_step_t;10901091typedef enum psa_jpake_round {1092PSA_JPAKE_FIRST = 0,1093PSA_JPAKE_SECOND = 1,1094PSA_JPAKE_FINISHED = 21095} psa_jpake_round_t;10961097typedef enum psa_jpake_io_mode {1098PSA_JPAKE_INPUT = 0,1099PSA_JPAKE_OUTPUT = 11100} psa_jpake_io_mode_t;11011102struct psa_jpake_computation_stage_s {1103/* The J-PAKE round we are currently on */1104psa_jpake_round_t MBEDTLS_PRIVATE(round);1105/* The 'mode' we are currently in (inputting or outputting) */1106psa_jpake_io_mode_t MBEDTLS_PRIVATE(io_mode);1107/* The number of completed inputs so far this round */1108uint8_t MBEDTLS_PRIVATE(inputs);1109/* The number of completed outputs so far this round */1110uint8_t MBEDTLS_PRIVATE(outputs);1111/* The next expected step (KEY_SHARE, ZK_PUBLIC or ZK_PROOF) */1112psa_pake_step_t MBEDTLS_PRIVATE(step);1113};11141115#define PSA_JPAKE_EXPECTED_INPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \1116((round) == PSA_JPAKE_FIRST ? 2 : 1))1117#define PSA_JPAKE_EXPECTED_OUTPUTS(round) ((round) == PSA_JPAKE_FINISHED ? 0 : \1118((round) == PSA_JPAKE_FIRST ? 2 : 1))11191120struct psa_pake_operation_s {1121#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)1122mbedtls_psa_client_handle_t handle;1123#else1124/** Unique ID indicating which driver got assigned to do the1125* operation. Since driver contexts are driver-specific, swapping1126* drivers halfway through the operation is not supported.1127* ID values are auto-generated in psa_crypto_driver_wrappers.h1128* ID value zero means the context is not valid or not assigned to1129* any driver (i.e. none of the driver contexts are active). */1130unsigned int MBEDTLS_PRIVATE(id);1131/* Algorithm of the PAKE operation */1132psa_algorithm_t MBEDTLS_PRIVATE(alg);1133/* A primitive of type compatible with algorithm */1134psa_pake_primitive_t MBEDTLS_PRIVATE(primitive);1135/* Stage of the PAKE operation: waiting for the setup, collecting inputs1136* or computing. */1137uint8_t MBEDTLS_PRIVATE(stage);1138/* Holds computation stage of the PAKE algorithms. */1139union {1140uint8_t MBEDTLS_PRIVATE(dummy);1141#if defined(PSA_WANT_ALG_JPAKE)1142struct psa_jpake_computation_stage_s MBEDTLS_PRIVATE(jpake);1143#endif1144} MBEDTLS_PRIVATE(computation_stage);1145union {1146psa_driver_pake_context_t MBEDTLS_PRIVATE(ctx);1147struct psa_crypto_driver_pake_inputs_s MBEDTLS_PRIVATE(inputs);1148} MBEDTLS_PRIVATE(data);1149#endif1150};11511152/** \addtogroup pake1153* @{1154*/11551156/** The type of the data structure for PAKE cipher suites.1157*1158* This is an implementation-defined \c struct. Applications should not1159* make any assumptions about the content of this structure.1160* Implementation details can change in future versions without notice.1161*/1162typedef struct psa_pake_cipher_suite_s psa_pake_cipher_suite_t;11631164/** Return an initial value for a PAKE cipher suite object.1165*/1166#if !(defined(__cplusplus) && defined(_MSC_VER))1167static psa_pake_cipher_suite_t psa_pake_cipher_suite_init(void);1168#endif11691170/** Retrieve the PAKE algorithm from a PAKE cipher suite.1171*1172* \param[in] cipher_suite The cipher suite structure to query.1173*1174* \return The PAKE algorithm stored in the cipher suite structure.1175*/1176static psa_algorithm_t psa_pake_cs_get_algorithm(1177const psa_pake_cipher_suite_t *cipher_suite);11781179/** Declare the PAKE algorithm for the cipher suite.1180*1181* This function overwrites any PAKE algorithm1182* previously set in \p cipher_suite.1183*1184* \param[out] cipher_suite The cipher suite structure to write to.1185* \param algorithm The PAKE algorithm to write.1186* (`PSA_ALG_XXX` values of type ::psa_algorithm_t1187* such that #PSA_ALG_IS_PAKE(\c alg) is true.)1188* If this is 0, the PAKE algorithm in1189* \p cipher_suite becomes unspecified.1190*/1191static void psa_pake_cs_set_algorithm(psa_pake_cipher_suite_t *cipher_suite,1192psa_algorithm_t algorithm);11931194/** Retrieve the primitive from a PAKE cipher suite.1195*1196* \param[in] cipher_suite The cipher suite structure to query.1197*1198* \return The primitive stored in the cipher suite structure.1199*/1200static psa_pake_primitive_t psa_pake_cs_get_primitive(1201const psa_pake_cipher_suite_t *cipher_suite);12021203/** Declare the primitive for a PAKE cipher suite.1204*1205* This function overwrites any primitive previously set in \p cipher_suite.1206*1207* \param[out] cipher_suite The cipher suite structure to write to.1208* \param primitive The primitive to write. If this is 0, the1209* primitive type in \p cipher_suite becomes1210* unspecified.1211*/1212static void psa_pake_cs_set_primitive(psa_pake_cipher_suite_t *cipher_suite,1213psa_pake_primitive_t primitive);12141215/** Retrieve the PAKE family from a PAKE cipher suite.1216*1217* \param[in] cipher_suite The cipher suite structure to query.1218*1219* \return The PAKE family stored in the cipher suite structure.1220*/1221static psa_pake_family_t psa_pake_cs_get_family(1222const psa_pake_cipher_suite_t *cipher_suite);12231224/** Retrieve the PAKE primitive bit-size from a PAKE cipher suite.1225*1226* \param[in] cipher_suite The cipher suite structure to query.1227*1228* \return The PAKE primitive bit-size stored in the cipher suite structure.1229*/1230static uint16_t psa_pake_cs_get_bits(1231const psa_pake_cipher_suite_t *cipher_suite);12321233/** Retrieve the hash algorithm from a PAKE cipher suite.1234*1235* \param[in] cipher_suite The cipher suite structure to query.1236*1237* \return The hash algorithm stored in the cipher suite structure. The return1238* value is 0 if the PAKE is not parametrised by a hash algorithm or if1239* the hash algorithm is not set.1240*/1241static psa_algorithm_t psa_pake_cs_get_hash(1242const psa_pake_cipher_suite_t *cipher_suite);12431244/** Declare the hash algorithm for a PAKE cipher suite.1245*1246* This function overwrites any hash algorithm1247* previously set in \p cipher_suite.1248*1249* Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`1250* values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)1251* for more information.1252*1253* \param[out] cipher_suite The cipher suite structure to write to.1254* \param hash The hash involved in the cipher suite.1255* (`PSA_ALG_XXX` values of type ::psa_algorithm_t1256* such that #PSA_ALG_IS_HASH(\c alg) is true.)1257* If this is 0, the hash algorithm in1258* \p cipher_suite becomes unspecified.1259*/1260static void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite,1261psa_algorithm_t hash);12621263/** The type of the state data structure for PAKE operations.1264*1265* Before calling any function on a PAKE operation object, the application1266* must initialize it by any of the following means:1267* - Set the structure to all-bits-zero, for example:1268* \code1269* psa_pake_operation_t operation;1270* memset(&operation, 0, sizeof(operation));1271* \endcode1272* - Initialize the structure to logical zero values, for example:1273* \code1274* psa_pake_operation_t operation = {0};1275* \endcode1276* - Initialize the structure to the initializer #PSA_PAKE_OPERATION_INIT,1277* for example:1278* \code1279* psa_pake_operation_t operation = PSA_PAKE_OPERATION_INIT;1280* \endcode1281* - Assign the result of the function psa_pake_operation_init()1282* to the structure, for example:1283* \code1284* psa_pake_operation_t operation;1285* operation = psa_pake_operation_init();1286* \endcode1287*1288* This is an implementation-defined \c struct. Applications should not1289* make any assumptions about the content of this structure.1290* Implementation details can change in future versions without notice. */1291typedef struct psa_pake_operation_s psa_pake_operation_t;12921293/** The type of input values for PAKE operations. */1294typedef struct psa_crypto_driver_pake_inputs_s psa_crypto_driver_pake_inputs_t;12951296/** The type of computation stage for J-PAKE operations. */1297typedef struct psa_jpake_computation_stage_s psa_jpake_computation_stage_t;12981299/** Return an initial value for a PAKE operation object.1300*/1301#if !(defined(__cplusplus) && defined(_MSC_VER))1302static psa_pake_operation_t psa_pake_operation_init(void);1303#endif13041305/** Get the length of the password in bytes from given inputs.1306*1307* \param[in] inputs Operation inputs.1308* \param[out] password_len Password length.1309*1310* \retval #PSA_SUCCESS1311* Success.1312* \retval #PSA_ERROR_BAD_STATE1313* Password hasn't been set yet.1314*/1315psa_status_t psa_crypto_driver_pake_get_password_len(1316const psa_crypto_driver_pake_inputs_t *inputs,1317size_t *password_len);13181319/** Get the password from given inputs.1320*1321* \param[in] inputs Operation inputs.1322* \param[out] buffer Return buffer for password.1323* \param buffer_size Size of the return buffer in bytes.1324* \param[out] buffer_length Actual size of the password in bytes.1325*1326* \retval #PSA_SUCCESS1327* Success.1328* \retval #PSA_ERROR_BAD_STATE1329* Password hasn't been set yet.1330*/1331psa_status_t psa_crypto_driver_pake_get_password(1332const psa_crypto_driver_pake_inputs_t *inputs,1333uint8_t *buffer, size_t buffer_size, size_t *buffer_length);13341335/** Get the length of the user id in bytes from given inputs.1336*1337* \param[in] inputs Operation inputs.1338* \param[out] user_len User id length.1339*1340* \retval #PSA_SUCCESS1341* Success.1342* \retval #PSA_ERROR_BAD_STATE1343* User id hasn't been set yet.1344*/1345psa_status_t psa_crypto_driver_pake_get_user_len(1346const psa_crypto_driver_pake_inputs_t *inputs,1347size_t *user_len);13481349/** Get the length of the peer id in bytes from given inputs.1350*1351* \param[in] inputs Operation inputs.1352* \param[out] peer_len Peer id length.1353*1354* \retval #PSA_SUCCESS1355* Success.1356* \retval #PSA_ERROR_BAD_STATE1357* Peer id hasn't been set yet.1358*/1359psa_status_t psa_crypto_driver_pake_get_peer_len(1360const psa_crypto_driver_pake_inputs_t *inputs,1361size_t *peer_len);13621363/** Get the user id from given inputs.1364*1365* \param[in] inputs Operation inputs.1366* \param[out] user_id User id.1367* \param user_id_size Size of \p user_id in bytes.1368* \param[out] user_id_len Size of the user id in bytes.1369*1370* \retval #PSA_SUCCESS1371* Success.1372* \retval #PSA_ERROR_BAD_STATE1373* User id hasn't been set yet.1374* \retval #PSA_ERROR_BUFFER_TOO_SMALL1375* The size of the \p user_id is too small.1376*/1377psa_status_t psa_crypto_driver_pake_get_user(1378const psa_crypto_driver_pake_inputs_t *inputs,1379uint8_t *user_id, size_t user_id_size, size_t *user_id_len);13801381/** Get the peer id from given inputs.1382*1383* \param[in] inputs Operation inputs.1384* \param[out] peer_id Peer id.1385* \param peer_id_size Size of \p peer_id in bytes.1386* \param[out] peer_id_length Size of the peer id in bytes.1387*1388* \retval #PSA_SUCCESS1389* Success.1390* \retval #PSA_ERROR_BAD_STATE1391* Peer id hasn't been set yet.1392* \retval #PSA_ERROR_BUFFER_TOO_SMALL1393* The size of the \p peer_id is too small.1394*/1395psa_status_t psa_crypto_driver_pake_get_peer(1396const psa_crypto_driver_pake_inputs_t *inputs,1397uint8_t *peer_id, size_t peer_id_size, size_t *peer_id_length);13981399/** Get the cipher suite from given inputs.1400*1401* \param[in] inputs Operation inputs.1402* \param[out] cipher_suite Return buffer for role.1403*1404* \retval #PSA_SUCCESS1405* Success.1406* \retval #PSA_ERROR_BAD_STATE1407* Cipher_suite hasn't been set yet.1408*/1409psa_status_t psa_crypto_driver_pake_get_cipher_suite(1410const psa_crypto_driver_pake_inputs_t *inputs,1411psa_pake_cipher_suite_t *cipher_suite);14121413/** Set the session information for a password-authenticated key exchange.1414*1415* The sequence of operations to set up a password-authenticated key exchange1416* is as follows:1417* -# Allocate an operation object which will be passed to all the functions1418* listed here.1419* -# Initialize the operation object with one of the methods described in the1420* documentation for #psa_pake_operation_t, e.g.1421* #PSA_PAKE_OPERATION_INIT.1422* -# Call psa_pake_setup() to specify the cipher suite.1423* -# Call \c psa_pake_set_xxx() functions on the operation to complete the1424* setup. The exact sequence of \c psa_pake_set_xxx() functions that needs1425* to be called depends on the algorithm in use.1426*1427* Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`1428* values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)1429* for more information.1430*1431* A typical sequence of calls to perform a password-authenticated key1432* exchange:1433* -# Call psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to get the1434* key share that needs to be sent to the peer.1435* -# Call psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to provide1436* the key share that was received from the peer.1437* -# Depending on the algorithm additional calls to psa_pake_output() and1438* psa_pake_input() might be necessary.1439* -# Call psa_pake_get_implicit_key() for accessing the shared secret.1440*1441* Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`1442* values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)1443* for more information.1444*1445* If an error occurs at any step after a call to psa_pake_setup(),1446* the operation will need to be reset by a call to psa_pake_abort(). The1447* application may call psa_pake_abort() at any time after the operation1448* has been initialized.1449*1450* After a successful call to psa_pake_setup(), the application must1451* eventually terminate the operation. The following events terminate an1452* operation:1453* - A call to psa_pake_abort().1454* - A successful call to psa_pake_get_implicit_key().1455*1456* \param[in,out] operation The operation object to set up. It must have1457* been initialized but not set up yet.1458* \param[in] cipher_suite The cipher suite to use. (A cipher suite fully1459* characterizes a PAKE algorithm and determines1460* the algorithm as well.)1461*1462* \retval #PSA_SUCCESS1463* Success.1464* \retval #PSA_ERROR_INVALID_ARGUMENT1465* The algorithm in \p cipher_suite is not a PAKE algorithm, or the1466* PAKE primitive in \p cipher_suite is not compatible with the1467* PAKE algorithm, or the hash algorithm in \p cipher_suite is invalid1468* or not compatible with the PAKE algorithm and primitive.1469* \retval #PSA_ERROR_NOT_SUPPORTED1470* The algorithm in \p cipher_suite is not a supported PAKE algorithm,1471* or the PAKE primitive in \p cipher_suite is not supported or not1472* compatible with the PAKE algorithm, or the hash algorithm in1473* \p cipher_suite is not supported or not compatible with the PAKE1474* algorithm and primitive.1475* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1476* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1477* \retval #PSA_ERROR_BAD_STATE1478* The operation state is not valid, or1479* the library has not been previously initialized by psa_crypto_init().1480* It is implementation-dependent whether a failure to initialize1481* results in this error code.1482*/1483psa_status_t psa_pake_setup(psa_pake_operation_t *operation,1484const psa_pake_cipher_suite_t *cipher_suite);14851486/** Set the password for a password-authenticated key exchange from key ID.1487*1488* Call this function when the password, or a value derived from the password,1489* is already present in the key store.1490*1491* \param[in,out] operation The operation object to set the password for. It1492* must have been set up by psa_pake_setup() and1493* not yet in use (neither psa_pake_output() nor1494* psa_pake_input() has been called yet). It must1495* be on operation for which the password hasn't1496* been set yet (psa_pake_set_password_key()1497* hasn't been called yet).1498* \param password Identifier of the key holding the password or a1499* value derived from the password (eg. by a1500* memory-hard function). It must remain valid1501* until the operation terminates. It must be of1502* type #PSA_KEY_TYPE_PASSWORD or1503* #PSA_KEY_TYPE_PASSWORD_HASH. It has to allow1504* the usage #PSA_KEY_USAGE_DERIVE.1505*1506* \retval #PSA_SUCCESS1507* Success.1508* \retval #PSA_ERROR_INVALID_HANDLE1509* \p password is not a valid key identifier.1510* \retval #PSA_ERROR_NOT_PERMITTED1511* The key does not have the #PSA_KEY_USAGE_DERIVE flag, or it does not1512* permit the \p operation's algorithm.1513* \retval #PSA_ERROR_INVALID_ARGUMENT1514* The key type for \p password is not #PSA_KEY_TYPE_PASSWORD or1515* #PSA_KEY_TYPE_PASSWORD_HASH, or \p password is not compatible with1516* the \p operation's cipher suite.1517* \retval #PSA_ERROR_NOT_SUPPORTED1518* The key type or key size of \p password is not supported with the1519* \p operation's cipher suite.1520* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1521* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1522* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription1523* \retval #PSA_ERROR_DATA_CORRUPT \emptydescription1524* \retval #PSA_ERROR_DATA_INVALID \emptydescription1525* \retval #PSA_ERROR_BAD_STATE1526* The operation state is not valid (it must have been set up.), or1527* the library has not been previously initialized by psa_crypto_init().1528* It is implementation-dependent whether a failure to initialize1529* results in this error code.1530*/1531psa_status_t psa_pake_set_password_key(psa_pake_operation_t *operation,1532mbedtls_svc_key_id_t password);15331534/** Set the user ID for a password-authenticated key exchange.1535*1536* Call this function to set the user ID. For PAKE algorithms that associate a1537* user identifier with each side of the session you need to call1538* psa_pake_set_peer() as well. For PAKE algorithms that associate a single1539* user identifier with the session, call psa_pake_set_user() only.1540*1541* Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`1542* values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)1543* for more information.1544*1545* \param[in,out] operation The operation object to set the user ID for. It1546* must have been set up by psa_pake_setup() and1547* not yet in use (neither psa_pake_output() nor1548* psa_pake_input() has been called yet). It must1549* be on operation for which the user ID hasn't1550* been set (psa_pake_set_user() hasn't been1551* called yet).1552* \param[in] user_id The user ID to authenticate with.1553* \param user_id_len Size of the \p user_id buffer in bytes.1554*1555* \retval #PSA_SUCCESS1556* Success.1557* \retval #PSA_ERROR_INVALID_ARGUMENT1558* \p user_id is not valid for the \p operation's algorithm and cipher1559* suite.1560* \retval #PSA_ERROR_NOT_SUPPORTED1561* The value of \p user_id is not supported by the implementation.1562* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription1563* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1564* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1565* \retval #PSA_ERROR_BAD_STATE1566* The operation state is not valid, or1567* the library has not been previously initialized by psa_crypto_init().1568* It is implementation-dependent whether a failure to initialize1569* results in this error code.1570*/1571psa_status_t psa_pake_set_user(psa_pake_operation_t *operation,1572const uint8_t *user_id,1573size_t user_id_len);15741575/** Set the peer ID for a password-authenticated key exchange.1576*1577* Call this function in addition to psa_pake_set_user() for PAKE algorithms1578* that associate a user identifier with each side of the session. For PAKE1579* algorithms that associate a single user identifier with the session, call1580* psa_pake_set_user() only.1581*1582* Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`1583* values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)1584* for more information.1585*1586* \param[in,out] operation The operation object to set the peer ID for. It1587* must have been set up by psa_pake_setup() and1588* not yet in use (neither psa_pake_output() nor1589* psa_pake_input() has been called yet). It must1590* be on operation for which the peer ID hasn't1591* been set (psa_pake_set_peer() hasn't been1592* called yet).1593* \param[in] peer_id The peer's ID to authenticate.1594* \param peer_id_len Size of the \p peer_id buffer in bytes.1595*1596* \retval #PSA_SUCCESS1597* Success.1598* \retval #PSA_ERROR_INVALID_ARGUMENT1599* \p peer_id is not valid for the \p operation's algorithm and cipher1600* suite.1601* \retval #PSA_ERROR_NOT_SUPPORTED1602* The algorithm doesn't associate a second identity with the session.1603* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription1604* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1605* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1606* \retval #PSA_ERROR_BAD_STATE1607* Calling psa_pake_set_peer() is invalid with the \p operation's1608* algorithm, the operation state is not valid, or the library has not1609* been previously initialized by psa_crypto_init().1610* It is implementation-dependent whether a failure to initialize1611* results in this error code.1612*/1613psa_status_t psa_pake_set_peer(psa_pake_operation_t *operation,1614const uint8_t *peer_id,1615size_t peer_id_len);16161617/** Set the application role for a password-authenticated key exchange.1618*1619* Not all PAKE algorithms need to differentiate the communicating entities.1620* It is optional to call this function for PAKEs that don't require a role1621* to be specified. For such PAKEs the application role parameter is ignored,1622* or #PSA_PAKE_ROLE_NONE can be passed as \c role.1623*1624* Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX`1625* values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true)1626* for more information.1627*1628* \param[in,out] operation The operation object to specify the1629* application's role for. It must have been set up1630* by psa_pake_setup() and not yet in use (neither1631* psa_pake_output() nor psa_pake_input() has been1632* called yet). It must be on operation for which1633* the application's role hasn't been specified1634* (psa_pake_set_role() hasn't been called yet).1635* \param role A value of type ::psa_pake_role_t indicating the1636* application's role in the PAKE the algorithm1637* that is being set up. For more information see1638* the documentation of \c PSA_PAKE_ROLE_XXX1639* constants.1640*1641* \retval #PSA_SUCCESS1642* Success.1643* \retval #PSA_ERROR_INVALID_ARGUMENT1644* The \p role is not a valid PAKE role in the \p operation’s algorithm.1645* \retval #PSA_ERROR_NOT_SUPPORTED1646* The \p role for this algorithm is not supported or is not valid.1647* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1648* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1649* \retval #PSA_ERROR_BAD_STATE1650* The operation state is not valid, or1651* the library has not been previously initialized by psa_crypto_init().1652* It is implementation-dependent whether a failure to initialize1653* results in this error code.1654*/1655psa_status_t psa_pake_set_role(psa_pake_operation_t *operation,1656psa_pake_role_t role);16571658/** Get output for a step of a password-authenticated key exchange.1659*1660* Depending on the algorithm being executed, you might need to call this1661* function several times or you might not need to call this at all.1662*1663* The exact sequence of calls to perform a password-authenticated key1664* exchange depends on the algorithm in use. Refer to the documentation of1665* individual PAKE algorithm types (`PSA_ALG_XXX` values of type1666* ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more1667* information.1668*1669* If this function returns an error status, the operation enters an error1670* state and must be aborted by calling psa_pake_abort().1671*1672* \param[in,out] operation Active PAKE operation.1673* \param step The step of the algorithm for which the output is1674* requested.1675* \param[out] output Buffer where the output is to be written in the1676* format appropriate for this \p step. Refer to1677* the documentation of the individual1678* \c PSA_PAKE_STEP_XXX constants for more1679* information.1680* \param output_size Size of the \p output buffer in bytes. This must1681* be at least #PSA_PAKE_OUTPUT_SIZE(\c alg, \c1682* primitive, \p output_step) where \c alg and1683* \p primitive are the PAKE algorithm and primitive1684* in the operation's cipher suite, and \p step is1685* the output step.1686*1687* \param[out] output_length On success, the number of bytes of the returned1688* output.1689*1690* \retval #PSA_SUCCESS1691* Success.1692* \retval #PSA_ERROR_BUFFER_TOO_SMALL1693* The size of the \p output buffer is too small.1694* \retval #PSA_ERROR_INVALID_ARGUMENT1695* \p step is not compatible with the operation's algorithm.1696* \retval #PSA_ERROR_NOT_SUPPORTED1697* \p step is not supported with the operation's algorithm.1698* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription1699* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription1700* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1701* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1702* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription1703* \retval #PSA_ERROR_DATA_CORRUPT \emptydescription1704* \retval #PSA_ERROR_DATA_INVALID \emptydescription1705* \retval #PSA_ERROR_BAD_STATE1706* The operation state is not valid (it must be active, and fully set1707* up, and this call must conform to the algorithm's requirements1708* for ordering of input and output steps), or1709* the library has not been previously initialized by psa_crypto_init().1710* It is implementation-dependent whether a failure to initialize1711* results in this error code.1712*/1713psa_status_t psa_pake_output(psa_pake_operation_t *operation,1714psa_pake_step_t step,1715uint8_t *output,1716size_t output_size,1717size_t *output_length);17181719/** Provide input for a step of a password-authenticated key exchange.1720*1721* Depending on the algorithm being executed, you might need to call this1722* function several times or you might not need to call this at all.1723*1724* The exact sequence of calls to perform a password-authenticated key1725* exchange depends on the algorithm in use. Refer to the documentation of1726* individual PAKE algorithm types (`PSA_ALG_XXX` values of type1727* ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more1728* information.1729*1730* If this function returns an error status, the operation enters an error1731* state and must be aborted by calling psa_pake_abort().1732*1733* \param[in,out] operation Active PAKE operation.1734* \param step The step for which the input is provided.1735* \param[in] input Buffer containing the input in the format1736* appropriate for this \p step. Refer to the1737* documentation of the individual1738* \c PSA_PAKE_STEP_XXX constants for more1739* information.1740* \param input_length Size of the \p input buffer in bytes.1741*1742* \retval #PSA_SUCCESS1743* Success.1744* \retval #PSA_ERROR_INVALID_SIGNATURE1745* The verification fails for a #PSA_PAKE_STEP_ZK_PROOF input step.1746* \retval #PSA_ERROR_INVALID_ARGUMENT1747* \p input_length is not compatible with the \p operation’s algorithm,1748* or the \p input is not valid for the \p operation's algorithm,1749* cipher suite or \p step.1750* \retval #PSA_ERROR_NOT_SUPPORTED1751* \p step p is not supported with the \p operation's algorithm, or the1752* \p input is not supported for the \p operation's algorithm, cipher1753* suite or \p step.1754* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription1755* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1756* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1757* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription1758* \retval #PSA_ERROR_DATA_CORRUPT \emptydescription1759* \retval #PSA_ERROR_DATA_INVALID \emptydescription1760* \retval #PSA_ERROR_BAD_STATE1761* The operation state is not valid (it must be active, and fully set1762* up, and this call must conform to the algorithm's requirements1763* for ordering of input and output steps), or1764* the library has not been previously initialized by psa_crypto_init().1765* It is implementation-dependent whether a failure to initialize1766* results in this error code.1767*/1768psa_status_t psa_pake_input(psa_pake_operation_t *operation,1769psa_pake_step_t step,1770const uint8_t *input,1771size_t input_length);17721773/** Get implicitly confirmed shared secret from a PAKE.1774*1775* At this point there is a cryptographic guarantee that only the authenticated1776* party who used the same password is able to compute the key. But there is no1777* guarantee that the peer is the party it claims to be and was able to do so.1778*1779* That is, the authentication is only implicit. Since the peer is not1780* authenticated yet, no action should be taken yet that assumes that the peer1781* is who it claims to be. For example, do not access restricted files on the1782* peer's behalf until an explicit authentication has succeeded.1783*1784* This function can be called after the key exchange phase of the operation1785* has completed. It imports the shared secret output of the PAKE into the1786* provided derivation operation. The input step1787* #PSA_KEY_DERIVATION_INPUT_SECRET is used when placing the shared key1788* material in the key derivation operation.1789*1790* The exact sequence of calls to perform a password-authenticated key1791* exchange depends on the algorithm in use. Refer to the documentation of1792* individual PAKE algorithm types (`PSA_ALG_XXX` values of type1793* ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more1794* information.1795*1796* When this function returns successfully, \p operation becomes inactive.1797* If this function returns an error status, both \p operation1798* and \c key_derivation operations enter an error state and must be aborted by1799* calling psa_pake_abort() and psa_key_derivation_abort() respectively.1800*1801* \param[in,out] operation Active PAKE operation.1802* \param[out] output A key derivation operation that is ready1803* for an input step of type1804* #PSA_KEY_DERIVATION_INPUT_SECRET.1805*1806* \retval #PSA_SUCCESS1807* Success.1808* \retval #PSA_ERROR_INVALID_ARGUMENT1809* #PSA_KEY_DERIVATION_INPUT_SECRET is not compatible with the1810* algorithm in the \p output key derivation operation.1811* \retval #PSA_ERROR_NOT_SUPPORTED1812* Input from a PAKE is not supported by the algorithm in the \p output1813* key derivation operation.1814* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription1815* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1816* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1817* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription1818* \retval #PSA_ERROR_DATA_CORRUPT \emptydescription1819* \retval #PSA_ERROR_DATA_INVALID \emptydescription1820* \retval #PSA_ERROR_BAD_STATE1821* The PAKE operation state is not valid (it must be active, but beyond1822* that validity is specific to the algorithm), or1823* the library has not been previously initialized by psa_crypto_init(),1824* or the state of \p output is not valid for1825* the #PSA_KEY_DERIVATION_INPUT_SECRET step. This can happen if the1826* step is out of order or the application has done this step already1827* and it may not be repeated.1828* It is implementation-dependent whether a failure to initialize1829* results in this error code.1830*/1831psa_status_t psa_pake_get_implicit_key(psa_pake_operation_t *operation,1832psa_key_derivation_operation_t *output);18331834/** Abort a PAKE operation.1835*1836* Aborting an operation frees all associated resources except for the \c1837* operation structure itself. Once aborted, the operation object can be reused1838* for another operation by calling psa_pake_setup() again.1839*1840* This function may be called at any time after the operation1841* object has been initialized as described in #psa_pake_operation_t.1842*1843* In particular, calling psa_pake_abort() after the operation has been1844* terminated by a call to psa_pake_abort() or psa_pake_get_implicit_key()1845* is safe and has no effect.1846*1847* \param[in,out] operation The operation to abort.1848*1849* \retval #PSA_SUCCESS1850* Success.1851* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription1852* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription1853* \retval #PSA_ERROR_BAD_STATE1854* The library has not been previously initialized by psa_crypto_init().1855* It is implementation-dependent whether a failure to initialize1856* results in this error code.1857*/1858psa_status_t psa_pake_abort(psa_pake_operation_t *operation);18591860/**@}*/18611862static inline psa_algorithm_t psa_pake_cs_get_algorithm(1863const psa_pake_cipher_suite_t *cipher_suite)1864{1865return cipher_suite->algorithm;1866}18671868static inline void psa_pake_cs_set_algorithm(1869psa_pake_cipher_suite_t *cipher_suite,1870psa_algorithm_t algorithm)1871{1872if (!PSA_ALG_IS_PAKE(algorithm)) {1873cipher_suite->algorithm = 0;1874} else {1875cipher_suite->algorithm = algorithm;1876}1877}18781879static inline psa_pake_primitive_t psa_pake_cs_get_primitive(1880const psa_pake_cipher_suite_t *cipher_suite)1881{1882return PSA_PAKE_PRIMITIVE(cipher_suite->type, cipher_suite->family,1883cipher_suite->bits);1884}18851886static inline void psa_pake_cs_set_primitive(1887psa_pake_cipher_suite_t *cipher_suite,1888psa_pake_primitive_t primitive)1889{1890cipher_suite->type = (psa_pake_primitive_type_t) (primitive >> 24);1891cipher_suite->family = (psa_pake_family_t) (0xFF & (primitive >> 16));1892cipher_suite->bits = (uint16_t) (0xFFFF & primitive);1893}18941895static inline psa_pake_family_t psa_pake_cs_get_family(1896const psa_pake_cipher_suite_t *cipher_suite)1897{1898return cipher_suite->family;1899}19001901static inline uint16_t psa_pake_cs_get_bits(1902const psa_pake_cipher_suite_t *cipher_suite)1903{1904return cipher_suite->bits;1905}19061907static inline psa_algorithm_t psa_pake_cs_get_hash(1908const psa_pake_cipher_suite_t *cipher_suite)1909{1910return cipher_suite->hash;1911}19121913static inline void psa_pake_cs_set_hash(psa_pake_cipher_suite_t *cipher_suite,1914psa_algorithm_t hash)1915{1916if (!PSA_ALG_IS_HASH(hash)) {1917cipher_suite->hash = 0;1918} else {1919cipher_suite->hash = hash;1920}1921}19221923static inline struct psa_pake_cipher_suite_s psa_pake_cipher_suite_init(void)1924{1925const struct psa_pake_cipher_suite_s v = PSA_PAKE_CIPHER_SUITE_INIT;1926return v;1927}19281929static inline struct psa_pake_operation_s psa_pake_operation_init(void)1930{1931const struct psa_pake_operation_s v = PSA_PAKE_OPERATION_INIT;1932return v;1933}19341935#ifdef __cplusplus1936}1937#endif19381939#endif /* PSA_CRYPTO_EXTRA_H */194019411942