1/* $NetBSD: hmac_test.c,v 1.2 2024/02/21 22:52:50 christos Exp $ */ 2 3/* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16/* ! \file */ 17 18#include <inttypes.h> 19#include <sched.h> /* IWYU pragma: keep */ 20#include <setjmp.h> 21#include <stdarg.h> 22#include <stddef.h> 23#include <stdlib.h> 24#include <string.h> 25 26/* 27 * As a workaround, include an OpenSSL header file before including cmocka.h, 28 * because OpenSSL 3.1.0 uses __attribute__(malloc), conflicting with a 29 * redefined malloc in cmocka.h. 30 */ 31#include <openssl/err.h> 32 33#define UNIT_TESTING 34#include <cmocka.h> 35 36#include <isc/buffer.h> 37#include <isc/hex.h> 38#include <isc/hmac.h> 39#include <isc/region.h> 40#include <isc/result.h> 41 42#include "hmac.c" 43 44#include <tests/isc.h> 45 46#define TEST_INPUT(x) (x), sizeof(x) - 1 47 48static int 49_setup(void **state) { 50 isc_hmac_t *hmac_st = isc_hmac_new(); 51 if (hmac_st == NULL) { 52 return (-1); 53 } 54 *state = hmac_st; 55 return (0); 56} 57 58static int 59_teardown(void **state) { 60 if (*state == NULL) { 61 return (-1); 62 } 63 isc_hmac_free(*state); 64 return (0); 65} 66 67static int 68_reset(void **state) { 69 if (*state == NULL) { 70 return (-1); 71 } 72 if (isc_hmac_reset(*state) != ISC_R_SUCCESS) { 73 return (-1); 74 } 75 return (0); 76} 77 78ISC_RUN_TEST_IMPL(isc_hmac_new) { 79 UNUSED(state); 80 81 isc_hmac_t *hmac_st = isc_hmac_new(); 82 assert_non_null(hmac_st); 83 isc_hmac_free(hmac_st); /* Cleanup */ 84} 85 86ISC_RUN_TEST_IMPL(isc_hmac_free) { 87 UNUSED(state); 88 89 isc_hmac_t *hmac_st = isc_hmac_new(); 90 assert_non_null(hmac_st); 91 isc_hmac_free(hmac_st); /* Test freeing valid message digest context */ 92 isc_hmac_free(NULL); /* Test freeing NULL argument */ 93} 94 95static void 96isc_hmac_test(isc_hmac_t *hmac_st, const void *key, size_t keylen, 97 const isc_md_type_t *type, const char *buf, size_t buflen, 98 const char *result, const size_t repeats) { 99 isc_result_t res; 100 101 assert_non_null(hmac_st); 102 assert_int_equal(isc_hmac_init(hmac_st, key, keylen, type), 103 ISC_R_SUCCESS); 104 105 for (size_t i = 0; i < repeats; i++) { 106 assert_int_equal(isc_hmac_update(hmac_st, 107 (const unsigned char *)buf, 108 buflen), 109 ISC_R_SUCCESS); 110 } 111 112 unsigned char digest[ISC_MAX_MD_SIZE]; 113 unsigned int digestlen = sizeof(digest); 114 assert_int_equal(isc_hmac_final(hmac_st, digest, &digestlen), 115 ISC_R_SUCCESS); 116 117 char hexdigest[ISC_MAX_MD_SIZE * 2 + 3]; 118 isc_region_t r = { .base = digest, .length = digestlen }; 119 isc_buffer_t b; 120 isc_buffer_init(&b, hexdigest, sizeof(hexdigest)); 121 122 res = isc_hex_totext(&r, 0, "", &b); 123 124 assert_return_code(res, ISC_R_SUCCESS); 125 126 assert_memory_equal(hexdigest, result, (result ? strlen(result) : 0)); 127 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 128} 129 130ISC_RUN_TEST_IMPL(isc_hmac_init) { 131 isc_hmac_t *hmac_st = *state; 132 assert_non_null(hmac_st); 133 134 expect_assert_failure(isc_hmac_init(NULL, "", 0, ISC_MD_MD5)); 135 136 assert_int_equal(isc_hmac_init(hmac_st, "", 0, NULL), 137 ISC_R_NOTIMPLEMENTED); 138 139 expect_assert_failure(isc_hmac_init(hmac_st, NULL, 0, ISC_MD_MD5)); 140 141 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_MD5), 142 ISC_R_SUCCESS); 143 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 144 145 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA1), 146 ISC_R_SUCCESS); 147 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 148 149 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA224), 150 ISC_R_SUCCESS); 151 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 152 153 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA256), 154 ISC_R_SUCCESS); 155 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 156 157 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA384), 158 ISC_R_SUCCESS); 159 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 160 161 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA512), 162 ISC_R_SUCCESS); 163 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 164} 165 166ISC_RUN_TEST_IMPL(isc_hmac_update) { 167 isc_hmac_t *hmac_st = *state; 168 assert_non_null(hmac_st); 169 170 /* Uses message digest context initialized in isc_hmac_init_test() */ 171 expect_assert_failure(isc_hmac_update(NULL, NULL, 0)); 172 173 assert_int_equal(isc_hmac_update(hmac_st, NULL, 100), ISC_R_SUCCESS); 174 assert_int_equal(isc_hmac_update(hmac_st, (const unsigned char *)"", 0), 175 ISC_R_SUCCESS); 176} 177 178ISC_RUN_TEST_IMPL(isc_hmac_reset) { 179 isc_hmac_t *hmac_st = *state; 180#if 0 181 unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused)); 182 unsigned int digestlen __attribute((unused)); 183#endif /* if 0 */ 184 185 assert_non_null(hmac_st); 186 187 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA512), 188 ISC_R_SUCCESS); 189 assert_int_equal( 190 isc_hmac_update(hmac_st, (const unsigned char *)"a", 1), 191 ISC_R_SUCCESS); 192 assert_int_equal( 193 isc_hmac_update(hmac_st, (const unsigned char *)"b", 1), 194 ISC_R_SUCCESS); 195 196 assert_int_equal(isc_hmac_reset(hmac_st), ISC_R_SUCCESS); 197 198#if 0 199 /* 200 * This test would require OpenSSL compiled with mock_assert(), 201 * so this could be only manually checked that the test will 202 * segfault when called by hand 203 */ 204 expect_assert_failure(isc_hmac_final(hmac_st, digest, &digestlen)); 205#endif /* if 0 */ 206} 207 208ISC_RUN_TEST_IMPL(isc_hmac_final) { 209 isc_hmac_t *hmac_st = *state; 210 assert_non_null(hmac_st); 211 212 unsigned char digest[ISC_MAX_MD_SIZE]; 213 unsigned int digestlen = sizeof(digest); 214 215 /* Fail when message digest context is empty */ 216 expect_assert_failure(isc_hmac_final(NULL, digest, &digestlen)); 217 /* Fail when output buffer is empty */ 218 expect_assert_failure(isc_hmac_final(hmac_st, NULL, &digestlen)); 219 220 assert_int_equal(isc_hmac_init(hmac_st, "", 0, ISC_MD_SHA512), 221 ISC_R_SUCCESS); 222 /* Fail when the digest length pointer is empty */ 223 expect_assert_failure(isc_hmac_final(hmac_st, digest, NULL)); 224} 225 226ISC_RUN_TEST_IMPL(isc_hmac_md5) { 227 isc_hmac_t *hmac_st = *state; 228 229 /* Test 0 */ 230 isc_hmac_test(hmac_st, TEST_INPUT(""), ISC_MD_MD5, TEST_INPUT(""), 231 "74E6F7298A9C2D168935F58C001BAD88", 1); 232 233 /* Test 1 */ 234 isc_hmac_test(hmac_st, 235 TEST_INPUT("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 236 "\x0b\x0b\x0b\x0b\x0b\x0b"), 237 ISC_MD_MD5, 238 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 239 "9294727A3638BB1C13F48EF8158BFC9D", 1); 240 241 /* Test 2 */ 242 isc_hmac_test(hmac_st, TEST_INPUT("Jefe"), ISC_MD_MD5, 243 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79" 244 "\x61\x20\x77\x61\x6e\x74\x20\x66\x6f" 245 "\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f"), 246 "750C783E6AB0B503EAA86E310A5DB738", 1); 247 248 /* Test 3 */ 249 isc_hmac_test(hmac_st, 250 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 251 "\xaa\xaa\xaa\xaa\xaa\xaa"), 252 ISC_MD_MD5, 253 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 254 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 255 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 256 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 257 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"), 258 "56BE34521D144C88DBB8C733F0E8B3F6", 1); 259 /* Test 4 */ 260 isc_hmac_test(hmac_st, 261 TEST_INPUT("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 262 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 263 "\x15\x16\x17\x18\x19"), 264 ISC_MD_MD5, 265 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 266 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 267 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 268 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 269 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"), 270 "697EAF0ACA3A3AEA3A75164746FFAA79", 1); 271#if 0 272 /* Test 5 -- unimplemented optional functionality */ 273 isc_hmac_test(hmac_st, 274 TEST_INPUT("\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 275 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"), 276 ISC_MD_MD5, 277 TEST_INPUT("Test With Truncation"), 278 "4C1A03424B55E07FE7F27BE1", 279 1); 280 /* Test 6 -- unimplemented optional functionality */ 281 isc_hmac_test(hmac_st, 282 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 283 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 284 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 285 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 286 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 287 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 288 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 289 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 290 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 291 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 292 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 293 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 294 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 295 ISC_MD_MD5, 296 TEST_INPUT("Test Using Larger Than Block-Size Key - " 297 "Hash Key First"), 298 "AA4AE5E15272D00E95705637CE8A3B55ED402112", 299 1); 300 /* Test 7 -- unimplemented optional functionality */ 301 isc_hmac_test(hmac_st, 302 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 303 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 304 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 305 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 306 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 307 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 308 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 309 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 310 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 311 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 312 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 313 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 314 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 315 ISC_MD_MD5, 316 TEST_INPUT("Test Using Larger Than Block-Size Key and " 317 "Larger Than One Block-Size Data"), 318 "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 319 1); 320#endif /* if 0 */ 321} 322 323ISC_RUN_TEST_IMPL(isc_hmac_sha1) { 324 isc_hmac_t *hmac_st = *state; 325 326 /* Test 0 */ 327 isc_hmac_test(hmac_st, TEST_INPUT(""), ISC_MD_SHA1, TEST_INPUT(""), 328 "FBDB1D1B18AA6C08324B7D64B71FB76370690E1D", 1); 329 330 /* Test 1 */ 331 isc_hmac_test(hmac_st, 332 TEST_INPUT("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 333 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"), 334 ISC_MD_SHA1, 335 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 336 "B617318655057264E28BC0B6FB378C8EF146BE00", 1); 337 /* Test 2 */ 338 isc_hmac_test(hmac_st, TEST_INPUT("Jefe"), ISC_MD_SHA1, 339 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61" 340 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20" 341 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"), 342 "EFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79", 1); 343 /* Test 3 */ 344 isc_hmac_test(hmac_st, 345 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 346 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 347 ISC_MD_SHA1, 348 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 349 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 350 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 351 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 352 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"), 353 "125D7342B9AC11CD91A39AF48AA17B4F63F175D3", 1); 354 /* Test 4 */ 355 isc_hmac_test(hmac_st, 356 TEST_INPUT("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 357 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 358 "\x15\x16\x17\x18\x19"), 359 ISC_MD_SHA1, 360 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 361 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 362 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 363 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 364 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"), 365 "4C9007F4026250C6BC8414F9BF50C86C2D7235DA", 1); 366#if 0 367 /* Test 5 */ 368 isc_hmac_test(hmac_st, 369 TEST_INPUT("\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 370 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"), 371 ISC_MD_SHA1, 372 TEST_INPUT("Test With Truncation"), 373 "4C1A03424B55E07FE7F27BE1", 374 1); 375#endif /* if 0 */ 376 /* Test 6 */ 377 isc_hmac_test(hmac_st, 378 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 379 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 380 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 381 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 382 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 383 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 384 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 385 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 386 ISC_MD_SHA1, 387 TEST_INPUT("Test Using Larger Than Block-Size Key - " 388 "Hash Key First"), 389 "AA4AE5E15272D00E95705637CE8A3B55ED402112", 1); 390 /* Test 7 */ 391 isc_hmac_test(hmac_st, 392 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 393 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 394 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 395 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 396 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 397 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 398 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 399 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 400 ISC_MD_SHA1, 401 TEST_INPUT("Test Using Larger Than Block-Size Key and " 402 "Larger Than One Block-Size Data"), 403 "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 1); 404} 405 406ISC_RUN_TEST_IMPL(isc_hmac_sha224) { 407 isc_hmac_t *hmac_st = *state; 408 409 /* Test 0 */ 410 isc_hmac_test(hmac_st, TEST_INPUT(""), ISC_MD_SHA224, TEST_INPUT(""), 411 "5CE14F72894662213E2748D2A6BA234B74263910CEDDE2F5" 412 "A9271524", 413 1); 414 415 /* Test 1 */ 416 isc_hmac_test(hmac_st, 417 TEST_INPUT("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 418 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"), 419 ISC_MD_SHA224, 420 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 421 "896FB1128ABBDF196832107CD49DF33F47B4B1169912BA" 422 "4F53684B22", 423 1); 424 /* Test 2 */ 425 isc_hmac_test(hmac_st, TEST_INPUT("Jefe"), ISC_MD_SHA224, 426 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61" 427 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20" 428 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"), 429 "A30E01098BC6DBBF45690F3A7E9E6D0F8BBEA2A39E61480" 430 "08FD05E44", 431 1); 432 /* Test 3 */ 433 isc_hmac_test(hmac_st, 434 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 435 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 436 ISC_MD_SHA224, 437 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 438 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 439 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 440 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 441 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"), 442 "7FB3CB3588C6C1F6FFA9694D7D6AD2649365B0C1F65D69" 443 "D1EC8333EA", 444 1); 445 /* Test 4 */ 446 isc_hmac_test(hmac_st, 447 TEST_INPUT("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 448 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 449 "\x15\x16\x17\x18\x19"), 450 ISC_MD_SHA224, 451 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 452 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 453 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 454 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 455 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"), 456 "6C11506874013CAC6A2ABC1BB382627CEC6A90D86EFC01" 457 "2DE7AFEC5A", 458 1); 459#if 0 460 /* Test 5 -- unimplemented optional functionality */ 461 isc_hmac_test(hmac_st, 462 TEST_INPUT("\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 463 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"), 464 ISC_MD_SHA224, 465 TEST_INPUT("Test With Truncation"), 466 "4C1A03424B55E07FE7F27BE1", 467 1); 468#endif /* if 0 */ 469 /* Test 6 */ 470 isc_hmac_test(hmac_st, 471 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 472 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 473 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 474 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 475 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 476 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 477 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 478 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 479 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 480 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 481 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 482 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 483 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 484 "\xaa"), 485 ISC_MD_SHA224, 486 TEST_INPUT("Test Using Larger Than Block-Size Key - " 487 "Hash Key First"), 488 "95E9A0DB962095ADAEBE9B2D6F0DBCE2D499F112F2D2B7" 489 "273FA6870E", 490 1); 491 /* Test 7 */ 492 isc_hmac_test(hmac_st, 493 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 494 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 495 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 496 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 497 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 498 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 499 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 500 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 501 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 502 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 503 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 504 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 505 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 506 "\xaa"), 507 ISC_MD_SHA224, 508 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20" 509 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67" 510 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20" 511 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b" 512 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20" 513 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67" 514 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c" 515 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64" 516 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b" 517 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74" 518 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65" 519 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62" 520 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20" 521 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41" 522 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68" 523 "\x6d\x2e"), 524 "3A854166AC5D9F023F54D517D0B39DBD946770DB9C2B95" 525 "C9F6F565D1", 526 1); 527} 528 529ISC_RUN_TEST_IMPL(isc_hmac_sha256) { 530 isc_hmac_t *hmac_st = *state; 531 532 /* Test 0 */ 533 isc_hmac_test(hmac_st, TEST_INPUT(""), ISC_MD_SHA256, TEST_INPUT(""), 534 "B613679A0814D9EC772F95D778C35FC5FF1697C493715653" 535 "C6C712144292C5AD", 536 1); 537 538 /* Test 1 */ 539 isc_hmac_test(hmac_st, 540 TEST_INPUT("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 541 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"), 542 ISC_MD_SHA256, 543 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 544 "B0344C61D8DB38535CA8AFCEAF0BF12B881DC200C9833D" 545 "A726E9376C2E32CFF7", 546 1); 547 /* Test 2 */ 548 isc_hmac_test(hmac_st, TEST_INPUT("Jefe"), ISC_MD_SHA256, 549 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61" 550 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20" 551 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"), 552 "5BDCC146BF60754E6A042426089575C75A003F089D2739" 553 "839DEC58B964EC3843", 554 1); 555 /* Test 3 */ 556 isc_hmac_test(hmac_st, 557 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 558 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 559 ISC_MD_SHA256, 560 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 561 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 562 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 563 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 564 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"), 565 "773EA91E36800E46854DB8EBD09181A72959098B3EF8C1" 566 "22D9635514CED565FE", 567 1); 568 /* Test 4 */ 569 isc_hmac_test(hmac_st, 570 TEST_INPUT("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 571 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 572 "\x15\x16\x17\x18\x19"), 573 ISC_MD_SHA256, 574 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 575 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 576 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 577 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 578 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"), 579 "82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8" 580 "077A2E3FF46729665B", 581 1); 582#if 0 583 /* Test 5 -- unimplemented optional functionality */ 584 isc_hmac_test(hmac_st, 585 TEST_INPUT("\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 586 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"), 587 ISC_MD_SHA256, 588 TEST_INPUT("Test With Truncation"), 589 "4C1A03424B55E07FE7F27BE1", 590 1); 591#endif /* if 0 */ 592 /* Test 6 */ 593 isc_hmac_test(hmac_st, 594 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 595 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 596 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 597 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 598 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 599 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 600 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 601 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 602 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 603 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 604 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 605 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 606 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 607 "\xaa"), 608 ISC_MD_SHA256, 609 TEST_INPUT("Test Using Larger Than Block-Size Key - " 610 "Hash Key First"), 611 "60E431591EE0B67F0D8A26AACBF5B77F8E0BC6213728C5" 612 "140546040F0EE37F54", 613 1); 614 /* Test 7 */ 615 isc_hmac_test(hmac_st, 616 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 617 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 618 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 619 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 620 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 621 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 622 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 623 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 624 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 625 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 626 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 627 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 628 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 629 "\xaa"), 630 ISC_MD_SHA256, 631 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20" 632 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67" 633 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20" 634 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b" 635 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20" 636 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67" 637 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c" 638 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64" 639 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b" 640 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74" 641 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65" 642 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62" 643 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20" 644 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41" 645 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68" 646 "\x6d\x2e"), 647 "9B09FFA71B942FCB27635FBCD5B0E944BFDC63644F0713" 648 "938A7F51535C3A35E2", 649 1); 650} 651 652ISC_RUN_TEST_IMPL(isc_hmac_sha384) { 653 isc_hmac_t *hmac_st = *state; 654 655 /* Test 0 */ 656 isc_hmac_test(hmac_st, TEST_INPUT(""), ISC_MD_SHA384, TEST_INPUT(""), 657 "6C1F2EE938FAD2E24BD91298474382CA218C75DB3D83E114" 658 "B3D4367776D14D3551289E75E8209CD4B792302840234ADC", 659 1); 660 661 /* Test 1 */ 662 isc_hmac_test(hmac_st, 663 TEST_INPUT("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 664 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"), 665 ISC_MD_SHA384, 666 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 667 "AFD03944D84895626B0825F4AB46907F15F9DADBE4101E" 668 "C682AA034C7CEBC59CFAEA9EA9076EDE7F4AF152" 669 "E8B2FA9CB6", 670 1); 671 /* Test 2 */ 672 isc_hmac_test(hmac_st, TEST_INPUT("Jefe"), ISC_MD_SHA384, 673 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61" 674 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20" 675 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"), 676 "AF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B" 677 "47E42EC3736322445E8E2240CA5E69E2C78B3239" 678 "ECFAB21649", 679 1); 680 /* Test 3 */ 681 isc_hmac_test(hmac_st, 682 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 683 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 684 ISC_MD_SHA384, 685 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 686 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 687 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 688 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 689 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"), 690 "88062608D3E6AD8A0AA2ACE014C8A86F0AA635D947AC9F" 691 "EBE83EF4E55966144B2A5AB39DC13814B94E3AB6" 692 "E101A34F27", 693 1); 694 /* Test 4 */ 695 isc_hmac_test(hmac_st, 696 TEST_INPUT("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 697 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 698 "\x15\x16\x17\x18\x19"), 699 ISC_MD_SHA384, 700 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 701 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 702 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 703 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 704 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"), 705 "3E8A69B7783C25851933AB6290AF6CA77A998148085000" 706 "9CC5577C6E1F573B4E6801DD23C4A7D679CCF8A3" 707 "86C674CFFB", 708 1); 709#if 0 710 /* Test 5 -- unimplemented optional functionality */ 711 isc_hmac_test(hmac_st, 712 TEST_INPUT("\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 713 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"), 714 ISC_MD_SHA384, 715 TEST_INPUT("Test With Truncation"), 716 "4C1A03424B55E07FE7F27BE1", 717 1); 718#endif /* if 0 */ 719 /* Test 6 */ 720 isc_hmac_test(hmac_st, 721 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 722 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 723 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 724 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 725 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 726 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 727 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 728 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 729 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 730 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 731 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 732 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 733 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 734 "\xaa"), 735 ISC_MD_SHA384, 736 TEST_INPUT("Test Using Larger Than Block-Size Key - " 737 "Hash Key First"), 738 "4ECE084485813E9088D2C63A041BC5B44F9EF1012A2B58" 739 "8F3CD11F05033AC4C60C2EF6AB4030FE8296248D" 740 "F163F44952", 741 1); 742 /* Test 7 */ 743 isc_hmac_test(hmac_st, 744 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 745 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 746 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 747 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 748 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 749 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 750 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 751 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 752 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 753 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 754 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 755 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 756 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 757 "\xaa"), 758 ISC_MD_SHA384, 759 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20" 760 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67" 761 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20" 762 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b" 763 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20" 764 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67" 765 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c" 766 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64" 767 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b" 768 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74" 769 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65" 770 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62" 771 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20" 772 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41" 773 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68" 774 "\x6d\x2e"), 775 "6617178E941F020D351E2F254E8FD32C602420FEB0B8FB" 776 "9ADCCEBB82461E99C5A678CC31E799176D3860E6" 777 "110C46523E", 778 1); 779} 780 781ISC_RUN_TEST_IMPL(isc_hmac_sha512) { 782 isc_hmac_t *hmac_st = *state; 783 784 /* Test 0 */ 785 isc_hmac_test(hmac_st, TEST_INPUT(""), ISC_MD_SHA512, TEST_INPUT(""), 786 "B936CEE86C9F87AA5D3C6F2E84CB5A4239A5FE50480A6EC6" 787 "6B70AB5B1F4AC6730C6C515421B327EC1D69402E53DFB49A" 788 "D7381EB067B338FD7B0CB22247225D47", 789 1); 790 791 /* Test 1 */ 792 isc_hmac_test(hmac_st, 793 TEST_INPUT("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" 794 "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"), 795 ISC_MD_SHA512, 796 TEST_INPUT("\x48\x69\x20\x54\x68\x65\x72\x65"), 797 "87AA7CDEA5EF619D4FF0B4241A1D6CB02379F4E2CE4EC2" 798 "787AD0B30545E17CDEDAA833B7D6B8A702038B27" 799 "4EAEA3F4E4BE9D914EEB61F1702E696C203A126854", 800 1); 801 /* Test 2 */ 802 isc_hmac_test(hmac_st, TEST_INPUT("Jefe"), ISC_MD_SHA512, 803 TEST_INPUT("\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61" 804 "\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20" 805 "\x6e\x6f\x74\x68\x69\x6e\x67\x3f"), 806 "164B7A7BFCF819E2E395FBE73B56E0A387BD64222E831F" 807 "D610270CD7EA2505549758BF75C05A994A6D034F" 808 "65F8F0E6FDCAEAB1A34D4A6B4B636E070A38BCE737", 809 1); 810 /* Test 3 */ 811 isc_hmac_test(hmac_st, 812 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 813 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"), 814 ISC_MD_SHA512, 815 TEST_INPUT("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 816 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 817 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 818 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" 819 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"), 820 "FA73B0089D56A284EFB0F0756C890BE9B1B5DBDD8EE81A" 821 "3655F83E33B2279D39BF3E848279A722C806B485" 822 "A47E67C807B946A337BEE8942674278859E13292FB", 823 1); 824 /* Test 4 */ 825 isc_hmac_test(hmac_st, 826 TEST_INPUT("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 827 "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" 828 "\x15\x16\x17\x18\x19"), 829 ISC_MD_SHA512, 830 TEST_INPUT("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 831 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 832 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 833 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" 834 "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"), 835 "B0BA465637458C6990E5A8C5F61D4AF7E576D97FF94B87" 836 "2DE76F8050361EE3DBA91CA5C11AA25EB4D67927" 837 "5CC5788063A5F19741120C4F2DE2ADEBEB10A298DD", 838 1); 839#if 0 840 /* Test 5 -- unimplemented optional functionality */ 841 isc_hmac_test(hmac_st, 842 TEST_INPUT("\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c" 843 "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"), 844 ISC_MD_SHA512, 845 TEST_INPUT("Test With Truncation"), 846 "4C1A03424B55E07FE7F27BE1", 847 1); 848#endif /* if 0 */ 849 /* Test 6 */ 850 isc_hmac_test(hmac_st, 851 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 852 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 853 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 854 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 855 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 856 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 857 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 858 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 859 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 860 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 861 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 862 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 863 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 864 "\xaa"), 865 ISC_MD_SHA512, 866 TEST_INPUT("Test Using Larger Than Block-Size Key - " 867 "Hash Key First"), 868 "80B24263C7C1A3EBB71493C1DD7BE8B49B46D1F41B4AEE" 869 "C1121B013783F8F3526B56D037E05F2598BD0FD2" 870 "215D6A1E5295E64F73F63F0AEC8B915A985D786598", 871 1); 872 /* Test 7 */ 873 isc_hmac_test(hmac_st, 874 TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 875 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 876 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 877 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 878 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 879 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 880 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 881 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 882 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 883 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 884 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 885 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 886 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" 887 "\xaa"), 888 ISC_MD_SHA512, 889 TEST_INPUT("\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20" 890 "\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67" 891 "\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20" 892 "\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b" 893 "\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20" 894 "\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67" 895 "\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c" 896 "\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64" 897 "\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b" 898 "\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74" 899 "\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65" 900 "\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62" 901 "\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20" 902 "\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41" 903 "\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68" 904 "\x6d\x2e"), 905 "E37B6A775DC87DBAA4DFA9F96E5E3FFDDEBD71F8867289" 906 "865DF5A32D20CDC944B6022CAC3C4982B10D5EEB" 907 "55C3E4DE15134676FB6DE0446065C97440FA8C6A58", 908 1); 909} 910 911ISC_TEST_LIST_START 912 913ISC_TEST_ENTRY(isc_hmac_new) 914ISC_TEST_ENTRY_CUSTOM(isc_hmac_init, _reset, _reset) 915 916ISC_TEST_ENTRY_CUSTOM(isc_hmac_reset, _reset, _reset) 917 918ISC_TEST_ENTRY(isc_hmac_md5) 919ISC_TEST_ENTRY(isc_hmac_sha1) 920ISC_TEST_ENTRY(isc_hmac_sha224) 921ISC_TEST_ENTRY(isc_hmac_sha256) 922ISC_TEST_ENTRY(isc_hmac_sha384) 923ISC_TEST_ENTRY(isc_hmac_sha512) 924 925ISC_TEST_ENTRY_CUSTOM(isc_hmac_update, _reset, _reset) 926ISC_TEST_ENTRY_CUSTOM(isc_hmac_final, _reset, _reset) 927 928ISC_TEST_ENTRY(isc_hmac_free) 929 930ISC_TEST_LIST_END 931 932ISC_TEST_MAIN_CUSTOM(_setup, _teardown) 933