blob: 5ed26d002e32dad9d6038409354f184416bf06e9 [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
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 Cron46f91782021-03-17 08:16:34 +010026/**
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 */
79psa_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 */
142psa_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 Elliottadb8b162021-04-20 16:06:57 +0100151/** 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 Elliottcbbde5f2021-05-10 18:19:46 +0100158 * If an error occurs at any step after a call to
Paul Elliott4148a682021-05-14 17:26:56 +0100159 * 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 Elliottcbbde5f2021-05-10 18:19:46 +0100161 * mbedtls_psa_aead_abort() at any time after the operation has been
Paul Elliott36869702021-08-19 19:17:04 +0100162 * initialized, and is required to when the operation is no longer needed.
Paul Elliottadb8b162021-04-20 16:06:57 +0100163 *
164 * \param[in,out] operation The operation object to set up. It must have
165 * been initialized as per the documentation for
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100166 * #mbedtls_psa_aead_operation_t and not yet in
167 * use.
Paul Elliottadb8b162021-04-20 16:06:57 +0100168 * \param[in] attributes The attributes of the key to use for the
169 * operation.
170 * \param[in] key_buffer The buffer containing the key context.
171 * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
172 * \param alg The AEAD algorithm to compute
173 * (\c PSA_ALG_XXX value such that
174 * #PSA_ALG_IS_AEAD(\p alg) is true).
175 *
176 * \retval #PSA_SUCCESS
177 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100178 * \retval #PSA_ERROR_INVALID_ARGUMENT
Paul Elliotta8940ed2021-06-24 16:57:52 +0100179 * An invalid block length was supplied.
Paul Elliottadb8b162021-04-20 16:06:57 +0100180 * \retval #PSA_ERROR_NOT_SUPPORTED
Paul Elliott1c8de152021-06-03 15:54:00 +0100181 * \p alg is not supported.
Paul Elliottadb8b162021-04-20 16:06:57 +0100182 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Paul Elliottb91f3312021-05-19 12:30:15 +0100183 * Failed to allocate memory for key material
Paul Elliottadb8b162021-04-20 16:06:57 +0100184 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100185psa_status_t mbedtls_psa_aead_encrypt_setup(
186 mbedtls_psa_aead_operation_t *operation,
187 const psa_key_attributes_t *attributes,
188 const uint8_t *key_buffer,
189 size_t key_buffer_size,
190 psa_algorithm_t alg );
Paul Elliottadb8b162021-04-20 16:06:57 +0100191
192/** Set the key for a multipart authenticated decryption operation.
193 *
194 * \note The signature of this function is that of a PSA driver
195 * aead_decrypt_setup entry point. This function behaves as an
196 * aead_decrypt_setup entry point as defined in the PSA driver interface
197 * specification for transparent drivers.
198 *
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100199 * If an error occurs at any step after a call to
Paul Elliott4148a682021-05-14 17:26:56 +0100200 * mbedtls_psa_aead_decrypt_setup(), the PSA core resets the operation by a
201 * call to mbedtls_psa_aead_abort(). The PSA core may call
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100202 * mbedtls_psa_aead_abort() at any time after the operation has been
Paul Elliott36869702021-08-19 19:17:04 +0100203 * initialized, and is required to when the operation is no longer needed.
Paul Elliottadb8b162021-04-20 16:06:57 +0100204 *
205 * \param[in,out] operation The operation object to set up. It must have
206 * been initialized as per the documentation for
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100207 * #mbedtls_psa_aead_operation_t and not yet in
208 * use.
Paul Elliottadb8b162021-04-20 16:06:57 +0100209 * \param[in] attributes The attributes of the key to use for the
210 * operation.
211 * \param[in] key_buffer The buffer containing the key context.
212 * \param key_buffer_size Size of the \p key_buffer buffer in bytes.
213 * \param alg The AEAD algorithm to compute
214 * (\c PSA_ALG_XXX value such that
215 * #PSA_ALG_IS_AEAD(\p alg) is true).
216 *
217 * \retval #PSA_SUCCESS
218 * Success.
Paul Elliotta8940ed2021-06-24 16:57:52 +0100219 * \retval #PSA_ERROR_INVALID_ARGUMENT
220 * An invalid block length was supplied.
Paul Elliottadb8b162021-04-20 16:06:57 +0100221 * \retval #PSA_ERROR_NOT_SUPPORTED
Paul Elliott1c8de152021-06-03 15:54:00 +0100222 * \p alg is not supported.
Paul Elliottadb8b162021-04-20 16:06:57 +0100223 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Paul Elliottb91f3312021-05-19 12:30:15 +0100224 * Failed to allocate memory for key material
Paul Elliottadb8b162021-04-20 16:06:57 +0100225 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100226psa_status_t mbedtls_psa_aead_decrypt_setup(
227 mbedtls_psa_aead_operation_t *operation,
228 const psa_key_attributes_t *attributes,
229 const uint8_t *key_buffer,
230 size_t key_buffer_size,
231 psa_algorithm_t alg );
Paul Elliottadb8b162021-04-20 16:06:57 +0100232
Paul Elliottadb8b162021-04-20 16:06:57 +0100233/** Set the nonce for an authenticated encryption or decryption operation.
234 *
Paul Elliott4148a682021-05-14 17:26:56 +0100235 * \note The signature of this function is that of a PSA driver aead_set_nonce
236 * entry point. This function behaves as an aead_set_nonce entry point as
237 * defined in the PSA driver interface specification for transparent
238 * drivers.
Paul Elliottadb8b162021-04-20 16:06:57 +0100239 *
240 * This function sets the nonce for the authenticated
241 * encryption or decryption operation.
242 *
Paul Elliott4148a682021-05-14 17:26:56 +0100243 * The PSA core calls mbedtls_psa_aead_encrypt_setup() or
Paul Elliottadb8b162021-04-20 16:06:57 +0100244 * mbedtls_psa_aead_decrypt_setup() before calling this function.
245 *
Paul Elliott498d3502021-05-17 18:16:20 +0100246 * If this function returns an error status, the PSA core will call
Paul Elliott4148a682021-05-14 17:26:56 +0100247 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100248 *
249 * \param[in,out] operation Active AEAD operation.
250 * \param[in] nonce Buffer containing the nonce to use.
251 * \param nonce_length Size of the nonce in bytes.
252 *
253 * \retval #PSA_SUCCESS
254 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100255 * \retval #PSA_ERROR_INVALID_ARGUMENT
256 * The size of \p nonce is not acceptable for the chosen algorithm.
Paul Elliottb91f3312021-05-19 12:30:15 +0100257 * \retval #PSA_ERROR_NOT_SUPPORTED
258 * Algorithm previously set is not supported in this configuration of
259 * the library.
Paul Elliottadb8b162021-04-20 16:06:57 +0100260 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100261psa_status_t mbedtls_psa_aead_set_nonce(
262 mbedtls_psa_aead_operation_t *operation,
263 const uint8_t *nonce,
264 size_t nonce_length );
Paul Elliottadb8b162021-04-20 16:06:57 +0100265
266/** Declare the lengths of the message and additional data for AEAD.
267 *
Paul Elliott4148a682021-05-14 17:26:56 +0100268 * \note The signature of this function is that of a PSA driver aead_set_lengths
269 * entry point. This function behaves as an aead_set_lengths entry point
270 * as defined in the PSA driver interface specification for transparent
271 * drivers.
Paul Elliottadb8b162021-04-20 16:06:57 +0100272 *
Paul Elliott4148a682021-05-14 17:26:56 +0100273 * The PSA core calls this function before calling mbedtls_psa_aead_update_ad()
274 * or mbedtls_psa_aead_update() if the algorithm for the operation requires it.
275 * If the algorithm does not require it, calling this function is optional, but
276 * if this function is called then the implementation must enforce the lengths.
Paul Elliottadb8b162021-04-20 16:06:57 +0100277 *
Paul Elliott4148a682021-05-14 17:26:56 +0100278 * The PSA core may call this function before or after setting the nonce with
279 * mbedtls_psa_aead_set_nonce().
Paul Elliottadb8b162021-04-20 16:06:57 +0100280 *
281 * - For #PSA_ALG_CCM, calling this function is required.
282 * - For the other AEAD algorithms defined in this specification, calling
283 * this function is not required.
Paul Elliottadb8b162021-04-20 16:06:57 +0100284 *
Paul Elliott498d3502021-05-17 18:16:20 +0100285 * If this function returns an error status, the PSA core calls
286 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100287 *
288 * \param[in,out] operation Active AEAD operation.
289 * \param ad_length Size of the non-encrypted additional
290 * authenticated data in bytes.
291 * \param plaintext_length Size of the plaintext to encrypt in bytes.
292 *
293 * \retval #PSA_SUCCESS
294 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100295 * \retval #PSA_ERROR_INVALID_ARGUMENT
296 * At least one of the lengths is not acceptable for the chosen
297 * algorithm.
Paul Elliottb91f3312021-05-19 12:30:15 +0100298 * \retval #PSA_ERROR_NOT_SUPPORTED
299 * Algorithm previously set is not supported in this configuration of
300 * the library.
Paul Elliottadb8b162021-04-20 16:06:57 +0100301 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100302psa_status_t mbedtls_psa_aead_set_lengths(
303 mbedtls_psa_aead_operation_t *operation,
304 size_t ad_length,
305 size_t plaintext_length );
Paul Elliottadb8b162021-04-20 16:06:57 +0100306
307/** Pass additional data to an active AEAD operation.
308 *
309 * \note The signature of this function is that of a PSA driver
310 * aead_update_ad entry point. This function behaves as an aead_update_ad
311 * entry point as defined in the PSA driver interface specification for
312 * transparent drivers.
313 *
314 * Additional data is authenticated, but not encrypted.
315 *
Paul Elliott4148a682021-05-14 17:26:56 +0100316 * The PSA core can call this function multiple times to pass successive
317 * fragments of the additional data. It will not call this function after
318 * passing data to encrypt or decrypt with mbedtls_psa_aead_update().
Paul Elliottadb8b162021-04-20 16:06:57 +0100319 *
Paul Elliott498d3502021-05-17 18:16:20 +0100320 * Before calling this function, the PSA core will:
Paul Elliott4148a682021-05-14 17:26:56 +0100321 * 1. Call either mbedtls_psa_aead_encrypt_setup() or
322 * mbedtls_psa_aead_decrypt_setup().
323 * 2. Set the nonce with mbedtls_psa_aead_set_nonce().
Paul Elliottadb8b162021-04-20 16:06:57 +0100324 *
Paul Elliott4148a682021-05-14 17:26:56 +0100325 * If this function returns an error status, the PSA core will call
326 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100327 *
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100328 * \warning When decrypting, until mbedtls_psa_aead_verify() has returned
329 * #PSA_SUCCESS, there is no guarantee that the input is valid.
330 * Therefore, until you have called mbedtls_psa_aead_verify() and it
331 * has returned #PSA_SUCCESS, treat the input as untrusted and prepare
332 * to undo any action that depends on the input if
333 * mbedtls_psa_aead_verify() returns an error status.
Paul Elliottadb8b162021-04-20 16:06:57 +0100334 *
Paul Elliottadb8b162021-04-20 16:06:57 +0100335 *
336 * \param[in,out] operation Active AEAD operation.
337 * \param[in] input Buffer containing the fragment of
338 * additional data.
339 * \param input_length Size of the \p input buffer in bytes.
340 *
341 * \retval #PSA_SUCCESS
342 * Success.
Paul Elliottb91f3312021-05-19 12:30:15 +0100343 * \retval #PSA_ERROR_NOT_SUPPORTED
344 * Algorithm previously set is not supported in this configuration of
345 * the library.
Paul Elliottadb8b162021-04-20 16:06:57 +0100346 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100347psa_status_t mbedtls_psa_aead_update_ad(
348 mbedtls_psa_aead_operation_t *operation,
349 const uint8_t *input,
350 size_t input_length );
Paul Elliottadb8b162021-04-20 16:06:57 +0100351
352/** Encrypt or decrypt a message fragment in an active AEAD operation.
353 *
354 * \note The signature of this function is that of a PSA driver
355 * aead_update entry point. This function behaves as an aead_update entry
356 * point as defined in the PSA driver interface specification for
357 * transparent drivers.
358 *
Paul Elliott4148a682021-05-14 17:26:56 +0100359 * Before calling this function, the PSA core will:
360 * 1. Call either mbedtls_psa_aead_encrypt_setup() or
361 * mbedtls_psa_aead_decrypt_setup(). The choice of setup function
362 * determines whether this function encrypts or decrypts its input.
363 * 2. Set the nonce with mbedtls_psa_aead_set_nonce().
364 * 3. Call mbedtls_psa_aead_update_ad() to pass all the additional data.
Paul Elliottadb8b162021-04-20 16:06:57 +0100365 *
Paul Elliott4148a682021-05-14 17:26:56 +0100366 * If this function returns an error status, the PSA core will call
367 * mbedtls_psa_aead_abort().
Paul Elliottadb8b162021-04-20 16:06:57 +0100368 *
369 * This function does not require the input to be aligned to any
370 * particular block boundary. If the implementation can only process
371 * a whole block at a time, it must consume all the input provided, but
372 * it may delay the end of the corresponding output until a subsequent
373 * call to mbedtls_psa_aead_update(), mbedtls_psa_aead_finish() or
374 * mbedtls_psa_aead_verify() provides sufficient input. The amount of data that
375 * can be delayed in this way is bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE.
376 *
Paul Elliottadb8b162021-04-20 16:06:57 +0100377 * \param[in,out] operation Active AEAD operation.
378 * \param[in] input Buffer containing the message fragment to
379 * encrypt or decrypt.
380 * \param input_length Size of the \p input buffer in bytes.
381 * \param[out] output Buffer where the output is to be written.
382 * \param output_size Size of the \p output buffer in bytes.
Paul Elliott9622c9a2021-05-17 17:30:52 +0100383 * This must be appropriate for the selected
384 * algorithm and key:
385 * - A sufficient output size is
386 * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type,
387 * \c alg, \p input_length) where
388 * \c key_type is the type of key and \c alg is
389 * the algorithm that were used to set up the
390 * operation.
391 * - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p
392 * input_length) evaluates to the maximum
393 * output size of any supported AEAD
394 * algorithm.
Paul Elliottadb8b162021-04-20 16:06:57 +0100395 * \param[out] output_length On success, the number of bytes
396 * that make up the returned output.
397 *
398 * \retval #PSA_SUCCESS
399 * Success.
Paul Elliotta8940ed2021-06-24 16:57:52 +0100400 *
Paul Elliottadb8b162021-04-20 16:06:57 +0100401 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
402 * The size of the \p output buffer is too small.
Paul Elliott9622c9a2021-05-17 17:30:52 +0100403 * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or
404 * #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to
405 * determine the required buffer size.
Paul Elliottadb8b162021-04-20 16:06:57 +0100406 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100407psa_status_t mbedtls_psa_aead_update(
408 mbedtls_psa_aead_operation_t *operation,
409 const uint8_t *input,
410 size_t input_length,
411 uint8_t *output,
412 size_t output_size,
413 size_t *output_length );
Paul Elliottadb8b162021-04-20 16:06:57 +0100414
415/** Finish encrypting a message in an AEAD operation.
416 *
417 * \note The signature of this function is that of a PSA driver
418 * aead_finish entry point. This function behaves as an aead_finish entry
419 * point as defined in the PSA driver interface specification for
420 * transparent drivers.
421 *
Paul Elliott4148a682021-05-14 17:26:56 +0100422 * The operation must have been set up by the PSA core with
423 * mbedtls_psa_aead_encrypt_setup().
Paul Elliottadb8b162021-04-20 16:06:57 +0100424 *
425 * This function finishes the authentication of the additional data
426 * formed by concatenating the inputs passed to preceding calls to
427 * mbedtls_psa_aead_update_ad() with the plaintext formed by concatenating the
428 * inputs passed to preceding calls to mbedtls_psa_aead_update().
429 *
430 * This function has two output buffers:
431 * - \p ciphertext contains trailing ciphertext that was buffered from
Paul Elliott498d3502021-05-17 18:16:20 +0100432 * preceding calls to mbedtls_psa_aead_update().
Paul Elliott4148a682021-05-14 17:26:56 +0100433 * - \p tag contains the authentication tag.
Paul Elliottadb8b162021-04-20 16:06:57 +0100434 *
Paul Elliott4148a682021-05-14 17:26:56 +0100435 * Whether or not this function returns successfuly, the PSA core subsequently
436 * calls mbedtls_psa_aead_abort() to deactivate the operation.
Paul Elliottadb8b162021-04-20 16:06:57 +0100437 *
438 * \param[in,out] operation Active AEAD operation.
439 * \param[out] ciphertext Buffer where the last part of the ciphertext
440 * is to be written.
441 * \param ciphertext_size Size of the \p ciphertext buffer in bytes.
Paul Elliott9622c9a2021-05-17 17:30:52 +0100442 * This must be appropriate for the selected
443 * algorithm and key:
444 * - A sufficient output size is
445 * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type,
446 * \c alg) where \c key_type is the type of key
447 * and \c alg is the algorithm that were used to
448 * set up the operation.
449 * - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to
450 * the maximum output size of any supported AEAD
451 * algorithm.
Paul Elliottadb8b162021-04-20 16:06:57 +0100452 * \param[out] ciphertext_length On success, the number of bytes of
453 * returned ciphertext.
454 * \param[out] tag Buffer where the authentication tag is
455 * to be written.
456 * \param tag_size Size of the \p tag buffer in bytes.
Paul Elliott4148a682021-05-14 17:26:56 +0100457 * This must be appropriate for the selected
458 * algorithm and key:
459 * - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c
460 * key_type, \c key_bits, \c alg) where
461 * \c key_type and \c key_bits are the type and
Paul Elliott498d3502021-05-17 18:16:20 +0100462 * bit-size of the key, and \c alg are the
Paul Elliott4148a682021-05-14 17:26:56 +0100463 * algorithm that were used in the call to
Paul Elliott498d3502021-05-17 18:16:20 +0100464 * mbedtls_psa_aead_encrypt_setup().
Paul Elliott4148a682021-05-14 17:26:56 +0100465 * - #PSA_AEAD_TAG_MAX_SIZE evaluates to the
466 * maximum tag size of any supported AEAD
467 * algorithm.
Paul Elliottadb8b162021-04-20 16:06:57 +0100468 * \param[out] tag_length On success, the number of bytes
469 * that make up the returned tag.
470 *
471 * \retval #PSA_SUCCESS
472 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100473 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
Paul Elliotted68d742021-06-24 20:37:32 +0100474 * The size of the \p tag buffer is too small.
475 * #PSA_AEAD_TAG_LENGTH(\c key_type, key_bits, \c alg) or
476 * #PSA_AEAD_TAG_MAX_SIZE can be used to determine the required \p tag
477 * buffer size.
Paul Elliottadb8b162021-04-20 16:06:57 +0100478 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100479psa_status_t mbedtls_psa_aead_finish(
480 mbedtls_psa_aead_operation_t *operation,
481 uint8_t *ciphertext,
482 size_t ciphertext_size,
483 size_t *ciphertext_length,
484 uint8_t *tag,
485 size_t tag_size,
486 size_t *tag_length );
Paul Elliottadb8b162021-04-20 16:06:57 +0100487
Paul Elliottadb8b162021-04-20 16:06:57 +0100488/** Abort an AEAD operation.
489 *
490 * \note The signature of this function is that of a PSA driver
491 * aead_abort entry point. This function behaves as an aead_abort entry
492 * point as defined in the PSA driver interface specification for
493 * transparent drivers.
494 *
495 * Aborting an operation frees all associated resources except for the
496 * \p operation structure itself. Once aborted, the operation object
Paul Elliott4148a682021-05-14 17:26:56 +0100497 * can be reused for another operation by the PSA core by it calling
Paul Elliottadb8b162021-04-20 16:06:57 +0100498 * mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup() again.
499 *
Paul Elliott4148a682021-05-14 17:26:56 +0100500 * The PSA core may call this function any time after the operation object has
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100501 * been initialized as described in #mbedtls_psa_aead_operation_t.
Paul Elliottadb8b162021-04-20 16:06:57 +0100502 *
503 * In particular, calling mbedtls_psa_aead_abort() after the operation has been
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100504 * terminated by a call to mbedtls_psa_aead_abort(), mbedtls_psa_aead_finish()
505 * or mbedtls_psa_aead_verify() is safe and has no effect.
Paul Elliottadb8b162021-04-20 16:06:57 +0100506 *
507 * \param[in,out] operation Initialized AEAD operation.
508 *
509 * \retval #PSA_SUCCESS
Paul Elliottb91f3312021-05-19 12:30:15 +0100510 * Success.
Paul Elliottadb8b162021-04-20 16:06:57 +0100511 */
Paul Elliottbb8bf662021-05-19 17:29:42 +0100512psa_status_t mbedtls_psa_aead_abort(
513 mbedtls_psa_aead_operation_t *operation );
Paul Elliottadb8b162021-04-20 16:06:57 +0100514
Ronald Cron7ceee8d2021-03-17 16:55:43 +0100515#endif /* PSA_CRYPTO_AEAD */