blob: 9bdcc33872895c98596e8df6cd9a3ac97f462139 [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
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#ifndef PSA_CRYPTO_PAKE_H
22#define PSA_CRYPTO_PAKE_H
23
24#include <psa/crypto.h>
25
26/** Set the session information for a password-authenticated key exchange.
27 *
Przemek Stekielca674832022-12-07 14:47:34 +010028 * \note The signature of this function is that of a PSA driver
29 * pake_setup entry point. This function behaves as a pake_setup
30 * entry point as defined in the PSA driver interface specification for
31 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020032 *
33 * \param[in,out] operation The operation object to set up. It must have
34 * been initialized but not set up yet.
Przemek Stekielca674832022-12-07 14:47:34 +010035 * \param[in] inputs Inputs required for PAKE operation (role, password,
36 * key lifetime, cipher suite)
Neil Armstrong56b8d232022-06-01 18:05:57 +020037 *
38 * \retval #PSA_SUCCESS
39 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +020040 * \retval #PSA_ERROR_NOT_SUPPORTED
41 * The algorithm in \p cipher_suite is not a supported PAKE algorithm,
42 * or the PAKE primitive in \p cipher_suite is not supported or not
43 * compatible with the PAKE algorithm, or the hash algorithm in
44 * \p cipher_suite is not supported or not compatible with the PAKE
45 * algorithm and primitive.
Przemek Stekiel6b648622023-02-19 22:55:33 +010046 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
47 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +020048 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010049psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel51eac532022-12-07 11:04:51 +010050 const psa_crypto_driver_pake_inputs_t *inputs);
Neil Armstrong56b8d232022-06-01 18:05:57 +020051
Neil Armstrong56b8d232022-06-01 18:05:57 +020052
53/** Get output for a step of a password-authenticated key exchange.
54 *
Przemek Stekielca674832022-12-07 14:47:34 +010055 * \note The signature of this function is that of a PSA driver
56 * pake_output entry point. This function behaves as a pake_output
57 * entry point as defined in the PSA driver interface specification for
58 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020059 *
60 * \param[in,out] operation Active PAKE operation.
61 * \param step The step of the algorithm for which the output is
62 * requested.
63 * \param[out] output Buffer where the output is to be written in the
Przemek Stekiel6b648622023-02-19 22:55:33 +010064 * format appropriate for this driver \p step. Refer to
65 * the documentation of psa_crypto_driver_pake_step_t for
66 * more information.
Neil Armstrong56b8d232022-06-01 18:05:57 +020067 * \param output_size Size of the \p output buffer in bytes. This must
68 * be at least #PSA_PAKE_OUTPUT_SIZE(\p alg, \p
69 * primitive, \p step) where \p alg and
70 * \p primitive are the PAKE algorithm and primitive
71 * in the operation's cipher suite, and \p step is
72 * the output step.
73 *
74 * \param[out] output_length On success, the number of bytes of the returned
75 * output.
76 *
77 * \retval #PSA_SUCCESS
78 * Success.
79 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
80 * The size of the \p output buffer is too small.
Neil Armstrong56b8d232022-06-01 18:05:57 +020081 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
Neil Armstrong56b8d232022-06-01 18:05:57 +020082 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +020083 * \retval #PSA_ERROR_DATA_CORRUPT
84 * \retval #PSA_ERROR_DATA_INVALID
Neil Armstrong56b8d232022-06-01 18:05:57 +020085 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010086psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +010087 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +020088 uint8_t *output,
89 size_t output_size,
90 size_t *output_length);
91
92/** Provide input for a step of a password-authenticated key exchange.
93 *
Przemek Stekielca674832022-12-07 14:47:34 +010094 * \note The signature of this function is that of a PSA driver
Przemek Stekiel6b648622023-02-19 22:55:33 +010095 * pake_input entry point. This function behaves as a pake_input
Przemek Stekielca674832022-12-07 14:47:34 +010096 * entry point as defined in the PSA driver interface specification for
97 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020098 *
99 * \param[in,out] operation Active PAKE operation.
Przemek Stekiel6b648622023-02-19 22:55:33 +0100100 * \param step The driver step for which the input is provided.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200101 * \param[in] input Buffer containing the input in the format
102 * appropriate for this \p step. Refer to the
Przemek Stekiel6b648622023-02-19 22:55:33 +0100103 * documentation of psa_crypto_driver_pake_step_t
104 * for more information.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200105 * \param input_length Size of the \p input buffer in bytes.
106 *
107 * \retval #PSA_SUCCESS
108 * Success.
109 * \retval #PSA_ERROR_INVALID_SIGNATURE
Przemek Stekiel6b648622023-02-19 22:55:33 +0100110 * The verification fails for a zero-knowledge input step.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200111 * \retval #PSA_ERROR_INVALID_ARGUMENT
Przemek Stekiel6b648622023-02-19 22:55:33 +0100112 * the \p input is not valid for the \p operation's algorithm, cipher suite
Neil Armstrong56b8d232022-06-01 18:05:57 +0200113 * or \p step.
114 * \retval #PSA_ERROR_NOT_SUPPORTED
Przemek Stekiel6b648622023-02-19 22:55:33 +0100115 * the \p input is not supported for the \p operation's algorithm, cipher
Neil Armstrong56b8d232022-06-01 18:05:57 +0200116 * suite or \p step.
117 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Neil Armstrong56b8d232022-06-01 18:05:57 +0200118 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +0200119 * \retval #PSA_ERROR_DATA_CORRUPT
120 * \retval #PSA_ERROR_DATA_INVALID
Neil Armstrong56b8d232022-06-01 18:05:57 +0200121 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100122psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +0100123 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200124 const uint8_t *input,
125 size_t input_length);
126
127/** Get implicitly confirmed shared secret from a PAKE.
128 *
Przemek Stekielca674832022-12-07 14:47:34 +0100129 * \note The signature of this function is that of a PSA driver
130 * pake_get_implicit_key entry point. This function behaves as a
131 * pake_get_implicit_key entry point as defined in the PSA driver
132 * interface specification for transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200133 *
134 * \param[in,out] operation Active PAKE operation.
Przemek Stekiel6b648622023-02-19 22:55:33 +0100135 * \param[out] output Output buffer for implicit key.
136 * \param output_size Size of the output buffer in bytes.
137 * \param[out] output_length On success, the number of bytes of the implicit key.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200138 *
139 * \retval #PSA_SUCCESS
140 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200141 * \retval #PSA_ERROR_NOT_SUPPORTED
142 * Input from a PAKE is not supported by the algorithm in the \p output
143 * key derivation operation.
144 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Neil Armstrong56b8d232022-06-01 18:05:57 +0200145 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +0200146 * \retval #PSA_ERROR_DATA_CORRUPT
147 * \retval #PSA_ERROR_DATA_INVALID
Neil Armstrong56b8d232022-06-01 18:05:57 +0200148 */
149psa_status_t mbedtls_psa_pake_get_implicit_key(
Przemek Stekiel6c764412022-11-22 14:05:12 +0100150 mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel6b648622023-02-19 22:55:33 +0100151 uint8_t *output, size_t output_size,
152 size_t *output_length);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200153
154/** Abort a PAKE operation.
155 *
Przemek Stekielca674832022-12-07 14:47:34 +0100156 * \note The signature of this function is that of a PSA driver
157 * pake_abort entry point. This function behaves as a pake_abort
158 * entry point as defined in the PSA driver interface specification for
159 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200160 *
161 * \param[in,out] operation The operation to abort.
162 *
163 * \retval #PSA_SUCCESS
164 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200165 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +0200166 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100167psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200168
169#endif /* PSA_CRYPTO_PAKE_H */