Ronald Cron | 7ceee8d | 2021-03-17 16:55:43 +0100 | [diff] [blame] | 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 | |
| 21 | #ifndef PSA_CRYPTO_AEAD_H |
| 22 | #define PSA_CRYPTO_AEAD_H |
| 23 | |
| 24 | #include <psa/crypto.h> |
| 25 | |
Ronald Cron | 46f9178 | 2021-03-17 08:16:34 +0100 | [diff] [blame] | 26 | /** |
| 27 | * \brief Process an authenticated encryption operation. |
| 28 | * |
| 29 | * \note The signature of this function is that of a PSA driver |
| 30 | * aead_encrypt entry point. This function behaves as an aead_encrypt |
| 31 | * entry point as defined in the PSA driver interface specification for |
| 32 | * transparent drivers. |
| 33 | * |
| 34 | * \param[in] attributes The attributes of the key to use for the |
| 35 | * operation. |
| 36 | * \param[in] key_buffer The buffer containing the key context. |
| 37 | * \param key_buffer_size Size of the \p key_buffer buffer in bytes. |
| 38 | * \param alg The AEAD algorithm to compute. |
| 39 | * \param[in] nonce Nonce or IV to use. |
| 40 | * \param nonce_length Size of the nonce buffer in bytes. This must |
| 41 | * be appropriate for the selected algorithm. |
| 42 | * The default nonce size is |
| 43 | * PSA_AEAD_NONCE_LENGTH(key_type, alg) where |
| 44 | * key_type is the type of key. |
| 45 | * \param[in] additional_data Additional data that will be authenticated |
| 46 | * but not encrypted. |
| 47 | * \param additional_data_length Size of additional_data in bytes. |
| 48 | * \param[in] plaintext Data that will be authenticated and encrypted. |
| 49 | * \param plaintext_length Size of plaintext in bytes. |
| 50 | * \param[out] ciphertext Output buffer for the authenticated and |
| 51 | * encrypted data. The additional data is not |
| 52 | * part of this output. For algorithms where the |
| 53 | * encrypted data and the authentication tag are |
| 54 | * defined as separate outputs, the |
| 55 | * authentication tag is appended to the |
| 56 | * encrypted data. |
| 57 | * \param ciphertext_size Size of the ciphertext buffer in bytes. This |
| 58 | * must be appropriate for the selected algorithm |
| 59 | * and key: |
| 60 | * - A sufficient output size is |
| 61 | * PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, |
| 62 | * plaintext_length) where key_type is the type |
| 63 | * of key. |
| 64 | * - PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( |
| 65 | * plaintext_length) evaluates to the maximum |
| 66 | * ciphertext size of any supported AEAD |
| 67 | * encryption. |
| 68 | * \param[out] ciphertext_length On success, the size of the output in the |
| 69 | * ciphertext buffer. |
| 70 | * |
| 71 | * \retval #PSA_SUCCESS Success. |
| 72 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 73 | * \p alg is not supported. |
| 74 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 75 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 76 | * ciphertext_size is too small. |
| 77 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 78 | */ |
| 79 | psa_status_t mbedtls_psa_aead_encrypt( |
| 80 | const psa_key_attributes_t *attributes, |
| 81 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 82 | psa_algorithm_t alg, |
| 83 | const uint8_t *nonce, size_t nonce_length, |
| 84 | const uint8_t *additional_data, size_t additional_data_length, |
| 85 | const uint8_t *plaintext, size_t plaintext_length, |
| 86 | uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length ); |
| 87 | |
| 88 | /** |
| 89 | * \brief Process an authenticated decryption operation. |
| 90 | * |
| 91 | * \note The signature of this function is that of a PSA driver |
| 92 | * aead_decrypt entry point. This function behaves as an aead_decrypt |
| 93 | * entry point as defined in the PSA driver interface specification for |
| 94 | * transparent drivers. |
| 95 | * |
| 96 | * \param[in] attributes The attributes of the key to use for the |
| 97 | * operation. |
| 98 | * \param[in] key_buffer The buffer containing the key context. |
| 99 | * \param key_buffer_size Size of the \p key_buffer buffer in bytes. |
| 100 | * \param alg The AEAD algorithm to compute. |
| 101 | * \param[in] nonce Nonce or IV to use. |
| 102 | * \param nonce_length Size of the nonce buffer in bytes. This must |
| 103 | * be appropriate for the selected algorithm. |
| 104 | * The default nonce size is |
| 105 | * PSA_AEAD_NONCE_LENGTH(key_type, alg) where |
| 106 | * key_type is the type of key. |
| 107 | * \param[in] additional_data Additional data that has been authenticated |
| 108 | * but not encrypted. |
| 109 | * \param additional_data_length Size of additional_data in bytes. |
| 110 | * \param[in] ciphertext Data that has been authenticated and |
| 111 | * encrypted. For algorithms where the encrypted |
| 112 | * data and the authentication tag are defined |
| 113 | * as separate inputs, the buffer contains |
| 114 | * encrypted data followed by the authentication |
| 115 | * tag. |
| 116 | * \param ciphertext_length Size of ciphertext in bytes. |
| 117 | * \param[out] plaintext Output buffer for the decrypted data. |
| 118 | * \param plaintext_size Size of the plaintext buffer in bytes. This |
| 119 | * must be appropriate for the selected algorithm |
| 120 | * and key: |
| 121 | * - A sufficient output size is |
| 122 | * PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, |
| 123 | * ciphertext_length) where key_type is the |
| 124 | * type of key. |
| 125 | * - PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE( |
| 126 | * ciphertext_length) evaluates to the maximum |
| 127 | * plaintext size of any supported AEAD |
| 128 | * decryption. |
| 129 | * \param[out] plaintext_length On success, the size of the output in the |
| 130 | * plaintext buffer. |
| 131 | * |
| 132 | * \retval #PSA_SUCCESS Success. |
| 133 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
| 134 | * The cipher is not authentic. |
| 135 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 136 | * \p alg is not supported. |
| 137 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 138 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 139 | * plaintext_size is too small. |
| 140 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 141 | */ |
| 142 | psa_status_t mbedtls_psa_aead_decrypt( |
| 143 | const psa_key_attributes_t *attributes, |
| 144 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 145 | psa_algorithm_t alg, |
| 146 | const uint8_t *nonce, size_t nonce_length, |
| 147 | const uint8_t *additional_data, size_t additional_data_length, |
| 148 | const uint8_t *ciphertext, size_t ciphertext_length, |
| 149 | uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length ); |
| 150 | |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 151 | /** Set the key for a multipart authenticated encryption operation. |
| 152 | * |
| 153 | * \note The signature of this function is that of a PSA driver |
| 154 | * aead_encrypt_setup entry point. This function behaves as an |
| 155 | * aead_encrypt_setup entry point as defined in the PSA driver interface |
| 156 | * specification for transparent drivers. |
| 157 | * |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 158 | * If an error occurs at any step after a call to |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 159 | * mbedtls_psa_aead_encrypt_setup(), the operation is reset by the PSA core by a |
| 160 | * call to mbedtls_psa_aead_abort(). The PSA core may call |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 161 | * mbedtls_psa_aead_abort() at any time after the operation has been |
| 162 | * initialized. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 163 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 164 | * After a successful call to mbedtls_psa_aead_encrypt_setup(), the PSA core |
| 165 | * eventually terminates the operation by calling mbedtls_psa_aead_abort(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 166 | * |
| 167 | * \param[in,out] operation The operation object to set up. It must have |
| 168 | * been initialized as per the documentation for |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 169 | * #mbedtls_psa_aead_operation_t and not yet in |
| 170 | * use. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 171 | * \param[in] attributes The attributes of the key to use for the |
| 172 | * operation. |
| 173 | * \param[in] key_buffer The buffer containing the key context. |
| 174 | * \param key_buffer_size Size of the \p key_buffer buffer in bytes. |
| 175 | * \param alg The AEAD algorithm to compute |
| 176 | * (\c PSA_ALG_XXX value such that |
| 177 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 178 | * |
| 179 | * \retval #PSA_SUCCESS |
| 180 | * Success. |
| 181 | * \retval #PSA_ERROR_BAD_STATE |
| 182 | * The operation state is not valid (it must be inactive). |
| 183 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 184 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 185 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 186 | * \p key is not compatible with \p alg. |
| 187 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 188 | * \p alg is not supported or is not an AEAD algorithm. |
| 189 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 190 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 191 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 192 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 193 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 194 | * \retval #PSA_ERROR_BAD_STATE |
| 195 | * The library has not been previously initialized by psa_crypto_init(). |
| 196 | * It is implementation-dependent whether a failure to initialize |
| 197 | * results in this error code. |
| 198 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 199 | psa_status_t mbedtls_psa_aead_encrypt_setup(mbedtls_psa_aead_operation_t |
| 200 | *operation, |
| 201 | const psa_key_attributes_t |
| 202 | *attributes, |
| 203 | const uint8_t *key_buffer, |
| 204 | size_t key_buffer_size, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 205 | psa_algorithm_t alg); |
| 206 | |
| 207 | /** Set the key for a multipart authenticated decryption operation. |
| 208 | * |
| 209 | * \note The signature of this function is that of a PSA driver |
| 210 | * aead_decrypt_setup entry point. This function behaves as an |
| 211 | * aead_decrypt_setup entry point as defined in the PSA driver interface |
| 212 | * specification for transparent drivers. |
| 213 | * |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 214 | * If an error occurs at any step after a call to |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 215 | * mbedtls_psa_aead_decrypt_setup(), the PSA core resets the operation by a |
| 216 | * call to mbedtls_psa_aead_abort(). The PSA core may call |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 217 | * mbedtls_psa_aead_abort() at any time after the operation has been |
| 218 | * initialized. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 219 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 220 | * After a successful call to mbedtls_psa_aead_decrypt_setup(), the PSA core |
| 221 | * eventually terminates the operation by a call to mbedtls_psa_aead_abort(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 222 | * |
| 223 | * \param[in,out] operation The operation object to set up. It must have |
| 224 | * been initialized as per the documentation for |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 225 | * #mbedtls_psa_aead_operation_t and not yet in |
| 226 | * use. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 227 | * \param[in] attributes The attributes of the key to use for the |
| 228 | * operation. |
| 229 | * \param[in] key_buffer The buffer containing the key context. |
| 230 | * \param key_buffer_size Size of the \p key_buffer buffer in bytes. |
| 231 | * \param alg The AEAD algorithm to compute |
| 232 | * (\c PSA_ALG_XXX value such that |
| 233 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 234 | * |
| 235 | * \retval #PSA_SUCCESS |
| 236 | * Success. |
| 237 | * \retval #PSA_ERROR_BAD_STATE |
| 238 | * The operation state is not valid (it must be inactive). |
| 239 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 240 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 241 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 242 | * \p key is not compatible with \p alg. |
| 243 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 244 | * \p alg is not supported or is not an AEAD algorithm. |
| 245 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 246 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 247 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 248 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 249 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 250 | * \retval #PSA_ERROR_BAD_STATE |
| 251 | * The library has not been previously initialized by psa_crypto_init(). |
| 252 | * It is implementation-dependent whether a failure to initialize |
| 253 | * results in this error code. |
| 254 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 255 | psa_status_t mbedtls_psa_aead_decrypt_setup(mbedtls_psa_aead_operation_t |
| 256 | *operation, |
| 257 | const psa_key_attributes_t |
| 258 | *attributes, |
| 259 | const uint8_t *key_buffer, |
| 260 | size_t key_buffer_size, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 261 | psa_algorithm_t alg); |
| 262 | |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 263 | /** Set the nonce for an authenticated encryption or decryption operation. |
| 264 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 265 | * \note The signature of this function is that of a PSA driver aead_set_nonce |
| 266 | * entry point. This function behaves as an aead_set_nonce entry point as |
| 267 | * defined in the PSA driver interface specification for transparent |
| 268 | * drivers. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 269 | * |
| 270 | * This function sets the nonce for the authenticated |
| 271 | * encryption or decryption operation. |
| 272 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 273 | * The PSA core calls mbedtls_psa_aead_encrypt_setup() or |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 274 | * mbedtls_psa_aead_decrypt_setup() before calling this function. |
| 275 | * |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 276 | * If this function returns an error status, the PSA core will call |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 277 | * mbedtls_psa_aead_abort(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 278 | * |
| 279 | * \param[in,out] operation Active AEAD operation. |
| 280 | * \param[in] nonce Buffer containing the nonce to use. |
| 281 | * \param nonce_length Size of the nonce in bytes. |
| 282 | * |
| 283 | * \retval #PSA_SUCCESS |
| 284 | * Success. |
| 285 | * \retval #PSA_ERROR_BAD_STATE |
| 286 | * The operation state is not valid (it must be active, with no nonce |
| 287 | * set). |
| 288 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 289 | * The size of \p nonce is not acceptable for the chosen algorithm. |
| 290 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 291 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 292 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 293 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 294 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 295 | * \retval #PSA_ERROR_BAD_STATE |
| 296 | * The library has not been previously initialized by psa_crypto_init(). |
| 297 | * It is implementation-dependent whether a failure to initialize |
| 298 | * results in this error code. |
| 299 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 300 | psa_status_t mbedtls_psa_aead_set_nonce(mbedtls_psa_aead_operation_t *operation, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 301 | const uint8_t *nonce, |
| 302 | size_t nonce_length); |
| 303 | |
| 304 | /** Declare the lengths of the message and additional data for AEAD. |
| 305 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 306 | * \note The signature of this function is that of a PSA driver aead_set_lengths |
| 307 | * entry point. This function behaves as an aead_set_lengths entry point |
| 308 | * as defined in the PSA driver interface specification for transparent |
| 309 | * drivers. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 310 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 311 | * The PSA core calls this function before calling mbedtls_psa_aead_update_ad() |
| 312 | * or mbedtls_psa_aead_update() if the algorithm for the operation requires it. |
| 313 | * If the algorithm does not require it, calling this function is optional, but |
| 314 | * if this function is called then the implementation must enforce the lengths. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 315 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 316 | * The PSA core may call this function before or after setting the nonce with |
| 317 | * mbedtls_psa_aead_set_nonce(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 318 | * |
| 319 | * - For #PSA_ALG_CCM, calling this function is required. |
| 320 | * - For the other AEAD algorithms defined in this specification, calling |
| 321 | * this function is not required. |
| 322 | * - For vendor-defined algorithm, refer to the vendor documentation. |
| 323 | * |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 324 | * If this function returns an error status, the PSA core calls |
| 325 | * mbedtls_psa_aead_abort(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 326 | * |
| 327 | * \param[in,out] operation Active AEAD operation. |
| 328 | * \param ad_length Size of the non-encrypted additional |
| 329 | * authenticated data in bytes. |
| 330 | * \param plaintext_length Size of the plaintext to encrypt in bytes. |
| 331 | * |
| 332 | * \retval #PSA_SUCCESS |
| 333 | * Success. |
| 334 | * \retval #PSA_ERROR_BAD_STATE |
| 335 | * The operation state is not valid (it must be active, and |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 336 | * mbedtls_psa_aead_update_ad() and mbedtls_psa_aead_update() must not |
| 337 | * have been called yet). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 338 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 339 | * At least one of the lengths is not acceptable for the chosen |
| 340 | * algorithm. |
| 341 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 342 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 343 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 344 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 345 | * \retval #PSA_ERROR_BAD_STATE |
| 346 | * The library has not been previously initialized by psa_crypto_init(). |
| 347 | * It is implementation-dependent whether a failure to initialize |
| 348 | * results in this error code. |
| 349 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 350 | psa_status_t mbedtls_psa_aead_set_lengths(mbedtls_psa_aead_operation_t |
| 351 | *operation, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 352 | size_t ad_length, |
| 353 | size_t plaintext_length); |
| 354 | |
| 355 | /** Pass additional data to an active AEAD operation. |
| 356 | * |
| 357 | * \note The signature of this function is that of a PSA driver |
| 358 | * aead_update_ad entry point. This function behaves as an aead_update_ad |
| 359 | * entry point as defined in the PSA driver interface specification for |
| 360 | * transparent drivers. |
| 361 | * |
| 362 | * Additional data is authenticated, but not encrypted. |
| 363 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 364 | * The PSA core can call this function multiple times to pass successive |
| 365 | * fragments of the additional data. It will not call this function after |
| 366 | * passing data to encrypt or decrypt with mbedtls_psa_aead_update(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 367 | * |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 368 | * Before calling this function, the PSA core will: |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 369 | * 1. Call either mbedtls_psa_aead_encrypt_setup() or |
| 370 | * mbedtls_psa_aead_decrypt_setup(). |
| 371 | * 2. Set the nonce with mbedtls_psa_aead_set_nonce(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 372 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 373 | * If this function returns an error status, the PSA core will call |
| 374 | * mbedtls_psa_aead_abort(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 375 | * |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 376 | * \warning When decrypting, until mbedtls_psa_aead_verify() has returned |
| 377 | * #PSA_SUCCESS, there is no guarantee that the input is valid. |
| 378 | * Therefore, until you have called mbedtls_psa_aead_verify() and it |
| 379 | * has returned #PSA_SUCCESS, treat the input as untrusted and prepare |
| 380 | * to undo any action that depends on the input if |
| 381 | * mbedtls_psa_aead_verify() returns an error status. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 382 | * |
| 383 | * \note For the time being #PSA_ALG_CCM and #PSA_ALG_GCM require the entire |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 384 | * additional data to be passed in in one go, i.e. |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 385 | * mbedtls_psa_aead_update_ad() can only be called once. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 386 | * |
| 387 | * \param[in,out] operation Active AEAD operation. |
| 388 | * \param[in] input Buffer containing the fragment of |
| 389 | * additional data. |
| 390 | * \param input_length Size of the \p input buffer in bytes. |
| 391 | * |
| 392 | * \retval #PSA_SUCCESS |
| 393 | * Success. |
| 394 | * \retval #PSA_ERROR_BAD_STATE |
| 395 | * The operation state is not valid (it must be active, have a nonce |
| 396 | * set, have lengths set if required by the algorithm, and |
| 397 | * mbedtls_psa_aead_update() must not have been called yet). |
| 398 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 399 | * The total input length overflows the additional data length that |
| 400 | * was previously specified with mbedtls_psa_aead_set_lengths(). |
| 401 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 402 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 403 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 404 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 405 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 406 | * \retval #PSA_ERROR_BAD_STATE |
| 407 | * The library has not been previously initialized by psa_crypto_init(). |
| 408 | * It is implementation-dependent whether a failure to initialize |
| 409 | * results in this error code. |
| 410 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 411 | psa_status_t mbedtls_psa_aead_update_ad(mbedtls_psa_aead_operation_t *operation, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 412 | const uint8_t *input, |
| 413 | size_t input_length); |
| 414 | |
| 415 | /** Encrypt or decrypt a message fragment in an active AEAD operation. |
| 416 | * |
| 417 | * \note The signature of this function is that of a PSA driver |
| 418 | * aead_update entry point. This function behaves as an aead_update entry |
| 419 | * point as defined in the PSA driver interface specification for |
| 420 | * transparent drivers. |
| 421 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 422 | * Before calling this function, the PSA core will: |
| 423 | * 1. Call either mbedtls_psa_aead_encrypt_setup() or |
| 424 | * mbedtls_psa_aead_decrypt_setup(). The choice of setup function |
| 425 | * determines whether this function encrypts or decrypts its input. |
| 426 | * 2. Set the nonce with mbedtls_psa_aead_set_nonce(). |
| 427 | * 3. Call mbedtls_psa_aead_update_ad() to pass all the additional data. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 428 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 429 | * If this function returns an error status, the PSA core will call |
| 430 | * mbedtls_psa_aead_abort(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 431 | * |
| 432 | * This function does not require the input to be aligned to any |
| 433 | * particular block boundary. If the implementation can only process |
| 434 | * a whole block at a time, it must consume all the input provided, but |
| 435 | * it may delay the end of the corresponding output until a subsequent |
| 436 | * call to mbedtls_psa_aead_update(), mbedtls_psa_aead_finish() or |
| 437 | * mbedtls_psa_aead_verify() provides sufficient input. The amount of data that |
| 438 | * can be delayed in this way is bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE. |
| 439 | * |
| 440 | * \note For the time being #PSA_ALG_CCM and #PSA_ALG_GCM require the entire |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 441 | * data to be passed in in one go, i.e. mbedtls_psa_aead_update() can only |
| 442 | * be called once. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 443 | * |
| 444 | * \param[in,out] operation Active AEAD operation. |
| 445 | * \param[in] input Buffer containing the message fragment to |
| 446 | * encrypt or decrypt. |
| 447 | * \param input_length Size of the \p input buffer in bytes. |
| 448 | * \param[out] output Buffer where the output is to be written. |
| 449 | * \param output_size Size of the \p output buffer in bytes. |
Paul Elliott | 9622c9a | 2021-05-17 17:30:52 +0100 | [diff] [blame] | 450 | * This must be appropriate for the selected |
| 451 | * algorithm and key: |
| 452 | * - A sufficient output size is |
| 453 | * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, |
| 454 | * \c alg, \p input_length) where |
| 455 | * \c key_type is the type of key and \c alg is |
| 456 | * the algorithm that were used to set up the |
| 457 | * operation. |
| 458 | * - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p |
| 459 | * input_length) evaluates to the maximum |
| 460 | * output size of any supported AEAD |
| 461 | * algorithm. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 462 | * \param[out] output_length On success, the number of bytes |
| 463 | * that make up the returned output. |
| 464 | * |
| 465 | * \retval #PSA_SUCCESS |
| 466 | * Success. |
| 467 | * \retval #PSA_ERROR_BAD_STATE |
| 468 | * The operation state is not valid (it must be active, have a nonce |
| 469 | * set, and have lengths set if required by the algorithm). |
| 470 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 471 | * The size of the \p output buffer is too small. |
Paul Elliott | 9622c9a | 2021-05-17 17:30:52 +0100 | [diff] [blame] | 472 | * The size of the \p output buffer is too small. |
| 473 | * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or |
| 474 | * #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to |
| 475 | * determine the required buffer size. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 476 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 477 | * The total length of input to mbedtls_psa_aead_update_ad() so far is |
| 478 | * less than the additional data length that was previously |
| 479 | * specified with mbedtls_psa_aead_set_lengths(). |
| 480 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 481 | * The total input length overflows the plaintext length that |
| 482 | * was previously specified with mbedtls_psa_aead_set_lengths(). |
| 483 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 484 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 485 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 486 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 487 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 488 | * \retval #PSA_ERROR_BAD_STATE |
| 489 | * The library has not been previously initialized by psa_crypto_init(). |
| 490 | * It is implementation-dependent whether a failure to initialize |
| 491 | * results in this error code. |
| 492 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 493 | psa_status_t mbedtls_psa_aead_update(mbedtls_psa_aead_operation_t *operation, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 494 | const uint8_t *input, |
| 495 | size_t input_length, |
| 496 | uint8_t *output, |
| 497 | size_t output_size, |
| 498 | size_t *output_length); |
| 499 | |
| 500 | /** Finish encrypting a message in an AEAD operation. |
| 501 | * |
| 502 | * \note The signature of this function is that of a PSA driver |
| 503 | * aead_finish entry point. This function behaves as an aead_finish entry |
| 504 | * point as defined in the PSA driver interface specification for |
| 505 | * transparent drivers. |
| 506 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 507 | * The operation must have been set up by the PSA core with |
| 508 | * mbedtls_psa_aead_encrypt_setup(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 509 | * |
| 510 | * This function finishes the authentication of the additional data |
| 511 | * formed by concatenating the inputs passed to preceding calls to |
| 512 | * mbedtls_psa_aead_update_ad() with the plaintext formed by concatenating the |
| 513 | * inputs passed to preceding calls to mbedtls_psa_aead_update(). |
| 514 | * |
| 515 | * This function has two output buffers: |
| 516 | * - \p ciphertext contains trailing ciphertext that was buffered from |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 517 | * preceding calls to mbedtls_psa_aead_update(). |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 518 | * - \p tag contains the authentication tag. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 519 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 520 | * Whether or not this function returns successfuly, the PSA core subsequently |
| 521 | * calls mbedtls_psa_aead_abort() to deactivate the operation. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 522 | * |
| 523 | * \param[in,out] operation Active AEAD operation. |
| 524 | * \param[out] ciphertext Buffer where the last part of the ciphertext |
| 525 | * is to be written. |
| 526 | * \param ciphertext_size Size of the \p ciphertext buffer in bytes. |
Paul Elliott | 9622c9a | 2021-05-17 17:30:52 +0100 | [diff] [blame] | 527 | * This must be appropriate for the selected |
| 528 | * algorithm and key: |
| 529 | * - A sufficient output size is |
| 530 | * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, |
| 531 | * \c alg) where \c key_type is the type of key |
| 532 | * and \c alg is the algorithm that were used to |
| 533 | * set up the operation. |
| 534 | * - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to |
| 535 | * the maximum output size of any supported AEAD |
| 536 | * algorithm. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 537 | * \param[out] ciphertext_length On success, the number of bytes of |
| 538 | * returned ciphertext. |
| 539 | * \param[out] tag Buffer where the authentication tag is |
| 540 | * to be written. |
| 541 | * \param tag_size Size of the \p tag buffer in bytes. |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 542 | * This must be appropriate for the selected |
| 543 | * algorithm and key: |
| 544 | * - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c |
| 545 | * key_type, \c key_bits, \c alg) where |
| 546 | * \c key_type and \c key_bits are the type and |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 547 | * bit-size of the key, and \c alg are the |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 548 | * algorithm that were used in the call to |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 549 | * mbedtls_psa_aead_encrypt_setup(). |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 550 | * - #PSA_AEAD_TAG_MAX_SIZE evaluates to the |
| 551 | * maximum tag size of any supported AEAD |
| 552 | * algorithm. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 553 | * \param[out] tag_length On success, the number of bytes |
| 554 | * that make up the returned tag. |
| 555 | * |
| 556 | * \retval #PSA_SUCCESS |
| 557 | * Success. |
| 558 | * \retval #PSA_ERROR_BAD_STATE |
| 559 | * The operation state is not valid (it must be an active encryption |
| 560 | * operation with a nonce set). |
| 561 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 562 | * The size of the \p ciphertext or \p tag buffer is too small. |
Paul Elliott | 9622c9a | 2021-05-17 17:30:52 +0100 | [diff] [blame] | 563 | * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, \c alg) or |
| 564 | * #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE can be used to determine the |
| 565 | * required \p ciphertext buffer size. #PSA_AEAD_TAG_LENGTH(\c key_type, |
| 566 | * \c key_bits, \c alg) or #PSA_AEAD_TAG_MAX_SIZE can be used to |
| 567 | * determine the required \p tag buffer size. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 568 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 569 | * The total length of input to mbedtls_psa_aead_update_ad() so far is |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 570 | * less than the additional data length that was previously |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 571 | * specified with mbedtls_psa_aead_set_lengths(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 572 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 573 | * The total length of input to mbedtls_psa_aead_update() so far is |
| 574 | * less than the plaintext length that was previously |
| 575 | * specified with mbedtls_psa_aead_set_lengths(). |
| 576 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 577 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 578 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 579 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 580 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 581 | * \retval #PSA_ERROR_BAD_STATE |
| 582 | * The library has not been previously initialized by psa_crypto_init(). |
| 583 | * It is implementation-dependent whether a failure to initialize |
| 584 | * results in this error code. |
| 585 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 586 | psa_status_t mbedtls_psa_aead_finish(mbedtls_psa_aead_operation_t *operation, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 587 | uint8_t *ciphertext, |
| 588 | size_t ciphertext_size, |
| 589 | size_t *ciphertext_length, |
| 590 | uint8_t *tag, |
| 591 | size_t tag_size, |
| 592 | size_t *tag_length); |
| 593 | |
| 594 | /** Finish authenticating and decrypting a message in an AEAD operation. |
| 595 | * |
| 596 | * \note The signature of this function is that of a PSA driver |
| 597 | * aead_verify entry point. This function behaves as an aead_verify entry |
| 598 | * point as defined in the PSA driver interface specification for |
| 599 | * transparent drivers. |
| 600 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 601 | * The operation must have been set up by the PSA core with |
| 602 | * mbedtls_psa_aead_decrypt_setup(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 603 | * |
| 604 | * This function finishes the authenticated decryption of the message |
| 605 | * components: |
| 606 | * |
| 607 | * - The additional data consisting of the concatenation of the inputs |
| 608 | * passed to preceding calls to mbedtls_psa_aead_update_ad(). |
| 609 | * - The ciphertext consisting of the concatenation of the inputs passed to |
| 610 | * preceding calls to mbedtls_psa_aead_update(). |
| 611 | * - The tag passed to this function call. |
| 612 | * |
| 613 | * If the authentication tag is correct, this function outputs any remaining |
| 614 | * plaintext and reports success. If the authentication tag is not correct, |
| 615 | * this function returns #PSA_ERROR_INVALID_SIGNATURE. |
| 616 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 617 | * Whether or not this function returns successfully, the PSA core subsequently |
| 618 | * calls mbedtls_psa_aead_abort() to deactivate the operation. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 619 | * |
| 620 | * \note Implementations shall make the best effort to ensure that the |
| 621 | * comparison between the actual tag and the expected tag is performed |
| 622 | * in constant time. |
| 623 | * |
| 624 | * \param[in,out] operation Active AEAD operation. |
| 625 | * \param[out] plaintext Buffer where the last part of the plaintext |
| 626 | * is to be written. This is the remaining data |
| 627 | * from previous calls to mbedtls_psa_aead_update() |
| 628 | * that could not be processed until the end |
| 629 | * of the input. |
| 630 | * \param plaintext_size Size of the \p plaintext buffer in bytes. |
Paul Elliott | 9622c9a | 2021-05-17 17:30:52 +0100 | [diff] [blame] | 631 | * This must be appropriate for the selected |
| 632 | * algorithm and key: |
| 633 | * - A sufficient output size is |
| 634 | * #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type, |
| 635 | * \c alg) where \c key_type is the type of key |
| 636 | * and \c alg is the algorithm that were used to |
| 637 | * set up the operation. |
| 638 | * - #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE evaluates to |
| 639 | * the maximum output size of any supported AEAD |
| 640 | * algorithm. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 641 | * \param[out] plaintext_length On success, the number of bytes of |
| 642 | * returned plaintext. |
| 643 | * \param[in] tag Buffer containing the authentication tag. |
| 644 | * \param tag_length Size of the \p tag buffer in bytes. |
| 645 | * |
| 646 | * \retval #PSA_SUCCESS |
| 647 | * Success. |
| 648 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
| 649 | * The calculations were successful, but the authentication tag is |
| 650 | * not correct. |
| 651 | * \retval #PSA_ERROR_BAD_STATE |
| 652 | * The operation state is not valid (it must be an active decryption |
| 653 | * operation with a nonce set). |
| 654 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 655 | * The size of the \p plaintext buffer is too small. |
Paul Elliott | 9622c9a | 2021-05-17 17:30:52 +0100 | [diff] [blame] | 656 | * #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type, \c alg) or |
| 657 | * #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE can be used to determine the |
| 658 | * required buffer size. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 659 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 660 | * The total length of input to mbedtls_psa_aead_update_ad() so far is |
| 661 | * less than the additional data length that was previously |
| 662 | * specified with mbedtls_psa_aead_set_lengths(). |
| 663 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 664 | * The total length of input to mbedtls_psa_aead_update() so far is |
| 665 | * less than the plaintext length that was previously |
Paul Elliott | 498d350 | 2021-05-17 18:16:20 +0100 | [diff] [blame^] | 666 | * specified with mbedtls_psa_aead_set_lengths(). |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 667 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 668 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 669 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 670 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 671 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 672 | * \retval #PSA_ERROR_BAD_STATE |
| 673 | * The library has not been previously initialized by psa_crypto_init(). |
| 674 | * It is implementation-dependent whether a failure to initialize |
| 675 | * results in this error code. |
| 676 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 677 | psa_status_t mbedtls_psa_aead_verify(mbedtls_psa_aead_operation_t *operation, |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 678 | uint8_t *plaintext, |
| 679 | size_t plaintext_size, |
| 680 | size_t *plaintext_length, |
| 681 | const uint8_t *tag, |
| 682 | size_t tag_length); |
| 683 | |
| 684 | /** Abort an AEAD operation. |
| 685 | * |
| 686 | * \note The signature of this function is that of a PSA driver |
| 687 | * aead_abort entry point. This function behaves as an aead_abort entry |
| 688 | * point as defined in the PSA driver interface specification for |
| 689 | * transparent drivers. |
| 690 | * |
| 691 | * Aborting an operation frees all associated resources except for the |
| 692 | * \p operation structure itself. Once aborted, the operation object |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 693 | * can be reused for another operation by the PSA core by it calling |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 694 | * mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup() again. |
| 695 | * |
Paul Elliott | 4148a68 | 2021-05-14 17:26:56 +0100 | [diff] [blame] | 696 | * The PSA core may call this function any time after the operation object has |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 697 | * been initialized as described in #mbedtls_psa_aead_operation_t. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 698 | * |
| 699 | * In particular, calling mbedtls_psa_aead_abort() after the operation has been |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 700 | * terminated by a call to mbedtls_psa_aead_abort(), mbedtls_psa_aead_finish() |
| 701 | * or mbedtls_psa_aead_verify() is safe and has no effect. |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 702 | * |
| 703 | * \param[in,out] operation Initialized AEAD operation. |
| 704 | * |
| 705 | * \retval #PSA_SUCCESS |
| 706 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 707 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 708 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 709 | * \retval #PSA_ERROR_BAD_STATE |
| 710 | * The library has not been previously initialized by psa_crypto_init(). |
| 711 | * It is implementation-dependent whether a failure to initialize |
| 712 | * results in this error code. |
| 713 | */ |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 714 | psa_status_t mbedtls_psa_aead_abort(mbedtls_psa_aead_operation_t *operation); |
Paul Elliott | adb8b16 | 2021-04-20 16:06:57 +0100 | [diff] [blame] | 715 | |
| 716 | |
Ronald Cron | 7ceee8d | 2021-03-17 16:55:43 +0100 | [diff] [blame] | 717 | #endif /* PSA_CRYPTO_AEAD */ |