summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Laurie <ben@openssl.org>2008-10-12 14:32:47 +0000
committerBen Laurie <ben@openssl.org>2008-10-12 14:32:47 +0000
commitbabb379849ffb4112792f266f92e9ebb2bd35332 (patch)
treed401aa7a4af8cc1180fe602711897a50d8feb74f
parent6665ef303e837ed45654d1b5dd42123e7a51b0f4 (diff)
Type-checked (and modern C compliant) OBJ_bsearch.
-rw-r--r--CHANGES5
-rwxr-xr-xConfigure1
-rw-r--r--apps/s_client.c2
-rw-r--r--apps/s_server.c2
-rw-r--r--crypto/asn1/a_strnid.c18
-rw-r--r--crypto/asn1/ameth_lib.c21
-rw-r--r--crypto/evp/evp_pbe.c17
-rw-r--r--crypto/evp/pmeth_lib.c20
-rw-r--r--crypto/objects/obj_dat.c76
-rw-r--r--crypto/objects/obj_xref.c58
-rw-r--r--crypto/objects/obj_xref.h69
-rw-r--r--crypto/objects/objects.h66
-rw-r--r--crypto/objects/objxref.pl8
-rw-r--r--crypto/x509/x509_vpm.c19
-rw-r--r--crypto/x509v3/ext_dat.h2
-rw-r--r--crypto/x509v3/v3_alt.c16
-rw-r--r--crypto/x509v3/v3_conf.c10
-rw-r--r--crypto/x509v3/v3_crld.c31
-rw-r--r--crypto/x509v3/v3_extku.c16
-rw-r--r--crypto/x509v3/v3_lib.c26
-rw-r--r--crypto/x509v3/v3_ncons.c26
-rw-r--r--crypto/x509v3/v3_ocsp.c42
-rw-r--r--crypto/x509v3/v3_pcons.c20
-rw-r--r--crypto/x509v3/v3_pmaps.c18
-rw-r--r--crypto/x509v3/v3_prn.c2
-rw-r--r--crypto/x509v3/v3_purp.c16
-rw-r--r--crypto/x509v3/x509v3.h40
-rw-r--r--engines/Makefile3
-rw-r--r--ssl/d1_lib.c4
-rw-r--r--ssl/s23_lib.c7
-rw-r--r--ssl/s2_lib.c18
-rw-r--r--ssl/s2_meth.c6
-rw-r--r--ssl/s2_srvr.c2
-rw-r--r--ssl/s3_clnt.c2
-rw-r--r--ssl/s3_lib.c13
-rw-r--r--ssl/s3_meth.c6
-rw-r--r--ssl/ssl.h8
-rw-r--r--ssl/ssl3.h2
-rw-r--r--ssl/ssl_ciph.c19
-rw-r--r--ssl/ssl_lib.c10
-rw-r--r--ssl/ssl_locl.h24
-rw-r--r--ssl/ssltest.c4
42 files changed, 424 insertions, 351 deletions
diff --git a/CHANGES b/CHANGES
index ecead77be9..0a087c149d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,11 @@
Changes between 0.9.8j and 0.9.9 [xx XXX xxxx]
+ *) Type-checked OBJ_bsearch. Also some constification necessitated
+ by type-checking. Still to come: TXT_DB, bsearch(?),
+ OBJ_bsearch_ex, qsort, CRYPTO_EX_DATA, ASN1_VALUE, ASN1_STRING,
+ CONF_VALUE. [Ben Laurie]
+
*) New function OPENSSL_gmtime_adj() to add a specific number of days and
seconds to a tm structure directly, instead of going through OS
specific date routines. This avoids any issues with OS routines such
diff --git a/Configure b/Configure
index aa396e00eb..77b13e4c7b 100755
--- a/Configure
+++ b/Configure
@@ -164,6 +164,7 @@ my %table=(
"debug-ben-openbsd","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::",
"debug-ben-openbsd-debug","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::",
"debug-ben-debug", "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::::",
+"debug-ben-no-opt", "gcc: -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -DDEBUG_SAFESTACK -DCRYPTO_MDEBUG -Werror -DL_ENDIAN -DTERMIOS -Wall -g3::(unknown)::::::",
"debug-ben-strict", "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DCONST_STRICT -O2 -Wall -Wshadow -Werror -Wpointer-arith -Wcast-qual -Wwrite-strings -pipe::(unknown)::::::",
"debug-rse","cc:-DTERMIOS -DL_ENDIAN -pipe -O -g -ggdb3 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
"debug-bodo", "gcc:-DL_ENDIAN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBIO_PAIR_DEBUG -DPEDANTIC -g -march=i486 -pedantic -Wshadow -Wall::-D_REENTRANT:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}",
diff --git a/apps/s_client.c b/apps/s_client.c
index 776196ef08..12e5c40b7d 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -1531,7 +1531,7 @@ static void print_stuff(BIO *bio, SSL *s, int full)
char buf[BUFSIZ];
STACK_OF(X509) *sk;
STACK_OF(X509_NAME) *sk2;
- SSL_CIPHER *c;
+ const SSL_CIPHER *c;
X509_NAME *xn;
int j,i;
#ifndef OPENSSL_NO_COMP
diff --git a/apps/s_server.c b/apps/s_server.c
index 27e520a9f3..c95057a7f8 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -2182,7 +2182,7 @@ static int www_body(char *hostname, int s, unsigned char *context)
int ret=1;
int i,j,k,blank,dot;
SSL *con;
- SSL_CIPHER *c;
+ const SSL_CIPHER *c;
BIO *io,*ssl_bio,*sbio;
long total_bytes;
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c
index ecf1d6004e..f0d5416660 100644
--- a/crypto/asn1/a_strnid.c
+++ b/crypto/asn1/a_strnid.c
@@ -67,7 +67,6 @@ static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
static void st_free(ASN1_STRING_TABLE *tbl);
static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
const ASN1_STRING_TABLE * const *b);
-static int table_cmp(const void *a, const void *b);
/* This is the global mask for the mbstring functions: this is use to
@@ -186,22 +185,25 @@ static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
return (*a)->nid - (*b)->nid;
}
-static int table_cmp(const void *a, const void *b)
+DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table_cmp);
+
+static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b)
{
- const ASN1_STRING_TABLE *sa = a, *sb = b;
- return sa->nid - sb->nid;
+ return a->nid - b->nid;
}
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table_cmp);
+
ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
{
int idx;
ASN1_STRING_TABLE *ttmp;
ASN1_STRING_TABLE fnd;
fnd.nid = nid;
- ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd,
- (char *)tbl_standard,
- sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
- sizeof(ASN1_STRING_TABLE), table_cmp);
+ ttmp = OBJ_bsearch(ASN1_STRING_TABLE, &fnd,
+ ASN1_STRING_TABLE, tbl_standard,
+ sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
+ table_cmp);
if(ttmp) return ttmp;
if(!stable) return NULL;
idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c
index 47cbdd28d0..300195bf95 100644
--- a/crypto/asn1/ameth_lib.c
+++ b/crypto/asn1/ameth_lib.c
@@ -112,12 +112,18 @@ void main()
}
#endif
+DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PKEY_ASN1_METHOD *,
+ const EVP_PKEY_ASN1_METHOD *, ameth_cmp);
+
static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
- const EVP_PKEY_ASN1_METHOD * const *b)
+ const EVP_PKEY_ASN1_METHOD * const *b)
{
return ((*a)->pkey_id - (*b)->pkey_id);
}
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PKEY_ASN1_METHOD *,
+ const EVP_PKEY_ASN1_METHOD *, ameth_cmp);
+
int EVP_PKEY_asn1_get_count(void)
{
int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
@@ -139,7 +145,8 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx)
static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
{
- EVP_PKEY_ASN1_METHOD tmp, *t = &tmp, **ret;
+ EVP_PKEY_ASN1_METHOD tmp, *t = &tmp;
+ const EVP_PKEY_ASN1_METHOD **ret;
tmp.pkey_id = type;
if (app_methods)
{
@@ -148,11 +155,11 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
if (idx >= 0)
return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
}
- ret = (EVP_PKEY_ASN1_METHOD **) OBJ_bsearch((char *)&t,
- (char *)standard_methods,
- sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *),
- sizeof(EVP_PKEY_ASN1_METHOD *),
- (int (*)(const void *, const void *))ameth_cmp);
+ ret = OBJ_bsearch(EVP_PKEY_ASN1_METHOD *, &t,
+ const EVP_PKEY_ASN1_METHOD *, standard_methods,
+ sizeof(standard_methods)
+ /sizeof(EVP_PKEY_ASN1_METHOD *),
+ ameth_cmp);
if (!ret || !*ret)
return NULL;
return *ret;
diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c
index 8fecd34221..7d6a50266a 100644
--- a/crypto/evp/evp_pbe.c
+++ b/crypto/evp/evp_pbe.c
@@ -189,10 +189,10 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
return 1;
}
-static int pbe_cmp2(const void *a, const void *b)
+DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe_cmp2);
+
+static int pbe_cmp2(const EVP_PBE_CTL *pbe1, const EVP_PBE_CTL *pbe2)
{
- const EVP_PBE_CTL *pbe1 = a;
- const EVP_PBE_CTL *pbe2 = b;
int ret = pbe1->pbe_type - pbe2->pbe_type;
if (ret)
return ret;
@@ -200,6 +200,8 @@ static int pbe_cmp2(const void *a, const void *b)
return pbe1->pbe_nid - pbe2->pbe_nid;
}
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe_cmp2);
+
static int pbe_cmp(const EVP_PBE_CTL * const *a, const EVP_PBE_CTL * const *b)
{
int ret = (*a)->pbe_type - (*b)->pbe_type;
@@ -269,11 +271,10 @@ int EVP_PBE_find(int type, int pbe_nid,
}
if (pbetmp == NULL)
{
- pbetmp = (EVP_PBE_CTL *) OBJ_bsearch((char *)&pbelu,
- (char *)builtin_pbe,
- sizeof(builtin_pbe)/sizeof(EVP_PBE_CTL),
- sizeof(EVP_PBE_CTL),
- pbe_cmp2);
+ pbetmp = OBJ_bsearch(EVP_PBE_CTL, &pbelu,
+ EVP_PBE_CTL, builtin_pbe,
+ sizeof(builtin_pbe)/sizeof(EVP_PBE_CTL),
+ pbe_cmp2);
}
if (pbetmp == NULL)
return 0;
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index 765a6c07db..3fd11cbb5a 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -84,15 +84,22 @@ static const EVP_PKEY_METHOD *standard_methods[] =
&hmac_pkey_meth,
};
+DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
+ pmeth_cmp);
+
static int pmeth_cmp(const EVP_PKEY_METHOD * const *a,
- const EVP_PKEY_METHOD * const *b)
+ const EVP_PKEY_METHOD * const *b)
{
return ((*a)->pkey_id - (*b)->pkey_id);
}
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
+ pmeth_cmp);
+
const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
{
- EVP_PKEY_METHOD tmp, *t = &tmp, **ret;
+ EVP_PKEY_METHOD tmp, *t = &tmp;
+ const EVP_PKEY_METHOD **ret;
tmp.pkey_id = type;
if (app_pkey_methods)
{
@@ -101,11 +108,10 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
if (idx >= 0)
return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
}
- ret = (EVP_PKEY_METHOD **) OBJ_bsearch((char *)&t,
- (char *)standard_methods,
- sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *),
- sizeof(EVP_PKEY_METHOD *),
- (int (*)(const void *, const void *))pmeth_cmp);
+ ret = OBJ_bsearch(EVP_PKEY_METHOD *, &t,
+ const EVP_PKEY_METHOD *, standard_methods,
+ sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *),
+ pmeth_cmp);
if (!ret || !*ret)
return NULL;
return *ret;
diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c
index db88f5f980..acb6bcfb06 100644
--- a/crypto/objects/obj_dat.c
+++ b/crypto/objects/obj_dat.c
@@ -81,9 +81,10 @@ static const unsigned int ln_objs[1];
static const unsigned int obj_objs[1];
#endif
-static int sn_cmp(const void *a, const void *b);
-static int ln_cmp(const void *a, const void *b);
-static int obj_cmp(const void *a, const void *b);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, const unsigned int, sn_cmp);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, const unsigned int, ln_cmp);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, const unsigned int, obj_cmp);
+
#define ADDED_DATA 0
#define ADDED_SNAME 1
#define ADDED_LNAME 2
@@ -99,19 +100,15 @@ DECLARE_LHASH_OF(ADDED_OBJ);
static int new_nid=NUM_NID;
static LHASH_OF(ADDED_OBJ) *added=NULL;
-static int sn_cmp(const void *a, const void *b)
- {
- const ASN1_OBJECT * const *ap = a;
- const unsigned int *bp = b;
- return(strcmp((*ap)->sn,nid_objs[*bp].sn));
- }
+static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
+ { return(strcmp((*a)->sn,nid_objs[*b].sn)); }
-static int ln_cmp(const void *a, const void *b)
- {
- const ASN1_OBJECT * const *ap = a;
- const unsigned int *bp = b;
- return(strcmp((*ap)->ln,nid_objs[*bp].ln));
- }
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, const unsigned int, sn_cmp)
+
+static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
+ { return(strcmp((*a)->ln,nid_objs[*b].ln)); }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, const unsigned int, ln_cmp)
static unsigned long added_obj_hash(const ADDED_OBJ *ca)
{
@@ -385,6 +382,19 @@ const char *OBJ_nid2ln(int n)
}
}
+static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
+ {
+ int j;
+ const ASN1_OBJECT *a= *ap;
+ const ASN1_OBJECT *b= &nid_objs[*bp];
+
+ j=(a->length - b->length);
+ if (j) return(j);
+ return(memcmp(a->data,b->data,a->length));
+ }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, const unsigned int, obj_cmp)
+
int OBJ_obj2nid(const ASN1_OBJECT *a)
{
const unsigned int *op;
@@ -402,8 +412,8 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
adp=lh_ADDED_OBJ_retrieve(added,&ad);
if (adp != NULL) return (adp->obj->nid);
}
- op=(const unsigned int *)OBJ_bsearch((const char *)&a,(const char *)obj_objs,
- NUM_OBJ, sizeof(obj_objs[0]),obj_cmp);
+ op=OBJ_bsearch(const ASN1_OBJECT *, &a, const unsigned int, obj_objs,
+ NUM_OBJ, obj_cmp);
if (op == NULL)
return(NID_undef);
return(nid_objs[*op].nid);
@@ -625,7 +635,8 @@ int OBJ_txt2nid(const char *s)
int OBJ_ln2nid(const char *s)
{
- ASN1_OBJECT o,*oo= &o;
+ ASN1_OBJECT o;
+ const ASN1_OBJECT *oo= &o;
ADDED_OBJ ad,*adp;
const unsigned int *op;
@@ -637,15 +648,16 @@ int OBJ_ln2nid(const char *s)
adp=lh_ADDED_OBJ_retrieve(added,&ad);
if (adp != NULL) return (adp->obj->nid);
}
- op=(const unsigned int*)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN,
- sizeof(ln_objs[0]),ln_cmp);
+ op=OBJ_bsearch(const ASN1_OBJECT *, &oo, const unsigned int, ln_objs,
+ NUM_LN, ln_cmp);
if (op == NULL) return(NID_undef);
return(nid_objs[*op].nid);
}
int OBJ_sn2nid(const char *s)
{
- ASN1_OBJECT o,*oo= &o;
+ ASN1_OBJECT o;
+ const ASN1_OBJECT *oo= &o;
ADDED_OBJ ad,*adp;
const unsigned int *op;
@@ -657,32 +669,22 @@ int OBJ_sn2nid(const char *s)
adp=lh_ADDED_OBJ_retrieve(added,&ad);
if (adp != NULL) return (adp->obj->nid);
}
- op=(const unsigned int *)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
- sizeof(sn_objs[0]),sn_cmp);
+ op=OBJ_bsearch(const ASN1_OBJECT *, &oo, const unsigned int, sn_objs,
+ NUM_SN, sn_cmp);
if (op == NULL) return(NID_undef);
return(nid_objs[*op].nid);
}
-static int obj_cmp(const void *ap, const void *bp)
- {
- int j;
- const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap;
- const ASN1_OBJECT *b= &nid_objs[*((const unsigned int *)bp)];
-
- j=(a->length - b->length);
- if (j) return(j);
- return(memcmp(a->data,b->data,a->length));
- }
-
-const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
- int (*cmp)(const void *, const void *))
+const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
+ int (*cmp)(const void *, const void *))
{
return OBJ_bsearch_ex(key, base, num, size, cmp, 0);
}
-const char *OBJ_bsearch_ex(const char *key, const char *base, int num,
+const void *OBJ_bsearch_ex(const void *key, const void *base_, int num,
int size, int (*cmp)(const void *, const void *), int flags)
{
+ const char *base=base_;
int l,h,i=0,c=0;
const char *p = NULL;
diff --git a/crypto/objects/obj_xref.c b/crypto/objects/obj_xref.c
index 4ebaa1cc6a..3e85e7a576 100644
--- a/crypto/objects/obj_xref.c
+++ b/crypto/objects/obj_xref.c
@@ -64,28 +64,35 @@ STACK_OF(nid_triple) *sig_app, *sigx_app;
static int cmp_sig(const nid_triple *a, const nid_triple *b)
{
- return **a - **b;
+ return a->sign_id - b->sign_id;
}
+DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple, const nid_triple, cmp_sig);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple, const nid_triple, cmp_sig)
+
static int cmp_sig_sk(const nid_triple * const *a, const nid_triple * const *b)
{
- return ***a - ***b;
+ return (*a)->sign_id - (*b)->sign_id;
}
+DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, cmp_sigx);
+
static int cmp_sigx(const nid_triple * const *a, const nid_triple * const *b)
{
int ret;
- ret = (**a)[1] - (**b)[1];
+ ret = (*a)->hash_id - (*b)->hash_id;
if (ret)
return ret;
- return (**a)[2] - (**b)[2];
+ return (*a)->pkey_id - (*b)->pkey_id;
}
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, cmp_sigx)
int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
{
- nid_triple tmp, *rv = NULL;
- tmp[0] = signid;
+ nid_triple tmp;
+ const nid_triple *rv = NULL;
+ tmp.sign_id = signid;
if (sig_app)
{
@@ -97,25 +104,27 @@ int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
#ifndef OBJ_XREF_TEST2
if (rv == NULL)
{
- rv = (nid_triple *)OBJ_bsearch((char *)&tmp,
- (char *)sigoid_srt,
- sizeof(sigoid_srt) / sizeof(nid_triple),
- sizeof(nid_triple),
- (int (*)(const void *, const void *))cmp_sig);
+ rv = OBJ_bsearch(const nid_triple,&tmp,
+ const nid_triple,sigoid_srt,
+ sizeof(sigoid_srt) / sizeof(nid_triple),
+ cmp_sig);
}
#endif
if (rv == NULL)
return 0;
- *pdig_nid = (*rv)[1];
- *ppkey_nid = (*rv)[2];
+ *pdig_nid = rv->hash_id;
+ *ppkey_nid = rv->pkey_id;
return 1;
}
int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
{
- nid_triple tmp, *t=&tmp, **rv = NULL;
- tmp[1] = dig_nid;
- tmp[2] = pkey_nid;
+ nid_triple tmp;
+ const nid_triple const *t=&tmp;
+ const nid_triple **rv = NULL;
+
+ tmp.hash_id = dig_nid;
+ tmp.pkey_id = pkey_nid;
if (sigx_app)
{
@@ -130,16 +139,15 @@ int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
#ifndef OBJ_XREF_TEST2
if (rv == NULL)
{
- rv = (nid_triple **)OBJ_bsearch((char *)&t,
- (char *)sigoid_srt_xref,
- sizeof(sigoid_srt_xref) / sizeof(nid_triple *),
- sizeof(nid_triple *),
- (int (*)(const void *, const void *))cmp_sigx);
+ rv = OBJ_bsearch(const nid_triple *,&t,
+ const nid_triple *,sigoid_srt_xref,
+ sizeof(sigoid_srt_xref) / sizeof(nid_triple *),
+ cmp_sigx);
}
#endif
if (rv == NULL)
return 0;
- *psignid = (**rv)[0];
+ *psignid = (*rv)->sign_id;
return 1;
}
@@ -157,9 +165,9 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
ntr = OPENSSL_malloc(sizeof(int) * 3);
if (!ntr)
return 0;
- (*ntr)[0] = signid;
- (*ntr)[1] = dig_id;
- (*ntr)[2] = pkey_id;
+ ntr->sign_id = signid;
+ ntr->hash_id = dig_id;
+ ntr->pkey_id = pkey_id;
if (!sk_nid_triple_push(sig_app, ntr))
{
diff --git a/crypto/objects/obj_xref.h b/crypto/objects/obj_xref.h
deleted file mode 100644
index c139d3a8e2..0000000000
--- a/crypto/objects/obj_xref.h
+++ /dev/null
@@ -1,69 +0,0 @@
-
-typedef int nid_triple[3];
-
-static const nid_triple sigoid_srt[] =
- {
- {NID_md2WithRSAEncryption, NID_md2, NID_rsaEncryption},
- {NID_md5WithRSAEncryption, NID_md5, NID_rsaEncryption},
- {NID_shaWithRSAEncryption, NID_sha, NID_rsaEncryption},
- {NID_sha1WithRSAEncryption, NID_sha1, NID_rsaEncryption},
- {NID_dsaWithSHA, NID_sha, NID_dsa},
- {NID_dsaWithSHA1_2, NID_sha1, NID_dsa_2},
- {NID_mdc2WithRSA, NID_mdc2, NID_rsaEncryption},
- {NID_md5WithRSA, NID_md5, NID_rsa},
- {NID_dsaWithSHA1, NID_sha1, NID_dsa},
- {NID_sha1WithRSA, NID_sha1, NID_rsa},
- {NID_ripemd160WithRSA, NID_ripemd160, NID_rsaEncryption},
- {NID_md4WithRSAEncryption, NID_md4, NID_rsaEncryption},
- {NID_ecdsa_with_SHA1, NID_sha1, NID_X9_62_id_ecPublicKey},
- {NID_sha256WithRSAEncryption, NID_sha256, NID_rsaEncryption},
- {NID_sha384WithRSAEncryption, NID_sha384, NID_rsaEncryption},
- {NID_sha512WithRSAEncryption, NID_sha512, NID_rsaEncryption},
- {NID_sha224WithRSAEncryption, NID_sha224, NID_rsaEncryption},
- {NID_ecdsa_with_Recommended, NID_undef, NID_X9_62_id_ecPublicKey},
- {NID_ecdsa_with_Specified, NID_undef, NID_X9_62_id_ecPublicKey},
- {NID_ecdsa_with_SHA224, NID_sha224, NID_X9_62_id_ecPublicKey},
- {NID_ecdsa_with_SHA256, NID_sha256, NID_X9_62_id_ecPublicKey},
- {NID_ecdsa_with_SHA384, NID_sha384, NID_X9_62_id_ecPublicKey},
- {NID_ecdsa_with_SHA512, NID_sha512, NID_X9_62_id_ecPublicKey},
- {NID_dsa_with_SHA224, NID_sha224, NID_dsa},
- {NID_dsa_with_SHA256, NID_sha256, NID_dsa},
- {NID_id_GostR3411_94_with_GostR3410_2001, NID_id_GostR3411_94, NID_id_GostR3410_2001},
- {NID_id_GostR3411_94_with_GostR3410_94, NID_id_GostR3411_94, NID_id_GostR3410_94},
- {NID_id_GostR3411_94_with_GostR3410_94_cc, NID_id_GostR3411_94, NID_id_GostR3410_94_cc},
- {NID_id_GostR3411_94_with_GostR3410_2001_cc, NID_id_GostR3411_94, NID_id_GostR3410_2001_cc},
- };
-
-static const nid_triple * const sigoid_srt_xref[] =
- {
- &sigoid_srt[17],
- &sigoid_srt[18],
- &sigoid_srt[0],
- &sigoid_srt[1],
- &sigoid_srt[7],
- &sigoid_srt[2],
- &sigoid_srt[4],
- &sigoid_srt[3],
- &sigoid_srt[9],
- &sigoid_srt[5],
- &sigoid_srt[8],
- &sigoid_srt[12],
- &sigoid_srt[6],
- &sigoid_srt[10],
- &sigoid_srt[11],
- &sigoid_srt[13],
- &sigoid_srt[24],
- &sigoid_srt[20],
- &sigoid_srt[14],
- &sigoid_srt[21],
- &sigoid_srt[15],
- &sigoid_srt[22],
- &sigoid_srt[16],
- &sigoid_srt[23],
- &sigoid_srt[19],
- &sigoid_srt[25],
- &sigoid_srt[26],
- &sigoid_srt[27],
- &sigoid_srt[28],
- };
-
diff --git a/crypto/objects/objects.h b/crypto/objects/objects.h
index 7d8cdc97c3..7dc1bf5f00 100644
--- a/crypto/objects/objects.h
+++ b/crypto/objects/objects.h
@@ -1011,10 +1011,68 @@ int OBJ_txt2nid(const char *s);
int OBJ_ln2nid(const char *s);
int OBJ_sn2nid(const char *s);
int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
-const char * OBJ_bsearch(const char *key,const char *base,int num,int size,
- int (*cmp)(const void *, const void *));
-const char * OBJ_bsearch_ex(const char *key,const char *base,int num,
- int size, int (*cmp)(const void *, const void *), int flags);
+const void * OBJ_bsearch_(const void *key,const void *base,int num,int size,
+ int (*cmp)(const void *, const void *));
+const void * OBJ_bsearch_ex(const void *key,const void *base,int num,
+ int size, int (*cmp)(const void *, const void *),
+ int flags);
+
+#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, cmp) \
+ scope type1 *cmp##_type_1; \
+ scope type2 *cmp##_type_2; \
+ scope int cmp##_BSEARCH_CMP_FN(const void *, const void *); \
+ scope int cmp(const type1 const *, const type2 const *);
+
+#define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \
+ _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
+#define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, cmp) \
+ _DECLARE_OBJ_BSEARCH_CMP_FN(, type1, type2, cmp)
+
+/*
+ * Unsolved problem: if a type is actually a pointer type, like
+ * nid_triple is, then its impossible to get a const where you need
+ * it. Consider:
+ *
+ * typedef int nid_triple[3];
+ * const void *a_;
+ * const nid_triple const *a = a_;
+ *
+ * The assignement discards a const because what you really want is:
+ *
+ * const int const * const *a = a_;
+ *
+ * But if you do that, you lose the fact that a is an array of 3 ints,
+ * which breaks comparison functions.
+ *
+ * Thus we end up having to cast, sadly, or unpack the
+ * declarations. Or, as I finally did in this case, delcare nid_triple
+ * to be a struct, which it should have been in the first place.
+ *
+ * Ben, August 2008.
+ *
+ * Also, strictly speaking not all types need be const, but handling
+ * the non-constness means a lot of complication, and in practice
+ * comparison routines do always not touch their arguments.
+ */
+#define _IMPLEMENT_OBJ_BSEARCH_CMP_FN(scope, type1, type2, cmp) \
+ scope int cmp##_BSEARCH_CMP_FN(const void *a_, const void *b_) \
+ { \
+ const type1 const *a = a_; \
+ const type2 const *b = b_; \
+ return cmp(a,b); \
+ }
+
+#define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \
+ _IMPLEMENT_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
+#define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, cmp) \
+ _IMPLEMENT_OBJ_BSEARCH_CMP_FN(, type1, type2, cmp)
+
+#define OBJ_bsearch(type1,key,type2,base,num,cmp) \
+ ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
+ num,sizeof(type2), \
+ (cmp##_type_1=CHECKED_PTR_OF(type1,cmp##_type_1), \
+ cmp##_type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \
+ cmp##_BSEARCH_CMP_FN)))
int OBJ_new_nid(int num);
int OBJ_add_object(const ASN1_OBJECT *obj);
diff --git a/crypto/objects/objxref.pl b/crypto/objects/objxref.pl
index 0dd360b5b0..4a42924c56 100644
--- a/crypto/objects/objxref.pl
+++ b/crypto/objects/objxref.pl
@@ -50,8 +50,14 @@ my @srt2 = sort
print <<EOF;
+/* AUTOGENERATED BY $0, DO NOT EDIT */
-typedef int nid_triple[3];
+typedef struct
+ {
+ int sign_id;
+ int hash_id;
+ int pkey_id;
+ } nid_triple;
static const nid_triple sigoid_srt[] =
{
diff --git a/crypto/x509/x509_vpm.c b/crypto/x509/x509_vpm.c
index e9db6d62a7..9c37c4ded3 100644
--- a/crypto/x509/x509_vpm.c
+++ b/crypto/x509/x509_vpm.c
@@ -356,12 +356,17 @@ static const X509_VERIFY_PARAM default_table[] = {
static STACK_OF(X509_VERIFY_PARAM) *param_table = NULL;
-static int table_cmp(const void *pa, const void *pb)
+static int table_cmp(const X509_VERIFY_PARAM *a, const X509_VERIFY_PARAM *b)
+
{
- const X509_VERIFY_PARAM *a = pa, *b = pb;
return strcmp(a->name, b->name);
}
+DECLARE_OBJ_BSEARCH_CMP_FN(const X509_VERIFY_PARAM, const X509_VERIFY_PARAM,
+ table_cmp);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const X509_VERIFY_PARAM, const X509_VERIFY_PARAM,
+ table_cmp);
+
static int param_cmp(const X509_VERIFY_PARAM * const *a,
const X509_VERIFY_PARAM * const *b)
{
@@ -397,6 +402,7 @@ const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name)
{
int idx;
X509_VERIFY_PARAM pm;
+
pm.name = (char *)name;
if (param_table)
{
@@ -404,