diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/conf/conf.h | 30 | ||||
-rw-r--r-- | crypto/conf/conf_api.c | 114 | ||||
-rw-r--r-- | crypto/conf/conf_def.c | 11 | ||||
-rw-r--r-- | crypto/conf/conf_lib.c | 30 | ||||
-rw-r--r-- | crypto/engine/eng_table.c | 51 | ||||
-rw-r--r-- | crypto/err/err.c | 136 | ||||
-rw-r--r-- | crypto/err/err.h | 6 | ||||
-rw-r--r-- | crypto/ex_data.c | 26 | ||||
-rw-r--r-- | crypto/lhash/lh_stats.c | 12 | ||||
-rw-r--r-- | crypto/lhash/lhash.c | 38 | ||||
-rw-r--r-- | crypto/lhash/lhash.h | 148 | ||||
-rw-r--r-- | crypto/mem_dbg.c | 85 | ||||
-rw-r--r-- | crypto/objects/o_names.c | 47 | ||||
-rw-r--r-- | crypto/objects/obj_dat.c | 52 | ||||
-rw-r--r-- | crypto/stack/safestack.h | 234 | ||||
-rw-r--r-- | crypto/txt_db/txt_db.c | 41 | ||||
-rw-r--r-- | crypto/txt_db/txt_db.h | 14 | ||||
-rw-r--r-- | crypto/x509v3/v3_conf.c | 41 | ||||
-rw-r--r-- | crypto/x509v3/x509v3.h | 19 |
19 files changed, 730 insertions, 405 deletions
diff --git a/crypto/conf/conf.h b/crypto/conf/conf.h index a8ac256e52..06e0b55102 100644 --- a/crypto/conf/conf.h +++ b/crypto/conf/conf.h @@ -78,7 +78,8 @@ typedef struct char *value; } CONF_VALUE; -DECLARE_STACK_OF(CONF_VALUE) +DECLARE_STACK_OF(CONF_VALUE); +DECLARE_LHASH_OF(CONF_VALUE); struct conf_st; struct conf_method_st; @@ -118,18 +119,23 @@ typedef void conf_finish_func(CONF_IMODULE *md); #define CONF_MFLAGS_DEFAULT_SECTION 0x20 int CONF_set_default_method(CONF_METHOD *meth); -void CONF_set_nconf(CONF *conf,LHASH *hash); -LHASH *CONF_load(LHASH *conf,const char *file,long *eline); +void CONF_set_nconf(CONF *conf,LHASH_OF(CONF_VALUE) *hash); +LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf,const char *file, + long *eline); #ifndef OPENSSL_NO_FP_API -LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline); +LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, + long *eline); #endif -LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline); -STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section); -char *CONF_get_string(LHASH *conf,const char *group,const char *name); -long CONF_get_number(LHASH *conf,const char *group,const char *name); -void CONF_free(LHASH *conf); -int CONF_dump_fp(LHASH *conf, FILE *out); -int CONF_dump_bio(LHASH *conf, BIO *out); +LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,long *eline); +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf, + const char *section); +char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf,const char *group, + const char *name); +long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group, + const char *name); +void CONF_free(LHASH_OF(CONF_VALUE) *conf); +int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out); +int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out); void OPENSSL_config(const char *config_name); void OPENSSL_no_config(void); @@ -141,7 +147,7 @@ struct conf_st { CONF_METHOD *meth; void *meth_data; - LHASH *data; + LHASH_OF(CONF_VALUE) *data; }; CONF *NCONF_new(CONF_METHOD *meth); diff --git a/crypto/conf/conf_api.c b/crypto/conf/conf_api.c index 599ab25378..2438f8771e 100644 --- a/crypto/conf/conf_api.c +++ b/crypto/conf/conf_api.c @@ -69,16 +69,14 @@ #include <openssl/conf_api.h> #include "e_os.h" -static void value_free_hash(CONF_VALUE *a, LHASH *conf); -static void value_free_stack(CONF_VALUE *a,LHASH *conf); -static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE *, LHASH *) -static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE *, LHASH *) -/* We don't use function pointer casting or wrapper functions - but cast each - * callback parameter inside the callback functions. */ -/* static unsigned long hash(CONF_VALUE *v); */ -static unsigned long hash(const void *v_void); -/* static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); */ -static int cmp_conf(const void *a_void,const void *b_void); +static void value_free_hash_doall_arg(CONF_VALUE *a, + LHASH_OF(CONF_VALUE) *conf); +static void value_free_stack_doall_arg(CONF_VALUE *a, + LHASH_OF(CONF_VALUE) *conf); +static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_hash, CONF_VALUE, + LHASH_OF(CONF_VALUE)) +static IMPLEMENT_LHASH_DOALL_ARG_FN(value_free_stack, CONF_VALUE, + LHASH_OF(CONF_VALUE)) /* Up until OpenSSL 0.9.5a, this was get_section */ CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) @@ -88,7 +86,7 @@ CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section) if ((conf == NULL) || (section == NULL)) return(NULL); vv.name=NULL; vv.section=(char *)section; - v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); + v=lh_CONF_VALUE_retrieve(conf->data,&vv); return(v); } @@ -118,7 +116,7 @@ int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value) return 0; } - v = (CONF_VALUE *)lh_insert(conf->data, value); + v = lh_CONF_VALUE_insert(conf->data, value); if (v != NULL) { (void)sk_CONF_VALUE_delete_ptr(ts,v); @@ -141,7 +139,7 @@ char *_CONF_get_string(const CONF *conf, const char *section, const char *name) { vv.name=(char *)name; vv.section=(char *)section; - v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); + v=lh_CONF_VALUE_retrieve(conf->data,&vv); if (v != NULL) return(v->value); if (strcmp(section,"ENV") == 0) { @@ -151,7 +149,7 @@ char *_CONF_get_string(const CONF *conf, const char *section, const char *name) } vv.section="default"; vv.name=(char *)name; - v=(CONF_VALUE *)lh_retrieve(conf->data,&vv); + v=lh_CONF_VALUE_retrieve(conf->data,&vv); if (v != NULL) return(v->value); else @@ -182,6 +180,34 @@ long _CONF_get_number(CONF *conf, char *section, char *name) } #endif +static unsigned long conf_value_hash(const CONF_VALUE *v) + { + return (lh_strhash(v->section)<<2)^lh_strhash(v->name); + } +static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE) + +static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) + { + int i; + + if (a->section != b->section) + { + i=strcmp(a->section,b->section); + if (i) return(i); + } + + if ((a->name != NULL) && (b->name != NULL)) + { + i=strcmp(a->name,b->name); + return(i); + } + else if (a->name == b->name) + return(0); + else + return((a->name == NULL)?-1:1); + } +static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE) + int _CONF_new_data(CONF *conf) { if (conf == NULL) @@ -189,7 +215,7 @@ int _CONF_new_data(CONF *conf) return 0; } if (conf->data == NULL) - if ((conf->data = lh_new(hash, cmp_conf)) == NULL) + if ((conf->data = lh_CONF_VALUE_new()) == NULL) { return 0; } @@ -200,28 +226,29 @@ void _CONF_free_data(CONF *conf) { if (conf == NULL || conf->data == NULL) return; - conf->data->down_load=0; /* evil thing to make sure the 'OPENSSL_free()' - * works as expected */ - lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash), - conf->data); + lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make + * sure the 'OPENSSL_free()' works as + * expected */ + lh_CONF_VALUE_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_hash), + LHASH_OF(CONF_VALUE), conf->data); /* We now have only 'section' entries in the hash table. * Due to problems with */ - lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(value_free_stack), - conf->data); - lh_free(conf->data); + lh_CONF_VALUE_doall_arg(conf->data, + LHASH_DOALL_ARG_FN(value_free_stack), + LHASH_OF(CONF_VALUE), conf->data); + lh_CONF_VALUE_free(conf->data); } -static void value_free_hash(CONF_VALUE *a, LHASH *conf) +static void value_free_hash_doall_arg(CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf) { if (a->name != NULL) - { - a=(CONF_VALUE *)lh_delete(conf,a); - } + lh_CONF_VALUE_delete(conf,a); } -static void value_free_stack(CONF_VALUE *a, LHASH *conf) +static void value_free_stack_doall_arg(CONF_VALUE *a, + LHASH_OF(CONF_VALUE) *conf) { CONF_VALUE *vv; STACK *sk; @@ -242,37 +269,6 @@ static void value_free_stack(CONF_VALUE *a, LHASH *conf) OPENSSL_free(a); } -/* static unsigned long hash(CONF_VALUE *v) */ -static unsigned long hash(const void *v_void) - { - CONF_VALUE *v = (CONF_VALUE *)v_void; - return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); - } - -/* static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) */ -static int cmp_conf(const void *a_void,const void *b_void) - { - int i; - CONF_VALUE *a = (CONF_VALUE *)a_void; - CONF_VALUE *b = (CONF_VALUE *)b_void; - - if (a->section != b->section) - { - i=strcmp(a->section,b->section); - if (i) return(i); - } - - if ((a->name != NULL) && (b->name != NULL)) - { - i=strcmp(a->name,b->name); - return(i); - } - else if (a->name == b->name) - return(0); - else - return((a->name == NULL)?-1:1); - } - /* Up until OpenSSL 0.9.5a, this was new_section */ CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) { @@ -292,7 +288,7 @@ CONF_VALUE *_CONF_new_section(CONF *conf, const char *section) v->name=NULL; v->value=(char *)sk; - vv=(CONF_VALUE *)lh_insert(conf->data,v); + vv=lh_CONF_VALUE_insert(conf->data,v); assert(vv == NULL); ok=1; err: diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index d8bce8732a..0b571b0394 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -129,7 +129,7 @@ static CONF *def_create(CONF_METHOD *meth) { CONF *ret; - ret = (CONF *)OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *)); + ret = OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *)); if (ret) if (meth->init(ret) == 0) { @@ -145,7 +145,7 @@ static int def_init_default(CONF *conf) return 0; conf->meth = &default_method; - conf->meth_data = (void *)CONF_type_default; + conf->meth_data = CONF_type_default; conf->data = NULL; return 1; @@ -722,7 +722,7 @@ static char *scan_dquote(CONF *conf, char *p) return(p); } -static void dump_value(CONF_VALUE *a, BIO *out) +static void dump_value_doall_arg(CONF_VALUE *a, BIO *out) { if (a->name) BIO_printf(out, "[%s] %s=%s\n", a->section, a->name, a->value); @@ -730,11 +730,12 @@ static void dump_value(CONF_VALUE *a, BIO *out) BIO_printf(out, "[[%s]]\n", a->section); } -static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE *, BIO *) +static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_value, CONF_VALUE, BIO) static int def_dump(const CONF *conf, BIO *out) { - lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), out); + lh_CONF_VALUE_doall_arg(conf->data, LHASH_DOALL_ARG_FN(dump_value), + BIO, out); return 1; } diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c index 2a3399d269..54046defca 100644 --- a/crypto/conf/conf_lib.c +++ b/crypto/conf/conf_lib.c @@ -69,7 +69,7 @@ static CONF_METHOD *default_CONF_method=NULL; /* Init a 'CONF' structure from an old LHASH */ -void CONF_set_nconf(CONF *conf, LHASH *hash) +void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash) { if (default_CONF_method == NULL) default_CONF_method = NCONF_default(); @@ -87,9 +87,10 @@ int CONF_set_default_method(CONF_METHOD *meth) return 1; } -LHASH *CONF_load(LHASH *conf, const char *file, long *eline) +LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, + long *eline) { - LHASH *ltmp; + LHASH_OF(CONF_VALUE) *ltmp; BIO *in=NULL; #ifdef OPENSSL_SYS_VMS @@ -110,10 +111,11 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline) } #ifndef OPENSSL_NO_FP_API -LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline) +LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, + long *eline) { BIO *btmp; - LHASH *ltmp; + LHASH_OF(CONF_VALUE) *ltmp; if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); return NULL; @@ -124,7 +126,8 @@ LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline) } #endif -LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline) +LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp, + long *eline) { CONF ctmp; int ret; @@ -137,7 +140,8 @@ LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline) return NULL; } -STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section) +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf, + const char *section) { if (conf == NULL) { @@ -151,7 +155,8 @@ STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section) } } -char *CONF_get_string(LHASH *conf,const char *group,const char *name) +char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf,const char *group, + const char *name) { if (conf == NULL) { @@ -165,7 +170,8 @@ char *CONF_get_string(LHASH *conf,const char *group,const char *name) } } -long CONF_get_number(LHASH *conf,const char *group,const char *name) +long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group, + const char *name) { int status; long result = 0; @@ -189,7 +195,7 @@ long CONF_get_number(LHASH *conf,const char *group,const char *name) return result; } -void CONF_free(LHASH *conf) +void CONF_free(LHASH_OF(CONF_VALUE) *conf) { CONF ctmp; CONF_set_nconf(&ctmp, conf); @@ -197,7 +203,7 @@ void CONF_free(LHASH *conf) } #ifndef OPENSSL_NO_FP_API -int CONF_dump_fp(LHASH *conf, FILE *out) +int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out) { BIO *btmp; int ret; @@ -212,7 +218,7 @@ int CONF_dump_fp(LHASH *conf, FILE *out) } #endif -int CONF_dump_bio(LHASH *conf, BIO *out) +int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out) { CONF ctmp; CONF_set_nconf(&ctmp, conf); diff --git a/crypto/engine/eng_table.c b/crypto/engine/eng_table.c index 1f0fff6180..4f28abca34 100644 --- a/crypto/engine/eng_table.c +++ b/crypto/engine/eng_table.c @@ -70,10 +70,12 @@ typedef struct st_engine_pile int uptodate; } ENGINE_PILE; +DECLARE_LHASH_OF(ENGINE_PILE); + /* The type exposed in eng_int.h */ struct st_engine_table { - LHASH piles; + LHASH_OF(ENGINE_PILE) piles; }; /* ENGINE_TABLE */ @@ -92,6 +94,7 @@ unsigned int ENGINE_get_table_flags(void) { return table_flags; } + void ENGINE_set_table_flags(unsigned int flags) { table_flags = flags; @@ -102,19 +105,21 @@ static unsigned long engine_pile_hash(const ENGINE_PILE *c) { return c->nid; } + static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b) { return a->nid - b->nid; } -static IMPLEMENT_LHASH_HASH_FN(engine_pile_hash, const ENGINE_PILE *) -static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *) +static IMPLEMENT_LHASH_HASH_FN(engine_pile, const ENGINE_PILE) +static IMPLEMENT_LHASH_COMP_FN(engine_pile, const ENGINE_PILE) + static int int_table_check(ENGINE_TABLE **t, int create) { - LHASH *lh; + LHASH_OF(ENGINE_PILE) *lh; + if(*t) return 1; if(!create) return 0; - if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash), - LHASH_COMP_FN(engine_pile_cmp))) == NULL) + if((lh = lh_ENGINE_PILE_new()) == NULL) return 0; *t = (ENGINE_TABLE *)lh; return 1; @@ -138,7 +143,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, while(num_nids--) { tmplate.nid = *nids; - fnd = lh_retrieve(&(*table)->piles, &tmplate); + fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); if(!fnd) { fnd = OPENSSL_malloc(sizeof(ENGINE_PILE)); @@ -152,7 +157,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, goto end; } fnd->funct = NULL; - lh_insert(&(*table)->piles, fnd); + lh_ENGINE_PILE_insert(&(*table)->piles, fnd); } /* A registration shouldn't add duplciate entries */ (void)sk_ENGINE_delete_ptr(fnd->sk, e); @@ -181,7 +186,7 @@ end: CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); return ret; } -static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e) +static void int_unregister_cb_doall_arg(ENGINE_PILE *pile, ENGINE *e) { int n; /* Iterate the 'c->sk' stack removing any occurance of 'e' */ @@ -196,31 +201,35 @@ static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e) pile->funct = NULL; } } -static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *) +static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb, ENGINE_PILE, ENGINE) + void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e) { CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); if(int_table_check(table, 0)) - lh_doall_arg(&(*table)->piles, - LHASH_DOALL_ARG_FN(int_unregister_cb), e); + lh_ENGINE_PILE_doall_arg(&(*table)->piles, + LHASH_DOALL_ARG_FN(int_unregister_cb), + ENGINE, e); CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); } -static void int_cleanup_cb(ENGINE_PILE *p) +static void int_cleanup_cb_doall(ENGINE_PILE *p) { sk_ENGINE_free(p->sk); if(p->funct) engine_unlocked_finish(p->funct, 0); OPENSSL_free(p); } -static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb,ENGINE_PILE *) +static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb, ENGINE_PILE) + void engine_table_cleanup(ENGINE_TABLE **table) { CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); if(*table) { - lh_doall(&(*table)->piles, LHASH_DOALL_FN(int_cleanup_cb)); - lh_free(&(*table)->piles); + lh_ENGINE_PILE_doall(&(*table)->piles, + LHASH_DOALL_FN(int_cleanup_cb)); + lh_ENGINE_PILE_free(&(*table)->piles); *table = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); @@ -250,7 +259,7 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, in * operations. But don't worry about a fprintf(stderr). */ if(!int_table_check(table, 0)) goto end; tmplate.nid = nid; - fnd = lh_retrieve(&(*table)->piles, &tmplate); + fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); if(!fnd) goto end; if(fnd->funct && engine_unlocked_init(fnd->funct)) { @@ -324,18 +333,18 @@ end: /* Table enumeration */ -static void int_doall_cb(ENGINE_PILE *pile, ENGINE_PILE_DOALL *dall) +static void int_cb_doall_arg(ENGINE_PILE *pile, ENGINE_PILE_DOALL *dall) { dall->cb(pile->nid, pile->sk, pile->funct, dall->arg); } +static IMPLEMENT_LHASH_DOALL_ARG_FN(int_cb, ENGINE_PILE,ENGINE_PILE_DOALL) -static IMPLEMENT_LHASH_DOALL_ARG_FN(int_doall_cb,ENGINE_PILE *,ENGINE_PILE_DOALL *) void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb, void *arg) { ENGINE_PILE_DOALL dall; dall.cb = cb; dall.arg = arg; - lh_doall_arg(&table->piles, - LHASH_DOALL_ARG_FN(int_doall_cb), &dall); + lh_ENGINE_PILE_doall_arg(&table->piles, LHASH_DOALL_ARG_FN(int_cb), + ENGINE_PILE_DOALL, &dall); } diff --git a/crypto/err/err.c b/crypto/err/err.c index 8adcd9f96d..66d4da8556 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -119,6 +119,9 @@ #include <openssl/bio.h> #include <openssl/err.h> +DECLARE_LHASH_OF(ERR_STRING_DATA); +DECLARE_LHASH_OF(ERR_STATE); + static void err_load_strings(int lib, ERR_STRING_DATA *str); static void ERR_STATE_free(ERR_STATE *s); @@ -223,14 +226,14 @@ static ERR_STRING_DATA ERR_str_reasons[]= struct st_ERR_FNS { /* Works on the "error_hash" string table */ - LHASH *(*cb_err_get)(int create); + LHASH_OF(ERR_STRING_DATA) *(*cb_err_get)(int create); void (*cb_err_del)(void); ERR_STRING_DATA *(*cb_err_get_item)(const ERR_STRING_DATA *); ERR_STRING_DATA *(*cb_err_set_item)(ERR_STRING_DATA *); ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *); /* Works on the "thread_hash" error-state table */ - LHASH *(*cb_thread_get)(int create); - void (*cb_thread_release)(LHASH **hash); + LHASH_OF(ERR_STATE) *(*cb_thread_get)(int create); + void (*cb_thread_release)(LHASH_OF(ERR_STATE) **hash); ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *); ERR_STATE *(*cb_thread_set_item)(ERR_STATE *); void (*cb_thread_del_item)(const ERR_STATE *); @@ -239,13 +242,13 @@ struct st_ERR_FNS }; /* Predeclarations of the "err_defaults" functions */ -static LHASH *int_err_get(int create); +static LHASH_OF(ERR_STRING_DATA) *int_err_get(int create); static void int_err_del(void); static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *); static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *); static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *); -static LHASH *int_thread_get(int create); -static void int_thread_release(LHASH **hash); +static LHASH_OF(ERR_STATE) *int_thread_get(int create); +static void int_thread_release(LHASH_OF(ERR_STATE) **hash); static ERR_STATE *int_thread_get_item(const ERR_STATE *); static ERR_STATE *int_thread_set_item(ERR_STATE *); static void int_thread_del_item(const ERR_STATE *); @@ -277,8 +280,8 @@ static const ERR_FNS *err_fns = NULL; * "err_defaults" functions. This way, a linked module can completely defer all * ERR state operation (together with requisite locking) to the implementations * and state in the loading application. */ -static LHASH *int_error_hash = NULL; -static LHASH *int_thread_hash = NULL; +static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL; +static LHASH_OF(ERR_STATE) *int_thread_hash = NULL; static int int_thread_hash_references = 0; static int int_err_library_number= ERR_LIB_USER; @@ -321,28 +324,37 @@ int ERR_set_implementation(const ERR_FNS *fns) /* These are the callbacks provided to "lh_new()" when creating the LHASH tables * internal to the "err_defaults" implementation. */ -/* static unsigned long err_hash(ERR_STRING_DATA *a); */ -static unsigned long err_hash(const void *a_void); -/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); */ -static int err_cmp(const void *a_void, const void *b_void); -/* static unsigned long pid_hash(ERR_STATE *pid); */ -static unsigned long pid_hash(const void *pid_void); -/* static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); */ -static int pid_cmp(const void *a_void,const void *pid_void); static unsigned long get_error_values(int inc,int top,const char **file,int *line, const char **data,int *flags); /* The internal functions used in the "err_defaults" implementation */ -static LHASH *int_err_get(int create) +static unsigned long err_string_data_hash(const ERR_STRING_DATA *a) { - LHASH *ret = NULL; + unsigned long ret,l; + + l=a->error; + ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); + return(ret^ret%19*13); + } +static IMPLEMENT_LHASH_HASH_FN(err_string_data, ERR_STRING_DATA); + +static int err_string_data_cmp(const ERR_STRING_DATA *a, + const ERR_STRING_DATA *b) + { + return (int)(a->error - b->error); + } +static IMPLEMENT_LHASH_COMP_FN(err_string_data, ERR_STRING_DATA); + +static LHASH_OF(ERR_STRING_DATA) *int_err_get(int create) + { + LHASH_OF(ERR_STRING_DATA) *ret = NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (!int_error_hash && create) { CRYPTO_push_info("int_err_get (err.c)"); - int_error_hash = lh_new(err_hash, err_cmp); + int_error_hash = lh_ERR_STRING_DATA_new(); CRYPTO_pop_info(); } if (int_error_hash) @@ -357,7 +369,7 @@ static void int_err_del(void) CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (int_error_hash) { - lh_free(int_error_hash); + lh_ERR_STRING_DATA_free(int_error_hash); int_error_hash = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); @@ -366,7 +378,7 @@ static void int_err_del(void) static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d) { ERR_STRING_DATA *p; - LHASH *hash; + LHASH_OF(ERR_STRING_DATA) *hash; err_fns_check(); hash = ERRFN(err_get)(0); @@ -374,7 +386,7 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d) return NULL; CRYPTO_r_lock(CRYPTO_LOCK_ERR); - p = (ERR_STRING_DATA *)lh_retrieve(hash, d); + p = lh_ERR_STRING_DATA_retrieve(hash, d); CRYPTO_r_unlock(CRYPTO_LOCK_ERR); return p; @@ -383,7 +395,7 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d) static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d) { ERR_STRING_DATA *p; - LHASH *hash; + LHASH_OF(ERR_STRING_DATA) *hash; err_fns_check(); hash = ERRFN(err_get)(1); @@ -391,7 +403,7 @@ static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d) return NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); - p = (ERR_STRING_DATA *)lh_insert(hash, d); + p = lh_ERR_STRING_DATA_insert(hash, d); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); return p; @@ -400,7 +412,7 @@ static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *d) static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d) { ERR_STRING_DATA *p; - LHASH *hash; + LHASH_OF(ERR_STRING_DATA) *hash; err_fns_check(); hash = ERRFN(err_get)(0); @@ -408,21 +420,33 @@ static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d) return NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); - p = (ERR_STRING_DATA *)lh_delete(hash, d); + p = lh_ERR_STRING_DATA_delete(hash, d); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); return p; } -static LHASH *int_thread_get(int create) +static unsigned long err_state_hash(const ERR_STATE *a) + { + return CRYPTO_THREADID_hash(&a->tid); + } +static IMPLEMENT_LHASH_HASH_FN(err_state, ERR_STATE); + +static int err_state_cmp(const ERR_STATE *a, const ERR_STATE *b) + { + return CRYPTO_THREADID_cmp(&a->tid, &b->tid); + } +static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE); + +static LHASH_OF(ERR_STATE) *int_thread_get(int create) { - LHASH *ret = NULL; + LHASH_OF(ERR_STATE) *ret = NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (!int_thread_hash && create) { CRYPTO_push_info("int_thread_get (err.c)"); - int_thread_hash = lh_new(pid_hash, pid_cmp); + int_thread_hash = lh_ERR_STATE_new(); CRYPTO_pop_info(); } if (int_thread_hash) @@ -434,7 +458,7 @@ static LHASH *int_thread_get(int create) return ret; } -static void int_thread_release(LHASH **hash) +static void int_thread_release(LHASH_OF(ERR_STATE) **hash) { int i; @@ -460,7 +484,7 @@ static void int_thread_release(LHASH **hash) static ERR_STATE *int_thread_get_item(const ERR_STATE *d) { ERR_STATE *p; - LHASH *hash; + LHASH_OF(ERR_STATE) *hash; err_fns_check(); hash = ERRFN(thread_get)(0); @@ -468,7 +492,7 @@ static ERR_STATE *int_thread_get_item(const ERR_STATE *d) return NULL; CRYPTO_r_lock(CRYPTO_LOCK_ERR); - p = (ERR_STATE *)lh_retrieve(hash, d); + p = lh_ERR_STATE_retrieve(hash, d); CRYPTO_r_unlock(CRYPTO_LOCK_ERR); ERRFN(thread_release)(&hash); @@ -478,7 +502,7 @@ static ERR_STATE *int_thread_get_item(const ERR_STATE *d) static ERR_STATE *int_thread_set_item(ERR_STATE *d) { ERR_STATE *p; - LHASH *hash; + LHASH_OF(ERR_STATE) *hash; err_fns_check(); hash = ERRFN(thread_get)(1); @@ -486,7 +510,7 @@ static ERR_STATE *int_thread_set_item(ERR_STATE *d) return NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); - p = (ERR_STATE *)lh_insert(hash, d); + p = lh_ERR_STATE_insert(hash, d); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); ERRFN(thread_release)(&hash); @@ -496,7 +520,7 @@ static ERR_STATE *int_thread_set_item(ERR_STATE *d) static void int_thread_del_item(const ERR_STATE *d) { ERR_STATE *p; - LHASH *hash; + LHASH_OF(ERR_STATE) *hash; err_fns_check(); hash = ERRFN(thread_get)(0); @@ -504,12 +528,12 @@ static void int_thread_del_item(const ERR_STATE *d) return; CRYPTO_w_lock(CRYPTO_LOCK_ERR); - p = (ERR_STATE *)lh_delete(hash, d); + p = lh_ERR_STATE_delete(hash, d); /* make sure we don't leak memory */ if (int_thread_hash_references == 1 - && int_thread_hash && (lh_num_items(int_thread_hash) == 0)) + && int_thread_hash && lh_ERR_STATE_num_items(int_thread_hash) == 0) { - lh_free(int_thread_hash); + lh_ERR_STATE_free(int_thread_hash); int_thread_hash = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); @@ -894,19 +918,19 @@ char *ERR_error_string(unsigned long e, char *ret) return ret; } -LHASH *ERR_get_string_table(void) +LHASH_OF(ERR_STRING_DATA) *ERR_get_string_table(void) { err_fns_check(); return ERRFN(err_get)(0); } -LHASH *ERR_get_err_state_table(void) +LHASH_OF(ERR_STATE) *ERR_get_err_state_table(void) { err_fns_check(); return ERRFN(thread_get)(0); } -void ERR_release_err_state_table(LHASH **hash) +void ERR_release_err_state_table(LHASH_OF(ERR_STATE) **hash) { err_fns_check(); ERRFN(thread_release)(hash); @@ -955,36 +979,6 @@ const char *ERR_reason_error_string(unsigned long e) return((p == NULL)?NULL:p->string); } -/* static unsigned long err_hash(ERR_STRING_DATA *a) */ -static unsigned long err_hash(const void *a_void) - { - unsigned long ret,l; - - l=((const ERR_STRING_DATA *)a_void)->error; - ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); - return(ret^ret%19*13); - } - -/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */ -static int err_cmp(const void *a_void, const void *b_void) - { - return((int)(((const ERR_STRING_DATA *)a_void)->error - - ((const ERR_STRING_DATA *)b_void)->error)); - } - -/* static unsigned long pid_hash(ERR_STATE *a) */ -static unsigned long pid_hash(const void *a_void) - { - return CRYPTO_THREADID_hash(&((const ERR_STATE *)a_void)->tid); - } - -/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */ -static int pid_cmp(const void *a_void, const void *b_void) - { - return CRYPTO_THREADID_cmp(&((const ERR_STATE *)a_void)->tid, - &((const ERR_STATE *)b_void)->tid); - } - void ERR_remove_thread_state(CRYPTO_THREADID *tid) { ERR_STATE tmp; diff --git a/crypto/err/err.h b/crypto/err/err.h index c56f5aadb2..c34ce72ada 100644 --- a/crypto/err/err.h +++ b/crypto/err/err.h @@ -358,9 +358,9 @@ void ERR_remove_state(unsigned long pid); /* if zero we look it up */ ERR_STATE *ERR_get_state(void); #ifndef OPENSSL_NO_LHASH -LHASH *ERR_get_string_table(void); -LHASH *ERR_get_err_state_table(void); -void ERR_release_err_state_table(LHASH **hash); +LHASH_OF(ERR_STRING_DATA) *ERR_get_string_table(void); +LHASH_OF(ERR_STATE) *ERR_get_err_state_table(void); +void ERR_release_err_state_table(LHASH_OF(ERR_STATE) **hash); #endif int ERR_get_next_error_library(void); |