diff options
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | apps/apps.c | 4 | ||||
-rw-r--r-- | apps/openssl.c | 2 | ||||
-rw-r--r-- | crypto/asn1/tasn_dec.c | 2 | ||||
-rw-r--r-- | crypto/conf/conf_api.c | 2 | ||||
-rw-r--r-- | crypto/lhash/lh_stats.c | 32 | ||||
-rw-r--r-- | crypto/lhash/lhash.c | 124 | ||||
-rw-r--r-- | crypto/lhash/lhash_lcl.h | 42 | ||||
-rw-r--r-- | crypto/objects/o_names.c | 4 | ||||
-rw-r--r-- | crypto/objects/obj_dat.c | 4 | ||||
-rw-r--r-- | crypto/stack/stack.c | 106 | ||||
-rw-r--r-- | crypto/txt_db/txt_db.c | 4 | ||||
-rw-r--r-- | doc/crypto/lh_stats.pod | 25 | ||||
-rw-r--r-- | doc/crypto/lhash.pod | 84 | ||||
-rw-r--r-- | doc/crypto/sk_X509_num.pod | 213 | ||||
-rw-r--r-- | doc/crypto/stack.pod | 212 | ||||
-rw-r--r-- | include/openssl/lhash.h | 142 | ||||
-rw-r--r-- | include/openssl/safestack.h | 84 | ||||
-rw-r--r-- | include/openssl/stack.h | 83 | ||||
-rw-r--r-- | include/openssl/txt_db.h | 2 | ||||
-rw-r--r-- | ssl/ssl_sess.c | 6 | ||||
-rw-r--r-- | util/libcrypto.num | 80 |
22 files changed, 623 insertions, 639 deletions
@@ -4,6 +4,11 @@ Changes between 1.0.2h and 1.1.0 [xx XXX 2016] + *) The stack and lhash API's were renamed to start with OPENSSL_SK_ + and OPENSSL_LH_, respectively. The old names are available + with API compatibility. They new names are now completely documented. + [Rich Salz] + *) Unify TYPE_up_ref(obj) methods signature. SSL_CTX_up_ref(), SSL_up_ref(), X509_up_ref(), EVP_PKEY_up_ref(), X509_CRL_up_ref(), X509_OBJECT_up_ref_count() methods are now returning an diff --git a/apps/apps.c b/apps/apps.c index 37f423b909..5db4b22b3a 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -1283,7 +1283,7 @@ static unsigned long index_serial_hash(const OPENSSL_CSTRING *a) n = a[DB_serial]; while (*n == '0') n++; - return (lh_strhash(n)); + return OPENSSL_LH_strhash(n); } static int index_serial_cmp(const OPENSSL_CSTRING *a, @@ -1303,7 +1303,7 @@ static int index_name_qual(char **a) static unsigned long index_name_hash(const OPENSSL_CSTRING *a) { - return (lh_strhash(a[DB_name])); + return OPENSSL_LH_strhash(a[DB_name]); } int index_name_cmp(const OPENSSL_CSTRING *a, const OPENSSL_CSTRING *b) diff --git a/apps/openssl.c b/apps/openssl.c index e55401036c..f06927778a 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -525,7 +525,7 @@ static int function_cmp(const FUNCTION * a, const FUNCTION * b) static unsigned long function_hash(const FUNCTION * a) { - return lh_strhash(a->name); + return OPENSSL_LH_strhash(a->name); } static int SortFnByName(const void *_f1, const void *_f2) diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index cc491977d6..64bbe40d8f 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -535,7 +535,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, } else if (ret == -1) return -1; if (!*val) - *val = (ASN1_VALUE *)sk_new_null(); + *val = (ASN1_VALUE *)OPENSSL_sk_new_null(); else { /* * We've got a valid STACK: free up any items present diff --git a/crypto/conf/conf_api.c b/crypto/conf/conf_api.c index 0d4b23f681..5535416ab3 100644 --- a/crypto/conf/conf_api.c +++ b/crypto/conf/conf_api.c @@ -100,7 +100,7 @@ char *_CONF_get_string(const CONF *conf, const char *section, static unsigned long conf_value_hash(const CONF_VALUE *v) { - return (lh_strhash(v->section) << 2) ^ lh_strhash(v->name); + return (OPENSSL_LH_strhash(v->section) << 2) ^ OPENSSL_LH_strhash(v->name); } static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) diff --git a/crypto/lhash/lh_stats.c b/crypto/lhash/lh_stats.c index 0644c756e8..7337832422 100644 --- a/crypto/lhash/lh_stats.c +++ b/crypto/lhash/lh_stats.c @@ -18,50 +18,48 @@ #include <openssl/bio.h> #include <openssl/lhash.h> +#include "lhash_lcl.h" # ifndef OPENSSL_NO_STDIO -void lh_stats(const _LHASH *lh, FILE *fp) +void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp) { BIO *bp; bp = BIO_new(BIO_s_file()); if (bp == NULL) - goto end; + return; BIO_set_fp(bp, fp, BIO_NOCLOSE); - lh_stats_bio(lh, bp); + OPENSSL_LH_stats_bio(lh, bp); BIO_free(bp); - end:; } -void lh_node_stats(const _LHASH *lh, FILE *fp) +void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp) { BIO *bp; bp = BIO_new(BIO_s_file()); if (bp == NULL) - goto end; + return; BIO_set_fp(bp, fp, BIO_NOCLOSE); - lh_node_stats_bio(lh, bp); + OPENSSL_LH_node_stats_bio(lh, bp); BIO_free(bp); - end:; } -void lh_node_usage_stats(const _LHASH *lh, FILE *fp) +void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp) { BIO *bp; bp = BIO_new(BIO_s_file()); if (bp == NULL) - goto end; + return; BIO_set_fp(bp, fp, BIO_NOCLOSE); - lh_node_usage_stats_bio(lh, bp); + OPENSSL_LH_node_usage_stats_bio(lh, bp); BIO_free(bp); - end:; } # endif -void lh_stats_bio(const _LHASH *lh, BIO *out) +void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out) { BIO_printf(out, "num_items = %lu\n", lh->num_items); BIO_printf(out, "num_nodes = %u\n", lh->num_nodes); @@ -82,9 +80,9 @@ void lh_stats_bio(const _LHASH *lh, BIO *out) BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps); } -void lh_node_stats_bio(const _LHASH *lh, BIO *out) +void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out) { - LHASH_NODE *n; + OPENSSL_LH_NODE *n; unsigned int i, num; for (i = 0; i < lh->num_nodes; i++) { @@ -94,9 +92,9 @@ void lh_node_stats_bio(const _LHASH *lh, BIO *out) } } -void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out) +void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out) { - LHASH_NODE *n; + OPENSSL_LH_NODE *n; unsigned long num; unsigned int i; unsigned long total = 0, n_used = 0; diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c index 9fa46b0927..3e58eea9c5 100644 --- a/crypto/lhash/lhash.c +++ b/crypto/lhash/lhash.c @@ -7,70 +7,33 @@ * https://www.openssl.org/source/license.html */ -/*- - * Code for dynamic hash table routines - * Author - Eric Young v 2.0 - * - * 2.2 eay - added #include "crypto.h" so the memory leak checking code is - * present. eay 18-Jun-98 - * - * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98 - * - * 2.0 eay - Fixed a bug that occurred when using lh_delete - * from inside lh_doall(). As entries were deleted, - * the 'table' was 'contract()ed', making some entries - * jump from the end of the table to the start, there by - * skipping the lh_doall() processing. eay - 4/12/95 - * - * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs - * were not being free()ed. 21/11/95 - * - * 1.8 eay - Put the stats routines into a separate file, lh_stats.c - * 19/09/95 - * - * 1.7 eay - Removed the fputs() for realloc failures - the code - * should silently tolerate them. I have also fixed things - * lint complained about 04/05/95 - * - * 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92 - * - * 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992 - * - * 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91 - * - * 1.3 eay - Fixed a few lint problems 19/3/1991 - * - * 1.2 eay - Fixed lh_doall problem 13/3/1991 - * - * 1.1 eay - Added lh_doall - * - * 1.0 eay - First version - */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <openssl/crypto.h> #include <openssl/lhash.h> +#include "lhash_lcl.h" + #undef MIN_NODES #define MIN_NODES 16 #define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ #define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ -static void expand(_LHASH *lh); -static void contract(_LHASH *lh); -static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash); +static void expand(OPENSSL_LHASH *lh); +static void contract(OPENSSL_LHASH *lh); +static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, const void *data, unsigned long *rhash); -_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c) +OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c) { - _LHASH *ret; + OPENSSL_LHASH *ret; if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) goto err0; if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL) goto err1; - ret->comp = ((c == NULL) ? (LHASH_COMP_FN_TYPE)strcmp : c); - ret->hash = ((h == NULL) ? (LHASH_HASH_FN_TYPE)lh_strhash : h); + ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c); + ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h); ret->num_nodes = MIN_NODES / 2; ret->num_alloc_nodes = MIN_NODES; ret->pmax = MIN_NODES / 2; @@ -84,10 +47,10 @@ _LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c) return (NULL); } -void lh_free(_LHASH *lh) +void OPENSSL_LH_free(OPENSSL_LHASH *lh) { unsigned int i; - LHASH_NODE *n, *nn; + OPENSSL_LH_NODE *n, *nn; if (lh == NULL) return; @@ -104,10 +67,10 @@ void lh_free(_LHASH *lh) OPENSSL_free(lh); } -void *lh_insert(_LHASH *lh, void *data) +void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data) { unsigned long hash; - LHASH_NODE *nn, **rn; + OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; @@ -137,10 +100,10 @@ void *lh_insert(_LHASH *lh, void *data) return (ret); } -void *lh_delete(_LHASH *lh, const void *data) +void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; - LHASH_NODE *nn, **rn; + OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; @@ -165,10 +128,10 @@ void *lh_delete(_LHASH *lh, const void *data) return (ret); } -void *lh_retrieve(_LHASH *lh, const void *data) +void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; - LHASH_NODE **rn; + OPENSSL_LH_NODE **rn; void *ret; lh->error = 0; @@ -184,11 +147,12 @@ void *lh_retrieve(_LHASH *lh, const void *data) return (ret); } -static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, - LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) +static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg, + OPENSSL_LH_DOALL_FUNC func, + OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg) { int i; - LHASH_NODE *a, *n; + OPENSSL_LH_NODE *a, *n; if (lh == NULL) return; @@ -200,13 +164,6 @@ static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { - /* - * 28/05/91 - eay - n added so items can be deleted via lh_doall - */ - /* - * 22/05/08 - ben - eh? since a is not passed, this should not be - * needed - */ n = a->next; if (use_arg) func_arg(a->data, arg); @@ -217,19 +174,19 @@ static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, } } -void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func) +void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func) { - doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL); + doall_util_fn(lh, 0, func, (OPENSSL_LH_DOALL_FUNCARG)0, NULL); } -void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg) +void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg) { - doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg); + doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg); } -static void expand(_LHASH *lh) +static void expand(OPENSSL_LHASH *lh) { - LHASH_NODE **n, **n1, **n2, *np; + OPENSSL_LH_NODE **n, **n1, **n2, *np; unsigned int p, i, j; unsigned long hash, nni; @@ -238,7 +195,7 @@ static void expand(_LHASH *lh) p = (int)lh->p++; n1 = &(lh->b[p]); n2 = &(lh->b[p + (int)lh->pmax]); - *n2 = NULL; /* 27/07/92 - eay - undefined pointer bug */ + *n2 = NULL; nni = lh->num_alloc_nodes; for (np = *n1; np != NULL;) { @@ -254,7 +211,7 @@ static void expand(_LHASH *lh) if ((lh->p) >= lh->pmax) { j = (int)lh->num_alloc_nodes * 2; - n = OPENSSL_realloc(lh->b, (int)(sizeof(LHASH_NODE *) * j)); + n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j)); if (n == NULL) { /* fputs("realloc error in lhash",stderr); */ lh->error++; @@ -271,15 +228,15 @@ static void expand(_LHASH *lh) } } -static void contract(_LHASH *lh) +static void contract(OPENSSL_LHASH *lh) { - LHASH_NODE **n, *n1, *np; + OPENSSL_LH_NODE **n, *n1, *np; np = lh->b[lh->p + lh->pmax - 1]; lh->b[lh->p + lh->pmax - 1] = NULL; /* 24/07-92 - eay - weird but :-( */ if (lh->p == 0) { n = OPENSSL_realloc(lh->b, - (unsigned int)(sizeof(LHASH_NODE *) * lh->pmax)); + (unsigned int)(sizeof(OPENSSL_LH_NODE *) * lh->pmax)); if (n == NULL) { /* fputs("realloc error in lhash",stderr); */ lh->error++; @@ -306,11 +263,12 @@ static void contract(_LHASH *lh) } } -static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash) +static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, + const void *data, unsigned long *rhash) { - LHASH_NODE **ret, *n1; + OPENSSL_LH_NODE **ret, *n1; unsigned long hash, nn; - LHASH_COMP_FN_TYPE cf; + OPENSSL_LH_COMPFUNC cf; hash = (*(lh->hash)) (data); lh->num_hash_calls++; @@ -341,7 +299,7 @@ static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash) * collisions on /usr/dict/words and it distributes on %2^n quite well, not * as good as MD5, but still good. */ -unsigned long lh_strhash(const char *c) +unsigned long OPENSSL_LH_strhash(const char *c) { unsigned long ret = 0; long n; @@ -369,22 +327,22 @@ unsigned long lh_strhash(const char *c) return ((ret >> 16) ^ ret); } -unsigned long lh_num_items(const _LHASH *lh) +unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh) { return lh ? lh->num_items : 0; } -unsigned long lh_get_down_load(const _LHASH *lh) +unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh) { return lh->down_load; } -void lh_set_down_load(_LHASH *lh, unsigned long down_load) +void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load) { lh->down_load = down_load; } -int lh_error(_LHASH *lh) +int OPENSSL_LH_error(OPENSSL_LHASH *lh) { return lh->error; } diff --git a/crypto/lhash/lhash_lcl.h b/crypto/lhash/lhash_lcl.h new file mode 100644 index 0000000000..cfb0e1ab7b --- /dev/null +++ b/crypto/lhash/lhash_lcl.h @@ -0,0 +1,42 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + + +struct lhash_node_st { + void *data; + struct lhash_node_st *next; + unsigned long hash; +}; + +struct lhash_st { + LHASH_NODE **b; + OPENSSL_LH_COMPFUNC comp; + OPENSSL_LH_HASHFUNC hash; + unsigned int num_nodes; + unsigned int num_alloc_nodes; + unsigned int p; + unsigned int pmax; + unsigned long up_load; /* load times 256 */ + unsigned long down_load; /* load times 256 */ + unsigned long num_items; + unsigned long num_expands; + unsigned long num_expand_reallocs; + unsigned long num_contracts; + unsigned long num_contract_reallocs; + unsigned long num_hash_calls; + unsigned long num_comp_calls; + unsigned long num_insert; + unsigned long num_replace; + unsigned long num_delete; + unsigned long num_no_delete; + unsigned long num_retrieve; + unsigned long num_retrieve_miss; + unsigned long num_hash_comps; + int error; +}; diff --git a/crypto/objects/o_names.c b/crypto/objects/o_names.c index 321a342846..e43fb30a76 100644 --- a/crypto/objects/o_names.c +++ b/crypto/objects/o_names.c @@ -99,7 +99,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); return (0); } - name_funcs->hash_func = lh_strhash; + name_funcs->hash_func = OPENSSL_LH_strhash; name_funcs->cmp_func = obj_strcmp; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); sk_NAME_FUNCS_push(name_funcs_stack, name_funcs); @@ -141,7 +141,7 @@ static unsigned long obj_name_hash(const OBJ_NAME *a) sk_NAME_FUNCS_value(name_funcs_stack, a->type)->hash_func(a->name); } else { - ret = lh_strhash(a->name); + ret = OPENSSL_LH_strhash(a->name); } ret ^= a->type; return (ret); diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index 3b836fe6a5..46f98cb0ff 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -68,10 +68,10 @@ static unsigned long added_obj_hash(const ADDED_OBJ *ca) ret ^= p[i] << ((i * 3) % 24); break; case ADDED_SNAME: - ret = lh_strhash(a->sn); + ret = OPENSSL_LH_strhash(a->sn); break; case ADDED_LNAME: - ret = lh_strhash(a->ln); + ret = OPENSSL_LH_strhash(a->ln); break; case ADDED_NID: ret = a->nid; diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c index c23f3051ea..36fc921aa3 100644 --- a/crypto/stack/stack.c +++ b/crypto/stack/stack.c @@ -17,7 +17,7 @@ struct stack_st { char **data; int sorted; int num_alloc; - int (*comp) (const void *, const void *); + OPENSSL_sk_compfunc comp; }; #undef MIN_NODES @@ -25,9 +25,9 @@ struct stack_st { #include <errno.h> -int (*sk_set_cmp_func(_STACK *sk, int (*c) (const void *, const void *))) - (const void *, const void *) { - int (*old) (const void *, const void *) = sk->comp; +OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfunc c) +{ + OPENSSL_sk_compfunc old = sk->comp; if (sk->comp != c) sk->sorted = 0; @@ -36,12 +36,12 @@ int (*sk_set_cmp_func(_STACK *sk, int (*c) (const void *, const void *))) return old; } -_STACK *sk_dup(_STACK *sk) +OPENSSL_STACK *OPENSSL_sk_dup(OPENSSL_STACK *sk) { - _STACK *ret; + OPENSSL_STACK *ret; char **s; - if ((ret = sk_new(sk->comp)) == NULL) + if ((ret = OPENSSL_sk_new(sk->comp)) == NULL) goto err; s = OPENSSL_realloc((char *)ret->data, (unsigned int)sizeof(char *) * sk->num_alloc); @@ -56,17 +56,17 @@ _STACK *sk_dup(_STACK *sk) ret->comp = sk->comp; return (ret); err: - sk_free(ret); + OPENSSL_sk_free(ret); return (NULL); } -_STACK *sk_deep_copy(_STACK *sk, void *(*copy_func) (void *), - void (*free_func) (void *)) +OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *sk, OPENSSL_sk_copyfunc copy_func, + OPENSSL_sk_freefunc free_func) { - _STACK *ret; + OPENSSL_STACK *ret; int i; - if ((ret = OPENSSL_malloc(sizeof(_STACK))) == NULL) + if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) return ret; ret->comp = sk->comp; ret->sorted = sk->sorted; @@ -87,23 +87,23 @@ _STACK *sk_deep_copy(_STACK *sk, void *(*copy_func) (void *), while (--i >= 0) if (ret->data[i] != NULL) free_func(ret->data[i]); - sk_free(ret); + OPENSSL_sk_free(ret); return NULL; } } return ret; } -_STACK *sk_new_null(void) +OPENSSL_STACK *OPENSSL_sk_new_null(void) { - return sk_new((int (*)(const void *, const void *))0); + return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL); } -_STACK *sk_new(int (*c) (const void *, const void *)) +OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c) { - _STACK *ret; + OPENSSL_STACK *ret; - if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL) + if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) goto err; if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL) goto err; @@ -116,7 +116,7 @@ _STACK *sk_new(int (*c) (const void *, const void *)) return (NULL); } -int sk_insert(_STACK *st, void *data, int loc) +int OPENSSL_sk_insert(OPENSSL_STACK *st, void *data, int loc) { char **s; @@ -142,22 +142,22 @@ int sk_insert(_STACK *st, void *data, int loc) return (st->num); } -void *sk_delete_ptr(_STACK *st, void *p) +void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, void *p) { int i; for (i = 0; i < st->num; i++) if (st->data[i] == p) - return (sk_delete(st, i)); + return (OPENSSL_sk_delete(st, i)); return (NULL); } -void *sk_delete(_STACK *st, int loc) +void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc) { char *ret; int i, j; - if (!st || (loc < 0) || (loc >= st->num)) + if (st == NULL || loc < 0 || loc >= st->num) return NULL; ret = st->data[loc]; @@ -174,7 +174,7 @@ void *sk_delete(_STACK *st, int loc) return (ret); } -static int internal_find(_STACK *st, void *data, int ret_val_options) +static int internal_find(OPENSSL_STACK *st, void *data, int ret_val_options) { const void *const *r; int i; @@ -188,7 +188,7 @@ static int internal_find(_STACK *st, void *data, int ret_val_options) return (i); return (-1); } - sk_sort(st); + OPENSSL_sk_sort(st); if (data == NULL) return (-1); r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp, @@ -198,45 +198,45 @@ static int internal_find(_STACK *st, void *data, int ret_val_options) return (int)((char **)r - st->data); } -int sk_find(_STACK *st, void *data) +int OPENSSL_sk_find(OPENSSL_STACK *st, void *data) { return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH); } -int sk_find_ex(_STACK *st, void *data) +int OPENSSL_sk_find_ex(OPENSSL_STACK *st, void *data) { return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH); } -int sk_push(_STACK *st, void *data) +int OPENSSL_sk_push(OPENSSL_STACK *st, void *data) { - return (sk_insert(st, data, st->num)); + return (OPENSSL_sk_insert(st, data, st->num)); } -int sk_unshift(_STACK *st, void *data) +int OPENSSL_sk_unshift(OPENSSL_STACK *st, void *data) { - return (sk_insert(st, data, 0)); + return (OPENSSL_sk_insert(st, data, 0)); } -void *sk_shift(_STACK *st) +void *OPENSSL_sk_shift(OPENSSL_STACK *st) { if (st == NULL) return (NULL); if (st->num <= 0) return (NULL); - return (sk_delete(st, 0)); + return (OPENSSL_sk_delete(st, 0)); } -void *sk_pop(_STACK *st) +void *OPENSSL_sk_pop(OPENSSL_STACK *st) { if (st == NULL) return (NULL); if (st->num <= 0) return (NULL); - return (sk_delete(st, st->num - 1)); + return (OPENSSL_sk_delete(st, st->num - 1)); } -void sk_zero(_STACK *st) +void OPENSSL_sk_zero(OPENSSL_STACK *st) { if (st == NULL) return; @@ -246,7 +246,7 @@ void sk_zero(_STACK *st) st->num = 0; } -void sk_pop_free(_STACK *st, void (*func) (void *)) +void OPENSSL_sk_pop_free(OPENSSL_STACK *st, OPENSSL_sk_freefunc func) { int i; @@ -255,10 +255,10 @@ void sk_pop_free(_STACK *st, void (*func) (void *)) for (i = 0; i < st->num; i++) if (st->data[i] != NULL) func(st->data[i]); - sk_free(st); + OPENSSL_sk_free(st); } -void sk_free(_STACK *st) +void OPENSSL_sk_free(OPENSSL_STACK *st) { if (st == NULL) return; @@ -266,48 +266,38 @@ void sk_free(_STACK *st) OPENSSL_free(st); } -int sk_num(const _STACK *st) +int OPENSSL_sk_num(const OPENSSL_STACK *st) { if (st == NULL) return -1; return st->num; } -void *sk_value(const _STACK *st, int i) +void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i) { - if (!st || (i < 0) || (i >= st->num)) + if (st == NULL || i < 0 || i >= st->num) return NULL; return st->data[i]; } -void *sk_set(_STACK *st, int i, void *value) +void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, void *value) { - if (!st || (i < 0) || (i >= st->num)) + if (st == NULL || i < 0 || i >= st->num) return NULL; return (st->data[i] = value); } -void sk_sort(_STACK *st) +void OPENSSL_sk_sort(OPENSSL_STACK *st) { if (st && !st->sorted && st->comp != NULL) { - int (*comp_func) (const void *, const void *); - - /* - * same comment as in sk_find ... previously st->comp was declared as - * a (void*,void*) callback type, but this made the population of the - * callback pointer illogical - our callbacks compare type** with - * type**, so we leave the casting until absolutely necessary (ie. - * "now"). - */ - comp_func = (int (*)(const void *, const void *))(st->comp); - qsort(st->data, st->num, sizeof(char *), comp_func); + qsort(st->data, st->num, sizeof(char *), st->comp); st->sorted = 1; } } -int sk_is_sorted(const _STACK *st) +int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st) { - if (!st) + if (st == NULL) return 1; return st->sorted; } diff --git a/crypto/txt_db/txt_db.c b/crypto/txt_db/txt_db.c index 6bc026231c..14322309a7 100644 --- a/crypto/txt_db/txt_db.c +++ b/crypto/txt_db/txt_db.c @@ -145,7 +145,7 @@ OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, } int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), - LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp) + OPENSSL_LH_HASHFUNC hash, OPENSSL_LH_COMPFUNC cmp) { LHASH_OF(OPENSSL_STRING) *idx; OPENSSL_STRING *r; @@ -156,7 +156,7 @@ int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), return (0); } /* FIXME: we lose type checking at this point */ - if ((idx = (LHASH_OF(OPENSSL_STRING) *)lh_new(hash, cmp)) == NULL) { + if ((idx = (LHASH_OF(OPENSSL_STRING) *)OPENSSL_LH_new(hash, cmp)) == NULL) { db->error = DB_ERROR_MALLOC; return (0); } diff --git a/doc/crypto/lh_stats.pod b/doc/crypto/lh_stats.pod index 12b4a16f2f..bdc19b4e84 100644 --- a/doc/crypto/lh_stats.pod +++ b/doc/crypto/lh_stats.pod @@ -2,20 +2,21 @@ =head1 NAME -lh_stats, lh_node_stats, lh_node_usage_stats, lh_stats_bio, -lh_node_stats_bio, lh_node_usage_stats_bio - LHASH statistics +OPENSSL_LH_stats, OPENSSL_LH_node_stats, OPENSSL_LH_node_usage_stats, +OPENSSL_LH_stats_bio, +OPENSSL_LH_node_stats_bio, OPENSSL_LH_node_usage_stats_bio - LHASH statistics =head1 SYNOPSIS #include <openssl/lhash.h> - void lh_stats(LHASH *table, FILE *out); - void lh_node_stats(LHASH *table, FILE *out); - void lh_node_usage_stats(LHASH *table, FILE *out); + void OPENSSL_LH_stats(LHASH *table, FILE *out); + void OPENSSL_LH_node_stats(LHASH *table, FILE *out); + void OPENSSL_LH_node_usage_stats(LHASH *table, FILE *out); - void lh_stats_bio(LHASH *table, BIO *out); - void lh_node_stats_bio(LHASH *table, BIO *out); - void lh_node_usage_stats_bio(LHASH *table, BIO *out); + void OPENSSL_LH_stats_bio(LHASH *table, BIO *out); + void OPENSSL_LH_node_stats_bio(LHASH *table, BIO *out); + void OPENSSL_LH_node_usage_stats_bio(LHASH *table, BIO *out); =head1 DESCRIPTION @@ -24,14 +25,14 @@ accessing the hash table. This is mostly a legacy of Eric Young writing this library for the reasons of implementing what looked like a nice algorithm rather than for a particular software product. -lh_stats() prints out statistics on the size of the hash table, how +OPENSSL_LH_stats() prints out statistics on the size of the hash table, how many entries are in it, and the number and result of calls to the routines in this library. -lh_node_stats() prints the number of entries for each 'bucket' in the +OPENSSL_LH_node_stats() prints the number of entries for each 'bucket' in the hash table. -lh_node_usage_stats() prints out a short summary of the state of the +OPENSSL_LH |