From cf9904a4b13d79f0e11e7db5209260a381b4a83f Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 21 Jan 2017 04:44:43 +0000 Subject: Expand DECLARE_OBJ_BSEARCH_CMP_FN and IMPLEMENT_OBJ_BSEARCH_CMP_FN macros. No change to generated assembly excluding line numbers. --- src/lib/libcrypto/evp/evp_pbe.c | 22 +++++++++++-- src/lib/libcrypto/evp/pmeth_lib.c | 24 +++++++++++--- src/lib/libcrypto/objects/obj_dat.c | 62 ++++++++++++++++++++++++++++++++---- src/lib/libcrypto/objects/obj_xref.c | 42 +++++++++++++++++++++--- src/lib/libcrypto/x509v3/v3_lib.c | 24 +++++++++++--- src/lib/libcrypto/x509v3/v3_purp.c | 22 +++++++++++-- 6 files changed, 168 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c index 0787e2dc94..c7f0c7749a 100644 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ b/src/lib/libcrypto/evp/evp_pbe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_pbe.c,v 1.23 2015/02/08 22:20:18 miod Exp $ */ +/* $OpenBSD: evp_pbe.c,v 1.24 2017/01/21 04:38:23 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -169,7 +169,9 @@ EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, return 1; } -DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe2); +static int pbe2_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int pbe2_cmp(EVP_PBE_CTL const *, EVP_PBE_CTL const *); +static EVP_PBE_CTL *OBJ_bsearch_pbe2(EVP_PBE_CTL *key, EVP_PBE_CTL const *base, int num); static int pbe2_cmp(const EVP_PBE_CTL *pbe1, const EVP_PBE_CTL *pbe2) @@ -182,7 +184,21 @@ pbe2_cmp(const EVP_PBE_CTL *pbe1, const EVP_PBE_CTL *pbe2) return pbe1->pbe_nid - pbe2->pbe_nid; } -IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PBE_CTL, EVP_PBE_CTL, pbe2); + +static int +pbe2_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + EVP_PBE_CTL const *a = a_; + EVP_PBE_CTL const *b = b_; + return pbe2_cmp(a, b); +} + +static EVP_PBE_CTL * +OBJ_bsearch_pbe2(EVP_PBE_CTL *key, EVP_PBE_CTL const *base, int num) +{ + return (EVP_PBE_CTL *)OBJ_bsearch_(key, base, num, sizeof(EVP_PBE_CTL), + pbe2_cmp_BSEARCH_CMP_FN); +} static int pbe_cmp(const EVP_PBE_CTL * const *a, const EVP_PBE_CTL * const *b) diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c index c93fa99cc6..1d64edcbeb 100644 --- a/src/lib/libcrypto/evp/pmeth_lib.c +++ b/src/lib/libcrypto/evp/pmeth_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmeth_lib.c,v 1.11 2015/02/11 03:19:37 doug Exp $ */ +/* $OpenBSD: pmeth_lib.c,v 1.12 2017/01/21 04:38:23 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -103,8 +103,9 @@ static const EVP_PKEY_METHOD *standard_methods[] = { &cmac_pkey_meth, }; -DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, - pmeth); +static int pmeth_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int pmeth_cmp(const EVP_PKEY_METHOD * const *, const EVP_PKEY_METHOD * const *); +static const EVP_PKEY_METHOD * *OBJ_bsearch_pmeth(const EVP_PKEY_METHOD * *key, const EVP_PKEY_METHOD * const *base, int num); static int pmeth_cmp(const EVP_PKEY_METHOD * const *a, const EVP_PKEY_METHOD * const *b) @@ -112,8 +113,21 @@ pmeth_cmp(const EVP_PKEY_METHOD * const *a, const EVP_PKEY_METHOD * const *b) return ((*a)->pkey_id - (*b)->pkey_id); } -IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *, - pmeth); + +static int +pmeth_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + const EVP_PKEY_METHOD * const *a = a_; + const EVP_PKEY_METHOD * const *b = b_; + return pmeth_cmp(a, b); +} + +static const EVP_PKEY_METHOD * * +OBJ_bsearch_pmeth(const EVP_PKEY_METHOD * *key, const EVP_PKEY_METHOD * const *base, int num) +{ + return (const EVP_PKEY_METHOD * *)OBJ_bsearch_(key, base, num, sizeof(const EVP_PKEY_METHOD *), + pmeth_cmp_BSEARCH_CMP_FN); +} const EVP_PKEY_METHOD * EVP_PKEY_meth_find(int type) diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 1d6207072d..e1dacc0d39 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: obj_dat.c,v 1.37 2016/12/22 16:57:38 inoguchi Exp $ */ +/* $OpenBSD: obj_dat.c,v 1.38 2017/01/21 04:44:43 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -72,9 +72,15 @@ /* obj_dat.h is generated from objects.h by obj_dat.pl */ #include "obj_dat.h" -DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); -DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); -DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); +static int sn_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int sn_cmp(const ASN1_OBJECT * const *, unsigned int const *); +static unsigned int *OBJ_bsearch_sn(const ASN1_OBJECT * *key, unsigned int const *base, int num); +static int ln_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const *); +static unsigned int *OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num); +static int obj_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int obj_cmp(const ASN1_OBJECT * const *, unsigned int const *); +static unsigned int *OBJ_bsearch_obj(const ASN1_OBJECT * *key, unsigned int const *base, int num); #define ADDED_DATA 0 #define ADDED_SNAME 1 @@ -95,14 +101,42 @@ static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) return (strcmp((*a)->sn, nid_objs[*b].sn)); } -IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); + +static int +sn_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + const ASN1_OBJECT * const *a = a_; + unsigned int const *b = b_; + return sn_cmp(a, b); +} + +static unsigned int * +OBJ_bsearch_sn(const ASN1_OBJECT * *key, unsigned int const *base, int num) +{ + return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof(unsigned int), + sn_cmp_BSEARCH_CMP_FN); +} 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 *, unsigned int, ln); + +static int +ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + const ASN1_OBJECT * const *a = a_; + unsigned int const *b = b_; + return ln_cmp(a, b); +} + +static unsigned int * +OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num) +{ + return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof(unsigned int), + ln_cmp_BSEARCH_CMP_FN); +} static unsigned long added_obj_hash(const ADDED_OBJ *ca) @@ -400,7 +434,21 @@ obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp) return (memcmp(a->data, b->data, a->length)); } -IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); + +static int +obj_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + const ASN1_OBJECT * const *a = a_; + unsigned int const *b = b_; + return obj_cmp(a, b); +} + +static unsigned int * +OBJ_bsearch_obj(const ASN1_OBJECT * *key, unsigned int const *base, int num) +{ + return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof(unsigned int), + obj_cmp_BSEARCH_CMP_FN); +} int OBJ_obj2nid(const ASN1_OBJECT *a) diff --git a/src/lib/libcrypto/objects/obj_xref.c b/src/lib/libcrypto/objects/obj_xref.c index 94dd6293dd..3e8730d1c6 100644 --- a/src/lib/libcrypto/objects/obj_xref.c +++ b/src/lib/libcrypto/objects/obj_xref.c @@ -1,4 +1,4 @@ -/* $OpenBSD: obj_xref.c,v 1.7 2014/06/12 15:49:30 deraadt Exp $ */ +/* $OpenBSD: obj_xref.c,v 1.8 2017/01/21 04:44:43 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -68,8 +68,24 @@ sig_cmp(const nid_triple *a, const nid_triple *b) return a->sign_id - b->sign_id; } -DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig); -IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig); +static int sig_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int sig_cmp(nid_triple const *, nid_triple const *); +static nid_triple *OBJ_bsearch_sig(nid_triple *key, nid_triple const *base, int num); + +static int +sig_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + nid_triple const *a = a_; + nid_triple const *b = b_; + return sig_cmp(a, b); +} + +static nid_triple * +OBJ_bsearch_sig(nid_triple *key, nid_triple const *base, int num) +{ + return (nid_triple *)OBJ_bsearch_(key, base, num, sizeof(nid_triple), + sig_cmp_BSEARCH_CMP_FN); +} static int sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b) @@ -77,7 +93,9 @@ sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b) return (*a)->sign_id - (*b)->sign_id; } -DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx); +static int sigx_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int sigx_cmp(const nid_triple * const *, const nid_triple * const *); +static const nid_triple * *OBJ_bsearch_sigx(const nid_triple * *key, const nid_triple * const *base, int num); static int sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) @@ -90,7 +108,21 @@ sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) return (*a)->pkey_id - (*b)->pkey_id; } -IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx); + +static int +sigx_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + const nid_triple * const *a = a_; + const nid_triple * const *b = b_; + return sigx_cmp(a, b); +} + +static const nid_triple * * +OBJ_bsearch_sigx(const nid_triple * *key, const nid_triple * const *base, int num) +{ + return (const nid_triple * *)OBJ_bsearch_(key, base, num, sizeof(const nid_triple *), + sigx_cmp_BSEARCH_CMP_FN); +} int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid) diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c index 2e92747d43..946ef1d54e 100644 --- a/src/lib/libcrypto/x509v3/v3_lib.c +++ b/src/lib/libcrypto/x509v3/v3_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: v3_lib.c,v 1.15 2016/12/30 15:54:49 jsing Exp $ */ +/* $OpenBSD: v3_lib.c,v 1.16 2017/01/21 04:42:16 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -91,10 +91,24 @@ ext_cmp(const X509V3_EXT_METHOD * const *a, const X509V3_EXT_METHOD * const *b) return ((*a)->ext_nid - (*b)->ext_nid); } -DECLARE_OBJ_BSEARCH_CMP_FN(const X509V3_EXT_METHOD *, - const X509V3_EXT_METHOD *, ext); -IMPLEMENT_OBJ_BSEARCH_CMP_FN(const X509V3_EXT_METHOD *, - const X509V3_EXT_METHOD *, ext); +static int ext_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int ext_cmp(const X509V3_EXT_METHOD * const *, const X509V3_EXT_METHOD * const *); +static const X509V3_EXT_METHOD * *OBJ_bsearch_ext(const X509V3_EXT_METHOD * *key, const X509V3_EXT_METHOD * const *base, int num); + +static int +ext_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + const X509V3_EXT_METHOD * const *a = a_; + const X509V3_EXT_METHOD * const *b = b_; + return ext_cmp(a, b); +} + +static const X509V3_EXT_METHOD * * +OBJ_bsearch_ext(const X509V3_EXT_METHOD * *key, const X509V3_EXT_METHOD * const *base, int num) +{ + return (const X509V3_EXT_METHOD * *)OBJ_bsearch_(key, base, num, sizeof(const X509V3_EXT_METHOD *), + ext_cmp_BSEARCH_CMP_FN); +} const X509V3_EXT_METHOD * X509V3_EXT_get_nid(int nid) diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c index a091a7f425..d8ab679304 100644 --- a/src/lib/libcrypto/x509v3/v3_purp.c +++ b/src/lib/libcrypto/x509v3/v3_purp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: v3_purp.c,v 1.27 2016/11/08 20:01:06 miod Exp $ */ +/* $OpenBSD: v3_purp.c,v 1.28 2017/01/21 04:42:16 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2001. */ @@ -325,8 +325,24 @@ nid_cmp(const int *a, const int *b) return *a - *b; } -DECLARE_OBJ_BSEARCH_CMP_FN(int, int, nid); -IMPLEMENT_OBJ_BSEARCH_CMP_FN(int, int, nid); +static int nid_cmp_BSEARCH_CMP_FN(const void *, const void *); +static int nid_cmp(int const *, int const *); +static int *OBJ_bsearch_nid(int *key, int const *base, int num); + +static int +nid_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) +{ + int const *a = a_; + int const *b = b_; + return nid_cmp(a, b); +} + +static int * +OBJ_bsearch_nid(int *key, int const *base, int num) +{ + return (int *)OBJ_bsearch_(key, base, num, sizeof(int), + nid_cmp_BSEARCH_CMP_FN); +} int X509_supported_extension(X509_EXTENSION *ex) -- cgit v1.2.3-55-g6feb