1a8e1175bSopenharmony_ci/* 2a8e1175bSopenharmony_ci * PSA PAKE layer on top of Mbed TLS software crypto 3a8e1175bSopenharmony_ci */ 4a8e1175bSopenharmony_ci/* 5a8e1175bSopenharmony_ci * Copyright The Mbed TLS Contributors 6a8e1175bSopenharmony_ci * SPDX-License-Identifier: Apache-2.0 7a8e1175bSopenharmony_ci * 8a8e1175bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); you may 9a8e1175bSopenharmony_ci * not use this file except in compliance with the License. 10a8e1175bSopenharmony_ci * You may obtain a copy of the License at 11a8e1175bSopenharmony_ci * 12a8e1175bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 13a8e1175bSopenharmony_ci * 14a8e1175bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 15a8e1175bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 16a8e1175bSopenharmony_ci * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17a8e1175bSopenharmony_ci * See the License for the specific language governing permissions and 18a8e1175bSopenharmony_ci * limitations under the License. 19a8e1175bSopenharmony_ci */ 20a8e1175bSopenharmony_ci 21a8e1175bSopenharmony_ci#ifndef PSA_CRYPTO_PAKE_H 22a8e1175bSopenharmony_ci#define PSA_CRYPTO_PAKE_H 23a8e1175bSopenharmony_ci 24a8e1175bSopenharmony_ci#include <psa/crypto.h> 25a8e1175bSopenharmony_ci 26a8e1175bSopenharmony_ci/** Set the session information for a password-authenticated key exchange. 27a8e1175bSopenharmony_ci * 28a8e1175bSopenharmony_ci * \note The signature of this function is that of a PSA driver 29a8e1175bSopenharmony_ci * pake_setup entry point. This function behaves as a pake_setup 30a8e1175bSopenharmony_ci * entry point as defined in the PSA driver interface specification for 31a8e1175bSopenharmony_ci * transparent drivers. 32a8e1175bSopenharmony_ci * 33a8e1175bSopenharmony_ci * \param[in,out] operation The operation object to set up. It must have 34a8e1175bSopenharmony_ci * been initialized but not set up yet. 35a8e1175bSopenharmony_ci * \param[in] inputs Inputs required for PAKE operation (role, password, 36a8e1175bSopenharmony_ci * key lifetime, cipher suite) 37a8e1175bSopenharmony_ci * 38a8e1175bSopenharmony_ci * \retval #PSA_SUCCESS 39a8e1175bSopenharmony_ci * Success. 40a8e1175bSopenharmony_ci * \retval #PSA_ERROR_NOT_SUPPORTED 41a8e1175bSopenharmony_ci * The algorithm in \p cipher_suite is not a supported PAKE algorithm, 42a8e1175bSopenharmony_ci * or the PAKE primitive in \p cipher_suite is not supported or not 43a8e1175bSopenharmony_ci * compatible with the PAKE algorithm, or the hash algorithm in 44a8e1175bSopenharmony_ci * \p cipher_suite is not supported or not compatible with the PAKE 45a8e1175bSopenharmony_ci * algorithm and primitive. 46a8e1175bSopenharmony_ci * \retval #PSA_ERROR_INSUFFICIENT_MEMORY 47a8e1175bSopenharmony_ci * \retval #PSA_ERROR_CORRUPTION_DETECTED 48a8e1175bSopenharmony_ci */ 49a8e1175bSopenharmony_cipsa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation, 50a8e1175bSopenharmony_ci const psa_crypto_driver_pake_inputs_t *inputs); 51a8e1175bSopenharmony_ci 52a8e1175bSopenharmony_ci 53a8e1175bSopenharmony_ci/** Get output for a step of a password-authenticated key exchange. 54a8e1175bSopenharmony_ci * 55a8e1175bSopenharmony_ci * \note The signature of this function is that of a PSA driver 56a8e1175bSopenharmony_ci * pake_output entry point. This function behaves as a pake_output 57a8e1175bSopenharmony_ci * entry point as defined in the PSA driver interface specification for 58a8e1175bSopenharmony_ci * transparent drivers. 59a8e1175bSopenharmony_ci * 60a8e1175bSopenharmony_ci * \param[in,out] operation Active PAKE operation. 61a8e1175bSopenharmony_ci * \param step The step of the algorithm for which the output is 62a8e1175bSopenharmony_ci * requested. 63a8e1175bSopenharmony_ci * \param[out] output Buffer where the output is to be written in the 64a8e1175bSopenharmony_ci * format appropriate for this driver \p step. Refer to 65a8e1175bSopenharmony_ci * the documentation of psa_crypto_driver_pake_step_t for 66a8e1175bSopenharmony_ci * more information. 67a8e1175bSopenharmony_ci * \param output_size Size of the \p output buffer in bytes. This must 68a8e1175bSopenharmony_ci * be at least #PSA_PAKE_OUTPUT_SIZE(\p alg, \p 69a8e1175bSopenharmony_ci * primitive, \p step) where \p alg and 70a8e1175bSopenharmony_ci * \p primitive are the PAKE algorithm and primitive 71a8e1175bSopenharmony_ci * in the operation's cipher suite, and \p step is 72a8e1175bSopenharmony_ci * the output step. 73a8e1175bSopenharmony_ci * 74a8e1175bSopenharmony_ci * \param[out] output_length On success, the number of bytes of the returned 75a8e1175bSopenharmony_ci * output. 76a8e1175bSopenharmony_ci * 77a8e1175bSopenharmony_ci * \retval #PSA_SUCCESS 78a8e1175bSopenharmony_ci * Success. 79a8e1175bSopenharmony_ci * \retval #PSA_ERROR_BUFFER_TOO_SMALL 80a8e1175bSopenharmony_ci * The size of the \p output buffer is too small. 81a8e1175bSopenharmony_ci * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY 82a8e1175bSopenharmony_ci * \retval #PSA_ERROR_CORRUPTION_DETECTED 83a8e1175bSopenharmony_ci * \retval #PSA_ERROR_DATA_CORRUPT 84a8e1175bSopenharmony_ci * \retval #PSA_ERROR_DATA_INVALID 85a8e1175bSopenharmony_ci */ 86a8e1175bSopenharmony_cipsa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation, 87a8e1175bSopenharmony_ci psa_crypto_driver_pake_step_t step, 88a8e1175bSopenharmony_ci uint8_t *output, 89a8e1175bSopenharmony_ci size_t output_size, 90a8e1175bSopenharmony_ci size_t *output_length); 91a8e1175bSopenharmony_ci 92a8e1175bSopenharmony_ci/** Provide input for a step of a password-authenticated key exchange. 93a8e1175bSopenharmony_ci * 94a8e1175bSopenharmony_ci * \note The signature of this function is that of a PSA driver 95a8e1175bSopenharmony_ci * pake_input entry point. This function behaves as a pake_input 96a8e1175bSopenharmony_ci * entry point as defined in the PSA driver interface specification for 97a8e1175bSopenharmony_ci * transparent drivers. 98a8e1175bSopenharmony_ci * 99a8e1175bSopenharmony_ci * \note The core checks that input_length is smaller than PSA_PAKE_INPUT_MAX_SIZE. 100a8e1175bSopenharmony_ci * 101a8e1175bSopenharmony_ci * \param[in,out] operation Active PAKE operation. 102a8e1175bSopenharmony_ci * \param step The driver step for which the input is provided. 103a8e1175bSopenharmony_ci * \param[in] input Buffer containing the input in the format 104a8e1175bSopenharmony_ci * appropriate for this \p step. Refer to the 105a8e1175bSopenharmony_ci * documentation of psa_crypto_driver_pake_step_t 106a8e1175bSopenharmony_ci * for more information. 107a8e1175bSopenharmony_ci * \param input_length Size of the \p input buffer in bytes. 108a8e1175bSopenharmony_ci * 109a8e1175bSopenharmony_ci * \retval #PSA_SUCCESS 110a8e1175bSopenharmony_ci * Success. 111a8e1175bSopenharmony_ci * \retval #PSA_ERROR_INVALID_SIGNATURE 112a8e1175bSopenharmony_ci * The verification fails for a zero-knowledge input step. 113a8e1175bSopenharmony_ci * \retval #PSA_ERROR_INVALID_ARGUMENT 114a8e1175bSopenharmony_ci * the \p input is not valid for the \p operation's algorithm, cipher suite 115a8e1175bSopenharmony_ci * or \p step. 116a8e1175bSopenharmony_ci * \retval #PSA_ERROR_NOT_SUPPORTED 117a8e1175bSopenharmony_ci * the \p input is not supported for the \p operation's algorithm, cipher 118a8e1175bSopenharmony_ci * suite or \p step. 119a8e1175bSopenharmony_ci * \retval #PSA_ERROR_INSUFFICIENT_MEMORY 120a8e1175bSopenharmony_ci * \retval #PSA_ERROR_CORRUPTION_DETECTED 121a8e1175bSopenharmony_ci * \retval #PSA_ERROR_DATA_CORRUPT 122a8e1175bSopenharmony_ci * \retval #PSA_ERROR_DATA_INVALID 123a8e1175bSopenharmony_ci */ 124a8e1175bSopenharmony_cipsa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation, 125a8e1175bSopenharmony_ci psa_crypto_driver_pake_step_t step, 126a8e1175bSopenharmony_ci const uint8_t *input, 127a8e1175bSopenharmony_ci size_t input_length); 128a8e1175bSopenharmony_ci 129a8e1175bSopenharmony_ci/** Get implicitly confirmed shared secret from a PAKE. 130a8e1175bSopenharmony_ci * 131a8e1175bSopenharmony_ci * \note The signature of this function is that of a PSA driver 132a8e1175bSopenharmony_ci * pake_get_implicit_key entry point. This function behaves as a 133a8e1175bSopenharmony_ci * pake_get_implicit_key entry point as defined in the PSA driver 134a8e1175bSopenharmony_ci * interface specification for transparent drivers. 135a8e1175bSopenharmony_ci * 136a8e1175bSopenharmony_ci * \param[in,out] operation Active PAKE operation. 137a8e1175bSopenharmony_ci * \param[out] output Output buffer for implicit key. 138a8e1175bSopenharmony_ci * \param output_size Size of the output buffer in bytes. 139a8e1175bSopenharmony_ci * \param[out] output_length On success, the number of bytes of the implicit key. 140a8e1175bSopenharmony_ci * 141a8e1175bSopenharmony_ci * \retval #PSA_SUCCESS 142a8e1175bSopenharmony_ci * Success. 143a8e1175bSopenharmony_ci * \retval #PSA_ERROR_NOT_SUPPORTED 144a8e1175bSopenharmony_ci * Input from a PAKE is not supported by the algorithm in the \p output 145a8e1175bSopenharmony_ci * key derivation operation. 146a8e1175bSopenharmony_ci * \retval #PSA_ERROR_INSUFFICIENT_MEMORY 147a8e1175bSopenharmony_ci * \retval #PSA_ERROR_CORRUPTION_DETECTED 148a8e1175bSopenharmony_ci * \retval #PSA_ERROR_DATA_CORRUPT 149a8e1175bSopenharmony_ci * \retval #PSA_ERROR_DATA_INVALID 150a8e1175bSopenharmony_ci */ 151a8e1175bSopenharmony_cipsa_status_t mbedtls_psa_pake_get_implicit_key( 152a8e1175bSopenharmony_ci mbedtls_psa_pake_operation_t *operation, 153a8e1175bSopenharmony_ci uint8_t *output, size_t output_size, 154a8e1175bSopenharmony_ci size_t *output_length); 155a8e1175bSopenharmony_ci 156a8e1175bSopenharmony_ci/** Abort a PAKE operation. 157a8e1175bSopenharmony_ci * 158a8e1175bSopenharmony_ci * \note The signature of this function is that of a PSA driver 159a8e1175bSopenharmony_ci * pake_abort entry point. This function behaves as a pake_abort 160a8e1175bSopenharmony_ci * entry point as defined in the PSA driver interface specification for 161a8e1175bSopenharmony_ci * transparent drivers. 162a8e1175bSopenharmony_ci * 163a8e1175bSopenharmony_ci * \param[in,out] operation The operation to abort. 164a8e1175bSopenharmony_ci * 165a8e1175bSopenharmony_ci * \retval #PSA_SUCCESS 166a8e1175bSopenharmony_ci * Success. 167a8e1175bSopenharmony_ci * \retval #PSA_ERROR_CORRUPTION_DETECTED 168a8e1175bSopenharmony_ci */ 169a8e1175bSopenharmony_cipsa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation); 170a8e1175bSopenharmony_ci 171a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_PAKE_H */ 172