blob: eb308813e9e9399a941f08c3224d51057c38f36d [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 *
Przemek Stekiel4dc83d42023-02-27 11:49:35 +010099 * \note The core has checked that input_length is smaller than
100 PSA_PAKE_INPUT_SIZE(PSA_ALG_JPAKE, primitive, step)
101 where primitive is the JPAKE algorithm primitive and step
102 the PSA API level input step. Thus no risk of integer overflow while
103 checking operation buffer overflow.
104 *
Neil Armstrong56b8d232022-06-01 18:05:57 +0200105 * \param[in,out] operation Active PAKE operation.
Przemek Stekiel6b648622023-02-19 22:55:33 +0100106 * \param step The driver step for which the input is provided.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200107 * \param[in] input Buffer containing the input in the format
108 * appropriate for this \p step. Refer to the
Przemek Stekiel6b648622023-02-19 22:55:33 +0100109 * documentation of psa_crypto_driver_pake_step_t
110 * for more information.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200111 * \param input_length Size of the \p input buffer in bytes.
112 *
113 * \retval #PSA_SUCCESS
114 * Success.
115 * \retval #PSA_ERROR_INVALID_SIGNATURE
Przemek Stekiel6b648622023-02-19 22:55:33 +0100116 * The verification fails for a zero-knowledge input step.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200117 * \retval #PSA_ERROR_INVALID_ARGUMENT
Przemek Stekiel6b648622023-02-19 22:55:33 +0100118 * the \p input is not valid for the \p operation's algorithm, cipher suite
Neil Armstrong56b8d232022-06-01 18:05:57 +0200119 * or \p step.
120 * \retval #PSA_ERROR_NOT_SUPPORTED
Przemek Stekiel6b648622023-02-19 22:55:33 +0100121 * the \p input is not supported for the \p operation's algorithm, cipher
Neil Armstrong56b8d232022-06-01 18:05:57 +0200122 * suite or \p step.
123 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Neil Armstrong56b8d232022-06-01 18:05:57 +0200124 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +0200125 * \retval #PSA_ERROR_DATA_CORRUPT
126 * \retval #PSA_ERROR_DATA_INVALID
Neil Armstrong56b8d232022-06-01 18:05:57 +0200127 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100128psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +0100129 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200130 const uint8_t *input,
131 size_t input_length);
132
133/** Get implicitly confirmed shared secret from a PAKE.
134 *
Przemek Stekielca674832022-12-07 14:47:34 +0100135 * \note The signature of this function is that of a PSA driver
136 * pake_get_implicit_key entry point. This function behaves as a
137 * pake_get_implicit_key entry point as defined in the PSA driver
138 * interface specification for transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200139 *
140 * \param[in,out] operation Active PAKE operation.
Przemek Stekiel6b648622023-02-19 22:55:33 +0100141 * \param[out] output Output buffer for implicit key.
142 * \param output_size Size of the output buffer in bytes.
143 * \param[out] output_length On success, the number of bytes of the implicit key.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200144 *
145 * \retval #PSA_SUCCESS
146 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200147 * \retval #PSA_ERROR_NOT_SUPPORTED
148 * Input from a PAKE is not supported by the algorithm in the \p output
149 * key derivation operation.
150 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Neil Armstrong56b8d232022-06-01 18:05:57 +0200151 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +0200152 * \retval #PSA_ERROR_DATA_CORRUPT
153 * \retval #PSA_ERROR_DATA_INVALID
Neil Armstrong56b8d232022-06-01 18:05:57 +0200154 */
155psa_status_t mbedtls_psa_pake_get_implicit_key(
Przemek Stekiel6c764412022-11-22 14:05:12 +0100156 mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel6b648622023-02-19 22:55:33 +0100157 uint8_t *output, size_t output_size,
158 size_t *output_length);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200159
160/** Abort a PAKE operation.
161 *
Przemek Stekielca674832022-12-07 14:47:34 +0100162 * \note The signature of this function is that of a PSA driver
163 * pake_abort entry point. This function behaves as a pake_abort
164 * entry point as defined in the PSA driver interface specification for
165 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200166 *
167 * \param[in,out] operation The operation to abort.
168 *
169 * \retval #PSA_SUCCESS
170 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200171 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Neil Armstrong56b8d232022-06-01 18:05:57 +0200172 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100173psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200174
175#endif /* PSA_CRYPTO_PAKE_H */