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