blob: a3392199f61a8b9ef62fcfab063d936ee5a2ab0b [file] [log] [blame]
Ronald Cron7ceee8d2021-03-17 16:55:43 +01001/*
2 * PSA AEAD driver entry points
3 */
4/*
5 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00006 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Ronald Cron7ceee8d2021-03-17 16:55:43 +01007 */
8
9#ifndef PSA_CRYPTO_AEAD_H
10#define PSA_CRYPTO_AEAD_H
11
12#include <psa/crypto.h>
13
Ronald Cron46f91782021-03-17 08:16:34 +010014/**
15 * \brief Process an authenticated encryption operation.
16 *
17 * \note The signature of this function is that of a PSA driver
18 * aead_encrypt entry point. This function behaves as an aead_encrypt
19 * entry point as defined in the PSA driver interface specification for
20 * transparent drivers.
21 *
22 * \param[in] attributes The attributes of the key to use for the
23 * operation.
24 * \param[in] key_buffer The buffer containing the key context.
25 * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
26 * \param alg The AEAD algorithm to compute.
27 * \param[in] nonce Nonce or IV to use.
28 * \param nonce_length Size of the nonce buffer in bytes. This must
29 * be appropriate for the selected algorithm.
30 * The default nonce size is
31 * PSA_AEAD_NONCE_LENGTH(key_type, alg) where
32 * key_type is the type of key.
33 * \param[in] additional_data Additional data that will be authenticated
34 * but not encrypted.
35 * \param additional_data_length Size of additional_data in bytes.
36 * \param[in] plaintext Data that will be authenticated and encrypted.
37 * \param plaintext_length Size of plaintext in bytes.
38 * \param[out] ciphertext Output buffer for the authenticated and
39 * encrypted data. The additional data is not
40 * part of this output. For algorithms where the
41 * encrypted data and the authentication tag are
42 * defined as separate outputs, the
43 * authentication tag is appended to the
44 * encrypted data.
45 * \param ciphertext_size Size of the ciphertext buffer in bytes. This
46 * must be appropriate for the selected algorithm
47 * and key:
48 * - A sufficient output size is
49 * PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg,
50 * plaintext_length) where key_type is the type
51 * of key.
52 * - PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(
53 * plaintext_length) evaluates to the maximum
54 * ciphertext size of any supported AEAD
55 * encryption.
56 * \param[out] ciphertext_length On success, the size of the output in the
57 * ciphertext buffer.
58 *
59 * \retval #PSA_SUCCESS Success.
60 * \retval #PSA_ERROR_NOT_SUPPORTED
61 * \p alg is not supported.
Gilles Peskineed733552023-02-14 19:21:09 +010062 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
Ronald Cron46f91782021-03-17 08:16:34 +010063 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
64 * ciphertext_size is too small.
Gilles Peskineed733552023-02-14 19:21:09 +010065 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Ronald Cron46f91782021-03-17 08:16:34 +010066 */
67psa_status_t mbedtls_psa_aead_encrypt(
68 const psa_key_attributes_t *attributes,
69 const uint8_t *key_buffer, size_t key_buffer_size,
70 psa_algorithm_t alg,
71 const uint8_t *nonce, size_t nonce_length,
72 const uint8_t *additional_data, size_t additional_data_length,
73 const uint8_t *plaintext, size_t plaintext_length,
Gilles Peskine449bd832023-01-11 14:50:10 +010074 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length);
Ronald Cron46f91782021-03-17 08:16:34 +010075
76/**
77 * \brief Process an authenticated decryption operation.
78 *
79 * \note The signature of this function is that of a PSA driver
80 * aead_decrypt entry point. This function behaves as an aead_decrypt
81 * entry point as defined in the PSA driver interface specification for
82 * transparent drivers.
83 *
84 * \param[in] attributes The attributes of the key to use for the
85 * operation.
86 * \param[in] key_buffer The buffer containing the key context.
87 * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
88 * \param alg The AEAD algorithm to compute.
89 * \param[in] nonce Nonce or IV to use.
90 * \param nonce_length Size of the nonce buffer in bytes. This must
91 * be appropriate for the selected algorithm.
92 * The default nonce size is
93 * PSA_AEAD_NONCE_LENGTH(key_type, alg) where
94 * key_type is the type of key.
95 * \param[in] additional_data Additional data that has been authenticated
96 * but not encrypted.
97 * \param additional_data_length Size of additional_data in bytes.
98 * \param[in] ciphertext Data that has been authenticated and
99 * encrypted. For algorithms where the encrypted
100 * data and the authentication tag are defined
101 * as separate inputs, the buffer contains
102 * encrypted data followed by the authentication
103 * tag.
104 * \param ciphertext_length Size of ciphertext in bytes.
105 * \param[out] plaintext Output buffer for the decrypted data.
106 * \param plaintext_size Size of the plaintext buffer in bytes. This
107 * must be appropriate for the selected algorithm
108 * and key:
109 * - A sufficient output size is
110 * PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg,
111 * ciphertext_length) where key_type is the
112 * type of key.
113 * - PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(
114 * ciphertext_length) evaluates to the maximum
115 * plaintext size of any supported AEAD
116 * decryption.
117 * \param[out] plaintext_length On success, the size of the output in the
118 * plaintext buffer.
119 *
120 * \retval #PSA_SUCCESS Success.
121 * \retval #PSA_ERROR_INVALID_SIGNATURE
122 * The cipher is not authentic.
123 * \retval #PSA_ERROR_NOT_SUPPORTED
124 * \p alg is not supported.
Gilles Peskineed733552023-02-14 19:21:09 +0100125 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
Ronald Cron46f91782021-03-17 08:16:34 +0100126 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
127 * plaintext_size is too small.
Gilles Peskineed733552023-02-14 19:21:09 +0100128 * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
Ronald Cron46f91782021-03-17 08:16:34 +0100129 */
130psa_status_t mbedtls_psa_aead_decrypt(
131 const psa_key_attributes_t *attributes,
132 const uint8_t *key_buffer, size_t key_buffer_size,
133 psa_algorithm_t alg,
134 const uint8_t *nonce, size_t nonce_length,
135 const uint8_t *additional_data, size_t additional_data_length,
136 const uint8_t *ciphertext, size_t ciphertext_length,
Gilles Peskine449bd832023-01-11 14:50:10 +0100137 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length);
Ronald Cron46f91782021-03-17 08:16:34 +0100138
Paul Elliottadb8b162021-04-20 16:06:57 +0100139/** Set the key for a multipart authenticated encryption operation.
140 *
141 * \note The signature of this function is that of a PSA driver
142 * aead_encrypt_setup entry point. This function behaves as an
143 * aead_encrypt_setup entry point as defined in the PSA driver interface
144 * specification for transparent drivers.
145 *
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100146 * If an error occurs at any step after a call to
Paul Elliott4148a682021-05-14 17:26:56 +0100147 * mbedtls_psa_aead_encrypt_setup(), the operation is reset by the PSA core by a
148 * call to mbedtls_psa_aead_abort(). The PSA core may call
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100149 * mbedtls_psa_aead_abort() at any time after the operation has been
Paul Elliott36869702021-08-19 19:17:04 +0100150 * initialized, and is required to when the operation is no longer needed.
Paul Elliottadb8b162021-04-20 16:06:57 +0100151 *
152 * \param[in,out] operation The operation object to set up. It must have
153 * been initialized as per the documentation for
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100154 * #mbedtls_psa_aead_operation_t and not yet in
155 * use.
Paul Elliottadb8b162021-04-20 16:06:57 +0100156 * \param[in] attributes The attributes of the key to use for the
157 * operation.
158 * \param[in] key_buffer The buffer containing the key context.
159 * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
Paul Elliottc78833a2021-09-27 16:00:40 +0100160 It must be consistent with the size in bits
161 recorded in \p attributes.
Paul Elliottadb8b162021-04-20 16:06:57 +0100162 * \param alg The AEAD algorithm to compute
163 * (\c PSA_ALG_XXX value such that
164 * #PSA_ALG_IS_AEAD(\p alg) is true).
165 *
166 * \retval #PSA_SUCCESS
167 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100168 * \retval #PSA_ERROR_INVALID_ARGUMENT
Paul Elliotta8940ed2021-06-24 16:57:52 +0100169 * An invalid block length was supplied.
Paul Elliottadb8b162021-04-20 16:06:57 +0100170 * \retval #PSA_ERROR_NOT_SUPPORTED
Paul Elliott1c8de152021-06-03 15:54:00 +0100171 * \p alg is not supported.
Paul Elliottadb8b162021-04-20 16:06:57 +0100172 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Paul Elliottb91f3312021-05-19 12:30:15 +0100173 * Failed to allocate memory for key material
Paul Elliottadb8b162021-04-20 16:06:57 +0100174 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100175psa_status_t mbedtls_psa_aead_encrypt_setup(
176 mbedtls_psa_aead_operation_t *operation,
177 const psa_key_attributes_t *attributes,
178 const uint8_t *key_buffer,
179 size_t key_buffer_size,
Gilles Peskine449bd832023-01-11 14:50:10 +0100180 psa_algorithm_t alg);
Paul Elliottadb8b162021-04-20 16:06:57 +0100181
182/** Set the key for a multipart authenticated decryption operation.
183 *
184 * \note The signature of this function is that of a PSA driver
185 * aead_decrypt_setup entry point. This function behaves as an
186 * aead_decrypt_setup entry point as defined in the PSA driver interface
187 * specification for transparent drivers.
188 *
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100189 * If an error occurs at any step after a call to
Paul Elliott4148a682021-05-14 17:26:56 +0100190 * mbedtls_psa_aead_decrypt_setup(), the PSA core resets the operation by a
191 * call to mbedtls_psa_aead_abort(). The PSA core may call
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100192 * mbedtls_psa_aead_abort() at any time after the operation has been
Paul Elliott36869702021-08-19 19:17:04 +0100193 * initialized, and is required to when the operation is no longer needed.
Paul Elliottadb8b162021-04-20 16:06:57 +0100194 *
195 * \param[in,out] operation The operation object to set up. It must have
196 * been initialized as per the documentation for
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100197 * #mbedtls_psa_aead_operation_t and not yet in
198 * use.
Paul Elliottadb8b162021-04-20 16:06:57 +0100199 * \param[in] attributes The attributes of the key to use for the
200 * operation.
201 * \param[in] key_buffer The buffer containing the key context.
202 * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
Paul Elliottc78833a2021-09-27 16:00:40 +0100203 It must be consistent with the size in bits
204 recorded in \p attributes.
Paul Elliottadb8b162021-04-20 16:06:57 +0100205 * \param alg The AEAD algorithm to compute
206 * (\c PSA_ALG_XXX value such that
207 * #PSA_ALG_IS_AEAD(\p alg) is true).
208 *
209 * \retval #PSA_SUCCESS
210 * Success.
Paul Elliotta8940ed2021-06-24 16:57:52 +0100211 * \retval #PSA_ERROR_INVALID_ARGUMENT
212 * An invalid block length was supplied.
Paul Elliottadb8b162021-04-20 16:06:57 +0100213 * \retval #PSA_ERROR_NOT_SUPPORTED
Paul Elliott1c8de152021-06-03 15:54:00 +0100214 * \p alg is not supported.
Paul Elliottadb8b162021-04-20 16:06:57 +0100215 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Paul Elliottb91f3312021-05-19 12:30:15 +0100216 * Failed to allocate memory for key material
Paul Elliottadb8b162021-04-20 16:06:57 +0100217 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100218psa_status_t mbedtls_psa_aead_decrypt_setup(
219 mbedtls_psa_aead_operation_t *operation,
220 const psa_key_attributes_t *attributes,
221 const uint8_t *key_buffer,
222 size_t key_buffer_size,
Gilles Peskine449bd832023-01-11 14:50:10 +0100223 psa_algorithm_t alg);
Paul Elliottadb8b162021-04-20 16:06:57 +0100224
Paul Elliottadb8b162021-04-20 16:06:57 +0100225/** Set the nonce for an authenticated encryption or decryption operation.
226 *
Paul Elliott4148a682021-05-14 17:26:56 +0100227 * \note The signature of this function is that of a PSA driver aead_set_nonce
228 * entry point. This function behaves as an aead_set_nonce entry point as
229 * defined in the PSA driver interface specification for transparent
230 * drivers.
Paul Elliottadb8b162021-04-20 16:06:57 +0100231 *
232 * This function sets the nonce for the authenticated
233 * encryption or decryption operation.
234 *
Paul Elliott4148a682021-05-14 17:26:56 +0100235 * The PSA core calls mbedtls_psa_aead_encrypt_setup() or
Paul Elliottadb8b162021-04-20 16:06:57 +0100236 * mbedtls_psa_aead_decrypt_setup() before calling this function.
237 *
Paul Elliott498d3502021-05-17 18:16:20 +0100238 * If this function returns an error status, the PSA core will call
Paul Elliott4148a682021-05-14 17:26:56 +0100239 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100240 *
241 * \param[in,out] operation Active AEAD operation.
242 * \param[in] nonce Buffer containing the nonce to use.
243 * \param nonce_length Size of the nonce in bytes.
244 *
245 * \retval #PSA_SUCCESS
246 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100247 * \retval #PSA_ERROR_INVALID_ARGUMENT
248 * The size of \p nonce is not acceptable for the chosen algorithm.
Paul Elliottb91f3312021-05-19 12:30:15 +0100249 * \retval #PSA_ERROR_NOT_SUPPORTED
250 * Algorithm previously set is not supported in this configuration of
251 * the library.
Paul Elliottadb8b162021-04-20 16:06:57 +0100252 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100253psa_status_t mbedtls_psa_aead_set_nonce(
254 mbedtls_psa_aead_operation_t *operation,
255 const uint8_t *nonce,
Gilles Peskine449bd832023-01-11 14:50:10 +0100256 size_t nonce_length);
Paul Elliottadb8b162021-04-20 16:06:57 +0100257
Paul Elliottdff6c5d2021-09-28 11:00:20 +0100258/** Declare the lengths of the message and additional data for AEAD.
259 *
260 * \note The signature of this function is that of a PSA driver aead_set_lengths
261 * entry point. This function behaves as an aead_set_lengths entry point
262 * as defined in the PSA driver interface specification for transparent
263 * drivers.
264 *
265 * The PSA core calls this function before calling mbedtls_psa_aead_update_ad()
266 * or mbedtls_psa_aead_update() if the algorithm for the operation requires it.
267 * If the algorithm does not require it, calling this function is optional, but
268 * if this function is called then the implementation must enforce the lengths.
269 *
270 * The PSA core may call this function before or after setting the nonce with
271 * mbedtls_psa_aead_set_nonce().
272 *
273 * - For #PSA_ALG_CCM, calling this function is required.
274 * - For the other AEAD algorithms defined in this specification, calling
275 * this function is not required.
276 *
277 * If this function returns an error status, the PSA core calls
278 * mbedtls_psa_aead_abort().
279 *
280 * \param[in,out] operation Active AEAD operation.
281 * \param ad_length Size of the non-encrypted additional
282 * authenticated data in bytes.
283 * \param plaintext_length Size of the plaintext to encrypt in bytes.
284 *
285 * \retval #PSA_SUCCESS
286 * Success.
287 * \retval #PSA_ERROR_INVALID_ARGUMENT
288 * At least one of the lengths is not acceptable for the chosen
289 * algorithm.
290 * \retval #PSA_ERROR_NOT_SUPPORTED
291 * Algorithm previously set is not supported in this configuration of
292 * the library.
293 */
294psa_status_t mbedtls_psa_aead_set_lengths(
295 mbedtls_psa_aead_operation_t *operation,
296 size_t ad_length,
Gilles Peskine449bd832023-01-11 14:50:10 +0100297 size_t plaintext_length);
Paul Elliottdff6c5d2021-09-28 11:00:20 +0100298
Paul Elliottadb8b162021-04-20 16:06:57 +0100299/** Pass additional data to an active AEAD operation.
300 *
301 * \note The signature of this function is that of a PSA driver
302 * aead_update_ad entry point. This function behaves as an aead_update_ad
303 * entry point as defined in the PSA driver interface specification for
304 * transparent drivers.
305 *
306 * Additional data is authenticated, but not encrypted.
307 *
Paul Elliott4148a682021-05-14 17:26:56 +0100308 * The PSA core can call this function multiple times to pass successive
309 * fragments of the additional data. It will not call this function after
310 * passing data to encrypt or decrypt with mbedtls_psa_aead_update().
Paul Elliottadb8b162021-04-20 16:06:57 +0100311 *
Paul Elliott498d3502021-05-17 18:16:20 +0100312 * Before calling this function, the PSA core will:
Paul Elliott4148a682021-05-14 17:26:56 +0100313 * 1. Call either mbedtls_psa_aead_encrypt_setup() or
314 * mbedtls_psa_aead_decrypt_setup().
315 * 2. Set the nonce with mbedtls_psa_aead_set_nonce().
Paul Elliottadb8b162021-04-20 16:06:57 +0100316 *
Paul Elliott4148a682021-05-14 17:26:56 +0100317 * If this function returns an error status, the PSA core will call
318 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100319 *
Paul Elliottadb8b162021-04-20 16:06:57 +0100320 * \param[in,out] operation Active AEAD operation.
321 * \param[in] input Buffer containing the fragment of
322 * additional data.
323 * \param input_length Size of the \p input buffer in bytes.
324 *
325 * \retval #PSA_SUCCESS
326 * Success.
Paul Elliottb91f3312021-05-19 12:30:15 +0100327 * \retval #PSA_ERROR_NOT_SUPPORTED
328 * Algorithm previously set is not supported in this configuration of
329 * the library.
Paul Elliottadb8b162021-04-20 16:06:57 +0100330 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100331psa_status_t mbedtls_psa_aead_update_ad(
332 mbedtls_psa_aead_operation_t *operation,
333 const uint8_t *input,
Gilles Peskine449bd832023-01-11 14:50:10 +0100334 size_t input_length);
Paul Elliottadb8b162021-04-20 16:06:57 +0100335
336/** Encrypt or decrypt a message fragment in an active AEAD operation.
337 *
338 * \note The signature of this function is that of a PSA driver
339 * aead_update entry point. This function behaves as an aead_update entry
340 * point as defined in the PSA driver interface specification for
341 * transparent drivers.
342 *
Paul Elliott4148a682021-05-14 17:26:56 +0100343 * Before calling this function, the PSA core will:
344 * 1. Call either mbedtls_psa_aead_encrypt_setup() or
345 * mbedtls_psa_aead_decrypt_setup(). The choice of setup function
346 * determines whether this function encrypts or decrypts its input.
347 * 2. Set the nonce with mbedtls_psa_aead_set_nonce().
348 * 3. Call mbedtls_psa_aead_update_ad() to pass all the additional data.
Paul Elliottadb8b162021-04-20 16:06:57 +0100349 *
Paul Elliott4148a682021-05-14 17:26:56 +0100350 * If this function returns an error status, the PSA core will call
351 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100352 *
353 * This function does not require the input to be aligned to any
354 * particular block boundary. If the implementation can only process
355 * a whole block at a time, it must consume all the input provided, but
356 * it may delay the end of the corresponding output until a subsequent
Paul Elliott12acb6b2021-09-15 17:45:22 +0100357 * call to mbedtls_psa_aead_update(), mbedtls_psa_aead_finish() provides
358 * sufficient input. The amount of data that can be delayed in this way is
359 * bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE.
Paul Elliottadb8b162021-04-20 16:06:57 +0100360 *
Paul Elliottadb8b162021-04-20 16:06:57 +0100361 * \param[in,out] operation Active AEAD operation.
362 * \param[in] input Buffer containing the message fragment to
363 * encrypt or decrypt.
364 * \param input_length Size of the \p input buffer in bytes.
365 * \param[out] output Buffer where the output is to be written.
366 * \param output_size Size of the \p output buffer in bytes.
Paul Elliott9622c9a2021-05-17 17:30:52 +0100367 * This must be appropriate for the selected
368 * algorithm and key:
369 * - A sufficient output size is
370 * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type,
371 * \c alg, \p input_length) where
372 * \c key_type is the type of key and \c alg is
373 * the algorithm that were used to set up the
374 * operation.
375 * - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p
376 * input_length) evaluates to the maximum
377 * output size of any supported AEAD
378 * algorithm.
Paul Elliottadb8b162021-04-20 16:06:57 +0100379 * \param[out] output_length On success, the number of bytes
380 * that make up the returned output.
381 *
382 * \retval #PSA_SUCCESS
383 * Success.
Paul Elliotta8940ed2021-06-24 16:57:52 +0100384 *
Paul Elliottadb8b162021-04-20 16:06:57 +0100385 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
386 * The size of the \p output buffer is too small.
Paul Elliott9622c9a2021-05-17 17:30:52 +0100387 * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or
388 * #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to
389 * determine the required buffer size.
Paul Elliottadb8b162021-04-20 16:06:57 +0100390 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100391psa_status_t mbedtls_psa_aead_update(
392 mbedtls_psa_aead_operation_t *operation,
393 const uint8_t *input,
394 size_t input_length,
395 uint8_t *output,
396 size_t output_size,
Gilles Peskine449bd832023-01-11 14:50:10 +0100397 size_t *output_length);
Paul Elliottadb8b162021-04-20 16:06:57 +0100398
399/** Finish encrypting a message in an AEAD operation.
400 *
401 * \note The signature of this function is that of a PSA driver
402 * aead_finish entry point. This function behaves as an aead_finish entry
403 * point as defined in the PSA driver interface specification for
404 * transparent drivers.
405 *
Paul Elliott4148a682021-05-14 17:26:56 +0100406 * The operation must have been set up by the PSA core with
407 * mbedtls_psa_aead_encrypt_setup().
Paul Elliottadb8b162021-04-20 16:06:57 +0100408 *
409 * This function finishes the authentication of the additional data
410 * formed by concatenating the inputs passed to preceding calls to
411 * mbedtls_psa_aead_update_ad() with the plaintext formed by concatenating the
412 * inputs passed to preceding calls to mbedtls_psa_aead_update().
413 *
414 * This function has two output buffers:
415 * - \p ciphertext contains trailing ciphertext that was buffered from
Paul Elliott498d3502021-05-17 18:16:20 +0100416 * preceding calls to mbedtls_psa_aead_update().
Paul Elliott4148a682021-05-14 17:26:56 +0100417 * - \p tag contains the authentication tag.
Paul Elliottadb8b162021-04-20 16:06:57 +0100418 *
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800419 * Whether or not this function returns successfully, the PSA core subsequently
Paul Elliott4148a682021-05-14 17:26:56 +0100420 * calls mbedtls_psa_aead_abort() to deactivate the operation.
Paul Elliottadb8b162021-04-20 16:06:57 +0100421 *
422 * \param[in,out] operation Active AEAD operation.
423 * \param[out] ciphertext Buffer where the last part of the ciphertext
424 * is to be written.
425 * \param ciphertext_size Size of the \p ciphertext buffer in bytes.
Paul Elliott9622c9a2021-05-17 17:30:52 +0100426 * This must be appropriate for the selected
427 * algorithm and key:
428 * - A sufficient output size is
429 * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type,
430 * \c alg) where \c key_type is the type of key
431 * and \c alg is the algorithm that were used to
432 * set up the operation.
433 * - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to
434 * the maximum output size of any supported AEAD
435 * algorithm.
Paul Elliottadb8b162021-04-20 16:06:57 +0100436 * \param[out] ciphertext_length On success, the number of bytes of
437 * returned ciphertext.
438 * \param[out] tag Buffer where the authentication tag is
439 * to be written.
440 * \param tag_size Size of the \p tag buffer in bytes.
Paul Elliott4148a682021-05-14 17:26:56 +0100441 * This must be appropriate for the selected
442 * algorithm and key:
443 * - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c
444 * key_type, \c key_bits, \c alg) where
445 * \c key_type and \c key_bits are the type and
Paul Elliott498d3502021-05-17 18:16:20 +0100446 * bit-size of the key, and \c alg are the
Paul Elliott4148a682021-05-14 17:26:56 +0100447 * algorithm that were used in the call to
Paul Elliott498d3502021-05-17 18:16:20 +0100448 * mbedtls_psa_aead_encrypt_setup().
Paul Elliott4148a682021-05-14 17:26:56 +0100449 * - #PSA_AEAD_TAG_MAX_SIZE evaluates to the
450 * maximum tag size of any supported AEAD
451 * algorithm.
Paul Elliottadb8b162021-04-20 16:06:57 +0100452 * \param[out] tag_length On success, the number of bytes
453 * that make up the returned tag.
454 *
455 * \retval #PSA_SUCCESS
456 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100457 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
Paul Elliotted68d742021-06-24 20:37:32 +0100458 * The size of the \p tag buffer is too small.
459 * #PSA_AEAD_TAG_LENGTH(\c key_type, key_bits, \c alg) or
460 * #PSA_AEAD_TAG_MAX_SIZE can be used to determine the required \p tag
461 * buffer size.
Paul Elliottadb8b162021-04-20 16:06:57 +0100462 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100463psa_status_t mbedtls_psa_aead_finish(
464 mbedtls_psa_aead_operation_t *operation,
465 uint8_t *ciphertext,
466 size_t ciphertext_size,
467 size_t *ciphertext_length,
468 uint8_t *tag,
469 size_t tag_size,
Gilles Peskine449bd832023-01-11 14:50:10 +0100470 size_t *tag_length);
Paul Elliottadb8b162021-04-20 16:06:57 +0100471
Paul Elliottadb8b162021-04-20 16:06:57 +0100472/** Abort an AEAD operation.
473 *
474 * \note The signature of this function is that of a PSA driver
475 * aead_abort entry point. This function behaves as an aead_abort entry
476 * point as defined in the PSA driver interface specification for
477 * transparent drivers.
478 *
479 * Aborting an operation frees all associated resources except for the
480 * \p operation structure itself. Once aborted, the operation object
Paul Elliott4148a682021-05-14 17:26:56 +0100481 * can be reused for another operation by the PSA core by it calling
Paul Elliottadb8b162021-04-20 16:06:57 +0100482 * mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup() again.
483 *
Paul Elliott4148a682021-05-14 17:26:56 +0100484 * The PSA core may call this function any time after the operation object has
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100485 * been initialized as described in #mbedtls_psa_aead_operation_t.
Paul Elliottadb8b162021-04-20 16:06:57 +0100486 *
487 * In particular, calling mbedtls_psa_aead_abort() after the operation has been
Paul Elliott12acb6b2021-09-15 17:45:22 +0100488 * terminated by a call to mbedtls_psa_aead_abort() or
489 * mbedtls_psa_aead_finish() is safe and has no effect.
Paul Elliottadb8b162021-04-20 16:06:57 +0100490 *
491 * \param[in,out] operation Initialized AEAD operation.
492 *
493 * \retval #PSA_SUCCESS
Paul Elliottb91f3312021-05-19 12:30:15 +0100494 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100495 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100496psa_status_t mbedtls_psa_aead_abort(
Gilles Peskine449bd832023-01-11 14:50:10 +0100497 mbedtls_psa_aead_operation_t *operation);
Paul Elliottadb8b162021-04-20 16:06:57 +0100498
Pengyu Lvc1ecb252022-11-08 18:17:00 +0800499#endif /* PSA_CRYPTO_AEAD_H */