xref: /openbsd-src/usr.sbin/nsd/lookup3.h (revision cbbc2d6cdd2f1bfa0d6618cbef3bebc5a2370302)
12c1ae072Ssthen /*
22c1ae072Ssthen  * util/storage/lookup3.h - header file for hashing functions.
32c1ae072Ssthen  *
42c1ae072Ssthen  * Copyright (c) 2007, NLnet Labs. All rights reserved.
52c1ae072Ssthen  *
62c1ae072Ssthen  * This software is open source.
72c1ae072Ssthen  *
82c1ae072Ssthen  * Redistribution and use in source and binary forms, with or without
92c1ae072Ssthen  * modification, are permitted provided that the following conditions
102c1ae072Ssthen  * are met:
112c1ae072Ssthen  *
122c1ae072Ssthen  * Redistributions of source code must retain the above copyright notice,
132c1ae072Ssthen  * this list of conditions and the following disclaimer.
142c1ae072Ssthen  *
152c1ae072Ssthen  * Redistributions in binary form must reproduce the above copyright notice,
162c1ae072Ssthen  * this list of conditions and the following disclaimer in the documentation
172c1ae072Ssthen  * and/or other materials provided with the distribution.
182c1ae072Ssthen  *
192c1ae072Ssthen  * Neither the name of the NLNET LABS nor the names of its contributors may
202c1ae072Ssthen  * be used to endorse or promote products derived from this software without
212c1ae072Ssthen  * specific prior written permission.
222c1ae072Ssthen  *
232c1ae072Ssthen  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24*cbbc2d6cSbrad  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25*cbbc2d6cSbrad  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26*cbbc2d6cSbrad  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27*cbbc2d6cSbrad  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28*cbbc2d6cSbrad  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29*cbbc2d6cSbrad  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30*cbbc2d6cSbrad  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31*cbbc2d6cSbrad  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32*cbbc2d6cSbrad  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*cbbc2d6cSbrad  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
342c1ae072Ssthen  */
352c1ae072Ssthen 
362c1ae072Ssthen /**
372c1ae072Ssthen  * \file
382c1ae072Ssthen  *
392c1ae072Ssthen  * This file contains header definitions for the hash functions we use.
402c1ae072Ssthen  * The hash functions are public domain (see lookup3.c).
412c1ae072Ssthen  */
422c1ae072Ssthen 
432c1ae072Ssthen #ifndef UTIL_STORAGE_LOOKUP3_H
442c1ae072Ssthen #define UTIL_STORAGE_LOOKUP3_H
452c1ae072Ssthen 
462c1ae072Ssthen /**
472c1ae072Ssthen  * Hash key made of 4byte chunks.
482c1ae072Ssthen  * @param k: the key, an array of uint32_t values
492c1ae072Ssthen  * @param length: the length of the key, in uint32_ts
502c1ae072Ssthen  * @param initval: the previous hash, or an arbitrary value
512c1ae072Ssthen  * @return: hash value.
522c1ae072Ssthen  */
532c1ae072Ssthen uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval);
542c1ae072Ssthen 
552c1ae072Ssthen /**
562c1ae072Ssthen  * Hash key data.
572c1ae072Ssthen  * @param k: the key, array of uint8_t
582c1ae072Ssthen  * @param length: the length of the key, in uint8_ts
592c1ae072Ssthen  * @param initval: the previous hash, or an arbitrary value
602c1ae072Ssthen  * @return: hash value.
612c1ae072Ssthen  */
622c1ae072Ssthen uint32_t hashlittle(const void *k, size_t length, uint32_t initval);
632c1ae072Ssthen 
642c1ae072Ssthen /**
652c1ae072Ssthen  * Set the randomisation initial value, set this before threads start,
662c1ae072Ssthen  * and before hashing stuff (because it changes subsequent results).
672c1ae072Ssthen  * @param v: value
682c1ae072Ssthen  */
692c1ae072Ssthen void hash_set_raninit(uint32_t v);
702c1ae072Ssthen 
712c1ae072Ssthen #endif /* UTIL_STORAGE_LOOKUP3_H */
72