]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/quic_record_test.c
QUIC Record Layer (Refactor and TX Side)
[thirdparty/openssl.git] / test / quic_record_test.c
1 /*
2 * Copyright 2022 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_record_tx.h"
12 #include "testutil.h"
13
14 static const QUIC_CONN_ID empty_conn_id = {0, {0}};
15
16 #define RX_TEST_OP_END 0 /* end of script */
17 #define RX_TEST_OP_SET_SCID_LEN 1 /* change SCID length */
18 #define RX_TEST_OP_SET_INIT_LARGEST_PN 2 /* set initial largest PN */
19 #define RX_TEST_OP_ADD_RX_DCID 3 /* register an RX DCID */
20 #define RX_TEST_OP_INJECT 4 /* inject a datagram into demux */
21 #define RX_TEST_OP_PROVIDE_SECRET 5 /* provide RX secret */
22 #define RX_TEST_OP_PROVIDE_SECRET_INITIAL 6 /* provide RX secret for initial */
23 #define RX_TEST_OP_DISCARD_EL 7 /* discard an encryption level */
24 #define RX_TEST_OP_CHECK_PKT 8 /* read packet, compare to expected */
25 #define RX_TEST_OP_CHECK_NO_PKT 9 /* check no packet is available to read */
26
27 struct rx_test_op {
28 unsigned char op;
29 const unsigned char *buf;
30 size_t buf_len;
31 const QUIC_PKT_HDR *hdr;
32 uint32_t enc_level, suite_id;
33 QUIC_PN largest_pn;
34 const QUIC_CONN_ID *dcid;
35 int (*new_qrx)(QUIC_DEMUX **demux, OSSL_QRX **qrx);
36 };
37
38 #define RX_OP_END \
39 { RX_TEST_OP_END }
40 #define RX_OP_SET_SCID_LEN(scid_len) \
41 { RX_TEST_OP_SET_SCID_LEN, NULL, 0, NULL, (scid_len), 0, 0, NULL, NULL },
42 #define RX_OP_SET_INIT_LARGEST_PN(largest_pn) \
43 { RX_TEST_OP_SET_INIT_LARGEST_PN, NULL, 0, NULL, 0, 0, (largest_pn), NULL, NULL },
44 #define RX_OP_ADD_RX_DCID(dcid) \
45 { RX_TEST_OP_ADD_RX_DCID, NULL, 0, NULL, 0, 0, 0, &(dcid), NULL },
46 #define RX_OP_INJECT(dgram) \
47 { RX_TEST_OP_INJECT, (dgram), sizeof(dgram), NULL, 0, 0, 0, NULL },
48 #define RX_OP_PROVIDE_SECRET(el, suite, key) \
49 { \
50 RX_TEST_OP_PROVIDE_SECRET, (key), sizeof(key), \
51 NULL, (el), (suite), 0, NULL, NULL \
52 },
53 #define RX_OP_PROVIDE_SECRET_INITIAL(dcid) \
54 { RX_TEST_OP_PROVIDE_SECRET_INITIAL, NULL, 0, NULL, 0, 0, 0, &(dcid), NULL },
55 #define RX_OP_DISCARD_EL(el) \
56 { RX_TEST_OP_DISCARD_EL, NULL, 0, NULL, (el), 0, 0, NULL, NULL },
57 #define RX_OP_CHECK_PKT(expect_hdr, expect_body) \
58 { \
59 RX_TEST_OP_CHECK_PKT, (expect_body), sizeof(expect_body), \
60 &(expect_hdr), 0, 0, 0, NULL, NULL \
61 },
62 #define RX_OP_CHECK_NO_PKT() \
63 { RX_TEST_OP_CHECK_NO_PKT, NULL, 0, NULL, 0, 0, 0, NULL, NULL },
64
65 #define RX_OP_INJECT_N(n) \
66 RX_OP_INJECT(rx_script_##n##_in)
67 #define RX_OP_CHECK_PKT_N(n) \
68 RX_OP_CHECK_PKT(rx_script_##n##_expect_hdr, rx_script_##n##_body)
69
70 #define RX_OP_INJECT_CHECK(n) \
71 RX_OP_INJECT_N(n) \
72 RX_OP_CHECK_PKT_N(n)
73
74 /* 1. RFC 9001 - A.3 Server Initial */
75 static const unsigned char rx_script_1_in[] = {
76 0xcf, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a,
77 0x42, 0x62, 0xb5, 0x00, 0x40, 0x75, 0xc0, 0xd9, 0x5a, 0x48, 0x2c, 0xd0,
78 0x99, 0x1c, 0xd2, 0x5b, 0x0a, 0xac, 0x40, 0x6a, 0x58, 0x16, 0xb6, 0x39,
79 0x41, 0x00, 0xf3, 0x7a, 0x1c, 0x69, 0x79, 0x75, 0x54, 0x78, 0x0b, 0xb3,
80 0x8c, 0xc5, 0xa9, 0x9f, 0x5e, 0xde, 0x4c, 0xf7, 0x3c, 0x3e, 0xc2, 0x49,
81 0x3a, 0x18, 0x39, 0xb3, 0xdb, 0xcb, 0xa3, 0xf6, 0xea, 0x46, 0xc5, 0xb7,
82 0x68, 0x4d, 0xf3, 0x54, 0x8e, 0x7d, 0xde, 0xb9, 0xc3, 0xbf, 0x9c, 0x73,
83 0xcc, 0x3f, 0x3b, 0xde, 0xd7, 0x4b, 0x56, 0x2b, 0xfb, 0x19, 0xfb, 0x84,
84 0x02, 0x2f, 0x8e, 0xf4, 0xcd, 0xd9, 0x37, 0x95, 0xd7, 0x7d, 0x06, 0xed,
85 0xbb, 0x7a, 0xaf, 0x2f, 0x58, 0x89, 0x18, 0x50, 0xab, 0xbd, 0xca, 0x3d,
86 0x20, 0x39, 0x8c, 0x27, 0x64, 0x56, 0xcb, 0xc4, 0x21, 0x58, 0x40, 0x7d,
87 0xd0, 0x74, 0xee
88 };
89
90 static const unsigned char rx_script_1_body[] = {
91 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x40, 0x5a, 0x02, 0x00, 0x00,
92 0x56, 0x03, 0x03, 0xee, 0xfc, 0xe7, 0xf7, 0xb3, 0x7b, 0xa1, 0xd1, 0x63,
93 0x2e, 0x96, 0x67, 0x78, 0x25, 0xdd, 0xf7, 0x39, 0x88, 0xcf, 0xc7, 0x98,
94 0x25, 0xdf, 0x56, 0x6d, 0xc5, 0x43, 0x0b, 0x9a, 0x04, 0x5a, 0x12, 0x00,
95 0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00,
96 0x20, 0x9d, 0x3c, 0x94, 0x0d, 0x89, 0x69, 0x0b, 0x84, 0xd0, 0x8a, 0x60,
97 0x99, 0x3c, 0x14, 0x4e, 0xca, 0x68, 0x4d, 0x10, 0x81, 0x28, 0x7c, 0x83,
98 0x4d, 0x53, 0x11, 0xbc, 0xf3, 0x2b, 0xb9, 0xda, 0x1a, 0x00, 0x2b, 0x00,
99 0x02, 0x03, 0x04
100 };
101
102 static const QUIC_CONN_ID rx_script_1_dcid = {
103 8, { 0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08 }
104 };
105
106 static const QUIC_PKT_HDR rx_script_1_expect_hdr = {
107 QUIC_PKT_TYPE_INITIAL,
108 0, 0, 2, 0, 1, 1, { 0, {0} },
109 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } },
110 { 0, 1, 0, 0 },
111 NULL, 0,
112 99, NULL
113 };
114
115 static const struct rx_test_op rx_script_1[] = {
116 RX_OP_SET_SCID_LEN(2)
117 RX_OP_SET_INIT_LARGEST_PN(0)
118 RX_OP_ADD_RX_DCID(empty_conn_id)
119 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_1_dcid)
120 RX_OP_INJECT_CHECK(1)
121 RX_OP_CHECK_NO_PKT()
122 RX_OP_END
123 };
124
125 /* 2. RFC 9001 - A.5 ChaCha20-Poly1305 Short Header Packet */
126 static const unsigned char rx_script_2_in[] = {
127 0x4c, 0xfe, 0x41, 0x89, 0x65, 0x5e, 0x5c, 0xd5, 0x5c, 0x41, 0xf6, 0x90,
128 0x80, 0x57, 0x5d, 0x79, 0x99, 0xc2, 0x5a, 0x5b, 0xfb
129 };
130
131 static const unsigned char rx_script_2_secret[] = {
132 0x9a, 0xc3, 0x12, 0xa7, 0xf8, 0x77, 0x46, 0x8e, 0xbe, 0x69, 0x42, 0x27,
133 0x48, 0xad, 0x00, 0xa1, 0x54, 0x43, 0xf1, 0x82, 0x03, 0xa0, 0x7d, 0x60,
134 0x60, 0xf6, 0x88, 0xf3, 0x0f, 0x21, 0x63, 0x2b
135 };
136
137 static const unsigned char rx_script_2_body[] = {
138 0x01
139 };
140
141 static const QUIC_PKT_HDR rx_script_2_expect_hdr = {
142 QUIC_PKT_TYPE_1RTT,
143 0, 0, 3, 0, 1, 0, {0, {0}}, {0, {0}},
144 {0x00, 0xbf, 0xf4, 0x00},
145 NULL, 0,
146 1, NULL
147 };
148
149 static const struct rx_test_op rx_script_2[] = {
150 RX_OP_SET_INIT_LARGEST_PN(654360560)
151 RX_OP_ADD_RX_DCID(empty_conn_id)
152 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_CHACHA20POLY1305,
153 rx_script_2_secret)
154 RX_OP_INJECT_CHECK(2)
155 RX_OP_CHECK_NO_PKT()
156 RX_OP_END
157 };
158
159 /* 3. Real World - Version Negotiation Response */
160 static const unsigned char rx_script_3_in[] = {
161 0xc7, /* Long; Random Bits */
162 0x00, 0x00, 0x00, 0x00, /* Version 0 (Version Negotiation) */
163 0x00, /* DCID */
164 0x0c, 0x35, 0x3c, 0x1b, 0x97, 0xca, /* SCID */
165 0xf8, 0x99, 0x11, 0x39, 0xad, 0x79,
166 0x1f,
167 0x00, 0x00, 0x00, 0x01, /* Supported Version: 1 */
168 0xaa, 0x9a, 0x3a, 0x9a /* Supported Version: Random (GREASE) */
169 };
170
171 static const QUIC_PKT_HDR rx_script_3_expect_hdr = {
172 QUIC_PKT_TYPE_VERSION_NEG,
173 0, /* Spin Bit */
174 0, /* Key Phase */
175 0, /* PN Length */
176 0, /* Partial */
177 1, /* Fixed */
178 0, /* Version */
179 {0, {0}}, /* DCID */
180 {12, {0x35, 0x3c, 0x1b, 0x97, 0xca, 0xf8, /* SCID */
181 0x99, 0x11, 0x39, 0xad, 0x79, 0x1f}},
182 {0}, /* PN */
183 NULL, 0, /* Token/Token Len */
184 8, NULL
185 };
186
187 static const unsigned char rx_script_3_body[] = {
188 0x00, 0x00, 0x00, 0x01,
189 0xaa, 0x9a, 0x3a, 0x9a
190 };
191
192 static const struct rx_test_op rx_script_3[] = {
193 RX_OP_ADD_RX_DCID(empty_conn_id)
194 RX_OP_INJECT_CHECK(3)
195 RX_OP_CHECK_NO_PKT()
196 RX_OP_END
197 };
198
199 /* 4. Real World - Retry (S2C) */
200 static const unsigned char rx_script_4_in[] = {
201 0xf0, /* Long; Retry */
202 0x00, 0x00, 0x00, 0x01, /* Version 1 */
203 0x00, /* DCID */
204 0x04, 0xad, 0x15, 0x3f, 0xae, /* SCID */
205 /* Retry Token, including 16-byte Retry Integrity Tag */
206 0xf6, 0x8b, 0x6e, 0xa3, 0xdc, 0x40, 0x38, 0xc6, 0xa5, 0x99, 0x1c, 0xa9,
207 0x77, 0xe6, 0x1d, 0x4f, 0x09, 0x36, 0x12, 0x26, 0x00, 0x56, 0x0b, 0x29,
208 0x7d, 0x5e, 0xda, 0x39, 0xc6, 0x61, 0x57, 0x69, 0x15, 0xff, 0x93, 0x39,
209 0x95, 0xf0, 0x57, 0xf1, 0xe5, 0x36, 0x08, 0xad, 0xd2, 0x75, 0xa9, 0x68,
210 0x29, 0xed, 0xaa, 0x03, 0x0e, 0x5f, 0xac, 0xbd, 0x26, 0x07, 0x95, 0x4e,
211 0x48, 0x61, 0x26, 0xc5, 0xe2, 0x6c, 0x60, 0xbf, 0xa8, 0x6f, 0x51, 0xbb,
212 0x1d, 0xf7, 0x98, 0x95, 0x3b, 0x2c, 0x50, 0x79, 0xcc, 0xde, 0x27, 0x84,
213 0x44, 0x9b, 0xb2, 0x4a, 0x94, 0x4d, 0x4d, 0x3d, 0xbc, 0x00, 0x9d, 0x69,
214 0xad, 0x45, 0x89, 0x04, 0x48, 0xca, 0x04, 0xf6, 0x3a, 0x62, 0xc1, 0x38,
215 0x9d, 0x82, 0xb3, 0x45, 0x62, 0x4c,
216 };
217
218 static const QUIC_PKT_HDR rx_script_4_expect_hdr = {
219 QUIC_PKT_TYPE_RETRY,
220 0, /* Spin Bit */
221 0, /* Key Phase */
222 0, /* PN Length */
223 0, /* Partial */
224 1, /* Fixed */
225 1, /* Version */
226 {0, {0}}, /* DCID */
227 {4, {0xad, 0x15, 0x3f, 0xae}}, /* SCID */
228 {0}, /* PN */
229 NULL, 0, /* Token/Token Len */
230 114, NULL
231 };
232
233 static const unsigned char rx_script_4_body[] = {
234 0xf6, 0x8b, 0x6e, 0xa3, 0xdc, 0x40, 0x38, 0xc6, 0xa5, 0x99, 0x1c, 0xa9,
235 0x77, 0xe6, 0x1d, 0x4f, 0x09, 0x36, 0x12, 0x26, 0x00, 0x56, 0x0b, 0x29,
236 0x7d, 0x5e, 0xda, 0x39, 0xc6, 0x61, 0x57, 0x69, 0x15, 0xff, 0x93, 0x39,
237 0x95, 0xf0, 0x57, 0xf1, 0xe5, 0x36, 0x08, 0xad, 0xd2, 0x75, 0xa9, 0x68,
238 0x29, 0xed, 0xaa, 0x03, 0x0e, 0x5f, 0xac, 0xbd, 0x26, 0x07, 0x95, 0x4e,
239 0x48, 0x61, 0x26, 0xc5, 0xe2, 0x6c, 0x60, 0xbf, 0xa8, 0x6f, 0x51, 0xbb,
240 0x1d, 0xf7, 0x98, 0x95, 0x3b, 0x2c, 0x50, 0x79, 0xcc, 0xde, 0x27, 0x84,
241 0x44, 0x9b, 0xb2, 0x4a, 0x94, 0x4d, 0x4d, 0x3d, 0xbc, 0x00, 0x9d, 0x69,
242 0xad, 0x45, 0x89, 0x04, 0x48, 0xca, 0x04, 0xf6, 0x3a, 0x62, 0xc1, 0x38,
243 0x9d, 0x82, 0xb3, 0x45, 0x62, 0x4c
244 };
245
246 static const struct rx_test_op rx_script_4[] = {
247 RX_OP_ADD_RX_DCID(empty_conn_id)
248 RX_OP_INJECT_CHECK(4)
249 RX_OP_CHECK_NO_PKT()
250 RX_OP_END
251 };
252
253 /*
254 * 5. Real World - S2C Multiple Packets
255 * - Initial, Handshake, 1-RTT (AES-128-GCM/SHA256)
256 */
257 static const QUIC_CONN_ID rx_script_5_c2s_init_dcid = {
258 4, {0xad, 0x15, 0x3f, 0xae}
259 };
260
261 static const unsigned char rx_script_5_handshake_secret[32] = {
262 0x5e, 0xc6, 0x4a, 0x4d, 0x0d, 0x40, 0x43, 0x3b, 0xd5, 0xbd, 0xe0, 0x19,
263 0x71, 0x47, 0x56, 0xf3, 0x59, 0x3a, 0xa6, 0xc9, 0x3e, 0xdc, 0x81, 0x1e,
264 0xc7, 0x72, 0x9d, 0x83, 0xd8, 0x8f, 0x88, 0x77
265 };
266
267 static const unsigned char rx_script_5_1rtt_secret[32] = {
268 0x53, 0xf2, 0x1b, 0x94, 0xa7, 0x65, 0xf7, 0x76, 0xfb, 0x06, 0x27, 0xaa,
269 0xd2, 0x3f, 0xe0, 0x9a, 0xbb, 0xcf, 0x99, 0x6f, 0x13, 0x2c, 0x6a, 0x37,
270 0x95, 0xf3, 0xda, 0x21, 0xcb, 0xcb, 0xa5, 0x26,
271 };
272
273 static const unsigned char rx_script_5_in[] = {
274 /* First Packet: Initial */
275 0xc4, /* Long, Initial, PN Length=2 bytes */
276 0x00, 0x00, 0x00, 0x01, /* Version */
277 0x00, /* DCID */
278 0x04, 0x83, 0xd0, 0x0a, 0x27, /* SCID */
279 0x00, /* Token Length */
280 0x41, 0xd2, /* Length (466) */
281 0xe3, 0xab, /* PN (0) */
282 0x22, 0x35, 0x34, 0x12, 0xcf, 0x20, 0x2b, 0x16, 0xaf, 0x08, 0xd4, 0xe0,
283 0x94, 0x8b, 0x1e, 0x62, 0xdf, 0x31, 0x61, 0xcc, 0xf9, 0xfa, 0x66, 0x4f,
284 0x18, 0x61, 0x07, 0xcb, 0x13, 0xd3, 0xf9, 0xbf, 0xe2, 0x8e, 0x25, 0x8d,
285 0xd1, 0xdf, 0x58, 0x9c, 0x05, 0x20, 0xf9, 0xf2, 0x01, 0x20, 0xe9, 0x39,
286 0xc3, 0x80, 0x77, 0xec, 0xa4, 0x57, 0xcf, 0x57, 0x8c, 0xdd, 0x68, 0x82,
287 0x91, 0xfe, 0x71, 0xa0, 0xfa, 0x56, 0x4c, 0xf2, 0xe7, 0x2b, 0xd0, 0xc0,
288 0xda, 0x81, 0xe2, 0x39, 0xb5, 0xf0, 0x0f, 0xd9, 0x07, 0xd5, 0x67, 0x09,
289 0x02, 0xf0, 0xff, 0x74, 0xb0, 0xa0, 0xd9, 0x3a, 0x7e, 0xb6, 0x57, 0x82,
290 0x47, 0x18, 0x66, 0xed, 0xe2, 0x18, 0x4d, 0xc2, 0x5c, 0x9f, 0x05, 0x09,
291 0x18, 0x24, 0x0e, 0x3f, 0x3d, 0xf9, 0x15, 0x8b, 0x08, 0xfd, 0x25, 0xe9,
292 0xc9, 0xb7, 0x8c, 0x18, 0x7b, 0xf3, 0x37, 0x58, 0xf0, 0xf0, 0xac, 0x33,
293 0x55, 0x3f, 0x39, 0xbc, 0x62, 0x03, 0x8a, 0xc0, 0xd6, 0xcc, 0x49, 0x47,
294 0xeb, 0x85, 0xb6, 0x72, 0xd7, 0xf8, 0xdc, 0x01, 0x32, 0xec, 0x1b, 0x4e,
295 0x38, 0x6e, 0x2c, 0xc5, 0x80, 0xf2, 0x43, 0x4a, 0xf5, 0xe5, 0xa2, 0xf8,
296 0x76, 0xa7, 0xa8, 0x57, 0x32, 0x67, 0x72, 0xeb, 0x82, 0xac, 0x3e, 0xc0,
297 0x15, 0x67, 0xac, 0x32, 0x19, 0x18, 0x0a, 0xef, 0x20, 0xa1, 0xe8, 0xaf,
298 0xac, 0x33, 0x87, 0x4c, 0x55, 0x05, 0x9b, 0x78, 0xf0, 0x3a, 0xce, 0x02,
299 0x28, 0x06, 0x84, 0x61, 0x97, 0xac, 0x87, 0x8f, 0x25, 0xe7, 0x1b, 0xa3,
300 0x02, 0x08, 0x4c, 0x2e, 0xef, 0xbd, 0x4f, 0x82, 0xe7, 0x37, 0x6c, 0x27,
301 0x6f, 0x85, 0xb4, 0xbc, 0x79, 0x38, 0x45, 0x80, 0x8a, 0xda, 0x2f, 0x11,
302 0x11, 0xac, 0x9c, 0xf3, 0x93, 0xc1, 0x49, 0x1b, 0x94, 0x12, 0x77, 0x07,
303 0xdc, 0xbf, 0xc2, 0xfd, 0x8b, 0xf6, 0xf1, 0x66, 0x1c, 0x7f, 0x07, 0xbf,
304 0x1f, 0xae, 0x27, 0x6c, 0x66, 0xe9, 0xa3, 0x64, 0x7a, 0x96, 0x78, 0x45,
305 0xfe, 0x4b, 0x8c, 0x6f, 0x7f, 0x03, 0x47, 0x3c, 0xd7, 0xf7, 0x63, 0x92,
306 0x58, 0x5b, 0x63, 0x83, 0x03, 0x05, 0xc3, 0x5d, 0x36, 0x62, 0x63, 0x5e,
307 0xcf, 0xfe, 0x0a, 0x29, 0xfa, 0xeb, 0xc8, 0xaf, 0xce, 0x31, 0x07, 0x6a,
308 0x09, 0x41, 0xc0, 0x2d, 0x98, 0x70, 0x05, 0x3b, 0x41, 0xfc, 0x7d, 0x61,
309 0xe0, 0x41, 0x7d, 0x13, 0x41, 0x51, 0x52, 0xb4, 0x78, 0xd5, 0x46, 0x51,
310 0x3b, 0xf1, 0xcd, 0xcc, 0x2e, 0x49, 0x30, 0x8b, 0x2a, 0xd2, 0xe6, 0x69,
311 0xb5, 0x6b, 0x7a, 0xf4, 0xbb, 0xd1, 0xf8, 0x4a, 0xe8, 0x53, 0x10, 0x46,
312 0x85, 0x8d, 0x66, 0x8e, 0x2b, 0xe8, 0x5d, 0xab, 0x7e, 0xfe, 0x5a, 0x79,
313 0xcf, 0xc5, 0x0c, 0x30, 0x9e, 0x98, 0x02, 0xb3, 0xa6, 0xd5, 0xfa, 0x25,
314 0xa8, 0xc8, 0xc1, 0xd9, 0x51, 0x60, 0x57, 0x5d, 0xfe, 0x75, 0x97, 0x05,
315 0xda, 0xbb, 0xc6, 0x6a, 0xbe, 0x5c, 0xa5, 0x65, 0x0a, 0x12, 0x33, 0x1c,
316 0xdf, 0xee, 0x08, 0xa9, 0x13, 0x13, 0x28, 0xce, 0x61, 0x59, 0xd1, 0x4e,
317 0xc7, 0x74, 0xfd, 0x64, 0xde, 0x08, 0xce, 0xda, 0x3f, 0xec, 0xad, 0xc9,
318 0xe1, 0xf9, 0x1f, 0x74, 0xf6, 0x86, 0x37, 0x6a, 0xa0, 0xc8, 0x0b, 0x1b,
319 0x94, 0x98, 0x86, 0x81, 0x3b, 0xfc, 0x47, 0x6c, 0xc9, 0x3e, 0x3c, 0x30,
320 0xc5, 0x9e, 0xb2, 0x32, 0x47, 0xf5, 0x0c, 0x6f,
321
322 /* Second Packet: Handshake */
323 0xe6, /* Long, Handshake, PN Length=2 bytes */
324 0x00, 0x00, 0x00, 0x01, /* Version */
325 0x00, /* DCID */
326 0x04, 0x83, 0xd0, 0x0a, 0x27, /* SCID */
327 0x42, 0x9c, /* Length (668) */
328 0x9c, 0x55, /* PN (0) */
329 0x55, 0xd4, 0x50, 0x02, 0x1a, 0x57, 0x84, 0x22, 0xcd, 0x01, 0xe5, 0x42,
330 0x1b, 0x1e, 0x06, 0xf1, 0x86, 0xe2, 0x90, 0xf8, 0x9c, 0x3d, 0xa2, 0x7c,
331 0xde, 0x2b, 0xc9, 0x2e, 0xcd, 0xa8, 0x4f, 0x5a, 0x20, 0xca, 0x96, 0xb6,
332 0x11, 0x4b, 0xc8, 0x71, 0x32, 0xb5, 0xc7, 0x1a, 0x69, 0x7f, 0x1e, 0x37,
333 0x49, 0xfb, 0x08, 0xce, 0x83, 0x5f, 0x02, 0x6d, 0x8a, 0x8f, 0xe7, 0x5d,
334 0xe1, 0x34, 0x31, 0x22, 0x53, 0x53, 0x32, 0xcb, 0x04, 0x21, 0xce, 0xbc,
335 0xa5, 0x1b, 0xdd, 0x4d, 0xd5, 0x1c, 0xd6, 0x5d, 0x88, 0x29, 0x5a, 0x19,
336 0x71, 0x6a, 0xc2, 0xfa, 0xb7, 0xb4, 0x7d, 0xd1, 0x72, 0x93, 0x8f, 0x7c,
337 0xb5, 0x36, 0x1b, 0xea, 0xf3, 0xf1, 0xd7, 0x6e, 0xd3, 0x91, 0x96, 0x62,
338 0x4d, 0xc6, 0xec, 0xb7, 0xb0, 0xb7, 0x9b, 0x95, 0x8b, 0x14, 0x8d, 0x1a,
339 0x0d, 0xb6, 0x3e, 0xec, 0xfe, 0x3b, 0x51, 0xea, 0x1a, 0x05, 0x14, 0x12,
340 0x93, 0x0e, 0x7e, 0xe6, 0xa2, 0xc5, 0x22, 0x87, 0x65, 0xf8, 0x5d, 0x3c,
341 0x55, 0x18, 0xcb, 0xe9, 0xef, 0x23, 0x43, 0xfe, 0xe8, 0x0d, 0xb2, 0x0f,
342 0xc5, 0xf4, 0xb3, 0xde, 0x0c, 0xea, 0xa4, 0x48, 0x8e, 0xbf, 0x1f, 0xc7,
343 0x99, 0x53, 0x8c, 0xc1, 0x3d, 0xba, 0xf4, 0x8e, 0x8e, 0x02, 0x52, 0xf6,
344 0x1f, 0xcf, 0x1d, 0xaa, 0xb3, 0xcb, 0x08, 0xc2, 0xe1, 0x70, 0x68, 0x74,
345 0x78, 0xa9, 0x30, 0x67, 0xba, 0x2b, 0xea, 0x35, 0x63, 0x47, 0xff, 0x29,
346 0x73, 0x29, 0xc6, 0xe8, 0x08, 0xa9, 0x1e, 0x8f, 0x28, 0x41, 0xa4, 0x24,
347 0x54, 0x26, 0x5f, 0x42, 0x77, 0xb1, 0x2b, 0x3d, 0x65, 0x67, 0x60, 0xa7,
348 0x23, 0x0d, 0xa7, 0xf4, 0xd6, 0xe9, 0x4e, 0x58, 0x43, 0x9f, 0x3c, 0x9e,
349 0x77, 0x61, 0xe5, 0x04, 0x4f, 0x73, 0xc9, 0x10, 0x79, 0xd0, 0xda, 0x3b,
350 0xc6, 0x19, 0x93, 0x9f, 0x48, 0x3b, 0x76, 0x38, 0xa1, 0x72, 0x49, 0x7d,
351 0x86, 0x7f, 0xe8, 0x1b, 0xa9, 0x5b, 0xc0, 0x47, 0xa0, 0x9c, 0x3f, 0x65,
352 0x60, 0x76, 0x59, 0xaf, 0x20, 0x2d, 0x40, 0xa6, 0x80, 0x49, 0x5a, 0x8f,
353 0x09, 0xf8, 0xf6, 0x97, 0xc1, 0xbd, 0xe1, 0x9f, 0x9b, 0xa2, 0x4c, 0x7b,
354 0x88, 0xac, 0xbe, 0x4b, 0x11, 0x28, 0xd7, 0x67, 0xe6, 0xad, 0xaf, 0xd0,
355 0xad, 0x01, 0x29, 0xa4, 0x4a, 0xc4, 0xb8, 0x2e, 0x42, 0x79, 0x24, 0x9e,
356 0xd5, 0x34, 0xae, 0x45, 0xf1, 0x0b, 0x38, 0x4a, 0x76, 0xfb, 0x50, 0xa2,
357 0x99, 0xc9, 0x5b, 0x6d, 0xc0, 0xb7, 0x55, 0xd8, 0x8d, 0x49, 0xdd, 0x1b,
358 0xb8, 0xec, 0x10, 0x57, 0x9e, 0x33, 0xb4, 0x10, 0x16, 0x19, 0xac, 0x69,
359 0xa2, 0x19, 0x1b, 0xd0, 0x77, 0x45, 0xeb, 0x49, 0x5c, 0xc5, 0x7c, 0xbe,
360 0x4b, 0x4a, 0x22, 0x5c, 0x3d, 0x0e, 0x6e, 0xe5, 0x4b, 0x36, 0x06, 0x63,
361 0x03, 0x97, 0xab, 0xed, 0xdc, 0xea, 0x64, 0xc2, 0x70, 0xb6, 0x7e, 0x35,
362 0xfb, 0x13, 0x66, 0x37, 0xa3, 0x3f, 0x28, 0x16, 0x6c, 0xe7, 0xd4, 0xe6,
363 0xca, 0x26, 0x0f, 0x19, 0xdd, 0x02, 0xae, 0xc1, 0xcf, 0x18, 0x7d, 0x56,
364 0xe6, 0x52, 0xf3, 0x37, 0xb5, 0x86, 0x9d, 0x1d, 0x55, 0xb3, 0x95, 0x19,
365 0x19, 0xa5, 0x44, 0x95, 0x81, 0xed, 0x02, 0x18, 0xf1, 0x85, 0x57, 0x78,
366 0x28, 0xc4, 0x9a, 0xba, 0xe8, 0x5e, 0x22, 0x8d, 0xc1, 0x7b, 0x2a, 0x8a,
367 0xc8, 0xb9, 0xdd, 0x82, 0xb2, 0x7b, 0x9f, 0x3d, 0xf5, 0x27, 0x2a, 0x48,
368 0x53, 0xc7, 0xa0, 0x70, 0x0e, 0x9d, 0x61, 0xaa, 0xe2, 0xad, 0x28, 0xf2,
369 0xb4, 0xfc, 0x56, 0x6b, 0x89, 0xe7, 0xf9, 0x51, 0xc9, 0xe9, 0xd3, 0x8a,
370 0x8c, 0x7e, 0x86, 0xdd, 0xba, 0x2f, 0x39, 0xbf, 0x26, 0x62, 0x23, 0xd6,
371 0x98, 0x6d, 0x3e, 0x72, 0xd7, 0x1b, 0xe1, 0x62, 0x94, 0x35, 0xe2, 0x18,
372 0x19, 0x46, 0xb8, 0x2c, 0xb5, 0x8f, 0x8f, 0xb0, 0x5b, 0x76, 0x7b, 0x7e,
373 0xb8, 0xc6, 0xb7, 0xe9, 0x4e, 0x9d, 0x30, 0x68, 0x03, 0x1e, 0x19, 0x73,
374 0xc5, 0x3e, 0x24, 0xe2, 0x95, 0x60, 0x1b, 0x27, 0x93, 0x7c, 0x17, 0xc2,
375 0xc6, 0xa3, 0xbd, 0xbd, 0x70, 0xc6, 0x60, 0x59, 0xc8, 0x5c, 0xd7, 0x9a,
376 0xc4, 0x29, 0xac, 0x0f, 0xaa, 0x0d, 0xa9, 0x92, 0xa3, 0x95, 0xd7, 0x0f,
377 0x6f, 0x74, 0x99, 0x9b, 0xc1, 0xd3, 0x68, 0x6d, 0xac, 0x82, 0x2d, 0x32,
378 0x41, 0x9e, 0x0c, 0xf7, 0x31, 0x59, 0x4c, 0x93, 0x1c, 0x3b, 0x71, 0x69,
379 0xcf, 0xc5, 0xca, 0x2b, 0xdf, 0xe7, 0xaa, 0xfd, 0x1d, 0x71, 0x01, 0x7e,
380 0x1c, 0x70, 0x62, 0x20, 0x61, 0xf8, 0x35, 0xc1, 0x71, 0xe7, 0x02, 0x0d,
381 0x88, 0x44, 0xd9, 0x00, 0xc5, 0xcc, 0x63, 0xe4, 0xf0, 0x86, 0xa7, 0xd0,
382 0xfe, 0xcc, 0xb7, 0x1d, 0xfc, 0x21, 0x61, 0x54, 0x15, 0xea, 0x81, 0x5e,
383 0xc0, 0x31, 0xfa, 0xbf, 0x7d, 0xb9, 0x3b, 0xa2, 0x1e, 0x42, 0x73, 0x05,
384 0x3c, 0xdb, 0x21, 0x59, 0x4f, 0x63,
385
386 /* Third Packet: 1-RTT */
387 0x5f, /* Short, 1-RTT, Spin=0, KP=0, PN Length=2 bytes */
388 0x68, 0x47, /* PN (0) */
389 0xa3, 0x3c, 0xa5, 0x27, 0x5e, 0xf9, 0x8d, 0xec, 0xea, 0x6c, 0x09, 0x18,
390 0x40, 0x80, 0xee, 0x9f, 0x6f, 0x73, 0x5c, 0x49, 0xe3, 0xec, 0xb7, 0x58,
391 0x05, 0x66, 0x8f, 0xa3, 0x52, 0x37, 0xa1, 0x22, 0x1f, 0xc6, 0x92, 0xd6,
392 0x59, 0x04, 0x99, 0xcb, 0x44, 0xef, 0x66, 0x05, 0x2d, 0xd0, 0x85, 0x24,
393 0xbb, 0xe3, 0xa1, 0xd1, 0xbe, 0xf7, 0x54, 0xad, 0x65, 0xf4, 0xd4, 0x59,
394 0x54, 0x87, 0x4e, 0x22, 0x4f, 0x06, 0x07, 0xa7, 0x8a, 0x14, 0x89, 0xd1,
395 0x3f, 0xd3, 0xe4, 0x6f, 0x71, 0x8f, 0x9a, 0xd2, 0x3b, 0x61, 0x0a, 0xba,
396 0x9a, 0x31, 0x56, 0xc7,
397 };
398
399 static const QUIC_PKT_HDR rx_script_5a_expect_hdr = {
400 QUIC_PKT_TYPE_INITIAL,
401 0, /* Spin Bit */
402 0, /* Key Phase */
403 2, /* PN Length */
404 0, /* Partial */
405 1, /* Fixed */
406 1, /* Version */
407 {0, {0}}, /* DCID */
408 {4, {0x83, 0xd0, 0x0a, 0x27}}, /* SCID */
409 {0}, /* PN */
410 NULL, 0, /* Token/Token Len */
411 448, NULL
412 };
413
414 static const unsigned char rx_script_5a_body[] = {
415 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x40, 0x5a, 0x02, 0x00,
445 0x00, 0x56, 0x03, 0x03, 0xe2, 0xd2, 0x0a, 0x3b, 0xa2, 0xc4, 0xd2, 0x29,
446 0xc8, 0xe8, 0xba, 0x23, 0x31, 0x88, 0x2c, 0x71, 0xeb, 0xba, 0x42, 0x5f,
447 0x94, 0xe9, 0x0a, 0x90, 0x35, 0x31, 0x1e, 0xca, 0xed, 0xf8, 0x8a, 0x8d,
448 0x00, 0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04,
449 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x96, 0x0b, 0x4b, 0x30,
450 0x66, 0x3a, 0x75, 0x01, 0x4a, 0xdc, 0x2a, 0x75, 0x1f, 0xce, 0x7a, 0x30,
451 0x9d, 0x00, 0xca, 0x20, 0xb4, 0xe0, 0x6b, 0x81, 0x23, 0x18, 0x0b, 0x20,
452 0x1f, 0x54, 0x86, 0x1d,
453 };
454
455 static const QUIC_PKT_HDR rx_script_5b_expect_hdr = {
456 QUIC_PKT_TYPE_HANDSHAKE,
457 0, /* Spin Bit */
458 0, /* Key Phase */
459 2, /* PN Length */
460 0, /* Partial */
461 1, /* Fixed */
462 1, /* Version */
463 {0, {0}}, /* DCID */
464 {4, {0x83, 0xd0, 0x0a, 0x27}}, /* SCID */
465 {0}, /* PN */
466 NULL, 0, /* Token/Token Len */
467 650, NULL
468 };
469
470 static const unsigned char rx_script_5b_body[] = {
471 0x06, 0x00, 0x42, 0x86, 0x08, 0x00, 0x00, 0x7d, 0x00, 0x7b, 0x00, 0x10,
472 0x00, 0x08, 0x00, 0x06, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x00, 0x39,
473 0x00, 0x6b, 0x4b, 0x20, 0x0b, 0x1b, 0xe1, 0x1f, 0xd0, 0x78, 0xc0, 0x69,
474 0x72, 0x9c, 0xe2, 0xf7, 0x05, 0x04, 0x80, 0x08, 0x00, 0x00, 0x06, 0x04,
475 0x80, 0x08, 0x00, 0x00, 0x07, 0x04, 0x80, 0x08, 0x00, 0x00, 0x04, 0x04,
476 0x80, 0x0c, 0x00, 0x00, 0x08, 0x02, 0x40, 0x64, 0x09, 0x02, 0x40, 0x64,
477 0x01, 0x04, 0x80, 0x00, 0x75, 0x30, 0x03, 0x02, 0x45, 0xac, 0x0b, 0x01,
478 0x1a, 0x0c, 0x00, 0x02, 0x10, 0x41, 0x94, 0x41, 0x8d, 0x0d, 0xfb, 0x60,
479 0x7b, 0xdc, 0xcc, 0xa2, 0x9c, 0x3e, 0xa5, 0xdf, 0x8d, 0x00, 0x08, 0x2d,
480 0x71, 0x8a, 0x38, 0xdf, 0xdd, 0xe0, 0x03, 0x0e, 0x01, 0x04, 0x0f, 0x04,
481 0x83, 0xd0, 0x0a, 0x27, 0x10, 0x04, 0xad, 0x15, 0x3f, 0xae, 0x20, 0x01,
482 0x00, 0x0b, 0x00, 0x01, 0x8f, 0x00, 0x00, 0x01, 0x8b, 0x00, 0x01, 0x86,
483 0x30, 0x82, 0x01, 0x82, 0x30, 0x82, 0x01, 0x29, 0xa0, 0x03, 0x02, 0x01,
484 0x02, 0x02, 0x14, 0x0a, 0x73, 0x0f, 0x86, 0x18, 0xf2, 0xc3, 0x30, 0x01,
485 0xd2, 0xc0, 0xc1, 0x62, 0x52, 0x13, 0xf1, 0x9c, 0x13, 0x39, 0xb5, 0x30,
486 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30,
487 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c,
488 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
489 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x38, 0x30, 0x32, 0x31, 0x32,
490 0x30, 0x30, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x39, 0x30,
491 0x31, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x30, 0x17, 0x31, 0x15,
492 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x6d, 0x61, 0x70,
493 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x30, 0x59, 0x30,
494 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08,
495 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04,
496 0x67, 0xf4, 0xd3, 0x8f, 0x15, 0x6d, 0xee, 0x85, 0xcc, 0x2a, 0x77, 0xfc,
497 0x0b, 0x8f, 0x9f, 0xcf, 0xa9, 0x95, 0x5d, 0x5b, 0xcd, 0xb7, 0x8b, 0xba,
498 0x31, 0x0a, 0x73, 0x62, 0xc5, 0xd0, 0x0e, 0x07, 0x90, 0xae, 0x38, 0x43,
499 0x79, 0xce, 0x5e, 0x33, 0xad, 0x31, 0xbf, 0x9f, 0x2a, 0x56, 0x83, 0xa5,
500 0x24, 0x16, 0xab, 0x0c, 0xf1, 0x64, 0xbe, 0xe4, 0x93, 0xb5, 0x89, 0xd6,
501 0x05, 0xe4, 0xf7, 0x7b, 0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06, 0x03,
502 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x02, 0x64, 0x0f, 0x55, 0x69,
503 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a, 0xd0, 0x48,
504 0x96, 0x9f, 0x60, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,
505 0x30, 0x16, 0x80, 0x14, 0x02, 0x64, 0x0f, 0x55, 0x69, 0x14, 0x91, 0x19,
506 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a, 0xd0, 0x48, 0x96, 0x9f, 0x60,
507 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05,
508 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48,
509 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30, 0x44, 0x02, 0x20,
510 0x0a, 0x82, 0x92, 0x6e, 0xd3, 0xc6, 0x66, 0xd9, 0xd3, 0x75, 0xff, 0x71,
511 0x3b, 0x61, 0x46, 0x21, 0x00, 0xe6, 0x21, 0x5d, 0x9c, 0x86, 0xe9, 0x65,
512 0x40, 0x4f, 0xeb, 0x70, 0x4f, 0x2c, 0xad, 0x00, 0x02, 0x20, 0x08, 0xc2,
513 0x07, 0x5d, 0x16, 0xfc, 0x54, 0x34, 0x2b, 0xb4, 0x18, 0x67, 0x44, 0x81,
514 0xc9, 0xa9, 0x67, 0x2e, 0xce, 0xa1, 0x02, 0x9f, 0x3b, 0xe5, 0x61, 0x16,
515 0x0b, 0x50, 0xf6, 0xa1, 0x50, 0x94, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x4a,
516 0x04, 0x03, 0x00, 0x46, 0x30, 0x44, 0x02, 0x20, 0x7d, 0x57, 0x17, 0x14,
517 0x46, 0x09, 0x95, 0x70, 0x09, 0x45, 0xe8, 0x9e, 0x5c, 0x87, 0x55, 0xd9,
518 0x08, 0xc6, 0x5e, 0x47, 0x73, 0x5e, 0xb1, 0xc9, 0xef, 0xcb, 0xe5, 0x7f,
519 0xcc, 0xb0, 0x28, 0xbc, 0x02, 0x20, 0x5d, 0xe4, 0x2b, 0x83, 0xd9, 0x78,
520 0x75, 0x45, 0xf3, 0x22, 0x2b, 0x38, 0xeb, 0x68, 0xe5, 0x71, 0x5d, 0xcb,
521 0xc3, 0x68, 0xb3, 0x0e, 0x7d, 0x5e, 0x1d, 0xc2, 0x1b, 0x8a, 0x62, 0x80,
522 0x48, 0x3e, 0x14, 0x00, 0x00, 0x20, 0x37, 0xcd, 0x55, 0xca, 0x3f, 0x4b,
523 0xf0, 0x95, 0xf8, 0xe4, 0xfe, 0x59, 0xab, 0xbc, 0xc1, 0x8f, 0x0c, 0x3f,
524 0x41, 0x59, 0xf6, 0x96, 0xdb, 0x75, 0xae, 0xe7, 0x86, 0x1a, 0x92, 0xa7,
525 0x53, 0x0a,
526 };
527
528 static const QUIC_PKT_HDR rx_script_5c_expect_hdr = {
529 QUIC_PKT_TYPE_1RTT,
530 0, /* Spin Bit */
531 0, /* Key Phase */
532 2, /* PN Length */
533 0, /* Partial */
534 1, /* Fixed */
535 0, /* Version */
536 {0, {0}}, /* DCID */
537 {0, {0}}, /* SCID */
538 {0}, /* PN */
539 NULL, 0, /* Token/Token Len */
540 72, NULL
541 };
542
543 static const unsigned char rx_script_5c_body[] = {
544 0x18, 0x03, 0x00, 0x04, 0x92, 0xec, 0xaa, 0xd6, 0x47, 0xd8, 0x8b, 0x56,
545 0x3b, 0x5f, 0x67, 0xe6, 0xb9, 0xb9, 0xca, 0x72, 0xca, 0xf2, 0x49, 0x7d,
546 0x18, 0x02, 0x00, 0x04, 0xa9, 0x6e, 0x9b, 0x84, 0x26, 0x43, 0x00, 0xc7,
547 0x55, 0x71, 0x67, 0x2e, 0x52, 0xdd, 0x47, 0xfd, 0x06, 0x51, 0x33, 0x08,
548 0x18, 0x01, 0x00, 0x04, 0x36, 0xd5, 0x1f, 0x06, 0x4e, 0xbf, 0xb4, 0xc9,
549 0xef, 0x97, 0x1e, 0x9a, 0x3c, 0xab, 0x1e, 0xfc, 0xb7, 0x90, 0xc3, 0x1a,
550 };
551
552 static const struct rx_test_op rx_script_5[] = {
553 RX_OP_ADD_RX_DCID(empty_conn_id)
554 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_5_c2s_init_dcid)
555 RX_OP_INJECT_N(5)
556 RX_OP_CHECK_PKT_N(5a)
557 RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
558 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
559 QRL_SUITE_AES128GCM, rx_script_5_handshake_secret)
560 RX_OP_CHECK_PKT_N(5b)
561 RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
562 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
563 QRL_SUITE_AES128GCM, rx_script_5_1rtt_secret)
564 RX_OP_CHECK_PKT_N(5c)
565 RX_OP_CHECK_NO_PKT()
566
567 /* Try injecting the packet again */
568 RX_OP_INJECT_N(5)
569 /*
570 * Initial packet is not output due to receiving a Handshake packet causing
571 * auto-discard of Initial keys
572 */
573 RX_OP_CHECK_PKT_N(5b)
574 RX_OP_CHECK_PKT_N(5c)
575 RX_OP_CHECK_NO_PKT()
576 /* Try again with discarded keys */
577 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
578 RX_OP_INJECT_N(5)
579 RX_OP_CHECK_PKT_N(5c)
580 RX_OP_CHECK_NO_PKT()
581 /* Try again */
582 RX_OP_INJECT_N(5)
583 RX_OP_CHECK_PKT_N(5c)
584 RX_OP_CHECK_NO_PKT()
585 /* Try again with discarded 1-RTT keys */
586 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
587 RX_OP_INJECT_N(5)
588 RX_OP_CHECK_NO_PKT()
589
590 /* Recreate QRL, test reading packets received before key */
591 RX_OP_SET_SCID_LEN(0)
592 RX_OP_ADD_RX_DCID(empty_conn_id)
593 RX_OP_INJECT_N(5)
594 RX_OP_CHECK_NO_PKT()
595 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_5_c2s_init_dcid)
596 RX_OP_CHECK_PKT_N(5a)
597 RX_OP_CHECK_NO_PKT()
598 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
599 QRL_SUITE_AES128GCM, rx_script_5_handshake_secret)
600 RX_OP_CHECK_PKT_N(5b)
601 RX_OP_CHECK_NO_PKT()
602 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
603 QRL_SUITE_AES128GCM, rx_script_5_1rtt_secret)
604 RX_OP_CHECK_PKT_N(5c)
605 RX_OP_CHECK_NO_PKT()
606
607 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
608 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
609 RX_OP_INJECT_N(5)
610 RX_OP_CHECK_NO_PKT()
611
612 RX_OP_END
613 };
614
615 /*
616 * 6. Real World - S2C Multiple Packets
617 * - Initial, Handshake, 1-RTT (AES-256-GCM/SHA384)
618 */
619 static const QUIC_CONN_ID rx_script_6_c2s_init_dcid = {
620 4, {0xac, 0x88, 0x95, 0xbd}
621 };
622
623 static const unsigned char rx_script_6_handshake_secret[48] = {
624 0xd1, 0x41, 0xb0, 0xf6, 0x0d, 0x8b, 0xbd, 0xe8, 0x5b, 0xa8, 0xff, 0xd7,
625 0x18, 0x9a, 0x23, 0x7b, 0x13, 0x5c, 0x1e, 0x90, 0x1d, 0x08, 0x95, 0xcc,
626 0xc5, 0x8e, 0x73, 0x4e, 0x02, 0x6f, 0x3c, 0xb6, 0x26, 0x77, 0x8d, 0x53,
627 0xc5, 0x62, 0x9f, 0xb5, 0xf0, 0x88, 0xfb, 0xe5, 0x14, 0x71, 0xab, 0xe6,
628 };
629
630 static const unsigned char rx_script_6_1rtt_secret[48] = {
631 0x2d, 0x6b, 0x9d, 0xd4, 0x39, 0xa0, 0xe7, 0xff, 0x17, 0xe2, 0xcb, 0x5c,
632 0x0d, 0x4a, 0xf6, 0x3f, 0xf4, 0xfe, 0xfc, 0xe5, 0x22, 0xfa, 0xf5, 0x5b,
633 0xc0, 0xb2, 0x18, 0xbb, 0x92, 0x4d, 0x35, 0xea, 0x67, 0xa6, 0xe7, 0xc1,
634 0x90, 0x10, 0xc9, 0x14, 0x46, 0xf5, 0x95, 0x57, 0x8b, 0x90, 0x88, 0x5d,
635 };
636
637 static const unsigned char rx_script_6_in[] = {
638 /* First Packet: Initial */
639 0xc5, /* Long, Initial, PN Length=2 bytes */
640 0x00, 0x00, 0x00, 0x01, /* Version */
641 0x00, /* DCID */
642 0x04, 0x36, 0xf4, 0x75, 0x2d, /* SCID */
643 0x00, /* Token Length */
644 0x41, 0xbe, /* Length (446) */
645 0xa9, 0xe2, /* PN (0) */
646 0x83, 0x39, 0x95, 0x8f, 0x8f, 0x8c, 0xa9, 0xaf, 0x10, 0x29, 0x3d, 0xfc,
647 0x56, 0x4a, 0x1c, 0x4b, 0xc9, 0x48, 0xb1, 0xaf, 0x36, 0xd5, 0xac, 0x95,
648 0xbf, 0xfd, 0x2c, 0x4d, 0x70, 0x2e, 0x5b, 0x7c, 0x22, 0x5f, 0x5f, 0xee,
649 0x10, 0x8f, 0xfb, 0x0b, 0x5f, 0x9d, 0x7e, 0x68, 0x2f, 0x94, 0x0b, 0xdb,
650 0xed, 0xef, 0xfa, 0x4e, 0xc6, 0xd5, 0xe7, 0xef, 0xe0, 0x78, 0x3c, 0xdc,
651 0xe9, 0xd8, 0xe8, 0x56, 0x71, 0xd7, 0xe7, 0x6c, 0x7f, 0x5d, 0xaa, 0x7a,
652 0x52, 0x1d, 0x95, 0x7a, 0x80, 0x70, 0x38, 0xc0, 0x8b, 0xa1, 0x2f, 0x09,
653 0x16, 0xd2, 0xec, 0xa3, 0x23, 0x72, 0x45, 0x3c, 0xbd, 0x8c, 0xda, 0xbb,
654 0x37, 0x5a, 0x8d, 0xb2, 0x00, 0x7e, 0x67, 0x0c, 0xa0, 0x32, 0xdd, 0x80,
655 0x07, 0x71, 0xb0, 0x95, 0x21, 0xbc, 0x1e, 0xbd, 0x63, 0x0a, 0x10, 0xe7,
656 0x4b, 0x6e, 0x2e, 0x85, 0x3a, 0x65, 0xf7, 0x06, 0x6e, 0x7e, 0x8f, 0x65,
657 0x8c, 0xb1, 0x93, 0xe9, 0x0d, 0xe8, 0x46, 0xe7, 0xcf, 0xa7, 0xd2, 0x8b,
658 0x15, 0x23, 0xec, 0xc3, 0xec, 0x44, 0xda, 0x62, 0x15, 0x35, 0x34, 0x2f,
659 0x62, 0x77, 0xc8, 0x1f, 0x83, 0x22, 0x00, 0xe5, 0xc0, 0x89, 0xb8, 0x97,
660 0xd2, 0x37, 0x02, 0xea, 0xa2, 0x35, 0xbf, 0x19, 0xf0, 0xba, 0x1d, 0xb7,
661 0xaa, 0x36, 0xbb, 0x11, 0x60, 0xc3, 0x45, 0x1f, 0xe5, 0x18, 0xde, 0x4c,
662 0x01, 0x23, 0x2d, 0x17, 0x78, 0xdd, 0x4c, 0x8a, 0x1e, 0x1b, 0xd4, 0xda,
663 0x56, 0x43, 0x13, 0xa4, 0x4f, 0xfd, 0xd5, 0x92, 0x6a, 0x05, 0x5f, 0x14,
664 0x63, 0x85, 0x7d, 0xf1, 0x31, 0xb8, 0x27, 0x0b, 0xa6, 0xb5, 0x50, 0xca,
665 0x8b, 0x0e, 0xa1, 0x0d, 0xf9, 0xc4, 0xea, 0x6a, 0x6e, 0x4b, 0x6d, 0xdf,
666 0x49, 0xe8, 0x32, 0xf6, 0x85, 0xc4, 0x29, 0x26, 0x32, 0xfb, 0x5e, 0xa8,
667 0x55, 0x6b, 0x67, 0xe9, 0xaa, 0x35, 0x33, 0x90, 0xd8, 0x2a, 0x71, 0x0b,
668 0x6a, 0x48, 0xc4, 0xa3, 0x8b, 0xe0, 0xe7, 0x00, 0x3d, 0xee, 0x30, 0x70,
669 0x84, 0xbd, 0xa3, 0x3c, 0x9e, 0xa3, 0x5c, 0x69, 0xab, 0x55, 0x7b, 0xe2,
670 0xe5, 0x86, 0x13, 0xcb, 0x93, 0x3f, 0xcb, 0x3e, 0x6d, 0xc9, 0xc2, 0x10,
671 0x2b, 0x00, 0x9b, 0x3f, 0x14, 0x4e, 0x04, 0x27, 0xc0, 0xae, 0x1d, 0x48,
672 0x89, 0x3a, 0xf4, 0xac, 0xe0, 0x05, 0x07, 0xc9, 0x74, 0x6e, 0x21, 0x01,
673 0xe9, 0x26, 0xfd, 0xb4, 0xb2, 0x2a, 0xda, 0x72, 0xda, 0xbf, 0x63, 0x9d,
674 0x37, 0xaf, 0x90, 0x05, 0xd6, 0x89, 0xc7, 0xa6, 0x81, 0x4e, 0x2a, 0x30,
675 0xe3, 0x05, 0x88, 0x9f, 0xd0, 0xba, 0x8d, 0xc4, 0x21, 0x52, 0x5a, 0x7a,
676 0xe1, 0xad, 0xd3, 0x88, 0xc2, 0x18, 0xad, 0x4c, 0xb1, 0x66, 0x73, 0x1b,
677 0xf2, 0xd1, 0xb9, 0x43, 0xaa, 0xc4, 0x66, 0xcd, 0x42, 0xfa, 0x80, 0xec,
678 0xa1, 0x7c, 0x45, 0x02, 0x53, 0x45, 0xd5, 0x07, 0xd4, 0x70, 0x12, 0x1b,
679 0x08, 0x05, 0x6e, 0x99, 0x0a, 0xd3, 0x5b, 0x99, 0x6b, 0x65, 0xc4, 0xc0,
680 0x04, 0x1b, 0x75, 0xf2, 0x86, 0x99, 0x09, 0x4a, 0x50, 0x70, 0x00, 0x7a,
681 0x93, 0xaa, 0xe6, 0xf4, 0x03, 0x29, 0x06, 0xa4, 0x30, 0x6d, 0x52, 0xbd,
682 0x60, 0xd1, 0x7e, 0xd6, 0x07, 0xc0, 0x41, 0x01, 0x12, 0x3e, 0x16, 0x94,
683
684 /* Second Packet: Handshake */
685 0xea, /* Long, Handshake, PN Length=2 bytes */
686 0x00, 0x00, 0x00, 0x01, /* Version */
687 0x00, /* DCID */
688 0x04, 0x36, 0xf4, 0x75, 0x2d, /* SCID */
689 0x42, 0xb0, /* Length (688) */
690 0x3a, 0xc5, /* PN (0) */
691 0x3b, 0x8e, 0x4c, 0x01, 0x72, 0x6b, 0xfa, 0xbb, 0xad, 0xf9, 0x9e, 0x21,
692 0xb1, 0xd0, 0x01, 0xf1, 0xd4, 0x67, 0x8d, 0x2c, 0xee, 0x04, 0x60, 0x4a,
693 0xe2, 0xe4, 0xc6, 0x89, 0x01, 0xae, 0x3c, 0x1f, 0xf7, 0xe6, 0xf7, 0xac,
694 0x26, 0xcf, 0x3c, 0x6d, 0x1d, 0xfd, 0x11, 0x02, 0x51, 0x73, 0xb5, 0xe1,
695 0xb2, 0x44, 0x42, 0x32, 0x0f, 0xf5, 0x3d, 0x55, 0x2d, 0x1f, 0x02, 0x29,
696 0x51, 0x35, 0xdb, 0xc7, 0x7a, 0x34, 0x4b, 0xec, 0x60, 0x49, 0xa2, 0x90,
697 0x11, 0xef, 0x5a, 0xa9, 0x1c, 0xf7, 0xd9, 0x21, 0x68, 0x1c, 0x2b, 0xc6,
698 0x57, 0xde, 0xb1, 0x0b, 0x31, 0xed, 0xef, 0x16, 0xba, 0x08, 0xb9, 0xe2,
699 0xd9, 0xd0, 0xd8, 0x1f, 0xc4, 0x32, 0xe8, 0x45, 0x2a, 0x86, 0xe4, 0xd3,
700 0xaf, 0x72, 0x4f, 0x30, 0x01, 0x71, 0x15, 0x9b, 0xa9, 0x55, 0x35, 0xf7,
701 0x39, 0x7e, 0x6a, 0x59, 0x18, 0x4f, 0xe6, 0xdf, 0xb5, 0x0d, 0xc2, 0xe7,
702 0xb2, 0xa1, 0xa6, 0xa3, 0x9c, 0xf0, 0x0d, 0x59, 0x05, 0x49, 0x95, 0xfa,
703 0xcc, 0x72, 0xd7, 0xc0, 0x84, 0x2e, 0xc4, 0x1c, 0xd4, 0xa0, 0xe3, 0x6c,
704 0x5a, 0x8c, 0x94, 0x4d, 0x37, 0x1a, 0x1c, 0x68, 0x93, 0x5f, 0xe5, 0x99,
705 0x27, 0xc6, 0x06, 0xaa, 0x1f, 0x29, 0x17, 0xc5, 0x8c, 0x3d, 0x53, 0xa7,
706 0x05, 0x3a, 0x44, 0x53, 0x86, 0xed, 0x56, 0x99, 0x4c, 0xe2, 0x7b, 0x3a,
707 0x1e, 0x5d, 0x6d, 0xac, 0x78, 0x1e, 0xfa, 0x55, 0x58, 0x6e, 0x72, 0xee,
708 0xf9, 0x33, 0x64, 0x7f, 0x93, 0x3c, 0xfe, 0x18, 0x97, 0x6b, 0x02, 0x74,
709 0x90, 0x0d, 0xba, 0x89, 0xc0, 0x22, 0x0a, 0x0a, 0x37, 0x4c, 0x28, 0x74,
710 0xa7, 0x3a, 0x44, 0x74, 0x42, 0xff, 0xf1, 0xd2, 0x8d, 0x0c, 0xc1, 0xed,
711 0x98, 0x98, 0x8e, 0xa8, 0x6b, 0x95, 0x6a, 0x86, 0x0b, 0xb4, 0x95, 0x58,
712 0x34, 0x12, 0xb0, 0xc0, 0xf8, 0x2d, 0x5b, 0x40, 0x51, 0x80, 0x07, 0x91,
713 0x31, 0x77, 0xd3, 0x06, 0xa5, 0xe5, 0x1f, 0xe2, 0xf8, 0x92, 0xe4, 0x23,
714 0x2b, 0xf0, 0x4c, 0xa9, 0xa5, 0x6c, 0x6f, 0xaf, 0xaf, 0xbf, 0x97, 0xcf,
715 0x46, 0xf2, 0x8d, 0x61, 0x0e, 0x73, 0xcd, 0xc5, 0xde, 0xda, 0x50, 0x82,
716 0x61, 0x6d, 0xb1, 0xa2, 0xbe, 0x6b, 0x99, 0xcd, 0x5b, 0x99, 0x8f, 0x66,
717 0xab, 0x11, 0x78, 0xcc, 0xdb, 0x66, 0x98, 0xca, 0x19, 0x92, 0xf4, 0x05,
718 0xae, 0xe6, 0xf3, 0xe7, 0xf0, 0x30, 0x28, 0x31, 0x74, 0xff, 0xe2, 0xb3,
719 0x3a, 0x4f, 0x79, 0xe7, 0x2a, 0x9f, 0xe3, 0x41, 0xb2, 0x88, 0xc8, 0x8f,
720 0x77, 0x57, 0x42, 0x65, 0xdb, 0x07, 0xf6, 0x5f, 0xb8, 0x34, 0x17, 0xe3,
721 0x8d, 0x22, 0x5b, 0x88, 0x94, 0x60, 0x97, 0x32, 0x3d, 0x8a, 0x51, 0x9d,
722 0xb5, 0xac, 0xd7, 0x99, 0x96, 0x23, 0x6d, 0xc9, 0xab, 0x61, 0x41, 0x8f,
723 0x72, 0x1b, 0xf8, 0x84, 0xd9, 0x57, 0x88, 0x68, 0x3d, 0x73, 0x5f, 0xb1,
724 0x18, 0x5c, 0x3a, 0x35, 0xd2, 0xc5, 0xb7, 0x29, 0xc7, 0x95, 0xdd, 0x21,
725 0xc0, 0x78, 0x49, 0xf3, 0x24, 0xe0, 0x4c, 0x5c, 0x32, 0x08, 0xb7, 0x00,
726 0x43, 0x70, 0x5a, 0x95, 0x23, 0x91, 0xf5, 0xb7, 0x61, 0x85, 0x6f, 0xb3,
727 0xa4, 0x6b, 0x05, 0x9d, 0x39, 0xa3, 0xb1, 0x1c, 0x61, 0xc5, 0xa5, 0xe7,
728 0x9a, 0xe9, 0x5d, 0xaa, 0xca, 0x11, 0xd8, 0x4b, 0xa4, 0x9c, 0x18, 0x4e,
729 0x2b, 0x2d, 0x75, 0xc1, 0x12, 0x20, 0xe4, 0x66, 0xa5, 0x59, 0x67, 0x4b,
730 0xcc, 0x52, 0x2d, 0xfa, 0xaa, 0xa4, 0xe9, 0xfc, 0x79, 0xd7, 0xff, 0x03,
731 0x3e, 0xec, 0xba, 0x97, 0x37, 0x52, 0xc1, 0x57, 0x31, 0x8e, 0x57, 0x0c,
732 0x54, 0x92, 0x9c, 0x25, 0x5c, 0xfa, 0x9f, 0xa5, 0x36, 0x18, 0xd0, 0xaa,
733 0xf3, 0x3b, 0x5b, 0x59, 0xbd, 0x33, 0x5e, 0x7d, 0x74, 0x7c, 0xaf, 0xe9,
734 0x54, 0x80, 0xc4, 0xb4, 0xa1, 0x24, 0x9e, 0x23, 0x0d, 0xbf, 0x4e, 0x0f,
735 0xaf, 0xa5, 0x16, 0xcb, 0x3b, 0xfa, 0x33, 0xa5, 0x68, 0xa6, 0x64, 0x48,
736 0x2f, 0x5e, 0xfa, 0x64, 0x4e, 0xe3, 0x27, 0x4f, 0x13, 0xe6, 0x37, 0xf6,
737 0xb9, 0x63, 0x4b, 0xdc, 0x49, 0x3c, 0x5e, 0x9e, 0x06, 0xea, 0xac, 0xa3,
738 0xdf, 0x6c, 0x49, 0xfb, 0xa1, 0x01, 0x4f, 0x6f, 0x74, 0x1f, 0xd3, 0x26,
739 0xa1, 0x92, 0x3e, 0xe0, 0x73, 0xd6, 0x3b, 0x67, 0x13, 0x53, 0x2e, 0xcb,
740 0xbc, 0x83, 0xd0, 0x6e, 0x28, 0xb1, 0xcb, 0xd9, 0x66, 0xe0, 0x33, 0x59,
741 0x45, 0xd3, 0x13, 0xc2, 0x48, 0xd5, 0x9e, 0x88, 0xba, 0x75, 0x7b, 0xb1,
742 0xfe, 0x6f, 0xec, 0xde, 0xff, 0x14, 0x59, 0x75, 0xbf, 0x1a, 0x74, 0x47,
743 0xc5, 0xd8, 0xe8, 0x1b, 0x3c, 0x86, 0xd7, 0x1f, 0x99, 0x11, 0xd3, 0x29,
744 0xfd, 0x5d, 0x22, 0x7e, 0x03, 0x78, 0xed, 0x62, 0x0e, 0xbe, 0x6d, 0x75,
745 0xf4, 0xa8, 0x6e, 0xc7, 0x21, 0x76, 0xc5, 0xa0, 0x0c, 0xaa, 0x58, 0x78,
746 0x7e, 0x6e, 0xfc, 0x1e, 0x2a, 0x1c, 0xdd, 0xe5, 0x78, 0x08, 0xbd, 0xdb,
747 0xea, 0x8f, 0x8a, 0xa5, 0xbf, 0x93, 0xfe, 0x0f, 0x03, 0xa1, 0xc8, 0x64,
748 0x9f, 0x4a,
749
750 /* Third Packet: 1-RTT */
751 0x48, /* Short, 1-RTT, Spin=0, KP=0, PN Length=2 bytes */
752 0x3e, 0x28, /* PN (0) */
753 0xb9, 0xdb, 0x61, 0xf8, 0x8b, 0x3a, 0xef, 0x26, 0x69, 0xf2, 0x57, 0xc6,
754 0x84, 0x25, 0x6b, 0x77, 0xbe, 0x8c, 0x43, 0x32, 0xf3, 0x9a, 0xd1, 0x85,
755 0x14, 0xbc, 0x89, 0x3b, 0x9c, 0xf3, 0xfc, 0x00, 0xa1, 0x3a, 0xc3, 0xc4,
756 0x1e, 0xdf, 0xd0, 0x11, 0x70, 0xd9, 0x02, 0x7a, 0xd4, 0xef, 0x86, 0x67,
757 0xb1, 0x1e, 0x5d, 0xe3, 0x7f, 0x82, 0x14, 0x52, 0xa5, 0x8a, 0x89, 0xa7,
758 0x98, 0x75, 0x2f, 0x8a, 0x00, 0xf3, 0xbd, 0x49, 0x26, 0x4d, 0x0c, 0xc7,
759 0x38, 0xe7, 0x91, 0x85, 0xc9, 0x21, 0x6a, 0x1c, 0xc4, 0xa3, 0x0e, 0xd8,
760 0xfe, 0xb1, 0x25, 0x1a,
761 };
762
763 static const QUIC_PKT_HDR rx_script_6a_expect_hdr = {
764 QUIC_PKT_TYPE_INITIAL,
765 0, /* Spin Bit */
766 0, /* Key Phase */
767 2, /* PN Length */
768 0, /* Partial */
769 1, /* Fixed */
770 1, /* Version */
771 {0, {0}}, /* DCID */
772 {4, {0x36, 0xf4, 0x75, 0x2d}}, /* SCID */
773 {0}, /* PN */
774 NULL, 0, /* Token/Token Len */
775 428, NULL
776 };
777
778 static const unsigned char rx_script_6a_body[] = {
779 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
780 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
781 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
782 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
783 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
784 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
785 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
786 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
787 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
788 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
789 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
790 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
791 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
792 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
793 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
794 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
795 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
796 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
797 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
798 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
799 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
800 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
801 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
802 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
804 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
805 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
806 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
807 0x40, 0x5a, 0x02, 0x00, 0x00, 0x56, 0x03, 0x03, 0xc3, 0x45, 0xe8, 0xb8,
808 0xf9, 0x7c, 0x9f, 0x5d, 0xcf, 0x66, 0x25, 0xe4, 0x91, 0x0e, 0xb0, 0x5a,
809 0x14, 0xce, 0xaf, 0xea, 0x83, 0x12, 0xde, 0x68, 0xd9, 0x31, 0xf2, 0x23,
810 0x11, 0x3a, 0x15, 0xcb, 0x00, 0x13, 0x02, 0x00, 0x00, 0x2e, 0x00, 0x2b,
811 0x00, 0x02, 0x03, 0x04, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20,
812 0xab, 0xd3, 0xc6, 0x9f, 0x36, 0xd3, 0x52, 0x93, 0x87, 0xee, 0x92, 0x01,
813 0xa2, 0xd6, 0x9a, 0x5e, 0x61, 0x43, 0xcc, 0x4a, 0xcc, 0x7a, 0xcd, 0x83,
814 0xb2, 0xd9, 0xad, 0xd1, 0x14, 0xdc, 0x84, 0x61,
815 };
816
817 static const QUIC_PKT_HDR rx_script_6b_expect_hdr = {
818 QUIC_PKT_TYPE_HANDSHAKE,
819 0, /* Spin Bit */
820 0, /* Key Phase */
821 2, /* PN Length */
822 0, /* Partial */
823 1, /* Fixed */
824 1, /* Version */
825 {0, {0}}, /* DCID */
826 {4, {0x36, 0xf4, 0x75, 0x2d}}, /* SCID */
827 {0}, /* PN */
828 NULL, 0, /* Token/Token Len */
829 670, NULL
830 };
831
832 static const unsigned char rx_script_6b_body[] = {
833 0x06, 0x00, 0x42, 0x9a, 0x08, 0x00, 0x00, 0x80, 0x00, 0x7e, 0x00, 0x10,
834 0x00, 0x08, 0x00, 0x06, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x00, 0x39,
835 0x00, 0x6e, 0x47, 0xfa, 0x05, 0x5a, 0xe0, 0xec, 0x4a, 0xf3, 0x05, 0x04,
836 0x80, 0x08, 0x00, 0x00, 0x06, 0x04, 0x80, 0x08, 0x00, 0x00, 0x07, 0x04,
837 0x80, 0x08, 0x00, 0x00, 0x04, 0x04, 0x80, 0x0c, 0x00, 0x00, 0x08, 0x02,
838 0x40, 0x64, 0x09, 0x02, 0x40, 0x64, 0x01, 0x04, 0x80, 0x00, 0x75, 0x30,
839 0x03, 0x02, 0x45, 0xac, 0x0b, 0x01, 0x1a, 0x0c, 0x00, 0x02, 0x10, 0x35,
840 0xd7, 0x7d, 0x8b, 0xc5, 0xb1, 0x89, 0xb1, 0x5c, 0x23, 0x74, 0x50, 0xfd,
841 0x47, 0xfe, 0xd2, 0x00, 0x11, 0x96, 0x38, 0x27, 0xde, 0x7d, 0xfb, 0x2b,
842 0x38, 0x56, 0xe5, 0x2a, 0xb8, 0x6b, 0xfa, 0xaa, 0xde, 0x81, 0x0e, 0x01,
843 0x04, 0x0f, 0x04, 0x36, 0xf4, 0x75, 0x2d, 0x10, 0x04, 0xac, 0x88, 0x95,
844 0xbd, 0x20, 0x01, 0x00, 0x0b, 0x00, 0x01, 0x8f, 0x00, 0x00, 0x01, 0x8b,
845 0x00, 0x01, 0x86, 0x30, 0x82, 0x01, 0x82, 0x30, 0x82, 0x01, 0x29, 0xa0,
846 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x0a, 0x73, 0x0f, 0x86, 0x18, 0xf2,
847 0xc3, 0x30, 0x01, 0xd2, 0xc0, 0xc1, 0x62, 0x52, 0x13, 0xf1, 0x9c, 0x13,
848 0x39, 0xb5, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04,
849 0x03, 0x02, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04,
850 0x03, 0x0c, 0x0c, 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f,
851 0x63, 0x61, 0x6c, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30, 0x38, 0x30,
852 0x32, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x32, 0x32,
853 0x30, 0x39, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x30,
854 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0c,
855 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
856 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
857 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
858 0x42, 0x00, 0x04, 0x67, 0xf4, 0xd3, 0x8f, 0x15, 0x6d, 0xee, 0x85, 0xcc,
859 0x2a, 0x77, 0xfc, 0x0b, 0x8f, 0x9f, 0xcf, 0xa9, 0x95, 0x5d, 0x5b, 0xcd,
860 0xb7, 0x8b, 0xba, 0x31, 0x0a, 0x73, 0x62, 0xc5, 0xd0, 0x0e, 0x07, 0x90,
861 0xae, 0x38, 0x43, 0x79, 0xce, 0x5e, 0x33, 0xad, 0x31, 0xbf, 0x9f, 0x2a,
862 0x56, 0x83, 0xa5, 0x24, 0x16, 0xab, 0x0c, 0xf1, 0x64, 0xbe, 0xe4, 0x93,
863 0xb5, 0x89, 0xd6, 0x05, 0xe4, 0xf7, 0x7b, 0xa3, 0x53, 0x30, 0x51, 0x30,
864 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x02, 0x64,
865 0x0f, 0x55, 0x69, 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5,
866 0x5a, 0xd0, 0x48, 0x96, 0x9f, 0x60, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d,
867 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x02, 0x64, 0x0f, 0x55, 0x69,
868 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a, 0xd0, 0x48,
869 0x96, 0x9f, 0x60, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01,
870 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a, 0x06, 0x08,
871 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30,
872 0x44, 0x02, 0x20, 0x0a, 0x82, 0x92, 0x6e, 0xd3, 0xc6, 0x66, 0xd9, 0xd3,
873 0x75, 0xff, 0x71, 0x3b, 0x61, 0x46, 0x21, 0x00, 0xe6, 0x21, 0x5d, 0x9c,
874 0x86, 0xe9, 0x65, 0x40, 0x4f, 0xeb, 0x70, 0x4f, 0x2c, 0xad, 0x00, 0x02,
875 0x20, 0x08, 0xc2, 0x07, 0x5d, 0x16, 0xfc, 0x54, 0x34, 0x2b, 0xb4, 0x18,
876 0x67, 0x44, 0x81, 0xc9, 0xa9, 0x67, 0x2e, 0xce, 0xa1, 0x02, 0x9f, 0x3b,
877 0xe5, 0x61, 0x16, 0x0b, 0x50, 0xf6, 0xa1, 0x50, 0x94, 0x00, 0x00, 0x0f,
878 0x00, 0x00, 0x4b, 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, 0x02, 0x20, 0x78,
879 0x9e, 0xe0, 0x6a, 0x7a, 0xbd, 0xc3, 0x84, 0x3d, 0x25, 0x6a, 0x59, 0x23,
880 0x97, 0x52, 0x64, 0x4e, 0xb6, 0x9f, 0xcc, 0xd3, 0xd7, 0xa9, 0x29, 0x44,
881 0x75, 0x6d, 0x50, 0xfc, 0x22, 0xde, 0xd3, 0x02, 0x21, 0x00, 0xe5, 0x28,
882 0xd6, 0x5a, 0xd1, 0xec, 0x4a, 0xcc, 0x20, 0xb4, 0xea, 0x15, 0xfb, 0x8e,
883 0x73, 0xa8, 0x6b, 0xbb, 0x42, 0x70, 0x90, 0x08, 0x6e, 0x74, 0x6f, 0x5a,
884 0x05, 0xb5, 0x39, 0xee, 0x01, 0x04, 0x14, 0x00, 0x00, 0x30, 0xff, 0x9f,
885 0xb2, 0x1d, 0xcb, 0x4f, 0xfc, 0x7a, 0xac, 0xf4, 0x75, 0x24, 0x83, 0x5f,
886 0x8d, 0xa3, 0x3e, 0x9d, 0xef, 0x43, 0x67, 0x89, 0x5d, 0x55, 0xc7, 0xce,
887 0x80, 0xab, 0xc3, 0xc7, 0x74, 0xc7, 0xb2, 0x91, 0x27, 0xce, 0xd8, 0x5e,
888 0xc4, 0x4e, 0x96, 0x19, 0x68, 0x2d, 0xbe, 0x6f, 0x49, 0xfa,
889 };
890
891 static const QUIC_PKT_HDR rx_script_6c_expect_hdr = {
892 QUIC_PKT_TYPE_1RTT,
893 0, /* Spin Bit */
894 0, /* Key Phase */
895 2, /* PN Length */
896 0, /* Partial */
897 1, /* Fixed */
898 0, /* Version */
899 {0, {0}}, /* DCID */
900 {0, {0}}, /* SCID */
901 {0}, /* PN */
902 NULL, 0, /* Token/Token Len */
903 72, NULL
904 };
905
906 static const unsigned char rx_script_6c_body[] = {
907 0x18, 0x03, 0x00, 0x04, 0xf2, 0x94, 0x49, 0xc3, 0x34, 0xa1, 0xf4, 0x0f,
908 0xcb, 0xb8, 0x03, 0x04, 0x1f, 0xc8, 0x69, 0xb9, 0x3b, 0xd5, 0xc6, 0x93,
909 0x18, 0x02, 0x00, 0x04, 0x9a, 0x4f, 0xec, 0x52, 0xde, 0xd2, 0xc8, 0xb7,
910 0x1c, 0x0c, 0xf3, 0x4e, 0x46, 0xf0, 0x6c, 0x54, 0x34, 0x1b, 0x0d, 0x98,
911 0x18, 0x01, 0x00, 0x04, 0xe3, 0x33, 0x9e, 0x59, 0x00, 0x69, 0xc3, 0xac,
912 0xfc, 0x58, 0x0e, 0xa4, 0xf4, 0xf3, 0x23, 0x1b, 0xd6, 0x8e, 0x5b, 0x08,
913 };
914
915 static const struct rx_test_op rx_script_6[] = {
916 RX_OP_ADD_RX_DCID(empty_conn_id)
917 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_6_c2s_init_dcid)
918 RX_OP_INJECT_N(6)
919 RX_OP_CHECK_PKT_N(6a)
920 RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
921 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
922 QRL_SUITE_AES256GCM, rx_script_6_handshake_secret)
923 RX_OP_CHECK_PKT_N(6b)
924 RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
925 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
926 QRL_SUITE_AES256GCM, rx_script_6_1rtt_secret)
927 RX_OP_CHECK_PKT_N(6c)
928 RX_OP_CHECK_NO_PKT()
929
930 /* Try injecting the packet again */
931 RX_OP_INJECT_N(6)
932 /*
933 * Initial packet is not output due to receiving a Handshake packet causing
934 * auto-discard of Initial keys
935 */
936 RX_OP_CHECK_PKT_N(6b)
937 RX_OP_CHECK_PKT_N(6c)
938 RX_OP_CHECK_NO_PKT()
939 /* Try again with discarded keys */
940 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
941 RX_OP_INJECT_N(6)
942 RX_OP_CHECK_PKT_N(6c)
943 RX_OP_CHECK_NO_PKT()
944 /* Try again */
945 RX_OP_INJECT_N(6)
946 RX_OP_CHECK_PKT_N(6c)
947 RX_OP_CHECK_NO_PKT()
948 /* Try again with discarded 1-RTT keys */
949 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
950 RX_OP_INJECT_N(6)
951 RX_OP_CHECK_NO_PKT()
952
953 /* Recreate QRL, test reading packets received before key */
954 RX_OP_SET_SCID_LEN(0)
955 RX_OP_ADD_RX_DCID(empty_conn_id)
956 RX_OP_INJECT_N(6)
957 RX_OP_CHECK_NO_PKT()
958 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_6_c2s_init_dcid)
959 RX_OP_CHECK_PKT_N(6a)
960 RX_OP_CHECK_NO_PKT()
961 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
962 QRL_SUITE_AES256GCM, rx_script_6_handshake_secret)
963 RX_OP_CHECK_PKT_N(6b)
964 RX_OP_CHECK_NO_PKT()
965 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
966 QRL_SUITE_AES256GCM, rx_script_6_1rtt_secret)
967 RX_OP_CHECK_PKT_N(6c)
968 RX_OP_CHECK_NO_PKT()
969
970 RX_OP_END
971 };
972
973 /*
974 * 7. Real World - S2C Multiple Packets
975 * - Initial, Handshake, 1-RTT (ChaCha20-Poly1305)
976 */
977 static const QUIC_CONN_ID rx_script_7_c2s_init_dcid = {
978 4, {0xfa, 0x5d, 0xd6, 0x80}
979 };
980
981 static const unsigned char rx_script_7_handshake_secret[32] = {
982 0x85, 0x44, 0xa4, 0x02, 0x46, 0x5b, 0x2a, 0x92, 0x80, 0x71, 0xfd, 0x11,
983 0x89, 0x73, 0x84, 0xeb, 0x3e, 0x0d, 0x89, 0x4f, 0x71, 0xdc, 0x9c, 0xdd,
984 0x55, 0x77, 0x9e, 0x79, 0x7b, 0xeb, 0xfa, 0x86,
985 };
986
987 static const unsigned char rx_script_7_1rtt_secret[32] = {
988 0x4a, 0x77, 0xb6, 0x0e, 0xfd, 0x90, 0xca, 0xbf, 0xc0, 0x1a, 0x64, 0x9f,
989 0xc0, 0x03, 0xd3, 0x8d, 0xc5, 0x41, 0x04, 0x50, 0xb1, 0x5b, 0x74, 0xe7,
990 0xe3, 0x99, 0x0c, 0xdf, 0x74, 0x61, 0x35, 0xe6,
991 };
992
993 static const unsigned char rx_script_7_in[] = {
994 /* First Packet: Initial */
995 0xc2, /* Long, Initial, PN Length=2 bytes */
996 0x00, 0x00, 0x00, 0x01, /* Version */
997 0x00, /* DCID */
998 0x04, 0x03, 0x45, 0x0c, 0x7a, /* SCID */
999 0x00, /* Token Length */
1000 0x41, 0xcb, /* Length (459) */
1001 0x3c, 0xe0, /* PN (0) */
1002 0x85, 0x05, 0xc2, 0x4d, 0x0f, 0xf3, 0x62, 0x51, 0x04, 0x33, 0xfa, 0xb5,
1003 0xa3, 0x02, 0xbd, 0x5c, 0x22, 0x0c, 0x1d, 0xda, 0x06, 0xf1, 0xd7, 0xe0,
1004 0xc8, 0x56, 0xb0, 0x3d, 0xc1, 0x49, 0x8c, 0xc2, 0x88, 0x5a, 0x0e, 0xd5,
1005 0x67, 0x72, 0xec, 0xcc, 0x7a, 0x2b, 0x46, 0x17, 0x49, 0x4b, 0x28, 0x6a,
1006 0x89, 0x71, 0xfd, 0x31, 0x9a, 0xa1, 0x97, 0x64, 0xe2, 0xbf, 0xa0, 0x6d,
1007 0xf6, 0x76, 0x83, 0x28, 0xc4, 0xd5, 0x39, 0x87, 0x22, 0x7c, 0x11, 0x9a,
1008 0x53, 0x66, 0xb4, 0x27, 0xf1, 0xab, 0x6f, 0x49, 0x43, 0x3f, 0x9a, 0x23,
1009 0xd3, 0x53, 0x06, 0xe8, 0x14, 0xfd, 0xc0, 0x67, 0x1f, 0x88, 0x2a, 0xa8,
1010 0xae, 0x5f, 0x05, 0x0a, 0xeb, 0x66, 0x72, 0x8c, 0x46, 0xcc, 0x54, 0x21,
1011 0x5e, 0x14, 0xfe, 0x68, 0xc7, 0xf7, 0x60, 0x67, 0xb5, 0xa7, 0x0d, 0xf4,
1012 0xe1, 0xff, 0x60, 0xe3, 0x11, 0x38, 0x92, 0x90, 0xc2, 0x48, 0x28, 0xbf,
1013 0xf3, 0x85, 0x27, 0xfe, 0xbf, 0x42, 0x26, 0x1a, 0x4e, 0x78, 0xf1, 0xf0,
1014 0x88, 0x16, 0x1b, 0x64, 0x5f, 0x66, 0x02, 0x0b, 0x45, 0x3d, 0x38, 0xd9,
1015 0x09, 0xd5, 0xff, 0xc2, 0x68, 0x02, 0x2c, 0xc4, 0x3f, 0x60, 0x6e, 0x2f,
1016 0x7f, 0x43, 0xf7, 0x1a, 0x37, 0xcc, 0xe0, 0xe0, 0x4b, 0x96, 0xc1, 0xb1,
1017 0x8b, 0x1c, 0x7c, 0x6e, 0x80, 0xe3, 0x92, 0x9b, 0x86, 0x87, 0x1f, 0x9a,
1018 0x6a, 0x62, 0x18, 0xf4, 0x86, 0xc2, 0x3e, 0x33, 0xa3, 0xbf, 0x43, 0x96,
1019 0x6e, 0xff, 0x94, 0xaf, 0x6d, 0x23, 0x5c, 0x42, 0xed, 0xe7, 0xb9, 0x2c,
1020 0x33, 0xb0, 0xc6, 0x3d, 0x44, 0x00, 0x0b, 0xa3, 0x39, 0xa8, 0xeb, 0x8c,
1021 0x81, 0x1a, 0x99, 0x20, 0xbd, 0xfa, 0xf3, 0xf4, 0xf0, 0x11, 0xd8, 0x41,
1022 0x31, 0x8d, 0xdc, 0x0d, 0x00, 0xa6, 0x31, 0x40, 0xc6, 0xc6, 0xad, 0x74,
1023 0x93, 0x62, 0x1c, 0x55, 0xce, 0x5f, 0x8c, 0x5b, 0x3c, 0xcb, 0x25, 0x5e,
1024 0xbf, 0xed, 0xbb, 0x3c, 0x97, 0x4b, 0x62, 0xe0, 0xba, 0xf1, 0xb0, 0x30,
1025 0xbf, 0x35, 0x89, 0x7e, 0x25, 0x61, 0x54, 0x86, 0x52, 0x11, 0x86, 0x90,
1026 0xc3, 0xf5, 0xad, 0xa0, 0x96, 0x30, 0xb2, 0xf0, 0xa6, 0x79, 0x39, 0x1c,
1027 0x51, 0x42, 0xa1, 0x00, 0x6f, 0x55, 0x7d, 0xdc, 0xd0, 0x7c, 0xcf, 0x01,
1028 0x88, 0x03, 0xd7, 0x2d, 0x65, 0x2b, 0x40, 0xee, 0xba, 0x10, 0xd8, 0x0c,
1029 0x85, 0x14, 0xb7, 0x4d, 0x9e, 0x7d, 0x7c, 0xde, 0x7f, 0x0d, 0x0e, 0x3b,
1030 0x3d, 0xe3, 0xd3, 0x63, 0xc2, 0xed, 0xc7, 0x41, 0xaf, 0x05, 0x85, 0x87,
1031 0x46, 0x55, 0x7e, 0xbe, 0x14, 0x5b, 0x98, 0xae, 0x6e, 0x67, 0x1a, 0x65,
1032 0xc6, 0xcf, 0xe1, 0x28, 0x50, 0x6b, 0xb4, 0xf6, 0xba, 0x63, 0xbc, 0xf1,
1033 0xd7, 0xa4, 0x97, 0x2d, 0x4d, 0x04, 0x26, 0x96, 0xec, 0x0c, 0xd4, 0xae,
1034 0x6a, 0xca, 0x7e, 0x65, 0xc5, 0x43, 0x7e, 0xf8, 0x77, 0x61, 0xd0, 0x2c,
1035 0xe5, 0x37, 0x0a, 0xb3, 0x7a, 0x8c, 0x2a, 0xa1, 0xdc, 0x29, 0xdb, 0xec,
1036 0xca, 0xdc, 0xfe, 0xdd, 0x38, 0xd2, 0x13, 0x9f, 0x94, 0x6d, 0x5b, 0x87,
1037 0xf3, 0x15, 0xa8, 0xe5, 0xe9, 0x65, 0x1d, 0x4f, 0x92, 0x1b, 0xf4, 0xa6,
1038 0xa4, 0xd6, 0x22, 0xfc, 0x26, 0x1b, 0x35, 0xa4, 0x1c, 0x88, 0x9f, 0x7d,
1039 0xe0, 0x9a, 0x89, 0x0f, 0x6c, 0xc1, 0xda, 0x6e, 0x45, 0xce, 0x74, 0xb1,
1040 0xff,
1041
1042 /* Second Packet: Handshake */
1043 0xeb, /* Long, Handshake, PN Length=2 bytes */
1044 0x00, 0x00, 0x00, 0x01, /* Version */
1045 0x00, /* DCID */
1046 0x04, 0x03, 0x45, 0x0c, 0x7a, /* SCID */
1047 0x42, 0xa3, /* Length (675) */
1048 0x43, 0x29, /* PN (0) */
1049 0xff, 0xdb, 0xcf, 0x3c, 0x17, 0xcf, 0xdc, 0x42, 0x3a, 0x59, 0x88, 0xdb,
1050 0x13, 0xef, 0x09, 0x3d, 0xf2, 0x24, 0xf3, 0xeb, 0xca, 0xb0, 0xe1, 0xa4,
1051 0x67, 0x64, 0x65, 0x80, 0x5f, 0x73, 0x29, 0x69, 0x29, 0xba, 0x03, 0x77,
1052 0x22, 0xc8, 0xa8, 0xd5, 0x21, 0xf2, 0xa2, 0x30, 0x7f, 0x86, 0x3a, 0x8a,
1053 0xdd, 0x92, 0x33, 0xa6, 0x57, 0x21, 0x39, 0xdd, 0x34, 0xb4, 0x39, 0xa7,
1054 0x6f, 0x0a, 0x14, 0xba, 0x9e, 0x3b, 0x3a, 0x6a, 0x4b, 0xc5, 0xda, 0x44,
1055 0x82, 0xca, 0x52, 0x86, 0x68, 0x8a, 0x0c, 0x5e, 0xeb, 0x1e, 0x81, 0x43,
1056 0x3a, 0x59, 0x2c, 0x26, 0x63, 0xa3, 0x89, 0x92, 0x80, 0xe9, 0x75, 0xc2,
1057 0xdb, 0xb9, 0x58, 0x6d, 0xab, 0xfd, 0x21, 0xe0, 0x35, 0x79, 0x2e, 0x56,
1058 0x7b, 0xfb, 0xb3, 0x7a, 0x05, 0x33, 0x0f, 0x13, 0xe5, 0xef, 0x04, 0x41,
1059 0x69, 0x85, 0x91, 0x24, 0xce, 0xb5, 0x21, 0x8d, 0x0a, 0x13, 0xda, 0xae,
1060 0x86, 0x2f, 0x25, 0x1f, 0x9c, 0x70, 0x8a, 0xaa, 0x05, 0xeb, 0x30, 0x93,
1061 0x50, 0xc1, 0x39, 0xab, 0x99, 0x8a, 0x31, 0xc1, 0xc1, 0x5e, 0x39, 0xcf,
1062 0x64, 0x3f, 0x9f, 0x5c, 0xa5, 0xa1, 0x88, 0xb2, 0x5f, 0x23, 0xcb, 0x76,
1063 0xe5, 0xf3, 0x2d, 0xa0, 0xed, 0xad, 0xcf, 0x30, 0x05, 0x44, 0xdc, 0xa5,
1064 0x81, 0xb1, 0x7f, 0x78, 0x0d, 0x4d, 0x96, 0xa3, 0xcb, 0xcb, 0x45, 0xcf,
1065 0x5f, 0x22, 0xb8, 0x93, 0x2b, 0x16, 0xe0, 0x1c, 0x53, 0x34, 0x76, 0x3b,
1066 0x7b, 0x78, 0xa1, 0x46, 0x40, 0x43, 0x4b, 0x0e, 0x1c, 0xfd, 0xcf, 0x01,
1067 0xf1, 0x2c, 0xee, 0xd0, 0xbd, 0x9f, 0x44, 0xd2, 0xd7, 0x13, 0xf9, 0x65,
1068 0x82, 0xf5, 0x42, 0xec, 0x9f, 0x5d, 0x51, 0x5a, 0x7b, 0xf2, 0x39, 0xbb,
1069 0xa6, 0x19, 0x5c, 0x73, 0x95, 0x65, 0x5b, 0x64, 0x2f, 0xda, 0x50, 0xd0,
1070 0x02, 0x34, 0x3f, 0x35, 0xc1, 0xd6, 0x31, 0x3b, 0xcf, 0x3f, 0x81, 0x8d,
1071 0xe0, 0x40, 0xfd, 0x6d, 0x32, 0x68, 0xa4, 0xf2, 0x4e, 0x3a, 0x4a, 0x42,
1072 0x2c, 0x07, 0x2d, 0x27, 0xa3, 0x34, 0xe7, 0x27, 0x87, 0x80, 0x76, 0xc0,
1073 0xa0, 0x72, 0x05, 0xf2, 0x88, 0x81, 0xe3, 0x32, 0x00, 0x76, 0x8d, 0x24,
1074 0x5c, 0x97, 0x2d, 0xd6, 0xb8, 0x34, 0xf8, 0x1c, 0x1a, 0x6d, 0xc7, 0x3f,
1075 0xcf, 0x56, 0xae, 0xec, 0x26, 0x74, 0x53, 0x69, 0xcd, 0x7a, 0x97, 0x29,
1076 0xab, 0x12, 0x7d, 0x75, 0xf8, 0x8d, 0x5b, 0xc0, 0x77, 0x20, 0xb6, 0x6a,
1077 0x0b, 0xce, 0x98, 0x50, 0xca, 0x47, 0x42, 0x1e, 0x5d, 0xc3, 0x24, 0x5a,
1078 0x47, 0x48, 0x3b, 0xa0, 0x9e, 0x43, 0xe9, 0x8d, 0x18, 0x23, 0xda, 0x6f,
1079 0x8c, 0xda, 0xd0, 0x3e, 0xdb, 0x37, 0xff, 0xfc, 0x7e, 0x17, 0xbe, 0x42,
1080 0xfd, 0xdb, 0x51, 0xb1, 0xa4, 0xfd, 0x9a, 0x20, 0x27, 0x24, 0x17, 0x04,
1081 0x70, 0xb6, 0x21, 0x87, 0x88, 0xe9, 0xda, 0x63, 0xcb, 0xcb, 0x1d, 0xaf,
1082 0x4a, 0x46, 0x76, 0x88, 0xa1, 0xf8, 0x48, 0x6c, 0x06, 0xb4, 0x62, 0x1a,
1083 0x67, 0x18, 0xb0, 0x1d, 0x58, 0x6a, 0xfe, 0x1f, 0xf1, 0x48, 0xff, 0xcb,
1084 0xa4, 0xd1, 0xa8, 0x12, 0x1f, 0x45, 0x94, 0x2f, 0x55, 0x80, 0x6a, 0x06,
1085 0xcc, 0x7b, 0xb0, 0xcc, 0xb8, 0x06, 0x52, 0x16, 0xe3, 0x6e, 0x7e, 0xb0,
1086 0x42, 0xfd, 0x3b, 0x7e, 0x0a, 0x42, 0x7b, 0x73, 0xaf, 0x2c, 0xf3, 0xbd,
1087 0xe5, 0x72, 0x8c, 0x16, 0xb2, 0xd7, 0x7a, 0x11, 0xb6, 0x9f, 0xd1, 0x69,
1088 0xc1, 0x1a, 0xe0, 0x26, 0x26, 0x13, 0xe2, 0x75, 0xf5, 0x74, 0xae, 0x3f,
1089 0xee, 0x1e, 0x09, 0x63, 0x5a, 0x30, 0x19, 0xa5, 0x59, 0x48, 0x90, 0x9b,
1090 0x46, 0x56, 0xd8, 0x6f, 0x6b, 0x76, 0x82, 0x32, 0xc7, 0x29, 0x76, 0x2e,
1091 0x32, 0xb6, 0x23, 0x99, 0xeb, 0x92, 0x5d, 0xc4, 0x4c, 0xa1, 0xe9, 0x26,
1092 0x37, 0x9a, 0x7d, 0x4c, 0x16, 0x9c, 0x18, 0xe9, 0xc0, 0xff, 0x48, 0x79,
1093 0xb1, 0x7b, 0x0b, 0x1e, 0x6f, 0xb1, 0x77, 0xa5, 0xd2, 0xc6, 0x9a, 0xa9,
1094 0xfc, 0xd1, 0x0f, 0x69, 0xf3, 0xe0, 0x49, 0x70, 0x57, 0x80, 0x86, 0xa7,
1095 0x3f, 0x54, 0xa8, 0x60, 0xfb, 0xe4, 0x06, 0xa3, 0x13, 0xb9, 0x2f, 0xa7,
1096 0x37, 0x80, 0x0c, 0x43, 0xac, 0x2f, 0xae, 0x6e, 0x62, 0x2b, 0x53, 0xe4,
1097 0xfe, 0x58, 0xd7, 0x8b, 0x96, 0xdc, 0xe6, 0xd3, 0x86, 0xb8, 0xd6, 0x42,
1098 0x5b, 0x68, 0x03, 0x48, 0x3f, 0xcd, 0xee, 0x39, 0x8b, 0xc4, 0x53, 0x30,
1099 0x87, 0x48, 0x2a, 0x01, 0x9d, 0x6f, 0x8e, 0x36, 0x75, 0x73, 0xef, 0x77,
1100 0x3a, 0x82, 0xd8, 0x4c, 0x0e, 0x7f, 0xb3, 0x8f, 0x16, 0xd1, 0x10, 0xcf,
1101 0x2f, 0xa3, 0xdf, 0x65, 0xba, 0x91, 0x79, 0xf6, 0x93, 0x60, 0x08, 0xe5,
1102 0xdb, 0x73, 0x02, 0x7a, 0x0b, 0x0e, 0xcc, 0x3b, 0x1f, 0x08, 0x2d, 0x51,
1103 0x3e, 0x87, 0x48, 0xd3, 0xd3, 0x75, 0xc2, 0x28, 0xa3, 0xf3, 0x02, 0xde,
1104 0x8f, 0xa6, 0xbd, 0xb3, 0x19, 0xa0, 0xdb, 0x48, 0x51, 0x03, 0x5f, 0x98,
1105 0xbe,
1106
1107 /* Third Packet: 1-RTT */
1108 0x5c, /* Short, 1-RTT, Spin=0, KP=0, PN Length=2 bytes */
1109 0x4f, 0x33, /* PN (0) */
1110 0x16, 0x75, 0x98, 0x67, 0x04, 0x16, 0x61, 0xe3, 0x00, 0xb7, 0x9d, 0x5c,
1111 0x53, 0x4c, 0x26, 0x90, 0x92, 0x8e, 0x0e, 0xc0, 0x9c, 0x6d, 0x8b, 0xac,
1112 0x15, 0x6d, 0x89, 0x74, 0x2f, 0xe7, 0x84, 0xe3, 0x46, 0x46, 0x8c, 0xc1,
1113 0x21, 0x7c, 0x44, 0xa5, 0x00, 0x29, 0xca, 0xf2, 0x11, 0x18, 0xe0, 0x04,
1114 0x40, 0x55, 0xd2, 0xa7, 0xe5, 0x9d, 0x22, 0xa2, 0x2a, 0x6c, 0x03, 0x87,
1115 0xa3, 0xa3, 0xfa, 0xf5, 0x6c, 0xd7, 0x7d, 0xae, 0x3f, 0x28, 0x01, 0xae,
1116 0x06, 0x11, 0x69, 0x67, 0x90, 0x57, 0x5a, 0xd0, 0xeb, 0xdd, 0xac, 0xbd,
1117 0x7f, 0x33, 0x86, 0xbb,
1118 };
1119
1120 static const QUIC_PKT_HDR rx_script_7a_expect_hdr = {
1121 QUIC_PKT_TYPE_INITIAL,
1122 0, /* Spin Bit */
1123 0, /* Key Phase */
1124 2, /* PN Length */
1125 0, /* Partial */
1126 1, /* Fixed */
1127 1, /* Version */
1128 {0, {0}}, /* DCID */
1129 {4, {0x03, 0x45, 0x0c, 0x7a}}, /* SCID */
1130 {0}, /* PN */
1131 NULL, 0, /* Token/Token Len */
1132 441, NULL
1133 };
1134
1135 static const unsigned char rx_script_7a_body[] = {
1136 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1158 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
1165 0x00, 0x40, 0x5a, 0x02, 0x00, 0x00, 0x56, 0x03, 0x03, 0xd5, 0xfb, 0x6a,
1166 0x81, 0x1c, 0xdb, 0xa2, 0x5c, 0x11, 0x31, 0xda, 0x15, 0x28, 0x97, 0x94,
1167 0x83, 0xfd, 0x9d, 0x91, 0x0e, 0x87, 0x71, 0x46, 0x64, 0xb4, 0xd9, 0x9e,
1168 0xbd, 0xa8, 0x48, 0x32, 0xbf, 0x00, 0x13, 0x03, 0x00, 0x00, 0x2e, 0x00,
1169 0x2b, 0x00, 0x02, 0x03, 0x04, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00,
1170 0x20, 0xef, 0xbb, 0x46, 0xe9, 0xb4, 0xf6, 0x54, 0xc4, 0x07, 0x71, 0xdc,
1171 0x50, 0xd5, 0x69, 0x40, 0xbc, 0x85, 0x7f, 0xf9, 0x48, 0x14, 0xe3, 0xd6,
1172 0x08, 0xa9, 0x0b, 0xfd, 0xbe, 0xf1, 0x57, 0x21, 0x34,
1173 };
1174
1175 static const QUIC_PKT_HDR rx_script_7b_expect_hdr = {
1176 QUIC_PKT_TYPE_HANDSHAKE,
1177 0, /* Spin Bit */
1178 0, /* Key Phase */
1179 2, /* PN Length */
1180 0, /* Partial */
1181 1, /* Fixed */
1182 1, /* Version */
1183 {0, {0}}, /* DCID */
1184 {4, {0x03, 0x45, 0x0c, 0x7a}}, /* SCID */
1185 {0}, /* PN */
1186 NULL, 0, /* Token/Token Len */
1187 657, NULL
1188 };
1189
1190 static const unsigned char rx_script_7b_body[] = {
1191 0x06, 0x00, 0x42, 0x8d, 0x08, 0x00, 0x00, 0x82, 0x00, 0x80, 0x00, 0x10,
1192 0x00, 0x08, 0x00, 0x06, 0x05, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x00, 0x39,
1193 0x00, 0x70, 0x46, 0x0a, 0x0d, 0xdc, 0x59, 0xf0, 0x4e, 0xb2, 0x2c, 0xac,
1194 0x69, 0x6a, 0xc9, 0x77, 0xa9, 0x99, 0x05, 0x04, 0x80, 0x08, 0x00, 0x00,
1195 0x06, 0x04, 0x80, 0x08, 0x00, 0x00, 0x07, 0x04, 0x80, 0x08, 0x00, 0x00,
1196 0x04, 0x04, 0x80, 0x0c, 0x00, 0x00, 0x08, 0x02, 0x40, 0x64, 0x09, 0x02,
1197 0x40, 0x64, 0x01, 0x04, 0x80, 0x00, 0x75, 0x30, 0x03, 0x02, 0x45, 0xac,
1198 0x0b, 0x01, 0x1a, 0x0c, 0x00, 0x02, 0x10, 0x42, 0xf0, 0xed, 0x09, 0x07,
1199 0x5b, 0xd9, 0x5a, 0xb2, 0x39, 0x5d, 0x73, 0x2c, 0x57, 0x1f, 0x50, 0x00,
1200 0x0b, 0xe0, 0x3e, 0xf3, 0xd6, 0x91, 0x6f, 0x9c, 0xcc, 0x31, 0xf7, 0xa5,
1201 0x0e, 0x01, 0x04, 0x0f, 0x04, 0x03, 0x45, 0x0c, 0x7a, 0x10, 0x04, 0xfa,
1202 0x5d, 0xd6, 0x80, 0x20, 0x01, 0x00, 0x0b, 0x00, 0x01, 0x8f, 0x00, 0x00,
1203 0x01, 0x8b, 0x00, 0x01, 0x86, 0x30, 0x82, 0x01, 0x82, 0x30, 0x82, 0x01,
1204 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x0a, 0x73, 0x0f, 0x86,
1205 0x18, 0xf2, 0xc3, 0x30, 0x01, 0xd2, 0xc0, 0xc1, 0x62, 0x52, 0x13, 0xf1,
1206 0x9c, 0x13, 0x39, 0xb5, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
1207 0x3d, 0x04, 0x03, 0x02, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03,
1208 0x55, 0x04, 0x03, 0x0c, 0x0c, 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e,
1209 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x30,
1210 0x38, 0x30, 0x32, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38, 0x5a, 0x17, 0x0d,
1211 0x32, 0x32, 0x30, 0x39, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x31, 0x38,
1212 0x5a, 0x30, 0x17, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03,
1213 0x0c, 0x0c, 0x6d, 0x61, 0x70, 0x61, 0x6b, 0x74, 0x2e, 0x6c, 0x6f, 0x63,
1214 0x61, 0x6c, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
1215 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01,
1216 0x07, 0x03, 0x42, 0x00, 0x04, 0x67, 0xf4, 0xd3, 0x8f, 0x15, 0x6d, 0xee,
1217 0x85, 0xcc, 0x2a, 0x77, 0xfc, 0x0b, 0x8f, 0x9f, 0xcf, 0xa9, 0x95, 0x5d,
1218 0x5b, 0xcd, 0xb7, 0x8b, 0xba, 0x31, 0x0a, 0x73, 0x62, 0xc5, 0xd0, 0x0e,
1219 0x07, 0x90, 0xae, 0x38, 0x43, 0x79, 0xce, 0x5e, 0x33, 0xad, 0x31, 0xbf,
1220 0x9f, 0x2a, 0x56, 0x83, 0xa5, 0x24, 0x16, 0xab, 0x0c, 0xf1, 0x64, 0xbe,
1221 0xe4, 0x93, 0xb5, 0x89, 0xd6, 0x05, 0xe4, 0xf7, 0x7b, 0xa3, 0x53, 0x30,
1222 0x51, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
1223 0x02, 0x64, 0x0f, 0x55, 0x69, 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9,
1224 0x1d, 0xa5, 0x5a, 0xd0, 0x48, 0x96, 0x9f, 0x60, 0x30, 0x1f, 0x06, 0x03,
1225 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x02, 0x64, 0x0f,
1226 0x55, 0x69, 0x14, 0x91, 0x19, 0xed, 0xf9, 0x1a, 0xe9, 0x1d, 0xa5, 0x5a,
1227 0xd0, 0x48, 0x96, 0x9f, 0x60, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13,
1228 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0a,
1229 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47,
1230 0x00, 0x30, 0x44, 0x02, 0x20, 0x0a, 0x82, 0x92, 0x6e, 0xd3, 0xc6, 0x66,
1231 0xd9, 0xd3, 0x75, 0xff, 0x71, 0x3b, 0x61, 0x46, 0x21, 0x00, 0xe6, 0x21,
1232 0x5d, 0x9c, 0x86, 0xe9, 0x65, 0x40, 0x4f, 0xeb, 0x70, 0x4f, 0x2c, 0xad,
1233 0x00, 0x02, 0x20, 0x08, 0xc2, 0x07, 0x5d, 0x16, 0xfc, 0x54, 0x34, 0x2b,
1234 0xb4, 0x18, 0x67, 0x44, 0x81, 0xc9, 0xa9, 0x67, 0x2e, 0xce, 0xa1, 0x02,
1235 0x9f, 0x3b, 0xe5, 0x61, 0x16, 0x0b, 0x50, 0xf6, 0xa1, 0x50, 0x94, 0x00,
1236 0x00, 0x0f, 0x00, 0x00, 0x4c, 0x04, 0x03, 0x00, 0x48, 0x30, 0x46, 0x02,
1237 0x21, 0x00, 0xaa, 0x18, 0x61, 0x93, 0xdf, 0xbb, 0x79, 0xe7, 0x34, 0x7e,
1238 0x2e, 0x61, 0x13, 0x8c, 0xa0, 0x33, 0xfb, 0x33, 0xca, 0xfc, 0xd2, 0x45,
1239 0xb0, 0xc7, 0x89, 0x3d, 0xf1, 0xd6, 0x54, 0x94, 0x05, 0xb6, 0x02, 0x21,
1240 0x00, 0xef, 0x6c, 0xb6, 0xf2, 0x00, 0xb2, 0x32, 0xb1, 0xf3, 0x3f, 0x59,
1241 0xf5, 0xc8, 0x18, 0xbe, 0x39, 0xbb, 0x27, 0xf8, 0x67, 0xac, 0xcb, 0x63,
1242 0xa4, 0x29, 0xfb, 0x8e, 0x88, 0x0f, 0xe5, 0xe9, 0x7e, 0x14, 0x00, 0x00,
1243 0x20, 0xfc, 0x2c, 0x4c, 0xa7, 0x77, 0x24, 0x79, 0x29, 0xa8, 0x82, 0x1a,
1244 0x4d, 0x58, 0x9d, 0x82, 0xe2, 0x09, 0x36, 0x63, 0x0e, 0x0b, 0x55, 0x51,
1245 0x80, 0x93, 0x40, 0xda, 0x41, 0x33, 0x08, 0x10, 0x2c,
1246 };
1247
1248 static const QUIC_PKT_HDR rx_script_7c_expect_hdr = {
1249 QUIC_PKT_TYPE_1RTT,
1250 0, /* Spin Bit */
1251 0, /* Key Phase */
1252 2, /* PN Length */
1253 0, /* Partial */
1254 1, /* Fixed */
1255 0, /* Version */
1256 {0, {0}}, /* DCID */
1257 {0, {0}}, /* SCID */
1258 {0}, /* PN */
1259 NULL, 0, /* Token/Token Len */
1260 72, NULL
1261 };
1262
1263 static const unsigned char rx_script_7c_body[] = {
1264 0x18, 0x03, 0x00, 0x04, 0xf7, 0x75, 0x72, 0xa2, 0xfd, 0x17, 0xd4, 0x82,
1265 0x8e, 0xe9, 0x5b, 0xce, 0xed, 0xec, 0x88, 0xb9, 0x73, 0xbf, 0x36, 0x9f,
1266 0x18, 0x02, 0x00, 0x04, 0x5f, 0x43, 0x96, 0xe4, 0x15, 0xdc, 0x56, 0x6b,
1267 0x67, 0x4c, 0x36, 0xb2, 0xe2, 0x77, 0xdc, 0x6e, 0xb9, 0x2c, 0x0d, 0x79,
1268 0x18, 0x01, 0x00, 0x04, 0xcb, 0x83, 0x4a, 0xf4, 0x8d, 0x7b, 0x69, 0x90,
1269 0xaf, 0x0d, 0xd2, 0x38, 0xa4, 0xf1, 0x94, 0xff, 0x63, 0x24, 0xd3, 0x7a,
1270 };
1271
1272 static const struct rx_test_op rx_script_7[] = {
1273 RX_OP_ADD_RX_DCID(empty_conn_id)
1274 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_7_c2s_init_dcid)
1275 RX_OP_INJECT_N(7)
1276 RX_OP_CHECK_PKT_N(7a)
1277 RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
1278 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
1279 QRL_SUITE_CHACHA20POLY1305, rx_script_7_handshake_secret)
1280 RX_OP_CHECK_PKT_N(7b)
1281 RX_OP_CHECK_NO_PKT() /* not got secret for next packet yet */
1282 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1283 QRL_SUITE_CHACHA20POLY1305, rx_script_7_1rtt_secret)
1284 RX_OP_CHECK_PKT_N(7c)
1285 RX_OP_CHECK_NO_PKT()
1286
1287 /* Try injecting the packet again */
1288 RX_OP_INJECT_N(7)
1289 /*
1290 * Initial packet is not output due to receiving a Handshake packet causing
1291 * auto-discard of Initial keys
1292 */
1293 RX_OP_CHECK_PKT_N(7b)
1294 RX_OP_CHECK_PKT_N(7c)
1295 RX_OP_CHECK_NO_PKT()
1296 /* Try again with discarded keys */
1297 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
1298 RX_OP_INJECT_N(7)
1299 RX_OP_CHECK_PKT_N(7c)
1300 RX_OP_CHECK_NO_PKT()
1301 /* Try again */
1302 RX_OP_INJECT_N(7)
1303 RX_OP_CHECK_PKT_N(7c)
1304 RX_OP_CHECK_NO_PKT()
1305 /* Try again with discarded 1-RTT keys */
1306 RX_OP_DISCARD_EL(QUIC_ENC_LEVEL_1RTT)
1307 RX_OP_INJECT_N(7)
1308 RX_OP_CHECK_NO_PKT()
1309
1310 /* Recreate QRL, test reading packets received before key */
1311 RX_OP_SET_SCID_LEN(0)
1312 RX_OP_ADD_RX_DCID(empty_conn_id)
1313 RX_OP_INJECT_N(7)
1314 RX_OP_CHECK_NO_PKT()
1315 RX_OP_PROVIDE_SECRET_INITIAL(rx_script_7_c2s_init_dcid)
1316 RX_OP_CHECK_PKT_N(7a)
1317 RX_OP_CHECK_NO_PKT()
1318 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE,
1319 QRL_SUITE_CHACHA20POLY1305, rx_script_7_handshake_secret)
1320 RX_OP_CHECK_PKT_N(7b)
1321 RX_OP_CHECK_NO_PKT()
1322 RX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT,
1323 QRL_SUITE_CHACHA20POLY1305, rx_script_7_1rtt_secret)
1324 RX_OP_CHECK_PKT_N(7c)
1325 RX_OP_CHECK_NO_PKT()
1326
1327 RX_OP_END
1328 };
1329
1330 static const struct rx_test_op *rx_scripts[] = {
1331 rx_script_1,
1332 rx_script_2,
1333 rx_script_3,
1334 rx_script_4,
1335 rx_script_5,
1336 rx_script_6,
1337 rx_script_7
1338 };
1339
1340 static int cmp_pkt_hdr(const QUIC_PKT_HDR *a, const QUIC_PKT_HDR *b,
1341 const unsigned char *b_data, size_t b_len,
1342 int cmp_data)
1343 {
1344 int ok = 1;
1345
1346 if (b_data == NULL) {
1347 b_data = b->data;
1348 b_len = b->len;
1349 }
1350
1351 if (!TEST_int_eq(a->type, b->type)
1352 || !TEST_int_eq(a->spin_bit, b->spin_bit)
1353 || !TEST_int_eq(a->key_phase, b->key_phase)
1354 || !TEST_int_eq(a->pn_len, b->pn_len)
1355 || !TEST_int_eq(a->partial, b->partial)
1356 || !TEST_int_eq(a->fixed, b->fixed)
1357 || !TEST_uint_eq(a->version, b->version)
1358 || !TEST_true(ossl_quic_conn_id_eq(&a->dst_conn_id, &b->dst_conn_id))
1359 || !TEST_true(ossl_quic_conn_id_eq(&a->src_conn_id, &b->src_conn_id))
1360 || !TEST_mem_eq(a->pn, sizeof(a->pn), b->pn, sizeof(b->pn))
1361 || !TEST_size_t_eq(a->token_len, b->token_len)
1362 || !TEST_uint64_t_eq(a->len, b->len))
1363 ok = 0;
1364
1365 if (a->token_len > 0 && b->token_len > 0
1366 && !TEST_mem_eq(a->token, a->token_len, b->token, b->token_len))
1367 ok = 0;
1368
1369 if ((a->token_len == 0 && !TEST_ptr_null(a->token))
1370 || (b->token_len == 0 && !TEST_ptr_null(b->token)))
1371 ok = 0;
1372
1373 if (cmp_data && !TEST_mem_eq(a->data, a->len, b_data, b_len))
1374 ok = 0;
1375
1376 return ok;
1377 }
1378
1379 struct rx_state {
1380 QUIC_DEMUX *demux;
1381 OSSL_QRX *qrx;
1382 OSSL_QRX_ARGS args;
1383 };
1384
1385 static void rx_state_teardown(struct rx_state *s)
1386 {
1387 if (s->qrx != NULL) {
1388 ossl_qrx_free(s->qrx);
1389 s->qrx = NULL;
1390 }
1391
1392 if (s->demux != NULL) {
1393 ossl_quic_demux_free(s->demux);
1394 s->demux = NULL;
1395 }
1396 }
1397
1398 static int rx_state_ensure(struct rx_state *s)
1399 {
1400 if (s->demux == NULL
1401 && !TEST_ptr(s->demux = ossl_quic_demux_new(NULL,
1402 s->args.short_conn_id_len,
1403 1500)))
1404 return 0;
1405
1406 s->args.demux = s->demux;
1407
1408 if (s->qrx == NULL
1409 && !TEST_ptr(s->qrx = ossl_qrx_new(&s->args)))
1410 return 0;
1411
1412 return 1;
1413 }
1414
1415 static int rx_run_script(const struct rx_test_op *script)
1416 {
1417 int testresult = 0, pkt_outstanding = 0;
1418 struct rx_state s = {0};
1419 size_t i;
1420 OSSL_QRX_PKT pkt = {0};
1421 const struct rx_test_op *op = script;
1422
1423 for (; op->op != RX_TEST_OP_END; ++op)
1424 switch (op->op) {
1425 case RX_TEST_OP_SET_SCID_LEN:
1426 rx_state_teardown(&s);
1427 s.args.short_conn_id_len = op->enc_level;
1428 break;
1429 case RX_TEST_OP_SET_INIT_LARGEST_PN:
1430 rx_state_teardown(&s);
1431 for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
1432 s.args.init_largest_pn[i] = op->largest_pn;
1433 break;
1434 case RX_TEST_OP_ADD_RX_DCID:
1435 if (!TEST_true(rx_state_ensure(&s)))
1436 goto err;
1437 if (!TEST_true(ossl_qrx_add_dst_conn_id(s.qrx, op->dcid)))
1438 goto err;
1439 break;
1440 case RX_TEST_OP_PROVIDE_SECRET:
1441 if (!TEST_true(rx_state_ensure(&s)))
1442 goto err;
1443 if (!TEST_true(ossl_qrx_provide_secret(s.qrx, op->enc_level,
1444 op->suite_id, NULL,
1445 op->buf,
1446 op->buf_len)))
1447 goto err;
1448 break;
1449 case RX_TEST_OP_PROVIDE_SECRET_INITIAL:
1450 if (!TEST_true(rx_state_ensure(&s)))
1451 goto err;
1452 if (!TEST_true(ossl_quic_provide_initial_secret(NULL, NULL,
1453 op->dcid, 0,
1454 s.qrx, NULL)))
1455 goto err;
1456 break;
1457 case RX_TEST_OP_DISCARD_EL:
1458 if (!TEST_true(rx_state_ensure(&s)))
1459 goto err;
1460 if (!TEST_true(ossl_qrx_discard_enc_level(s.qrx, op->enc_level)))
1461 goto err;
1462 break;
1463 case RX_TEST_OP_INJECT:
1464 if (!TEST_true(rx_state_ensure(&s)))
1465 goto err;
1466 if (!TEST_true(ossl_quic_demux_inject(s.demux,
1467 op->buf, op->buf_len,
1468 NULL, NULL)))
1469 goto err;
1470 break;
1471 case RX_TEST_OP_CHECK_PKT:
1472 if (!TEST_true(rx_state_ensure(&s)))
1473 goto err;
1474
1475 if (!TEST_true(ossl_qrx_read_pkt(s.qrx, &pkt)))
1476 goto err;
1477
1478 pkt_outstanding = 1;
1479 if (!TEST_ptr(pkt.hdr))
1480 goto err;
1481
1482 if (!TEST_mem_eq(pkt.hdr->data, pkt.hdr->len,
1483 op->buf, op->buf_len))
1484 goto err;
1485
1486 if (!TEST_true(cmp_pkt_hdr(pkt.hdr, op->hdr,
1487 op->buf, op->buf_len, 1)))
1488 goto err;
1489
1490 ossl_qrx_release_pkt(s.qrx, pkt.handle);
1491 pkt_outstanding = 0;
1492 break;
1493 case RX_TEST_OP_CHECK_NO_PKT:
1494 if (!TEST_true(rx_state_ensure(&s)))
1495 goto err;
1496
1497 if (!TEST_false(ossl_qrx_read_pkt(s.qrx, &pkt)))
1498 goto err;
1499
1500 break;
1501 default:
1502 OPENSSL_assert(0);
1503 goto err;
1504 }
1505
1506 testresult = 1;
1507 err:
1508 if (pkt_outstanding)
1509 ossl_qrx_release_pkt(s.qrx, pkt.handle);
1510 rx_state_teardown(&s);
1511 return testresult;
1512 }
1513
1514 static int test_rx_script(int idx)
1515 {
1516 return rx_run_script(rx_scripts[idx]);
1517 }
1518
1519 /* Packet Header Tests */
1520 struct pkt_hdr_test {
1521 QUIC_PKT_HDR hdr;
1522 const unsigned char *expected;
1523 size_t expected_len;
1524 const unsigned char *payload;
1525 size_t payload_len;
1526 size_t short_conn_id_len;
1527 /*
1528 * Minimum number of bytes which should be required for a successful decode.
1529 * SIZE_MAX if should never decode successfully.
1530 */
1531 size_t min_success_len;
1532 size_t pn_offset, sample_offset;
1533 };
1534
1535 /* Packet Header Test 1: INITIAL With SCID */
1536 static const unsigned char pkt_hdr_test_1_expected[] = {
1537 0xc1, /* Long|Fixed, Type=Initial, PN Len=2 */
1538 0x00, 0x00, 0x00, 0x01, /* Version */
1539 0x00, /* DCID Length */
1540 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1541 0x00, /* Token Length */
1542 0x15, /* Length=21 */
1543 0x33, 0x44, /* Encoded PN */
1544 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1545 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1546 0x20, 0x21, 0x22
1547 };
1548
1549 static const unsigned char pkt_hdr_test_1_payload[] = {
1550 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1551 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1552 0x20, 0x21, 0x22
1553 };
1554
1555 static const struct pkt_hdr_test pkt_hdr_test_1 = {
1556 {
1557 QUIC_PKT_TYPE_INITIAL, /* type */
1558 0, /* spin bit */
1559 0, /* key phase */
1560 2, /* PN length */
1561 0, /* partial */
1562 1, /* fixed */
1563 1, /* version */
1564 { 0, {0} }, /* DCID */
1565 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1566 { 0x33, 0x44 }, /* PN */
1567 NULL, 0, /* Token/Token Len */
1568 19, NULL /* Len/Data */
1569 },
1570 pkt_hdr_test_1_expected, OSSL_NELEM(pkt_hdr_test_1_expected),
1571 pkt_hdr_test_1_payload, OSSL_NELEM(pkt_hdr_test_1_payload),
1572 0, sizeof(pkt_hdr_test_1_expected),
1573 17, 21
1574 };
1575
1576 /* Packet Header Test 2: INITIAL With SCID and Token */
1577 static const unsigned char pkt_hdr_test_2_expected[] = {
1578 0xc1, /* Long|Fixed, Type=Initial, PN Len=2 */
1579 0x00, 0x00, 0x00, 0x01, /* Version */
1580 0x00, /* DCID Length */
1581 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1582 0x07, /* Token Length */
1583 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
1584 0x15, /* Length=21 */
1585 0x33, 0x44, /* Encoded PN */
1586 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1587 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1588 0x20, 0x21, 0x22
1589 };
1590
1591 static const unsigned char pkt_hdr_test_2_payload[] = {
1592 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1593 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1594 0x20, 0x21, 0x22
1595 };
1596
1597 static const unsigned char pkt_hdr_test_2_token[] = {
1598 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96
1599 };
1600
1601 static const struct pkt_hdr_test pkt_hdr_test_2 = {
1602 {
1603 QUIC_PKT_TYPE_INITIAL, /* type */
1604 0, /* spin bit */
1605 0, /* key phase */
1606 2, /* PN length */
1607 0, /* partial */
1608 1, /* fixed */
1609 1, /* version */
1610 { 0, {0} }, /* DCID */
1611 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1612 { 0x33, 0x44 }, /* PN */
1613 pkt_hdr_test_2_token, sizeof(pkt_hdr_test_2_token), /* Token */
1614 19, NULL /* Len/Data */
1615 },
1616 pkt_hdr_test_2_expected, OSSL_NELEM(pkt_hdr_test_2_expected),
1617 pkt_hdr_test_2_payload, OSSL_NELEM(pkt_hdr_test_2_payload),
1618 0, sizeof(pkt_hdr_test_2_expected),
1619 24, 28
1620 };
1621
1622 /* Packet Header Test 3: INITIAL With DCID and SCID and Token */
1623 static const unsigned char pkt_hdr_test_3_expected[] = {
1624 0xc1, /* Long|Fixed, Type=Initial, PN Len=2 */
1625 0x00, 0x00, 0x00, 0x01, /* Version */
1626 0x03, /* DCID Length */
1627 0x70, 0x71, 0x72, /* DCID */
1628 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1629 0x06, /* Token Length */
1630 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
1631 0x15, /* Length=21 */
1632 0x33, 0x44, /* Encoded PN */
1633 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1634 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1635 0x20, 0x21, 0x22
1636 };
1637
1638 static const unsigned char pkt_hdr_test_3_payload[] = {
1639 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1640 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1641 0x20, 0x21, 0x22
1642 };
1643
1644 static const unsigned char pkt_hdr_test_3_token[] = {
1645 0x91, 0x92, 0x93, 0x94, 0x95, 0x96
1646 };
1647
1648 static const struct pkt_hdr_test pkt_hdr_test_3 = {
1649 {
1650 QUIC_PKT_TYPE_INITIAL, /* type */
1651 0, /* spin bit */
1652 0, /* key phase */
1653 2, /* PN length */
1654 0, /* partial */
1655 1, /* fixed */
1656 1, /* version */
1657 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1658 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1659 { 0x33, 0x44 }, /* PN */
1660 pkt_hdr_test_3_token, sizeof(pkt_hdr_test_3_token), /* Token */
1661 19, NULL /* Len/Data */
1662 },
1663 pkt_hdr_test_3_expected, OSSL_NELEM(pkt_hdr_test_3_expected),
1664 pkt_hdr_test_3_payload, OSSL_NELEM(pkt_hdr_test_3_payload),
1665 0, sizeof(pkt_hdr_test_3_expected),
1666 26, 30
1667 };
1668
1669 /* Packet Header Test 4: 0-RTT */
1670 static const unsigned char pkt_hdr_test_4_expected[] = {
1671 0xd0, /* Long|Fixed, Type=0-RTT, PN Len=1 */
1672 0x00, 0x00, 0x00, 0x01, /* Version */
1673 0x03, /* DCID Length */
1674 0x70, 0x71, 0x72, /* DCID */
1675 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1676 0x14, /* Length=20 */
1677 0x33, /* Encoded PN */
1678 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1679 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1680 0x20, 0x21, 0x22
1681 };
1682
1683 static const unsigned char pkt_hdr_test_4_payload[] = {
1684 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1685 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1686 0x20, 0x21, 0x22
1687 };
1688
1689 static const struct pkt_hdr_test pkt_hdr_test_4 = {
1690 {
1691 QUIC_PKT_TYPE_0RTT, /* type */
1692 0, /* spin bit */
1693 0, /* key phase */
1694 1, /* PN length */
1695 0, /* partial */
1696 1, /* fixed */
1697 1, /* version */
1698 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1699 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1700 { 0x33 }, /* PN */
1701 NULL, 0, /* Token */
1702 19, NULL /* Len/Data */
1703 },
1704 pkt_hdr_test_4_expected, OSSL_NELEM(pkt_hdr_test_4_expected),
1705 pkt_hdr_test_4_payload, OSSL_NELEM(pkt_hdr_test_4_payload),
1706 0, sizeof(pkt_hdr_test_4_expected),
1707 19, 23
1708 };
1709
1710 /* Packet Header Test 5: Handshake */
1711 static const unsigned char pkt_hdr_test_5_expected[] = {
1712 0xe0, /* Long|Fixed, Type=Handshake, PN Len=1 */
1713 0x00, 0x00, 0x00, 0x01, /* Version */
1714 0x03, /* DCID Length */
1715 0x70, 0x71, 0x72, /* DCID */
1716 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1717 0x14, /* Length=20 */
1718 0x33, /* Encoded PN */
1719 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1720 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1721 0x20, 0x21, 0x22
1722 };
1723
1724 static const unsigned char pkt_hdr_test_5_payload[] = {
1725 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1726 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1727 0x20, 0x21, 0x22
1728 };
1729
1730 static const struct pkt_hdr_test pkt_hdr_test_5 = {
1731 {
1732 QUIC_PKT_TYPE_HANDSHAKE, /* type */
1733 0, /* spin bit */
1734 0, /* key phase */
1735 1, /* PN length */
1736 0, /* partial */
1737 1, /* fixed */
1738 1, /* version */
1739 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1740 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1741 { 0x33 }, /* PN */
1742 NULL, 0, /* Token */
1743 19, NULL /* Len/Data */
1744 },
1745 pkt_hdr_test_5_expected, OSSL_NELEM(pkt_hdr_test_5_expected),
1746 pkt_hdr_test_5_payload, OSSL_NELEM(pkt_hdr_test_5_payload),
1747 0, sizeof(pkt_hdr_test_5_expected),
1748 19, 23
1749 };
1750
1751 /* Packet Header Test 6: Retry */
1752 static const unsigned char pkt_hdr_test_6_expected[] = {
1753 0xf0, /* Long|Fixed, Type=Retry */
1754 0x00, 0x00, 0x00, 0x01, /* Version */
1755 0x03, /* DCID Length */
1756 0x70, 0x71, 0x72, /* DCID */
1757 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1758 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* Retry Token */
1759 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
1760 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f /* Retry Integrity Tag */
1761 };
1762
1763 static const unsigned char pkt_hdr_test_6_payload[] = {
1764 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* Retry Token */
1765 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
1766 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f /* Retry Integrity Tag */
1767 };
1768
1769 static const struct pkt_hdr_test pkt_hdr_test_6 = {
1770 {
1771 QUIC_PKT_TYPE_RETRY, /* type */
1772 0, /* spin bit */
1773 0, /* key phase */
1774 0, /* PN length */
1775 0, /* partial */
1776 1, /* fixed */
1777 1, /* version */
1778 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1779 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1780 { 0 }, /* PN */
1781 NULL, 0, /* Token */
1782 24, NULL /* Len/Data */
1783 },
1784 pkt_hdr_test_6_expected, OSSL_NELEM(pkt_hdr_test_6_expected),
1785 pkt_hdr_test_6_payload, OSSL_NELEM(pkt_hdr_test_6_payload),
1786 0, 21,
1787 SIZE_MAX, SIZE_MAX
1788 };
1789
1790 /* Packet Header Test 7: 1-RTT */
1791 static const unsigned char pkt_hdr_test_7_expected[] = {
1792 0x42, /* Short|Fixed, Type=1-RTT, PN Len=3 */
1793 0x70, 0x71, 0x72, /* DCID */
1794 0x50, 0x51, 0x52, /* PN */
1795 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1796 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1797 };
1798
1799 static const unsigned char pkt_hdr_test_7_payload[] = {
1800 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1801 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1802 };
1803
1804 static const struct pkt_hdr_test pkt_hdr_test_7 = {
1805 {
1806 QUIC_PKT_TYPE_1RTT, /* type */
1807 0, /* spin bit */
1808 0, /* key phase */
1809 3, /* PN length */
1810 0, /* partial */
1811 1, /* fixed */
1812 0, /* version */
1813 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1814 { 0, {0} }, /* SCID */
1815 { 0x50, 0x51, 0x52 }, /* PN */
1816 NULL, 0, /* Token */
1817 18, NULL /* Len/Data */
1818 },
1819 pkt_hdr_test_7_expected, OSSL_NELEM(pkt_hdr_test_7_expected),
1820 pkt_hdr_test_7_payload, OSSL_NELEM(pkt_hdr_test_7_payload),
1821 3, 21,
1822 4, 8
1823 };
1824
1825 /* Packet Header Test 8: 1-RTT with Spin Bit */
1826 static const unsigned char pkt_hdr_test_8_expected[] = {
1827 0x62, /* Short|Fixed, Type=1-RTT, PN Len=3, Spin=1 */
1828 0x70, 0x71, 0x72, /* DCID */
1829 0x50, 0x51, 0x52, /* PN */
1830 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1831 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1832 };
1833
1834 static const unsigned char pkt_hdr_test_8_payload[] = {
1835 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1836 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1837 };
1838
1839 static const struct pkt_hdr_test pkt_hdr_test_8 = {
1840 {
1841 QUIC_PKT_TYPE_1RTT, /* type */
1842 1, /* spin bit */
1843 0, /* key phase */
1844 3, /* PN length */
1845 0, /* partial */
1846 1, /* fixed */
1847 0, /* version */
1848 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1849 { 0, {0} }, /* SCID */
1850 { 0x50, 0x51, 0x52 }, /* PN */
1851 NULL, 0, /* Token */
1852 18, NULL /* Len/Data */
1853 },
1854 pkt_hdr_test_8_expected, OSSL_NELEM(pkt_hdr_test_8_expected),
1855 pkt_hdr_test_8_payload, OSSL_NELEM(pkt_hdr_test_8_payload),
1856 3, 21,
1857 4, 8
1858 };
1859
1860 /* Packet Header Test 9: 1-RTT with Key Phase Bit */
1861 static const unsigned char pkt_hdr_test_9_expected[] = {
1862 0x46, /* Short|Fixed, Type=1-RTT, PN Len=3, Key Phase=1 */
1863 0x70, 0x71, 0x72, /* DCID */
1864 0x50, 0x51, 0x52, /* PN */
1865 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1866 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1867 };
1868
1869 static const unsigned char pkt_hdr_test_9_payload[] = {
1870 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1871 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1872 };
1873
1874 static const struct pkt_hdr_test pkt_hdr_test_9 = {
1875 {
1876 QUIC_PKT_TYPE_1RTT, /* type */
1877 0, /* spin bit */
1878 1, /* key phase */
1879 3, /* PN length */
1880 0, /* partial */
1881 1, /* fixed */
1882 0, /* version */
1883 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1884 { 0, {0} }, /* SCID */
1885 { 0x50, 0x51, 0x52 }, /* PN */
1886 NULL, 0, /* Token */
1887 18, NULL /* Len/Data */
1888 },
1889 pkt_hdr_test_9_expected, OSSL_NELEM(pkt_hdr_test_9_expected),
1890 pkt_hdr_test_9_payload, OSSL_NELEM(pkt_hdr_test_9_payload),
1891 3, 21,
1892 4, 8
1893 };
1894
1895 /* Packet Header Test 10: Handshake with 4-Byte PN */
1896 static const unsigned char pkt_hdr_test_10_expected[] = {
1897 0xe3, /* Long|Fixed, Type=Handshake, PN Len=4 */
1898 0x00, 0x00, 0x00, 0x01, /* Version */
1899 0x03, /* DCID Length */
1900 0x70, 0x71, 0x72, /* DCID */
1901 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
1902 0x17, /* Length=20 */
1903 0x33, 0x44, 0x55, 0x66, /* Encoded PN */
1904 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
1905 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1906 0x20, 0x21, 0x22
1907 };
1908
1909 static const unsigned char pkt_hdr_test_10_payload[] = {
1910 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1911 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
1912 0x20, 0x21, 0x22
1913 };
1914
1915 static const struct pkt_hdr_test pkt_hdr_test_10 = {
1916 {
1917 QUIC_PKT_TYPE_HANDSHAKE, /* type */
1918 0, /* spin bit */
1919 0, /* key phase */
1920 4, /* PN length */
1921 0, /* partial */
1922 1, /* fixed */
1923 1, /* version */
1924 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1925 { 8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5 } }, /* SCID */
1926 { 0x33, 0x44, 0x55, 0x66 }, /* PN */
1927 NULL, 0, /* Token */
1928 19, NULL /* Len/Data */
1929 },
1930 pkt_hdr_test_10_expected, OSSL_NELEM(pkt_hdr_test_10_expected),
1931 pkt_hdr_test_10_payload, OSSL_NELEM(pkt_hdr_test_10_payload),
1932 0, sizeof(pkt_hdr_test_10_expected),
1933 19, 23
1934 };
1935
1936 /* Packet Header Test 11: 1-RTT with 4-Byte PN */
1937 static const unsigned char pkt_hdr_test_11_expected[] = {
1938 0x43, /* Short|Fixed, Type=1-RTT, PN Len=4 */
1939 0x70, 0x71, 0x72, /* DCID */
1940 0x50, 0x51, 0x52, 0x53, /* PN */
1941 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1942 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1943 };
1944
1945 static const unsigned char pkt_hdr_test_11_payload[] = {
1946 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
1947 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
1948 };
1949
1950 static const struct pkt_hdr_test pkt_hdr_test_11 = {
1951 {
1952 QUIC_PKT_TYPE_1RTT, /* type */
1953 0, /* spin bit */
1954 0, /* key phase */
1955 4, /* PN length */
1956 0, /* partial */
1957 1, /* fixed */
1958 0, /* version */
1959 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1960 { 0, {0} }, /* SCID */
1961 { 0x50, 0x51, 0x52, 0x53 }, /* PN */
1962 NULL, 0, /* Token */
1963 18, NULL /* Len/Data */
1964 },
1965 pkt_hdr_test_11_expected, OSSL_NELEM(pkt_hdr_test_11_expected),
1966 pkt_hdr_test_11_payload, OSSL_NELEM(pkt_hdr_test_11_payload),
1967 3, 21,
1968 4, 8
1969 };
1970
1971 /* Packet Header Test 12: Version Negotiation */
1972 static const unsigned char pkt_hdr_test_12_expected[] = {
1973 0xc0, /* Long|Fixed, Type=Version Neg */
1974 0x00, 0x00, 0x00, 0x00, /* Version (0) */
1975 0x03, 0x70, 0x71, 0x72, /* DCID */
1976 0x02, 0x81, 0x82, /* SCID */
1977 0x11, 0x22, 0x33, 0x44 /* One Version */
1978 };
1979
1980 static const unsigned char pkt_hdr_test_12_payload[] = {
1981 0x11, 0x22, 0x33, 0x44
1982 };
1983
1984 static const struct pkt_hdr_test pkt_hdr_test_12 = {
1985 {
1986 QUIC_PKT_TYPE_VERSION_NEG, /* type */
1987 0, /* spin bit */
1988 0, /* key phase */
1989 0, /* PN length */
1990 0, /* partial */
1991 1, /* fixed */
1992 0, /* version */
1993 { 3, {0x70, 0x71, 0x72} }, /* DCID */
1994 { 2, {0x81, 0x82} }, /* SCID */
1995 { 0 }, /* PN */
1996 NULL, 0, /* Token */
1997 4, NULL /* Len/Data */
1998 },
1999 pkt_hdr_test_12_expected, OSSL_NELEM(pkt_hdr_test_12_expected),
2000 pkt_hdr_test_12_payload, OSSL_NELEM(pkt_hdr_test_12_payload),
2001 0, 12,
2002 SIZE_MAX, SIZE_MAX
2003 };
2004
2005 /* Packet Header Test 13: Version Negotiation without Fixed Bit */
2006 static const unsigned char pkt_hdr_test_13_expected[] = {
2007 0x80, /* Long|Fixed, Type=Version Neg */
2008 0x00, 0x00, 0x00, 0x00, /* Version (0) */
2009 0x03, 0x70, 0x71, 0x72, /* DCID */
2010 0x02, 0x81, 0x82, /* SCID */
2011 0x11, 0x22, 0x33, 0x44 /* One Version */
2012 };
2013
2014 static const unsigned char pkt_hdr_test_13_payload[] = {
2015 0x11, 0x22, 0x33, 0x44
2016 };
2017
2018 static const struct pkt_hdr_test pkt_hdr_test_13 = {
2019 {
2020 QUIC_PKT_TYPE_VERSION_NEG, /* type */
2021 0, /* spin bit */
2022 0, /* key phase */
2023 0, /* PN length */
2024 0, /* partial */
2025 0, /* fixed */
2026 0, /* version */
2027 { 3, {0x70, 0x71, 0x72} }, /* DCID */
2028 { 2, {0x81, 0x82} }, /* SCID */
2029 { 0 }, /* PN */
2030 NULL, 0, /* Token */
2031 4, NULL /* Len/Data */
2032 },
2033 pkt_hdr_test_13_expected, OSSL_NELEM(pkt_hdr_test_13_expected),
2034 pkt_hdr_test_13_payload, OSSL_NELEM(pkt_hdr_test_13_payload),
2035 0, 12,
2036 SIZE_MAX, SIZE_MAX
2037 };
2038
2039 /* Packet Header Test 14: 1-RTT - Malformed - No Fixed Bit */
2040 static const unsigned char pkt_hdr_test_14_expected[] = {
2041 0x02, /* Fixed, Type=1-RTT, PN Len=3 */
2042 0x70, 0x71, 0x72, /* DCID */
2043 0x50, 0x51, 0x52, /* PN */
2044 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
2045 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1
2046 };
2047
2048 static const struct pkt_hdr_test pkt_hdr_test_14 = {
2049 { 0 },
2050 pkt_hdr_test_14_expected, OSSL_NELEM(pkt_hdr_test_14_expected),
2051 NULL, 0,
2052 3, SIZE_MAX,
2053 4, 8
2054 };
2055
2056 /* Packet Header Test 15: Handshake - Malformed - No Fixed Bit */
2057 static const unsigned char pkt_hdr_test_15_expected[] = {
2058 0xa0, /* Long, Type=Handshake, PN Len=1 */
2059 0x00, 0x00, 0x00, 0x01, /* Version */
2060 0x03, /* DCID Length */
2061 0x70, 0x71, 0x72, /* DCID */
2062 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2063 0x14, /* Length=20 */
2064 0x33, /* Encoded PN */
2065 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2066 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2067 0x20, 0x21, 0x22
2068 };
2069
2070 static const struct pkt_hdr_test pkt_hdr_test_15 = {
2071 { 0 },
2072 pkt_hdr_test_15_expected, OSSL_NELEM(pkt_hdr_test_15_expected),
2073 NULL, 0,
2074 0, SIZE_MAX,
2075 19, 23
2076 };
2077
2078 /* Packet Header Test 16: Handshake - Malformed - Wrong Version */
2079 static const unsigned char pkt_hdr_test_16_expected[] = {
2080 0xe0, /* Long|Fixed, Type=Handshake, PN Len=1 */
2081 0x00, 0x00, 0x00, 0x02, /* Version */
2082 0x03, /* DCID Length */
2083 0x70, 0x71, 0x72, /* DCID */
2084 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5, /* SCID Length, SCID */
2085 0x14, /* Length=20 */
2086 0x33, /* Encoded PN */
2087 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* Payload */
2088 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2089 0x20, 0x21, 0x22
2090 };
2091
2092 static const struct pkt_hdr_test pkt_hdr_test_16 = {
2093 { 0 },
2094 pkt_hdr_test_16_expected, OSSL_NELEM(pkt_hdr_test_16_expected),
2095 NULL, 0,
2096 0, SIZE_MAX,
2097 19, 23
2098 };
2099
2100 static const struct pkt_hdr_test *const pkt_hdr_tests[] = {
2101 &pkt_hdr_test_1,
2102 &pkt_hdr_test_2,
2103 &pkt_hdr_test_3,
2104 &pkt_hdr_test_4,
2105 &pkt_hdr_test_5,
2106 &pkt_hdr_test_6,
2107 &pkt_hdr_test_7,
2108 &pkt_hdr_test_8,
2109 &pkt_hdr_test_9,
2110 &pkt_hdr_test_10,
2111 &pkt_hdr_test_11,
2112 &pkt_hdr_test_12,
2113 &pkt_hdr_test_13,
2114 &pkt_hdr_test_14,
2115 &pkt_hdr_test_15,
2116 &pkt_hdr_test_16
2117 };
2118
2119 #define HPR_REPEAT_COUNT 4
2120 #define HPR_CIPHER_COUNT 3
2121
2122 /*
2123 * Count of number of times we observed an unchanged (u) or changed (c) bit in
2124 * each header-protectable bit over all test suites.
2125 */
2126 static unsigned int counts_u[HPR_CIPHER_COUNT][37] = {0};
2127 static unsigned int counts_c[HPR_CIPHER_COUNT][37] = {0};
2128
2129 static int test_wire_pkt_hdr_actual(int tidx, int repeat, int cipher,
2130 size_t trunc_len)
2131 {
2132 int testresult = 0;
2133 const struct pkt_hdr_test *t = pkt_hdr_tests[tidx];
2134 QUIC_PKT_HDR hdr = {0};
2135 QUIC_PKT_HDR_PTRS ptrs = {0}, wptrs = {0};
2136 PACKET pkt = {0};
2137 WPACKET wpkt = {0};
2138 BUF_MEM *buf = NULL;
2139 size_t l = 0, i, j;
2140 QUIC_HDR_PROTECTOR hpr = {0};
2141 unsigned char hpr_key[32] = {0,1,2,3,4,5,6,7};
2142 int have_hpr = 0, hpr_cipher_id, hpr_key_len;
2143 unsigned char *hbuf = NULL;
2144 int is_trunc = trunc_len < t->expected_len;
2145 int expect_fail = trunc_len < t->min_success_len;
2146 hpr_key[8] = (unsigned char)tidx;
2147 hpr_key[9] = (unsigned char)repeat;
2148
2149 switch (cipher) {
2150 case 0:
2151 hpr_cipher_id = QUIC_HDR_PROT_CIPHER_AES_128;
2152 hpr_key_len = 16;
2153 break;
2154 case 1:
2155 hpr_cipher_id = QUIC_HDR_PROT_CIPHER_AES_256;
2156 hpr_key_len = 32;
2157 break;
2158 case 2:
2159 hpr_cipher_id = QUIC_HDR_PROT_CIPHER_CHACHA;
2160 hpr_key_len = 32;
2161 break;
2162 default:
2163 goto err;
2164 }
2165
2166 if (!TEST_ptr(buf = BUF_MEM_new()))
2167 goto err;
2168
2169 if (!TEST_true(WPACKET_init(&wpkt, buf)))
2170 goto err;
2171
2172 if (!TEST_true(PACKET_buf_init(&pkt, t->expected, trunc_len)))
2173 goto err;
2174
2175 if (!TEST_int_eq(ossl_quic_wire_decode_pkt_hdr(&pkt, t->short_conn_id_len,
2176 0, &hdr, &ptrs),
2177 !expect_fail))
2178 goto err;
2179
2180 if (!expect_fail && !is_trunc) {
2181 if (!TEST_true(cmp_pkt_hdr(&hdr, &t->hdr, t->payload, t->payload_len, 1)))
2182 goto err;
2183
2184 if (!TEST_ptr_eq(ptrs.raw_start, t->expected))
2185 goto err;
2186
2187 if (t->pn_offset == SIZE_MAX) {
2188 if (!TEST_ptr_null(ptrs.raw_pn))
2189 goto err;
2190 } else {
2191 if (!TEST_ptr_eq(ptrs.raw_pn, t->expected + t->pn_offset))
2192 goto err;
2193 }
2194
2195 if (t->sample_offset != SIZE_MAX) {
2196 if (!TEST_ptr_eq(ptrs.raw_sample, t->expected + t->sample_offset))
2197 goto err;
2198 if (!TEST_size_t_eq(ptrs.raw_sample_len,
2199 t->expected_len - t->sample_offset))
2200 goto err;
2201 }
2202
2203 if (!TEST_true(ossl_quic_wire_encode_pkt_hdr(&wpkt, t->short_conn_id_len, &hdr, &wptrs)))
2204 goto err;
2205
2206 if (!TEST_true(WPACKET_memcpy(&wpkt, t->payload, t->payload_len)))
2207 goto err;
2208
2209 if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
2210 goto err;
2211
2212 if (!TEST_mem_eq(buf->data, l, t->expected, t->expected_len))
2213 goto err;
2214
2215 /* Test header protection. */
2216 if (t->sample_offset != SIZE_MAX) { /* if packet type has protection */
2217 if (!TEST_true(ossl_quic_hdr_protector_init(&hpr, NULL, NULL,
2218 hpr_cipher_id,
2219 hpr_key,
2220 hpr_key_len)))
2221 goto err;
2222
2223 have_hpr = 1;
2224
2225 /*
2226 * Copy into a duplicate buffer to test header protection by
2227 * comparing it against the original.
2228 */
2229 hbuf = OPENSSL_malloc(t->expected_len);
2230 if (!TEST_ptr(hbuf))
2231 goto err;
2232
2233 memcpy(hbuf, t->expected, t->expected_len);
2234
2235 /* Fixup pointers to new buffer and encrypt. */
2236 ptrs.raw_pn = hbuf + (ptrs.raw_pn - ptrs.raw_start);
2237 ptrs.raw_sample = hbuf + (ptrs.raw_sample - ptrs.raw_start);
2238 ptrs.raw_start = hbuf;
2239 if (!TEST_true(ossl_quic_hdr_protector_encrypt(&hpr, &ptrs)))
2240 goto err;
2241
2242 /* Ensure that bytes which should not have changed did not change */
2243 for (i = 0; i < t->expected_len; ++i) {
2244 unsigned char d = t->expected[i] ^ hbuf[i], rej_mask = 0xff;
2245 size_t jrel = 0;
2246 if (i == 0) {
2247 /* Bits in first byte which must not change */
2248 rej_mask = (t->hdr.type == QUIC_PKT_TYPE_1RTT) ? ~0x1f : ~0xf;
2249 } else if (i >= t->pn_offset && i < t->pn_offset + t->hdr.pn_len) {
2250 /* PN bytes change */
2251 rej_mask = 0;
2252 jrel = 5 + (i - t->pn_offset) * 8;
2253 }
2254
2255 if (rej_mask != 0xff)
2256 for (j = 0; j < 8; ++j) {
2257 if (((1U << j) & rej_mask) != 0)
2258 /*
2259 * Bit unrelated to header protection, do not record
2260 * stats about it.
2261 */
2262 continue;
2263
2264 OPENSSL_assert(jrel + j < OSSL_NELEM(counts_u[cipher]));
2265 if ((d & (1U << j)) != 0)
2266 ++counts_c[cipher][jrel + j]; /* bit did change */
2267 else
2268 ++counts_u[cipher][jrel + j]; /* bit did not change */
2269 }
2270
2271 /* Bits in rej_mask must not change */
2272 if (!TEST_int_eq(d & rej_mask, 0))
2273 goto err;
2274 }
2275
2276 /* Decrypt and check matches original. */
2277 if (!TEST_true(ossl_quic_hdr_protector_decrypt(&hpr, &ptrs)))
2278 goto err;
2279
2280 if (!TEST_mem_eq(hbuf, t->expected_len, t->expected, t->expected_len))
2281 goto err;
2282 }
2283 }
2284
2285 testresult = 1;
2286 err:
2287 if (have_hpr)
2288 ossl_quic_hdr_protector_destroy(&hpr);
2289 WPACKET_finish(&wpkt);
2290 BUF_MEM_free(buf);
2291 OPENSSL_free(hbuf);
2292 return testresult;
2293 }
2294
2295 static int test_wire_pkt_hdr_inner(int tidx, int repeat, int cipher)
2296 {
2297 int testresult = 0;
2298 const struct pkt_hdr_test *t = pkt_hdr_tests[tidx];
2299 size_t i;
2300
2301 /* Test with entire packet */
2302 if (!TEST_true(test_wire_pkt_hdr_actual(tidx, repeat, cipher,
2303 t->expected_len)))
2304 goto err;
2305
2306 /* Now repeat for every possible truncation of the packet */
2307 for (i = 0; i < t->expected_len; ++i)
2308 if (!TEST_true(test_wire_pkt_hdr_actual(tidx, repeat, cipher, i)))
2309 goto err;
2310
2311 testresult = 1;
2312 err:
2313 return testresult;
2314 }
2315
2316 static int test_hdr_prot_stats(void)
2317 {
2318 int testresult = 0;
2319 size_t i, cipher;
2320
2321 /*
2322 * Test that, across all previously executed tests for each header
2323 * protection cipher, every bit which can have header protection applied a)
2324 * was changed in at least one test of applying header protection, and b)
2325 * was unchanged in at least one test of applying header protection.
2326 */
2327 for (cipher = 0; cipher < HPR_CIPHER_COUNT; ++cipher)
2328 for (i = 0; i < OSSL_NELEM(counts_u[0]); ++i) {
2329 if (!TEST_true(counts_u[cipher][i]))
2330 goto err;
2331 if (!TEST_true(counts_c[cipher][i]))
2332 goto err;
2333 }
2334
2335 testresult = 1;
2336 err:
2337 return testresult;
2338 }
2339
2340 #define NUM_WIRE_PKT_HDR_TESTS \
2341 (OSSL_NELEM(pkt_hdr_tests) * HPR_REPEAT_COUNT * HPR_CIPHER_COUNT)
2342
2343 static int test_wire_pkt_hdr(int idx)
2344 {
2345 int tidx, repeat, cipher;
2346
2347 if (idx == NUM_WIRE_PKT_HDR_TESTS)
2348 return test_hdr_prot_stats();
2349
2350 cipher = idx % HPR_CIPHER_COUNT;
2351 idx /= HPR_CIPHER_COUNT;
2352
2353 repeat = idx % HPR_REPEAT_COUNT;
2354 idx /= HPR_REPEAT_COUNT;
2355
2356 tidx = idx;
2357
2358 return test_wire_pkt_hdr_inner(tidx, repeat, cipher);
2359 }
2360
2361 /* TX Tests */
2362 #define TX_TEST_OP_END 0 /* end of script */
2363 #define TX_TEST_OP_WRITE 1 /* write packet */
2364 #define TX_TEST_OP_PROVIDE_SECRET 2 /* provide TX secret */
2365 #define TX_TEST_OP_PROVIDE_SECRET_INITIAL 3 /* provide TX secret for initial */
2366 #define TX_TEST_OP_DISCARD_EL 4 /* discard an encryption level */
2367 #define TX_TEST_OP_CHECK_DGRAM 5 /* read datagram, compare to expected */
2368 #define TX_TEST_OP_CHECK_NO_DGRAM 6 /* check no datagram is in queue */
2369
2370 struct tx_test_op {
2371 unsigned char op;
2372 const unsigned char *buf;
2373 size_t buf_len;
2374 const OSSL_QTX_PKT *pkt;
2375 uint32_t enc_level, suite_id;
2376 const QUIC_CONN_ID *dcid;
2377 };
2378
2379 #define TX_OP_END \
2380 { TX_TEST_OP_END }
2381 #define TX_OP_WRITE(pkt) \
2382 { TX_TEST_OP_WRITE, NULL, 0, &(pkt), 0, 0, NULL },
2383 #define TX_OP_PROVIDE_SECRET(el, suite, key) \
2384 { \
2385 TX_TEST_OP_PROVIDE_SECRET, (key), sizeof(key), \
2386 NULL, (el), (suite), NULL \
2387 },
2388 #define TX_OP_PROVIDE_SECRET_INITIAL(dcid, is_server) \
2389 { TX_TEST_OP_PROVIDE_SECRET_INITIAL, \
2390 NULL, 0, NULL, 0, (is_server), &(dcid) },
2391 #define TX_OP_DISCARD_EL(el) \
2392 { TX_TEST_OP_DISCARD_EL, NULL, 0, NULL, (el), 0, NULL },
2393 #define TX_OP_CHECK_DGRAM(expect_dgram) \
2394 { \
2395 TX_TEST_OP_CHECK_DGRAM, (expect_dgram), sizeof(expect_dgram), \
2396 NULL, 0, 0, NULL \
2397 },
2398 #define TX_OP_CHECK_NO_DGRAM() \
2399 { TX_TEST_OP_CHECK_NO_PKT, NULL, 0, NULL, 0, 0, NULL },
2400
2401 #define TX_OP_WRITE_N(n) \
2402 TX_OP_WRITE(tx_script_##n##_pkt)
2403 #define TX_OP_CHECK_DGRAM_N(n) \
2404 TX_OP_CHECK_DGRAM(tx_script_##n##_dgram)
2405
2406 #define TX_OP_WRITE_CHECK(n) \
2407 TX_OP_WRITE_N(n) \
2408 TX_OP_CHECK_DGRAM_N(n)
2409
2410 /* 1. RFC 9001 - A.2 Client Initial */
2411 static const unsigned char tx_script_1_body[1162] = {
2412 0x06, 0x00, 0x40, 0xf1, 0x01, 0x00, 0x00, 0xed, 0x03, 0x03, 0xeb, 0xf8,
2413 0xfa, 0x56, 0xf1, 0x29, 0x39, 0xb9, 0x58, 0x4a, 0x38, 0x96, 0x47, 0x2e,
2414 0xc4, 0x0b, 0xb8, 0x63, 0xcf, 0xd3, 0xe8, 0x68, 0x04, 0xfe, 0x3a, 0x47,
2415 0xf0, 0x6a, 0x2b, 0x69, 0x48, 0x4c, 0x00, 0x00, 0x04, 0x13, 0x01, 0x13,
2416 0x02, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00,
2417 0x00, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
2418 0x6d, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06,
2419 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x10, 0x00, 0x07, 0x00, 0x05,
2420 0x04, 0x61, 0x6c, 0x70, 0x6e, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00,
2421 0x00, 0x00, 0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20,
2422 0x93, 0x70, 0xb2, 0xc9, 0xca, 0xa4, 0x7f, 0xba, 0xba, 0xf4, 0x55, 0x9f,
2423 0xed, 0xba, 0x75, 0x3d, 0xe1, 0x71, 0xfa, 0x71, 0xf5, 0x0f, 0x1c, 0xe1,
2424 0x5d, 0x43, 0xe9, 0x94, 0xec, 0x74, 0xd7, 0x48, 0x00, 0x2b, 0x00, 0x03,
2425 0x02, 0x03, 0x04, 0x00, 0x0d, 0x00, 0x10, 0x00, 0x0e, 0x04, 0x03, 0x05,
2426 0x03, 0x06, 0x03, 0x02, 0x03, 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x00,
2427 0x2d, 0x00, 0x02, 0x01, 0x01, 0x00, 0x1c, 0x00, 0x02, 0x40, 0x01, 0x00,
2428 0x39, 0x00, 0x32, 0x04, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2429 0xff, 0x05, 0x04, 0x80, 0x00, 0xff, 0xff, 0x07, 0x04, 0x80, 0x00, 0xff,
2430 0xff, 0x08, 0x01, 0x10, 0x01, 0x04, 0x80, 0x00, 0x75, 0x30, 0x09, 0x01,
2431 0x10, 0x0f, 0x08, 0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08, 0x06,
2432 0x04, 0x80, 0x00, 0xff, 0xff /* followed by zero padding */
2433 };
2434
2435 static const unsigned char tx_script_1_dgram[] = {
2436 0xc0, 0x00, 0x00, 0x00, 0x01, 0x08, 0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51,
2437 0x57, 0x08, 0x00, 0x00, 0x44, 0x9e, 0x7b, 0x9a, 0xec, 0x34, 0xd1, 0xb1,
2438 0xc9, 0x8d, 0xd7, 0x68, 0x9f, 0xb8, 0xec, 0x11, 0xd2, 0x42, 0xb1, 0x23,
2439 0xdc, 0x9b, 0xd8, 0xba, 0xb9, 0x36, 0xb4, 0x7d, 0x92, 0xec, 0x35, 0x6c,
2440 0x0b, 0xab, 0x7d, 0xf5, 0x97, 0x6d, 0x27, 0xcd, 0x44, 0x9f, 0x63, 0x30,
2441 0x00, 0x99, 0xf3, 0x99, 0x1c, 0x26, 0x0e, 0xc4, 0xc6, 0x0d, 0x17, 0xb3,
2442 0x1f, 0x84, 0x29, 0x15, 0x7b, 0xb3, 0x5a, 0x12, 0x82, 0xa6, 0x43, 0xa8,
2443 0xd2, 0x26, 0x2c, 0xad, 0x67, 0x50, 0x0c, 0xad, 0xb8, 0xe7, 0x37, 0x8c,
2444 0x8e, 0xb7, 0x53, 0x9e, 0xc4, 0xd4, 0x90, 0x5f, 0xed, 0x1b, 0xee, 0x1f,
2445 0xc8, 0xaa, 0xfb, 0xa1, 0x7c, 0x75, 0x0e, 0x2c, 0x7a, 0xce, 0x01, 0xe6,
2446 0x00, 0x5f, 0x80, 0xfc, 0xb7, 0xdf, 0x62, 0x12, 0x30, 0xc8, 0x37, 0x11,
2447 0xb3, 0x93, 0x43, 0xfa, 0x02, 0x8c, 0xea, 0x7f, 0x7f, 0xb5, 0xff, 0x89,
2448 0xea, 0xc2, 0x30, 0x82, 0x49, 0xa0, 0x22, 0x52, 0x15, 0x5e, 0x23, 0x47,
2449 0xb6, 0x3d, 0x58, 0xc5, 0x45, 0x7a, 0xfd, 0x84, 0xd0, 0x5d, 0xff, 0xfd,
2450 0xb2, 0x03, 0x92, 0x84, 0x4a, 0xe8, 0x12, 0x15, 0x46, 0x82, 0xe9, 0xcf,
2451 0x01, 0x2f, 0x90, 0x21, 0xa6, 0xf0, 0xbe, 0x17, 0xdd, 0xd0, 0xc2, 0x08,
2452 0x4d, 0xce, 0x25, 0xff, 0x9b, 0x06, 0xcd, 0xe5, 0x35, 0xd0, 0xf9, 0x20,
2453 0xa2, 0xdb, 0x1b, 0xf3, 0x62, 0xc2, 0x3e, 0x59, 0x6d, 0x11, 0xa4, 0xf5,
2454 0xa6, 0xcf, 0x39, 0x48, 0x83, 0x8a, 0x3a, 0xec, 0x4e, 0x15, 0xda, 0xf8,
2455 0x50, 0x0a, 0x6e, 0xf6, 0x9e, 0xc4, 0xe3, 0xfe, 0xb6, 0xb1, 0xd9, 0x8e,
2456 0x61, 0x0a, 0xc8, 0xb7, 0xec, 0x3f, 0xaf, 0x6a, 0xd7, 0x60, 0xb7, 0xba,
2457 0xd1, 0xdb, 0x4b, 0xa3, 0x48, 0x5e, 0x8a, 0x94, 0xdc, 0x25, 0x0a, 0xe3,
2458 0xfd, 0xb4, 0x1e, 0xd1, 0x5f, 0xb6, 0xa8, 0xe5, 0xeb, 0xa0, 0xfc, 0x3d,
2459 0xd6, 0x0b, 0xc8, 0xe3, 0x0c, 0x5c, 0x42, 0x87, 0xe5, 0x38, 0x05, 0xdb,
2460 0x05, 0x9a, 0xe0, 0x64, 0x8d, 0xb2, 0xf6, 0x42, 0x64, 0xed, 0x5e, 0x39,
2461 0xbe, 0x2e, 0x20, 0xd8, 0x2d, 0xf5, 0x66, 0xda, 0x8d, 0xd5, 0x99, 0x8c,
2462 0xca, 0xbd, 0xae, 0x05, 0x30, 0x60, 0xae, 0x6c, 0x7b, 0x43, 0x78, 0xe8,
2463 0x46, 0xd2, 0x9f, 0x37, 0xed, 0x7b, 0x4e, 0xa9, 0xec, 0x5d, 0x82, 0xe7,
2464 0x96, 0x1b, 0x7f, 0x25, 0xa9, 0x32, 0x38, 0x51, 0xf6, 0x81, 0xd5, 0x82,
2465 0x36, 0x3a, 0xa5, 0xf8, 0x99, 0x37, 0xf5, 0xa6, 0x72, 0x58, 0xbf, 0x63,
2466 0xad, 0x6f, 0x1a, 0x0b, 0x1d, 0x96, 0xdb, 0xd4, 0xfa, 0xdd, 0xfc, 0xef,
2467 0xc5, 0x26, 0x6b, 0xa6, 0x61, 0x17, 0x22, 0x39, 0x5c, 0x90, 0x65, 0x56,
2468 0xbe, 0x52, 0xaf, 0xe3, 0xf5, 0x65, 0x63, 0x6a, 0xd1, 0xb1, 0x7d, 0x50,
2469 0x8b, 0x73, 0xd8, 0x74, 0x3e, 0xeb, 0x52, 0x4b, 0xe2, 0x2b, 0x3d, 0xcb,
2470 0xc2, 0xc7, 0x46, 0x8d, 0x54, 0x11, 0x9c, 0x74, 0x68, 0x44, 0x9a, 0x13,
2471 0xd8, 0xe3, 0xb9, 0x58, 0x11, 0xa1, 0x98, 0xf3, 0x49, 0x1d, 0xe3, 0xe7,
2472 0xfe, 0x94, 0x2b, 0x33, 0x04, 0x07, 0xab, 0xf8, 0x2a, 0x4e, 0xd7, 0xc1,
2473 0xb3, 0x11, 0x66, 0x3a, 0xc6, 0x98, 0x90, 0xf4, 0x15, 0x70, 0x15, 0x85,
2474 0x3d, 0x91, 0xe9, 0x23, 0x03, 0x7c, 0x22, 0x7a, 0x33, 0xcd, 0xd5, 0xec,
2475 0x28, 0x1c, 0xa3, 0xf7, 0x9c, 0x44, 0x54, 0x6b, 0x9d, 0x90, 0xca, 0x00,
2476 0xf0, 0x64, 0xc9, 0x9e, 0x3d, 0xd9, 0x79, 0x11, 0xd3, 0x9f, 0xe9, 0xc5,
2477 0xd0, 0xb2, 0x3a, 0x22, 0x9a, 0x23, 0x4c, 0xb3, 0x61, 0x86, 0xc4, 0x81,
2478 0x9e, 0x8b, 0x9c, 0x59, 0x27, 0x72, 0x66, 0x32, 0x29, 0x1d, 0x6a, 0x41,
2479 0x82, 0x11, 0xcc, 0x29, 0x62, 0xe2, 0x0f, 0xe4, 0x7f, 0xeb, 0x3e, 0xdf,
2480 0x33, 0x0f, 0x2c, 0x60, 0x3a, 0x9d, 0x48, 0xc0, 0xfc, 0xb5, 0x69, 0x9d,
2481 0xbf, 0xe5, 0x89, 0x64, 0x25, 0xc5, 0xba, 0xc4, 0xae, 0xe8, 0x2e, 0x57,
2482 0xa8, 0x5a, 0xaf, 0x4e, 0x25, 0x13, 0xe4, 0xf0, 0x57, 0x96, 0xb0, 0x7b,
2483 0xa2, 0xee, 0x47, 0xd8, 0x05, 0x06, 0xf8, 0xd2, 0xc2, 0x5e, 0x50, 0xfd,
2484 0x14, 0xde, 0x71, 0xe6, 0xc4, 0x18, 0x55, 0x93, 0x02, 0xf9, 0x39, 0xb0,
2485 0xe1, 0xab, 0xd5, 0x76, 0xf2, 0x79, 0xc4, 0xb2, 0xe0, 0xfe, 0xb8, 0x5c,
2486 0x1f, 0x28, 0xff, 0x18, 0xf5, 0x88, 0x91, 0xff, 0xef, 0x13, 0x2e, 0xef,
2487 0x2f, 0xa0, 0x93, 0x46, 0xae, 0xe3, 0x3c, 0x28, 0xeb, 0x13, 0x0f, 0xf2,
2488 0x8f, 0x5b, 0x76, 0x69, 0x53, 0x33, 0x41, 0x13, 0x21, 0x19, 0x96, 0xd2,
2489 0x00, 0x11, 0xa1, 0x98, 0xe3, 0xfc, 0x43, 0x3f, 0x9f, 0x25, 0x41, 0x01,
2490 0x0a, 0xe1, 0x7c, 0x1b, 0xf2, 0x02, 0x58, 0x0f, 0x60, 0x47, 0x47, 0x2f,
2491 0xb3, 0x68, 0x57, 0xfe, 0x84, 0x3b, 0x19, 0xf5, 0x98, 0x40, 0x09, 0xdd,
2492 0xc3, 0x24, 0x04, 0x4e, 0x84, 0x7a, 0x4f, 0x4a, 0x0a, 0xb3, 0x4f, 0x71,
2493 0x95, 0x95, 0xde, 0x37, 0x25, 0x2d, 0x62, 0x35, 0x36, 0x5e, 0x9b, 0x84,
2494 0x39, 0x2b, 0x06, 0x10, 0x85, 0x34, 0x9d, 0x73, 0x20, 0x3a, 0x4a, 0x13,
2495 0xe9, 0x6f, 0x54, 0x32, 0xec, 0x0f, 0xd4, 0xa1, 0xee, 0x65, 0xac, 0xcd,
2496 0xd5, 0xe3, 0x90, 0x4d, 0xf5, 0x4c, 0x1d, 0xa5, 0x10, 0xb0, 0xff, 0x20,
2497 0xdc, 0xc0, 0xc7, 0x7f, 0xcb, 0x2c, 0x0e, 0x0e, 0xb6, 0x05, 0xcb, 0x05,
2498 0x04, 0xdb, 0x87, 0x63, 0x2c, 0xf3, 0xd8, 0xb4, 0xda, 0xe6, 0xe7, 0x05,
2499 0x76, 0x9d, 0x1d, 0xe3, 0x54, 0x27, 0x01, 0x23, 0xcb, 0x11, 0x45, 0x0e,
2500 0xfc, 0x60, 0xac, 0x47, 0x68, 0x3d, 0x7b, 0x8d, 0x0f, 0x81, 0x13, 0x65,
2501 0x56, 0x5f, 0xd9, 0x8c, 0x4c, 0x8e, 0xb9, 0x36, 0xbc, 0xab, 0x8d, 0x06,
2502 0x9f, 0xc3, 0x3b, 0xd8, 0x01, 0xb0, 0x3a, 0xde, 0xa2, 0xe1, 0xfb, 0xc5,
2503 0xaa, 0x46, 0x3d, 0x08, 0xca, 0x19, 0x89, 0x6d, 0x2b, 0xf5, 0x9a, 0x07,
2504 0x1b, 0x85, 0x1e, 0x6c, 0x23, 0x90, 0x52, 0x17, 0x2f, 0x29, 0x6b, 0xfb,
2505 0x5e, 0x72, 0x40, 0x47, 0x90, 0xa2, 0x18, 0x10, 0x14, 0xf3, 0xb9, 0x4a,
2506 0x4e, 0x97, 0xd1, 0x17, 0xb4, 0x38, 0x13, 0x03, 0x68, 0xcc, 0x39, 0xdb,
2507 0xb2, 0xd1, 0x98, 0x06, 0x5a, 0xe3, 0x98, 0x65, 0x47, 0x92, 0x6c, 0xd2,
2508 0x16, 0x2f, 0x40, 0xa2, 0x9f, 0x0c, 0x3c, 0x87, 0x45, 0xc0, 0xf5, 0x0f,
2509 0xba, 0x38, 0x52, 0xe5, 0x66, 0xd4, 0x45, 0x75, 0xc2, 0x9d, 0x39, 0xa0,
2510 0x3f, 0x0c, 0xda, 0x72, 0x19, 0x84, 0xb6, 0xf4, 0x40, 0x59, 0x1f, 0x35,
2511 0x5e, 0x12, 0xd4, 0x39, 0xff, 0x15, 0x0a, 0xab, 0x76, 0x13, 0x49, 0x9d,
2512 0xbd, 0x49, 0xad, 0xab, 0xc8, 0x67, 0x6e, 0xef, 0x02, 0x3b, 0x15, 0xb6,
2513 0x5b, 0xfc, 0x5c, 0xa0, 0x69, 0x48, 0x10, 0x9f, 0x23, 0xf3, 0x50, 0xdb,
2514 0x82, 0x12, 0x35, 0x35, 0xeb, 0x8a, 0x74, 0x33, 0xbd, 0xab, 0xcb, 0x90,
2515 0x92, 0x71, 0xa6, 0xec, 0xbc, 0xb5, 0x8b, 0x93, 0x6a, 0x88, 0xcd, 0x4e,
2516 0x8f, 0x2e, 0x6f, 0xf5, 0x80, 0x01, 0x75, 0xf1, 0x13, 0x25, 0x3d, 0x8f,
2517 0xa9, 0xca, 0x88, 0x85, 0xc2, 0xf5, 0x52, 0xe6, 0x57, 0xdc, 0x60, 0x3f,
2518 0x25, 0x2e, 0x1a, 0x8e, 0x30, 0x8f, 0x76, 0xf0, 0xbe, 0x79, 0xe2, 0xfb,
2519 0x8f, 0x5d, 0x5f, 0xbb, 0xe2, 0xe3, 0x0e, 0xca, 0xdd, 0x22, 0x07, 0x23,
2520 0xc8, 0xc0, 0xae, 0xa8, 0x07, 0x8c, 0xdf, 0xcb, 0x38, 0x68, 0x26, 0x3f,
2521 0xf8, 0xf0, 0x94, 0x00, 0x54, 0xda, 0x48, 0x78, 0x18, 0x93, 0xa7, 0xe4,
2522 0x9a, 0xd5, 0xaf, 0xf4, 0xaf, 0x30, 0x0c, 0xd8, 0x04, 0xa6, 0xb6, 0x27,
2523 0x9a, 0xb3, 0xff, 0x3a, 0xfb, 0x64, 0x49, 0x1c, 0x85, 0x19, 0x4a, 0xab,
2524 0x76, 0x0d, 0x58, 0xa6, 0x06, 0x65, 0x4f, 0x9f, 0x44, 0x00, 0xe8, 0xb3,
2525 0x85, 0x91, 0x35, 0x6f, 0xbf, 0x64, 0x25, 0xac, 0xa2, 0x6d, 0xc8, 0x52,
2526 0x44, 0x25, 0x9f, 0xf2, 0xb1, 0x9c, 0x41, 0xb9, 0xf9, 0x6f, 0x3c, 0xa9,
2527 0xec, 0x1d, 0xde, 0x43, 0x4d, 0xa7, 0xd2, 0xd3, 0x92, 0xb9, 0x05, 0xdd,
2528 0xf3, 0xd1, 0xf9, 0xaf, 0x93, 0xd1, 0xaf, 0x59, 0x50, 0xbd, 0x49, 0x3f,
2529 0x5a, 0xa7, 0x31, 0xb4, 0x05, 0x6d, 0xf3, 0x1b, 0xd2, 0x67, 0xb6, 0xb9,
2530 0x0a, 0x07, 0x98, 0x31, 0xaa, 0xf5, 0x79, 0xbe, 0x0a, 0x39, 0x01, 0x31,
2531 0x37, 0xaa, 0xc6, 0xd4, 0x04, 0xf5, 0x18, 0xcf, 0xd4, 0x68, 0x40, 0x64,
2532 0x7e, 0x78, 0xbf, 0xe7, 0x06, 0xca, 0x4c, 0xf5, 0xe9, 0xc5, 0x45, 0x3e,
2533 0x9f, 0x7c, 0xfd, 0x2b, 0x8b, 0x4c, 0x8d, 0x16, 0x9a, 0x44, 0xe5, 0x5c,
2534 0x88, 0xd4, 0xa9, 0xa7, 0xf9, 0x47, 0x42, 0x41, 0xe2, 0x21, 0xaf, 0x44,
2535 0x86, 0x00, 0x18, 0xab, 0x08, 0x56, 0x97, 0x2e, 0x19, 0x4c, 0xd9, 0x34
2536 };
2537
2538 static QUIC_PKT_HDR tx_script_1_hdr = {
2539 QUIC_PKT_TYPE_INITIAL, /* type */
2540 0, /* spin bit */
2541 0, /* key phase */
2542 4, /* PN length */
2543 0, /* partial */
2544 0, /* fixed */
2545 1, /* version */
2546 {8, {0x83, 0x94, 0xc8, 0xf0, 0x3e, 0x51, 0x57, 0x08}}, /* DCID */
2547 { 0, {0} }, /* SCID */
2548 { 0 }, /* PN */
2549 NULL, 0, /* Token */
2550 5555, NULL /* Len/Data */
2551 };
2552
2553 static const OSSL_QTX_IOVEC tx_script_1_iovec[] = {
2554 { tx_script_1_body, sizeof(tx_script_1_body) }
2555 };
2556
2557 static const OSSL_QTX_PKT tx_script_1_pkt = {
2558 &tx_script_1_hdr,
2559 tx_script_1_iovec,
2560 OSSL_NELEM(tx_script_1_iovec),
2561 NULL, NULL,
2562 2,
2563 0
2564 };
2565
2566 static const struct tx_test_op tx_script_1[] = {
2567 TX_OP_PROVIDE_SECRET_INITIAL(tx_script_1_hdr.dst_conn_id, 0)
2568 TX_OP_WRITE_CHECK(1)
2569 TX_OP_END
2570 };
2571
2572 /* 2. RFC 9001 - A.3 Server Initial */
2573 static const unsigned char tx_script_2_body[] = {
2574 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x40, 0x5a, 0x02, 0x00, 0x00,
2575 0x56, 0x03, 0x03, 0xee, 0xfc, 0xe7, 0xf7, 0xb3, 0x7b, 0xa1, 0xd1, 0x63,
2576 0x2e, 0x96, 0x67, 0x78, 0x25, 0xdd, 0xf7, 0x39, 0x88, 0xcf, 0xc7, 0x98,
2577 0x25, 0xdf, 0x56, 0x6d, 0xc5, 0x43, 0x0b, 0x9a, 0x04, 0x5a, 0x12, 0x00,
2578 0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00,
2579 0x20, 0x9d, 0x3c, 0x94, 0x0d, 0x89, 0x69, 0x0b, 0x84, 0xd0, 0x8a, 0x60,
2580 0x99, 0x3c, 0x14, 0x4e, 0xca, 0x68, 0x4d, 0x10, 0x81, 0x28, 0x7c, 0x83,
2581 0x4d, 0x53, 0x11, 0xbc, 0xf3, 0x2b, 0xb9, 0xda, 0x1a, 0x00, 0x2b, 0x00,
2582 0x02, 0x03, 0x04
2583 };
2584
2585 static const unsigned char tx_script_2_dgram[] = {
2586
2587 0xcf, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0xf0, 0x67, 0xa5, 0x50, 0x2a,
2588 0x42, 0x62, 0xb5, 0x00, 0x40, 0x75, 0xc0, 0xd9, 0x5a, 0x48, 0x2c, 0xd0,
2589 0x99, 0x1c, 0xd2, 0x5b, 0x0a, 0xac, 0x40, 0x6a, 0x58, 0x16, 0xb6, 0x39,
2590 0x41, 0x00, 0xf3, 0x7a, 0x1c, 0x69, 0x79, 0x75, 0x54, 0x78, 0x0b, 0xb3,
2591 0x8c, 0xc5, 0xa9, 0x9f, 0x5e, 0xde, 0x4c, 0xf7, 0x3c, 0x3e, 0xc2, 0x49,
2592 0x3a, 0x18, 0x39, 0xb3, 0xdb, 0xcb, 0xa3, 0xf6, 0xea, 0x46, 0xc5, 0xb7,
2593 0x68, 0x4d, 0xf3, 0x54, 0x8e, 0x7d, 0xde, 0xb9, 0xc3, 0xbf, 0x9c, 0x73,
2594 0xcc, 0x3f, 0x3b, 0xde, 0xd7, 0x4b, 0x56, 0x2b, 0xfb, 0x19, 0xfb, 0x84,
2595 0x02, 0x2f, 0x8e, 0xf4, 0xcd, 0xd9, 0x37, 0x95, 0xd7, 0x7d, 0x06, 0xed,
2596 0xbb, 0x7a, 0xaf, 0x2f, 0x58, 0x89, 0x18, 0x50, 0xab, 0xbd, 0xca, 0x3d,
2597 0x20, 0x39, 0x8c, 0x27, 0x64, 0x56, 0xcb, 0xc4, 0x21, 0x58, 0x40, 0x7d,
2598 0xd0, 0x74, 0xee
2599 };
2600
2601 static QUIC_PKT_HDR tx_script_2_hdr = {
2602 QUIC_PKT_TYPE_INITIAL, /* type */
2603 0, /* spin bit */
2604 0, /* key phase */
2605 2, /* PN length */
2606 0, /* partial */
2607 0, /* fixed */
2608 1, /* version */
2609 { 0, {0} }, /* DCID */
2610 {8, {0xf0, 0x67, 0xa5, 0x50, 0x2a, 0x42, 0x62, 0xb5}}, /* SCID */
2611 { 0 }, /* PN */
2612 NULL, 0, /* Token */
2613 5555, NULL /* Len/Data */
2614 };
2615
2616 static const OSSL_QTX_IOVEC tx_script_2_iovec[] = {
2617 { tx_script_2_body, sizeof(tx_script_2_body) }
2618 };
2619
2620 static const OSSL_QTX_PKT tx_script_2_pkt = {
2621 &tx_script_2_hdr,
2622 tx_script_2_iovec,
2623 OSSL_NELEM(tx_script_2_iovec),
2624 NULL, NULL,
2625 1,
2626 0
2627 };
2628
2629 static const struct tx_test_op tx_script_2[] = {
2630 TX_OP_PROVIDE_SECRET_INITIAL(tx_script_1_hdr.dst_conn_id, 1)
2631 TX_OP_WRITE_CHECK(2)
2632 TX_OP_END
2633 };
2634
2635 /* 3. RFC 9001 - A.5 ChaCha20-Poly1305 Short Header Packet */
2636 static const unsigned char tx_script_3_body[] = {
2637 0x01
2638 };
2639
2640 static const unsigned char tx_script_3_dgram[] = {
2641 0x4c, 0xfe, 0x41, 0x89, 0x65, 0x5e, 0x5c, 0xd5, 0x5c, 0x41, 0xf6, 0x90,
2642 0x80, 0x57, 0x5d, 0x79, 0x99, 0xc2, 0x5a, 0x5b, 0xfb
2643 };
2644 static const unsigned char tx_script_3_secret[] = {
2645 0x9a, 0xc3, 0x12, 0xa7, 0xf8, 0x77, 0x46, 0x8e, 0xbe, 0x69, 0x42, 0x27,
2646 0x48, 0xad, 0x00, 0xa1, 0x54, 0x43, 0xf1, 0x82, 0x03, 0xa0, 0x7d, 0x60,
2647 0x60, 0xf6, 0x88, 0xf3, 0x0f, 0x21, 0x63, 0x2b
2648 };
2649
2650 static QUIC_PKT_HDR tx_script_3_hdr = {
2651 QUIC_PKT_TYPE_1RTT, /* type */
2652 0, /* spin bit */
2653 0, /* key phase */
2654 3, /* PN length */
2655 0, /* partial */
2656 0, /* fixed */
2657 0, /* version */
2658 { 0, {0} }, /* DCID */
2659 { 0, {0} }, /* SCID */
2660 { 0 }, /* PN */
2661 NULL, 0, /* Token */
2662 5555, NULL /* Len/Data */
2663 };
2664
2665 static const OSSL_QTX_IOVEC tx_script_3_iovec[] = {
2666 { tx_script_3_body, sizeof(tx_script_3_body) }
2667 };
2668
2669 static const OSSL_QTX_PKT tx_script_3_pkt = {
2670 &tx_script_3_hdr,
2671 tx_script_3_iovec,
2672 OSSL_NELEM(tx_script_3_iovec),
2673 NULL, NULL,
2674 654360564,
2675 0
2676 };
2677
2678 static const struct tx_test_op tx_script_3[] = {
2679 TX_OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_CHACHA20POLY1305, tx_script_3_secret)
2680 TX_OP_WRITE_CHECK(3)
2681 TX_OP_END
2682 };
2683
2684 static const struct tx_test_op *const tx_scripts[] = {
2685 tx_script_1,
2686 tx_script_2,
2687 tx_script_3
2688 };
2689
2690 static int tx_run_script(const struct tx_test_op *script)
2691 {
2692 int testresult = 0;
2693 const struct tx_test_op *op = script;
2694 OSSL_QTX *qtx = NULL;
2695 BIO_MSG msg = {0};
2696 OSSL_QTX_ARGS args = {0};
2697
2698 args.mdpl = 1472;
2699
2700 if (!TEST_ptr(qtx = ossl_qtx_new(&args)))
2701 goto err;
2702
2703 for (; op->op != TX_TEST_OP_END; ++op)
2704 switch (op->op) {
2705 case TX_TEST_OP_PROVIDE_SECRET:
2706 if (!TEST_true(ossl_qtx_provide_secret(qtx, op->enc_level,
2707 op->suite_id, NULL,
2708 op->buf, op->buf_len)))
2709 goto err;
2710 break;
2711 case TX_TEST_OP_PROVIDE_SECRET_INITIAL:
2712 if (!TEST_true(ossl_quic_provide_initial_secret(NULL, NULL,
2713 op->dcid,
2714 (int)op->suite_id,
2715 NULL, qtx)))
2716 goto err;
2717 break;
2718 case TX_TEST_OP_DISCARD_EL:
2719 if (!TEST_true(ossl_qtx_discard_enc_level(qtx, op->enc_level)))
2720 goto err;
2721 break;
2722 case TX_TEST_OP_WRITE:
2723 {
2724 uint32_t enc_level
2725 = ossl_quic_pkt_type_to_enc_level(op->pkt->hdr->type);
2726 uint64_t old_value = 0, new_value, max_value;
2727
2728 if (enc_level < QUIC_ENC_LEVEL_NUM) { /* encrypted packet */
2729 max_value = ossl_qtx_get_max_epoch_pkt_count(qtx, enc_level);
2730
2731 if (!TEST_uint64_t_lt(max_value, UINT64_MAX))
2732 goto err;
2733
2734 old_value = ossl_qtx_get_cur_epoch_pkt_count(qtx, enc_level);
2735 if (!TEST_uint64_t_lt(old_value, UINT64_MAX))
2736 goto err;
2737 }
2738
2739 if (!TEST_true(ossl_qtx_write_pkt(qtx, op->pkt)))
2740 goto err;
2741
2742 if (enc_level < QUIC_ENC_LEVEL_NUM) {
2743 new_value = ossl_qtx_get_cur_epoch_pkt_count(qtx, enc_level);
2744 if (!TEST_uint64_t_eq(old_value + 1, new_value))
2745 goto err;
2746 }
2747 }
2748 break;
2749 case TX_TEST_OP_CHECK_DGRAM:
2750 if (!TEST_true(ossl_qtx_pop_net(qtx, &msg)))
2751 goto err;
2752
2753 if (!TEST_mem_eq(msg.data, msg.data_len, op->buf, op->buf_len))
2754 goto err;
2755
2756 break;
2757 case TX_TEST_OP_CHECK_NO_DGRAM:
2758 if (!TEST_false(ossl_qtx_pop_net(qtx, &msg)))
2759 goto err;
2760 break;
2761 default:
2762 OPENSSL_assert(0);
2763 goto err;
2764 }
2765
2766 testresult = 1;
2767 err:
2768 if (qtx != NULL)
2769 ossl_qtx_free(qtx);
2770
2771 return testresult;
2772 }
2773
2774 static int test_tx_script(int idx)
2775 {
2776 return tx_run_script(tx_scripts[idx]);
2777 }
2778
2779 int setup_tests(void)
2780 {
2781 ADD_ALL_TESTS(test_rx_script, OSSL_NELEM(rx_scripts));
2782 /*
2783 * Each instance of this test is executed multiple times to get enough
2784 * statistical coverage for our statistical test, as well as for each
2785 * supported key type.
2786 *
2787 * We call the statistical test as the last index in the wire_pkt_hdr
2788 * test rather than as a separate case, as it needs to execute last
2789 * and otherwise random test ordering will cause itt to randomly fail.
2790 */
2791 ADD_ALL_TESTS(test_wire_pkt_hdr, NUM_WIRE_PKT_HDR_TESTS + 1);
2792 ADD_ALL_TESTS(test_tx_script, OSSL_NELEM(tx_scripts));
2793 return 1;
2794 }