blob: 365855601bd2e9a08bbb3478e59eaa4ff05d8c38 [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.
61 * \param[out] output Buffer where the output is to be written in the
62 * format appropriate for this \p step. Refer to
63 * the documentation of the individual
64 * \c PSA_PAKE_STEP_XXX constants for more
65 * information.
66 * \param output_size Size of the \p output buffer in bytes. This must
67 * be at least #PSA_PAKE_OUTPUT_SIZE(\p alg, \p
68 * primitive, \p step) where \p alg and
69 * \p primitive are the PAKE algorithm and primitive
70 * in the operation's cipher suite, and \p step is
71 * the output step.
72 *
73 * \param[out] output_length On success, the number of bytes of the returned
74 * output.
75 *
76 * \retval #PSA_SUCCESS
77 * Success.
78 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
79 * The size of the \p output buffer is too small.
80 * \retval #PSA_ERROR_INVALID_ARGUMENT
81 * \p step is not compatible with the operation's algorithm.
82 * \retval #PSA_ERROR_NOT_SUPPORTED
83 * \p step is not supported with the operation's algorithm.
84 * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
85 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
86 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
87 * \retval #PSA_ERROR_CORRUPTION_DETECTED
88 * \retval #PSA_ERROR_STORAGE_FAILURE
89 * \retval #PSA_ERROR_DATA_CORRUPT
90 * \retval #PSA_ERROR_DATA_INVALID
91 * \retval #PSA_ERROR_BAD_STATE
92 * The operation state is not valid (it must be active, and fully set
93 * up, and this call must conform to the algorithm's requirements
Przemek Stekielca674832022-12-07 14:47:34 +010094 * for ordering of input and output steps).
Neil Armstrong56b8d232022-06-01 18:05:57 +020095 * It is implementation-dependent whether a failure to initialize
96 * results in this error code.
97 */
Przemek Stekiel6c764412022-11-22 14:05:12 +010098psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +010099 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200100 uint8_t *output,
101 size_t output_size,
102 size_t *output_length);
103
104/** Provide input for a step of a password-authenticated key exchange.
105 *
Przemek Stekielca674832022-12-07 14:47:34 +0100106 * \note The signature of this function is that of a PSA driver
107 * key_agreement entry point. This function behaves as a key_agreement
108 * entry point as defined in the PSA driver interface specification for
109 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200110 *
111 * \param[in,out] operation Active PAKE operation.
112 * \param step The step for which the input is provided.
113 * \param[in] input Buffer containing the input in the format
114 * appropriate for this \p step. Refer to the
115 * documentation of the individual
116 * \c PSA_PAKE_STEP_XXX constants for more
117 * information.
118 * \param input_length Size of the \p input buffer in bytes.
119 *
120 * \retval #PSA_SUCCESS
121 * Success.
122 * \retval #PSA_ERROR_INVALID_SIGNATURE
123 * The verification fails for a #PSA_PAKE_STEP_ZK_PROOF input step.
124 * \retval #PSA_ERROR_INVALID_ARGUMENT
Przemek Stekielca674832022-12-07 14:47:34 +0100125 * \p step is not compatible with the \p operation’s algorithm, or the
Neil Armstrong56b8d232022-06-01 18:05:57 +0200126 * \p input is not valid for the \p operation's algorithm, cipher suite
127 * or \p step.
128 * \retval #PSA_ERROR_NOT_SUPPORTED
129 * \p step p is not supported with the \p operation's algorithm, or the
130 * \p input is not supported for the \p operation's algorithm, cipher
131 * suite or \p step.
132 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
133 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
134 * \retval #PSA_ERROR_CORRUPTION_DETECTED
135 * \retval #PSA_ERROR_STORAGE_FAILURE
136 * \retval #PSA_ERROR_DATA_CORRUPT
137 * \retval #PSA_ERROR_DATA_INVALID
138 * \retval #PSA_ERROR_BAD_STATE
139 * The operation state is not valid (it must be active, and fully set
140 * up, and this call must conform to the algorithm's requirements
Przemek Stekielca674832022-12-07 14:47:34 +0100141 * for ordering of input and output steps).
Neil Armstrong56b8d232022-06-01 18:05:57 +0200142 * It is implementation-dependent whether a failure to initialize
143 * results in this error code.
144 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100145psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel251e86a2023-02-17 14:30:50 +0100146 psa_crypto_driver_pake_step_t step,
Neil Armstrong56b8d232022-06-01 18:05:57 +0200147 const uint8_t *input,
148 size_t input_length);
149
150/** Get implicitly confirmed shared secret from a PAKE.
151 *
Przemek Stekielca674832022-12-07 14:47:34 +0100152 * \note The signature of this function is that of a PSA driver
153 * pake_get_implicit_key entry point. This function behaves as a
154 * pake_get_implicit_key entry point as defined in the PSA driver
155 * interface specification for transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200156 *
157 * \param[in,out] operation Active PAKE operation.
Przemek Stekielca674832022-12-07 14:47:34 +0100158 * \param[out] output Output buffer for implicit key
159 * \param[out] output_size Size of the returned implicit key
Neil Armstrong56b8d232022-06-01 18:05:57 +0200160 *
161 * \retval #PSA_SUCCESS
162 * Success.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200163 * \retval #PSA_ERROR_NOT_SUPPORTED
164 * Input from a PAKE is not supported by the algorithm in the \p output
165 * key derivation operation.
166 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
167 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
168 * \retval #PSA_ERROR_CORRUPTION_DETECTED
169 * \retval #PSA_ERROR_STORAGE_FAILURE
170 * \retval #PSA_ERROR_DATA_CORRUPT
171 * \retval #PSA_ERROR_DATA_INVALID
172 * \retval #PSA_ERROR_BAD_STATE
173 * The PAKE operation state is not valid (it must be active, but beyond
Przemek Stekielca674832022-12-07 14:47:34 +0100174 * that validity is specific to the algorithm),
Neil Armstrong56b8d232022-06-01 18:05:57 +0200175 * or the state of \p output is not valid for
176 * the #PSA_KEY_DERIVATION_INPUT_SECRET step. This can happen if the
177 * step is out of order or the application has done this step already
178 * and it may not be repeated.
179 * It is implementation-dependent whether a failure to initialize
180 * results in this error code.
181 */
182psa_status_t mbedtls_psa_pake_get_implicit_key(
Przemek Stekiel6c764412022-11-22 14:05:12 +0100183 mbedtls_psa_pake_operation_t *operation,
Przemek Stekiel0c781802022-11-29 14:53:13 +0100184 uint8_t *output, size_t *output_size);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200185
186/** Abort a PAKE operation.
187 *
Przemek Stekielca674832022-12-07 14:47:34 +0100188 * \note The signature of this function is that of a PSA driver
189 * pake_abort entry point. This function behaves as a pake_abort
190 * entry point as defined in the PSA driver interface specification for
191 * transparent drivers.
Neil Armstrong56b8d232022-06-01 18:05:57 +0200192 *
193 * \param[in,out] operation The operation to abort.
194 *
195 * \retval #PSA_SUCCESS
196 * Success.
197 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
198 * \retval #PSA_ERROR_CORRUPTION_DETECTED
199 * \retval #PSA_ERROR_BAD_STATE
Neil Armstrong56b8d232022-06-01 18:05:57 +0200200 * It is implementation-dependent whether a failure to initialize
201 * results in this error code.
202 */
Przemek Stekiel6c764412022-11-22 14:05:12 +0100203psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation);
Neil Armstrong56b8d232022-06-01 18:05:57 +0200204
205#endif /* PSA_CRYPTO_PAKE_H */