psa_aead_encrypt() function
Process an authenticated encryption operation.
Syntax
psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key,
psa_algorithm_t alg,
const uint8_t *nonce,
size_t nonce_length,
const uint8_t *additional_data,
size_t additional_data_length,
const uint8_t *plaintext,
size_t plaintext_length,
uint8_t *ciphertext,
size_t ciphertext_size,
size_t *ciphertext_length);
Arguments
key
Identifier of the key to use for the operation. It must allow the usage #PSA_KEY_USAGE_ENCRYPT.
alg
The AEAD algorithm to compute (\c PSA_ALG_XXX value such that #PSA_ALG_IS_AEAD(\p alg) is true).
nonce_length
Size of the \p nonce buffer in bytes.
additional_data
Additional data that will be authenticated but not encrypted.
additional_data_length
Size of \p additional_data in bytes.
plaintext
Data that will be authenticated and encrypted.
plaintext_length
Size of \p plaintext in bytes.
ciphertext
Output buffer for the authenticated and encrypted data. The additional data is not part of this output. For algorithms where the encrypted data and the authentication tag are defined as separate outputs, the authentication tag is appended to the encrypted data.
ciphertext_size
Size of the \p ciphertext buffer in bytes. This must be appropriate for the selected algorithm and key: - A sufficient output size is #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type, \p alg, \p plaintext_length) where \c key_type is the type of \p key. - #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length) evaluates to the maximum ciphertext size of any supported AEAD encryption.
ciphertext_length
On success, the size of the output in the \p ciphertext buffer.
Return value
#PSA_SUCCESS Success. #PSA_ERROR_INVALID_HANDLE \emptydescription #PSA_ERROR_NOT_PERMITTED \emptydescription #PSA_ERROR_INVALID_ARGUMENT \p key is not compatible with \p alg. #PSA_ERROR_NOT_SUPPORTED \p alg is not supported or is not an AEAD algorithm. #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription #PSA_ERROR_BUFFER_TOO_SMALL \p ciphertext_size is too small. #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type, \p alg, \p plaintext_length) or #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length) can be used to determine the required buffer size. #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription #PSA_ERROR_HARDWARE_FAILURE \emptydescription #PSA_ERROR_CORRUPTION_DETECTED \emptydescription #PSA_ERROR_STORAGE_FAILURE \emptydescription #PSA_ERROR_BAD_STATE The library has not been previously initialized by psa_crypto_init(). It is implementation-dependent whether a failure to initialize results in this error code.