psa_crypto_ffdh.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * PSA FFDH layer on top of Mbed TLS crypto
  3. */
  4. /*
  5. * Copyright The Mbed TLS Contributors
  6. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  7. */
  8. #ifndef PSA_CRYPTO_FFDH_H
  9. #define PSA_CRYPTO_FFDH_H
  10. #include <psa/crypto.h>
  11. /** Perform a key agreement and return the FFDH shared secret.
  12. *
  13. * \param[in] attributes The attributes of the key to use for the
  14. * operation.
  15. * \param[in] peer_key The buffer containing the key context
  16. * of the peer's public key.
  17. * \param[in] peer_key_length Size of the \p peer_key buffer in
  18. * bytes.
  19. * \param[in] key_buffer The buffer containing the private key
  20. * context.
  21. * \param[in] key_buffer_size Size of the \p key_buffer buffer in
  22. * bytes.
  23. * \param[out] shared_secret The buffer to which the shared secret
  24. * is to be written.
  25. * \param[in] shared_secret_size Size of the \p shared_secret buffer in
  26. * bytes.
  27. * \param[out] shared_secret_length On success, the number of bytes that make
  28. * up the returned shared secret.
  29. * \retval #PSA_SUCCESS
  30. * Success. Shared secret successfully calculated.
  31. * \retval #PSA_ERROR_INVALID_ARGUMENT
  32. * \p key_buffer_size, \p peer_key_length, \p shared_secret_size
  33. * do not match
  34. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
  35. * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
  36. */
  37. psa_status_t mbedtls_psa_ffdh_key_agreement(
  38. const psa_key_attributes_t *attributes,
  39. const uint8_t *peer_key,
  40. size_t peer_key_length,
  41. const uint8_t *key_buffer,
  42. size_t key_buffer_size,
  43. uint8_t *shared_secret,
  44. size_t shared_secret_size,
  45. size_t *shared_secret_length);
  46. /** Export a public key or the public part of a DH key pair in binary format.
  47. *
  48. * \param[in] attributes The attributes for the key to export.
  49. * \param[in] key_buffer Material or context of the key to export.
  50. * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
  51. * \param[out] data Buffer where the key data is to be written.
  52. * \param[in] data_size Size of the \p data buffer in bytes.
  53. * \param[out] data_length On success, the number of bytes written in
  54. * \p data
  55. *
  56. * \retval #PSA_SUCCESS The public key was exported successfully.
  57. * \retval #PSA_ERROR_BUFFER_TOO_SMALL
  58. * The size of \p key_buffer is too small.
  59. * \retval #PSA_ERROR_NOT_PERMITTED \emptydescription
  60. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
  61. * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
  62. */
  63. psa_status_t mbedtls_psa_ffdh_export_public_key(
  64. const psa_key_attributes_t *attributes,
  65. const uint8_t *key_buffer,
  66. size_t key_buffer_size,
  67. uint8_t *data,
  68. size_t data_size,
  69. size_t *data_length);
  70. /**
  71. * \brief Generate DH key.
  72. *
  73. * \note The signature of the function is that of a PSA driver generate_key
  74. * entry point.
  75. *
  76. * \param[in] attributes The attributes for the key to generate.
  77. * \param[out] key_buffer Buffer where the key data is to be written.
  78. * \param[in] key_buffer_size Size of \p key_buffer in bytes.
  79. * \param[out] key_buffer_length On success, the number of bytes written in
  80. * \p key_buffer.
  81. *
  82. * \retval #PSA_SUCCESS
  83. * The key was generated successfully.
  84. * \retval #PSA_ERROR_NOT_SUPPORTED
  85. * Key size in bits is invalid.
  86. * \retval #PSA_ERROR_BUFFER_TOO_SMALL
  87. * The size of \p key_buffer is too small.
  88. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
  89. * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
  90. */
  91. psa_status_t mbedtls_psa_ffdh_generate_key(
  92. const psa_key_attributes_t *attributes,
  93. uint8_t *key_buffer,
  94. size_t key_buffer_size,
  95. size_t *key_buffer_length);
  96. /**
  97. * \brief Import DH key.
  98. *
  99. * \note The signature of the function is that of a PSA driver import_key
  100. * entry point.
  101. *
  102. * \param[in] attributes The attributes for the key to import.
  103. * \param[in] data The buffer containing the key data in import
  104. * format.
  105. * \param[in] data_length Size of the \p data buffer in bytes.
  106. * \param[out] key_buffer The buffer containing the key data in output
  107. * format.
  108. * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes. This
  109. * size is greater or equal to \p data_length.
  110. * \param[out] key_buffer_length The length of the data written in \p
  111. * key_buffer in bytes.
  112. * \param[out] bits The key size in number of bits.
  113. *
  114. * \retval #PSA_SUCCESS
  115. * The key was generated successfully.
  116. * \retval #PSA_ERROR_BUFFER_TOO_SMALL
  117. * The size of \p key_buffer is too small.
  118. */
  119. psa_status_t mbedtls_psa_ffdh_import_key(
  120. const psa_key_attributes_t *attributes,
  121. const uint8_t *data, size_t data_length,
  122. uint8_t *key_buffer, size_t key_buffer_size,
  123. size_t *key_buffer_length, size_t *bits);
  124. #endif /* PSA_CRYPTO_FFDH_H */