blob: 485c93af969a301a9060f133767ead611fe9c045 [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.
Neil Armstrong56b8d232022-06-01 18:05:57 +020046 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010047psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel51eac532022-12-07 11:04:51 +010048 const psa_crypto_driver_pake_inputs_t *inputs);
Neil Armstrong56b8d232022-06-01 18:05:57 +020049
Neil Armstrong56b8d232022-06-01 18:05:57 +020050
51/** Get output for a step of a password-authenticated key exchange.
52 *
Przemek Stekielca674832022-12-07 14:47:34 +010053 * \note The signature of this function is that of a PSA driver
54 * pake_output entry point. This function behaves as a pake_output
55 * entry point as defined in the PSA driver interface specification for
56 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +020057 *
58 * \param[in,out] operation Active PAKE operation.
59 * \param step The step of the algorithm for which the output is
60 * requested.
Przemek Stekiele12ed362022-12-21 12:54:46 +010061 * \param computation_stage The structure that holds PAKE computation stage.
Neil Armstrong56b8d232022-06-01 18:05:57 +020062 * \param[out] output Buffer where the output is to be written in the
63 * format appropriate for this \p step. Refer to
64 * the documentation of the individual
65 * \c PSA_PAKE_STEP_XXX constants for more
66 * information.
67 * \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.
81 * \retval #PSA_ERROR_INVALID_ARGUMENT
82 * \p step is not compatible with the operation's algorithm.
83 * \retval #PSA_ERROR_NOT_SUPPORTED
84 * \p step is not supported with the operation's algorithm.
85 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
86 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
87 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
88 * \retval #PSA_ERROR_CORRUPTION_DETECTED
89 * \retval #PSA_ERROR_STORAGE_FAILURE
90 * \retval #PSA_ERROR_DATA_CORRUPT
91 * \retval #PSA_ERROR_DATA_INVALID
92 * \retval #PSA_ERROR_BAD_STATE
93 * The operation state is not valid (it must be active, and fully set
94 * up, and this call must conform to the algorithm's requirements
Przemek Stekielca674832022-12-07 14:47:34 +010095 * for ordering of input and output steps).
Neil Armstrong56b8d232022-06-01 18:05:57 +020096 * It is implementation-dependent whether a failure to initialize
97 * results in this error code.
98 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010099psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200100 psa_pake_step_t step,
Przemek Stekiele12ed362022-12-21 12:54:46 +0100101 const psa_pake_computation_stage_t *computation_stage,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200102 uint8_t *output,
103 size_t output_size,
104 size_t *output_length);
105
106/** Provide input for a step of a password-authenticated key exchange.
107 *
Przemek Stekielca674832022-12-07 14:47:34 +0100108 * \note The signature of this function is that of a PSA driver
109 * key_agreement entry point. This function behaves as a key_agreement
110 * entry point as defined in the PSA driver interface specification for
111 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200112 *
113 * \param[in,out] operation Active PAKE operation.
114 * \param step The step for which the input is provided.
Przemek Stekiele12ed362022-12-21 12:54:46 +0100115 * \param computation_stage The structure that holds PAKE computation stage.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200116 * \param[in] input Buffer containing the input in the format
117 * appropriate for this \p step. Refer to the
118 * documentation of the individual
119 * \c PSA_PAKE_STEP_XXX constants for more
120 * information.
121 * \param input_length Size of the \p input buffer in bytes.
122 *
123 * \retval #PSA_SUCCESS
124 * Success.
125 * \retval #PSA_ERROR_INVALID_SIGNATURE
126 * The verification fails for a #PSA_PAKE_STEP_ZK_PROOF input step.
127 * \retval #PSA_ERROR_INVALID_ARGUMENT
Przemek Stekielca674832022-12-07 14:47:34 +0100128 * \p step is not compatible with the \p operation’s algorithm, or the
Neil Armstrong56b8d232022-06-01 18:05:57 +0200129 * \p input is not valid for the \p operation's algorithm, cipher suite
130 * or \p step.
131 * \retval #PSA_ERROR_NOT_SUPPORTED
132 * \p step p is not supported with the \p operation's algorithm, or the
133 * \p input is not supported for the \p operation's algorithm, cipher
134 * suite or \p step.
135 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
136 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
137 * \retval #PSA_ERROR_CORRUPTION_DETECTED
138 * \retval #PSA_ERROR_STORAGE_FAILURE
139 * \retval #PSA_ERROR_DATA_CORRUPT
140 * \retval #PSA_ERROR_DATA_INVALID
141 * \retval #PSA_ERROR_BAD_STATE
142 * The operation state is not valid (it must be active, and fully set
143 * up, and this call must conform to the algorithm's requirements
Przemek Stekielca674832022-12-07 14:47:34 +0100144 * for ordering of input and output steps).
Neil Armstrong56b8d232022-06-01 18:05:57 +0200145 * It is implementation-dependent whether a failure to initialize
146 * results in this error code.
147 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100148psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200149 psa_pake_step_t step,
Przemek Stekiele12ed362022-12-21 12:54:46 +0100150 const psa_pake_computation_stage_t *computation_stage,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200151 const uint8_t *input,
152 size_t input_length);
153
154/** Get implicitly confirmed shared secret from a PAKE.
155 *
Przemek Stekielca674832022-12-07 14:47:34 +0100156 * \note The signature of this function is that of a PSA driver
157 * pake_get_implicit_key entry point. This function behaves as a
158 * pake_get_implicit_key entry point as defined in the PSA driver
159 * interface specification for transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200160 *
161 * \param[in,out] operation Active PAKE operation.
Przemek Stekielca674832022-12-07 14:47:34 +0100162 * \param[out] output Output buffer for implicit key
163 * \param[out] output_size Size of the returned implicit key
Neil Armstrong56b8d232022-06-01 18:05:57 +0200164 *
165 * \retval #PSA_SUCCESS
166 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200167 * \retval #PSA_ERROR_NOT_SUPPORTED
168 * Input from a PAKE is not supported by the algorithm in the \p output
169 * key derivation operation.
170 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
171 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
172 * \retval #PSA_ERROR_CORRUPTION_DETECTED
173 * \retval #PSA_ERROR_STORAGE_FAILURE
174 * \retval #PSA_ERROR_DATA_CORRUPT
175 * \retval #PSA_ERROR_DATA_INVALID
176 * \retval #PSA_ERROR_BAD_STATE
177 * The PAKE operation state is not valid (it must be active, but beyond
Przemek Stekielca674832022-12-07 14:47:34 +0100178 * that validity is specific to the algorithm),
Neil Armstrong56b8d232022-06-01 18:05:57 +0200179 * or the state of \p output is not valid for
180 * the #PSA_KEY_DERIVATION_INPUT_SECRET step. This can happen if the
181 * step is out of order or the application has done this step already
182 * and it may not be repeated.
183 * It is implementation-dependent whether a failure to initialize
184 * results in this error code.
185 */
186psa_status_t mbedtls_psa_pake_get_implicit_key(
Przemek Stekiel6c764412022-11-22 14:05:12 +0100187 mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel0c781802022-11-29 14:53:13 +0100188 uint8_t *output, size_t *output_size);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200189
190/** Abort a PAKE operation.
191 *
Przemek Stekielca674832022-12-07 14:47:34 +0100192 * \note The signature of this function is that of a PSA driver
193 * pake_abort entry point. This function behaves as a pake_abort
194 * entry point as defined in the PSA driver interface specification for
195 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200196 *
197 * \param[in,out] operation The operation to abort.
198 *
199 * \retval #PSA_SUCCESS
200 * Success.
201 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
202 * \retval #PSA_ERROR_CORRUPTION_DETECTED
203 * \retval #PSA_ERROR_BAD_STATE
Neil Armstrong56b8d232022-06-01 18:05:57 +0200204 * It is implementation-dependent whether a failure to initialize
205 * results in this error code.
206 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100207psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200208
209#endif /* PSA_CRYPTO_PAKE_H */