diff options
author | tb <> | 2023-12-13 23:31:25 +0000 |
---|---|---|
committer | tb <> | 2023-12-13 23:31:25 +0000 |
commit | 2be751febeb2e986c60a7b151321579df8e4bf75 (patch) | |
tree | edc7d812ffd27e941a8cb0e982ddfcc85c7536e9 /src | |
parent | f9e4eb95614e9427e1bbb5caa4377d07c7fb4f0c (diff) | |
download | openbsd-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.c | 71 |
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 | ||
78 | static int sn_cmp_BSEARCH_CMP_FN(const void *, const void *); | ||
79 | static int sn_cmp(const ASN1_OBJECT * const *, unsigned int const *); | ||
80 | static unsigned int *OBJ_bsearch_sn(const ASN1_OBJECT * *key, unsigned int const *base, int num); | ||
81 | static int ln_cmp_BSEARCH_CMP_FN(const void *, const void *); | 78 | static int ln_cmp_BSEARCH_CMP_FN(const void *, const void *); |
82 | static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const *); | 79 | static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const *); |
83 | static unsigned int *OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num); | 80 | static unsigned int *OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num); |
@@ -96,33 +93,11 @@ DECLARE_LHASH_OF(ADDED_OBJ); | |||
96 | static int new_nid = NUM_NID; | 93 | static int new_nid = NUM_NID; |
97 | static LHASH_OF(ADDED_OBJ) *added = NULL; | 94 | static LHASH_OF(ADDED_OBJ) *added = NULL; |
98 | 95 | ||
99 | static 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 | |||
105 | static int | ||
106 | sn_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 | |||
113 | static unsigned int * | ||
114 | OBJ_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 | |||
120 | static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) | 96 | static 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 | |||
126 | static int | 101 | static int |
127 | ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | 102 | ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) |
128 | { | 103 | { |
@@ -518,26 +493,40 @@ OBJ_ln2nid(const char *s) | |||
518 | } | 493 | } |
519 | LCRYPTO_ALIAS(OBJ_ln2nid); | 494 | LCRYPTO_ALIAS(OBJ_ln2nid); |
520 | 495 | ||
496 | static int | ||
497 | sn_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 | |||
521 | int | 504 | int |
522 | OBJ_sn2nid(const char *s) | 505 | OBJ_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 | } |
542 | LCRYPTO_ALIAS(OBJ_sn2nid); | 531 | LCRYPTO_ALIAS(OBJ_sn2nid); |
543 | 532 | ||