Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 1 | /* |
| 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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 28 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 32 | * |
| 33 | * \param[in,out] operation The operation object to set up. It must have |
| 34 | * been initialized but not set up yet. |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 35 | * \param[in] inputs Inputs required for PAKE operation (role, password, |
| 36 | * key lifetime, cipher suite) |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 37 | * |
| 38 | * \retval #PSA_SUCCESS |
| 39 | * Success. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 40 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 46 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 47 | psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 48 | const psa_crypto_driver_pake_inputs_t *inputs); |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 49 | |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 50 | |
| 51 | /** Get output for a step of a password-authenticated key exchange. |
| 52 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 53 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 57 | * |
| 58 | * \param[in,out] operation Active PAKE operation. |
| 59 | * \param step The step of the algorithm for which the output is |
| 60 | * requested. |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame^] | 61 | * \param computation_stage The structure that holds PAKE computation stage. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 62 | * \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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 95 | * for ordering of input and output steps). |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 96 | * It is implementation-dependent whether a failure to initialize |
| 97 | * results in this error code. |
| 98 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 99 | psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 100 | psa_pake_step_t step, |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame^] | 101 | const psa_pake_computation_stage_t *computation_stage, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 102 | 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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 108 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 112 | * |
| 113 | * \param[in,out] operation Active PAKE operation. |
| 114 | * \param step The step for which the input is provided. |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame^] | 115 | * \param computation_stage The structure that holds PAKE computation stage. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 116 | * \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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 128 | * \p step is not compatible with the \p operation’s algorithm, or the |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 129 | * \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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 144 | * for ordering of input and output steps). |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 145 | * It is implementation-dependent whether a failure to initialize |
| 146 | * results in this error code. |
| 147 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 148 | psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 149 | psa_pake_step_t step, |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame^] | 150 | const psa_pake_computation_stage_t *computation_stage, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 151 | const uint8_t *input, |
| 152 | size_t input_length); |
| 153 | |
| 154 | /** Get implicitly confirmed shared secret from a PAKE. |
| 155 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 156 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 160 | * |
| 161 | * \param[in,out] operation Active PAKE operation. |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 162 | * \param[out] output Output buffer for implicit key |
| 163 | * \param[out] output_size Size of the returned implicit key |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 164 | * |
| 165 | * \retval #PSA_SUCCESS |
| 166 | * Success. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 167 | * \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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 178 | * that validity is specific to the algorithm), |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 179 | * 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 | */ |
| 186 | psa_status_t mbedtls_psa_pake_get_implicit_key( |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 187 | mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 188 | uint8_t *output, size_t *output_size); |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 189 | |
| 190 | /** Abort a PAKE operation. |
| 191 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 192 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 196 | * |
| 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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 204 | * It is implementation-dependent whether a failure to initialize |
| 205 | * results in this error code. |
| 206 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 207 | psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation); |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 208 | |
| 209 | #endif /* PSA_CRYPTO_PAKE_H */ |