RUNTIME_CHECK(setup_logging(mctx, stdout, &logc) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
- RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
- == ISC_R_SUCCESS);
-
dns_result_register();
RUNTIME_CHECK(cfg_parser_create(mctx, logc, &parser) == ISC_R_SUCCESS);
isc_log_destroy(&logc);
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_mem_destroy(&mctx);
RUNTIME_CHECK(setup_logging(mctx, errout, &lctx)
== ISC_R_SUCCESS);
RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
- RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
- == ISC_R_SUCCESS);
dns_result_register();
destroy();
if (lctx != NULL)
isc_log_destroy(&lctx);
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_mem_destroy(&mctx);
#ifdef _WIN32
if (ectx == NULL) {
setup_entropy(mctx, NULL, &ectx);
}
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS) {
- fatal("could not initialize hash");
- }
result = dst_lib_init(mctx, ectx,
ISC_ENTROPY_BLOCKING | ISC_ENTROPY_GOODONLY);
if (result != ISC_R_SUCCESS) {
free_all_sets();
cleanup_logging(&lctx);
dst_lib_destroy();
- isc_hash_destroy();
cleanup_entropy(&ectx);
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
if (result != ISC_R_SUCCESS)
fatal("could not initialize dst: %s",
isc_result_totext(result));
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- fatal("could not initialize hash");
isc_entropy_stopcallbacksources(ectx);
setup_logging(mctx, &log);
if (dns_rdataset_isassociated(&rdataset))
dns_rdataset_disassociate(&rdataset);
cleanup_logging(&log);
- isc_hash_destroy();
dst_lib_destroy();
cleanup_entropy(&ectx);
dns_name_destroy();
if (result != ISC_R_SUCCESS)
fatal("could not initialize dst: %s",
isc_result_totext(result));
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- fatal("could not initialize hash");
isc_entropy_stopcallbacksources(ectx);
setup_logging(mctx, &log);
if (dns_rdataset_isassociated(&rdataset))
dns_rdataset_disassociate(&rdataset);
cleanup_logging(&log);
- isc_hash_destroy();
dst_lib_destroy();
cleanup_entropy(&ectx);
dns_name_destroy();
if (result != ISC_R_SUCCESS)
fatal("Could not initialize dst: %s",
isc_result_totext(result));
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- fatal("Could not initialize hash");
isc_entropy_stopcallbacksources(ectx);
result = dst_key_fromnamedfile(filename, dir,
cleanup:
dst_key_free(&key);
- isc_hash_destroy();
dst_lib_destroy();
cleanup_entropy(&ectx);
if (verbose > 10)
if (result != ISC_R_SUCCESS)
fatal("Could not initialize dst: %s",
isc_result_totext(result));
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- fatal("Could not initialize hash");
isc_entropy_stopcallbacksources(ectx);
if (predecessor != NULL) {
if (prevkey != NULL)
dst_key_free(&prevkey);
dst_key_free(&key);
- isc_hash_destroy();
dst_lib_destroy();
cleanup_entropy(&ectx);
if (verbose > 10)
fatal("could not initialize dst: %s",
isc_result_totext(result));
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- fatal("could not create hash context");
-
isc_stdtime_get(&now);
if (startstr != NULL) {
dns_master_styledestroy(&dsstyle, mctx);
cleanup_logging(&log);
- isc_hash_destroy();
dst_lib_destroy();
cleanup_entropy(&ectx);
dns_name_destroy();
fatal("could not initialize dst: %s",
isc_result_totext(result));
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- fatal("could not create hash context");
-
isc_stdtime_get(&now);
rdclass = strtoclass(classname);
cleanup_logging(&log);
dst_lib_destroy();
- isc_hash_destroy();
cleanup_entropy(&ectx);
dns_name_destroy();
if (verbose > 10)
return (ISC_R_UNEXPECTED);
}
- result = isc_hash_create(named_g_mctx, named_g_entropy,
- DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_hash_create() failed: %s",
- isc_result_totext(result));
- return (ISC_R_UNEXPECTED);
- }
-
return (ISC_R_SUCCESS);
}
isc_taskmgr_destroy(&named_g_taskmgr);
isc_timermgr_destroy(&named_g_timermgr);
isc_socketmgr_destroy(&named_g_socketmgr);
-
- /*
- * isc_hash_destroy() cannot be called as long as a resolver may be
- * running. Calling this after isc_taskmgr_destroy() ensures the
- * call is safe.
- */
- isc_hash_destroy();
}
static void
CHECKFATAL(load_configuration(named_g_conffile, server, ISC_TRUE),
"loading configuration");
- isc_hash_init();
-
CHECKFATAL(load_zones(server, ISC_TRUE, ISC_FALSE), "loading zones");
#ifdef ENABLE_AFL
named_g_run_done = ISC_TRUE;
if (entropy == NULL)
setup_entropy(gmctx, NULL, &entropy);
- result = isc_hash_create(gmctx, entropy, DNS_NAME_MAXWIRE);
- check_result(result, "isc_hash_create");
-
result = dns_dispatchmgr_create(gmctx, entropy, &dispatchmgr);
check_result(result, "dns_dispatchmgr_create");
check_result(result, "dst_lib_init");
is_dst_up = ISC_TRUE;
- /* moved after dst_lib_init() */
- isc_hash_init();
-
attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP;
attrmask |= DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6;
ddebug("Shutting down timer manager");
isc_timermgr_destroy(&timermgr);
- ddebug("Destroying hash context");
- isc_hash_destroy();
-
ddebug("Destroying name state");
dns_name_destroy();
isc_log_t *lctx = NULL;
isc_entropy_t *ectx = NULL;
-static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE;
+static isc_boolean_t dst_active = ISC_FALSE;
/*
* Logging categories: this needs to match the list in bin/named/log.c.
CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING));
dst_active = ISC_TRUE;
- CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
- hash_active = ISC_TRUE;
-
CHECK(isc_log_create(mctx, &lctx, &logconfig));
isc_log_registercategories(lctx, categories);
isc_log_setcontext(lctx);
dst_lib_destroy();
dst_active = ISC_FALSE;
}
- if (hash_active) {
- isc_hash_destroy();
- hash_active = ISC_FALSE;
- }
if (ectx != NULL)
isc_entropy_detach(&ectx);
if (mctx != NULL)
result = isc_entropy_create(mctx, &ectx);
check_result(result, "isc_entropy_create()");
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- check_result(result, "isc_hash_create()");
-
result = isc_log_create(mctx, &lctx, &lcfg);
check_result(result, "isc_log_create()");
isc_log_setcontext(lctx);
isc_log_destroy(&lctx);
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_mempool_destroy(&cmp);
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
- RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
- == ISC_R_SUCCESS);
while ((ch = isc_commandline_parse(argc, argv, "d:vw:")) != -1) {
switch (ch) {
isc_log_destroy(&lctx);
- isc_hash_destroy();
isc_entropy_detach(&ectx);
if (verbose)
RUNCHECK(isc_entropy_createfilesource(ectx, randomfile));
RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY));
- RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
taskmgr = NULL;
RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr));
isc_task_detach(&task);
isc_taskmgr_destroy(&taskmgr);
- isc_hash_destroy();
dst_lib_destroy();
isc_entropy_detach(&ectx);
RUNCHECK(isc_log_create(mctx, &log, &logconfig));
RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY));
- RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
taskmgr = NULL;
RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr));
isc_log_destroy(&log);
- isc_hash_destroy();
dst_lib_destroy();
isc_entropy_detach(&ectx);
RUNCHECK(isc_log_create(mctx, &log, &logconfig));
RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY));
- RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
taskmgr = NULL;
RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr));
isc_log_destroy(&log);
- isc_hash_destroy();
dst_lib_destroy();
isc_entropy_detach(&ectx);
ectx = NULL;
RUNCHECK(isc_entropy_create(mctx, &ectx));
RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY));
- RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
RUNCHECK(isc_entropy_getdata(ectx, cookie_secret,
sizeof(cookie_secret), NULL, 0));
isc_taskmgr_destroy(&taskmgr);
dst_lib_destroy();
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_log_destroy(&lctx);
result = isc_entropy_create(mctx, &ectx);
isc_result_check (result, "isc_entropy_create");
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- isc_result_check (result, "isc_hash_create");
-
isc_buffer_init (&buff, argzone, strlen (argzone));
isc_buffer_add (&buff, strlen (argzone));
dns_fixedname_init (&fixedzone);
printf("Operation Complete.\n");
/* Cleanup */
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_mem_destroy(&mctx);
if (zonefile)
result = isc_entropy_create(mctx, &ectx);
check_result(result, "isc_entropy_create");
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- check_result(result, "isc_hash_create");
-
isc_buffer_init(&b, porigin, strlen(porigin));
isc_buffer_add(&b, strlen(porigin));
dns_fixedname_init(&forigin);
PQclear(res);
dns_dbiterator_destroy(&dbiter);
dns_db_detach(&db);
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_mem_destroy(&mctx);
closeandexit(0);
check_result(result, "isc_mem_create");
result = isc_entropy_create(mctx, &ectx);
check_result(result, "isc_entropy_create");
- result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
- check_result(result, "isc_hash_create");
isc_buffer_init(&b, porigin, strlen(porigin));
isc_buffer_add(&b, strlen(porigin));
dns_dbiterator_destroy(&dbiter);
dns_db_detach(&db);
- isc_hash_destroy();
isc_entropy_detach(&ectx);
isc_mem_destroy(&mctx);
*\li A hash value
*/
-unsigned int
-dns_name_hashbylabel(const dns_name_t *name, isc_boolean_t case_sensitive);
-/*%<
- * Provide a hash value for 'name', where the hash value is the sum
- * of the hash values of each label. This function should only be used
- * when incremental hashing is necessary, for example, during RBT
- * traversal. It is not currently used in BIND. Generally,
- * dns_name_fullhash() is the correct function to use for name
- * hashing.
- *
- * Note: if 'case_sensitive' is ISC_FALSE, then names which differ only in
- * case will have the same hash value.
- *
- * Requires:
- *\li 'name' is a valid name
- *
- * Returns:
- *\li A hash value
- */
-
/*
*** Comparisons
***/
result = isc_entropy_create(dns_g_mctx, &ectx);
if (result != ISC_R_SUCCESS)
goto cleanup_db;
- result = isc_hash_create(dns_g_mctx, NULL, DNS_NAME_MAXWIRE);
- if (result != ISC_R_SUCCESS)
- goto cleanup_ectx;
result = dst_lib_init(dns_g_mctx, ectx, 0);
if (result != ISC_R_SUCCESS)
- goto cleanup_hash;
+ goto cleanup_ectx;
result = isc_mutex_init(&reflock);
if (result != ISC_R_SUCCESS)
goto cleanup_dst;
- isc_hash_init();
isc_entropy_detach(&ectx);
initialize_done = ISC_TRUE;
cleanup_ectx:
if (ectx != NULL)
isc_entropy_detach(&ectx);
- cleanup_hash:
- isc_hash_destroy();
cleanup_db:
if (dbimp != NULL)
dns_ecdb_unregister(&dbimp);
dst_lib_destroy();
- if (isc_hashctx != NULL)
- isc_hash_destroy();
if (dbimp != NULL)
dns_ecdb_unregister(&dbimp);
if (dns_g_mctx != NULL)
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_wildcardname = &wild;
-unsigned int
-dns_fullname_hash(const dns_name_t *name, isc_boolean_t case_sensitive);
-
/*
* dns_name_t to text post-conversion procedure.
*/
case_sensitive, NULL));
}
-unsigned int
-dns_fullname_hash(const dns_name_t *name, isc_boolean_t case_sensitive) {
- /*
- * This function was deprecated due to the breakage of the name space
- * convention. We only keep this internally to provide binary backward
- * compatibility.
- */
- return (dns_name_fullhash(name, case_sensitive));
-}
-
-unsigned int
-dns_name_hashbylabel(const dns_name_t *name, isc_boolean_t case_sensitive) {
- unsigned char *offsets;
- dns_offsets_t odata;
- dns_name_t tname;
- unsigned int h = 0;
- unsigned int i;
-
- /*
- * Provide a hash value for 'name'.
- */
- REQUIRE(VALID_NAME(name));
-
- if (name->labels == 0)
- return (0);
- else if (name->labels == 1)
- return (isc_hash_function_reverse(name->ndata, name->length,
- case_sensitive, NULL));
-
- SETUP_OFFSETS(name, offsets, odata);
- DNS_NAME_INIT(&tname, NULL);
- tname.labels = 1;
- h = 0;
- for (i = 0; i < name->labels; i++) {
- tname.ndata = name->ndata + offsets[i];
- if (i == name->labels - 1)
- tname.length = name->length - offsets[i];
- else
- tname.length = offsets[i + 1] - offsets[i];
- h += isc_hash_function_reverse(tname.ndata, tname.length,
- case_sensitive, NULL);
- }
-
- return (h);
-}
-
dns_namereln_t
dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2,
int *orderp, unsigned int *nlabelsp)
result = isc_mem_create(0, 0, &mymctx);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
- result = isc_hash_create(mymctx, NULL, 256);
- ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-
result = dns_db_create(mymctx, "rbt", dns_rootname, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = isc_mem_create(0, 0, &mymctx);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
- result = isc_hash_create(mymctx, NULL, 256);
- ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-
result = dns_db_create(mymctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = isc_mem_create(0, 0, &mymctx);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
- result = isc_hash_create(mymctx, NULL, 256);
- ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-
result = dns_db_create(mymctx, "rbt", dns_rootname, dns_dbtype_cache,
dns_rdataclass_in, 0, NULL, &db);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
int ncpus;
isc_boolean_t debug_mem_record = ISC_TRUE;
-static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE;
+static isc_boolean_t dst_active = ISC_FALSE;
/*
* Logging categories: this needs to match the list in bin/named/log.c.
CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING));
dst_active = ISC_TRUE;
- CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
- hash_active = ISC_TRUE;
-
if (logfile != NULL) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
void
dns_test_end(void) {
- if (hash_active) {
- isc_hash_destroy();
- hash_active = ISC_FALSE;
- }
if (dst_active) {
dst_lib_destroy();
dst_active = ISC_FALSE;
dns_name_getlabelsequence
dns_name_hasbuffer
dns_name_hash
-dns_name_hashbylabel
dns_name_init
dns_name_internalwildcard
dns_name_invalidate
* information regarding copyright ownership.
*/
-/*! \file
- * Some portion of this code was derived from universal hash function
- * libraries of Rice University.
-\section license UH Universal Hashing Library
-
-Copyright ((c)) 2002, Rice University
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of Rice University (RICE) nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-
-This software is provided by RICE and the contributors on an "as is"
-basis, without any representations or warranties of any kind, express
-or implied including, but not limited to, representations or
-warranties of non-infringement, merchantability or fitness for a
-particular purpose. In no event shall RICE or contributors be liable
-for any direct, indirect, incidental, special, exemplary, or
-consequential damages (including, but not limited to, procurement of
-substitute goods or services; loss of use, data, or profits; or
-business interruption) however caused and on any theory of liability,
-whether in contract, strict liability, or tort (including negligence
-or otherwise) arising in any way out of the use of this software, even
-if advised of the possibility of such damage.
-*/
-
#include <config.h>
-
#include <isc/entropy.h>
#include <isc/hash.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/util.h>
-#define HASH_MAGIC ISC_MAGIC('H', 'a', 's', 'h')
-#define VALID_HASH(h) ISC_MAGIC_VALID((h), HASH_MAGIC)
-
-/*%
- * A large 32-bit prime number that specifies the range of the hash output.
- */
-#define PRIME32 0xFFFFFFFB /* 2^32 - 5 */
-
-/*@{*/
-/*%
- * Types of random seed and hash accumulator. Perhaps they can be system
- * dependent.
- */
-typedef isc_uint32_t hash_accum_t;
-typedef isc_uint16_t hash_random_t;
-/*@}*/
-
-/*% isc hash structure */
-struct isc_hash {
- unsigned int magic;
- isc_mem_t *mctx;
- isc_mutex_t lock;
- isc_boolean_t initialized;
- isc_refcount_t refcnt;
- isc_entropy_t *entropy; /*%< entropy source */
- size_t limit; /*%< upper limit of key length */
- size_t vectorlen; /*%< size of the vector below */
- hash_random_t *rndvector; /*%< random vector for universal hashing */
-};
-
-static isc_mutex_t createlock;
-static isc_once_t once = ISC_ONCE_INIT;
-
-LIBISC_EXTERNAL_DATA isc_hash_t *isc_hashctx = NULL;
+static isc_uint32_t fnv_offset_basis;
+static isc_once_t fnv_once = ISC_ONCE_INIT;
+static isc_boolean_t fnv_initialized = ISC_FALSE;
static unsigned char maptolower[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
-isc_result_t
-isc_hash_ctxcreate(isc_mem_t *mctx, isc_entropy_t *entropy,
- size_t limit, isc_hash_t **hctxp)
-{
- isc_result_t result;
- isc_hash_t *hctx;
- size_t vlen;
- hash_random_t *rv;
- hash_accum_t overflow_limit;
-
- REQUIRE(mctx != NULL);
- REQUIRE(hctxp != NULL && *hctxp == NULL);
-
- /*
- * Overflow check. Since our implementation only does a modulo
- * operation at the last stage of hash calculation, the accumulator
- * must not overflow.
- */
- overflow_limit =
- 1 << (((sizeof(hash_accum_t) - sizeof(hash_random_t))) * 8);
- if (overflow_limit < (limit + 1) * 0xff)
- return (ISC_R_RANGE);
-
- hctx = isc_mem_get(mctx, sizeof(isc_hash_t));
- if (hctx == NULL)
- return (ISC_R_NOMEMORY);
-
- vlen = sizeof(hash_random_t) * (limit + 1);
- rv = isc_mem_get(mctx, vlen);
- if (rv == NULL) {
- result = ISC_R_NOMEMORY;
- goto errout;
- }
-
- /*
- * We need a lock.
- */
- result = isc_mutex_init(&hctx->lock);
- if (result != ISC_R_SUCCESS)
- goto errout;
-
- /*
- * From here down, no failures will/can occur.
- */
- hctx->magic = HASH_MAGIC;
- hctx->mctx = NULL;
- isc_mem_attach(mctx, &hctx->mctx);
- hctx->initialized = ISC_FALSE;
- result = isc_refcount_init(&hctx->refcnt, 1);
- if (result != ISC_R_SUCCESS)
- goto cleanup_lock;
- hctx->entropy = NULL;
- hctx->limit = limit;
- hctx->vectorlen = vlen;
- hctx->rndvector = rv;
-
- if (entropy != NULL)
- isc_entropy_attach(entropy, &hctx->entropy);
-
- *hctxp = hctx;
- return (ISC_R_SUCCESS);
-
- cleanup_lock:
- DESTROYLOCK(&hctx->lock);
- errout:
- isc_mem_put(mctx, hctx, sizeof(isc_hash_t));
- if (rv != NULL)
- isc_mem_put(mctx, rv, vlen);
-
- return (result);
-}
-
-static void
-initialize_lock(void) {
- RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_hash_create(isc_mem_t *mctx, isc_entropy_t *entropy, size_t limit) {
- isc_result_t result = ISC_R_SUCCESS;
-
- REQUIRE(mctx != NULL);
- INSIST(isc_hashctx == NULL);
-
- RUNTIME_CHECK(isc_once_do(&once, initialize_lock) == ISC_R_SUCCESS);
-
- LOCK(&createlock);
-
- if (isc_hashctx == NULL)
- result = isc_hash_ctxcreate(mctx, entropy, limit,
- &isc_hashctx);
-
- UNLOCK(&createlock);
-
- return (result);
-}
-
-void
-isc_hash_ctxinit(isc_hash_t *hctx) {
- LOCK(&hctx->lock);
-
- if (hctx->initialized == ISC_TRUE)
- goto out;
-
- if (hctx->entropy != NULL) {
- isc_result_t result;
-
- result = isc_entropy_getdata(hctx->entropy,
- hctx->rndvector,
- (unsigned int)hctx->vectorlen,
- NULL, 0);
- INSIST(result == ISC_R_SUCCESS);
- } else {
- isc_uint32_t pr;
- size_t i, copylen;
- unsigned char *p;
-
- p = (unsigned char *)hctx->rndvector;
- for (i = 0; i < hctx->vectorlen; i += copylen, p += copylen) {
- isc_random_get(&pr);
- if (i + sizeof(pr) <= hctx->vectorlen)
- copylen = sizeof(pr);
- else
- copylen = hctx->vectorlen - i;
-
- memmove(p, &pr, copylen);
- }
- INSIST(p == (unsigned char *)hctx->rndvector +
- hctx->vectorlen);
- }
-
- hctx->initialized = ISC_TRUE;
-
- out:
- UNLOCK(&hctx->lock);
-}
-
-void
-isc_hash_init(void) {
- INSIST(isc_hashctx != NULL && VALID_HASH(isc_hashctx));
-
- isc_hash_ctxinit(isc_hashctx);
-}
-
-void
-isc_hash_ctxattach(isc_hash_t *hctx, isc_hash_t **hctxp) {
- REQUIRE(VALID_HASH(hctx));
- REQUIRE(hctxp != NULL && *hctxp == NULL);
-
- isc_refcount_increment(&hctx->refcnt, NULL);
- *hctxp = hctx;
-}
-
-static void
-destroy(isc_hash_t **hctxp) {
- isc_hash_t *hctx;
- isc_mem_t *mctx;
-
- REQUIRE(hctxp != NULL && *hctxp != NULL);
- hctx = *hctxp;
- *hctxp = NULL;
-
- LOCK(&hctx->lock);
-
- isc_refcount_destroy(&hctx->refcnt);
-
- mctx = hctx->mctx;
- if (hctx->entropy != NULL)
- isc_entropy_detach(&hctx->entropy);
- if (hctx->rndvector != NULL)
- isc_mem_put(mctx, hctx->rndvector, hctx->vectorlen);
-
- UNLOCK(&hctx->lock);
-
- DESTROYLOCK(&hctx->lock);
-
- memset(hctx, 0, sizeof(isc_hash_t));
- isc_mem_put(mctx, hctx, sizeof(isc_hash_t));
- isc_mem_detach(&mctx);
-}
-
-void
-isc_hash_ctxdetach(isc_hash_t **hctxp) {
- isc_hash_t *hctx;
- unsigned int refs;
-
- REQUIRE(hctxp != NULL && VALID_HASH(*hctxp));
- hctx = *hctxp;
-
- isc_refcount_decrement(&hctx->refcnt, &refs);
- if (refs == 0)
- destroy(&hctx);
-
- *hctxp = NULL;
-}
-
-void
-isc_hash_destroy(void) {
- unsigned int refs;
-
- INSIST(isc_hashctx != NULL && VALID_HASH(isc_hashctx));
-
- isc_refcount_decrement(&isc_hashctx->refcnt, &refs);
- INSIST(refs == 0);
-
- destroy(&isc_hashctx);
-}
-
-static inline unsigned int
-hash_calc(isc_hash_t *hctx, const unsigned char *key, unsigned int keylen,
- isc_boolean_t case_sensitive)
-{
- hash_accum_t partial_sum = 0;
- hash_random_t *p = hctx->rndvector;
- unsigned int i = 0;
-
- /* Make it sure that the hash context is initialized. */
- if (hctx->initialized == ISC_FALSE)
- isc_hash_ctxinit(hctx);
-
- if (case_sensitive) {
- for (i = 0; i < keylen; i++)
- partial_sum += key[i] * (hash_accum_t)p[i];
- } else {
- for (i = 0; i < keylen; i++)
- partial_sum += maptolower[key[i]] * (hash_accum_t)p[i];
- }
-
- partial_sum += p[i];
-
- return ((unsigned int)(partial_sum % PRIME32));
-}
-
-unsigned int
-isc_hash_ctxcalc(isc_hash_t *hctx, const unsigned char *key,
- unsigned int keylen, isc_boolean_t case_sensitive)
-{
- REQUIRE(hctx != NULL && VALID_HASH(hctx));
- REQUIRE(keylen <= hctx->limit);
-
- return (hash_calc(hctx, key, keylen, case_sensitive));
-}
-
-unsigned int
-isc_hash_calc(const unsigned char *key, unsigned int keylen,
- isc_boolean_t case_sensitive)
-{
- INSIST(isc_hashctx != NULL && VALID_HASH(isc_hashctx));
- REQUIRE(keylen <= isc_hashctx->limit);
-
- return (hash_calc(isc_hashctx, key, keylen, case_sensitive));
-}
-
-void
-isc__hash_setvec(const isc_uint16_t *vec) {
- int i;
- hash_random_t *p;
-
- if (isc_hashctx == NULL)
- return;
-
- p = isc_hashctx->rndvector;
- for (i = 0; i < 256; i++) {
- p[i] = vec[i];
- }
-}
-
-static isc_uint32_t fnv_offset_basis;
-static isc_once_t fnv_once = ISC_ONCE_INIT;
-static isc_boolean_t fnv_initialized = ISC_FALSE;
-
static void
fnv_initialize(void) {
/*
#ifndef ISC_HASH_H
#define ISC_HASH_H 1
-#include <isc/deprecated.h>
-#include <isc/types.h>
-
-/*****
- ***** Module Info
- *****/
-
-/*! \file isc/hash.h
- *
- * \brief The hash API
- * provides an unpredictable hash value for variable length data.
- * A hash object contains a random vector (which is hidden from clients
- * of this API) to make the actual hash value unpredictable.
- *
- * The algorithm used in the API guarantees the probability of hash
- * collision; in the current implementation, as long as the values stored
- * in the random vector are unpredictable, the probability of hash
- * collision between arbitrary two different values is at most 1/2^16.
- *
- * Although the API is generic about the hash keys, it mainly expects
- * DNS names (and sometimes IPv4/v6 addresses) as inputs. It has an
- * upper limit of the input length, and may run slow to calculate the
- * hash values for large inputs.
- *
- * This API is designed to be general so that it can provide multiple
- * different hash contexts that have different random vectors. However,
- * it should be typical to have a single context for an entire system.
- * To support such cases, the API also provides a single-context mode.
- *
- * \li MP:
- * The hash object is almost read-only. Once the internal random vector
- * is initialized, no write operation will occur, and there will be no
- * need to lock the object to calculate actual hash values.
- *
- * \li Reliability:
- * In some cases this module uses low-level data copy to initialize the
- * random vector. Errors in this part are likely to crash the server or
- * corrupt memory.
- *
- * \li Resources:
- * A buffer, used as a random vector for calculating hash values.
- *
- * \li Security:
- * This module intends to provide unpredictable hash values in
- * adversarial environments in order to avoid denial of service attacks
- * to hash buckets.
- * Its unpredictability relies on the quality of entropy to build the
- * random vector.
- *
- * \li Standards:
- * None.
- */
-
-/***
- *** Imports
- ***/
-
#include <isc/types.h>
/***
***/
ISC_LANG_BEGINDECLS
-LIBISC_EXTERNAL_DATA extern isc_hash_t *isc_hashctx;
-
-isc_result_t
-isc_hash_ctxcreate(isc_mem_t *mctx, isc_entropy_t *entropy, size_t limit,
- isc_hash_t **hctx);
-isc_result_t
-isc_hash_create(isc_mem_t *mctx, isc_entropy_t *entropy, size_t limit);
-/*!<
- * \brief Create a new hash object.
- *
- * isc_hash_ctxcreate() creates a different object.
- *
- * isc_hash_create() creates a module-internal object to support the
- * single-context mode. It should be called only once.
- *
- * 'entropy' must be NULL or a valid entropy object. If 'entropy' is NULL,
- * pseudo random values will be used to build the random vector, which may
- * weaken security.
- *
- * 'limit' specifies the maximum number of hash keys. If it is too large,
- * these functions may fail.
- */
-
-void
-isc_hash_ctxattach(isc_hash_t *hctx, isc_hash_t **hctxp)
- ISC_DEPRECATED;
-/*!<
- * \brief Attach to a hash object.
- *
- * This function is only necessary for the multiple-context mode.
- */
-
-void
-isc_hash_ctxdetach(isc_hash_t **hctxp)
- ISC_DEPRECATED;
-/*!<
- * \brief Detach from a hash object.
- *
- * This function is for the multiple-context mode, and takes a valid
- * hash object as an argument.
- */
-
-void
-isc_hash_destroy(void);
-/*!<
- * \brief This function is for the single-context mode, and is expected to be used
- * as a counterpart of isc_hash_create().
- *
- * A valid module-internal hash object must have been created, and this
- * function should be called only once.
- */
-
-/*@{*/
-void
-isc_hash_ctxinit(isc_hash_t *hctx);
-void
-isc_hash_init(void);
-/*!<
- * \brief Initialize a hash object.
- *
- * It fills in the random vector with a proper
- * source of entropy, which is typically from the entropy object specified
- * at the creation. Thus, it is desirable to call these functions after
- * initializing the entropy object with some good entropy sources.
- *
- * These functions should be called before the first hash calculation.
- *
- * isc_hash_ctxinit() is for the multiple-context mode, and takes a valid hash
- * object as an argument.
- *
- * isc_hash_init() is for the single-context mode. A valid module-internal
- * hash object must have been created, and this function should be called only
- * once.
- */
-/*@}*/
-
-/*@{*/
-unsigned int
-isc_hash_ctxcalc(isc_hash_t *hctx, const unsigned char *key,
- unsigned int keylen, isc_boolean_t case_sensitive)
- ISC_DEPRECATED;
-unsigned int
-isc_hash_calc(const unsigned char *key, unsigned int keylen,
- isc_boolean_t case_sensitive)
- ISC_DEPRECATED;
-/*!<
- * \brief Calculate a hash value.
- *
- * isc_hash_ctxinit() is for the multiple-context mode, and takes a valid hash
- * object as an argument.
- *
- * isc_hash_init() is for the single-context mode. A valid module-internal
- * hash object must have been created.
- *
- * 'key' is the hash key, which is a variable length buffer.
- *
- * 'keylen' specifies the key length, which must not be larger than the limit
- * specified for the corresponding hash object.
- *
- * 'case_sensitive' specifies whether the hash key should be treated as
- * case_sensitive values. It should typically be ISC_FALSE if the hash key
- * is a DNS name.
- */
-/*@}*/
-
-void
-isc__hash_setvec(const isc_uint16_t *vec)
- ISC_DEPRECATED;
-
-/*!<
- * \brief Set the contents of the random vector used in hashing.
- *
- * WARNING: This function is meant to be used only in testing code. It
- * must not be used anywhere in normally running code.
- *
- * The hash context must have been created beforehand, otherwise this
- * function is a nop.
- *
- * 'vec' is not documented here on purpose. You should know what you are
- * doing before using this function.
- */
-
const void *
isc_hash_get_initializer(void);
* useful in incremental hashing; for example, a previously hashed
* value for 'com' can be used as input when hashing 'example.com'.
*
- * This is a new variant of isc_hash_calc() and will supercede
- * isc_hash_calc() eventually.
- *
* 'data' is the data to be hashed.
*
* 'length' is the size of the data to be hashed.
isc_task_t *maintask = NULL;
int ncpus;
-static isc_boolean_t hash_active = ISC_FALSE;
-
/*
* Logging categories: this needs to match the list in bin/named/log.c.
*/
CHECK(isc_mem_create(0, 0, &mctx));
CHECK(isc_entropy_create(mctx, &ectx));
- CHECK(isc_hash_create(mctx, ectx, 255));
- hash_active = ISC_TRUE;
-
if (logfile != NULL) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
isc_task_detach(&maintask);
if (taskmgr != NULL)
isc_taskmgr_destroy(&taskmgr);
- if (hash_active) {
- isc_hash_destroy();
- hash_active = ISC_FALSE;
- }
if (ectx != NULL)
isc_entropy_detach(&ectx);
; These symbols are not needed by the WIN32 build, but build-tarballs
; will complain if they aren't present here.
-isc__hash_setvec
isc_socket_accept
isc_socket_attach
isc_socket_bind
isc__buffer_setactive
isc__buffer_subtract
isc__buffer_usedregion
-isc__hash_setvec
isc__mem_allocate
isc__mem_free
isc__mem_get
isc_fsaccess_changeowner
isc_fsaccess_remove
isc_fsaccess_set
-isc_hash_calc
-isc_hash_create
-isc_hash_ctxattach
-isc_hash_ctxcalc
-isc_hash_ctxcreate
-isc_hash_ctxdetach
-isc_hash_ctxinit
-isc_hash_destroy
isc_hash_function
isc_hash_function_reverse
isc_hash_get_initializer
-isc_hash_init
isc_hash_set_initializer
isc_heap_create
isc_heap_decreased
isc_boolean_t debug_mem_record = ISC_TRUE;
isc_boolean_t run_managers = ISC_FALSE;
-static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE;
+static isc_boolean_t dst_active = ISC_FALSE;
static dns_zone_t *served_zone = NULL;
CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING));
dst_active = ISC_TRUE;
- CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
- hash_active = ISC_TRUE;
-
if (logfile != NULL) {
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
cleanup_managers();
- if (hash_active) {
- isc_hash_destroy();
- hash_active = ISC_FALSE;
- }
-
if (ectx != NULL)
isc_entropy_detach(&ectx);