00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <atf-c.h>
00024
00025 #include <stdio.h>
00026 #include <string.h>
00027
00028 #include <isc/crc64.h>
00029 #include <isc/hmacmd5.h>
00030 #include <isc/hmacsha.h>
00031 #include <isc/md5.h>
00032 #include <isc/sha1.h>
00033 #include <isc/util.h>
00034 #include <isc/string.h>
00035
00036
00037
00038
00039
00040 unsigned char digest[ISC_SHA512_DIGESTLENGTH];
00041 unsigned char buffer[1024];
00042 const char *s;
00043 char str[2 * ISC_SHA512_DIGESTLENGTH + 3];
00044 unsigned char key[20];
00045
00046 isc_result_t
00047 tohexstr(unsigned char *d, unsigned int len, char *out);
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 isc_result_t
00060 tohexstr(unsigned char *d, unsigned int len, char *out) {
00061
00062 out[0]='\0';
00063 char c_ret[] = "AA";
00064 unsigned int i;
00065 strcat(out, "0x");
00066 for (i = 0; i < len; i++) {
00067 sprintf(c_ret, "%02X", d[i]);
00068 strcat(out, c_ret);
00069 }
00070 strcat(out, "\0");
00071 return (ISC_R_SUCCESS);
00072 }
00073
00074
00075 #define TEST_INPUT(x) (x), sizeof(x)-1
00076
00077 typedef struct hash_testcase {
00078 const char *input;
00079 size_t input_len;
00080 const char *result;
00081 int repeats;
00082 } hash_testcase_t;
00083
00084 typedef struct hash_test_key {
00085 const char *key;
00086 const int len;
00087 } hash_test_key_t;
00088
00089
00090
00091 ATF_TC(isc_sha1);
00092 ATF_TC_HEAD(isc_sha1, tc) {
00093 atf_tc_set_md_var(tc, "descr", "sha1 examples from RFC4634");
00094 }
00095 ATF_TC_BODY(isc_sha1, tc) {
00096 isc_sha1_t sha1;
00097 int i;
00098
00099 UNUSED(tc);
00100
00101
00102
00103
00104
00105
00106 hash_testcase_t testcases[] = {
00107
00108 {
00109 TEST_INPUT("abc"),
00110 "0xA9993E364706816ABA3E25717850C26C9CD0D89D",
00111 1
00112 },
00113
00114 {
00115 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijk"
00116 "ljklmklmnlmnomnopnopq"),
00117 "0x84983E441C3BD26EBAAE4AA1F95129E5E54670F1",
00118 1
00119 },
00120
00121 {
00122 TEST_INPUT("a") ,
00123 "0x34AA973CD4C4DAA4F61EEB2BDBAD27316534016F",
00124 1000000
00125 },
00126
00127 {
00128 TEST_INPUT("01234567012345670123456701234567"),
00129 "0xDEA356A2CDDD90C7A7ECEDC5EBB563934F460452",
00130 20
00131 },
00132 #if 0
00133
00134 {
00135 TEST_INPUT(""),
00136
00137 "0x29826B003B906E660EFF4027CE98AF3531AC75BA",
00138 1
00139 },
00140 #endif
00141
00142 {
00143 TEST_INPUT("\x5e"),
00144 "0x5E6F80A34A9798CAFC6A5DB96CC57BA4C4DB59C2",
00145 1
00146 },
00147 #if 0
00148
00149 {
00150 TEST_INPUT("\x49\xb2\xae\xc2\x59\x4b\xbe\x3a"
00151 "\x3b\x11\x75\x42\xd9\x4a\xc8"),
00152
00153 "0x6239781E03729919C01955B3FFA8ACB60B988340", 1 },
00154 #endif
00155
00156 {
00157 TEST_INPUT("\x9a\x7d\xfd\xf1\xec\xea\xd0\x6e\xd6\x46"
00158 "\xaa\x55\xfe\x75\x71\x46"),
00159 "0x82ABFF6605DBE1C17DEF12A394FA22A82B544A35",
00160 1
00161 },
00162 #if 0
00163
00164 {
00165 TEST_INPUT("\x65\xf9\x32\x99\x5b\xa4\xce\x2c\xb1\xb4"
00166 "\xa2\xe7\x1a\xe7\x02\x20\xaa\xce\xc8\x96"
00167 "\x2d\xd4\x49\x9c\xbd\x7c\x88\x7a\x94\xea"
00168 "\xaa\x10\x1e\xa5\xaa\xbc\x52\x9b\x4e\x7e"
00169 "\x43\x66\x5a\x5a\xf2\xcd\x03\xfe\x67\x8e"
00170 "\xa6\xa5\x00\x5b\xba\x3b\x08\x22\x04\xc2"
00171 "\x8b\x91\x09\xf4\x69\xda\xc9\x2a\xaa\xb3"
00172 "\xaa\x7c\x11\xa1\xb3\x2a"),
00173
00174 "0x8C5B2A5DDAE5A97FC7F9D85661C672ADBF7933D4",
00175 1
00176 },
00177 #endif
00178
00179 {
00180 TEST_INPUT("\xf7\x8f\x92\x14\x1b\xcd\x17\x0a\xe8\x9b"
00181 "\x4f\xba\x15\xa1\xd5\x9f\x3f\xd8\x4d\x22"
00182 "\x3c\x92\x51\xbd\xac\xbb\xae\x61\xd0\x5e"
00183 "\xd1\x15\xa0\x6a\x7c\xe1\x17\xb7\xbe\xea"
00184 "\xd2\x44\x21\xde\xd9\xc3\x25\x92\xbd\x57"
00185 "\xed\xea\xe3\x9c\x39\xfa\x1f\xe8\x94\x6a"
00186 "\x84\xd0\xcf\x1f\x7b\xee\xad\x17\x13\xe2"
00187 "\xe0\x95\x98\x97\x34\x7f\x67\xc8\x0b\x04"
00188 "\x00\xc2\x09\x81\x5d\x6b\x10\xa6\x83\x83"
00189 "\x6f\xd5\x56\x2a\x56\xca\xb1\xa2\x8e\x81"
00190 "\xb6\x57\x66\x54\x63\x1c\xf1\x65\x66\xb8"
00191 "\x6e\x3b\x33\xa1\x08\xb0\x53\x07\xc0\x0a"
00192 "\xff\x14\xa7\x68\xed\x73\x50\x60\x6a\x0f"
00193 "\x85\xe6\xa9\x1d\x39\x6f\x5b\x5c\xbe\x57"
00194 "\x7f\x9b\x38\x80\x7c\x7d\x52\x3d\x6d\x79"
00195 "\x2f\x6e\xbc\x24\xa4\xec\xf2\xb3\xa4\x27"
00196 "\xcd\xbb\xfb"),
00197 "0xCB0082C8F197D260991BA6A460E76E202BAD27B3",
00198 1
00199 },
00200 { NULL, 0, NULL, 1 }
00201 };
00202
00203 hash_testcase_t *testcase = testcases;
00204
00205 while (testcase->input != NULL && testcase->result != NULL) {
00206 isc_sha1_init(&sha1);
00207 for(i = 0; i < testcase->repeats; i++) {
00208 isc_sha1_update(&sha1,
00209 (const isc_uint8_t *) testcase->input,
00210 testcase->input_len);
00211 }
00212 isc_sha1_final(&sha1, digest);
00213 tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
00214 ATF_CHECK_STREQ(str, testcase->result);
00215
00216 testcase++;
00217 }
00218 }
00219
00220 ATF_TC(isc_sha224);
00221 ATF_TC_HEAD(isc_sha224, tc) {
00222 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
00223 }
00224 ATF_TC_BODY(isc_sha224, tc) {
00225 isc_sha224_t sha224;
00226 int i;
00227
00228 UNUSED(tc);
00229
00230
00231
00232
00233
00234
00235 hash_testcase_t testcases[] = {
00236
00237 {
00238 TEST_INPUT("abc"),
00239 "0x23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7"
00240 "E36C9DA7",
00241 1
00242 },
00243
00244 {
00245 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijklj"
00246 "klmklmnlmnomnopnopq"),
00247 "0x75388B16512776CC5DBA5DA1FD890150B0C6455CB4F58B"
00248 "1952522525",
00249 1
00250 },
00251
00252 {
00253 TEST_INPUT("a"),
00254 "0x20794655980C91D8BBB4C1EA97618A4BF03F42581948B2"
00255 "EE4EE7AD67",
00256 1000000
00257 },
00258
00259 {
00260 TEST_INPUT("01234567012345670123456701234567"),
00261 "0x567F69F168CD7844E65259CE658FE7AADFA25216E68ECA"
00262 "0EB7AB8262",
00263 20
00264 },
00265 #if 0
00266
00267 {
00268 TEST_INPUT(""),
00269 "0xXXX",
00270 1
00271 },
00272 #endif
00273
00274 {
00275 TEST_INPUT("\x07"),
00276 "0x00ECD5F138422B8AD74C9799FD826C531BAD2FCABC7450"
00277 "BEE2AA8C2A",
00278 1
00279 },
00280 #if 0
00281
00282 {
00283 TEST_INPUT(""),
00284 "0xXXX",
00285 1
00286 },
00287 #endif
00288
00289 {
00290 TEST_INPUT("\x18\x80\x40\x05\xdd\x4f\xbd\x15\x56\x29"
00291 "\x9d\x6f\x9d\x93\xdf\x62"),
00292 "0xDF90D78AA78821C99B40BA4C966921ACCD8FFB1E98AC38"
00293 "8E56191DB1",
00294 1
00295 },
00296 #if 0
00297
00298 {
00299 TEST_INPUT(""),
00300 "0xXXX",
00301 1
00302 },
00303 #endif
00304
00305 {
00306 TEST_INPUT("\x55\xb2\x10\x07\x9c\x61\xb5\x3a\xdd\x52"
00307 "\x06\x22\xd1\xac\x97\xd5\xcd\xbe\x8c\xb3"
00308 "\x3a\xa0\xae\x34\x45\x17\xbe\xe4\xd7\xba"
00309 "\x09\xab\xc8\x53\x3c\x52\x50\x88\x7a\x43"
00310 "\xbe\xbb\xac\x90\x6c\x2e\x18\x37\xf2\x6b"
00311 "\x36\xa5\x9a\xe3\xbe\x78\x14\xd5\x06\x89"
00312 "\x6b\x71\x8b\x2a\x38\x3e\xcd\xac\x16\xb9"
00313 "\x61\x25\x55\x3f\x41\x6f\xf3\x2c\x66\x74"
00314 "\xc7\x45\x99\xa9\x00\x53\x86\xd9\xce\x11"
00315 "\x12\x24\x5f\x48\xee\x47\x0d\x39\x6c\x1e"
00316 "\xd6\x3b\x92\x67\x0c\xa5\x6e\xc8\x4d\xee"
00317 "\xa8\x14\xb6\x13\x5e\xca\x54\x39\x2b\xde"
00318 "\xdb\x94\x89\xbc\x9b\x87\x5a\x8b\xaf\x0d"
00319 "\xc1\xae\x78\x57\x36\x91\x4a\xb7\xda\xa2"
00320 "\x64\xbc\x07\x9d\x26\x9f\x2c\x0d\x7e\xdd"
00321 "\xd8\x10\xa4\x26\x14\x5a\x07\x76\xf6\x7c"
00322 "\x87\x82\x73"),
00323 "0x0B31894EC8937AD9B91BDFBCBA294D9ADEFAA18E09305E"
00324 "9F20D5C3A4",
00325 1
00326 },
00327 { NULL, 0, NULL, 1 }
00328 };
00329
00330 hash_testcase_t *testcase = testcases;
00331
00332 while (testcase->input != NULL && testcase->result != NULL) {
00333 isc_sha224_init(&sha224);
00334 for(i = 0; i < testcase->repeats; i++) {
00335 isc_sha224_update(&sha224,
00336 (const isc_uint8_t *) testcase->input,
00337 testcase->input_len);
00338 }
00339 isc_sha224_final(digest, &sha224);
00340
00341
00342
00343
00344
00345
00346 tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
00347 ATF_CHECK_STREQ(str, testcase->result);
00348
00349 testcase++;
00350 }
00351 }
00352
00353 ATF_TC(isc_sha256);
00354 ATF_TC_HEAD(isc_sha256, tc) {
00355 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
00356 }
00357 ATF_TC_BODY(isc_sha256, tc) {
00358 isc_sha256_t sha256;
00359 int i;
00360
00361 UNUSED(tc);
00362
00363
00364
00365
00366
00367
00368 hash_testcase_t testcases[] = {
00369
00370 {
00371 TEST_INPUT("abc"),
00372 "0xBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A"
00373 "9CB410FF61F20015AD",
00374 1
00375 },
00376
00377 {
00378 TEST_INPUT("abcdbcdecdefdefgefghfghighijhijkijkljk"
00379 "lmklmnlmnomnopnopq"),
00380 "0x248D6A61D20638B8E5C026930C3E6039A33CE45964FF21"
00381 "67F6ECEDD419DB06C1",
00382 1
00383 },
00384
00385 {
00386 TEST_INPUT("a"),
00387 "0xCDC76E5C9914FB9281A1C7E284D73E67F1809A48A49720"
00388 "0E046D39CCC7112CD0",
00389 1000000 },
00390
00391 {
00392 TEST_INPUT("01234567012345670123456701234567"),
00393 "0x594847328451BDFA85056225462CC1D867D877FB388DF0"
00394 "CE35F25AB5562BFBB5",
00395 20
00396 },
00397 #if 0
00398
00399 {
00400 TEST_INPUT(""),
00401 "0xXXX",
00402 1
00403 },
00404 #endif
00405
00406 {
00407 TEST_INPUT("\x19"),
00408 "0x68AA2E2EE5DFF96E3355E6C7EE373E3D6A4E17F75F9518"
00409 "D843709C0C9BC3E3D4",
00410 1
00411 },
00412 #if 0
00413
00414 {
00415 TEST_INPUT(""),
00416 "0xXXX",
00417 1
00418 },
00419 #endif
00420
00421 {
00422 TEST_INPUT("\xe3\xd7\x25\x70\xdc\xdd\x78\x7c\xe3"
00423 "\x88\x7a\xb2\xcd\x68\x46\x52"),
00424 "0x175EE69B02BA9B58E2B0A5FD13819CEA573F3940A94F82"
00425 "5128CF4209BEABB4E8",
00426 1
00427 },
00428 #if 0
00429
00430 {
00431 TEST_INPUT(""),
00432 "0xXXX",
00433 1
00434 },
00435 #endif
00436
00437 {
00438 TEST_INPUT("\x83\x26\x75\x4e\x22\x77\x37\x2f\x4f\xc1"
00439 "\x2b\x20\x52\x7a\xfe\xf0\x4d\x8a\x05\x69"
00440 "\x71\xb1\x1a\xd5\x71\x23\xa7\xc1\x37\x76"
00441 "\x00\x00\xd7\xbe\xf6\xf3\xc1\xf7\xa9\x08"
00442 "\x3a\xa3\x9d\x81\x0d\xb3\x10\x77\x7d\xab"
00443 "\x8b\x1e\x7f\x02\xb8\x4a\x26\xc7\x73\x32"
00444 "\x5f\x8b\x23\x74\xde\x7a\x4b\x5a\x58\xcb"
00445 "\x5c\x5c\xf3\x5b\xce\xe6\xfb\x94\x6e\x5b"
00446 "\xd6\x94\xfa\x59\x3a\x8b\xeb\x3f\x9d\x65"
00447 "\x92\xec\xed\xaa\x66\xca\x82\xa2\x9d\x0c"
00448 "\x51\xbc\xf9\x33\x62\x30\xe5\xd7\x84\xe4"
00449 "\xc0\xa4\x3f\x8d\x79\xa3\x0a\x16\x5c\xba"
00450 "\xbe\x45\x2b\x77\x4b\x9c\x71\x09\xa9\x7d"
00451 "\x13\x8f\x12\x92\x28\x96\x6f\x6c\x0a\xdc"
00452 "\x10\x6a\xad\x5a\x9f\xdd\x30\x82\x57\x69"
00453 "\xb2\xc6\x71\xaf\x67\x59\xdf\x28\xeb\x39"
00454 "\x3d\x54\xd6"),
00455 "0x97DBCA7DF46D62C8A422C941DD7E835B8AD3361763F7E9"
00456 "B2D95F4F0DA6E1CCBC",
00457 1
00458 },
00459 { NULL, 0, NULL, 1 }
00460 };
00461
00462 hash_testcase_t *testcase = testcases;
00463
00464 while (testcase->input != NULL && testcase->result != NULL) {
00465 isc_sha256_init(&sha256);
00466 for(i = 0; i < testcase->repeats; i++) {
00467 isc_sha256_update(&sha256,
00468 (const isc_uint8_t *) testcase->input,
00469 testcase->input_len);
00470 }
00471 isc_sha256_final(digest, &sha256);
00472
00473
00474
00475
00476
00477
00478 tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
00479 ATF_CHECK_STREQ(str, testcase->result);
00480
00481 testcase++;
00482 }
00483 }
00484
00485 ATF_TC(isc_sha384);
00486 ATF_TC_HEAD(isc_sha384, tc) {
00487 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
00488 }
00489 ATF_TC_BODY(isc_sha384, tc) {
00490 isc_sha384_t sha384;
00491 int i;
00492
00493 UNUSED(tc);
00494
00495
00496
00497
00498
00499
00500 hash_testcase_t testcases[] = {
00501
00502 {
00503 TEST_INPUT("abc"),
00504 "0xCB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1"
00505 "631A8B605A43FF5BED8086072BA1E7CC2358BAEC"
00506 "A134C825A7",
00507 1
00508 },
00509
00510 {
00511 TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl"
00512 "fghijklmghijklmnhijklmnoijklmnopjklmnopq"
00513 "klmnopqrlmnopqrsmnopqrstnopqrstu"),
00514 "0x09330C33F71147E83D192FC782CD1B4753111B173B3B05"
00515 "D22FA08086E3B0F712FCC7C71A557E2DB966C3E9"
00516 "FA91746039",
00517 1
00518 },
00519
00520 {
00521 TEST_INPUT("a"),
00522 "0x9D0E1809716474CB086E834E310A4A1CED149E9C00F248"
00523 "527972CEC5704C2A5B07B8B3DC38ECC4EBAE97DD"
00524 "D87F3D8985",
00525 1000000
00526 },
00527
00528 {
00529 TEST_INPUT("01234567012345670123456701234567"),
00530 "0x2FC64A4F500DDB6828F6A3430B8DD72A368EB7F3A8322A"
00531 "70BC84275B9C0B3AB00D27A5CC3C2D224AA6B61A"
00532 "0D79FB4596",
00533 20
00534 },
00535 #if 0
00536
00537 {
00538 TEST_INPUT(""),
00539 "0xXXX",
00540 1
00541 },
00542 #endif
00543
00544 { TEST_INPUT("\xb9"),
00545 "0xBC8089A19007C0B14195F4ECC74094FEC64F01F9092928"
00546 "2C2FB392881578208AD466828B1C6C283D2722CF"
00547 "0AD1AB6938",
00548 1
00549 },
00550 #if 0
00551
00552 {
00553 TEST_INPUT(""),
00554 "0xXXX",
00555 1
00556 },
00557 #endif
00558
00559 {
00560 TEST_INPUT("\xa4\x1c\x49\x77\x79\xc0\x37\x5f\xf1"
00561 "\x0a\x7f\x4e\x08\x59\x17\x39"),
00562 "0xC9A68443A005812256B8EC76B00516F0DBB74FAB26D665"
00563 "913F194B6FFB0E91EA9967566B58109CBC675CC2"
00564 "08E4C823F7",
00565 1
00566 },
00567 #if 0
00568
00569 {
00570 TEST_INPUT(""),
00571 "0xXXX",
00572 1
00573 },
00574 #endif
00575
00576 {
00577 TEST_INPUT("\x39\x96\x69\xe2\x8f\x6b\x9c\x6d\xbc\xbb"
00578 "\x69\x12\xec\x10\xff\xcf\x74\x79\x03\x49"
00579 "\xb7\xdc\x8f\xbe\x4a\x8e\x7b\x3b\x56\x21"
00580 "\xdb\x0f\x3e\x7d\xc8\x7f\x82\x32\x64\xbb"
00581 "\xe4\x0d\x18\x11\xc9\xea\x20\x61\xe1\xc8"
00582 "\x4a\xd1\x0a\x23\xfa\xc1\x72\x7e\x72\x02"
00583 "\xfc\x3f\x50\x42\xe6\xbf\x58\xcb\xa8\xa2"
00584 "\x74\x6e\x1f\x64\xf9\xb9\xea\x35\x2c\x71"
00585 "\x15\x07\x05\x3c\xf4\xe5\x33\x9d\x52\x86"
00586 "\x5f\x25\xcc\x22\xb5\xe8\x77\x84\xa1\x2f"
00587 "\xc9\x61\xd6\x6c\xb6\xe8\x95\x73\x19\x9a"
00588 "\x2c\xe6\x56\x5c\xbd\xf1\x3d\xca\x40\x38"
00589 "\x32\xcf\xcb\x0e\x8b\x72\x11\xe8\x3a\xf3"
00590 "\x2a\x11\xac\x17\x92\x9f\xf1\xc0\x73\xa5"
00591 "\x1c\xc0\x27\xaa\xed\xef\xf8\x5a\xad\x7c"
00592 "\x2b\x7c\x5a\x80\x3e\x24\x04\xd9\x6d\x2a"
00593 "\x77\x35\x7b\xda\x1a\x6d\xae\xed\x17\x15"
00594 "\x1c\xb9\xbc\x51\x25\xa4\x22\xe9\x41\xde"
00595 "\x0c\xa0\xfc\x50\x11\xc2\x3e\xcf\xfe\xfd"
00596 "\xd0\x96\x76\x71\x1c\xf3\xdb\x0a\x34\x40"
00597 "\x72\x0e\x16\x15\xc1\xf2\x2f\xbc\x3c\x72"
00598 "\x1d\xe5\x21\xe1\xb9\x9b\xa1\xbd\x55\x77"
00599 "\x40\x86\x42\x14\x7e\xd0\x96"),
00600 "0x4F440DB1E6EDD2899FA335F09515AA025EE177A79F4B4A"
00601 "AF38E42B5C4DE660F5DE8FB2A5B2FBD2A3CBFFD2"
00602 "0CFF1288C0",
00603 1
00604 },
00605 { NULL, 0, NULL, 1 }
00606 };
00607
00608 hash_testcase_t *testcase = testcases;
00609
00610 while (testcase->input != NULL && testcase->result != NULL) {
00611 isc_sha384_init(&sha384);
00612 for(i = 0; i < testcase->repeats; i++) {
00613 isc_sha384_update(&sha384,
00614 (const isc_uint8_t *) testcase->input,
00615 testcase->input_len);
00616 }
00617 isc_sha384_final(digest, &sha384);
00618
00619
00620
00621
00622
00623
00624 tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
00625 ATF_CHECK_STREQ(str, testcase->result);
00626
00627 testcase++;
00628 }
00629 }
00630
00631 ATF_TC(isc_sha512);
00632 ATF_TC_HEAD(isc_sha512, tc) {
00633 atf_tc_set_md_var(tc, "descr", "sha224 examples from RFC4634");
00634 }
00635 ATF_TC_BODY(isc_sha512, tc) {
00636 isc_sha512_t sha512;
00637 int i;
00638
00639 UNUSED(tc);
00640
00641
00642
00643
00644
00645
00646 hash_testcase_t testcases[] = {
00647
00648 {
00649 TEST_INPUT("abc"),
00650 "0xDDAF35A193617ABACC417349AE20413112E6FA4E89A97E"
00651 "A20A9EEEE64B55D39A2192992A274FC1A836BA3C"
00652 "23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F",
00653 1
00654 },
00655
00656 {
00657 TEST_INPUT("abcdefghbcdefghicdefghijdefghijkefghijkl"
00658 "fghijklmghijklmnhijklmnoijklmnopjklmnopq"
00659 "klmnopqrlmnopqrsmnopqrstnopqrstu"),
00660 "0x8E959B75DAE313DA8CF4F72814FC143F8F7779C6EB9F7F"
00661 "A17299AEADB6889018501D289E4900F7E4331B99"
00662 "DEC4B5433AC7D329EEB6DD26545E96E55B874BE909",
00663 1
00664 },
00665
00666 {
00667 TEST_INPUT("a"),
00668 "0xE718483D0CE769644E2E42C7BC15B4638E1F98B13B2044"
00669 "285632A803AFA973EBDE0FF244877EA60A4CB043"
00670 "2CE577C31BEB009C5C2C49AA2E4EADB217AD8CC09B",
00671 1000000
00672 },
00673
00674 {
00675 TEST_INPUT("01234567012345670123456701234567"),
00676 "0x89D05BA632C699C31231DED4FFC127D5A894DAD412C0E0"
00677 "24DB872D1ABD2BA8141A0F85072A9BE1E2AA04CF"
00678 "33C765CB510813A39CD5A84C4ACAA64D3F3FB7BAE9",
00679 20
00680 },
00681 #if 0
00682
00683 {
00684 TEST_INPUT(""),
00685 "0xXXX",
00686 1
00687 },
00688 #endif
00689
00690 {
00691 TEST_INPUT("\xD0"),
00692 "0x9992202938E882E73E20F6B69E68A0A7149090423D93C8"
00693 "1BAB3F21678D4ACEEEE50E4E8CAFADA4C85A54EA"
00694 "8306826C4AD6E74CECE9631BFA8A549B4AB3FBBA15",
00695 1
00696 },
00697 #if 0
00698
00699 {
00700 TEST_INPUT(""),
00701 "0xXXX",
00702 1
00703 },
00704 #endif
00705
00706 {
00707 TEST_INPUT("\x8d\x4e\x3c\x0e\x38\x89\x19\x14\x91\x81"
00708 "\x6e\x9d\x98\xbf\xf0\xa0"),
00709 "0xCB0B67A4B8712CD73C9AABC0B199E9269B20844AFB75AC"
00710 "BDD1C153C9828924C3DDEDAAFE669C5FDD0BC66F"
00711 "630F6773988213EB1B16F517AD0DE4B2F0C95C90F8",
00712 1
00713 },
00714 #if 0
00715
00716 {
00717 TEST_INPUT(""),
00718 "0xXXX",
00719 1
00720 },
00721 #endif
00722
00723 {
00724 TEST_INPUT("\xa5\x5f\x20\xc4\x11\xaa\xd1\x32\x80\x7a"
00725 "\x50\x2d\x65\x82\x4e\x31\xa2\x30\x54\x32"
00726 "\xaa\x3d\x06\xd3\xe2\x82\xa8\xd8\x4e\x0d"
00727 "\xe1\xde\x69\x74\xbf\x49\x54\x69\xfc\x7f"
00728 "\x33\x8f\x80\x54\xd5\x8c\x26\xc4\x93\x60"
00729 "\xc3\xe8\x7a\xf5\x65\x23\xac\xf6\xd8\x9d"
00730 "\x03\xe5\x6f\xf2\xf8\x68\x00\x2b\xc3\xe4"
00731 "\x31\xed\xc4\x4d\xf2\xf0\x22\x3d\x4b\xb3"
00732 "\xb2\x43\x58\x6e\x1a\x7d\x92\x49\x36\x69"
00733 "\x4f\xcb\xba\xf8\x8d\x95\x19\xe4\xeb\x50"
00734 "\xa6\x44\xf8\xe4\xf9\x5e\xb0\xea\x95\xbc"
00735 "\x44\x65\xc8\x82\x1a\xac\xd2\xfe\x15\xab"
00736 "\x49\x81\x16\x4b\xbb\x6d\xc3\x2f\x96\x90"
00737 "\x87\xa1\x45\xb0\xd9\xcc\x9c\x67\xc2\x2b"
00738 "\x76\x32\x99\x41\x9c\xc4\x12\x8b\xe9\xa0"
00739 "\x77\xb3\xac\xe6\x34\x06\x4e\x6d\x99\x28"
00740 "\x35\x13\xdc\x06\xe7\x51\x5d\x0d\x73\x13"
00741 "\x2e\x9a\x0d\xc6\xd3\xb1\xf8\xb2\x46\xf1"
00742 "\xa9\x8a\x3f\xc7\x29\x41\xb1\xe3\xbb\x20"
00743 "\x98\xe8\xbf\x16\xf2\x68\xd6\x4f\x0b\x0f"
00744 "\x47\x07\xfe\x1e\xa1\xa1\x79\x1b\xa2\xf3"
00745 "\xc0\xc7\x58\xe5\xf5\x51\x86\x3a\x96\xc9"
00746 "\x49\xad\x47\xd7\xfb\x40\xd2"),
00747 "0xC665BEFB36DA189D78822D10528CBF3B12B3EEF7260399"
00748 "09C1A16A270D48719377966B957A878E72058477"
00749 "9A62825C18DA26415E49A7176A894E7510FD1451F5",
00750 1
00751 },
00752 { NULL, 0, NULL, 1 }
00753 };
00754
00755 hash_testcase_t *testcase = testcases;
00756
00757 while (testcase->input != NULL && testcase->result != NULL) {
00758 isc_sha512_init(&sha512);
00759 for(i = 0; i < testcase->repeats; i++) {
00760 isc_sha512_update(&sha512,
00761 (const isc_uint8_t *) testcase->input,
00762 testcase->input_len);
00763 }
00764 isc_sha512_final(digest, &sha512);
00765
00766
00767
00768
00769
00770
00771 tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
00772 ATF_CHECK_STREQ(str, testcase->result);
00773
00774 testcase++;
00775 }
00776 }
00777
00778 ATF_TC(isc_md5);
00779 ATF_TC_HEAD(isc_md5, tc) {
00780 atf_tc_set_md_var(tc, "descr", "md5 example from RFC1321");
00781 }
00782 ATF_TC_BODY(isc_md5, tc) {
00783 isc_md5_t md5;
00784 int i;
00785
00786 UNUSED(tc);
00787
00788
00789
00790
00791
00792
00793 hash_testcase_t testcases[] = {
00794 {
00795 TEST_INPUT(""),
00796 "0xD41D8CD98F00B204E9800998ECF8427E",
00797 1
00798 },
00799 {
00800 TEST_INPUT("a"),
00801 "0x0CC175B9C0F1B6A831C399E269772661",
00802 1
00803 },
00804 {
00805 TEST_INPUT("abc"),
00806 "0x900150983CD24FB0D6963F7D28E17F72",
00807 1
00808 },
00809 {
00810 TEST_INPUT("message digest"),
00811 "0xF96B697D7CB7938D525A2F31AAF161D0",
00812 1
00813 },
00814 {
00815 TEST_INPUT("abcdefghijklmnopqrstuvwxyz"),
00816 "0xC3FCD3D76192E4007DFB496CCA67E13B",
00817 1
00818 },
00819 {
00820 TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
00821 "nopqrstuvwxyz0123456789"),
00822 "0xD174AB98D277D9F5A5611C2C9F419D9F",
00823 1
00824 },
00825 {
00826 TEST_INPUT("123456789012345678901234567890123456789"
00827 "01234567890123456789012345678901234567890"),
00828 "0x57EDF4A22BE3C955AC49DA2E2107B67A",
00829 1
00830 },
00831 { NULL, 0, NULL, 1 }
00832 };
00833
00834 hash_testcase_t *testcase = testcases;
00835
00836 while (testcase->input != NULL && testcase->result != NULL) {
00837 isc_md5_init(&md5);
00838 for(i = 0; i < testcase->repeats; i++) {
00839 isc_md5_update(&md5,
00840 (const isc_uint8_t *) testcase->input,
00841 testcase->input_len);
00842 }
00843 isc_md5_final(&md5, digest);
00844 tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
00845 ATF_CHECK_STREQ(str, testcase->result);
00846
00847 testcase++;
00848 }
00849 }
00850
00851
00852 ATF_TC(isc_hmacsha1);
00853 ATF_TC_HEAD(isc_hmacsha1, tc) {
00854 atf_tc_set_md_var(tc, "descr", "HMAC-SHA1 examples from RFC2104");
00855 }
00856 ATF_TC_BODY(isc_hmacsha1, tc) {
00857 isc_hmacsha1_t hmacsha1;
00858
00859 UNUSED(tc);
00860
00861
00862
00863
00864
00865 hash_testcase_t testcases[] = {
00866
00867 {
00868 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
00869 "0xB617318655057264E28BC0B6FB378C8EF146BE00",
00870 1
00871 },
00872
00873 {
00874 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
00875 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
00876 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
00877 "0xEFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79",
00878 1
00879 },
00880
00881 {
00882 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
00883 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
00884 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
00885 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
00886 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
00887 "0x125D7342B9AC11CD91A39AF48AA17B4F63F175D3",
00888 1
00889 },
00890
00891 {
00892 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
00893 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
00894 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
00895 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
00896 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
00897 "0x4C9007F4026250C6BC8414F9BF50C86C2D7235DA",
00898 1
00899 },
00900 #if 0
00901
00902 {
00903 TEST_INPUT("Test With Truncation"),
00904 "0x4C1A03424B55E07FE7F27BE1",
00905 1
00906 },
00907 #endif
00908
00909 {
00910 TEST_INPUT("Test Using Larger Than Block-Size Key - "
00911 "Hash Key First"),
00912 "0xAA4AE5E15272D00E95705637CE8A3B55ED402112", 1 },
00913
00914 {
00915 TEST_INPUT("Test Using Larger Than Block-Size Key and "
00916 "Larger Than One Block-Size Data"),
00917 "0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91",
00918 1
00919 },
00920 { NULL, 0, NULL, 1 }
00921 };
00922
00923 hash_testcase_t *testcase = testcases;
00924
00925 hash_test_key_t test_keys[] = {
00926
00927 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
00928 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
00929
00930 { "Jefe", 4 },
00931
00932 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00933 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
00934
00935 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
00936 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
00937 "\x15\x16\x17\x18\x19", 25 },
00938 #if 0
00939
00940 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
00941 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
00942 #endif
00943
00944 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00945 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00946 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00947 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00948 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00949 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00950 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00951 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80 },
00952
00953 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00954 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00955 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00956 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00957 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00958 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00959 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
00960 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 80 },
00961 { "", 0 }
00962 };
00963
00964 hash_test_key_t *test_key = test_keys;
00965
00966 while (testcase->input != NULL && testcase->result != NULL) {
00967 memmove(buffer, test_key->key, test_key->len);
00968 isc_hmacsha1_init(&hmacsha1, buffer, test_key->len);
00969 isc_hmacsha1_update(&hmacsha1,
00970 (const isc_uint8_t *) testcase->input,
00971 testcase->input_len);
00972 isc_hmacsha1_sign(&hmacsha1, digest, ISC_SHA1_DIGESTLENGTH);
00973 tohexstr(digest, ISC_SHA1_DIGESTLENGTH, str);
00974 ATF_CHECK_STREQ(str, testcase->result);
00975
00976 testcase++;
00977 test_key++;
00978 }
00979 }
00980
00981
00982 ATF_TC(isc_hmacsha224);
00983 ATF_TC_HEAD(isc_hmacsha224, tc) {
00984 atf_tc_set_md_var(tc, "descr", "HMAC-SHA224 examples from RFC4634");
00985 }
00986 ATF_TC_BODY(isc_hmacsha224, tc) {
00987 isc_hmacsha224_t hmacsha224;
00988
00989 UNUSED(tc);
00990
00991
00992
00993
00994
00995
00996 hash_testcase_t testcases[] = {
00997
00998 {
00999 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
01000 "0x896FB1128ABBDF196832107CD49DF33F47B4B1169912BA"
01001 "4F53684B22",
01002 1
01003 },
01004
01005 {
01006 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
01007 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
01008 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
01009 "0xA30E01098BC6DBBF45690F3A7E9E6D0F8BBEA2A39E61480"
01010 "08FD05E44",
01011 1
01012 },
01013
01014 {
01015 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01016 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01017 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01018 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01019 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
01020 "0x7FB3CB3588C6C1F6FFA9694D7D6AD2649365B0C1F65D69"
01021 "D1EC8333EA",
01022 1
01023 },
01024
01025 {
01026 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01027 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01028 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01029 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01030 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
01031 "0x6C11506874013CAC6A2ABC1BB382627CEC6A90D86EFC01"
01032 "2DE7AFEC5A",
01033 1
01034 },
01035 #if 0
01036
01037 {
01038 TEST_INPUT("Test With Truncation"),
01039 "0x4C1A03424B55E07FE7F27BE1",
01040 1
01041 },
01042 #endif
01043
01044 {
01045 TEST_INPUT("Test Using Larger Than Block-Size Key - "
01046 "Hash Key First"),
01047 "0x95E9A0DB962095ADAEBE9B2D6F0DBCE2D499F112F2D2B7"
01048 "273FA6870E",
01049 1
01050 },
01051
01052 {
01053 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
01054 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
01055 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
01056 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
01057 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
01058 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
01059 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
01060 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
01061 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
01062 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
01063 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
01064 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
01065 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
01066 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
01067 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
01068 "\x6d\x2e"),
01069 "0x3A854166AC5D9F023F54D517D0B39DBD946770DB9C2B95"
01070 "C9F6F565D1",
01071 1
01072 },
01073 { NULL, 0, NULL, 1 }
01074 };
01075
01076 hash_testcase_t *testcase = testcases;
01077
01078 hash_test_key_t test_keys[] = {
01079
01080 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
01081 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
01082
01083 { "Jefe", 4 },
01084
01085 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01086 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
01087
01088 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
01089 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
01090 "\x15\x16\x17\x18\x19", 25 },
01091 #if 0
01092
01093 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
01094 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
01095 #endif
01096
01097 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01098 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01099 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01100 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01101 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01102 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01103 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01104 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01105 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01106 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01107 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01108 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01109 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01110
01111 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01112 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01113 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01114 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01115 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01116 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01117 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01118 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01119 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01120 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01121 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01122 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01123 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01124 { "", 0 }
01125 };
01126
01127 hash_test_key_t *test_key = test_keys;
01128
01129 while (testcase->input != NULL && testcase->result != NULL) {
01130 memmove(buffer, test_key->key, test_key->len);
01131 isc_hmacsha224_init(&hmacsha224, buffer, test_key->len);
01132 isc_hmacsha224_update(&hmacsha224,
01133 (const isc_uint8_t *) testcase->input,
01134 testcase->input_len);
01135 isc_hmacsha224_sign(&hmacsha224, digest, ISC_SHA224_DIGESTLENGTH);
01136 tohexstr(digest, ISC_SHA224_DIGESTLENGTH, str);
01137 ATF_CHECK_STREQ(str, testcase->result);
01138
01139 testcase++;
01140 test_key++;
01141 }
01142 }
01143
01144
01145 ATF_TC(isc_hmacsha256);
01146 ATF_TC_HEAD(isc_hmacsha256, tc) {
01147 atf_tc_set_md_var(tc, "descr", "HMAC-SHA256 examples from RFC4634");
01148 }
01149 ATF_TC_BODY(isc_hmacsha256, tc) {
01150 isc_hmacsha256_t hmacsha256;
01151
01152 UNUSED(tc);
01153
01154
01155
01156
01157
01158
01159 hash_testcase_t testcases[] = {
01160
01161 {
01162 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
01163 "0xB0344C61D8DB38535CA8AFCEAF0BF12B881DC200C9833D"
01164 "A726E9376C2E32CFF7",
01165 1
01166 },
01167
01168 {
01169 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
01170 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
01171 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
01172 "0x5BDCC146BF60754E6A042426089575C75A003F089D2739"
01173 "839DEC58B964EC3843",
01174 1
01175 },
01176
01177 {
01178 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01179 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01180 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01181 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01182 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
01183 "0x773EA91E36800E46854DB8EBD09181A72959098B3EF8C1"
01184 "22D9635514CED565FE",
01185 1
01186 },
01187
01188 {
01189 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01190 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01191 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01192 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01193 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
01194 "0x82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8"
01195 "077A2E3FF46729665B",
01196 1
01197 },
01198 #if 0
01199
01200 {
01201 TEST_INPUT("Test With Truncation"),
01202 "0x4C1A03424B55E07FE7F27BE1",
01203 1
01204 },
01205 #endif
01206
01207 {
01208 TEST_INPUT("Test Using Larger Than Block-Size Key - "
01209 "Hash Key First"),
01210 "0x60E431591EE0B67F0D8A26AACBF5B77F8E0BC6213728C5"
01211 "140546040F0EE37F54",
01212 1
01213 },
01214
01215 {
01216 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
01217 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
01218 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
01219 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
01220 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
01221 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
01222 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
01223 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
01224 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
01225 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
01226 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
01227 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
01228 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
01229 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
01230 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
01231 "\x6d\x2e"),
01232 "0x9B09FFA71B942FCB27635FBCD5B0E944BFDC63644F0713"
01233 "938A7F51535C3A35E2",
01234 1
01235 },
01236 { NULL, 0, NULL, 1 }
01237 };
01238
01239 hash_testcase_t *testcase = testcases;
01240
01241 hash_test_key_t test_keys[] = {
01242
01243 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
01244 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
01245
01246 { "Jefe", 4 },
01247
01248 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01249 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
01250
01251 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
01252 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
01253 "\x15\x16\x17\x18\x19", 25 },
01254 #if 0
01255
01256 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
01257 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
01258 #endif
01259
01260 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01261 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01262 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01263 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01264 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01265 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01266 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01267 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01268 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01269 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01270 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01271 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01272 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01273
01274 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01275 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01276 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01277 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01278 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01279 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01280 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01281 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01282 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01283 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01284 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01285 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01286 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01287 { "", 0 }
01288 };
01289
01290 hash_test_key_t *test_key = test_keys;
01291
01292 while (testcase->input != NULL && testcase->result != NULL) {
01293 memmove(buffer, test_key->key, test_key->len);
01294 isc_hmacsha256_init(&hmacsha256, buffer, test_key->len);
01295 isc_hmacsha256_update(&hmacsha256,
01296 (const isc_uint8_t *) testcase->input,
01297 testcase->input_len);
01298 isc_hmacsha256_sign(&hmacsha256, digest, ISC_SHA256_DIGESTLENGTH);
01299 tohexstr(digest, ISC_SHA256_DIGESTLENGTH, str);
01300 ATF_CHECK_STREQ(str, testcase->result);
01301
01302 testcase++;
01303 test_key++;
01304 }
01305 }
01306
01307
01308 ATF_TC(isc_hmacsha384);
01309 ATF_TC_HEAD(isc_hmacsha384, tc) {
01310 atf_tc_set_md_var(tc, "descr", "HMAC-SHA384 examples from RFC4634");
01311 }
01312 ATF_TC_BODY(isc_hmacsha384, tc) {
01313 isc_hmacsha384_t hmacsha384;
01314
01315 UNUSED(tc);
01316
01317
01318
01319
01320
01321
01322 hash_testcase_t testcases[] = {
01323
01324 {
01325 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
01326 "0xAFD03944D84895626B0825F4AB46907F15F9DADBE4101E"
01327 "C682AA034C7CEBC59CFAEA9EA9076EDE7F4AF152"
01328 "E8B2FA9CB6",
01329 1
01330 },
01331
01332 {
01333 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
01334 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
01335 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
01336 "0xAF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B"
01337 "47E42EC3736322445E8E2240CA5E69E2C78B3239"
01338 "ECFAB21649",
01339 1
01340 },
01341
01342 {
01343 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01344 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01345 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01346 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01347 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
01348 "0x88062608D3E6AD8A0AA2ACE014C8A86F0AA635D947AC9F"
01349 "EBE83EF4E55966144B2A5AB39DC13814B94E3AB6"
01350 "E101A34F27",
01351 1
01352 },
01353
01354 {
01355 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01356 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01357 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01358 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01359 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
01360 "0x3E8A69B7783C25851933AB6290AF6CA77A998148085000"
01361 "9CC5577C6E1F573B4E6801DD23C4A7D679CCF8A3"
01362 "86C674CFFB",
01363 1
01364 },
01365 #if 0
01366
01367 {
01368 TEST_INPUT("Test With Truncation"),
01369 "0x4C1A03424B55E07FE7F27BE1",
01370 1
01371 },
01372 #endif
01373
01374 {
01375 TEST_INPUT("Test Using Larger Than Block-Size Key - "
01376 "Hash Key First"),
01377 "0x4ECE084485813E9088D2C63A041BC5B44F9EF1012A2B58"
01378 "8F3CD11F05033AC4C60C2EF6AB4030FE8296248D"
01379 "F163F44952",
01380 1
01381 },
01382
01383 {
01384 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
01385 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
01386 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
01387 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
01388 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
01389 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
01390 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
01391 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
01392 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
01393 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
01394 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
01395 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
01396 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
01397 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
01398 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
01399 "\x6d\x2e"),
01400 "0x6617178E941F020D351E2F254E8FD32C602420FEB0B8FB"
01401 "9ADCCEBB82461E99C5A678CC31E799176D3860E6"
01402 "110C46523E",
01403 1
01404 },
01405 { NULL, 0, NULL, 1 }
01406 };
01407
01408 hash_testcase_t *testcase = testcases;
01409
01410 hash_test_key_t test_keys[] = {
01411
01412 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
01413 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
01414
01415 { "Jefe", 4 },
01416
01417 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01418 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
01419
01420 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
01421 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
01422 "\x15\x16\x17\x18\x19", 25 },
01423 #if 0
01424
01425 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
01426 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
01427 #endif
01428
01429 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01430 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01431 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01432 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01433 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01434 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01435 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01436 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01437 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01438 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01439 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01440 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01441 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01442
01443 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01444 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01445 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01446 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01447 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01448 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01449 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01450 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01451 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01452 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01453 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01454 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01455 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01456 { "", 0 }
01457 };
01458
01459 hash_test_key_t *test_key = test_keys;
01460
01461 while (testcase->input != NULL && testcase->result != NULL) {
01462 memmove(buffer, test_key->key, test_key->len);
01463 isc_hmacsha384_init(&hmacsha384, buffer, test_key->len);
01464 isc_hmacsha384_update(&hmacsha384,
01465 (const isc_uint8_t *) testcase->input,
01466 testcase->input_len);
01467 isc_hmacsha384_sign(&hmacsha384, digest, ISC_SHA384_DIGESTLENGTH);
01468 tohexstr(digest, ISC_SHA384_DIGESTLENGTH, str);
01469 ATF_CHECK_STREQ(str, testcase->result);
01470
01471 testcase++;
01472 test_key++;
01473 }
01474 }
01475
01476
01477 ATF_TC(isc_hmacsha512);
01478 ATF_TC_HEAD(isc_hmacsha512, tc) {
01479 atf_tc_set_md_var(tc, "descr", "HMAC-SHA512 examples from RFC4634");
01480 }
01481 ATF_TC_BODY(isc_hmacsha512, tc) {
01482 isc_hmacsha512_t hmacsha512;
01483
01484 UNUSED(tc);
01485
01486
01487
01488
01489
01490
01491 hash_testcase_t testcases[] = {
01492
01493 {
01494 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
01495 "0x87AA7CDEA5EF619D4FF0B4241A1D6CB02379F4E2CE4EC2"
01496 "787AD0B30545E17CDEDAA833B7D6B8A702038B27"
01497 "4EAEA3F4E4BE9D914EEB61F1702E696C203A126854",
01498 1
01499 },
01500
01501 {
01502 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61"
01503 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20"
01504 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
01505 "0x164B7A7BFCF819E2E395FBE73B56E0A387BD64222E831F"
01506 "D610270CD7EA2505549758BF75C05A994A6D034F"
01507 "65F8F0E6FDCAEAB1A34D4A6B4B636E070A38BCE737",
01508 1
01509 },
01510
01511 {
01512 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01513 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01514 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01515 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01516 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
01517 "0xFA73B0089D56A284EFB0F0756C890BE9B1B5DBDD8EE81A"
01518 "3655F83E33B2279D39BF3E848279A722C806B485"
01519 "A47E67C807B946A337BEE8942674278859E13292FB",
01520 1
01521 },
01522
01523 {
01524 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01525 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01526 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01527 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01528 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
01529 "0xB0BA465637458C6990E5A8C5F61D4AF7E576D97FF94B87"
01530 "2DE76F8050361EE3DBA91CA5C11AA25EB4D67927"
01531 "5CC5788063A5F19741120C4F2DE2ADEBEB10A298DD",
01532 1
01533 },
01534 #if 0
01535
01536 {
01537 TEST_INPUT("Test With Truncation"),
01538 "0x4C1A03424B55E07FE7F27BE1",
01539 1
01540 },
01541 #endif
01542
01543 {
01544 TEST_INPUT("Test Using Larger Than Block-Size Key - "
01545 "Hash Key First"),
01546 "0x80B24263C7C1A3EBB71493C1DD7BE8B49B46D1F41B4AEE"
01547 "C1121B013783F8F3526B56D037E05F2598BD0FD2"
01548 "215D6A1E5295E64F73F63F0AEC8B915A985D786598",
01549 1
01550 },
01551
01552 {
01553 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20"
01554 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67"
01555 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20"
01556 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
01557 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20"
01558 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67"
01559 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c"
01560 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64"
01561 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b"
01562 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74"
01563 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65"
01564 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62"
01565 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20"
01566 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41"
01567 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68"
01568 "\x6d\x2e"),
01569 "0xE37B6A775DC87DBAA4DFA9F96E5E3FFDDEBD71F8867289"
01570 "865DF5A32D20CDC944B6022CAC3C4982B10D5EEB"
01571 "55C3E4DE15134676FB6DE0446065C97440FA8C6A58",
01572 1
01573 },
01574 { NULL, 0, NULL, 1 }
01575 };
01576
01577 hash_testcase_t *testcase = testcases;
01578
01579 hash_test_key_t test_keys[] = {
01580
01581 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
01582 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20 },
01583
01584 { "Jefe", 4 },
01585
01586 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01587 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 20 },
01588
01589 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
01590 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
01591 "\x15\x16\x17\x18\x19", 25 },
01592 #if 0
01593
01594 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
01595 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
01596 #endif
01597
01598 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01599 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01600 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01601 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01602 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01603 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01604 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01605 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01606 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01607 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01608 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01609 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01610 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01611
01612 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01613 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01614 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01615 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01616 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01617 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01618 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01619 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01620 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01621 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01622 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01623 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01624 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01625 { "", 0 }
01626 };
01627
01628 hash_test_key_t *test_key = test_keys;
01629
01630 while (testcase->input != NULL && testcase->result != NULL) {
01631 memmove(buffer, test_key->key, test_key->len);
01632 isc_hmacsha512_init(&hmacsha512, buffer, test_key->len);
01633 isc_hmacsha512_update(&hmacsha512,
01634 (const isc_uint8_t *) testcase->input,
01635 testcase->input_len);
01636 isc_hmacsha512_sign(&hmacsha512, digest, ISC_SHA512_DIGESTLENGTH);
01637 tohexstr(digest, ISC_SHA512_DIGESTLENGTH, str);
01638 ATF_CHECK_STREQ(str, testcase->result);
01639
01640 testcase++;
01641 test_key++;
01642 }
01643 }
01644
01645
01646
01647 ATF_TC(isc_hmacmd5);
01648 ATF_TC_HEAD(isc_hmacmd5, tc) {
01649 atf_tc_set_md_var(tc, "descr", "HMAC-MD5 examples from RFC2104");
01650 }
01651 ATF_TC_BODY(isc_hmacmd5, tc) {
01652 isc_hmacmd5_t hmacmd5;
01653
01654 UNUSED(tc);
01655
01656
01657
01658
01659
01660
01661 hash_testcase_t testcases[] = {
01662
01663 {
01664 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"),
01665 "0x9294727A3638BB1C13F48EF8158BFC9D",
01666 1
01667 },
01668
01669 {
01670 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79"
01671 "\x61\x20\x77\x61\x6e\x74\x20\x66\x6f"
01672 "\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f"),
01673 "0x750C783E6AB0B503EAA86E310A5DB738", 1
01674 },
01675
01676 {
01677 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01678 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01679 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01680 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
01681 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"),
01682 "0x56BE34521D144C88DBB8C733F0E8B3F6",
01683 1
01684 },
01685
01686 {
01687 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01688 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01689 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01690 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
01691 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"),
01692 "0x697EAF0ACA3A3AEA3A75164746FFAA79",
01693 1
01694 },
01695 #if 0
01696
01697 {
01698 TEST_INPUT("Test With Truncation"),
01699 "0x4C1A03424B55E07FE7F27BE1",
01700 1
01701 },
01702
01703 {
01704 TEST_INPUT("Test Using Larger Than Block-Size Key - "
01705 "Hash Key First"),
01706 "0xAA4AE5E15272D00E95705637CE8A3B55ED402112",
01707 1
01708 },
01709
01710 {
01711 TEST_INPUT("Test Using Larger Than Block-Size Key and "
01712 "Larger Than One Block-Size Data"),
01713 "0xE8E99D0F45237D786D6BBAA7965C7808BBFF1A91",
01714 1
01715 },
01716 #endif
01717 { NULL, 0, NULL, 1 }
01718 };
01719
01720 hash_testcase_t *testcase = testcases;
01721
01722 hash_test_key_t test_keys[] = {
01723
01724 { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
01725 "\x0b\x0b\x0b\x0b\x0b\x0b", 16 },
01726
01727 { "Jefe", 4 },
01728
01729 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01730 "\xaa\xaa\xaa\xaa\xaa\xaa", 16 },
01731
01732 { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
01733 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
01734 "\x15\x16\x17\x18\x19", 25 },
01735 #if 0
01736
01737 { "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
01738 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20 },
01739
01740 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01741 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01742 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01743 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01744 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01745 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01746 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01747 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01748 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01749 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01750 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01751 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01752 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01753
01754 { "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01755 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01756 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01757 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01758 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01759 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01760 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01761 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01762 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01763 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01764 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01765 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
01766 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131 },
01767 #endif
01768 { "", 0 }
01769 };
01770
01771 hash_test_key_t *test_key = test_keys;
01772
01773 while (testcase->input != NULL && testcase->result != NULL) {
01774 memmove(buffer, test_key->key, test_key->len);
01775 isc_hmacmd5_init(&hmacmd5, buffer, test_key->len);
01776 isc_hmacmd5_update(&hmacmd5,
01777 (const isc_uint8_t *) testcase->input,
01778 testcase->input_len);
01779 isc_hmacmd5_sign(&hmacmd5, digest);
01780 tohexstr(digest, ISC_MD5_DIGESTLENGTH, str);
01781 ATF_CHECK_STREQ(str, testcase->result);
01782
01783 testcase++;
01784 test_key++;
01785 }
01786 }
01787
01788
01789 ATF_TC(isc_crc64);
01790 ATF_TC_HEAD(isc_crc64, tc) {
01791 atf_tc_set_md_var(tc, "descr", "64-bit cyclic redundancy check");
01792 }
01793 ATF_TC_BODY(isc_crc64, tc) {
01794 isc_uint64_t crc;
01795 int i;
01796
01797 UNUSED(tc);
01798
01799 hash_testcase_t testcases[] = {
01800 {
01801 TEST_INPUT(""),
01802 "0x0000000000000000", 1
01803 },
01804 {
01805 TEST_INPUT("a"),
01806 "0x9AA9C0AC27F473CE", 1
01807 },
01808 {
01809 TEST_INPUT("abc"),
01810 "0x0297F4F93A818B04", 1
01811 },
01812 {
01813 TEST_INPUT("message digest"),
01814 "0xF47B357AEAF97352", 1
01815 },
01816 {
01817 TEST_INPUT("abcdefghijklmnopqrstuvwxyz"),
01818 "0xA1AA8B21F979F059", 1
01819 },
01820 {
01821 TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
01822 "nopqrstuvwxyz0123456789"),
01823 "0xFBB6781EF7A86DA3", 1
01824 },
01825 {
01826 TEST_INPUT("123456789012345678901234567890123456789"
01827 "01234567890123456789012345678901234567890"),
01828 "0x4A87E7C873EBE581", 1
01829 },
01830 { NULL, 0, NULL, 1 }
01831 };
01832
01833 hash_testcase_t *testcase = testcases;
01834
01835 while (testcase->input != NULL && testcase->result != NULL) {
01836 isc_crc64_init(&crc);
01837 for(i = 0; i < testcase->repeats; i++) {
01838 isc_crc64_update(&crc,
01839 (const isc_uint8_t *) testcase->input,
01840 testcase->input_len);
01841 }
01842 isc_crc64_final(&crc);
01843 tohexstr((unsigned char *) &crc, sizeof(crc), str);
01844 ATF_CHECK_STREQ(str, testcase->result);
01845
01846 testcase++;
01847 }
01848 }
01849
01850
01851
01852
01853 ATF_TP_ADD_TCS(tp) {
01854 ATF_TP_ADD_TC(tp, isc_hmacmd5);
01855 ATF_TP_ADD_TC(tp, isc_hmacsha1);
01856 ATF_TP_ADD_TC(tp, isc_hmacsha224);
01857 ATF_TP_ADD_TC(tp, isc_hmacsha256);
01858 ATF_TP_ADD_TC(tp, isc_hmacsha384);
01859 ATF_TP_ADD_TC(tp, isc_hmacsha512);
01860 ATF_TP_ADD_TC(tp, isc_md5);
01861 ATF_TP_ADD_TC(tp, isc_sha1);
01862 ATF_TP_ADD_TC(tp, isc_sha224);
01863 ATF_TP_ADD_TC(tp, isc_sha256);
01864 ATF_TP_ADD_TC(tp, isc_sha384);
01865 ATF_TP_ADD_TC(tp, isc_sha512);
01866 ATF_TP_ADD_TC(tp, isc_crc64);
01867 return (atf_no_error());
01868 }
01869