xref: /onnv-gate/usr/src/common/openssl/crypto/lhash/lhash.h (revision 2139:6243c3338933)
10Sstevel@tonic-gate /* crypto/lhash/lhash.h */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate  * All rights reserved.
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * This package is an SSL implementation written
60Sstevel@tonic-gate  * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate  * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate  * the following conditions are aheared to.  The following conditions
110Sstevel@tonic-gate  * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
130Sstevel@tonic-gate  * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate  *
160Sstevel@tonic-gate  * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate  * the code are not to be removed.
180Sstevel@tonic-gate  * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate  * as the author of the parts of the library used.
200Sstevel@tonic-gate  * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate  * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate  *
230Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate  * are met:
260Sstevel@tonic-gate  * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate  *    must display the following acknowledgement:
330Sstevel@tonic-gate  *    "This product includes cryptographic software written by
340Sstevel@tonic-gate  *     Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate  *    The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate  *    being used are not cryptographic related :-).
370Sstevel@tonic-gate  * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate  *    the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate  * SUCH DAMAGE.
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate  * derivative of this code cannot be changed.  i.e. this code cannot simply be
550Sstevel@tonic-gate  * copied and put under another distribution licence
560Sstevel@tonic-gate  * [including the GNU Public Licence.]
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /* Header for dynamic hash table routines
600Sstevel@tonic-gate  * Author - Eric Young
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate 
630Sstevel@tonic-gate #ifndef HEADER_LHASH_H
640Sstevel@tonic-gate #define HEADER_LHASH_H
650Sstevel@tonic-gate 
66*2139Sjp161948 #include <openssl/e_os2.h>
670Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
680Sstevel@tonic-gate #include <stdio.h>
690Sstevel@tonic-gate #endif
700Sstevel@tonic-gate 
710Sstevel@tonic-gate #ifndef OPENSSL_NO_BIO
720Sstevel@tonic-gate #include <openssl/bio.h>
730Sstevel@tonic-gate #endif
740Sstevel@tonic-gate 
750Sstevel@tonic-gate #ifdef  __cplusplus
760Sstevel@tonic-gate extern "C" {
770Sstevel@tonic-gate #endif
780Sstevel@tonic-gate 
790Sstevel@tonic-gate typedef struct lhash_node_st
800Sstevel@tonic-gate 	{
81*2139Sjp161948 	void *data;
820Sstevel@tonic-gate 	struct lhash_node_st *next;
830Sstevel@tonic-gate #ifndef OPENSSL_NO_HASH_COMP
840Sstevel@tonic-gate 	unsigned long hash;
850Sstevel@tonic-gate #endif
860Sstevel@tonic-gate 	} LHASH_NODE;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
890Sstevel@tonic-gate typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
90*2139Sjp161948 typedef void (*LHASH_DOALL_FN_TYPE)(void *);
91*2139Sjp161948 typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.
940Sstevel@tonic-gate  * This way, callbacks can be provided to LHASH structures without function
950Sstevel@tonic-gate  * pointer casting and the macro-defined callbacks provide per-variable casting
960Sstevel@tonic-gate  * before deferring to the underlying type-specific callbacks. NB: It is
970Sstevel@tonic-gate  * possible to place a "static" in front of both the DECLARE and IMPLEMENT
980Sstevel@tonic-gate  * macros if the functions are strictly internal. */
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /* First: "hash" functions */
1010Sstevel@tonic-gate #define DECLARE_LHASH_HASH_FN(f_name,o_type) \
1020Sstevel@tonic-gate 	unsigned long f_name##_LHASH_HASH(const void *);
1030Sstevel@tonic-gate #define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
1040Sstevel@tonic-gate 	unsigned long f_name##_LHASH_HASH(const void *arg) { \
1050Sstevel@tonic-gate 		o_type a = (o_type)arg; \
1060Sstevel@tonic-gate 		return f_name(a); }
1070Sstevel@tonic-gate #define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate /* Second: "compare" functions */
1100Sstevel@tonic-gate #define DECLARE_LHASH_COMP_FN(f_name,o_type) \
1110Sstevel@tonic-gate 	int f_name##_LHASH_COMP(const void *, const void *);
1120Sstevel@tonic-gate #define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
1130Sstevel@tonic-gate 	int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
1140Sstevel@tonic-gate 		o_type a = (o_type)arg1; \
1150Sstevel@tonic-gate 		o_type b = (o_type)arg2; \
1160Sstevel@tonic-gate 		return f_name(a,b); }
1170Sstevel@tonic-gate #define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /* Third: "doall" functions */
1200Sstevel@tonic-gate #define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
121*2139Sjp161948 	void f_name##_LHASH_DOALL(void *);
1220Sstevel@tonic-gate #define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
123*2139Sjp161948 	void f_name##_LHASH_DOALL(void *arg) { \
1240Sstevel@tonic-gate 		o_type a = (o_type)arg; \
1250Sstevel@tonic-gate 		f_name(a); }
1260Sstevel@tonic-gate #define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /* Fourth: "doall_arg" functions */
1290Sstevel@tonic-gate #define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
130*2139Sjp161948 	void f_name##_LHASH_DOALL_ARG(void *, void *);
1310Sstevel@tonic-gate #define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
132*2139Sjp161948 	void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
1330Sstevel@tonic-gate 		o_type a = (o_type)arg1; \
1340Sstevel@tonic-gate 		a_type b = (a_type)arg2; \
1350Sstevel@tonic-gate 		f_name(a,b); }
1360Sstevel@tonic-gate #define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate typedef struct lhash_st
1390Sstevel@tonic-gate 	{
1400Sstevel@tonic-gate 	LHASH_NODE **b;
1410Sstevel@tonic-gate 	LHASH_COMP_FN_TYPE comp;
1420Sstevel@tonic-gate 	LHASH_HASH_FN_TYPE hash;
1430Sstevel@tonic-gate 	unsigned int num_nodes;
1440Sstevel@tonic-gate 	unsigned int num_alloc_nodes;
1450Sstevel@tonic-gate 	unsigned int p;
1460Sstevel@tonic-gate 	unsigned int pmax;
1470Sstevel@tonic-gate 	unsigned long up_load; /* load times 256 */
1480Sstevel@tonic-gate 	unsigned long down_load; /* load times 256 */
1490Sstevel@tonic-gate 	unsigned long num_items;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	unsigned long num_expands;
1520Sstevel@tonic-gate 	unsigned long num_expand_reallocs;
1530Sstevel@tonic-gate 	unsigned long num_contracts;
1540Sstevel@tonic-gate 	unsigned long num_contract_reallocs;
1550Sstevel@tonic-gate 	unsigned long num_hash_calls;
1560Sstevel@tonic-gate 	unsigned long num_comp_calls;
1570Sstevel@tonic-gate 	unsigned long num_insert;
1580Sstevel@tonic-gate 	unsigned long num_replace;
1590Sstevel@tonic-gate 	unsigned long num_delete;
1600Sstevel@tonic-gate 	unsigned long num_no_delete;
1610Sstevel@tonic-gate 	unsigned long num_retrieve;
1620Sstevel@tonic-gate 	unsigned long num_retrieve_miss;
1630Sstevel@tonic-gate 	unsigned long num_hash_comps;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	int error;
1660Sstevel@tonic-gate 	} LHASH;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define LH_LOAD_MULT	256
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /* Indicates a malloc() error in the last call, this is only bad
1710Sstevel@tonic-gate  * in lh_insert(). */
1720Sstevel@tonic-gate #define lh_error(lh)	((lh)->error)
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
1750Sstevel@tonic-gate void lh_free(LHASH *lh);
176*2139Sjp161948 void *lh_insert(LHASH *lh, void *data);
1770Sstevel@tonic-gate void *lh_delete(LHASH *lh, const void *data);
1780Sstevel@tonic-gate void *lh_retrieve(LHASH *lh, const void *data);
1790Sstevel@tonic-gate void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
1800Sstevel@tonic-gate void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
1810Sstevel@tonic-gate unsigned long lh_strhash(const char *c);
1820Sstevel@tonic-gate unsigned long lh_num_items(const LHASH *lh);
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
1850Sstevel@tonic-gate void lh_stats(const LHASH *lh, FILE *out);
1860Sstevel@tonic-gate void lh_node_stats(const LHASH *lh, FILE *out);
1870Sstevel@tonic-gate void lh_node_usage_stats(const LHASH *lh, FILE *out);
1880Sstevel@tonic-gate #endif
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate #ifndef OPENSSL_NO_BIO
1910Sstevel@tonic-gate void lh_stats_bio(const LHASH *lh, BIO *out);
1920Sstevel@tonic-gate void lh_node_stats_bio(const LHASH *lh, BIO *out);
1930Sstevel@tonic-gate void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
1940Sstevel@tonic-gate #endif
1950Sstevel@tonic-gate #ifdef  __cplusplus
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #endif
2000Sstevel@tonic-gate 
201