26 #if defined(MBEDTLS_CIPHER_C)
37 #if defined(MBEDTLS_CHACHAPOLY_C)
41 #if defined(MBEDTLS_GCM_C)
45 #if defined(MBEDTLS_CCM_C)
49 #if defined(MBEDTLS_CHACHA20_C)
53 #if defined(MBEDTLS_CMAC_C)
57 #if defined(MBEDTLS_USE_PSA_CRYPTO)
62 #if defined(MBEDTLS_NIST_KW_C)
68 #define CIPHER_VALIDATE_RET(cond) \
69 MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA)
70 #define CIPHER_VALIDATE(cond) \
71 MBEDTLS_INTERNAL_VALIDATE(cond)
84 while (def->
type != 0) {
102 if (def->
type == cipher_type) {
111 const char *cipher_name)
115 if (
NULL == cipher_name) {
158 #if defined(MBEDTLS_USE_PSA_CRYPTO)
159 if (
ctx->psa_enabled == 1) {
161 mbedtls_cipher_context_psa *
const cipher_psa =
162 (mbedtls_cipher_context_psa *)
ctx->cipher_ctx;
164 if (cipher_psa->slot_state == MBEDTLS_CIPHER_PSA_KEY_OWNED) {
178 #if defined(MBEDTLS_CMAC_C)
186 if (
ctx->cipher_ctx) {
187 ctx->cipher_info->base->ctx_free_func(
ctx->cipher_ctx);
197 if (cipher_info ==
NULL) {
207 ctx->cipher_info = cipher_info;
209 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
213 #if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
223 #if defined(MBEDTLS_USE_PSA_CRYPTO)
229 mbedtls_cipher_context_psa *cipher_psa;
237 alg = mbedtls_psa_translate_cipher_mode(cipher_info->
mode, taglen);
241 if (mbedtls_psa_translate_cipher_type(cipher_info->
type) == 0) {
247 cipher_psa =
mbedtls_calloc(1,
sizeof(mbedtls_cipher_context_psa));
248 if (cipher_psa ==
NULL) {
251 cipher_psa->alg = alg;
252 ctx->cipher_ctx = cipher_psa;
253 ctx->cipher_info = cipher_info;
254 ctx->psa_enabled = 1;
260 const unsigned char *
key,
268 if (
ctx->cipher_info ==
NULL) {
272 #if defined(MBEDTLS_USE_PSA_CRYPTO)
273 if (
ctx->psa_enabled == 1) {
274 mbedtls_cipher_context_psa *
const cipher_psa =
275 (mbedtls_cipher_context_psa *)
ctx->cipher_ctx;
277 size_t const key_bytelen = ((
size_t) key_bitlen + 7) / 8;
284 if (key_bitlen % 8 != 0) {
289 if (cipher_psa->slot_state != MBEDTLS_CIPHER_PSA_KEY_UNSET) {
293 key_type = mbedtls_psa_translate_cipher_type(
294 ctx->cipher_info->type);
323 cipher_psa->slot_state = MBEDTLS_CIPHER_PSA_KEY_OWNED;
325 ctx->key_bitlen = key_bitlen;
332 (
int)
ctx->cipher_info->key_bitlen != key_bitlen) {
336 ctx->key_bitlen = key_bitlen;
346 return ctx->cipher_info->base->setkey_enc_func(
ctx->cipher_ctx,
key,
351 return ctx->cipher_info->base->setkey_dec_func(
ctx->cipher_ctx,
key,
359 const unsigned char *iv,
362 size_t actual_iv_size;
366 if (
ctx->cipher_info ==
NULL) {
369 #if defined(MBEDTLS_USE_PSA_CRYPTO)
370 if (
ctx->psa_enabled == 1) {
384 actual_iv_size = iv_len;
386 actual_iv_size =
ctx->cipher_info->iv_size;
389 if (actual_iv_size > iv_len) {
394 #if defined(MBEDTLS_CHACHA20_C)
409 #if defined(MBEDTLS_CHACHAPOLY_C)
417 if (actual_iv_size != 0) {
418 memcpy(
ctx->iv, iv, actual_iv_size);
419 ctx->iv_size = actual_iv_size;
428 if (
ctx->cipher_info ==
NULL) {
432 #if defined(MBEDTLS_USE_PSA_CRYPTO)
433 if (
ctx->psa_enabled == 1) {
440 ctx->unprocessed_len = 0;
445 #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
447 const unsigned char *ad,
size_t ad_len)
451 if (
ctx->cipher_info ==
NULL) {
455 #if defined(MBEDTLS_USE_PSA_CRYPTO)
456 if (
ctx->psa_enabled == 1) {
464 #if defined(MBEDTLS_GCM_C)
467 ctx->iv,
ctx->iv_size, ad, ad_len);
471 #if defined(MBEDTLS_CHACHAPOLY_C)
497 size_t ilen,
unsigned char *
output,
size_t *olen)
506 if (
ctx->cipher_info ==
NULL) {
510 #if defined(MBEDTLS_USE_PSA_CRYPTO)
511 if (
ctx->psa_enabled == 1) {
521 if (0 == block_size) {
526 if (ilen != block_size) {
532 if (0 != (ret =
ctx->cipher_info->base->ecb_func(
ctx->cipher_ctx,
540 #if defined(MBEDTLS_GCM_C)
548 #if defined(MBEDTLS_CHACHAPOLY_C)
557 (
ctx->unprocessed_len != 0 || ilen % block_size)) {
561 #if defined(MBEDTLS_CIPHER_MODE_CBC)
569 ilen <= block_size - ctx->unprocessed_len) ||
571 ilen < block_size - ctx->unprocessed_len) ||
573 ilen < block_size - ctx->unprocessed_len)) {
574 memcpy(&(
ctx->unprocessed_data[
ctx->unprocessed_len]),
input,
577 ctx->unprocessed_len += ilen;
584 if (0 !=
ctx->unprocessed_len) {
585 copy_len = block_size -
ctx->unprocessed_len;
587 memcpy(&(
ctx->unprocessed_data[
ctx->unprocessed_len]),
input,
590 if (0 != (ret =
ctx->cipher_info->base->cbc_func(
ctx->cipher_ctx,
591 ctx->operation, block_size,
ctx->iv,
598 ctx->unprocessed_len = 0;
612 copy_len = ilen % block_size;
616 copy_len = block_size;
619 memcpy(
ctx->unprocessed_data, &(
input[ilen - copy_len]),
622 ctx->unprocessed_len += copy_len;
630 if (0 != (ret =
ctx->cipher_info->base->cbc_func(
ctx->cipher_ctx,
643 #if defined(MBEDTLS_CIPHER_MODE_CFB)
645 if (0 != (ret =
ctx->cipher_info->base->cfb_func(
ctx->cipher_ctx,
646 ctx->operation, ilen,
647 &
ctx->unprocessed_len,
ctx->iv,
658 #if defined(MBEDTLS_CIPHER_MODE_OFB)
660 if (0 != (ret =
ctx->cipher_info->base->ofb_func(
ctx->cipher_ctx,
661 ilen, &
ctx->unprocessed_len,
ctx->iv,
672 #if defined(MBEDTLS_CIPHER_MODE_CTR)
674 if (0 != (ret =
ctx->cipher_info->base->ctr_func(
ctx->cipher_ctx,
675 ilen, &
ctx->unprocessed_len,
ctx->iv,
686 #if defined(MBEDTLS_CIPHER_MODE_XTS)
688 if (
ctx->unprocessed_len > 0) {
693 ret =
ctx->cipher_info->base->xts_func(
ctx->cipher_ctx,
705 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
707 if (0 != (ret =
ctx->cipher_info->base->stream_func(
ctx->cipher_ctx,
721 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
722 #if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
729 size_t padding_len = output_len - data_len;
732 for (
i = 0;
i < padding_len;
i++) {
733 output[data_len +
i] = (
unsigned char) padding_len;
741 unsigned char padding_len, bad = 0;
747 padding_len =
input[input_len - 1];
748 *data_len = input_len - padding_len;
751 bad |= padding_len > input_len;
752 bad |= padding_len == 0;
756 pad_idx = input_len - padding_len;
757 for (
i = 0;
i < input_len;
i++) {
758 bad |= (
input[
i] ^ padding_len) * (
i >= pad_idx);
765 #if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
770 size_t output_len,
size_t data_len)
772 size_t padding_len = output_len - data_len;
776 for (
i = 1;
i < padding_len;
i++) {
785 unsigned char done = 0, prev_done, bad;
793 for (
i = input_len;
i > 0;
i--) {
796 *data_len |= (
i - 1) * (
done != prev_done);
805 #if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
810 size_t output_len,
size_t data_len)
812 size_t padding_len = output_len - data_len;
815 for (
i = 1;
i < padding_len;
i++) {
816 output[data_len +
i - 1] = 0x00;
818 output[output_len - 1] = (
unsigned char) padding_len;
825 unsigned char padding_len, bad = 0;
831 padding_len =
input[input_len - 1];
832 *data_len = input_len - padding_len;
835 bad |= padding_len > input_len;
836 bad |= padding_len == 0;
839 pad_idx = input_len - padding_len;
840 for (
i = 0;
i < input_len - 1;
i++) {
841 bad |=
input[
i] * (
i >= pad_idx);
848 #if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
853 size_t output_len,
size_t data_len)
857 for (
i = data_len;
i < output_len;
i++) {
866 unsigned char done = 0, prev_done;
873 for (
i = input_len;
i > 0;
i--) {
876 *data_len |=
i * (
done != prev_done);
896 *data_len = input_len;
903 unsigned char *
output,
size_t *olen)
908 if (
ctx->cipher_info ==
NULL) {
912 #if defined(MBEDTLS_USE_PSA_CRYPTO)
913 if (
ctx->psa_enabled == 1) {
938 if (
ctx->unprocessed_len != 0) {
945 #if defined(MBEDTLS_CIPHER_MODE_CBC)
951 if (
NULL ==
ctx->add_padding) {
952 if (0 !=
ctx->unprocessed_len) {
960 ctx->unprocessed_len);
966 if (
NULL ==
ctx->add_padding && 0 ==
ctx->unprocessed_len) {
974 if (0 != (ret =
ctx->cipher_info->base->cbc_func(
ctx->cipher_ctx,
999 #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
1009 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1010 if (
ctx->psa_enabled == 1) {
1023 #if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
1029 #if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
1035 #if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
1041 #if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
1060 #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
1062 unsigned char *
tag,
size_t tag_len)
1066 if (
ctx->cipher_info ==
NULL) {
1074 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1075 if (
ctx->psa_enabled == 1) {
1083 #if defined(MBEDTLS_GCM_C)
1090 #if defined(MBEDTLS_CHACHAPOLY_C)
1093 if (tag_len != 16U) {
1106 const unsigned char *
tag,
size_t tag_len)
1108 unsigned char check_tag[16];
1113 if (
ctx->cipher_info ==
NULL) {
1121 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1122 if (
ctx->psa_enabled == 1) {
1136 #if defined(MBEDTLS_GCM_C)
1138 if (tag_len >
sizeof(check_tag)) {
1144 check_tag, tag_len))) {
1156 #if defined(MBEDTLS_CHACHAPOLY_C)
1159 if (tag_len !=
sizeof(check_tag)) {
1187 const unsigned char *iv,
size_t iv_len,
1188 const unsigned char *
input,
size_t ilen,
1189 unsigned char *
output,
size_t *olen)
1200 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1201 if (
ctx->psa_enabled == 1) {
1207 mbedtls_cipher_context_psa *
const cipher_psa =
1208 (mbedtls_cipher_context_psa *)
ctx->cipher_ctx;
1249 output + *olen, ilen - *olen,
1274 &finish_olen)) != 0) {
1278 *olen += finish_olen;
1283 #if defined(MBEDTLS_CIPHER_MODE_AEAD)
1289 const unsigned char *iv,
size_t iv_len,
1290 const unsigned char *ad,
size_t ad_len,
1291 const unsigned char *
input,
size_t ilen,
1292 unsigned char *
output,
size_t *olen,
1293 unsigned char *
tag,
size_t tag_len)
1295 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1296 if (
ctx->psa_enabled == 1) {
1302 mbedtls_cipher_context_psa *
const cipher_psa =
1303 (mbedtls_cipher_context_psa *)
ctx->cipher_ctx;
1318 output, ilen + tag_len, olen);
1328 #if defined(MBEDTLS_GCM_C)
1332 ilen, iv, iv_len, ad, ad_len,
1336 #if defined(MBEDTLS_CCM_C)
1344 #if defined(MBEDTLS_CHACHAPOLY_C)
1347 if ((iv_len !=
ctx->cipher_info->iv_size) ||
1366 const unsigned char *iv,
size_t iv_len,
1367 const unsigned char *ad,
size_t ad_len,
1368 const unsigned char *
input,
size_t ilen,
1369 unsigned char *
output,
size_t *olen,
1370 const unsigned char *
tag,
size_t tag_len)
1372 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1373 if (
ctx->psa_enabled == 1) {
1379 mbedtls_cipher_context_psa *
const cipher_psa =
1380 (mbedtls_cipher_context_psa *)
ctx->cipher_ctx;
1394 input, ilen + tag_len,
1406 #if defined(MBEDTLS_GCM_C)
1412 iv, iv_len, ad, ad_len,
1422 #if defined(MBEDTLS_CCM_C)
1428 iv, iv_len, ad, ad_len,
1438 #if defined(MBEDTLS_CHACHAPOLY_C)
1443 if ((iv_len !=
ctx->cipher_info->iv_size) ||
1463 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
1468 const unsigned char *iv,
size_t iv_len,
1469 const unsigned char *ad,
size_t ad_len,
1470 const unsigned char *
input,
size_t ilen,
1471 unsigned char *
output,
size_t *olen,
1472 unsigned char *
tag,
size_t tag_len)
1491 const unsigned char *iv,
size_t iv_len,
1492 const unsigned char *ad,
size_t ad_len,
1493 const unsigned char *
input,
size_t ilen,
1494 unsigned char *
output,
size_t *olen,
1495 const unsigned char *
tag,
size_t tag_len)
1512 #if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
1517 const unsigned char *iv,
size_t iv_len,
1518 const unsigned char *ad,
size_t ad_len,
1519 const unsigned char *
input,
size_t ilen,
1520 unsigned char *
output,
size_t output_len,
1521 size_t *olen,
size_t tag_len)
1530 #if defined(MBEDTLS_NIST_KW_C)
1532 #
if defined(MBEDTLS_USE_PSA_CRYPTO)
1533 ctx->psa_enabled == 0 &&
1542 if (iv_len != 0 || tag_len != 0 || ad_len != 0) {
1550 output, olen, output_len);
1554 #if defined(MBEDTLS_CIPHER_MODE_AEAD)
1556 if (output_len < ilen + tag_len) {
1574 const unsigned char *iv,
size_t iv_len,
1575 const unsigned char *ad,
size_t ad_len,
1576 const unsigned char *
input,
size_t ilen,
1577 unsigned char *
output,
size_t output_len,
1578 size_t *olen,
size_t tag_len)
1587 #if defined(MBEDTLS_NIST_KW_C)
1589 #
if defined(MBEDTLS_USE_PSA_CRYPTO)
1590 ctx->psa_enabled == 0 &&
1599 if (iv_len != 0 || tag_len != 0 || ad_len != 0) {
1607 output, olen, output_len);
1611 #if defined(MBEDTLS_CIPHER_MODE_AEAD)
1613 if (ilen < tag_len || output_len < ilen - tag_len) {
1619 input + ilen - tag_len, tag_len);
static const struct attribute attributes[]
This file provides an API for the CCM authenticated encryption mode for block ciphers.
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.
#define MBEDTLS_ERR_CCM_AUTH_FAILED
Authenticated decryption failed.
This file contains ChaCha20 definitions and functions.
int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx, const unsigned char nonce[12], uint32_t counter)
This function sets the nonce and initial counter value.
This file contains the AEAD-ChaCha20-Poly1305 definitions and functions.
int mbedtls_chachapoly_finish(mbedtls_chachapoly_context *ctx, unsigned char mac[16])
This function finished the ChaCha20-Poly1305 operation and generates the MAC (authentication tag).
int mbedtls_chachapoly_starts(mbedtls_chachapoly_context *ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode)
This function starts a ChaCha20-Poly1305 encryption or decryption operation.
int mbedtls_chachapoly_update(mbedtls_chachapoly_context *ctx, size_t len, const unsigned char *input, unsigned char *output)
Thus function feeds data to be encrypted or decrypted into an on-going ChaCha20-Poly1305 operation.
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 ...
#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED
Authenticated decryption failed: data was not authentic.
mbedtls_chachapoly_mode_t
@ MBEDTLS_CHACHAPOLY_ENCRYPT
The mode value for performing encryption.
@ MBEDTLS_CHACHAPOLY_DECRYPT
The mode value for performing decryption.
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 ...
int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context *ctx, const unsigned char *aad, size_t aad_len)
This function feeds additional data to be authenticated into an ongoing ChaCha20-Poly1305 operation.
static void add_one_and_zeros_padding(unsigned char *output, size_t output_len, size_t data_len)
static int supported_init
static int get_zeros_and_len_padding(unsigned char *input, size_t input_len, size_t *data_len)
static int get_no_padding(unsigned char *input, size_t input_len, size_t *data_len)
static void add_zeros_padding(unsigned char *output, size_t output_len, size_t data_len)
#define CIPHER_VALIDATE_RET(cond)
static void add_zeros_and_len_padding(unsigned char *output, size_t output_len, size_t data_len)
static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, const unsigned char *tag, size_t tag_len)
static int get_pkcs_padding(unsigned char *input, size_t input_len, size_t *data_len)
static void add_pkcs_padding(unsigned char *output, size_t output_len, size_t data_len)
static int get_one_and_zeros_padding(unsigned char *input, size_t input_len, size_t *data_len)
static int get_zeros_padding(unsigned char *input, size_t input_len, size_t *data_len)
static int mbedtls_cipher_aead_encrypt(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, unsigned char *tag, size_t tag_len)
#define CIPHER_VALIDATE(cond)
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info)
This function initializes a cipher context for use with the given cipher primitive.
mbedtls_cipher_type_t
Supported {cipher type, cipher mode} pairs.
@ MBEDTLS_CIPHER_CHACHA20
ChaCha20 stream cipher.
@ MBEDTLS_CIPHER_CHACHA20_POLY1305
ChaCha20-Poly1305 AEAD cipher.
int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, const unsigned char *key, int key_bitlen, const mbedtls_operation_t operation)
This function sets the key to use with the given context.
#define MBEDTLS_ERR_CIPHER_INVALID_PADDING
Input data contains invalid padding and is rejected.
int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
The generic all-in-one encryption/decryption function, for all ciphers except AEAD constructs.
int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx)
This function resets the cipher state.
#define MBEDTLS_CIPHER_VARIABLE_IV_LEN
Cipher accepts IVs of variable length.
#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED
Cipher hardware accelerator failed.
#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
The selected feature is not available.
int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len)
This function sets the initialization vector (IV) or nonce.
mbedtls_cipher_padding_t
Supported cipher padding types.
@ MBEDTLS_PADDING_ZEROS
Zero padding (not reversible).
@ MBEDTLS_PADDING_ONE_AND_ZEROS
ISO/IEC 7816-4 padding.
@ MBEDTLS_PADDING_PKCS7
PKCS7 padding (default).
@ MBEDTLS_PADDING_ZEROS_AND_LEN
ANSI X.923 padding.
@ MBEDTLS_PADDING_NONE
Never pad (full blocks only).
int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen)
The generic cipher finalization function.
#define MBEDTLS_ERR_CIPHER_AUTH_FAILED
Authentication failed (for AEAD modes).
#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
Bad input parameters.
const int * mbedtls_cipher_list(void)
This function retrieves the list of ciphers supported by the generic cipher module.
void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx)
This function initializes a cipher_context as NONE.
#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN
Cipher accepts keys of variable length.
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_type(const mbedtls_cipher_type_t cipher_type)
This function retrieves the cipher-information structure associated with the given cipher type.
void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx)
This function frees and clears the cipher-specific context of ctx.
static int mbedtls_cipher_get_iv_size(const mbedtls_cipher_context_t *ctx)
This function returns the size of the IV or nonce of the cipher, in Bytes.
int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen)
The generic cipher update function.
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode)
This function retrieves the cipher-information structure associated with the given cipher ID,...
const mbedtls_cipher_info_t * mbedtls_cipher_info_from_string(const char *cipher_name)
This function retrieves the cipher-information structure associated with the given cipher name.
static unsigned int mbedtls_cipher_get_block_size(const mbedtls_cipher_context_t *ctx)
This function returns the block size of the given cipher.
mbedtls_operation_t
Type of operation.
#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED
Failed to allocate memory.
#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED
Decryption of block requires a full block.
mbedtls_cipher_mode_t
Supported cipher modes.
@ MBEDTLS_MODE_ECB
The ECB cipher mode.
@ MBEDTLS_MODE_CCM
The CCM cipher mode.
@ MBEDTLS_MODE_STREAM
The stream cipher mode.
@ MBEDTLS_MODE_CFB
The CFB cipher mode.
@ MBEDTLS_MODE_CTR
The CTR cipher mode.
@ MBEDTLS_MODE_GCM
The GCM cipher mode.
@ MBEDTLS_MODE_KW
The SP800-38F KW mode.
@ MBEDTLS_MODE_CBC
The CBC cipher mode.
@ MBEDTLS_MODE_OFB
The OFB cipher mode.
@ MBEDTLS_MODE_KWP
The SP800-38F KWP mode.
@ MBEDTLS_MODE_XTS
The XTS cipher mode.
#define MBEDTLS_MAX_IV_LENGTH
Maximum length of any IV, in Bytes.
#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT
The context is invalid.
mbedtls_cipher_id_t
Supported cipher types.
const mbedtls_cipher_definition_t mbedtls_cipher_definitions[]
int mbedtls_cipher_supported[]
This file contains CMAC definitions and functions.
int mbedtls_ct_memcmp(const void *a, const void *b, size_t n)
Constant-time functions.
Platform Security Architecture cryptography module.
This file contains GCM definitions and functions.
#define MBEDTLS_GCM_ENCRYPT
int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, int mode, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len)
This function starts a GCM encryption or decryption operation.
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.
int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, unsigned char *tag, size_t tag_len)
This function finishes the GCM operation and generates the authentication tag.
#define MBEDTLS_ERR_GCM_AUTH_FAILED
Authenticated decryption failed.
int mbedtls_gcm_update(mbedtls_gcm_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
This function feeds an input buffer into an ongoing GCM encryption or decryption operation.
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.
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)
Process an authenticated encryption operation.
psa_status_t psa_aead_decrypt(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 *ciphertext, size_t ciphertext_length, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length)
Process an authenticated decryption operation.
static void psa_set_key_usage_flags(psa_key_attributes_t *attributes, psa_key_usage_t usage_flags)
Declare usage flags for a key.
static void psa_set_key_type(psa_key_attributes_t *attributes, psa_key_type_t type)
Declare the type of a key.
#define PSA_KEY_ATTRIBUTES_INIT
This macro returns a suitable initializer for a key attribute structure of type psa_key_attributes_t.
static void psa_set_key_algorithm(psa_key_attributes_t *attributes, psa_algorithm_t alg)
Declare the permitted algorithm policy for a key.
psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, uint8_t *output, size_t output_size, size_t *output_length)
Finish encrypting or decrypting a message in a cipher operation.
#define PSA_CIPHER_OPERATION_INIT
This macro returns a suitable initializer for a cipher operation object of type psa_cipher_operation_...
psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
Set the key for a multipart symmetric encryption operation.
psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation, const uint8_t *iv, size_t iv_length)
Set the IV for a symmetric encryption or decryption operation.
psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, mbedtls_svc_key_id_t key, psa_algorithm_t alg)
Set the key for a multipart symmetric decryption operation.
psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, const uint8_t *input, size_t input_length, uint8_t *output, size_t output_size, size_t *output_length)
Encrypt or decrypt a message fragment in an active cipher operation.
uint16_t psa_key_type_t
Encoding of a key type.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
int32_t psa_status_t
Function return status.
#define PSA_ERROR_NOT_SUPPORTED
The requested operation or a parameter is not supported by this implementation.
#define PSA_ERROR_INVALID_SIGNATURE
The signature, MAC or hash is incorrect.
#define PSA_SUCCESS
The action was completed successfully.
#define PSA_ERROR_INSUFFICIENT_MEMORY
There is not enough runtime memory.
psa_status_t psa_import_key(const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, mbedtls_svc_key_id_t *key)
Import a key in binary format.
psa_status_t psa_destroy_key(mbedtls_svc_key_id_t key)
Destroy a key.
#define PSA_KEY_USAGE_ENCRYPT
Whether the key may be used to encrypt a message.
#define PSA_KEY_USAGE_DECRYPT
Whether the key may be used to decrypt a message.
if(yy_accept[yy_current_state])
const struct ncbi::grid::netcache::search::fields::KEY key
int strcmp(const char *str1, const char *str2)
#define mbedtls_cipher_write_tag
#define mbedtls_cipher_auth_decrypt
#define mbedtls_cipher_update_ad
#define mbedtls_cipher_auth_decrypt_ext
#define mbedtls_cipher_auth_encrypt
#define mbedtls_cipher_check_tag
#define mbedtls_cipher_set_padding_mode
#define mbedtls_cipher_auth_encrypt_ext
This file provides an API for key wrapping (KW) and key wrapping with padding (KWP) as defined in NIS...
int mbedtls_nist_kw_wrap(mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode, const unsigned char *input, size_t in_len, unsigned char *output, size_t *out_len, size_t out_size)
This function encrypts a buffer using key wrapping.
int mbedtls_nist_kw_unwrap(mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode, const unsigned char *input, size_t in_len, unsigned char *output, size_t *out_len, size_t out_size)
This function decrypts a buffer using key wrapping.
static SQLCHAR output[256]
Utility functions for the use of the PSA Crypto library.
Error to string translation.
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED
This is a bug in the library.
mbedtls_cipher_id_t cipher
Base Cipher type (e.g.
void *(* ctx_alloc_func)(void)
Allocate a new context.
mbedtls_cipher_type_t type
const mbedtls_cipher_info_t * info
unsigned int key_bitlen
The cipher key length, in bits.
mbedtls_cipher_type_t type
Full cipher identifier.
mbedtls_cipher_mode_t mode
The cipher mode.
const char * name
Name of the cipher.
const mbedtls_cipher_base_t * base
Struct for base cipher information and functions.
The CMAC context structure.
The GCM context structure.