summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-12-13 23:31:25 +0000
committertb <>2023-12-13 23:31:25 +0000
commit2be751febeb2e986c60a7b151321579df8e4bf75 (patch)
treeedc7d812ffd27e941a8cb0e982ddfcc85c7536e9 /src
parentf9e4eb95614e9427e1bbb5caa4377d07c7fb4f0c (diff)
downloadopenbsd-2be751febeb2e986c60a7b151321579df8e4bf75.tar.gz
openbsd-2be751febeb2e986c60a7b151321579df8e4bf75.tar.bz2
openbsd-2be751febeb2e986c60a7b151321579df8e4bf75.zip
Simplify OBJ_sn2nid()
Another OBJ_bsearch_() elimination. OBJ_sn2nid() is very similar to OBJ_obj2nid(). First it tries to retrieve an object identifier with matching "short name" from the global hash of added objects and then searches the table of built-in objects. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c71
1 files changed, 30 insertions, 41 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 76e7b22fb8..f4f7f60eab 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_dat.c,v 1.63 2023/12/13 23:28:47 tb Exp $ */ 1/* $OpenBSD: obj_dat.c,v 1.64 2023/12/13 23:31:25 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -75,9 +75,6 @@
75/* obj_dat.h is generated from objects.h by obj_dat.pl */ 75/* obj_dat.h is generated from objects.h by obj_dat.pl */
76#include "obj_dat.h" 76#include "obj_dat.h"
77 77
78static int sn_cmp_BSEARCH_CMP_FN(const void *, const void *);
79static int sn_cmp(const ASN1_OBJECT * const *, unsigned int const *);
80static unsigned int *OBJ_bsearch_sn(const ASN1_OBJECT * *key, unsigned int const *base, int num);
81static int ln_cmp_BSEARCH_CMP_FN(const void *, const void *); 78static int ln_cmp_BSEARCH_CMP_FN(const void *, const void *);
82static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const *); 79static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const *);
83static unsigned int *OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num); 80static unsigned int *OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num);
@@ -96,33 +93,11 @@ DECLARE_LHASH_OF(ADDED_OBJ);
96static int new_nid = NUM_NID; 93static int new_nid = NUM_NID;
97static LHASH_OF(ADDED_OBJ) *added = NULL; 94static LHASH_OF(ADDED_OBJ) *added = NULL;
98 95
99static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
100{
101 return (strcmp((*a)->sn, nid_objs[*b].sn));
102}
103
104
105static int
106sn_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
107{
108 const ASN1_OBJECT * const *a = a_;
109 unsigned int const *b = b_;
110 return sn_cmp(a, b);
111}
112
113static unsigned int *
114OBJ_bsearch_sn(const ASN1_OBJECT * *key, unsigned int const *base, int num)
115{
116 return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof(unsigned int),
117 sn_cmp_BSEARCH_CMP_FN);
118}
119
120static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) 96static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
121{ 97{
122 return (strcmp((*a)->ln, nid_objs[*b].ln)); 98 return (strcmp((*a)->ln, nid_objs[*b].ln));
123} 99}
124 100
125
126static int 101static int
127ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) 102ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)
128{ 103{
@@ -518,26 +493,40 @@ OBJ_ln2nid(const char *s)
518} 493}
519LCRYPTO_ALIAS(OBJ_ln2nid); 494LCRYPTO_ALIAS(OBJ_ln2nid);
520 495
496static int
497sn_objs_cmp(const void *a, const void *b)
498{
499 const unsigned int *nid = b;
500
501 return strcmp(a, nid_objs[*nid].sn);
502}
503
521int 504int
522OBJ_sn2nid(const char *s) 505OBJ_sn2nid(const char *sn)
523{ 506{
524 ASN1_OBJECT o; 507 const unsigned int *nid;
525 const ASN1_OBJECT *oo = &o;
526 ADDED_OBJ ad, *adp;
527 const unsigned int *op;
528 508
529 o.sn = s; 509 /* XXX - locking. OpenSSL 3 moved this after built-in object lookup. */
530 if (added != NULL) { 510 if (added != NULL) {
531 ad.type = ADDED_SNAME; 511 ASN1_OBJECT aobj = {
532 ad.obj = &o; 512 .sn = sn,
533 adp = lh_ADDED_OBJ_retrieve(added, &ad); 513 };
534 if (adp != NULL) 514 ADDED_OBJ needle = {
535 return (adp->obj->nid); 515 .type = ADDED_SNAME,
516 .obj = &aobj,
517 };
518 ADDED_OBJ *found;
519
520 if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
521 return found->obj->nid;
536 } 522 }
537 op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN); 523
538 if (op == NULL) 524 /* sn_objs holds NIDs in ascending alphabetical order of SN. */
539 return (NID_undef); 525 nid = bsearch(sn, sn_objs, NUM_SN, sizeof(unsigned int), sn_objs_cmp);
540 return (nid_objs[*op].nid); 526 if (nid != NULL)
527 return *nid;
528
529 return NID_undef;
541} 530}
542LCRYPTO_ALIAS(OBJ_sn2nid); 531LCRYPTO_ALIAS(OBJ_sn2nid);
543 532