QUIC MULTISTREAM TEST: Test idle timeout configuration
[openssl.git] / test / quic_record_test.c
1 /*
2  * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include "internal/quic_record_rx.h"
11 #include "internal/quic_rx_depack.h"
12 #include "internal/quic_record_tx.h"
13 #include "internal/quic_ackm.h"
14 #include "internal/quic_cc.h"
15 #include "internal/quic_ssl.h"
16 #include "testutil.h"
17 #include "quic_record_test_util.h"
18
19 static const QUIC_CONN_ID empty_conn_id = {0, {0}};
20
21 #define RX_TEST_OP_END                     0 /* end of script */
22 #define RX_TEST_OP_SET_SCID_LEN            1 /* change SCID length */
23 #define RX_TEST_OP_SET_INIT_LARGEST_PN     2 /* set initial largest PN */
24 #define RX_TEST_OP_SET_RX_DCID             3 /* register an RX DCID */
25 #define RX_TEST_OP_INJECT                  4 /* inject a datagram into demux */
26 #define RX_TEST_OP_PROVIDE_SECRET          5 /* provide RX secret */
27 #define RX_TEST_OP_PROVIDE_SECRET_INITIAL  6 /* provide RX secret for initial */
28 #define RX_TEST_OP_DISCARD_EL              7 /* discard an encryption level */
29 #define RX_TEST_OP_CHECK_PKT               8 /* read packet, compare to expected */
30 #define RX_TEST_OP_CHECK_NO_PKT            9 /* check no packet is available to read */
31 #define RX_TEST_OP_CHECK_KEY_EPOCH        10 /* check key epoch value matches */
32 #define RX_TEST_OP_KEY_UPDATE_TIMEOUT     11 /* complete key update process */
33 #define RX_TEST_OP_SET_INIT_KEY_PHASE     12 /* initial Key Phase bit value */
34 #define RX_TEST_OP_CHECK_PKT_EPOCH        13 /* check read key epoch matches */
35 #define RX_TEST_OP_ALLOW_1RTT             14 /* allow 1RTT packet processing */
36
37 struct rx_test_op {
38     unsigned char op;
39     unsigned char subop;
40     const unsigned char *buf;
41     size_t buf_len;
42     const QUIC_PKT_HDR *hdr;
43     uint32_t enc_level, suite_id;
44     QUIC_PN largest_pn;
45     const QUIC_CONN_ID *dcid;
46     int (*new_qrx)(QUIC_DEMUX **demux, OSSL_QRX **qrx);
47
48     /* For frame checking */
49 };
50
51 #define RX_OP_END \
52     { RX_TEST_OP_END }
53 #define RX_OP_SET_SCID_LEN(scid_len) \
54     { RX_TEST_OP_SET_SCID_LEN, 0, NULL, 0, NULL, (scid_len), 0, 0, NULL, NULL },
55 #define RX_OP_SET_INIT_LARGEST_PN(largest_pn) \
56     { RX_TEST_OP_SET_INIT_LARGEST_PN, 0, NULL, 0, NULL, 0, 0, (largest_pn), NULL, NULL },
57 #define RX_OP_SET_RX_DCID(dcid) \
58     { RX_TEST_OP_SET_RX_DCID, 0, NULL, 0, NULL, 0, 0, 0, &(dcid), NULL },
59 #define RX_OP_INJECT(dgram) \
60     { RX_TEST_OP_INJECT, 0, (dgram), sizeof(dgram), NULL, 0, 0, 0, NULL },
61 #define RX_OP_PROVIDE_SECRET(el, suite, key)                           \
62     {                                                               \
63         RX_TEST_OP_PROVIDE_SECRET, 0, (key), sizeof(key),             \
64         NULL, (el), (suite), 0, NULL, NULL                          \
65     },
66 #define RX_OP_PROVIDE_SECRET_INITIAL(dcid) \
67     { RX_TEST_OP_PROVIDE_SECRET_INITIAL, 0, NULL, 0, NULL, 0, 0, 0, &(dcid), NULL },
68 #define RX_OP_DISCARD_EL(el) \
69     { RX_TEST_OP_DISCARD_EL, 0, NULL, 0, NULL, (el), 0, 0, NULL, NULL },
70 #define RX_OP_CHECK_PKT(expect_hdr, expect_body)                       \
71     {                                                               \
72         RX_TEST_OP_CHECK_PKT, 0, (expect_body), sizeof(expect_body),  \
73         &(expect_hdr), 0, 0, 0, NULL, NULL                          \
74     },
75 #define RX_OP_CHECK_NO_PKT() \
76     { RX_TEST_OP_CHECK_NO_PKT, 0, NULL, 0, NULL, 0, 0, 0, NULL, NULL },
77 #define RX_OP_CHECK_KEY_EPOCH(expected) \
78     { RX_TEST_OP_CHECK_KEY_EPOCH, 0, NULL, 0, NULL, 0, 0, (expected), NULL },
79 #define RX_OP_KEY_UPDATE_TIMEOUT(normal) \
80     { RX_TEST_OP_KEY_UPDATE_TIMEOUT, 0, NULL, 0, NULL, (normal), 0, 0, NULL },
81 #define RX_OP_SET_INIT_KEY_PHASE(kp_bit) \
82     { RX_TEST_OP_SET_INIT_KEY_PHASE, 0, NULL, 0, NULL, (kp_bit), 0, 0, NULL },
83 #define RX_OP_CHECK_PKT_EPOCH(expected) \
84     { RX_TEST_OP_CHECK_PKT_EPOCH, 0, NULL, 0, NULL, 0, 0, (expected), NULL },
85 #define RX_OP_ALLOW_1RTT() \
86     { RX_TEST_OP_ALLOW_1RTT, 0, NULL, 0, NULL, 0, 0, 0, NULL },
87
88 #define RX_OP_INJECT_N(n)                                          \
89     RX_OP_INJECT(rx_script_##n##_in)
90 #define RX_OP_CHECK_PKT_N(n)                                       \
91     RX_OP_CHECK_PKT(rx_script_##n##_expect_hdr, rx_script_##n##_body)
92
93 #define RX_OP_INJECT_CHECK(n)                                  \
94     RX_OP_INJECT_N(n)                                              \
95     RX_OP_CHECK_PKT_N(n)
96
97 /* 1. RFC 9001 - A.3 Server Initial */
98 static const unsigned char rx_script_1_in[] = {
99     0xcf, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a,
100     0x42, 0x62, 0xb5, 0x00, 0x40, 0x75, 0xc0, 0xd9, 0x5a, 0x48, 0x2c, 0xd0,
101     0x99, 0x1c, 0xd2, 0x5b, 0x0a, 0xac, 0x40, 0x6a, 0x58, 0x16, 0xb6, 0x39,
102     0x41, 0x00, 0xf3, 0x7a, 0x1c, 0x69, 0x79, 0x75, 0x54, 0x78, 0x0b, 0xb3,
103     0x8c, 0xc5, 0xa9, 0x9f, 0x5e, 0xde, 0x4c, 0xf7, 0x3c, 0x3e, 0xc2, 0x49,
104     0x3a, 0x18, 0x39, 0xb3, 0xdb, 0xcb, 0xa3, 0xf6, 0xea, 0x46, 0xc5, 0xb7,
105     0x68, 0x4d, 0xf3, 0x54, 0x8e, 0x7d, 0xde, 0xb9, 0xc3, 0xbf, 0x9c, 0x73,
106     0xcc, 0x3f, 0x3b, 0xde, 0xd7, 0x4b, 0x56, 0x2b, 0xfb, 0x19, 0xfb, 0x84,
107     0x02, 0x2f, 0x8e, 0xf4, 0xcd, 0xd9, 0x37, 0x95, 0xd7, 0x7d, 0x06, 0xed,
108     0xbb, 0x7a, 0xaf, 0x2f, 0x58, 0x89, 0x18, 0x50, 0xab, 0xbd, 0xca, 0x3d,
109     0x20, 0x39, 0x8c, 0x27, 0x64, 0x56, 0xcb, 0xc4, 0x21, 0x58, 0x40, 0x7d,
110     0xd0, 0x74, 0xee
111 };
112
113 static const unsigned char rx_script_1_body[] = {
114     0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x40, 0x5a, 0x02, 0x00, 0x00,
115     0x56, 0x03, 0x03, 0xee, 0xfc, 0xe7, 0xf7, 0xb3, 0x7b, 0xa1, 0xd1, 0x63,
116     0x2e, 0x96, 0x67, 0x78, 0x25, 0xdd, 0xf7, 0x39, 0x88, 0xcf, 0xc7, 0x98,
117     0x25, 0xdf, 0x56, 0x6d, 0xc5, 0x43, 0x0b, 0x9a, 0x04, 0x5a, 0x12, 0x00,
118     0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00,
119     0x20, 0x9d, 0x3c, 0x94, 0x0d, 0x89, 0x69, 0x0b, 0x84, 0xd0, 0x8a, 0x60,
120     0x99, 0x3c, 0x14, 0x4e, 0xca, 0x68, 0x4d, 0x10, 0x81, 0x28, 0x7c, 0x83,
121     0x4d, 0x53, 0x11, 0xbc, 0xf3, 0x2b, 0xb9, 0xda, 0x1a, 0x00, 0x2b, 0x00,
122     0x02, 0x03, 0x04
123 };
124
125 static const QUIC_CONN_ID rx_script_1_dcid = {
126     8, { 0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08 }
127 };
128
129 static const QUIC_PKT_HDR rx_script_1_expect_hdr = {
130     QUIC_PKT_TYPE_INITIAL,
131     0, 0, 2, 0, 1, 0, 0, 1, { 0, {0} },
132     { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } },
133     { 0, 1, 0, 0 },
134     NULL, 0,
135     99, NULL
136 };
137
138 static const struct rx_test_op rx_script_1[] = {
139     RX_OP_SET_SCID_LEN(2)
140     RX_OP_SET_INIT_LARGEST_PN(0)
141     RX_OP_SET_RX_DCID(empty_conn_id)
142     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_1_dcid)
143     RX_OP_INJECT_CHECK(1)
144     RX_OP_CHECK_NO_PKT()
145     RX_OP_END
146 };
147
148 /* 2. RFC 9001 - A.5 ChaCha20-Poly1305 Short Header Packet */
149 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
150 static const unsigned char rx_script_2_in[] = {
151     0x4c, 0xfe, 0x41, 0x89, 0x65, 0x5e, 0x5c, 0xd5, 0x5c, 0x41, 0xf6, 0x90,
152     0x80, 0x57, 0x5d, 0x79, 0x99, 0xc2, 0x5a, 0x5b, 0xfb
153 };
154
155 static const unsigned char rx_script_2_secret[] = {
156     0x9a, 0xc3, 0x12, 0xa7, 0xf8, 0x77, 0x46, 0x8e, 0xbe, 0x69, 0x42, 0x27,
157     0x48, 0xad, 0x00, 0xa1, 0x54, 0x43, 0xf1, 0x82, 0x03, 0xa0, 0x7d, 0x60,
158     0x60, 0xf6, 0x88, 0xf3, 0x0f, 0x21, 0x63, 0x2b
159 };
160
161 static const unsigned char rx_script_2_body[] = {
162     0x01
163 };
164
165 static const QUIC_PKT_HDR rx_script_2_expect_hdr = {
166     QUIC_PKT_TYPE_1RTT,
167     0, 0, 3, 0, 1, 0, 0, 0, {0, {0}}, {0, {0}},
168     {0x00, 0xbf, 0xf4, 0x00},
169     NULL, 0,
170     1, NULL
171 };
172
173 static const struct rx_test_op rx_script_2[] = {
174     RX_OP_ALLOW_1RTT()
175     RX_OP_SET_INIT_LARGEST_PN(654360560)
176     RX_OP_SET_RX_DCID(empty_conn_id)
177     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_CHACHA20POLY1305,
178                          rx_script_2_secret)
179     RX_OP_INJECT_CHECK(2)
180     RX_OP_CHECK_NO_PKT()
181     RX_OP_END
182 };
183 #endif /* !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) */
184
185 /* 3. Real World - Version Negotiation Response */
186 static const unsigned char rx_script_3_in[] = {
187     0xc7,                               /* Long; Random Bits */
188     0x00, 0x00, 0x00, 0x00,             /* Version 0 (Version Negotiation) */
189     0x00,                               /* DCID */
190     0x0c, 0x35, 0x3c, 0x1b, 0x97, 0xca, /* SCID */
191     0xf8, 0x99, 0x11, 0x39, 0xad, 0x79,
192     0x1f,
193     0x00, 0x00, 0x00, 0x01,             /* Supported Version: 1 */
194     0xaa, 0x9a, 0x3a, 0x9a              /* Supported Version: Random (GREASE) */
195 };
196
197 static const QUIC_PKT_HDR rx_script_3_expect_hdr = {
198     QUIC_PKT_TYPE_VERSION_NEG,
199     0,          /* Spin Bit */
200     0,          /* Key Phase */
201     0,          /* PN Length */
202     0,          /* Partial */
203     1,          /* Fixed */
204     0,          /* Unused */
205     0,          /* Reserved */
206     0,          /* Version */
207     {0, {0}},                                   /* DCID */
208     {12, {0x35, 0x3c, 0x1b, 0x97, 0xca, 0xf8,   /* SCID */
209           0x99, 0x11, 0x39, 0xad, 0x79, 0x1f}},
210     {0},        /* PN */
211     NULL, 0,    /* Token/Token Len */
212     8, NULL
213 };
214
215 static const unsigned char rx_script_3_body[] = {
216     0x00, 0x00, 0x00, 0x01,
217     0xaa, 0x9a, 0x3a, 0x9a
218 };
219
220 static const struct rx_test_op rx_script_3[] = {
221     RX_OP_SET_RX_DCID(empty_conn_id)
222     /*
223      * This is a version negotiation packet, so doesn't have any frames.
224      * However, the depacketizer still handles this sort of packet, so
225      * we still pass the packet to it, to exercise what it does.
226      */
227     RX_OP_INJECT_CHECK(3)
228     RX_OP_CHECK_NO_PKT()
229     RX_OP_END
230 };
231
232 /* 4. Real World - Retry (S2C) */
233 static const unsigned char rx_script_4_in[] = {
234     0xf0,                           /* Long; Retry */
235     0x00, 0x00, 0x00, 0x01,         /* Version 1 */
236     0x00,                           /* DCID */
237     0x04, 0xad, 0x15, 0x3f, 0xae,   /* SCID */
238     /* Retry Token, including 16-byte Retry Integrity Tag */
239     0xf6, 0x8b, 0x6e, 0xa3, 0xdc, 0x40, 0x38, 0xc6, 0xa5, 0x99, 0x1c, 0xa9,
240     0x77, 0xe6, 0x1d, 0x4f, 0x09, 0x36, 0x12, 0x26, 0x00, 0x56, 0x0b, 0x29,
241     0x7d, 0x5e, 0xda, 0x39, 0xc6, 0x61, 0x57, 0x69, 0x15, 0xff, 0x93, 0x39,
242     0x95, 0xf0, 0x57, 0xf1, 0xe5, 0x36, 0x08, 0xad, 0xd2, 0x75, 0xa9, 0x68,
243     0x29, 0xed, 0xaa, 0x03, 0x0e, 0x5f, 0xac, 0xbd, 0x26, 0x07, 0x95, 0x4e,
244     0x48, 0x61, 0x26, 0xc5, 0xe2, 0x6c, 0x60, 0xbf, 0xa8, 0x6f, 0x51, 0xbb,
245     0x1d, 0xf7, 0x98, 0x95, 0x3b, 0x2c, 0x50, 0x79, 0xcc, 0xde, 0x27, 0x84,
246     0x44, 0x9b, 0xb2, 0x4a, 0x94, 0x4d, 0x4d, 0x3d, 0xbc, 0x00, 0x9d, 0x69,
247     0xad, 0x45, 0x89, 0x04, 0x48, 0xca, 0x04, 0xf6, 0x3a, 0x62, 0xc1, 0x38,
248     0x9d, 0x82, 0xb3, 0x45, 0x62, 0x4c,
249 };
250
251 static const QUIC_PKT_HDR rx_script_4_expect_hdr = {
252     QUIC_PKT_TYPE_RETRY,
253     0,          /* Spin Bit */
254     0,          /* Key Phase */
255     0,          /* PN Length */
256     0,          /* Partial */
257     1,          /* Fixed */
258     0,          /* Unused */
259     0,          /* Reserved */
260     1,          /* Version */
261     {0, {0}},                           /* DCID */
262     {4, {0xad, 0x15, 0x3f, 0xae}},      /* SCID */
263     {0},        /* PN */
264     NULL, 0,    /* Token/Token Len */
265     114, NULL
266 };
267
268 static const unsigned char rx_script_4_body[] = {
269     0xf6, 0x8b, 0x6e, 0xa3, 0xdc, 0x40, 0x38, 0xc6, 0xa5, 0x99, 0x1c, 0xa9,
270     0x77, 0xe6, 0x1d, 0x4f, 0x09, 0x36, 0x12, 0x26, 0x00, 0x56, 0x0b, 0x29,
271     0x7d, 0x5e, 0xda, 0x39, 0xc6, 0x61, 0x57, 0x69, 0x15, 0xff, 0x93, 0x39,
272     0x95, 0xf0, 0x57, 0xf1, 0xe5, 0x36, 0x08, 0xad, 0xd2, 0x75, 0xa9, 0x68,
273     0x29, 0xed, 0xaa, 0x03, 0x0e, 0x5f, 0xac, 0xbd, 0x26, 0x07, 0x95, 0x4e,
274     0x48, 0x61, 0x26, 0xc5, 0xe2, 0x6c, 0x60, 0xbf, 0xa8, 0x6f, 0x51, 0xbb,
275     0x1d, 0xf7, 0x98, 0x95, 0x3b, 0x2c, 0x50, 0x79, 0xcc, 0xde, 0x27, 0x84,
276     0x44, 0x9b, 0xb2, 0x4a, 0x94, 0x4d, 0x4d, 0x3d, 0xbc, 0x00, 0x9d, 0x69,
277     0xad, 0x45, 0x89, 0x04, 0x48, 0xca, 0x04, 0xf6, 0x3a, 0x62, 0xc1, 0x38,
278     0x9d, 0x82, 0xb3, 0x45, 0x62, 0x4c
279 };
280
281 static const struct rx_test_op rx_script_4[] = {
282     RX_OP_SET_RX_DCID(empty_conn_id)
283     RX_OP_INJECT_CHECK(4)
284     RX_OP_CHECK_NO_PKT()
285     RX_OP_END
286 };
287
288 /*
289  * 5. Real World - S2C Multiple Packets
290  *      - Initial, Handshake, 1-RTT (AES-128-GCM/SHA256)
291  */
292 static const QUIC_CONN_ID rx_script_5_c2s_init_dcid = {
293     4, {0xad, 0x15, 0x3f, 0xae}
294 };
295
296 static const unsigned char rx_script_5_handshake_secret[32] = {
297     0x5e, 0xc6, 0x4a, 0x4d, 0x0d, 0x40, 0x43, 0x3b, 0xd5, 0xbd, 0xe0, 0x19,
298     0x71, 0x47, 0x56, 0xf3, 0x59, 0x3a, 0xa6, 0xc9, 0x3e, 0xdc, 0x81, 0x1e,
299     0xc7, 0x72, 0x9d, 0x83, 0xd8, 0x8f, 0x88, 0x77
300 };
301
302 static const unsigned char rx_script_5_1rtt_secret[32] = {
303     0x53, 0xf2, 0x1b, 0x94, 0xa7, 0x65, 0xf7, 0x76, 0xfb, 0x06, 0x27, 0xaa,
304     0xd2, 0x3f, 0xe0, 0x9a, 0xbb, 0xcf, 0x99, 0x6f, 0x13, 0x2c, 0x6a, 0x37,
305     0x95, 0xf3, 0xda, 0x21, 0xcb, 0xcb, 0xa5, 0x26,
306 };
307
308 static const unsigned char rx_script_5_in[] = {
309     /* First Packet: Initial */
310     0xc4,                           /* Long, Initial, PN Length=2 bytes */
311     0x00, 0x00, 0x00, 0x01,         /* Version */
312     0x00,                           /* DCID */
313     0x04, 0x83, 0xd0, 0x0a, 0x27,   /* SCID */
314     0x00,                           /* Token Length */
315     0x41, 0xd2,                     /* Length (466) */
316     0xe3, 0xab,                     /* PN (0) */
317     0x22, 0x35, 0x34, 0x12, 0xcf, 0x20, 0x2b, 0x16, 0xaf, 0x08, 0xd4, 0xe0,
318     0x94, 0x8b, 0x1e, 0x62, 0xdf, 0x31, 0x61, 0xcc, 0xf9, 0xfa, 0x66, 0x4f,
319     0x18, 0x61, 0x07, 0xcb, 0x13, 0xd3, 0xf9, 0xbf, 0xe2, 0x8e, 0x25, 0x8d,
320     0xd1, 0xdf, 0x58, 0x9c, 0x05, 0x20, 0xf9, 0xf2, 0x01, 0x20, 0xe9, 0x39,
321     0xc3, 0x80, 0x77, 0xec, 0xa4, 0x57, 0xcf, 0x57, 0x8c, 0xdd, 0x68, 0x82,
322     0x91, 0xfe, 0x71, 0xa0, 0xfa, 0x56, 0x4c, 0xf2, 0xe7, 0x2b, 0xd0, 0xc0,
323     0xda, 0x81, 0xe2, 0x39, 0xb5, 0xf0, 0x0f, 0xd9, 0x07, 0xd5, 0x67, 0x09,
324     0x02, 0xf0, 0xff, 0x74, 0xb0, 0xa0, 0xd9, 0x3a, 0x7e, 0xb6, 0x57, 0x82,
325     0x47, 0x18, 0x66, 0xed, 0xe2, 0x18, 0x4d, 0xc2, 0x5c, 0x9f, 0x05, 0x09,
326     0x18, 0x24, 0x0e, 0x3f, 0x3d, 0xf9, 0x15, 0x8b, 0x08, 0xfd, 0x25, 0xe9,
327     0xc9, 0xb7, 0x8c, 0x18, 0x7b, 0xf3, 0x37, 0x58, 0xf0, 0xf0, 0xac, 0x33,
328     0x55, 0x3f, 0x39, 0xbc, 0x62, 0x03, 0x8a, 0xc0, 0xd6, 0xcc, 0x49, 0x47,
329     0xeb, 0x85, 0xb6, 0x72, 0xd7, 0xf8, 0xdc, 0x01, 0x32, 0xec, 0x1b, 0x4e,
330     0x38, 0x6e, 0x2c, 0xc5, 0x80, 0xf2, 0x43, 0x4a, 0xf5, 0xe5, 0xa2, 0xf8,
331     0x76, 0xa7, 0xa8, 0x57, 0x32, 0x67, 0x72, 0xeb, 0x82, 0xac, 0x3e, 0xc0,
332     0x15, 0x67, 0xac, 0x32, 0x19, 0x18, 0x0a, 0xef, 0x20, 0xa1, 0xe8, 0xaf,
333     0xac, 0x33, 0x87, 0x4c, 0x55, 0x05, 0x9b, 0x78, 0xf0, 0x3a, 0xce, 0x02,
334     0x28, 0x06, 0x84, 0x61, 0x97, 0xac, 0x87, 0x8f, 0x25, 0xe7, 0x1b, 0xa3,
335     0x02, 0x08, 0x4c, 0x2e, 0xef, 0xbd, 0x4f, 0x82, 0xe7, 0x37, 0x6c, 0x27,
336     0x6f, 0x85, 0xb4, 0xbc, 0x79, 0x38, 0x45, 0x80, 0x8a, 0xda, 0x2f, 0x11,
337     0x11, 0xac, 0x9c, 0xf3, 0x93, 0xc1, 0x49, 0x1b, 0x94, 0x12, 0x77, 0x07,
338     0xdc, 0xbf, 0xc2, 0xfd, 0x8b, 0xf6, 0xf1, 0x66, 0x1c, 0x7f, 0x07, 0xbf,
339     0x1f, 0xae, 0x27, 0x6c, 0x66, 0xe9, 0xa3, 0x64, 0x7a, 0x96, 0x78, 0x45,
340     0xfe, 0x4b, 0x8c, 0x6f, 0x7f, 0x03, 0x47, 0x3c, 0xd7, 0xf7, 0x63, 0x92,
341     0x58, 0x5b, 0x63, 0x83, 0x03, 0x05, 0xc3, 0x5d, 0x36, 0x62, 0x63, 0x5e,
342     0xcf, 0xfe, 0x0a, 0x29, 0xfa, 0xeb, 0xc8, 0xaf, 0xce, 0x31, 0x07, 0x6a,
343     0x09, 0x41, 0xc0, 0x2d, 0x98, 0x70, 0x05, 0x3b, 0x41, 0xfc, 0x7d, 0x61,
344     0xe0, 0x41, 0x7d, 0x13, 0x41, 0x51, 0x52, 0xb4, 0x78, 0xd5, 0x46, 0x51,
345     0x3b, 0xf1, 0xcd, 0xcc, 0x2e, 0x49, 0x30, 0x8b, 0x2a, 0xd2, 0xe6, 0x69,
346     0xb5, 0x6b, 0x7a, 0xf4, 0xbb, 0xd1, 0xf8, 0x4a, 0xe8, 0x53, 0x10, 0x46,
347     0x85, 0x8d, 0x66, 0x8e, 0x2b, 0xe8, 0x5d, 0xab, 0x7e, 0xfe, 0x5a, 0x79,
348     0xcf, 0xc5, 0x0c, 0x30, 0x9e, 0x98, 0x02, 0xb3, 0xa6, 0xd5, 0xfa, 0x25,
349     0xa8, 0xc8, 0xc1, 0xd9, 0x51, 0x60, 0x57, 0x5d, 0xfe, 0x75, 0x97, 0x05,
350     0xda, 0xbb, 0xc6, 0x6a, 0xbe, 0x5c, 0xa5, 0x65, 0x0a, 0x12, 0x33, 0x1c,
351     0xdf, 0xee, 0x08, 0xa9, 0x13, 0x13, 0x28, 0xce, 0x61, 0x59, 0xd1, 0x4e,
352     0xc7, 0x74, 0xfd, 0x64, 0xde, 0x08, 0xce, 0xda, 0x3f, 0xec, 0xad, 0xc9,
353     0xe1, 0xf9, 0x1f, 0x74, 0xf6, 0x86, 0x37, 0x6a, 0xa0, 0xc8, 0x0b, 0x1b,
354     0x94, 0x98, 0x86, 0x81, 0x3b, 0xfc, 0x47, 0x6c, 0xc9, 0x3e, 0x3c, 0x30,
355     0xc5, 0x9e, 0xb2, 0x32, 0x47, 0xf5, 0x0c, 0x6f,
356
357     /* Second Packet: Handshake */
358     0xe6,                           /* Long, Handshake, PN Length=2 bytes */
359     0x00, 0x00, 0x00, 0x01,         /* Version */
360     0x00,                           /* DCID */
361     0x04, 0x83, 0xd0, 0x0a, 0x27,   /* SCID */
362     0x42, 0x9c,                     /* Length (668) */
363     0x9c, 0x55,                     /* PN (0) */
364     0x55, 0xd4, 0x50, 0x02, 0x1a, 0x57, 0x84, 0x22, 0xcd, 0x01, 0xe5, 0x42,
365     0x1b, 0x1e, 0x06, 0xf1, 0x86, 0xe2, 0x90, 0xf8, 0x9c, 0x3d, 0xa2, 0x7c,
366     0xde, 0x2b, 0xc9, 0x2e, 0xcd, 0xa8, 0x4f, 0x5a, 0x20, 0xca, 0x96, 0xb6,
367     0x11, 0x4b, 0xc8, 0x71, 0x32, 0xb5, 0xc7, 0x1a, 0x69, 0x7f, 0x1e, 0x37,
368     0x49, 0xfb, 0x08, 0xce, 0x83, 0x5f, 0x02, 0x6d, 0x8a, 0x8f, 0xe7, 0x5d,
369     0xe1, 0x34, 0x31, 0x22, 0x53, 0x53, 0x32, 0xcb, 0x04, 0x21, 0xce, 0xbc,
370     0xa5, 0x1b, 0xdd, 0x4d, 0xd5, 0x1c, 0xd6, 0x5d, 0x88, 0x29, 0x5a, 0x19,
371     0x71, 0x6a, 0xc2, 0xfa, 0xb7, 0xb4, 0x7d, 0xd1, 0x72, 0x93, 0x8f, 0x7c,
372     0xb5, 0x36, 0x1b, 0xea, 0xf3, 0xf1, 0xd7, 0x6e, 0xd3, 0x91, 0x96, 0x62,
373     0x4d, 0xc6, 0xec, 0xb7, 0xb0, 0xb7, 0x9b, 0x95, 0x8b, 0x14, 0x8d, 0x1a,
374     0x0d, 0xb6, 0x3e, 0xec, 0xfe, 0x3b, 0x51, 0xea, 0x1a, 0x05, 0x14, 0x12,
375     0x93, 0x0e, 0x7e, 0xe6, 0xa2, 0xc5, 0x22, 0x87, 0x65, 0xf8, 0x5d, 0x3c,
376     0x55, 0x18, 0xcb, 0xe9, 0xef, 0x23, 0x43, 0xfe, 0xe8, 0x0d, 0xb2, 0x0f,
377     0xc5, 0xf4, 0xb3, 0xde, 0x0c, 0xea, 0xa4, 0x48, 0x8e, 0xbf, 0x1f, 0xc7,
378     0x99, 0x53, 0x8c, 0xc1, 0x3d, 0xba, 0xf4, 0x8e, 0x8e, 0x02, 0x52, 0xf6,
379     0x1f, 0xcf, 0x1d, 0xaa, 0xb3, 0xcb, 0x08, 0xc2, 0xe1, 0x70, 0x68, 0x74,
380     0x78, 0xa9, 0x30, 0x67, 0xba, 0x2b, 0xea, 0x35, 0x63, 0x47, 0xff, 0x29,
381     0x73, 0x29, 0xc6, 0xe8, 0x08, 0xa9, 0x1e, 0x8f, 0x28, 0x41, 0xa4, 0x24,
382     0x54, 0x26, 0x5f, 0x42, 0x77, 0xb1, 0x2b, 0x3d, 0x65, 0x67, 0x60, 0xa7,
383     0x23, 0x0d, 0xa7, 0xf4, 0xd6, 0xe9, 0x4e, 0x58, 0x43, 0x9f, 0x3c, 0x9e,
384     0x77, 0x61, 0xe5, 0x04, 0x4f, 0x73, 0xc9, 0x10, 0x79, 0xd0, 0xda, 0x3b,
385     0xc6, 0x19, 0x93, 0x9f, 0x48, 0x3b, 0x76, 0x38, 0xa1, 0x72, 0x49, 0x7d,
386     0x86, 0x7f, 0xe8, 0x1b, 0xa9, 0x5b, 0xc0, 0x47, 0xa0, 0x9c, 0x3f, 0x65,
387     0x60, 0x76, 0x59, 0xaf, 0x20, 0x2d, 0x40, 0xa6, 0x80, 0x49, 0x5a, 0x8f,
388     0x09, 0xf8, 0xf6, 0x97, 0xc1, 0xbd, 0xe1, 0x9f, 0x9b, 0xa2, 0x4c, 0x7b,
389     0x88, 0xac, 0xbe, 0x4b, 0x11, 0x28, 0xd7, 0x67, 0xe6, 0xad, 0xaf, 0xd0,
390     0xad, 0x01, 0x29, 0xa4, 0x4a, 0xc4, 0xb8, 0x2e, 0x42, 0x79, 0x24, 0x9e,
391     0xd5, 0x34, 0xae, 0x45, 0xf1, 0x0b, 0x38, 0x4a, 0x76, 0xfb, 0x50, 0xa2,
392     0x99, 0xc9, 0x5b, 0x6d, 0xc0, 0xb7, 0x55, 0xd8, 0x8d, 0x49, 0xdd, 0x1b,
393     0xb8, 0xec, 0x10, 0x57, 0x9e, 0x33, 0xb4, 0x10, 0x16, 0x19, 0xac, 0x69,
394     0xa2, 0x19, 0x1b, 0xd0, 0x77, 0x45, 0xeb, 0x49, 0x5c, 0xc5, 0x7c, 0xbe,
395     0x4b, 0x4a, 0x22, 0x5c, 0x3d, 0x0e, 0x6e, 0xe5, 0x4b, 0x36, 0x06, 0x63,
396     0x03, 0x97, 0xab, 0xed, 0xdc, 0xea, 0x64, 0xc2, 0x70, 0xb6, 0x7e, 0x35,
397     0xfb, 0x13, 0x66, 0x37, 0xa3, 0x3f, 0x28, 0x16, 0x6c, 0xe7, 0xd4, 0xe6,
398     0xca, 0x26, 0x0f, 0x19, 0xdd, 0x02, 0xae, 0xc1, 0xcf, 0x18, 0x7d, 0x56,
399     0xe6, 0x52, 0xf3, 0x37, 0xb5, 0x86, 0x9d, 0x1d, 0x55, 0xb3, 0x95, 0x19,
400     0x19, 0xa5, 0x44, 0x95, 0x81, 0xed, 0x02, 0x18, 0xf1, 0x85, 0x57, 0x78,
401     0x28, 0xc4, 0x9a, 0xba, 0xe8, 0x5e, 0x22, 0x8d, 0xc1, 0x7b, 0x2a, 0x8a,
402     0xc8, 0xb9, 0xdd, 0x82, 0xb2, 0x7b, 0x9f, 0x3d, 0xf5, 0x27, 0x2a, 0x48,
403     0x53, 0xc7, 0xa0, 0x70, 0x0e, 0x9d, 0x61, 0xaa, 0xe2, 0xad, 0x28, 0xf2,
404     0xb4, 0xfc, 0x56, 0x6b, 0x89, 0xe7, 0xf9, 0x51, 0xc9, 0xe9, 0xd3, 0x8a,
405     0x8c, 0x7e, 0x86, 0xdd, 0xba, 0x2f, 0x39, 0xbf, 0x26, 0x62, 0x23, 0xd6,
406     0x98, 0x6d, 0x3e, 0x72, 0xd7, 0x1b, 0xe1, 0x62, 0x94, 0x35, 0xe2, 0x18,
407     0x19, 0x46, 0xb8, 0x2c, 0xb5, 0x8f, 0x8f, 0xb0, 0x5b, 0x76, 0x7b, 0x7e,
408     0xb8, 0xc6, 0xb7, 0xe9, 0x4e, 0x9d, 0x30, 0x68, 0x03, 0x1e, 0x19, 0x73,
409     0xc5, 0x3e, 0x24, 0xe2, 0x95, 0x60, 0x1b, 0x27, 0x93, 0x7c, 0x17, 0xc2,
410     0xc6, 0xa3, 0xbd, 0xbd, 0x70, 0xc6, 0x60, 0x59, 0xc8, 0x5c, 0xd7, 0x9a,
411     0xc4, 0x29, 0xac, 0x0f, 0xaa, 0x0d, 0xa9, 0x92, 0xa3, 0x95, 0xd7, 0x0f,
412     0x6f, 0x74, 0x99, 0x9b, 0xc1, 0xd3, 0x68, 0x6d, 0xac, 0x82, 0x2d, 0x32,
413     0x41, 0x9e, 0x0c, 0xf7, 0x31, 0x59, 0x4c, 0x93, 0x1c, 0x3b, 0x71, 0x69,
414     0xcf, 0xc5, 0xca, 0x2b, 0xdf, 0xe7, 0xaa, 0xfd, 0x1d, 0x71, 0x01, 0x7e,
415     0x1c, 0x70, 0x62, 0x20, 0x61, 0xf8, 0x35, 0xc1, 0x71, 0xe7, 0x02, 0x0d,
416     0x88, 0x44, 0xd9, 0x00, 0xc5, 0xcc, 0x63, 0xe4, 0xf0, 0x86, 0xa7, 0xd0,
417     0xfe, 0xcc, 0xb7, 0x1d, 0xfc, 0x21, 0x61, 0x54, 0x15, 0xea, 0x81, 0x5e,
418     0xc0, 0x31, 0xfa, 0xbf, 0x7d, 0xb9, 0x3b, 0xa2, 0x1e, 0x42, 0x73, 0x05,
419     0x3c, 0xdb, 0x21, 0x59, 0x4f, 0x63,
420
421     /* Third Packet: 1-RTT */
422     0x5f,               /* Short, 1-RTT, Spin=0, KP=0, PN Length=2 bytes */
423     0x68, 0x47,         /* PN (0) */
424     0xa3, 0x3c, 0xa5, 0x27, 0x5e, 0xf9, 0x8d, 0xec, 0xea, 0x6c, 0x09, 0x18,
425     0x40, 0x80, 0xee, 0x9f, 0x6f, 0x73, 0x5c, 0x49, 0xe3, 0xec, 0xb7, 0x58,
426     0x05, 0x66, 0x8f, 0xa3, 0x52, 0x37, 0xa1, 0x22, 0x1f, 0xc6, 0x92, 0xd6,
427     0x59, 0x04, 0x99, 0xcb, 0x44, 0xef, 0x66, 0x05, 0x2d, 0xd0, 0x85, 0x24,
428     0xbb, 0xe3, 0xa1, 0xd1, 0xbe, 0xf7, 0x54, 0xad, 0x65, 0xf4, 0xd4, 0x59,
429     0x54, 0x87, 0x4e, 0x22, 0x4f, 0x06, 0x07, 0xa7, 0x8a, 0x14, 0x89, 0xd1,
430     0x3f, 0xd3, 0xe4, 0x6f, 0x71, 0x8f, 0x9a, 0xd2, 0x3b, 0x61, 0x0a, 0xba,
431     0x9a, 0x31, 0x56, 0xc7,
432 };
433
434 static const QUIC_PKT_HDR rx_script_5a_expect_hdr = {
435     QUIC_PKT_TYPE_INITIAL,
436     0,          /* Spin Bit */
437     0,          /* Key Phase */
438     2,          /* PN Length */
439     0,          /* Partial */
440     1,          /* Fixed */
441     0,          /* Unused */
442     0,          /* Reserved */
443     1,          /* Version */
444     {0, {0}},                           /* DCID */
445     {4, {0x83, 0xd0, 0x0a, 0x27}},      /* SCID */
446     {0},        /* PN */
447     NULL, 0,    /* Token/Token Len */
448     448, NULL
449 };
450
451 static const unsigned char rx_script_5a_body[] = {
452     0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
453     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
454     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
455     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
456     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
457     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
458     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
459     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
460     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
461     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
463     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
464     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
465     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
466     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
467     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
468     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
469     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
470     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
471     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
472     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
473     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
474     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
475     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
476     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
477     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
478     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
479     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
480     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
481     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x40, 0x5a, 0x02, 0x00,
482     0x00, 0x56, 0x03, 0x03, 0xe2, 0xd2, 0x0a, 0x3b, 0xa2, 0xc4, 0xd2, 0x29,
483     0xc8, 0xe8, 0xba, 0x23, 0x31, 0x88, 0x2c, 0x71, 0xeb, 0xba, 0x42, 0x5f,
484     0x94, 0xe9, 0x0a, 0x90, 0x35, 0x31, 0x1e, 0xca, 0xed, 0xf8, 0x8a, 0x8d,
485     0x00, 0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04,
486     0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x96, 0x0b, 0x4b, 0x30,
487     0x66, 0x3a, 0x75, 0x01, 0x4a, 0xdc, 0x2a, 0x75, 0x1f, 0xce, 0x7a, 0x30,
488     0x9d, 0x00, 0xca, 0x20, 0xb4, 0xe0, 0x6b, 0x81, 0x23, 0x18, 0x0b, 0x20,
489     0x1f, 0x54, 0x86, 0x1d,
490 };
491
492 static const QUIC_PKT_HDR rx_script_5b_expect_hdr = {
493     QUIC_PKT_TYPE_HANDSHAKE,
494     0,          /* Spin Bit */
495     0,          /* Key Phase */
496     2,          /* PN Length */
497     0,          /* Partial */
498     1,          /* Fixed */
499     0,          /* Unused */
500     0,          /* Reserved */
501     1,          /* Version */
502     {0, {0}},                           /* DCID */
503     {4, {0x83, 0xd0, 0x0a, 0x27}},      /* SCID */
504     {0},        /* PN */
505     NULL, 0,    /* Token/Token Len */
506     650, NULL
507 };
508
509 static const unsigned char rx_script_5b_body[] = {
510     0x06, 0x00, 0x42, 0x86, 0x08, 0x00, 0x00, 0x7d, 0x00, 0x7b, 0x00, 0x10,
511     0x00, 0x08, 0x00, 0x06, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x00, 0x39,
512     0x00, 0x6b, 0x4b, 0x20, 0x0b, 0x1b, 0xe1, 0x1f, 0xd0, 0x78, 0xc0, 0x69,
513     0x72, 0x9c, 0xe2, 0xf7, 0x05, 0x04, 0x80, 0x08, 0x00, 0x00, 0x06, 0x04,
514     0x80, 0x08, 0x00, 0x00, 0x07, 0x04, 0x80, 0x08, 0x00, 0x00, 0x04, 0x04,
515     0x80, 0x0c, 0x00, 0x00, 0x08, 0x02, 0x40, 0x64, 0x09, 0x02, 0x40, 0x64,
516     0x01, 0x04, 0x80, 0x00, 0x75, 0x30, 0x03, 0x02, 0x45, 0xac, 0x0b, 0x01,
517     0x1a, 0x0c, 0x00, 0x02, 0x10, 0x41, 0x94, 0x41, 0x8d, 0x0d, 0xfb, 0x60,
518     0x7b, 0xdc, 0xcc, 0xa2, 0x9c, 0x3e, 0xa5, 0xdf, 0x8d, 0x00, 0x08, 0x2d,
519     0x71, 0x8a, 0x38, 0xdf, 0xdd, 0xe0, 0x03, 0x0e, 0x01, 0x04, 0x0f, 0x04,
520     0x83, 0xd0, 0x0a, 0x27, 0x10, 0x04, 0xad, 0x15, 0x3f, 0xae, 0x20, 0x01,
521     0x00, 0x0b, 0x00, 0x01, 0x8f, 0x00, 0x00, 0x01, 0x8b, 0x00, 0x01, 0x86,
522     0x30, 0x82, 0x01, 0x82, 0x30, 0x82, 0x01, 0x29, 0xa0, 0x03, 0x02, 0x01,
523     0x02, 0x02, 0x14, 0x0a, 0x73, 0x0f, 0x86, 0x18, 0xf2, 0xc3, 0x30, 0x01,
524     0xd2, 0xc0, 0xc1, 0x62, 0x52, 0x13, 0xf1, 0x9c, 0x13, 0x39, 0xb5, 0x30,
525     0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30,
526     0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c,
527     0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
528     0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x38, 0x30, 0x32, 0x31, 0x32,
529     0x30, 0x30, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x39, 0x30,
530     0x31, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x30, 0x17, 0x31, 0x15,
531     0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x6d, 0x61, 0x70,
532     0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x30, 0x59, 0x30,
533     0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08,
534     0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04,
535     0x67, 0xf4, 0xd3, 0x8f, 0x15, 0x6d, 0xee, 0x85, 0xcc, 0x2a, 0x77, 0xfc,
536     0x0b, 0x8f, 0x9f, 0xcf, 0xa9, 0x95, 0x5d, 0x5b, 0xcd, 0xb7, 0x8b, 0xba,
537     0x31, 0x0a, 0x73, 0x62, 0xc5, 0xd0, 0x0e, 0x07, 0x90, 0xae, 0x38, 0x43,
538     0x79, 0xce, 0x5e, 0x33, 0xad, 0x31, 0xbf, 0x9f, 0x2a, 0x56, 0x83, 0xa5,
539     0x24, 0x16, 0xab, 0x0c, 0xf1, 0x64, 0xbe, 0xe4, 0x93, 0xb5, 0x89, 0xd6,
540     0x05, 0xe4, 0xf7, 0x7b, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06, 0x03,
541     0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x02, 0x64, 0x0f, 0x55, 0x69,
542     0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a, 0xd0, 0x48,
543     0x96, 0x9f, 0x60, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,
544     0x30, 0x16, 0x80, 0x14, 0x02, 0x64, 0x0f, 0x55, 0x69, 0x14, 0x91, 0x19,
545     0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a, 0xd0, 0x48, 0x96, 0x9f, 0x60,
546     0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05,
547     0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48,
548     0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20,
549     0x0a, 0x82, 0x92, 0x6e, 0xd3, 0xc6, 0x66, 0xd9, 0xd3, 0x75, 0xff, 0x71,
550     0x3b, 0x61, 0x46, 0x21, 0x00, 0xe6, 0x21, 0x5d, 0x9c, 0x86, 0xe9, 0x65,
551     0x40, 0x4f, 0xeb, 0x70, 0x4f, 0x2c, 0xad, 0x00, 0x02, 0x20, 0x08, 0xc2,
552     0x07, 0x5d, 0x16, 0xfc, 0x54, 0x34, 0x2b, 0xb4, 0x18, 0x67, 0x44, 0x81,
553     0xc9, 0xa9, 0x67, 0x2e, 0xce, 0xa1, 0x02, 0x9f, 0x3b, 0xe5, 0x61, 0x16,
554     0x0b, 0x50, 0xf6, 0xa1, 0x50, 0x94, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x4a,
555     0x04, 0x03, 0x00, 0x46, 0x30, 0x44, 0x02, 0x20, 0x7d, 0x57, 0x17, 0x14,
556     0x46, 0x09, 0x95, 0x70, 0x09, 0x45, 0xe8, 0x9e, 0x5c, 0x87, 0x55, 0xd9,
557     0x08, 0xc6, 0x5e, 0x47, 0x73, 0x5e, 0xb1, 0xc9, 0xef, 0xcb, 0xe5, 0x7f,
558     0xcc, 0xb0, 0x28, 0xbc, 0x02, 0x20, 0x5d, 0xe4, 0x2b, 0x83, 0xd9, 0x78,
559     0x75, 0x45, 0xf3, 0x22, 0x2b, 0x38, 0xeb, 0x68, 0xe5, 0x71, 0x5d, 0xcb,
560     0xc3, 0x68, 0xb3, 0x0e, 0x7d, 0x5e, 0x1d, 0xc2, 0x1b, 0x8a, 0x62, 0x80,
561     0x48, 0x3e, 0x14, 0x00, 0x00, 0x20, 0x37, 0xcd, 0x55, 0xca, 0x3f, 0x4b,
562     0xf0, 0x95, 0xf8, 0xe4, 0xfe, 0x59, 0xab, 0xbc, 0xc1, 0x8f, 0x0c, 0x3f,
563     0x41, 0x59, 0xf6, 0x96, 0xdb, 0x75, 0xae, 0xe7, 0x86, 0x1a, 0x92, 0xa7,
564     0x53, 0x0a,
565 };
566
567 static const QUIC_PKT_HDR rx_script_5c_expect_hdr = {
568     QUIC_PKT_TYPE_1RTT,
569     0,          /* Spin Bit */
570     0,          /* Key Phase */
571     2,          /* PN Length */
572     0,          /* Partial */
573     1,          /* Fixed */
574     0,          /* Unused */
575     0,          /* Reserved */
576     0,          /* Version */
577     {0, {0}},                           /* DCID */
578     {0, {0}},                           /* SCID */
579     {0},        /* PN */
580     NULL, 0,    /* Token/Token Len */
581     72, NULL
582 };
583
584 static const unsigned char rx_script_5c_body[] = {
585     0x18, 0x03, 0x00, 0x04, 0x92, 0xec, 0xaa, 0xd6, 0x47, 0xd8, 0x8b, 0x56,
586     0x3b, 0x5f, 0x67, 0xe6, 0xb9, 0xb9, 0xca, 0x72, 0xca, 0xf2, 0x49, 0x7d,
587     0x18, 0x02, 0x00, 0x04, 0xa9, 0x6e, 0x9b, 0x84, 0x26, 0x43, 0x00, 0xc7,
588     0x55, 0x71, 0x67, 0x2e, 0x52, 0xdd, 0x47, 0xfd, 0x06, 0x51, 0x33, 0x08,
589     0x18, 0x01, 0x00, 0x04, 0x36, 0xd5, 0x1f, 0x06, 0x4e, 0xbf, 0xb4, 0xc9,
590     0xef, 0x97, 0x1e, 0x9a, 0x3c, 0xab, 0x1e, 0xfc, 0xb7, 0x90, 0xc3, 0x1a,
591 };
592
593 static const struct rx_test_op rx_script_5[] = {
594     RX_OP_ALLOW_1RTT()
595     RX_OP_SET_RX_DCID(empty_conn_id)
596     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_5_c2s_init_dcid)
597     RX_OP_INJECT_N(5)
598     RX_OP_CHECK_PKT_N(5a)
599     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
600     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
601                       QRL_SUITE_AES128GCM, rx_script_5_handshake_secret)
602     RX_OP_CHECK_PKT_N(5b)
603     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
604     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
605                       QRL_SUITE_AES128GCM, rx_script_5_1rtt_secret)
606     RX_OP_CHECK_PKT_N(5c)
607     RX_OP_CHECK_NO_PKT()
608
609     /* Discard Initial EL and try injecting the packet again */
610     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
611     RX_OP_INJECT_N(5)
612     /* Initial packet is not output because we have discarded Initial keys */
613     RX_OP_CHECK_PKT_N(5b)
614     RX_OP_CHECK_PKT_N(5c)
615     RX_OP_CHECK_NO_PKT()
616     /* Try again with discarded keys */
617     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
618     RX_OP_INJECT_N(5)
619     RX_OP_CHECK_PKT_N(5c)
620     RX_OP_CHECK_NO_PKT()
621     /* Try again */
622     RX_OP_INJECT_N(5)
623     RX_OP_CHECK_PKT_N(5c)
624     RX_OP_CHECK_NO_PKT()
625     /* Try again with discarded 1-RTT keys */
626     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
627     RX_OP_INJECT_N(5)
628     RX_OP_CHECK_NO_PKT()
629
630     /* Recreate QRL, test reading packets received before key */
631     RX_OP_SET_SCID_LEN(0)
632     RX_OP_SET_RX_DCID(empty_conn_id)
633     RX_OP_INJECT_N(5)
634     RX_OP_CHECK_NO_PKT()
635     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_5_c2s_init_dcid)
636     RX_OP_CHECK_PKT_N(5a)
637     RX_OP_CHECK_NO_PKT()
638     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
639                       QRL_SUITE_AES128GCM, rx_script_5_handshake_secret)
640     RX_OP_CHECK_PKT_N(5b)
641     RX_OP_CHECK_NO_PKT()
642     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
643                       QRL_SUITE_AES128GCM, rx_script_5_1rtt_secret)
644     RX_OP_CHECK_PKT_N(5c)
645     RX_OP_CHECK_NO_PKT()
646
647     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
648     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
649     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
650     RX_OP_INJECT_N(5)
651     RX_OP_CHECK_NO_PKT()
652
653     RX_OP_END
654 };
655
656 /*
657  * 6. Real World - S2C Multiple Packets
658  *      - Initial, Handshake, 1-RTT (AES-256-GCM/SHA384)
659  */
660 static const QUIC_CONN_ID rx_script_6_c2s_init_dcid = {
661     4, {0xac, 0x88, 0x95, 0xbd}
662 };
663
664 static const unsigned char rx_script_6_handshake_secret[48] = {
665     0xd1, 0x41, 0xb0, 0xf6, 0x0d, 0x8b, 0xbd, 0xe8, 0x5b, 0xa8, 0xff, 0xd7,
666     0x18, 0x9a, 0x23, 0x7b, 0x13, 0x5c, 0x1e, 0x90, 0x1d, 0x08, 0x95, 0xcc,
667     0xc5, 0x8e, 0x73, 0x4e, 0x02, 0x6f, 0x3c, 0xb6, 0x26, 0x77, 0x8d, 0x53,
668     0xc5, 0x62, 0x9f, 0xb5, 0xf0, 0x88, 0xfb, 0xe5, 0x14, 0x71, 0xab, 0xe6,
669 };
670
671 static const unsigned char rx_script_6_1rtt_secret[48] = {
672     0x2d, 0x6b, 0x9d, 0xd4, 0x39, 0xa0, 0xe7, 0xff, 0x17, 0xe2, 0xcb, 0x5c,
673     0x0d, 0x4a, 0xf6, 0x3f, 0xf4, 0xfe, 0xfc, 0xe5, 0x22, 0xfa, 0xf5, 0x5b,
674     0xc0, 0xb2, 0x18, 0xbb, 0x92, 0x4d, 0x35, 0xea, 0x67, 0xa6, 0xe7, 0xc1,
675     0x90, 0x10, 0xc9, 0x14, 0x46, 0xf5, 0x95, 0x57, 0x8b, 0x90, 0x88, 0x5d,
676 };
677
678 static const unsigned char rx_script_6_in[] = {
679     /* First Packet: Initial */
680     0xc5,                           /* Long, Initial, PN Length=2 bytes */
681     0x00, 0x00, 0x00, 0x01,         /* Version */
682     0x00,                           /* DCID */
683     0x04, 0x36, 0xf4, 0x75, 0x2d,   /* SCID */
684     0x00,                           /* Token Length */
685     0x41, 0xbe,                     /* Length (446) */
686     0xa9, 0xe2,                     /* PN (0) */
687     0x83, 0x39, 0x95, 0x8f, 0x8f, 0x8c, 0xa9, 0xaf, 0x10, 0x29, 0x3d, 0xfc,
688     0x56, 0x4a, 0x1c, 0x4b, 0xc9, 0x48, 0xb1, 0xaf, 0x36, 0xd5, 0xac, 0x95,
689     0xbf, 0xfd, 0x2c, 0x4d, 0x70, 0x2e, 0x5b, 0x7c, 0x22, 0x5f, 0x5f, 0xee,
690     0x10, 0x8f, 0xfb, 0x0b, 0x5f, 0x9d, 0x7e, 0x68, 0x2f, 0x94, 0x0b, 0xdb,
691     0xed, 0xef, 0xfa, 0x4e, 0xc6, 0xd5, 0xe7, 0xef, 0xe0, 0x78, 0x3c, 0xdc,
692     0xe9, 0xd8, 0xe8, 0x56, 0x71, 0xd7, 0xe7, 0x6c, 0x7f, 0x5d, 0xaa, 0x7a,
693     0x52, 0x1d, 0x95, 0x7a, 0x80, 0x70, 0x38, 0xc0, 0x8b, 0xa1, 0x2f, 0x09,
694     0x16, 0xd2, 0xec, 0xa3, 0x23, 0x72, 0x45, 0x3c, 0xbd, 0x8c, 0xda, 0xbb,
695     0x37, 0x5a, 0x8d, 0xb2, 0x00, 0x7e, 0x67, 0x0c, 0xa0, 0x32, 0xdd, 0x80,
696     0x07, 0x71, 0xb0, 0x95, 0x21, 0xbc, 0x1e, 0xbd, 0x63, 0x0a, 0x10, 0xe7,
697     0x4b, 0x6e, 0x2e, 0x85, 0x3a, 0x65, 0xf7, 0x06, 0x6e, 0x7e, 0x8f, 0x65,
698     0x8c, 0xb1, 0x93, 0xe9, 0x0d, 0xe8, 0x46, 0xe7, 0xcf, 0xa7, 0xd2, 0x8b,
699     0x15, 0x23, 0xec, 0xc3, 0xec, 0x44, 0xda, 0x62, 0x15, 0x35, 0x34, 0x2f,
700     0x62, 0x77, 0xc8, 0x1f, 0x83, 0x22, 0x00, 0xe5, 0xc0, 0x89, 0xb8, 0x97,
701     0xd2, 0x37, 0x02, 0xea, 0xa2, 0x35, 0xbf, 0x19, 0xf0, 0xba, 0x1d, 0xb7,
702     0xaa, 0x36, 0xbb, 0x11, 0x60, 0xc3, 0x45, 0x1f, 0xe5, 0x18, 0xde, 0x4c,
703     0x01, 0x23, 0x2d, 0x17, 0x78, 0xdd, 0x4c, 0x8a, 0x1e, 0x1b, 0xd4, 0xda,
704     0x56, 0x43, 0x13, 0xa4, 0x4f, 0xfd, 0xd5, 0x92, 0x6a, 0x05, 0x5f, 0x14,
705     0x63, 0x85, 0x7d, 0xf1, 0x31, 0xb8, 0x27, 0x0b, 0xa6, 0xb5, 0x50, 0xca,
706     0x8b, 0x0e, 0xa1, 0x0d, 0xf9, 0xc4, 0xea, 0x6a, 0x6e, 0x4b, 0x6d, 0xdf,
707     0x49, 0xe8, 0x32, 0xf6, 0x85, 0xc4, 0x29, 0x26, 0x32, 0xfb, 0x5e, 0xa8,
708     0x55, 0x6b, 0x67, 0xe9, 0xaa, 0x35, 0x33, 0x90, 0xd8, 0x2a, 0x71, 0x0b,
709     0x6a, 0x48, 0xc4, 0xa3, 0x8b, 0xe0, 0xe7, 0x00, 0x3d, 0xee, 0x30, 0x70,
710     0x84, 0xbd, 0xa3, 0x3c, 0x9e, 0xa3, 0x5c, 0x69, 0xab, 0x55, 0x7b, 0xe2,
711     0xe5, 0x86, 0x13, 0xcb, 0x93, 0x3f, 0xcb, 0x3e, 0x6d, 0xc9, 0xc2, 0x10,
712     0x2b, 0x00, 0x9b, 0x3f, 0x14, 0x4e, 0x04, 0x27, 0xc0, 0xae, 0x1d, 0x48,
713     0x89, 0x3a, 0xf4, 0xac, 0xe0, 0x05, 0x07, 0xc9, 0x74, 0x6e, 0x21, 0x01,
714     0xe9, 0x26, 0xfd, 0xb4, 0xb2, 0x2a, 0xda, 0x72, 0xda, 0xbf, 0x63, 0x9d,
715     0x37, 0xaf, 0x90, 0x05, 0xd6, 0x89, 0xc7, 0xa6, 0x81, 0x4e, 0x2a, 0x30,
716     0xe3, 0x05, 0x88, 0x9f, 0xd0, 0xba, 0x8d, 0xc4, 0x21, 0x52, 0x5a, 0x7a,
717     0xe1, 0xad, 0xd3, 0x88, 0xc2, 0x18, 0xad, 0x4c, 0xb1, 0x66, 0x73, 0x1b,
718     0xf2, 0xd1, 0xb9, 0x43, 0xaa, 0xc4, 0x66, 0xcd, 0x42, 0xfa, 0x80, 0xec,
719     0xa1, 0x7c, 0x45, 0x02, 0x53, 0x45, 0xd5, 0x07, 0xd4, 0x70, 0x12, 0x1b,
720     0x08, 0x05, 0x6e, 0x99, 0x0a, 0xd3, 0x5b, 0x99, 0x6b, 0x65, 0xc4, 0xc0,
721     0x04, 0x1b, 0x75, 0xf2, 0x86, 0x99, 0x09, 0x4a, 0x50, 0x70, 0x00, 0x7a,
722     0x93, 0xaa, 0xe6, 0xf4, 0x03, 0x29, 0x06, 0xa4, 0x30, 0x6d, 0x52, 0xbd,
723     0x60, 0xd1, 0x7e, 0xd6, 0x07, 0xc0, 0x41, 0x01, 0x12, 0x3e, 0x16, 0x94,
724
725     /* Second Packet: Handshake */
726     0xea,                           /* Long, Handshake, PN Length=2 bytes */
727     0x00, 0x00, 0x00, 0x01,         /* Version */
728     0x00,                           /* DCID */
729     0x04, 0x36, 0xf4, 0x75, 0x2d,   /* SCID */
730     0x42, 0xb0,                     /* Length (688) */
731     0x3a, 0xc5,                     /* PN (0) */
732     0x3b, 0x8e, 0x4c, 0x01, 0x72, 0x6b, 0xfa, 0xbb, 0xad, 0xf9, 0x9e, 0x21,
733     0xb1, 0xd0, 0x01, 0xf1, 0xd4, 0x67, 0x8d, 0x2c, 0xee, 0x04, 0x60, 0x4a,
734     0xe2, 0xe4, 0xc6, 0x89, 0x01, 0xae, 0x3c, 0x1f, 0xf7, 0xe6, 0xf7, 0xac,
735     0x26, 0xcf, 0x3c, 0x6d, 0x1d, 0xfd, 0x11, 0x02, 0x51, 0x73, 0xb5, 0xe1,
736     0xb2, 0x44, 0x42, 0x32, 0x0f, 0xf5, 0x3d, 0x55, 0x2d, 0x1f, 0x02, 0x29,
737     0x51, 0x35, 0xdb, 0xc7, 0x7a, 0x34, 0x4b, 0xec, 0x60, 0x49, 0xa2, 0x90,
738     0x11, 0xef, 0x5a, 0xa9, 0x1c, 0xf7, 0xd9, 0x21, 0x68, 0x1c, 0x2b, 0xc6,
739     0x57, 0xde, 0xb1, 0x0b, 0x31, 0xed, 0xef, 0x16, 0xba, 0x08, 0xb9, 0xe2,
740     0xd9, 0xd0, 0xd8, 0x1f, 0xc4, 0x32, 0xe8, 0x45, 0x2a, 0x86, 0xe4, 0xd3,
741     0xaf, 0x72, 0x4f, 0x30, 0x01, 0x71, 0x15, 0x9b, 0xa9, 0x55, 0x35, 0xf7,
742     0x39, 0x7e, 0x6a, 0x59, 0x18, 0x4f, 0xe6, 0xdf, 0xb5, 0x0d, 0xc2, 0xe7,
743     0xb2, 0xa1, 0xa6, 0xa3, 0x9c, 0xf0, 0x0d, 0x59, 0x05, 0x49, 0x95, 0xfa,
744     0xcc, 0x72, 0xd7, 0xc0, 0x84, 0x2e, 0xc4, 0x1c, 0xd4, 0xa0, 0xe3, 0x6c,
745     0x5a, 0x8c, 0x94, 0x4d, 0x37, 0x1a, 0x1c, 0x68, 0x93, 0x5f, 0xe5, 0x99,
746     0x27, 0xc6, 0x06, 0xaa, 0x1f, 0x29, 0x17, 0xc5, 0x8c, 0x3d, 0x53, 0xa7,
747     0x05, 0x3a, 0x44, 0x53, 0x86, 0xed, 0x56, 0x99, 0x4c, 0xe2, 0x7b, 0x3a,
748     0x1e, 0x5d, 0x6d, 0xac, 0x78, 0x1e, 0xfa, 0x55, 0x58, 0x6e, 0x72, 0xee,
749     0xf9, 0x33, 0x64, 0x7f, 0x93, 0x3c, 0xfe, 0x18, 0x97, 0x6b, 0x02, 0x74,
750     0x90, 0x0d, 0xba, 0x89, 0xc0, 0x22, 0x0a, 0x0a, 0x37, 0x4c, 0x28, 0x74,
751     0xa7, 0x3a, 0x44, 0x74, 0x42, 0xff, 0xf1, 0xd2, 0x8d, 0x0c, 0xc1, 0xed,
752     0x98, 0x98, 0x8e, 0xa8, 0x6b, 0x95, 0x6a, 0x86, 0x0b, 0xb4, 0x95, 0x58,
753     0x34, 0x12, 0xb0, 0xc0, 0xf8, 0x2d, 0x5b, 0x40, 0x51, 0x80, 0x07, 0x91,
754     0x31, 0x77, 0xd3, 0x06, 0xa5, 0xe5, 0x1f, 0xe2, 0xf8, 0x92, 0xe4, 0x23,
755     0x2b, 0xf0, 0x4c, 0xa9, 0xa5, 0x6c, 0x6f, 0xaf, 0xaf, 0xbf, 0x97, 0xcf,
756     0x46, 0xf2, 0x8d, 0x61, 0x0e, 0x73, 0xcd, 0xc5, 0xde, 0xda, 0x50, 0x82,
757     0x61, 0x6d, 0xb1, 0xa2, 0xbe, 0x6b, 0x99, 0xcd, 0x5b, 0x99, 0x8f, 0x66,
758     0xab, 0x11, 0x78, 0xcc, 0xdb, 0x66, 0x98, 0xca, 0x19, 0x92, 0xf4, 0x05,
759     0xae, 0xe6, 0xf3, 0xe7, 0xf0, 0x30, 0x28, 0x31, 0x74, 0xff, 0xe2, 0xb3,
760     0x3a, 0x4f, 0x79, 0xe7, 0x2a, 0x9f, 0xe3, 0x41, 0xb2, 0x88, 0xc8, 0x8f,
761     0x77, 0x57, 0x42, 0x65, 0xdb, 0x07, 0xf6, 0x5f, 0xb8, 0x34, 0x17, 0xe3,
762     0x8d, 0x22, 0x5b, 0x88, 0x94, 0x60, 0x97, 0x32, 0x3d, 0x8a, 0x51, 0x9d,
763     0xb5, 0xac, 0xd7, 0x99, 0x96, 0x23, 0x6d, 0xc9, 0xab, 0x61, 0x41, 0x8f,
764     0x72, 0x1b, 0xf8, 0x84, 0xd9, 0x57, 0x88, 0x68, 0x3d, 0x73, 0x5f, 0xb1,
765     0x18, 0x5c, 0x3a, 0x35, 0xd2, 0xc5, 0xb7, 0x29, 0xc7, 0x95, 0xdd, 0x21,
766     0xc0, 0x78, 0x49, 0xf3, 0x24, 0xe0, 0x4c, 0x5c, 0x32, 0x08, 0xb7, 0x00,
767     0x43, 0x70, 0x5a, 0x95, 0x23, 0x91, 0xf5, 0xb7, 0x61, 0x85, 0x6f, 0xb3,
768     0xa4, 0x6b, 0x05, 0x9d, 0x39, 0xa3, 0xb1, 0x1c, 0x61, 0xc5, 0xa5, 0xe7,
769     0x9a, 0xe9, 0x5d, 0xaa, 0xca, 0x11, 0xd8, 0x4b, 0xa4, 0x9c, 0x18, 0x4e,
770     0x2b, 0x2d, 0x75, 0xc1, 0x12, 0x20, 0xe4, 0x66, 0xa5, 0x59, 0x67, 0x4b,
771     0xcc, 0x52, 0x2d, 0xfa, 0xaa, 0xa4, 0xe9, 0xfc, 0x79, 0xd7, 0xff, 0x03,
772     0x3e, 0xec, 0xba, 0x97, 0x37, 0x52, 0xc1, 0x57, 0x31, 0x8e, 0x57, 0x0c,
773     0x54, 0x92, 0x9c, 0x25, 0x5c, 0xfa, 0x9f, 0xa5, 0x36, 0x18, 0xd0, 0xaa,
774     0xf3, 0x3b, 0x5b, 0x59, 0xbd, 0x33, 0x5e, 0x7d, 0x74, 0x7c, 0xaf, 0xe9,
775     0x54, 0x80, 0xc4, 0xb4, 0xa1, 0x24, 0x9e, 0x23, 0x0d, 0xbf, 0x4e, 0x0f,
776     0xaf, 0xa5, 0x16, 0xcb, 0x3b, 0xfa, 0x33, 0xa5, 0x68, 0xa6, 0x64, 0x48,
777     0x2f, 0x5e, 0xfa, 0x64, 0x4e, 0xe3, 0x27, 0x4f, 0x13, 0xe6, 0x37, 0xf6,
778     0xb9, 0x63, 0x4b, 0xdc, 0x49, 0x3c, 0x5e, 0x9e, 0x06, 0xea, 0xac, 0xa3,
779     0xdf, 0x6c, 0x49, 0xfb, 0xa1, 0x01, 0x4f, 0x6f, 0x74, 0x1f, 0xd3, 0x26,
780     0xa1, 0x92, 0x3e, 0xe0, 0x73, 0xd6, 0x3b, 0x67, 0x13, 0x53, 0x2e, 0xcb,
781     0xbc, 0x83, 0xd0, 0x6e, 0x28, 0xb1, 0xcb, 0xd9, 0x66, 0xe0, 0x33, 0x59,
782     0x45, 0xd3, 0x13, 0xc2, 0x48, 0xd5, 0x9e, 0x88, 0xba, 0x75, 0x7b, 0xb1,
783     0xfe, 0x6f, 0xec, 0xde, 0xff, 0x14, 0x59, 0x75, 0xbf, 0x1a, 0x74, 0x47,
784     0xc5, 0xd8, 0xe8, 0x1b, 0x3c, 0x86, 0xd7, 0x1f, 0x99, 0x11, 0xd3, 0x29,
785     0xfd, 0x5d, 0x22, 0x7e, 0x03, 0x78, 0xed, 0x62, 0x0e, 0xbe, 0x6d, 0x75,
786     0xf4, 0xa8, 0x6e, 0xc7, 0x21, 0x76, 0xc5, 0xa0, 0x0c, 0xaa, 0x58, 0x78,
787     0x7e, 0x6e, 0xfc, 0x1e, 0x2a, 0x1c, 0xdd, 0xe5, 0x78, 0x08, 0xbd, 0xdb,
788     0xea, 0x8f, 0x8a, 0xa5, 0xbf, 0x93, 0xfe, 0x0f, 0x03, 0xa1, 0xc8, 0x64,
789     0x9f, 0x4a,
790
791     /* Third Packet: 1-RTT */
792     0x48,               /* Short, 1-RTT, Spin=0, KP=0, PN Length=2 bytes */
793     0x3e, 0x28,         /* PN (0) */
794     0xb9, 0xdb, 0x61, 0xf8, 0x8b, 0x3a, 0xef, 0x26, 0x69, 0xf2, 0x57, 0xc6,
795     0x84, 0x25, 0x6b, 0x77, 0xbe, 0x8c, 0x43, 0x32, 0xf3, 0x9a, 0xd1, 0x85,
796     0x14, 0xbc, 0x89, 0x3b, 0x9c, 0xf3, 0xfc, 0x00, 0xa1, 0x3a, 0xc3, 0xc4,
797     0x1e, 0xdf, 0xd0, 0x11, 0x70, 0xd9, 0x02, 0x7a, 0xd4, 0xef, 0x86, 0x67,
798     0xb1, 0x1e, 0x5d, 0xe3, 0x7f, 0x82, 0x14, 0x52, 0xa5, 0x8a, 0x89, 0xa7,
799     0x98, 0x75, 0x2f, 0x8a, 0x00, 0xf3, 0xbd, 0x49, 0x26, 0x4d, 0x0c, 0xc7,
800     0x38, 0xe7, 0x91, 0x85, 0xc9, 0x21, 0x6a, 0x1c, 0xc4, 0xa3, 0x0e, 0xd8,
801     0xfe, 0xb1, 0x25, 0x1a,
802 };
803
804 static const QUIC_PKT_HDR rx_script_6a_expect_hdr = {
805     QUIC_PKT_TYPE_INITIAL,
806     0,          /* Spin Bit */
807     0,          /* Key Phase */
808     2,          /* PN Length */
809     0,          /* Partial */
810     1,          /* Fixed */
811     0,          /* Unused */
812     0,          /* Reserved */
813     1,          /* Version */
814     {0, {0}},                           /* DCID */
815     {4, {0x36, 0xf4, 0x75, 0x2d}},      /* SCID */
816     {0},        /* PN */
817     NULL, 0,    /* Token/Token Len */
818     428, NULL
819 };
820
821 static const unsigned char rx_script_6a_body[] = {
822     0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
823     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
824     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
825     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
828     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
829     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
830     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
831     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
832     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
833     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
835     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
836     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
837     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
838     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
839     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
840     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
841     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
842     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
843     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
844     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
845     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
846     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
847     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
848     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
849     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
850     0x40, 0x5a, 0x02, 0x00, 0x00, 0x56, 0x03, 0x03, 0xc3, 0x45, 0xe8, 0xb8,
851     0xf9, 0x7c, 0x9f, 0x5d, 0xcf, 0x66, 0x25, 0xe4, 0x91, 0x0e, 0xb0, 0x5a,
852     0x14, 0xce, 0xaf, 0xea, 0x83, 0x12, 0xde, 0x68, 0xd9, 0x31, 0xf2, 0x23,
853     0x11, 0x3a, 0x15, 0xcb, 0x00, 0x13, 0x02, 0x00, 0x00, 0x2e, 0x00, 0x2b,
854     0x00, 0x02, 0x03, 0x04, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20,
855     0xab, 0xd3, 0xc6, 0x9f, 0x36, 0xd3, 0x52, 0x93, 0x87, 0xee, 0x92, 0x01,
856     0xa2, 0xd6, 0x9a, 0x5e, 0x61, 0x43, 0xcc, 0x4a, 0xcc, 0x7a, 0xcd, 0x83,
857     0xb2, 0xd9, 0xad, 0xd1, 0x14, 0xdc, 0x84, 0x61,
858 };
859
860 static const QUIC_PKT_HDR rx_script_6b_expect_hdr = {
861     QUIC_PKT_TYPE_HANDSHAKE,
862     0,          /* Spin Bit */
863     0,          /* Key Phase */
864     2,          /* PN Length */
865     0,          /* Partial */
866     1,          /* Fixed */
867     0,          /* Unused */
868     0,          /* Reserved */
869     1,          /* Version */
870     {0, {0}},                           /* DCID */
871     {4, {0x36, 0xf4, 0x75, 0x2d}},      /* SCID */
872     {0},        /* PN */
873     NULL, 0,    /* Token/Token Len */
874     670, NULL
875 };
876
877 static const unsigned char rx_script_6b_body[] = {
878     0x06, 0x00, 0x42, 0x9a, 0x08, 0x00, 0x00, 0x80, 0x00, 0x7e, 0x00, 0x10,
879     0x00, 0x08, 0x00, 0x06, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x00, 0x39,
880     0x00, 0x6e, 0x47, 0xfa, 0x05, 0x5a, 0xe0, 0xec, 0x4a, 0xf3, 0x05, 0x04,
881     0x80, 0x08, 0x00, 0x00, 0x06, 0x04, 0x80, 0x08, 0x00, 0x00, 0x07, 0x04,
882     0x80, 0x08, 0x00, 0x00, 0x04, 0x04, 0x80, 0x0c, 0x00, 0x00, 0x08, 0x02,
883     0x40, 0x64, 0x09, 0x02, 0x40, 0x64, 0x01, 0x04, 0x80, 0x00, 0x75, 0x30,
884     0x03, 0x02, 0x45, 0xac, 0x0b, 0x01, 0x1a, 0x0c, 0x00, 0x02, 0x10, 0x35,
885     0xd7, 0x7d, 0x8b, 0xc5, 0xb1, 0x89, 0xb1, 0x5c, 0x23, 0x74, 0x50, 0xfd,
886     0x47, 0xfe, 0xd2, 0x00, 0x11, 0x96, 0x38, 0x27, 0xde, 0x7d, 0xfb, 0x2b,
887     0x38, 0x56, 0xe5, 0x2a, 0xb8, 0x6b, 0xfa, 0xaa, 0xde, 0x81, 0x0e, 0x01,
888     0x04, 0x0f, 0x04, 0x36, 0xf4, 0x75, 0x2d, 0x10, 0x04, 0xac, 0x88, 0x95,
889     0xbd, 0x20, 0x01, 0x00, 0x0b, 0x00, 0x01, 0x8f, 0x00, 0x00, 0x01, 0x8b,
890     0x00, 0x01, 0x86, 0x30, 0x82, 0x01, 0x82, 0x30, 0x82, 0x01, 0x29, 0xa0,
891     0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x0a, 0x73, 0x0f, 0x86, 0x18, 0xf2,
892     0xc3, 0x30, 0x01, 0xd2, 0xc0, 0xc1, 0x62, 0x52, 0x13, 0xf1, 0x9c, 0x13,
893     0x39, 0xb5, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,
894     0x03, 0x02, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04,
895     0x03, 0x0c, 0x0c, 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f,
896     0x63, 0x61, 0x6c, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x38, 0x30,
897     0x32, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x32, 0x32,
898     0x30, 0x39, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x30,
899     0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c,
900     0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
901     0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
902     0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
903     0x42, 0x00, 0x04, 0x67, 0xf4, 0xd3, 0x8f, 0x15, 0x6d, 0xee, 0x85, 0xcc,
904     0x2a, 0x77, 0xfc, 0x0b, 0x8f, 0x9f, 0xcf, 0xa9, 0x95, 0x5d, 0x5b, 0xcd,
905     0xb7, 0x8b, 0xba, 0x31, 0x0a, 0x73, 0x62, 0xc5, 0xd0, 0x0e, 0x07, 0x90,
906     0xae, 0x38, 0x43, 0x79, 0xce, 0x5e, 0x33, 0xad, 0x31, 0xbf, 0x9f, 0x2a,
907     0x56, 0x83, 0xa5, 0x24, 0x16, 0xab, 0x0c, 0xf1, 0x64, 0xbe, 0xe4, 0x93,
908     0xb5, 0x89, 0xd6, 0x05, 0xe4, 0xf7, 0x7b, 0xa3, 0x53, 0x30, 0x51, 0x30,
909     0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x02, 0x64,
910     0x0f, 0x55, 0x69, 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5,
911     0x5a, 0xd0, 0x48, 0x96, 0x9f, 0x60, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d,
912     0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x02, 0x64, 0x0f, 0x55, 0x69,
913     0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a, 0xd0, 0x48,
914     0x96, 0x9f, 0x60, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01,
915     0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08,
916     0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30,
917     0x44, 0x02, 0x20, 0x0a, 0x82, 0x92, 0x6e, 0xd3, 0xc6, 0x66, 0xd9, 0xd3,
918     0x75, 0xff, 0x71, 0x3b, 0x61, 0x46, 0x21, 0x00, 0xe6, 0x21, 0x5d, 0x9c,
919     0x86, 0xe9, 0x65, 0x40, 0x4f, 0xeb, 0x70, 0x4f, 0x2c, 0xad, 0x00, 0x02,
920     0x20, 0x08, 0xc2, 0x07, 0x5d, 0x16, 0xfc, 0x54, 0x34, 0x2b, 0xb4, 0x18,
921     0x67, 0x44, 0x81, 0xc9, 0xa9, 0x67, 0x2e, 0xce, 0xa1, 0x02, 0x9f, 0x3b,
922     0xe5, 0x61, 0x16, 0x0b, 0x50, 0xf6, 0xa1, 0x50, 0x94, 0x00, 0x00, 0x0f,
923     0x00, 0x00, 0x4b, 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x78,
924     0x9e, 0xe0, 0x6a, 0x7a, 0xbd, 0xc3, 0x84, 0x3d, 0x25, 0x6a, 0x59, 0x23,
925     0x97, 0x52, 0x64, 0x4e, 0xb6, 0x9f, 0xcc, 0xd3, 0xd7, 0xa9, 0x29, 0x44,
926     0x75, 0x6d, 0x50, 0xfc, 0x22, 0xde, 0xd3, 0x02, 0x21, 0x00, 0xe5, 0x28,
927     0xd6, 0x5a, 0xd1, 0xec, 0x4a, 0xcc, 0x20, 0xb4, 0xea, 0x15, 0xfb, 0x8e,
928     0x73, 0xa8, 0x6b, 0xbb, 0x42, 0x70, 0x90, 0x08, 0x6e, 0x74, 0x6f, 0x5a,
929     0x05, 0xb5, 0x39, 0xee, 0x01, 0x04, 0x14, 0x00, 0x00, 0x30, 0xff, 0x9f,
930     0xb2, 0x1d, 0xcb, 0x4f, 0xfc, 0x7a, 0xac, 0xf4, 0x75, 0x24, 0x83, 0x5f,
931     0x8d, 0xa3, 0x3e, 0x9d, 0xef, 0x43, 0x67, 0x89, 0x5d, 0x55, 0xc7, 0xce,
932     0x80, 0xab, 0xc3, 0xc7, 0x74, 0xc7, 0xb2, 0x91, 0x27, 0xce, 0xd8, 0x5e,
933     0xc4, 0x4e, 0x96, 0x19, 0x68, 0x2d, 0xbe, 0x6f, 0x49, 0xfa,
934 };
935
936 static const QUIC_PKT_HDR rx_script_6c_expect_hdr = {
937     QUIC_PKT_TYPE_1RTT,
938     0,          /* Spin Bit */
939     0,          /* Key Phase */
940     2,          /* PN Length */
941     0,          /* Partial */
942     1,          /* Fixed */
943     0,          /* Unused */
944     0,          /* Reserved */
945     0,          /* Version */
946     {0, {0}},                           /* DCID */
947     {0, {0}},                           /* SCID */
948     {0},        /* PN */
949     NULL, 0,    /* Token/Token Len */
950     72, NULL
951 };
952
953 static const unsigned char rx_script_6c_body[] = {
954     0x18, 0x03, 0x00, 0x04, 0xf2, 0x94, 0x49, 0xc3, 0x34, 0xa1, 0xf4, 0x0f,
955     0xcb, 0xb8, 0x03, 0x04, 0x1f, 0xc8, 0x69, 0xb9, 0x3b, 0xd5, 0xc6, 0x93,
956     0x18, 0x02, 0x00, 0x04, 0x9a, 0x4f, 0xec, 0x52, 0xde, 0xd2, 0xc8, 0xb7,
957     0x1c, 0x0c, 0xf3, 0x4e, 0x46, 0xf0, 0x6c, 0x54, 0x34, 0x1b, 0x0d, 0x98,
958     0x18, 0x01, 0x00, 0x04, 0xe3, 0x33, 0x9e, 0x59, 0x00, 0x69, 0xc3, 0xac,
959     0xfc, 0x58, 0x0e, 0xa4, 0xf4, 0xf3, 0x23, 0x1b, 0xd6, 0x8e, 0x5b, 0x08,
960 };
961
962 static const struct rx_test_op rx_script_6[] = {
963     RX_OP_ALLOW_1RTT()
964     RX_OP_SET_RX_DCID(empty_conn_id)
965     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_6_c2s_init_dcid)
966     RX_OP_INJECT_N(6)
967     RX_OP_CHECK_PKT_N(6a)
968     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
969     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
970                       QRL_SUITE_AES256GCM, rx_script_6_handshake_secret)
971     RX_OP_CHECK_PKT_N(6b)
972     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
973     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
974                       QRL_SUITE_AES256GCM, rx_script_6_1rtt_secret)
975     RX_OP_CHECK_PKT_N(6c)
976     RX_OP_CHECK_NO_PKT()
977
978     /* Discard Initial EL and try injecting the packet again */
979     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
980     RX_OP_INJECT_N(6)
981     /* Initial packet is not output because we have discarded Initial keys */
982     RX_OP_CHECK_PKT_N(6b)
983     RX_OP_CHECK_PKT_N(6c)
984     RX_OP_CHECK_NO_PKT()
985     /* Try again with discarded keys */
986     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
987     RX_OP_INJECT_N(6)
988     RX_OP_CHECK_PKT_N(6c)
989     RX_OP_CHECK_NO_PKT()
990     /* Try again */
991     RX_OP_INJECT_N(6)
992     RX_OP_CHECK_PKT_N(6c)
993     RX_OP_CHECK_NO_PKT()
994     /* Try again with discarded 1-RTT keys */
995     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
996     RX_OP_INJECT_N(6)
997     RX_OP_CHECK_NO_PKT()
998
999     /* Recreate QRL, test reading packets received before key */
1000     RX_OP_SET_SCID_LEN(0)
1001     RX_OP_SET_RX_DCID(empty_conn_id)
1002     RX_OP_INJECT_N(6)
1003     RX_OP_CHECK_NO_PKT()
1004     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_6_c2s_init_dcid)
1005     RX_OP_CHECK_PKT_N(6a)
1006     RX_OP_CHECK_NO_PKT()
1007     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
1008                       QRL_SUITE_AES256GCM, rx_script_6_handshake_secret)
1009     RX_OP_CHECK_PKT_N(6b)
1010     RX_OP_CHECK_NO_PKT()
1011     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1012                       QRL_SUITE_AES256GCM, rx_script_6_1rtt_secret)
1013     RX_OP_CHECK_PKT_N(6c)
1014     RX_OP_CHECK_NO_PKT()
1015
1016     RX_OP_END
1017 };
1018
1019 /*
1020  * 7. Real World - S2C Multiple Packets
1021  *      - Initial, Handshake, 1-RTT (ChaCha20-Poly1305)
1022  */
1023 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1024 static const QUIC_CONN_ID rx_script_7_c2s_init_dcid = {
1025     4, {0xfa, 0x5d, 0xd6, 0x80}
1026 };
1027
1028 static const unsigned char rx_script_7_handshake_secret[32] = {
1029     0x85, 0x44, 0xa4, 0x02, 0x46, 0x5b, 0x2a, 0x92, 0x80, 0x71, 0xfd, 0x11,
1030     0x89, 0x73, 0x84, 0xeb, 0x3e, 0x0d, 0x89, 0x4f, 0x71, 0xdc, 0x9c, 0xdd,
1031     0x55, 0x77, 0x9e, 0x79, 0x7b, 0xeb, 0xfa, 0x86,
1032 };
1033
1034 static const unsigned char rx_script_7_1rtt_secret[32] = {
1035     0x4a, 0x77, 0xb6, 0x0e, 0xfd, 0x90, 0xca, 0xbf, 0xc0, 0x1a, 0x64, 0x9f,
1036     0xc0, 0x03, 0xd3, 0x8d, 0xc5, 0x41, 0x04, 0x50, 0xb1, 0x5b, 0x74, 0xe7,
1037     0xe3, 0x99, 0x0c, 0xdf, 0x74, 0x61, 0x35, 0xe6,
1038 };
1039
1040 static const unsigned char rx_script_7_in[] = {
1041     /* First Packet: Initial */
1042     0xc2,                           /* Long, Initial, PN Length=2 bytes */
1043     0x00, 0x00, 0x00, 0x01,         /* Version */
1044     0x00,                           /* DCID */
1045     0x04, 0x03, 0x45, 0x0c, 0x7a,   /* SCID */
1046     0x00,                           /* Token Length */
1047     0x41, 0xcb,                     /* Length (459) */
1048     0x3c, 0xe0,                     /* PN (0) */
1049     0x85, 0x05, 0xc2, 0x4d, 0x0f, 0xf3, 0x62, 0x51, 0x04, 0x33, 0xfa, 0xb5,
1050     0xa3, 0x02, 0xbd, 0x5c, 0x22, 0x0c, 0x1d, 0xda, 0x06, 0xf1, 0xd7, 0xe0,
1051     0xc8, 0x56, 0xb0, 0x3d, 0xc1, 0x49, 0x8c, 0xc2, 0x88, 0x5a, 0x0e, 0xd5,
1052     0x67, 0x72, 0xec, 0xcc, 0x7a, 0x2b, 0x46, 0x17, 0x49, 0x4b, 0x28, 0x6a,
1053     0x89, 0x71, 0xfd, 0x31, 0x9a, 0xa1, 0x97, 0x64, 0xe2, 0xbf, 0xa0, 0x6d,
1054     0xf6, 0x76, 0x83, 0x28, 0xc4, 0xd5, 0x39, 0x87, 0x22, 0x7c, 0x11, 0x9a,
1055     0x53, 0x66, 0xb4, 0x27, 0xf1, 0xab, 0x6f, 0x49, 0x43, 0x3f, 0x9a, 0x23,
1056     0xd3, 0x53, 0x06, 0xe8, 0x14, 0xfd, 0xc0, 0x67, 0x1f, 0x88, 0x2a, 0xa8,
1057     0xae, 0x5f, 0x05, 0x0a, 0xeb, 0x66, 0x72, 0x8c, 0x46, 0xcc, 0x54, 0x21,
1058     0x5e, 0x14, 0xfe, 0x68, 0xc7, 0xf7, 0x60, 0x67, 0xb5, 0xa7, 0x0d, 0xf4,
1059     0xe1, 0xff, 0x60, 0xe3, 0x11, 0x38, 0x92, 0x90, 0xc2, 0x48, 0x28, 0xbf,
1060     0xf3, 0x85, 0x27, 0xfe, 0xbf, 0x42, 0x26, 0x1a, 0x4e, 0x78, 0xf1, 0xf0,
1061     0x88, 0x16, 0x1b, 0x64, 0x5f, 0x66, 0x02, 0x0b, 0x45, 0x3d, 0x38, 0xd9,
1062     0x09, 0xd5, 0xff, 0xc2, 0x68, 0x02, 0x2c, 0xc4, 0x3f, 0x60, 0x6e, 0x2f,
1063     0x7f, 0x43, 0xf7, 0x1a, 0x37, 0xcc, 0xe0, 0xe0, 0x4b, 0x96, 0xc1, 0xb1,
1064     0x8b, 0x1c, 0x7c, 0x6e, 0x80, 0xe3, 0x92, 0x9b, 0x86, 0x87, 0x1f, 0x9a,
1065     0x6a, 0x62, 0x18, 0xf4, 0x86, 0xc2, 0x3e, 0x33, 0xa3, 0xbf, 0x43, 0x96,
1066     0x6e, 0xff, 0x94, 0xaf, 0x6d, 0x23, 0x5c, 0x42, 0xed, 0xe7, 0xb9, 0x2c,
1067     0x33, 0xb0, 0xc6, 0x3d, 0x44, 0x00, 0x0b, 0xa3, 0x39, 0xa8, 0xeb, 0x8c,
1068     0x81, 0x1a, 0x99, 0x20, 0xbd, 0xfa, 0xf3, 0xf4, 0xf0, 0x11, 0xd8, 0x41,
1069     0x31, 0x8d, 0xdc, 0x0d, 0x00, 0xa6, 0x31, 0x40, 0xc6, 0xc6, 0xad, 0x74,
1070     0x93, 0x62, 0x1c, 0x55, 0xce, 0x5f, 0x8c, 0x5b, 0x3c, 0xcb, 0x25, 0x5e,
1071     0xbf, 0xed, 0xbb, 0x3c, 0x97, 0x4b, 0x62, 0xe0, 0xba, 0xf1, 0xb0, 0x30,
1072     0xbf, 0x35, 0x89, 0x7e, 0x25, 0x61, 0x54, 0x86, 0x52, 0x11, 0x86, 0x90,
1073     0xc3, 0xf5, 0xad, 0xa0, 0x96, 0x30, 0xb2, 0xf0, 0xa6, 0x79, 0x39, 0x1c,
1074     0x51, 0x42, 0xa1, 0x00, 0x6f, 0x55, 0x7d, 0xdc, 0xd0, 0x7c, 0xcf, 0x01,
1075     0x88, 0x03, 0xd7, 0x2d, 0x65, 0x2b, 0x40, 0xee, 0xba, 0x10, 0xd8, 0x0c,
1076     0x85, 0x14, 0xb7, 0x4d, 0x9e, 0x7d, 0x7c, 0xde, 0x7f, 0x0d, 0x0e, 0x3b,
1077     0x3d, 0xe3, 0xd3, 0x63, 0xc2, 0xed, 0xc7, 0x41, 0xaf, 0x05, 0x85, 0x87,
1078     0x46, 0x55, 0x7e, 0xbe, 0x14, 0x5b, 0x98, 0xae, 0x6e, 0x67, 0x1a, 0x65,
1079     0xc6, 0xcf, 0xe1, 0x28, 0x50, 0x6b, 0xb4, 0xf6, 0xba, 0x63, 0xbc, 0xf1,
1080     0xd7, 0xa4, 0x97, 0x2d, 0x4d, 0x04, 0x26, 0x96, 0xec, 0x0c, 0xd4, 0xae,
1081     0x6a, 0xca, 0x7e, 0x65, 0xc5, 0x43, 0x7e, 0xf8, 0x77, 0x61, 0xd0, 0x2c,
1082     0xe5, 0x37, 0x0a, 0xb3, 0x7a, 0x8c, 0x2a, 0xa1, 0xdc, 0x29, 0xdb, 0xec,
1083     0xca, 0xdc, 0xfe, 0xdd, 0x38, 0xd2, 0x13, 0x9f, 0x94, 0x6d, 0x5b, 0x87,
1084     0xf3, 0x15, 0xa8, 0xe5, 0xe9, 0x65, 0x1d, 0x4f, 0x92, 0x1b, 0xf4, 0xa6,
1085     0xa4, 0xd6, 0x22, 0xfc, 0x26, 0x1b, 0x35, 0xa4, 0x1c, 0x88, 0x9f, 0x7d,
1086     0xe0, 0x9a, 0x89, 0x0f, 0x6c, 0xc1, 0xda, 0x6e, 0x45, 0xce, 0x74, 0xb1,
1087     0xff,
1088
1089     /* Second Packet: Handshake */
1090     0xeb,                           /* Long, Handshake, PN Length=2 bytes */
1091     0x00, 0x00, 0x00, 0x01,         /* Version */
1092     0x00,                           /* DCID */
1093     0x04, 0x03, 0x45, 0x0c, 0x7a,   /* SCID */
1094     0x42, 0xa3,                     /* Length (675) */
1095     0x43, 0x29,                     /* PN (0) */
1096     0xff, 0xdb, 0xcf, 0x3c, 0x17, 0xcf, 0xdc, 0x42, 0x3a, 0x59, 0x88, 0xdb,
1097     0x13, 0xef, 0x09, 0x3d, 0xf2, 0x24, 0xf3, 0xeb, 0xca, 0xb0, 0xe1, 0xa4,
1098     0x67, 0x64, 0x65, 0x80, 0x5f, 0x73, 0x29, 0x69, 0x29, 0xba, 0x03, 0x77,
1099     0x22, 0xc8, 0xa8, 0xd5, 0x21, 0xf2, 0xa2, 0x30, 0x7f, 0x86, 0x3a, 0x8a,
1100     0xdd, 0x92, 0x33, 0xa6, 0x57, 0x21, 0x39, 0xdd, 0x34, 0xb4, 0x39, 0xa7,
1101     0x6f, 0x0a, 0x14, 0xba, 0x9e, 0x3b, 0x3a, 0x6a, 0x4b, 0xc5, 0xda, 0x44,
1102     0x82, 0xca, 0x52, 0x86, 0x68, 0x8a, 0x0c, 0x5e, 0xeb, 0x1e, 0x81, 0x43,
1103     0x3a, 0x59, 0x2c, 0x26, 0x63, 0xa3, 0x89, 0x92, 0x80, 0xe9, 0x75, 0xc2,
1104     0xdb, 0xb9, 0x58, 0x6d, 0xab, 0xfd, 0x21, 0xe0, 0x35, 0x79, 0x2e, 0x56,
1105     0x7b, 0xfb, 0xb3, 0x7a, 0x05, 0x33, 0x0f, 0x13, 0xe5, 0xef, 0x04, 0x41,
1106     0x69, 0x85, 0x91, 0x24, 0xce, 0xb5, 0x21, 0x8d, 0x0a, 0x13, 0xda, 0xae,
1107     0x86, 0x2f, 0x25, 0x1f, 0x9c, 0x70, 0x8a, 0xaa, 0x05, 0xeb, 0x30, 0x93,
1108     0x50, 0xc1, 0x39, 0xab, 0x99, 0x8a, 0x31, 0xc1, 0xc1, 0x5e, 0x39, 0xcf,
1109     0x64, 0x3f, 0x9f, 0x5c, 0xa5, 0xa1, 0x88, 0xb2, 0x5f, 0x23, 0xcb, 0x76,
1110     0xe5, 0xf3, 0x2d, 0xa0, 0xed, 0xad, 0xcf, 0x30, 0x05, 0x44, 0xdc, 0xa5,
1111     0x81, 0xb1, 0x7f, 0x78, 0x0d, 0x4d, 0x96, 0xa3, 0xcb, 0xcb, 0x45, 0xcf,
1112     0x5f, 0x22, 0xb8, 0x93, 0x2b, 0x16, 0xe0, 0x1c, 0x53, 0x34, 0x76, 0x3b,
1113     0x7b, 0x78, 0xa1, 0x46, 0x40, 0x43, 0x4b, 0x0e, 0x1c, 0xfd, 0xcf, 0x01,
1114     0xf1, 0x2c, 0xee, 0xd0, 0xbd, 0x9f, 0x44, 0xd2, 0xd7, 0x13, 0xf9, 0x65,
1115     0x82, 0xf5, 0x42, 0xec, 0x9f, 0x5d, 0x51, 0x5a, 0x7b, 0xf2, 0x39, 0xbb,
1116     0xa6, 0x19, 0x5c, 0x73, 0x95, 0x65, 0x5b, 0x64, 0x2f, 0xda, 0x50, 0xd0,
1117     0x02, 0x34, 0x3f, 0x35, 0xc1, 0xd6, 0x31, 0x3b, 0xcf, 0x3f, 0x81, 0x8d,
1118     0xe0, 0x40, 0xfd, 0x6d, 0x32, 0x68, 0xa4, 0xf2, 0x4e, 0x3a, 0x4a, 0x42,
1119     0x2c, 0x07, 0x2d, 0x27, 0xa3, 0x34, 0xe7, 0x27, 0x87, 0x80, 0x76, 0xc0,
1120     0xa0, 0x72, 0x05, 0xf2, 0x88, 0x81, 0xe3, 0x32, 0x00, 0x76, 0x8d, 0x24,
1121     0x5c, 0x97, 0x2d, 0xd6, 0xb8, 0x34, 0xf8, 0x1c, 0x1a, 0x6d, 0xc7, 0x3f,
1122     0xcf, 0x56, 0xae, 0xec, 0x26, 0x74, 0x53, 0x69, 0xcd, 0x7a, 0x97, 0x29,
1123     0xab, 0x12, 0x7d, 0x75, 0xf8, 0x8d, 0x5b, 0xc0, 0x77, 0x20, 0xb6, 0x6a,
1124     0x0b, 0xce, 0x98, 0x50, 0xca, 0x47, 0x42, 0x1e, 0x5d, 0xc3, 0x24, 0x5a,
1125     0x47, 0x48, 0x3b, 0xa0, 0x9e, 0x43, 0xe9, 0x8d, 0x18, 0x23, 0xda, 0x6f,
1126     0x8c, 0xda, 0xd0, 0x3e, 0xdb, 0x37, 0xff, 0xfc, 0x7e, 0x17, 0xbe, 0x42,
1127     0xfd, 0xdb, 0x51, 0xb1, 0xa4, 0xfd, 0x9a, 0x20, 0x27, 0x24, 0x17, 0x04,
1128     0x70, 0xb6, 0x21, 0x87, 0x88, 0xe9, 0xda, 0x63, 0xcb, 0xcb, 0x1d, 0xaf,
1129     0x4a, 0x46, 0x76, 0x88, 0xa1, 0xf8, 0x48, 0x6c, 0x06, 0xb4, 0x62, 0x1a,
1130     0x67, 0x18, 0xb0, 0x1d, 0x58, 0x6a, 0xfe, 0x1f, 0xf1, 0x48, 0xff, 0xcb,
1131     0xa4, 0xd1, 0xa8, 0x12, 0x1f, 0x45, 0x94, 0x2f, 0x55, 0x80, 0x6a, 0x06,
1132     0xcc, 0x7b, 0xb0, 0xcc, 0xb8, 0x06, 0x52, 0x16, 0xe3, 0x6e, 0x7e, 0xb0,
1133     0x42, 0xfd, 0x3b, 0x7e, 0x0a, 0x42, 0x7b, 0x73, 0xaf, 0x2c, 0xf3, 0xbd,
1134     0xe5, 0x72, 0x8c, 0x16, 0xb2, 0xd7, 0x7a, 0x11, 0xb6, 0x9f, 0xd1, 0x69,
1135     0xc1, 0x1a, 0xe0, 0x26, 0x26, 0x13, 0xe2, 0x75, 0xf5, 0x74, 0xae, 0x3f,
1136     0xee, 0x1e, 0x09, 0x63, 0x5a, 0x30, 0x19, 0xa5, 0x59, 0x48, 0x90, 0x9b,
1137     0x46, 0x56, 0xd8, 0x6f, 0x6b, 0x76, 0x82, 0x32, 0xc7, 0x29, 0x76, 0x2e,
1138     0x32, 0xb6, 0x23, 0x99, 0xeb, 0x92, 0x5d, 0xc4, 0x4c, 0xa1, 0xe9, 0x26,
1139     0x37, 0x9a, 0x7d, 0x4c, 0x16, 0x9c, 0x18, 0xe9, 0xc0, 0xff, 0x48, 0x79,
1140     0xb1, 0x7b, 0x0b, 0x1e, 0x6f, 0xb1, 0x77, 0xa5, 0xd2, 0xc6, 0x9a, 0xa9,
1141     0xfc, 0xd1, 0x0f, 0x69, 0xf3, 0xe0, 0x49, 0x70, 0x57, 0x80, 0x86, 0xa7,
1142     0x3f, 0x54, 0xa8, 0x60, 0xfb, 0xe4, 0x06, 0xa3, 0x13, 0xb9, 0x2f, 0xa7,
1143     0x37, 0x80, 0x0c, 0x43, 0xac, 0x2f, 0xae, 0x6e, 0x62, 0x2b, 0x53, 0xe4,
1144     0xfe, 0x58, 0xd7, 0x8b, 0x96, 0xdc, 0xe6, 0xd3, 0x86, 0xb8, 0xd6, 0x42,
1145     0x5b, 0x68, 0x03, 0x48, 0x3f, 0xcd, 0xee, 0x39, 0x8b, 0xc4, 0x53, 0x30,
1146     0x87, 0x48, 0x2a, 0x01, 0x9d, 0x6f, 0x8e, 0x36, 0x75, 0x73, 0xef, 0x77,
1147     0x3a, 0x82, 0xd8, 0x4c, 0x0e, 0x7f, 0xb3, 0x8f, 0x16, 0xd1, 0x10, 0xcf,
1148     0x2f, 0xa3, 0xdf, 0x65, 0xba, 0x91, 0x79, 0xf6, 0x93, 0x60, 0x08, 0xe5,
1149     0xdb, 0x73, 0x02, 0x7a, 0x0b, 0x0e, 0xcc, 0x3b, 0x1f, 0x08, 0x2d, 0x51,
1150     0x3e, 0x87, 0x48, 0xd3, 0xd3, 0x75, 0xc2, 0x28, 0xa3, 0xf3, 0x02, 0xde,
1151     0x8f, 0xa6, 0xbd, 0xb3, 0x19, 0xa0, 0xdb, 0x48, 0x51, 0x03, 0x5f, 0x98,
1152     0xbe,
1153
1154     /* Third Packet: 1-RTT */
1155     0x5c,               /* Short, 1-RTT, Spin=0, KP=0, PN Length=2 bytes */
1156     0x4f, 0x33,         /* PN (0) */
1157     0x16, 0x75, 0x98, 0x67, 0x04, 0x16, 0x61, 0xe3, 0x00, 0xb7, 0x9d, 0x5c,
1158     0x53, 0x4c, 0x26, 0x90, 0x92, 0x8e, 0x0e, 0xc0, 0x9c, 0x6d, 0x8b, 0xac,
1159     0x15, 0x6d, 0x89, 0x74, 0x2f, 0xe7, 0x84, 0xe3, 0x46, 0x46, 0x8c, 0xc1,
1160     0x21, 0x7c, 0x44, 0xa5, 0x00, 0x29, 0xca, 0xf2, 0x11, 0x18, 0xe0, 0x04,
1161     0x40, 0x55, 0xd2, 0xa7, 0xe5, 0x9d, 0x22, 0xa2, 0x2a, 0x6c, 0x03, 0x87,
1162     0xa3, 0xa3, 0xfa, 0xf5, 0x6c, 0xd7, 0x7d, 0xae, 0x3f, 0x28, 0x01, 0xae,
1163     0x06, 0x11, 0x69, 0x67, 0x90, 0x57, 0x5a, 0xd0, 0xeb, 0xdd, 0xac, 0xbd,
1164     0x7f, 0x33, 0x86, 0xbb,
1165 };
1166
1167 static const QUIC_PKT_HDR rx_script_7a_expect_hdr = {
1168     QUIC_PKT_TYPE_INITIAL,
1169     0,          /* Spin Bit */
1170     0,          /* Key Phase */
1171     2,          /* PN Length */
1172     0,          /* Partial */
1173     1,          /* Fixed */
1174     0,          /* Unused */
1175     0,          /* Reserved */
1176     1,          /* Version */
1177     {0, {0}},                           /* DCID */
1178     {4, {0x03, 0x45, 0x0c, 0x7a}},      /* SCID */
1179     {0},        /* PN */
1180     NULL, 0,    /* Token/Token Len */
1181     441, NULL
1182 };
1183
1184 static const unsigned char rx_script_7a_body[] = {
1185     0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1186     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1187     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1188     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1189     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1190     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1191     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1192     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1193     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1194     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1195     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1196     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1197     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1198     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1199     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1200     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1201     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1202     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1203     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1204     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1205     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1206     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1207     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1208     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1209     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1210     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1211     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1212     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1213     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
1214     0x00, 0x40, 0x5a, 0x02, 0x00, 0x00, 0x56, 0x03, 0x03, 0xd5, 0xfb, 0x6a,
1215     0x81, 0x1c, 0xdb, 0xa2, 0x5c, 0x11, 0x31, 0xda, 0x15, 0x28, 0x97, 0x94,
1216     0x83, 0xfd, 0x9d, 0x91, 0x0e, 0x87, 0x71, 0x46, 0x64, 0xb4, 0xd9, 0x9e,
1217     0xbd, 0xa8, 0x48, 0x32, 0xbf, 0x00, 0x13, 0x03, 0x00, 0x00, 0x2e, 0x00,
1218     0x2b, 0x00, 0x02, 0x03, 0x04, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00,
1219     0x20, 0xef, 0xbb, 0x46, 0xe9, 0xb4, 0xf6, 0x54, 0xc4, 0x07, 0x71, 0xdc,
1220     0x50, 0xd5, 0x69, 0x40, 0xbc, 0x85, 0x7f, 0xf9, 0x48, 0x14, 0xe3, 0xd6,
1221     0x08, 0xa9, 0x0b, 0xfd, 0xbe, 0xf1, 0x57, 0x21, 0x34,
1222 };
1223
1224 static const QUIC_PKT_HDR rx_script_7b_expect_hdr = {
1225     QUIC_PKT_TYPE_HANDSHAKE,
1226     0,          /* Spin Bit */
1227     0,          /* Key Phase */
1228     2,          /* PN Length */
1229     0,          /* Partial */
1230     1,          /* Fixed */
1231     0,          /* Unused */
1232     0,          /* Reserved */
1233     1,          /* Version */
1234     {0, {0}},                           /* DCID */
1235     {4, {0x03, 0x45, 0x0c, 0x7a}},      /* SCID */
1236     {0},        /* PN */
1237     NULL, 0,    /* Token/Token Len */
1238     657, NULL
1239 };
1240
1241 static const unsigned char rx_script_7b_body[] = {
1242     0x06, 0x00, 0x42, 0x8d, 0x08, 0x00, 0x00, 0x82, 0x00, 0x80, 0x00, 0x10,
1243     0x00, 0x08, 0x00, 0x06, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x00, 0x39,
1244     0x00, 0x70, 0x46, 0x0a, 0x0d, 0xdc, 0x59, 0xf0, 0x4e, 0xb2, 0x2c, 0xac,
1245     0x69, 0x6a, 0xc9, 0x77, 0xa9, 0x99, 0x05, 0x04, 0x80, 0x08, 0x00, 0x00,
1246     0x06, 0x04, 0x80, 0x08, 0x00, 0x00, 0x07, 0x04, 0x80, 0x08, 0x00, 0x00,
1247     0x04, 0x04, 0x80, 0x0c, 0x00, 0x00, 0x08, 0x02, 0x40, 0x64, 0x09, 0x02,
1248     0x40, 0x64, 0x01, 0x04, 0x80, 0x00, 0x75, 0x30, 0x03, 0x02, 0x45, 0xac,
1249     0x0b, 0x01, 0x1a, 0x0c, 0x00, 0x02, 0x10, 0x42, 0xf0, 0xed, 0x09, 0x07,
1250     0x5b, 0xd9, 0x5a, 0xb2, 0x39, 0x5d, 0x73, 0x2c, 0x57, 0x1f, 0x50, 0x00,
1251     0x0b, 0xe0, 0x3e, 0xf3, 0xd6, 0x91, 0x6f, 0x9c, 0xcc, 0x31, 0xf7, 0xa5,
1252     0x0e, 0x01, 0x04, 0x0f, 0x04, 0x03, 0x45, 0x0c, 0x7a, 0x10, 0x04, 0xfa,
1253     0x5d, 0xd6, 0x80, 0x20, 0x01, 0x00, 0x0b, 0x00, 0x01, 0x8f, 0x00, 0x00,
1254     0x01, 0x8b, 0x00, 0x01, 0x86, 0x30, 0x82, 0x01, 0x82, 0x30, 0x82, 0x01,
1255     0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x0a, 0x73, 0x0f, 0x86,
1256     0x18, 0xf2, 0xc3, 0x30, 0x01, 0xd2, 0xc0, 0xc1, 0x62, 0x52, 0x13, 0xf1,
1257     0x9c, 0x13, 0x39, 0xb5, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
1258     0x3d, 0x04, 0x03, 0x02, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03,
1259     0x55, 0x04, 0x03, 0x0c, 0x0c, 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e,
1260     0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30,
1261     0x38, 0x30, 0x32, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x17, 0x0d,
1262     0x32, 0x32, 0x30, 0x39, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38,
1263     0x5a, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03,
1264     0x0c, 0x0c, 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63,
1265     0x61, 0x6c, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
1266     0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01,
1267     0x07, 0x03, 0x42, 0x00, 0x04, 0x67, 0xf4, 0xd3, 0x8f, 0x15, 0x6d, 0xee,
1268     0x85, 0xcc, 0x2a, 0x77, 0xfc, 0x0b, 0x8f, 0x9f, 0xcf, 0xa9, 0x95, 0x5d,
1269     0x5b, 0xcd, 0xb7, 0x8b, 0xba, 0x31, 0x0a, 0x73, 0x62, 0xc5, 0xd0, 0x0e,
1270     0x07, 0x90, 0xae, 0x38, 0x43, 0x79, 0xce, 0x5e, 0x33, 0xad, 0x31, 0xbf,
1271     0x9f, 0x2a, 0x56, 0x83, 0xa5, 0x24, 0x16, 0xab, 0x0c, 0xf1, 0x64, 0xbe,
1272     0xe4, 0x93, 0xb5, 0x89, 0xd6, 0x05, 0xe4, 0xf7, 0x7b, 0xa3, 0x53, 0x30,
1273     0x51, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
1274     0x02, 0x64, 0x0f, 0x55, 0x69, 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9,
1275     0x1d, 0xa5, 0x5a, 0xd0, 0x48, 0x96, 0x9f, 0x60, 0x30, 0x1f, 0x06, 0x03,
1276     0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x02, 0x64, 0x0f,
1277     0x55, 0x69, 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a,
1278     0xd0, 0x48, 0x96, 0x9f, 0x60, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13,
1279     0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a,
1280     0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47,
1281     0x00, 0x30, 0x44, 0x02, 0x20, 0x0a, 0x82, 0x92, 0x6e, 0xd3, 0xc6, 0x66,
1282     0xd9, 0xd3, 0x75, 0xff, 0x71, 0x3b, 0x61, 0x46, 0x21, 0x00, 0xe6, 0x21,
1283     0x5d, 0x9c, 0x86, 0xe9, 0x65, 0x40, 0x4f, 0xeb, 0x70, 0x4f, 0x2c, 0xad,
1284     0x00, 0x02, 0x20, 0x08, 0xc2, 0x07, 0x5d, 0x16, 0xfc, 0x54, 0x34, 0x2b,
1285     0xb4, 0x18, 0x67, 0x44, 0x81, 0xc9, 0xa9, 0x67, 0x2e, 0xce, 0xa1, 0x02,
1286     0x9f, 0x3b, 0xe5, 0x61, 0x16, 0x0b, 0x50, 0xf6, 0xa1, 0x50, 0x94, 0x00,
1287     0x00, 0x0f, 0x00, 0x00, 0x4c, 0x04, 0x03, 0x00, 0x48, 0x30, 0x46, 0x02,
1288     0x21, 0x00, 0xaa, 0x18, 0x61, 0x93, 0xdf, 0xbb, 0x79, 0xe7, 0x34, 0x7e,
1289     0x2e, 0x61, 0x13, 0x8c, 0xa0, 0x33, 0xfb, 0x33, 0xca, 0xfc, 0xd2, 0x45,
1290     0xb0, 0xc7, 0x89, 0x3d, 0xf1, 0xd6, 0x54, 0x94, 0x05, 0xb6, 0x02, 0x21,
1291     0x00, 0xef, 0x6c, 0xb6, 0xf2, 0x00, 0xb2, 0x32, 0xb1, 0xf3, 0x3f, 0x59,
1292     0xf5, 0xc8, 0x18, 0xbe, 0x39, 0xbb, 0x27, 0xf8, 0x67, 0xac, 0xcb, 0x63,
1293     0xa4, 0x29, 0xfb, 0x8e, 0x88, 0x0f, 0xe5, 0xe9, 0x7e, 0x14, 0x00, 0x00,
1294     0x20, 0xfc, 0x2c, 0x4c, 0xa7, 0x77, 0x24, 0x79, 0x29, 0xa8, 0x82, 0x1a,
1295     0x4d, 0x58, 0x9d, 0x82, 0xe2, 0x09, 0x36, 0x63, 0x0e, 0x0b, 0x55, 0x51,
1296     0x80, 0x93, 0x40, 0xda, 0x41, 0x33, 0x08, 0x10, 0x2c,
1297 };
1298
1299 static const QUIC_PKT_HDR rx_script_7c_expect_hdr = {
1300     QUIC_PKT_TYPE_1RTT,
1301     0,          /* Spin Bit */
1302     0,          /* Key Phase */
1303     2,          /* PN Length */
1304     0,          /* Partial */
1305     1,          /* Fixed */
1306     0,          /* Unused */
1307     0,          /* Reserved */
1308     0,          /* Version */
1309     {0, {0}},                           /* DCID */
1310     {0, {0}},                           /* SCID */
1311     {0},        /* PN */
1312     NULL, 0,    /* Token/Token Len */
1313     72, NULL
1314 };
1315
1316 static const unsigned char rx_script_7c_body[] = {
1317     0x18, 0x03, 0x00, 0x04, 0xf7, 0x75, 0x72, 0xa2, 0xfd, 0x17, 0xd4, 0x82,
1318     0x8e, 0xe9, 0x5b, 0xce, 0xed, 0xec, 0x88, 0xb9, 0x73, 0xbf, 0x36, 0x9f,
1319     0x18, 0x02, 0x00, 0x04, 0x5f, 0x43, 0x96, 0xe4, 0x15, 0xdc, 0x56, 0x6b,
1320     0x67, 0x4c, 0x36, 0xb2, 0xe2, 0x77, 0xdc, 0x6e, 0xb9, 0x2c, 0x0d, 0x79,
1321     0x18, 0x01, 0x00, 0x04, 0xcb, 0x83, 0x4a, 0xf4, 0x8d, 0x7b, 0x69, 0x90,
1322     0xaf, 0x0d, 0xd2, 0x38, 0xa4, 0xf1, 0x94, 0xff, 0x63, 0x24, 0xd3, 0x7a,
1323 };
1324
1325 static const struct rx_test_op rx_script_7[] = {
1326     RX_OP_ALLOW_1RTT()
1327     RX_OP_SET_RX_DCID(empty_conn_id)
1328     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_7_c2s_init_dcid)
1329     RX_OP_INJECT_N(7)
1330     RX_OP_CHECK_PKT_N(7a)
1331     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
1332     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
1333                       QRL_SUITE_CHACHA20POLY1305, rx_script_7_handshake_secret)
1334     RX_OP_CHECK_PKT_N(7b)
1335     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
1336     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1337                       QRL_SUITE_CHACHA20POLY1305, rx_script_7_1rtt_secret)
1338     RX_OP_CHECK_PKT_N(7c)
1339     RX_OP_CHECK_NO_PKT()
1340
1341     /* Discard Initial EL and try injecting the packet again */
1342     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
1343     RX_OP_INJECT_N(7)
1344     /* Initial packet is not output because we have discarded Initial keys */
1345     RX_OP_CHECK_PKT_N(7b)
1346     RX_OP_CHECK_PKT_N(7c)
1347     RX_OP_CHECK_NO_PKT()
1348     /* Try again with discarded keys */
1349     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
1350     RX_OP_INJECT_N(7)
1351     RX_OP_CHECK_PKT_N(7c)
1352     RX_OP_CHECK_NO_PKT()
1353     /* Try again */
1354     RX_OP_INJECT_N(7)
1355     RX_OP_CHECK_PKT_N(7c)
1356     RX_OP_CHECK_NO_PKT()
1357     /* Try again with discarded 1-RTT keys */
1358     RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
1359     RX_OP_INJECT_N(7)
1360     RX_OP_CHECK_NO_PKT()
1361
1362     /* Recreate QRL, test reading packets received before key */
1363     RX_OP_SET_SCID_LEN(0)
1364     RX_OP_SET_RX_DCID(empty_conn_id)
1365     RX_OP_INJECT_N(7)
1366     RX_OP_CHECK_NO_PKT()
1367     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_7_c2s_init_dcid)
1368     RX_OP_CHECK_PKT_N(7a)
1369     RX_OP_CHECK_NO_PKT()
1370     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
1371                       QRL_SUITE_CHACHA20POLY1305, rx_script_7_handshake_secret)
1372     RX_OP_CHECK_PKT_N(7b)
1373     RX_OP_CHECK_NO_PKT()
1374     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1375                       QRL_SUITE_CHACHA20POLY1305, rx_script_7_1rtt_secret)
1376     RX_OP_CHECK_PKT_N(7c)
1377     RX_OP_CHECK_NO_PKT()
1378
1379     RX_OP_END
1380 };
1381 #endif /* !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) */
1382
1383 /*
1384  * 8. Real World - S2C Multiple Packets with Peer Initiated Key Phase Update
1385  */
1386 static const unsigned char rx_script_8_1rtt_secret[32] = {
1387     0x5f, 0x1f, 0x47, 0xea, 0xc3, 0xb2, 0xce, 0x73, 0xfb, 0xa2, 0x9f, 0xac,
1388     0xc3, 0xa0, 0xfe, 0x9b, 0xf3, 0xc0, 0xde, 0x5d, 0x33, 0x11, 0x1c, 0x70,
1389     0xdd, 0xb4, 0x06, 0xcc, 0xdf, 0x7d, 0xe9, 0x9a
1390 };
1391
1392 static const unsigned char rx_script_8a_in[] = {
1393     0x51,                           /* Short, 1-RTT, PN Length=2 bytes, KP=0 */
1394     0xcb, 0xf4,                     /* PN (4) */
1395     0x3f, 0x68, 0x7b, 0xa8, 0x2b, 0xb9, 0xfa, 0x7d, 0xe4, 0x6b, 0x20, 0x48,
1396     0xd1, 0x3c, 0xcb, 0x4b, 0xef, 0xb1, 0xfd, 0x5e, 0x1b, 0x19, 0x83, 0xa9,
1397     0x47, 0x62, 0xc1, 0x6e, 0xef, 0x27, 0xc3, 0x9b, 0x8f, 0x3f, 0xce, 0x11,
1398     0x68, 0xf5, 0x73, 0x0d, 0xf2, 0xdc, 0xe0, 0x28, 0x28, 0x79, 0xa6, 0x39,
1399     0xc3, 0xb9, 0xd3,
1400 };
1401
1402 static const QUIC_PKT_HDR rx_script_8a_expect_hdr = {
1403     QUIC_PKT_TYPE_1RTT,
1404     0,          /* Spin Bit */
1405     0,          /* Key Phase */
1406     2,          /* PN Length */
1407     0,          /* Partial */
1408     1,          /* Fixed */
1409     0,          /* Unused */
1410     0,          /* Reserved */
1411     0,          /* Version */
1412     {0, {0}},   /* DCID */
1413     {0, {0}},   /* SCID */
1414     {0, 4},     /* PN */
1415     NULL, 0,    /* Token/Token Len */
1416     35, NULL
1417 };
1418
1419 static const unsigned char rx_script_8a_body[] = {
1420     0x02, 0x03, 0x06, 0x00, 0x03, 0x0c, 0x00, 0x1b, 0x49, 0x27, 0x6d, 0x20,
1421     0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f, 0x6e,
1422     0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65
1423 };
1424
1425 static const unsigned char rx_script_8b_in[] = {
1426     0x52,                           /* Short, 1-RTT, PN Length=2 bytes, KP=1 */
1427     0x21, 0x8e,                     /* PN (5) */
1428     0xa2, 0x6a, 0x9c, 0x83, 0x24, 0x48, 0xae, 0x60, 0x1e, 0xc2, 0xa5, 0x91,
1429     0xfa, 0xe5, 0xf2, 0x05, 0x14, 0x37, 0x04, 0x6a, 0xa8, 0xae, 0x06, 0x58,
1430     0xd7, 0x85, 0x48, 0xd7, 0x3b, 0x85, 0x9e, 0x5a, 0xb3, 0x46, 0x89, 0x1b,
1431     0x4b, 0x6e, 0x1d, 0xd1, 0xfc, 0xb7, 0x47, 0xda, 0x6a, 0x64, 0x4b, 0x8e,
1432     0xf2, 0x69, 0x16,
1433 };
1434
1435 static const QUIC_PKT_HDR rx_script_8b_expect_hdr = {
1436     QUIC_PKT_TYPE_1RTT,
1437     0,          /* Spin Bit */
1438     1,          /* Key Phase */
1439     2,          /* PN Length */
1440     0,          /* Partial */
1441     1,          /* Fixed */
1442     0,          /* Unused */
1443     0,          /* Reserved */
1444     0,          /* Version */
1445     {0, {0}},   /* DCID */
1446     {0, {0}},   /* SCID */
1447     {0, 5},     /* PN */
1448     NULL, 0,    /* Token/Token Len */
1449     35, NULL
1450 };
1451
1452 static const unsigned char rx_script_8b_body[] = {
1453     0x02, 0x04, 0x03, 0x00, 0x00, 0x0c, 0x00, 0x36, 0x49, 0x27, 0x6d, 0x20,
1454     0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f, 0x6e,
1455     0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65,
1456 };
1457
1458 static const unsigned char rx_script_8c_in[] = {
1459     0x5b,                           /* Short, 1-RTT, PN Length=2 bytes, KP=0 */
1460     0x98, 0xd6,                     /* PN (3) */
1461     0x3c, 0x6f, 0x94, 0x20, 0x5e, 0xfc, 0x5b, 0x3a, 0x4a, 0x65, 0x1a, 0x9a,
1462     0x6c, 0x00, 0x52, 0xb6, 0x0c, 0x9b, 0x07, 0xf9, 0x6f, 0xbc, 0x3d, 0xb4,
1463     0x57, 0xe0, 0x15, 0x74, 0xfe, 0x76, 0xea, 0x1f, 0x23, 0xae, 0x22, 0x62,
1464     0xb7, 0x90, 0x94, 0x89, 0x38, 0x9b, 0x5b, 0x47, 0xed,
1465 };
1466
1467 static const QUIC_PKT_HDR rx_script_8c_expect_hdr = {
1468     QUIC_PKT_TYPE_1RTT,
1469     0,          /* Spin Bit */
1470     0,          /* Key Phase */
1471     2,          /* PN Length */
1472     0,          /* Partial */
1473     1,          /* Fixed */
1474     0,          /* Unused */
1475     0,          /* Reserved */
1476     0,          /* Version */
1477     {0, {0}},   /* DCID */
1478     {0, {0}},   /* SCID */
1479     {0, 3},     /* PN */
1480     NULL, 0,    /* Token/Token Len */
1481     29, NULL
1482 };
1483
1484 static const unsigned char rx_script_8c_body[] = {
1485     0x08, 0x00, 0x49, 0x27, 0x6d, 0x20, 0x68, 0x61, 0x76, 0x69, 0x6e, 0x67,
1486     0x20, 0x61, 0x20, 0x77, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6c,
1487     0x20, 0x74, 0x69, 0x6d, 0x65,
1488 };
1489
1490 static const unsigned char rx_script_8d_in[] = {
1491     0x55,                           /* Short, 1-RTT, PN Length=2 bytes, KP=1 */
1492     0x98, 0x20,                     /* PN (6) */
1493     0x45, 0x53, 0x05, 0x29, 0x30, 0x42, 0x29, 0x02, 0xf2, 0xa7, 0x27, 0xd6,
1494     0xb0, 0xb7, 0x30, 0xad, 0x45, 0xd8, 0x73, 0xd7, 0xe3, 0x65, 0xee, 0xd9,
1495     0x35, 0x33, 0x03, 0x3a, 0x35, 0x0b, 0x59, 0xa7, 0xbc, 0x23, 0x37, 0xc2,
1496     0x5e, 0x13, 0x88, 0x18, 0x79, 0x94, 0x6c, 0x15, 0xe3, 0x1f, 0x0d, 0xd1,
1497     0xc3, 0xfa, 0x40, 0xff,
1498 };
1499
1500 static const QUIC_PKT_HDR rx_script_8d_expect_hdr = {
1501     QUIC_PKT_TYPE_1RTT,
1502     0,          /* Spin Bit */
1503     1,          /* Key Phase */
1504     2,          /* PN Length */
1505     0,          /* Partial */
1506     1,          /* Fixed */
1507     0,          /* Unused */
1508     0,          /* Reserved */
1509     0,          /* Version */
1510     {0, {0}},   /* DCID */
1511     {0, {0}},   /* SCID */
1512     {0, 6},     /* PN */
1513     NULL, 0,    /* Token/Token Len */
1514     36, NULL
1515 };
1516
1517 static const unsigned char rx_script_8d_body[] = {
1518     0x02, 0x05, 0x03, 0x00, 0x00, 0x0c, 0x00, 0x40, 0x51, 0x49, 0x27, 0x6d,
1519     0x20, 0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f,
1520     0x6e, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65,
1521 };
1522
1523 static const unsigned char rx_script_8e_in[] = {
1524     0x55,                           /* Short, 1-RTTT, PN Length=2 bytes, KP=0 */
1525     0x76, 0x25,                     /* PN (10) */
1526     0x1c, 0x0d, 0x70, 0x4c, 0x2b, 0xc5, 0x7d, 0x7b, 0x77, 0x64, 0x03, 0x27,
1527     0xb3, 0x5d, 0x83, 0x9e, 0x35, 0x05, 0x10, 0xd2, 0xa4, 0x5c, 0x83, 0xd6,
1528     0x94, 0x12, 0x18, 0xc5, 0xb3, 0x0f, 0x0a, 0xb1, 0x8a, 0x82, 0x9f, 0xd6,
1529     0xa9, 0xab, 0x40, 0xc1, 0x05, 0xe8, 0x1b, 0x74, 0xaa, 0x8e, 0xd6, 0x8b,
1530     0xa5, 0xa3, 0x77, 0x79,
1531 };
1532
1533 static const QUIC_PKT_HDR rx_script_8e_expect_hdr = {
1534     QUIC_PKT_TYPE_1RTT,
1535     0,          /* Spin Bit */
1536     0,          /* Key Phase */
1537     2,          /* PN Length */
1538     0,          /* Partial */
1539     1,          /* Fixed */
1540     0,          /* Unused */
1541     0,          /* Reserved */
1542     0,          /* Version */
1543     {0, {0}},   /* DCID */
1544     {0, {0}},   /* SCID */
1545     {0, 10},    /* PN */
1546     NULL, 0,    /* Token/Token Len */
1547     36, NULL
1548 };
1549
1550 static const unsigned char rx_script_8e_body[] = {
1551     0x02, 0x09, 0x04, 0x00, 0x00, 0x0c, 0x00, 0x40, 0xbd, 0x49, 0x27, 0x6d,
1552     0x20, 0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f,
1553     0x6e, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65,
1554 };
1555
1556 static const unsigned char rx_script_8f_in[] = {
1557     0x48,                           /* Short, 1-RTT, PN Length=2 Bytes, KP=1 */
1558     0x4d, 0xf6,                     /* PN (15) */
1559     0x42, 0x86, 0xa1, 0xfa, 0x69, 0x6b, 0x1a, 0x45, 0xf2, 0xcd, 0xf6, 0x92,
1560     0xe1, 0xe6, 0x1a, 0x49, 0x37, 0xd7, 0x10, 0xae, 0x09, 0xbd
1561 };
1562
1563 static const QUIC_PKT_HDR rx_script_8f_expect_hdr = {
1564     QUIC_PKT_TYPE_1RTT,
1565     0,          /* Spin Bit */
1566     1,          /* Key Phase */
1567     2,          /* PN Length */
1568     0,          /* Partial */
1569     1,          /* Fixed */
1570     0,          /* Unused */
1571     0,          /* Reserved */
1572     0,          /* Version */
1573     {0, {0}},   /* DCID */
1574     {0, {0}},   /* SCID */
1575     {0, 15},    /* PN */
1576     NULL, 0,    /* Token/Token Len */
1577     6, NULL
1578 };
1579
1580 static const unsigned char rx_script_8f_body[] = {
1581     0x02, 0x0e, 0x4c, 0x54, 0x00, 0x02
1582 };
1583
1584 static const struct rx_test_op rx_script_8[] = {
1585     RX_OP_ALLOW_1RTT()
1586     RX_OP_SET_RX_DCID(empty_conn_id)
1587     /* Inject before we get the keys */
1588     RX_OP_INJECT_N(8a)
1589     /* Nothing yet */
1590     RX_OP_CHECK_NO_PKT()
1591     /* Provide keys */
1592     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1593                          QRL_SUITE_AES128GCM, rx_script_8_1rtt_secret)
1594     /* Now the injected packet is successfully returned */
1595     RX_OP_CHECK_PKT_N(8a)
1596     RX_OP_CHECK_NO_PKT()
1597     RX_OP_CHECK_KEY_EPOCH(0)
1598     RX_OP_CHECK_PKT_EPOCH(0)
1599
1600     /* Packet with new key phase */
1601     RX_OP_INJECT_N(8b)
1602     /* Packet is successfully decrypted and returned */
1603     RX_OP_CHECK_PKT_N(8b)
1604     RX_OP_CHECK_NO_PKT()
1605     /* Key epoch has increased */
1606     RX_OP_CHECK_KEY_EPOCH(1)
1607     RX_OP_CHECK_PKT_EPOCH(1)
1608
1609     /*
1610      * Now inject an old packet with the old keys (perhaps reordered in
1611      * network).
1612      */
1613     RX_OP_INJECT_N(8c)
1614     /* Should still be decrypted OK */
1615     RX_OP_CHECK_PKT_N(8c)
1616     RX_OP_CHECK_NO_PKT()
1617     /* Epoch has not changed */
1618     RX_OP_CHECK_KEY_EPOCH(1)
1619     RX_OP_CHECK_PKT_EPOCH(0)
1620
1621     /* Another packet with the new keys. */
1622     RX_OP_INJECT_N(8d)
1623     RX_OP_CHECK_PKT_N(8d)
1624     RX_OP_CHECK_NO_PKT()
1625     RX_OP_CHECK_KEY_EPOCH(1)
1626     RX_OP_CHECK_PKT_EPOCH(1)
1627
1628     /* We can inject the old packet multiple times and it still works */
1629     RX_OP_INJECT_N(8c)
1630     RX_OP_CHECK_PKT_N(8c)
1631     RX_OP_CHECK_NO_PKT()
1632     RX_OP_CHECK_KEY_EPOCH(1)
1633     RX_OP_CHECK_PKT_EPOCH(0)
1634
1635     /* Until we move from UPDATING to COOLDOWN */
1636     RX_OP_KEY_UPDATE_TIMEOUT(0)
1637     RX_OP_INJECT_N(8c)
1638     RX_OP_CHECK_NO_PKT()
1639     RX_OP_CHECK_KEY_EPOCH(1)
1640
1641     /*
1642      * Injecting a packet from the next epoch (epoch 2) while in COOLDOWN
1643      * doesn't work
1644      */
1645     RX_OP_INJECT_N(8e)
1646     RX_OP_CHECK_NO_PKT()
1647     RX_OP_CHECK_KEY_EPOCH(1)
1648
1649     /* Move from COOLDOWN to NORMAL and try again */
1650     RX_OP_KEY_UPDATE_TIMEOUT(1)
1651     RX_OP_INJECT_N(8e)
1652     RX_OP_CHECK_PKT_N(8e)
1653     RX_OP_CHECK_NO_PKT()
1654     RX_OP_CHECK_KEY_EPOCH(2)
1655     RX_OP_CHECK_PKT_EPOCH(2)
1656
1657     /* Can still receive old packet */
1658     RX_OP_INJECT_N(8d)
1659     RX_OP_CHECK_PKT_N(8d)
1660     RX_OP_CHECK_NO_PKT()
1661     RX_OP_CHECK_KEY_EPOCH(2)
1662     RX_OP_CHECK_PKT_EPOCH(1)
1663
1664     /* Move straight from UPDATING to NORMAL */
1665     RX_OP_KEY_UPDATE_TIMEOUT(1)
1666
1667     /* Try a packet from epoch 3 */
1668     RX_OP_INJECT_N(8f)
1669     RX_OP_CHECK_PKT_N(8f)
1670     RX_OP_CHECK_NO_PKT()
1671     RX_OP_CHECK_KEY_EPOCH(3)
1672     RX_OP_CHECK_PKT_EPOCH(3)
1673
1674     RX_OP_END
1675 };
1676
1677 /* 9. 1-RTT Deferral Test */
1678 static const struct rx_test_op rx_script_9[] = {
1679     RX_OP_SET_RX_DCID(empty_conn_id)
1680     RX_OP_PROVIDE_SECRET_INITIAL(rx_script_5_c2s_init_dcid)
1681     RX_OP_INJECT_N(5)
1682
1683     RX_OP_CHECK_PKT_N(5a)
1684     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
1685     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
1686                       QRL_SUITE_AES128GCM, rx_script_5_handshake_secret)
1687     RX_OP_CHECK_PKT_N(5b)
1688     RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
1689     RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1690                       QRL_SUITE_AES128GCM, rx_script_5_1rtt_secret)
1691     RX_OP_CHECK_NO_PKT() /* still nothing - 1-RTT not enabled */
1692     RX_OP_ALLOW_1RTT()
1693     RX_OP_CHECK_PKT_N(5c) /* now we get the 1-RTT packet */
1694     RX_OP_CHECK_NO_PKT()
1695
1696     RX_OP_END
1697 };
1698
1699 static const struct rx_test_op *rx_scripts[] = {
1700     rx_script_1,
1701 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1702     rx_script_2,
1703 #endif
1704     rx_script_3,
1705     rx_script_4,
1706     rx_script_5,
1707     rx_script_6,
1708 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1709     rx_script_7,
1710 #endif
1711     rx_script_8,
1712     rx_script_9
1713 };
1714
1715 struct rx_state {
1716     QUIC_DEMUX         *demux;
1717
1718     /* OSSL_QRX with necessary data */
1719     OSSL_QRX           *qrx;
1720     OSSL_QRX_ARGS       args;
1721
1722     /* Used for the RX depacketizer */
1723     SSL_CTX            *quic_ssl_ctx;
1724     QUIC_CONNECTION    *quic_conn;
1725
1726     QUIC_CONN_ID        rx_dcid;
1727
1728     int                 allow_1rtt;
1729 };
1730
1731 static void rx_state_teardown(struct rx_state *s)
1732 {
1733     if (s->quic_conn != NULL) {
1734         SSL_free((SSL *)s->quic_conn);
1735         s->quic_conn = NULL;
1736     }
1737     if (s->quic_ssl_ctx != NULL) {
1738         SSL_CTX_free(s->quic_ssl_ctx);
1739         s->quic_ssl_ctx = NULL;
1740     }
1741
1742     if (s->qrx != NULL) {
1743         ossl_qrx_free(s->qrx);
1744         s->qrx = NULL;
1745     }
1746
1747     if (s->demux != NULL) {
1748         ossl_quic_demux_free(s->demux);
1749         s->demux = NULL;
1750     }
1751 }
1752
1753 static uint64_t time_counter = 0;
1754
1755 static OSSL_TIME expected_time(uint64_t counter)
1756 {
1757     return ossl_time_multiply(ossl_ticks2time(OSSL_TIME_MS), counter);
1758 }
1759
1760 static OSSL_TIME fake_time(void *arg)
1761 {
1762     return expected_time(++time_counter);
1763 }
1764
1765 static void demux_default_handler(QUIC_URXE *e, void *arg,
1766                                   const QUIC_CONN_ID *dcid)
1767 {
1768     struct rx_state *s = arg;
1769
1770     if (dcid == NULL || !ossl_quic_conn_id_eq(dcid, &s->rx_dcid))
1771         return;
1772
1773     ossl_qrx_inject_urxe(s->qrx, e);
1774 }
1775
1776 static int rx_state_ensure(struct rx_state *s)
1777 {
1778     if (s->demux == NULL
1779         && !TEST_ptr(s->demux = ossl_quic_demux_new(NULL,
1780                                                     s->args.short_conn_id_len,
1781                                                     fake_time,
1782                                                     NULL)))
1783         return 0;
1784
1785     s->args.demux           = s->demux;
1786     s->args.max_deferred    = 32;
1787
1788     /* Initialise OSSL_QRX */
1789     if (s->qrx == NULL
1790         && !TEST_ptr(s->qrx = ossl_qrx_new(&s->args)))
1791         return 0;
1792
1793     ossl_quic_demux_set_default_handler(s->demux, demux_default_handler, s);
1794
1795     if (s->allow_1rtt)
1796         ossl_qrx_allow_1rtt_processing(s->qrx);
1797
1798     return 1;
1799 }
1800
1801 static int rx_run_script(const struct rx_test_op *script)
1802 {
1803     int testresult = 0;
1804     struct rx_state s = {0};
1805     size_t i;
1806     OSSL_QRX_PKT *pkt = NULL;
1807     const struct rx_test_op *op = script;
1808     uint64_t last_key_epoch = UINT64_MAX;
1809
1810     for (; op->op != RX_TEST_OP_END; ++op)
1811         switch (op->op) {
1812             case RX_TEST_OP_SET_SCID_LEN:
1813                 rx_state_teardown(&s);
1814                 s.args.short_conn_id_len = op->enc_level;
1815                 break;
1816             case RX_TEST_OP_SET_INIT_LARGEST_PN:
1817                 rx_state_teardown(&s);
1818                 for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
1819                     s.args.init_largest_pn[i] = op->largest_pn;
1820                 break;
1821             case RX_TEST_OP_SET_RX_DCID:
1822                 if (!TEST_true(rx_state_ensure(&s)))
1823                     goto err;
1824                 s.rx_dcid = *op->dcid;
1825                 break;
1826             case RX_TEST_OP_PROVIDE_SECRET:
1827                 if (!TEST_true(rx_state_ensure(&s)))
1828                     goto err;
1829                 if (!TEST_true(ossl_qrx_provide_secret(s.qrx, op->enc_level,
1830                                                        op->suite_id, NULL,
1831                                                        op->buf,
1832                                                        op->buf_len)))
1833                     goto err;
1834                 break;
1835             case RX_TEST_OP_PROVIDE_SECRET_INITIAL:
1836                 if (!TEST_true(rx_state_ensure(&s)))
1837                     goto err;
1838                 if (!TEST_true(ossl_quic_provide_initial_secret(NULL, NULL,
1839                                                                 op->dcid, 0,
1840                                                                 s.qrx, NULL)))
1841                     goto err;
1842                 break;
1843             case RX_TEST_OP_DISCARD_EL:
1844                 if (!TEST_true(rx_state_ensure(&s)))
1845                     goto err;
1846                 if (!TEST_true(ossl_qrx_discard_enc_level(s.qrx, op->enc_level)))
1847                     goto err;
1848                 break;
1849             case RX_TEST_OP_INJECT:
1850                 if (!TEST_true(rx_state_ensure(&s)))
1851                     goto err;
1852                 if (!TEST_true(ossl_quic_demux_inject(s.demux,
1853                                                       op->buf, op->buf_len,
1854                                                       NULL, NULL)))
1855                     goto err;
1856                 break;
1857             case RX_TEST_OP_CHECK_PKT:
1858                 if (!TEST_true(rx_state_ensure(&s)))
1859                     goto err;
1860
1861                 if (!TEST_true(ossl_qrx_read_pkt(s.qrx, &pkt)))
1862                     goto err;
1863
1864                 if (!TEST_ptr(pkt) || !TEST_ptr(pkt->hdr))
1865                     goto err;
1866
1867                 if (!TEST_mem_eq(pkt->hdr->data, pkt->hdr->len,
1868                                  op->buf, op->buf_len))
1869                     goto err;
1870
1871                 if (!TEST_true(cmp_pkt_hdr(pkt->hdr, op->hdr,
1872                                            op->buf, op->buf_len, 1)))
1873                     goto err;
1874
1875                 last_key_epoch = pkt->key_epoch;
1876
1877                 ossl_qrx_pkt_release(pkt);
1878                 pkt = NULL;
1879                 break;
1880             case RX_TEST_OP_CHECK_NO_PKT:
1881                 if (!TEST_true(rx_state_ensure(&s)))
1882                     goto err;
1883
1884                 if (!TEST_false(ossl_qrx_read_pkt(s.qrx, &pkt)))
1885                     goto err;
1886
1887                 break;
1888             case RX_TEST_OP_CHECK_KEY_EPOCH:
1889                 if (!TEST_true(rx_state_ensure(&s)))
1890                     goto err;
1891
1892                 if (!TEST_uint64_t_eq(ossl_qrx_get_key_epoch(s.qrx),
1893                                       op->largest_pn))
1894                     goto err;
1895
1896                 break;
1897             case RX_TEST_OP_CHECK_PKT_EPOCH:
1898                 if (!TEST_true(rx_state_ensure(&s)))
1899                     goto err;
1900
1901                 if (!TEST_uint64_t_eq(last_key_epoch, op->largest_pn))
1902                     goto err;
1903
1904                 break;
1905             case RX_TEST_OP_KEY_UPDATE_TIMEOUT:
1906                 if (!TEST_true(rx_state_ensure(&s)))
1907                     goto err;
1908
1909                 if (!TEST_true(ossl_qrx_key_update_timeout(s.qrx,
1910                                                            op->enc_level)))
1911                     goto err;
1912
1913                 break;
1914             case RX_TEST_OP_SET_INIT_KEY_PHASE:
1915                 rx_state_teardown(&s);
1916                 s.args.init_key_phase_bit = (unsigned char)op->enc_level;
1917                 break;
1918             case RX_TEST_OP_ALLOW_1RTT:
1919                 s.allow_1rtt = 1;
1920
1921                 if (!TEST_true(rx_state_ensure(&s)))
1922                     goto err;
1923
1924                 break;
1925             default:
1926                 OPENSSL_assert(0);
1927                 goto err;
1928         }
1929
1930     testresult = 1;
1931 err:
1932     ossl_qrx_pkt_release(pkt);
1933     rx_state_teardown(&s);
1934     return testresult;
1935 }
1936
1937 static int test_rx_script(int idx)
1938 {
1939     return rx_run_script(rx_scripts[idx]);
1940 }
1941
1942 /* Packet Header Tests */
1943 struct pkt_hdr_test {
1944     QUIC_PKT_HDR hdr;
1945     const unsigned char *expected;
1946     size_t expected_len;
1947     const unsigned char *payload;
1948     size_t payload_len;
1949     size_t short_conn_id_len;
1950     /*
1951      * Minimum number of bytes which should be required for a successful decode.
1952      * SIZE_MAX if should never decode successfully.
1953      */
1954     size_t min_success_len;
1955     size_t pn_offset, sample_offset;
1956 };
1957
1958 /* Packet Header Test 1: INITIAL With SCID */
1959 static const unsigned char pkt_hdr_test_1_expected[] = {
1960     0xc1,                     /* Long|Fixed, Type=Initial, PN Len=2 */
1961     0x00, 0x00, 0x00, 0x01,   /* Version */
1962     0x00,                     /* DCID Length */
1963     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1964     0x00,                     /* Token Length */
1965     0x15,                     /* Length=21 */
1966     0x33, 0x44,               /* Encoded PN */
1967     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1968     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1969     0x20, 0x21, 0x22
1970 };
1971
1972 static const unsigned char pkt_hdr_test_1_payload[] = {
1973     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1974     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1975     0x20, 0x21, 0x22
1976 };
1977
1978 static const struct pkt_hdr_test pkt_hdr_test_1 = {
1979     {
1980         QUIC_PKT_TYPE_INITIAL,  /* type */
1981         0,                      /* spin bit */
1982         0,                      /* key phase */
1983         2,                      /* PN length */
1984         0,                      /* partial */
1985         1,                      /* fixed */
1986         0,                      /* unused */
1987         0,                      /* reserved */
1988         1,                      /* version */
1989         { 0, {0} },             /* DCID */
1990         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1991         { 0x33, 0x44 },         /* PN */
1992         NULL, 0,                /* Token/Token Len */
1993         19, NULL                /* Len/Data */
1994     },
1995     pkt_hdr_test_1_expected, OSSL_NELEM(pkt_hdr_test_1_expected),
1996     pkt_hdr_test_1_payload,  OSSL_NELEM(pkt_hdr_test_1_payload),
1997     0, sizeof(pkt_hdr_test_1_expected),
1998     17, 21
1999 };
2000
2001 /* Packet Header Test 2: INITIAL With SCID and Token */
2002 static const unsigned char pkt_hdr_test_2_expected[] = {
2003     0xc1,                     /* Long|Fixed, Type=Initial, PN Len=2 */
2004     0x00, 0x00, 0x00, 0x01,   /* Version */
2005     0x00,                     /* DCID Length */
2006     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2007     0x07,                     /* Token Length */
2008     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
2009     0x15,                     /* Length=21 */
2010     0x33, 0x44,               /* Encoded PN */
2011     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2012     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2013     0x20, 0x21, 0x22
2014 };
2015
2016 static const unsigned char pkt_hdr_test_2_payload[] = {
2017     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2018     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2019     0x20, 0x21, 0x22
2020 };
2021
2022 static const unsigned char pkt_hdr_test_2_token[] = {
2023     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96
2024 };
2025
2026 static const struct pkt_hdr_test pkt_hdr_test_2 = {
2027     {
2028         QUIC_PKT_TYPE_INITIAL,  /* type */
2029         0,                      /* spin bit */
2030         0,                      /* key phase */
2031         2,                      /* PN length */
2032         0,                      /* partial */
2033         1,                      /* fixed */
2034         0,                      /* unused */
2035         0,                      /* reserved */
2036         1,                      /* version */
2037         { 0, {0} },             /* DCID */
2038         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2039         { 0x33, 0x44 },         /* PN */
2040         pkt_hdr_test_2_token, sizeof(pkt_hdr_test_2_token), /* Token */
2041         19, NULL                /* Len/Data */
2042     },
2043     pkt_hdr_test_2_expected, OSSL_NELEM(pkt_hdr_test_2_expected),
2044     pkt_hdr_test_2_payload,  OSSL_NELEM(pkt_hdr_test_2_payload),
2045     0, sizeof(pkt_hdr_test_2_expected),
2046     24, 28
2047 };
2048
2049 /* Packet Header Test 3: INITIAL With DCID and SCID and Token */
2050 static const unsigned char pkt_hdr_test_3_expected[] = {
2051     0xc1,                     /* Long|Fixed, Type=Initial, PN Len=2 */
2052     0x00, 0x00, 0x00, 0x01,   /* Version */
2053     0x03,                     /* DCID Length */
2054     0x70, 0x71, 0x72,         /* DCID */
2055     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2056     0x06,                     /* Token Length */
2057     0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
2058     0x15,                     /* Length=21 */
2059     0x33, 0x44,               /* Encoded PN */
2060     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2061     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2062     0x20, 0x21, 0x22
2063 };
2064
2065 static const unsigned char pkt_hdr_test_3_payload[] = {
2066     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2067     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2068     0x20, 0x21, 0x22
2069 };
2070
2071 static const unsigned char pkt_hdr_test_3_token[] = {
2072     0x91, 0x92, 0x93, 0x94, 0x95, 0x96
2073 };
2074
2075 static const struct pkt_hdr_test pkt_hdr_test_3 = {
2076     {
2077         QUIC_PKT_TYPE_INITIAL,  /* type */
2078         0,                      /* spin bit */
2079         0,                      /* key phase */
2080         2,                      /* PN length */
2081         0,                      /* partial */
2082         1,                      /* fixed */
2083         0,                      /* unused */
2084         0,                      /* reserved */
2085         1,                      /* version */
2086         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2087         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2088         { 0x33, 0x44 },         /* PN */
2089         pkt_hdr_test_3_token, sizeof(pkt_hdr_test_3_token), /* Token */
2090         19, NULL                /* Len/Data */
2091     },
2092     pkt_hdr_test_3_expected, OSSL_NELEM(pkt_hdr_test_3_expected),
2093     pkt_hdr_test_3_payload,  OSSL_NELEM(pkt_hdr_test_3_payload),
2094     0, sizeof(pkt_hdr_test_3_expected),
2095     26, 30
2096 };
2097
2098 /* Packet Header Test 4: 0-RTT */
2099 static const unsigned char pkt_hdr_test_4_expected[] = {
2100     0xd0,                     /* Long|Fixed, Type=0-RTT, PN Len=1 */
2101     0x00, 0x00, 0x00, 0x01,   /* Version */
2102     0x03,                     /* DCID Length */
2103     0x70, 0x71, 0x72,         /* DCID */
2104     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2105     0x14,                     /* Length=20 */
2106     0x33,                     /* Encoded PN */
2107     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2108     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2109     0x20, 0x21, 0x22
2110 };
2111
2112 static const unsigned char pkt_hdr_test_4_payload[] = {
2113     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2114     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2115     0x20, 0x21, 0x22
2116 };
2117
2118 static const struct pkt_hdr_test pkt_hdr_test_4 = {
2119     {
2120         QUIC_PKT_TYPE_0RTT,     /* type */
2121         0,                      /* spin bit */
2122         0,                      /* key phase */
2123         1,                      /* PN length */
2124         0,                      /* partial */
2125         1,                      /* fixed */
2126         0,                      /* unused */
2127         0,                      /* reserved */
2128         1,                      /* version */
2129         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2130         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2131         { 0x33 },               /* PN */
2132         NULL, 0,                /* Token */
2133         19, NULL                /* Len/Data */
2134     },
2135     pkt_hdr_test_4_expected, OSSL_NELEM(pkt_hdr_test_4_expected),
2136     pkt_hdr_test_4_payload,  OSSL_NELEM(pkt_hdr_test_4_payload),
2137     0, sizeof(pkt_hdr_test_4_expected),
2138     19, 23
2139 };
2140
2141 /* Packet Header Test 5: Handshake */
2142 static const unsigned char pkt_hdr_test_5_expected[] = {
2143     0xe0,                     /* Long|Fixed, Type=Handshake, PN Len=1 */
2144     0x00, 0x00, 0x00, 0x01,   /* Version */
2145     0x03,                     /* DCID Length */
2146     0x70, 0x71, 0x72,         /* DCID */
2147     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2148     0x14,                     /* Length=20 */
2149     0x33,                     /* Encoded PN */
2150     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2151     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2152     0x20, 0x21, 0x22
2153 };
2154
2155 static const unsigned char pkt_hdr_test_5_payload[] = {
2156     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2157     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2158     0x20, 0x21, 0x22
2159 };
2160
2161 static const struct pkt_hdr_test pkt_hdr_test_5 = {
2162     {
2163         QUIC_PKT_TYPE_HANDSHAKE,    /* type */
2164         0,                          /* spin bit */
2165         0,                          /* key phase */
2166         1,                          /* PN length */
2167         0,                          /* partial */
2168         1,                          /* fixed */
2169         0,                          /* unused */
2170         0,                          /* reserved */
2171         1,                          /* version */
2172         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2173         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2174         { 0x33 },                   /* PN */
2175         NULL, 0,                    /* Token */
2176         19, NULL                    /* Len/Data */
2177     },
2178     pkt_hdr_test_5_expected, OSSL_NELEM(pkt_hdr_test_5_expected),
2179     pkt_hdr_test_5_payload,  OSSL_NELEM(pkt_hdr_test_5_payload),
2180     0, sizeof(pkt_hdr_test_5_expected),
2181     19, 23
2182 };
2183
2184 /* Packet Header Test 6: Retry */
2185 static const unsigned char pkt_hdr_test_6_expected[] = {
2186     0xf0,                     /* Long|Fixed, Type=Retry */
2187     0x00, 0x00, 0x00, 0x01,   /* Version */
2188     0x03,                     /* DCID Length */
2189     0x70, 0x71, 0x72,         /* DCID */
2190     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2191     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,       /* Retry Token */
2192     0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
2193     0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f              /* Retry Integrity Tag */
2194 };
2195
2196 static const unsigned char pkt_hdr_test_6_payload[] = {
2197     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,       /* Retry Token */
2198     0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
2199     0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f              /* Retry Integrity Tag */
2200 };
2201
2202 static const struct pkt_hdr_test pkt_hdr_test_6 = {
2203     {
2204         QUIC_PKT_TYPE_RETRY,        /* type */
2205         0,                          /* spin bit */
2206         0,                          /* key phase */
2207         0,                          /* PN length */
2208         0,                          /* partial */
2209         1,                          /* fixed */
2210         0,                          /* unused */
2211         0,                          /* reserved */
2212         1,                          /* version */
2213         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2214         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2215         { 0 },                      /* PN */
2216         NULL, 0,                    /* Token */
2217         24, NULL                    /* Len/Data */
2218     },
2219     pkt_hdr_test_6_expected, OSSL_NELEM(pkt_hdr_test_6_expected),
2220     pkt_hdr_test_6_payload,  OSSL_NELEM(pkt_hdr_test_6_payload),
2221     0, 21,
2222     SIZE_MAX, SIZE_MAX
2223 };
2224
2225 /* Packet Header Test 7: 1-RTT */
2226 static const unsigned char pkt_hdr_test_7_expected[] = {
2227     0x42,                     /* Short|Fixed, Type=1-RTT, PN Len=3 */
2228     0x70, 0x71, 0x72,         /* DCID */
2229     0x50, 0x51, 0x52,         /* PN */
2230     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2231     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2232 };
2233
2234 static const unsigned char pkt_hdr_test_7_payload[] = {
2235     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2236     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2237 };
2238
2239 static const struct pkt_hdr_test pkt_hdr_test_7 = {
2240     {
2241         QUIC_PKT_TYPE_1RTT,         /* type */
2242         0,                          /* spin bit */
2243         0,                          /* key phase */
2244         3,                          /* PN length */
2245         0,                          /* partial */
2246         1,                          /* fixed */
2247         0,                          /* unused */
2248         0,                          /* reserved */
2249         0,                          /* version */
2250         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2251         { 0, {0} },                 /* SCID */
2252         { 0x50, 0x51, 0x52 },       /* PN */
2253         NULL, 0,                    /* Token */
2254         18, NULL                    /* Len/Data */
2255     },
2256     pkt_hdr_test_7_expected, OSSL_NELEM(pkt_hdr_test_7_expected),
2257     pkt_hdr_test_7_payload,  OSSL_NELEM(pkt_hdr_test_7_payload),
2258     3, 21,
2259     4, 8
2260 };
2261
2262 /* Packet Header Test 8: 1-RTT with Spin Bit */
2263 static const unsigned char pkt_hdr_test_8_expected[] = {
2264     0x62,                     /* Short|Fixed, Type=1-RTT, PN Len=3, Spin=1 */
2265     0x70, 0x71, 0x72,         /* DCID */
2266     0x50, 0x51, 0x52,         /* PN */
2267     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2268     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2269 };
2270
2271 static const unsigned char pkt_hdr_test_8_payload[] = {
2272     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2273     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2274 };
2275
2276 static const struct pkt_hdr_test pkt_hdr_test_8 = {
2277     {
2278         QUIC_PKT_TYPE_1RTT,         /* type */
2279         1,                          /* spin bit */
2280         0,                          /* key phase */
2281         3,                          /* PN length */
2282         0,                          /* partial */
2283         1,                          /* fixed */
2284         0,                          /* unused */
2285         0,                          /* reserved */
2286         0,                          /* version */
2287         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2288         { 0, {0} },                 /* SCID */
2289         { 0x50, 0x51, 0x52 },       /* PN */
2290         NULL, 0,                    /* Token */
2291         18, NULL                    /* Len/Data */
2292     },
2293     pkt_hdr_test_8_expected, OSSL_NELEM(pkt_hdr_test_8_expected),
2294     pkt_hdr_test_8_payload,  OSSL_NELEM(pkt_hdr_test_8_payload),
2295     3, 21,
2296     4, 8
2297 };
2298
2299 /* Packet Header Test 9: 1-RTT with Key Phase Bit */
2300 static const unsigned char pkt_hdr_test_9_expected[] = {
2301     0x46,                     /* Short|Fixed, Type=1-RTT, PN Len=3, Key Phase=1 */
2302     0x70, 0x71, 0x72,         /* DCID */
2303     0x50, 0x51, 0x52,         /* PN */
2304     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2305     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2306 };
2307
2308 static const unsigned char pkt_hdr_test_9_payload[] = {
2309     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2310     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2311 };
2312
2313 static const struct pkt_hdr_test pkt_hdr_test_9 = {
2314     {
2315         QUIC_PKT_TYPE_1RTT,         /* type */
2316         0,                          /* spin bit */
2317         1,                          /* key phase */
2318         3,                          /* PN length */
2319         0,                          /* partial */
2320         1,                          /* fixed */
2321         0,                          /* unused */
2322         0,                          /* reserved */
2323         0,                          /* version */
2324         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2325         { 0, {0} },                 /* SCID */
2326         { 0x50, 0x51, 0x52 },       /* PN */
2327         NULL, 0,                    /* Token */
2328         18, NULL                    /* Len/Data */
2329     },
2330     pkt_hdr_test_9_expected, OSSL_NELEM(pkt_hdr_test_9_expected),
2331     pkt_hdr_test_9_payload,  OSSL_NELEM(pkt_hdr_test_9_payload),
2332     3, 21,
2333     4, 8
2334 };
2335
2336 /* Packet Header Test 10: Handshake with 4-Byte PN */
2337 static const unsigned char pkt_hdr_test_10_expected[] = {
2338     0xe3,                     /* Long|Fixed, Type=Handshake, PN Len=4 */
2339     0x00, 0x00, 0x00, 0x01,   /* Version */
2340     0x03,                     /* DCID Length */
2341     0x70, 0x71, 0x72,         /* DCID */
2342     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2343     0x17,                     /* Length=20 */
2344     0x33, 0x44, 0x55, 0x66,   /* Encoded PN */
2345     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2346     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2347     0x20, 0x21, 0x22
2348 };
2349
2350 static const unsigned char pkt_hdr_test_10_payload[] = {
2351     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2352     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2353     0x20, 0x21, 0x22
2354 };
2355
2356 static const struct pkt_hdr_test pkt_hdr_test_10 = {
2357     {
2358         QUIC_PKT_TYPE_HANDSHAKE,    /* type */
2359         0,                          /* spin bit */
2360         0,                          /* key phase */
2361         4,                          /* PN length */
2362         0,                          /* partial */
2363         1,                          /* fixed */
2364         0,                          /* unused */
2365         0,                          /* reserved */
2366         1,                          /* version */
2367         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2368         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2369         { 0x33, 0x44, 0x55, 0x66 }, /* PN */
2370         NULL, 0,                    /* Token */
2371         19, NULL                    /* Len/Data */
2372     },
2373     pkt_hdr_test_10_expected, OSSL_NELEM(pkt_hdr_test_10_expected),
2374     pkt_hdr_test_10_payload,  OSSL_NELEM(pkt_hdr_test_10_payload),
2375     0, sizeof(pkt_hdr_test_10_expected),
2376     19, 23
2377 };
2378
2379 /* Packet Header Test 11: 1-RTT with 4-Byte PN */
2380 static const unsigned char pkt_hdr_test_11_expected[] = {
2381     0x43,                     /* Short|Fixed, Type=1-RTT, PN Len=4 */
2382     0x70, 0x71, 0x72,         /* DCID */
2383     0x50, 0x51, 0x52, 0x53,   /* PN */
2384     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2385     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2386 };
2387
2388 static const unsigned char pkt_hdr_test_11_payload[] = {
2389     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2390     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2391 };
2392
2393 static const struct pkt_hdr_test pkt_hdr_test_11 = {
2394     {
2395         QUIC_PKT_TYPE_1RTT,         /* type */
2396         0,                          /* spin bit */
2397         0,                          /* key phase */
2398         4,                          /* PN length */
2399         0,                          /* partial */
2400         1,                          /* fixed */
2401         0,                          /* unused */
2402         0,                          /* reserved */
2403         0,                          /* version */
2404         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2405         { 0, {0} },                 /* SCID */
2406         { 0x50, 0x51, 0x52, 0x53 }, /* PN */
2407         NULL, 0,                    /* Token */
2408         18, NULL                    /* Len/Data */
2409     },
2410     pkt_hdr_test_11_expected, OSSL_NELEM(pkt_hdr_test_11_expected),
2411     pkt_hdr_test_11_payload,  OSSL_NELEM(pkt_hdr_test_11_payload),
2412     3, 21,
2413     4, 8
2414 };
2415
2416 /* Packet Header Test 12: Version Negotiation */
2417 static const unsigned char pkt_hdr_test_12_expected[] = {
2418     0xc0,                       /* Long|Fixed, Type=Version Neg */
2419     0x00, 0x00, 0x00, 0x00,     /* Version (0) */
2420     0x03, 0x70, 0x71, 0x72,     /* DCID */
2421     0x02, 0x81, 0x82,           /* SCID */
2422     0x11, 0x22, 0x33, 0x44      /* One Version */
2423 };
2424
2425 static const unsigned char pkt_hdr_test_12_payload[] = {
2426     0x11, 0x22, 0x33, 0x44
2427 };
2428
2429 static const struct pkt_hdr_test pkt_hdr_test_12 = {
2430     {
2431         QUIC_PKT_TYPE_VERSION_NEG,  /* type */
2432         0,                          /* spin bit */
2433         0,                          /* key phase */
2434         0,                          /* PN length */
2435         0,                          /* partial */
2436         1,                          /* fixed */
2437         0,                          /* unused */
2438         0,                          /* reserved */
2439         0,                          /* version */
2440         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2441         { 2, {0x81, 0x82} },        /* SCID */
2442         { 0 },                      /* PN */
2443         NULL, 0,                    /* Token */
2444         4, NULL                     /* Len/Data */
2445     },
2446     pkt_hdr_test_12_expected, OSSL_NELEM(pkt_hdr_test_12_expected),
2447     pkt_hdr_test_12_payload,  OSSL_NELEM(pkt_hdr_test_12_payload),
2448     0, 12,
2449     SIZE_MAX, SIZE_MAX
2450 };
2451
2452 /* Packet Header Test 13: Version Negotiation without Fixed Bit */
2453 static const unsigned char pkt_hdr_test_13_expected[] = {
2454     0x80,                       /* Long|Fixed, Type=Version Neg */
2455     0x00, 0x00, 0x00, 0x00,     /* Version (0) */
2456     0x03, 0x70, 0x71, 0x72,     /* DCID */
2457     0x02, 0x81, 0x82,           /* SCID */
2458     0x11, 0x22, 0x33, 0x44      /* One Version */
2459 };
2460
2461 static const unsigned char pkt_hdr_test_13_payload[] = {
2462     0x11, 0x22, 0x33, 0x44
2463 };
2464
2465 static const struct pkt_hdr_test pkt_hdr_test_13 = {
2466     {
2467         QUIC_PKT_TYPE_VERSION_NEG,  /* type */
2468         0,                          /* spin bit */
2469         0,                          /* key phase */
2470         0,                          /* PN length */
2471         0,                          /* partial */
2472         0,                          /* fixed */
2473         0,                          /* unused */
2474         0,                          /* reserved */
2475         0,                          /* version */
2476         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2477         { 2, {0x81, 0x82} },        /* SCID */
2478         { 0 },                      /* PN */
2479         NULL, 0,                    /* Token */
2480         4, NULL                     /* Len/Data */
2481     },
2482     pkt_hdr_test_13_expected, OSSL_NELEM(pkt_hdr_test_13_expected),
2483     pkt_hdr_test_13_payload,  OSSL_NELEM(pkt_hdr_test_13_payload),
2484     0, 12,
2485     SIZE_MAX, SIZE_MAX
2486 };
2487
2488 /* Packet Header Test 14: 1-RTT - Malformed - No Fixed Bit */
2489 static const unsigned char pkt_hdr_test_14_expected[] = {
2490     0x02,                     /* Fixed, Type=1-RTT, PN Len=3 */
2491     0x70, 0x71, 0x72,         /* DCID */
2492     0x50, 0x51, 0x52,         /* PN */
2493     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2494     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2495 };
2496
2497 static const struct pkt_hdr_test pkt_hdr_test_14 = {
2498     { 0 },
2499     pkt_hdr_test_14_expected, OSSL_NELEM(pkt_hdr_test_14_expected),
2500     NULL, 0,
2501     3, SIZE_MAX,
2502     4, 8
2503 };
2504
2505 /* Packet Header Test 15: Handshake - Malformed - No Fixed Bit */
2506 static const unsigned char pkt_hdr_test_15_expected[] = {
2507     0xa0,                     /* Long, Type=Handshake, PN Len=1 */
2508     0x00, 0x00, 0x00, 0x01,   /* Version */
2509     0x03,                     /* DCID Length */
2510     0x70, 0x71, 0x72,         /* DCID */
2511     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2512     0x14,                     /* Length=20 */
2513     0x33,                     /* Encoded PN */
2514     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2515     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2516     0x20, 0x21, 0x22
2517 };
2518
2519 static const struct pkt_hdr_test pkt_hdr_test_15 = {
2520     { 0 },
2521     pkt_hdr_test_15_expected, OSSL_NELEM(pkt_hdr_test_15_expected),
2522     NULL, 0,
2523     0, SIZE_MAX,
2524     19, 23
2525 };
2526
2527 /* Packet Header Test 16: Handshake - Malformed - Wrong Version */
2528 static const unsigned char pkt_hdr_test_16_expected[] = {
2529     0xe0,                     /* Long|Fixed, Type=Handshake, PN Len=1 */
2530     0x00, 0x00, 0x00, 0x02,   /* Version */
2531     0x03,                     /* DCID Length */
2532     0x70, 0x71, 0x72,         /* DCID */
2533     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2534     0x14,                     /* Length=20 */
2535     0x33,                     /* Encoded PN */
2536     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2537     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2538     0x20, 0x21, 0x22
2539 };
2540
2541 static const struct pkt_hdr_test pkt_hdr_test_16 = {
2542     { 0 },
2543     pkt_hdr_test_16_expected, OSSL_NELEM(pkt_hdr_test_16_expected),
2544     NULL, 0,
2545     0, SIZE_MAX,
2546     19, 23
2547 };
2548
2549 /* Packet Header Test 17: Initial - Non-Zero Reserved Bits */
2550 static const unsigned char pkt_hdr_test_17_expected[] = {
2551     0xcd,                     /* Long|Fixed, Type=Initial, PN Len=2 */
2552     0x00, 0x00, 0x00, 0x01,   /* Version */
2553     0x00,                     /* DCID Length */
2554     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2555     0x00,                     /* Token Length */
2556     0x15,                     /* Length=21 */
2557     0x33, 0x44,               /* Encoded PN */
2558     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2559     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2560     0x20, 0x21, 0x22
2561 };
2562
2563 static const unsigned char pkt_hdr_test_17_payload[] = {
2564     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2565     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2566     0x20, 0x21, 0x22
2567 };
2568
2569 static const struct pkt_hdr_test pkt_hdr_test_17 = {
2570     {
2571         QUIC_PKT_TYPE_INITIAL,  /* type */
2572         0,                      /* spin bit */
2573         0,                      /* key phase */
2574         2,                      /* PN length */
2575         0,                      /* partial */
2576         1,                      /* fixed */
2577         0,                      /* unused */
2578         3,                      /* reserved */
2579         1,                      /* version */
2580         { 0, {0} },             /* DCID */
2581         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2582         { 0x33, 0x44 },         /* PN */
2583         NULL, 0,                /* Token/Token Len */
2584         19, NULL                /* Len/Data */
2585     },
2586     pkt_hdr_test_17_expected, OSSL_NELEM(pkt_hdr_test_17_expected),
2587     pkt_hdr_test_17_payload,  OSSL_NELEM(pkt_hdr_test_17_payload),
2588     0, sizeof(pkt_hdr_test_17_expected),
2589     17, 21
2590 };
2591
2592 /* Packet Header Test 18: 0-RTT - Non-Zero Reserved Bits */
2593 static const unsigned char pkt_hdr_test_18_expected[] = {
2594     0xd8,                     /* Long|Fixed, Type=0-RTT, PN Len=1 */
2595     0x00, 0x00, 0x00, 0x01,   /* Version */
2596     0x03,                     /* DCID Length */
2597     0x70, 0x71, 0x72,         /* DCID */
2598     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2599     0x14,                     /* Length=20 */
2600     0x33,                     /* Encoded PN */
2601     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2602     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2603     0x20, 0x21, 0x22
2604 };
2605
2606 static const unsigned char pkt_hdr_test_18_payload[] = {
2607     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2608     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2609     0x20, 0x21, 0x22
2610 };
2611
2612 static const struct pkt_hdr_test pkt_hdr_test_18 = {
2613     {
2614         QUIC_PKT_TYPE_0RTT,     /* type */
2615         0,                      /* spin bit */
2616         0,                      /* key phase */
2617         1,                      /* PN length */
2618         0,                      /* partial */
2619         1,                      /* fixed */
2620         0,                      /* unused */
2621         2,                      /* reserved */
2622         1,                      /* version */
2623         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2624         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2625         { 0x33 },               /* PN */
2626         NULL, 0,                /* Token */
2627         19, NULL                /* Len/Data */
2628     },
2629     pkt_hdr_test_18_expected, OSSL_NELEM(pkt_hdr_test_18_expected),
2630     pkt_hdr_test_18_payload,  OSSL_NELEM(pkt_hdr_test_18_payload),
2631     0, sizeof(pkt_hdr_test_18_expected),
2632     19, 23
2633 };
2634
2635 /* Packet Header Test 19: Handshake - Non-Zero Reserved Bits */
2636 static const unsigned char pkt_hdr_test_19_expected[] = {
2637     0xe4,                     /* Long|Fixed, Type=Handshake, PN Len=1 */
2638     0x00, 0x00, 0x00, 0x01,   /* Version */
2639     0x03,                     /* DCID Length */
2640     0x70, 0x71, 0x72,         /* DCID */
2641     0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2642     0x14,                     /* Length=20 */
2643     0x33,                     /* Encoded PN */
2644     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2645     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2646     0x20, 0x21, 0x22
2647 };
2648
2649 static const unsigned char pkt_hdr_test_19_payload[] = {
2650     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2651     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2652     0x20, 0x21, 0x22
2653 };
2654
2655 static const struct pkt_hdr_test pkt_hdr_test_19 = {
2656     {
2657         QUIC_PKT_TYPE_HANDSHAKE,    /* type */
2658         0,                          /* spin bit */
2659         0,                          /* key phase */
2660         1,                          /* PN length */
2661         0,                          /* partial */
2662         1,                          /* fixed */
2663         0,                          /* unused */
2664         1,                          /* reserved */
2665         1,                          /* version */
2666         { 3, {0x70, 0x71, 0x72} },                                /* DCID */
2667         { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
2668         { 0x33 },                   /* PN */
2669         NULL, 0,                    /* Token */
2670         19, NULL                    /* Len/Data */
2671     },
2672     pkt_hdr_test_19_expected, OSSL_NELEM(pkt_hdr_test_19_expected),
2673     pkt_hdr_test_19_payload,  OSSL_NELEM(pkt_hdr_test_19_payload),
2674     0, sizeof(pkt_hdr_test_19_expected),
2675     19, 23
2676 };
2677
2678 /* Packet Header Test 20: 1-RTT with Non-Zero Reserved Bits */
2679 static const unsigned char pkt_hdr_test_20_expected[] = {
2680     0x5a,                     /* Short|Fixed, Type=1-RTT, PN Len=3 */
2681     0x70, 0x71, 0x72,         /* DCID */
2682     0x50, 0x51, 0x52,         /* PN */
2683     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2684     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2685 };
2686
2687 static const unsigned char pkt_hdr_test_20_payload[] = {
2688     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2689     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2690 };
2691
2692 static const struct pkt_hdr_test pkt_hdr_test_20 = {
2693     {
2694         QUIC_PKT_TYPE_1RTT,         /* type */
2695         0,                          /* spin bit */
2696         0,                          /* key phase */
2697         3,                          /* PN length */
2698         0,                          /* partial */
2699         1,                          /* fixed */
2700         0,                          /* unused */
2701         3,                          /* reserved */
2702         0,                          /* version */
2703         { 3, {0x70, 0x71, 0x72} },  /* DCID */
2704         { 0, {0} },                 /* SCID */
2705         { 0x50, 0x51, 0x52 },       /* PN */
2706         NULL, 0,                    /* Token */
2707         18, NULL                    /* Len/Data */
2708     },
2709     pkt_hdr_test_20_expected, OSSL_NELEM(pkt_hdr_test_20_expected),
2710     pkt_hdr_test_20_payload,  OSSL_NELEM(pkt_hdr_test_20_payload),
2711     3, 21,
2712     4, 8
2713 };
2714
2715 static const struct pkt_hdr_test *const pkt_hdr_tests[] = {
2716     &pkt_hdr_test_1,
2717     &pkt_hdr_test_2,
2718     &pkt_hdr_test_3,
2719     &pkt_hdr_test_4,
2720     &pkt_hdr_test_5,
2721     &pkt_hdr_test_6,
2722     &pkt_hdr_test_7,
2723     &pkt_hdr_test_8,
2724     &pkt_hdr_test_9,
2725     &pkt_hdr_test_10,
2726     &pkt_hdr_test_11,
2727     &pkt_hdr_test_12,
2728     &pkt_hdr_test_13,
2729     &pkt_hdr_test_14,
2730     &pkt_hdr_test_15,
2731     &pkt_hdr_test_16,
2732     &pkt_hdr_test_17,
2733     &pkt_hdr_test_18,
2734     &pkt_hdr_test_19,
2735     &pkt_hdr_test_20
2736 };
2737
2738 #define HPR_REPEAT_COUNT 4
2739 #define HPR_CIPHER_COUNT 3
2740
2741 /*
2742  * Count of number of times we observed an unchanged (u) or changed (c) bit in
2743  * each header-protectable bit over all test suites.
2744  */
2745 static unsigned int counts_u[HPR_CIPHER_COUNT][37] = {0};
2746 static unsigned int counts_c[HPR_CIPHER_COUNT][37] = {0};
2747
2748 #define TEST_PKT_BUF_LEN 20000
2749
2750 static int test_wire_pkt_hdr_actual(int tidx, int repeat, int cipher,
2751                                     size_t trunc_len)
2752 {
2753     int testresult = 0;
2754     const struct pkt_hdr_test *t = pkt_hdr_tests[tidx];
2755     QUIC_PKT_HDR hdr = {0};
2756     QUIC_PKT_HDR_PTRS ptrs = {0}, wptrs = {0};
2757     PACKET pkt = {0};
2758     WPACKET wpkt = {0};
2759     unsigned char *buf = NULL;
2760     size_t l = 0, i, j;
2761     QUIC_HDR_PROTECTOR hpr = {0};
2762     unsigned char hpr_key[32] = {0,1,2,3,4,5,6,7};
2763     int have_hpr = 0, hpr_cipher_id, hpr_key_len;
2764     unsigned char *hbuf = NULL;
2765     int is_trunc = trunc_len < t->expected_len;
2766     int expect_fail = trunc_len < t->min_success_len;
2767     hpr_key[8] = (unsigned char)tidx;
2768     hpr_key[9] = (unsigned char)repeat;
2769
2770     if (is_trunc && trunc_len > t->min_success_len
2771         && t->hdr.type == QUIC_PKT_TYPE_VERSION_NEG
2772         && ((trunc_len - t->min_success_len) % 4) != 0)
2773         expect_fail = 1;
2774
2775     switch (cipher) {
2776         case 0:
2777             hpr_cipher_id = QUIC_HDR_PROT_CIPHER_AES_128;
2778             hpr_key_len   = 16;
2779             break;
2780         case 1:
2781             hpr_cipher_id = QUIC_HDR_PROT_CIPHER_AES_256;
2782             hpr_key_len   = 32;
2783             break;
2784         case 2:
2785             /*
2786              * In a build without CHACHA, we rerun the AES 256 tests.
2787              * Removing all dependence on CHACHA is more difficult and these
2788              * tests are fast enough.
2789              */
2790 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
2791             hpr_cipher_id = QUIC_HDR_PROT_CIPHER_CHACHA;
2792 #else
2793             hpr_cipher_id = QUIC_HDR_PROT_CIPHER_AES_256;
2794 #endif
2795             hpr_key_len   = 32;
2796             break;
2797         default:
2798             goto err;
2799     }
2800
2801     if (!TEST_ptr(buf = OPENSSL_malloc(TEST_PKT_BUF_LEN)))
2802         goto err;
2803
2804     if (!TEST_true(WPACKET_init_static_len(&wpkt, buf, TEST_PKT_BUF_LEN, 0)))
2805         goto err;
2806
2807     if (!TEST_true(PACKET_buf_init(&pkt, t->expected, trunc_len)))
2808         goto err;
2809
2810     if (!TEST_int_eq(ossl_quic_wire_decode_pkt_hdr(&pkt, t->short_conn_id_len,
2811                                                    0, 0, &hdr, &ptrs),
2812                      !expect_fail))
2813         goto err;
2814
2815     if (!expect_fail && !is_trunc) {
2816         if (!TEST_true(cmp_pkt_hdr(&hdr, &t->hdr, t->payload, t->payload_len, 1)))
2817             goto err;
2818
2819         if (!TEST_ptr_eq(ptrs.raw_start, t->expected))
2820             goto err;
2821
2822         if (t->pn_offset == SIZE_MAX) {
2823             if (!TEST_ptr_null(ptrs.raw_pn))
2824                 goto err;
2825         } else {
2826             if (!TEST_ptr_eq(ptrs.raw_pn, t->expected + t->pn_offset))
2827                 goto err;
2828         }
2829
2830         if (t->sample_offset != SIZE_MAX) {
2831             if (!TEST_ptr_eq(ptrs.raw_sample, t->expected + t->sample_offset))
2832                 goto err;
2833             if (!TEST_size_t_eq(ptrs.raw_sample_len,
2834                                 t->expected_len - t->sample_offset))
2835                 goto err;
2836         }
2837
2838         if (!TEST_true(ossl_quic_wire_encode_pkt_hdr(&wpkt, t->short_conn_id_len, &hdr, &wptrs)))
2839             goto err;
2840
2841         if (!TEST_true(WPACKET_memcpy(&wpkt, t->payload, t->payload_len)))
2842             goto err;
2843
2844         if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
2845             goto err;
2846
2847         if (!TEST_mem_eq(buf, l, t->expected, t->expected_len))
2848             goto err;
2849
2850         /* Test header protection. */
2851         if (t->sample_offset != SIZE_MAX) { /* if packet type has protection */
2852             if (!TEST_true(ossl_quic_hdr_protector_init(&hpr, NULL, NULL,
2853                                                         hpr_cipher_id,
2854                                                         hpr_key,
2855                                                         hpr_key_len)))
2856                 goto err;
2857
2858             have_hpr = 1;
2859
2860             /*
2861              * Copy into a duplicate buffer to test header protection by
2862              * comparing it against the original.
2863              */
2864             hbuf = OPENSSL_malloc(t->expected_len);
2865             if (!TEST_ptr(hbuf))
2866                 goto err;
2867
2868             memcpy(hbuf, t->expected, t->expected_len);
2869
2870             /* Fixup pointers to new buffer and encrypt. */
2871             ptrs.raw_pn         = hbuf + (ptrs.raw_pn     - ptrs.raw_start);
2872             ptrs.raw_sample     = hbuf + (ptrs.raw_sample - ptrs.raw_start);
2873             ptrs.raw_start      = hbuf;
2874             if (!TEST_true(ossl_quic_hdr_protector_encrypt(&hpr, &ptrs)))
2875                 goto err;
2876
2877             /* Ensure that bytes which should not have changed did not change */
2878             for (i = 0; i < t->expected_len; ++i) {
2879                 unsigned char d = t->expected[i] ^ hbuf[i], rej_mask = 0xff;
2880                 size_t jrel = 0;
2881                 if (i == 0) {
2882                     /* Bits in first byte which must not change */
2883                     rej_mask = (t->hdr.type == QUIC_PKT_TYPE_1RTT) ? ~0x1f : ~0xf;
2884                 } else if (i >= t->pn_offset && i < t->pn_offset + t->hdr.pn_len) {
2885                     /* PN bytes change */
2886                     rej_mask = 0;
2887                     jrel = 5 + (i - t->pn_offset) * 8;
2888                 }
2889
2890                 if (rej_mask != 0xff)
2891                     for (j = 0; j < 8; ++j) {
2892                         if (((1U << j) & rej_mask) != 0)
2893                             /*
2894                              * Bit unrelated to header protection, do not record
2895                              * stats about it.
2896                              */
2897                             continue;
2898
2899                         OPENSSL_assert(jrel + j < OSSL_NELEM(counts_u[cipher]));
2900                         if ((d & (1U << j)) != 0)
2901                             ++counts_c[cipher][jrel + j]; /* bit did change */
2902                         else
2903                             ++counts_u[cipher][jrel + j]; /* bit did not change */
2904                     }
2905
2906                 /* Bits in rej_mask must not change */
2907                 if (!TEST_int_eq(d & rej_mask, 0))
2908                     goto err;
2909             }
2910
2911             /* Decrypt and check matches original. */
2912             if (!TEST_true(ossl_quic_hdr_protector_decrypt(&hpr, &ptrs)))
2913                 goto err;
2914
2915             if (!TEST_mem_eq(hbuf, t->expected_len, t->expected, t->expected_len))
2916                 goto err;
2917         }
2918     }
2919
2920     testresult = 1;
2921 err:
2922     if (have_hpr)
2923         ossl_quic_hdr_protector_cleanup(&hpr);
2924     WPACKET_finish(&wpkt);
2925     OPENSSL_free(buf);
2926     OPENSSL_free(hbuf);
2927     return testresult;
2928 }
2929
2930 static int test_wire_pkt_hdr_inner(int tidx, int repeat, int cipher)
2931 {
2932     int testresult = 0;
2933     const struct pkt_hdr_test *t = pkt_hdr_tests[tidx];
2934     size_t i;
2935
2936     /* Test with entire packet */
2937     if (!TEST_true(test_wire_pkt_hdr_actual(tidx, repeat, cipher,
2938                                             t->expected_len)))
2939         goto err;
2940
2941     /* Now repeat for every possible truncation of the packet */
2942     for (i = 0; i < t->expected_len; ++i)
2943         if (!TEST_true(test_wire_pkt_hdr_actual(tidx, repeat, cipher, i)))
2944             goto err;
2945
2946     testresult = 1;
2947 err:
2948     return testresult;
2949 }
2950
2951 static int test_hdr_prot_stats(void)
2952 {
2953     int testresult = 0;
2954     size_t i, cipher;
2955
2956     /*
2957      * Test that, across all previously executed tests for each header
2958      * protection cipher, every bit which can have header protection applied a)
2959      * was changed in at least one test of applying header protection, and b)
2960      * was unchanged in at least one test of applying header protection.
2961      */
2962     for (cipher = 0; cipher < HPR_CIPHER_COUNT; ++cipher)
2963         for (i = 0; i < OSSL_NELEM(counts_u[0]); ++i) {
2964             if (!TEST_uint_gt(counts_u[cipher][i], 0))
2965                 goto err;
2966             if (!TEST_uint_gt(counts_c[cipher][i], 0))
2967                 goto err;
2968         }
2969
2970     testresult = 1;
2971 err:
2972     return testresult;
2973 }
2974
2975 #define NUM_WIRE_PKT_HDR_TESTS \
2976     (OSSL_NELEM(pkt_hdr_tests) * HPR_REPEAT_COUNT * HPR_CIPHER_COUNT)
2977
2978 static int test_wire_pkt_hdr(int idx)
2979 {
2980     int tidx, repeat, cipher;
2981
2982     if (idx == NUM_WIRE_PKT_HDR_TESTS)
2983         return test_hdr_prot_stats();
2984
2985     cipher = idx % HPR_CIPHER_COUNT;
2986     idx /= HPR_CIPHER_COUNT;
2987
2988     repeat = idx % HPR_REPEAT_COUNT;
2989     idx /= HPR_REPEAT_COUNT;
2990
2991     tidx = idx;
2992
2993     return test_wire_pkt_hdr_inner(tidx, repeat, cipher);
2994 }
2995
2996 /* TX Tests */
2997 #define TX_TEST_OP_END                     0 /* end of script */
2998 #define TX_TEST_OP_WRITE                   1 /* write packet */
2999 #define TX_TEST_OP_PROVIDE_SECRET          2 /* provide TX secret */
3000 #define TX_TEST_OP_PROVIDE_SECRET_INITIAL  3 /* provide TX secret for initial */
3001 #define TX_TEST_OP_DISCARD_EL              4 /* discard an encryption level */
3002 #define TX_TEST_OP_CHECK_DGRAM             5 /* read datagram, compare to expected */
3003 #define TX_TEST_OP_CHECK_NO_DGRAM          6 /* check no datagram is in queue */
3004 #define TX_TEST_OP_KEY_UPDATE              7 /* perform key update for 1-RTT */
3005
3006 struct tx_test_op {
3007     unsigned char op;
3008     const unsigned char *buf;
3009     size_t buf_len;
3010     const OSSL_QTX_PKT *pkt;
3011     uint32_t enc_level, suite_id;
3012     const QUIC_CONN_ID *dcid;
3013 };
3014
3015 #define TX_OP_END                                                       \
3016     { TX_TEST_OP_END }
3017 #define TX_OP_WRITE(pkt)                                                \
3018     { TX_TEST_OP_WRITE, NULL, 0, &(pkt), 0, 0, NULL },
3019 #define TX_OP_PROVIDE_SECRET(el, suite, key)                            \
3020     {                                                                   \
3021         TX_TEST_OP_PROVIDE_SECRET, (key), sizeof(key),                  \
3022         NULL, (el), (suite), NULL                                       \
3023     },
3024 #define TX_OP_PROVIDE_SECRET_INITIAL(dcid, is_server)                   \
3025     { TX_TEST_OP_PROVIDE_SECRET_INITIAL,                                \
3026       NULL, 0, NULL, 0, (is_server), &(dcid) },
3027 #define TX_OP_DISCARD_EL(el)                                            \
3028     { TX_TEST_OP_DISCARD_EL, NULL, 0, NULL, (el), 0, NULL },
3029 #define TX_OP_CHECK_DGRAM(expect_dgram)                                 \
3030     {                                                                   \
3031         TX_TEST_OP_CHECK_DGRAM, (expect_dgram), sizeof(expect_dgram),   \
3032         NULL, 0, 0, NULL                                                \
3033     },
3034 #define TX_OP_CHECK_NO_DGRAM() \
3035     { TX_TEST_OP_CHECK_NO_PKT, NULL, 0, NULL, 0, 0, NULL },
3036
3037 #define TX_OP_WRITE_N(n)                                                \
3038     TX_OP_WRITE(tx_script_##n##_pkt)
3039 #define TX_OP_CHECK_DGRAM_N(n)                                          \
3040     TX_OP_CHECK_DGRAM(tx_script_##n##_dgram)
3041
3042 #define TX_OP_WRITE_CHECK(n)                                            \
3043     TX_OP_WRITE_N(n)                                                    \
3044     TX_OP_CHECK_DGRAM_N(n)
3045
3046 #define TX_OP_KEY_UPDATE()                                              \
3047     { TX_TEST_OP_KEY_UPDATE, NULL, 0, NULL, 0, 0, NULL },
3048
3049 /* 1. RFC 9001 - A.2 Client Initial */
3050 static const unsigned char tx_script_1_body[1162] = {
3051     0x06, 0x00, 0x40, 0xf1, 0x01, 0x00, 0x00, 0xed, 0x03, 0x03, 0xeb, 0xf8,
3052     0xfa, 0x56, 0xf1, 0x29, 0x39, 0xb9, 0x58, 0x4a, 0x38, 0x96, 0x47, 0x2e,
3053     0xc4, 0x0b, 0xb8, 0x63, 0xcf, 0xd3, 0xe8, 0x68, 0x04, 0xfe, 0x3a, 0x47,
3054     0xf0, 0x6a, 0x2b, 0x69, 0x48, 0x4c, 0x00, 0x00, 0x04, 0x13, 0x01, 0x13,
3055     0x02, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00,
3056     0x00, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
3057     0x6d, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06,
3058     0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x10, 0x00, 0x07, 0x00, 0x05,
3059     0x04, 0x61, 0x6c, 0x70, 0x6e, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00,
3060     0x00, 0x00, 0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20,
3061     0x93, 0x70, 0xb2, 0xc9, 0xca, 0xa4, 0x7f, 0xba, 0xba, 0xf4, 0x55, 0x9f,
3062     0xed, 0xba, 0x75, 0x3d, 0xe1, 0x71, 0xfa, 0x71, 0xf5, 0x0f, 0x1c, 0xe1,
3063     0x5d, 0x43, 0xe9, 0x94, 0xec, 0x74, 0xd7, 0x48, 0x00, 0x2b, 0x00, 0x03,
3064     0x02, 0x03, 0x04, 0x00, 0x0d, 0x00, 0x10, 0x00, 0x0e, 0x04, 0x03, 0x05,
3065     0x03, 0x06, 0x03, 0x02, 0x03, 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x00,
3066     0x2d, 0x00, 0x02, 0x01, 0x01, 0x00, 0x1c, 0x00, 0x02, 0x40, 0x01, 0x00,
3067     0x39, 0x00, 0x32, 0x04, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3068     0xff, 0x05, 0x04, 0x80, 0x00, 0xff, 0xff, 0x07, 0x04, 0x80, 0x00, 0xff,
3069     0xff, 0x08, 0x01, 0x10, 0x01, 0x04, 0x80, 0x00, 0x75, 0x30, 0x09, 0x01,
3070     0x10, 0x0f, 0x08, 0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08, 0x06,
3071     0x04, 0x80, 0x00, 0xff, 0xff /* followed by zero padding */
3072 };
3073
3074 static const unsigned char tx_script_1_dgram[] = {
3075     0xc0, 0x00, 0x00, 0x00, 0x01, 0x08, 0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51,
3076     0x57, 0x08, 0x00, 0x00, 0x44, 0x9e, 0x7b, 0x9a, 0xec, 0x34, 0xd1, 0xb1,
3077     0xc9, 0x8d, 0xd7, 0x68, 0x9f, 0xb8, 0xec, 0x11, 0xd2, 0x42, 0xb1, 0x23,
3078     0xdc, 0x9b, 0xd8, 0xba, 0xb9, 0x36, 0xb4, 0x7d, 0x92, 0xec, 0x35, 0x6c,
3079     0x0b, 0xab, 0x7d, 0xf5, 0x97, 0x6d, 0x27, 0xcd, 0x44, 0x9f, 0x63, 0x30,
3080     0x00, 0x99, 0xf3, 0x99, 0x1c, 0x26, 0x0e, 0xc4, 0xc6, 0x0d, 0x17, 0xb3,
3081     0x1f, 0x84, 0x29, 0x15, 0x7b, 0xb3, 0x5a, 0x12, 0x82, 0xa6, 0x43, 0xa8,
3082     0xd2, 0x26, 0x2c, 0xad, 0x67, 0x50, 0x0c, 0xad, 0xb8, 0xe7, 0x37, 0x8c,
3083     0x8e, 0xb7, 0x53, 0x9e, 0xc4, 0xd4, 0x90, 0x5f, 0xed, 0x1b, 0xee, 0x1f,
3084     0xc8, 0xaa, 0xfb, 0xa1, 0x7c, 0x75, 0x0e, 0x2c, 0x7a, 0xce, 0x01, 0xe6,
3085     0x00, 0x5f, 0x80, 0xfc, 0xb7, 0xdf, 0x62, 0x12, 0x30, 0xc8, 0x37, 0x11,
3086     0xb3, 0x93, 0x43, 0xfa, 0x02, 0x8c, 0xea, 0x7f, 0x7f, 0xb5, 0xff, 0x89,
3087     0xea, 0xc2, 0x30, 0x82, 0x49, 0xa0, 0x22, 0x52, 0x15, 0x5e, 0x23, 0x47,
3088     0xb6, 0x3d, 0x58, 0xc5, 0x45, 0x7a, 0xfd, 0x84, 0xd0, 0x5d, 0xff, 0xfd,
3089     0xb2, 0x03, 0x92, 0x84, 0x4a, 0xe8, 0x12, 0x15, 0x46, 0x82, 0xe9, 0xcf,
3090     0x01, 0x2f, 0x90, 0x21, 0xa6, 0xf0, 0xbe, 0x17, 0xdd, 0xd0, 0xc2, 0x08,
3091     0x4d, 0xce, 0x25, 0xff, 0x9b, 0x06, 0xcd, 0xe5, 0x35, 0xd0, 0xf9, 0x20,
3092     0xa2, 0xdb, 0x1b, 0xf3, 0x62, 0xc2, 0x3e, 0x59, 0x6d, 0x11, 0xa4, 0xf5,
3093     0xa6, 0xcf, 0x39, 0x48, 0x83, 0x8a, 0x3a, 0xec, 0x4e, 0x15, 0xda, 0xf8,
3094     0x50, 0x0a, 0x6e, 0xf6, 0x9e, 0xc4, 0xe3, 0xfe, 0xb6, 0xb1, 0xd9, 0x8e,
3095     0x61, 0x0a, 0xc8, 0xb7, 0xec, 0x3f, 0xaf, 0x6a, 0xd7, 0x60, 0xb7, 0xba,
3096     0xd1, 0xdb, 0x4b, 0xa3, 0x48, 0x5e, 0x8a, 0x94, 0xdc, 0x25, 0x0a, 0xe3,
3097     0xfd, 0xb4, 0x1e, 0xd1, 0x5f, 0xb6, 0xa8, 0xe5, 0xeb, 0xa0, 0xfc, 0x3d,
3098     0xd6, 0x0b, 0xc8, 0xe3, 0x0c, 0x5c, 0x42, 0x87, 0xe5, 0x38, 0x05, 0xdb,
3099     0x05, 0x9a, 0xe0, 0x64, 0x8d, 0xb2, 0xf6, 0x42, 0x64, 0xed, 0x5e, 0x39,
3100     0xbe, 0x2e, 0x20, 0xd8, 0x2d, 0xf5, 0x66, 0xda, 0x8d, 0xd5, 0x99, 0x8c,
3101     0xca, 0xbd, 0xae, 0x05, 0x30, 0x60, 0xae, 0x6c, 0x7b, 0x43, 0x78, 0xe8,
3102     0x46, 0xd2, 0x9f, 0x37, 0xed, 0x7b, 0x4e, 0xa9, 0xec, 0x5d, 0x82, 0xe7,
3103     0x96, 0x1b, 0x7f, 0x25, 0xa9, 0x32, 0x38, 0x51, 0xf6, 0x81, 0xd5, 0x82,
3104     0x36, 0x3a, 0xa5, 0xf8, 0x99, 0x37, 0xf5, 0xa6, 0x72, 0x58, 0xbf, 0x63,
3105     0xad, 0x6f, 0x1a, 0x0b, 0x1d, 0x96, 0xdb, 0xd4, 0xfa, 0xdd, 0xfc, 0xef,
3106     0xc5, 0x26, 0x6b, 0xa6, 0x61, 0x17, 0x22, 0x39, 0x5c, 0x90, 0x65, 0x56,
3107     0xbe, 0x52, 0xaf, 0xe3, 0xf5, 0x65, 0x63, 0x6a, 0xd1, 0xb1, 0x7d, 0x50,
3108     0x8b, 0x73, 0xd8, 0x74, 0x3e, 0xeb, 0x52, 0x4b, 0xe2, 0x2b, 0x3d, 0xcb,
3109     0xc2, 0xc7, 0x46, 0x8d, 0x54, 0x11, 0x9c, 0x74, 0x68, 0x44, 0x9a, 0x13,
3110     0xd8, 0xe3, 0xb9, 0x58, 0x11, 0xa1, 0x98, 0xf3, 0x49, 0x1d, 0xe3, 0xe7,
3111     0xfe, 0x94, 0x2b, 0x33, 0x04, 0x07, 0xab, 0xf8, 0x2a, 0x4e, 0xd7, 0xc1,
3112     0xb3, 0x11, 0x66, 0x3a, 0xc6, 0x98, 0x90, 0xf4, 0x15, 0x70, 0x15, 0x85,
3113     0x3d, 0x91, 0xe9, 0x23, 0x03, 0x7c, 0x22, 0x7a, 0x33, 0xcd, 0xd5, 0xec,
3114     0x28, 0x1c, 0xa3, 0xf7, 0x9c, 0x44, 0x54, 0x6b, 0x9d, 0x90, 0xca, 0x00,
3115     0xf0, 0x64, 0xc9, 0x9e, 0x3d, 0xd9, 0x79, 0x11, 0xd3, 0x9f, 0xe9, 0xc5,
3116     0xd0, 0xb2, 0x3a, 0x22, 0x9a, 0x23, 0x4c, 0xb3, 0x61, 0x86, 0xc4, 0x81,
3117     0x9e, 0x8b, 0x9c, 0x59, 0x27, 0x72, 0x66, 0x32, 0x29, 0x1d, 0x6a, 0x41,
3118     0x82, 0x11, 0xcc, 0x29, 0x62, 0xe2, 0x0f, 0xe4, 0x7f, 0xeb, 0x3e, 0xdf,
3119     0x33, 0x0f, 0x2c, 0x60, 0x3a, 0x9d, 0x48, 0xc0, 0xfc, 0xb5, 0x69, 0x9d,
3120     0xbf, 0xe5, 0x89, 0x64, 0x25, 0xc5, 0xba, 0xc4, 0xae, 0xe8, 0x2e, 0x57,
3121     0xa8, 0x5a, 0xaf, 0x4e, 0x25, 0x13, 0xe4, 0xf0, 0x57, 0x96, 0xb0, 0x7b,
3122     0xa2, 0xee, 0x47, 0xd8, 0x05, 0x06, 0xf8, 0xd2, 0xc2, 0x5e, 0x50, 0xfd,
3123     0x14, 0xde, 0x71, 0xe6, 0xc4, 0x18, 0x55, 0x93, 0x02, 0xf9, 0x39, 0xb0,
3124     0xe1, 0xab, 0xd5, 0x76, 0xf2, 0x79, 0xc4, 0xb2, 0xe0, 0xfe, 0xb8, 0x5c,
3125     0x1f, 0x28, 0xff, 0x18, 0xf5, 0x88, 0x91, 0xff, 0xef, 0x13, 0x2e, 0xef,
3126     0x2f, 0xa0, 0x93, 0x46, 0xae, 0xe3, 0x3c, 0x28, 0xeb, 0x13, 0x0f, 0xf2,
3127     0x8f, 0x5b, 0x76, 0x69, 0x53, 0x33, 0x41, 0x13, 0x21, 0x19, 0x96, 0xd2,
3128     0x00, 0x11, 0xa1, 0x98, 0xe3, 0xfc, 0x43, 0x3f, 0x9f, 0x25, 0x41, 0x01,
3129     0x0a, 0xe1, 0x7c, 0x1b, 0xf2, 0x02, 0x58, 0x0f, 0x60, 0x47, 0x47, 0x2f,
3130     0xb3, 0x68, 0x57, 0xfe, 0x84, 0x3b, 0x19, 0xf5, 0x98, 0x40, 0x09, 0xdd,
3131     0xc3, 0x24, 0x04, 0x4e, 0x84, 0x7a, 0x4f, 0x4a, 0x0a, 0xb3, 0x4f, 0x71,
3132     0x95, 0x95, 0xde, 0x37, 0x25, 0x2d, 0x62, 0x35, 0x36, 0x5e, 0x9b, 0x84,
3133     0x39, 0x2b, 0x06, 0x10, 0x85, 0x34, 0x9d, 0x73, 0x20, 0x3a, 0x4a, 0x13,
3134     0xe9, 0x6f, 0x54, 0x32, 0xec, 0x0f, 0xd4, 0xa1, 0xee, 0x65, 0xac, 0xcd,
3135     0xd5, 0xe3, 0x90, 0x4d, 0xf5, 0x4c, 0x1d, 0xa5, 0x10, 0xb0, 0xff, 0x20,
3136     0xdc, 0xc0, 0xc7, 0x7f, 0xcb, 0x2c, 0x0e, 0x0e, 0xb6, 0x05, 0xcb, 0x05,
3137     0x04, 0xdb, 0x87, 0x63, 0x2c, 0xf3, 0xd8, 0xb4, 0xda, 0xe6, 0xe7, 0x05,
3138     0x76, 0x9d, 0x1d, 0xe3, 0x54, 0x27, 0x01, 0x23, 0xcb, 0x11, 0x45, 0x0e,
3139     0xfc, 0x60, 0xac, 0x47, 0x68, 0x3d, 0x7b, 0x8d, 0x0f, 0x81, 0x13, 0x65,
3140     0x56, 0x5f, 0xd9, 0x8c, 0x4c, 0x8e, 0xb9, 0x36, 0xbc, 0xab, 0x8d, 0x06,
3141     0x9f, 0xc3, 0x3b, 0xd8, 0x01, 0xb0, 0x3a, 0xde, 0xa2, 0xe1, 0xfb, 0xc5,
3142     0xaa, 0x46, 0x3d, 0x08, 0xca, 0x19, 0x89, 0x6d, 0x2b, 0xf5, 0x9a, 0x07,
3143     0x1b, 0x85, 0x1e, 0x6c, 0x23, 0x90, 0x52, 0x17, 0x2f, 0x29, 0x6b, 0xfb,
3144     0x5e, 0x72, 0x40, 0x47, 0x90, 0xa2, 0x18, 0x10, 0x14, 0xf3, 0xb9, 0x4a,
3145     0x4e, 0x97, 0xd1, 0x17, 0xb4, 0x38, 0x13, 0x03, 0x68, 0xcc, 0x39, 0xdb,
3146     0xb2, 0xd1, 0x98, 0x06, 0x5a, 0xe3, 0x98, 0x65, 0x47, 0x92, 0x6c, 0xd2,
3147     0x16, 0x2f, 0x40, 0xa2, 0x9f, 0x0c, 0x3c, 0x87, 0x45, 0xc0, 0xf5, 0x0f,
3148     0xba, 0x38, 0x52, 0xe5, 0x66, 0xd4, 0x45, 0x75, 0xc2, 0x9d, 0x39, 0xa0,
3149     0x3f, 0x0c, 0xda, 0x72, 0x19, 0x84, 0xb6, 0xf4, 0x40, 0x59, 0x1f, 0x35,
3150     0x5e, 0x12, 0xd4, 0x39, 0xff, 0x15, 0x0a, 0xab, 0x76, 0x13, 0x49, 0x9d,
3151     0xbd, 0x49, 0xad, 0xab, 0xc8, 0x67, 0x6e, 0xef, 0x02, 0x3b, 0x15, 0xb6,
3152     0x5b, 0xfc, 0x5c, 0xa0, 0x69, 0x48, 0x10, 0x9f, 0x23, 0xf3, 0x50, 0xdb,
3153     0x82, 0x12, 0x35, 0x35, 0xeb, 0x8a, 0x74, 0x33, 0xbd, 0xab, 0xcb, 0x90,
3154     0x92, 0x71, 0xa6, 0xec, 0xbc, 0xb5, 0x8b, 0x93, 0x6a, 0x88, 0xcd, 0x4e,
3155     0x8f, 0x2e, 0x6f, 0xf5, 0x80, 0x01, 0x75, 0xf1, 0x13, 0x25, 0x3d, 0x8f,
3156     0xa9, 0xca, 0x88, 0x85, 0xc2, 0xf5, 0x52, 0xe6, 0x57, 0xdc, 0x60, 0x3f,
3157     0x25, 0x2e, 0x1a, 0x8e, 0x30, 0x8f, 0x76, 0xf0, 0xbe, 0x79, 0xe2, 0xfb,
3158     0x8f, 0x5d, 0x5f, 0xbb, 0xe2, 0xe3, 0x0e, 0xca, 0xdd, 0x22, 0x07, 0x23,
3159     0xc8, 0xc0, 0xae, 0xa8, 0x07, 0x8c, 0xdf, 0xcb, 0x38, 0x68, 0x26, 0x3f,
3160     0xf8, 0xf0, 0x94, 0x00, 0x54, 0xda, 0x48, 0x78, 0x18, 0x93, 0xa7, 0xe4,
3161     0x9a, 0xd5, 0xaf, 0xf4, 0xaf, 0x30, 0x0c, 0xd8, 0x04, 0xa6, 0xb6, 0x27,
3162     0x9a, 0xb3, 0xff, 0x3a, 0xfb, 0x64, 0x49, 0x1c, 0x85, 0x19, 0x4a, 0xab,
3163     0x76, 0x0d, 0x58, 0xa6, 0x06, 0x65, 0x4f, 0x9f, 0x44, 0x00, 0xe8, 0xb3,
3164     0x85, 0x91, 0x35, 0x6f, 0xbf, 0x64, 0x25, 0xac, 0xa2, 0x6d, 0xc8, 0x52,
3165     0x44, 0x25, 0x9f, 0xf2, 0xb1, 0x9c, 0x41, 0xb9, 0xf9, 0x6f, 0x3c, 0xa9,
3166     0xec, 0x1d, 0xde, 0x43, 0x4d, 0xa7, 0xd2, 0xd3, 0x92, 0xb9, 0x05, 0xdd,
3167     0xf3, 0xd1, 0xf9, 0xaf, 0x93, 0xd1, 0xaf, 0x59, 0x50, 0xbd, 0x49, 0x3f,
3168     0x5a, 0xa7, 0x31, 0xb4, 0x05, 0x6d, 0xf3, 0x1b, 0xd2, 0x67, 0xb6, 0xb9,
3169     0x0a, 0x07, 0x98, 0x31, 0xaa, 0xf5, 0x79, 0xbe, 0x0a, 0x39, 0x01, 0x31,
3170     0x37, 0xaa, 0xc6, 0xd4, 0x04, 0xf5, 0x18, 0xcf, 0xd4, 0x68, 0x40, 0x64,
3171     0x7e, 0x78, 0xbf, 0xe7, 0x06, 0xca, 0x4c, 0xf5, 0xe9, 0xc5, 0x45, 0x3e,
3172     0x9f, 0x7c, 0xfd, 0x2b, 0x8b, 0x4c, 0x8d, 0x16, 0x9a, 0x44, 0xe5, 0x5c,
3173     0x88, 0xd4, 0xa9, 0xa7, 0xf9, 0x47, 0x42, 0x41, 0xe2, 0x21, 0xaf, 0x44,
3174     0x86, 0x00, 0x18, 0xab, 0x08, 0x56, 0x97, 0x2e, 0x19, 0x4c, 0xd9, 0x34
3175 };
3176
3177 static QUIC_PKT_HDR tx_script_1_hdr = {
3178     QUIC_PKT_TYPE_INITIAL,      /* type */
3179     0,                          /* spin bit */
3180     0,                          /* key phase */
3181     4,                          /* PN length */
3182     0,                          /* partial */
3183     0,                          /* fixed */
3184     0,                          /* unused */
3185     0,                          /* reserved */
3186     1,                          /* version */
3187     {8, {0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08}}, /* DCID */
3188     { 0, {0} },                 /* SCID */
3189     { 0 },                      /* PN */
3190     NULL, 0,                    /* Token */
3191     5555, NULL                  /* Len/Data */
3192 };
3193
3194 static const OSSL_QTX_IOVEC tx_script_1_iovec[] = {
3195     { tx_script_1_body, sizeof(tx_script_1_body) }
3196 };
3197
3198 static const OSSL_QTX_PKT tx_script_1_pkt = {
3199     &tx_script_1_hdr,
3200     tx_script_1_iovec,
3201     OSSL_NELEM(tx_script_1_iovec),
3202     NULL, NULL,
3203     2,
3204     0
3205 };
3206
3207 static const struct tx_test_op tx_script_1[] = {
3208     TX_OP_PROVIDE_SECRET_INITIAL(tx_script_1_hdr.dst_conn_id, 0)
3209     TX_OP_WRITE_CHECK(1)
3210     TX_OP_END
3211 };
3212
3213 /* 2. RFC 9001 - A.3 Server Initial */
3214 static const unsigned char tx_script_2_body[] = {
3215     0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x40, 0x5a, 0x02, 0x00, 0x00,
3216     0x56, 0x03, 0x03, 0xee, 0xfc, 0xe7, 0xf7, 0xb3, 0x7b, 0xa1, 0xd1, 0x63,
3217     0x2e, 0x96, 0x67, 0x78, 0x25, 0xdd, 0xf7, 0x39, 0x88, 0xcf, 0xc7, 0x98,
3218     0x25, 0xdf, 0x56, 0x6d, 0xc5, 0x43, 0x0b, 0x9a, 0x04, 0x5a, 0x12, 0x00,
3219     0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00,
3220     0x20, 0x9d, 0x3c, 0x94, 0x0d, 0x89, 0x69, 0x0b, 0x84, 0xd0, 0x8a, 0x60,
3221     0x99, 0x3c, 0x14, 0x4e, 0xca, 0x68, 0x4d, 0x10, 0x81, 0x28, 0x7c, 0x83,
3222     0x4d, 0x53, 0x11, 0xbc, 0xf3, 0x2b, 0xb9, 0xda, 0x1a, 0x00, 0x2b, 0x00,
3223     0x02, 0x03, 0x04
3224 };
3225
3226 static const unsigned char tx_script_2_dgram[] = {
3227
3228     0xcf, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a,
3229     0x42, 0x62, 0xb5, 0x00, 0x40, 0x75, 0xc0, 0xd9, 0x5a, 0x48, 0x2c, 0xd0,
3230     0x99, 0x1c, 0xd2, 0x5b, 0x0a, 0xac, 0x40, 0x6a, 0x58, 0x16, 0xb6, 0x39,
3231     0x41, 0x00, 0xf3, 0x7a, 0x1c, 0x69, 0x79, 0x75, 0x54, 0x78, 0x0b, 0xb3,
3232     0x8c, 0xc5, 0xa9, 0x9f, 0x5e, 0xde, 0x4c, 0xf7, 0x3c, 0x3e, 0xc2, 0x49,
3233     0x3a, 0x18, 0x39, 0xb3, 0xdb, 0xcb, 0xa3, 0xf6, 0xea, 0x46, 0xc5, 0xb7,
3234     0x68, 0x4d, 0xf3, 0x54, 0x8e, 0x7d, 0xde, 0xb9, 0xc3, 0xbf, 0x9c, 0x73,
3235     0xcc, 0x3f, 0x3b, 0xde, 0xd7, 0x4b, 0x56, 0x2b, 0xfb, 0x19, 0xfb, 0x84,
3236     0x02, 0x2f, 0x8e, 0xf4, 0xcd, 0xd9, 0x37, 0x95, 0xd7, 0x7d, 0x06, 0xed,
3237     0xbb, 0x7a, 0xaf, 0x2f, 0x58, 0x89, 0x18, 0x50, 0xab, 0xbd, 0xca, 0x3d,
3238     0x20, 0x39, 0x8c, 0x27, 0x64, 0x56, 0xcb, 0xc4, 0x21, 0x58, 0x40, 0x7d,
3239     0xd0, 0x74, 0xee
3240 };
3241
3242 static QUIC_PKT_HDR tx_script_2_hdr = {
3243     QUIC_PKT_TYPE_INITIAL,      /* type */
3244     0,                          /* spin bit */
3245     0,                          /* key phase */
3246     2,                          /* PN length */
3247     0,                          /* partial */
3248     0,                          /* fixed */
3249     0,                          /* unused */
3250     0,                          /* reserved */
3251     1,                          /* version */
3252     { 0, {0} },                 /* DCID */
3253     {8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5}}, /* SCID */
3254     { 0 },                      /* PN */
3255     NULL, 0,                    /* Token */
3256     5555, NULL                  /* Len/Data */
3257 };
3258
3259 static const OSSL_QTX_IOVEC tx_script_2_iovec[] = {
3260     { tx_script_2_body, sizeof(tx_script_2_body) }
3261 };
3262
3263 static const OSSL_QTX_PKT tx_script_2_pkt = {
3264     &tx_script_2_hdr,
3265     tx_script_2_iovec,
3266     OSSL_NELEM(tx_script_2_iovec),
3267     NULL, NULL,
3268     1,
3269     0
3270 };
3271
3272 static const struct tx_test_op tx_script_2[] = {
3273     TX_OP_PROVIDE_SECRET_INITIAL(tx_script_1_hdr.dst_conn_id, 1)
3274     TX_OP_WRITE_CHECK(2)
3275     TX_OP_END
3276 };
3277
3278 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
3279 /* 3. RFC 9001 - A.5 ChaCha20-Poly1305 Short Header Packet */
3280 static const unsigned char tx_script_3_body[] = {
3281     0x01
3282 };
3283
3284 static const unsigned char tx_script_3_dgram[] = {
3285     0x4c, 0xfe, 0x41, 0x89, 0x65, 0x5e, 0x5c, 0xd5, 0x5c, 0x41, 0xf6, 0x90,
3286     0x80, 0x57, 0x5d, 0x79, 0x99, 0xc2, 0x5a, 0x5b, 0xfb
3287 };
3288 static const unsigned char tx_script_3_secret[] = {
3289     0x9a, 0xc3, 0x12, 0xa7, 0xf8, 0x77, 0x46, 0x8e, 0xbe, 0x69, 0x42, 0x27,
3290     0x48, 0xad, 0x00, 0xa1, 0x54, 0x43, 0xf1, 0x82, 0x03, 0xa0, 0x7d, 0x60,
3291     0x60, 0xf6, 0x88, 0xf3, 0x0f, 0x21, 0x63, 0x2b
3292 };
3293
3294 static QUIC_PKT_HDR tx_script_3_hdr = {
3295     QUIC_PKT_TYPE_1RTT,         /* type */
3296     0,                          /* spin bit */
3297     0,                          /* key phase */
3298     3,                          /* PN length */
3299     0,                          /* partial */
3300     0,                          /* fixed */
3301     0,                          /* unused */
3302     0,                          /* reserved */
3303     0,                          /* version */
3304     { 0, {0} },                 /* DCID */
3305     { 0, {0} },                 /* SCID */
3306     { 0 },                      /* PN */
3307     NULL, 0,                    /* Token */
3308     5555, NULL                  /* Len/Data */
3309 };
3310
3311 static const OSSL_QTX_IOVEC tx_script_3_iovec[] = {
3312     { tx_script_3_body, sizeof(tx_script_3_body) }
3313 };
3314
3315 static const OSSL_QTX_PKT tx_script_3_pkt = {
3316     &tx_script_3_hdr,
3317     tx_script_3_iovec,
3318     OSSL_NELEM(tx_script_3_iovec),
3319     NULL, NULL,
3320     654360564,
3321     0
3322 };
3323
3324 static const struct tx_test_op tx_script_3[] = {
3325     TX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_CHACHA20POLY1305, tx_script_3_secret)
3326     TX_OP_WRITE_CHECK(3)
3327     TX_OP_END
3328 };
3329 #endif /* !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) */
3330
3331 /* 4. Real World - AES-128-GCM Key Update */
3332 static const unsigned char tx_script_4_secret[] = {
3333     0x70, 0x82, 0xc0, 0x45, 0x61, 0x4d, 0xfe, 0x04, 0x76, 0xa6, 0x4e, 0xf0,
3334     0x38, 0xe6, 0x63, 0xd9, 0xdd, 0x4a, 0x75, 0x16, 0xa8, 0xa0, 0x06, 0x5a,
3335     0xf2, 0x56, 0xfd, 0x84, 0x78, 0xfd, 0xf6, 0x5e
3336 };
3337
3338 static const unsigned char tx_script_4a_body[] = {
3339     0x02, 0x03, 0x09, 0x00, 0x03, 0x0c, 0x00, 0x36, 0x49, 0x27, 0x6d, 0x20,
3340     0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f, 0x6e,
3341     0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65,
3342 };
3343
3344 static const unsigned char tx_script_4a_dgram[] = {
3345     0x47, 0x6e, 0x4e, 0xbd, 0x49, 0x7e, 0xbd, 0x15, 0x1c, 0xd1, 0x3e, 0xc8,
3346     0xcd, 0x43, 0x87, 0x6b, 0x84, 0xdb, 0xeb, 0x06, 0x8b, 0x8a, 0xae, 0x37,
3347     0xed, 0x9c, 0xeb, 0xbc, 0xcf, 0x0d, 0x3c, 0xf0, 0xa1, 0x6f, 0xee, 0xd2,
3348     0x7c, 0x07, 0x6e, 0xd1, 0xbe, 0x40, 0x6a, 0xd4, 0x53, 0x38, 0x9e, 0x63,
3349     0xb5, 0xde, 0x35, 0x09, 0xb2, 0x78, 0x94, 0xe4, 0x2b, 0x37
3350 };
3351
3352 static QUIC_PKT_HDR tx_script_4a_hdr = {
3353     QUIC_PKT_TYPE_1RTT,         /* type */
3354     0,                          /* spin bit */
3355     0,                          /* key phase */
3356     2,                          /* PN length */
3357     0,                          /* partial */
3358     0,                          /* fixed */
3359     0,                          /* unused */
3360     0,                          /* reserved */
3361     0,                          /* version */
3362     { 4, {0x6e, 0x4e, 0xbd, 0x49} }, /* DCID */
3363     { 0, {0} },                 /* SCID */
3364     { 0 },                      /* PN */
3365     NULL, 0,                    /* Token */
3366     5555, NULL                  /* Len/Data */
3367 };
3368
3369 static const OSSL_QTX_IOVEC tx_script_4a_iovec[] = {
3370     { tx_script_4a_body, sizeof(tx_script_4a_body) }
3371 };
3372
3373 static const OSSL_QTX_PKT tx_script_4a_pkt = {
3374     &tx_script_4a_hdr,
3375     tx_script_4a_iovec,
3376     OSSL_NELEM(tx_script_4a_iovec),
3377     NULL, NULL,
3378     4,
3379     0
3380 };
3381
3382 static const unsigned char tx_script_4b_body[] = {
3383     0x02, 0x04, 0x07, 0x00, 0x00, 0x0c, 0x00, 0x40, 0x51, 0x49, 0x27, 0x6d,
3384     0x20, 0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f,
3385     0x6e, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65,
3386 };
3387
3388 static const unsigned char tx_script_4b_dgram[] = {
3389     0x58, 0x6e, 0x4e, 0xbd, 0x49, 0xa4, 0x43, 0x33, 0xea, 0x11, 0x3a, 0x6c,
3390     0xf5, 0x20, 0xef, 0x55, 0x8d, 0x25, 0xe2, 0x3b, 0x0e, 0x8c, 0xea, 0x17,
3391     0xfc, 0x2b, 0x7a, 0xab, 0xfa, 0x3d, 0x07, 0xda, 0xa7, 0x7c, 0xc7, 0x47,
3392     0x82, 0x02, 0x46, 0x40, 0x4f, 0x01, 0xad, 0xb2, 0x9d, 0x97, 0xdb, 0xfc,
3393     0x9c, 0x4b, 0x46, 0xb1, 0x5a, 0x7f, 0x0b, 0x12, 0xaf, 0x49, 0xdf,
3394 };
3395
3396 static QUIC_PKT_HDR tx_script_4b_hdr = {
3397     QUIC_PKT_TYPE_1RTT,         /* type */
3398     0,                          /* spin bit */
3399     1,                          /* key phase */
3400     2,                          /* PN length */
3401     0,                          /* partial */
3402     0,                          /* fixed */
3403     0,                          /* unused */
3404     0,                          /* reserved */
3405     0,                          /* version */
3406     { 4, {0x6e, 0x4e, 0xbd, 0x49} }, /* DCID */
3407     { 0, {0} },                 /* SCID */
3408     { 0 },                      /* PN */
3409     NULL, 0,                    /* Token */
3410     5555, NULL                  /* Len/Data */
3411 };
3412
3413 static const OSSL_QTX_IOVEC tx_script_4b_iovec[] = {
3414     { tx_script_4b_body, sizeof(tx_script_4b_body) }
3415 };
3416
3417 static const OSSL_QTX_PKT tx_script_4b_pkt = {
3418     &tx_script_4b_hdr,
3419     tx_script_4b_iovec,
3420     OSSL_NELEM(tx_script_4b_iovec),
3421     NULL, NULL,
3422     5,
3423     0
3424 };
3425
3426 static const unsigned char tx_script_4c_body[] = {
3427     0x02, 0x09, 0x0e, 0x00, 0x00, 0x0c, 0x00, 0x40, 0xd8, 0x49, 0x27, 0x6d,
3428     0x20, 0x68, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x77, 0x6f,
3429     0x6e, 0x64, 0x65, 0x72, 0x66, 0x75, 0x6c, 0x20, 0x74, 0x69, 0x6d, 0x65,
3430 };
3431
3432 static const unsigned char tx_script_4c_dgram[] = {
3433     0x49, 0x6e, 0x4e, 0xbd, 0x49, 0x4d, 0xd9, 0x85, 0xba, 0x26, 0xfb, 0x68,
3434     0x83, 0x9b, 0x94, 0x34, 0x7d, 0xc1, 0x7a, 0x05, 0xb7, 0x38, 0x43, 0x21,
3435     0xe2, 0xec, 0x2b, 0xc1, 0x81, 0x74, 0x2d, 0xda, 0x24, 0xba, 0xbd, 0x99,
3436     0x69, 0xd2, 0x56, 0xfa, 0xae, 0x29, 0x24, 0xb2, 0xaa, 0xda, 0xbd, 0x82,
3437     0x80, 0xf1, 0xbb, 0x6a, 0xfd, 0xae, 0xda, 0x0e, 0x09, 0xcf, 0x09,
3438 };
3439
3440 static QUIC_PKT_HDR tx_script_4c_hdr = {
3441     QUIC_PKT_TYPE_1RTT,         /* type */
3442     0,                          /* spin bit */
3443     0,                          /* key phase */
3444     2,                          /* PN length */
3445     0,                          /* partial */
3446     0,                          /* fixed */
3447     0,                          /* unused */
3448     0,                          /* reserved */
3449     0,                          /* version */
3450     { 4, {0x6e, 0x4e, 0xbd, 0x49} }, /* DCID */
3451     { 0, {0} },                 /* SCID */
3452     { 0 },                      /* PN */
3453     NULL, 0,                    /* Token */
3454     5555, NULL                  /* Len/Data */
3455 };
3456
3457 static const OSSL_QTX_IOVEC tx_script_4c_iovec[] = {
3458     { tx_script_4c_body, sizeof(tx_script_4c_body) }
3459 };
3460
3461 static const OSSL_QTX_PKT tx_script_4c_pkt = {
3462     &tx_script_4c_hdr,
3463     tx_script_4c_iovec,
3464     OSSL_NELEM(tx_script_4c_iovec),
3465     NULL, NULL,
3466     10,
3467     0
3468 };
3469
3470 static const struct tx_test_op tx_script_4[] = {
3471     TX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, tx_script_4_secret)
3472     TX_OP_WRITE_CHECK(4a)
3473     TX_OP_KEY_UPDATE()
3474     TX_OP_WRITE_CHECK(4b)
3475     TX_OP_KEY_UPDATE()
3476     TX_OP_WRITE_CHECK(4c)
3477     TX_OP_END
3478 };
3479
3480 /* 5. Real World - Retry Packet */
3481 static const unsigned char tx_script_5_body[] = {
3482     /* Retry Token */
3483     0x92, 0xe7, 0xc6, 0xd8, 0x09, 0x65, 0x72, 0x55, 0xe5, 0xe2, 0x73, 0x04,
3484     0xf3, 0x07, 0x5b, 0x21, 0x9f, 0x50, 0xcb, 0xbc, 0x79, 0xc5, 0x77, 0x5a,
3485     0x29, 0x43, 0x65, 0x49, 0xf0, 0x6e, 0xc1, 0xc0, 0x3a, 0xe8, 0xca, 0xd2,
3486     0x44, 0x69, 0xdd, 0x23, 0x31, 0x93, 0x52, 0x02, 0xf7, 0x42, 0x07, 0x78,
3487     0xa1, 0x81, 0x61, 0x9c, 0x39, 0x07, 0x18, 0x69, 0x6e, 0x4f, 0xdc, 0xa0,
3488     0xbe, 0x4b, 0xe5, 0xf2, 0xe9, 0xd2, 0xa4, 0xa7, 0x34, 0x55, 0x5e, 0xf3,
3489     0xf8, 0x9c, 0x49, 0x8f, 0x0c, 0xc8, 0xb2, 0x75, 0x4b, 0x4d, 0x2f, 0xfe,
3490     0x05, 0x5a, 0xdd, 0x4b, 0xe6, 0x14, 0xb4, 0xd2, 0xc0, 0x93, 0x6e, 0x0e,
3491     0x84, 0x41, 0x4d, 0x31,
3492     /* Retry Integrity Tag */
3493     0x43, 0x8e, 0xab, 0xcd, 0xce, 0x24, 0x44, 0xc2, 0x20, 0xe1, 0xe2, 0xc8,
3494     0xae, 0xa3, 0x8d, 0x4e, 
3495 };
3496
3497 static const unsigned char tx_script_5_dgram[] = {
3498     0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0xa9, 0x20, 0xcc, 0xc2, 0x92,
3499     0xe7, 0xc6, 0xd8, 0x09, 0x65, 0x72, 0x55, 0xe5, 0xe2, 0x73, 0x04, 0xf3,
3500     0x07, 0x5b, 0x21, 0x9f, 0x50, 0xcb, 0xbc, 0x79, 0xc5, 0x77, 0x5a, 0x29,
3501     0x43, 0x65, 0x49, 0xf0, 0x6e, 0xc1, 0xc0, 0x3a, 0xe8, 0xca, 0xd2, 0x44,
3502     0x69, 0xdd, 0x23, 0x31, 0x93, 0x52, 0x02, 0xf7, 0x42, 0x07, 0x78, 0xa1,
3503     0x81, 0x61, 0x9c, 0x39, 0x07, 0x18, 0x69, 0x6e, 0x4f, 0xdc, 0xa0, 0xbe,
3504     0x4b, 0xe5, 0xf2, 0xe9, 0xd2, 0xa4, 0xa7, 0x34, 0x55, 0x5e, 0xf3, 0xf8,
3505     0x9c, 0x49, 0x8f, 0x0c, 0xc8, 0xb2, 0x75, 0x4b, 0x4d, 0x2f, 0xfe, 0x05,
3506     0x5a, 0xdd, 0x4b, 0xe6, 0x14, 0xb4, 0xd2, 0xc0, 0x93, 0x6e, 0x0e, 0x84,
3507     0x41, 0x4d, 0x31, 0x43, 0x8e, 0xab, 0xcd, 0xce, 0x24, 0x44, 0xc2, 0x20,
3508     0xe1, 0xe2, 0xc8, 0xae, 0xa3, 0x8d, 0x4e, 
3509 };
3510
3511 static QUIC_PKT_HDR tx_script_5_hdr = {
3512     QUIC_PKT_TYPE_RETRY,        /* type */
3513     0,                          /* spin bit */
3514     0,                          /* key phase */
3515     0,                          /* PN length */
3516     0,                          /* partial */
3517     0,                          /* fixed */
3518     0,                          /* unused */
3519     0,                          /* reserved */
3520     1,                          /* version */
3521     { 0, {0} },                 /* DCID */
3522     { 4, {0xa9, 0x20, 0xcc, 0xc2} },   /* SCID */
3523     { 0 },                      /* PN */
3524     NULL, 0,                    /* Token */
3525     5555, NULL                  /* Len/Data */
3526 };
3527
3528 static const OSSL_QTX_IOVEC tx_script_5_iovec[] = {
3529     { tx_script_5_body, sizeof(tx_script_5_body) }
3530 };
3531
3532 static const OSSL_QTX_PKT tx_script_5_pkt = {
3533     &tx_script_5_hdr,
3534     tx_script_5_iovec,
3535     OSSL_NELEM(tx_script_5_iovec),
3536     NULL, NULL,
3537     0,
3538     0
3539 };
3540
3541 static const struct tx_test_op tx_script_5[] = {
3542     TX_OP_WRITE_CHECK(5)
3543     TX_OP_END
3544 };
3545
3546 /* 6. Real World - Version Negotiation Packet */
3547 static const unsigned char tx_script_6_body[] = {
3548     0x00, 0x00, 0x00, 0x01,             /* Supported Version: 1 */
3549     0xaa, 0x9a, 0x3a, 0x9a              /* Supported Version: Random (GREASE) */
3550 };
3551
3552 static const unsigned char tx_script_6_dgram[] = {
3553     0x80,                               /* Long */
3554     0x00, 0x00, 0x00, 0x00,             /* Version 0 (Version Negotiation) */
3555     0x00,                               /* DCID */
3556     0x0c, 0x35, 0x3c, 0x1b, 0x97, 0xca, /* SCID */
3557     0xf8, 0x99, 0x11, 0x39, 0xad, 0x79,
3558     0x1f,
3559     0x00, 0x00, 0x00, 0x01,             /* Supported Version: 1 */
3560     0xaa, 0x9a, 0x3a, 0x9a              /* Supported Version: Random (GREASE) */
3561 };
3562
3563 static QUIC_PKT_HDR tx_script_6_hdr = {
3564     QUIC_PKT_TYPE_VERSION_NEG,  /* type */
3565     0,                          /* spin bit */
3566     0,                          /* key phase */
3567     0,                          /* PN length */
3568     0,                          /* partial */
3569     0,                          /* fixed */
3570     0,                          /* unused */
3571     0,                          /* reserved */
3572     0,                          /* version */
3573     { 0, {0} },                 /* DCID */
3574     { 12, {0x35, 0x3c, 0x1b, 0x97, 0xca, 0xf8, 0x99,
3575            0x11, 0x39, 0xad, 0x79, 0x1f} }, /* SCID */
3576     { 0 },                      /* PN */
3577     NULL, 0,                    /* Token */
3578     5555, NULL                  /* Len/Data */
3579 };
3580
3581 static const OSSL_QTX_IOVEC tx_script_6_iovec[] = {
3582     { tx_script_6_body, sizeof(tx_script_6_body) }
3583 };
3584
3585 static const OSSL_QTX_PKT tx_script_6_pkt = {
3586     &tx_script_6_hdr,
3587     tx_script_6_iovec,
3588     OSSL_NELEM(tx_script_6_iovec),
3589     NULL, NULL,
3590     0,
3591     0
3592 };
3593
3594 static const struct tx_test_op tx_script_6[] = {
3595     TX_OP_WRITE_CHECK(6)
3596     TX_OP_END
3597 };
3598
3599 static const struct tx_test_op *const tx_scripts[] = {
3600     tx_script_1,
3601     tx_script_2,
3602 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
3603     tx_script_3,
3604 #endif
3605     tx_script_4,
3606     tx_script_5,
3607     tx_script_6
3608 };
3609
3610 static int tx_run_script(const struct tx_test_op *script)
3611 {
3612     int testresult = 0;
3613     const struct tx_test_op *op = script;
3614     OSSL_QTX *qtx = NULL;
3615     BIO_MSG msg = {0};
3616     OSSL_QTX_ARGS args = {0};
3617
3618     args.mdpl = 1472;
3619
3620     if (!TEST_ptr(qtx = ossl_qtx_new(&args)))
3621         goto err;
3622
3623     for (; op->op != TX_TEST_OP_END; ++op)
3624         switch (op->op) {
3625             case TX_TEST_OP_PROVIDE_SECRET:
3626                 if (!TEST_true(ossl_qtx_provide_secret(qtx, op->enc_level,
3627                                                        op->suite_id, NULL,
3628                                                        op->buf, op->buf_len)))
3629                     goto err;
3630                 break;
3631             case TX_TEST_OP_PROVIDE_SECRET_INITIAL:
3632                 if (!TEST_true(ossl_quic_provide_initial_secret(NULL, NULL,
3633                                                                 op->dcid,
3634                                                                 (int)op->suite_id,
3635                                                                 NULL, qtx)))
3636                     goto err;
3637                 break;
3638             case TX_TEST_OP_DISCARD_EL:
3639                 if (!TEST_true(ossl_qtx_discard_enc_level(qtx, op->enc_level)))
3640                     goto err;
3641                 break;
3642             case TX_TEST_OP_WRITE:
3643                 {
3644                     uint32_t enc_level
3645                         = ossl_quic_pkt_type_to_enc_level(op->pkt->hdr->type);
3646                     uint64_t old_value = 0, new_value, max_value;
3647
3648                     if (enc_level < QUIC_ENC_LEVEL_NUM) { /* encrypted packet */
3649                         max_value = ossl_qtx_get_max_epoch_pkt_count(qtx, enc_level);
3650
3651                         if (!TEST_uint64_t_lt(max_value, UINT64_MAX))
3652                             goto err;
3653
3654                         old_value = ossl_qtx_get_cur_epoch_pkt_count(qtx, enc_level);
3655                         if (!TEST_uint64_t_lt(old_value, UINT64_MAX))
3656                             goto err;
3657                     }
3658
3659                     if (!TEST_true(ossl_qtx_write_pkt(qtx, op->pkt)))
3660                         goto err;
3661
3662                     if (enc_level < QUIC_ENC_LEVEL_NUM) {
3663                         new_value = ossl_qtx_get_cur_epoch_pkt_count(qtx, enc_level);
3664                         if (!TEST_uint64_t_eq(old_value + 1, new_value))
3665                             goto err;
3666                     }
3667                 }
3668                 break;
3669             case TX_TEST_OP_CHECK_DGRAM:
3670                 if (!TEST_true(ossl_qtx_pop_net(qtx, &msg)))
3671                     goto err;
3672
3673                 if (!TEST_mem_eq(msg.data, msg.data_len, op->buf, op->buf_len))
3674                     goto err;
3675
3676                 break;
3677             case TX_TEST_OP_CHECK_NO_DGRAM:
3678                 if (!TEST_false(ossl_qtx_pop_net(qtx, &msg)))
3679                     goto err;
3680                 break;
3681             case TX_TEST_OP_KEY_UPDATE:
3682                 if (!TEST_true(ossl_qtx_trigger_key_update(qtx)))
3683                     goto err;
3684                 break;
3685             default:
3686                 OPENSSL_assert(0);
3687                 goto err;
3688         }
3689
3690     testresult = 1;
3691 err:
3692     if (qtx != NULL)
3693         ossl_qtx_free(qtx);
3694
3695     return testresult;
3696 }
3697
3698 static int test_tx_script(int idx)
3699 {
3700     return tx_run_script(tx_scripts[idx]);
3701 }
3702
3703 int setup_tests(void)
3704 {
3705     ADD_ALL_TESTS(test_rx_script, OSSL_NELEM(rx_scripts));
3706     /*
3707      * Each instance of this test is executed multiple times to get enough
3708      * statistical coverage for our statistical test, as well as for each
3709      * supported key type.
3710      *
3711      * We call the statistical test as the last index in the wire_pkt_hdr
3712      * test rather than as a separate case, as it needs to execute last
3713      * and otherwise random test ordering will cause itt to randomly fail.
3714      */
3715     ADD_ALL_TESTS(test_wire_pkt_hdr, NUM_WIRE_PKT_HDR_TESTS + 1);
3716     ADD_ALL_TESTS(test_tx_script, OSSL_NELEM(tx_scripts));
3717     return 1;
3718 }