sync with OpenBSD -current

This commit is contained in:
purplerain 2023-12-14 01:14:09 +00:00
parent 24ffeadca5
commit 8801582927
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
30 changed files with 1221 additions and 280 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: obj_dat.c,v 1.62 2023/11/27 11:52:32 tb Exp $ */
/* $OpenBSD: obj_dat.c,v 1.65 2023/12/13 23:34:45 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -59,6 +59,7 @@
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/opensslconf.h>
@ -74,16 +75,6 @@
/* obj_dat.h is generated from objects.h by obj_dat.pl */
#include "obj_dat.h"
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
#define ADDED_LNAME 2
@ -98,48 +89,6 @@ DECLARE_LHASH_OF(ADDED_OBJ);
static int new_nid = NUM_NID;
static LHASH_OF(ADDED_OBJ) *added = NULL;
static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
{
return (strcmp((*a)->sn, nid_objs[*b].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));
}
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)
{
@ -417,51 +366,42 @@ OBJ_nid2ln(int n)
LCRYPTO_ALIAS(OBJ_nid2ln);
static int
obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
obj_objs_cmp(const void *aobj, const void *b)
{
const ASN1_OBJECT *a = *ap;
const ASN1_OBJECT *b = &nid_objs[*bp];
const unsigned int *nid = b;
return OBJ_cmp(a, b);
}
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);
return OBJ_cmp(aobj, &nid_objs[*nid]);
}
int
OBJ_obj2nid(const ASN1_OBJECT *a)
OBJ_obj2nid(const ASN1_OBJECT *aobj)
{
const unsigned int *op;
ADDED_OBJ ad, *adp;
const unsigned int *nid;
if (a == NULL || a->length == 0)
return (NID_undef);
if (a->nid != NID_undef)
return (a->nid);
if (aobj == NULL || aobj->length == 0)
return NID_undef;
if (aobj->nid != NID_undef)
return aobj->nid;
/* XXX - locking. OpenSSL 3 moved this after built-in object lookup. */
if (added != NULL) {
ad.type = ADDED_DATA;
ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
adp = lh_ADDED_OBJ_retrieve(added, &ad);
if (adp != NULL)
return (adp->obj->nid);
ADDED_OBJ needle = {
.type = ADDED_DATA,
.obj = (ASN1_OBJECT *)aobj,
};
ADDED_OBJ *found;
if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
return found->obj->nid;
}
op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
if (op == NULL)
return (NID_undef);
return (nid_objs[*op].nid);
/* obj_objs holds built-in obj NIDs in ascending OBJ_cmp() order. */
nid = bsearch(aobj, obj_objs, NUM_OBJ, sizeof(unsigned int), obj_objs_cmp);
if (nid != NULL)
return *nid;
return NID_undef;
}
LCRYPTO_ALIAS(OBJ_obj2nid);
@ -506,49 +446,77 @@ OBJ_txt2nid(const char *s)
}
LCRYPTO_ALIAS(OBJ_txt2nid);
int
OBJ_ln2nid(const char *s)
static int
ln_objs_cmp(const void *ln, const void *b)
{
ASN1_OBJECT o;
const ASN1_OBJECT *oo = &o;
ADDED_OBJ ad, *adp;
const unsigned int *op;
const unsigned int *nid = b;
o.ln = s;
return strcmp(ln, nid_objs[*nid].ln);
}
int
OBJ_ln2nid(const char *ln)
{
const unsigned int *nid;
/* XXX - locking. OpenSSL 3 moved this after built-in object lookup. */
if (added != NULL) {
ad.type = ADDED_LNAME;
ad.obj = &o;
adp = lh_ADDED_OBJ_retrieve(added, &ad);
if (adp != NULL)
return (adp->obj->nid);
ASN1_OBJECT aobj = {
.ln = ln,
};
ADDED_OBJ needle = {
.type = ADDED_LNAME,
.obj = &aobj,
};
ADDED_OBJ *found;
if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
return found->obj->nid;
}
op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
if (op == NULL)
return (NID_undef);
return (nid_objs[*op].nid);
/* ln_objs holds NIDs in ascending alphabetical order of LN. */
nid = bsearch(ln, ln_objs, NUM_LN, sizeof(unsigned int), ln_objs_cmp);
if (nid != NULL)
return *nid;
return NID_undef;
}
LCRYPTO_ALIAS(OBJ_ln2nid);
int
OBJ_sn2nid(const char *s)
static int
sn_objs_cmp(const void *sn, const void *b)
{
ASN1_OBJECT o;
const ASN1_OBJECT *oo = &o;
ADDED_OBJ ad, *adp;
const unsigned int *op;
const unsigned int *nid = b;
o.sn = s;
return strcmp(sn, nid_objs[*nid].sn);
}
int
OBJ_sn2nid(const char *sn)
{
const unsigned int *nid;
/* XXX - locking. OpenSSL 3 moved this after built-in object lookup. */
if (added != NULL) {
ad.type = ADDED_SNAME;
ad.obj = &o;
adp = lh_ADDED_OBJ_retrieve(added, &ad);
if (adp != NULL)
return (adp->obj->nid);
ASN1_OBJECT aobj = {
.sn = sn,
};
ADDED_OBJ needle = {
.type = ADDED_SNAME,
.obj = &aobj,
};
ADDED_OBJ *found;
if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
return found->obj->nid;
}
op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
if (op == NULL)
return (NID_undef);
return (nid_objs[*op].nid);
/* sn_objs holds NIDs in ascending alphabetical order of SN. */
nid = bsearch(sn, sn_objs, NUM_SN, sizeof(unsigned int), sn_objs_cmp);
if (nid != NULL)
return *nid;
return NID_undef;
}
LCRYPTO_ALIAS(OBJ_sn2nid);