psa_crypto_aead.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * PSA AEAD driver entry points
  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_AEAD_H
  21. #define PSA_CRYPTO_AEAD_H
  22. #include <psa/crypto.h>
  23. /**
  24. * \brief Process an authenticated encryption operation.
  25. *
  26. * \note The signature of this function is that of a PSA driver
  27. * aead_encrypt entry point. This function behaves as an aead_encrypt
  28. * entry point as defined in the PSA driver interface specification for
  29. * transparent drivers.
  30. *
  31. * \param[in] attributes The attributes of the key to use for the
  32. * operation.
  33. * \param[in] key_buffer The buffer containing the key context.
  34. * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
  35. * \param alg The AEAD algorithm to compute.
  36. * \param[in] nonce Nonce or IV to use.
  37. * \param nonce_length Size of the nonce buffer in bytes. This must
  38. * be appropriate for the selected algorithm.
  39. * The default nonce size is
  40. * PSA_AEAD_NONCE_LENGTH(key_type, alg) where
  41. * key_type is the type of key.
  42. * \param[in] additional_data Additional data that will be authenticated
  43. * but not encrypted.
  44. * \param additional_data_length Size of additional_data in bytes.
  45. * \param[in] plaintext Data that will be authenticated and encrypted.
  46. * \param plaintext_length Size of plaintext in bytes.
  47. * \param[out] ciphertext Output buffer for the authenticated and
  48. * encrypted data. The additional data is not
  49. * part of this output. For algorithms where the
  50. * encrypted data and the authentication tag are
  51. * defined as separate outputs, the
  52. * authentication tag is appended to the
  53. * encrypted data.
  54. * \param ciphertext_size Size of the ciphertext buffer in bytes. This
  55. * must be appropriate for the selected algorithm
  56. * and key:
  57. * - A sufficient output size is
  58. * PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg,
  59. * plaintext_length) where key_type is the type
  60. * of key.
  61. * - PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(
  62. * plaintext_length) evaluates to the maximum
  63. * ciphertext size of any supported AEAD
  64. * encryption.
  65. * \param[out] ciphertext_length On success, the size of the output in the
  66. * ciphertext buffer.
  67. *
  68. * \retval #PSA_SUCCESS Success.
  69. * \retval #PSA_ERROR_NOT_SUPPORTED
  70. * \p alg is not supported.
  71. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
  72. * \retval #PSA_ERROR_BUFFER_TOO_SMALL
  73. * ciphertext_size is too small.
  74. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  75. */
  76. psa_status_t mbedtls_psa_aead_encrypt(
  77. const psa_key_attributes_t *attributes,
  78. const uint8_t *key_buffer, size_t key_buffer_size,
  79. psa_algorithm_t alg,
  80. const uint8_t *nonce, size_t nonce_length,
  81. const uint8_t *additional_data, size_t additional_data_length,
  82. const uint8_t *plaintext, size_t plaintext_length,
  83. uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length );
  84. /**
  85. * \brief Process an authenticated decryption operation.
  86. *
  87. * \note The signature of this function is that of a PSA driver
  88. * aead_decrypt entry point. This function behaves as an aead_decrypt
  89. * entry point as defined in the PSA driver interface specification for
  90. * transparent drivers.
  91. *
  92. * \param[in] attributes The attributes of the key to use for the
  93. * operation.
  94. * \param[in] key_buffer The buffer containing the key context.
  95. * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
  96. * \param alg The AEAD algorithm to compute.
  97. * \param[in] nonce Nonce or IV to use.
  98. * \param nonce_length Size of the nonce buffer in bytes. This must
  99. * be appropriate for the selected algorithm.
  100. * The default nonce size is
  101. * PSA_AEAD_NONCE_LENGTH(key_type, alg) where
  102. * key_type is the type of key.
  103. * \param[in] additional_data Additional data that has been authenticated
  104. * but not encrypted.
  105. * \param additional_data_length Size of additional_data in bytes.
  106. * \param[in] ciphertext Data that has been authenticated and
  107. * encrypted. For algorithms where the encrypted
  108. * data and the authentication tag are defined
  109. * as separate inputs, the buffer contains
  110. * encrypted data followed by the authentication
  111. * tag.
  112. * \param ciphertext_length Size of ciphertext in bytes.
  113. * \param[out] plaintext Output buffer for the decrypted data.
  114. * \param plaintext_size Size of the plaintext buffer in bytes. This
  115. * must be appropriate for the selected algorithm
  116. * and key:
  117. * - A sufficient output size is
  118. * PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg,
  119. * ciphertext_length) where key_type is the
  120. * type of key.
  121. * - PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(
  122. * ciphertext_length) evaluates to the maximum
  123. * plaintext size of any supported AEAD
  124. * decryption.
  125. * \param[out] plaintext_length On success, the size of the output in the
  126. * plaintext buffer.
  127. *
  128. * \retval #PSA_SUCCESS Success.
  129. * \retval #PSA_ERROR_INVALID_SIGNATURE
  130. * The cipher is not authentic.
  131. * \retval #PSA_ERROR_NOT_SUPPORTED
  132. * \p alg is not supported.
  133. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
  134. * \retval #PSA_ERROR_BUFFER_TOO_SMALL
  135. * plaintext_size is too small.
  136. * \retval #PSA_ERROR_CORRUPTION_DETECTED
  137. */
  138. psa_status_t mbedtls_psa_aead_decrypt(
  139. const psa_key_attributes_t *attributes,
  140. const uint8_t *key_buffer, size_t key_buffer_size,
  141. psa_algorithm_t alg,
  142. const uint8_t *nonce, size_t nonce_length,
  143. const uint8_t *additional_data, size_t additional_data_length,
  144. const uint8_t *ciphertext, size_t ciphertext_length,
  145. uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length );
  146. #endif /* PSA_CRYPTO_AEAD */