/usr/include/dnsdb/hash.h is in libyadifa-dev 2.2.3-1+deb9u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | /*------------------------------------------------------------------------------
*
* Copyright (c) 2011-2016, EURid. All rights reserved.
* The YADIFA TM software product is provided under the BSD 3-clause license:
*
* 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 EURid 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
*
*------------------------------------------------------------------------------
*
*/
/** @defgroup dnsdbcollection Collections used by the database
* @ingroup dnsdb
* @brief Functions used to hash a dns formatted string
*
* Implements the functions used to hash a dns formatted string.
* There functions require the call to an initialization function (hash_init);
*
* @{
*/
#ifndef _HASH_H
#define _HASH_H
#include <dnscore/dnsname.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef u32 hashcode;
#define ZDB_HASH_TABLE_CHAR_SET_SIZE 37
extern const u32 ZDB_HASH_TABLE[256][ZDB_HASH_TABLE_CHAR_SET_SIZE];
extern const u32 ZDB_HASH_TABLE_MAP[256];
extern const u8* WILD_LABEL;
extern const hashcode WILD_HASH;
/** @brief Initializes the hash functions
*
* Initializes the hash function. This MUST be called at least one before
* calling any other hash function.
*
*/
void hash_init();
/** @brief Compute the hash code of a dns name (concatenation of pascal strings ending with an empty one.)
*
* Compute the hash code of a dns name (concatenation of pascal strings ending with an empty one.)
* The function hash_init() MUST be called once first. (This requirement will be lifted later)
*
* @param[in] dns_name the name in its DNS form
*
* @return the hash code as a 32 bits integer
*/
hashcode hash_dnsname(const u8* dns_name);
/** @brief Compute the hash code of a dns label (one pascal string)
*
* Compute the hash code of a dns name (a pascal string)
* The function hash_init() MUST be called once first.
*
* This is one of the most-called functions in the ZDB. Its speed is critical.
*
* @param[in] dns_name the name in its DNS form
*
* @return the hash code as a 32 bits integer
*/
static inline hashcode hash_dnslabel(const u8 *dns_label)
{
u32 len = *dns_label++;
u32 hash = ZDB_HASH_TABLE[len][0];
const u32 *hash_line = (u32*) & ZDB_HASH_TABLE[1][0];
const u8 * const limit = &dns_label[len];
while(dns_label != limit)
{
hash += hash_line[ZDB_HASH_TABLE_MAP[*dns_label++]];
hash_line += ZDB_HASH_TABLE_CHAR_SET_SIZE;
}
return hash;
}
/** @brief Compute the hash code of a pascal name
*
* Compute the hash code of a pascal name.
* The function hash_init() MUST be called once first. (This requirement will be lifted later)
* An interesting thing about a dnsname label : it's a pascal string.
*
* @param[in] pascal_name the name in pascal form
*
* @return the hash code as a 32 bits integer
*/
hashcode hash_pascalname(const u8* pascal_name);
/** @brief Compute the hash code of an asciiz name
*
* Compute the hash code of a pascal name from its asciiz form.
* The function hash_init() MUST be called once first. (This requirement will be lifted later)
*
* @param[in] pascal_name the name in asciiz form
*
* @return the hash code as a 32 bits integer
*/
hashcode hash_asciizname(const char* asciiz_name);
#ifdef __cplusplus
#endif
#endif /* _HASH_H */
/** @} */
/*----------------------------------------------------------------------------*/
|