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. |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 46 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 47 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 48 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 49 | 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] | 50 | const psa_crypto_driver_pake_inputs_t *inputs); |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 51 | |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 52 | |
| 53 | /** Get output for a step of a password-authenticated key exchange. |
| 54 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 55 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 59 | * |
| 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 Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 64 | * format appropriate for this driver \p step. Refer to |
| 65 | * the documentation of psa_crypto_driver_pake_step_t for |
| 66 | * more information. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 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. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 81 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 82 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 83 | * \retval #PSA_ERROR_DATA_CORRUPT |
| 84 | * \retval #PSA_ERROR_DATA_INVALID |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 85 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 86 | psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 87 | psa_crypto_driver_pake_step_t step, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 88 | 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 Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 94 | * \note The signature of this function is that of a PSA driver |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 95 | * pake_input entry point. This function behaves as a pake_input |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 96 | * entry point as defined in the PSA driver interface specification for |
| 97 | * transparent drivers. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 98 | * |
Przemek Stekiel | 4dc83d4 | 2023-02-27 11:49:35 +0100 | [diff] [blame^] | 99 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 105 | * \param[in,out] operation Active PAKE operation. |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 106 | * \param step The driver step for which the input is provided. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 107 | * \param[in] input Buffer containing the input in the format |
| 108 | * appropriate for this \p step. Refer to the |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 109 | * documentation of psa_crypto_driver_pake_step_t |
| 110 | * for more information. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 111 | * \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 Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 116 | * The verification fails for a zero-knowledge input step. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 117 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 118 | * the \p input is not valid for the \p operation's algorithm, cipher suite |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 119 | * or \p step. |
| 120 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 121 | * the \p input is not supported for the \p operation's algorithm, cipher |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 122 | * suite or \p step. |
| 123 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 124 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 125 | * \retval #PSA_ERROR_DATA_CORRUPT |
| 126 | * \retval #PSA_ERROR_DATA_INVALID |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 127 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 128 | psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 129 | psa_crypto_driver_pake_step_t step, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 130 | const uint8_t *input, |
| 131 | size_t input_length); |
| 132 | |
| 133 | /** Get implicitly confirmed shared secret from a PAKE. |
| 134 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 135 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 139 | * |
| 140 | * \param[in,out] operation Active PAKE operation. |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 141 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 144 | * |
| 145 | * \retval #PSA_SUCCESS |
| 146 | * Success. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 147 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 151 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 152 | * \retval #PSA_ERROR_DATA_CORRUPT |
| 153 | * \retval #PSA_ERROR_DATA_INVALID |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 154 | */ |
| 155 | psa_status_t mbedtls_psa_pake_get_implicit_key( |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 156 | mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 157 | uint8_t *output, size_t output_size, |
| 158 | size_t *output_length); |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 159 | |
| 160 | /** Abort a PAKE operation. |
| 161 | * |
Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 162 | * \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 Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 166 | * |
| 167 | * \param[in,out] operation The operation to abort. |
| 168 | * |
| 169 | * \retval #PSA_SUCCESS |
| 170 | * Success. |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 171 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 172 | */ |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 173 | 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] | 174 | |
| 175 | #endif /* PSA_CRYPTO_PAKE_H */ |