23 #if defined(MBEDTLS_PSA_CRYPTO_C)
39 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
42 #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
45 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
51 #define AEAD_OPERATION_INIT { 0, 0, { 0 } }
56 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
61 #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
66 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
84 size_t full_tag_length = 0;
91 if (cipher_info ==
NULL) {
96 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
110 key_buffer, (
unsigned int) key_bits));
117 #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
120 full_tag_length = 16;
131 key_buffer, (
unsigned int) key_bits));
138 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
141 full_tag_length = 16;
178 const uint8_t *key_buffer,
size_t key_buffer_size,
180 const uint8_t *nonce,
size_t nonce_length,
181 const uint8_t *additional_data,
size_t additional_data_length,
182 const uint8_t *plaintext,
size_t plaintext_length,
183 uint8_t *ciphertext,
size_t ciphertext_size,
size_t *ciphertext_length)
188 (void) key_buffer_size;
197 if (ciphertext_size < (plaintext_length +
operation.tag_length)) {
201 tag = ciphertext + plaintext_length;
203 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
210 additional_data_length,
211 plaintext, ciphertext,
215 #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
222 additional_data, additional_data_length,
223 plaintext, ciphertext,
227 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
229 if (nonce_length != 12) {
230 if (nonce_length == 8) {
247 additional_data_length,
257 (void) additional_data;
258 (void) additional_data_length;
264 *ciphertext_length = plaintext_length +
operation.tag_length;
280 size_t ciphertext_length,
281 size_t plaintext_size,
284 size_t payload_length;
285 if (tag_length > ciphertext_length) {
288 payload_length = ciphertext_length - tag_length;
289 if (payload_length > plaintext_size) {
292 *p_tag = ciphertext + payload_length;
298 const uint8_t *key_buffer,
size_t key_buffer_size,
300 const uint8_t *nonce,
size_t nonce_length,
301 const uint8_t *additional_data,
size_t additional_data_length,
302 const uint8_t *ciphertext,
size_t ciphertext_length,
303 uint8_t *plaintext,
size_t plaintext_size,
size_t *plaintext_length)
308 (void) key_buffer_size;
316 ciphertext, ciphertext_length,
317 plaintext_size, &
tag);
322 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
326 ciphertext_length -
operation.tag_length,
329 additional_data_length,
330 ciphertext, plaintext,
334 #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
338 ciphertext_length -
operation.tag_length,
341 additional_data_length,
343 ciphertext, plaintext));
346 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
348 if (nonce_length != 12) {
349 if (nonce_length == 8) {
363 ciphertext_length -
operation.tag_length,
366 additional_data_length,
375 (void) additional_data;
376 (void) additional_data_length;
382 *plaintext_length = ciphertext_length -
operation.tag_length;
389 *plaintext_length = ciphertext_length -
operation.tag_length;
static const struct attribute attributes[]
This file provides an API for the CCM authenticated encryption mode for block ciphers.
void mbedtls_ccm_free(mbedtls_ccm_context *ctx)
This function releases and clears the specified CCM context and underlying cipher sub-context.
int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
This function initializes the CCM context set in the ctx parameter and sets the encryption key.
int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, unsigned char *tag, size_t tag_len)
This function encrypts a buffer using CCM.
int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, const unsigned char *tag, size_t tag_len)
This function performs a CCM authenticated decryption of a buffer.
void mbedtls_ccm_init(mbedtls_ccm_context *ctx)
This function initializes the specified CCM context, to make references valid, and prepare the contex...
This file contains the AEAD-ChaCha20-Poly1305 definitions and functions.
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
This function initializes the specified ChaCha20-Poly1305 context.
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx, const unsigned char key[32])
This function sets the ChaCha20-Poly1305 symmetric encryption key.
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
This function releases and clears the specified ChaCha20-Poly1305 context.
int mbedtls_chachapoly_encrypt_and_tag(mbedtls_chachapoly_context *ctx, size_t length, const unsigned char nonce[12], const unsigned char *aad, size_t aad_len, const unsigned char *input, unsigned char *output, unsigned char tag[16])
This function performs a complete ChaCha20-Poly1305 authenticated encryption with the previously-set ...
int mbedtls_chachapoly_auth_decrypt(mbedtls_chachapoly_context *ctx, size_t length, const unsigned char nonce[12], const unsigned char *aad, size_t aad_len, const unsigned char tag[16], const unsigned char *input, unsigned char *output)
This function performs a complete ChaCha20-Poly1305 authenticated decryption with the previously-set ...
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
mbedtls_cipher_id_t
Supported cipher types.
#define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg)
The length of a tag for an AEAD algorithm, in bytes.
This file contains GCM definitions and functions.
#define MBEDTLS_GCM_ENCRYPT
int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx, int mode, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, size_t tag_len, unsigned char *tag)
This function performs GCM encryption or decryption of a buffer.
void mbedtls_gcm_init(mbedtls_gcm_context *ctx)
This function initializes the specified GCM context, to make references valid, and prepares the conte...
int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
This function associates a GCM context with a cipher algorithm and a key.
void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
This function clears a GCM context and the underlying cipher sub-context.
int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *tag, size_t tag_len, const unsigned char *input, unsigned char *output)
This function performs a GCM authenticated decryption of a buffer.
#define PSA_ALG_GCM
The GCM authenticated encryption algorithm.
#define PSA_ALG_CHACHA20_POLY1305
The Chacha20-Poly1305 AEAD algorithm.
#define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length)
Macro to build a shortened AEAD algorithm.
#define PSA_ALG_CCM
The CCM authenticated encryption algorithm.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type)
The block size of a block cipher.
int32_t psa_status_t
Function return status.
#define PSA_ERROR_CORRUPTION_DETECTED
A tampering attempt was detected.
#define PSA_ERROR_NOT_SUPPORTED
The requested operation or a parameter is not supported by this implementation.
#define PSA_SUCCESS
The action was completed successfully.
#define PSA_ERROR_BUFFER_TOO_SMALL
An output buffer is too small.
#define PSA_ERROR_INVALID_ARGUMENT
The parameters passed to the function are invalid.
#define mbedtls_to_psa_error
#define AEAD_OPERATION_INIT
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)
static void psa_aead_abort_internal(aead_operation_t *operation)
static psa_status_t psa_aead_setup(aead_operation_t *operation, const psa_key_attributes_t *attributes, const uint8_t *key_buffer, psa_algorithm_t alg)
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)
Process an authenticated encryption operation.
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)
Process an authenticated decryption operation.
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_psa(psa_algorithm_t alg, psa_key_type_t key_type, size_t key_bits, mbedtls_cipher_id_t *cipher_id)
Get Mbed TLS cipher information given the cipher algorithm PSA identifier as well as the PSA type and...
The CCM context-type definition.
The GCM context structure.