2 * Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
28 #include <isc/hmacmd5.h>
29 #include <isc/hmacsha.h>
33 #include <isc/string.h>
36 * Test data from RFC6234
39 unsigned char digest[ISC_SHA512_DIGESTLENGTH];
40 unsigned char buffer[1024];
42 char str[ISC_SHA512_DIGESTLENGTH];
43 unsigned char key[20];
47 tohexstr(unsigned char *d, unsigned int len, char *out);
49 * Precondition: a hexadecimal number in *d, the length of that number in len,
50 * and a pointer to a character array to put the output (*out).
51 * Postcondition: A String representation of the given hexadecimal number is
52 * placed into the array *out
54 * 'out' MUST point to an array of at least len / 2 + 1
56 * Return values: ISC_R_SUCCESS if the operation is sucessful
60 tohexstr(unsigned char *d, unsigned int len, char *out) {
66 for (i = 0; i < len; i++) {
67 sprintf(c_ret, "%02X", d[i]);
71 return (ISC_R_SUCCESS);
75 #define TEST_INPUT(x) (x), sizeof(x)-1
77 typedef struct hash_testcase {
84 typedef struct hash_test_key {
92 ATF_TC_HEAD(isc_sha1, tc) {
93 atf_tc_set_md_var(tc, "descr", "sha1 examples from RFC4634");
95 ATF_TC_BODY(isc_sha1, tc) {
101 * These are the various test vectors. All of these are passed
102 * through the hash function and the results are compared to the
103 * result specified here.
105 hash_testcase_t testcases[] = {
109 "0xA9993E364706816ABA3E25717850C26C9CD0D89D",
114 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijk"
115 "ljklmklmnlmnomnopnopq"),
116 "0x84983E441C3BD26EBAAE4AA1F95129E5E54670F1",
121 TEST_INPUT("a") /* times 1000000 */,
122 "0x34AA973CD4C4DAA4F61EEB2BDBAD27316534016F",
125 /* Test 4 -- exact multiple of 512 bits */
127 TEST_INPUT("01234567012345670123456701234567"),
128 "0xDEA356A2CDDD90C7A7ECEDC5EBB563934F460452",
132 /* Test 5 -- optional feature, not implemented */
135 /* "extrabits": 0x98 , "numberextrabits": 5 */
136 "0x29826B003B906E660EFF4027CE98AF3531AC75BA",
143 "0x5E6F80A34A9798CAFC6A5DB96CC57BA4C4DB59C2",
147 /* Test 7 -- optional feature, not implemented */
149 TEST_INPUT("\x49\xb2\xae\xc2\x59\x4b\xbe\x3a"
150 "\x3b\x11\x75\x42\xd9\x4a\xc8"),
151 /* "extrabits": 0x80, "numberextrabits": 3 */
152 "0x6239781E03729919C01955B3FFA8ACB60B988340", 1 },
156 TEST_INPUT("\x9a\x7d\xfd\xf1\xec\xea\xd0\x6e\xd6\x46"
157 "\xaa\x55\xfe\x75\x71\x46"),
158 "0x82ABFF6605DBE1C17DEF12A394FA22A82B544A35",
162 /* Test 9 -- optional feature, not implemented */
164 TEST_INPUT("\x65\xf9\x32\x99\x5b\xa4\xce\x2c\xb1\xb4"
165 "\xa2\xe7\x1a\xe7\x02\x20\xaa\xce\xc8\x96"
166 "\x2d\xd4\x49\x9c\xbd\x7c\x88\x7a\x94\xea"
167 "\xaa\x10\x1e\xa5\xaa\xbc\x52\x9b\x4e\x7e"
168 "\x43\x66\x5a\x5a\xf2\xcd\x03\xfe\x67\x8e"
169 "\xa6\xa5\x00\x5b\xba\x3b\x08\x22\x04\xc2"
170 "\x8b\x91\x09\xf4\x69\xda\xc9\x2a\xaa\xb3"
171 "\xaa\x7c\x11\xa1\xb3\x2a"),
172 /* "extrabits": 0xE0 , "numberextrabits": 3 */
173 "0x8C5B2A5DDAE5A97FC7F9D85661C672ADBF7933D4",
179 TEST_INPUT("\xf7\x8f\x92\x14\x1b\xcd\x17\x0a\xe8\x9b"
180 "\x4f\xba\x15\xa1\xd5\x9f\x3f\xd8\x4d\x22"
181 "\x3c\x92\x51\xbd\xac\xbb\xae\x61\xd0\x5e"
182 "\xd1\x15\xa0\x6a\x7c\xe1\x17\xb7\xbe\xea"
183 "\xd2\x44\x21\xde\xd9\xc3\x25\x92\xbd\x57"
184 "\xed\xea\xe3\x9c\x39\xfa\x1f\xe8\x94\x6a"
185 "\x84\xd0\xcf\x1f\x7b\xee\xad\x17\x13\xe2"
186 "\xe0\x95\x98\x97\x34\x7f\x67\xc8\x0b\x04"
187 "\x00\xc2\x09\x81\x5d\x6b\x10\xa6\x83\x83"
188 "\x6f\xd5\x56\x2a\x56\xca\xb1\xa2\x8e\x81"
189 "\xb6\x57\x66\x54\x63\x1c\xf1\x65\x66\xb8"
190 "\x6e\x3b\x33\xa1\x08\xb0\x53\x07\xc0\x0a"
191 "\xff\x14\xa7\x68\xed\x73\x50\x60\x6a\x0f"
192 "\x85\xe6\xa9\x1d\x39\x6f\x5b\x5c\xbe\x57"
193 "\x7f\x9b\x38\x80\x7c\x7d\x52\x3d\x6d\x79"
194 "\x2f\x6e\xbc\x24\xa4\xec\xf2\xb3\xa4\x27"
196 "0xCB0082C8F197D260991BA6A460E76E202BAD27B3",
202 hash_testcase_t *testcase = testcases;
204 while (testcase->input != NULL && testcase->result != NULL) {
205 isc_sha1_init(&sha1);
206 for(i = 0; i < testcase->repeats; i++) {
207 isc_sha1_update(&sha1,
208 (const isc_uint8_t *) testcase->input,
209 testcase->input_len);
211 isc_sha1_final(&sha1, digest);
212 tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
213 ATF_CHECK_STREQ(str, testcase->result);
221 ATF_TC_HEAD(isc_sha224, tc) {
222 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
224 ATF_TC_BODY(isc_sha224, tc) {
230 * These are the various test vectors. All of these are passed
231 * through the hash function and the results are compared to the
232 * result specified here.
234 hash_testcase_t testcases[] = {
238 "0x23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7"
244 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijklj"
245 "klmklmnlmnomnopnopq"),
246 "0x75388B16512776CC5DBA5DA1FD890150B0C6455CB4F58B"
253 "0x20794655980C91D8BBB4C1EA97618A4BF03F42581948B2"
259 TEST_INPUT("01234567012345670123456701234567"),
260 "0x567F69F168CD7844E65259CE658FE7AADFA25216E68ECA"
265 /* Test 5 -- unimplemented optional functionality */
275 "0x00ECD5F138422B8AD74C9799FD826C531BAD2FCABC7450"
280 /* Test 7 -- unimplemented optional functionality */
289 TEST_INPUT("\x18\x80\x40\x05\xdd\x4f\xbd\x15\x56\x29"
290 "\x9d\x6f\x9d\x93\xdf\x62"),
291 "0xDF90D78AA78821C99B40BA4C966921ACCD8FFB1E98AC38"
305 TEST_INPUT("\x55\xb2\x10\x07\x9c\x61\xb5\x3a\xdd\x52"
306 "\x06\x22\xd1\xac\x97\xd5\xcd\xbe\x8c\xb3"
307 "\x3a\xa0\xae\x34\x45\x17\xbe\xe4\xd7\xba"
308 "\x09\xab\xc8\x53\x3c\x52\x50\x88\x7a\x43"
309 "\xbe\xbb\xac\x90\x6c\x2e\x18\x37\xf2\x6b"
310 "\x36\xa5\x9a\xe3\xbe\x78\x14\xd5\x06\x89"
311 "\x6b\x71\x8b\x2a\x38\x3e\xcd\xac\x16\xb9"
312 "\x61\x25\x55\x3f\x41\x6f\xf3\x2c\x66\x74"
313 "\xc7\x45\x99\xa9\x00\x53\x86\xd9\xce\x11"
314 "\x12\x24\x5f\x48\xee\x47\x0d\x39\x6c\x1e"
315 "\xd6\x3b\x92\x67\x0c\xa5\x6e\xc8\x4d\xee"
316 "\xa8\x14\xb6\x13\x5e\xca\x54\x39\x2b\xde"
317 "\xdb\x94\x89\xbc\x9b\x87\x5a\x8b\xaf\x0d"
318 "\xc1\xae\x78\x57\x36\x91\x4a\xb7\xda\xa2"
319 "\x64\xbc\x07\x9d\x26\x9f\x2c\x0d\x7e\xdd"
320 "\xd8\x10\xa4\x26\x14\x5a\x07\x76\xf6\x7c"
322 "0x0B31894EC8937AD9B91BDFBCBA294D9ADEFAA18E09305E"
329 hash_testcase_t *testcase = testcases;
331 while (testcase->input != NULL && testcase->result != NULL) {
332 isc_sha224_init(&sha224);
333 for(i = 0; i < testcase->repeats; i++) {
334 isc_sha224_update(&sha224,
335 (const isc_uint8_t *) testcase->input,
336 testcase->input_len);
338 isc_sha224_final(digest, &sha224);
340 *API inconsistency BUG HERE
341 * in order to be consistant with the other isc_hash_final
342 * functions the call should be
343 * isc_sha224_final(&sha224, digest);
345 tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
346 ATF_CHECK_STREQ(str, testcase->result);
354 ATF_TC_HEAD(isc_sha256, tc) {
355 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
357 ATF_TC_BODY(isc_sha256, tc) {
363 * These are the various test vectors. All of these are passed
364 * through the hash function and the results are compared to the
365 * result specified here.
367 hash_testcase_t testcases[] = {
371 "0xBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A"
372 "9CB410FF61F20015AD",
377 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijkljk"
378 "lmklmnlmnomnopnopq"),
379 "0x248D6A61D20638B8E5C026930C3E6039A33CE45964FF21"
380 "67F6ECEDD419DB06C1",
386 "0xCDC76E5C9914FB9281A1C7E284D73E67F1809A48A49720"
387 "0E046D39CCC7112CD0",
391 TEST_INPUT("01234567012345670123456701234567"),
392 "0x594847328451BDFA85056225462CC1D867D877FB388DF0"
393 "CE35F25AB5562BFBB5",
397 /* Test 5 -- unimplemented optional functionality */
407 "0x68AA2E2EE5DFF96E3355E6C7EE373E3D6A4E17F75F9518"
408 "D843709C0C9BC3E3D4",
412 /* Test 7 -- unimplemented optional functionality */
421 TEST_INPUT("\xe3\xd7\x25\x70\xdc\xdd\x78\x7c\xe3"
422 "\x88\x7a\xb2\xcd\x68\x46\x52"),
423 "0x175EE69B02BA9B58E2B0A5FD13819CEA573F3940A94F82"
424 "5128CF4209BEABB4E8",
428 /* Test 9 -- unimplemented optional functionality */
437 TEST_INPUT("\x83\x26\x75\x4e\x22\x77\x37\x2f\x4f\xc1"
438 "\x2b\x20\x52\x7a\xfe\xf0\x4d\x8a\x05\x69"
439 "\x71\xb1\x1a\xd5\x71\x23\xa7\xc1\x37\x76"
440 "\x00\x00\xd7\xbe\xf6\xf3\xc1\xf7\xa9\x08"
441 "\x3a\xa3\x9d\x81\x0d\xb3\x10\x77\x7d\xab"
442 "\x8b\x1e\x7f\x02\xb8\x4a\x26\xc7\x73\x32"
443 "\x5f\x8b\x23\x74\xde\x7a\x4b\x5a\x58\xcb"
444 "\x5c\x5c\xf3\x5b\xce\xe6\xfb\x94\x6e\x5b"
445 "\xd6\x94\xfa\x59\x3a\x8b\xeb\x3f\x9d\x65"
446 "\x92\xec\xed\xaa\x66\xca\x82\xa2\x9d\x0c"
447 "\x51\xbc\xf9\x33\x62\x30\xe5\xd7\x84\xe4"
448 "\xc0\xa4\x3f\x8d\x79\xa3\x0a\x16\x5c\xba"
449 "\xbe\x45\x2b\x77\x4b\x9c\x71\x09\xa9\x7d"
450 "\x13\x8f\x12\x92\x28\x96\x6f\x6c\x0a\xdc"
451 "\x10\x6a\xad\x5a\x9f\xdd\x30\x82\x57\x69"
452 "\xb2\xc6\x71\xaf\x67\x59\xdf\x28\xeb\x39"
454 "0x97DBCA7DF46D62C8A422C941DD7E835B8AD3361763F7E9"
455 "B2D95F4F0DA6E1CCBC",
461 hash_testcase_t *testcase = testcases;
463 while (testcase->input != NULL && testcase->result != NULL) {
464 isc_sha256_init(&sha256);
465 for(i = 0; i < testcase->repeats; i++) {
466 isc_sha256_update(&sha256,
467 (const isc_uint8_t *) testcase->input,
468 testcase->input_len);
470 isc_sha256_final(digest, &sha256);
472 *API inconsistency BUG HERE
473 * in order to be consistant with the other isc_hash_final
474 * functions the call should be
475 * isc_sha224_final(&sha224, digest);
477 tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
478 ATF_CHECK_STREQ(str, testcase->result);
486 ATF_TC_HEAD(isc_sha384, tc) {
487 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
489 ATF_TC_BODY(isc_sha384, tc) {
495 * These are the various test vectors. All of these are passed
496 * through the hash function and the results are compared to the
497 * result specified here.
499 hash_testcase_t testcases[] = {
503 "0xCB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1"
504 "631A8B605A43FF5BED8086072BA1E7CC2358BAEC"
510 TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl"
511 "fghijklmghijklmnhijklmnoijklmnopjklmnopq"
512 "klmnopqrlmnopqrsmnopqrstnopqrstu"),
513 "0x09330C33F71147E83D192FC782CD1B4753111B173B3B05"
514 "D22FA08086E3B0F712FCC7C71A557E2DB966C3E9"
521 "0x9D0E1809716474CB086E834E310A4A1CED149E9C00F248"
522 "527972CEC5704C2A5B07B8B3DC38ECC4EBAE97DD"
528 TEST_INPUT("01234567012345670123456701234567"),
529 "0x2FC64A4F500DDB6828F6A3430B8DD72A368EB7F3A8322A"
530 "70BC84275B9C0B3AB00D27A5CC3C2D224AA6B61A"
535 /* Test 5 -- unimplemented optional functionality */
543 { TEST_INPUT("\xb9"),
544 "0xBC8089A19007C0B14195F4ECC74094FEC64F01F9092928"
545 "2C2FB392881578208AD466828B1C6C283D2722CF"
550 /* Test 7 -- unimplemented optional functionality */
559 TEST_INPUT("\xa4\x1c\x49\x77\x79\xc0\x37\x5f\xf1"
560 "\x0a\x7f\x4e\x08\x59\x17\x39"),
561 "0xC9A68443A005812256B8EC76B00516F0DBB74FAB26D665"
562 "913F194B6FFB0E91EA9967566B58109CBC675CC2"
567 /* Test 9 -- unimplemented optional functionality */
576 TEST_INPUT("\x39\x96\x69\xe2\x8f\x6b\x9c\x6d\xbc\xbb"
577 "\x69\x12\xec\x10\xff\xcf\x74\x79\x03\x49"
578 "\xb7\xdc\x8f\xbe\x4a\x8e\x7b\x3b\x56\x21"
579 "\xdb\x0f\x3e\x7d\xc8\x7f\x82\x32\x64\xbb"
580 "\xe4\x0d\x18\x11\xc9\xea\x20\x61\xe1\xc8"
581 "\x4a\xd1\x0a\x23\xfa\xc1\x72\x7e\x72\x02"
582 "\xfc\x3f\x50\x42\xe6\xbf\x58\xcb\xa8\xa2"
583 "\x74\x6e\x1f\x64\xf9\xb9\xea\x35\x2c\x71"
584 "\x15\x07\x05\x3c\xf4\xe5\x33\x9d\x52\x86"
585 "\x5f\x25\xcc\x22\xb5\xe8\x77\x84\xa1\x2f"
586 "\xc9\x61\xd6\x6c\xb6\xe8\x95\x73\x19\x9a"
587 "\x2c\xe6\x56\x5c\xbd\xf1\x3d\xca\x40\x38"
588 "\x32\xcf\xcb\x0e\x8b\x72\x11\xe8\x3a\xf3"
589 "\x2a\x11\xac\x17\x92\x9f\xf1\xc0\x73\xa5"
590 "\x1c\xc0\x27\xaa\xed\xef\xf8\x5a\xad\x7c"
591 "\x2b\x7c\x5a\x80\x3e\x24\x04\xd9\x6d\x2a"
592 "\x77\x35\x7b\xda\x1a\x6d\xae\xed\x17\x15"
593 "\x1c\xb9\xbc\x51\x25\xa4\x22\xe9\x41\xde"
594 "\x0c\xa0\xfc\x50\x11\xc2\x3e\xcf\xfe\xfd"
595 "\xd0\x96\x76\x71\x1c\xf3\xdb\x0a\x34\x40"
596 "\x72\x0e\x16\x15\xc1\xf2\x2f\xbc\x3c\x72"
597 "\x1d\xe5\x21\xe1\xb9\x9b\xa1\xbd\x55\x77"
598 "\x40\x86\x42\x14\x7e\xd0\x96"),
599 "0x4F440DB1E6EDD2899FA335F09515AA025EE177A79F4B4A"
600 "AF38E42B5C4DE660F5DE8FB2A5B2FBD2A3CBFFD2"
607 hash_testcase_t *testcase = testcases;
609 while (testcase->input != NULL && testcase->result != NULL) {
610 isc_sha384_init(&sha384);
611 for(i = 0; i < testcase->repeats; i++) {
612 isc_sha384_update(&sha384,
613 (const isc_uint8_t *) testcase->input,
614 testcase->input_len);
616 isc_sha384_final(digest, &sha384);
618 *API inconsistency BUG HERE
619 * in order to be consistant with the other isc_hash_final
620 * functions the call should be
621 * isc_sha224_final(&sha224, digest);
623 tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
624 ATF_CHECK_STREQ(str, testcase->result);
632 ATF_TC_HEAD(isc_sha512, tc) {
633 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
635 ATF_TC_BODY(isc_sha512, tc) {
641 * These are the various test vectors. All of these are passed
642 * through the hash function and the results are compared to the
643 * result specified here.
645 hash_testcase_t testcases[] = {
649 "0xDDAF35A193617ABACC417349AE20413112E6FA4E89A97E"
650 "A20A9EEEE64B55D39A2192992A274FC1A836BA3C"
651 "23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F",
656 TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl"
657 "fghijklmghijklmnhijklmnoijklmnopjklmnopq"
658 "klmnopqrlmnopqrsmnopqrstnopqrstu"),
659 "0x8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7F"
660 "A17299AEADB6889018501D289E4900F7E4331B99"
661 "DEC4B5433AC7D329EEB6DD26545E96E55B874BE909",
667 "0xE718483D0CE769644E2E42C7BC15B4638E1F98B13B2044"
668 "285632A803AFA973EBDE0FF244877EA60A4CB043"
669 "2CE577C31BEB009C5C2C49AA2E4EADB217AD8CC09B",
674 TEST_INPUT("01234567012345670123456701234567"),
675 "0x89D05BA632C699C31231DED4FFC127D5A894DAD412C0E0"
676 "24DB872D1ABD2BA8141A0F85072A9BE1E2AA04CF"
677 "33C765CB510813A39CD5A84C4ACAA64D3F3FB7BAE9",
681 /* Test 5 -- unimplemented optional functionality */
691 "0x9992202938E882E73E20F6B69E68A0A7149090423D93C8"
692 "1BAB3F21678D4ACEEEE50E4E8CAFADA4C85A54EA"
693 "8306826C4AD6E74CECE9631BFA8A549B4AB3FBBA15",
697 /* Test 7 -- unimplemented optional functionality */
706 TEST_INPUT("\x8d\x4e\x3c\x0e\x38\x89\x19\x14\x91\x81"
707 "\x6e\x9d\x98\xbf\xf0\xa0"),
708 "0xCB0B67A4B8712CD73C9AABC0B199E9269B20844AFB75AC"
709 "BDD1C153C9828924C3DDEDAAFE669C5FDD0BC66F"
710 "630F6773988213EB1B16F517AD0DE4B2F0C95C90F8",
714 /* Test 9 -- unimplemented optional functionality */
723 TEST_INPUT("\xa5\x5f\x20\xc4\x11\xaa\xd1\x32\x80\x7a"
724 "\x50\x2d\x65\x82\x4e\x31\xa2\x30\x54\x32"
725 "\xaa\x3d\x06\xd3\xe2\x82\xa8\xd8\x4e\x0d"
726 "\xe1\xde\x69\x74\xbf\x49\x54\x69\xfc\x7f"
727 "\x33\x8f\x80\x54\xd5\x8c\x26\xc4\x93\x60"
728 "\xc3\xe8\x7a\xf5\x65\x23\xac\xf6\xd8\x9d"
729 "\x03\xe5\x6f\xf2\xf8\x68\x00\x2b\xc3\xe4"
730 "\x31\xed\xc4\x4d\xf2\xf0\x22\x3d\x4b\xb3"
731 "\xb2\x43\x58\x6e\x1a\x7d\x92\x49\x36\x69"
732 "\x4f\xcb\xba\xf8\x8d\x95\x19\xe4\xeb\x50"
733 "\xa6\x44\xf8\xe4\xf9\x5e\xb0\xea\x95\xbc"
734 "\x44\x65\xc8\x82\x1a\xac\xd2\xfe\x15\xab"
735 "\x49\x81\x16\x4b\xbb\x6d\xc3\x2f\x96\x90"
736 "\x87\xa1\x45\xb0\xd9\xcc\x9c\x67\xc2\x2b"
737 "\x76\x32\x99\x41\x9c\xc4\x12\x8b\xe9\xa0"
738 "\x77\xb3\xac\xe6\x34\x06\x4e\x6d\x99\x28"
739 "\x35\x13\xdc\x06\xe7\x51\x5d\x0d\x73\x13"
740 "\x2e\x9a\x0d\xc6\xd3\xb1\xf8\xb2\x46\xf1"
741 "\xa9\x8a\x3f\xc7\x29\x41\xb1\xe3\xbb\x20"
742 "\x98\xe8\xbf\x16\xf2\x68\xd6\x4f\x0b\x0f"
743 "\x47\x07\xfe\x1e\xa1\xa1\x79\x1b\xa2\xf3"
744 "\xc0\xc7\x58\xe5\xf5\x51\x86\x3a\x96\xc9"
745 "\x49\xad\x47\xd7\xfb\x40\xd2"),
746 "0xC665BEFB36DA189D78822D10528CBF3B12B3EEF7260399"
747 "09C1A16A270D48719377966B957A878E72058477"
748 "9A62825C18DA26415E49A7176A894E7510FD1451F5",
754 hash_testcase_t *testcase = testcases;
756 while (testcase->input != NULL && testcase->result != NULL) {
757 isc_sha512_init(&sha512);
758 for(i = 0; i < testcase->repeats; i++) {
759 isc_sha512_update(&sha512,
760 (const isc_uint8_t *) testcase->input,
761 testcase->input_len);
763 isc_sha512_final(digest, &sha512);
765 *API inconsistency BUG HERE
766 * in order to be consistant with the other isc_hash_final
767 * functions the call should be
768 * isc_sha224_final(&sha224, digest);
770 tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
771 ATF_CHECK_STREQ(str, testcase->result);
779 ATF_TC_HEAD(isc_md5, tc) {
780 atf_tc_set_md_var(tc, "descr", "md5 example from RFC1321");
782 ATF_TC_BODY(isc_md5, tc) {
788 * These are the various test vectors. All of these are passed
789 * through the hash function and the results are compared to the
790 * result specified here.
792 hash_testcase_t testcases[] = {
795 "0xD41D8CD98F00B204E9800998ECF8427E",
800 "0x0CC175B9C0F1B6A831C399E269772661",
805 "0x900150983CD24FB0D6963F7D28E17F72",
809 TEST_INPUT("message digest"),
810 "0xF96B697D7CB7938D525A2F31AAF161D0",
814 TEST_INPUT("abcdefghijklmnopqrstuvwxyz"),
815 "0xC3FCD3D76192E4007DFB496CCA67E13B",
819 TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
820 "nopqrstuvwxyz0123456789"),
821 "0xD174AB98D277D9F5A5611C2C9F419D9F",
825 TEST_INPUT("123456789012345678901234567890123456789"
826 "01234567890123456789012345678901234567890"),
827 "0x57EDF4A22BE3C955AC49DA2E2107B67A",
833 hash_testcase_t *testcase = testcases;
835 while (testcase->input != NULL && testcase->result != NULL) {
837 for(i = 0; i < testcase->repeats; i++) {
839 (const isc_uint8_t *) testcase->input,
840 testcase->input_len);
842 isc_md5_final(&md5, digest);
843 tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
844 ATF_CHECK_STREQ(str, testcase->result);
851 ATF_TC(isc_hmacsha1);
852 ATF_TC_HEAD(isc_hmacsha1, tc) {
853 atf_tc_set_md_var(tc, "descr", "HMAC-SHA1 examples from RFC2104");
855 ATF_TC_BODY(isc_hmacsha1, tc) {
856 isc_hmacsha1_t hmacsha1;
860 * These are the various test vectors. All of these are passed
861 * through the hash function and the results are compared to the
862 * result specified here.
864 hash_testcase_t testcases[] = {
867 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
868 "0xB617318655057264E28BC0B6FB378C8EF146BE00",
873 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
874 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
875 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
876 "0xEFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79",
881 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
882 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
883 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
884 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
885 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
886 "0x125D7342B9AC11CD91A39AF48AA17B4F63F175D3",
891 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
892 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
893 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
894 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
895 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
896 "0x4C9007F4026250C6BC8414F9BF50C86C2D7235DA",
900 /* Test 5 -- unimplemented optional functionality */
902 TEST_INPUT("Test With Truncation"),
903 "0x4C1A03424B55E07FE7F27BE1",
909 TEST_INPUT("Test Using Larger Than Block-Size Key - "
911 "0xAA4AE5E15272D00E95705637CE8A3B55ED402112", 1 },
914 TEST_INPUT("Test Using Larger Than Block-Size Key and "
915 "Larger Than One Block-Size Data"),
916 "0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91",
922 hash_testcase_t *testcase = testcases;
924 hash_test_key_t test_keys[] = {
926 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
927 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
931 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
932 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
934 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
935 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
936 "\x15\x16\x17\x18\x19", 25 },
939 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
940 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
943 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
944 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
945 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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", 80 },
952 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
953 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
954 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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", 80 },
963 hash_test_key_t *test_key = test_keys;
965 while (testcase->input != NULL && testcase->result != NULL) {
966 memcpy(buffer, test_key->key, test_key->len);
967 isc_hmacsha1_init(&hmacsha1, buffer, test_key->len);
968 isc_hmacsha1_update(&hmacsha1,
969 (const isc_uint8_t *) testcase->input,
970 testcase->input_len);
971 isc_hmacsha1_sign(&hmacsha1, digest, ISC_SHA1_DIGESTLENGTH);
972 tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
973 ATF_CHECK_STREQ(str, testcase->result);
980 /* HMAC-SHA224 test */
981 ATF_TC(isc_hmacsha224);
982 ATF_TC_HEAD(isc_hmacsha224, tc) {
983 atf_tc_set_md_var(tc, "descr", "HMAC-SHA224 examples from RFC4634");
985 ATF_TC_BODY(isc_hmacsha224, tc) {
986 isc_hmacsha224_t hmacsha224;
991 * These are the various test vectors. All of these are passed
992 * through the hash function and the results are compared to the
993 * result specified here.
995 hash_testcase_t testcases[] = {
998 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
999 "0x896FB1128ABBDF196832107CD49DF33F47B4B1169912BA"
1005 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1006 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1007 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1008 "0xA30E01098BC6DBBF45690F3A7E9E6D0F8BBEA2A39E61480"
1014 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1015 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1016 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1017 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1018 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1019 "0x7FB3CB3588C6C1F6FFA9694D7D6AD2649365B0C1F65D69"
1025 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1026 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1027 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1028 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1029 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1030 "0x6C11506874013CAC6A2ABC1BB382627CEC6A90D86EFC01"
1035 /* Test 5 -- unimplemented optional functionality */
1037 TEST_INPUT("Test With Truncation"),
1038 "0x4C1A03424B55E07FE7F27BE1",
1044 TEST_INPUT("Test Using Larger Than Block-Size Key - "
1046 "0x95E9A0DB962095ADAEBE9B2D6F0DBCE2D499F112F2D2B7"
1052 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1053 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1054 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1055 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1056 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1057 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1058 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1059 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1060 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1061 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1062 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1063 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1064 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1065 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1066 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1068 "0x3A854166AC5D9F023F54D517D0B39DBD946770DB9C2B95"
1072 { NULL, 0, NULL, 1 }
1075 hash_testcase_t *testcase = testcases;
1077 hash_test_key_t test_keys[] = {
1079 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1080 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1084 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1085 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1087 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1088 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1089 "\x15\x16\x17\x18\x19", 25 },
1092 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1093 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1096 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1097 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1098 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1110 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1111 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1112 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1126 hash_test_key_t *test_key = test_keys;
1128 while (testcase->input != NULL && testcase->result != NULL) {
1129 memcpy(buffer, test_key->key, test_key->len);
1130 isc_hmacsha224_init(&hmacsha224, buffer, test_key->len);
1131 isc_hmacsha224_update(&hmacsha224,
1132 (const isc_uint8_t *) testcase->input,
1133 testcase->input_len);
1134 isc_hmacsha224_sign(&hmacsha224, digest, ISC_SHA224_DIGESTLENGTH);
1135 tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
1136 ATF_CHECK_STREQ(str, testcase->result);
1143 /* HMAC-SHA256 test */
1144 ATF_TC(isc_hmacsha256);
1145 ATF_TC_HEAD(isc_hmacsha256, tc) {
1146 atf_tc_set_md_var(tc, "descr", "HMAC-SHA256 examples from RFC4634");
1148 ATF_TC_BODY(isc_hmacsha256, tc) {
1149 isc_hmacsha256_t hmacsha256;
1154 * These are the various test vectors. All of these are passed
1155 * through the hash function and the results are compared to the
1156 * result specified here.
1158 hash_testcase_t testcases[] = {
1161 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1162 "0xB0344C61D8DB38535CA8AFCEAF0BF12B881DC200C9833D"
1163 "A726E9376C2E32CFF7",
1168 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1169 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1170 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1171 "0x5BDCC146BF60754E6A042426089575C75A003F089D2739"
1172 "839DEC58B964EC3843",
1177 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1178 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1179 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1180 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1181 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1182 "0x773EA91E36800E46854DB8EBD09181A72959098B3EF8C1"
1183 "22D9635514CED565FE",
1188 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1189 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1190 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1191 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1192 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1193 "0x82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8"
1194 "077A2E3FF46729665B",
1198 /* Test 5 -- unimplemented optional functionality */
1200 TEST_INPUT("Test With Truncation"),
1201 "0x4C1A03424B55E07FE7F27BE1",
1207 TEST_INPUT("Test Using Larger Than Block-Size Key - "
1209 "0x60E431591EE0B67F0D8A26AACBF5B77F8E0BC6213728C5"
1210 "140546040F0EE37F54",
1215 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1216 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1217 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1218 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1219 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1220 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1221 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1222 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1223 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1224 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1225 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1226 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1227 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1228 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1229 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1231 "0x9B09FFA71B942FCB27635FBCD5B0E944BFDC63644F0713"
1232 "938A7F51535C3A35E2",
1235 { NULL, 0, NULL, 1 }
1238 hash_testcase_t *testcase = testcases;
1240 hash_test_key_t test_keys[] = {
1242 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1243 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1247 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1248 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1250 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1251 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1252 "\x15\x16\x17\x18\x19", 25 },
1255 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1256 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1259 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1260 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1261 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1273 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1274 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1275 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1289 hash_test_key_t *test_key = test_keys;
1291 while (testcase->input != NULL && testcase->result != NULL) {
1292 memcpy(buffer, test_key->key, test_key->len);
1293 isc_hmacsha256_init(&hmacsha256, buffer, test_key->len);
1294 isc_hmacsha256_update(&hmacsha256,
1295 (const isc_uint8_t *) testcase->input,
1296 testcase->input_len);
1297 isc_hmacsha256_sign(&hmacsha256, digest, ISC_SHA256_DIGESTLENGTH);
1298 tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
1299 ATF_CHECK_STREQ(str, testcase->result);
1306 /* HMAC-SHA384 test */
1307 ATF_TC(isc_hmacsha384);
1308 ATF_TC_HEAD(isc_hmacsha384, tc) {
1309 atf_tc_set_md_var(tc, "descr", "HMAC-SHA384 examples from RFC4634");
1311 ATF_TC_BODY(isc_hmacsha384, tc) {
1312 isc_hmacsha384_t hmacsha384;
1317 * These are the various test vectors. All of these are passed
1318 * through the hash function and the results are compared to the
1319 * result specified here.
1321 hash_testcase_t testcases[] = {
1324 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1325 "0xAFD03944D84895626B0825F4AB46907F15F9DADBE4101E"
1326 "C682AA034C7CEBC59CFAEA9EA9076EDE7F4AF152"
1332 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1333 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1334 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1335 "0xAF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B"
1336 "47E42EC3736322445E8E2240CA5E69E2C78B3239"
1342 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1343 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1344 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1345 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1346 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1347 "0x88062608D3E6AD8A0AA2ACE014C8A86F0AA635D947AC9F"
1348 "EBE83EF4E55966144B2A5AB39DC13814B94E3AB6"
1354 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1355 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1356 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1357 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1358 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1359 "0x3E8A69B7783C25851933AB6290AF6CA77A998148085000"
1360 "9CC5577C6E1F573B4E6801DD23C4A7D679CCF8A3"
1365 /* Test 5 -- unimplemented optional functionality */
1367 TEST_INPUT("Test With Truncation"),
1368 "0x4C1A03424B55E07FE7F27BE1",
1374 TEST_INPUT("Test Using Larger Than Block-Size Key - "
1376 "0x4ECE084485813E9088D2C63A041BC5B44F9EF1012A2B58"
1377 "8F3CD11F05033AC4C60C2EF6AB4030FE8296248D"
1383 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1384 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1385 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1386 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1387 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1388 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1389 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1390 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1391 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1392 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1393 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1394 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1395 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1396 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1397 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1399 "0x6617178E941F020D351E2F254E8FD32C602420FEB0B8FB"
1400 "9ADCCEBB82461E99C5A678CC31E799176D3860E6"
1404 { NULL, 0, NULL, 1 }
1407 hash_testcase_t *testcase = testcases;
1409 hash_test_key_t test_keys[] = {
1411 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1412 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1416 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1417 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1419 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1420 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1421 "\x15\x16\x17\x18\x19", 25 },
1424 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1425 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1428 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1429 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1430 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1442 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1443 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1444 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1458 hash_test_key_t *test_key = test_keys;
1460 while (testcase->input != NULL && testcase->result != NULL) {
1461 memcpy(buffer, test_key->key, test_key->len);
1462 isc_hmacsha384_init(&hmacsha384, buffer, test_key->len);
1463 isc_hmacsha384_update(&hmacsha384,
1464 (const isc_uint8_t *) testcase->input,
1465 testcase->input_len);
1466 isc_hmacsha384_sign(&hmacsha384, digest, ISC_SHA384_DIGESTLENGTH);
1467 tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
1468 ATF_CHECK_STREQ(str, testcase->result);
1475 /* HMAC-SHA512 test */
1476 ATF_TC(isc_hmacsha512);
1477 ATF_TC_HEAD(isc_hmacsha512, tc) {
1478 atf_tc_set_md_var(tc, "descr", "HMAC-SHA512 examples from RFC4634");
1480 ATF_TC_BODY(isc_hmacsha512, tc) {
1481 isc_hmacsha512_t hmacsha512;
1486 * These are the various test vectors. All of these are passed
1487 * through the hash function and the results are compared to the
1488 * result specified here.
1490 hash_testcase_t testcases[] = {
1493 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1494 "0x87AA7CDEA5EF619D4FF0B4241A1D6CB02379F4E2CE4EC2"
1495 "787AD0B30545E17CDEDAA833B7D6B8A702038B27"
1496 "4EAEA3F4E4BE9D914EEB61F1702E696C203A126854",
1501 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
1502 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
1503 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1504 "0x164B7A7BFCF819E2E395FBE73B56E0A387BD64222E831F"
1505 "D610270CD7EA2505549758BF75C05A994A6D034F"
1506 "65F8F0E6FDCAEAB1A34D4A6B4B636E070A38BCE737",
1511 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1512 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1513 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1514 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1515 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1516 "0xFA73B0089D56A284EFB0F0756C890BE9B1B5DBDD8EE81A"
1517 "3655F83E33B2279D39BF3E848279A722C806B485"
1518 "A47E67C807B946A337BEE8942674278859E13292FB",
1523 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1524 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1525 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1526 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1527 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1528 "0xB0BA465637458C6990E5A8C5F61D4AF7E576D97FF94B87"
1529 "2DE76F8050361EE3DBA91CA5C11AA25EB4D67927"
1530 "5CC5788063A5F19741120C4F2DE2ADEBEB10A298DD",
1534 /* Test 5 -- unimplemented optional functionality */
1536 TEST_INPUT("Test With Truncation"),
1537 "0x4C1A03424B55E07FE7F27BE1",
1543 TEST_INPUT("Test Using Larger Than Block-Size Key - "
1545 "0x80B24263C7C1A3EBB71493C1DD7BE8B49B46D1F41B4AEE"
1546 "C1121B013783F8F3526B56D037E05F2598BD0FD2"
1547 "215D6A1E5295E64F73F63F0AEC8B915A985D786598",
1552 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
1553 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
1554 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
1555 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
1556 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
1557 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
1558 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
1559 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
1560 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
1561 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
1562 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
1563 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
1564 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
1565 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
1566 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
1568 "0xE37B6A775DC87DBAA4DFA9F96E5E3FFDDEBD71F8867289"
1569 "865DF5A32D20CDC944B6022CAC3C4982B10D5EEB"
1570 "55C3E4DE15134676FB6DE0446065C97440FA8C6A58",
1573 { NULL, 0, NULL, 1 }
1576 hash_testcase_t *testcase = testcases;
1578 hash_test_key_t test_keys[] = {
1580 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1581 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
1585 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1586 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
1588 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1589 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1590 "\x15\x16\x17\x18\x19", 25 },
1593 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1594 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1597 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1598 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1599 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1611 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1612 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1613 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1627 hash_test_key_t *test_key = test_keys;
1629 while (testcase->input != NULL && testcase->result != NULL) {
1630 memcpy(buffer, test_key->key, test_key->len);
1631 isc_hmacsha512_init(&hmacsha512, buffer, test_key->len);
1632 isc_hmacsha512_update(&hmacsha512,
1633 (const isc_uint8_t *) testcase->input,
1634 testcase->input_len);
1635 isc_hmacsha512_sign(&hmacsha512, digest, ISC_SHA512_DIGESTLENGTH);
1636 tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
1637 ATF_CHECK_STREQ(str, testcase->result);
1646 ATF_TC(isc_hmacmd5);
1647 ATF_TC_HEAD(isc_hmacmd5, tc) {
1648 atf_tc_set_md_var(tc, "descr", "HMAC-MD5 examples from RFC2104");
1650 ATF_TC_BODY(isc_hmacmd5, tc) {
1651 isc_hmacmd5_t hmacmd5;
1656 * These are the various test vectors. All of these are passed
1657 * through the hash function and the results are compared to the
1658 * result specified here.
1660 hash_testcase_t testcases[] = {
1663 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
1664 "0x9294727A3638BB1C13F48EF8158BFC9D",
1669 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79"
1670 "\x61\x20\x77\x61\x6e\x74\x20\x66\x6f"
1671 "\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
1672 "0x750C783E6AB0B503EAA86E310A5DB738", 1
1676 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1677 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1678 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1679 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
1680 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
1681 "0x56BE34521D144C88DBB8C733F0E8B3F6",
1686 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1687 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1688 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1689 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
1690 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
1691 "0x697EAF0ACA3A3AEA3A75164746FFAA79",
1695 /* Test 5 -- unimplemented optional functionality */
1697 TEST_INPUT("Test With Truncation"),
1698 "0x4C1A03424B55E07FE7F27BE1",
1701 /* Test 6 -- unimplemented optional functionality */
1703 TEST_INPUT("Test Using Larger Than Block-Size Key - "
1705 "0xAA4AE5E15272D00E95705637CE8A3B55ED402112",
1708 /* Test 7 -- unimplemented optional functionality */
1710 TEST_INPUT("Test Using Larger Than Block-Size Key and "
1711 "Larger Than One Block-Size Data"),
1712 "0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91",
1716 { NULL, 0, NULL, 1 }
1719 hash_testcase_t *testcase = testcases;
1721 hash_test_key_t test_keys[] = {
1723 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
1724 "\x0b\x0b\x0b\x0b\x0b\x0b", 16 },
1728 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1729 "\xaa\xaa\xaa\xaa\xaa\xaa", 16 },
1731 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
1732 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
1733 "\x15\x16\x17\x18\x19", 25 },
1736 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
1737 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
1739 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1740 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1741 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1753 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1754 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
1755 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
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\xaa", 131 },
1770 hash_test_key_t *test_key = test_keys;
1772 while (testcase->input != NULL && testcase->result != NULL) {
1773 memcpy(buffer, test_key->key, test_key->len);
1774 isc_hmacmd5_init(&hmacmd5, buffer, test_key->len);
1775 isc_hmacmd5_update(&hmacmd5,
1776 (const isc_uint8_t *) testcase->input,
1777 testcase->input_len);
1778 isc_hmacmd5_sign(&hmacmd5, digest);
1779 tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
1780 ATF_CHECK_STREQ(str, testcase->result);
1790 ATF_TP_ADD_TCS(tp) {
1791 ATF_TP_ADD_TC(tp, isc_hmacmd5);
1792 ATF_TP_ADD_TC(tp, isc_hmacsha1);
1793 ATF_TP_ADD_TC(tp, isc_hmacsha224);
1794 ATF_TP_ADD_TC(tp, isc_hmacsha256);
1795 ATF_TP_ADD_TC(tp, isc_hmacsha384);
1796 ATF_TP_ADD_TC(tp, isc_hmacsha512);
1797 ATF_TP_ADD_TC(tp, isc_md5);
1798 ATF_TP_ADD_TC(tp, isc_sha1);
1799 ATF_TP_ADD_TC(tp, isc_sha224);
1800 ATF_TP_ADD_TC(tp, isc_sha256);
1801 ATF_TP_ADD_TC(tp, isc_sha384);
1802 ATF_TP_ADD_TC(tp, isc_sha512);
1803 return (atf_no_error());