| 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 | 691e91a | 2023-03-07 16:26:37 +0100 | [diff] [blame] | 99 | * \note The core checks that input_length is smaller than PSA_PAKE_INPUT_MAX_SIZE. | 
| Przemek Stekiel | 4dc83d4 | 2023-02-27 11:49:35 +0100 | [diff] [blame] | 100 | * | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 101 | * \param[in,out] operation    Active PAKE operation. | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 102 | * \param step                 The driver step for which the input is provided. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 103 | * \param[in] input            Buffer containing the input in the format | 
|  | 104 | *                             appropriate for this \p step. Refer to the | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 105 | *                             documentation of psa_crypto_driver_pake_step_t | 
|  | 106 | *                             for more information. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 107 | * \param input_length         Size of the \p input buffer in bytes. | 
|  | 108 | * | 
|  | 109 | * \retval #PSA_SUCCESS | 
|  | 110 | *         Success. | 
|  | 111 | * \retval #PSA_ERROR_INVALID_SIGNATURE | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 112 | *         The verification fails for a zero-knowledge input step. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 113 | * \retval #PSA_ERROR_INVALID_ARGUMENT | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 114 | *         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] | 115 | *         or \p step. | 
|  | 116 | * \retval #PSA_ERROR_NOT_SUPPORTED | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 117 | *         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] | 118 | *         suite or \p step. | 
|  | 119 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 120 | * \retval #PSA_ERROR_CORRUPTION_DETECTED | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 121 | * \retval #PSA_ERROR_DATA_CORRUPT | 
|  | 122 | * \retval #PSA_ERROR_DATA_INVALID | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 123 | */ | 
| Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 124 | 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] | 125 | psa_crypto_driver_pake_step_t step, | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 126 | const uint8_t *input, | 
|  | 127 | size_t input_length); | 
|  | 128 |  | 
|  | 129 | /** Get implicitly confirmed shared secret from a PAKE. | 
|  | 130 | * | 
| Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 131 | * \note The signature of this function is that of a PSA driver | 
|  | 132 | *       pake_get_implicit_key entry point. This function behaves as a | 
|  | 133 | *       pake_get_implicit_key entry point as defined in the PSA driver | 
|  | 134 | *       interface specification for transparent drivers. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 135 | * | 
|  | 136 | * \param[in,out] operation    Active PAKE operation. | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 137 | * \param[out] output          Output buffer for implicit key. | 
|  | 138 | * \param      output_size     Size of the output buffer in bytes. | 
|  | 139 | * \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] | 140 | * | 
|  | 141 | * \retval #PSA_SUCCESS | 
|  | 142 | *         Success. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 143 | * \retval #PSA_ERROR_NOT_SUPPORTED | 
|  | 144 | *         Input from a PAKE is not supported by the algorithm in the \p output | 
|  | 145 | *         key derivation operation. | 
|  | 146 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 147 | * \retval #PSA_ERROR_CORRUPTION_DETECTED | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 148 | * \retval #PSA_ERROR_DATA_CORRUPT | 
|  | 149 | * \retval #PSA_ERROR_DATA_INVALID | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 150 | */ | 
|  | 151 | psa_status_t mbedtls_psa_pake_get_implicit_key( | 
| Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 152 | mbedtls_psa_pake_operation_t *operation, | 
| Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 153 | uint8_t *output, size_t output_size, | 
|  | 154 | size_t *output_length); | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 155 |  | 
|  | 156 | /** Abort a PAKE operation. | 
|  | 157 | * | 
| Przemek Stekiel | ca67483 | 2022-12-07 14:47:34 +0100 | [diff] [blame] | 158 | * \note The signature of this function is that of a PSA driver | 
|  | 159 | *       pake_abort entry point. This function behaves as a pake_abort | 
|  | 160 | *       entry point as defined in the PSA driver interface specification for | 
|  | 161 | *       transparent drivers. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 162 | * | 
|  | 163 | * \param[in,out] operation    The operation to abort. | 
|  | 164 | * | 
|  | 165 | * \retval #PSA_SUCCESS | 
|  | 166 | *         Success. | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 167 | * \retval #PSA_ERROR_CORRUPTION_DETECTED | 
| Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 168 | */ | 
| Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 169 | 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] | 170 |  | 
|  | 171 | #endif /* PSA_CRYPTO_PAKE_H */ |