- return quic_crypto_cipher_setup_crypto (ctx, 1, key, EVP_aes_256_ctr (),
- quic_crypto_cipher_encrypt);
-}
-
-#endif // QUIC_HP_CRYPTO
-
-void
-quic_crypto_aead_encrypt_init (ptls_aead_context_t * _ctx, const void *iv,
- const void *aad, size_t aadlen)
-{
- quic_main_t *qm = &quic_main;
- u32 thread_index = vlib_get_thread_index ();
-
- struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
-
- vnet_crypto_op_id_t id;
- if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
- {
- id = VNET_CRYPTO_OP_AES_128_GCM_ENC;
- }
- else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
- {
- id = VNET_CRYPTO_OP_AES_256_GCM_ENC;
- }
- else
- {
- assert (0);
- }
-
- quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
- &qm->wrk_ctx[thread_index].crypto_context_batch;
-
- vnet_crypto_op_t *vnet_op =
- &quic_crypto_batch_ctx->aead_crypto_tx_packets_ops
- [quic_crypto_batch_ctx->nb_tx_packets];
- vnet_crypto_op_init (vnet_op, id);
- vnet_op->aad = (u8 *) aad;
- vnet_op->aad_len = aadlen;
- vnet_op->iv = clib_mem_alloc (PTLS_MAX_IV_SIZE);
- clib_memcpy (vnet_op->iv, iv, PTLS_MAX_IV_SIZE);
- vnet_op->key_index = ctx->key_index;
-}
-
-size_t
-quic_crypto_aead_encrypt_update (ptls_aead_context_t * _ctx, void *output,
- const void *input, size_t inlen)
-{
- struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
-
- quic_main_t *qm = &quic_main;
- u32 thread_index = vlib_get_thread_index ();
- quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
- &qm->wrk_ctx[thread_index].crypto_context_batch;
-
- vnet_crypto_op_t *vnet_op =
- &quic_crypto_batch_ctx->aead_crypto_tx_packets_ops
- [quic_crypto_batch_ctx->nb_tx_packets];
- vnet_op->src = (u8 *) input;
- vnet_op->dst = output;
- vnet_op->len = inlen;
- vnet_op->tag_len = ctx->super.algo->tag_size;
-
- vnet_op->tag = vnet_op->src + inlen;
-
- return 0;
-}
-
-size_t
-quic_crypto_aead_encrypt_final (ptls_aead_context_t * _ctx, void *output)
-{
- quic_main_t *qm = &quic_main;
- u32 thread_index = vlib_get_thread_index ();
- quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
- &qm->wrk_ctx[thread_index].crypto_context_batch;
-
- vnet_crypto_op_t *vnet_op =
- &quic_crypto_batch_ctx->
- aead_crypto_tx_packets_ops[quic_crypto_batch_ctx->nb_tx_packets];
- quic_crypto_batch_ctx->nb_tx_packets++;
- return vnet_op->len + vnet_op->tag_len;
-}
-
-size_t
-quic_crypto_aead_decrypt (ptls_aead_context_t * _ctx, void *_output,
- const void *input, size_t inlen, const void *iv,
- const void *aad, size_t aadlen)
-{
- vlib_main_t *vm = vlib_get_main ();
- struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
-
- vnet_crypto_op_id_t id;
- if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
- {
- id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
- }
- else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
- {
- id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
- }
- else
- {
- assert (0);
- }
-
- vnet_crypto_op_init (&ctx->op, id);
- ctx->op.aad = (u8 *) aad;
- ctx->op.aad_len = aadlen;
- ctx->op.iv = (u8 *) iv;
-
- ctx->op.src = (u8 *) input;
- ctx->op.dst = _output;
- ctx->op.key_index = ctx->key_index;
- ctx->op.len = inlen - ctx->super.algo->tag_size;
-
- ctx->op.tag_len = ctx->super.algo->tag_size;
- ctx->op.tag = ctx->op.src + ctx->op.len;
-
- vnet_crypto_process_ops (vm, &ctx->op, 1);
-
- if (ctx->op.status != VNET_CRYPTO_OP_STATUS_COMPLETED)
- return SIZE_MAX;
-
- return ctx->op.len;
-}
-
-static size_t
-quic_crypto_offload_aead_decrypt (quic_ctx_t * qctx,
- ptls_aead_context_t * _ctx, void *_output,
- const void *input, size_t inlen,
- uint64_t decrypted_pn, const void *aad,
- size_t aadlen)
-{
- struct aead_crypto_context_t *ctx = (struct aead_crypto_context_t *) _ctx;
- vnet_crypto_op_id_t id;
- if (!strcmp (ctx->super.algo->name, "AES128-GCM"))
- {
- id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
- }
- else if (!strcmp (ctx->super.algo->name, "AES256-GCM"))
- {
- id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
- }
- else
- {
- return SIZE_MAX;
- }
-
- quic_main_t *qm = &quic_main;
- quic_crypto_batch_ctx_t *quic_crypto_batch_ctx =
- &qm->wrk_ctx[qctx->c_thread_index].crypto_context_batch;
-
- vnet_crypto_op_t *vnet_op =
- &quic_crypto_batch_ctx->aead_crypto_rx_packets_ops
- [quic_crypto_batch_ctx->nb_rx_packets];
-
- vnet_crypto_op_init (vnet_op, id);
- vnet_op->aad = (u8 *) aad;
- vnet_op->aad_len = aadlen;
- vnet_op->iv = clib_mem_alloc (PTLS_MAX_IV_SIZE);
- build_iv (_ctx, vnet_op->iv, decrypted_pn);
- vnet_op->src = (u8 *) input;
- vnet_op->dst = _output;
- vnet_op->key_index = ctx->key_index;
- vnet_op->len = inlen - ctx->super.algo->tag_size;
- vnet_op->tag_len = ctx->super.algo->tag_size;
- vnet_op->tag = vnet_op->src + vnet_op->len;
- quic_crypto_batch_ctx->nb_rx_packets++;
- return vnet_op->len;
-}
-
-static void
-quic_crypto_aead_dispose_crypto (ptls_aead_context_t * _ctx)
-{
-