diff --git a/lib/dns/name.c b/lib/dns/name.c index dcea87e1b2..2c3ce4a8e8 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -456,15 +456,16 @@ dns_name_hash(const dns_name_t *name, bool case_sensitive) { */ REQUIRE(VALID_NAME(name)); - if (name->labels == 0) + if (name->labels == 0) { return (0); + } length = name->length; - if (length > 16) + if (length > 16) { length = 16; + } - return (isc_hash_function_reverse(name->ndata, length, - case_sensitive)); + return (isc_hash_function(name->ndata, length, case_sensitive)); } unsigned int @@ -474,11 +475,11 @@ dns_name_fullhash(const dns_name_t *name, bool case_sensitive) { */ REQUIRE(VALID_NAME(name)); - if (name->labels == 0) + if (name->labels == 0) { return (0); + } - return (isc_hash_function_reverse(name->ndata, name->length, - case_sensitive)); + return (isc_hash_function(name->ndata, name->length, case_sensitive)); } dns_namereln_t diff --git a/lib/isc/hash.c b/lib/isc/hash.c index 4d9857889b..2b58a9ae4c 100644 --- a/lib/isc/hash.c +++ b/lib/isc/hash.c @@ -115,7 +115,8 @@ isc_hash_set_initializer(const void *initializer) { } uint64_t -isc_hash_function(const void *data, const size_t length, +isc_hash_function(const void *data, + const size_t length, const bool case_sensitive) { uint64_t hval; @@ -138,34 +139,3 @@ isc_hash_function(const void *data, const size_t length, return (hval); } - -uint64_t -isc_hash_function_reverse(const void *data, const size_t length, - const bool case_sensitive) -{ - uint64_t hval; -#if defined(WIN32) || defined(WIN64) - uint8_t *input = _alloca(length); - INSIST(buf != NULL); -#else - uint8_t input[length]; -#endif - - REQUIRE(length == 0 || data != NULL); - - RUNTIME_CHECK(isc_once_do(&isc_hash_once, - isc_hash_initialize) == ISC_R_SUCCESS); - - if (case_sensitive) { - for (unsigned int i = 0, j = length - 1; i < length; i++, j--) { - input[i] = ((const uint8_t *)data)[j]; - } - } else { - for (unsigned int i = 0, j = length - 1; i < length; i++, j--) { - input[i] = maptolower[((const uint8_t *)data)[j]]; - } - } - - isc_siphash24(isc_hash_key, input, length, (uint8_t *)&hval); - return (hval); -} diff --git a/lib/isc/include/isc/hash.h b/lib/isc/include/isc/hash.h index f1c1f57450..3989d0449e 100644 --- a/lib/isc/include/isc/hash.h +++ b/lib/isc/include/isc/hash.h @@ -30,9 +30,8 @@ void isc_hash_set_initializer(const void *initializer); uint64_t -isc_hash_function(const void *data, const size_t length, const bool case_sensitive); -uint64_t -isc_hash_function_reverse(const void *data, const size_t length, const bool case_sensitive); +isc_hash_function(const void *data, const size_t length, + const bool case_sensitive); /*!< * \brief Calculate a hash over data. * @@ -43,10 +42,7 @@ isc_hash_function_reverse(const void *data, const size_t length, const bool case * distribution. * * isc_hash_function() calculates the hash from start to end over the - * input data. isc_hash_function_reverse() calculates the hash from the - * end to the start over the input data. The difference in order is - * useful in incremental hashing; for example, a previously hashed - * value for 'com' can be used as input when hashing 'example.com'. + * input data. * * 'data' is the data to be hashed. * @@ -56,9 +52,9 @@ isc_hash_function_reverse(const void *data, const size_t length, const bool case * case_sensitive values. It should typically be false if the hash key * is a DNS name. * - * 'previous_hashp' is a pointer to a previous hash value returned by - * this function. It can be used to perform incremental hashing. NULL - * must be passed during first calls. + * WARNING: In case of case insensitive input, the input buffer cannot + * be longer than 1024, which should be fine, as it is only used for + * DNS names. */ ISC_LANG_ENDDECLS diff --git a/lib/isc/tests/hash_test.c b/lib/isc/tests/hash_test.c index 056197a445..cb6830b373 100644 --- a/lib/isc/tests/hash_test.c +++ b/lib/isc/tests/hash_test.c @@ -70,39 +70,6 @@ isc_hash_function_test(void **state) { assert_int_not_equal(h1, h2); } -/* Reverse hash function test */ -static void -isc_hash_function_reverse_test(void **state) { - unsigned int h1; - unsigned int h2; - - UNUSED(state); - - /* Immutability of hash function */ - h1 = isc_hash_function_reverse(NULL, 0, true); - h2 = isc_hash_function_reverse(NULL, 0, true); - - assert_int_equal(h1, h2); - - /* Hash function characteristics */ - h1 = isc_hash_function_reverse("Hello world", 12, true); - h2 = isc_hash_function_reverse("Hello world", 12, true); - - assert_int_equal(h1, h2); - - /* Case */ - h1 = isc_hash_function_reverse("Hello world", 12, false); - h2 = isc_hash_function_reverse("heLLo WorLd", 12, false); - - assert_int_equal(h1, h2); - - /* Unequal */ - h1 = isc_hash_function_reverse("Hello world", 12, true); - h2 = isc_hash_function_reverse("heLLo WorLd", 12, true); - - assert_true(h1 != h2); -} - /* Hash function initializer test */ static void isc_hash_initializer_test(void **state) { @@ -128,7 +95,6 @@ int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(isc_hash_function_test), - cmocka_unit_test(isc_hash_function_reverse_test), cmocka_unit_test(isc_hash_initializer_test), };