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. |
| 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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 94 | * for ordering of input and output steps). |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 95 | * It is implementation-dependent whether a failure to initialize |
| 96 | * results in this error code. |
| 97 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 98 | 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] | 99 | psa_pake_step_t step, |
| 100 | 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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 106 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 110 | * |
| 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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 125 | * \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] | 126 | * \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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 141 | * for ordering of input and output steps). |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 142 | * It is implementation-dependent whether a failure to initialize |
| 143 | * results in this error code. |
| 144 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 145 | 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] | 146 | psa_pake_step_t step, |
| 147 | const uint8_t *input, |
| 148 | size_t input_length); |
| 149 | |
| 150 | /** Get implicitly confirmed shared secret from a PAKE. |
| 151 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 152 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 156 | * |
| 157 | * \param[in,out] operation Active PAKE operation. |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 158 | * \param[out] output Output buffer for implicit key |
| 159 | * \param[out] output_size Size of the returned implicit key |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 160 | * |
| 161 | * \retval #PSA_SUCCESS |
| 162 | * Success. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 163 | * \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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 174 | * that validity is specific to the algorithm), |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 175 | * 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 | */ |
| 182 | psa_status_t mbedtls_psa_pake_get_implicit_key( |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 183 | mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 184 | uint8_t *output, size_t *output_size); |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 185 | |
| 186 | /** Abort a PAKE operation. |
| 187 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame^] | 188 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 192 | * |
| 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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 200 | * It is implementation-dependent whether a failure to initialize |
| 201 | * results in this error code. |
| 202 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 203 | 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] | 204 | |
| 205 | #endif /* PSA_CRYPTO_PAKE_H */ |