2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "internal/quic_record_tx.h"
11 #include "internal/bio_addr.h"
12 #include "internal/common.h"
13 #include "quic_record_shared.h"
14 #include "internal/list.h"
15 #include "../ssl_local.h"
20 * Encrypted packets awaiting transmission are kept in TX Entries (TXEs), which
21 * are queued in linked lists just like TXEs.
23 typedef struct txe_st TXE;
26 OSSL_LIST_MEMBER(txe, TXE);
27 size_t data_len, alloc_len;
30 * Destination and local addresses, as applicable. Both of these are only
31 * used if the family is not AF_UNSPEC.
36 * alloc_len allocated bytes (of which data_len bytes are valid) follow this
41 DEFINE_LIST_OF(txe, TXE);
42 typedef OSSL_LIST(txe) TXE_LIST;
44 static ossl_inline unsigned char *txe_data(const TXE *e)
46 return (unsigned char *)(e + 1);
57 /* Per encryption-level state. */
58 OSSL_QRL_ENC_LEVEL_SET el_set;
63 /* TX maximum datagram payload length. */
67 * List of TXEs which are not currently in use. These are moved to the
68 * pending list (possibly via tx_cons first) as they are filled.
73 * List of TXEs which are filled with completed datagrams ready to be
77 size_t pending_count; /* items in list */
78 size_t pending_bytes; /* sum(txe->data_len) in pending */
81 * TXE which is under construction for coalescing purposes, if any.
82 * This TXE is neither on the free nor pending list. Once the datagram
83 * is completed, it is moved to the pending list.
86 size_t cons_count; /* num packets */
89 * Number of packets transmitted in this key epoch. Used to enforce AEAD
90 * confidentiality limit.
92 uint64_t epoch_pkt_count;
94 ossl_mutate_packet_cb mutatecb;
95 ossl_finish_mutate_cb finishmutatecb;
98 /* Message callback related arguments */
99 ossl_msg_cb msg_callback;
100 void *msg_callback_arg;
104 /* Instantiates a new QTX. */
105 OSSL_QTX *ossl_qtx_new(const OSSL_QTX_ARGS *args)
109 if (args->mdpl < QUIC_MIN_INITIAL_DGRAM_LEN)
112 qtx = OPENSSL_zalloc(sizeof(OSSL_QTX));
116 qtx->libctx = args->libctx;
117 qtx->propq = args->propq;
118 qtx->bio = args->bio;
119 qtx->mdpl = args->mdpl;
120 qtx->msg_callback = args->msg_callback;
121 qtx->msg_callback_arg = args->msg_callback_arg;
122 qtx->msg_callback_s = args->msg_callback_s;
126 static void qtx_cleanup_txl(TXE_LIST *l)
130 for (e = ossl_list_txe_head(l); e != NULL; e = enext) {
131 enext = ossl_list_txe_next(e);
137 void ossl_qtx_free(OSSL_QTX *qtx)
144 /* Free TXE queue data. */
145 qtx_cleanup_txl(&qtx->pending);
146 qtx_cleanup_txl(&qtx->free);
147 OPENSSL_free(qtx->cons);
149 /* Drop keying material and crypto resources. */
150 for (i = 0; i < QUIC_ENC_LEVEL_NUM; ++i)
151 ossl_qrl_enc_level_set_discard(&qtx->el_set, i);
156 /* Set mutator callbacks for test framework support */
157 void ossl_qtx_set_mutator(OSSL_QTX *qtx, ossl_mutate_packet_cb mutatecb,
158 ossl_finish_mutate_cb finishmutatecb, void *mutatearg)
160 qtx->mutatecb = mutatecb;
161 qtx->finishmutatecb = finishmutatecb;
162 qtx->mutatearg = mutatearg;
165 int ossl_qtx_provide_secret(OSSL_QTX *qtx,
169 const unsigned char *secret,
172 if (enc_level >= QUIC_ENC_LEVEL_NUM)
175 return ossl_qrl_enc_level_set_provide_secret(&qtx->el_set,
187 int ossl_qtx_discard_enc_level(OSSL_QTX *qtx, uint32_t enc_level)
189 if (enc_level >= QUIC_ENC_LEVEL_NUM)
192 ossl_qrl_enc_level_set_discard(&qtx->el_set, enc_level);
196 int ossl_qtx_is_enc_level_provisioned(OSSL_QTX *qtx, uint32_t enc_level)
198 return ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1) != NULL;
201 /* Allocate a new TXE. */
202 static TXE *qtx_alloc_txe(size_t alloc_len)
206 if (alloc_len >= SIZE_MAX - sizeof(TXE))
209 txe = OPENSSL_malloc(sizeof(TXE) + alloc_len);
213 ossl_list_txe_init_elem(txe);
214 txe->alloc_len = alloc_len;
220 * Ensures there is at least one TXE in the free list, allocating a new entry
221 * if necessary. The returned TXE is in the free list; it is not popped.
223 * alloc_len is a hint which may be used to determine the TXE size if allocation
224 * is necessary. Returns NULL on allocation failure.
226 static TXE *qtx_ensure_free_txe(OSSL_QTX *qtx, size_t alloc_len)
230 txe = ossl_list_txe_head(&qtx->free);
234 txe = qtx_alloc_txe(alloc_len);
238 ossl_list_txe_insert_tail(&qtx->free, txe);
243 * Resize the data buffer attached to an TXE to be n bytes in size. The address
244 * of the TXE might change; the new address is returned, or NULL on failure, in
245 * which case the original TXE remains valid.
247 static TXE *qtx_resize_txe(OSSL_QTX *qtx, TXE_LIST *txl, TXE *txe, size_t n)
251 /* Should never happen. */
255 if (n >= SIZE_MAX - sizeof(TXE))
258 /* Remove the item from the list to avoid accessing freed memory */
259 p = ossl_list_txe_prev(txe);
260 ossl_list_txe_remove(txl, txe);
263 * NOTE: We do not clear old memory, although it does contain decrypted
266 txe2 = OPENSSL_realloc(txe, sizeof(TXE) + n);
267 if (txe2 == NULL || txe == txe2) {
269 ossl_list_txe_insert_head(txl, txe);
271 ossl_list_txe_insert_after(txl, p, txe);
276 ossl_list_txe_insert_head(txl, txe2);
278 ossl_list_txe_insert_after(txl, p, txe2);
280 if (qtx->cons == txe)
288 * Ensure the data buffer attached to an TXE is at least n bytes in size.
289 * Returns NULL on failure.
291 static TXE *qtx_reserve_txe(OSSL_QTX *qtx, TXE_LIST *txl,
294 if (txe->alloc_len >= n)
297 return qtx_resize_txe(qtx, txl, txe, n);
300 /* Move a TXE from pending to free. */
301 static void qtx_pending_to_free(OSSL_QTX *qtx)
303 TXE *txe = ossl_list_txe_head(&qtx->pending);
306 ossl_list_txe_remove(&qtx->pending, txe);
307 --qtx->pending_count;
308 qtx->pending_bytes -= txe->data_len;
309 ossl_list_txe_insert_tail(&qtx->free, txe);
312 /* Add a TXE not currently in any list to the pending list. */
313 static void qtx_add_to_pending(OSSL_QTX *qtx, TXE *txe)
315 ossl_list_txe_insert_tail(&qtx->pending, txe);
316 ++qtx->pending_count;
317 qtx->pending_bytes += txe->data_len;
321 const OSSL_QTX_IOVEC *iovec;
322 size_t num_iovec, idx, byte_off, bytes_remaining;
325 static size_t iovec_total_bytes(const OSSL_QTX_IOVEC *iovec,
330 for (i = 0; i < num_iovec; ++i)
331 l += iovec[i].buf_len;
336 static void iovec_cur_init(struct iovec_cur *cur,
337 const OSSL_QTX_IOVEC *iovec,
341 cur->num_iovec = num_iovec;
344 cur->bytes_remaining = iovec_total_bytes(iovec, num_iovec);
348 * Get an extent of bytes from the iovec cursor. *buf is set to point to the
349 * buffer and the number of bytes in length of the buffer is returned. This
350 * value may be less than the max_buf_len argument. If no more data is
351 * available, returns 0.
353 static size_t iovec_cur_get_buffer(struct iovec_cur *cur,
354 const unsigned char **buf,
359 if (max_buf_len == 0) {
365 if (cur->idx >= cur->num_iovec)
368 l = cur->iovec[cur->idx].buf_len - cur->byte_off;
373 *buf = cur->iovec[cur->idx].buf + cur->byte_off;
375 cur->bytes_remaining -= l;
380 * Zero-length iovec entry or we already consumed all of it, try the
388 /* Determines the size of the AEAD output given the input size. */
389 static size_t qtx_inflate_payload_len(OSSL_QTX *qtx, uint32_t enc_level,
390 size_t plaintext_len)
392 OSSL_QRL_ENC_LEVEL *el
393 = ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
395 assert(el != NULL); /* Already checked by caller. */
398 * We currently only support ciphers with a 1:1 mapping between plaintext
399 * and ciphertext size, save for authentication tag.
401 return plaintext_len + ossl_qrl_get_suite_cipher_tag_len(el->suite_id);
404 /* Determines the size of the AEAD input given the output size. */
405 int ossl_qtx_calculate_plaintext_payload_len(OSSL_QTX *qtx, uint32_t enc_level,
406 size_t ciphertext_len,
407 size_t *plaintext_len)
409 OSSL_QRL_ENC_LEVEL *el
410 = ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
418 tag_len = ossl_qrl_get_suite_cipher_tag_len(el->suite_id);
420 if (ciphertext_len < tag_len) {
425 *plaintext_len = ciphertext_len - tag_len;
429 /* Any other error (including packet being too big for MDPL). */
430 #define QTX_FAIL_GENERIC (-1)
433 * Returned where there is insufficient room in the datagram to write the
436 #define QTX_FAIL_INSUFFICIENT_LEN (-2)
438 static int qtx_write_hdr(OSSL_QTX *qtx, const QUIC_PKT_HDR *hdr, TXE *txe,
439 QUIC_PKT_HDR_PTRS *ptrs)
443 unsigned char *data = txe_data(txe) + txe->data_len;
445 if (!WPACKET_init_static_len(&wpkt, data, txe->alloc_len - txe->data_len, 0))
448 if (!ossl_quic_wire_encode_pkt_hdr(&wpkt, hdr->dst_conn_id.id_len,
450 || !WPACKET_get_total_written(&wpkt, &l)) {
451 WPACKET_finish(&wpkt);
454 WPACKET_finish(&wpkt);
456 if (qtx->msg_callback != NULL)
457 qtx->msg_callback(1, OSSL_QUIC1_VERSION, SSL3_RT_QUIC_PACKET, data, l,
458 qtx->msg_callback_s, qtx->msg_callback_arg);
465 static int qtx_encrypt_into_txe(OSSL_QTX *qtx, struct iovec_cur *cur, TXE *txe,
466 uint32_t enc_level, QUIC_PN pn,
467 const unsigned char *hdr, size_t hdr_len,
468 QUIC_PKT_HDR_PTRS *ptrs)
471 OSSL_QRL_ENC_LEVEL *el
472 = ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
473 unsigned char nonce[EVP_MAX_IV_LENGTH];
475 EVP_CIPHER_CTX *cctx = NULL;
477 /* We should not have been called if we do not have key material. */
478 if (!ossl_assert(el != NULL))
482 * Have we already encrypted the maximum number of packets using the current
485 if (el->op_count >= ossl_qrl_get_suite_max_pkt(el->suite_id))
489 * TX key update is simpler than for RX; once we initiate a key update, we
490 * never need the old keys, as we never deliberately send a packet with old
491 * keys. Thus the EL always uses keyslot 0 for the TX side.
494 if (!ossl_assert(cctx != NULL))
497 /* Construct nonce (nonce=IV ^ PN). */
498 nonce_len = EVP_CIPHER_CTX_get_iv_length(cctx);
499 if (!ossl_assert(nonce_len >= sizeof(QUIC_PN)))
502 memcpy(nonce, el->iv[0], nonce_len);
503 for (i = 0; i < sizeof(QUIC_PN); ++i)
504 nonce[nonce_len - i - 1] ^= (unsigned char)(pn >> (i * 8));
506 /* type and key will already have been setup; feed the IV. */
507 if (EVP_CipherInit_ex(cctx, NULL, NULL, NULL, nonce, /*enc=*/1) != 1)
511 if (EVP_CipherUpdate(cctx, NULL, &l, hdr, hdr_len) != 1)
514 /* Encrypt plaintext directly into TXE. */
516 const unsigned char *src;
519 src_len = iovec_cur_get_buffer(cur, &src, SIZE_MAX);
523 if (EVP_CipherUpdate(cctx, txe_data(txe) + txe->data_len,
524 &l, src, src_len) != 1)
527 assert(l > 0 && src_len == (size_t)l);
528 txe->data_len += src_len;
531 /* Finalise and get tag. */
532 if (EVP_CipherFinal_ex(cctx, NULL, &l2) != 1)
535 if (EVP_CIPHER_CTX_ctrl(cctx, EVP_CTRL_AEAD_GET_TAG,
536 el->tag_len, txe_data(txe) + txe->data_len) != 1)
539 txe->data_len += el->tag_len;
541 /* Apply header protection. */
542 if (!ossl_quic_hdr_protector_encrypt(&el->hpr, ptrs))
550 * Append a packet to the TXE buffer, serializing and encrypting it in the
553 static int qtx_write(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt, TXE *txe,
556 int ret, needs_encrypt;
557 size_t hdr_len, pred_hdr_len, payload_len, pkt_len, space_left;
558 size_t min_len, orig_data_len;
559 struct iovec_cur cur;
560 QUIC_PKT_HDR_PTRS ptrs;
561 unsigned char *hdr_start;
562 OSSL_QRL_ENC_LEVEL *el = NULL;
564 const OSSL_QTX_IOVEC *iovec;
568 * Determine if the packet needs encryption and the minimum conceivable
569 * serialization length.
571 if (!ossl_quic_pkt_type_is_encrypted(pkt->hdr->type)) {
573 min_len = QUIC_MIN_VALID_PKT_LEN;
576 min_len = QUIC_MIN_VALID_PKT_LEN_CRYPTO;
577 el = ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
578 if (!ossl_assert(el != NULL)) /* should already have been checked */
582 orig_data_len = txe->data_len;
583 space_left = txe->alloc_len - txe->data_len;
584 if (space_left < min_len) {
585 /* Not even a possibility of it fitting. */
586 ret = QTX_FAIL_INSUFFICIENT_LEN;
590 /* Set some fields in the header we are responsible for. */
591 if (pkt->hdr->type == QUIC_PKT_TYPE_1RTT)
592 pkt->hdr->key_phase = (unsigned char)(el->key_epoch & 1);
594 /* If we are running tests then mutate_packet may be non NULL */
595 if (qtx->mutatecb != NULL) {
596 if (!qtx->mutatecb(pkt->hdr, pkt->iovec, pkt->num_iovec, &hdr,
597 &iovec, &num_iovec, qtx->mutatearg)) {
598 ret = QTX_FAIL_GENERIC;
604 num_iovec = pkt->num_iovec;
607 /* Walk the iovecs to determine actual input payload length. */
608 iovec_cur_init(&cur, iovec, num_iovec);
610 if (cur.bytes_remaining == 0) {
611 /* No zero-length payloads allowed. */
612 ret = QTX_FAIL_GENERIC;
616 /* Determine encrypted payload length. */
617 payload_len = needs_encrypt ? qtx_inflate_payload_len(qtx, enc_level,
619 : cur.bytes_remaining;
621 /* Determine header length. */
623 hdr->len = payload_len;
624 pred_hdr_len = ossl_quic_wire_get_encoded_pkt_hdr_len(hdr->dst_conn_id.id_len,
626 if (pred_hdr_len == 0) {
627 ret = QTX_FAIL_GENERIC;
631 /* We now definitively know our packet length. */
632 pkt_len = pred_hdr_len + payload_len;
634 if (pkt_len > space_left) {
635 ret = QTX_FAIL_INSUFFICIENT_LEN;
639 if (ossl_quic_pkt_type_has_pn(hdr->type)) {
640 if (!ossl_quic_wire_encode_pkt_hdr_pn(pkt->pn,
643 ret = QTX_FAIL_GENERIC;
648 /* Append the header to the TXE. */
649 hdr_start = txe_data(txe) + txe->data_len;
650 if (!qtx_write_hdr(qtx, hdr, txe, &ptrs)) {
651 ret = QTX_FAIL_GENERIC;
655 hdr_len = (txe_data(txe) + txe->data_len) - hdr_start;
656 assert(hdr_len == pred_hdr_len);
658 if (!needs_encrypt) {
659 /* Just copy the payload across. */
660 const unsigned char *src;
664 /* Buffer length has already been checked above. */
665 src_len = iovec_cur_get_buffer(&cur, &src, SIZE_MAX);
669 memcpy(txe_data(txe) + txe->data_len, src, src_len);
670 txe->data_len += src_len;
673 /* Encrypt into TXE. */
674 if (!qtx_encrypt_into_txe(qtx, &cur, txe, enc_level, pkt->pn,
675 hdr_start, hdr_len, &ptrs)) {
676 ret = QTX_FAIL_GENERIC;
680 assert(txe->data_len - orig_data_len == pkt_len);
683 if (qtx->finishmutatecb != NULL)
684 qtx->finishmutatecb(qtx->mutatearg);
689 * Restore original length so we don't leave a half-written packet in the
692 txe->data_len = orig_data_len;
693 if (qtx->finishmutatecb != NULL)
694 qtx->finishmutatecb(qtx->mutatearg);
698 static TXE *qtx_ensure_cons(OSSL_QTX *qtx)
700 TXE *txe = qtx->cons;
705 txe = qtx_ensure_free_txe(qtx, qtx->mdpl);
709 ossl_list_txe_remove(&qtx->free, txe);
716 static int addr_eq(const BIO_ADDR *a, const BIO_ADDR *b)
718 return ((a == NULL || BIO_ADDR_family(a) == AF_UNSPEC)
719 && (b == NULL || BIO_ADDR_family(b) == AF_UNSPEC))
720 || (a != NULL && b != NULL && memcmp(a, b, sizeof(*a)) == 0);
723 int ossl_qtx_write_pkt(OSSL_QTX *qtx, const OSSL_QTX_PKT *pkt)
726 int coalescing = (pkt->flags & OSSL_QTX_PKT_FLAG_COALESCE) != 0;
731 /* Must have EL configured, must have header. */
732 if (pkt->hdr == NULL)
735 enc_level = ossl_quic_pkt_type_to_enc_level(pkt->hdr->type);
737 /* Some packet types must be in a packet all by themselves. */
738 if (!ossl_quic_pkt_type_can_share_dgram(pkt->hdr->type))
739 ossl_qtx_finish_dgram(qtx);
740 else if (enc_level >= QUIC_ENC_LEVEL_NUM
741 || ossl_qrl_enc_level_set_have_el(&qtx->el_set, enc_level) != 1) {
742 /* All other packet types are encrypted. */
746 was_coalescing = (qtx->cons != NULL && qtx->cons->data_len > 0);
748 if (!addr_eq(&qtx->cons->peer, pkt->peer)
749 || !addr_eq(&qtx->cons->local, pkt->local)) {
750 /* Must stop coalescing if addresses have changed */
751 ossl_qtx_finish_dgram(qtx);
757 * Start a new coalescing session or continue using the existing one and
758 * serialize/encrypt the packet. We always encrypt packets as soon as
759 * our caller gives them to us, which relieves the caller of any need to
760 * keep the plaintext around.
762 txe = qtx_ensure_cons(qtx);
764 return 0; /* allocation failure */
767 * Ensure TXE has at least MDPL bytes allocated. This should only be
768 * possible if the MDPL has increased.
770 if (!qtx_reserve_txe(qtx, NULL, txe, qtx->mdpl))
773 if (!was_coalescing) {
774 /* Set addresses in TXE. */
775 if (pkt->peer != NULL)
776 txe->peer = *pkt->peer;
778 BIO_ADDR_clear(&txe->peer);
780 if (pkt->local != NULL)
781 txe->local = *pkt->local;
783 BIO_ADDR_clear(&txe->local);
786 ret = qtx_write(qtx, pkt, txe, enc_level);
789 } else if (ret == QTX_FAIL_INSUFFICIENT_LEN) {
790 if (was_coalescing) {
792 * We failed due to insufficient length, so end the current
793 * datagram and try again.
795 ossl_qtx_finish_dgram(qtx);
799 * We failed due to insufficient length, but we were not
800 * coalescing/started with an empty datagram, so any future
801 * attempt to write this packet must also fail.
806 return 0; /* other error */
813 * Some packet types cannot have another packet come after them.
815 if (ossl_quic_pkt_type_must_be_last(pkt->hdr->type))
819 ossl_qtx_finish_dgram(qtx);
825 * Finish any incomplete datagrams for transmission which were flagged for
826 * coalescing. If there is no current coalescing datagram, this is a no-op.
828 void ossl_qtx_finish_dgram(OSSL_QTX *qtx)
830 TXE *txe = qtx->cons;
835 if (txe->data_len == 0)
837 * If we did not put anything in the datagram, just move it back to the
840 ossl_list_txe_insert_tail(&qtx->free, txe);
842 qtx_add_to_pending(qtx, txe);
848 static void txe_to_msg(TXE *txe, BIO_MSG *msg)
850 msg->data = txe_data(txe);
851 msg->data_len = txe->data_len;
854 = BIO_ADDR_family(&txe->peer) != AF_UNSPEC ? &txe->peer : NULL;
856 = BIO_ADDR_family(&txe->local) != AF_UNSPEC ? &txe->local : NULL;
859 #define MAX_MSGS_PER_SEND 32
861 int ossl_qtx_flush_net(OSSL_QTX *qtx)
863 BIO_MSG msg[MAX_MSGS_PER_SEND];
864 size_t wr, i, total_written = 0;
868 if (ossl_list_txe_head(&qtx->pending) == NULL)
869 return QTX_FLUSH_NET_RES_OK; /* Nothing to send. */
871 if (qtx->bio == NULL)
872 return QTX_FLUSH_NET_RES_PERMANENT_FAIL;
875 for (txe = ossl_list_txe_head(&qtx->pending), i = 0;
876 txe != NULL && i < OSSL_NELEM(msg);
877 txe = ossl_list_txe_next(txe), ++i)
878 txe_to_msg(txe, &msg[i]);
881 /* Nothing to send. */
885 res = BIO_sendmmsg(qtx->bio, msg, sizeof(BIO_MSG), i, 0, &wr);
886 if (res && wr == 0) {
888 * Treat 0 messages sent as a transient error and just stop for now.
890 ERR_clear_last_mark();
894 * We did not get anything, so further calls will probably not
897 if (BIO_err_is_non_fatal(ERR_peek_last_error())) {
898 /* Transient error, just stop for now, clearing the error. */
902 /* Non-transient error, fail and do not clear the error. */
903 ERR_clear_last_mark();
904 return QTX_FLUSH_NET_RES_PERMANENT_FAIL;
908 ERR_clear_last_mark();
911 * Remove everything which was successfully sent from the pending queue.
913 for (i = 0; i < wr; ++i)
914 qtx_pending_to_free(qtx);
919 return total_written > 0
920 ? QTX_FLUSH_NET_RES_OK
921 : QTX_FLUSH_NET_RES_TRANSIENT_FAIL;
924 int ossl_qtx_pop_net(OSSL_QTX *qtx, BIO_MSG *msg)
926 TXE *txe = ossl_list_txe_head(&qtx->pending);
931 txe_to_msg(txe, msg);
932 qtx_pending_to_free(qtx);
936 void ossl_qtx_set_bio(OSSL_QTX *qtx, BIO *bio)
941 int ossl_qtx_set_mdpl(OSSL_QTX *qtx, size_t mdpl)
943 if (mdpl < QUIC_MIN_INITIAL_DGRAM_LEN)
950 size_t ossl_qtx_get_mdpl(OSSL_QTX *qtx)
955 size_t ossl_qtx_get_queue_len_datagrams(OSSL_QTX *qtx)
957 return qtx->pending_count;
960 size_t ossl_qtx_get_queue_len_bytes(OSSL_QTX *qtx)
962 return qtx->pending_bytes;
965 size_t ossl_qtx_get_cur_dgram_len_bytes(OSSL_QTX *qtx)
967 return qtx->cons != NULL ? qtx->cons->data_len : 0;
970 size_t ossl_qtx_get_unflushed_pkt_count(OSSL_QTX *qtx)
972 return qtx->cons_count;
975 int ossl_qtx_trigger_key_update(OSSL_QTX *qtx)
977 return ossl_qrl_enc_level_set_key_update(&qtx->el_set,
978 QUIC_ENC_LEVEL_1RTT);
981 uint64_t ossl_qtx_get_cur_epoch_pkt_count(OSSL_QTX *qtx, uint32_t enc_level)
983 OSSL_QRL_ENC_LEVEL *el;
985 el = ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
992 uint64_t ossl_qtx_get_max_epoch_pkt_count(OSSL_QTX *qtx, uint32_t enc_level)
994 OSSL_QRL_ENC_LEVEL *el;
996 el = ossl_qrl_enc_level_set_get(&qtx->el_set, enc_level, 1);
1000 return ossl_qrl_get_suite_max_pkt(el->suite_id);