*/
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
*/
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
}
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;
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);
-}
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.
*
* 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.
*
* 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
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) {
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),
};