Home | History | Annotate | Line # | Download | only in test
      1 /*
      2  * Copyright 2022-2026 The OpenSSL Project Authors. All Rights Reserved.
      3  *
      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
      8  */
      9 #include "internal/packet.h"
     10 #include "internal/quic_txp.h"
     11 #include "internal/quic_statm.h"
     12 #include "internal/quic_demux.h"
     13 #include "internal/quic_record_rx.h"
     14 #include "testutil.h"
     15 #include "quic_record_test_util.h"
     16 
     17 static const QUIC_CONN_ID scid_1 = {
     18     1, { 0x5f }
     19 };
     20 
     21 static const QUIC_CONN_ID dcid_1 = {
     22     8, { 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8 }
     23 };
     24 
     25 static const QUIC_CONN_ID cid_1 = {
     26     8, { 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8 }
     27 };
     28 
     29 static const unsigned char reset_token_1[16] = {
     30     0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0xaa,
     31     0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12
     32 };
     33 
     34 static const unsigned char secret_1[32] = {
     35     0x01
     36 };
     37 
     38 static OSSL_TIME fake_now(void *arg)
     39 {
     40     return ossl_time_now(); /* TODO */
     41 }
     42 
     43 struct helper {
     44     OSSL_QUIC_TX_PACKETISER *txp;
     45     OSSL_QUIC_TX_PACKETISER_ARGS args;
     46     OSSL_QTX_ARGS qtx_args;
     47     BIO *bio1, *bio2;
     48     QUIC_TXFC conn_txfc;
     49     QUIC_RXFC conn_rxfc, stream_rxfc;
     50     QUIC_RXFC max_streams_bidi_rxfc, max_streams_uni_rxfc;
     51     OSSL_STATM statm;
     52     OSSL_CC_DATA *cc_data;
     53     const OSSL_CC_METHOD *cc_method;
     54     QUIC_STREAM_MAP qsm;
     55     char have_statm, have_qsm;
     56     QUIC_DEMUX *demux;
     57     OSSL_QRX *qrx;
     58     OSSL_QRX_ARGS qrx_args;
     59     OSSL_QRX_PKT *qrx_pkt;
     60     PACKET pkt;
     61     uint64_t frame_type;
     62     union {
     63         uint64_t max_data;
     64         OSSL_QUIC_FRAME_NEW_CONN_ID new_conn_id;
     65         OSSL_QUIC_FRAME_ACK ack;
     66         struct {
     67             const unsigned char *token;
     68             size_t token_len;
     69         } new_token;
     70         OSSL_QUIC_FRAME_CRYPTO crypto;
     71         OSSL_QUIC_FRAME_STREAM stream;
     72         OSSL_QUIC_FRAME_STOP_SENDING stop_sending;
     73         OSSL_QUIC_FRAME_RESET_STREAM reset_stream;
     74         OSSL_QUIC_FRAME_CONN_CLOSE conn_close;
     75     } frame;
     76     OSSL_QUIC_ACK_RANGE ack_ranges[16];
     77 };
     78 
     79 static void helper_cleanup(struct helper *h)
     80 {
     81     size_t i;
     82     uint32_t pn_space;
     83 
     84     ossl_qrx_pkt_release(h->qrx_pkt);
     85     h->qrx_pkt = NULL;
     86 
     87     for (pn_space = QUIC_PN_SPACE_INITIAL;
     88         pn_space < QUIC_PN_SPACE_NUM;
     89         ++pn_space)
     90         ossl_ackm_on_pkt_space_discarded(h->args.ackm, pn_space);
     91 
     92     ossl_quic_tx_packetiser_free(h->txp);
     93     ossl_qtx_free(h->args.qtx);
     94     ossl_quic_txpim_free(h->args.txpim);
     95     ossl_quic_cfq_free(h->args.cfq);
     96     if (h->cc_data != NULL)
     97         h->cc_method->free(h->cc_data);
     98     if (h->have_statm)
     99         ossl_statm_destroy(&h->statm);
    100     if (h->have_qsm)
    101         ossl_quic_stream_map_cleanup(&h->qsm);
    102     for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
    103         ossl_quic_sstream_free(h->args.crypto[i]);
    104     ossl_ackm_free(h->args.ackm);
    105     ossl_qrx_free(h->qrx);
    106     ossl_quic_demux_free(h->demux);
    107     BIO_free(h->bio1);
    108     BIO_free(h->bio2);
    109 }
    110 
    111 static void demux_default_handler(QUIC_URXE *e, void *arg,
    112     const QUIC_CONN_ID *dcid)
    113 {
    114     struct helper *h = arg;
    115 
    116     if (dcid == NULL || !ossl_quic_conn_id_eq(dcid, &dcid_1))
    117         return;
    118 
    119     ossl_qrx_inject_urxe(h->qrx, e);
    120 }
    121 
    122 static int helper_init(struct helper *h)
    123 {
    124     int rc = 0;
    125     size_t i;
    126 
    127     memset(h, 0, sizeof(*h));
    128 
    129     /* Initialisation */
    130     if (!TEST_true(BIO_new_bio_dgram_pair(&h->bio1, 0, &h->bio2, 0)))
    131         goto err;
    132 
    133     h->qtx_args.bio = h->bio1;
    134     h->qtx_args.mdpl = 1200;
    135 
    136     if (!TEST_ptr(h->args.qtx = ossl_qtx_new(&h->qtx_args)))
    137         goto err;
    138 
    139     if (!TEST_ptr(h->args.txpim = ossl_quic_txpim_new()))
    140         goto err;
    141 
    142     if (!TEST_ptr(h->args.cfq = ossl_quic_cfq_new()))
    143         goto err;
    144 
    145     if (!TEST_true(ossl_quic_txfc_init(&h->conn_txfc, NULL)))
    146         goto err;
    147 
    148     if (!TEST_true(ossl_quic_rxfc_init(&h->conn_rxfc, NULL,
    149             2 * 1024 * 1024,
    150             10 * 1024 * 1024,
    151             fake_now,
    152             NULL)))
    153         goto err;
    154 
    155     if (!TEST_true(ossl_quic_rxfc_init(&h->stream_rxfc, &h->conn_rxfc,
    156             1 * 1024 * 1024,
    157             5 * 1024 * 1024,
    158             fake_now,
    159             NULL)))
    160         goto err;
    161 
    162     if (!TEST_true(ossl_quic_rxfc_init(&h->max_streams_bidi_rxfc, NULL,
    163             100, 100,
    164             fake_now,
    165             NULL)))
    166         goto err;
    167 
    168     if (!TEST_true(ossl_quic_rxfc_init(&h->max_streams_uni_rxfc, NULL,
    169             100, 100,
    170             fake_now,
    171             NULL)))
    172 
    173         if (!TEST_true(ossl_statm_init(&h->statm)))
    174             goto err;
    175 
    176     h->have_statm = 1;
    177 
    178     h->cc_method = &ossl_cc_dummy_method;
    179     if (!TEST_ptr(h->cc_data = h->cc_method->new(fake_now, NULL)))
    180         goto err;
    181 
    182     if (!TEST_ptr(h->args.ackm = ossl_ackm_new(fake_now, NULL,
    183                       &h->statm,
    184                       h->cc_method,
    185                       h->cc_data,
    186                       /* is_server */ 0)))
    187         goto err;
    188 
    189     if (!TEST_true(ossl_quic_stream_map_init(&h->qsm, NULL, NULL,
    190             &h->max_streams_bidi_rxfc,
    191             &h->max_streams_uni_rxfc,
    192             /*is_server=*/0)))
    193         goto err;
    194 
    195     h->have_qsm = 1;
    196 
    197     for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
    198         if (!TEST_ptr(h->args.crypto[i] = ossl_quic_sstream_new(4096)))
    199             goto err;
    200 
    201     h->args.cur_scid = scid_1;
    202     h->args.cur_dcid = dcid_1;
    203     h->args.qsm = &h->qsm;
    204     h->args.conn_txfc = &h->conn_txfc;
    205     h->args.conn_rxfc = &h->conn_rxfc;
    206     h->args.max_streams_bidi_rxfc = &h->max_streams_bidi_rxfc;
    207     h->args.max_streams_uni_rxfc = &h->max_streams_uni_rxfc;
    208     h->args.cc_method = h->cc_method;
    209     h->args.cc_data = h->cc_data;
    210     h->args.now = fake_now;
    211     h->args.protocol_version = QUIC_VERSION_1;
    212 
    213     if (!TEST_ptr(h->txp = ossl_quic_tx_packetiser_new(&h->args)))
    214         goto err;
    215 
    216     /*
    217      * Our helper should always skip validation
    218      * as the tests are not written to expect delayed connections
    219      */
    220     ossl_quic_tx_packetiser_set_validated(h->txp);
    221 
    222     if (!TEST_ptr(h->demux = ossl_quic_demux_new(h->bio2, 8,
    223                       fake_now, NULL)))
    224         goto err;
    225 
    226     ossl_quic_demux_set_default_handler(h->demux, demux_default_handler, h);
    227 
    228     h->qrx_args.demux = h->demux;
    229     h->qrx_args.short_conn_id_len = 8;
    230     h->qrx_args.max_deferred = 32;
    231 
    232     if (!TEST_ptr(h->qrx = ossl_qrx_new(&h->qrx_args)))
    233         goto err;
    234 
    235     ossl_qrx_allow_1rtt_processing(h->qrx);
    236 
    237     rc = 1;
    238 err:
    239     if (!rc)
    240         helper_cleanup(h);
    241 
    242     return rc;
    243 }
    244 
    245 #define OPK_END 0 /* End of Script */
    246 #define OPK_TXP_GENERATE 1 /* Call generate, expect packet output */
    247 #define OPK_TXP_GENERATE_NONE 2 /* Call generate, expect no packet output */
    248 #define OPK_RX_PKT 3 /* Receive, expect packet */
    249 #define OPK_RX_PKT_NONE 4 /* Receive, expect no packet */
    250 #define OPK_EXPECT_DGRAM_LEN 5 /* Expect received datagram length in range */
    251 #define OPK_EXPECT_FRAME 6 /* Expect next frame is of type */
    252 #define OPK_EXPECT_INITIAL_TOKEN 7 /* Expect initial token buffer match */
    253 #define OPK_EXPECT_HDR 8 /* Expect header structure match */
    254 #define OPK_CHECK 9 /* Call check function */
    255 #define OPK_NEXT_FRAME 10 /* Next frame */
    256 #define OPK_EXPECT_NO_FRAME 11 /* Expect no further frames */
    257 #define OPK_PROVIDE_SECRET 12 /* Provide secret to QTX and QRX */
    258 #define OPK_DISCARD_EL 13 /* Discard QTX EL */
    259 #define OPK_CRYPTO_SEND 14 /* Push data into crypto send stream */
    260 #define OPK_STREAM_NEW 15 /* Create new application stream */
    261 #define OPK_STREAM_SEND 16 /* Push data into application send stream */
    262 #define OPK_STREAM_FIN 17 /* Mark stream as finished */
    263 #define OPK_STOP_SENDING 18 /* Mark stream for STOP_SENDING */
    264 #define OPK_RESET_STREAM 19 /* Mark stream for RESET_STREAM */
    265 #define OPK_CONN_TXFC_BUMP 20 /* Bump connection TXFC CWM */
    266 #define OPK_STREAM_TXFC_BUMP 21 /* Bump stream TXFC CWM */
    267 #define OPK_HANDSHAKE_COMPLETE 22 /* Mark handshake as complete */
    268 #define OPK_NOP 23 /* No-op */
    269 
    270 struct script_op {
    271     uint32_t opcode;
    272     uint64_t arg0, arg1;
    273     const void *buf;
    274     size_t buf_len;
    275     int (*check_func)(struct helper *h);
    276 };
    277 
    278 #define OP_END \
    279     { OPK_END }
    280 #define OP_TXP_GENERATE() \
    281     { OPK_TXP_GENERATE },
    282 #define OP_TXP_GENERATE_NONE() \
    283     { OPK_TXP_GENERATE_NONE },
    284 #define OP_RX_PKT() \
    285     { OPK_RX_PKT },
    286 #define OP_RX_PKT_NONE() \
    287     { OPK_RX_PKT_NONE },
    288 #define OP_EXPECT_DGRAM_LEN(lo, hi) \
    289     { OPK_EXPECT_DGRAM_LEN, (lo), (hi) },
    290 #define OP_EXPECT_FRAME(frame_type) \
    291     { OPK_EXPECT_FRAME, (frame_type) },
    292 #define OP_EXPECT_INITIAL_TOKEN(buf) \
    293     { OPK_EXPECT_INITIAL_TOKEN, sizeof(buf), 0, buf },
    294 #define OP_EXPECT_HDR(hdr) \
    295     { OPK_EXPECT_HDR, 0, 0, &(hdr) },
    296 #define OP_CHECK(func) \
    297     { OPK_CHECK, 0, 0, NULL, 0, (func) },
    298 #define OP_NEXT_FRAME() \
    299     { OPK_NEXT_FRAME },
    300 #define OP_EXPECT_NO_FRAME() \
    301     { OPK_EXPECT_NO_FRAME },
    302 #define OP_PROVIDE_SECRET(el, suite, secret) \
    303     { OPK_PROVIDE_SECRET, (el), (suite), (secret), sizeof(secret) },
    304 #define OP_DISCARD_EL(el) \
    305     { OPK_DISCARD_EL, (el) },
    306 #define OP_CRYPTO_SEND(pn_space, buf) \
    307     { OPK_CRYPTO_SEND, (pn_space), 0, (buf), sizeof(buf) },
    308 #define OP_STREAM_NEW(id) \
    309     { OPK_STREAM_NEW, (id) },
    310 #define OP_STREAM_SEND(id, buf) \
    311     { OPK_STREAM_SEND, (id), 0, (buf), sizeof(buf) },
    312 #define OP_STREAM_FIN(id) \
    313     { OPK_STREAM_FIN, (id) },
    314 #define OP_STOP_SENDING(id, aec) \
    315     { OPK_STOP_SENDING, (id), (aec) },
    316 #define OP_RESET_STREAM(id, aec) \
    317     { OPK_RESET_STREAM, (id), (aec) },
    318 #define OP_CONN_TXFC_BUMP(cwm) \
    319     { OPK_CONN_TXFC_BUMP, (cwm) },
    320 #define OP_STREAM_TXFC_BUMP(id, cwm) \
    321     { OPK_STREAM_TXFC_BUMP, (cwm), (id) },
    322 #define OP_HANDSHAKE_COMPLETE() \
    323     { OPK_HANDSHAKE_COMPLETE },
    324 #define OP_NOP() \
    325     { OPK_NOP },
    326 
    327 static int schedule_handshake_done(struct helper *h)
    328 {
    329     ossl_quic_tx_packetiser_schedule_handshake_done(h->txp);
    330     return 1;
    331 }
    332 
    333 static int schedule_ack_eliciting_app(struct helper *h)
    334 {
    335     ossl_quic_tx_packetiser_schedule_ack_eliciting(h->txp, QUIC_PN_SPACE_APP);
    336     return 1;
    337 }
    338 
    339 /* 1. 1-RTT, Single Handshake Done Frame */
    340 static const struct script_op script_1[] = {
    341     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    342         OP_TXP_GENERATE_NONE()
    343             OP_CHECK(schedule_handshake_done)
    344                 OP_TXP_GENERATE()
    345                     OP_RX_PKT()
    346     /* Should not be long */
    347     OP_EXPECT_DGRAM_LEN(21, 32)
    348         OP_NEXT_FRAME()
    349             OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE)
    350                 OP_EXPECT_NO_FRAME()
    351                     OP_RX_PKT_NONE()
    352                         OP_TXP_GENERATE_NONE()
    353                             OP_END
    354 };
    355 
    356 /* 2. 1-RTT, Forced ACK-Eliciting Frame */
    357 static const struct script_op script_2[] = {
    358     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    359         OP_TXP_GENERATE_NONE()
    360             OP_CHECK(schedule_ack_eliciting_app)
    361                 OP_TXP_GENERATE()
    362                     OP_RX_PKT()
    363     /* Should not be long */
    364     OP_EXPECT_DGRAM_LEN(21, 32)
    365     /* A PING frame should have been added */
    366     OP_NEXT_FRAME()
    367         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
    368             OP_EXPECT_NO_FRAME()
    369                 OP_RX_PKT_NONE()
    370                     OP_TXP_GENERATE_NONE()
    371                         OP_END
    372 };
    373 
    374 /* 3. 1-RTT, MAX_DATA */
    375 static int schedule_max_data(struct helper *h)
    376 {
    377     uint64_t cwm;
    378 
    379     cwm = ossl_quic_rxfc_get_cwm(&h->stream_rxfc);
    380 
    381     if (!TEST_true(ossl_quic_rxfc_on_rx_stream_frame(&h->stream_rxfc, cwm, 0))
    382         || !TEST_true(ossl_quic_rxfc_on_retire(&h->stream_rxfc, cwm,
    383             ossl_ticks2time(OSSL_TIME_MS))))
    384         return 0;
    385 
    386     return 1;
    387 }
    388 
    389 static const struct script_op script_3[] = {
    390     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    391         OP_TXP_GENERATE_NONE()
    392             OP_CHECK(schedule_max_data)
    393                 OP_TXP_GENERATE()
    394                     OP_RX_PKT()
    395     /* Should not be long */
    396     OP_EXPECT_DGRAM_LEN(21, 40)
    397     /* A PING frame should have been added */
    398     OP_NEXT_FRAME()
    399         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_MAX_DATA)
    400             OP_EXPECT_NO_FRAME()
    401                 OP_RX_PKT_NONE()
    402                     OP_TXP_GENERATE_NONE()
    403                         OP_END
    404 };
    405 
    406 /* 4. 1-RTT, CFQ (NEW_CONN_ID) */
    407 static void free_buf_mem(unsigned char *buf, size_t buf_len, void *arg)
    408 {
    409     BUF_MEM_free((BUF_MEM *)arg);
    410 }
    411 
    412 static int schedule_cfq_new_conn_id(struct helper *h)
    413 {
    414     int rc = 0;
    415     QUIC_CFQ_ITEM *cfq_item;
    416     WPACKET wpkt;
    417     BUF_MEM *buf_mem = NULL;
    418     size_t l = 0;
    419     OSSL_QUIC_FRAME_NEW_CONN_ID ncid = { 0 };
    420 
    421     ncid.seq_num = 2345;
    422     ncid.retire_prior_to = 1234;
    423     ncid.conn_id = cid_1;
    424     memcpy(ncid.stateless_reset.token, reset_token_1, sizeof(reset_token_1));
    425 
    426     if (!TEST_ptr(buf_mem = BUF_MEM_new()))
    427         goto err;
    428 
    429     if (!TEST_true(WPACKET_init(&wpkt, buf_mem)))
    430         goto err;
    431 
    432     if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt, &ncid))) {
    433         WPACKET_cleanup(&wpkt);
    434         goto err;
    435     }
    436 
    437     WPACKET_finish(&wpkt);
    438 
    439     if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
    440         goto err;
    441 
    442     if (!TEST_ptr(cfq_item = ossl_quic_cfq_add_frame(h->args.cfq, 1,
    443                       QUIC_PN_SPACE_APP,
    444                       OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, 0,
    445                       (unsigned char *)buf_mem->data, l,
    446                       free_buf_mem,
    447                       buf_mem)))
    448         goto err;
    449 
    450     rc = 1;
    451 err:
    452     if (!rc)
    453         BUF_MEM_free(buf_mem);
    454     return rc;
    455 }
    456 
    457 static int check_cfq_new_conn_id(struct helper *h)
    458 {
    459     if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 2345)
    460         || !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 1234)
    461         || !TEST_mem_eq(&h->frame.new_conn_id.conn_id, sizeof(cid_1),
    462             &cid_1, sizeof(cid_1))
    463         || !TEST_mem_eq(&h->frame.new_conn_id.stateless_reset.token,
    464             sizeof(reset_token_1),
    465             reset_token_1,
    466             sizeof(reset_token_1)))
    467         return 0;
    468 
    469     return 1;
    470 }
    471 
    472 static const struct script_op script_4[] = {
    473     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    474         OP_TXP_GENERATE_NONE()
    475             OP_CHECK(schedule_cfq_new_conn_id)
    476                 OP_TXP_GENERATE()
    477                     OP_RX_PKT()
    478                         OP_EXPECT_DGRAM_LEN(21, 128)
    479                             OP_NEXT_FRAME()
    480                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)
    481                                     OP_CHECK(check_cfq_new_conn_id)
    482                                         OP_EXPECT_NO_FRAME()
    483                                             OP_RX_PKT_NONE()
    484                                                 OP_TXP_GENERATE_NONE()
    485                                                     OP_END
    486 };
    487 
    488 /* 5. 1-RTT, CFQ (NEW_TOKEN) */
    489 static const unsigned char token_1[] = {
    490     0x10, 0x11, 0x12, 0x13, 0x14, 0x15
    491 };
    492 
    493 static int schedule_cfq_new_token(struct helper *h)
    494 {
    495     int rc = 0;
    496     QUIC_CFQ_ITEM *cfq_item;
    497     WPACKET wpkt;
    498     BUF_MEM *buf_mem = NULL;
    499     size_t l = 0;
    500 
    501     if (!TEST_ptr(buf_mem = BUF_MEM_new()))
    502         goto err;
    503 
    504     if (!TEST_true(WPACKET_init(&wpkt, buf_mem)))
    505         goto err;
    506 
    507     if (!TEST_true(ossl_quic_wire_encode_frame_new_token(&wpkt, token_1,
    508             sizeof(token_1)))) {
    509         WPACKET_cleanup(&wpkt);
    510         goto err;
    511     }
    512 
    513     WPACKET_finish(&wpkt);
    514 
    515     if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
    516         goto err;
    517 
    518     if (!TEST_ptr(cfq_item = ossl_quic_cfq_add_frame(h->args.cfq, 1,
    519                       QUIC_PN_SPACE_APP,
    520                       OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, 0,
    521                       (unsigned char *)buf_mem->data, l,
    522                       free_buf_mem,
    523                       buf_mem)))
    524         goto err;
    525 
    526     rc = 1;
    527 err:
    528     if (!rc)
    529         BUF_MEM_free(buf_mem);
    530     return rc;
    531 }
    532 
    533 static int check_cfq_new_token(struct helper *h)
    534 {
    535     if (!TEST_mem_eq(h->frame.new_token.token,
    536             h->frame.new_token.token_len,
    537             token_1,
    538             sizeof(token_1)))
    539         return 0;
    540 
    541     return 1;
    542 }
    543 
    544 static const struct script_op script_5[] = {
    545     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    546         OP_TXP_GENERATE_NONE()
    547             OP_CHECK(schedule_cfq_new_token)
    548                 OP_TXP_GENERATE()
    549                     OP_RX_PKT()
    550                         OP_EXPECT_DGRAM_LEN(21, 512)
    551                             OP_NEXT_FRAME()
    552                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)
    553                                     OP_CHECK(check_cfq_new_token)
    554                                         OP_EXPECT_NO_FRAME()
    555                                             OP_RX_PKT_NONE()
    556                                                 OP_TXP_GENERATE_NONE()
    557                                                     OP_END
    558 };
    559 
    560 /* 6. 1-RTT, ACK */
    561 static int schedule_ack(struct helper *h)
    562 {
    563     size_t i;
    564     OSSL_ACKM_RX_PKT rx_pkt = { 0 };
    565 
    566     /* Stimulate ACK emission by simulating a few received packets. */
    567     for (i = 0; i < 5; ++i) {
    568         rx_pkt.pkt_num = i;
    569         rx_pkt.time = fake_now(NULL);
    570         rx_pkt.pkt_space = QUIC_PN_SPACE_APP;
    571         rx_pkt.is_ack_eliciting = 1;
    572 
    573         if (!TEST_true(ossl_ackm_on_rx_packet(h->args.ackm, &rx_pkt)))
    574             return 0;
    575     }
    576 
    577     return 1;
    578 }
    579 
    580 static const struct script_op script_6[] = {
    581     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    582         OP_TXP_GENERATE_NONE()
    583             OP_CHECK(schedule_ack)
    584                 OP_TXP_GENERATE()
    585                     OP_RX_PKT()
    586                         OP_EXPECT_DGRAM_LEN(21, 512)
    587                             OP_NEXT_FRAME()
    588                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN)
    589                                     OP_EXPECT_NO_FRAME()
    590                                         OP_RX_PKT_NONE()
    591                                             OP_TXP_GENERATE_NONE()
    592                                                 OP_END
    593 };
    594 
    595 /* 7. 1-RTT, ACK, NEW_TOKEN */
    596 static const struct script_op script_7[] = {
    597     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    598         OP_TXP_GENERATE_NONE()
    599             OP_CHECK(schedule_cfq_new_token)
    600                 OP_CHECK(schedule_ack)
    601                     OP_TXP_GENERATE()
    602                         OP_RX_PKT()
    603                             OP_EXPECT_DGRAM_LEN(21, 512)
    604     /* ACK must come before NEW_TOKEN */
    605     OP_NEXT_FRAME()
    606         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN)
    607             OP_NEXT_FRAME()
    608                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)
    609                     OP_EXPECT_NO_FRAME()
    610                         OP_RX_PKT_NONE()
    611                             OP_TXP_GENERATE_NONE()
    612                                 OP_END
    613 };
    614 
    615 /* 8. 1-RTT, CRYPTO */
    616 static const unsigned char crypto_1[] = {
    617     0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09
    618 };
    619 
    620 static const struct script_op script_8[] = {
    621     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    622         OP_TXP_GENERATE_NONE()
    623             OP_CRYPTO_SEND(QUIC_PN_SPACE_APP, crypto_1)
    624                 OP_TXP_GENERATE()
    625                     OP_RX_PKT()
    626                         OP_EXPECT_DGRAM_LEN(21, 512)
    627                             OP_NEXT_FRAME()
    628                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
    629                                     OP_EXPECT_NO_FRAME()
    630                                         OP_RX_PKT_NONE()
    631                                             OP_TXP_GENERATE_NONE()
    632                                                 OP_END
    633 };
    634 
    635 /* 9. 1-RTT, STREAM */
    636 static const unsigned char stream_9[] = {
    637     0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x7a, 0x7b
    638 };
    639 
    640 static int check_stream_9(struct helper *h)
    641 {
    642     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
    643             stream_9, sizeof(stream_9)))
    644         return 0;
    645 
    646     return 1;
    647 }
    648 
    649 static const struct script_op script_9[] = {
    650     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    651         OP_HANDSHAKE_COMPLETE()
    652             OP_TXP_GENERATE_NONE()
    653                 OP_STREAM_NEW(42)
    654                     OP_STREAM_SEND(42, stream_9)
    655     /* Still no output because of TXFC */
    656     OP_TXP_GENERATE_NONE()
    657     /* Now grant a TXFC budget */
    658     OP_CONN_TXFC_BUMP(1000)
    659         OP_STREAM_TXFC_BUMP(42, 1000)
    660             OP_TXP_GENERATE()
    661                 OP_RX_PKT()
    662                     OP_EXPECT_DGRAM_LEN(21, 512)
    663                         OP_NEXT_FRAME()
    664                             OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
    665                                 OP_CHECK(check_stream_9)
    666                                     OP_EXPECT_NO_FRAME()
    667                                         OP_RX_PKT_NONE()
    668                                             OP_TXP_GENERATE_NONE()
    669                                                 OP_END
    670 };
    671 
    672 /* 10. 1-RTT, STREAM, round robin */
    673 /* The data below is randomly generated data. */
    674 static const unsigned char stream_10a[1300] = {
    675     0x40, 0x0d, 0xb6, 0x0d, 0x25, 0x5f, 0xdd, 0xb9, 0x05, 0x79, 0xa8, 0xe3,
    676     0x79, 0x32, 0xb2, 0xa7, 0x30, 0x6d, 0x29, 0xf6, 0xba, 0x50, 0xbe, 0x83,
    677     0xcb, 0x56, 0xec, 0xd6, 0xc7, 0x80, 0x84, 0xa2, 0x2f, 0xeb, 0xc4, 0x37,
    678     0x40, 0x44, 0xef, 0xd8, 0x78, 0xbb, 0x92, 0x80, 0x22, 0x33, 0xc0, 0xce,
    679     0x33, 0x5b, 0x75, 0x8c, 0xa5, 0x1a, 0x7a, 0x2a, 0xa9, 0x88, 0xaf, 0xf6,
    680     0x3a, 0xe2, 0x5e, 0x60, 0x52, 0x6d, 0xef, 0x7f, 0x2a, 0x9a, 0xaa, 0x17,
    681     0x0e, 0x12, 0x51, 0x82, 0x08, 0x2f, 0x0f, 0x5b, 0xff, 0xf5, 0x7c, 0x7c,
    682     0x89, 0x04, 0xfb, 0xa7, 0x80, 0x4e, 0xda, 0x12, 0x89, 0x01, 0x4a, 0x81,
    683     0x84, 0x78, 0x15, 0xa9, 0x12, 0x28, 0x69, 0x4a, 0x25, 0xe5, 0x8b, 0x69,
    684     0xc2, 0x9f, 0xb6, 0x59, 0x49, 0xe3, 0x53, 0x90, 0xef, 0xc9, 0xb8, 0x40,
    685     0xdd, 0x62, 0x5f, 0x99, 0x68, 0xd2, 0x0a, 0x77, 0xde, 0xf3, 0x11, 0x39,
    686     0x7f, 0x93, 0x8b, 0x81, 0x69, 0x36, 0xa7, 0x76, 0xa4, 0x10, 0x56, 0x51,
    687     0xe5, 0x45, 0x3a, 0x42, 0x49, 0x6c, 0xc6, 0xa0, 0xb4, 0x13, 0x46, 0x59,
    688     0x0e, 0x48, 0x60, 0xc9, 0xff, 0x70, 0x10, 0x8d, 0x6a, 0xf9, 0x5b, 0x94,
    689     0xc2, 0x9e, 0x49, 0x19, 0x56, 0xf2, 0xc1, 0xff, 0x08, 0x3f, 0x9e, 0x26,
    690     0x8e, 0x99, 0x71, 0xc4, 0x25, 0xb1, 0x4e, 0xcc, 0x7e, 0x5f, 0xf0, 0x4e,
    691     0x25, 0xa2, 0x2f, 0x3f, 0x68, 0xaa, 0xcf, 0xbd, 0x19, 0x19, 0x1c, 0x92,
    692     0xa0, 0xb6, 0xb8, 0x32, 0xb1, 0x0b, 0x91, 0x05, 0xa9, 0xf8, 0x1a, 0x4b,
    693     0x74, 0x09, 0xf9, 0x57, 0xd0, 0x1c, 0x38, 0x10, 0x05, 0x54, 0xd8, 0x4e,
    694     0x12, 0x67, 0xcc, 0x43, 0xa3, 0x81, 0xa9, 0x3a, 0x12, 0x57, 0xe7, 0x4b,
    695     0x0e, 0xe5, 0x51, 0xf9, 0x5f, 0xd4, 0x46, 0x73, 0xa2, 0x78, 0xb7, 0x00,
    696     0x24, 0x69, 0x35, 0x10, 0x1e, 0xb8, 0xa7, 0x4a, 0x9b, 0xbc, 0xfc, 0x04,
    697     0x6f, 0x1a, 0xb0, 0x4f, 0x12, 0xc9, 0x2b, 0x3b, 0x94, 0x85, 0x1b, 0x8e,
    698     0xba, 0xac, 0xfd, 0x10, 0x22, 0x68, 0x90, 0x17, 0x13, 0x44, 0x18, 0x2f,
    699     0x33, 0x37, 0x1a, 0x89, 0xc0, 0x2c, 0x14, 0x59, 0xb2, 0xaf, 0xc0, 0x6b,
    700     0xdc, 0x28, 0xe1, 0xe9, 0xc1, 0x0c, 0xb4, 0x80, 0x90, 0xb9, 0x1f, 0x45,
    701     0xb4, 0x63, 0x9a, 0x0e, 0xfa, 0x33, 0xf5, 0x75, 0x3a, 0x4f, 0xc3, 0x8c,
    702     0x70, 0xdb, 0xd7, 0xbf, 0xf6, 0xb8, 0x7f, 0xcc, 0xe5, 0x85, 0xb6, 0xae,
    703     0x25, 0x60, 0x18, 0x5b, 0xf1, 0x51, 0x1a, 0x85, 0xc1, 0x7f, 0xf3, 0xbe,
    704     0xb6, 0x82, 0x38, 0xe3, 0xd2, 0xff, 0x8a, 0xc4, 0xdb, 0x08, 0xe6, 0x96,
    705     0xd5, 0x3d, 0x1f, 0xc5, 0x12, 0x35, 0x45, 0x75, 0x5d, 0x17, 0x4e, 0xe1,
    706     0xb8, 0xc9, 0xf0, 0x45, 0x95, 0x0b, 0x03, 0xcb, 0x85, 0x47, 0xaf, 0xc7,
    707     0x88, 0xb6, 0xc1, 0x2c, 0xb8, 0x9b, 0xe6, 0x8b, 0x51, 0xd5, 0x2e, 0x71,
    708     0xba, 0xc9, 0xa9, 0x37, 0x5e, 0x1c, 0x2c, 0x03, 0xf0, 0xc7, 0xc1, 0xd3,
    709     0x72, 0xaa, 0x4d, 0x19, 0xd6, 0x51, 0x64, 0x12, 0xeb, 0x39, 0xeb, 0x45,
    710     0xe9, 0xb4, 0x84, 0x08, 0xb6, 0x6c, 0xc7, 0x3e, 0xf0, 0x88, 0x64, 0xc2,
    711     0x91, 0xb7, 0xa5, 0x86, 0x66, 0x83, 0xd5, 0xd3, 0x41, 0x24, 0xb2, 0x1c,
    712     0x9a, 0x18, 0x10, 0x0e, 0xa5, 0xc9, 0xef, 0xcd, 0x06, 0xce, 0xa8, 0xaf,
    713     0x22, 0x52, 0x25, 0x0b, 0x99, 0x3d, 0xe9, 0x26, 0xda, 0xa9, 0x47, 0xd1,
    714     0x4b, 0xa6, 0x4c, 0xfc, 0x80, 0xaf, 0x6a, 0x59, 0x4b, 0x35, 0xa4, 0x93,
    715     0x39, 0x5b, 0xfa, 0x91, 0x9d, 0xdf, 0x9d, 0x3c, 0xfb, 0x53, 0xca, 0x18,
    716     0x19, 0xe4, 0xda, 0x95, 0x47, 0x5a, 0x37, 0x59, 0xd7, 0xd2, 0xe4, 0x75,
    717     0x45, 0x0d, 0x03, 0x7f, 0xa0, 0xa9, 0xa0, 0x71, 0x06, 0xb1, 0x9d, 0x46,
    718     0xbd, 0xcf, 0x4a, 0x8b, 0x73, 0xc1, 0x45, 0x5c, 0x00, 0x61, 0xfd, 0xd1,
    719     0xa4, 0xa2, 0x3e, 0xaa, 0xbe, 0x72, 0xf1, 0x7a, 0x1a, 0x76, 0x88, 0x5c,
    720     0x9e, 0x74, 0x6d, 0x2a, 0x34, 0xfc, 0xf7, 0x41, 0x28, 0xe8, 0xa3, 0x43,
    721     0x4d, 0x43, 0x1d, 0x6c, 0x36, 0xb1, 0x45, 0x71, 0x5a, 0x3c, 0xd3, 0x28,
    722     0x44, 0xe4, 0x9b, 0xbf, 0x54, 0x16, 0xc3, 0x99, 0x6c, 0x42, 0xd8, 0x20,
    723     0xb6, 0x20, 0x5f, 0x6e, 0xbc, 0xba, 0x88, 0x5e, 0x2f, 0xa5, 0xd1, 0x82,
    724     0x5c, 0x92, 0xd0, 0x79, 0xfd, 0xcc, 0x61, 0x49, 0xd0, 0x73, 0x92, 0xe6,
    725     0x98, 0xe3, 0x80, 0x7a, 0xf9, 0x56, 0x63, 0x33, 0x19, 0xda, 0x54, 0x13,
    726     0xf0, 0x21, 0xa8, 0x15, 0xf6, 0xb7, 0x43, 0x7c, 0x1c, 0x1e, 0xb1, 0x89,
    727     0x8d, 0xce, 0x20, 0x54, 0x81, 0x80, 0xb5, 0x8f, 0x9b, 0xb1, 0x09, 0x92,
    728     0xdb, 0x25, 0x6f, 0x30, 0x29, 0x08, 0x1a, 0x05, 0x08, 0xf4, 0x83, 0x8b,
    729     0x1e, 0x2d, 0xfd, 0xe4, 0xb2, 0x76, 0xc8, 0x4d, 0xf3, 0xa6, 0x49, 0x5f,
    730     0x2c, 0x99, 0x78, 0xbd, 0x07, 0xef, 0xc8, 0xd9, 0xb5, 0x70, 0x3b, 0x0a,
    731     0xcb, 0xbd, 0xa0, 0xea, 0x15, 0xfb, 0xd1, 0x6e, 0x61, 0x83, 0xcb, 0x90,
    732     0xd0, 0xa3, 0x81, 0x28, 0xdc, 0xd5, 0x84, 0xae, 0x55, 0x28, 0x13, 0x9e,
    733     0xc6, 0xd8, 0xf4, 0x67, 0xd6, 0x0d, 0xd4, 0x69, 0xac, 0xf6, 0x35, 0x95,
    734     0x99, 0x44, 0x26, 0x72, 0x36, 0x55, 0xf9, 0x42, 0xa6, 0x1b, 0x00, 0x93,
    735     0x00, 0x19, 0x2f, 0x70, 0xd3, 0x16, 0x66, 0x4e, 0x80, 0xbb, 0xb6, 0x84,
    736     0xa1, 0x2c, 0x09, 0xfb, 0x41, 0xdf, 0x63, 0xde, 0x62, 0x3e, 0xd0, 0xa8,
    737     0xd8, 0x0c, 0x03, 0x06, 0xa9, 0x82, 0x17, 0x9c, 0xd2, 0xa9, 0xd5, 0x6f,
    738     0xcc, 0xc0, 0xf2, 0x5d, 0xb1, 0xba, 0xf8, 0x2e, 0x37, 0x8b, 0xe6, 0x5d,
    739     0x9f, 0x1b, 0xfb, 0x53, 0x0a, 0x96, 0xbe, 0x69, 0x31, 0x19, 0x8f, 0x44,
    740     0x1b, 0xc2, 0x42, 0x7e, 0x65, 0x12, 0x1d, 0x52, 0x1e, 0xe2, 0xc0, 0x86,
    741     0x70, 0x88, 0xe5, 0xf6, 0x87, 0x5d, 0x03, 0x4b, 0x12, 0x3c, 0x2d, 0xaf,
    742     0x09, 0xf5, 0x4f, 0x82, 0x2e, 0x2e, 0xbe, 0x07, 0xe8, 0x8d, 0x57, 0x6e,
    743     0xc0, 0xeb, 0xf9, 0x37, 0xac, 0x89, 0x01, 0xb7, 0xc6, 0x52, 0x1c, 0x86,
    744     0xe5, 0xbc, 0x1f, 0xbd, 0xde, 0xa2, 0x42, 0xb6, 0x73, 0x85, 0x6f, 0x06,
    745     0x36, 0x56, 0x40, 0x2b, 0xea, 0x16, 0x8c, 0xf4, 0x7b, 0x65, 0x6a, 0xca,
    746     0x3c, 0x56, 0x68, 0x01, 0xe3, 0x9c, 0xbb, 0xb9, 0x45, 0x54, 0xcd, 0x13,
    747     0x74, 0xad, 0x80, 0x40, 0xbc, 0xd0, 0x74, 0xb4, 0x31, 0xe4, 0xca, 0xd5,
    748     0xf8, 0x4f, 0x08, 0x5b, 0xc4, 0x15, 0x1a, 0x51, 0x3b, 0xc6, 0x40, 0xc8,
    749     0xea, 0x76, 0x30, 0x95, 0xb7, 0x76, 0xa4, 0xda, 0x20, 0xdb, 0x75, 0x1c,
    750     0xf4, 0x87, 0x24, 0x29, 0x54, 0xc6, 0x59, 0x0c, 0xf0, 0xed, 0xf5, 0x3d,
    751     0xce, 0x95, 0x23, 0x30, 0x49, 0x91, 0xa7, 0x7b, 0x22, 0xb5, 0xd7, 0x71,
    752     0xb0, 0x60, 0xe1, 0xf0, 0x84, 0x74, 0x0e, 0x2f, 0xa8, 0x79, 0x35, 0xb9,
    753     0x03, 0xb5, 0x2c, 0xdc, 0x60, 0x48, 0x12, 0xd9, 0x14, 0x5a, 0x58, 0x5d,
    754     0x95, 0xc6, 0x47, 0xfd, 0xaf, 0x09, 0xc2, 0x67, 0xa5, 0x09, 0xae, 0xff,
    755     0x4b, 0xd5, 0x6c, 0x2f, 0x1d, 0x33, 0x31, 0xcb, 0xdb, 0xcf, 0xf5, 0xf6,
    756     0xbc, 0x90, 0xb2, 0x15, 0xd4, 0x34, 0xeb, 0xde, 0x0e, 0x8f, 0x3d, 0xea,
    757     0xa4, 0x9b, 0x29, 0x8a, 0xf9, 0x4a, 0xac, 0x38, 0x1e, 0x46, 0xb2, 0x2d,
    758     0xa2, 0x61, 0xc5, 0x99, 0x5e, 0x85, 0x36, 0x85, 0xb0, 0xb1, 0x6b, 0xc4,
    759     0x06, 0x68, 0xc7, 0x9b, 0x54, 0xb9, 0xc8, 0x9d, 0xf3, 0x1a, 0xe0, 0x67,
    760     0x0e, 0x4d, 0x5c, 0x13, 0x54, 0xa4, 0x62, 0x62, 0x6f, 0xae, 0x0e, 0x86,
    761     0xa2, 0xe0, 0x31, 0xc7, 0x72, 0xa1, 0xbb, 0x87, 0x3e, 0x61, 0x96, 0xb7,
    762     0x53, 0xf9, 0x34, 0xcb, 0xfd, 0x6c, 0x67, 0x25, 0x73, 0x61, 0x75, 0x4f,
    763     0xab, 0x37, 0x08, 0xef, 0x35, 0x5a, 0x03, 0xe5, 0x08, 0x43, 0xec, 0xdc,
    764     0xb5, 0x2c, 0x1f, 0xe6, 0xeb, 0xc6, 0x06, 0x0b, 0xed, 0xad, 0x74, 0xf4,
    765     0x55, 0xef, 0xe0, 0x2e, 0x83, 0x00, 0xdb, 0x32, 0xde, 0xe9, 0xe4, 0x2f,
    766     0xf5, 0x20, 0x6d, 0x72, 0x47, 0xf4, 0x68, 0xa6, 0x7f, 0x3e, 0x6a, 0x5a,
    767     0x21, 0x76, 0x31, 0x97, 0xa0, 0xc6, 0x7d, 0x03, 0xf7, 0x27, 0x45, 0x5a,
    768     0x75, 0x03, 0xc1, 0x5c, 0x94, 0x2b, 0x37, 0x9f, 0x46, 0x8f, 0xc3, 0xa7,
    769     0x50, 0xe4, 0xe7, 0x23, 0xf7, 0x20, 0xa2, 0x8e, 0x4b, 0xfd, 0x7a, 0xa7,
    770     0x8a, 0x54, 0x7b, 0x32, 0xef, 0x0e, 0x82, 0xb9, 0xf9, 0x14, 0x62, 0x68,
    771     0x32, 0x9e, 0x55, 0xc0, 0xd8, 0xc7, 0x41, 0x9c, 0x67, 0x95, 0xbf, 0xc3,
    772     0x86, 0x74, 0x70, 0x64, 0x44, 0x23, 0x77, 0x79, 0x82, 0x23, 0x1c, 0xf4,
    773     0xa1, 0x05, 0xd3, 0x98, 0x89, 0xde, 0x7d, 0xb3, 0x5b, 0xef, 0x38, 0xd2,
    774     0x07, 0xbc, 0x5a, 0x69, 0xa3, 0xe4, 0x37, 0x9b, 0x53, 0xff, 0x04, 0x6b,
    775     0xd9, 0xd8, 0x32, 0x89, 0xf7, 0x82, 0x77, 0xcf, 0xe6, 0xff, 0xf4, 0x15,
    776     0x54, 0x91, 0x65, 0x96, 0x49, 0xd7, 0x0a, 0xa4, 0xf3, 0x55, 0x2b, 0xc1,
    777     0x48, 0xc1, 0x7e, 0x56, 0x69, 0x27, 0xf4, 0xd1, 0x47, 0x1f, 0xde, 0x86,
    778     0x15, 0x67, 0x04, 0x9d, 0x41, 0x1f, 0xe8, 0xe1, 0x23, 0xe4, 0x56, 0xb9,
    779     0xdb, 0x4e, 0xe4, 0x84, 0x6c, 0x63, 0x39, 0xad, 0x44, 0x6d, 0x4e, 0x28,
    780     0xcd, 0xf6, 0xac, 0xec, 0xc2, 0xad, 0xcd, 0xc3, 0xed, 0x03, 0x63, 0x5d,
    781     0xef, 0x1d, 0x40, 0x8d, 0x9a, 0x02, 0x67, 0x4b, 0x55, 0xb5, 0xfe, 0x75,
    782     0xb6, 0x53, 0x34, 0x1d, 0x7b, 0x26, 0x23, 0xfe, 0xb9, 0x21, 0xd3, 0xe0,
    783     0xa0, 0x1a, 0x85, 0xe5
    784 };
    785 
    786 static const unsigned char stream_10b[1300] = {
    787     0x18, 0x00, 0xd7, 0xfb, 0x12, 0xda, 0xdb, 0x68, 0xeb, 0x38, 0x4d, 0xf6,
    788     0xb2, 0x45, 0x74, 0x4c, 0xcc, 0xe7, 0xa7, 0xc1, 0x26, 0x84, 0x3d, 0xdf,
    789     0x7d, 0xc5, 0xe9, 0xd4, 0x31, 0xa2, 0x51, 0x38, 0x95, 0xe2, 0x68, 0x11,
    790     0x9d, 0xd1, 0x52, 0xb5, 0xef, 0x76, 0xe0, 0x3d, 0x11, 0x50, 0xd7, 0xb2,
    791     0xc1, 0x7d, 0x12, 0xaf, 0x02, 0x52, 0x97, 0x03, 0xf3, 0x2e, 0x54, 0xdf,
    792     0xa0, 0x40, 0x76, 0x52, 0x82, 0x23, 0x3c, 0xbd, 0x20, 0x6d, 0x0a, 0x6f,
    793     0x81, 0xfc, 0x41, 0x9d, 0x2e, 0xa7, 0x2c, 0x78, 0x9c, 0xd8, 0x56, 0xb0,
    794     0x31, 0x35, 0xc8, 0x53, 0xef, 0xf9, 0x43, 0x17, 0xc0, 0x8c, 0x2c, 0x8f,
    795     0x4a, 0x68, 0xe8, 0x9f, 0xbd, 0x3f, 0xf2, 0x18, 0xb8, 0xe6, 0x55, 0xea,
    796     0x2a, 0x37, 0x3e, 0xac, 0xb0, 0x75, 0xd4, 0x75, 0x12, 0x82, 0xec, 0x21,
    797     0xb9, 0xce, 0xe5, 0xc1, 0x62, 0x49, 0xd5, 0xf1, 0xca, 0xd4, 0x32, 0x76,
    798     0x34, 0x5f, 0x3e, 0xc9, 0xb3, 0x54, 0xe4, 0xd0, 0xa9, 0x7d, 0x0c, 0x64,
    799     0x48, 0x0a, 0x74, 0x38, 0x03, 0xd0, 0x20, 0xac, 0xe3, 0x58, 0x3d, 0x4b,
    800     0xa7, 0x46, 0xac, 0x57, 0x63, 0x12, 0x17, 0xcb, 0x96, 0xed, 0xc9, 0x39,
    801     0x64, 0xde, 0xff, 0xc6, 0xb2, 0x40, 0x2c, 0xf9, 0x1d, 0xa6, 0x94, 0x2a,
    802     0x16, 0x4d, 0x7f, 0x22, 0x91, 0x8b, 0xfe, 0x83, 0x77, 0x02, 0x68, 0x62,
    803     0x27, 0x77, 0x2e, 0xe9, 0xce, 0xbc, 0x20, 0xe8, 0xfb, 0xf8, 0x4e, 0x17,
    804     0x07, 0xe1, 0xaa, 0x29, 0xb7, 0x50, 0xcf, 0xb0, 0x6a, 0xcf, 0x01, 0xec,
    805     0xbf, 0xff, 0xb5, 0x9f, 0x00, 0x64, 0x80, 0xbb, 0xa6, 0xe4, 0xa2, 0x1e,
    806     0xe4, 0xf8, 0xa3, 0x0d, 0xc7, 0x65, 0x45, 0xb7, 0x01, 0x33, 0x80, 0x37,
    807     0x11, 0x16, 0x34, 0xc1, 0x06, 0xc5, 0xd3, 0xc4, 0x70, 0x62, 0x75, 0xd8,
    808     0xa3, 0xba, 0x84, 0x9f, 0x81, 0x9f, 0xda, 0x01, 0x83, 0x42, 0x84, 0x05,
    809     0x69, 0x68, 0xb0, 0x74, 0x73, 0x0f, 0x68, 0x39, 0xd3, 0x11, 0xc5, 0x55,
    810     0x3e, 0xf2, 0xb7, 0xf4, 0xa6, 0xed, 0x0b, 0x50, 0xbe, 0x44, 0xf8, 0x67,
    811     0x48, 0x46, 0x5e, 0x71, 0x07, 0xcf, 0xca, 0x8a, 0xbc, 0xa4, 0x3c, 0xd2,
    812     0x4a, 0x80, 0x2e, 0x4f, 0xc5, 0x3b, 0x61, 0xc1, 0x7e, 0x93, 0x9e, 0xe0,
    813     0x05, 0xfb, 0x10, 0xe8, 0x53, 0xff, 0x16, 0x5e, 0x18, 0xe0, 0x9f, 0x39,
    814     0xbf, 0xaa, 0x80, 0x6d, 0xb7, 0x9f, 0x51, 0x91, 0xa0, 0xf6, 0xce, 0xad,
    815     0xed, 0x56, 0x15, 0xb9, 0x12, 0x57, 0x60, 0xa6, 0xae, 0x54, 0x6e, 0x36,
    816     0xf3, 0xe0, 0x05, 0xd8, 0x3e, 0x6d, 0x08, 0x36, 0xc9, 0x79, 0x64, 0x51,
    817     0x63, 0x92, 0xa8, 0xa1, 0xbf, 0x55, 0x26, 0x80, 0x75, 0x44, 0x33, 0x33,
    818     0xfb, 0xb7, 0xec, 0xf9, 0xc6, 0x01, 0xf9, 0xd5, 0x93, 0xfc, 0xb7, 0x43,
    819     0xa2, 0x38, 0x0d, 0x17, 0x75, 0x67, 0xec, 0xc9, 0x98, 0xd6, 0x25, 0xe6,
    820     0xb9, 0xed, 0x61, 0xa4, 0xee, 0x2c, 0xda, 0x27, 0xbd, 0xff, 0x86, 0x1e,
    821     0x45, 0x64, 0xfe, 0xcf, 0x0c, 0x9b, 0x7b, 0x75, 0x5f, 0xf1, 0xe0, 0xba,
    822     0x77, 0x8c, 0x03, 0x8f, 0xb4, 0x3a, 0xb6, 0x9c, 0xda, 0x9a, 0x83, 0xcb,
    823     0xe9, 0xcb, 0x3f, 0xf4, 0x10, 0x99, 0x5b, 0xe1, 0x19, 0x8f, 0x6b, 0x95,
    824     0x50, 0xe6, 0x78, 0xc9, 0x35, 0xb6, 0x87, 0xd8, 0x9e, 0x17, 0x30, 0x96,
    825     0x70, 0xa3, 0x04, 0x69, 0x1c, 0xa2, 0x6c, 0xd4, 0x88, 0x48, 0x44, 0x14,
    826     0x94, 0xd4, 0xc9, 0x4d, 0xe3, 0x82, 0x7e, 0x62, 0xf0, 0x0a, 0x18, 0x4d,
    827     0xd0, 0xd6, 0x63, 0xa3, 0xdf, 0xea, 0x28, 0xf4, 0x00, 0x75, 0x70, 0x78,
    828     0x08, 0x70, 0x3f, 0xff, 0x84, 0x86, 0x72, 0xea, 0x4f, 0x15, 0x8c, 0x17,
    829     0x60, 0x5f, 0xa1, 0x50, 0xa0, 0xfc, 0x6f, 0x8a, 0x46, 0xfc, 0x01, 0x8d,
    830     0x7c, 0xdc, 0x69, 0x6a, 0xd3, 0x74, 0x69, 0x76, 0x77, 0xdd, 0xe4, 0x9c,
    831     0x49, 0x1e, 0x6f, 0x7d, 0x31, 0x14, 0xd9, 0xe9, 0xe7, 0x17, 0x66, 0x82,
    832     0x1b, 0xf1, 0x0f, 0xe2, 0xba, 0xd2, 0x28, 0xd1, 0x6f, 0x48, 0xc7, 0xac,
    833     0x08, 0x4e, 0xee, 0x94, 0x66, 0x99, 0x34, 0x16, 0x5d, 0x95, 0xae, 0xe3,
    834     0x59, 0x79, 0x7f, 0x8e, 0x9f, 0xe3, 0xdb, 0xff, 0xdc, 0x4d, 0xb0, 0xbf,
    835     0xf9, 0xf3, 0x3e, 0xec, 0xcf, 0x50, 0x3d, 0x2d, 0xba, 0x94, 0x1f, 0x1a,
    836     0xab, 0xa4, 0xf4, 0x67, 0x43, 0x7e, 0xb9, 0x65, 0x20, 0x13, 0xb1, 0xd9,
    837     0x88, 0x4a, 0x24, 0x13, 0x84, 0x86, 0xae, 0x2b, 0x0c, 0x6c, 0x7e, 0xd4,
    838     0x25, 0x6e, 0xaa, 0x8d, 0x0c, 0x54, 0x99, 0xde, 0x1d, 0xac, 0x8c, 0x5c,
    839     0x73, 0x94, 0xd9, 0x75, 0xcb, 0x5a, 0x54, 0x3d, 0xeb, 0xff, 0xc1, 0x95,
    840     0x53, 0xb5, 0x39, 0xf7, 0xe5, 0xf1, 0x77, 0xd1, 0x42, 0x82, 0x4b, 0xb0,
    841     0xab, 0x19, 0x28, 0xff, 0x53, 0x28, 0x87, 0x46, 0xc6, 0x6f, 0x05, 0x06,
    842     0xa6, 0x0c, 0x97, 0x93, 0x68, 0x38, 0xe1, 0x61, 0xed, 0xf8, 0x90, 0x13,
    843     0xa3, 0x6f, 0xf2, 0x08, 0x37, 0xd7, 0x05, 0x25, 0x34, 0x43, 0x57, 0x72,
    844     0xfd, 0x6c, 0xc2, 0x19, 0x26, 0xe7, 0x50, 0x30, 0xb8, 0x6d, 0x09, 0x71,
    845     0x83, 0x75, 0xd4, 0x11, 0x25, 0x29, 0xc6, 0xee, 0xb2, 0x51, 0x1c, 0x1c,
    846     0x9e, 0x2d, 0x09, 0xb9, 0x73, 0x2b, 0xbf, 0xda, 0xc8, 0x1e, 0x2b, 0xe5,
    847     0x3f, 0x1e, 0x63, 0xe9, 0xc0, 0x6d, 0x04, 0x3a, 0x48, 0x61, 0xa8, 0xc6,
    848     0x16, 0x8d, 0x69, 0xc0, 0x67, 0x0c, 0x3b, 0xc4, 0x05, 0x36, 0xa1, 0x30,
    849     0x62, 0x92, 0x4d, 0x44, 0x31, 0x66, 0x46, 0xda, 0xef, 0x0f, 0x4e, 0xfb,
    850     0x78, 0x6a, 0xa9, 0x5b, 0xf8, 0x56, 0x26, 0x74, 0x16, 0xab, 0x17, 0x93,
    851     0x3c, 0x36, 0xbb, 0xa2, 0xbf, 0xad, 0xba, 0xb1, 0xfe, 0xc4, 0x9f, 0x75,
    852     0x47, 0x1e, 0x99, 0x7e, 0x32, 0xe8, 0xd4, 0x6c, 0xa4, 0xf8, 0xd2, 0xe4,
    853     0xb2, 0x51, 0xbb, 0xb2, 0xd7, 0xce, 0x94, 0xaf, 0x7f, 0xe6, 0x2c, 0x13,
    854     0xae, 0xd2, 0x29, 0x30, 0x7b, 0xfd, 0x25, 0x61, 0xf9, 0xe8, 0x35, 0x2d,
    855     0x1a, 0xc9, 0x81, 0xa5, 0xfe, 0xce, 0xf6, 0x17, 0xc5, 0xfb, 0x8c, 0x79,
    856     0x67, 0xa8, 0x5f, 0x5c, 0x31, 0xbc, 0xfc, 0xf3, 0x6b, 0xd3, 0x0d, 0xe0,
    857     0x62, 0xab, 0x86, 0xc3, 0x17, 0x5a, 0xba, 0x97, 0x86, 0x8f, 0x65, 0xd6,
    858     0xbd, 0x0c, 0xa1, 0xfb, 0x7f, 0x7c, 0xdc, 0xcb, 0x94, 0x30, 0x0b, 0x04,
    859     0x54, 0xc4, 0x31, 0xa1, 0xca, 0x1e, 0xc5, 0xf0, 0xb6, 0x08, 0xd7, 0x2e,
    860     0xa1, 0x90, 0x41, 0xce, 0xd9, 0xef, 0x3a, 0x58, 0x01, 0x1a, 0x73, 0x18,
    861     0xad, 0xdc, 0x20, 0x25, 0x95, 0x1a, 0xfe, 0x61, 0xf1, 0x58, 0x32, 0x8b,
    862     0x43, 0x59, 0xd6, 0x21, 0xdb, 0xa9, 0x8e, 0x54, 0xe6, 0x21, 0xcf, 0xd3,
    863     0x6b, 0x59, 0x29, 0x9b, 0x3e, 0x6c, 0x7f, 0xe2, 0x29, 0x72, 0x8c, 0xd1,
    864     0x3e, 0x9a, 0x84, 0x98, 0xb0, 0xf3, 0x20, 0x30, 0x34, 0x71, 0xa7, 0x5b,
    865     0xf0, 0x26, 0xe1, 0xf4, 0x76, 0x65, 0xc9, 0xd7, 0xe4, 0xb9, 0x25, 0x48,
    866     0xc2, 0x7e, 0xa6, 0x0b, 0x0d, 0x05, 0x68, 0xa1, 0x96, 0x61, 0x0b, 0x4c,
    867     0x2f, 0x1a, 0xe3, 0x56, 0x71, 0x89, 0x48, 0x66, 0xd8, 0xd0, 0x69, 0x37,
    868     0x7a, 0xdf, 0xdb, 0xed, 0xad, 0x82, 0xaa, 0x40, 0x25, 0x47, 0x3e, 0x75,
    869     0xa6, 0x0e, 0xf5, 0x2f, 0xa7, 0x4e, 0x97, 0xa2, 0x5f, 0x01, 0x99, 0x48,
    870     0x3a, 0x63, 0x18, 0x20, 0x61, 0x72, 0xe4, 0xcf, 0x4b, 0x3b, 0x99, 0x36,
    871     0xe1, 0xf3, 0xbf, 0xae, 0x2b, 0x6b, 0xa1, 0x94, 0xa0, 0x15, 0x94, 0xd6,
    872     0xe0, 0xba, 0x71, 0xa2, 0x85, 0xa0, 0x8c, 0x5e, 0x58, 0xe2, 0xde, 0x6b,
    873     0x08, 0x68, 0x90, 0x82, 0x71, 0x8d, 0xfd, 0x12, 0xa2, 0x49, 0x87, 0x70,
    874     0xee, 0x2a, 0x08, 0xe2, 0x26, 0xaf, 0xeb, 0x85, 0x35, 0xd2, 0x0e, 0xfd,
    875     0x2b, 0x6f, 0xc0, 0xfe, 0x41, 0xbb, 0xd7, 0x0a, 0xa3, 0x8d, 0x8b, 0xec,
    876     0x44, 0x9f, 0x46, 0x59, 0x4d, 0xac, 0x04, 0x1e, 0xde, 0x10, 0x7b, 0x17,
    877     0x0a, 0xb0, 0xcc, 0x26, 0x0c, 0xa9, 0x3c, 0x5f, 0xd8, 0xe6, 0x52, 0xd3,
    878     0xfd, 0x0b, 0x66, 0x75, 0x06, 0x84, 0x23, 0x64, 0x2b, 0x80, 0x68, 0xf9,
    879     0xcb, 0xcd, 0x04, 0x07, 0xf7, 0xe0, 0x07, 0xb4, 0xc6, 0xa0, 0x08, 0xd0,
    880     0x76, 0x16, 0x77, 0xd8, 0x48, 0xf0, 0x45, 0x4e, 0xe2, 0xf2, 0x88, 0xcd,
    881     0x0f, 0xbd, 0x7d, 0xb6, 0xbe, 0x4e, 0x9e, 0x5d, 0x6c, 0x47, 0x26, 0x34,
    882     0x94, 0xfb, 0xc5, 0x4f, 0x5c, 0xb5, 0xb5, 0xfc, 0x99, 0x34, 0x71, 0xe5,
    883     0xe1, 0x36, 0x0c, 0xd2, 0x95, 0xb8, 0x93, 0x3c, 0x5d, 0x2d, 0x71, 0x55,
    884     0x0b, 0x96, 0x4e, 0x9f, 0x07, 0x9a, 0x38, 0x9a, 0xcc, 0x24, 0xb5, 0xac,
    885     0x05, 0x8b, 0x1c, 0x61, 0xd4, 0xf2, 0xdf, 0x9e, 0x11, 0xe3, 0x7d, 0x64,
    886     0x2f, 0xe5, 0x13, 0xd4, 0x0a, 0xe9, 0x32, 0x26, 0xa8, 0x93, 0x21, 0x59,
    887     0xf3, 0x41, 0x48, 0x0a, 0xbd, 0x59, 0x8f, 0xf8, 0x72, 0xab, 0xd3, 0x65,
    888     0x8e, 0xdc, 0xaa, 0x0c, 0xc0, 0x01, 0x36, 0xb7, 0xf5, 0x84, 0x27, 0x9a,
    889     0x98, 0x89, 0x73, 0x3a, 0xeb, 0x55, 0x15, 0xc9, 0x3d, 0xe1, 0xf8, 0xea,
    890     0xf6, 0x11, 0x28, 0xe0, 0x80, 0x93, 0xcc, 0xba, 0xe1, 0xf1, 0x81, 0xbc,
    891     0xa4, 0x30, 0xbc, 0x98, 0xe8, 0x9e, 0x8d, 0x17, 0x7e, 0xb7, 0xb1, 0x27,
    892     0x6f, 0xcf, 0x9c, 0x0d, 0x1d, 0x01, 0xea, 0x45, 0xc0, 0x90, 0xda, 0x53,
    893     0xf6, 0xde, 0xdf, 0x12, 0xa1, 0x23, 0x3d, 0x92, 0x89, 0x77, 0xa7, 0x2a,
    894     0xe7, 0x45, 0x24, 0xdd, 0xf2, 0x17, 0x10, 0xca, 0x6e, 0x14, 0xb2, 0x77,
    895     0x08, 0xc4, 0x18, 0xcd
    896 };
    897 
    898 static uint64_t stream_10a_off, stream_10b_off;
    899 
    900 static int check_stream_10a(struct helper *h)
    901 {
    902     /*
    903      * Must have filled or almost filled the packet (using default MDPL of
    904      * 1200).
    905      */
    906     if (!TEST_uint64_t_ge(h->frame.stream.len, 1150)
    907         || !TEST_uint64_t_le(h->frame.stream.len, 1200))
    908         return 0;
    909 
    910     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
    911             stream_10a, (size_t)h->frame.stream.len))
    912         return 0;
    913 
    914     stream_10a_off = h->frame.stream.offset + h->frame.stream.len;
    915     return 1;
    916 }
    917 
    918 static int check_stream_10b(struct helper *h)
    919 {
    920     if (!TEST_uint64_t_ge(h->frame.stream.len, 1150)
    921         || !TEST_uint64_t_le(h->frame.stream.len, 1200))
    922         return 0;
    923 
    924     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
    925             stream_10b, (size_t)h->frame.stream.len))
    926         return 0;
    927 
    928     stream_10b_off = h->frame.stream.offset + h->frame.stream.len;
    929     return 1;
    930 }
    931 
    932 static int check_stream_10c(struct helper *h)
    933 {
    934     if (!TEST_uint64_t_ge(h->frame.stream.len, 5)
    935         || !TEST_uint64_t_le(h->frame.stream.len, 200))
    936         return 0;
    937 
    938     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
    939             stream_10a + stream_10a_off, (size_t)h->frame.stream.len))
    940         return 0;
    941 
    942     return 1;
    943 }
    944 
    945 static int check_stream_10d(struct helper *h)
    946 {
    947     if (!TEST_uint64_t_ge(h->frame.stream.len, 5)
    948         || !TEST_uint64_t_le(h->frame.stream.len, 200))
    949         return 0;
    950 
    951     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
    952             stream_10b + stream_10b_off, (size_t)h->frame.stream.len))
    953         return 0;
    954 
    955     return 1;
    956 }
    957 
    958 static const struct script_op script_10[] = {
    959     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
    960         OP_HANDSHAKE_COMPLETE()
    961             OP_TXP_GENERATE_NONE()
    962                 OP_STREAM_NEW(42)
    963                     OP_STREAM_NEW(43)
    964                         OP_CONN_TXFC_BUMP(10000)
    965                             OP_STREAM_TXFC_BUMP(42, 5000)
    966                                 OP_STREAM_TXFC_BUMP(43, 5000)
    967                                     OP_STREAM_SEND(42, stream_10a)
    968                                         OP_STREAM_SEND(43, stream_10b)
    969 
    970     /* First packet containing data from stream 42 */
    971     OP_TXP_GENERATE()
    972         OP_RX_PKT()
    973             OP_EXPECT_DGRAM_LEN(1100, 1200)
    974                 OP_NEXT_FRAME()
    975                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
    976                         OP_CHECK(check_stream_10a)
    977                             OP_EXPECT_NO_FRAME()
    978 
    979     /* Second packet containing data from stream 43 */
    980     OP_TXP_GENERATE()
    981         OP_RX_PKT()
    982             OP_EXPECT_DGRAM_LEN(1100, 1200)
    983                 OP_NEXT_FRAME()
    984                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
    985                         OP_CHECK(check_stream_10b)
    986                             OP_EXPECT_NO_FRAME()
    987 
    988     /* Third packet containing data from stream 42 */
    989     OP_TXP_GENERATE()
    990         OP_RX_PKT()
    991             OP_EXPECT_DGRAM_LEN(200, 500)
    992                 OP_NEXT_FRAME()
    993                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN)
    994                         OP_CHECK(check_stream_10c)
    995                             OP_NEXT_FRAME()
    996                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM_OFF)
    997                                     OP_CHECK(check_stream_10d)
    998                                         OP_EXPECT_NO_FRAME()
    999 
   1000                                             OP_RX_PKT_NONE()
   1001                                                 OP_TXP_GENERATE_NONE()
   1002 
   1003                                                     OP_END
   1004 };
   1005 
   1006 /* 11. Initial, CRYPTO */
   1007 static const struct script_op script_11[] = {
   1008     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
   1009         OP_TXP_GENERATE_NONE()
   1010             OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, crypto_1)
   1011                 OP_TXP_GENERATE()
   1012                     OP_RX_PKT()
   1013                         OP_EXPECT_DGRAM_LEN(1200, 1200)
   1014                             OP_NEXT_FRAME()
   1015                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
   1016                                     OP_EXPECT_NO_FRAME()
   1017                                         OP_RX_PKT_NONE()
   1018                                             OP_TXP_GENERATE_NONE()
   1019                                                 OP_END
   1020 };
   1021 
   1022 /* 12. 1-RTT, STOP_SENDING */
   1023 static int check_stream_12(struct helper *h)
   1024 {
   1025     if (!TEST_uint64_t_eq(h->frame.stop_sending.stream_id, 42)
   1026         || !TEST_uint64_t_eq(h->frame.stop_sending.app_error_code, 4568))
   1027         return 0;
   1028 
   1029     return 1;
   1030 }
   1031 
   1032 static const struct script_op script_12[] = {
   1033     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
   1034         OP_HANDSHAKE_COMPLETE()
   1035             OP_TXP_GENERATE_NONE()
   1036                 OP_STREAM_NEW(42)
   1037                     OP_STOP_SENDING(42, 4568)
   1038                         OP_TXP_GENERATE()
   1039                             OP_RX_PKT()
   1040                                 OP_EXPECT_DGRAM_LEN(21, 128)
   1041                                     OP_NEXT_FRAME()
   1042                                         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STOP_SENDING)
   1043                                             OP_CHECK(check_stream_12)
   1044                                                 OP_EXPECT_NO_FRAME()
   1045                                                     OP_RX_PKT_NONE()
   1046                                                         OP_TXP_GENERATE_NONE()
   1047                                                             OP_END
   1048 };
   1049 
   1050 /* 13. 1-RTT, RESET_STREAM */
   1051 static const unsigned char stream_13[] = {
   1052     0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x7a, 0x7b
   1053 };
   1054 
   1055 static ossl_unused int check_stream_13(struct helper *h)
   1056 {
   1057     if (!TEST_uint64_t_eq(h->frame.reset_stream.stream_id, 42)
   1058         || !TEST_uint64_t_eq(h->frame.reset_stream.app_error_code, 4568)
   1059         || !TEST_uint64_t_eq(h->frame.reset_stream.final_size, 0))
   1060         return 0;
   1061 
   1062     return 1;
   1063 }
   1064 
   1065 static const struct script_op script_13[] = {
   1066     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
   1067         OP_HANDSHAKE_COMPLETE()
   1068             OP_TXP_GENERATE_NONE()
   1069                 OP_STREAM_NEW(42)
   1070                     OP_CONN_TXFC_BUMP(8)
   1071                         OP_STREAM_TXFC_BUMP(42, 8)
   1072                             OP_STREAM_SEND(42, stream_13)
   1073                                 OP_RESET_STREAM(42, 4568)
   1074                                     OP_TXP_GENERATE()
   1075                                         OP_RX_PKT()
   1076                                             OP_EXPECT_DGRAM_LEN(21, 128)
   1077                                                 OP_NEXT_FRAME()
   1078                                                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_RESET_STREAM)
   1079                                                         OP_CHECK(check_stream_13)
   1080                                                             OP_NEXT_FRAME()
   1081                                                                 OP_EXPECT_NO_FRAME()
   1082                                                                     OP_RX_PKT_NONE()
   1083                                                                         OP_TXP_GENERATE_NONE()
   1084                                                                             OP_END
   1085 };
   1086 
   1087 /* 14. 1-RTT, CONNECTION_CLOSE */
   1088 static int gen_conn_close(struct helper *h)
   1089 {
   1090     OSSL_QUIC_FRAME_CONN_CLOSE f = { 0 };
   1091 
   1092     f.error_code = 2345;
   1093     f.frame_type = OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE;
   1094     f.reason = "Reason string";
   1095     f.reason_len = strlen(f.reason);
   1096 
   1097     if (!TEST_true(ossl_quic_tx_packetiser_schedule_conn_close(h->txp, &f)))
   1098         return 0;
   1099 
   1100     return 1;
   1101 }
   1102 
   1103 static int check_14(struct helper *h)
   1104 {
   1105     if (!TEST_int_eq(h->frame.conn_close.is_app, 0)
   1106         || !TEST_uint64_t_eq(h->frame.conn_close.frame_type,
   1107             OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE)
   1108         || !TEST_uint64_t_eq(h->frame.conn_close.error_code, 2345)
   1109         || !TEST_mem_eq(h->frame.conn_close.reason, h->frame.conn_close.reason_len,
   1110             "Reason string", 13))
   1111         return 0;
   1112 
   1113     return 1;
   1114 }
   1115 
   1116 static const struct script_op script_14[] = {
   1117     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
   1118         OP_HANDSHAKE_COMPLETE()
   1119             OP_TXP_GENERATE_NONE()
   1120                 OP_CHECK(gen_conn_close)
   1121                     OP_TXP_GENERATE()
   1122                         OP_RX_PKT()
   1123                             OP_EXPECT_DGRAM_LEN(21, 512)
   1124                                 OP_NEXT_FRAME()
   1125                                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT)
   1126                                         OP_CHECK(check_14)
   1127                                             OP_EXPECT_NO_FRAME()
   1128                                                 OP_RX_PKT_NONE()
   1129                                                     OP_END
   1130 };
   1131 
   1132 /* 15. INITIAL, Anti-Deadlock Probe Simulation */
   1133 static int gen_probe_initial(struct helper *h)
   1134 {
   1135     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
   1136 
   1137     /*
   1138      * Pretend the ACKM asked for an anti-deadlock Initial probe.
   1139      * We test output of this in the ACKM unit tests.
   1140      */
   1141     ++probe->anti_deadlock_initial;
   1142     return 1;
   1143 }
   1144 
   1145 static const struct script_op script_15[] = {
   1146     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
   1147         OP_TXP_GENERATE_NONE()
   1148             OP_CHECK(gen_probe_initial)
   1149                 OP_TXP_GENERATE()
   1150                     OP_RX_PKT()
   1151                         OP_EXPECT_DGRAM_LEN(1200, 1200)
   1152                             OP_NEXT_FRAME()
   1153                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
   1154                                     OP_EXPECT_NO_FRAME()
   1155                                         OP_RX_PKT_NONE()
   1156                                             OP_TXP_GENERATE_NONE()
   1157                                                 OP_END
   1158 };
   1159 
   1160 /* 16. HANDSHAKE, Anti-Deadlock Probe Simulation */
   1161 static int gen_probe_handshake(struct helper *h)
   1162 {
   1163     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
   1164 
   1165     /*
   1166      * Pretend the ACKM asked for an anti-deadlock Handshake probe.
   1167      * We test output of this in the ACKM unit tests.
   1168      */
   1169     ++probe->anti_deadlock_handshake;
   1170     return 1;
   1171 }
   1172 
   1173 static const struct script_op script_16[] = {
   1174     OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
   1175         OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE, QRL_SUITE_AES128GCM, secret_1)
   1176             OP_TXP_GENERATE_NONE()
   1177                 OP_CHECK(gen_probe_handshake)
   1178                     OP_TXP_GENERATE()
   1179                         OP_RX_PKT()
   1180                             OP_EXPECT_DGRAM_LEN(21, 512)
   1181                                 OP_NEXT_FRAME()
   1182                                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
   1183                                         OP_EXPECT_NO_FRAME()
   1184                                             OP_RX_PKT_NONE()
   1185                                                 OP_TXP_GENERATE_NONE()
   1186                                                     OP_END
   1187 };
   1188 
   1189 /* 17. 1-RTT, Probe Simulation */
   1190 static int gen_probe_1rtt(struct helper *h)
   1191 {
   1192     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
   1193 
   1194     /*
   1195      * Pretend the ACKM asked for a 1-RTT PTO probe.
   1196      * We test output of this in the ACKM unit tests.
   1197      */
   1198     ++probe->pto[QUIC_PN_SPACE_APP];
   1199     return 1;
   1200 }
   1201 
   1202 static const struct script_op script_17[] = {
   1203     OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
   1204         OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
   1205             OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
   1206                 OP_TXP_GENERATE_NONE()
   1207                     OP_CHECK(gen_probe_1rtt)
   1208                         OP_TXP_GENERATE()
   1209                             OP_RX_PKT()
   1210                                 OP_EXPECT_DGRAM_LEN(21, 512)
   1211                                     OP_NEXT_FRAME()
   1212                                         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
   1213                                             OP_EXPECT_NO_FRAME()
   1214                                                 OP_RX_PKT_NONE()
   1215                                                     OP_TXP_GENERATE_NONE()
   1216                                                         OP_END
   1217 };
   1218 
   1219 /* 18. Big Token Rejection */
   1220 static const unsigned char big_token[1950];
   1221 
   1222 static int try_big_token(struct helper *h)
   1223 {
   1224     size_t i;
   1225 
   1226     /* Ensure big token is rejected */
   1227     if (!TEST_false(ossl_quic_tx_packetiser_set_initial_token(h->txp,
   1228             big_token,
   1229             sizeof(big_token),
   1230             NULL,
   1231             NULL)))
   1232         return 0;
   1233 
   1234     /*
   1235      * Keep trying until we find an acceptable size, then make sure
   1236      * that works for generation
   1237      */
   1238     for (i = sizeof(big_token) - 1;; --i) {
   1239         if (!TEST_size_t_gt(i, 0))
   1240             return 0;
   1241 
   1242         if (ossl_quic_tx_packetiser_set_initial_token(h->txp, big_token, i,
   1243                 NULL, NULL))
   1244             break;
   1245     }
   1246 
   1247     return 1;
   1248 }
   1249 
   1250 static const struct script_op script_18[] = {
   1251     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
   1252         OP_TXP_GENERATE_NONE()
   1253             OP_CHECK(try_big_token)
   1254                 OP_TXP_GENERATE_NONE()
   1255                     OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, crypto_1)
   1256                         OP_TXP_GENERATE()
   1257                             OP_RX_PKT()
   1258                                 OP_EXPECT_DGRAM_LEN(1200, 1200)
   1259                                     OP_NEXT_FRAME()
   1260                                         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
   1261                                             OP_EXPECT_NO_FRAME()
   1262                                                 OP_RX_PKT_NONE()
   1263                                                     OP_TXP_GENERATE_NONE()
   1264                                                         OP_END
   1265 };
   1266 
   1267 static const struct script_op *const scripts[] = {
   1268     script_1,
   1269     script_2,
   1270     script_3,
   1271     script_4,
   1272     script_5,
   1273     script_6,
   1274     script_7,
   1275     script_8,
   1276     script_9,
   1277     script_10,
   1278     script_11,
   1279     script_12,
   1280     script_13,
   1281     script_14,
   1282     script_15,
   1283     script_16,
   1284     script_17,
   1285     script_18
   1286 };
   1287 
   1288 static void skip_padding(struct helper *h)
   1289 {
   1290     uint64_t frame_type;
   1291 
   1292     if (!ossl_quic_wire_peek_frame_header(&h->pkt, &frame_type, NULL))
   1293         return; /* EOF */
   1294 
   1295     if (frame_type == OSSL_QUIC_FRAME_TYPE_PADDING)
   1296         ossl_quic_wire_decode_padding(&h->pkt);
   1297 }
   1298 
   1299 static int run_script(int script_idx, const struct script_op *script)
   1300 {
   1301     int testresult = 0, have_helper = 0;
   1302     QUIC_TXP_STATUS status;
   1303     struct helper h;
   1304     const struct script_op *op;
   1305     size_t opn = 0;
   1306 
   1307     if (!helper_init(&h))
   1308         goto err;
   1309 
   1310     have_helper = 1;
   1311     for (op = script, opn = 0; op->opcode != OPK_END; ++op, ++opn) {
   1312         switch (op->opcode) {
   1313         case OPK_TXP_GENERATE:
   1314             if (!TEST_true(ossl_quic_tx_packetiser_generate(h.txp, &status))
   1315                 && !TEST_size_t_gt(status.sent_pkt, 0))
   1316                 goto err;
   1317 
   1318             ossl_qtx_finish_dgram(h.args.qtx);
   1319             ossl_qtx_flush_net(h.args.qtx);
   1320             break;
   1321         case OPK_TXP_GENERATE_NONE:
   1322             if (!TEST_true(ossl_quic_tx_packetiser_generate(h.txp, &status))
   1323                 && !TEST_size_t_eq(status.sent_pkt, 0))
   1324                 goto err;
   1325 
   1326             break;
   1327         case OPK_RX_PKT:
   1328             ossl_quic_demux_pump(h.demux);
   1329             ossl_qrx_pkt_release(h.qrx_pkt);
   1330             h.qrx_pkt = NULL;
   1331             if (!TEST_true(ossl_qrx_read_pkt(h.qrx, &h.qrx_pkt)))
   1332                 goto err;
   1333             if (!TEST_true(PACKET_buf_init(&h.pkt,
   1334                     h.qrx_pkt->hdr->data,
   1335                     h.qrx_pkt->hdr->len)))
   1336                 goto err;
   1337             h.frame_type = UINT64_MAX;
   1338             break;
   1339         case OPK_RX_PKT_NONE:
   1340             ossl_quic_demux_pump(h.demux);
   1341             if (!TEST_false(ossl_qrx_read_pkt(h.qrx, &h.qrx_pkt)))
   1342                 goto err;
   1343             h.frame_type = UINT64_MAX;
   1344             break;
   1345         case OPK_EXPECT_DGRAM_LEN:
   1346             if (!TEST_size_t_ge(h.qrx_pkt->datagram_len, (size_t)op->arg0)
   1347                 || !TEST_size_t_le(h.qrx_pkt->datagram_len, (size_t)op->arg1))
   1348                 goto err;
   1349             break;
   1350         case OPK_EXPECT_FRAME:
   1351             if (!TEST_uint64_t_eq(h.frame_type, op->arg0))
   1352                 goto err;
   1353             break;
   1354         case OPK_EXPECT_INITIAL_TOKEN:
   1355             if (!TEST_mem_eq(h.qrx_pkt->hdr->token, h.qrx_pkt->hdr->token_len,
   1356                     op->buf, (size_t)op->arg0))
   1357                 goto err;
   1358             break;
   1359         case OPK_EXPECT_HDR:
   1360             if (!TEST_true(cmp_pkt_hdr(h.qrx_pkt->hdr, op->buf,
   1361                     NULL, 0, 0)))
   1362                 goto err;
   1363             break;
   1364         case OPK_CHECK:
   1365             if (!TEST_true(op->check_func(&h)))
   1366                 goto err;
   1367             break;
   1368         case OPK_NEXT_FRAME:
   1369             skip_padding(&h);
   1370             if (!ossl_quic_wire_peek_frame_header(&h.pkt, &h.frame_type, NULL)) {
   1371                 h.frame_type = UINT64_MAX;
   1372                 break;
   1373             }
   1374 
   1375             switch (h.frame_type) {
   1376             case OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE:
   1377                 if (!TEST_true(ossl_quic_wire_decode_frame_handshake_done(&h.pkt)))
   1378                     goto err;
   1379                 break;
   1380             case OSSL_QUIC_FRAME_TYPE_PING:
   1381                 if (!TEST_true(ossl_quic_wire_decode_frame_ping(&h.pkt)))
   1382                     goto err;
   1383                 break;
   1384             case OSSL_QUIC_FRAME_TYPE_MAX_DATA:
   1385                 if (!TEST_true(ossl_quic_wire_decode_frame_max_data(&h.pkt,
   1386                         &h.frame.max_data)))
   1387                     goto err;
   1388                 break;
   1389             case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID:
   1390                 if (!TEST_true(ossl_quic_wire_decode_frame_new_conn_id(&h.pkt,
   1391                         &h.frame.new_conn_id)))
   1392                     goto err;
   1393                 break;
   1394             case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN:
   1395                 if (!TEST_true(ossl_quic_wire_decode_frame_new_token(&h.pkt,
   1396                         &h.frame.new_token.token,
   1397                         &h.frame.new_token.token_len)))
   1398                     goto err;
   1399                 break;
   1400             case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN:
   1401             case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN:
   1402                 h.frame.ack.ack_ranges = h.ack_ranges;
   1403                 h.frame.ack.num_ack_ranges = OSSL_NELEM(h.ack_ranges);
   1404                 if (!TEST_true(ossl_quic_wire_decode_frame_ack(&h.pkt,
   1405                         h.args.ack_delay_exponent,
   1406                         &h.frame.ack,
   1407                         NULL)))
   1408                     goto err;
   1409                 break;
   1410             case OSSL_QUIC_FRAME_TYPE_CRYPTO:
   1411                 if (!TEST_true(ossl_quic_wire_decode_frame_crypto(&h.pkt, 0, &h.frame.crypto)))
   1412                     goto err;
   1413                 break;
   1414 
   1415             case OSSL_QUIC_FRAME_TYPE_STREAM:
   1416             case OSSL_QUIC_FRAME_TYPE_STREAM_FIN:
   1417             case OSSL_QUIC_FRAME_TYPE_STREAM_LEN:
   1418             case OSSL_QUIC_FRAME_TYPE_STREAM_LEN_FIN:
   1419             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF:
   1420             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_FIN:
   1421             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN:
   1422             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN_FIN:
   1423                 if (!TEST_true(ossl_quic_wire_decode_frame_stream(&h.pkt, 0, &h.frame.stream)))
   1424                     goto err;
   1425                 break;
   1426 
   1427             case OSSL_QUIC_FRAME_TYPE_STOP_SENDING:
   1428                 if (!TEST_true(ossl_quic_wire_decode_frame_stop_sending(&h.pkt,
   1429                         &h.frame.stop_sending)))
   1430                     goto err;
   1431                 break;
   1432 
   1433             case OSSL_QUIC_FRAME_TYPE_RESET_STREAM:
   1434                 if (!TEST_true(ossl_quic_wire_decode_frame_reset_stream(&h.pkt,
   1435                         &h.frame.reset_stream)))
   1436                     goto err;
   1437                 break;
   1438 
   1439             case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT:
   1440             case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP:
   1441                 if (!TEST_true(ossl_quic_wire_decode_frame_conn_close(&h.pkt,
   1442                         &h.frame.conn_close)))
   1443                     goto err;
   1444                 break;
   1445 
   1446             default:
   1447                 TEST_error("unknown frame type");
   1448                 goto err;
   1449             }
   1450             break;
   1451         case OPK_EXPECT_NO_FRAME:
   1452             skip_padding(&h);
   1453             if (!TEST_size_t_eq(PACKET_remaining(&h.pkt), 0))
   1454                 goto err;
   1455             break;
   1456         case OPK_PROVIDE_SECRET:
   1457             if (!TEST_true(ossl_qtx_provide_secret(h.args.qtx,
   1458                     (uint32_t)op->arg0,
   1459                     (uint32_t)op->arg1,
   1460                     NULL, op->buf, op->buf_len)))
   1461                 goto err;
   1462             if (!TEST_true(ossl_qrx_provide_secret(h.qrx,
   1463                     (uint32_t)op->arg0,
   1464                     (uint32_t)op->arg1,
   1465                     NULL, op->buf, op->buf_len)))
   1466                 goto err;
   1467             break;
   1468         case OPK_DISCARD_EL:
   1469             if (!TEST_true(ossl_quic_tx_packetiser_discard_enc_level(h.txp,
   1470                     (uint32_t)op->arg0)))
   1471                 goto err;
   1472             /*
   1473              * We do not discard on the QRX here, the object is to test the
   1474              * TXP so if the TXP does erroneously send at a discarded EL we
   1475              * want to know about it.
   1476              */
   1477             break;
   1478         case OPK_CRYPTO_SEND: {
   1479             size_t consumed = 0;
   1480 
   1481             if (!TEST_true(ossl_quic_sstream_append(h.args.crypto[op->arg0],
   1482                     op->buf, op->buf_len,
   1483                     &consumed)))
   1484                 goto err;
   1485 
   1486             if (!TEST_size_t_eq(consumed, op->buf_len))
   1487                 goto err;
   1488         } break;
   1489         case OPK_STREAM_NEW: {
   1490             QUIC_STREAM *s;
   1491 
   1492             if (!TEST_ptr(s = ossl_quic_stream_map_alloc(h.args.qsm, op->arg0,
   1493                               QUIC_STREAM_DIR_BIDI)))
   1494                 goto err;
   1495 
   1496             if (!TEST_ptr(s->sstream = ossl_quic_sstream_new(512 * 1024))
   1497                 || !TEST_true(ossl_quic_txfc_init(&s->txfc, &h.conn_txfc))
   1498                 || !TEST_true(ossl_quic_rxfc_init(&s->rxfc, &h.conn_rxfc,
   1499                     1 * 1024 * 1024,
   1500                     16 * 1024 * 1024,
   1501                     fake_now, NULL))
   1502                 || !TEST_ptr(s->rstream = ossl_quic_rstream_new(&s->rxfc,
   1503                                  NULL, 1024))) {
   1504                 ossl_quic_sstream_free(s->sstream);
   1505                 ossl_quic_stream_map_release(h.args.qsm, s);
   1506                 goto err;
   1507             }
   1508         } break;
   1509         case OPK_STREAM_SEND: {
   1510             QUIC_STREAM *s;
   1511             size_t consumed = 0;
   1512 
   1513             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
   1514                               op->arg0)))
   1515                 goto err;
   1516 
   1517             if (!TEST_true(ossl_quic_sstream_append(s->sstream, op->buf,
   1518                     op->buf_len, &consumed)))
   1519                 goto err;
   1520 
   1521             if (!TEST_size_t_eq(consumed, op->buf_len))
   1522                 goto err;
   1523 
   1524             ossl_quic_stream_map_update_state(h.args.qsm, s);
   1525         } break;
   1526         case OPK_STREAM_FIN: {
   1527             QUIC_STREAM *s;
   1528 
   1529             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
   1530                               op->arg0)))
   1531                 goto err;
   1532 
   1533             ossl_quic_sstream_fin(s->sstream);
   1534         } break;
   1535         case OPK_STOP_SENDING: {
   1536             QUIC_STREAM *s;
   1537 
   1538             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
   1539                               op->arg0)))
   1540                 goto err;
   1541 
   1542             if (!TEST_true(ossl_quic_stream_map_stop_sending_recv_part(h.args.qsm,
   1543                     s, op->arg1)))
   1544                 goto err;
   1545 
   1546             ossl_quic_stream_map_update_state(h.args.qsm, s);
   1547 
   1548             if (!TEST_true(s->active))
   1549                 goto err;
   1550         } break;
   1551         case OPK_RESET_STREAM: {
   1552             QUIC_STREAM *s;
   1553 
   1554             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
   1555                               op->arg0)))
   1556                 goto err;
   1557 
   1558             if (!TEST_true(ossl_quic_stream_map_reset_stream_send_part(h.args.qsm,
   1559                     s, op->arg1)))
   1560                 goto err;
   1561 
   1562             ossl_quic_stream_map_update_state(h.args.qsm, s);
   1563 
   1564             if (!TEST_true(s->active))
   1565                 goto err;
   1566         } break;
   1567         case OPK_CONN_TXFC_BUMP:
   1568             if (!TEST_true(ossl_quic_txfc_bump_cwm(h.args.conn_txfc, op->arg0)))
   1569                 goto err;
   1570 
   1571             break;
   1572         case OPK_STREAM_TXFC_BUMP: {
   1573             QUIC_STREAM *s;
   1574 
   1575             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
   1576                               op->arg1)))
   1577                 goto err;
   1578 
   1579             if (!TEST_true(ossl_quic_txfc_bump_cwm(&s->txfc, op->arg0)))
   1580                 goto err;
   1581 
   1582             ossl_quic_stream_map_update_state(h.args.qsm, s);
   1583         } break;
   1584         case OPK_HANDSHAKE_COMPLETE:
   1585             ossl_quic_tx_packetiser_notify_handshake_complete(h.txp);
   1586             break;
   1587         case OPK_NOP:
   1588             break;
   1589         default:
   1590             TEST_error("bad opcode");
   1591             goto err;
   1592         }
   1593     }
   1594 
   1595     testresult = 1;
   1596 err:
   1597     if (!testresult)
   1598         TEST_error("script %d failed at op %zu", script_idx + 1, opn + 1);
   1599     if (have_helper)
   1600         helper_cleanup(&h);
   1601     return testresult;
   1602 }
   1603 
   1604 static int test_script(int idx)
   1605 {
   1606     return run_script(idx, scripts[idx]);
   1607 }
   1608 
   1609 /*
   1610  * Dynamic Script 1.
   1611  *
   1612  * This script exists to test the interactions between multiple packets (ELs) in
   1613  * the same datagram when there is a padding requirement (due to the datagram
   1614  * containing an Initial packet). There are boundary cases which are difficult
   1615  * to get right so it is important to test this entire space. Examples of such
   1616  * edge cases include:
   1617  *
   1618  * - If we are planning on generating both an Initial and Handshake packet in a
   1619  *   datagram ordinarily we would plan on adding the padding frames to meet the
   1620  *   mandatory minimum size to the last packet in the datagram (i.e., the
   1621  *   Handshake packet). But if the amount of room remaining in a datagram is
   1622  *   e.g. only 3 bytes after generating the Initial packet, this is not
   1623  *   enough room for another packet and we have a problem as having finished
   1624  *   the Initial packet we have no way to add the necessary padding.
   1625  *
   1626  * - If we do have room for another packet but it is not enough room to encode
   1627  *   any desired frame.
   1628  *
   1629  * This test confirms we handle these cases correctly for multi-packet datagrams
   1630  * by placing two packets in a datagram and varying the size of the first
   1631  * datagram.
   1632  */
   1633 static const unsigned char dyn_script_1_crypto_1a[1200];
   1634 static const unsigned char dyn_script_1_crypto_1b[1];
   1635 
   1636 static int check_is_initial(struct helper *h)
   1637 {
   1638     return h->qrx_pkt->hdr->type == QUIC_PKT_TYPE_INITIAL;
   1639 }
   1640 
   1641 static int check_is_handshake(struct helper *h)
   1642 {
   1643     return h->qrx_pkt->hdr->type == QUIC_PKT_TYPE_HANDSHAKE;
   1644 }
   1645 
   1646 static struct script_op dyn_script_1[] = {
   1647     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
   1648         OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE, QRL_SUITE_AES128GCM, secret_1)
   1649             OP_TXP_GENERATE_NONE()
   1650                 OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, dyn_script_1_crypto_1a) /* [crypto_idx] */
   1651     OP_CRYPTO_SEND(QUIC_PN_SPACE_HANDSHAKE, dyn_script_1_crypto_1b)
   1652         OP_TXP_GENERATE()
   1653             OP_RX_PKT()
   1654                 OP_EXPECT_DGRAM_LEN(1200, 1200)
   1655                     OP_CHECK(check_is_initial)
   1656                         OP_NOP() /* [pkt_idx] */
   1657     OP_NOP() /* [check_idx] */
   1658     OP_END
   1659 };
   1660 
   1661 static const size_t dyn_script_1_crypto_idx = 3;
   1662 static const size_t dyn_script_1_pkt_idx = 9;
   1663 static const size_t dyn_script_1_check_idx = 10;
   1664 static const size_t dyn_script_1_start_from = 1000;
   1665 
   1666 static int test_dyn_script_1(int idx)
   1667 {
   1668     size_t target_size = dyn_script_1_start_from + (size_t)idx;
   1669     int expect_handshake_pkt_in_same_dgram = (target_size <= 1115);
   1670 
   1671     dyn_script_1[dyn_script_1_crypto_idx].buf_len = target_size;
   1672 
   1673     if (expect_handshake_pkt_in_same_dgram) {
   1674         dyn_script_1[dyn_script_1_pkt_idx].opcode = OPK_RX_PKT;
   1675         dyn_script_1[dyn_script_1_check_idx].opcode = OPK_CHECK;
   1676         dyn_script_1[dyn_script_1_check_idx].check_func = check_is_handshake;
   1677     } else {
   1678         dyn_script_1[dyn_script_1_pkt_idx].opcode = OPK_RX_PKT_NONE;
   1679         dyn_script_1[dyn_script_1_check_idx].opcode = OPK_NOP;
   1680     }
   1681 
   1682     if (!run_script(idx, dyn_script_1)) {
   1683         TEST_error("failed dyn script 1 with target size %zu", target_size);
   1684         return 0;
   1685     }
   1686 
   1687     return 1;
   1688 }
   1689 
   1690 int setup_tests(void)
   1691 {
   1692     ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts));
   1693     ADD_ALL_TESTS(test_dyn_script_1,
   1694         OSSL_NELEM(dyn_script_1_crypto_1a)
   1695             - dyn_script_1_start_from + 1);
   1696     return 1;
   1697 }
   1698