1/* 2 * Copyright (C) 2011, 2012 Internet Systems Consortium, Inc. ("ISC") 3 * 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. 7 * 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. 15 */ 16 17/* $Id$ */ 18 19/* ! \file */ 20 21#include <config.h> 22 23#include <atf-c.h> 24 25#include <stdio.h> 26#include <string.h> 27 28#include <isc/hmacmd5.h> 29#include <isc/hmacsha.h> 30#include <isc/md5.h> 31#include <isc/sha1.h> 32#include <isc/util.h> 33#include <isc/string.h> 34 35/* 36 * Test data from RFC6234 37 */ 38 39unsigned char digest[ISC_SHA512_DIGESTLENGTH]; 40unsigned char buffer[1024]; 41const char *s; 42char str[ISC_SHA512_DIGESTLENGTH]; 43unsigned char key[20]; 44int i = 0; 45 46isc_result_t 47tohexstr(unsigned char *d, unsigned int len, char *out); 48/* 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 53 * 54 * 'out' MUST point to an array of at least len / 2 + 1 55 * 56 * Return values: ISC_R_SUCCESS if the operation is sucessful 57 */ 58 59isc_result_t 60tohexstr(unsigned char *d, unsigned int len, char *out) { 61 62 out[0]='\0'; 63 char c_ret[] = "AA"; 64 unsigned int i; 65 strcat(out, "0x"); 66 for (i = 0; i < len; i++) { 67 sprintf(c_ret, "%02X", d[i]); 68 strcat(out, c_ret); 69 } 70 strcat(out, "\0"); 71 return (ISC_R_SUCCESS); 72} 73 74 75#define TEST_INPUT(x) (x), sizeof(x)-1 76 77typedef struct hash_testcase { 78 const char *input; 79 size_t input_len; 80 const char *result; 81 int repeats; 82} hash_testcase_t; 83 84typedef struct hash_test_key { 85 const char *key; 86 const int len; 87} hash_test_key_t; 88 89/* non-hmac tests */ 90 91ATF_TC(isc_sha1); 92ATF_TC_HEAD(isc_sha1, tc) { 93 atf_tc_set_md_var(tc, "descr", "sha1 examples from RFC4634"); 94} 95ATF_TC_BODY(isc_sha1, tc) { 96 isc_sha1_t sha1; 97 98 UNUSED(tc); 99 100 /* 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. 104 */ 105 hash_testcase_t testcases[] = { 106 /* Test 1 */ 107 { 108 TEST_INPUT("abc"), 109 "0xA9993E364706816ABA3E25717850C26C9CD0D89D", 110 1 111 }, 112 /* Test 2 */ 113 { 114 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijk" 115 "ljklmklmnlmnomnopnopq"), 116 "0x84983E441C3BD26EBAAE4AA1F95129E5E54670F1", 117 1 118 }, 119 /* Test 3 */ 120 { 121 TEST_INPUT("a") /* times 1000000 */, 122 "0x34AA973CD4C4DAA4F61EEB2BDBAD27316534016F", 123 1000000 124 }, 125 /* Test 4 -- exact multiple of 512 bits */ 126 { 127 TEST_INPUT("01234567012345670123456701234567"), 128 "0xDEA356A2CDDD90C7A7ECEDC5EBB563934F460452", 129 20 /* 20 times */ 130 }, 131#if 0 132 /* Test 5 -- optional feature, not implemented */ 133 { 134 TEST_INPUT(""), 135 /* "extrabits": 0x98 , "numberextrabits": 5 */ 136 "0x29826B003B906E660EFF4027CE98AF3531AC75BA", 137 1 138 }, 139#endif 140 /* Test 6 */ 141 { 142 TEST_INPUT("\x5e"), 143 "0x5E6F80A34A9798CAFC6A5DB96CC57BA4C4DB59C2", 144 1 145 }, 146#if 0 147 /* Test 7 -- optional feature, not implemented */ 148 { 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 }, 153#endif 154 /* Test 8 */ 155 { 156 TEST_INPUT("\x9a\x7d\xfd\xf1\xec\xea\xd0\x6e\xd6\x46" 157 "\xaa\x55\xfe\x75\x71\x46"), 158 "0x82ABFF6605DBE1C17DEF12A394FA22A82B544A35", 159 1 160 }, 161#if 0 162 /* Test 9 -- optional feature, not implemented */ 163 { 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", 174 1 175 }, 176#endif 177 /* Test 10 */ 178 { 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" 195 "\xcd\xbb\xfb"), 196 "0xCB0082C8F197D260991BA6A460E76E202BAD27B3", 197 1 198 }, 199 { NULL, 0, NULL, 1 } 200 }; 201 202 hash_testcase_t *testcase = testcases; 203 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); 210 } 211 isc_sha1_final(&sha1, digest); 212 tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str); 213 ATF_CHECK_STREQ(str, testcase->result); 214 215 testcase++; 216 } 217} 218 219 220ATF_TC(isc_sha224); 221ATF_TC_HEAD(isc_sha224, tc) { 222 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634"); 223} 224ATF_TC_BODY(isc_sha224, tc) { 225 isc_sha224_t sha224; 226 227 UNUSED(tc); 228 229 /* 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. 233 */ 234 hash_testcase_t testcases[] = { 235 /* Test 1 */ 236 { 237 TEST_INPUT("abc"), 238 "0x23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7" 239 "E36C9DA7", 240 1 241 }, 242 /* Test 2 */ 243 { 244 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijklj" 245 "klmklmnlmnomnopnopq"), 246 "0x75388B16512776CC5DBA5DA1FD890150B0C6455CB4F58B" 247 "1952522525", 248 1 249 }, 250 /* Test 3 */ 251 { 252 TEST_INPUT("a"), 253 "0x20794655980C91D8BBB4C1EA97618A4BF03F42581948B2" 254 "EE4EE7AD67", 255 1000000 256 }, 257 /* Test 4 */ 258 { 259 TEST_INPUT("01234567012345670123456701234567"), 260 "0x567F69F168CD7844E65259CE658FE7AADFA25216E68ECA" 261 "0EB7AB8262", 262 20 263 }, 264#if 0 265 /* Test 5 -- unimplemented optional functionality */ 266 { 267 TEST_INPUT(""), 268 "0xXXX", 269 1 270 }, 271#endif 272 /* Test 6 */ 273 { 274 TEST_INPUT("\x07"), 275 "0x00ECD5F138422B8AD74C9799FD826C531BAD2FCABC7450" 276 "BEE2AA8C2A", 277 1 278 }, 279#if 0 280 /* Test 7 -- unimplemented optional functionality */ 281 { 282 TEST_INPUT(""), 283 "0xXXX", 284 1 285 }, 286#endif 287 /* Test 8 */ 288 { 289 TEST_INPUT("\x18\x80\x40\x05\xdd\x4f\xbd\x15\x56\x29" 290 "\x9d\x6f\x9d\x93\xdf\x62"), 291 "0xDF90D78AA78821C99B40BA4C966921ACCD8FFB1E98AC38" 292 "8E56191DB1", 293 1 294 }, 295#if 0 296 /* Test 9 */ 297 { 298 TEST_INPUT(""), 299 "0xXXX", 300 1 301 }, 302#endif 303 /* Test 10 */ 304 { 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" 321 "\x87\x82\x73"), 322 "0x0B31894EC8937AD9B91BDFBCBA294D9ADEFAA18E09305E" 323 "9F20D5C3A4", 324 1 325 }, 326 { NULL, 0, NULL, 1 } 327 }; 328 329 hash_testcase_t *testcase = testcases; 330 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); 337 } 338 isc_sha224_final(digest, &sha224); 339 /* 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); 344 */ 345 tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str); 346 ATF_CHECK_STREQ(str, testcase->result); 347 348 testcase++; 349 } 350 351} 352 353ATF_TC(isc_sha256); 354ATF_TC_HEAD(isc_sha256, tc) { 355 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634"); 356} 357ATF_TC_BODY(isc_sha256, tc) { 358 isc_sha256_t sha256; 359 360 UNUSED(tc); 361 362 /* 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. 366 */ 367 hash_testcase_t testcases[] = { 368 /* Test 1 */ 369 { 370 TEST_INPUT("abc"), 371 "0xBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A" 372 "9CB410FF61F20015AD", 373 1 374 }, 375 /* Test 2 */ 376 { 377 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijkljk" 378 "lmklmnlmnomnopnopq"), 379 "0x248D6A61D20638B8E5C026930C3E6039A33CE45964FF21" 380 "67F6ECEDD419DB06C1", 381 1 382 }, 383 /* Test 3 */ 384 { 385 TEST_INPUT("a"), 386 "0xCDC76E5C9914FB9281A1C7E284D73E67F1809A48A49720" 387 "0E046D39CCC7112CD0", 388 1000000 }, 389 /* Test 4 */ 390 { 391 TEST_INPUT("01234567012345670123456701234567"), 392 "0x594847328451BDFA85056225462CC1D867D877FB388DF0" 393 "CE35F25AB5562BFBB5", 394 20 395 }, 396#if 0 397 /* Test 5 -- unimplemented optional functionality */ 398 { 399 TEST_INPUT(""), 400 "0xXXX", 401 1 402 }, 403#endif 404 /* Test 6 */ 405 { 406 TEST_INPUT("\x19"), 407 "0x68AA2E2EE5DFF96E3355E6C7EE373E3D6A4E17F75F9518" 408 "D843709C0C9BC3E3D4", 409 1 410 }, 411#if 0 412 /* Test 7 -- unimplemented optional functionality */ 413 { 414 TEST_INPUT(""), 415 "0xXXX", 416 1 417 }, 418#endif 419 /* Test 8 */ 420 { 421 TEST_INPUT("\xe3\xd7\x25\x70\xdc\xdd\x78\x7c\xe3" 422 "\x88\x7a\xb2\xcd\x68\x46\x52"), 423 "0x175EE69B02BA9B58E2B0A5FD13819CEA573F3940A94F82" 424 "5128CF4209BEABB4E8", 425 1 426 }, 427#if 0 428 /* Test 9 -- unimplemented optional functionality */ 429 { 430 TEST_INPUT(""), 431 "0xXXX", 432 1 433 }, 434#endif 435 /* Test 10 */ 436 { 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" 453 "\x3d\x54\xd6"), 454 "0x97DBCA7DF46D62C8A422C941DD7E835B8AD3361763F7E9" 455 "B2D95F4F0DA6E1CCBC", 456 1 457 }, 458 { NULL, 0, NULL, 1 } 459 }; 460 461 hash_testcase_t *testcase = testcases; 462 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); 469 } 470 isc_sha256_final(digest, &sha256); 471 /* 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); 476 */ 477 tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str); 478 ATF_CHECK_STREQ(str, testcase->result); 479 480 testcase++; 481 } 482 483} 484 485ATF_TC(isc_sha384); 486ATF_TC_HEAD(isc_sha384, tc) { 487 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634"); 488} 489ATF_TC_BODY(isc_sha384, tc) { 490 isc_sha384_t sha384; 491 492 UNUSED(tc); 493 494 /* 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. 498 */ 499 hash_testcase_t testcases[] = { 500 /* Test 1 */ 501 { 502 TEST_INPUT("abc"), 503 "0xCB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1" 504 "631A8B605A43FF5BED8086072BA1E7CC2358BAEC" 505 "A134C825A7", 506 1 507 }, 508 /* Test 2 */ 509 { 510 TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl" 511 "fghijklmghijklmnhijklmnoijklmnopjklmnopq" 512 "klmnopqrlmnopqrsmnopqrstnopqrstu"), 513 "0x09330C33F71147E83D192FC782CD1B4753111B173B3B05" 514 "D22FA08086E3B0F712FCC7C71A557E2DB966C3E9" 515 "FA91746039", 516 1 517 }, 518 /* Test 3 */ 519 { 520 TEST_INPUT("a"), 521 "0x9D0E1809716474CB086E834E310A4A1CED149E9C00F248" 522 "527972CEC5704C2A5B07B8B3DC38ECC4EBAE97DD" 523 "D87F3D8985", 524 1000000 525 }, 526 /* Test 4 */ 527 { 528 TEST_INPUT("01234567012345670123456701234567"), 529 "0x2FC64A4F500DDB6828F6A3430B8DD72A368EB7F3A8322A" 530 "70BC84275B9C0B3AB00D27A5CC3C2D224AA6B61A" 531 "0D79FB4596", 532 20 533 }, 534#if 0 535 /* Test 5 -- unimplemented optional functionality */ 536 { 537 TEST_INPUT(""), 538 "0xXXX", 539 1 540 }, 541#endif 542 /* Test 6 */ 543 { TEST_INPUT("\xb9"), 544 "0xBC8089A19007C0B14195F4ECC74094FEC64F01F9092928" 545 "2C2FB392881578208AD466828B1C6C283D2722CF" 546 "0AD1AB6938", 547 1 548 }, 549#if 0 550 /* Test 7 -- unimplemented optional functionality */ 551 { 552 TEST_INPUT(""), 553 "0xXXX", 554 1 555 }, 556#endif 557 /* Test 8 */ 558 { 559 TEST_INPUT("\xa4\x1c\x49\x77\x79\xc0\x37\x5f\xf1" 560 "\x0a\x7f\x4e\x08\x59\x17\x39"), 561 "0xC9A68443A005812256B8EC76B00516F0DBB74FAB26D665" 562 "913F194B6FFB0E91EA9967566B58109CBC675CC2" 563 "08E4C823F7", 564 1 565 }, 566#if 0 567 /* Test 9 -- unimplemented optional functionality */ 568 { 569 TEST_INPUT(""), 570 "0xXXX", 571 1 572 }, 573#endif 574 /* Test 10 */ 575 { 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" 601 "0CFF1288C0", 602 1 603 }, 604 { NULL, 0, NULL, 1 } 605 }; 606 607 hash_testcase_t *testcase = testcases; 608 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); 615 } 616 isc_sha384_final(digest, &sha384); 617 /* 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); 622 */ 623 tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str); 624 ATF_CHECK_STREQ(str, testcase->result); 625 626 testcase++; 627 } 628 629} 630 631ATF_TC(isc_sha512); 632ATF_TC_HEAD(isc_sha512, tc) { 633 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634"); 634} 635ATF_TC_BODY(isc_sha512, tc) { 636 isc_sha512_t sha512; 637 638 UNUSED(tc); 639 640 /* 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. 644 */ 645 hash_testcase_t testcases[] = { 646 /* Test 1 */ 647 { 648 TEST_INPUT("abc"), 649 "0xDDAF35A193617ABACC417349AE20413112E6FA4E89A97E" 650 "A20A9EEEE64B55D39A2192992A274FC1A836BA3C" 651 "23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F", 652 1 653 }, 654 /* Test 2 */ 655 { 656 TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl" 657 "fghijklmghijklmnhijklmnoijklmnopjklmnopq" 658 "klmnopqrlmnopqrsmnopqrstnopqrstu"), 659 "0x8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7F" 660 "A17299AEADB6889018501D289E4900F7E4331B99" 661 "DEC4B5433AC7D329EEB6DD26545E96E55B874BE909", 662 1 663 }, 664 /* Test 3 */ 665 { 666 TEST_INPUT("a"), 667 "0xE718483D0CE769644E2E42C7BC15B4638E1F98B13B2044" 668 "285632A803AFA973EBDE0FF244877EA60A4CB043" 669 "2CE577C31BEB009C5C2C49AA2E4EADB217AD8CC09B", 670 1000000 671 }, 672 /* Test 4 */ 673 { 674 TEST_INPUT("01234567012345670123456701234567"), 675 "0x89D05BA632C699C31231DED4FFC127D5A894DAD412C0E0" 676 "24DB872D1ABD2BA8141A0F85072A9BE1E2AA04CF" 677 "33C765CB510813A39CD5A84C4ACAA64D3F3FB7BAE9", 678 20 679 }, 680#if 0 681 /* Test 5 -- unimplemented optional functionality */ 682 { 683 TEST_INPUT(""), 684 "0xXXX", 685 1 686 }, 687#endif 688 /* Test 6 */ 689 { 690 TEST_INPUT("\xD0"), 691 "0x9992202938E882E73E20F6B69E68A0A7149090423D93C8" 692 "1BAB3F21678D4ACEEEE50E4E8CAFADA4C85A54EA" 693 "8306826C4AD6E74CECE9631BFA8A549B4AB3FBBA15", 694 1 695 }, 696#if 0 697 /* Test 7 -- unimplemented optional functionality */ 698 { 699 TEST_INPUT(""), 700 "0xXXX", 701 1 702 }, 703#endif 704 /* Test 8 */ 705 { 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", 711 1 712 }, 713#if 0 714 /* Test 9 -- unimplemented optional functionality */ 715 { 716 TEST_INPUT(""), 717 "0xXXX", 718 1 719 }, 720#endif 721 /* Test 10 */ 722 { 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", 749 1 750 }, 751 { NULL, 0, NULL, 1 } 752 }; 753 754 hash_testcase_t *testcase = testcases; 755 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); 762 } 763 isc_sha512_final(digest, &sha512); 764 /* 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); 769 */ 770 tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str); 771 ATF_CHECK_STREQ(str, testcase->result); 772 773 testcase++; 774 } 775 776} 777 778ATF_TC(isc_md5); 779ATF_TC_HEAD(isc_md5, tc) { 780 atf_tc_set_md_var(tc, "descr", "md5 example from RFC1321"); 781} 782ATF_TC_BODY(isc_md5, tc) { 783 isc_md5_t md5; 784 785 UNUSED(tc); 786 787 /* 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. 791 */ 792 hash_testcase_t testcases[] = { 793 { 794 TEST_INPUT(""), 795 "0xD41D8CD98F00B204E9800998ECF8427E", 796 1 797 }, 798 { 799 TEST_INPUT("a"), 800 "0x0CC175B9C0F1B6A831C399E269772661", 801 1 802 }, 803 { 804 TEST_INPUT("abc"), 805 "0x900150983CD24FB0D6963F7D28E17F72", 806 1 807 }, 808 { 809 TEST_INPUT("message digest"), 810 "0xF96B697D7CB7938D525A2F31AAF161D0", 811 1 812 }, 813 { 814 TEST_INPUT("abcdefghijklmnopqrstuvwxyz"), 815 "0xC3FCD3D76192E4007DFB496CCA67E13B", 816 1 817 }, 818 { 819 TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm" 820 "nopqrstuvwxyz0123456789"), 821 "0xD174AB98D277D9F5A5611C2C9F419D9F", 822 1 823 }, 824 { 825 TEST_INPUT("123456789012345678901234567890123456789" 826 "01234567890123456789012345678901234567890"), 827 "0x57EDF4A22BE3C955AC49DA2E2107B67A", 828 1 829 }, 830 { NULL, 0, NULL, 1 } 831 }; 832 833 hash_testcase_t *testcase = testcases; 834 835 while (testcase->input != NULL && testcase->result != NULL) { 836 isc_md5_init(&md5); 837 for(i = 0; i < testcase->repeats; i++) { 838 isc_md5_update(&md5, 839 (const isc_uint8_t *) testcase->input, 840 testcase->input_len); 841 } 842 isc_md5_final(&md5, digest); 843 tohexstr(digest, ISC_MD5_DIGESTLENGTH, str); 844 ATF_CHECK_STREQ(str, testcase->result); 845 846 testcase++; 847 } 848} 849 850/* HMAC-SHA1 test */ 851ATF_TC(isc_hmacsha1); 852ATF_TC_HEAD(isc_hmacsha1, tc) { 853 atf_tc_set_md_var(tc, "descr", "HMAC-SHA1 examples from RFC2104"); 854} 855ATF_TC_BODY(isc_hmacsha1, tc) { 856 isc_hmacsha1_t hmacsha1; 857 858 UNUSED(tc); 859 /* 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. 863 */ 864 hash_testcase_t testcases[] = { 865 /* Test 1 */ 866 { 867 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 868 "0xB617318655057264E28BC0B6FB378C8EF146BE00", 869 1 870 }, 871 /* Test 2 */ 872 { 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", 877 1 878 }, 879 /* Test 3 */ 880 { 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", 887 1 888 }, 889 /* Test 4 */ 890 { 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", 897 1 898 }, 899#if 0 900 /* Test 5 -- unimplemented optional functionality */ 901 { 902 TEST_INPUT("Test With Truncation"), 903 "0x4C1A03424B55E07FE7F27BE1", 904 1 905 }, 906#endif 907 /* Test 6 */ 908 { 909 TEST_INPUT("Test Using Larger Than Block-Size Key - " 910 "Hash Key First"), 911 "0xAA4AE5E15272D00E95705637CE8A3B55ED402112", 1 }, 912 /* Test 7 */ 913 { 914 TEST_INPUT("Test Using Larger Than Block-Size Key and " 915 "Larger Than One Block-Size Data"), 916 "0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 917 1 918 }, 919 { NULL, 0, NULL, 1 } 920 }; 921 922 hash_testcase_t *testcase = testcases; 923 924 hash_test_key_t test_keys[] = { 925 /* Key 1 */ 926 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 927 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 }, 928 /* Key 2 */ 929 { "Jefe", 4 }, 930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\xaa\xaa\xaa\xaa\xaa" 959 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80 }, 960 { "", 0 } 961 }; 962 963 hash_test_key_t *test_key = test_keys; 964 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); 974 975 testcase++; 976 test_key++; 977 } 978} 979 980/* HMAC-SHA224 test */ 981ATF_TC(isc_hmacsha224); 982ATF_TC_HEAD(isc_hmacsha224, tc) { 983 atf_tc_set_md_var(tc, "descr", "HMAC-SHA224 examples from RFC4634"); 984} 985ATF_TC_BODY(isc_hmacsha224, tc) { 986 isc_hmacsha224_t hmacsha224; 987 988 UNUSED(tc); 989 990 /* 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. 994 */ 995 hash_testcase_t testcases[] = { 996 /* Test 1 */ 997 { 998 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 999 "0x896FB1128ABBDF196832107CD49DF33F47B4B1169912BA" 1000 "4F53684B22", 1001 1 1002 }, 1003 /* Test 2 */ 1004 { 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" 1009 "08FD05E44", 1010 1 1011 }, 1012 /* Test 3 */ 1013 { 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" 1020 "D1EC8333EA", 1021 1 1022 }, 1023 /* Test 4 */ 1024 { 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" 1031 "2DE7AFEC5A", 1032 1 1033 }, 1034#if 0 1035 /* Test 5 -- unimplemented optional functionality */ 1036 { 1037 TEST_INPUT("Test With Truncation"), 1038 "0x4C1A03424B55E07FE7F27BE1", 1039 1 1040 }, 1041#endif 1042 /* Test 6 */ 1043 { 1044 TEST_INPUT("Test Using Larger Than Block-Size Key - " 1045 "Hash Key First"), 1046 "0x95E9A0DB962095ADAEBE9B2D6F0DBCE2D499F112F2D2B7" 1047 "273FA6870E", 1048 1 1049 }, 1050 /* Test 7 */ 1051 { 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" 1067 "\x6d\x2e"), 1068 "0x3A854166AC5D9F023F54D517D0B39DBD946770DB9C2B95" 1069 "C9F6F565D1", 1070 1 1071 }, 1072 { NULL, 0, NULL, 1 } 1073 }; 1074 1075 hash_testcase_t *testcase = testcases; 1076 1077 hash_test_key_t test_keys[] = { 1078 /* Key 1 */ 1079 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 1080 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 }, 1081 /* Key 2 */ 1082 { "Jefe", 4 }, 1083 /* Key 3 */ 1084 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 1085 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 }, 1086 /* Key 4 */ 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 }, 1090#if 0 1091 /* Key 5 */ 1092 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 1093 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 }, 1094#endif 1095 /* Key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\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 }, 1123 { "", 0 } 1124 }; 1125 1126 hash_test_key_t *test_key = test_keys; 1127 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); 1137 1138 testcase++; 1139 test_key++; 1140 } 1141} 1142 1143/* HMAC-SHA256 test */ 1144ATF_TC(isc_hmacsha256); 1145ATF_TC_HEAD(isc_hmacsha256, tc) { 1146 atf_tc_set_md_var(tc, "descr", "HMAC-SHA256 examples from RFC4634"); 1147} 1148ATF_TC_BODY(isc_hmacsha256, tc) { 1149 isc_hmacsha256_t hmacsha256; 1150 1151 UNUSED(tc); 1152 1153 /* 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. 1157 */ 1158 hash_testcase_t testcases[] = { 1159 /* Test 1 */ 1160 { 1161 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 1162 "0xB0344C61D8DB38535CA8AFCEAF0BF12B881DC200C9833D" 1163 "A726E9376C2E32CFF7", 1164 1 1165 }, 1166 /* Test 2 */ 1167 { 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", 1173 1 1174 }, 1175 /* Test 3 */ 1176 { 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", 1184 1 1185 }, 1186 /* Test 4 */ 1187 { 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", 1195 1 1196 }, 1197#if 0 1198 /* Test 5 -- unimplemented optional functionality */ 1199 { 1200 TEST_INPUT("Test With Truncation"), 1201 "0x4C1A03424B55E07FE7F27BE1", 1202 1 1203 }, 1204#endif 1205 /* Test 6 */ 1206 { 1207 TEST_INPUT("Test Using Larger Than Block-Size Key - " 1208 "Hash Key First"), 1209 "0x60E431591EE0B67F0D8A26AACBF5B77F8E0BC6213728C5" 1210 "140546040F0EE37F54", 1211 1 1212 }, 1213 /* Test 7 */ 1214 { 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" 1230 "\x6d\x2e"), 1231 "0x9B09FFA71B942FCB27635FBCD5B0E944BFDC63644F0713" 1232 "938A7F51535C3A35E2", 1233 1 1234 }, 1235 { NULL, 0, NULL, 1 } 1236 }; 1237 1238 hash_testcase_t *testcase = testcases; 1239 1240 hash_test_key_t test_keys[] = { 1241 /* Key 1 */ 1242 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 1243 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 }, 1244 /* Key 2 */ 1245 { "Jefe", 4 }, 1246 /* Key 3 */ 1247 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 1248 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 }, 1249 /* Key 4 */ 1250 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 1251 "\x0b\x0c\x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\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 }, 1286 { "", 0 } 1287 }; 1288 1289 hash_test_key_t *test_key = test_keys; 1290 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); 1300 1301 testcase++; 1302 test_key++; 1303 } 1304} 1305 1306/* HMAC-SHA384 test */ 1307ATF_TC(isc_hmacsha384); 1308ATF_TC_HEAD(isc_hmacsha384, tc) { 1309 atf_tc_set_md_var(tc, "descr", "HMAC-SHA384 examples from RFC4634"); 1310} 1311ATF_TC_BODY(isc_hmacsha384, tc) { 1312 isc_hmacsha384_t hmacsha384; 1313 1314 UNUSED(tc); 1315 1316 /* 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. 1320 */ 1321 hash_testcase_t testcases[] = { 1322 /* Test 1 */ 1323 { 1324 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 1325 "0xAFD03944D84895626B0825F4AB46907F15F9DADBE4101E" 1326 "C682AA034C7CEBC59CFAEA9EA9076EDE7F4AF152" 1327 "E8B2FA9CB6", 1328 1 1329 }, 1330 /* Test 2 */ 1331 { 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" 1337 "ECFAB21649", 1338 1 1339 }, 1340 /* Test 3 */ 1341 { 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" 1349 "E101A34F27", 1350 1 1351 }, 1352 /* Test 4 */ 1353 { 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" 1361 "86C674CFFB", 1362 1 1363 }, 1364#if 0 1365 /* Test 5 -- unimplemented optional functionality */ 1366 { 1367 TEST_INPUT("Test With Truncation"), 1368 "0x4C1A03424B55E07FE7F27BE1", 1369 1 1370 }, 1371#endif 1372 /* Test 6 */ 1373 { 1374 TEST_INPUT("Test Using Larger Than Block-Size Key - " 1375 "Hash Key First"), 1376 "0x4ECE084485813E9088D2C63A041BC5B44F9EF1012A2B58" 1377 "8F3CD11F05033AC4C60C2EF6AB4030FE8296248D" 1378 "F163F44952", 1379 1 1380 }, 1381 /* Test 7 */ 1382 { 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" 1398 "\x6d\x2e"), 1399 "0x6617178E941F020D351E2F254E8FD32C602420FEB0B8FB" 1400 "9ADCCEBB82461E99C5A678CC31E799176D3860E6" 1401 "110C46523E", 1402 1 1403 }, 1404 { NULL, 0, NULL, 1 } 1405 }; 1406 1407 hash_testcase_t *testcase = testcases; 1408 1409 hash_test_key_t test_keys[] = { 1410 /* Key 1 */ 1411 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 1412 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 }, 1413 /* Key 2 */ 1414 { "Jefe", 4 }, 1415 /* Key 3 */ 1416 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 1417 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 }, 1418 /* Key 4 */ 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 }, 1422#if 0 1423 /* Key 5 */ 1424 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 1425 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 }, 1426#endif 1427 /* Key 6 */ 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 }, 1441 /* Key 7 */ 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 }, 1455 { "", 0 } 1456 }; 1457 1458 hash_test_key_t *test_key = test_keys; 1459 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); 1469 1470 testcase++; 1471 test_key++; 1472 } 1473} 1474 1475/* HMAC-SHA512 test */ 1476ATF_TC(isc_hmacsha512); 1477ATF_TC_HEAD(isc_hmacsha512, tc) { 1478 atf_tc_set_md_var(tc, "descr", "HMAC-SHA512 examples from RFC4634"); 1479} 1480ATF_TC_BODY(isc_hmacsha512, tc) { 1481 isc_hmacsha512_t hmacsha512; 1482 1483 UNUSED(tc); 1484 1485 /* 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. 1489 */ 1490 hash_testcase_t testcases[] = { 1491 /* Test 1 */ 1492 { 1493 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 1494 "0x87AA7CDEA5EF619D4FF0B4241A1D6CB02379F4E2CE4EC2" 1495 "787AD0B30545E17CDEDAA833B7D6B8A702038B27" 1496 "4EAEA3F4E4BE9D914EEB61F1702E696C203A126854", 1497 1 1498 }, 1499 /* Test 2 */ 1500 { 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", 1507 1 1508 }, 1509 /* Test 3 */ 1510 { 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", 1519 1 1520 }, 1521 /* Test 4 */ 1522 { 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", 1531 1 1532 }, 1533#if 0 1534 /* Test 5 -- unimplemented optional functionality */ 1535 { 1536 TEST_INPUT("Test With Truncation"), 1537 "0x4C1A03424B55E07FE7F27BE1", 1538 1 1539 }, 1540#endif 1541 /* Test 6 */ 1542 { 1543 TEST_INPUT("Test Using Larger Than Block-Size Key - " 1544 "Hash Key First"), 1545 "0x80B24263C7C1A3EBB71493C1DD7BE8B49B46D1F41B4AEE" 1546 "C1121B013783F8F3526B56D037E05F2598BD0FD2" 1547 "215D6A1E5295E64F73F63F0AEC8B915A985D786598", 1548 1 1549 }, 1550 /* Test 7 */ 1551 { 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" 1567 "\x6d\x2e"), 1568 "0xE37B6A775DC87DBAA4DFA9F96E5E3FFDDEBD71F8867289" 1569 "865DF5A32D20CDC944B6022CAC3C4982B10D5EEB" 1570 "55C3E4DE15134676FB6DE0446065C97440FA8C6A58", 1571 1 1572 }, 1573 { NULL, 0, NULL, 1 } 1574 }; 1575 1576 hash_testcase_t *testcase = testcases; 1577 1578 hash_test_key_t test_keys[] = { 1579 /* Key 1 */ 1580 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 1581 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 }, 1582 /* Key 2 */ 1583 { "Jefe", 4 }, 1584 /* Key 3 */ 1585 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 1586 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 }, 1587 /* Key 4 */ 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 }, 1591#if 0 1592 /* Key 5 */ 1593 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 1594 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\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a" 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 }, 1624 { "", 0 } 1625 }; 1626 1627 hash_test_key_t *test_key = test_keys; 1628 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); 1638 1639 testcase++; 1640 test_key++; 1641 } 1642} 1643 1644 1645/* HMAC-MD5 Test */ 1646ATF_TC(isc_hmacmd5); 1647ATF_TC_HEAD(isc_hmacmd5, tc) { 1648 atf_tc_set_md_var(tc, "descr", "HMAC-MD5 examples from RFC2104"); 1649} 1650ATF_TC_BODY(isc_hmacmd5, tc) { 1651 isc_hmacmd5_t hmacmd5; 1652 1653 UNUSED(tc); 1654 1655 /* 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. 1659 */ 1660 hash_testcase_t testcases[] = { 1661 /* Test 1 */ 1662 { 1663 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 1664 "0x9294727A3638BB1C13F48EF8158BFC9D", 1665 1 1666 }, 1667 /* Test 2 */ 1668 { 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 1673 }, 1674 /* Test 3 */ 1675 { 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", 1682 1 1683 }, 1684 /* Test 4 */ 1685 { 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", 1692 1 1693 }, 1694#if 0 1695 /* Test 5 -- unimplemented optional functionality */ 1696 { 1697 TEST_INPUT("Test With Truncation"), 1698 "0x4C1A03424B55E07FE7F27BE1", 1699 1 1700 }, 1701 /* Test 6 -- unimplemented optional functionality */ 1702 { 1703 TEST_INPUT("Test Using Larger Than Block-Size Key - " 1704 "Hash Key First"), 1705 "0xAA4AE5E15272D00E95705637CE8A3B55ED402112", 1706 1 1707 }, 1708 /* Test 7 -- unimplemented optional functionality */ 1709 { 1710 TEST_INPUT("Test Using Larger Than Block-Size Key and " 1711 "Larger Than One Block-Size Data"), 1712 "0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 1713 1 1714 }, 1715#endif 1716 { NULL, 0, NULL, 1 } 1717 }; 1718 1719 hash_testcase_t *testcase = testcases; 1720 1721 hash_test_key_t test_keys[] = { 1722 /* Key 1 */ 1723 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 1724 "\x0b\x0b\x0b\x0b\x0b\x0b", 16 }, 1725 /* Key 2 */ 1726 { "Jefe", 4 }, 1727 /* Key 3 */ 1728 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 1729 "\xaa\xaa\xaa\xaa\xaa\xaa", 16 }, 1730 /* Key 4 */ 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 }, 1734#if 0 1735 /* Key 5 */ 1736 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 1737 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 }, 1738 /* Key 6 */ 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 }, 1752 /* Key 7 */ 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 }, 1766#endif 1767 { "", 0 } 1768 }; 1769 1770 hash_test_key_t *test_key = test_keys; 1771 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); 1781 1782 testcase++; 1783 test_key++; 1784 } 1785} 1786 1787/* 1788 * Main 1789 */ 1790ATF_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()); 1804} 1805 1806