1 /*	$NetBSD: hash_test.c,v 1.1.1.7 2015/07/08 15:38:05 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2011-2015  Internet Systems Consortium, Inc. ("ISC")
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* Id */
20 
21 /* ! \file */
22 
23 #include <config.h>
24 
25 #include <atf-c.h>
26 
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include <isc/crc64.h>
31 #include <isc/hmacmd5.h>
32 #include <isc/hmacsha.h>
33 #include <isc/md5.h>
34 #include <isc/sha1.h>
35 #include <isc/util.h>
36 #include <isc/string.h>
37 
38 /*
39  * Test data from RFC6234
40  */
41 
42 unsigned char digest[ISC_SHA512_DIGESTLENGTH];
43 unsigned char buffer[1024];
44 const char *s;
45 char str[2 * ISC_SHA512_DIGESTLENGTH + 1];
46 unsigned char key[20];
47 
48 isc_result_t
49 tohexstr(unsigned char *d, unsigned int len, char *out);
50 /*
51  * Precondition: a hexadecimal number in *d, the length of that number in len,
52  *   and a pointer to a character array to put the output (*out).
53  * Postcondition: A String representation of the given hexadecimal number is
54  *   placed into the array *out
55  *
56  * 'out' MUST point to an array of at least len * 2 + 1
57  *
58  * Return values: ISC_R_SUCCESS if the operation is sucessful
59  */
60 
61 isc_result_t
62 tohexstr(unsigned char *d, unsigned int len, char *out) {
63 
64 	out[0]='\0';
65 	char c_ret[] = "AA";
66 	unsigned int i;
67 	strcat(out, "0x");
68 	for (i = 0; i < len; i++) {
69 		sprintf(c_ret, "%02X", d[i]);
70 		strcat(out, c_ret);
71 	}
72 	strcat(out, "\0");
73 	return (ISC_R_SUCCESS);
74 }
75 
76 
77 #define TEST_INPUT(x) (x), sizeof(x)-1
78 
79 typedef struct hash_testcase {
80 	const char *input;
81 	size_t input_len;
82 	const char *result;
83 	int repeats;
84 } hash_testcase_t;
85 
86 typedef struct hash_test_key {
87 	const char *key;
88 	const int len;
89 } hash_test_key_t;
90 
91 /* non-hmac tests */
92 
93 ATF_TC(isc_sha1);
94 ATF_TC_HEAD(isc_sha1, tc) {
95 	atf_tc_set_md_var(tc, "descr", "sha1 examples from RFC4634");
96 }
97 ATF_TC_BODY(isc_sha1, tc) {
98 	isc_sha1_t sha1;
99 	int i;
100 
101 	UNUSED(tc);
102 
103 	/*
104 	 * These are the various test vectors.  All of these are passed
105 	 * through the hash function and the results are compared to the
106 	 * result specified here.
107 	 */
108 	hash_testcase_t testcases[] = {
109 		/* Test 1 */
110 		{
111 			TEST_INPUT("abc"),
112 			"0xA9993E364706816ABA3E25717850C26C9CD0D89D",
113 			1
114 		},
115 		/* Test 2 */
116 		{
117 			TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijk"
118 				   "ljklmklmnlmnomnopnopq"),
119 			"0x84983E441C3BD26EBAAE4AA1F95129E5E54670F1",
120 			1
121 		},
122 		/* Test 3 */
123 		{
124 			TEST_INPUT("a") /* times 1000000 */,
125 			"0x34AA973CD4C4DAA4F61EEB2BDBAD27316534016F",
126 			1000000
127 		},
128 		/* Test 4 -- exact multiple of 512 bits */
129 		{
130 			TEST_INPUT("01234567012345670123456701234567"),
131 			"0xDEA356A2CDDD90C7A7ECEDC5EBB563934F460452",
132 			20 /* 20 times */
133 		},
134 #if 0
135 		/* Test 5 -- optional feature, not implemented */
136 		{
137 			TEST_INPUT(""),
138 			/* "extrabits": 0x98 , "numberextrabits": 5 */
139 			"0x29826B003B906E660EFF4027CE98AF3531AC75BA",
140 			1
141 		},
142 #endif
143 		/* Test 6 */
144 		{
145 			TEST_INPUT("\x5e"),
146 			"0x5E6F80A34A9798CAFC6A5DB96CC57BA4C4DB59C2",
147 			1
148 		},
149 #if 0
150 		/* Test 7 -- optional feature, not implemented */
151 		{
152 			TEST_INPUT("\x49\xb2\xae\xc2\x59\x4b\xbe\x3a"
153 				   "\x3b\x11\x75\x42\xd9\x4a\xc8"),
154 			/* "extrabits": 0x80, "numberextrabits": 3 */
155 		  "0x6239781E03729919C01955B3FFA8ACB60B988340", 1 },
156 #endif
157 		/* Test 8 */
158 		{
159 			TEST_INPUT("\x9a\x7d\xfd\xf1\xec\xea\xd0\x6e\xd6\x46"
160 				   "\xaa\x55\xfe\x75\x71\x46"),
161 			"0x82ABFF6605DBE1C17DEF12A394FA22A82B544A35",
162 			1
163 		},
164 #if 0
165 		/* Test 9 -- optional feature, not implemented */
166 		{
167 			TEST_INPUT("\x65\xf9\x32\x99\x5b\xa4\xce\x2c\xb1\xb4"
168 				   "\xa2\xe7\x1a\xe7\x02\x20\xaa\xce\xc8\x96"
169 				   "\x2d\xd4\x49\x9c\xbd\x7c\x88\x7a\x94\xea"
170 				   "\xaa\x10\x1e\xa5\xaa\xbc\x52\x9b\x4e\x7e"
171 				   "\x43\x66\x5a\x5a\xf2\xcd\x03\xfe\x67\x8e"
172 				   "\xa6\xa5\x00\x5b\xba\x3b\x08\x22\x04\xc2"
173 				   "\x8b\x91\x09\xf4\x69\xda\xc9\x2a\xaa\xb3"
174 				   "\xaa\x7c\x11\xa1\xb3\x2a"),
175 			/* "extrabits": 0xE0 , "numberextrabits": 3 */
176 			"0x8C5B2A5DDAE5A97FC7F9D85661C672ADBF7933D4",
177 			1
178 		},
179 #endif
180 		/* Test 10 */
181 		{
182 			TEST_INPUT("\xf7\x8f\x92\x14\x1b\xcd\x17\x0a\xe8\x9b"
183 				   "\x4f\xba\x15\xa1\xd5\x9f\x3f\xd8\x4d\x22"
184 				   "\x3c\x92\x51\xbd\xac\xbb\xae\x61\xd0\x5e"
185 				   "\xd1\x15\xa0\x6a\x7c\xe1\x17\xb7\xbe\xea"
186 				   "\xd2\x44\x21\xde\xd9\xc3\x25\x92\xbd\x57"
187 				   "\xed\xea\xe3\x9c\x39\xfa\x1f\xe8\x94\x6a"
188 				   "\x84\xd0\xcf\x1f\x7b\xee\xad\x17\x13\xe2"
189 				   "\xe0\x95\x98\x97\x34\x7f\x67\xc8\x0b\x04"
190 				   "\x00\xc2\x09\x81\x5d\x6b\x10\xa6\x83\x83"
191 				   "\x6f\xd5\x56\x2a\x56\xca\xb1\xa2\x8e\x81"
192 				   "\xb6\x57\x66\x54\x63\x1c\xf1\x65\x66\xb8"
193 				   "\x6e\x3b\x33\xa1\x08\xb0\x53\x07\xc0\x0a"
194 				   "\xff\x14\xa7\x68\xed\x73\x50\x60\x6a\x0f"
195 				   "\x85\xe6\xa9\x1d\x39\x6f\x5b\x5c\xbe\x57"
196 				   "\x7f\x9b\x38\x80\x7c\x7d\x52\x3d\x6d\x79"
197 				   "\x2f\x6e\xbc\x24\xa4\xec\xf2\xb3\xa4\x27"
198 				   "\xcd\xbb\xfb"),
199 			"0xCB0082C8F197D260991BA6A460E76E202BAD27B3",
200 			1
201 		},
202 		{ NULL, 0, NULL, 1 }
203 	};
204 
205 	hash_testcase_t *testcase = testcases;
206 
207 	while (testcase->input != NULL && testcase->result != NULL) {
208 		isc_sha1_init(&sha1);
209 		for(i = 0; i < testcase->repeats; i++) {
210 			isc_sha1_update(&sha1,
211 					(const isc_uint8_t *) testcase->input,
212 					testcase->input_len);
213 		}
214 		isc_sha1_final(&sha1, digest);
215 		tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
216 		ATF_CHECK_STREQ(str, testcase->result);
217 
218 		testcase++;
219 	}
220 }
221 
222 ATF_TC(isc_sha224);
223 ATF_TC_HEAD(isc_sha224, tc) {
224 	atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
225 }
226 ATF_TC_BODY(isc_sha224, tc) {
227 	isc_sha224_t sha224;
228 	int i;
229 
230 	UNUSED(tc);
231 
232 	/*
233 	 * These are the various test vectors.  All of these are passed
234 	 * through the hash function and the results are compared to the
235 	 * result specified here.
236 	 */
237 	hash_testcase_t testcases[] = {
238 		/* Test 1 */
239 		{
240 			TEST_INPUT("abc"),
241 			"0x23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7"
242 				"E36C9DA7",
243 			1
244 		},
245 		/* Test 2 */
246 		{
247 			TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijklj"
248 				   "klmklmnlmnomnopnopq"),
249 			"0x75388B16512776CC5DBA5DA1FD890150B0C6455CB4F58B"
250 				"1952522525",
251 			1
252 		},
253 		/* Test 3 */
254 		{
255 			TEST_INPUT("a"),
256 			"0x20794655980C91D8BBB4C1EA97618A4BF03F42581948B2"
257 				"EE4EE7AD67",
258 			1000000
259 		},
260 		/* Test 4 */
261 		{
262 			TEST_INPUT("01234567012345670123456701234567"),
263 			"0x567F69F168CD7844E65259CE658FE7AADFA25216E68ECA"
264 				"0EB7AB8262",
265 			20
266 		},
267 #if 0
268 		/* Test 5 -- unimplemented optional functionality */
269 		{
270 			TEST_INPUT(""),
271 			"0xXXX",
272 			1
273 		},
274 #endif
275 		/* Test 6 */
276 		{
277 			TEST_INPUT("\x07"),
278 			"0x00ECD5F138422B8AD74C9799FD826C531BAD2FCABC7450"
279 				"BEE2AA8C2A",
280 			1
281 		},
282 #if 0
283 		/* Test 7 -- unimplemented optional functionality */
284 		{
285 			TEST_INPUT(""),
286 			"0xXXX",
287 			1
288 		},
289 #endif
290 		/* Test 8 */
291 		{
292 			TEST_INPUT("\x18\x80\x40\x05\xdd\x4f\xbd\x15\x56\x29"
293 				   "\x9d\x6f\x9d\x93\xdf\x62"),
294 			"0xDF90D78AA78821C99B40BA4C966921ACCD8FFB1E98AC38"
295 				"8E56191DB1",
296 			1
297 		},
298 #if 0
299 		/* Test 9 */
300 		{
301 			TEST_INPUT(""),
302 			"0xXXX",
303 			1
304 		},
305 #endif
306 		/* Test 10 */
307 		{
308 			TEST_INPUT("\x55\xb2\x10\x07\x9c\x61\xb5\x3a\xdd\x52"
309 				   "\x06\x22\xd1\xac\x97\xd5\xcd\xbe\x8c\xb3"
310 				   "\x3a\xa0\xae\x34\x45\x17\xbe\xe4\xd7\xba"
311 				   "\x09\xab\xc8\x53\x3c\x52\x50\x88\x7a\x43"
312 				   "\xbe\xbb\xac\x90\x6c\x2e\x18\x37\xf2\x6b"
313 				   "\x36\xa5\x9a\xe3\xbe\x78\x14\xd5\x06\x89"
314 				   "\x6b\x71\x8b\x2a\x38\x3e\xcd\xac\x16\xb9"
315 				   "\x61\x25\x55\x3f\x41\x6f\xf3\x2c\x66\x74"
316 				   "\xc7\x45\x99\xa9\x00\x53\x86\xd9\xce\x11"
317 				   "\x12\x24\x5f\x48\xee\x47\x0d\x39\x6c\x1e"
318 				   "\xd6\x3b\x92\x67\x0c\xa5\x6e\xc8\x4d\xee"
319 				   "\xa8\x14\xb6\x13\x5e\xca\x54\x39\x2b\xde"
320 				   "\xdb\x94\x89\xbc\x9b\x87\x5a\x8b\xaf\x0d"
321 				   "\xc1\xae\x78\x57\x36\x91\x4a\xb7\xda\xa2"
322 				   "\x64\xbc\x07\x9d\x26\x9f\x2c\x0d\x7e\xdd"
323 				   "\xd8\x10\xa4\x26\x14\x5a\x07\x76\xf6\x7c"
324 				   "\x87\x82\x73"),
325 			"0x0B31894EC8937AD9B91BDFBCBA294D9ADEFAA18E09305E"
326 				"9F20D5C3A4",
327 			1
328 		},
329 		{ NULL, 0, NULL, 1 }
330 	};
331 
332 	hash_testcase_t *testcase = testcases;
333 
334 	while (testcase->input != NULL && testcase->result != NULL) {
335 		isc_sha224_init(&sha224);
336 		for(i = 0; i < testcase->repeats; i++) {
337 			isc_sha224_update(&sha224,
338 					  (const isc_uint8_t *) testcase->input,
339 					  testcase->input_len);
340 		}
341 		isc_sha224_final(digest, &sha224);
342 		/*
343 		*API inconsistency BUG HERE
344 		* in order to be consistant with the other isc_hash_final
345 		* functions the call should be
346 		* isc_sha224_final(&sha224, digest);
347 		 */
348 		tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
349 		ATF_CHECK_STREQ(str, testcase->result);
350 
351 		testcase++;
352 	}
353 }
354 
355 ATF_TC(isc_sha256);
356 ATF_TC_HEAD(isc_sha256, tc) {
357 	atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
358 }
359 ATF_TC_BODY(isc_sha256, tc) {
360 	isc_sha256_t sha256;
361 	int i;
362 
363 	UNUSED(tc);
364 
365 	/*
366 	 * These are the various test vectors.  All of these are passed
367 	 * through the hash function and the results are compared to the
368 	 * result specified here.
369 	 */
370 	hash_testcase_t testcases[] = {
371 		/* Test 1 */
372 		{
373 			TEST_INPUT("abc"),
374 			"0xBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A"
375 				"9CB410FF61F20015AD",
376 			1
377 		},
378 		/* Test 2 */
379 		{
380 			TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijkljk"
381 				   "lmklmnlmnomnopnopq"),
382 			"0x248D6A61D20638B8E5C026930C3E6039A33CE45964FF21"
383 				"67F6ECEDD419DB06C1",
384 			1
385 		},
386 		/* Test 3 */
387 		{
388 			TEST_INPUT("a"),
389 			"0xCDC76E5C9914FB9281A1C7E284D73E67F1809A48A49720"
390 				"0E046D39CCC7112CD0",
391 			1000000 },
392 		/* Test 4 */
393 		{
394 			TEST_INPUT("01234567012345670123456701234567"),
395 			"0x594847328451BDFA85056225462CC1D867D877FB388DF0"
396 				"CE35F25AB5562BFBB5",
397 			20
398 		},
399 #if 0
400 		/* Test 5 -- unimplemented optional functionality */
401 		{
402 			TEST_INPUT(""),
403 			"0xXXX",
404 			1
405 		},
406 #endif
407 		/* Test 6 */
408 		{
409 			TEST_INPUT("\x19"),
410 			"0x68AA2E2EE5DFF96E3355E6C7EE373E3D6A4E17F75F9518"
411 				"D843709C0C9BC3E3D4",
412 			1
413 		},
414 #if 0
415 		/* Test 7 -- unimplemented optional functionality */
416 		{
417 			TEST_INPUT(""),
418 			"0xXXX",
419 			1
420 		},
421 #endif
422 		/* Test 8 */
423 		{
424 			TEST_INPUT("\xe3\xd7\x25\x70\xdc\xdd\x78\x7c\xe3"
425 				   "\x88\x7a\xb2\xcd\x68\x46\x52"),
426 			"0x175EE69B02BA9B58E2B0A5FD13819CEA573F3940A94F82"
427 				"5128CF4209BEABB4E8",
428 			1
429 		},
430 #if 0
431 		/* Test 9 -- unimplemented optional functionality */
432 		{
433 			TEST_INPUT(""),
434 			"0xXXX",
435 			1
436 		},
437 #endif
438 		/* Test 10 */
439 		{
440 			TEST_INPUT("\x83\x26\x75\x4e\x22\x77\x37\x2f\x4f\xc1"
441 				   "\x2b\x20\x52\x7a\xfe\xf0\x4d\x8a\x05\x69"
442 				   "\x71\xb1\x1a\xd5\x71\x23\xa7\xc1\x37\x76"
443 				   "\x00\x00\xd7\xbe\xf6\xf3\xc1\xf7\xa9\x08"
444 				   "\x3a\xa3\x9d\x81\x0d\xb3\x10\x77\x7d\xab"
445 				   "\x8b\x1e\x7f\x02\xb8\x4a\x26\xc7\x73\x32"
446 				   "\x5f\x8b\x23\x74\xde\x7a\x4b\x5a\x58\xcb"
447 				   "\x5c\x5c\xf3\x5b\xce\xe6\xfb\x94\x6e\x5b"
448 				   "\xd6\x94\xfa\x59\x3a\x8b\xeb\x3f\x9d\x65"
449 				   "\x92\xec\xed\xaa\x66\xca\x82\xa2\x9d\x0c"
450 				   "\x51\xbc\xf9\x33\x62\x30\xe5\xd7\x84\xe4"
451 				   "\xc0\xa4\x3f\x8d\x79\xa3\x0a\x16\x5c\xba"
452 				   "\xbe\x45\x2b\x77\x4b\x9c\x71\x09\xa9\x7d"
453 				   "\x13\x8f\x12\x92\x28\x96\x6f\x6c\x0a\xdc"
454 				   "\x10\x6a\xad\x5a\x9f\xdd\x30\x82\x57\x69"
455 				   "\xb2\xc6\x71\xaf\x67\x59\xdf\x28\xeb\x39"
456 				   "\x3d\x54\xd6"),
457 			"0x97DBCA7DF46D62C8A422C941DD7E835B8AD3361763F7E9"
458 				"B2D95F4F0DA6E1CCBC",
459 			1
460 		},
461 		{ NULL, 0, NULL, 1 }
462 	};
463 
464 	hash_testcase_t *testcase = testcases;
465 
466 	while (testcase->input != NULL && testcase->result != NULL) {
467 		isc_sha256_init(&sha256);
468 		for(i = 0; i < testcase->repeats; i++) {
469 			isc_sha256_update(&sha256,
470 					  (const isc_uint8_t *) testcase->input,
471 					  testcase->input_len);
472 		}
473 		isc_sha256_final(digest, &sha256);
474 		/*
475 		*API inconsistency BUG HERE
476 		* in order to be consistant with the other isc_hash_final
477 		* functions the call should be
478 		* isc_sha224_final(&sha224, digest);
479 		 */
480 		tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
481 		ATF_CHECK_STREQ(str, testcase->result);
482 
483 		testcase++;
484 	}
485 }
486 
487 ATF_TC(isc_sha384);
488 ATF_TC_HEAD(isc_sha384, tc) {
489 	atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
490 }
491 ATF_TC_BODY(isc_sha384, tc) {
492 	isc_sha384_t sha384;
493 	int i;
494 
495 	UNUSED(tc);
496 
497 	/*
498 	 * These are the various test vectors.  All of these are passed
499 	 * through the hash function and the results are compared to the
500 	 * result specified here.
501 	 */
502 	hash_testcase_t testcases[] = {
503 		/* Test 1 */
504 		{
505 			TEST_INPUT("abc"),
506 			"0xCB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1"
507 				"631A8B605A43FF5BED8086072BA1E7CC2358BAEC"
508 				"A134C825A7",
509 			1
510 		},
511 		/* Test 2 */
512 		{
513 			TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl"
514 				   "fghijklmghijklmnhijklmnoijklmnopjklmnopq"
515 				   "klmnopqrlmnopqrsmnopqrstnopqrstu"),
516 			"0x09330C33F71147E83D192FC782CD1B4753111B173B3B05"
517 				"D22FA08086E3B0F712FCC7C71A557E2DB966C3E9"
518 				"FA91746039",
519 			1
520 		},
521 		/* Test 3 */
522 		{
523 			TEST_INPUT("a"),
524 			"0x9D0E1809716474CB086E834E310A4A1CED149E9C00F248"
525 				"527972CEC5704C2A5B07B8B3DC38ECC4EBAE97DD"
526 				"D87F3D8985",
527 			1000000
528 		},
529 		/* Test 4 */
530 		{
531 			TEST_INPUT("01234567012345670123456701234567"),
532 			"0x2FC64A4F500DDB6828F6A3430B8DD72A368EB7F3A8322A"
533 				"70BC84275B9C0B3AB00D27A5CC3C2D224AA6B61A"
534 				"0D79FB4596",
535 			20
536 		},
537 #if 0
538 		/* Test 5 -- unimplemented optional functionality */
539 		{
540 			TEST_INPUT(""),
541 			"0xXXX",
542 			1
543 		},
544 #endif
545 		/* Test 6 */
546 		{ TEST_INPUT("\xb9"),
547 			"0xBC8089A19007C0B14195F4ECC74094FEC64F01F9092928"
548 				"2C2FB392881578208AD466828B1C6C283D2722CF"
549 				"0AD1AB6938",
550 			1
551 		},
552 #if 0
553 		/* Test 7 -- unimplemented optional functionality */
554 		{
555 			TEST_INPUT(""),
556 			"0xXXX",
557 			1
558 		},
559 #endif
560 		/* Test 8 */
561 		{
562 			TEST_INPUT("\xa4\x1c\x49\x77\x79\xc0\x37\x5f\xf1"
563 				   "\x0a\x7f\x4e\x08\x59\x17\x39"),
564 			"0xC9A68443A005812256B8EC76B00516F0DBB74FAB26D665"
565 				"913F194B6FFB0E91EA9967566B58109CBC675CC2"
566 				"08E4C823F7",
567 			1
568 		},
569 #if 0
570 		/* Test 9 -- unimplemented optional functionality */
571 		{
572 			TEST_INPUT(""),
573 			"0xXXX",
574 			1
575 		},
576 #endif
577 		/* Test 10 */
578 		{
579 			TEST_INPUT("\x39\x96\x69\xe2\x8f\x6b\x9c\x6d\xbc\xbb"
580 				   "\x69\x12\xec\x10\xff\xcf\x74\x79\x03\x49"
581 				   "\xb7\xdc\x8f\xbe\x4a\x8e\x7b\x3b\x56\x21"
582 				   "\xdb\x0f\x3e\x7d\xc8\x7f\x82\x32\x64\xbb"
583 				   "\xe4\x0d\x18\x11\xc9\xea\x20\x61\xe1\xc8"
584 				   "\x4a\xd1\x0a\x23\xfa\xc1\x72\x7e\x72\x02"
585 				   "\xfc\x3f\x50\x42\xe6\xbf\x58\xcb\xa8\xa2"
586 				   "\x74\x6e\x1f\x64\xf9\xb9\xea\x35\x2c\x71"
587 				   "\x15\x07\x05\x3c\xf4\xe5\x33\x9d\x52\x86"
588 				   "\x5f\x25\xcc\x22\xb5\xe8\x77\x84\xa1\x2f"
589 				   "\xc9\x61\xd6\x6c\xb6\xe8\x95\x73\x19\x9a"
590 				   "\x2c\xe6\x56\x5c\xbd\xf1\x3d\xca\x40\x38"
591 				   "\x32\xcf\xcb\x0e\x8b\x72\x11\xe8\x3a\xf3"
592 				   "\x2a\x11\xac\x17\x92\x9f\xf1\xc0\x73\xa5"
593 				   "\x1c\xc0\x27\xaa\xed\xef\xf8\x5a\xad\x7c"
594 				   "\x2b\x7c\x5a\x80\x3e\x24\x04\xd9\x6d\x2a"
595 				   "\x77\x35\x7b\xda\x1a\x6d\xae\xed\x17\x15"
596 				   "\x1c\xb9\xbc\x51\x25\xa4\x22\xe9\x41\xde"
597 				   "\x0c\xa0\xfc\x50\x11\xc2\x3e\xcf\xfe\xfd"
598 				   "\xd0\x96\x76\x71\x1c\xf3\xdb\x0a\x34\x40"
599 				   "\x72\x0e\x16\x15\xc1\xf2\x2f\xbc\x3c\x72"
600 				   "\x1d\xe5\x21\xe1\xb9\x9b\xa1\xbd\x55\x77"
601 				   "\x40\x86\x42\x14\x7e\xd0\x96"),
602 			"0x4F440DB1E6EDD2899FA335F09515AA025EE177A79F4B4A"
603 				"AF38E42B5C4DE660F5DE8FB2A5B2FBD2A3CBFFD2"
604 				"0CFF1288C0",
605 			1
606 		},
607 		{ NULL, 0, NULL, 1 }
608 	};
609 
610 	hash_testcase_t *testcase = testcases;
611 
612 	while (testcase->input != NULL && testcase->result != NULL) {
613 		isc_sha384_init(&sha384);
614 		for(i = 0; i < testcase->repeats; i++) {
615 			isc_sha384_update(&sha384,
616 					  (const isc_uint8_t *) testcase->input,
617 					  testcase->input_len);
618 		}
619 		isc_sha384_final(digest, &sha384);
620 		/*
621 		*API inconsistency BUG HERE
622 		* in order to be consistant with the other isc_hash_final
623 		* functions the call should be
624 		* isc_sha224_final(&sha224, digest);
625 		 */
626 		tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
627 		ATF_CHECK_STREQ(str, testcase->result);
628 
629 		testcase++;
630 	}
631 }
632 
633 ATF_TC(isc_sha512);
634 ATF_TC_HEAD(isc_sha512, tc) {
635 	atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
636 }
637 ATF_TC_BODY(isc_sha512, tc) {
638 	isc_sha512_t sha512;
639 	int i;
640 
641 	UNUSED(tc);
642 
643 	/*
644 	 * These are the various test vectors.  All of these are passed
645 	 * through the hash function and the results are compared to the
646 	 * result specified here.
647 	 */
648 	hash_testcase_t testcases[] = {
649 		/* Test 1 */
650 		{
651 			TEST_INPUT("abc"),
652 			"0xDDAF35A193617ABACC417349AE20413112E6FA4E89A97E"
653 				"A20A9EEEE64B55D39A2192992A274FC1A836BA3C"
654 				"23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F",
655 			1
656 		},
657 		/* Test 2 */
658 		{
659 			TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl"
660 				   "fghijklmghijklmnhijklmnoijklmnopjklmnopq"
661 				   "klmnopqrlmnopqrsmnopqrstnopqrstu"),
662 			"0x8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7F"
663 				"A17299AEADB6889018501D289E4900F7E4331B99"
664 				"DEC4B5433AC7D329EEB6DD26545E96E55B874BE909",
665 			1
666 		},
667 		/* Test 3 */
668 		{
669 			TEST_INPUT("a"),
670 			"0xE718483D0CE769644E2E42C7BC15B4638E1F98B13B2044"
671 				"285632A803AFA973EBDE0FF244877EA60A4CB043"
672 				"2CE577C31BEB009C5C2C49AA2E4EADB217AD8CC09B",
673 			1000000
674 		},
675 		/* Test 4 */
676 		{
677 			TEST_INPUT("01234567012345670123456701234567"),
678 			"0x89D05BA632C699C31231DED4FFC127D5A894DAD412C0E0"
679 				"24DB872D1ABD2BA8141A0F85072A9BE1E2AA04CF"
680 				"33C765CB510813A39CD5A84C4ACAA64D3F3FB7BAE9",
681 			20
682 		},
683 #if 0
684 		/* Test 5 -- unimplemented optional functionality */
685 		{
686 			TEST_INPUT(""),
687 			"0xXXX",
688 			1
689 		},
690 #endif
691 		/* Test 6 */
692 		{
693 			TEST_INPUT("\xD0"),
694 			"0x9992202938E882E73E20F6B69E68A0A7149090423D93C8"
695 				"1BAB3F21678D4ACEEEE50E4E8CAFADA4C85A54EA"
696 				"8306826C4AD6E74CECE9631BFA8A549B4AB3FBBA15",
697 			1
698 		},
699 #if 0
700 		/* Test 7 -- unimplemented optional functionality */
701 		{
702 			TEST_INPUT(""),
703 			"0xXXX",
704 			1
705 		},
706 #endif
707 		/* Test 8 */
708 		{
709 			TEST_INPUT("\x8d\x4e\x3c\x0e\x38\x89\x19\x14\x91\x81"
710 				   "\x6e\x9d\x98\xbf\xf0\xa0"),
711 			"0xCB0B67A4B8712CD73C9AABC0B199E9269B20844AFB75AC"
712 				"BDD1C153C9828924C3DDEDAAFE669C5FDD0BC66F"
713 				"630F6773988213EB1B16F517AD0DE4B2F0C95C90F8",
714 			1
715 		},
716 #if 0
717 		/* Test 9 -- unimplemented optional functionality */
718 		{
719 			TEST_INPUT(""),
720 			"0xXXX",
721 			1
722 		},
723 #endif
724 		/* Test 10 */
725 		{
726 			TEST_INPUT("\xa5\x5f\x20\xc4\x11\xaa\xd1\x32\x80\x7a"
727 				   "\x50\x2d\x65\x82\x4e\x31\xa2\x30\x54\x32"
728 				   "\xaa\x3d\x06\xd3\xe2\x82\xa8\xd8\x4e\x0d"
729 				   "\xe1\xde\x69\x74\xbf\x49\x54\x69\xfc\x7f"
730 				   "\x33\x8f\x80\x54\xd5\x8c\x26\xc4\x93\x60"
731 				   "\xc3\xe8\x7a\xf5\x65\x23\xac\xf6\xd8\x9d"
732 				   "\x03\xe5\x6f\xf2\xf8\x68\x00\x2b\xc3\xe4"
733 				   "\x31\xed\xc4\x4d\xf2\xf0\x22\x3d\x4b\xb3"
734 				   "\xb2\x43\x58\x6e\x1a\x7d\x92\x49\x36\x69"
735 				   "\x4f\xcb\xba\xf8\x8d\x95\x19\xe4\xeb\x50"
736 				   "\xa6\x44\xf8\xe4\xf9\x5e\xb0\xea\x95\xbc"
737 				   "\x44\x65\xc8\x82\x1a\xac\xd2\xfe\x15\xab"
738 				   "\x49\x81\x16\x4b\xbb\x6d\xc3\x2f\x96\x90"
739 				   "\x87\xa1\x45\xb0\xd9\xcc\x9c\x67\xc2\x2b"
740 				   "\x76\x32\x99\x41\x9c\xc4\x12\x8b\xe9\xa0"
741 				   "\x77\xb3\xac\xe6\x34\x06\x4e\x6d\x99\x28"
742 				   "\x35\x13\xdc\x06\xe7\x51\x5d\x0d\x73\x13"
743 				   "\x2e\x9a\x0d\xc6\xd3\xb1\xf8\xb2\x46\xf1"
744 				   "\xa9\x8a\x3f\xc7\x29\x41\xb1\xe3\xbb\x20"
745 				   "\x98\xe8\xbf\x16\xf2\x68\xd6\x4f\x0b\x0f"
746 				   "\x47\x07\xfe\x1e\xa1\xa1\x79\x1b\xa2\xf3"
747 				   "\xc0\xc7\x58\xe5\xf5\x51\x86\x3a\x96\xc9"
748 				   "\x49\xad\x47\xd7\xfb\x40\xd2"),
749 		  "0xC665BEFB36DA189D78822D10528CBF3B12B3EEF7260399"
750 			  "09C1A16A270D48719377966B957A878E72058477"
751 			  "9A62825C18DA26415E49A7176A894E7510FD1451F5",
752 		  1
753 		},
754 		{ NULL, 0, NULL, 1 }
755 	};
756 
757 	hash_testcase_t *testcase = testcases;
758 
759 	while (testcase->input != NULL && testcase->result != NULL) {
760 		isc_sha512_init(&sha512);
761 		for(i = 0; i < testcase->repeats; i++) {
762 			isc_sha512_update(&sha512,
763 					  (const isc_uint8_t *) testcase->input,
764 					  testcase->input_len);
765 		}
766 		isc_sha512_final(digest, &sha512);
767 		/*
768 		*API inconsistency BUG HERE
769 		* in order to be consistant with the other isc_hash_final
770 		* functions the call should be
771 		* isc_sha224_final(&sha224, digest);
772 		 */
773 		tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
774 		ATF_CHECK_STREQ(str, testcase->result);
775 
776 		testcase++;
777 	}
778 }
779 
780 ATF_TC(isc_md5);
781 ATF_TC_HEAD(isc_md5, tc) {
782 	atf_tc_set_md_var(tc, "descr", "md5 example from RFC1321");
783 }
784 ATF_TC_BODY(isc_md5, tc) {
785 	isc_md5_t md5;
786 	int i;
787 
788 	UNUSED(tc);
789 
790 	/*
791 	 * These are the various test vectors.  All of these are passed
792 	 * through the hash function and the results are compared to the
793 	 * result specified here.
794 	 */
795 	hash_testcase_t testcases[] = {
796 		{
797 			TEST_INPUT(""),
798 			"0xD41D8CD98F00B204E9800998ECF8427E",
799 			1
800 		},
801 		{
802 			TEST_INPUT("a"),
803 			"0x0CC175B9C0F1B6A831C399E269772661",
804 			1
805 		},
806 		{
807 			TEST_INPUT("abc"),
808 			"0x900150983CD24FB0D6963F7D28E17F72",
809 			1
810 		},
811 		{
812 			TEST_INPUT("message digest"),
813 			"0xF96B697D7CB7938D525A2F31AAF161D0",
814 			1
815 		},
816 		{
817 			TEST_INPUT("abcdefghijklmnopqrstuvwxyz"),
818 			"0xC3FCD3D76192E4007DFB496CCA67E13B",
819 			1
820 		},
821 		{
822 			TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
823 				   "nopqrstuvwxyz0123456789"),
824 			"0xD174AB98D277D9F5A5611C2C9F419D9F",
825 			1
826 		},
827 		{
828 			TEST_INPUT("123456789012345678901234567890123456789"
829 				   "01234567890123456789012345678901234567890"),
830 			"0x57EDF4A22BE3C955AC49DA2E2107B67A",
831 			1
832 		},
833 		{ NULL, 0, NULL, 1 }
834 	};
835 
836 	hash_testcase_t *testcase = testcases;
837 
838 	while (testcase->input != NULL && testcase->result != NULL) {
839 		isc_md5_init(&md5);
840 		for(i = 0; i < testcase->repeats; i++) {
841 			isc_md5_update(&md5,
842 				       (const isc_uint8_t *) testcase->input,
843 				       testcase->input_len);
844 		}
845 		isc_md5_final(&md5, digest);
846 		tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
847 		ATF_CHECK_STREQ(str, testcase->result);
848 
849 		testcase++;
850 	}
851 }
852 
853 /* HMAC-SHA1 test */
854 ATF_TC(isc_hmacsha1);
855 ATF_TC_HEAD(isc_hmacsha1, tc) {
856 	atf_tc_set_md_var(tc, "descr", "HMAC-SHA1 examples from RFC2104");
857 }
858 ATF_TC_BODY(isc_hmacsha1, tc) {
859 	isc_hmacsha1_t hmacsha1;
860 
861 	UNUSED(tc);
862 	/*
863 	 * These are the various test vectors.  All of these are passed
864 	 * through the hash function and the results are compared to the
865 	 * result specified here.
866 	 */
867 	hash_testcase_t testcases[] = {
868 		/* Test 1 */
869 		{
870 			TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
871 			"0xB617318655057264E28BC0B6FB378C8EF146BE00",
872 			1
873 		},
874 		/* Test 2 */
875 		{
876 			TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
877 				   "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
878 				   "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
879 			"0xEFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79",
880 			1
881 		},
882 		/* Test 3 */
883 		{
884 			TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
885 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
886 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
887 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
888 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
889 			"0x125D7342B9AC11CD91A39AF48AA17B4F63F175D3",
890 			1
891 		},
892 		/* Test 4 */
893 		{
894 			TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
895 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
896 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
897 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
898 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
899 			"0x4C9007F4026250C6BC8414F9BF50C86C2D7235DA",
900 			1
901 		},
902 #if 0
903 		/* Test 5 -- unimplemented optional functionality */
904 		{
905 			TEST_INPUT("Test With Truncation"),
906 			"0x4C1A03424B55E07FE7F27BE1",
907 			1
908 		},
909 #endif
910 		/* Test 6 */
911 		{
912 			TEST_INPUT("Test Using Larger Than Block-Size Key - "
913 				   "Hash Key First"),
914 			"0xAA4AE5E15272D00E95705637CE8A3B55ED402112", 1 },
915 		/* Test 7 */
916 		{
917 			TEST_INPUT("Test Using Larger Than Block-Size Key and "
918 				   "Larger Than One Block-Size Data"),
919 			"0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91",
920 			1
921 		},
922 		{ NULL, 0, NULL, 1 }
923 	};
924 
925 	hash_testcase_t *testcase = testcases;
926 
927 	hash_test_key_t test_keys[] = {
928 		/* Key 1 */
929 		{ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
930 		  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
931 		/* Key 2 */
932 		{ "Jefe", 4 },
933 		/* Key 3 */
934 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
935 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
936 		/* Key 4 */
937 		{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
938 		  "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
939 		  "\x15\x16\x17\x18\x19", 25 },
940 #if 0
941 		/* Key 5 */
942 		{ "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
943 		  "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
944 #endif
945 		/* Key 6 */
946 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
947 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
948 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
949 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
950 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
951 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
952 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
953 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80 },
954 		/* Key 7 */
955 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
956 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
957 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
958 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
959 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
960 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
961 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
962 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80 },
963 		{ "", 0 }
964 	};
965 
966 	hash_test_key_t *test_key = test_keys;
967 
968 	while (testcase->input != NULL && testcase->result != NULL) {
969 		memmove(buffer, test_key->key, test_key->len);
970 		isc_hmacsha1_init(&hmacsha1, buffer, test_key->len);
971 		isc_hmacsha1_update(&hmacsha1,
972 				    (const isc_uint8_t *) testcase->input,
973 				    testcase->input_len);
974 		isc_hmacsha1_sign(&hmacsha1, digest, ISC_SHA1_DIGESTLENGTH);
975 		tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
976 		ATF_CHECK_STREQ(str, testcase->result);
977 
978 		testcase++;
979 		test_key++;
980 	}
981 }
982 
983 /* HMAC-SHA224 test */
984 ATF_TC(isc_hmacsha224);
985 ATF_TC_HEAD(isc_hmacsha224, tc) {
986 	atf_tc_set_md_var(tc, "descr", "HMAC-SHA224 examples from RFC4634");
987 }
988 ATF_TC_BODY(isc_hmacsha224, tc) {
989 	isc_hmacsha224_t hmacsha224;
990 
991 	UNUSED(tc);
992 
993 	/*
994 	 * These are the various test vectors.  All of these are passed
995 	 * through the hash function and the results are compared to the
996 	 * result specified here.
997 	 */
998 	hash_testcase_t testcases[] = {
999 		/* Test 1 */
1000 		{
1001 			TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1002 			"0x896FB1128ABBDF196832107CD49DF33F47B4B1169912BA"
1003 				"4F53684B22",
1004 			1
1005 		},
1006 		/* Test 2 */
1007 		{
1008 			TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1009 				   "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1010 				   "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1011 			"0xA30E01098BC6DBBF45690F3A7E9E6D0F8BBEA2A39E61480"
1012 				"08FD05E44",
1013 			1
1014 		},
1015 		/* Test 3 */
1016 		{
1017 			TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1018 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1019 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1020 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1021 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1022 			"0x7FB3CB3588C6C1F6FFA9694D7D6AD2649365B0C1F65D69"
1023 				"D1EC8333EA",
1024 			1
1025 		},
1026 		/* Test 4 */
1027 		{
1028 			TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1029 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1030 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1031 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1032 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1033 			"0x6C11506874013CAC6A2ABC1BB382627CEC6A90D86EFC01"
1034 				"2DE7AFEC5A",
1035 			1
1036 		},
1037 #if 0
1038 		/* Test 5 -- unimplemented optional functionality */
1039 		{
1040 			TEST_INPUT("Test With Truncation"),
1041 			"0x4C1A03424B55E07FE7F27BE1",
1042 			1
1043 		},
1044 #endif
1045 		/* Test 6 */
1046 		{
1047 			TEST_INPUT("Test Using Larger Than Block-Size Key - "
1048 				   "Hash Key First"),
1049 			"0x95E9A0DB962095ADAEBE9B2D6F0DBCE2D499F112F2D2B7"
1050 				"273FA6870E",
1051 			1
1052 		},
1053 		/* Test 7 */
1054 		{
1055 			TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1056 				   "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1057 				   "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1058 				   "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1059 				   "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1060 				   "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1061 				   "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1062 				   "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1063 				   "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1064 				   "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1065 				   "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1066 				   "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1067 				   "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1068 				   "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1069 				   "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1070 				   "\x6d\x2e"),
1071 			"0x3A854166AC5D9F023F54D517D0B39DBD946770DB9C2B95"
1072 				"C9F6F565D1",
1073 			1
1074 		},
1075 		{ NULL, 0, NULL, 1 }
1076 	};
1077 
1078 	hash_testcase_t *testcase = testcases;
1079 
1080 	hash_test_key_t test_keys[] = {
1081 		/* Key 1 */
1082 		{ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1083 		  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1084 		/* Key 2 */
1085 		{ "Jefe", 4 },
1086 		/* Key 3 */
1087 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1088 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1089 		/* Key 4 */
1090 		{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1091 		  "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1092 		  "\x15\x16\x17\x18\x19", 25 },
1093 #if 0
1094 		/* Key 5 */
1095 		{ "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1096 		  "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1097 #endif
1098 		/* Key 6 */
1099 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1100 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1101 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1102 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1103 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1104 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1105 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1106 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1107 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1108 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1109 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1110 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1111 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1112 		/* Key 7 */
1113 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1114 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1115 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1116 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1117 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1118 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1119 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1120 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1121 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1122 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1123 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1124 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1125 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1126 		{ "", 0 }
1127 	};
1128 
1129 	hash_test_key_t *test_key = test_keys;
1130 
1131 	while (testcase->input != NULL && testcase->result != NULL) {
1132 		memmove(buffer, test_key->key, test_key->len);
1133 		isc_hmacsha224_init(&hmacsha224, buffer, test_key->len);
1134 		isc_hmacsha224_update(&hmacsha224,
1135 				      (const isc_uint8_t *) testcase->input,
1136 				      testcase->input_len);
1137 		isc_hmacsha224_sign(&hmacsha224, digest, ISC_SHA224_DIGESTLENGTH);
1138 		tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
1139 		ATF_CHECK_STREQ(str, testcase->result);
1140 
1141 		testcase++;
1142 		test_key++;
1143 	}
1144 }
1145 
1146 /* HMAC-SHA256 test */
1147 ATF_TC(isc_hmacsha256);
1148 ATF_TC_HEAD(isc_hmacsha256, tc) {
1149 	atf_tc_set_md_var(tc, "descr", "HMAC-SHA256 examples from RFC4634");
1150 }
1151 ATF_TC_BODY(isc_hmacsha256, tc) {
1152 	isc_hmacsha256_t hmacsha256;
1153 
1154 	UNUSED(tc);
1155 
1156 	/*
1157 	 * These are the various test vectors.  All of these are passed
1158 	 * through the hash function and the results are compared to the
1159 	 * result specified here.
1160 	 */
1161 	hash_testcase_t testcases[] = {
1162 		/* Test 1 */
1163 		{
1164 			TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1165 			"0xB0344C61D8DB38535CA8AFCEAF0BF12B881DC200C9833D"
1166 				"A726E9376C2E32CFF7",
1167 			1
1168 		},
1169 		/* Test 2 */
1170 		{
1171 			TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1172 				   "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1173 				   "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1174 			"0x5BDCC146BF60754E6A042426089575C75A003F089D2739"
1175 				"839DEC58B964EC3843",
1176 			1
1177 		},
1178 		/* Test 3 */
1179 		{
1180 			TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1181 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1182 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1183 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1184 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1185 			"0x773EA91E36800E46854DB8EBD09181A72959098B3EF8C1"
1186 				"22D9635514CED565FE",
1187 			1
1188 		},
1189 		/* Test 4 */
1190 		{
1191 			TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1192 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1193 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1194 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1195 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1196 			"0x82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8"
1197 				"077A2E3FF46729665B",
1198 			1
1199 		},
1200 #if 0
1201 		/* Test 5 -- unimplemented optional functionality */
1202 		{
1203 			TEST_INPUT("Test With Truncation"),
1204 			"0x4C1A03424B55E07FE7F27BE1",
1205 			1
1206 		},
1207 #endif
1208 		/* Test 6 */
1209 		{
1210 			TEST_INPUT("Test Using Larger Than Block-Size Key - "
1211 				   "Hash Key First"),
1212 			"0x60E431591EE0B67F0D8A26AACBF5B77F8E0BC6213728C5"
1213 				"140546040F0EE37F54",
1214 			1
1215 		},
1216 		/* Test 7 */
1217 		{
1218 			TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1219 				   "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1220 				   "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1221 				   "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1222 				   "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1223 				   "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1224 				   "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1225 				   "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1226 				   "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1227 				   "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1228 				   "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1229 				   "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1230 				   "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1231 				   "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1232 				   "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1233 				   "\x6d\x2e"),
1234 			"0x9B09FFA71B942FCB27635FBCD5B0E944BFDC63644F0713"
1235 				"938A7F51535C3A35E2",
1236 			1
1237 		},
1238 		{ NULL, 0, NULL, 1 }
1239 	};
1240 
1241 	hash_testcase_t *testcase = testcases;
1242 
1243 	hash_test_key_t test_keys[] = {
1244 		/* Key 1 */
1245 		{ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1246 		  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1247 		/* Key 2 */
1248 		{ "Jefe", 4 },
1249 		/* Key 3 */
1250 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1251 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1252 		/* Key 4 */
1253 		{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1254 		  "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1255 		  "\x15\x16\x17\x18\x19", 25 },
1256 #if 0
1257 		/* Key 5 */
1258 		{ "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1259 		  "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1260 #endif
1261 		/* Key 6 */
1262 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1263 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1264 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1265 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1266 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1267 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1268 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1269 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1270 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1271 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1272 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1273 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1274 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1275 		/* Key 7 */
1276 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1277 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1278 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1279 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1280 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1281 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1282 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1283 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1284 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1285 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1286 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1287 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1288 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1289 		{ "", 0 }
1290 	};
1291 
1292 	hash_test_key_t *test_key = test_keys;
1293 
1294 	while (testcase->input != NULL && testcase->result != NULL) {
1295 		memmove(buffer, test_key->key, test_key->len);
1296 		isc_hmacsha256_init(&hmacsha256, buffer, test_key->len);
1297 		isc_hmacsha256_update(&hmacsha256,
1298 				      (const isc_uint8_t *) testcase->input,
1299 				      testcase->input_len);
1300 		isc_hmacsha256_sign(&hmacsha256, digest, ISC_SHA256_DIGESTLENGTH);
1301 		tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
1302 		ATF_CHECK_STREQ(str, testcase->result);
1303 
1304 		testcase++;
1305 		test_key++;
1306 	}
1307 }
1308 
1309 /* HMAC-SHA384 test */
1310 ATF_TC(isc_hmacsha384);
1311 ATF_TC_HEAD(isc_hmacsha384, tc) {
1312 	atf_tc_set_md_var(tc, "descr", "HMAC-SHA384 examples from RFC4634");
1313 }
1314 ATF_TC_BODY(isc_hmacsha384, tc) {
1315 	isc_hmacsha384_t hmacsha384;
1316 
1317 	UNUSED(tc);
1318 
1319 	/*
1320 	 * These are the various test vectors.  All of these are passed
1321 	 * through the hash function and the results are compared to the
1322 	 * result specified here.
1323 	 */
1324 	hash_testcase_t testcases[] = {
1325 		/* Test 1 */
1326 		{
1327 			TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1328 			"0xAFD03944D84895626B0825F4AB46907F15F9DADBE4101E"
1329 				"C682AA034C7CEBC59CFAEA9EA9076EDE7F4AF152"
1330 				"E8B2FA9CB6",
1331 			1
1332 		},
1333 		/* Test 2 */
1334 		{
1335 			TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1336 				   "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1337 				   "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1338 			"0xAF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B"
1339 				"47E42EC3736322445E8E2240CA5E69E2C78B3239"
1340 				"ECFAB21649",
1341 			1
1342 		},
1343 		/* Test 3 */
1344 		{
1345 			TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1346 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1347 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1348 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1349 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1350 			"0x88062608D3E6AD8A0AA2ACE014C8A86F0AA635D947AC9F"
1351 				"EBE83EF4E55966144B2A5AB39DC13814B94E3AB6"
1352 				"E101A34F27",
1353 			1
1354 		},
1355 		/* Test 4 */
1356 		{
1357 			TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1358 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1359 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1360 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1361 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1362 			"0x3E8A69B7783C25851933AB6290AF6CA77A998148085000"
1363 				"9CC5577C6E1F573B4E6801DD23C4A7D679CCF8A3"
1364 				"86C674CFFB",
1365 			1
1366 		},
1367 #if 0
1368 		/* Test 5 -- unimplemented optional functionality */
1369 		{
1370 			TEST_INPUT("Test With Truncation"),
1371 			"0x4C1A03424B55E07FE7F27BE1",
1372 			1
1373 		},
1374 #endif
1375 		/* Test 6 */
1376 		{
1377 			TEST_INPUT("Test Using Larger Than Block-Size Key - "
1378 				   "Hash Key First"),
1379 			"0x4ECE084485813E9088D2C63A041BC5B44F9EF1012A2B58"
1380 				"8F3CD11F05033AC4C60C2EF6AB4030FE8296248D"
1381 				"F163F44952",
1382 			1
1383 		},
1384 		/* Test 7 */
1385 		{
1386 			TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1387 				   "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1388 				   "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1389 				   "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1390 				   "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1391 				   "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1392 				   "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1393 				   "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1394 				   "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1395 				   "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1396 				   "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1397 				   "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1398 				   "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1399 				   "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1400 				   "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1401 				   "\x6d\x2e"),
1402 			"0x6617178E941F020D351E2F254E8FD32C602420FEB0B8FB"
1403 				"9ADCCEBB82461E99C5A678CC31E799176D3860E6"
1404 				"110C46523E",
1405 			1
1406 		},
1407 		{ NULL, 0, NULL, 1 }
1408 	};
1409 
1410 	hash_testcase_t *testcase = testcases;
1411 
1412 	hash_test_key_t test_keys[] = {
1413 		/* Key 1 */
1414 		{ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1415 		  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1416 		/* Key 2 */
1417 		{ "Jefe", 4 },
1418 		/* Key 3 */
1419 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1420 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1421 		/* Key 4 */
1422 		{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1423 		  "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1424 		  "\x15\x16\x17\x18\x19", 25 },
1425 #if 0
1426 		/* Key 5 */
1427 		{ "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1428 		  "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1429 #endif
1430 		/* Key 6 */
1431 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1432 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1433 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1434 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1435 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1436 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1437 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1438 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1439 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1440 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1441 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1442 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1443 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1444 		/* Key 7 */
1445 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1446 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1447 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1448 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1449 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1450 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1451 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1452 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1453 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1454 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1455 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1456 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1457 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1458 		{ "", 0 }
1459 	};
1460 
1461 	hash_test_key_t *test_key = test_keys;
1462 
1463 	while (testcase->input != NULL && testcase->result != NULL) {
1464 		memmove(buffer, test_key->key, test_key->len);
1465 		isc_hmacsha384_init(&hmacsha384, buffer, test_key->len);
1466 		isc_hmacsha384_update(&hmacsha384,
1467 				      (const isc_uint8_t *) testcase->input,
1468 				      testcase->input_len);
1469 		isc_hmacsha384_sign(&hmacsha384, digest, ISC_SHA384_DIGESTLENGTH);
1470 		tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
1471 		ATF_CHECK_STREQ(str, testcase->result);
1472 
1473 		testcase++;
1474 		test_key++;
1475 	}
1476 }
1477 
1478 /* HMAC-SHA512 test */
1479 ATF_TC(isc_hmacsha512);
1480 ATF_TC_HEAD(isc_hmacsha512, tc) {
1481 	atf_tc_set_md_var(tc, "descr", "HMAC-SHA512 examples from RFC4634");
1482 }
1483 ATF_TC_BODY(isc_hmacsha512, tc) {
1484 	isc_hmacsha512_t hmacsha512;
1485 
1486 	UNUSED(tc);
1487 
1488 	/*
1489 	 * These are the various test vectors.  All of these are passed
1490 	 * through the hash function and the results are compared to the
1491 	 * result specified here.
1492 	 */
1493 	hash_testcase_t testcases[] = {
1494 		/* Test 1 */
1495 		{
1496 			TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1497 			"0x87AA7CDEA5EF619D4FF0B4241A1D6CB02379F4E2CE4EC2"
1498 				"787AD0B30545E17CDEDAA833B7D6B8A702038B27"
1499 				"4EAEA3F4E4BE9D914EEB61F1702E696C203A126854",
1500 			1
1501 		},
1502 		/* Test 2 */
1503 		{
1504 			TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1505 				   "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1506 				   "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1507 			"0x164B7A7BFCF819E2E395FBE73B56E0A387BD64222E831F"
1508 				"D610270CD7EA2505549758BF75C05A994A6D034F"
1509 				"65F8F0E6FDCAEAB1A34D4A6B4B636E070A38BCE737",
1510 			1
1511 		},
1512 		/* Test 3 */
1513 		{
1514 			TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1515 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1516 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1517 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1518 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1519 			"0xFA73B0089D56A284EFB0F0756C890BE9B1B5DBDD8EE81A"
1520 				"3655F83E33B2279D39BF3E848279A722C806B485"
1521 				"A47E67C807B946A337BEE8942674278859E13292FB",
1522 			1
1523 		},
1524 		/* Test 4 */
1525 		{
1526 			TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1527 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1528 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1529 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1530 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1531 			"0xB0BA465637458C6990E5A8C5F61D4AF7E576D97FF94B87"
1532 				"2DE76F8050361EE3DBA91CA5C11AA25EB4D67927"
1533 				"5CC5788063A5F19741120C4F2DE2ADEBEB10A298DD",
1534 			1
1535 		},
1536 #if 0
1537 		/* Test 5 -- unimplemented optional functionality */
1538 		{
1539 			TEST_INPUT("Test With Truncation"),
1540 			"0x4C1A03424B55E07FE7F27BE1",
1541 			1
1542 		},
1543 #endif
1544 		/* Test 6 */
1545 		{
1546 			TEST_INPUT("Test Using Larger Than Block-Size Key - "
1547 				   "Hash Key First"),
1548 			"0x80B24263C7C1A3EBB71493C1DD7BE8B49B46D1F41B4AEE"
1549 				"C1121B013783F8F3526B56D037E05F2598BD0FD2"
1550 				"215D6A1E5295E64F73F63F0AEC8B915A985D786598",
1551 			1
1552 		},
1553 		/* Test 7 */
1554 		{
1555 			TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1556 				   "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1557 				   "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1558 				   "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1559 				   "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1560 				   "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1561 				   "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1562 				   "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1563 				   "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1564 				   "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1565 				   "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1566 				   "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1567 				   "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1568 				   "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1569 				   "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1570 				   "\x6d\x2e"),
1571 			"0xE37B6A775DC87DBAA4DFA9F96E5E3FFDDEBD71F8867289"
1572 				"865DF5A32D20CDC944B6022CAC3C4982B10D5EEB"
1573 				"55C3E4DE15134676FB6DE0446065C97440FA8C6A58",
1574 			1
1575 		},
1576 		{ NULL, 0, NULL, 1 }
1577 	};
1578 
1579 	hash_testcase_t *testcase = testcases;
1580 
1581 	hash_test_key_t test_keys[] = {
1582 		/* Key 1 */
1583 		{ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1584 		  "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1585 		/* Key 2 */
1586 		{ "Jefe", 4 },
1587 		/* Key 3 */
1588 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1589 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1590 		/* Key 4 */
1591 		{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1592 		  "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1593 		  "\x15\x16\x17\x18\x19", 25 },
1594 #if 0
1595 		/* Key 5 */
1596 		{ "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1597 		  "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1598 #endif
1599 		/* Key 6 */
1600 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1601 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1602 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1603 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1604 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1605 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1606 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1607 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1608 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1609 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1610 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1611 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1612 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1613 		/* Key 7 */
1614 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1615 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1616 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1617 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1618 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1619 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1620 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1621 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1622 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1623 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1624 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1625 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1626 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1627 		{ "", 0 }
1628 	};
1629 
1630 	hash_test_key_t *test_key = test_keys;
1631 
1632 	while (testcase->input != NULL && testcase->result != NULL) {
1633 		memmove(buffer, test_key->key, test_key->len);
1634 		isc_hmacsha512_init(&hmacsha512, buffer, test_key->len);
1635 		isc_hmacsha512_update(&hmacsha512,
1636 				      (const isc_uint8_t *) testcase->input,
1637 				      testcase->input_len);
1638 		isc_hmacsha512_sign(&hmacsha512, digest, ISC_SHA512_DIGESTLENGTH);
1639 		tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
1640 		ATF_CHECK_STREQ(str, testcase->result);
1641 
1642 		testcase++;
1643 		test_key++;
1644 	}
1645 }
1646 
1647 
1648 /* HMAC-MD5 Test */
1649 ATF_TC(isc_hmacmd5);
1650 ATF_TC_HEAD(isc_hmacmd5, tc) {
1651 	atf_tc_set_md_var(tc, "descr", "HMAC-MD5 examples from RFC2104");
1652 }
1653 ATF_TC_BODY(isc_hmacmd5, tc) {
1654 	isc_hmacmd5_t hmacmd5;
1655 
1656 	UNUSED(tc);
1657 
1658 	/*
1659 	 * These are the various test vectors.  All of these are passed
1660 	 * through the hash function and the results are compared to the
1661 	 * result specified here.
1662 	 */
1663 	hash_testcase_t testcases[] = {
1664 		/* Test 1 */
1665 		{
1666 			TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1667 			"0x9294727A3638BB1C13F48EF8158BFC9D",
1668 			1
1669 		},
1670 		/* Test 2 */
1671 		{
1672 			TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79"
1673 				   "\x61\x20\x77\x61\x6e\x74\x20\x66\x6f"
1674 				   "\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1675 			"0x750C783E6AB0B503EAA86E310A5DB738", 1
1676 		},
1677 		/* Test 3 */
1678 		{
1679 			TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1680 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1681 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1682 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1683 				   "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1684 			"0x56BE34521D144C88DBB8C733F0E8B3F6",
1685 			1
1686 		},
1687 		/* Test 4 */
1688 		{
1689 			TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1690 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1691 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1692 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1693 				   "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1694 			"0x697EAF0ACA3A3AEA3A75164746FFAA79",
1695 			1
1696 		},
1697 #if 0
1698 		/* Test 5 -- unimplemented optional functionality */
1699 		{
1700 			TEST_INPUT("Test With Truncation"),
1701 			"0x4C1A03424B55E07FE7F27BE1",
1702 			1
1703 		},
1704 		/* Test 6 -- unimplemented optional functionality */
1705 		{
1706 			TEST_INPUT("Test Using Larger Than Block-Size Key - "
1707 				   "Hash Key First"),
1708 			"0xAA4AE5E15272D00E95705637CE8A3B55ED402112",
1709 			1
1710 		 },
1711 		/* Test 7 -- unimplemented optional functionality */
1712 		{
1713 			TEST_INPUT("Test Using Larger Than Block-Size Key and "
1714 				   "Larger Than One Block-Size Data"),
1715 			"0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91",
1716 			1
1717 		},
1718 #endif
1719 		{ NULL, 0, NULL, 1 }
1720 	};
1721 
1722 	hash_testcase_t *testcase = testcases;
1723 
1724 	hash_test_key_t test_keys[] = {
1725 		/* Key 1 */
1726 		{ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1727 		  "\x0b\x0b\x0b\x0b\x0b\x0b", 16 },
1728 		/* Key 2 */
1729 		{ "Jefe", 4 },
1730 		/* Key 3 */
1731 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1732 		  "\xaa\xaa\xaa\xaa\xaa\xaa", 16 },
1733 		/* Key 4 */
1734 		{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1735 		  "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1736 		  "\x15\x16\x17\x18\x19", 25 },
1737 #if 0
1738 		/* Key 5 */
1739 		{ "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1740 		  "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1741 		/* Key 6 */
1742 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1743 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1744 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1745 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1746 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1747 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1748 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1749 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1750 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1751 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1752 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1753 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1754 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1755 		/* Key 7 */
1756 		{ "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1757 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1758 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1759 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1760 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1761 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1762 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1763 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1764 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1765 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1766 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1767 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1768 		  "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
1769 #endif
1770 		{ "", 0 }
1771 	};
1772 
1773 	hash_test_key_t *test_key = test_keys;
1774 
1775 	while (testcase->input != NULL && testcase->result != NULL) {
1776 		memmove(buffer, test_key->key, test_key->len);
1777 		isc_hmacmd5_init(&hmacmd5, buffer, test_key->len);
1778 		isc_hmacmd5_update(&hmacmd5,
1779 				   (const isc_uint8_t *) testcase->input,
1780 				   testcase->input_len);
1781 		isc_hmacmd5_sign(&hmacmd5, digest);
1782 		tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
1783 		ATF_CHECK_STREQ(str, testcase->result);
1784 
1785 		testcase++;
1786 		test_key++;
1787 	}
1788 }
1789 
1790 /* CRC64 Test */
1791 ATF_TC(isc_crc64);
1792 ATF_TC_HEAD(isc_crc64, tc) {
1793 	atf_tc_set_md_var(tc, "descr", "64-bit cyclic redundancy check");
1794 }
1795 ATF_TC_BODY(isc_crc64, tc) {
1796 	isc_uint64_t crc;
1797 	int i;
1798 
1799 	UNUSED(tc);
1800 
1801 	hash_testcase_t testcases[] = {
1802 		{
1803 			TEST_INPUT(""),
1804 			"0x0000000000000000", 1
1805 		},
1806 		{
1807 			TEST_INPUT("a"),
1808 			"0x9AA9C0AC27F473CE", 1
1809 		},
1810 		{
1811 			TEST_INPUT("abc"),
1812 			"0x0297F4F93A818B04", 1
1813 		},
1814 		{
1815 			TEST_INPUT("message digest"),
1816 			"0xF47B357AEAF97352", 1
1817 		},
1818 		{
1819 			TEST_INPUT("abcdefghijklmnopqrstuvwxyz"),
1820 			"0xA1AA8B21F979F059", 1
1821 		},
1822 		{
1823 			TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
1824 				   "nopqrstuvwxyz0123456789"),
1825 			"0xFBB6781EF7A86DA3", 1
1826 		},
1827 		{
1828 			TEST_INPUT("123456789012345678901234567890123456789"
1829 				   "01234567890123456789012345678901234567890"),
1830 			"0x4A87E7C873EBE581", 1
1831 		},
1832 		{ NULL, 0, NULL, 1 }
1833 	};
1834 
1835 	hash_testcase_t *testcase = testcases;
1836 
1837 	while (testcase->input != NULL && testcase->result != NULL) {
1838 		isc_crc64_init(&crc);
1839 		for(i = 0; i < testcase->repeats; i++) {
1840 			isc_crc64_update(&crc,
1841 				       (const isc_uint8_t *) testcase->input,
1842 				       testcase->input_len);
1843 		}
1844 		isc_crc64_final(&crc);
1845 		tohexstr((unsigned char *) &crc, sizeof(crc), str);
1846 		ATF_CHECK_STREQ(str, testcase->result);
1847 
1848 		testcase++;
1849 	}
1850 }
1851 
1852 /*
1853  * Main
1854  */
1855 ATF_TP_ADD_TCS(tp) {
1856 	ATF_TP_ADD_TC(tp, isc_hmacmd5);
1857 	ATF_TP_ADD_TC(tp, isc_hmacsha1);
1858 	ATF_TP_ADD_TC(tp, isc_hmacsha224);
1859 	ATF_TP_ADD_TC(tp, isc_hmacsha256);
1860 	ATF_TP_ADD_TC(tp, isc_hmacsha384);
1861 	ATF_TP_ADD_TC(tp, isc_hmacsha512);
1862 	ATF_TP_ADD_TC(tp, isc_md5);
1863 	ATF_TP_ADD_TC(tp, isc_sha1);
1864 	ATF_TP_ADD_TC(tp, isc_sha224);
1865 	ATF_TP_ADD_TC(tp, isc_sha256);
1866 	ATF_TP_ADD_TC(tp, isc_sha384);
1867 	ATF_TP_ADD_TC(tp, isc_sha512);
1868 	ATF_TP_ADD_TC(tp, isc_crc64);
1869 	return (atf_no_error());
1870 }
1871 
1872