iPXE
tlskey_test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * TLS key schedule tests
29 *
30 * TLS version 1.3 example handshake traces are provided in RFC 8448.
31 * We include the "Simple 1-RTT Handshake" and "Resumed 0-RTT
32 * Handshake" test cases, to exercise all successful code paths for
33 * the HKDF-based key schedule (including session resumption).
34 *
35 * For TLS version 1.2 and earlier, there are no good reference
36 * example handshake traces available. We choose to run through a
37 * non-functional minimal handshake that allows us to exercise the
38 * relevant code paths and so at least prevent regressions.
39 *
40 */
41
42/* Forcibly enable assertions */
43#undef NDEBUG
44
45#include <string.h>
46#include <ipxe/malloc.h>
47#include <ipxe/sha256.h>
48#include <ipxe/md5_sha1.h>
49#include <ipxe/x25519.h>
50#include <ipxe/tlskey.h>
51#include <ipxe/test.h>
52
53/** RFC 8448 simple 1-RTT test: client random bytes */
55 .bytes = {
56 0xcb, 0x34, 0xec, 0xb1, 0xe7, 0x81, 0x63, 0xba, 0x1c, 0x38,
57 0xc6, 0xda, 0xcb, 0x19, 0x6a, 0x6d, 0xff, 0xa2, 0x1a, 0x8d,
58 0x99, 0x12, 0xec, 0x18, 0xa2, 0xef, 0x62, 0x83, 0x02, 0x4d,
59 0xec, 0xe7
60 },
61};
62
63/** RFC 8448 simple 1-RTT test: client X25519 private key */
65 0x49, 0xaf, 0x42, 0xba, 0x7f, 0x79, 0x94, 0x85, 0x2d, 0x71, 0x3e,
66 0xf2, 0x78, 0x4b, 0xcb, 0xca, 0xa7, 0x91, 0x1d, 0xe2, 0x6a, 0xdc,
67 0x56, 0x42, 0xcb, 0x63, 0x45, 0x40, 0xe7, 0xea, 0x50, 0x05
68};
69
70/** RFC 8448 simple 1-RTT test: server X25519 public key */
72 0xc9, 0x82, 0x88, 0x76, 0x11, 0x20, 0x95, 0xfe, 0x66, 0x76, 0x2b,
73 0xdb, 0xf7, 0xc6, 0x72, 0xe1, 0x56, 0xd6, 0xcc, 0x25, 0x3b, 0x83,
74 0x3d, 0xf1, 0xdd, 0x69, 0xb1, 0xb0, 0x4e, 0x75, 0x1f, 0x0f
75};
76
77/** RFC 8448 simple 1-RTT test: ticket nonce */
78static const uint8_t rfc8448_simple_ticket_nonce[] = { 0x00, 0x00 };
79
80/** RFC 8448 simple 1-RTT test: ClientHello */
82 0x01, 0x00, 0x00, 0xc0, 0x03, 0x03, 0xcb, 0x34, 0xec, 0xb1, 0xe7,
83 0x81, 0x63, 0xba, 0x1c, 0x38, 0xc6, 0xda, 0xcb, 0x19, 0x6a, 0x6d,
84 0xff, 0xa2, 0x1a, 0x8d, 0x99, 0x12, 0xec, 0x18, 0xa2, 0xef, 0x62,
85 0x83, 0x02, 0x4d, 0xec, 0xe7, 0x00, 0x00, 0x06, 0x13, 0x01, 0x13,
86 0x03, 0x13, 0x02, 0x01, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x0b,
87 0x00, 0x09, 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
88 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x12,
89 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x01, 0x00, 0x01,
90 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x00, 0x23, 0x00, 0x00,
91 0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x99,
92 0x38, 0x1d, 0xe5, 0x60, 0xe4, 0xbd, 0x43, 0xd2, 0x3d, 0x8e, 0x43,
93 0x5a, 0x7d, 0xba, 0xfe, 0xb3, 0xc0, 0x6e, 0x51, 0xc1, 0x3c, 0xae,
94 0x4d, 0x54, 0x13, 0x69, 0x1e, 0x52, 0x9a, 0xaf, 0x2c, 0x00, 0x2b,
95 0x00, 0x03, 0x02, 0x03, 0x04, 0x00, 0x0d, 0x00, 0x20, 0x00, 0x1e,
96 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x02, 0x03, 0x08, 0x04, 0x08,
97 0x05, 0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01,
98 0x04, 0x02, 0x05, 0x02, 0x06, 0x02, 0x02, 0x02, 0x00, 0x2d, 0x00,
99 0x02, 0x01, 0x01, 0x00, 0x1c, 0x00, 0x02, 0x40, 0x01
100};
101
102/** RFC 8448 simple 1-RTT test: ServerHello */
104 0x02, 0x00, 0x00, 0x56, 0x03, 0x03, 0xa6, 0xaf, 0x06, 0xa4, 0x12,
105 0x18, 0x60, 0xdc, 0x5e, 0x6e, 0x60, 0x24, 0x9c, 0xd3, 0x4c, 0x95,
106 0x93, 0x0c, 0x8a, 0xc5, 0xcb, 0x14, 0x34, 0xda, 0xc1, 0x55, 0x77,
107 0x2e, 0xd3, 0xe2, 0x69, 0x28, 0x00, 0x13, 0x01, 0x00, 0x00, 0x2e,
108 0x00, 0x33, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0xc9, 0x82, 0x88,
109 0x76, 0x11, 0x20, 0x95, 0xfe, 0x66, 0x76, 0x2b, 0xdb, 0xf7, 0xc6,
110 0x72, 0xe1, 0x56, 0xd6, 0xcc, 0x25, 0x3b, 0x83, 0x3d, 0xf1, 0xdd,
111 0x69, 0xb1, 0xb0, 0x4e, 0x75, 0x1f, 0x0f, 0x00, 0x2b, 0x00, 0x02,
112 0x03, 0x04
113};
114
115/** RFC 8448 simple 1-RTT test: EncryptedExtensions */
117 0x08, 0x00, 0x00, 0x24, 0x00, 0x22, 0x00, 0x0a, 0x00, 0x14, 0x00,
118 0x12, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x01, 0x00,
119 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x00, 0x1c, 0x00,
120 0x02, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00
121};
122
123/** RFC 8448 simple 1-RTT test: Certificate */
125 0x0b, 0x00, 0x01, 0xb9, 0x00, 0x00, 0x01, 0xb5, 0x00, 0x01, 0xb0,
126 0x30, 0x82, 0x01, 0xac, 0x30, 0x82, 0x01, 0x15, 0xa0, 0x03, 0x02,
127 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
128 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0e,
129 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03,
130 0x72, 0x73, 0x61, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x37,
131 0x33, 0x30, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39, 0x5a, 0x17, 0x0d,
132 0x32, 0x36, 0x30, 0x37, 0x33, 0x30, 0x30, 0x31, 0x32, 0x33, 0x35,
133 0x39, 0x5a, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55,
134 0x04, 0x03, 0x13, 0x03, 0x72, 0x73, 0x61, 0x30, 0x81, 0x9f, 0x30,
135 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
136 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02,
137 0x81, 0x81, 0x00, 0xb4, 0xbb, 0x49, 0x8f, 0x82, 0x79, 0x30, 0x3d,
138 0x98, 0x08, 0x36, 0x39, 0x9b, 0x36, 0xc6, 0x98, 0x8c, 0x0c, 0x68,
139 0xde, 0x55, 0xe1, 0xbd, 0xb8, 0x26, 0xd3, 0x90, 0x1a, 0x24, 0x61,
140 0xea, 0xfd, 0x2d, 0xe4, 0x9a, 0x91, 0xd0, 0x15, 0xab, 0xbc, 0x9a,
141 0x95, 0x13, 0x7a, 0xce, 0x6c, 0x1a, 0xf1, 0x9e, 0xaa, 0x6a, 0xf9,
142 0x8c, 0x7c, 0xed, 0x43, 0x12, 0x09, 0x98, 0xe1, 0x87, 0xa8, 0x0e,
143 0xe0, 0xcc, 0xb0, 0x52, 0x4b, 0x1b, 0x01, 0x8c, 0x3e, 0x0b, 0x63,
144 0x26, 0x4d, 0x44, 0x9a, 0x6d, 0x38, 0xe2, 0x2a, 0x5f, 0xda, 0x43,
145 0x08, 0x46, 0x74, 0x80, 0x30, 0x53, 0x0e, 0xf0, 0x46, 0x1c, 0x8c,
146 0xa9, 0xd9, 0xef, 0xbf, 0xae, 0x8e, 0xa6, 0xd1, 0xd0, 0x3e, 0x2b,
147 0xd1, 0x93, 0xef, 0xf0, 0xab, 0x9a, 0x80, 0x02, 0xc4, 0x74, 0x28,
148 0xa6, 0xd3, 0x5a, 0x8d, 0x88, 0xd7, 0x9f, 0x7f, 0x1e, 0x3f, 0x02,
149 0x03, 0x01, 0x00, 0x01, 0xa3, 0x1a, 0x30, 0x18, 0x30, 0x09, 0x06,
150 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06,
151 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02, 0x05, 0xa0, 0x30,
152 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
153 0x0b, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x85, 0xaa, 0xd2, 0xa0,
154 0xe5, 0xb9, 0x27, 0x6b, 0x90, 0x8c, 0x65, 0xf7, 0x3a, 0x72, 0x67,
155 0x17, 0x06, 0x18, 0xa5, 0x4c, 0x5f, 0x8a, 0x7b, 0x33, 0x7d, 0x2d,
156 0xf7, 0xa5, 0x94, 0x36, 0x54, 0x17, 0xf2, 0xea, 0xe8, 0xf8, 0xa5,
157 0x8c, 0x8f, 0x81, 0x72, 0xf9, 0x31, 0x9c, 0xf3, 0x6b, 0x7f, 0xd6,
158 0xc5, 0x5b, 0x80, 0xf2, 0x1a, 0x03, 0x01, 0x51, 0x56, 0x72, 0x60,
159 0x96, 0xfd, 0x33, 0x5e, 0x5e, 0x67, 0xf2, 0xdb, 0xf1, 0x02, 0x70,
160 0x2e, 0x60, 0x8c, 0xca, 0xe6, 0xbe, 0xc1, 0xfc, 0x63, 0xa4, 0x2a,
161 0x99, 0xbe, 0x5c, 0x3e, 0xb7, 0x10, 0x7c, 0x3c, 0x54, 0xe9, 0xb9,
162 0xeb, 0x2b, 0xd5, 0x20, 0x3b, 0x1c, 0x3b, 0x84, 0xe0, 0xa8, 0xb2,
163 0xf7, 0x59, 0x40, 0x9b, 0xa3, 0xea, 0xc9, 0xd9, 0x1d, 0x40, 0x2d,
164 0xcc, 0x0c, 0xc8, 0xf8, 0x96, 0x12, 0x29, 0xac, 0x91, 0x87, 0xb4,
165 0x2b, 0x4d, 0xe1, 0x00, 0x00
166};
167
168/** RFC 8448 simple 1-RTT test: CertificateVerify */
170 0x0f, 0x00, 0x00, 0x84, 0x08, 0x04, 0x00, 0x80, 0x5a, 0x74, 0x7c,
171 0x5d, 0x88, 0xfa, 0x9b, 0xd2, 0xe5, 0x5a, 0xb0, 0x85, 0xa6, 0x10,
172 0x15, 0xb7, 0x21, 0x1f, 0x82, 0x4c, 0xd4, 0x84, 0x14, 0x5a, 0xb3,
173 0xff, 0x52, 0xf1, 0xfd, 0xa8, 0x47, 0x7b, 0x0b, 0x7a, 0xbc, 0x90,
174 0xdb, 0x78, 0xe2, 0xd3, 0x3a, 0x5c, 0x14, 0x1a, 0x07, 0x86, 0x53,
175 0xfa, 0x6b, 0xef, 0x78, 0x0c, 0x5e, 0xa2, 0x48, 0xee, 0xaa, 0xa7,
176 0x85, 0xc4, 0xf3, 0x94, 0xca, 0xb6, 0xd3, 0x0b, 0xbe, 0x8d, 0x48,
177 0x59, 0xee, 0x51, 0x1f, 0x60, 0x29, 0x57, 0xb1, 0x54, 0x11, 0xac,
178 0x02, 0x76, 0x71, 0x45, 0x9e, 0x46, 0x44, 0x5c, 0x9e, 0xa5, 0x8c,
179 0x18, 0x1e, 0x81, 0x8e, 0x95, 0xb8, 0xc3, 0xfb, 0x0b, 0xf3, 0x27,
180 0x84, 0x09, 0xd3, 0xbe, 0x15, 0x2a, 0x3d, 0xa5, 0x04, 0x3e, 0x06,
181 0x3d, 0xda, 0x65, 0xcd, 0xf5, 0xae, 0xa2, 0x0d, 0x53, 0xdf, 0xac,
182 0xd4, 0x2f, 0x74, 0xf3
183};
184
185/** RFC 8448 simple 1-RTT test: server Finished */
187 0x14, 0x00, 0x00, 0x20, 0x9b, 0x9b, 0x14, 0x1d, 0x90, 0x63, 0x37,
188 0xfb, 0xd2, 0xcb, 0xdc, 0xe7, 0x1d, 0xf4, 0xde, 0xda, 0x4a, 0xb4,
189 0x2c, 0x30, 0x95, 0x72, 0xcb, 0x7f, 0xff, 0xee, 0x54, 0x54, 0xb7,
190 0x8f, 0x07, 0x18
191};
192
193/** RFC 8448 simple 1-RTT test: client Finished */
195 0x14, 0x00, 0x00, 0x20, 0xa8, 0xec, 0x43, 0x6d, 0x67, 0x76, 0x34,
196 0xae, 0x52, 0x5a, 0xc1, 0xfc, 0xeb, 0xe1, 0x1a, 0x03, 0x9e, 0xc1,
197 0x76, 0x94, 0xfa, 0xc6, 0xe9, 0x85, 0x27, 0xb6, 0x42, 0xf2, 0xed,
198 0xd5, 0xce, 0x61
199};
200
201/** RFC 8448 simple 1-RTT test: NewSessionTicket */
203 0x04, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, 0x1e, 0xfa, 0xd6, 0xaa,
204 0xc5, 0x02, 0x00, 0x00, 0x00, 0xb2, 0x2c, 0x03, 0x5d, 0x82, 0x93,
205 0x59, 0xee, 0x5f, 0xf7, 0xaf, 0x4e, 0xc9, 0x00, 0x00, 0x00, 0x00,
206 0x26, 0x2a, 0x64, 0x94, 0xdc, 0x48, 0x6d, 0x2c, 0x8a, 0x34, 0xcb,
207 0x33, 0xfa, 0x90, 0xbf, 0x1b, 0x00, 0x70, 0xad, 0x3c, 0x49, 0x88,
208 0x83, 0xc9, 0x36, 0x7c, 0x09, 0xa2, 0xbe, 0x78, 0x5a, 0xbc, 0x55,
209 0xcd, 0x22, 0x60, 0x97, 0xa3, 0xa9, 0x82, 0x11, 0x72, 0x83, 0xf8,
210 0x2a, 0x03, 0xa1, 0x43, 0xef, 0xd3, 0xff, 0x5d, 0xd3, 0x6d, 0x64,
211 0xe8, 0x61, 0xbe, 0x7f, 0xd6, 0x1d, 0x28, 0x27, 0xdb, 0x27, 0x9c,
212 0xce, 0x14, 0x50, 0x77, 0xd4, 0x54, 0xa3, 0x66, 0x4d, 0x4e, 0x6d,
213 0xa4, 0xd2, 0x9e, 0xe0, 0x37, 0x25, 0xa6, 0xa4, 0xda, 0xfc, 0xd0,
214 0xfc, 0x67, 0xd2, 0xae, 0xa7, 0x05, 0x29, 0x51, 0x3e, 0x3d, 0xa2,
215 0x67, 0x7f, 0xa5, 0x90, 0x6c, 0x5b, 0x3f, 0x7d, 0x8f, 0x92, 0xf2,
216 0x28, 0xbd, 0xa4, 0x0d, 0xda, 0x72, 0x14, 0x70, 0xf9, 0xfb, 0xf2,
217 0x97, 0xb5, 0xae, 0xa6, 0x17, 0x64, 0x6f, 0xac, 0x5c, 0x03, 0x27,
218 0x2e, 0x97, 0x07, 0x27, 0xc6, 0x21, 0xa7, 0x91, 0x41, 0xef, 0x5f,
219 0x7d, 0xe6, 0x50, 0x5e, 0x5b, 0xfb, 0xc3, 0x88, 0xe9, 0x33, 0x43,
220 0x69, 0x40, 0x93, 0x93, 0x4a, 0xe4, 0xd3, 0x57, 0x00, 0x08, 0x00,
221 0x2a, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00
222};
223
224/** RFC 8448 simple 1-RTT test: early secret */
226 0x33, 0xad, 0x0a, 0x1c, 0x60, 0x7e, 0xc0, 0x3b, 0x09, 0xe6, 0xcd,
227 0x98, 0x93, 0x68, 0x0c, 0xe2, 0x10, 0xad, 0xf3, 0x00, 0xaa, 0x1f,
228 0x26, 0x60, 0xe1, 0xb2, 0x2e, 0x10, 0xf1, 0x70, 0xf9, 0x2a
229};
230
231/** RFC 8448 simple 1-RTT test: handshake secret */
233 0x1d, 0xc8, 0x26, 0xe9, 0x36, 0x06, 0xaa, 0x6f, 0xdc, 0x0a, 0xad,
234 0xc1, 0x2f, 0x74, 0x1b, 0x01, 0x04, 0x6a, 0xa6, 0xb9, 0x9f, 0x69,
235 0x1e, 0xd2, 0x21, 0xa9, 0xf0, 0xca, 0x04, 0x3f, 0xbe, 0xac
236};
237
238/** RFC 8448 simple 1-RTT test: client handshake traffic secret */
240 0xb3, 0xed, 0xdb, 0x12, 0x6e, 0x06, 0x7f, 0x35, 0xa7, 0x80, 0xb3,
241 0xab, 0xf4, 0x5e, 0x2d, 0x8f, 0x3b, 0x1a, 0x95, 0x07, 0x38, 0xf5,
242 0x2e, 0x96, 0x00, 0x74, 0x6a, 0x0e, 0x27, 0xa5, 0x5a, 0x21
243};
244
245/** RFC 8448 simple 1-RTT test: client handshake traffic key */
247 0xdb, 0xfa, 0xa6, 0x93, 0xd1, 0x76, 0x2c, 0x5b, 0x66, 0x6a, 0xf5,
248 0xd9, 0x50, 0x25, 0x8d, 0x01
249};
250
251/** RFC 8448 simple 1-RTT test: client handshake traffic IV */
253 0x5b, 0xd3, 0xc7, 0x1b, 0x83, 0x6e, 0x0b, 0x76, 0xbb, 0x73, 0x26,
254 0x5f
255};
256
257/** RFC 8448 simple 1-RTT test: server handshake traffic secret */
259 0xb6, 0x7b, 0x7d, 0x69, 0x0c, 0xc1, 0x6c, 0x4e, 0x75, 0xe5, 0x42,
260 0x13, 0xcb, 0x2d, 0x37, 0xb4, 0xe9, 0xc9, 0x12, 0xbc, 0xde, 0xd9,
261 0x10, 0x5d, 0x42, 0xbe, 0xfd, 0x59, 0xd3, 0x91, 0xad, 0x38
262};
263
264/** RFC 8448 simple 1-RTT test: server handshake traffic key */
266 0x3f, 0xce, 0x51, 0x60, 0x09, 0xc2, 0x17, 0x27, 0xd0, 0xf2, 0xe4,
267 0xe8, 0x6e, 0xe4, 0x03, 0xbc
268};
269
270/** RFC 8448 simple 1-RTT test: server handshake traffic IV */
272 0x5d, 0x31, 0x3e, 0xb2, 0x67, 0x12, 0x76, 0xee, 0x13, 0x00, 0x0b,
273 0x30
274};
275
276/** RFC 8448 simple 1-RTT test: client verification */
278 0xa8, 0xec, 0x43, 0x6d, 0x67, 0x76, 0x34, 0xae, 0x52, 0x5a, 0xc1,
279 0xfc, 0xeb, 0xe1, 0x1a, 0x03, 0x9e, 0xc1, 0x76, 0x94, 0xfa, 0xc6,
280 0xe9, 0x85, 0x27, 0xb6, 0x42, 0xf2, 0xed, 0xd5, 0xce, 0x61
281};
282
283/** RFC 8448 simple 1-RTT test: server verification */
285 0x9b, 0x9b, 0x14, 0x1d, 0x90, 0x63, 0x37, 0xfb, 0xd2, 0xcb, 0xdc,
286 0xe7, 0x1d, 0xf4, 0xde, 0xda, 0x4a, 0xb4, 0x2c, 0x30, 0x95, 0x72,
287 0xcb, 0x7f, 0xff, 0xee, 0x54, 0x54, 0xb7, 0x8f, 0x07, 0x18
288};
289
290/** RFC 8448 simple 1-RTT test: master secret */
292 0x18, 0xdf, 0x06, 0x84, 0x3d, 0x13, 0xa0, 0x8b, 0xf2, 0xa4, 0x49,
293 0x84, 0x4c, 0x5f, 0x8a, 0x47, 0x80, 0x01, 0xbc, 0x4d, 0x4c, 0x62,
294 0x79, 0x84, 0xd5, 0xa4, 0x1d, 0xa8, 0xd0, 0x40, 0x29, 0x19
295};
296
297/** RFC 8448 simple 1-RTT test: client application traffic secret */
299 0x9e, 0x40, 0x64, 0x6c, 0xe7, 0x9a, 0x7f, 0x9d, 0xc0, 0x5a, 0xf8,
300 0x88, 0x9b, 0xce, 0x65, 0x52, 0x87, 0x5a, 0xfa, 0x0b, 0x06, 0xdf,
301 0x00, 0x87, 0xf7, 0x92, 0xeb, 0xb7, 0xc1, 0x75, 0x04, 0xa5
302};
303
304/** RFC 8448 simple 1-RTT test: client application traffic key */
306 0x17, 0x42, 0x2d, 0xda, 0x59, 0x6e, 0xd5, 0xd9, 0xac, 0xd8, 0x90,
307 0xe3, 0xc6, 0x3f, 0x50, 0x51
308};
309
310/** RFC 8448 simple 1-RTT test: client application traffic IV */
312 0x5b, 0x78, 0x92, 0x3d, 0xee, 0x08, 0x57, 0x90, 0x33, 0xe5, 0x23,
313 0xd9
314};
315
316/** RFC 8448 simple 1-RTT test: server application traffic secret */
318 0xa1, 0x1a, 0xf9, 0xf0, 0x55, 0x31, 0xf8, 0x56, 0xad, 0x47, 0x11,
319 0x6b, 0x45, 0xa9, 0x50, 0x32, 0x82, 0x04, 0xb4, 0xf4, 0x4b, 0xfb,
320 0x6b, 0x3a, 0x4b, 0x4f, 0x1f, 0x3f, 0xcb, 0x63, 0x16, 0x43
321};
322
323/** RFC 8448 simple 1-RTT test: server application traffic key */
325 0x9f, 0x02, 0x28, 0x3b, 0x6c, 0x9c, 0x07, 0xef, 0xc2, 0x6b, 0xb9,
326 0xf2, 0xac, 0x92, 0xe3, 0x56
327};
328
329/** RFC 8448 simple 1-RTT test: server application traffic IV */
331 0xcf, 0x78, 0x2b, 0x88, 0xdd, 0x83, 0x54, 0x9a, 0xad, 0xf1, 0xe9,
332 0x84
333};
334
335/** RFC 8448 simple 1-RTT test: resumption secret */
337 0x4e, 0xcd, 0x0e, 0xb6, 0xec, 0x3b, 0x4d, 0x87, 0xf5, 0xd6, 0x02,
338 0x8f, 0x92, 0x2c, 0xa4, 0xc5, 0x85, 0x1a, 0x27, 0x7f, 0xd4, 0x13,
339 0x11, 0xc9, 0xe6, 0x2d, 0x2c, 0x94, 0x92, 0xe1, 0xc4, 0xf3
340};
341
342/** RFC 8448 simple 1-RTT test: server CertificateVerify signable digest
343 *
344 * This value is not provided directly within RFC 8448, but may be
345 * calculated from the provided values.
346 */
348 0xbe, 0xed, 0x95, 0xaf, 0x40, 0x4e, 0x23, 0xdd, 0x55, 0x3e, 0xbc,
349 0xfb, 0x4a, 0x00, 0xb8, 0xdb, 0xbf, 0x22, 0x44, 0xdb, 0x2a, 0x9a,
350 0xa3, 0x9a, 0x37, 0x92, 0x56, 0x51, 0x26, 0x7c, 0x14, 0x1f
351};
352
353/** RFC 8448 resumed 0-RTT test: server random bytes */
355 .bytes = {
356 0x3c, 0xcf, 0xd2, 0xde, 0xc8, 0x90, 0x22, 0x27, 0x63, 0x47,
357 0x2a, 0xe8, 0x13, 0x67, 0x77, 0xc9, 0xd7, 0x35, 0x87, 0x77,
358 0xbb, 0x66, 0xe9, 0x1e, 0xa5, 0x12, 0x24, 0x95, 0xf5, 0x59,
359 0xea, 0x2d
360 },
361};
362
363/** RFC 8448 resumed 0-RTT test: client X25519 private key */
365 0xbf, 0xf9, 0x11, 0x88, 0x28, 0x38, 0x46, 0xdd, 0x6a, 0x21, 0x34,
366 0xef, 0x71, 0x80, 0xca, 0x2b, 0x0b, 0x14, 0xfb, 0x10, 0xdc, 0xe7,
367 0x07, 0xb5, 0x09, 0x8c, 0x0d, 0xdd, 0xc8, 0x13, 0xb2, 0xdf
368};
369
370/** RFC 8448 resumed 0-RTT test: server X25519 public key */
372 0x12, 0x17, 0x61, 0xee, 0x42, 0xc3, 0x33, 0xe1, 0xb9, 0xe7, 0x7b,
373 0x60, 0xdd, 0x57, 0xc2, 0x05, 0x3c, 0xd9, 0x45, 0x12, 0xab, 0x47,
374 0xf1, 0x15, 0xe8, 0x6e, 0xff, 0x50, 0x94, 0x2c, 0xea, 0x31
375};
376
377/** RFC 8448 resumed 0-RTT test: ClientHello */
379 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03, 0x1b, 0xc3, 0xce, 0xb6, 0xbb,
380 0xe3, 0x9c, 0xff, 0x93, 0x83, 0x55, 0xb5, 0xa5, 0x0a, 0xdb, 0x6d,
381 0xb2, 0x1b, 0x7a, 0x6a, 0xf6, 0x49, 0xd7, 0xb4, 0xbc, 0x41, 0x9d,
382 0x78, 0x76, 0x48, 0x7d, 0x95, 0x00, 0x00, 0x06, 0x13, 0x01, 0x13,
383 0x03, 0x13, 0x02, 0x01, 0x00, 0x01, 0xcd, 0x00, 0x00, 0x00, 0x0b,
384 0x00, 0x09, 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
385 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x12,
386 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x01, 0x00, 0x01,
387 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x00, 0x33, 0x00, 0x26,
388 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0xe4, 0xff, 0xb6, 0x8a, 0xc0,
389 0x5f, 0x8d, 0x96, 0xc9, 0x9d, 0xa2, 0x66, 0x98, 0x34, 0x6c, 0x6b,
390 0xe1, 0x64, 0x82, 0xba, 0xdd, 0xda, 0xfe, 0x05, 0x1a, 0x66, 0xb4,
391 0xf1, 0x8d, 0x66, 0x8f, 0x0b, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2b,
392 0x00, 0x03, 0x02, 0x03, 0x04, 0x00, 0x0d, 0x00, 0x20, 0x00, 0x1e,
393 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x02, 0x03, 0x08, 0x04, 0x08,
394 0x05, 0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01,
395 0x04, 0x02, 0x05, 0x02, 0x06, 0x02, 0x02, 0x02, 0x00, 0x2d, 0x00,
396 0x02, 0x01, 0x01, 0x00, 0x1c, 0x00, 0x02, 0x40, 0x01, 0x00, 0x15,
397 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
405 0x00, 0x00, 0x29, 0x00, 0xdd, 0x00, 0xb8, 0x00, 0xb2, 0x2c, 0x03,
406 0x5d, 0x82, 0x93, 0x59, 0xee, 0x5f, 0xf7, 0xaf, 0x4e, 0xc9, 0x00,
407 0x00, 0x00, 0x00, 0x26, 0x2a, 0x64, 0x94, 0xdc, 0x48, 0x6d, 0x2c,
408 0x8a, 0x34, 0xcb, 0x33, 0xfa, 0x90, 0xbf, 0x1b, 0x00, 0x70, 0xad,
409 0x3c, 0x49, 0x88, 0x83, 0xc9, 0x36, 0x7c, 0x09, 0xa2, 0xbe, 0x78,
410 0x5a, 0xbc, 0x55, 0xcd, 0x22, 0x60, 0x97, 0xa3, 0xa9, 0x82, 0x11,
411 0x72, 0x83, 0xf8, 0x2a, 0x03, 0xa1, 0x43, 0xef, 0xd3, 0xff, 0x5d,
412 0xd3, 0x6d, 0x64, 0xe8, 0x61, 0xbe, 0x7f, 0xd6, 0x1d, 0x28, 0x27,
413 0xdb, 0x27, 0x9c, 0xce, 0x14, 0x50, 0x77, 0xd4, 0x54, 0xa3, 0x66,
414 0x4d, 0x4e, 0x6d, 0xa4, 0xd2, 0x9e, 0xe0, 0x37, 0x25, 0xa6, 0xa4,
415 0xda, 0xfc, 0xd0, 0xfc, 0x67, 0xd2, 0xae, 0xa7, 0x05, 0x29, 0x51,
416 0x3e, 0x3d, 0xa2, 0x67, 0x7f, 0xa5, 0x90, 0x6c, 0x5b, 0x3f, 0x7d,
417 0x8f, 0x92, 0xf2, 0x28, 0xbd, 0xa4, 0x0d, 0xda, 0x72, 0x14, 0x70,
418 0xf9, 0xfb, 0xf2, 0x97, 0xb5, 0xae, 0xa6, 0x17, 0x64, 0x6f, 0xac,
419 0x5c, 0x03, 0x27, 0x2e, 0x97, 0x07, 0x27, 0xc6, 0x21, 0xa7, 0x91,
420 0x41, 0xef, 0x5f, 0x7d, 0xe6, 0x50, 0x5e, 0x5b, 0xfb, 0xc3, 0x88,
421 0xe9, 0x33, 0x43, 0x69, 0x40, 0x93, 0x93, 0x4a, 0xe4, 0xd3, 0x57,
422 0xfa, 0xd6, 0xaa, 0xcb, 0x00, 0x21, 0x20, 0x3a, 0xdd, 0x4f, 0xb2,
423 0xd8, 0xfd, 0xf8, 0x22, 0xa0, 0xca, 0x3c, 0xf7, 0x67, 0x8e, 0xf5,
424 0xe8, 0x8d, 0xae, 0x99, 0x01, 0x41, 0xc5, 0x92, 0x4d, 0x57, 0xbb,
425 0x6f, 0xa3, 0x1b, 0x9e, 0x5f, 0x9d
426};
427
428/** RFC 8448 resumed 0-RTT test: ServerHello */
430 0x02, 0x00, 0x00, 0x5c, 0x03, 0x03, 0x3c, 0xcf, 0xd2, 0xde, 0xc8,
431 0x90, 0x22, 0x27, 0x63, 0x47, 0x2a, 0xe8, 0x13, 0x67, 0x77, 0xc9,
432 0xd7, 0x35, 0x87, 0x77, 0xbb, 0x66, 0xe9, 0x1e, 0xa5, 0x12, 0x24,
433 0x95, 0xf5, 0x59, 0xea, 0x2d, 0x00, 0x13, 0x01, 0x00, 0x00, 0x34,
434 0x00, 0x29, 0x00, 0x02, 0x00, 0x00, 0x00, 0x33, 0x00, 0x24, 0x00,
435 0x1d, 0x00, 0x20, 0x12, 0x17, 0x61, 0xee, 0x42, 0xc3, 0x33, 0xe1,
436 0xb9, 0xe7, 0x7b, 0x60, 0xdd, 0x57, 0xc2, 0x05, 0x3c, 0xd9, 0x45,
437 0x12, 0xab, 0x47, 0xf1, 0x15, 0xe8, 0x6e, 0xff, 0x50, 0x94, 0x2c,
438 0xea, 0x31, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04
439};
440
441/** RFC 8448 resumed 0-RTT test: ClientHello prefix length */
443 ( sizeof ( rfc8448_resumed_clienthello ) - 35 );
444
445/** RFC 8448 resumed 0-RTT test: EncryptedExtensions */
447 0x08, 0x00, 0x00, 0x28, 0x00, 0x26, 0x00, 0x0a, 0x00, 0x14, 0x00,
448 0x12, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x01, 0x00,
449 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x00, 0x1c, 0x00,
450 0x02, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00
451};
452
453/** RFC 8448 resumed 0-RTT test: server Finished */
455 0x14, 0x00, 0x00, 0x20, 0x48, 0xd3, 0xe0, 0xe1, 0xb3, 0xd9, 0x07,
456 0xc6, 0xac, 0xff, 0x14, 0x5e, 0x16, 0x09, 0x03, 0x88, 0xc7, 0x7b,
457 0x05, 0xc0, 0x50, 0xb6, 0x34, 0xab, 0x1a, 0x88, 0xbb, 0xd0, 0xdd,
458 0x1a, 0x34, 0xb2
459};
460
461/** RFC 8448 resumed 0-RTT test: EndOfEarlyData */
463 0x05, 0x00, 0x00, 0x00
464};
465
466/** RFC 8448 resumed 0-RTT test: client Finished */
468 0x14, 0x00, 0x00, 0x20, 0x72, 0x30, 0xa9, 0xc9, 0x52, 0xc2, 0x5c,
469 0xd6, 0x13, 0x8f, 0xc5, 0xe6, 0x62, 0x83, 0x08, 0xc4, 0x1c, 0x53,
470 0x35, 0xdd, 0x81, 0xb9, 0xf9, 0x6b, 0xce, 0xa5, 0x0f, 0xd3, 0x2b,
471 0xda, 0x41, 0x6d
472};
473
474/** RFC 8448 resumed 0-RTT test: PSK binder */
476 0x3a, 0xdd, 0x4f, 0xb2, 0xd8, 0xfd, 0xf8, 0x22, 0xa0, 0xca, 0x3c,
477 0xf7, 0x67, 0x8e, 0xf5, 0xe8, 0x8d, 0xae, 0x99, 0x01, 0x41, 0xc5,
478 0x92, 0x4d, 0x57, 0xbb, 0x6f, 0xa3, 0x1b, 0x9e, 0x5f, 0x9d
479};
480
481/** RFC 8448 resumed 0-RTT test: early secret */
483 0x9b, 0x21, 0x88, 0xe9, 0xb2, 0xfc, 0x6d, 0x64, 0xd7, 0x1d, 0xc3,
484 0x29, 0x90, 0x0e, 0x20, 0xbb, 0x41, 0x91, 0x50, 0x00, 0xf6, 0x78,
485 0xaa, 0x83, 0x9c, 0xbb, 0x79, 0x7c, 0xb7, 0xd8, 0x33, 0x2c
486};
487
488/** RFC 8448 resumed 0-RTT test: client early traffic secret */
490 0x3f, 0xbb, 0xe6, 0xa6, 0x0d, 0xeb, 0x66, 0xc3, 0x0a, 0x32, 0x79,
491 0x5a, 0xba, 0x0e, 0xff, 0x7e, 0xaa, 0x10, 0x10, 0x55, 0x86, 0xe7,
492 0xbe, 0x5c, 0x09, 0x67, 0x8d, 0x63, 0xb6, 0xca, 0xab, 0x62
493};
494
495/** RFC 8448 resumed 0-RTT test: client early traffic key */
497 0x92, 0x02, 0x05, 0xa5, 0xb7, 0xbf, 0x21, 0x15, 0xe6, 0xfc, 0x5c,
498 0x29, 0x42, 0x83, 0x4f, 0x54
499};
500
501/** RFC 8448 resumed 0-RTT test: client early traffic IV */
503 0x6d, 0x47, 0x5f, 0x09, 0x93, 0xc8, 0xe5, 0x64, 0x61, 0x0d, 0xb2,
504 0xb9
505};
506
507/** RFC 8448 resumed 0-RTT test: handshake secret */
509 0x00, 0x5c, 0xb1, 0x12, 0xfd, 0x8e, 0xb4, 0xcc, 0xc6, 0x23, 0xbb,
510 0x88, 0xa0, 0x7c, 0x64, 0xb3, 0xed, 0xe1, 0x60, 0x53, 0x63, 0xfc,
511 0x7d, 0x0d, 0xf8, 0xc7, 0xce, 0x4f, 0xf0, 0xfb, 0x4a, 0xe6
512};
513
514/** RFC 8448 resumed 0-RTT test: client handshake traffic secret */
516 0x2f, 0xaa, 0xc0, 0x8f, 0x85, 0x1d, 0x35, 0xfe, 0xa3, 0x60, 0x4f,
517 0xcb, 0x4d, 0xe8, 0x2d, 0xc6, 0x2c, 0x9b, 0x16, 0x4a, 0x70, 0x97,
518 0x4d, 0x04, 0x62, 0xe2, 0x7f, 0x1a, 0xb2, 0x78, 0x70, 0x0f
519};
520
521/** RFC 8448 resumed 0-RTT test: client handshake traffic key */
523 0xb1, 0x53, 0x08, 0x06, 0xf4, 0xad, 0xfe, 0xac, 0x83, 0xf1, 0x41,
524 0x30, 0x32, 0xbb, 0xfa, 0x82
525};
526
527/** RFC 8448 resumed 0-RTT test: client handshake traffic IV */
529 0xeb, 0x50, 0xc1, 0x6b, 0xe7, 0x65, 0x4a, 0xbf, 0x99, 0xdd, 0x06,
530 0xd9
531};
532
533/** RFC 8448 resumed 0-RTT test: server handshake traffic secret */
535 0xfe, 0x92, 0x7a, 0xe2, 0x71, 0x31, 0x2e, 0x8b, 0xf0, 0x27, 0x5b,
536 0x58, 0x1c, 0x54, 0xee, 0xf0, 0x20, 0x45, 0x0d, 0xc4, 0xec, 0xff,
537 0xaa, 0x05, 0xa1, 0xa3, 0x5d, 0x27, 0x51, 0x8e, 0x78, 0x03
538};
539
540/** RFC 8448 resumed 0-RTT test: server handshake traffic key */
542 0x27, 0xc6, 0xbd, 0xc0, 0xa3, 0xdc, 0xea, 0x39, 0xa4, 0x73, 0x26,
543 0xd7, 0x9b, 0xc9, 0xe4, 0xee
544};
545
546/** RFC 8448 resumed 0-RTT test: server handshake traffic IV */
548 0x95, 0x69, 0xec, 0xdd, 0x4d, 0x05, 0x36, 0x70, 0x5e, 0x9e, 0xf7,
549 0x25
550};
551
552/** RFC 8448 resumed 0-RTT test: client verification */
554 0x72, 0x30, 0xa9, 0xc9, 0x52, 0xc2, 0x5c, 0xd6, 0x13, 0x8f, 0xc5,
555 0xe6, 0x62, 0x83, 0x08, 0xc4, 0x1c, 0x53, 0x35, 0xdd, 0x81, 0xb9,
556 0xf9, 0x6b, 0xce, 0xa5, 0x0f, 0xd3, 0x2b, 0xda, 0x41, 0x6d
557};
558
559/** RFC 8448 resumed 0-RTT test: server verification */
561 0x48, 0xd3, 0xe0, 0xe1, 0xb3, 0xd9, 0x07, 0xc6, 0xac, 0xff, 0x14,
562 0x5e, 0x16, 0x09, 0x03, 0x88, 0xc7, 0x7b, 0x05, 0xc0, 0x50, 0xb6,
563 0x34, 0xab, 0x1a, 0x88, 0xbb, 0xd0, 0xdd, 0x1a, 0x34, 0xb2
564};
565
566/** RFC 8448 resumed 0-RTT test: master secret */
568 0xe2, 0xd3, 0x2d, 0x4e, 0xd6, 0x6d, 0xd3, 0x78, 0x97, 0xa0, 0xe8,
569 0x0c, 0x84, 0x10, 0x75, 0x03, 0xce, 0x58, 0xbf, 0x8a, 0xad, 0x4c,
570 0xb5, 0x5a, 0x50, 0x02, 0xd7, 0x7e, 0xcb, 0x89, 0x0e, 0xce
571};
572
573/** RFC 8448 resumed 0-RTT test: client application traffic secret */
575 0x2a, 0xbb, 0xf2, 0xb8, 0xe3, 0x81, 0xd2, 0x3d, 0xbe, 0xbe, 0x1d,
576 0xd2, 0xa7, 0xd1, 0x6a, 0x8b, 0xf4, 0x84, 0xcb, 0x49, 0x50, 0xd2,
577 0x3f, 0xb7, 0xfb, 0x7f, 0xa8, 0x54, 0x70, 0x62, 0xd9, 0xa1
578};
579
580/** RFC 8448 resumed 0-RTT test: client application traffic key */
582 0x3c, 0xf1, 0x22, 0xf3, 0x01, 0xc6, 0x35, 0x8c, 0xa7, 0x98, 0x95,
583 0x53, 0x25, 0x0e, 0xfd, 0x72
584};
585
586/** RFC 8448 resumed 0-RTT test: client application traffic IV */
588 0xab, 0x1a, 0xec, 0x26, 0xaa, 0x78, 0xb8, 0xfc, 0x11, 0x76, 0xb9,
589 0xac
590};
591
592/** RFC 8448 resumed 0-RTT test: server application traffic secret */
594 0xcc, 0x21, 0xf1, 0xbf, 0x8f, 0xeb, 0x7d, 0xd5, 0xfa, 0x50, 0x5b,
595 0xd9, 0xc4, 0xb4, 0x68, 0xa9, 0x98, 0x4d, 0x55, 0x4a, 0x99, 0x3d,
596 0xc4, 0x9e, 0x6d, 0x28, 0x55, 0x98, 0xfb, 0x67, 0x26, 0x91
597};
598
599/** RFC 8448 resumed 0-RTT test: server application traffic key */
601 0xe8, 0x57, 0xc6, 0x90, 0xa3, 0x4c, 0x5a, 0x91, 0x29, 0xd8, 0x33,
602 0x61, 0x96, 0x84, 0xf9, 0x5e
603};
604
605/** RFC 8448 resumed 0-RTT test: server application traffic IV */
607 0x06, 0x85, 0xd6, 0xb5, 0x61, 0xaa, 0xb9, 0xef, 0x10, 0x13, 0xfa,
608 0xf9
609};
610
611/** Dummy minimal tests: client random bytes */
612static const struct tls_random dummy_client_nonce = {
613 .bytes = {
614 0x86, 0x75, 0xa3, 0x00, 0x0c, 0x3d, 0x73, 0x79, 0xa3, 0x78,
615 0x04, 0xfc, 0x5d, 0x7f, 0x99, 0xef, 0xf1, 0x9e, 0xda, 0x74,
616 0x80, 0x3c, 0x60, 0x83, 0xac, 0xbe, 0x15, 0xae, 0x11, 0x3f,
617 0xbe, 0xba
618 },
619};
620
621/** Dummy minimal tests: ClientHello */
622static const uint8_t dummy_clienthello[] = {
623 0x01, 0x00, 0x00, 0x22, 0x03, 0x02, 0x86, 0x75, 0xa3, 0x00, 0x0c,
624 0x3d, 0x73, 0x79, 0xa3, 0x78, 0x04, 0xfc, 0x5d, 0x7f, 0x99, 0xef,
625 0xf1, 0x9e, 0xda, 0x74, 0x80, 0x3c, 0x60, 0x83, 0xac, 0xbe, 0x15,
626 0xae, 0x11, 0x3f, 0xbe, 0xba
627};
628
629/** Dummy minimal tests: ServerHello */
630static const uint8_t dummy_serverhello[] = {
631 0x02, 0x00, 0x00, 0x22, 0x03, 0x02, 0xa3, 0xdd, 0xe4, 0x56, 0xda,
632 0xc8, 0x65, 0xd8, 0x2c, 0xc3, 0xb0, 0x47, 0x49, 0x2f, 0xdb, 0xfd,
633 0xc3, 0xaf, 0x6b, 0x60, 0x98, 0xe1, 0x99, 0xb3, 0xd4, 0x9b, 0x55,
634 0x15, 0x43, 0x8d, 0xec, 0x3e
635};
636
637/** Dummy minimal tests: pre-master secret */
638static const uint8_t dummy_premaster[] = {
639 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64,
640 0x21, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61,
641 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x70, 0x72, 0x65, 0x2d,
642 0x6d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x73, 0x65, 0x63, 0x72,
643 0x65, 0x74, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x65, 0x6e, 0x6f,
644 0x75, 0x67, 0x68, 0x20, 0x74, 0x6f, 0x20, 0x72, 0x65, 0x71, 0x75,
645 0x69, 0x72, 0x65, 0x20, 0x48, 0x4d, 0x41, 0x43, 0x20, 0x6b, 0x65,
646 0x79, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69,
647 0x6f, 0x6e, 0x2e
648};
649
650/** Dummy minimal tests: ServerKeyExchange DH parameters */
651static const uint8_t dummy_dh_param[] = {
652 0x65, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c
653};
654
655/** Dummy minimal TLSv1.2 test: master secret */
657 0x6f, 0x57, 0xe7, 0xab, 0xd9, 0x0c, 0xcc, 0x99, 0xe0, 0x18, 0xa6,
658 0x2b, 0x7c, 0x7d, 0x04, 0x84, 0x18, 0x37, 0xee, 0x9e, 0xad, 0x47,
659 0x54, 0x6e, 0xd4, 0xd0, 0x84, 0x99, 0x91, 0x5d, 0x8f, 0xee, 0xfa,
660 0xec, 0x08, 0x21, 0x35, 0x2d, 0x1e, 0xe3, 0x4b, 0xe5, 0xbf, 0x81,
661 0xc2, 0x23, 0x47, 0x10
662};
663
664/** Dummy minimal TLSv1.2 test: client verification */
666 0xd6, 0x5d, 0xbb, 0xff, 0x72, 0xc5, 0x51, 0xa5, 0xa9, 0x53, 0x85,
667 0xab
668};
669
670/** Dummy minimal TLSv1.2 test: server verification */
672 0x6c, 0xe4, 0x95, 0x70, 0xc3, 0x8d, 0x2a, 0xcd, 0x2d, 0x8b, 0x0b,
673 0x33
674};
675
676/** Dummy minimal TLSv1.2 test: client traffic key */
678 0xda, 0x2a, 0x4b, 0xbd, 0x5b, 0x0a, 0xa5, 0xd3, 0x30, 0x54, 0x9a,
679 0xcc, 0x99, 0x28, 0x93, 0xfa
680};
681
682/** Dummy minimal TLSv1.2 test: client traffic IV */
684 0xcd, 0xa5, 0x5a, 0x1d
685};
686
687/** Dummy minimal TLSv1.2 test: client traffic MAC */
689 0xe8, 0x4e, 0x9b, 0x7a, 0xb9, 0x97, 0x7d, 0x47, 0xfb, 0x4a, 0xe8,
690 0x1e, 0xb6, 0x6e, 0xfc, 0x2b, 0x94, 0x8a, 0xd4, 0x75, 0xde, 0xd9,
691 0xb9, 0x73, 0x23, 0x16, 0x06, 0x2f, 0x96, 0xb0, 0xb6, 0xcb
692};
693
694/** Dummy minimal TLSv1.2 test: server traffic key */
696 0x0b, 0x58, 0x8a, 0xbc, 0x5a, 0x6a, 0x44, 0x33, 0xdc, 0x60, 0xd4,
697 0xd1, 0xf1, 0x9b, 0xba, 0xd7
698};
699
700/** Dummy minimal TLSv1.2 test: server traffic IV */
702 0xa2, 0x35, 0xf7, 0x40
703};
704
705/** Dummy minimal TLSv1.2 test: server traffic MAC */
707 0x16, 0x7c, 0x12, 0x5d, 0x85, 0x84, 0xfd, 0x5e, 0xf1, 0x3d, 0x0f,
708 0x5a, 0xbf, 0xf6, 0x44, 0x22, 0x93, 0xf8, 0xea, 0x17, 0x3c, 0x0b,
709 0x4e, 0xdf, 0x82, 0x5e, 0x26, 0xd0, 0xcb, 0xe5, 0xac, 0xa4
710};
711
712/** Dummy minimal TLSv1.2 test: client signable digest */
714 0x14, 0x3b, 0xc1, 0x0c, 0x25, 0xf3, 0x6a, 0x4d, 0x4a, 0x7a, 0xd9,
715 0xb2, 0xee, 0x7e, 0x48, 0xc8, 0xf4, 0x71, 0x53, 0xb0, 0x69, 0x29,
716 0xe5, 0x2c, 0x0d, 0xeb, 0xa3, 0xf9, 0xe1, 0xcd, 0x02, 0x3d
717};
718
719/** Dummy minimal TLSv1.2 test: server signable digest */
721 0xd4, 0x11, 0x45, 0x52, 0xa6, 0xf0, 0xe5, 0xe0, 0x5e, 0x20, 0x99,
722 0x77, 0x5e, 0x0c, 0xbe, 0xce, 0x3e, 0xd9, 0x81, 0xf7, 0x73, 0x49,
723 0xc1, 0xab, 0xf2, 0xd3, 0x1e, 0xf7, 0xf3, 0x72, 0xc4, 0x15
724};
725
726/** Dummy minimal TLSv1.0 test: master secret (MD5 portion) */
728 0xed, 0x60, 0x7e, 0x6b, 0xce, 0xcb, 0x2c, 0xaf, 0x04, 0x19, 0xeb,
729 0xee, 0xbd, 0x35, 0xfa, 0x85, 0xc2, 0xcf, 0x5b, 0x5d, 0xea, 0x62,
730 0xae, 0xe2,
731};
732
733/** Dummy minimal TLSv1.0 test: master secret (SHA-1 portion) */
735 0xa2, 0x81, 0x2c, 0x2f, 0xbd, 0x69, 0x59, 0x19, 0xb8, 0xe5, 0x41,
736 0xfc, 0xb0, 0x63, 0x21, 0xbd, 0xd6, 0xca, 0x15, 0xab, 0xb1, 0x18,
737 0xea, 0x14
738};
739
740/** Dummy minimal TLSv1.0 test: client verification */
742 0xc3, 0x50, 0x18, 0xee, 0x24, 0x70, 0x27, 0x6a, 0x98, 0xe0, 0xd0,
743 0x73
744};
745
746/** Dummy minimal TLSv1.0 test: server verification */
748 0xcb, 0xa0, 0xc8, 0x13, 0x10, 0xc4, 0xba, 0xe1, 0x4c, 0xe3, 0x99,
749 0xeb
750};
751
752/** Dummy minimal TLSv1.0 test: client traffic key */
754 0x0e, 0xa5, 0x90, 0xb8, 0x12, 0xa2, 0xf0, 0xe1, 0xaa, 0x0a, 0xba,
755 0x85, 0x8d, 0x73, 0xcd, 0x99
756};
757
758/** Dummy minimal TLSv1.0 test: client traffic IV */
760 0xac, 0x25, 0xe7, 0x78
761};
762
763/** Dummy minimal TLSv1.0 test: client traffic MAC */
765 0x84, 0xe9, 0x05, 0xb6, 0xb0, 0x21, 0x71, 0x10, 0x93, 0xdd, 0xc7,
766 0x0b, 0xb8, 0x03, 0x3e, 0x14, 0x25, 0x69, 0xfe, 0xd6, 0xb3, 0x90,
767 0xf0, 0x0b, 0xa0, 0x9a, 0xff, 0x9b, 0x02, 0xc4, 0x3a, 0x49
768};
769
770/** Dummy minimal TLSv1.0 test: server traffic key */
772 0x7a, 0xea, 0x6d, 0xb8, 0x9d, 0xa8, 0xc5, 0x64, 0x7c, 0xd7, 0x0d,
773 0xc4, 0x1a, 0xfa, 0x92, 0x26
774};
775
776/** Dummy minimal TLSv1.0 test: server traffic IV */
778 0xa0, 0xa9, 0x81, 0x33
779};
780
781/** Dummy minimal TLSv1.0 test: server traffic MAC */
783 0x39, 0x7b, 0x90, 0xd7, 0xc8, 0xe3, 0x11, 0x4b, 0x39, 0x47, 0x56,
784 0x6a, 0xe5, 0xb8, 0x40, 0x4e, 0x58, 0xad, 0x8a, 0x1a, 0xbf, 0x9a,
785 0x91, 0x40, 0x44, 0x7d, 0xa3, 0xd0, 0x0b, 0x42, 0xa8, 0x09
786};
787
788/**
789 * Perform RFC 8448 simple 1-RTT test
790 *
791 * @v tlskey Key schedule
792 * @v psk Pre-shared key from which to resume
793 */
794static void rfc8448_simple_test ( struct tls_key_schedule *tlskey,
795 struct tls_preshared_key *psk ) {
796 struct exchange_algorithm *exchange = &x25519_algorithm;
797 struct digest_algorithm *digest = &sha256_algorithm;
798 size_t sharedsize = exchange->sharedsize;
799 size_t digestsize = digest->digestsize;
800 uint8_t shared[sharedsize];
801 uint8_t tbshash[digestsize];
802 uint8_t verify[digestsize];
803 uint8_t key[16];
804 uint8_t iv[12];
805
806 /* Start key schedule */
807 ok ( tlskey_start ( tlskey, &tlskey_hkdf, digest,
809
810 /* Early secret */
812 tlskey->kdf.secret, digestsize ) == 0 );
813
814 /* ClientHello */
816 sizeof ( rfc8448_simple_clienthello ) );
817
818 /* ServerHello */
820 sizeof ( rfc8448_simple_serverhello ) );
822 rfc8448_simple_x25519_partner, shared ) == 0 );
823 ok ( tlskey_apply ( tlskey, shared, sizeof ( shared ) ) == 0 );
824
825 /* Handshake secret */
827 tlskey->kdf.secret, digestsize ) == 0 );
828
829 /* Client handshake traffic secret */
830 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_handshake ) == 0 );
832 tlskey->traffic[TLS_CLIENT].secret, digestsize ) == 0 );
833
834 /* Server handshake traffic secret */
835 ok ( tlskey_traffic ( tlskey, &tls_server, &tls_handshake ) == 0 );
837 tlskey->traffic[TLS_SERVER].secret, digestsize ) == 0 );
838
839 /* Master secret */
840 ok ( tlskey_master ( tlskey, 1 ) == 0 );
842 tlskey->kdf.secret, digestsize ) == 0 );
843
844 /* Server handshake traffic keys */
845 ok ( tlskey_cipher ( tlskey, &tls_server, key, sizeof ( key ),
846 iv, sizeof ( iv ), NULL, 0 ) == 0 );
848 key, sizeof ( key ) ) == 0 );
850 iv, sizeof ( iv ) ) == 0 );
851
852 /* EncryptedExtensions */
855
856 /* Certificate */
858 sizeof ( rfc8448_simple_certificate ) );
859
860 /* CertificateVerify signable digest */
861 ok ( tlskey_tbshash ( tlskey, &tls_server, digest, NULL, 0,
862 tbshash ) == 0 );
864 tbshash, sizeof ( tbshash ) ) == 0 );
865
866 /* CertificateVerify */
869
870 /* Server verification */
871 ok ( tlskey_verify ( tlskey, &tls_server, verify,
872 sizeof ( verify ) ) == 0 );
874 verify, sizeof ( verify ) ) == 0 );
875
876 /* Server Finished */
879
880 /* Server application traffic secret */
881 ok ( tlskey_traffic ( tlskey, &tls_server, &tls_application ) == 0 );
883 tlskey->traffic[TLS_SERVER].secret, digestsize ) == 0 );
884
885 /* Server application traffic keys */
886 ok ( tlskey_cipher ( tlskey, &tls_server, key, sizeof ( key ),
887 iv, sizeof ( iv ), NULL, 0 ) == 0 );
889 key, sizeof ( key ) ) == 0 );
891 iv, sizeof ( iv ) ) == 0 );
892
893 /* Client handshake traffic keys */
894 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
895 iv, sizeof ( iv ), NULL, 0 ) == 0 );
897 key, sizeof ( key ) ) == 0 );
899 iv, sizeof ( iv ) ) == 0 );
900
901 /* Client verification */
902 ok ( tlskey_verify ( tlskey, &tls_client, verify,
903 sizeof ( verify ) ) == 0 );
905 verify, sizeof ( verify ) ) == 0 );
906
907 /* Client application traffic secret */
908 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_application ) == 0 );
910 tlskey->traffic[TLS_CLIENT].secret, digestsize ) == 0 );
911
912 /* Client Finished */
915
916 /* Client application traffic keys */
917 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
918 iv, sizeof ( iv ), NULL, 0 ) == 0 );
920 key, sizeof ( key ) ) == 0 );
922 iv, sizeof ( iv ) ) == 0 );
923
924 /* NewSessionTicket */
927
928 /* Resumption secret */
931 psk ) == 0 );
933 psk->key.resumption, digestsize ) == 0 );
934
935 /* Stop key schedule */
936 tlskey_stop ( tlskey );
937}
938
939/**
940 * Perform RFC 8448 resumed 0-RTT test
941 *
942 * @v tlskey Key schedule
943 * @v psk Pre-shared key from which to resume
944 */
945static void rfc8448_resumed_test ( struct tls_key_schedule *tlskey,
946 struct tls_preshared_key *psk ) {
947 struct exchange_algorithm *exchange = &x25519_algorithm;
948 struct digest_algorithm *digest = &sha256_algorithm;
949 size_t sharedsize = exchange->sharedsize;
950 size_t digestsize = digest->digestsize;
951 uint8_t shared[sharedsize];
952 uint8_t binder[digestsize];
953 uint8_t verify[digestsize];
954 uint8_t key[16];
955 int8_t iv[12];
956
957 /* Start key schedule */
958 ok ( tlskey_start ( tlskey, &tlskey_hkdf, digest,
960
961 /* ClientHello */
964 binder, sizeof ( binder ) ) == 0 );
966 binder, sizeof ( binder ) ) == 0 );
968 sizeof ( rfc8448_resumed_clienthello ) );
969
970 /* Early secret */
971 ok ( tlskey_load ( tlskey, 1, psk ) == 0 );
973 tlskey->kdf.secret, digestsize ) == 0 );
974
975 /* Client early traffic secret */
976 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_early ) == 0 );
978 tlskey->traffic[TLS_CLIENT].secret, digestsize ) == 0 );
979
980 /* Client early traffic keys */
981 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
982 iv, sizeof ( iv ), NULL, 0 ) == 0 );
984 key, sizeof ( key ) ) == 0 );
986 iv, sizeof ( iv ) ) == 0 );
987
988 /* ServerHello */
990 sizeof ( rfc8448_resumed_serverhello ) );
992 rfc8448_resumed_x25519_partner, shared ) == 0 );
993 ok ( tlskey_apply ( tlskey, shared, sizeof ( shared ) ) == 0 );
994
995 /* Handshake secret */
997 tlskey->kdf.secret, digestsize ) == 0 );
998
999 /* Client handshake traffic secret */
1000 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_handshake ) == 0 );
1002 tlskey->traffic[TLS_CLIENT].secret, digestsize ) == 0 );
1003
1004 /* Server handshake traffic secret */
1005 ok ( tlskey_traffic ( tlskey, &tls_server, &tls_handshake ) == 0 );
1007 tlskey->traffic[TLS_SERVER].secret, digestsize ) == 0 );
1008
1009 /* Master secret */
1010 ok ( tlskey_master ( tlskey, 1 ) == 0 );
1012 tlskey->kdf.secret, digestsize ) == 0 );
1013
1014 /* Server handshake traffic keys */
1015 ok ( tlskey_cipher ( tlskey, &tls_server, key, sizeof ( key ),
1016 iv, sizeof ( iv ), NULL, 0 ) == 0 );
1018 key, sizeof ( key ) ) == 0 );
1020 iv, sizeof ( iv ) ) == 0 );
1021
1022 /* EncryptedExtensions */
1025
1026 /* Server verification */
1027 ok ( tlskey_verify ( tlskey, &tls_server, verify,
1028 sizeof ( verify ) ) == 0 );
1030 verify, sizeof ( verify ) ) == 0 );
1031
1032 /* Server Finished */
1035
1036 /* Server application traffic secret */
1037 ok ( tlskey_traffic ( tlskey, &tls_server, &tls_application ) == 0 );
1039 tlskey->traffic[TLS_SERVER].secret, digestsize ) == 0 );
1040
1041 /* Server application traffic keys */
1042 ok ( tlskey_cipher ( tlskey, &tls_server, key, sizeof ( key ),
1043 iv, sizeof ( iv ), NULL, 0 ) == 0 );
1045 key, sizeof ( key ) ) == 0 );
1047 iv, sizeof ( iv ) ) == 0 );
1048
1049 /* Client handshake traffic keys */
1050 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
1051 iv, sizeof ( iv ), NULL, 0 ) == 0 );
1053 key, sizeof ( key ) ) == 0 );
1055 iv, sizeof ( iv ) ) == 0 );
1056
1057 /* EndOfEarlyData */
1059 sizeof ( rfc8448_resumed_endofearlydata ) );
1060
1061 /* Client verification */
1062 ok ( tlskey_verify ( tlskey, &tls_client, verify,
1063 sizeof ( verify ) ) == 0 );
1065 verify, sizeof ( verify ) ) == 0 );
1066
1067 /* Client application traffic secret */
1068 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_application ) == 0 );
1070 tlskey->traffic[TLS_CLIENT].secret, digestsize ) == 0 );
1071
1072 /* Client Finished */
1075
1076 /* Client application traffic keys */
1077 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
1078 iv, sizeof ( iv ), NULL, 0 ) == 0 );
1080 key, sizeof ( key ) ) == 0 );
1082 iv, sizeof ( iv ) ) == 0 );
1083
1084 /* Stop key schedule */
1085 tlskey_stop ( tlskey );
1086}
1087
1088/**
1089 * Perform dummy TLS version 1.2 test
1090 *
1091 * @v tlskey Key schedule
1092 * @v psk Pre-shared key
1093 */
1094static void dummy_hash ( struct tls_key_schedule *tlskey,
1095 struct tls_preshared_key *psk ) {
1096 struct digest_algorithm *digest = &sha256_algorithm;
1097 size_t digestsize = digest->digestsize;
1098 const int extended = 1;
1099 uint8_t tbshash[digestsize];
1100 uint8_t verify[12];
1101 uint8_t key[16];
1102 uint8_t iv[4];
1103 uint8_t mac[32];
1104
1105 /* Start key schedule */
1106 ok ( tlskey_start ( tlskey, &tlskey_hash, digest,
1107 &dummy_client_nonce ) == 0 );
1108
1109 /* ClientHello */
1111 sizeof ( dummy_clienthello ) );
1112
1113 /* ServerHello */
1115 sizeof ( dummy_serverhello ) );
1116
1117 /* Pre-master secret */
1118 ok ( tlskey_apply ( tlskey, dummy_premaster,
1119 sizeof ( dummy_premaster ) ) == 0 );
1120
1121 /* Master secret */
1122 ok ( tlskey_master ( tlskey, extended ) == 0 );
1124 sizeof ( dummy_hash_master_secret ) ) == 0 );
1125
1126 /* Client verification */
1127 ok ( tlskey_verify ( tlskey, &tls_client, verify,
1128 sizeof ( verify ) ) == 0 );
1130 sizeof ( verify ) ) == 0 );
1131
1132 /* Server verification */
1133 ok ( tlskey_verify ( tlskey, &tls_server, verify,
1134 sizeof ( verify ) ) == 0 );
1136 sizeof ( verify ) ) == 0 );
1137
1138 /* Client traffic keys */
1139 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_application ) == 0 );
1140 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
1141 iv, sizeof ( iv ), mac, sizeof ( mac ) ) == 0 );
1143 key, sizeof ( key ) ) == 0 );
1145 iv, sizeof ( iv ) ) == 0 );
1147 mac, sizeof ( mac ) ) == 0 );
1148
1149 /* Server traffic keys */
1150 ok ( tlskey_traffic ( tlskey, &tls_server, &tls_application ) == 0 );
1151 ok ( tlskey_cipher ( tlskey, &tls_server, key, sizeof ( key ),
1152 iv, sizeof ( iv ), mac, sizeof ( mac ) ) == 0 );
1154 key, sizeof ( key ) ) == 0 );
1156 iv, sizeof ( iv ) ) == 0 );
1158 mac, sizeof ( mac ) ) == 0 );
1159
1160 /* Client signable digest */
1161 ok ( tlskey_tbshash ( tlskey, &tls_client, digest, NULL, 0,
1162 tbshash ) == 0 );
1164 tbshash, sizeof ( tbshash ) ) == 0 );
1165
1166 /* Server signable digest */
1167 ok ( tlskey_tbshash ( tlskey, &tls_server, digest, dummy_dh_param,
1168 sizeof ( dummy_dh_param ), tbshash ) == 0 );
1170 tbshash, sizeof ( tbshash ) ) == 0 );
1171
1172 /* Save resumption secret */
1173 ok ( tlskey_save ( tlskey, NULL, 0, psk ) == 0 );
1174
1175 /* Stop key schedule */
1176 tlskey_stop ( tlskey );
1177
1178 /* Start key schedule */
1179 ok ( tlskey_start ( tlskey, &tlskey_hash, digest,
1180 &dummy_client_nonce ) == 0 );
1181
1182 /* ClientHello */
1184 sizeof ( dummy_clienthello ) );
1185
1186 /* ServerHello */
1188 sizeof ( dummy_serverhello ) );
1189
1190 /* Load resumption secret */
1192 sizeof ( dummy_hash_master_secret ) ) != 0 );
1193 ok ( tlskey_load ( tlskey, extended, psk ) == 0 );
1195 sizeof ( dummy_hash_master_secret ) ) == 0 );
1196
1197 /* Stop key schedule */
1198 tlskey_stop ( tlskey );
1199}
1200
1201/**
1202 * Perform dummy TLS version 1.0 test
1203 *
1204 * @v tlskey Key schedule
1205 * @v psk Pre-shared key
1206 */
1207static void dummy_md5_sha1 ( struct tls_key_schedule *tlskey,
1208 struct tls_preshared_key *psk ) {
1209 struct digest_algorithm *digest = &md5_sha1_algorithm;
1210 const struct md5_sha1_hmac_keys *hkeys;
1211 const int extended = 0;
1212 uint8_t verify[12];
1213 uint8_t key[16];
1214 uint8_t iv[4];
1215 uint8_t mac[32];
1216
1217 /* Start key schedule */
1218 ok ( tlskey_start ( tlskey, &tlskey_md5_sha1, digest,
1219 &dummy_client_nonce ) == 0 );
1220 hkeys = tlskey->kdf.secret;
1221
1222 /* ClientHello */
1224 sizeof ( dummy_clienthello ) );
1225
1226 /* ServerHello */
1228 sizeof ( dummy_serverhello ) );
1229
1230 /* Pre-master secret */
1231 ok ( tlskey_apply ( tlskey, dummy_premaster,
1232 sizeof ( dummy_premaster ) ) == 0 );
1233
1234 /* Master secret */
1235 ok ( tlskey_master ( tlskey, extended ) == 0 );
1237 sizeof ( dummy_md5_sha1_master_secret_md5 ) ) == 0 );
1239 sizeof ( dummy_md5_sha1_master_secret_sha1 ) ) == 0 );
1240
1241 /* Client verification */
1242 ok ( tlskey_verify ( tlskey, &tls_client, verify,
1243 sizeof ( verify ) ) == 0 );
1245 sizeof ( verify ) ) == 0 );
1246
1247 /* Server verification */
1248 ok ( tlskey_verify ( tlskey, &tls_server, verify,
1249 sizeof ( verify ) ) == 0 );
1251 sizeof ( verify ) ) == 0 );
1252
1253 /* Client traffic keys */
1254 ok ( tlskey_traffic ( tlskey, &tls_client, &tls_application ) == 0 );
1255 ok ( tlskey_cipher ( tlskey, &tls_client, key, sizeof ( key ),
1256 iv, sizeof ( iv ), mac, sizeof ( mac ) ) == 0 );
1258 key, sizeof ( key ) ) == 0 );
1260 iv, sizeof ( iv ) ) == 0 );
1262 mac, sizeof ( mac ) ) == 0 );
1263
1264 /* Server traffic keys */
1265 ok ( tlskey_traffic ( tlskey, &tls_server, &tls_application ) == 0 );
1266 ok ( tlskey_cipher ( tlskey, &tls_server, key, sizeof ( key ),
1267 iv, sizeof ( iv ), mac, sizeof ( mac ) ) == 0 );
1269 key, sizeof ( key ) ) == 0 );
1271 iv, sizeof ( iv ) ) == 0 );
1273 mac, sizeof ( mac ) ) == 0 );
1274
1275 /* Save resumption secret */
1276 ok ( tlskey_save ( tlskey, NULL, 0, psk ) == 0 );
1277
1278 /* Stop key schedule */
1279 tlskey_stop ( tlskey );
1280
1281 /* Start key schedule */
1282 ok ( tlskey_start ( tlskey, &tlskey_md5_sha1, digest,
1283 &dummy_client_nonce ) == 0 );
1284 hkeys = tlskey->kdf.secret;
1285
1286 /* ClientHello */
1288 sizeof ( dummy_clienthello ) );
1289
1290 /* ServerHello */
1292 sizeof ( dummy_serverhello ) );
1293
1294 /* Load resumption secret */
1296 sizeof ( dummy_md5_sha1_master_secret_md5 ) ) != 0 );
1298 sizeof ( dummy_md5_sha1_master_secret_sha1 ) ) != 0 );
1299 ok ( tlskey_load ( tlskey, extended, psk ) == 0 );
1301 sizeof ( dummy_md5_sha1_master_secret_md5 ) ) == 0 );
1303 sizeof ( dummy_md5_sha1_master_secret_sha1 ) ) == 0 );
1304
1305 /* Stop key schedule */
1306 tlskey_stop ( tlskey );
1307}
1308
1309/**
1310 * Perform TLS key schedule self-test
1311 *
1312 */
1313static void tlskey_test_exec ( void ) {
1314 struct tls_key_schedule tlskey;
1315 struct tls_preshared_key psk;
1316
1317 /* Initialise data structures */
1318 memset ( &tlskey, 0, sizeof ( tlskey ) );
1319 memset ( &psk, 0, sizeof ( psk ) );
1320
1321 /* RFC 8448 simple 1-RTT test */
1322 rfc8448_simple_test ( &tlskey, &psk );
1323
1324 /* RFC 8448 resumed 0-RTT test */
1325 rfc8448_resumed_test ( &tlskey, &psk );
1326
1327 /* Dummy TLS version 1.2 test */
1328 dummy_hash ( &tlskey, &psk );
1329
1330 /* Dummy TLS version 1.0 test */
1331 dummy_md5_sha1 ( &tlskey, &psk );
1332}
1333
1334/** TLS key schedule self-test */
1335struct self_test tlskey_test __self_test = {
1336 .name = "tlskey",
1337 .exec = tlskey_test_exec,
1338};
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
union @162305117151260234136356364136041353210355154177 key
unsigned char uint8_t
Definition stdint.h:10
signed char int8_t
Definition stdint.h:15
uint8_t mac[ETH_ALEN]
MAC address.
Definition ena.h:13
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
static int exchange_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
Definition crypto.h:403
String functions.
void * memset(void *dest, int character, size_t len) __nonnull
Dynamic memory allocation.
struct digest_algorithm md5_sha1_algorithm
Hybrid MD5+SHA1 digest algorithm.
Definition md5_sha1.c:84
Hybrid MD5+SHA1 hash as used by TLSv1.1 and earlier.
uint32_t digestsize
Digest size (i.e.
Definition pccrr.h:1
SHA-256 algorithm.
struct digest_algorithm sha256_algorithm
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
A message digest algorithm.
Definition crypto.h:19
size_t digestsize
Digest size.
Definition crypto.h:27
A key exchange algorithm.
Definition crypto.h:210
size_t sharedsize
Shared secret size.
Definition crypto.h:218
An MD5+SHA1 HMAC key block.
Definition md5_sha1.h:57
uint8_t md5[MD5_BLOCK_SIZE]
MD5 HMAC key.
Definition md5_sha1.h:59
uint8_t sha1[SHA1_BLOCK_SIZE]
SHA-1 HMAC key.
Definition md5_sha1.h:61
A self-test set.
Definition test.h:15
TLS client state.
Definition tls.h:421
void * secret
Secret.
Definition tlskey.h:77
A TLS key schedule.
Definition tlskey.h:100
struct tls_traffic_secret traffic[2]
Traffic secrets.
Definition tlskey.h:124
struct tls_kdf_secret kdf
Key derivation function secret.
Definition tlskey.h:122
A TLS pre-shared key.
Definition tlskey.h:128
uint8_t resumption[48]
Resumption secret.
Definition tlskey.h:165
union tls_preshared_key::@022173016027117201055347232316162256252261104170 key
Key material.
TLS client or server random bytes.
Definition tlskey.h:36
TLS server state.
Definition tls.h:431
void * secret
Secret.
Definition tlskey.h:94
Self-test infrastructure.
#define ok(success)
Definition test.h:46
#define __self_test
Declare a self-test.
Definition test.h:32
int tlskey_save(struct tls_key_schedule *tlskey, const void *nonce, size_t nonce_len, struct tls_preshared_key *psk)
Save pre-shared key.
Definition tlskey.c:785
int tlskey_master(struct tls_key_schedule *tlskey, int ems)
Generate master secret.
Definition tlskey.c:557
int tlskey_cipher(struct tls_key_schedule *tlskey, const struct tls_endpoint *writer, void *key, size_t key_len, void *iv, size_t iv_len, void *mac, size_t mac_len)
Generate cipher key material.
Definition tlskey.c:691
int tlskey_load(struct tls_key_schedule *tlskey, int ems, const struct tls_preshared_key *psk)
Load pre-shared key.
Definition tlskey.c:828
void tlskey_stop(struct tls_key_schedule *tlskey)
Stop key schedule.
Definition tlskey.c:259
const struct tls_phase tls_early
Early traffic phase.
Definition tlskey.c:137
const struct tls_phase tls_handshake
Handshake traffic phase.
Definition tlskey.c:144
int tlskey_start(struct tls_key_schedule *tlskey, const struct tls_key_schedule_operations *op, struct digest_algorithm *digest, const struct tls_random *nonce)
Start key schedule.
Definition tlskey.c:180
int tlskey_tbshash(struct tls_key_schedule *tlskey, const struct tls_endpoint *end, struct digest_algorithm *digest, const void *data, size_t len, void *tbs)
Generate signable digest value.
Definition tlskey.c:744
int tlskey_apply(struct tls_key_schedule *tlskey, const void *shared, size_t shared_len)
Apply a new shared secret.
Definition tlskey.c:522
const struct tls_key_schedule_operations tlskey_hash
TLS key schedule based on P_Hash().
Definition tlskey.c:1819
int tlskey_traffic(struct tls_key_schedule *tlskey, const struct tls_endpoint *writer, const struct tls_phase *phase)
Generate traffic secret.
Definition tlskey.c:639
const struct tls_key_schedule_operations tlskey_md5_sha1
TLS key schedule based on P_MD5()+P_SHA1().
Definition tlskey.c:1993
int tlskey_verify(struct tls_key_schedule *tlskey, const struct tls_endpoint *end, void *verify, size_t verify_len)
Generate verification data.
Definition tlskey.c:602
void tlskey_digest(struct tls_key_schedule *tlskey, const void *data, size_t len)
Add handshake to running transcript digest.
Definition tlskey.c:416
const struct tls_phase tls_application
Application traffic phase.
Definition tlskey.c:151
int tlskey_bind(const struct tls_preshared_key *psk, const void *prefix, size_t prefix_len, void *binder, size_t binder_len)
Generate pre-shared key binder value.
Definition tlskey.c:885
const struct tls_key_schedule_operations tlskey_hkdf
TLS key schedule based on HKDF.
Definition tlskey.c:1369
TLS key schedules.
#define TLS_CLIENT
Client endpoint index.
Definition tlskey.h:27
#define TLS_SERVER
Server endpoint index.
Definition tlskey.h:30
static const uint8_t rfc8448_simple_client_handshake_traffic_key[]
RFC 8448 simple 1-RTT test: client handshake traffic key.
static const uint8_t rfc8448_resumed_early_secret[]
RFC 8448 resumed 0-RTT test: early secret.
static const uint8_t rfc8448_resumed_endofearlydata[]
RFC 8448 resumed 0-RTT test: EndOfEarlyData.
static const uint8_t rfc8448_resumed_client_early_traffic_secret[]
RFC 8448 resumed 0-RTT test: client early traffic secret.
static const uint8_t rfc8448_simple_handshake_secret[]
RFC 8448 simple 1-RTT test: handshake secret.
static const uint8_t rfc8448_simple_client_application_traffic_key[]
RFC 8448 simple 1-RTT test: client application traffic key.
static const uint8_t rfc8448_simple_newsessionticket[]
RFC 8448 simple 1-RTT test: NewSessionTicket.
static const uint8_t rfc8448_resumed_handshake_secret[]
RFC 8448 resumed 0-RTT test: handshake secret.
static const uint8_t rfc8448_simple_encryptedextensions[]
RFC 8448 simple 1-RTT test: EncryptedExtensions.
static const uint8_t rfc8448_simple_server_handshake_traffic_iv[]
RFC 8448 simple 1-RTT test: server handshake traffic IV.
static const struct tls_random rfc8448_simple_client_nonce
RFC 8448 simple 1-RTT test: client random bytes.
Definition tlskey_test.c:54
static const uint8_t rfc8448_simple_x25519_private[]
RFC 8448 simple 1-RTT test: client X25519 private key.
Definition tlskey_test.c:64
static const uint8_t dummy_dh_param[]
Dummy minimal tests: ServerKeyExchange DH parameters.
static const uint8_t dummy_md5_sha1_master_secret_md5[]
Dummy minimal TLSv1.0 test: master secret (MD5 portion).
static const uint8_t dummy_md5_sha1_server_traffic_iv[]
Dummy minimal TLSv1.0 test: server traffic IV.
static const uint8_t rfc8448_simple_server_verify[]
RFC 8448 simple 1-RTT test: server verification.
static const uint8_t rfc8448_resumed_x25519_partner[]
RFC 8448 resumed 0-RTT test: server X25519 public key.
static const uint8_t dummy_hash_master_secret[]
Dummy minimal TLSv1.2 test: master secret.
static const uint8_t rfc8448_resumed_client_handshake_traffic_key[]
RFC 8448 resumed 0-RTT test: client handshake traffic key.
static const uint8_t dummy_serverhello[]
Dummy minimal tests: ServerHello.
static const struct tls_random dummy_client_nonce
Dummy minimal tests: client random bytes.
static const uint8_t rfc8448_simple_ticket_nonce[]
RFC 8448 simple 1-RTT test: ticket nonce.
Definition tlskey_test.c:78
static const uint8_t rfc8448_simple_client_verify[]
RFC 8448 simple 1-RTT test: client verification.
static const uint8_t dummy_hash_client_traffic_iv[]
Dummy minimal TLSv1.2 test: client traffic IV.
static void rfc8448_resumed_test(struct tls_key_schedule *tlskey, struct tls_preshared_key *psk)
Perform RFC 8448 resumed 0-RTT test.
static const uint8_t rfc8448_simple_client_application_traffic_secret[]
RFC 8448 simple 1-RTT test: client application traffic secret.
static const uint8_t rfc8448_resumed_client_application_traffic_iv[]
RFC 8448 resumed 0-RTT test: client application traffic IV.
static const uint8_t rfc8448_simple_client_application_traffic_iv[]
RFC 8448 simple 1-RTT test: client application traffic IV.
static const uint8_t dummy_hash_server_traffic_mac[]
Dummy minimal TLSv1.2 test: server traffic MAC.
static const uint8_t rfc8448_simple_serverhello[]
RFC 8448 simple 1-RTT test: ServerHello.
static const uint8_t rfc8448_simple_resumption[]
RFC 8448 simple 1-RTT test: resumption secret.
static const uint8_t rfc8448_simple_client_handshake_traffic_iv[]
RFC 8448 simple 1-RTT test: client handshake traffic IV.
static const uint8_t rfc8448_resumed_server_verify[]
RFC 8448 resumed 0-RTT test: server verification.
static const uint8_t rfc8448_resumed_server_application_traffic_key[]
RFC 8448 resumed 0-RTT test: server application traffic key.
static const uint8_t dummy_md5_sha1_master_secret_sha1[]
Dummy minimal TLSv1.0 test: master secret (SHA-1 portion).
static const uint8_t rfc8448_simple_early_secret[]
RFC 8448 simple 1-RTT test: early secret.
static const uint8_t rfc8448_resumed_client_early_traffic_iv[]
RFC 8448 resumed 0-RTT test: client early traffic IV.
static const uint8_t dummy_md5_sha1_client_traffic_mac[]
Dummy minimal TLSv1.0 test: client traffic MAC.
static const uint8_t dummy_hash_client_tbshash[]
Dummy minimal TLSv1.2 test: client signable digest.
static const uint8_t dummy_hash_client_verify[]
Dummy minimal TLSv1.2 test: client verification.
static const uint8_t dummy_md5_sha1_client_traffic_key[]
Dummy minimal TLSv1.0 test: client traffic key.
static const uint8_t rfc8448_simple_server_tbshash[]
RFC 8448 simple 1-RTT test: server CertificateVerify signable digest.
static const uint8_t rfc8448_resumed_server_application_traffic_iv[]
RFC 8448 resumed 0-RTT test: server application traffic IV.
static const uint8_t dummy_hash_server_tbshash[]
Dummy minimal TLSv1.2 test: server signable digest.
static const uint8_t rfc8448_simple_certificateverify[]
RFC 8448 simple 1-RTT test: CertificateVerify.
static const uint8_t rfc8448_resumed_server_handshake_traffic_key[]
RFC 8448 resumed 0-RTT test: server handshake traffic key.
static const uint8_t rfc8448_resumed_client_application_traffic_secret[]
RFC 8448 resumed 0-RTT test: client application traffic secret.
static const uint8_t dummy_hash_server_traffic_iv[]
Dummy minimal TLSv1.2 test: server traffic IV.
static const uint8_t rfc8448_simple_client_handshake_traffic_secret[]
RFC 8448 simple 1-RTT test: client handshake traffic secret.
static const uint8_t rfc8448_resumed_server_finished[]
RFC 8448 resumed 0-RTT test: server Finished.
static const uint8_t dummy_md5_sha1_server_traffic_key[]
Dummy minimal TLSv1.0 test: server traffic key.
static const uint8_t rfc8448_resumed_client_verify[]
RFC 8448 resumed 0-RTT test: client verification.
static void tlskey_test_exec(void)
Perform TLS key schedule self-test.
static const uint8_t rfc8448_simple_x25519_partner[]
RFC 8448 simple 1-RTT test: server X25519 public key.
Definition tlskey_test.c:71
static const uint8_t rfc8448_simple_clienthello[]
RFC 8448 simple 1-RTT test: ClientHello.
Definition tlskey_test.c:81
static const struct tls_random rfc8448_resumed_server_nonce
RFC 8448 resumed 0-RTT test: server random bytes.
static const uint8_t rfc8448_simple_master_secret[]
RFC 8448 simple 1-RTT test: master secret.
static const uint8_t rfc8448_resumed_client_early_traffic_key[]
RFC 8448 resumed 0-RTT test: client early traffic key.
static const uint8_t dummy_md5_sha1_server_traffic_mac[]
Dummy minimal TLSv1.0 test: server traffic MAC.
static void rfc8448_simple_test(struct tls_key_schedule *tlskey, struct tls_preshared_key *psk)
Perform RFC 8448 simple 1-RTT test.
static const uint8_t rfc8448_resumed_client_application_traffic_key[]
RFC 8448 resumed 0-RTT test: client application traffic key.
static const uint8_t rfc8448_simple_client_finished[]
RFC 8448 simple 1-RTT test: client Finished.
static const uint8_t rfc8448_simple_server_handshake_traffic_secret[]
RFC 8448 simple 1-RTT test: server handshake traffic secret.
static const uint8_t dummy_md5_sha1_server_verify[]
Dummy minimal TLSv1.0 test: server verification.
static const uint8_t dummy_md5_sha1_client_traffic_iv[]
Dummy minimal TLSv1.0 test: client traffic IV.
static const uint8_t dummy_md5_sha1_client_verify[]
Dummy minimal TLSv1.0 test: client verification.
static const uint8_t rfc8448_simple_server_application_traffic_iv[]
RFC 8448 simple 1-RTT test: server application traffic IV.
static const uint8_t rfc8448_simple_server_application_traffic_key[]
RFC 8448 simple 1-RTT test: server application traffic key.
static const uint8_t rfc8448_resumed_encryptedextensions[]
RFC 8448 resumed 0-RTT test: EncryptedExtensions.
static const uint8_t rfc8448_resumed_client_finished[]
RFC 8448 resumed 0-RTT test: client Finished.
static const uint8_t rfc8448_resumed_client_handshake_traffic_secret[]
RFC 8448 resumed 0-RTT test: client handshake traffic secret.
static const uint8_t rfc8448_simple_certificate[]
RFC 8448 simple 1-RTT test: Certificate.
static const uint8_t rfc8448_simple_server_handshake_traffic_key[]
RFC 8448 simple 1-RTT test: server handshake traffic key.
static const uint8_t rfc8448_resumed_master_secret[]
RFC 8448 resumed 0-RTT test: master secret.
static const uint8_t rfc8448_resumed_server_handshake_traffic_iv[]
RFC 8448 resumed 0-RTT test: server handshake traffic IV.
static void dummy_md5_sha1(struct tls_key_schedule *tlskey, struct tls_preshared_key *psk)
Perform dummy TLS version 1.0 test.
static const uint8_t dummy_clienthello[]
Dummy minimal tests: ClientHello.
static const uint8_t dummy_premaster[]
Dummy minimal tests: pre-master secret.
static void dummy_hash(struct tls_key_schedule *tlskey, struct tls_preshared_key *psk)
Perform dummy TLS version 1.2 test.
static const uint8_t dummy_hash_server_traffic_key[]
Dummy minimal TLSv1.2 test: server traffic key.
static const uint8_t rfc8448_resumed_serverhello[]
RFC 8448 resumed 0-RTT test: ServerHello.
static const uint8_t rfc8448_simple_server_finished[]
RFC 8448 simple 1-RTT test: server Finished.
static const uint8_t rfc8448_resumed_psk_binder[]
RFC 8448 resumed 0-RTT test: PSK binder.
static const uint8_t dummy_hash_client_traffic_mac[]
Dummy minimal TLSv1.2 test: client traffic MAC.
static const uint8_t rfc8448_simple_server_application_traffic_secret[]
RFC 8448 simple 1-RTT test: server application traffic secret.
static const uint8_t rfc8448_resumed_client_handshake_traffic_iv[]
RFC 8448 resumed 0-RTT test: client handshake traffic IV.
static const size_t rfc8448_resumed_clienthello_prefix_len
RFC 8448 resumed 0-RTT test: ClientHello prefix length.
static const uint8_t dummy_hash_server_verify[]
Dummy minimal TLSv1.2 test: server verification.
static const uint8_t dummy_hash_client_traffic_key[]
Dummy minimal TLSv1.2 test: client traffic key.
static const uint8_t rfc8448_resumed_server_handshake_traffic_secret[]
RFC 8448 resumed 0-RTT test: server handshake traffic secret.
static const uint8_t rfc8448_resumed_clienthello[]
RFC 8448 resumed 0-RTT test: ClientHello.
static const uint8_t rfc8448_resumed_server_application_traffic_secret[]
RFC 8448 resumed 0-RTT test: server application traffic secret.
static const uint8_t rfc8448_resumed_x25519_private[]
RFC 8448 resumed 0-RTT test: client X25519 private key.
u8 iv[16]
Initialization vector.
Definition wpa.h:33
struct exchange_algorithm x25519_algorithm
X25519 key exchange algorithm.
Definition x25519.c:875
X25519 key exchange.