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