Lines Matching refs:ctx
202 void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx) in mbedtls_cipher_init() argument
204 memset(ctx, 0, sizeof(mbedtls_cipher_context_t)); in mbedtls_cipher_init()
207 void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx) in mbedtls_cipher_free() argument
209 if (ctx == NULL) { in mbedtls_cipher_free()
214 if (ctx->psa_enabled == 1) { in mbedtls_cipher_free()
215 if (ctx->cipher_ctx != NULL) { in mbedtls_cipher_free()
217 (mbedtls_cipher_context_psa *) ctx->cipher_ctx; in mbedtls_cipher_free()
227 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_cipher_context_t)); in mbedtls_cipher_free()
233 if (ctx->cmac_ctx) { in mbedtls_cipher_free()
234 mbedtls_zeroize_and_free(ctx->cmac_ctx, in mbedtls_cipher_free()
239 if (ctx->cipher_ctx) { in mbedtls_cipher_free()
240 mbedtls_cipher_get_base(ctx->cipher_info)->ctx_free_func(ctx->cipher_ctx); in mbedtls_cipher_free()
243 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_cipher_context_t)); in mbedtls_cipher_free()
275 int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_setup() argument
282 memset(ctx, 0, sizeof(mbedtls_cipher_context_t)); in mbedtls_cipher_setup()
285 ctx->cipher_ctx = mbedtls_cipher_get_base(cipher_info)->ctx_alloc_func(); in mbedtls_cipher_setup()
286 if (ctx->cipher_ctx == NULL) { in mbedtls_cipher_setup()
291 ctx->cipher_info = cipher_info; in mbedtls_cipher_setup()
297 int mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_setup_psa() argument
304 if (NULL == cipher_info || NULL == ctx) { in mbedtls_cipher_setup_psa()
318 memset(ctx, 0, sizeof(mbedtls_cipher_context_t)); in mbedtls_cipher_setup_psa()
325 ctx->cipher_ctx = cipher_psa; in mbedtls_cipher_setup_psa()
326 ctx->cipher_info = cipher_info; in mbedtls_cipher_setup_psa()
327 ctx->psa_enabled = 1; in mbedtls_cipher_setup_psa()
332 int mbedtls_cipher_setup_info(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_setup_info() argument
335 if (NULL == cipher_info || NULL == ctx) in mbedtls_cipher_setup_info()
338 ctx->cipher_info = cipher_info; in mbedtls_cipher_setup_info()
342 int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_setkey() argument
350 if (ctx->cipher_info == NULL) { in mbedtls_cipher_setkey()
354 if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) && in mbedtls_cipher_setkey()
361 if (ctx->psa_enabled == 1) { in mbedtls_cipher_setkey()
363 (mbedtls_cipher_context_psa *) ctx->cipher_ctx; in mbedtls_cipher_setkey()
382 ((mbedtls_cipher_type_t) ctx->cipher_info->type)); in mbedtls_cipher_setkey()
412 ctx->key_bitlen = key_bitlen; in mbedtls_cipher_setkey()
413 ctx->operation = operation; in mbedtls_cipher_setkey()
418 if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN) == 0 && in mbedtls_cipher_setkey()
419 (int) mbedtls_cipher_info_get_key_bitlen(ctx->cipher_info) != key_bitlen) { in mbedtls_cipher_setkey()
423 ctx->key_bitlen = key_bitlen; in mbedtls_cipher_setkey()
424 ctx->operation = operation; in mbedtls_cipher_setkey()
431 MBEDTLS_MODE_CFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_setkey()
432 MBEDTLS_MODE_OFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_setkey()
433 MBEDTLS_MODE_CTR == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_setkey()
434 return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key, in mbedtls_cipher_setkey()
435 ctx->key_bitlen); in mbedtls_cipher_setkey()
439 return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_dec_func(ctx->cipher_ctx, key, in mbedtls_cipher_setkey()
440 ctx->key_bitlen); in mbedtls_cipher_setkey()
444 return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key, in mbedtls_cipher_setkey()
445 ctx->key_bitlen); in mbedtls_cipher_setkey()
452 int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_set_iv() argument
458 if (ctx->cipher_info == NULL) { in mbedtls_cipher_set_iv()
462 if (ctx->psa_enabled == 1) { in mbedtls_cipher_set_iv()
475 if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_IV_LEN) != 0) { in mbedtls_cipher_set_iv()
478 actual_iv_size = mbedtls_cipher_info_get_iv_size(ctx->cipher_info); in mbedtls_cipher_set_iv()
487 if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20) { in mbedtls_cipher_set_iv()
495 if (0 != mbedtls_chacha20_starts((mbedtls_chacha20_context *) ctx->cipher_ctx, in mbedtls_cipher_set_iv()
502 if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20_POLY1305 && in mbedtls_cipher_set_iv()
510 if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_set_iv()
511 return mbedtls_gcm_starts((mbedtls_gcm_context *) ctx->cipher_ctx, in mbedtls_cipher_set_iv()
512 ctx->operation, in mbedtls_cipher_set_iv()
518 if (MBEDTLS_MODE_CCM_STAR_NO_TAG == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_set_iv()
523 (mbedtls_ccm_context *) ctx->cipher_ctx, in mbedtls_cipher_set_iv()
529 if (ctx->operation == MBEDTLS_DECRYPT) { in mbedtls_cipher_set_iv()
531 } else if (ctx->operation == MBEDTLS_ENCRYPT) { in mbedtls_cipher_set_iv()
537 return mbedtls_ccm_starts((mbedtls_ccm_context *) ctx->cipher_ctx, in mbedtls_cipher_set_iv()
544 memcpy(ctx->iv, iv, actual_iv_size); in mbedtls_cipher_set_iv()
545 ctx->iv_size = actual_iv_size; in mbedtls_cipher_set_iv()
551 int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx) in mbedtls_cipher_reset() argument
553 if (ctx->cipher_info == NULL) { in mbedtls_cipher_reset()
558 if (ctx->psa_enabled == 1) { in mbedtls_cipher_reset()
565 ctx->unprocessed_len = 0; in mbedtls_cipher_reset()
571 int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_update_ad() argument
574 if (ctx->cipher_info == NULL) { in mbedtls_cipher_update_ad()
579 if (ctx->psa_enabled == 1) { in mbedtls_cipher_update_ad()
588 if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_update_ad()
589 return mbedtls_gcm_update_ad((mbedtls_gcm_context *) ctx->cipher_ctx, in mbedtls_cipher_update_ad()
595 if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { in mbedtls_cipher_update_ad()
599 mode = (ctx->operation == MBEDTLS_ENCRYPT) in mbedtls_cipher_update_ad()
603 result = mbedtls_chachapoly_starts((mbedtls_chachapoly_context *) ctx->cipher_ctx, in mbedtls_cipher_update_ad()
604 ctx->iv, in mbedtls_cipher_update_ad()
610 return mbedtls_chachapoly_update_aad((mbedtls_chachapoly_context *) ctx->cipher_ctx, in mbedtls_cipher_update_ad()
619 int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *input, in mbedtls_cipher_update() argument
625 if (ctx->cipher_info == NULL) { in mbedtls_cipher_update()
630 if (ctx->psa_enabled == 1) { in mbedtls_cipher_update()
639 block_size = mbedtls_cipher_get_block_size(ctx); in mbedtls_cipher_update()
644 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_ECB) { in mbedtls_cipher_update()
651 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ecb_func(ctx->cipher_ctx, in mbedtls_cipher_update()
652 ctx->operation, input, in mbedtls_cipher_update()
661 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_GCM) { in mbedtls_cipher_update()
662 return mbedtls_gcm_update((mbedtls_gcm_context *) ctx->cipher_ctx, in mbedtls_cipher_update()
669 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CCM_STAR_NO_TAG) { in mbedtls_cipher_update()
670 return mbedtls_ccm_update((mbedtls_ccm_context *) ctx->cipher_ctx, in mbedtls_cipher_update()
677 if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20_POLY1305) { in mbedtls_cipher_update()
679 return mbedtls_chachapoly_update((mbedtls_chachapoly_context *) ctx->cipher_ctx, in mbedtls_cipher_update()
685 (ctx->unprocessed_len != 0 || ilen % block_size)) { in mbedtls_cipher_update()
690 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CBC) { in mbedtls_cipher_update()
696 if ((ctx->operation == MBEDTLS_DECRYPT && NULL != ctx->add_padding && in mbedtls_cipher_update()
697 ilen <= block_size - ctx->unprocessed_len) || in mbedtls_cipher_update()
698 (ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding && in mbedtls_cipher_update()
699 ilen < block_size - ctx->unprocessed_len) || in mbedtls_cipher_update()
700 (ctx->operation == MBEDTLS_ENCRYPT && in mbedtls_cipher_update()
701 ilen < block_size - ctx->unprocessed_len)) { in mbedtls_cipher_update()
702 memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input, in mbedtls_cipher_update()
705 ctx->unprocessed_len += ilen; in mbedtls_cipher_update()
712 if (0 != ctx->unprocessed_len) { in mbedtls_cipher_update()
713 copy_len = block_size - ctx->unprocessed_len; in mbedtls_cipher_update()
715 memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input, in mbedtls_cipher_update()
718 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx, in mbedtls_cipher_update()
719 ctx->operation, in mbedtls_cipher_update()
720 block_size, ctx->iv, in mbedtls_cipher_update()
721 ctx-> in mbedtls_cipher_update()
729 ctx->unprocessed_len = 0; in mbedtls_cipher_update()
745 ctx->operation == MBEDTLS_DECRYPT && in mbedtls_cipher_update()
746 NULL != ctx->add_padding) { in mbedtls_cipher_update()
750 memcpy(ctx->unprocessed_data, &(input[ilen - copy_len]), in mbedtls_cipher_update()
753 ctx->unprocessed_len += copy_len; in mbedtls_cipher_update()
761 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx, in mbedtls_cipher_update()
762 ctx->operation, in mbedtls_cipher_update()
763 ilen, ctx->iv, in mbedtls_cipher_update()
777 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CFB) { in mbedtls_cipher_update()
778 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cfb_func(ctx->cipher_ctx, in mbedtls_cipher_update()
779 ctx->operation, ilen, in mbedtls_cipher_update()
780 &ctx->unprocessed_len, in mbedtls_cipher_update()
781 ctx->iv, in mbedtls_cipher_update()
793 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_OFB) { in mbedtls_cipher_update()
794 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ofb_func(ctx->cipher_ctx, in mbedtls_cipher_update()
796 &ctx->unprocessed_len, in mbedtls_cipher_update()
797 ctx->iv, in mbedtls_cipher_update()
809 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CTR) { in mbedtls_cipher_update()
810 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ctr_func(ctx->cipher_ctx, in mbedtls_cipher_update()
812 &ctx->unprocessed_len, in mbedtls_cipher_update()
813 ctx->iv, in mbedtls_cipher_update()
814 ctx->unprocessed_data, in mbedtls_cipher_update()
826 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_XTS) { in mbedtls_cipher_update()
827 if (ctx->unprocessed_len > 0) { in mbedtls_cipher_update()
832 ret = mbedtls_cipher_get_base(ctx->cipher_info)->xts_func(ctx->cipher_ctx, in mbedtls_cipher_update()
833 ctx->operation, in mbedtls_cipher_update()
835 ctx->iv, in mbedtls_cipher_update()
849 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_STREAM) { in mbedtls_cipher_update()
850 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->stream_func(ctx->cipher_ctx, in mbedtls_cipher_update()
1059 int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_finish() argument
1062 if (ctx->cipher_info == NULL) { in mbedtls_cipher_finish()
1067 if (ctx->psa_enabled == 1) { in mbedtls_cipher_finish()
1080 if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_finish()
1081 if (ctx->get_padding == NULL) { in mbedtls_cipher_finish()
1087 if (MBEDTLS_MODE_CFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_finish()
1088 MBEDTLS_MODE_OFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_finish()
1089 MBEDTLS_MODE_CTR == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_finish()
1090 MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_finish()
1091 MBEDTLS_MODE_CCM_STAR_NO_TAG == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_finish()
1092 MBEDTLS_MODE_XTS == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_finish()
1093 MBEDTLS_MODE_STREAM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_finish()
1097 if ((MBEDTLS_CIPHER_CHACHA20 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) || in mbedtls_cipher_finish()
1098 (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type))) { in mbedtls_cipher_finish()
1102 if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_finish()
1103 if (ctx->unprocessed_len != 0) { in mbedtls_cipher_finish()
1111 if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_finish()
1114 if (MBEDTLS_ENCRYPT == ctx->operation) { in mbedtls_cipher_finish()
1116 if (NULL == ctx->add_padding) { in mbedtls_cipher_finish()
1117 if (0 != ctx->unprocessed_len) { in mbedtls_cipher_finish()
1124 ctx->add_padding(ctx->unprocessed_data, mbedtls_cipher_get_iv_size(ctx), in mbedtls_cipher_finish()
1125 ctx->unprocessed_len); in mbedtls_cipher_finish()
1126 } else if (mbedtls_cipher_get_block_size(ctx) != ctx->unprocessed_len) { in mbedtls_cipher_finish()
1131 if (NULL == ctx->add_padding && 0 == ctx->unprocessed_len) { in mbedtls_cipher_finish()
1139 if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx, in mbedtls_cipher_finish()
1140 ctx->operation, in mbedtls_cipher_finish()
1142 ctx), in mbedtls_cipher_finish()
1143 ctx->iv, in mbedtls_cipher_finish()
1144 ctx->unprocessed_data, in mbedtls_cipher_finish()
1150 if (MBEDTLS_DECRYPT == ctx->operation) { in mbedtls_cipher_finish()
1151 return ctx->get_padding(output, mbedtls_cipher_get_block_size(ctx), in mbedtls_cipher_finish()
1156 *olen = mbedtls_cipher_get_block_size(ctx); in mbedtls_cipher_finish()
1167 int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_set_padding_mode() argument
1170 if (NULL == ctx->cipher_info || in mbedtls_cipher_set_padding_mode()
1171 MBEDTLS_MODE_CBC != ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_set_padding_mode()
1176 if (ctx->psa_enabled == 1) { in mbedtls_cipher_set_padding_mode()
1191 ctx->add_padding = add_pkcs_padding; in mbedtls_cipher_set_padding_mode()
1192 ctx->get_padding = mbedtls_get_pkcs_padding; in mbedtls_cipher_set_padding_mode()
1197 ctx->add_padding = add_one_and_zeros_padding; in mbedtls_cipher_set_padding_mode()
1198 ctx->get_padding = get_one_and_zeros_padding; in mbedtls_cipher_set_padding_mode()
1203 ctx->add_padding = add_zeros_and_len_padding; in mbedtls_cipher_set_padding_mode()
1204 ctx->get_padding = get_zeros_and_len_padding; in mbedtls_cipher_set_padding_mode()
1209 ctx->add_padding = add_zeros_padding; in mbedtls_cipher_set_padding_mode()
1210 ctx->get_padding = get_zeros_padding; in mbedtls_cipher_set_padding_mode()
1214 ctx->add_padding = NULL; in mbedtls_cipher_set_padding_mode()
1215 ctx->get_padding = get_no_padding; in mbedtls_cipher_set_padding_mode()
1227 int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_write_tag() argument
1230 if (ctx->cipher_info == NULL) { in mbedtls_cipher_write_tag()
1234 if (MBEDTLS_ENCRYPT != ctx->operation) { in mbedtls_cipher_write_tag()
1239 if (ctx->psa_enabled == 1) { in mbedtls_cipher_write_tag()
1248 if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_write_tag()
1252 return mbedtls_gcm_finish((mbedtls_gcm_context *) ctx->cipher_ctx, in mbedtls_cipher_write_tag()
1259 if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { in mbedtls_cipher_write_tag()
1266 (mbedtls_chachapoly_context *) ctx->cipher_ctx, tag); in mbedtls_cipher_write_tag()
1273 int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_check_tag() argument
1279 if (ctx->cipher_info == NULL) { in mbedtls_cipher_check_tag()
1283 if (MBEDTLS_DECRYPT != ctx->operation) { in mbedtls_cipher_check_tag()
1288 if (ctx->psa_enabled == 1) { in mbedtls_cipher_check_tag()
1300 if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_check_tag()
1310 (mbedtls_gcm_context *) ctx->cipher_ctx, in mbedtls_cipher_check_tag()
1325 if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { in mbedtls_cipher_check_tag()
1332 (mbedtls_chachapoly_context *) ctx->cipher_ctx, check_tag); in mbedtls_cipher_check_tag()
1354 int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_crypt() argument
1363 if (ctx->psa_enabled == 1) { in mbedtls_cipher_crypt()
1370 (mbedtls_cipher_context_psa *) ctx->cipher_ctx; in mbedtls_cipher_crypt()
1376 if (ctx->operation == MBEDTLS_DECRYPT) { in mbedtls_cipher_crypt()
1380 } else if (ctx->operation == MBEDTLS_ENCRYPT) { in mbedtls_cipher_crypt()
1396 if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) != MBEDTLS_MODE_ECB) { in mbedtls_cipher_crypt()
1422 if ((ret = mbedtls_cipher_set_iv(ctx, iv, iv_len)) != 0) { in mbedtls_cipher_crypt()
1426 if ((ret = mbedtls_cipher_reset(ctx)) != 0) { in mbedtls_cipher_crypt()
1430 if ((ret = mbedtls_cipher_update(ctx, input, ilen, in mbedtls_cipher_crypt()
1435 if ((ret = mbedtls_cipher_finish(ctx, output + *olen, in mbedtls_cipher_crypt()
1450 static int mbedtls_cipher_aead_encrypt(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_aead_encrypt() argument
1458 if (ctx->psa_enabled == 1) { in mbedtls_cipher_aead_encrypt()
1465 (mbedtls_cipher_context_psa *) ctx->cipher_ctx; in mbedtls_cipher_aead_encrypt()
1491 if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_aead_encrypt()
1493 return mbedtls_gcm_crypt_and_tag(ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, in mbedtls_cipher_aead_encrypt()
1499 if (MBEDTLS_MODE_CCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_aead_encrypt()
1501 return mbedtls_ccm_encrypt_and_tag(ctx->cipher_ctx, ilen, in mbedtls_cipher_aead_encrypt()
1507 if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { in mbedtls_cipher_aead_encrypt()
1509 if ((iv_len != mbedtls_cipher_info_get_iv_size(ctx->cipher_info)) || in mbedtls_cipher_aead_encrypt()
1515 return mbedtls_chachapoly_encrypt_and_tag(ctx->cipher_ctx, in mbedtls_cipher_aead_encrypt()
1527 static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_aead_decrypt() argument
1535 if (ctx->psa_enabled == 1) { in mbedtls_cipher_aead_decrypt()
1542 (mbedtls_cipher_context_psa *) ctx->cipher_ctx; in mbedtls_cipher_aead_decrypt()
1569 if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_aead_decrypt()
1573 ret = mbedtls_gcm_auth_decrypt(ctx->cipher_ctx, ilen, in mbedtls_cipher_aead_decrypt()
1585 if (MBEDTLS_MODE_CCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { in mbedtls_cipher_aead_decrypt()
1589 ret = mbedtls_ccm_auth_decrypt(ctx->cipher_ctx, ilen, in mbedtls_cipher_aead_decrypt()
1601 if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { in mbedtls_cipher_aead_decrypt()
1605 if ((iv_len != mbedtls_cipher_info_get_iv_size(ctx->cipher_info)) || in mbedtls_cipher_aead_decrypt()
1611 ret = mbedtls_chachapoly_auth_decrypt(ctx->cipher_ctx, ilen, in mbedtls_cipher_aead_decrypt()
1630 int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_auth_encrypt_ext() argument
1640 ctx->psa_enabled == 0 && in mbedtls_cipher_auth_encrypt_ext()
1642 (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_auth_encrypt_ext()
1643 MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode))) { in mbedtls_cipher_auth_encrypt_ext()
1645 (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) ? in mbedtls_cipher_auth_encrypt_ext()
1657 return mbedtls_nist_kw_wrap(ctx->cipher_ctx, mode, input, ilen, in mbedtls_cipher_auth_encrypt_ext()
1668 int ret = mbedtls_cipher_aead_encrypt(ctx, iv, iv_len, ad, ad_len, in mbedtls_cipher_auth_encrypt_ext()
1681 int mbedtls_cipher_auth_decrypt_ext(mbedtls_cipher_context_t *ctx, in mbedtls_cipher_auth_decrypt_ext() argument
1691 ctx->psa_enabled == 0 && in mbedtls_cipher_auth_decrypt_ext()
1693 (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || in mbedtls_cipher_auth_decrypt_ext()
1694 MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode))) { in mbedtls_cipher_auth_decrypt_ext()
1696 (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) ? in mbedtls_cipher_auth_decrypt_ext()
1708 return mbedtls_nist_kw_unwrap(ctx->cipher_ctx, mode, input, ilen, in mbedtls_cipher_auth_decrypt_ext()
1719 return mbedtls_cipher_aead_decrypt(ctx, iv, iv_len, ad, ad_len, in mbedtls_cipher_auth_decrypt_ext()