2021-03-17 16:55:43 +01:00
|
|
|
/*
|
|
|
|
* PSA AEAD entry points
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
2023-11-03 13:21:36 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2021-03-17 16:55:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
|
|
|
|
|
|
|
#include "psa_crypto_aead.h"
|
2021-03-17 08:16:34 +01:00
|
|
|
#include "psa_crypto_core.h"
|
2022-11-02 10:25:38 +01:00
|
|
|
#include "psa_crypto_cipher.h"
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2021-04-20 17:06:57 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include "mbedtls/platform.h"
|
|
|
|
|
2021-03-17 08:16:34 +01:00
|
|
|
#include "mbedtls/ccm.h"
|
|
|
|
#include "mbedtls/chachapoly.h"
|
|
|
|
#include "mbedtls/cipher.h"
|
|
|
|
#include "mbedtls/gcm.h"
|
2021-04-20 17:06:57 +02:00
|
|
|
#include "mbedtls/error.h"
|
2021-03-17 08:16:34 +01:00
|
|
|
|
|
|
|
static psa_status_t psa_aead_setup(
|
2021-05-10 19:19:46 +02:00
|
|
|
mbedtls_psa_aead_operation_t *operation,
|
2021-03-17 08:16:34 +01:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer,
|
2021-05-12 13:22:28 +02:00
|
|
|
size_t key_buffer_size,
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_algorithm_t alg)
|
2021-03-17 08:16:34 +01:00
|
|
|
{
|
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
|
|
|
size_t key_bits;
|
2021-03-26 13:25:17 +01:00
|
|
|
const mbedtls_cipher_info_t *cipher_info;
|
2021-03-17 08:16:34 +01:00
|
|
|
mbedtls_cipher_id_t cipher_id;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
(void) key_buffer_size;
|
2021-05-12 13:22:28 +02:00
|
|
|
|
2021-03-17 08:16:34 +01:00
|
|
|
key_bits = attributes->core.bits;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
cipher_info = mbedtls_cipher_info_from_psa(alg,
|
|
|
|
attributes->core.type, key_bits,
|
|
|
|
&cipher_id);
|
|
|
|
if (cipher_info == NULL) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 0)) {
|
2021-03-17 08:16:34 +01:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 0):
|
2021-04-20 15:13:23 +02:00
|
|
|
operation->alg = PSA_ALG_CCM;
|
2021-03-17 08:16:34 +01:00
|
|
|
/* 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. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(attributes->core.type) != 16) {
|
|
|
|
return PSA_ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&operation->ctx.ccm);
|
2021-03-17 08:16:34 +01:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_setkey(&operation->ctx.ccm, cipher_id,
|
|
|
|
key_buffer, (unsigned int) key_bits));
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
break;
|
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, 0):
|
2021-04-20 15:13:23 +02:00
|
|
|
operation->alg = PSA_ALG_GCM;
|
2021-03-17 08:16:34 +01:00
|
|
|
/* 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. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(attributes->core.type) != 16) {
|
|
|
|
return PSA_ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_init(&operation->ctx.gcm);
|
2021-03-17 08:16:34 +01:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_setkey(&operation->ctx.gcm, cipher_id,
|
|
|
|
key_buffer, (unsigned int) key_bits));
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
break;
|
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CHACHA20_POLY1305, 0):
|
2021-04-20 15:13:23 +02:00
|
|
|
operation->alg = PSA_ALG_CHACHA20_POLY1305;
|
2021-03-17 08:16:34 +01:00
|
|
|
/* We only support the default tag length. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (alg != PSA_ALG_CHACHA20_POLY1305) {
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_init(&operation->ctx.chachapoly);
|
2021-03-17 08:16:34 +01:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_setkey(&operation->ctx.chachapoly,
|
|
|
|
key_buffer));
|
|
|
|
if (status != PSA_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
break;
|
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
|
|
|
|
default:
|
2021-04-28 14:29:00 +02:00
|
|
|
(void) status;
|
|
|
|
(void) key_buffer;
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
operation->key_type = psa_get_key_type(attributes);
|
2021-05-10 19:19:46 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
operation->tag_length = PSA_ALG_AEAD_GET_TAG_LENGTH(alg);
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length)
|
2021-03-17 08:16:34 +01:00
|
|
|
{
|
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
2021-05-10 19:19:46 +02:00
|
|
|
mbedtls_psa_aead_operation_t operation = MBEDTLS_PSA_AEAD_OPERATION_INIT;
|
2021-03-17 08:16:34 +01:00
|
|
|
uint8_t *tag;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_aead_setup(&operation, attributes, key_buffer,
|
|
|
|
key_buffer_size, alg);
|
2021-05-12 13:22:28 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status != PSA_SUCCESS) {
|
2021-03-17 08:16:34 +01:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
|
|
|
/* For all currently supported modes, the tag is at the end of the
|
|
|
|
* ciphertext. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ciphertext_size < (plaintext_length + operation.tag_length)) {
|
2021-03-17 08:16:34 +01:00
|
|
|
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
tag = ciphertext + plaintext_length;
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation.alg == PSA_ALG_CCM) {
|
2021-03-17 08:16:34 +01:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
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
|
2021-03-17 08:16:34 +01:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2021-04-06 09:01:39 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation.alg == PSA_ALG_GCM) {
|
2021-04-06 09:01:39 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
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
|
2021-04-06 09:01:39 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
2021-03-17 08:16:34 +01:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation.alg == PSA_ALG_CHACHA20_POLY1305) {
|
|
|
|
if (operation.tag_length != 16) {
|
2021-03-17 08:16:34 +01:00
|
|
|
status = PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_encrypt_and_tag(&operation.ctx.chachapoly,
|
|
|
|
plaintext_length,
|
|
|
|
nonce,
|
|
|
|
additional_data,
|
|
|
|
additional_data_length,
|
|
|
|
plaintext,
|
|
|
|
ciphertext,
|
|
|
|
tag));
|
|
|
|
} else
|
2021-03-17 08:16:34 +01:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
{
|
|
|
|
(void) tag;
|
2021-04-28 14:29:00 +02:00
|
|
|
(void) nonce;
|
|
|
|
(void) nonce_length;
|
|
|
|
(void) additional_data;
|
|
|
|
(void) additional_data_length;
|
|
|
|
(void) plaintext;
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-03-17 08:16:34 +01:00
|
|
|
*ciphertext_length = plaintext_length + operation.tag_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_psa_aead_abort(&operation);
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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. */
|
2023-01-11 14:50:10 +01:00
|
|
|
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)
|
2021-03-17 08:16:34 +01:00
|
|
|
{
|
|
|
|
size_t payload_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (tag_length > ciphertext_length) {
|
|
|
|
return PSA_ERROR_INVALID_ARGUMENT;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
payload_length = ciphertext_length - tag_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (payload_length > plaintext_size) {
|
|
|
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
*p_tag = ciphertext + payload_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length)
|
2021-03-17 08:16:34 +01:00
|
|
|
{
|
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
2021-05-10 19:19:46 +02:00
|
|
|
mbedtls_psa_aead_operation_t operation = MBEDTLS_PSA_AEAD_OPERATION_INIT;
|
2021-03-17 08:16:34 +01:00
|
|
|
const uint8_t *tag = NULL;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_aead_setup(&operation, attributes, key_buffer,
|
|
|
|
key_buffer_size, alg);
|
2021-05-12 13:22:28 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status != PSA_SUCCESS) {
|
2021-03-17 08:16:34 +01:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_aead_unpadded_locate_tag(operation.tag_length,
|
|
|
|
ciphertext, ciphertext_length,
|
|
|
|
plaintext_size, &tag);
|
|
|
|
if (status != PSA_SUCCESS) {
|
2021-03-17 08:16:34 +01:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2021-04-06 09:01:39 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation.alg == PSA_ALG_CCM) {
|
2021-03-17 08:16:34 +01:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
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
|
2021-04-06 09:01:39 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation.alg == PSA_ALG_GCM) {
|
2021-03-17 08:16:34 +01:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
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
|
2021-04-06 09:01:39 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
2021-03-17 08:16:34 +01:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation.alg == PSA_ALG_CHACHA20_POLY1305) {
|
|
|
|
if (operation.tag_length != 16) {
|
2021-03-17 08:16:34 +01:00
|
|
|
status = PSA_ERROR_NOT_SUPPORTED;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_auth_decrypt(&operation.ctx.chachapoly,
|
|
|
|
ciphertext_length - operation.tag_length,
|
|
|
|
nonce,
|
|
|
|
additional_data,
|
|
|
|
additional_data_length,
|
|
|
|
tag,
|
|
|
|
ciphertext,
|
|
|
|
plaintext));
|
|
|
|
} else
|
2021-03-17 08:16:34 +01:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
{
|
2021-04-28 14:29:00 +02:00
|
|
|
(void) nonce;
|
|
|
|
(void) nonce_length;
|
|
|
|
(void) additional_data;
|
|
|
|
(void) additional_data_length;
|
|
|
|
(void) plaintext;
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-03-17 08:16:34 +01:00
|
|
|
*plaintext_length = ciphertext_length - operation.tag_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-03-17 08:16:34 +01:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_psa_aead_abort(&operation);
|
2021-03-17 08:16:34 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-03-17 08:16:34 +01:00
|
|
|
*plaintext_length = ciphertext_length - operation.tag_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
return status;
|
2021-03-17 08:16:34 +01:00
|
|
|
}
|
2021-03-17 16:55:43 +01:00
|
|
|
|
2021-04-20 17:06:57 +02:00
|
|
|
/* Set the key and algorithm for a multipart authenticated encryption
|
|
|
|
* operation. */
|
2021-05-19 18:29:42 +02:00
|
|
|
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,
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_algorithm_t alg)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
2021-05-13 15:30:53 +02:00
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_aead_setup(operation, attributes, key_buffer,
|
|
|
|
key_buffer_size, alg);
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-04-20 17:06:57 +02:00
|
|
|
operation->is_encrypt = 1;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the key and algorithm for a multipart authenticated decryption
|
|
|
|
* operation. */
|
2021-05-19 18:29:42 +02:00
|
|
|
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,
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_algorithm_t alg)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
2021-05-13 15:30:53 +02:00
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
status = psa_aead_setup(operation, attributes, key_buffer,
|
|
|
|
key_buffer_size, alg);
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-04-20 17:06:57 +02:00
|
|
|
operation->is_encrypt = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a nonce for the multipart AEAD operation*/
|
2021-05-19 18:29:42 +02:00
|
|
|
psa_status_t mbedtls_psa_aead_set_nonce(
|
|
|
|
mbedtls_psa_aead_operation_t *operation,
|
|
|
|
const uint8_t *nonce,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t nonce_length)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
2021-05-13 15:30:53 +02:00
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2021-06-03 16:29:00 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_GCM) {
|
2021-05-21 20:28:26 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_starts(&operation->ctx.gcm,
|
|
|
|
operation->is_encrypt ?
|
|
|
|
MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
|
|
|
|
nonce,
|
|
|
|
nonce_length));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
2021-10-01 14:00:16 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CCM) {
|
2021-10-01 14:00:16 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_starts(&operation->ctx.ccm,
|
|
|
|
operation->is_encrypt ?
|
|
|
|
MBEDTLS_CCM_ENCRYPT : MBEDTLS_CCM_DECRYPT,
|
|
|
|
nonce,
|
|
|
|
nonce_length));
|
|
|
|
} else
|
2021-10-01 14:00:16 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2021-04-20 17:06:57 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
|
2021-09-28 15:32:55 +02:00
|
|
|
/* 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. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (nonce_length != 12) {
|
|
|
|
return PSA_ERROR_INVALID_ARGUMENT;
|
2021-09-28 15:32:55 +02:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:52:18 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_starts(&operation->ctx.chachapoly,
|
2021-05-07 18:52:18 +02:00
|
|
|
nonce,
|
|
|
|
operation->is_encrypt ?
|
|
|
|
MBEDTLS_CHACHAPOLY_ENCRYPT :
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_CHACHAPOLY_DECRYPT));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
(void) operation;
|
|
|
|
(void) nonce;
|
|
|
|
(void) nonce_length;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
2021-08-25 18:16:52 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
/* Declare the lengths of the message and additional data for AEAD. */
|
2021-09-28 12:00:20 +02:00
|
|
|
psa_status_t mbedtls_psa_aead_set_lengths(
|
|
|
|
mbedtls_psa_aead_operation_t *operation,
|
|
|
|
size_t ad_length,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t plaintext_length)
|
2021-09-28 12:00:20 +02:00
|
|
|
{
|
2021-10-01 14:00:16 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
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));
|
2021-10-01 14:00:16 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
#else /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2023-01-11 14:50:10 +01:00
|
|
|
(void) operation;
|
|
|
|
(void) ad_length;
|
|
|
|
(void) plaintext_length;
|
2021-10-01 14:00:16 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2021-09-28 12:00:20 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2021-09-28 12:00:20 +02:00
|
|
|
}
|
|
|
|
|
2021-04-20 17:06:57 +02:00
|
|
|
/* Pass additional data to an active multipart AEAD operation. */
|
2021-05-19 18:29:42 +02:00
|
|
|
psa_status_t mbedtls_psa_aead_update_ad(
|
|
|
|
mbedtls_psa_aead_operation_t *operation,
|
|
|
|
const uint8_t *input,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t input_length)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_GCM) {
|
2021-05-07 18:52:18 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_update_ad(&operation->ctx.gcm, input, input_length));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
2021-10-01 14:00:16 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CCM) {
|
2021-10-01 14:00:16 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_update_ad(&operation->ctx.ccm, input, input_length));
|
|
|
|
} else
|
2021-10-01 14:00:16 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2021-04-20 17:06:57 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
|
2021-05-07 18:52:18 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_update_aad(&operation->ctx.chachapoly,
|
2021-05-07 18:52:18 +02:00
|
|
|
input,
|
2023-01-11 14:50:10 +01:00
|
|
|
input_length));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
(void) operation;
|
|
|
|
(void) input;
|
|
|
|
(void) input_length;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Encrypt or decrypt a message fragment in an active multipart AEAD
|
|
|
|
* operation.*/
|
2021-05-19 18:29:42 +02:00
|
|
|
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,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t *output_length)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
2021-05-13 18:16:01 +02:00
|
|
|
size_t update_output_length;
|
2021-04-20 17:06:57 +02:00
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
|
|
|
|
2021-05-13 18:16:01 +02:00
|
|
|
update_output_length = input_length;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_GCM) {
|
2021-05-21 20:28:26 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_update(&operation->ctx.gcm,
|
|
|
|
input, input_length,
|
|
|
|
output, output_size,
|
|
|
|
&update_output_length));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
2021-10-01 14:00:16 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CCM) {
|
|
|
|
if (output_size < input_length) {
|
|
|
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2021-10-01 14:00:16 +02:00
|
|
|
|
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_update(&operation->ctx.ccm,
|
2021-10-01 14:00:16 +02:00
|
|
|
input, input_length,
|
|
|
|
output, output_size,
|
2023-01-11 14:50:10 +01:00
|
|
|
&update_output_length));
|
|
|
|
} else
|
2021-10-01 14:00:16 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2021-04-20 17:06:57 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
|
|
|
|
if (output_size < input_length) {
|
|
|
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2021-07-23 16:44:11 +02:00
|
|
|
|
2021-05-07 18:52:18 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_update(&operation->ctx.chachapoly,
|
2021-05-07 18:52:18 +02:00
|
|
|
input_length,
|
|
|
|
input,
|
2023-01-11 14:50:10 +01:00
|
|
|
output));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
(void) operation;
|
|
|
|
(void) input;
|
|
|
|
(void) output;
|
|
|
|
(void) output_size;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-05-13 18:16:01 +02:00
|
|
|
*output_length = update_output_length;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finish encrypting a message in a multipart AEAD operation. */
|
2021-05-19 18:29:42 +02:00
|
|
|
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,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t *tag_length)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
|
|
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
2021-04-25 19:10:42 +02:00
|
|
|
size_t finish_output_size = 0;
|
2021-04-20 17:06:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (tag_size < operation->tag_length) {
|
|
|
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2021-04-20 17:06:57 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_GCM) {
|
2021-05-21 20:28:26 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_finish(&operation->ctx.gcm,
|
|
|
|
ciphertext, ciphertext_size, ciphertext_length,
|
|
|
|
tag, operation->tag_length));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
2021-10-01 14:00:16 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CCM) {
|
2021-10-01 14:00:16 +02:00
|
|
|
/* tag must be big enough to store a tag of size passed into set
|
|
|
|
* lengths. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (tag_size < operation->tag_length) {
|
|
|
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2021-10-01 14:00:16 +02:00
|
|
|
|
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_finish(&operation->ctx.ccm,
|
|
|
|
tag, operation->tag_length));
|
|
|
|
} else
|
2021-10-01 14:00:16 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
2021-04-20 17:06:57 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
|
2021-07-22 19:48:24 +02:00
|
|
|
/* 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. */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (tag_size < 16) {
|
|
|
|
return PSA_ERROR_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2021-07-22 19:48:24 +02:00
|
|
|
|
2021-05-07 18:52:18 +02:00
|
|
|
status = mbedtls_to_psa_error(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_finish(&operation->ctx.chachapoly,
|
|
|
|
tag));
|
|
|
|
} else
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
(void) ciphertext;
|
|
|
|
(void) ciphertext_size;
|
|
|
|
(void) ciphertext_length;
|
|
|
|
(void) tag;
|
|
|
|
(void) tag_size;
|
|
|
|
(void) tag_length;
|
|
|
|
|
|
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (status == PSA_SUCCESS) {
|
2021-09-19 19:39:23 +02:00
|
|
|
/* This will be zero for all supported algorithms currently, but left
|
|
|
|
* here for future support. */
|
2021-04-20 17:06:57 +02:00
|
|
|
*ciphertext_length = finish_output_size;
|
2021-04-25 19:10:42 +02:00
|
|
|
*tag_length = operation->tag_length;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return status;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Abort an AEAD operation */
|
2021-05-19 18:29:42 +02:00
|
|
|
psa_status_t mbedtls_psa_aead_abort(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_psa_aead_operation_t *operation)
|
2021-04-20 17:06:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (operation->alg) {
|
2021-04-22 12:31:14 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
|
|
|
case PSA_ALG_CCM:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&operation->ctx.ccm);
|
2021-04-20 17:06:57 +02:00
|
|
|
break;
|
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
|
|
|
case PSA_ALG_GCM:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_gcm_free(&operation->ctx.gcm);
|
2021-04-20 17:06:57 +02:00
|
|
|
break;
|
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2021-04-22 12:31:14 +02:00
|
|
|
case PSA_ALG_CHACHA20_POLY1305:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_chachapoly_free(&operation->ctx.chachapoly);
|
2021-04-22 12:31:14 +02:00
|
|
|
break;
|
2021-04-20 17:06:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
}
|
|
|
|
|
2021-05-10 19:19:46 +02:00
|
|
|
operation->is_encrypt = 0;
|
2021-05-20 19:24:07 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return PSA_SUCCESS;
|
2021-04-20 17:06:57 +02:00
|
|
|
}
|
|
|
|
|
2021-03-17 16:55:43 +01:00
|
|
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|