iPXE
hkdf_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 * HKDF self-tests
29 *
30 * These test vectors are taken from RFC 5869 Appendix A.
31 */
32
33/* Forcibly enable assertions */
34#undef NDEBUG
35
36#include <string.h>
37#include <ipxe/crypto.h>
38#include <ipxe/sha1.h>
39#include <ipxe/sha256.h>
40#include <ipxe/hkdf.h>
41#include <ipxe/test.h>
42
43/** Define inline input keying material */
44#define IKM(...) { __VA_ARGS__ }
45
46/** Define inline salt */
47#define SALT(...) { __VA_ARGS__ }
48
49/** Define inline additional information */
50#define INFO(...) { __VA_ARGS__ }
51
52/** Define inline expected pseudorandom key */
53#define PRK(...) { __VA_ARGS__ }
54
55/** Define inline expected output keying material */
56#define OKM(...) { __VA_ARGS__ }
57
58/** An HKDF self-test */
59struct hkdf_test {
60 /** Digest algorithm */
62 /** Input keying material */
63 const void *ikm;
64 /** Length of input keying material */
65 size_t ikm_len;
66 /** Salt */
67 const void *salt;
68 /** Length of salt */
69 size_t salt_len;
70 /** Additional information */
71 const void *info;
72 /** Length of additional information */
73 size_t info_len;
74 /** Expected pseudorandom key */
75 const void *prk;
76 /** Length of expected pseudorandom key */
77 size_t prk_len;
78 /** Expected output keying material */
79 const void *okm;
80 /** Length of expected output keying material */
81 size_t okm_len;
82};
83
84/**
85 * Define an HKDF test
86 *
87 * @v name Test name
88 * @v DIGEST Digest algorithm
89 * @v SALTED Use salt value
90 * @v IKM Input keying material
91 * @v SALT Salt
92 * @v INFO Additional information
93 * @v PRK Expected pseudorandom key
94 * @v OKM Expected output keying material
95 */
96#define HKDF_TEST( name, DIGEST, SALTED, IKM, SALT, INFO, PRK, OKM ) \
97 static const uint8_t name ## _ikm[] = IKM; \
98 static const uint8_t name ## _salt[] = SALT; \
99 static const uint8_t name ## _info[] = INFO; \
100 static const uint8_t name ## _prk[] = PRK; \
101 static const uint8_t name ## _okm[] = OKM; \
102 static struct hkdf_test name = { \
103 .digest = DIGEST, \
104 .ikm = name ## _ikm, \
105 .ikm_len = sizeof ( name ## _ikm ), \
106 .salt = ( SALTED ? name ## _salt : NULL ), \
107 .salt_len = sizeof ( name ## _salt ), \
108 .info = name ## _info, \
109 .info_len = sizeof ( name ## _info ), \
110 .prk = name ## _prk, \
111 .prk_len = sizeof ( name ## _prk ), \
112 .okm = name ## _okm, \
113 .okm_len = sizeof ( name ## _okm ), \
114 }
115
116/**
117 * Report an HKDF test result
118 *
119 * @v test HKDF test
120 * @v file Test code file
121 * @v line Test code line
122 */
123static void hkdf_okx ( struct hkdf_test *test, const char *file,
124 unsigned int line ) {
125 size_t digestsize = test->digest->digestsize;
126 union {
127 uint8_t ikm[test->ikm_len];
128 uint8_t salt[test->salt_len];
129 uint8_t info[test->info_len];
130 uint8_t prk[test->prk_len];
131 uint8_t okm[test->okm_len];
132 } overlap;
133 uint8_t prk[digestsize];
134 uint8_t okm[test->okm_len];
135 size_t check_len;
136
137 /* Sanity checks */
138 okx ( ( test->salt != NULL ) || ( test->salt_len == 0 ), file, line );
139 okx ( test->prk_len == digestsize, file, line );
140
141 /* Test extraction */
142 hkdf_extract ( test->digest, test->salt, test->salt_len, test->ikm,
143 test->ikm_len, prk );
144 okx ( memcmp ( prk, test->prk, digestsize ) == 0, file, line );
145
146 /* Test expansion */
147 hkdf_expand ( test->digest, test->prk, test->info, test->info_len,
148 okm, test->okm_len );
149 okx ( memcmp ( okm, test->okm, test->okm_len ) == 0, file, line );
150
151 /* Test overlap between salt and pseudorandom key */
152 if ( test->salt ) {
153 memcpy ( overlap.salt, test->salt, test->salt_len );
154 hkdf_extract ( test->digest, overlap.salt, test->salt_len,
155 test->ikm, test->ikm_len, overlap.prk );
156 okx ( memcmp ( overlap.prk, test->prk, digestsize ) == 0,
157 file, line );
158 }
159
160 /* Test overlap between input keying material and pseudorandom key */
161 memcpy ( overlap.ikm, test->ikm, test->ikm_len );
162 hkdf_extract ( test->digest, test->salt, test->salt_len, overlap.ikm,
163 test->ikm_len, overlap.prk );
164 okx ( memcmp ( overlap.prk, test->prk, digestsize ) == 0,
165 file, line );
166
167 /* Calculate length for expansion overlap tests */
168 check_len = test->okm_len;
169 if ( check_len > digestsize )
170 check_len = digestsize;
171
172 /* Test overlap between pseudorandom key and output */
173 memcpy ( overlap.prk, test->prk, test->prk_len );
174 hkdf_expand ( test->digest, overlap.prk, test->info, test->info_len,
175 overlap.okm, test->okm_len );
176 okx ( memcmp ( overlap.okm, test->okm, check_len ) == 0, file, line );
177
178 /* Test overlap between additional information and output */
179 memcpy ( overlap.info, test->info, test->info_len );
180 hkdf_expand ( test->digest, test->prk, overlap.info, test->info_len,
181 overlap.okm, test->okm_len );
182 okx ( memcmp ( overlap.okm, test->okm, check_len ) == 0, file, line );
183}
184#define hkdf_ok( test ) hkdf_okx ( test, __FILE__, __LINE__ )
185
186/** RFC 5869 test case 1: Basic test case with SHA-256 */
187HKDF_TEST ( hkdf_test_1, &sha256_algorithm, 1,
188 IKM ( 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
189 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
190 0x0b, 0x0b ),
191 SALT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
192 0x0a, 0x0b, 0x0c ),
193 INFO ( 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 ),
194 PRK ( 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, 0x0d, 0xdc,
195 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x3b,
196 0xb5, 0x0f, 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2,
197 0xb3, 0xe5 ),
198 OKM ( 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43,
199 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90,
200 0xcf, 0x1a, 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4,
201 0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
202 0x58, 0x65 ) );
203
204/** RFC 5869 test case 2: Test with SHA-256 and longer inputs/outputs */
205HKDF_TEST ( hkdf_test_2, &sha256_algorithm, 1,
206 IKM ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
207 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
208 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
209 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
210 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
211 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
212 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
213 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f ),
214 SALT ( 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
215 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
216 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d,
217 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
218 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91,
219 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
220 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
221 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf ),
222 INFO ( 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
223 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,
224 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd,
225 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
226 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1,
227 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
228 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
229 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff ),
230 PRK ( 0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a, 0x06, 0x10,
231 0x4c, 0x9c, 0xeb, 0x35, 0xb4, 0x5c, 0xef, 0x76, 0x00, 0x14,
232 0x90, 0x46, 0x71, 0x01, 0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f,
233 0xc2, 0x44 ),
234 OKM ( 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7,
235 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda,
236 0x2d, 0x4e, 0xfa, 0xd8, 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf,
237 0xa9, 0x7c, 0x59, 0x04, 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72,
238 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 0x0e, 0x09, 0xda, 0x32,
239 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77, 0x93, 0xa9,
240 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec,
241 0x3e, 0x87, 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f,
242 0x1d, 0x87 ) );
243
244/** RFC 5869 test case 3: Test with SHA-256 and zero-length salt/info */
245HKDF_TEST ( hkdf_test_3, &sha256_algorithm, 1,
246 IKM ( 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
247 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
248 0x0b, 0x0b ),
249 SALT(), INFO(),
250 PRK ( 0x19, 0xef, 0x24, 0xa3, 0x2c, 0x71, 0x7b, 0x16, 0x7f, 0x33,
251 0xa9, 0x1d, 0x6f, 0x64, 0x8b, 0xdf, 0x96, 0x59, 0x67, 0x76,
252 0xaf, 0xdb, 0x63, 0x77, 0xac, 0x43, 0x4c, 0x1c, 0x29, 0x3c,
253 0xcb, 0x04 ),
254 OKM ( 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f,
255 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c,
256 0x5e, 0xe1, 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73,
257 0x8d, 0x2d, 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
258 0x96, 0xc8 ) );
259
260/** RFC 5869 test case 4: Basic test case with SHA-1 */
261HKDF_TEST ( hkdf_test_4, &sha1_algorithm, 1,
262 IKM ( 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
263 0x0b ),
264 SALT ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
265 0x0a, 0x0b, 0x0c ),
266 INFO ( 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 ),
267 PRK ( 0x9b, 0x6c, 0x18, 0xc4, 0x32, 0xa7, 0xbf, 0x8f, 0x0e, 0x71,
268 0xc8, 0xeb, 0x88, 0xf4, 0xb3, 0x0b, 0xaa, 0x2b, 0xa2, 0x43 ),
269 OKM ( 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06,
270 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82,
271 0x2f, 0x5b, 0x09, 0x15, 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55,
272 0xfd, 0xa2, 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
273 0xf8, 0x96 ) );
274
275/** RFC 5869 test case 5: Test with SHA-1 and longer inputs/outputs */
276HKDF_TEST ( hkdf_test_5, &sha1_algorithm, 1,
277 IKM ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
278 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
279 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
280 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
281 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
282 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
283 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
284 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f ),
285 SALT ( 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
286 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
287 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d,
288 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
289 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91,
290 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
291 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
292 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf ),
293 INFO ( 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
294 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,
295 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd,
296 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
297 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1,
298 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
299 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
300 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff ),
301 PRK ( 0x8a, 0xda, 0xe0, 0x9a, 0x2a, 0x30, 0x70, 0x59, 0x47, 0x8d,
302 0x30, 0x9b, 0x26, 0xc4, 0x11, 0x5a, 0x22, 0x4c, 0xfa, 0xf6 ),
303 OKM ( 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1,
304 0x2c, 0xd5, 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae,
305 0x89, 0x9d, 0x92, 0x19, 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba,
306 0x2f, 0xfe, 0x8f, 0xa3, 0xf1, 0xa4, 0xe5, 0xad, 0x79, 0xf3,
307 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, 0x17, 0x3c, 0x48, 0x6e,
308 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c, 0x7f, 0x9d,
309 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f,
310 0x4c, 0x43, 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52,
311 0xd3, 0xb4 ) );
312
313/** RFC 5869 test case 6: Test with SHA-1 and zero-length salt/info */
314HKDF_TEST ( hkdf_test_6, &sha1_algorithm, 1,
315 IKM ( 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
316 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
317 0x0b, 0x0b ),
318 SALT(), INFO(),
319 PRK ( 0xda, 0x8c, 0x8a, 0x73, 0xc7, 0xfa, 0x77, 0x28, 0x8e, 0xc6,
320 0xf5, 0xe7, 0xc2, 0x97, 0x78, 0x6a, 0xa0, 0xd3, 0x2d, 0x01 ),
321 OKM ( 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5,
322 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05,
323 0x72, 0x20, 0xa3, 0x06, 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf,
324 0x21, 0xd0, 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
325 0x49, 0x18 ) );
326
327/** RFC 5869 test case 7: Test with SHA-1, salt not provided */
328HKDF_TEST ( hkdf_test_7, &sha1_algorithm, 0,
329 IKM ( 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
330 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
331 0x0c, 0x0c ),
332 SALT(), INFO(),
333 PRK ( 0x2a, 0xdc, 0xca, 0xda, 0x18, 0x77, 0x9e, 0x7c, 0x20, 0x77,
334 0xad, 0x2e, 0xb1, 0x9d, 0x3f, 0x3e, 0x73, 0x13, 0x85, 0xdd ),
335 OKM ( 0x2c, 0x91, 0x11, 0x72, 0x04, 0xd7, 0x45, 0xf3, 0x50, 0x0d,
336 0x63, 0x6a, 0x62, 0xf6, 0x4f, 0x0a, 0xb3, 0xba, 0xe5, 0x48,
337 0xaa, 0x53, 0xd4, 0x23, 0xb0, 0xd1, 0xf2, 0x7e, 0xbb, 0xa6,
338 0xf5, 0xe5, 0x67, 0x3a, 0x08, 0x1d, 0x70, 0xcc, 0xe7, 0xac,
339 0xfc, 0x48 ) );
340
341/**
342 * Perform HKDF self-tests
343 *
344 */
345static void hkdf_test_exec ( void ) {
346
347 hkdf_ok ( &hkdf_test_1 );
348 hkdf_ok ( &hkdf_test_2 );
349 hkdf_ok ( &hkdf_test_3 );
350 hkdf_ok ( &hkdf_test_4 );
351 hkdf_ok ( &hkdf_test_5 );
352 hkdf_ok ( &hkdf_test_6 );
353 hkdf_ok ( &hkdf_test_7 );
354}
355
356/** HKDF self-test */
358 .name = "hkdf",
359 .exec = hkdf_test_exec,
360};
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
u32 info
Definition ar9003_mac.h:0
unsigned char uint8_t
Definition stdint.h:10
static int test
Definition epic100.c:73
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
void hkdf_expand(struct digest_algorithm *digest, const void *prk, const void *info, size_t info_len, void *out, size_t len)
Expand pseudorandom key.
Definition hkdf.c:95
void hkdf_extract(struct digest_algorithm *digest, const void *salt, size_t salt_len, const void *ikm, size_t ikm_len, void *prk)
Extract fixed-length pseudorandom key.
Definition hkdf.c:56
HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
#define OKM(...)
Define inline expected output keying material.
Definition hkdf_test.c:56
#define HKDF_TEST(name, DIGEST, SALTED, IKM, SALT, INFO, PRK, OKM)
Define an HKDF test.
Definition hkdf_test.c:96
#define PRK(...)
Define inline expected pseudorandom key.
Definition hkdf_test.c:53
#define hkdf_ok(test)
Definition hkdf_test.c:184
#define IKM(...)
Define inline input keying material.
Definition hkdf_test.c:44
static void hkdf_test_exec(void)
Perform HKDF self-tests.
Definition hkdf_test.c:345
#define SALT(...)
Define inline salt.
Definition hkdf_test.c:47
#define INFO(...)
Define inline additional information.
Definition hkdf_test.c:50
static void hkdf_okx(struct hkdf_test *test, const char *file, unsigned int line)
Report an HKDF test result.
Definition hkdf_test.c:123
Cryptographic API.
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t digestsize
Digest size (i.e.
Definition pccrr.h:1
SHA-1 algorithm.
struct digest_algorithm sha1_algorithm
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
An HKDF self-test.
Definition hkdf_test.c:59
size_t info_len
Length of additional information.
Definition hkdf_test.c:73
const void * okm
Expected output keying material.
Definition hkdf_test.c:79
const void * info
Additional information.
Definition hkdf_test.c:71
struct digest_algorithm * digest
Digest algorithm.
Definition hkdf_test.c:61
size_t salt_len
Length of salt.
Definition hkdf_test.c:69
const void * salt
Salt.
Definition hkdf_test.c:67
size_t ikm_len
Length of input keying material.
Definition hkdf_test.c:65
const void * prk
Expected pseudorandom key.
Definition hkdf_test.c:75
size_t prk_len
Length of expected pseudorandom key.
Definition hkdf_test.c:77
const void * ikm
Input keying material.
Definition hkdf_test.c:63
size_t okm_len
Length of expected output keying material.
Definition hkdf_test.c:81
A self-test set.
Definition test.h:15
Self-test infrastructure.
#define okx(success, file, line)
Report test result.
Definition test.h:44
#define __self_test
Declare a self-test.
Definition test.h:32