1*b0563631STom Van Eyck /* 2*b0563631STom Van Eyck * PSA AEAD driver entry points 3*b0563631STom Van Eyck */ 4*b0563631STom Van Eyck /* 5*b0563631STom Van Eyck * Copyright The Mbed TLS Contributors 6*b0563631STom Van Eyck * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 7*b0563631STom Van Eyck */ 8*b0563631STom Van Eyck 9*b0563631STom Van Eyck #ifndef PSA_CRYPTO_AEAD_H 10*b0563631STom Van Eyck #define PSA_CRYPTO_AEAD_H 11*b0563631STom Van Eyck 12*b0563631STom Van Eyck #include <psa/crypto.h> 13*b0563631STom Van Eyck 14*b0563631STom Van Eyck /** 15*b0563631STom Van Eyck * \brief Process an authenticated encryption operation. 16*b0563631STom Van Eyck * 17*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 18*b0563631STom Van Eyck * aead_encrypt entry point. This function behaves as an aead_encrypt 19*b0563631STom Van Eyck * entry point as defined in the PSA driver interface specification for 20*b0563631STom Van Eyck * transparent drivers. 21*b0563631STom Van Eyck * 22*b0563631STom Van Eyck * \param[in] attributes The attributes of the key to use for the 23*b0563631STom Van Eyck * operation. 24*b0563631STom Van Eyck * \param[in] key_buffer The buffer containing the key context. 25*b0563631STom Van Eyck * \param key_buffer_size Size of the \p key_buffer buffer in bytes. 26*b0563631STom Van Eyck * \param alg The AEAD algorithm to compute. 27*b0563631STom Van Eyck * \param[in] nonce Nonce or IV to use. 28*b0563631STom Van Eyck * \param nonce_length Size of the nonce buffer in bytes. This must 29*b0563631STom Van Eyck * be appropriate for the selected algorithm. 30*b0563631STom Van Eyck * The default nonce size is 31*b0563631STom Van Eyck * PSA_AEAD_NONCE_LENGTH(key_type, alg) where 32*b0563631STom Van Eyck * key_type is the type of key. 33*b0563631STom Van Eyck * \param[in] additional_data Additional data that will be authenticated 34*b0563631STom Van Eyck * but not encrypted. 35*b0563631STom Van Eyck * \param additional_data_length Size of additional_data in bytes. 36*b0563631STom Van Eyck * \param[in] plaintext Data that will be authenticated and encrypted. 37*b0563631STom Van Eyck * \param plaintext_length Size of plaintext in bytes. 38*b0563631STom Van Eyck * \param[out] ciphertext Output buffer for the authenticated and 39*b0563631STom Van Eyck * encrypted data. The additional data is not 40*b0563631STom Van Eyck * part of this output. For algorithms where the 41*b0563631STom Van Eyck * encrypted data and the authentication tag are 42*b0563631STom Van Eyck * defined as separate outputs, the 43*b0563631STom Van Eyck * authentication tag is appended to the 44*b0563631STom Van Eyck * encrypted data. 45*b0563631STom Van Eyck * \param ciphertext_size Size of the ciphertext buffer in bytes. This 46*b0563631STom Van Eyck * must be appropriate for the selected algorithm 47*b0563631STom Van Eyck * and key: 48*b0563631STom Van Eyck * - A sufficient output size is 49*b0563631STom Van Eyck * PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, 50*b0563631STom Van Eyck * plaintext_length) where key_type is the type 51*b0563631STom Van Eyck * of key. 52*b0563631STom Van Eyck * - PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE( 53*b0563631STom Van Eyck * plaintext_length) evaluates to the maximum 54*b0563631STom Van Eyck * ciphertext size of any supported AEAD 55*b0563631STom Van Eyck * encryption. 56*b0563631STom Van Eyck * \param[out] ciphertext_length On success, the size of the output in the 57*b0563631STom Van Eyck * ciphertext buffer. 58*b0563631STom Van Eyck * 59*b0563631STom Van Eyck * \retval #PSA_SUCCESS Success. 60*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 61*b0563631STom Van Eyck * \p alg is not supported. 62*b0563631STom Van Eyck * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription 63*b0563631STom Van Eyck * \retval #PSA_ERROR_BUFFER_TOO_SMALL 64*b0563631STom Van Eyck * ciphertext_size is too small. 65*b0563631STom Van Eyck * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription 66*b0563631STom Van Eyck */ 67*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_encrypt( 68*b0563631STom Van Eyck const psa_key_attributes_t *attributes, 69*b0563631STom Van Eyck const uint8_t *key_buffer, size_t key_buffer_size, 70*b0563631STom Van Eyck psa_algorithm_t alg, 71*b0563631STom Van Eyck const uint8_t *nonce, size_t nonce_length, 72*b0563631STom Van Eyck const uint8_t *additional_data, size_t additional_data_length, 73*b0563631STom Van Eyck const uint8_t *plaintext, size_t plaintext_length, 74*b0563631STom Van Eyck uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length); 75*b0563631STom Van Eyck 76*b0563631STom Van Eyck /** 77*b0563631STom Van Eyck * \brief Process an authenticated decryption operation. 78*b0563631STom Van Eyck * 79*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 80*b0563631STom Van Eyck * aead_decrypt entry point. This function behaves as an aead_decrypt 81*b0563631STom Van Eyck * entry point as defined in the PSA driver interface specification for 82*b0563631STom Van Eyck * transparent drivers. 83*b0563631STom Van Eyck * 84*b0563631STom Van Eyck * \param[in] attributes The attributes of the key to use for the 85*b0563631STom Van Eyck * operation. 86*b0563631STom Van Eyck * \param[in] key_buffer The buffer containing the key context. 87*b0563631STom Van Eyck * \param key_buffer_size Size of the \p key_buffer buffer in bytes. 88*b0563631STom Van Eyck * \param alg The AEAD algorithm to compute. 89*b0563631STom Van Eyck * \param[in] nonce Nonce or IV to use. 90*b0563631STom Van Eyck * \param nonce_length Size of the nonce buffer in bytes. This must 91*b0563631STom Van Eyck * be appropriate for the selected algorithm. 92*b0563631STom Van Eyck * The default nonce size is 93*b0563631STom Van Eyck * PSA_AEAD_NONCE_LENGTH(key_type, alg) where 94*b0563631STom Van Eyck * key_type is the type of key. 95*b0563631STom Van Eyck * \param[in] additional_data Additional data that has been authenticated 96*b0563631STom Van Eyck * but not encrypted. 97*b0563631STom Van Eyck * \param additional_data_length Size of additional_data in bytes. 98*b0563631STom Van Eyck * \param[in] ciphertext Data that has been authenticated and 99*b0563631STom Van Eyck * encrypted. For algorithms where the encrypted 100*b0563631STom Van Eyck * data and the authentication tag are defined 101*b0563631STom Van Eyck * as separate inputs, the buffer contains 102*b0563631STom Van Eyck * encrypted data followed by the authentication 103*b0563631STom Van Eyck * tag. 104*b0563631STom Van Eyck * \param ciphertext_length Size of ciphertext in bytes. 105*b0563631STom Van Eyck * \param[out] plaintext Output buffer for the decrypted data. 106*b0563631STom Van Eyck * \param plaintext_size Size of the plaintext buffer in bytes. This 107*b0563631STom Van Eyck * must be appropriate for the selected algorithm 108*b0563631STom Van Eyck * and key: 109*b0563631STom Van Eyck * - A sufficient output size is 110*b0563631STom Van Eyck * PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, 111*b0563631STom Van Eyck * ciphertext_length) where key_type is the 112*b0563631STom Van Eyck * type of key. 113*b0563631STom Van Eyck * - PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE( 114*b0563631STom Van Eyck * ciphertext_length) evaluates to the maximum 115*b0563631STom Van Eyck * plaintext size of any supported AEAD 116*b0563631STom Van Eyck * decryption. 117*b0563631STom Van Eyck * \param[out] plaintext_length On success, the size of the output in the 118*b0563631STom Van Eyck * plaintext buffer. 119*b0563631STom Van Eyck * 120*b0563631STom Van Eyck * \retval #PSA_SUCCESS Success. 121*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_SIGNATURE 122*b0563631STom Van Eyck * The cipher is not authentic. 123*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 124*b0563631STom Van Eyck * \p alg is not supported. 125*b0563631STom Van Eyck * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription 126*b0563631STom Van Eyck * \retval #PSA_ERROR_BUFFER_TOO_SMALL 127*b0563631STom Van Eyck * plaintext_size is too small. 128*b0563631STom Van Eyck * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription 129*b0563631STom Van Eyck */ 130*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_decrypt( 131*b0563631STom Van Eyck const psa_key_attributes_t *attributes, 132*b0563631STom Van Eyck const uint8_t *key_buffer, size_t key_buffer_size, 133*b0563631STom Van Eyck psa_algorithm_t alg, 134*b0563631STom Van Eyck const uint8_t *nonce, size_t nonce_length, 135*b0563631STom Van Eyck const uint8_t *additional_data, size_t additional_data_length, 136*b0563631STom Van Eyck const uint8_t *ciphertext, size_t ciphertext_length, 137*b0563631STom Van Eyck uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length); 138*b0563631STom Van Eyck 139*b0563631STom Van Eyck /** Set the key for a multipart authenticated encryption operation. 140*b0563631STom Van Eyck * 141*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 142*b0563631STom Van Eyck * aead_encrypt_setup entry point. This function behaves as an 143*b0563631STom Van Eyck * aead_encrypt_setup entry point as defined in the PSA driver interface 144*b0563631STom Van Eyck * specification for transparent drivers. 145*b0563631STom Van Eyck * 146*b0563631STom Van Eyck * If an error occurs at any step after a call to 147*b0563631STom Van Eyck * mbedtls_psa_aead_encrypt_setup(), the operation is reset by the PSA core by a 148*b0563631STom Van Eyck * call to mbedtls_psa_aead_abort(). The PSA core may call 149*b0563631STom Van Eyck * mbedtls_psa_aead_abort() at any time after the operation has been 150*b0563631STom Van Eyck * initialized, and is required to when the operation is no longer needed. 151*b0563631STom Van Eyck * 152*b0563631STom Van Eyck * \param[in,out] operation The operation object to set up. It must have 153*b0563631STom Van Eyck * been initialized as per the documentation for 154*b0563631STom Van Eyck * #mbedtls_psa_aead_operation_t and not yet in 155*b0563631STom Van Eyck * use. 156*b0563631STom Van Eyck * \param[in] attributes The attributes of the key to use for the 157*b0563631STom Van Eyck * operation. 158*b0563631STom Van Eyck * \param[in] key_buffer The buffer containing the key context. 159*b0563631STom Van Eyck * \param key_buffer_size Size of the \p key_buffer buffer in bytes. 160*b0563631STom Van Eyck It must be consistent with the size in bits 161*b0563631STom Van Eyck recorded in \p attributes. 162*b0563631STom Van Eyck * \param alg The AEAD algorithm to compute 163*b0563631STom Van Eyck * (\c PSA_ALG_XXX value such that 164*b0563631STom Van Eyck * #PSA_ALG_IS_AEAD(\p alg) is true). 165*b0563631STom Van Eyck * 166*b0563631STom Van Eyck * \retval #PSA_SUCCESS 167*b0563631STom Van Eyck * Success. 168*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT 169*b0563631STom Van Eyck * An invalid block length was supplied. 170*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 171*b0563631STom Van Eyck * \p alg is not supported. 172*b0563631STom Van Eyck * \retval #PSA_ERROR_INSUFFICIENT_MEMORY 173*b0563631STom Van Eyck * Failed to allocate memory for key material 174*b0563631STom Van Eyck */ 175*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_encrypt_setup( 176*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 177*b0563631STom Van Eyck const psa_key_attributes_t *attributes, 178*b0563631STom Van Eyck const uint8_t *key_buffer, 179*b0563631STom Van Eyck size_t key_buffer_size, 180*b0563631STom Van Eyck psa_algorithm_t alg); 181*b0563631STom Van Eyck 182*b0563631STom Van Eyck /** Set the key for a multipart authenticated decryption operation. 183*b0563631STom Van Eyck * 184*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 185*b0563631STom Van Eyck * aead_decrypt_setup entry point. This function behaves as an 186*b0563631STom Van Eyck * aead_decrypt_setup entry point as defined in the PSA driver interface 187*b0563631STom Van Eyck * specification for transparent drivers. 188*b0563631STom Van Eyck * 189*b0563631STom Van Eyck * If an error occurs at any step after a call to 190*b0563631STom Van Eyck * mbedtls_psa_aead_decrypt_setup(), the PSA core resets the operation by a 191*b0563631STom Van Eyck * call to mbedtls_psa_aead_abort(). The PSA core may call 192*b0563631STom Van Eyck * mbedtls_psa_aead_abort() at any time after the operation has been 193*b0563631STom Van Eyck * initialized, and is required to when the operation is no longer needed. 194*b0563631STom Van Eyck * 195*b0563631STom Van Eyck * \param[in,out] operation The operation object to set up. It must have 196*b0563631STom Van Eyck * been initialized as per the documentation for 197*b0563631STom Van Eyck * #mbedtls_psa_aead_operation_t and not yet in 198*b0563631STom Van Eyck * use. 199*b0563631STom Van Eyck * \param[in] attributes The attributes of the key to use for the 200*b0563631STom Van Eyck * operation. 201*b0563631STom Van Eyck * \param[in] key_buffer The buffer containing the key context. 202*b0563631STom Van Eyck * \param key_buffer_size Size of the \p key_buffer buffer in bytes. 203*b0563631STom Van Eyck It must be consistent with the size in bits 204*b0563631STom Van Eyck recorded in \p attributes. 205*b0563631STom Van Eyck * \param alg The AEAD algorithm to compute 206*b0563631STom Van Eyck * (\c PSA_ALG_XXX value such that 207*b0563631STom Van Eyck * #PSA_ALG_IS_AEAD(\p alg) is true). 208*b0563631STom Van Eyck * 209*b0563631STom Van Eyck * \retval #PSA_SUCCESS 210*b0563631STom Van Eyck * Success. 211*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT 212*b0563631STom Van Eyck * An invalid block length was supplied. 213*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 214*b0563631STom Van Eyck * \p alg is not supported. 215*b0563631STom Van Eyck * \retval #PSA_ERROR_INSUFFICIENT_MEMORY 216*b0563631STom Van Eyck * Failed to allocate memory for key material 217*b0563631STom Van Eyck */ 218*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_decrypt_setup( 219*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 220*b0563631STom Van Eyck const psa_key_attributes_t *attributes, 221*b0563631STom Van Eyck const uint8_t *key_buffer, 222*b0563631STom Van Eyck size_t key_buffer_size, 223*b0563631STom Van Eyck psa_algorithm_t alg); 224*b0563631STom Van Eyck 225*b0563631STom Van Eyck /** Set the nonce for an authenticated encryption or decryption operation. 226*b0563631STom Van Eyck * 227*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver aead_set_nonce 228*b0563631STom Van Eyck * entry point. This function behaves as an aead_set_nonce entry point as 229*b0563631STom Van Eyck * defined in the PSA driver interface specification for transparent 230*b0563631STom Van Eyck * drivers. 231*b0563631STom Van Eyck * 232*b0563631STom Van Eyck * This function sets the nonce for the authenticated 233*b0563631STom Van Eyck * encryption or decryption operation. 234*b0563631STom Van Eyck * 235*b0563631STom Van Eyck * The PSA core calls mbedtls_psa_aead_encrypt_setup() or 236*b0563631STom Van Eyck * mbedtls_psa_aead_decrypt_setup() before calling this function. 237*b0563631STom Van Eyck * 238*b0563631STom Van Eyck * If this function returns an error status, the PSA core will call 239*b0563631STom Van Eyck * mbedtls_psa_aead_abort(). 240*b0563631STom Van Eyck * 241*b0563631STom Van Eyck * \param[in,out] operation Active AEAD operation. 242*b0563631STom Van Eyck * \param[in] nonce Buffer containing the nonce to use. 243*b0563631STom Van Eyck * \param nonce_length Size of the nonce in bytes. 244*b0563631STom Van Eyck * 245*b0563631STom Van Eyck * \retval #PSA_SUCCESS 246*b0563631STom Van Eyck * Success. 247*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT 248*b0563631STom Van Eyck * The size of \p nonce is not acceptable for the chosen algorithm. 249*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 250*b0563631STom Van Eyck * Algorithm previously set is not supported in this configuration of 251*b0563631STom Van Eyck * the library. 252*b0563631STom Van Eyck */ 253*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_set_nonce( 254*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 255*b0563631STom Van Eyck const uint8_t *nonce, 256*b0563631STom Van Eyck size_t nonce_length); 257*b0563631STom Van Eyck 258*b0563631STom Van Eyck /** Declare the lengths of the message and additional data for AEAD. 259*b0563631STom Van Eyck * 260*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver aead_set_lengths 261*b0563631STom Van Eyck * entry point. This function behaves as an aead_set_lengths entry point 262*b0563631STom Van Eyck * as defined in the PSA driver interface specification for transparent 263*b0563631STom Van Eyck * drivers. 264*b0563631STom Van Eyck * 265*b0563631STom Van Eyck * The PSA core calls this function before calling mbedtls_psa_aead_update_ad() 266*b0563631STom Van Eyck * or mbedtls_psa_aead_update() if the algorithm for the operation requires it. 267*b0563631STom Van Eyck * If the algorithm does not require it, calling this function is optional, but 268*b0563631STom Van Eyck * if this function is called then the implementation must enforce the lengths. 269*b0563631STom Van Eyck * 270*b0563631STom Van Eyck * The PSA core may call this function before or after setting the nonce with 271*b0563631STom Van Eyck * mbedtls_psa_aead_set_nonce(). 272*b0563631STom Van Eyck * 273*b0563631STom Van Eyck * - For #PSA_ALG_CCM, calling this function is required. 274*b0563631STom Van Eyck * - For the other AEAD algorithms defined in this specification, calling 275*b0563631STom Van Eyck * this function is not required. 276*b0563631STom Van Eyck * 277*b0563631STom Van Eyck * If this function returns an error status, the PSA core calls 278*b0563631STom Van Eyck * mbedtls_psa_aead_abort(). 279*b0563631STom Van Eyck * 280*b0563631STom Van Eyck * \param[in,out] operation Active AEAD operation. 281*b0563631STom Van Eyck * \param ad_length Size of the non-encrypted additional 282*b0563631STom Van Eyck * authenticated data in bytes. 283*b0563631STom Van Eyck * \param plaintext_length Size of the plaintext to encrypt in bytes. 284*b0563631STom Van Eyck * 285*b0563631STom Van Eyck * \retval #PSA_SUCCESS 286*b0563631STom Van Eyck * Success. 287*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT 288*b0563631STom Van Eyck * At least one of the lengths is not acceptable for the chosen 289*b0563631STom Van Eyck * algorithm. 290*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 291*b0563631STom Van Eyck * Algorithm previously set is not supported in this configuration of 292*b0563631STom Van Eyck * the library. 293*b0563631STom Van Eyck */ 294*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_set_lengths( 295*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 296*b0563631STom Van Eyck size_t ad_length, 297*b0563631STom Van Eyck size_t plaintext_length); 298*b0563631STom Van Eyck 299*b0563631STom Van Eyck /** Pass additional data to an active AEAD operation. 300*b0563631STom Van Eyck * 301*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 302*b0563631STom Van Eyck * aead_update_ad entry point. This function behaves as an aead_update_ad 303*b0563631STom Van Eyck * entry point as defined in the PSA driver interface specification for 304*b0563631STom Van Eyck * transparent drivers. 305*b0563631STom Van Eyck * 306*b0563631STom Van Eyck * Additional data is authenticated, but not encrypted. 307*b0563631STom Van Eyck * 308*b0563631STom Van Eyck * The PSA core can call this function multiple times to pass successive 309*b0563631STom Van Eyck * fragments of the additional data. It will not call this function after 310*b0563631STom Van Eyck * passing data to encrypt or decrypt with mbedtls_psa_aead_update(). 311*b0563631STom Van Eyck * 312*b0563631STom Van Eyck * Before calling this function, the PSA core will: 313*b0563631STom Van Eyck * 1. Call either mbedtls_psa_aead_encrypt_setup() or 314*b0563631STom Van Eyck * mbedtls_psa_aead_decrypt_setup(). 315*b0563631STom Van Eyck * 2. Set the nonce with mbedtls_psa_aead_set_nonce(). 316*b0563631STom Van Eyck * 317*b0563631STom Van Eyck * If this function returns an error status, the PSA core will call 318*b0563631STom Van Eyck * mbedtls_psa_aead_abort(). 319*b0563631STom Van Eyck * 320*b0563631STom Van Eyck * \param[in,out] operation Active AEAD operation. 321*b0563631STom Van Eyck * \param[in] input Buffer containing the fragment of 322*b0563631STom Van Eyck * additional data. 323*b0563631STom Van Eyck * \param input_length Size of the \p input buffer in bytes. 324*b0563631STom Van Eyck * 325*b0563631STom Van Eyck * \retval #PSA_SUCCESS 326*b0563631STom Van Eyck * Success. 327*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED 328*b0563631STom Van Eyck * Algorithm previously set is not supported in this configuration of 329*b0563631STom Van Eyck * the library. 330*b0563631STom Van Eyck */ 331*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_update_ad( 332*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 333*b0563631STom Van Eyck const uint8_t *input, 334*b0563631STom Van Eyck size_t input_length); 335*b0563631STom Van Eyck 336*b0563631STom Van Eyck /** Encrypt or decrypt a message fragment in an active AEAD operation. 337*b0563631STom Van Eyck * 338*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 339*b0563631STom Van Eyck * aead_update entry point. This function behaves as an aead_update entry 340*b0563631STom Van Eyck * point as defined in the PSA driver interface specification for 341*b0563631STom Van Eyck * transparent drivers. 342*b0563631STom Van Eyck * 343*b0563631STom Van Eyck * Before calling this function, the PSA core will: 344*b0563631STom Van Eyck * 1. Call either mbedtls_psa_aead_encrypt_setup() or 345*b0563631STom Van Eyck * mbedtls_psa_aead_decrypt_setup(). The choice of setup function 346*b0563631STom Van Eyck * determines whether this function encrypts or decrypts its input. 347*b0563631STom Van Eyck * 2. Set the nonce with mbedtls_psa_aead_set_nonce(). 348*b0563631STom Van Eyck * 3. Call mbedtls_psa_aead_update_ad() to pass all the additional data. 349*b0563631STom Van Eyck * 350*b0563631STom Van Eyck * If this function returns an error status, the PSA core will call 351*b0563631STom Van Eyck * mbedtls_psa_aead_abort(). 352*b0563631STom Van Eyck * 353*b0563631STom Van Eyck * This function does not require the input to be aligned to any 354*b0563631STom Van Eyck * particular block boundary. If the implementation can only process 355*b0563631STom Van Eyck * a whole block at a time, it must consume all the input provided, but 356*b0563631STom Van Eyck * it may delay the end of the corresponding output until a subsequent 357*b0563631STom Van Eyck * call to mbedtls_psa_aead_update(), mbedtls_psa_aead_finish() provides 358*b0563631STom Van Eyck * sufficient input. The amount of data that can be delayed in this way is 359*b0563631STom Van Eyck * bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE. 360*b0563631STom Van Eyck * 361*b0563631STom Van Eyck * \param[in,out] operation Active AEAD operation. 362*b0563631STom Van Eyck * \param[in] input Buffer containing the message fragment to 363*b0563631STom Van Eyck * encrypt or decrypt. 364*b0563631STom Van Eyck * \param input_length Size of the \p input buffer in bytes. 365*b0563631STom Van Eyck * \param[out] output Buffer where the output is to be written. 366*b0563631STom Van Eyck * \param output_size Size of the \p output buffer in bytes. 367*b0563631STom Van Eyck * This must be appropriate for the selected 368*b0563631STom Van Eyck * algorithm and key: 369*b0563631STom Van Eyck * - A sufficient output size is 370*b0563631STom Van Eyck * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, 371*b0563631STom Van Eyck * \c alg, \p input_length) where 372*b0563631STom Van Eyck * \c key_type is the type of key and \c alg is 373*b0563631STom Van Eyck * the algorithm that were used to set up the 374*b0563631STom Van Eyck * operation. 375*b0563631STom Van Eyck * - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p 376*b0563631STom Van Eyck * input_length) evaluates to the maximum 377*b0563631STom Van Eyck * output size of any supported AEAD 378*b0563631STom Van Eyck * algorithm. 379*b0563631STom Van Eyck * \param[out] output_length On success, the number of bytes 380*b0563631STom Van Eyck * that make up the returned output. 381*b0563631STom Van Eyck * 382*b0563631STom Van Eyck * \retval #PSA_SUCCESS 383*b0563631STom Van Eyck * Success. 384*b0563631STom Van Eyck * 385*b0563631STom Van Eyck * \retval #PSA_ERROR_BUFFER_TOO_SMALL 386*b0563631STom Van Eyck * The size of the \p output buffer is too small. 387*b0563631STom Van Eyck * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or 388*b0563631STom Van Eyck * #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to 389*b0563631STom Van Eyck * determine the required buffer size. 390*b0563631STom Van Eyck */ 391*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_update( 392*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 393*b0563631STom Van Eyck const uint8_t *input, 394*b0563631STom Van Eyck size_t input_length, 395*b0563631STom Van Eyck uint8_t *output, 396*b0563631STom Van Eyck size_t output_size, 397*b0563631STom Van Eyck size_t *output_length); 398*b0563631STom Van Eyck 399*b0563631STom Van Eyck /** Finish encrypting a message in an AEAD operation. 400*b0563631STom Van Eyck * 401*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 402*b0563631STom Van Eyck * aead_finish entry point. This function behaves as an aead_finish entry 403*b0563631STom Van Eyck * point as defined in the PSA driver interface specification for 404*b0563631STom Van Eyck * transparent drivers. 405*b0563631STom Van Eyck * 406*b0563631STom Van Eyck * The operation must have been set up by the PSA core with 407*b0563631STom Van Eyck * mbedtls_psa_aead_encrypt_setup(). 408*b0563631STom Van Eyck * 409*b0563631STom Van Eyck * This function finishes the authentication of the additional data 410*b0563631STom Van Eyck * formed by concatenating the inputs passed to preceding calls to 411*b0563631STom Van Eyck * mbedtls_psa_aead_update_ad() with the plaintext formed by concatenating the 412*b0563631STom Van Eyck * inputs passed to preceding calls to mbedtls_psa_aead_update(). 413*b0563631STom Van Eyck * 414*b0563631STom Van Eyck * This function has two output buffers: 415*b0563631STom Van Eyck * - \p ciphertext contains trailing ciphertext that was buffered from 416*b0563631STom Van Eyck * preceding calls to mbedtls_psa_aead_update(). 417*b0563631STom Van Eyck * - \p tag contains the authentication tag. 418*b0563631STom Van Eyck * 419*b0563631STom Van Eyck * Whether or not this function returns successfully, the PSA core subsequently 420*b0563631STom Van Eyck * calls mbedtls_psa_aead_abort() to deactivate the operation. 421*b0563631STom Van Eyck * 422*b0563631STom Van Eyck * \param[in,out] operation Active AEAD operation. 423*b0563631STom Van Eyck * \param[out] ciphertext Buffer where the last part of the ciphertext 424*b0563631STom Van Eyck * is to be written. 425*b0563631STom Van Eyck * \param ciphertext_size Size of the \p ciphertext buffer in bytes. 426*b0563631STom Van Eyck * This must be appropriate for the selected 427*b0563631STom Van Eyck * algorithm and key: 428*b0563631STom Van Eyck * - A sufficient output size is 429*b0563631STom Van Eyck * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, 430*b0563631STom Van Eyck * \c alg) where \c key_type is the type of key 431*b0563631STom Van Eyck * and \c alg is the algorithm that were used to 432*b0563631STom Van Eyck * set up the operation. 433*b0563631STom Van Eyck * - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to 434*b0563631STom Van Eyck * the maximum output size of any supported AEAD 435*b0563631STom Van Eyck * algorithm. 436*b0563631STom Van Eyck * \param[out] ciphertext_length On success, the number of bytes of 437*b0563631STom Van Eyck * returned ciphertext. 438*b0563631STom Van Eyck * \param[out] tag Buffer where the authentication tag is 439*b0563631STom Van Eyck * to be written. 440*b0563631STom Van Eyck * \param tag_size Size of the \p tag buffer in bytes. 441*b0563631STom Van Eyck * This must be appropriate for the selected 442*b0563631STom Van Eyck * algorithm and key: 443*b0563631STom Van Eyck * - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c 444*b0563631STom Van Eyck * key_type, \c key_bits, \c alg) where 445*b0563631STom Van Eyck * \c key_type and \c key_bits are the type and 446*b0563631STom Van Eyck * bit-size of the key, and \c alg are the 447*b0563631STom Van Eyck * algorithm that were used in the call to 448*b0563631STom Van Eyck * mbedtls_psa_aead_encrypt_setup(). 449*b0563631STom Van Eyck * - #PSA_AEAD_TAG_MAX_SIZE evaluates to the 450*b0563631STom Van Eyck * maximum tag size of any supported AEAD 451*b0563631STom Van Eyck * algorithm. 452*b0563631STom Van Eyck * \param[out] tag_length On success, the number of bytes 453*b0563631STom Van Eyck * that make up the returned tag. 454*b0563631STom Van Eyck * 455*b0563631STom Van Eyck * \retval #PSA_SUCCESS 456*b0563631STom Van Eyck * Success. 457*b0563631STom Van Eyck * \retval #PSA_ERROR_BUFFER_TOO_SMALL 458*b0563631STom Van Eyck * The size of the \p tag buffer is too small. 459*b0563631STom Van Eyck * #PSA_AEAD_TAG_LENGTH(\c key_type, key_bits, \c alg) or 460*b0563631STom Van Eyck * #PSA_AEAD_TAG_MAX_SIZE can be used to determine the required \p tag 461*b0563631STom Van Eyck * buffer size. 462*b0563631STom Van Eyck */ 463*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_finish( 464*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation, 465*b0563631STom Van Eyck uint8_t *ciphertext, 466*b0563631STom Van Eyck size_t ciphertext_size, 467*b0563631STom Van Eyck size_t *ciphertext_length, 468*b0563631STom Van Eyck uint8_t *tag, 469*b0563631STom Van Eyck size_t tag_size, 470*b0563631STom Van Eyck size_t *tag_length); 471*b0563631STom Van Eyck 472*b0563631STom Van Eyck /** Abort an AEAD operation. 473*b0563631STom Van Eyck * 474*b0563631STom Van Eyck * \note The signature of this function is that of a PSA driver 475*b0563631STom Van Eyck * aead_abort entry point. This function behaves as an aead_abort entry 476*b0563631STom Van Eyck * point as defined in the PSA driver interface specification for 477*b0563631STom Van Eyck * transparent drivers. 478*b0563631STom Van Eyck * 479*b0563631STom Van Eyck * Aborting an operation frees all associated resources except for the 480*b0563631STom Van Eyck * \p operation structure itself. Once aborted, the operation object 481*b0563631STom Van Eyck * can be reused for another operation by the PSA core by it calling 482*b0563631STom Van Eyck * mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup() again. 483*b0563631STom Van Eyck * 484*b0563631STom Van Eyck * The PSA core may call this function any time after the operation object has 485*b0563631STom Van Eyck * been initialized as described in #mbedtls_psa_aead_operation_t. 486*b0563631STom Van Eyck * 487*b0563631STom Van Eyck * In particular, calling mbedtls_psa_aead_abort() after the operation has been 488*b0563631STom Van Eyck * terminated by a call to mbedtls_psa_aead_abort() or 489*b0563631STom Van Eyck * mbedtls_psa_aead_finish() is safe and has no effect. 490*b0563631STom Van Eyck * 491*b0563631STom Van Eyck * \param[in,out] operation Initialized AEAD operation. 492*b0563631STom Van Eyck * 493*b0563631STom Van Eyck * \retval #PSA_SUCCESS 494*b0563631STom Van Eyck * Success. 495*b0563631STom Van Eyck */ 496*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_abort( 497*b0563631STom Van Eyck mbedtls_psa_aead_operation_t *operation); 498*b0563631STom Van Eyck 499*b0563631STom Van Eyck #endif /* PSA_CRYPTO_AEAD_H */ 500