summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/objects
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/objects')
-rw-r--r--src/lib/libcrypto/objects/Makefile130
-rw-r--r--src/lib/libcrypto/objects/Makefile.ssl123
-rw-r--r--src/lib/libcrypto/objects/o_names.c47
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c180
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl20
-rw-r--r--src/lib/libcrypto/objects/obj_err.c2
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c35
-rw-r--r--src/lib/libcrypto/objects/obj_mac.num34
-rw-r--r--src/lib/libcrypto/objects/objects.h97
-rw-r--r--src/lib/libcrypto/objects/objects.pl16
-rw-r--r--src/lib/libcrypto/objects/objects.txt44
11 files changed, 398 insertions, 330 deletions
diff --git a/src/lib/libcrypto/objects/Makefile b/src/lib/libcrypto/objects/Makefile
new file mode 100644
index 0000000000..a8aedbd422
--- /dev/null
+++ b/src/lib/libcrypto/objects/Makefile
@@ -0,0 +1,130 @@
1#
2# OpenSSL/crypto/objects/Makefile
3#
4
5DIR= objects
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12PERL= perl
13
14CFLAGS= $(INCLUDES) $(CFLAG)
15
16GENERAL=Makefile README
17TEST=
18APPS=
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC= o_names.c obj_dat.c obj_lib.c obj_err.c obj_xref.c
22LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= objects.h obj_mac.h
27HEADER= $(EXHEADER) obj_dat.h obj_xref.h
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: obj_dat.h obj_xref.h lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41obj_dat.h: obj_dat.pl obj_mac.h
42 $(PERL) obj_dat.pl obj_mac.h obj_dat.h
43
44# objects.pl both reads and writes obj_mac.num
45obj_mac.h: objects.pl objects.txt obj_mac.num
46 $(PERL) objects.pl objects.txt obj_mac.num obj_mac.h
47 @sleep 1; touch obj_mac.h; sleep 1
48
49obj_xref.h: objxref.pl obj_xref.txt obj_mac.num
50 $(PERL) objxref.pl obj_mac.num obj_xref.txt > obj_xref.h
51 @sleep 1; touch obj_xref.h; sleep 1
52
53files:
54 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
55
56links:
57 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
58 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
59 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
60
61install:
62 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
63 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
64 do \
65 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
66 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
67 done;
68
69tags:
70 ctags $(SRC)
71
72tests:
73
74lint:
75 lint -DLINT $(INCLUDES) $(SRC)>fluff
76
77depend:
78 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
79 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
80
81dclean:
82 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
83 mv -f Makefile.new $(MAKEFILE)
84
85clean:
86 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
87
88# DO NOT DELETE THIS LINE -- make depend depends on it.
89
90o_names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
91o_names.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
92o_names.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
93o_names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
94o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95o_names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
96o_names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97o_names.o: o_names.c
98obj_dat.o: ../../e_os.h ../../include/openssl/asn1.h
99obj_dat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
100obj_dat.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
101obj_dat.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102obj_dat.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
103obj_dat.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
104obj_dat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105obj_dat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
106obj_dat.o: ../../include/openssl/symhacks.h ../cryptlib.h obj_dat.c obj_dat.h
107obj_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
108obj_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
109obj_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
110obj_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
111obj_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
112obj_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
113obj_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
114obj_err.o: obj_err.c
115obj_lib.o: ../../e_os.h ../../include/openssl/asn1.h
116obj_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
117obj_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
118obj_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
119obj_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
120obj_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
121obj_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
122obj_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
123obj_lib.o: ../cryptlib.h obj_lib.c
124obj_xref.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
125obj_xref.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
126obj_xref.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
127obj_xref.o: ../../include/openssl/opensslconf.h
128obj_xref.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
129obj_xref.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
130obj_xref.o: ../../include/openssl/symhacks.h obj_xref.c obj_xref.h
diff --git a/src/lib/libcrypto/objects/Makefile.ssl b/src/lib/libcrypto/objects/Makefile.ssl
new file mode 100644
index 0000000000..3e7a194cf9
--- /dev/null
+++ b/src/lib/libcrypto/objects/Makefile.ssl
@@ -0,0 +1,123 @@
1#
2# SSLeay/crypto/objects/Makefile
3#
4
5DIR= objects
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18PERL= perl
19
20CFLAGS= $(INCLUDES) $(CFLAG)
21
22GENERAL=Makefile README
23TEST=
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= o_names.c obj_dat.c obj_lib.c obj_err.c
28LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o
29
30SRC= $(LIBSRC)
31
32EXHEADER= objects.h obj_mac.h
33HEADER= $(EXHEADER) obj_dat.h
34
35ALL= $(GENERAL) $(SRC) $(HEADER)
36
37top:
38 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
39
40all: obj_dat.h lib
41
42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ)
44 $(RANLIB) $(LIB) || echo Never mind.
45 @touch lib
46
47obj_dat.h: obj_dat.pl obj_mac.h
48 $(PERL) obj_dat.pl obj_mac.h obj_dat.h
49
50# objects.pl both reads and writes obj_mac.num
51obj_mac.h: objects.pl objects.txt obj_mac.num
52 $(PERL) objects.pl objects.txt obj_mac.num obj_mac.h
53
54files:
55 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
56
57links:
58 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
59 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
60 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
61 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
62
63install:
64 @for i in $(EXHEADER) ; \
65 do \
66 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
67 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
68 done;
69
70tags:
71 ctags $(SRC)
72
73tests:
74
75lint:
76 lint -DLINT $(INCLUDES) $(SRC)>fluff
77
78depend:
79 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
80
81dclean:
82 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
83 mv -f Makefile.new $(MAKEFILE)
84
85clean:
86 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
87
88# DO NOT DELETE THIS LINE -- make depend depends on it.
89
90o_names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
91o_names.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
92o_names.o: ../../include/openssl/e_os2.h ../../include/openssl/lhash.h
93o_names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
94o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95o_names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
96o_names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97o_names.o: o_names.c
98obj_dat.o: ../../e_os.h ../../include/openssl/asn1.h
99obj_dat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
100obj_dat.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
101obj_dat.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102obj_dat.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
103obj_dat.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
104obj_dat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105obj_dat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
106obj_dat.o: ../../include/openssl/symhacks.h ../cryptlib.h obj_dat.c obj_dat.h
107obj_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
108obj_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
109obj_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
110obj_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
111obj_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
112obj_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
113obj_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
114obj_err.o: ../../include/openssl/symhacks.h obj_err.c
115obj_lib.o: ../../e_os.h ../../include/openssl/asn1.h
116obj_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
117obj_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
118obj_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
119obj_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
120obj_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
121obj_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
122obj_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
123obj_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h obj_lib.c
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index 84380a96a9..adb5731f76 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -22,8 +22,7 @@
22/* I use the ex_data stuff to manage the identifiers for the obj_name_types 22/* I use the ex_data stuff to manage the identifiers for the obj_name_types
23 * that applications may define. I only really use the free function field. 23 * that applications may define. I only really use the free function field.
24 */ 24 */
25DECLARE_LHASH_OF(OBJ_NAME); 25static LHASH *names_lh=NULL;
26static LHASH_OF(OBJ_NAME) *names_lh=NULL;
27static int names_type_num=OBJ_NAME_TYPE_NUM; 26static int names_type_num=OBJ_NAME_TYPE_NUM;
28 27
29typedef struct name_funcs_st 28typedef struct name_funcs_st
@@ -47,14 +46,11 @@ static unsigned long obj_name_hash(const void *a_void);
47/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */ 46/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
48static int obj_name_cmp(const void *a_void,const void *b_void); 47static int obj_name_cmp(const void *a_void,const void *b_void);
49 48
50static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME)
51static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME)
52
53int OBJ_NAME_init(void) 49int OBJ_NAME_init(void)
54 { 50 {
55 if (names_lh != NULL) return(1); 51 if (names_lh != NULL) return(1);
56 MemCheck_off(); 52 MemCheck_off();
57 names_lh=lh_OBJ_NAME_new(); 53 names_lh=lh_new(obj_name_hash, obj_name_cmp);
58 MemCheck_on(); 54 MemCheck_on();
59 return(names_lh != NULL); 55 return(names_lh != NULL);
60 } 56 }
@@ -168,7 +164,7 @@ const char *OBJ_NAME_get(const char *name, int type)
168 164
169 for (;;) 165 for (;;)
170 { 166 {
171 ret=lh_OBJ_NAME_retrieve(names_lh,&on); 167 ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
172 if (ret == NULL) return(NULL); 168 if (ret == NULL) return(NULL);
173 if ((ret->alias) && !alias) 169 if ((ret->alias) && !alias)
174 { 170 {
@@ -204,7 +200,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
204 onp->type=type; 200 onp->type=type;
205 onp->data=data; 201 onp->data=data;
206 202
207 ret=lh_OBJ_NAME_insert(names_lh,onp); 203 ret=(OBJ_NAME *)lh_insert(names_lh,onp);
208 if (ret != NULL) 204 if (ret != NULL)
209 { 205 {
210 /* free things */ 206 /* free things */
@@ -221,7 +217,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
221 } 217 }
222 else 218 else
223 { 219 {
224 if (lh_OBJ_NAME_error(names_lh)) 220 if (lh_error(names_lh))
225 { 221 {
226 /* ERROR */ 222 /* ERROR */
227 return(0); 223 return(0);
@@ -239,7 +235,7 @@ int OBJ_NAME_remove(const char *name, int type)
239 type&= ~OBJ_NAME_ALIAS; 235 type&= ~OBJ_NAME_ALIAS;
240 on.name=name; 236 on.name=name;
241 on.type=type; 237 on.type=type;
242 ret=lh_OBJ_NAME_delete(names_lh,&on); 238 ret=(OBJ_NAME *)lh_delete(names_lh,&on);
243 if (ret != NULL) 239 if (ret != NULL)
244 { 240 {
245 /* free things */ 241 /* free things */
@@ -266,13 +262,13 @@ struct doall
266 void *arg; 262 void *arg;
267 }; 263 };
268 264
269static void do_all_fn_doall_arg(const OBJ_NAME *name,struct doall *d) 265static void do_all_fn(const OBJ_NAME *name,struct doall *d)
270 { 266 {
271 if(name->type == d->type) 267 if(name->type == d->type)
272 d->fn(name,d->arg); 268 d->fn(name,d->arg);
273 } 269 }
274 270
275static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall) 271static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME *, struct doall *)
276 272
277void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg) 273void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
278 { 274 {
@@ -282,8 +278,7 @@ void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
282 d.fn=fn; 278 d.fn=fn;
283 d.arg=arg; 279 d.arg=arg;
284 280
285 lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn), 281 lh_doall_arg(names_lh,LHASH_DOALL_ARG_FN(do_all_fn),&d);
286 struct doall, &d);
287 } 282 }
288 283
289struct doall_sorted 284struct doall_sorted
@@ -318,7 +313,7 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
318 int n; 313 int n;
319 314
320 d.type=type; 315 d.type=type;
321 d.names=OPENSSL_malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names); 316 d.names=OPENSSL_malloc(lh_num_items(names_lh)*sizeof *d.names);
322 d.n=0; 317 d.n=0;
323 OBJ_NAME_do_all(type,do_all_sorted_fn,&d); 318 OBJ_NAME_do_all(type,do_all_sorted_fn,&d);
324 319
@@ -332,16 +327,18 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
332 327
333static int free_type; 328static int free_type;
334 329
335static void names_lh_free_doall(OBJ_NAME *onp) 330static void names_lh_free(OBJ_NAME *onp)
336 { 331{
337 if (onp == NULL) 332 if(onp == NULL)
338 return; 333 return;
339 334
340 if (free_type < 0 || free_type == onp->type) 335 if ((free_type < 0) || (free_type == onp->type))
336 {
341 OBJ_NAME_remove(onp->name,onp->type); 337 OBJ_NAME_remove(onp->name,onp->type);
338 }
342 } 339 }
343 340
344static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME) 341static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME *)
345 342
346static void name_funcs_free(NAME_FUNCS *ptr) 343static void name_funcs_free(NAME_FUNCS *ptr)
347 { 344 {
@@ -355,18 +352,18 @@ void OBJ_NAME_cleanup(int type)
355 if (names_lh == NULL) return; 352 if (names_lh == NULL) return;
356 353
357 free_type=type; 354 free_type=type;
358 down_load=lh_OBJ_NAME_down_load(names_lh); 355 down_load=names_lh->down_load;
359 lh_OBJ_NAME_down_load(names_lh)=0; 356 names_lh->down_load=0;
360 357
361 lh_OBJ_NAME_doall(names_lh,LHASH_DOALL_FN(names_lh_free)); 358 lh_doall(names_lh,LHASH_DOALL_FN(names_lh_free));
362 if (type < 0) 359 if (type < 0)
363 { 360 {
364 lh_OBJ_NAME_free(names_lh); 361 lh_free(names_lh);
365 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free); 362 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free);
366 names_lh=NULL; 363 names_lh=NULL;
367 name_funcs_stack = NULL; 364 name_funcs_stack = NULL;
368 } 365 }
369 else 366 else
370 lh_OBJ_NAME_down_load(names_lh)=down_load; 367 names_lh->down_load=down_load;
371 } 368 }
372 369
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 8a342ba3eb..7fd7433241 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -74,17 +74,16 @@
74#define NUM_SN 0 74#define NUM_SN 0
75#define NUM_LN 0 75#define NUM_LN 0
76#define NUM_OBJ 0 76#define NUM_OBJ 0
77static const unsigned char lvalues[1]; 77static unsigned char lvalues[1];
78static const ASN1_OBJECT nid_objs[1]; 78static ASN1_OBJECT nid_objs[1];
79static const unsigned int sn_objs[1]; 79static ASN1_OBJECT *sn_objs[1];
80static const unsigned int ln_objs[1]; 80static ASN1_OBJECT *ln_objs[1];
81static const unsigned int obj_objs[1]; 81static ASN1_OBJECT *obj_objs[1];
82#endif 82#endif
83 83
84DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); 84static int sn_cmp(const void *a, const void *b);
85DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); 85static int ln_cmp(const void *a, const void *b);
86DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); 86static int obj_cmp(const void *a, const void *b);
87
88#define ADDED_DATA 0 87#define ADDED_DATA 0
89#define ADDED_SNAME 1 88#define ADDED_SNAME 1
90#define ADDED_LNAME 2 89#define ADDED_LNAME 2
@@ -95,27 +94,30 @@ typedef struct added_obj_st
95 int type; 94 int type;
96 ASN1_OBJECT *obj; 95 ASN1_OBJECT *obj;
97 } ADDED_OBJ; 96 } ADDED_OBJ;
98DECLARE_LHASH_OF(ADDED_OBJ);
99 97
100static int new_nid=NUM_NID; 98static int new_nid=NUM_NID;
101static LHASH_OF(ADDED_OBJ) *added=NULL; 99static LHASH *added=NULL;
102
103static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
104 { return(strcmp((*a)->sn,nid_objs[*b].sn)); }
105
106IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
107 100
108static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) 101static int sn_cmp(const void *a, const void *b)
109 { return(strcmp((*a)->ln,nid_objs[*b].ln)); } 102 {
103 const ASN1_OBJECT * const *ap = a, * const *bp = b;
104 return(strcmp((*ap)->sn,(*bp)->sn));
105 }
110 106
111IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); 107static int ln_cmp(const void *a, const void *b)
108 {
109 const ASN1_OBJECT * const *ap = a, * const *bp = b;
110 return(strcmp((*ap)->ln,(*bp)->ln));
111 }
112 112
113static unsigned long added_obj_hash(const ADDED_OBJ *ca) 113/* static unsigned long add_hash(ADDED_OBJ *ca) */
114static unsigned long add_hash(const void *ca_void)
114 { 115 {
115 const ASN1_OBJECT *a; 116 const ASN1_OBJECT *a;
116 int i; 117 int i;
117 unsigned long ret=0; 118 unsigned long ret=0;
118 unsigned char *p; 119 unsigned char *p;
120 const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void;
119 121
120 a=ca->obj; 122 a=ca->obj;
121 switch (ca->type) 123 switch (ca->type)
@@ -143,12 +145,14 @@ static unsigned long added_obj_hash(const ADDED_OBJ *ca)
143 ret|=ca->type<<30L; 145 ret|=ca->type<<30L;
144 return(ret); 146 return(ret);
145 } 147 }
146static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ)
147 148
148static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb) 149/* static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) */
150static int add_cmp(const void *ca_void, const void *cb_void)
149 { 151 {
150 ASN1_OBJECT *a,*b; 152 ASN1_OBJECT *a,*b;
151 int i; 153 int i;
154 const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void;
155 const ADDED_OBJ *cb = (const ADDED_OBJ *)cb_void;
152 156
153 i=ca->type-cb->type; 157 i=ca->type-cb->type;
154 if (i) return(i); 158 if (i) return(i);
@@ -175,16 +179,15 @@ static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
175 return 0; 179 return 0;
176 } 180 }
177 } 181 }
178static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
179 182
180static int init_added(void) 183static int init_added(void)
181 { 184 {
182 if (added != NULL) return(1); 185 if (added != NULL) return(1);
183 added=lh_ADDED_OBJ_new(); 186 added=lh_new(add_hash,add_cmp);
184 return(added != NULL); 187 return(added != NULL);
185 } 188 }
186 189
187static void cleanup1_doall(ADDED_OBJ *a) 190static void cleanup1(ADDED_OBJ *a)
188 { 191 {
189 a->obj->nid=0; 192 a->obj->nid=0;
190 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| 193 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
@@ -192,46 +195,28 @@ static void cleanup1_doall(ADDED_OBJ *a)
192 ASN1_OBJECT_FLAG_DYNAMIC_DATA; 195 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
193 } 196 }
194 197
195static void cleanup2_doall(ADDED_OBJ *a) 198static void cleanup2(ADDED_OBJ *a)
196 { a->obj->nid++; } 199 { a->obj->nid++; }
197 200
198static void cleanup3_doall(ADDED_OBJ *a) 201static void cleanup3(ADDED_OBJ *a)
199 { 202 {
200 if (--a->obj->nid == 0) 203 if (--a->obj->nid == 0)
201 ASN1_OBJECT_free(a->obj); 204 ASN1_OBJECT_free(a->obj);
202 OPENSSL_free(a); 205 OPENSSL_free(a);
203 } 206 }
204 207
205static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ) 208static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *)
206static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ) 209static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *)
207static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ) 210static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *)
208
209/* The purpose of obj_cleanup_defer is to avoid EVP_cleanup() attempting
210 * to use freed up OIDs. If neccessary the actual freeing up of OIDs is
211 * delayed.
212 */
213
214int obj_cleanup_defer = 0;
215
216void check_defer(int nid)
217 {
218 if (!obj_cleanup_defer && nid >= NUM_NID)
219 obj_cleanup_defer = 1;
220 }
221 211
222void OBJ_cleanup(void) 212void OBJ_cleanup(void)
223 { 213 {
224 if (obj_cleanup_defer)
225 {
226 obj_cleanup_defer = 2;
227 return ;
228 }
229 if (added == NULL) return; 214 if (added == NULL) return;
230 lh_ADDED_OBJ_down_load(added) = 0; 215 added->down_load=0;
231 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */ 216 lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */
232 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */ 217 lh_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */
233 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */ 218 lh_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */
234 lh_ADDED_OBJ_free(added); 219 lh_free(added);
235 added=NULL; 220 added=NULL;
236 } 221 }
237 222
@@ -267,7 +252,7 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
267 { 252 {
268 ao[i]->type=i; 253 ao[i]->type=i;
269 ao[i]->obj=o; 254 ao[i]->obj=o;
270 aop=lh_ADDED_OBJ_insert(added,ao[i]); 255 aop=(ADDED_OBJ *)lh_insert(added,ao[i]);
271 /* memory leak, buit should not normally matter */ 256 /* memory leak, buit should not normally matter */
272 if (aop != NULL) 257 if (aop != NULL)
273 OPENSSL_free(aop); 258 OPENSSL_free(aop);
@@ -307,7 +292,7 @@ ASN1_OBJECT *OBJ_nid2obj(int n)
307 ad.type=ADDED_NID; 292 ad.type=ADDED_NID;
308 ad.obj= &ob; 293 ad.obj= &ob;
309 ob.nid=n; 294 ob.nid=n;
310 adp=lh_ADDED_OBJ_retrieve(added,&ad); 295 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
311 if (adp != NULL) 296 if (adp != NULL)
312 return(adp->obj); 297 return(adp->obj);
313 else 298 else
@@ -339,7 +324,7 @@ const char *OBJ_nid2sn(int n)
339 ad.type=ADDED_NID; 324 ad.type=ADDED_NID;
340 ad.obj= &ob; 325 ad.obj= &ob;
341 ob.nid=n; 326 ob.nid=n;
342 adp=lh_ADDED_OBJ_retrieve(added,&ad); 327 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
343 if (adp != NULL) 328 if (adp != NULL)
344 return(adp->obj->sn); 329 return(adp->obj->sn);
345 else 330 else
@@ -371,7 +356,7 @@ const char *OBJ_nid2ln(int n)
371 ad.type=ADDED_NID; 356 ad.type=ADDED_NID;
372 ad.obj= &ob; 357 ad.obj= &ob;
373 ob.nid=n; 358 ob.nid=n;
374 adp=lh_ADDED_OBJ_retrieve(added,&ad); 359 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
375 if (adp != NULL) 360 if (adp != NULL)
376 return(adp->obj->ln); 361 return(adp->obj->ln);
377 else 362 else
@@ -382,22 +367,9 @@ const char *OBJ_nid2ln(int n)
382 } 367 }
383 } 368 }
384 369
385static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
386 {
387 int j;
388 const ASN1_OBJECT *a= *ap;
389 const ASN1_OBJECT *b= &nid_objs[*bp];
390
391 j=(a->length - b->length);
392 if (j) return(j);
393 return(memcmp(a->data,b->data,a->length));
394 }
395
396IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
397
398int OBJ_obj2nid(const ASN1_OBJECT *a) 370int OBJ_obj2nid(const ASN1_OBJECT *a)
399 { 371 {
400 const unsigned int *op; 372 ASN1_OBJECT **op;
401 ADDED_OBJ ad,*adp; 373 ADDED_OBJ ad,*adp;
402 374
403 if (a == NULL) 375 if (a == NULL)
@@ -409,13 +381,14 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
409 { 381 {
410 ad.type=ADDED_DATA; 382 ad.type=ADDED_DATA;
411 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */ 383 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
412 adp=lh_ADDED_OBJ_retrieve(added,&ad); 384 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
413 if (adp != NULL) return (adp->obj->nid); 385 if (adp != NULL) return (adp->obj->nid);
414 } 386 }
415 op=OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ); 387 op=(ASN1_OBJECT **)OBJ_bsearch((const char *)&a,(const char *)obj_objs,
388 NUM_OBJ, sizeof(ASN1_OBJECT *),obj_cmp);
416 if (op == NULL) 389 if (op == NULL)
417 return(NID_undef); 390 return(NID_undef);
418 return(nid_objs[*op].nid); 391 return((*op)->nid);
419 } 392 }
420 393
421/* Convert an object name into an ASN1_OBJECT 394/* Convert an object name into an ASN1_OBJECT
@@ -468,7 +441,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
468 int i,n=0,len,nid, first, use_bn; 441 int i,n=0,len,nid, first, use_bn;
469 BIGNUM *bl; 442 BIGNUM *bl;
470 unsigned long l; 443 unsigned long l;
471 const unsigned char *p; 444 unsigned char *p;
472 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2]; 445 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
473 446
474 if ((a == NULL) || (a->data == NULL)) { 447 if ((a == NULL) || (a->data == NULL)) {
@@ -483,13 +456,10 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
483 s=OBJ_nid2ln(nid); 456 s=OBJ_nid2ln(nid);
484 if (s == NULL) 457 if (s == NULL)
485 s=OBJ_nid2sn(nid); 458 s=OBJ_nid2sn(nid);
486 if (s) 459 if (buf)
487 { 460 BUF_strlcpy(buf,s,buf_len);
488 if (buf) 461 n=strlen(s);
489 BUF_strlcpy(buf,s,buf_len); 462 return n;
490 n=strlen(s);
491 return n;
492 }
493 } 463 }
494 464
495 465
@@ -637,56 +607,62 @@ int OBJ_txt2nid(const char *s)
637 607
638int OBJ_ln2nid(const char *s) 608int OBJ_ln2nid(const char *s)
639 { 609 {
640 ASN1_OBJECT o; 610 ASN1_OBJECT o,*oo= &o,**op;
641 const ASN1_OBJECT *oo= &o;
642 ADDED_OBJ ad,*adp; 611 ADDED_OBJ ad,*adp;
643 const unsigned int *op;
644 612
645 o.ln=s; 613 o.ln=s;
646 if (added != NULL) 614 if (added != NULL)
647 { 615 {
648 ad.type=ADDED_LNAME; 616 ad.type=ADDED_LNAME;
649 ad.obj= &o; 617 ad.obj= &o;
650 adp=lh_ADDED_OBJ_retrieve(added,&ad); 618 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
651 if (adp != NULL) return (adp->obj->nid); 619 if (adp != NULL) return (adp->obj->nid);
652 } 620 }
653 op=OBJ_bsearch_ln(&oo, ln_objs, NUM_LN); 621 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN,
622 sizeof(ASN1_OBJECT *),ln_cmp);
654 if (op == NULL) return(NID_undef); 623 if (op == NULL) return(NID_undef);
655 return(nid_objs[*op].nid); 624 return((*op)->nid);
656 } 625 }
657 626
658int OBJ_sn2nid(const char *s) 627int OBJ_sn2nid(const char *s)
659 { 628 {
660 ASN1_OBJECT o; 629 ASN1_OBJECT o,*oo= &o,**op;
661 const ASN1_OBJECT *oo= &o;
662 ADDED_OBJ ad,*adp; 630 ADDED_OBJ ad,*adp;
663 const unsigned int *op;
664 631
665 o.sn=s; 632 o.sn=s;
666 if (added != NULL) 633 if (added != NULL)
667 { 634 {
668 ad.type=ADDED_SNAME; 635 ad.type=ADDED_SNAME;
669 ad.obj= &o; 636 ad.obj= &o;
670 adp=lh_ADDED_OBJ_retrieve(added,&ad); 637 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
671 if (adp != NULL) return (adp->obj->nid); 638 if (adp != NULL) return (adp->obj->nid);
672 } 639 }
673 op=OBJ_bsearch_sn(&oo, sn_objs, NUM_SN); 640 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
641 sizeof(ASN1_OBJECT *),sn_cmp);
674 if (op == NULL) return(NID_undef); 642 if (op == NULL) return(NID_undef);
675 return(nid_objs[*op].nid); 643 return((*op)->nid);
676 } 644 }
677 645
678const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, 646static int obj_cmp(const void *ap, const void *bp)
679 int (*cmp)(const void *, const void *)) 647 {
648 int j;
649 const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap;
650 const ASN1_OBJECT *b= *(ASN1_OBJECT * const *)bp;
651
652 j=(a->length - b->length);
653 if (j) return(j);
654 return(memcmp(a->data,b->data,a->length));
655 }
656
657const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
658 int (*cmp)(const void *, const void *))
680 { 659 {
681 return OBJ_bsearch_ex_(key, base, num, size, cmp, 0); 660 return OBJ_bsearch_ex(key, base, num, size, cmp, 0);
682 } 661 }
683 662
684const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num, 663const char *OBJ_bsearch_ex(const char *key, const char *base, int num,
685 int size, 664 int size, int (*cmp)(const void *, const void *), int flags)
686 int (*cmp)(const void *, const void *),
687 int flags)
688 { 665 {
689 const char *base=base_;
690 int l,h,i=0,c=0; 666 int l,h,i=0,c=0;
691 const char *p = NULL; 667 const char *p = NULL;
692 668
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
index c67f71c327..7de2f77afd 100644
--- a/src/lib/libcrypto/objects/obj_dat.pl
+++ b/src/lib/libcrypto/objects/obj_dat.pl
@@ -2,7 +2,9 @@
2 2
3# fixes bug in floating point emulation on sparc64 when 3# fixes bug in floating point emulation on sparc64 when
4# this script produces off-by-one output on sparc64 4# this script produces off-by-one output on sparc64
5use integer; 5eval 'use integer;';
6
7print STDERR "Warning: perl module integer not found.\n" if ($@);
6 8
7sub obj_cmp 9sub obj_cmp
8 { 10 {
@@ -148,13 +150,13 @@ for ($i=0; $i<$n; $i++)
148@a=grep(defined($sn{$nid{$_}}),0 .. $n); 150@a=grep(defined($sn{$nid{$_}}),0 .. $n);
149foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a) 151foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a)
150 { 152 {
151 push(@sn,sprintf("%2d,\t/* \"$sn{$nid{$_}}\" */\n",$_)); 153 push(@sn,sprintf("&(nid_objs[%2d]),/* \"$sn{$nid{$_}}\" */\n",$_));
152 } 154 }
153 155
154@a=grep(defined($ln{$nid{$_}}),0 .. $n); 156@a=grep(defined($ln{$nid{$_}}),0 .. $n);
155foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a) 157foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a)
156 { 158 {
157 push(@ln,sprintf("%2d,\t/* \"$ln{$nid{$_}}\" */\n",$_)); 159 push(@ln,sprintf("&(nid_objs[%2d]),/* \"$ln{$nid{$_}}\" */\n",$_));
158 } 160 }
159 161
160@a=grep(defined($obj{$nid{$_}}),0 .. $n); 162@a=grep(defined($obj{$nid{$_}}),0 .. $n);
@@ -164,7 +166,7 @@ foreach (sort obj_cmp @a)
164 $v=$objd{$m}; 166 $v=$objd{$m};
165 $v =~ s/L//g; 167 $v =~ s/L//g;
166 $v =~ s/,/ /g; 168 $v =~ s/,/ /g;
167 push(@ob,sprintf("%2d,\t/* %-32s %s */\n",$_,$m,$v)); 169 push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v));
168 } 170 }
169 171
170print OUT <<'EOF'; 172print OUT <<'EOF';
@@ -239,11 +241,11 @@ printf OUT "#define NUM_SN %d\n",$#sn+1;
239printf OUT "#define NUM_LN %d\n",$#ln+1; 241printf OUT "#define NUM_LN %d\n",$#ln+1;
240printf OUT "#define NUM_OBJ %d\n\n",$#ob+1; 242printf OUT "#define NUM_OBJ %d\n\n",$#ob+1;
241 243
242printf OUT "static const unsigned char lvalues[%d]={\n",$lvalues+1; 244printf OUT "static unsigned char lvalues[%d]={\n",$lvalues+1;
243print OUT @lvalues; 245print OUT @lvalues;
244print OUT "};\n\n"; 246print OUT "};\n\n";
245 247
246printf OUT "static const ASN1_OBJECT nid_objs[NUM_NID]={\n"; 248printf OUT "static ASN1_OBJECT nid_objs[NUM_NID]={\n";
247foreach (@out) 249foreach (@out)
248 { 250 {
249 if (length($_) > 75) 251 if (length($_) > 75)
@@ -267,15 +269,15 @@ foreach (@out)
267 } 269 }
268print OUT "};\n\n"; 270print OUT "};\n\n";
269 271
270printf OUT "static const unsigned int sn_objs[NUM_SN]={\n"; 272printf OUT "static ASN1_OBJECT *sn_objs[NUM_SN]={\n";
271print OUT @sn; 273print OUT @sn;
272print OUT "};\n\n"; 274print OUT "};\n\n";
273 275
274printf OUT "static const unsigned int ln_objs[NUM_LN]={\n"; 276printf OUT "static ASN1_OBJECT *ln_objs[NUM_LN]={\n";
275print OUT @ln; 277print OUT @ln;
276print OUT "};\n\n"; 278print OUT "};\n\n";
277 279
278printf OUT "static const unsigned int obj_objs[NUM_OBJ]={\n"; 280printf OUT "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n";
279print OUT @ob; 281print OUT @ob;
280print OUT "};\n\n"; 282print OUT "};\n\n";
281 283
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
index 2e7a034c3f..12b48850c6 100644
--- a/src/lib/libcrypto/objects/obj_err.c
+++ b/src/lib/libcrypto/objects/obj_err.c
@@ -1,6 +1,6 @@
1/* crypto/objects/obj_err.c */ 1/* crypto/objects/obj_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
index 23e9d48cdf..706fa0b0e7 100644
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -66,8 +66,7 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
66 { 66 {
67 ASN1_OBJECT *r; 67 ASN1_OBJECT *r;
68 int i; 68 int i;
69 char *ln=NULL,*sn=NULL; 69 char *ln=NULL;
70 unsigned char *data=NULL;
71 70
72 if (o == NULL) return(NULL); 71 if (o == NULL) return(NULL);
73 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) 72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
@@ -80,42 +79,42 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); 79 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
81 return(NULL); 80 return(NULL);
82 } 81 }
83 data=OPENSSL_malloc(o->length); 82 r->data=OPENSSL_malloc(o->length);
84 if (data == NULL) 83 if (r->data == NULL)
85 goto err; 84 goto err;
86 if (o->data != NULL) 85 if (o->data != NULL)
87 memcpy(data,o->data,o->length); 86 memcpy(r->data,o->data,o->length);
88 /* once data attached to object it remains const */
89 r->data = data;
90 r->length=o->length; 87 r->length=o->length;
91 r->nid=o->nid; 88 r->nid=o->nid;
92 r->ln=r->sn=NULL; 89 r->ln=r->sn=NULL;
93 if (o->ln != NULL) 90 if (o->ln != NULL)
94 { 91 {
95 i=strlen(o->ln)+1; 92 i=strlen(o->ln)+1;
96 ln=OPENSSL_malloc(i); 93 r->ln=ln=OPENSSL_malloc(i);
97 if (ln == NULL) goto err; 94 if (r->ln == NULL) goto err;
98 memcpy(ln,o->ln,i); 95 memcpy(ln,o->ln,i);
99 r->ln=ln;
100 } 96 }
101 97
102 if (o->sn != NULL) 98 if (o->sn != NULL)
103 { 99 {
100 char *s;
101
104 i=strlen(o->sn)+1; 102 i=strlen(o->sn)+1;
105 sn=OPENSSL_malloc(i); 103 r->sn=s=OPENSSL_malloc(i);
106 if (sn == NULL) goto err; 104 if (r->sn == NULL) goto err;
107 memcpy(sn,o->sn,i); 105 memcpy(s,o->sn,i);
108 r->sn=sn;
109 } 106 }
110 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC| 107 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
111 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA); 108 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
112 return(r); 109 return(r);
113err: 110err:
114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); 111 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
115 if (ln != NULL) OPENSSL_free(ln); 112 if (r != NULL)
116 if (sn != NULL) OPENSSL_free(sn); 113 {
117 if (data != NULL) OPENSSL_free(data); 114 if (ln != NULL) OPENSSL_free(ln);
118 if (r != NULL) OPENSSL_free(r); 115 if (r->data != NULL) OPENSSL_free(r->data);
116 OPENSSL_free(r);
117 }
119 return(NULL); 118 return(NULL);
120 } 119 }
121 120
diff --git a/src/lib/libcrypto/objects/obj_mac.num b/src/lib/libcrypto/objects/obj_mac.num
index 8c50aac27f..e3f56bc52c 100644
--- a/src/lib/libcrypto/objects/obj_mac.num
+++ b/src/lib/libcrypto/objects/obj_mac.num
@@ -856,37 +856,3 @@ hmac 855
856LocalKeySet 856 856LocalKeySet 856
857freshest_crl 857 857freshest_crl 857
858id_on_permanentIdentifier 858 858id_on_permanentIdentifier 858
859searchGuide 859
860businessCategory 860
861postalAddress 861
862postOfficeBox 862
863physicalDeliveryOfficeName 863
864telephoneNumber 864
865telexNumber 865
866teletexTerminalIdentifier 866
867facsimileTelephoneNumber 867
868x121Address 868
869internationaliSDNNumber 869
870registeredAddress 870
871destinationIndicator 871
872preferredDeliveryMethod 872
873presentationAddress 873
874supportedApplicationContext 874
875member 875
876owner 876
877roleOccupant 877
878seeAlso 878
879userPassword 879
880userCertificate 880
881cACertificate 881
882authorityRevocationList 882
883certificateRevocationList 883
884crossCertificatePair 884
885enhancedSearchGuide 885
886protocolInformation 886
887distinguishedName 887
888uniqueMember 888
889houseIdentifier 889
890supportedAlgorithms 890
891deltaRevocationList 891
892dmdName 892
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
index bd0ee52feb..7242f76fb0 100644
--- a/src/lib/libcrypto/objects/objects.h
+++ b/src/lib/libcrypto/objects/objects.h
@@ -1011,91 +1011,10 @@ int OBJ_txt2nid(const char *s);
1011int OBJ_ln2nid(const char *s); 1011int OBJ_ln2nid(const char *s);
1012int OBJ_sn2nid(const char *s); 1012int OBJ_sn2nid(const char *s);
1013int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); 1013int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
1014const void * OBJ_bsearch_(const void *key,const void *base,int num,int size, 1014const char * OBJ_bsearch(const char *key,const char *base,int num,int size,
1015 int (*cmp)(const void *, const void *)); 1015 int (*cmp)(const void *, const void *));
1016const void * OBJ_bsearch_ex_(const void *key,const void *base,int num, 1016const char * OBJ_bsearch_ex(const char *key,const char *base,int num,
1017 int size, 1017 int size, int (*cmp)(const void *, const void *), int flags);
1018 int (*cmp)(const void *, const void *),
1019 int flags);
1020
1021#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \
1022 static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
1023 static int nm##_cmp(type1 const *, type2 const *); \
1024 scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
1025
1026#define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \
1027 _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
1028#define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \
1029 type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
1030
1031/*
1032 * Unsolved problem: if a type is actually a pointer type, like
1033 * nid_triple is, then its impossible to get a const where you need
1034 * it. Consider:
1035 *
1036 * typedef int nid_triple[3];
1037 * const void *a_;
1038 * const nid_triple const *a = a_;
1039 *
1040 * The assignement discards a const because what you really want is:
1041 *
1042 * const int const * const *a = a_;
1043 *
1044 * But if you do that, you lose the fact that a is an array of 3 ints,
1045 * which breaks comparison functions.
1046 *
1047 * Thus we end up having to cast, sadly, or unpack the
1048 * declarations. Or, as I finally did in this case, delcare nid_triple
1049 * to be a struct, which it should have been in the first place.
1050 *
1051 * Ben, August 2008.
1052 *
1053 * Also, strictly speaking not all types need be const, but handling
1054 * the non-constness means a lot of complication, and in practice
1055 * comparison routines do always not touch their arguments.
1056 */
1057
1058#define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \
1059 static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \
1060 { \
1061 type1 const *a = a_; \
1062 type2 const *b = b_; \
1063 return nm##_cmp(a,b); \
1064 } \
1065 static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
1066 { \
1067 return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
1068 nm##_cmp_BSEARCH_CMP_FN); \
1069 } \
1070 extern void dummy_prototype(void)
1071
1072#define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \
1073 static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \
1074 { \
1075 type1 const *a = a_; \
1076 type2 const *b = b_; \
1077 return nm##_cmp(a,b); \
1078 } \
1079 type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
1080 { \
1081 return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
1082 nm##_cmp_BSEARCH_CMP_FN); \
1083 } \
1084 extern void dummy_prototype(void)
1085
1086#define OBJ_bsearch(type1,key,type2,base,num,cmp) \
1087 ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
1088 num,sizeof(type2), \
1089 ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \
1090 (void)CHECKED_PTR_OF(type2,cmp##_type_2), \
1091 cmp##_BSEARCH_CMP_FN)))
1092
1093#define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \
1094 ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
1095 num,sizeof(type2), \
1096 ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \
1097 (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \
1098 cmp##_BSEARCH_CMP_FN)),flags)
1099 1018
1100int OBJ_new_nid(int num); 1019int OBJ_new_nid(int num);
1101int OBJ_add_object(const ASN1_OBJECT *obj); 1020int OBJ_add_object(const ASN1_OBJECT *obj);
@@ -1103,14 +1022,6 @@ int OBJ_create(const char *oid,const char *sn,const char *ln);
1103void OBJ_cleanup(void ); 1022void OBJ_cleanup(void );
1104int OBJ_create_objects(BIO *in); 1023int OBJ_create_objects(BIO *in);
1105 1024
1106int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
1107int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
1108int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
1109void OBJ_sigid_free(void);
1110
1111extern int obj_cleanup_defer;
1112void check_defer(int nid);
1113
1114/* BEGIN ERROR CODES */ 1025/* BEGIN ERROR CODES */
1115/* The following lines are auto generated by the script mkerr.pl. Any changes 1026/* The following lines are auto generated by the script mkerr.pl. Any changes
1116 * made after this point may be overwritten when the script is next run. 1027 * made after this point may be overwritten when the script is next run.
diff --git a/src/lib/libcrypto/objects/objects.pl b/src/lib/libcrypto/objects/objects.pl
index 15c00bbd52..76bb8da677 100644
--- a/src/lib/libcrypto/objects/objects.pl
+++ b/src/lib/libcrypto/objects/objects.pl
@@ -14,8 +14,6 @@ while(<NUMIN>)
14 $Cname =~ s/^X//; 14 $Cname =~ s/^X//;
15 if (defined($nidn{$mynum})) 15 if (defined($nidn{$mynum}))
16 { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; } 16 { die "$ARGV[1]:$o:There's already an object with NID ",$mynum," on line ",$order{$mynum},"\n"; }
17 if (defined($nid{$Cname}))
18 { die "$ARGV[1]:$o:There's already an object with name ",$Cname," on line ",$order{$nid{$Cname}},"\n"; }
19 $nid{$Cname} = $mynum; 17 $nid{$Cname} = $mynum;
20 $nidn{$mynum} = $Cname; 18 $nidn{$mynum} = $Cname;
21 $order{$mynum} = $o; 19 $order{$mynum} = $o;
@@ -104,18 +102,18 @@ while (<IN>)
104 $max_nid++; 102 $max_nid++;
105 $nid{$Cname} = $max_nid; 103 $nid{$Cname} = $max_nid;
106 $nidn{$max_nid} = $Cname; 104 $nidn{$max_nid} = $Cname;
107print STDERR "Added OID $Cname\n";
108 } 105 }
109 $Cname=""; 106 $Cname="";
110 } 107 }
111close IN; 108close IN;
112 109
113open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]"; 110#XXX don't modify input files
114foreach (sort { $a <=> $b } keys %nidn) 111#open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
115 { 112#foreach (sort { $a <=> $b } keys %nidn)
116 print NUMOUT $nidn{$_},"\t\t",$_,"\n"; 113# {
117 } 114# print NUMOUT $nidn{$_},"\t\t",$_,"\n";
118close NUMOUT; 115# }
116#close NUMOUT;
119 117
120open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]"; 118open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
121print OUT <<'EOF'; 119print OUT <<'EOF';
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt
index e61fe60cbf..a6a811b8e7 100644
--- a/src/lib/libcrypto/objects/objects.txt
+++ b/src/lib/libcrypto/objects/objects.txt
@@ -20,7 +20,7 @@ identified-organization 132 : certicom-arc
20joint-iso-itu-t 23 : international-organizations : International Organizations 20joint-iso-itu-t 23 : international-organizations : International Organizations
21 21
22international-organizations 43 : wap 22international-organizations 43 : wap
23wap 1 : wap-wsg 23wap 13 : wap-wsg
24 24
25joint-iso-itu-t 5 1 5 : selected-attribute-types : Selected Attribute Types 25joint-iso-itu-t 5 1 5 : selected-attribute-types : Selected Attribute Types
26 26
@@ -664,52 +664,18 @@ X509 5 : : serialNumber
664X509 6 : C : countryName 664X509 6 : C : countryName
665X509 7 : L : localityName 665X509 7 : L : localityName
666X509 8 : ST : stateOrProvinceName 666X509 8 : ST : stateOrProvinceName
667X509 9 : street : streetAddress 667X509 9 : : streetAddress
668X509 10 : O : organizationName 668X509 10 : O : organizationName
669X509 11 : OU : organizationalUnitName 669X509 11 : OU : organizationalUnitName
670X509 12 : title : title 670X509 12 : : title
671X509 13 : : description 671X509 13 : : description
672X509 14 : : searchGuide 672X509 17 : : postalCode
673X509 15 : : businessCategory
674X509 16 : : postalAddress
675X509 17 : : postalCode
676X509 18 : : postOfficeBox
677X509 19 : : physicalDeliveryOfficeName
678X509 20 : : telephoneNumber
679X509 21 : : telexNumber
680X509 22 : : teletexTerminalIdentifier
681X509 23 : : facsimileTelephoneNumber
682X509 24 : : x121Address
683X509 25 : : internationaliSDNNumber
684X509 26 : : registeredAddress
685X509 27 : : destinationIndicator
686X509 28 : : preferredDeliveryMethod
687X509 29 : : presentationAddress
688X509 30 : : supportedApplicationContext
689X509 31 : member :
690X509 32 : owner :
691X509 33 : : roleOccupant
692X509 34 : seeAlso :
693X509 35 : : userPassword
694X509 36 : : userCertificate
695X509 37 : : cACertificate
696X509 38 : : authorityRevocationList
697X509 39 : : certificateRevocationList
698X509 40 : : crossCertificatePair
699X509 41 : name : name 673X509 41 : name : name
700X509 42 : GN : givenName 674X509 42 : GN : givenName
701X509 43 : initials : initials 675X509 43 : : initials
702X509 44 : : generationQualifier 676X509 44 : : generationQualifier
703X509 45 : : x500UniqueIdentifier 677X509 45 : : x500UniqueIdentifier
704X509 46 : dnQualifier : dnQualifier 678X509 46 : dnQualifier : dnQualifier
705X509 47 : : enhancedSearchGuide
706X509 48 : : protocolInformation
707X509 49 : : distinguishedName
708X509 50 : : uniqueMember
709X509 51 : : houseIdentifier
710X509 52 : : supportedAlgorithms
711X509 53 : : deltaRevocationList
712X509 54 : dmdName :
713X509 65 : : pseudonym 679X509 65 : : pseudonym
714X509 72 : role : role 680X509 72 : role : role
715 681