#include <config.h>
#include <isc/entropy.h>
#include <isc/hash.h>
#include <isc/mem.h>
#include <isc/magic.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/random.h>
#include <isc/refcount.h>
#include <isc/string.h>
#include <isc/util.h>
Go to the source code of this file.
Data Structures | |
struct | isc_hash |
isc hash structure More... | |
Defines | |
#define | HASH_MAGIC ISC_MAGIC('H', 'a', 's', 'h') |
#define | VALID_HASH(h) ISC_MAGIC_VALID((h), HASH_MAGIC) |
#define | PRIME32 0xFFFFFFFB |
A large 32-bit prime number that specifies the range of the hash output. | |
Typedefs | |
typedef isc_uint32_t | hash_accum_t |
Types of random seed and hash accumulator. Perhaps they can be system dependent. | |
typedef isc_uint16_t | hash_random_t |
Types of random seed and hash accumulator. Perhaps they can be system dependent. | |
Functions | |
isc_result_t | isc_hash_ctxcreate (isc_mem_t *mctx, isc_entropy_t *entropy, size_t limit, isc_hash_t **hctxp) |
static void | initialize_lock (void) |
isc_result_t | isc_hash_create (isc_mem_t *mctx, isc_entropy_t *entropy, size_t limit) |
Create a new hash object. | |
void | isc_hash_ctxinit (isc_hash_t *hctx) |
void | isc_hash_init (void) |
Initialize a hash object. | |
void | isc_hash_ctxattach (isc_hash_t *hctx, isc_hash_t **hctxp) |
Attach to a hash object. | |
static void | destroy (isc_hash_t **hctxp) |
void | isc_hash_ctxdetach (isc_hash_t **hctxp) |
Detach from a hash object. | |
void | isc_hash_destroy (void) |
This function is for the single-context mode, and is expected to be used as a counterpart of isc_hash_create(). | |
static unsigned int | hash_calc (isc_hash_t *hctx, const unsigned char *key, unsigned int keylen, isc_boolean_t case_sensitive) |
unsigned int | isc_hash_ctxcalc (isc_hash_t *hctx, const unsigned char *key, unsigned int keylen, isc_boolean_t case_sensitive) |
unsigned int | isc_hash_calc (const unsigned char *key, unsigned int keylen, isc_boolean_t case_sensitive) |
Calculate a hash value. | |
void | isc__hash_setvec (const isc_uint16_t *vec) |
Set the contents of the random vector used in hashing. | |
Variables | |
static isc_mutex_t | createlock |
static isc_once_t | once = ISC_ONCE_INIT |
static isc_hash_t * | hash = NULL |
static unsigned char | maptolower [] |
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.
Definition in file hash.c.
#define HASH_MAGIC ISC_MAGIC('H', 'a', 's', 'h') |
#define VALID_HASH | ( | h | ) | ISC_MAGIC_VALID((h), HASH_MAGIC) |
Definition at line 73 of file hash.c.
Referenced by isc_hash_calc(), isc_hash_ctxattach(), isc_hash_ctxcalc(), isc_hash_ctxdetach(), isc_hash_destroy(), and isc_hash_init().
#define PRIME32 0xFFFFFFFB |
A large 32-bit prime number that specifies the range of the hash output.
Definition at line 78 of file hash.c.
Referenced by hash_calc().
typedef isc_uint32_t hash_accum_t |
typedef isc_uint16_t hash_random_t |
isc_result_t isc_hash_ctxcreate | ( | isc_mem_t * | mctx, | |
isc_entropy_t * | entropy, | |||
size_t | limit, | |||
isc_hash_t ** | hctxp | |||
) |
Definition at line 142 of file hash.c.
References DESTROYLOCK, isc_hash::entropy, HASH_MAGIC, isc_hash::initialized, isc_entropy_attach(), ISC_FALSE, isc_mem_attach(), isc_mem_get, isc_mem_put, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_RANGE, ISC_R_SUCCESS, isc_refcount_init(), isc_hash::limit, isc_hash::lock, isc_hash::magic, isc_hash::mctx, isc_hash::refcnt, REQUIRE, isc_hash::rndvector, and isc_hash::vectorlen.
Referenced by isc_hash_create().
static void initialize_lock | ( | void | ) | [static] |
Definition at line 214 of file hash.c.
References createlock, isc_mutex_init, ISC_R_SUCCESS, and RUNTIME_CHECK.
Referenced by isc_hash_create().
isc_result_t isc_hash_create | ( | isc_mem_t * | mctx, | |
isc_entropy_t * | entropy, | |||
size_t | limit | |||
) |
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.
Definition at line 219 of file hash.c.
References createlock, initialize_lock(), INSIST, isc_hash_ctxcreate(), isc_once_do, ISC_R_SUCCESS, LOCK, once, REQUIRE, RUNTIME_CHECK, and UNLOCK.
Referenced by ATF_TC_BODY(), create_managers(), dns_test_begin(), initialize(), isc_test_begin(), main(), and setup_system().
void isc_hash_ctxinit | ( | isc_hash_t * | hctx | ) |
Definition at line 238 of file hash.c.
References isc_hash::entropy, isc_hash::initialized, INSIST, isc_entropy_getdata(), ISC_R_SUCCESS, isc_random_get(), ISC_TRUE, isc_hash::lock, LOCK, isc_hash::rndvector, UNLOCK, and isc_hash::vectorlen.
Referenced by hash_calc(), and isc_hash_init().
void isc_hash_init | ( | void | ) |
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.
Definition at line 278 of file hash.c.
References INSIST, isc_hash_ctxinit(), and VALID_HASH.
Referenced by run_server(), and setup_system().
void isc_hash_ctxattach | ( | isc_hash_t * | hctx, | |
isc_hash_t ** | hctxp | |||
) |
Attach to a hash object.
This function is only necessary for the multiple-context mode.
Definition at line 285 of file hash.c.
References isc_refcount_increment, isc_hash::refcnt, REQUIRE, and VALID_HASH.
static void destroy | ( | isc_hash_t ** | hctxp | ) | [static] |
Definition at line 294 of file hash.c.
References DESTROYLOCK, isc_hash::entropy, isc_entropy_detach(), isc_mem_detach(), isc_mem_put, isc_refcount_destroy, isc_hash::lock, LOCK, isc_hash::mctx, mctx, isc_hash::refcnt, REQUIRE, isc_hash::rndvector, UNLOCK, and isc_hash::vectorlen.
void isc_hash_ctxdetach | ( | isc_hash_t ** | hctxp | ) |
Detach from a hash object.
This function is for the multiple-context mode, and takes a valid hash object as an argument.
Definition at line 322 of file hash.c.
References destroy(), isc_refcount_decrement, isc_hash::refcnt, REQUIRE, and VALID_HASH.
void isc_hash_destroy | ( | void | ) |
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.
Definition at line 337 of file hash.c.
References destroy(), INSIST, isc_refcount_decrement, isc_hash::refcnt, and VALID_HASH.
Referenced by cleanup(), destroy_managers(), dns_lib_shutdown(), dns_test_end(), initialize(), isc_test_end(), and main().
static unsigned int hash_calc | ( | isc_hash_t * | hctx, | |
const unsigned char * | key, | |||
unsigned int | keylen, | |||
isc_boolean_t | case_sensitive | |||
) | [inline, static] |
Definition at line 349 of file hash.c.
References isc_hash::initialized, ISC_FALSE, isc_hash_ctxinit(), maptolower, PRIME32, and isc_hash::rndvector.
Referenced by isc_hash_calc(), and isc_hash_ctxcalc().
unsigned int isc_hash_ctxcalc | ( | isc_hash_t * | hctx, | |
const unsigned char * | key, | |||
unsigned int | keylen, | |||
isc_boolean_t | case_sensitive | |||
) |
unsigned int isc_hash_calc | ( | const unsigned char * | key, | |
unsigned int | keylen, | |||
isc_boolean_t | case_sensitive | |||
) |
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.
Definition at line 384 of file hash.c.
References hash_calc(), INSIST, REQUIRE, and VALID_HASH.
Referenced by dns_acache_putdb(), dns_acache_setdb(), dns_name_fullhash(), finddbent(), and isc_sockaddr_hash().
void isc__hash_setvec | ( | const isc_uint16_t * | vec | ) |
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.
Definition at line 394 of file hash.c.
References isc_hash::rndvector.
isc_mutex_t createlock [static] |
isc_once_t once = ISC_ONCE_INIT [static] |
isc_hash_t* hash = NULL [static] |
Definition at line 104 of file hash.c.
Referenced by addnsec3(), dash_option(), dns_compress_add(), dns_compress_findglobal(), dns_nsec3_addnsec3(), dns_nsec3_delnsec3(), dns_nsec3_hashname(), dns_nsec3_noexistnodata(), dns_rbt_findnode(), dns_rdatatype_fromtext(), dns_view_adddelegationonly(), dns_view_excludedelegationonly(), dns_view_isdelegationonly(), expand_rrl_hash(), get_entry(), getnsec3parameters(), grow_table(), hashlist_add_dns_name(), hashlist_exists(), hashlist_findnext(), isc_entropy_getdata(), isc_file_sanitize(), ISC_LIST(), isdelegation(), ns_server_signing(), nsec3clean(), query_findclosestnsec3(), totext_nsec3(), and totext_nsec3param().
unsigned char maptolower[] [static] |
Definition at line 106 of file hash.c.
Referenced by dns_name_downcase(), dns_name_equal(), dns_name_fromtext(), dns_name_fromwire(), dns_name_fullcompare(), dns_name_rdatacompare(), hash_calc(), and name_hash().