FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
rfc4231.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /* Test vectors published in RFC4231 */
17 
18 #include <vppinfra/clib.h>
19 #include <vnet/crypto/crypto.h>
20 #include <unittest/crypto/crypto.h>
21 
22 static u8 tc1_key[] = {
23  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
24  0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
25  0x0b, 0x0b, 0x0b, 0x0b
26 };
27 
28 static char tc1_data[8] = "Hi There";
29 
30 static u8 tc1_digest_sha224[] = {
31  0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
32  0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
33  0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
34  0x53, 0x68, 0x4b, 0x22
35 };
36 
37 static u8 tc1_digest_sha256[] = {
38  0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
39  0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
40  0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
41  0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7,
42 };
43 
44 static u8 tc1_digest_sha384[] = {
45  0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
46  0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
47  0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
48  0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
49  0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
50  0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
51 };
52 
53 static u8 tc1_digest_sha512[] = {
54  0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
55  0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
56  0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
57  0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
58  0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
59  0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
60  0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
61  0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
62 };
63 
64 /* *INDENT-OFF* */
65 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha224) = {
66  .name = "RFC4231 TC1",
67  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
68  .key = TEST_DATA (tc1_key),
69  .plaintext = TEST_DATA (tc1_data),
70  .digest = TEST_DATA (tc1_digest_sha224),
71 };
72 
73 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha256) = {
74  .name = "RFC4231 TC1",
75  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
76  .key = TEST_DATA (tc1_key),
77  .plaintext = TEST_DATA (tc1_data),
78  .digest = TEST_DATA (tc1_digest_sha256),
79 };
80 
81 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha384) = {
82  .name = "RFC4231 TC1",
83  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
84  .key = TEST_DATA (tc1_key),
85  .plaintext = TEST_DATA (tc1_data),
86  .digest = TEST_DATA (tc1_digest_sha384),
87 };
88 
89 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc1_sha512) = {
90  .name = "RFC4231 TC1",
91  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
92  .key = TEST_DATA (tc1_key),
93  .plaintext = TEST_DATA (tc1_data),
94  .digest = TEST_DATA (tc1_digest_sha512),
95 };
96 /* *INDENT-ON* */
97 
98 static char tc2_key[4] = "Jefe";
99 
100 static char tc2_data[28] = "what do ya want for nothing?";
101 
102 static u8 tc2_digest_sha224[] = {
103  0xa3, 0x0e, 0x01, 0x09, 0x8b, 0xc6, 0xdb, 0xbf,
104  0x45, 0x69, 0x0f, 0x3a, 0x7e, 0x9e, 0x6d, 0x0f,
105  0x8b, 0xbe, 0xa2, 0xa3, 0x9e, 0x61, 0x48, 0x00,
106  0x8f, 0xd0, 0x5e, 0x44
107 };
108 
109 static u8 tc2_digest_sha256[] = {
110  0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
111  0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
112  0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
113  0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43,
114 };
115 
116 static u8 tc2_digest_sha384[] = {
117  0xaf, 0x45, 0xd2, 0xe3, 0x76, 0x48, 0x40, 0x31,
118  0x61, 0x7f, 0x78, 0xd2, 0xb5, 0x8a, 0x6b, 0x1b,
119  0x9c, 0x7e, 0xf4, 0x64, 0xf5, 0xa0, 0x1b, 0x47,
120  0xe4, 0x2e, 0xc3, 0x73, 0x63, 0x22, 0x44, 0x5e,
121  0x8e, 0x22, 0x40, 0xca, 0x5e, 0x69, 0xe2, 0xc7,
122  0x8b, 0x32, 0x39, 0xec, 0xfa, 0xb2, 0x16, 0x49,
123 };
124 
125 static u8 tc2_digest_sha512[] = {
126  0x16, 0x4b, 0x7a, 0x7b, 0xfc, 0xf8, 0x19, 0xe2,
127  0xe3, 0x95, 0xfb, 0xe7, 0x3b, 0x56, 0xe0, 0xa3,
128  0x87, 0xbd, 0x64, 0x22, 0x2e, 0x83, 0x1f, 0xd6,
129  0x10, 0x27, 0x0c, 0xd7, 0xea, 0x25, 0x05, 0x54,
130  0x97, 0x58, 0xbf, 0x75, 0xc0, 0x5a, 0x99, 0x4a,
131  0x6d, 0x03, 0x4f, 0x65, 0xf8, 0xf0, 0xe6, 0xfd,
132  0xca, 0xea, 0xb1, 0xa3, 0x4d, 0x4a, 0x6b, 0x4b,
133  0x63, 0x6e, 0x07, 0x0a, 0x38, 0xbc, 0xe7, 0x37,
134 };
135 
136 /* *INDENT-OFF* */
137 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha224) = {
138  .name = "RFC4231 TC2",
139  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
140  .key = TEST_DATA (tc2_key),
141  .plaintext = TEST_DATA (tc2_data),
142  .digest = TEST_DATA (tc2_digest_sha224),
143 };
144 
145 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha256) = {
146  .name = "RFC4231 TC2",
147  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
148  .key = TEST_DATA (tc2_key),
149  .plaintext = TEST_DATA (tc2_data),
150  .digest = TEST_DATA (tc2_digest_sha256),
151 };
152 
153 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha384) = {
154  .name = "RFC4231 TC2",
155  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
156  .key = TEST_DATA (tc2_key),
157  .plaintext = TEST_DATA (tc2_data),
158  .digest = TEST_DATA (tc2_digest_sha384),
159 };
160 
161 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc2_sha512) = {
162  .name = "RFC4231 TC2",
163  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
164  .key = TEST_DATA (tc2_key),
165  .plaintext = TEST_DATA (tc2_data),
166  .digest = TEST_DATA (tc2_digest_sha512),
167 };
168 /* *INDENT-ON* */
169 
170 static u8 tc3_key[20] = {
171  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
172  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
173  0xaa, 0xaa, 0xaa, 0xaa
174 };
175 
176 static u8 tc3_data[50] = {
177  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
178  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
179  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
180  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
181  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
182  0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
183  0xdd, 0xdd,
184 };
185 
186 static u8 tc3_digest_sha224[] = {
187  0x7f, 0xb3, 0xcb, 0x35, 0x88, 0xc6, 0xc1, 0xf6,
188  0xff, 0xa9, 0x69, 0x4d, 0x7d, 0x6a, 0xd2, 0x64,
189  0x93, 0x65, 0xb0, 0xc1, 0xf6, 0x5d, 0x69, 0xd1,
190  0xec, 0x83, 0x33, 0xea
191 };
192 
193 static u8 tc3_digest_sha256[] = {
194  0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46,
195  0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7,
196  0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
197  0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5, 0x65, 0xfe
198 };
199 
200 static u8 tc3_digest_sha384[] = {
201  0x88, 0x06, 0x26, 0x08, 0xd3, 0xe6, 0xad, 0x8a,
202  0x0a, 0xa2, 0xac, 0xe0, 0x14, 0xc8, 0xa8, 0x6f,
203  0x0a, 0xa6, 0x35, 0xd9, 0x47, 0xac, 0x9f, 0xeb,
204  0xe8, 0x3e, 0xf4, 0xe5, 0x59, 0x66, 0x14, 0x4b,
205  0x2a, 0x5a, 0xb3, 0x9d, 0xc1, 0x38, 0x14, 0xb9,
206  0x4e, 0x3a, 0xb6, 0xe1, 0x01, 0xa3, 0x4f, 0x27
207 };
208 
209 static u8 tc3_digest_sha512[] = {
210  0xfa, 0x73, 0xb0, 0x08, 0x9d, 0x56, 0xa2, 0x84,
211  0xef, 0xb0, 0xf0, 0x75, 0x6c, 0x89, 0x0b, 0xe9,
212  0xb1, 0xb5, 0xdb, 0xdd, 0x8e, 0xe8, 0x1a, 0x36,
213  0x55, 0xf8, 0x3e, 0x33, 0xb2, 0x27, 0x9d, 0x39,
214  0xbf, 0x3e, 0x84, 0x82, 0x79, 0xa7, 0x22, 0xc8,
215  0x06, 0xb4, 0x85, 0xa4, 0x7e, 0x67, 0xc8, 0x07,
216  0xb9, 0x46, 0xa3, 0x37, 0xbe, 0xe8, 0x94, 0x26,
217  0x74, 0x27, 0x88, 0x59, 0xe1, 0x32, 0x92, 0xfb
218 };
219 
220 /* *INDENT-OFF* */
221 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha224) = {
222  .name = "RFC4231 TC3",
223  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
224  .key = TEST_DATA (tc3_key),
225  .plaintext = TEST_DATA (tc3_data),
226  .digest = TEST_DATA (tc3_digest_sha224),
227 };
228 
229 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha256) = {
230  .name = "RFC4231 TC3",
231  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
232  .key = TEST_DATA (tc3_key),
233  .plaintext = TEST_DATA (tc3_data),
234  .digest = TEST_DATA (tc3_digest_sha256),
235 };
236 
237 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha384) = {
238  .name = "RFC4231 TC3",
239  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
240  .key = TEST_DATA (tc3_key),
241  .plaintext = TEST_DATA (tc3_data),
242  .digest = TEST_DATA (tc3_digest_sha384),
243 };
244 
245 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc3_sha512) = {
246  .name = "RFC4231 TC3",
247  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
248  .key = TEST_DATA (tc3_key),
249  .plaintext = TEST_DATA (tc3_data),
250  .digest = TEST_DATA (tc3_digest_sha512),
251 };
252 /* *INDENT-ON* */
253 
254 static u8 tc4_key[25] = {
255  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
256  0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
257  0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
258  0x19
259 };
260 
261 static u8 tc4_data[50] = {
262  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
263  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
264  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
265  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
266  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
267  0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
268  0xcd, 0xcd
269 };
270 
271 static u8 tc4_digest_sha224[] = {
272  0x6c, 0x11, 0x50, 0x68, 0x74, 0x01, 0x3c, 0xac,
273  0x6a, 0x2a, 0xbc, 0x1b, 0xb3, 0x82, 0x62, 0x7c,
274  0xec, 0x6a, 0x90, 0xd8, 0x6e, 0xfc, 0x01, 0x2d,
275  0xe7, 0xaf, 0xec, 0x5a
276 };
277 
278 static u8 tc4_digest_sha256[] = {
279  0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e,
280  0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a,
281  0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
282  0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29, 0x66, 0x5b
283 };
284 
285 static u8 tc4_digest_sha384[] = {
286  0x3e, 0x8a, 0x69, 0xb7, 0x78, 0x3c, 0x25, 0x85,
287  0x19, 0x33, 0xab, 0x62, 0x90, 0xaf, 0x6c, 0xa7,
288  0x7a, 0x99, 0x81, 0x48, 0x08, 0x50, 0x00, 0x9c,
289  0xc5, 0x57, 0x7c, 0x6e, 0x1f, 0x57, 0x3b, 0x4e,
290  0x68, 0x01, 0xdd, 0x23, 0xc4, 0xa7, 0xd6, 0x79,
291  0xcc, 0xf8, 0xa3, 0x86, 0xc6, 0x74, 0xcf, 0xfb
292 };
293 
294 static u8 tc4_digest_sha512[] = {
295  0xb0, 0xba, 0x46, 0x56, 0x37, 0x45, 0x8c, 0x69,
296  0x90, 0xe5, 0xa8, 0xc5, 0xf6, 0x1d, 0x4a, 0xf7,
297  0xe5, 0x76, 0xd9, 0x7f, 0xf9, 0x4b, 0x87, 0x2d,
298  0xe7, 0x6f, 0x80, 0x50, 0x36, 0x1e, 0xe3, 0xdb,
299  0xa9, 0x1c, 0xa5, 0xc1, 0x1a, 0xa2, 0x5e, 0xb4,
300  0xd6, 0x79, 0x27, 0x5c, 0xc5, 0x78, 0x80, 0x63,
301  0xa5, 0xf1, 0x97, 0x41, 0x12, 0x0c, 0x4f, 0x2d,
302  0xe2, 0xad, 0xeb, 0xeb, 0x10, 0xa2, 0x98, 0xdd
303 };
304 
305 /* *INDENT-OFF* */
306 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha224) = {
307  .name = "RFC4231 TC4",
308  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
309  .key = TEST_DATA (tc4_key),
310  .plaintext = TEST_DATA (tc4_data),
311  .digest = TEST_DATA (tc4_digest_sha224),
312 };
313 
314 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha256) = {
315  .name = "RFC4231 TC4",
316  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
317  .key = TEST_DATA (tc4_key),
318  .plaintext = TEST_DATA (tc4_data),
319  .digest = TEST_DATA (tc4_digest_sha256),
320 };
321 
322 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha384) = {
323  .name = "RFC4231 TC4",
324  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
325  .key = TEST_DATA (tc4_key),
326  .plaintext = TEST_DATA (tc4_data),
327  .digest = TEST_DATA (tc4_digest_sha384),
328 };
329 
330 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc4_sha512) = {
331  .name = "RFC4231 TC4",
332  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
333  .key = TEST_DATA (tc4_key),
334  .plaintext = TEST_DATA (tc4_data),
335  .digest = TEST_DATA (tc4_digest_sha512),
336 };
337 /* *INDENT-ON* */
338 
339 static u8 tc5_key[20] = {
340  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
341  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
342  0x0c, 0x0c, 0x0c, 0x0c
343 };
344 
345 static u8 tc5_data[] = {
346  0x54, 0x65, 0x73, 0x74, 0x20, 0x57, 0x69, 0x74,
347  0x68, 0x20, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61,
348  0x74, 0x69, 0x6f, 0x6e
349 };
350 
351 static u8 tc5_digest_sha224[16] = {
352  0x0e, 0x2a, 0xea, 0x68, 0xa9, 0x0c, 0x8d, 0x37,
353  0xc9, 0x88, 0xbc, 0xdb, 0x9f, 0xca, 0x6f, 0xa8
354 };
355 
356 static u8 tc5_digest_sha256[16] = {
357  0xa3, 0xb6, 0x16, 0x74, 0x73, 0x10, 0x0e, 0xe0,
358  0x6e, 0x0c, 0x79, 0x6c, 0x29, 0x55, 0x55, 0x2b
359 };
360 
361 static u8 tc5_digest_sha384[16] = {
362  0x3a, 0xbf, 0x34, 0xc3, 0x50, 0x3b, 0x2a, 0x23,
363  0xa4, 0x6e, 0xfc, 0x61, 0x9b, 0xae, 0xf8, 0x97
364 };
365 
366 static u8 tc5_digest_sha512[16] = {
367  0x41, 0x5f, 0xad, 0x62, 0x71, 0x58, 0x0a, 0x53,
368  0x1d, 0x41, 0x79, 0xbc, 0x89, 0x1d, 0x87, 0xa6
369 };
370 
371 /* *INDENT-OFF* */
372 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha224) = {
373  .name = "RFC4231 TC5",
374  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
375  .key = TEST_DATA (tc5_key),
376  .plaintext = TEST_DATA (tc5_data),
377  .digest = TEST_DATA (tc5_digest_sha224),
378 };
379 
380 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha256) = {
381  .name = "RFC4231 TC5",
382  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
383  .key = TEST_DATA (tc5_key),
384  .plaintext = TEST_DATA (tc5_data),
385  .digest = TEST_DATA (tc5_digest_sha256),
386 };
387 
388 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha384) = {
389  .name = "RFC4231 TC5",
390  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
391  .key = TEST_DATA (tc5_key),
392  .plaintext = TEST_DATA (tc5_data),
393  .digest = TEST_DATA (tc5_digest_sha384),
394 };
395 
396 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc5_sha512) = {
397  .name = "RFC4231 TC5",
398  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
399  .key = TEST_DATA (tc5_key),
400  .plaintext = TEST_DATA (tc5_data),
401  .digest = TEST_DATA (tc5_digest_sha512),
402 };
403 /* *INDENT-ON* */
404 
405 static u8 tc6_key[131] = {
406  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
407  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
408  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
409  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
410  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
411  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
412  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
413  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
414  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
415  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
416  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
417  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
418  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
419  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
420  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
421  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
422  0xaa, 0xaa, 0xaa
423 };
424 
425 static char tc6_data[54] =
426  "Test Using Larger Than Block-Size Key - Hash Key First";
427 
428 static u8 tc6_digest_sha224[] = {
429  0x95, 0xe9, 0xa0, 0xdb, 0x96, 0x20, 0x95, 0xad,
430  0xae, 0xbe, 0x9b, 0x2d, 0x6f, 0x0d, 0xbc, 0xe2,
431  0xd4, 0x99, 0xf1, 0x12, 0xf2, 0xd2, 0xb7, 0x27,
432  0x3f, 0xa6, 0x87, 0x0e
433 };
434 
435 static u8 tc6_digest_sha256[] = {
436  0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f,
437  0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f,
438  0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
439  0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3, 0x7f, 0x54
440 };
441 
442 static u8 tc6_digest_sha384[] = {
443  0x4e, 0xce, 0x08, 0x44, 0x85, 0x81, 0x3e, 0x90,
444  0x88, 0xd2, 0xc6, 0x3a, 0x04, 0x1b, 0xc5, 0xb4,
445  0x4f, 0x9e, 0xf1, 0x01, 0x2a, 0x2b, 0x58, 0x8f,
446  0x3c, 0xd1, 0x1f, 0x05, 0x03, 0x3a, 0xc4, 0xc6,
447  0x0c, 0x2e, 0xf6, 0xab, 0x40, 0x30, 0xfe, 0x82,
448  0x96, 0x24, 0x8d, 0xf1, 0x63, 0xf4, 0x49, 0x52
449 };
450 
451 static u8 tc6_digest_sha512[] = {
452  0x80, 0xb2, 0x42, 0x63, 0xc7, 0xc1, 0xa3, 0xeb,
453  0xb7, 0x14, 0x93, 0xc1, 0xdd, 0x7b, 0xe8, 0xb4,
454  0x9b, 0x46, 0xd1, 0xf4, 0x1b, 0x4a, 0xee, 0xc1,
455  0x12, 0x1b, 0x01, 0x37, 0x83, 0xf8, 0xf3, 0x52,
456  0x6b, 0x56, 0xd0, 0x37, 0xe0, 0x5f, 0x25, 0x98,
457  0xbd, 0x0f, 0xd2, 0x21, 0x5d, 0x6a, 0x1e, 0x52,
458  0x95, 0xe6, 0x4f, 0x73, 0xf6, 0x3f, 0x0a, 0xec,
459  0x8b, 0x91, 0x5a, 0x98, 0x5d, 0x78, 0x65, 0x98
460 };
461 
462 /* *INDENT-OFF* */
463 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha224) = {
464  .name = "RFC4231 TC6",
465  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
466  .key = TEST_DATA (tc6_key),
467  .plaintext = TEST_DATA (tc6_data),
468  .digest = TEST_DATA (tc6_digest_sha224),
469 };
470 
471 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha256) = {
472  .name = "RFC4231 TC6",
473  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
474  .key = TEST_DATA (tc6_key),
475  .plaintext = TEST_DATA (tc6_data),
476  .digest = TEST_DATA (tc6_digest_sha256),
477 };
478 
479 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha384) = {
480  .name = "RFC4231 TC6",
481  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
482  .key = TEST_DATA (tc6_key),
483  .plaintext = TEST_DATA (tc6_data),
484  .digest = TEST_DATA (tc6_digest_sha384),
485 };
486 
487 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc6_sha512) = {
488  .name = "RFC4231 TC6",
489  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
490  .key = TEST_DATA (tc6_key),
491  .plaintext = TEST_DATA (tc6_data),
492  .digest = TEST_DATA (tc6_digest_sha512),
493 };
494 /* *INDENT-ON* */
495 
496 static u8 tc7_key[131] = {
497  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
498  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
499  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
500  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
501  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
502  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
503  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
504  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
505  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
506  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
507  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
508  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
509  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
510  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
511  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
512  0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
513  0xaa, 0xaa, 0xaa
514 };
515 
516 static char tc7_data[152] =
517  "This is a test using a larger than block-size key and a larger than "
518  "block-size data. The key needs to be hashed before being used by the "
519  "HMAC algorithm.";
520 
521 static u8 tc7_digest_sha224[] = {
522  0x3a, 0x85, 0x41, 0x66, 0xac, 0x5d, 0x9f, 0x02,
523  0x3f, 0x54, 0xd5, 0x17, 0xd0, 0xb3, 0x9d, 0xbd,
524  0x94, 0x67, 0x70, 0xdb, 0x9c, 0x2b, 0x95, 0xc9,
525  0xf6, 0xf5, 0x65, 0xd1
526 };
527 
528 static u8 tc7_digest_sha256[] = {
529  0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb,
530  0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44,
531  0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
532  0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2
533 };
534 
535 static u8 tc7_digest_sha384[] = {
536  0x66, 0x17, 0x17, 0x8e, 0x94, 0x1f, 0x02, 0x0d,
537  0x35, 0x1e, 0x2f, 0x25, 0x4e, 0x8f, 0xd3, 0x2c,
538  0x60, 0x24, 0x20, 0xfe, 0xb0, 0xb8, 0xfb, 0x9a,
539  0xdc, 0xce, 0xbb, 0x82, 0x46, 0x1e, 0x99, 0xc5,
540  0xa6, 0x78, 0xcc, 0x31, 0xe7, 0x99, 0x17, 0x6d,
541  0x38, 0x60, 0xe6, 0x11, 0x0c, 0x46, 0x52, 0x3e
542 };
543 
544 static u8 tc7_digest_sha512[] = {
545  0xe3, 0x7b, 0x6a, 0x77, 0x5d, 0xc8, 0x7d, 0xba,
546  0xa4, 0xdf, 0xa9, 0xf9, 0x6e, 0x5e, 0x3f, 0xfd,
547  0xde, 0xbd, 0x71, 0xf8, 0x86, 0x72, 0x89, 0x86,
548  0x5d, 0xf5, 0xa3, 0x2d, 0x20, 0xcd, 0xc9, 0x44,
549  0xb6, 0x02, 0x2c, 0xac, 0x3c, 0x49, 0x82, 0xb1,
550  0x0d, 0x5e, 0xeb, 0x55, 0xc3, 0xe4, 0xde, 0x15,
551  0x13, 0x46, 0x76, 0xfb, 0x6d, 0xe0, 0x44, 0x60,
552  0x65, 0xc9, 0x74, 0x40, 0xfa, 0x8c, 0x6a, 0x58
553 };
554 
555 /* *INDENT-OFF* */
556 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha224) = {
557  .name = "RFC4231 TC7",
558  .alg = VNET_CRYPTO_ALG_HMAC_SHA224,
559  .key = TEST_DATA (tc7_key),
560  .plaintext = TEST_DATA (tc7_data),
561  .digest = TEST_DATA (tc7_digest_sha224),
562 };
563 
564 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha256) = {
565  .name = "RFC4231 TC7",
566  .alg = VNET_CRYPTO_ALG_HMAC_SHA256,
567  .key = TEST_DATA (tc7_key),
568  .plaintext = TEST_DATA (tc7_data),
569  .digest = TEST_DATA (tc7_digest_sha256),
570 };
571 
572 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha384) = {
573  .name = "RFC4231 TC7",
574  .alg = VNET_CRYPTO_ALG_HMAC_SHA384,
575  .key = TEST_DATA (tc7_key),
576  .plaintext = TEST_DATA (tc7_data),
577  .digest = TEST_DATA (tc7_digest_sha384),
578 };
579 
580 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha512) = {
581  .name = "RFC4231 TC7",
582  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
583  .key = TEST_DATA (tc7_key),
584  .plaintext = TEST_DATA (tc7_data),
585  .digest = TEST_DATA (tc7_digest_sha512),
586 };
587 
588 UNITTEST_REGISTER_CRYPTO_TEST (rfc4231_tc7_sha512_chain) = {
589  .name = "RFC4231 TC7 [chained]",
590  .alg = VNET_CRYPTO_ALG_HMAC_SHA512,
591  .key = TEST_DATA (tc7_key),
592  .digest = TEST_DATA (tc7_digest_sha512),
593  .is_chained = 1,
594  .pt_chunks = {
595  TEST_DATA_CHUNK (tc7_data, 0, 50),
596  TEST_DATA_CHUNK (tc7_data, 50, 50),
597  TEST_DATA_CHUNK (tc7_data, 100, 50),
598  TEST_DATA_CHUNK (tc7_data, 150, 2),
599  },
600 };
601 /* *INDENT-ON* */
602 
603 /*
604  * fd.io coding-style-patch-verification: ON
605  *
606  * Local Variables:
607  * eval: (c-set-style "gnu")
608  * End:
609  */
static u8 tc7_digest_sha256[]
Definition: rfc4231.c:528
static u8 tc3_data[50]
Definition: rfc4231.c:176
static u8 tc2_digest_sha384[]
Definition: rfc4231.c:116
static u8 tc3_digest_sha256[]
Definition: rfc4231.c:193
static u8 tc7_digest_sha512[]
Definition: rfc4231.c:544
static u8 tc5_digest_sha224[16]
Definition: rfc4231.c:351
static u8 tc4_digest_sha256[]
Definition: rfc4231.c:278
static u8 tc5_digest_sha384[16]
Definition: rfc4231.c:361
static u8 tc6_digest_sha256[]
Definition: rfc4231.c:435
unsigned char u8
Definition: types.h:56
static u8 tc6_digest_sha512[]
Definition: rfc4231.c:451
static char tc1_data[8]
Definition: rfc4231.c:28
static u8 tc2_digest_sha512[]
Definition: rfc4231.c:125
static u8 tc7_digest_sha384[]
Definition: rfc4231.c:535
static u8 tc1_digest_sha224[]
Definition: rfc4231.c:30
static u8 tc1_digest_sha256[]
Definition: rfc4231.c:37
static u8 tc2_digest_sha224[]
Definition: rfc4231.c:102
static u8 tc2_digest_sha256[]
Definition: rfc4231.c:109
static u8 tc6_key[131]
Definition: rfc4231.c:405
static u8 tc7_digest_sha224[]
Definition: rfc4231.c:521
static char tc2_key[4]
Definition: rfc4231.c:98
static u8 tc3_digest_sha512[]
Definition: rfc4231.c:209
static u8 tc5_key[20]
Definition: rfc4231.c:339
static u8 tc3_digest_sha224[]
Definition: rfc4231.c:186
static u8 tc5_digest_sha256[16]
Definition: rfc4231.c:356
static u8 tc1_digest_sha512[]
Definition: rfc4231.c:53
static u8 tc5_digest_sha512[16]
Definition: rfc4231.c:366
static char tc2_data[28]
Definition: rfc4231.c:100
static u8 tc7_key[131]
Definition: rfc4231.c:496
static u8 tc1_digest_sha384[]
Definition: rfc4231.c:44
static u8 tc6_digest_sha224[]
Definition: rfc4231.c:428
static u8 tc4_data[50]
Definition: rfc4231.c:261
static u8 tc4_digest_sha512[]
Definition: rfc4231.c:294
static u8 tc4_digest_sha384[]
Definition: rfc4231.c:285
static u8 tc6_digest_sha384[]
Definition: rfc4231.c:442
static char tc6_data[54]
Definition: rfc4231.c:425
static u8 tc4_digest_sha224[]
Definition: rfc4231.c:271
#define TEST_DATA(n)
Definition: crypto.h:63
#define TEST_DATA_CHUNK(s, off, n)
Definition: crypto.h:64
static u8 tc5_data[]
Definition: rfc4231.c:345
static char tc7_data[152]
Definition: rfc4231.c:516
static u8 tc4_key[25]
Definition: rfc4231.c:254
static u8 tc3_key[20]
Definition: rfc4231.c:170
static u8 tc1_key[]
Definition: rfc4231.c:22
static u8 tc3_digest_sha384[]
Definition: rfc4231.c:200
UNITTEST_REGISTER_CRYPTO_TEST(rfc4231_tc1_sha224)