123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650 |
- /*
- * PSA AEAD entry points
- */
- /*
- * Copyright The Mbed TLS Contributors
- * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
- */
- #include "common.h"
- #if defined(MBEDTLS_PSA_CRYPTO_C)
- #include "psa_crypto_aead.h"
- #include "psa_crypto_core.h"
- #include "psa_crypto_cipher.h"
- #include <string.h>
- #include "mbedtls/platform.h"
- #include "mbedtls/ccm.h"
- #include "mbedtls/chachapoly.h"
- #include "mbedtls/cipher.h"
- #include "mbedtls/gcm.h"
- #include "mbedtls/error.h"
- static psa_status_t psa_aead_setup(
- mbedtls_psa_aead_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- mbedtls_cipher_id_t cipher_id;
- mbedtls_cipher_mode_t mode;
- size_t key_bits = attributes->bits;
- (void) key_buffer_size;
- status = mbedtls_cipher_values_from_psa(alg, attributes->type,
- &key_bits, &mode, &cipher_id);
- if (status != PSA_SUCCESS) {
- return status;
- }
- switch (PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 0)) {
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 0):
- operation->alg = PSA_ALG_CCM;
- /* CCM allows the following tag lengths: 4, 6, 8, 10, 12, 14, 16.
- * The call to mbedtls_ccm_encrypt_and_tag or
- * mbedtls_ccm_auth_decrypt will validate the tag length. */
- if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(attributes->type) != 16) {
- return PSA_ERROR_INVALID_ARGUMENT;
- }
- mbedtls_ccm_init(&operation->ctx.ccm);
- status = mbedtls_to_psa_error(
- mbedtls_ccm_setkey(&operation->ctx.ccm, cipher_id,
- key_buffer, (unsigned int) key_bits));
- if (status != PSA_SUCCESS) {
- return status;
- }
- break;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, 0):
- operation->alg = PSA_ALG_GCM;
- /* GCM allows the following tag lengths: 4, 8, 12, 13, 14, 15, 16.
- * The call to mbedtls_gcm_crypt_and_tag or
- * mbedtls_gcm_auth_decrypt will validate the tag length. */
- if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(attributes->type) != 16) {
- return PSA_ERROR_INVALID_ARGUMENT;
- }
- mbedtls_gcm_init(&operation->ctx.gcm);
- status = mbedtls_to_psa_error(
- mbedtls_gcm_setkey(&operation->ctx.gcm, cipher_id,
- key_buffer, (unsigned int) key_bits));
- if (status != PSA_SUCCESS) {
- return status;
- }
- break;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CHACHA20_POLY1305, 0):
- operation->alg = PSA_ALG_CHACHA20_POLY1305;
- /* We only support the default tag length. */
- if (alg != PSA_ALG_CHACHA20_POLY1305) {
- return PSA_ERROR_NOT_SUPPORTED;
- }
- mbedtls_chachapoly_init(&operation->ctx.chachapoly);
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_setkey(&operation->ctx.chachapoly,
- key_buffer));
- if (status != PSA_SUCCESS) {
- return status;
- }
- break;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- default:
- (void) status;
- (void) key_buffer;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- operation->key_type = psa_get_key_type(attributes);
- operation->tag_length = PSA_ALG_AEAD_GET_TAG_LENGTH(alg);
- return PSA_SUCCESS;
- }
- psa_status_t mbedtls_psa_aead_encrypt(
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer, size_t key_buffer_size,
- 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)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- mbedtls_psa_aead_operation_t operation = MBEDTLS_PSA_AEAD_OPERATION_INIT;
- uint8_t *tag;
- status = psa_aead_setup(&operation, attributes, key_buffer,
- key_buffer_size, alg);
- if (status != PSA_SUCCESS) {
- goto exit;
- }
- /* For all currently supported modes, the tag is at the end of the
- * ciphertext. */
- if (ciphertext_size < (plaintext_length + operation.tag_length)) {
- status = PSA_ERROR_BUFFER_TOO_SMALL;
- goto exit;
- }
- tag = ciphertext + plaintext_length;
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation.alg == PSA_ALG_CCM) {
- status = mbedtls_to_psa_error(
- mbedtls_ccm_encrypt_and_tag(&operation.ctx.ccm,
- plaintext_length,
- nonce, nonce_length,
- additional_data,
- additional_data_length,
- plaintext, ciphertext,
- tag, operation.tag_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- if (operation.alg == PSA_ALG_GCM) {
- status = mbedtls_to_psa_error(
- mbedtls_gcm_crypt_and_tag(&operation.ctx.gcm,
- MBEDTLS_GCM_ENCRYPT,
- plaintext_length,
- nonce, nonce_length,
- additional_data, additional_data_length,
- plaintext, ciphertext,
- operation.tag_length, tag));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- if (operation.alg == PSA_ALG_CHACHA20_POLY1305) {
- if (operation.tag_length != 16) {
- status = PSA_ERROR_NOT_SUPPORTED;
- goto exit;
- }
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_encrypt_and_tag(&operation.ctx.chachapoly,
- plaintext_length,
- nonce,
- additional_data,
- additional_data_length,
- plaintext,
- ciphertext,
- tag));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- {
- (void) tag;
- (void) nonce;
- (void) nonce_length;
- (void) additional_data;
- (void) additional_data_length;
- (void) plaintext;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- if (status == PSA_SUCCESS) {
- *ciphertext_length = plaintext_length + operation.tag_length;
- }
- exit:
- mbedtls_psa_aead_abort(&operation);
- return status;
- }
- /* Locate the tag in a ciphertext buffer containing the encrypted data
- * followed by the tag. Return the length of the part preceding the tag in
- * *plaintext_length. This is the size of the plaintext in modes where
- * the encrypted data has the same size as the plaintext, such as
- * CCM and GCM. */
- static psa_status_t psa_aead_unpadded_locate_tag(size_t tag_length,
- const uint8_t *ciphertext,
- size_t ciphertext_length,
- size_t plaintext_size,
- const uint8_t **p_tag)
- {
- size_t payload_length;
- if (tag_length > ciphertext_length) {
- return PSA_ERROR_INVALID_ARGUMENT;
- }
- payload_length = ciphertext_length - tag_length;
- if (payload_length > plaintext_size) {
- return PSA_ERROR_BUFFER_TOO_SMALL;
- }
- *p_tag = ciphertext + payload_length;
- return PSA_SUCCESS;
- }
- psa_status_t mbedtls_psa_aead_decrypt(
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer, size_t key_buffer_size,
- 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 *ciphertext, size_t ciphertext_length,
- uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- mbedtls_psa_aead_operation_t operation = MBEDTLS_PSA_AEAD_OPERATION_INIT;
- const uint8_t *tag = NULL;
- status = psa_aead_setup(&operation, attributes, key_buffer,
- key_buffer_size, alg);
- if (status != PSA_SUCCESS) {
- goto exit;
- }
- status = psa_aead_unpadded_locate_tag(operation.tag_length,
- ciphertext, ciphertext_length,
- plaintext_size, &tag);
- if (status != PSA_SUCCESS) {
- goto exit;
- }
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation.alg == PSA_ALG_CCM) {
- status = mbedtls_to_psa_error(
- mbedtls_ccm_auth_decrypt(&operation.ctx.ccm,
- ciphertext_length - operation.tag_length,
- nonce, nonce_length,
- additional_data,
- additional_data_length,
- ciphertext, plaintext,
- tag, operation.tag_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- if (operation.alg == PSA_ALG_GCM) {
- status = mbedtls_to_psa_error(
- mbedtls_gcm_auth_decrypt(&operation.ctx.gcm,
- ciphertext_length - operation.tag_length,
- nonce, nonce_length,
- additional_data,
- additional_data_length,
- tag, operation.tag_length,
- ciphertext, plaintext));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- if (operation.alg == PSA_ALG_CHACHA20_POLY1305) {
- if (operation.tag_length != 16) {
- status = PSA_ERROR_NOT_SUPPORTED;
- goto exit;
- }
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_auth_decrypt(&operation.ctx.chachapoly,
- ciphertext_length - operation.tag_length,
- nonce,
- additional_data,
- additional_data_length,
- tag,
- ciphertext,
- plaintext));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- {
- (void) nonce;
- (void) nonce_length;
- (void) additional_data;
- (void) additional_data_length;
- (void) plaintext;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- if (status == PSA_SUCCESS) {
- *plaintext_length = ciphertext_length - operation.tag_length;
- }
- exit:
- mbedtls_psa_aead_abort(&operation);
- if (status == PSA_SUCCESS) {
- *plaintext_length = ciphertext_length - operation.tag_length;
- }
- return status;
- }
- /* Set the key and algorithm for a multipart authenticated encryption
- * operation. */
- psa_status_t mbedtls_psa_aead_encrypt_setup(
- mbedtls_psa_aead_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- status = psa_aead_setup(operation, attributes, key_buffer,
- key_buffer_size, alg);
- if (status == PSA_SUCCESS) {
- operation->is_encrypt = 1;
- }
- return status;
- }
- /* Set the key and algorithm for a multipart authenticated decryption
- * operation. */
- psa_status_t mbedtls_psa_aead_decrypt_setup(
- mbedtls_psa_aead_operation_t *operation,
- const psa_key_attributes_t *attributes,
- const uint8_t *key_buffer,
- size_t key_buffer_size,
- psa_algorithm_t alg)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- status = psa_aead_setup(operation, attributes, key_buffer,
- key_buffer_size, alg);
- if (status == PSA_SUCCESS) {
- operation->is_encrypt = 0;
- }
- return status;
- }
- /* Set a nonce for the multipart AEAD operation*/
- psa_status_t mbedtls_psa_aead_set_nonce(
- mbedtls_psa_aead_operation_t *operation,
- const uint8_t *nonce,
- size_t nonce_length)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- if (operation->alg == PSA_ALG_GCM) {
- status = mbedtls_to_psa_error(
- mbedtls_gcm_starts(&operation->ctx.gcm,
- operation->is_encrypt ?
- MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
- nonce,
- nonce_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation->alg == PSA_ALG_CCM) {
- status = mbedtls_to_psa_error(
- mbedtls_ccm_starts(&operation->ctx.ccm,
- operation->is_encrypt ?
- MBEDTLS_CCM_ENCRYPT : MBEDTLS_CCM_DECRYPT,
- nonce,
- nonce_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
- /* Note - ChaChaPoly allows an 8 byte nonce, but we would have to
- * allocate a buffer in the operation, copy the nonce to it and pad
- * it, so for now check the nonce is 12 bytes, as
- * mbedtls_chachapoly_starts() assumes it can read 12 bytes from the
- * passed in buffer. */
- if (nonce_length != 12) {
- return PSA_ERROR_INVALID_ARGUMENT;
- }
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_starts(&operation->ctx.chachapoly,
- nonce,
- operation->is_encrypt ?
- MBEDTLS_CHACHAPOLY_ENCRYPT :
- MBEDTLS_CHACHAPOLY_DECRYPT));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- {
- (void) operation;
- (void) nonce;
- (void) nonce_length;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- return status;
- }
- /* Declare the lengths of the message and additional data for AEAD. */
- psa_status_t mbedtls_psa_aead_set_lengths(
- mbedtls_psa_aead_operation_t *operation,
- size_t ad_length,
- size_t plaintext_length)
- {
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation->alg == PSA_ALG_CCM) {
- return mbedtls_to_psa_error(
- mbedtls_ccm_set_lengths(&operation->ctx.ccm,
- ad_length,
- plaintext_length,
- operation->tag_length));
- }
- #else /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- (void) operation;
- (void) ad_length;
- (void) plaintext_length;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- return PSA_SUCCESS;
- }
- /* Pass additional data to an active multipart AEAD operation. */
- psa_status_t mbedtls_psa_aead_update_ad(
- mbedtls_psa_aead_operation_t *operation,
- const uint8_t *input,
- size_t input_length)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- if (operation->alg == PSA_ALG_GCM) {
- status = mbedtls_to_psa_error(
- mbedtls_gcm_update_ad(&operation->ctx.gcm, input, input_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation->alg == PSA_ALG_CCM) {
- status = mbedtls_to_psa_error(
- mbedtls_ccm_update_ad(&operation->ctx.ccm, input, input_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_update_aad(&operation->ctx.chachapoly,
- input,
- input_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- {
- (void) operation;
- (void) input;
- (void) input_length;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- return status;
- }
- /* Encrypt or decrypt a message fragment in an active multipart AEAD
- * operation.*/
- psa_status_t mbedtls_psa_aead_update(
- mbedtls_psa_aead_operation_t *operation,
- const uint8_t *input,
- size_t input_length,
- uint8_t *output,
- size_t output_size,
- size_t *output_length)
- {
- size_t update_output_length;
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- update_output_length = input_length;
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- if (operation->alg == PSA_ALG_GCM) {
- status = mbedtls_to_psa_error(
- mbedtls_gcm_update(&operation->ctx.gcm,
- input, input_length,
- output, output_size,
- &update_output_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation->alg == PSA_ALG_CCM) {
- if (output_size < input_length) {
- return PSA_ERROR_BUFFER_TOO_SMALL;
- }
- status = mbedtls_to_psa_error(
- mbedtls_ccm_update(&operation->ctx.ccm,
- input, input_length,
- output, output_size,
- &update_output_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
- if (output_size < input_length) {
- return PSA_ERROR_BUFFER_TOO_SMALL;
- }
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_update(&operation->ctx.chachapoly,
- input_length,
- input,
- output));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- {
- (void) operation;
- (void) input;
- (void) output;
- (void) output_size;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- if (status == PSA_SUCCESS) {
- *output_length = update_output_length;
- }
- return status;
- }
- /* Finish encrypting a message in a multipart AEAD operation. */
- psa_status_t mbedtls_psa_aead_finish(
- mbedtls_psa_aead_operation_t *operation,
- uint8_t *ciphertext,
- size_t ciphertext_size,
- size_t *ciphertext_length,
- uint8_t *tag,
- size_t tag_size,
- size_t *tag_length)
- {
- psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
- size_t finish_output_size = 0;
- if (tag_size < operation->tag_length) {
- return PSA_ERROR_BUFFER_TOO_SMALL;
- }
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- if (operation->alg == PSA_ALG_GCM) {
- status = mbedtls_to_psa_error(
- mbedtls_gcm_finish(&operation->ctx.gcm,
- ciphertext, ciphertext_size, ciphertext_length,
- tag, operation->tag_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- if (operation->alg == PSA_ALG_CCM) {
- /* tag must be big enough to store a tag of size passed into set
- * lengths. */
- if (tag_size < operation->tag_length) {
- return PSA_ERROR_BUFFER_TOO_SMALL;
- }
- status = mbedtls_to_psa_error(
- mbedtls_ccm_finish(&operation->ctx.ccm,
- tag, operation->tag_length));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
- /* Belt and braces. Although the above tag_size check should have
- * already done this, if we later start supporting smaller tag sizes
- * for chachapoly, then passing a tag buffer smaller than 16 into here
- * could cause a buffer overflow, so better safe than sorry. */
- if (tag_size < 16) {
- return PSA_ERROR_BUFFER_TOO_SMALL;
- }
- status = mbedtls_to_psa_error(
- mbedtls_chachapoly_finish(&operation->ctx.chachapoly,
- tag));
- } else
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- {
- (void) ciphertext;
- (void) ciphertext_size;
- (void) ciphertext_length;
- (void) tag;
- (void) tag_size;
- (void) tag_length;
- return PSA_ERROR_NOT_SUPPORTED;
- }
- if (status == PSA_SUCCESS) {
- /* This will be zero for all supported algorithms currently, but left
- * here for future support. */
- *ciphertext_length = finish_output_size;
- *tag_length = operation->tag_length;
- }
- return status;
- }
- /* Abort an AEAD operation */
- psa_status_t mbedtls_psa_aead_abort(
- mbedtls_psa_aead_operation_t *operation)
- {
- switch (operation->alg) {
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
- case PSA_ALG_CCM:
- mbedtls_ccm_free(&operation->ctx.ccm);
- break;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
- case PSA_ALG_GCM:
- mbedtls_gcm_free(&operation->ctx.gcm);
- break;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
- #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
- case PSA_ALG_CHACHA20_POLY1305:
- mbedtls_chachapoly_free(&operation->ctx.chachapoly);
- break;
- #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
- }
- operation->is_encrypt = 0;
- return PSA_SUCCESS;
- }
- #endif /* MBEDTLS_PSA_CRYPTO_C */
|