psa_crypto_pake.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #ifndef PSA_CRYPTO_PAKE_H
  21. #define PSA_CRYPTO_PAKE_H
  22. #include <psa/crypto.h>
  23. /** Set the session information for a password-authenticated key exchange.
  24. *
  25. * \note The signature of this function is that of a PSA driver
  26. * pake_setup entry point. This function behaves as a pake_setup
  27. * entry point as defined in the PSA driver interface specification for
  28. * transparent drivers.
  29. *
  30. * \param[in,out] operation The operation object to set up. It must have
  31. * been initialized but not set up yet.
  32. * \param[in] inputs Inputs required for PAKE operation (role, password,
  33. * key lifetime, cipher suite)
  34. *
  35. * \retval #PSA_SUCCESS
  36. * Success.
  37. * \retval #PSA_ERROR_NOT_SUPPORTED
  38. * The algorithm in \p cipher_suite is not a supported PAKE algorithm,
  39. * or the PAKE primitive in \p cipher_suite is not supported or not
  40. * compatible with the PAKE algorithm, or the hash algorithm in
  41. * \p cipher_suite is not supported or not compatible with the PAKE
  42. * algorithm and primitive.
  43. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
  44. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  45. */
  46. psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation,
  47. const psa_crypto_driver_pake_inputs_t *inputs);
  48. /** Get output for a step of a password-authenticated key exchange.
  49. *
  50. * \note The signature of this function is that of a PSA driver
  51. * pake_output entry point. This function behaves as a pake_output
  52. * entry point as defined in the PSA driver interface specification for
  53. * transparent drivers.
  54. *
  55. * \param[in,out] operation Active PAKE operation.
  56. * \param step The step of the algorithm for which the output is
  57. * requested.
  58. * \param[out] output Buffer where the output is to be written in the
  59. * format appropriate for this driver \p step. Refer to
  60. * the documentation of psa_crypto_driver_pake_step_t for
  61. * more information.
  62. * \param output_size Size of the \p output buffer in bytes. This must
  63. * be at least #PSA_PAKE_OUTPUT_SIZE(\p alg, \p
  64. * primitive, \p step) where \p alg and
  65. * \p primitive are the PAKE algorithm and primitive
  66. * in the operation's cipher suite, and \p step is
  67. * the output step.
  68. *
  69. * \param[out] output_length On success, the number of bytes of the returned
  70. * output.
  71. *
  72. * \retval #PSA_SUCCESS
  73. * Success.
  74. * \retval #PSA_ERROR_BUFFER_TOO_SMALL
  75. * The size of the \p output buffer is too small.
  76. * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
  77. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  78. * \retval #PSA_ERROR_DATA_CORRUPT
  79. * \retval #PSA_ERROR_DATA_INVALID
  80. */
  81. psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation,
  82. psa_crypto_driver_pake_step_t step,
  83. uint8_t *output,
  84. size_t output_size,
  85. size_t *output_length);
  86. /** Provide input for a step of a password-authenticated key exchange.
  87. *
  88. * \note The signature of this function is that of a PSA driver
  89. * pake_input entry point. This function behaves as a pake_input
  90. * entry point as defined in the PSA driver interface specification for
  91. * transparent drivers.
  92. *
  93. * \note The core checks that input_length is smaller than PSA_PAKE_INPUT_MAX_SIZE.
  94. *
  95. * \param[in,out] operation Active PAKE operation.
  96. * \param step The driver step for which the input is provided.
  97. * \param[in] input Buffer containing the input in the format
  98. * appropriate for this \p step. Refer to the
  99. * documentation of psa_crypto_driver_pake_step_t
  100. * for more information.
  101. * \param input_length Size of the \p input buffer in bytes.
  102. *
  103. * \retval #PSA_SUCCESS
  104. * Success.
  105. * \retval #PSA_ERROR_INVALID_SIGNATURE
  106. * The verification fails for a zero-knowledge input step.
  107. * \retval #PSA_ERROR_INVALID_ARGUMENT
  108. * the \p input is not valid for the \p operation's algorithm, cipher suite
  109. * or \p step.
  110. * \retval #PSA_ERROR_NOT_SUPPORTED
  111. * the \p input is not supported for the \p operation's algorithm, cipher
  112. * suite or \p step.
  113. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
  114. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  115. * \retval #PSA_ERROR_DATA_CORRUPT
  116. * \retval #PSA_ERROR_DATA_INVALID
  117. */
  118. psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation,
  119. psa_crypto_driver_pake_step_t step,
  120. const uint8_t *input,
  121. size_t input_length);
  122. /** Get implicitly confirmed shared secret from a PAKE.
  123. *
  124. * \note The signature of this function is that of a PSA driver
  125. * pake_get_implicit_key entry point. This function behaves as a
  126. * pake_get_implicit_key entry point as defined in the PSA driver
  127. * interface specification for transparent drivers.
  128. *
  129. * \param[in,out] operation Active PAKE operation.
  130. * \param[out] output Output buffer for implicit key.
  131. * \param output_size Size of the output buffer in bytes.
  132. * \param[out] output_length On success, the number of bytes of the implicit key.
  133. *
  134. * \retval #PSA_SUCCESS
  135. * Success.
  136. * \retval #PSA_ERROR_NOT_SUPPORTED
  137. * Input from a PAKE is not supported by the algorithm in the \p output
  138. * key derivation operation.
  139. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
  140. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  141. * \retval #PSA_ERROR_DATA_CORRUPT
  142. * \retval #PSA_ERROR_DATA_INVALID
  143. */
  144. psa_status_t mbedtls_psa_pake_get_implicit_key(
  145. mbedtls_psa_pake_operation_t *operation,
  146. uint8_t *output, size_t output_size,
  147. size_t *output_length);
  148. /** Abort a PAKE operation.
  149. *
  150. * \note The signature of this function is that of a PSA driver
  151. * pake_abort entry point. This function behaves as a pake_abort
  152. * entry point as defined in the PSA driver interface specification for
  153. * transparent drivers.
  154. *
  155. * \param[in,out] operation The operation to abort.
  156. *
  157. * \retval #PSA_SUCCESS
  158. * Success.
  159. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  160. */
  161. psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation);
  162. #endif /* PSA_CRYPTO_PAKE_H */