blob: 3d3ee0cc9af14fdb56d422284231beaaa8321789 [file] [log] [blame]
Neil Armstrong56b8d232022-06-01 18:05:57 +02001/*
2 * PSA PAKE layer on top of Mbed TLS software crypto
3 */
4/*
5 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00006 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Neil Armstrong56b8d232022-06-01 18:05:57 +02007 */
8
9#ifndef PSA_CRYPTO_PAKE_H
10#define PSA_CRYPTO_PAKE_H
11
12#include <psa/crypto.h>
13
14/** Set the session information for a password-authenticated key exchange.
15 *
Przemek Stekielca674832022-12-07 14:47:34 +010016 * \note The signature of this function is that of a PSA driver
17 * pake_setup entry point. This function behaves as a pake_setup
18 * entry point as defined in the PSA driver interface specification for
19 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020020 *
21 * \param[in,out] operation The operation object to set up. It must have
22 * been initialized but not set up yet.
Przemek Stekielca674832022-12-07 14:47:34 +010023 * \param[in] inputs Inputs required for PAKE operation (role, password,
24 * key lifetime, cipher suite)
Neil Armstrong56b8d232022-06-01 18:05:57 +020025 *
26 * \retval #PSA_SUCCESS
27 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +020028 * \retval #PSA_ERROR_NOT_SUPPORTED
29 * The algorithm in \p cipher_suite is not a supported PAKE algorithm,
30 * or the PAKE primitive in \p cipher_suite is not supported or not
31 * compatible with the PAKE algorithm, or the hash algorithm in
32 * \p cipher_suite is not supported or not compatible with the PAKE
33 * algorithm and primitive.
Paul Elliott24f4b732023-06-20 15:51:46 +010034 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
35 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Neil Armstrong56b8d232022-06-01 18:05:57 +020036 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010037psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel51eac532022-12-07 11:04:51 +010038 const psa_crypto_driver_pake_inputs_t *inputs);
Neil Armstrong56b8d232022-06-01 18:05:57 +020039
Neil Armstrong56b8d232022-06-01 18:05:57 +020040
41/** Get output for a step of a password-authenticated key exchange.
42 *
Przemek Stekielca674832022-12-07 14:47:34 +010043 * \note The signature of this function is that of a PSA driver
44 * pake_output entry point. This function behaves as a pake_output
45 * entry point as defined in the PSA driver interface specification for
46 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020047 *
48 * \param[in,out] operation Active PAKE operation.
49 * \param step The step of the algorithm for which the output is
50 * requested.
51 * \param[out] output Buffer where the output is to be written in the
Przemek Stekiel6b648622023-02-19 22:55:33 +010052 * format appropriate for this driver \p step. Refer to
53 * the documentation of psa_crypto_driver_pake_step_t for
54 * more information.
Neil Armstrong56b8d232022-06-01 18:05:57 +020055 * \param output_size Size of the \p output buffer in bytes. This must
56 * be at least #PSA_PAKE_OUTPUT_SIZE(\p alg, \p
57 * primitive, \p step) where \p alg and
58 * \p primitive are the PAKE algorithm and primitive
59 * in the operation's cipher suite, and \p step is
60 * the output step.
61 *
62 * \param[out] output_length On success, the number of bytes of the returned
63 * output.
64 *
65 * \retval #PSA_SUCCESS
66 * Success.
67 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
68 * The size of the \p output buffer is too small.
Paul Elliott24f4b732023-06-20 15:51:46 +010069 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
70 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
71 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
72 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Neil Armstrong56b8d232022-06-01 18:05:57 +020073 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010074psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +010075 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +020076 uint8_t *output,
77 size_t output_size,
78 size_t *output_length);
79
80/** Provide input for a step of a password-authenticated key exchange.
81 *
Przemek Stekielca674832022-12-07 14:47:34 +010082 * \note The signature of this function is that of a PSA driver
Przemek Stekiel6b648622023-02-19 22:55:33 +010083 * pake_input entry point. This function behaves as a pake_input
Przemek Stekielca674832022-12-07 14:47:34 +010084 * entry point as defined in the PSA driver interface specification for
85 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020086 *
Przemek Stekiel691e91a2023-03-07 16:26:37 +010087 * \note The core checks that input_length is smaller than PSA_PAKE_INPUT_MAX_SIZE.
Przemek Stekiel4dc83d42023-02-27 11:49:35 +010088 *
Neil Armstrong56b8d232022-06-01 18:05:57 +020089 * \param[in,out] operation Active PAKE operation.
Przemek Stekiel6b648622023-02-19 22:55:33 +010090 * \param step The driver step for which the input is provided.
Neil Armstrong56b8d232022-06-01 18:05:57 +020091 * \param[in] input Buffer containing the input in the format
92 * appropriate for this \p step. Refer to the
Przemek Stekiel6b648622023-02-19 22:55:33 +010093 * documentation of psa_crypto_driver_pake_step_t
94 * for more information.
Neil Armstrong56b8d232022-06-01 18:05:57 +020095 * \param input_length Size of the \p input buffer in bytes.
96 *
97 * \retval #PSA_SUCCESS
98 * Success.
99 * \retval #PSA_ERROR_INVALID_SIGNATURE
Przemek Stekiel6b648622023-02-19 22:55:33 +0100100 * The verification fails for a zero-knowledge input step.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200101 * \retval #PSA_ERROR_INVALID_ARGUMENT
Przemek Stekiel6b648622023-02-19 22:55:33 +0100102 * the \p input is not valid for the \p operation's algorithm, cipher suite
Neil Armstrong56b8d232022-06-01 18:05:57 +0200103 * or \p step.
104 * \retval #PSA_ERROR_NOT_SUPPORTED
Przemek Stekiel6b648622023-02-19 22:55:33 +0100105 * the \p input is not supported for the \p operation's algorithm, cipher
Neil Armstrong56b8d232022-06-01 18:05:57 +0200106 * suite or \p step.
Paul Elliott24f4b732023-06-20 15:51:46 +0100107 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
108 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
109 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
110 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Neil Armstrong56b8d232022-06-01 18:05:57 +0200111 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100112psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +0100113 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200114 const uint8_t *input,
115 size_t input_length);
116
117/** Get implicitly confirmed shared secret from a PAKE.
118 *
Przemek Stekielca674832022-12-07 14:47:34 +0100119 * \note The signature of this function is that of a PSA driver
120 * pake_get_implicit_key entry point. This function behaves as a
121 * pake_get_implicit_key entry point as defined in the PSA driver
122 * interface specification for transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200123 *
124 * \param[in,out] operation Active PAKE operation.
Przemek Stekiel6b648622023-02-19 22:55:33 +0100125 * \param[out] output Output buffer for implicit key.
126 * \param output_size Size of the output buffer in bytes.
127 * \param[out] output_length On success, the number of bytes of the implicit key.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200128 *
129 * \retval #PSA_SUCCESS
130 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200131 * \retval #PSA_ERROR_NOT_SUPPORTED
132 * Input from a PAKE is not supported by the algorithm in the \p output
133 * key derivation operation.
Paul Elliott24f4b732023-06-20 15:51:46 +0100134 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
135 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
136 * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
137 * \retval #PSA_ERROR_DATA_INVALID \emptydescription
Neil Armstrong56b8d232022-06-01 18:05:57 +0200138 */
139psa_status_t mbedtls_psa_pake_get_implicit_key(
Przemek Stekiel6c764412022-11-22 14:05:12 +0100140 mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel6b648622023-02-19 22:55:33 +0100141 uint8_t *output, size_t output_size,
142 size_t *output_length);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200143
144/** Abort a PAKE operation.
145 *
Przemek Stekielca674832022-12-07 14:47:34 +0100146 * \note The signature of this function is that of a PSA driver
147 * pake_abort entry point. This function behaves as a pake_abort
148 * entry point as defined in the PSA driver interface specification for
149 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200150 *
151 * \param[in,out] operation The operation to abort.
152 *
153 * \retval #PSA_SUCCESS
154 * Success.
Paul Elliott24f4b732023-06-20 15:51:46 +0100155 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Neil Armstrong56b8d232022-06-01 18:05:57 +0200156 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100157psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200158
159#endif /* PSA_CRYPTO_PAKE_H */