xref: /openbsd-src/usr.sbin/unbound/util/storage/lookup3.h (revision 5d76a658a62184f1f911e7dc8293a7e6a3baf214)
1933707f3Ssthen /*
2933707f3Ssthen  * util/storage/lookup3.h - header file for hashing functions.
3933707f3Ssthen  *
4933707f3Ssthen  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5933707f3Ssthen  *
6933707f3Ssthen  * This software is open source.
7933707f3Ssthen  *
8933707f3Ssthen  * Redistribution and use in source and binary forms, with or without
9933707f3Ssthen  * modification, are permitted provided that the following conditions
10933707f3Ssthen  * are met:
11933707f3Ssthen  *
12933707f3Ssthen  * Redistributions of source code must retain the above copyright notice,
13933707f3Ssthen  * this list of conditions and the following disclaimer.
14933707f3Ssthen  *
15933707f3Ssthen  * Redistributions in binary form must reproduce the above copyright notice,
16933707f3Ssthen  * this list of conditions and the following disclaimer in the documentation
17933707f3Ssthen  * and/or other materials provided with the distribution.
18933707f3Ssthen  *
19933707f3Ssthen  * Neither the name of the NLNET LABS nor the names of its contributors may
20933707f3Ssthen  * be used to endorse or promote products derived from this software without
21933707f3Ssthen  * specific prior written permission.
22933707f3Ssthen  *
23933707f3Ssthen  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24*5d76a658Ssthen  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25*5d76a658Ssthen  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26*5d76a658Ssthen  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27*5d76a658Ssthen  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28*5d76a658Ssthen  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29*5d76a658Ssthen  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30*5d76a658Ssthen  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31*5d76a658Ssthen  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32*5d76a658Ssthen  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*5d76a658Ssthen  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34933707f3Ssthen  */
35933707f3Ssthen 
36933707f3Ssthen /**
37933707f3Ssthen  * \file
38933707f3Ssthen  *
39933707f3Ssthen  * This file contains header definitions for the hash functions we use.
40933707f3Ssthen  * The hash functions are public domain (see lookup3.c).
41933707f3Ssthen  */
42933707f3Ssthen 
43933707f3Ssthen #ifndef UTIL_STORAGE_LOOKUP3_H
44933707f3Ssthen #define UTIL_STORAGE_LOOKUP3_H
45933707f3Ssthen 
46933707f3Ssthen /**
47933707f3Ssthen  * Hash key made of 4byte chunks.
48933707f3Ssthen  * @param k: the key, an array of uint32_t values
49933707f3Ssthen  * @param length: the length of the key, in uint32_ts
50933707f3Ssthen  * @param initval: the previous hash, or an arbitrary value
51933707f3Ssthen  * @return: hash value.
52933707f3Ssthen  */
53933707f3Ssthen uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval);
54933707f3Ssthen 
55933707f3Ssthen /**
56933707f3Ssthen  * Hash key data.
57933707f3Ssthen  * @param k: the key, array of uint8_t
58933707f3Ssthen  * @param length: the length of the key, in uint8_ts
59933707f3Ssthen  * @param initval: the previous hash, or an arbitrary value
60933707f3Ssthen  * @return: hash value.
61933707f3Ssthen  */
62933707f3Ssthen uint32_t hashlittle(const void *k, size_t length, uint32_t initval);
63933707f3Ssthen 
64933707f3Ssthen /**
65933707f3Ssthen  * Set the randomisation initial value, set this before threads start,
66933707f3Ssthen  * and before hashing stuff (because it changes subsequent results).
67933707f3Ssthen  * @param v: value
68933707f3Ssthen  */
69933707f3Ssthen void hash_set_raninit(uint32_t v);
70933707f3Ssthen 
71933707f3Ssthen #endif /* UTIL_STORAGE_LOOKUP3_H */
72