]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove isc_hash_reverse function
authorOndřej Surý <ondrej@sury.org>
Thu, 9 May 2019 08:50:57 +0000 (15:50 +0700)
committerOndřej Surý <ondrej@sury.org>
Tue, 21 May 2019 10:23:17 +0000 (10:23 +0000)
lib/dns/name.c
lib/isc/hash.c
lib/isc/include/isc/hash.h
lib/isc/tests/hash_test.c

index dcea87e1b2355a61b82da022081025cda8002044..2c3ce4a8e826f24e1492dda5233ba8a57f924158 100644 (file)
@@ -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
index 4d9857889b64543bfae4d3371e93afa5907aa735..2b58a9ae4c552e481e2a9ec04d304cf4426f7b30 100644 (file)
@@ -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);
-}
index f1c1f57450f22b9bb20395bb5a09a97c0693c8c9..3989d0449ec40d412f395779331dc76948cca060 100644 (file)
@@ -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
index 056197a4454b31d96d42d74739aa626b259541aa..cb6830b373f6606a01cb8dba3b9438d012dee2c8 100644 (file)
@@ -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),
        };