diff options
Diffstat (limited to 'src/lib/libcrypto/objects/obj_dat.c')
-rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 74 |
1 files changed, 32 insertions, 42 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index f4f7f60eab..14da51645d 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.64 2023/12/13 23:31:25 tb Exp $ */ | 1 | /* $OpenBSD: obj_dat.c,v 1.65 2023/12/13 23:34:45 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,10 +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 ln_cmp_BSEARCH_CMP_FN(const void *, const void *); | ||
79 | static int ln_cmp(const ASN1_OBJECT * const *, unsigned int const *); | ||
80 | static unsigned int *OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num); | ||
81 | |||
82 | #define ADDED_DATA 0 | 78 | #define ADDED_DATA 0 |
83 | #define ADDED_SNAME 1 | 79 | #define ADDED_SNAME 1 |
84 | #define ADDED_LNAME 2 | 80 | #define ADDED_LNAME 2 |
@@ -93,26 +89,6 @@ DECLARE_LHASH_OF(ADDED_OBJ); | |||
93 | static int new_nid = NUM_NID; | 89 | static int new_nid = NUM_NID; |
94 | static LHASH_OF(ADDED_OBJ) *added = NULL; | 90 | static LHASH_OF(ADDED_OBJ) *added = NULL; |
95 | 91 | ||
96 | static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) | ||
97 | { | ||
98 | return (strcmp((*a)->ln, nid_objs[*b].ln)); | ||
99 | } | ||
100 | |||
101 | static int | ||
102 | ln_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) | ||
103 | { | ||
104 | const ASN1_OBJECT * const *a = a_; | ||
105 | unsigned int const *b = b_; | ||
106 | return ln_cmp(a, b); | ||
107 | } | ||
108 | |||
109 | static unsigned int * | ||
110 | OBJ_bsearch_ln(const ASN1_OBJECT * *key, unsigned int const *base, int num) | ||
111 | { | ||
112 | return (unsigned int *)OBJ_bsearch_(key, base, num, sizeof(unsigned int), | ||
113 | ln_cmp_BSEARCH_CMP_FN); | ||
114 | } | ||
115 | |||
116 | static unsigned long | 92 | static unsigned long |
117 | added_obj_hash(const ADDED_OBJ *ca) | 93 | added_obj_hash(const ADDED_OBJ *ca) |
118 | { | 94 | { |
@@ -470,35 +446,49 @@ OBJ_txt2nid(const char *s) | |||
470 | } | 446 | } |
471 | LCRYPTO_ALIAS(OBJ_txt2nid); | 447 | LCRYPTO_ALIAS(OBJ_txt2nid); |
472 | 448 | ||
449 | static int | ||
450 | ln_objs_cmp(const void *ln, const void *b) | ||
451 | { | ||
452 | const unsigned int *nid = b; | ||
453 | |||
454 | return strcmp(ln, nid_objs[*nid].ln); | ||
455 | } | ||
456 | |||
473 | int | 457 | int |
474 | OBJ_ln2nid(const char *s) | 458 | OBJ_ln2nid(const char *ln) |
475 | { | 459 | { |
476 | ASN1_OBJECT o; | 460 | const unsigned int *nid; |
477 | const ASN1_OBJECT *oo = &o; | ||
478 | ADDED_OBJ ad, *adp; | ||
479 | const unsigned int *op; | ||
480 | 461 | ||
481 | o.ln = s; | 462 | /* XXX - locking. OpenSSL 3 moved this after built-in object lookup. */ |
482 | if (added != NULL) { | 463 | if (added != NULL) { |
483 | ad.type = ADDED_LNAME; | 464 | ASN1_OBJECT aobj = { |
484 | ad.obj = &o; | 465 | .ln = ln, |
485 | adp = lh_ADDED_OBJ_retrieve(added, &ad); | 466 | }; |
486 | if (adp != NULL) | 467 | ADDED_OBJ needle = { |
487 | return (adp->obj->nid); | 468 | .type = ADDED_LNAME, |
469 | .obj = &aobj, | ||
470 | }; | ||
471 | ADDED_OBJ *found; | ||
472 | |||
473 | if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL) | ||
474 | return found->obj->nid; | ||
488 | } | 475 | } |
489 | op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN); | 476 | |
490 | if (op == NULL) | 477 | /* ln_objs holds NIDs in ascending alphabetical order of LN. */ |
491 | return (NID_undef); | 478 | nid = bsearch(ln, ln_objs, NUM_LN, sizeof(unsigned int), ln_objs_cmp); |
492 | return (nid_objs[*op].nid); | 479 | if (nid != NULL) |
480 | return *nid; | ||
481 | |||
482 | return NID_undef; | ||
493 | } | 483 | } |
494 | LCRYPTO_ALIAS(OBJ_ln2nid); | 484 | LCRYPTO_ALIAS(OBJ_ln2nid); |
495 | 485 | ||
496 | static int | 486 | static int |
497 | sn_objs_cmp(const void *a, const void *b) | 487 | sn_objs_cmp(const void *sn, const void *b) |
498 | { | 488 | { |
499 | const unsigned int *nid = b; | 489 | const unsigned int *nid = b; |
500 | 490 | ||
501 | return strcmp(a, nid_objs[*nid].sn); | 491 | return strcmp(sn, nid_objs[*nid].sn); |
502 | } | 492 | } |
503 | 493 | ||
504 | int | 494 | int |