summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/objects/o_names.c421
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c858
-rw-r--r--src/lib/libcrypto/objects/obj_err.c51
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c116
-rw-r--r--src/lib/libcrypto/objects/obj_xref.c127
-rw-r--r--src/lib/libcrypto/objects/objects.h54
-rw-r--r--src/lib/libssl/src/crypto/objects/o_names.c421
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_dat.c858
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_err.c51
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_lib.c116
-rw-r--r--src/lib/libssl/src/crypto/objects/obj_xref.c127
-rw-r--r--src/lib/libssl/src/crypto/objects/objects.h54
12 files changed, 1628 insertions, 1626 deletions
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index c238a8b266..9ed1de92c9 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -12,15 +12,14 @@
12 * that applications may define. I only really use the free function field. 12 * that applications may define. I only really use the free function field.
13 */ 13 */
14DECLARE_LHASH_OF(OBJ_NAME); 14DECLARE_LHASH_OF(OBJ_NAME);
15static LHASH_OF(OBJ_NAME) *names_lh=NULL; 15static LHASH_OF(OBJ_NAME) *names_lh = NULL;
16static int names_type_num=OBJ_NAME_TYPE_NUM; 16static int names_type_num = OBJ_NAME_TYPE_NUM;
17 17
18typedef struct name_funcs_st 18typedef struct name_funcs_st {
19 {
20 unsigned long (*hash_func)(const char *name); 19 unsigned long (*hash_func)(const char *name);
21 int (*cmp_func)(const char *a,const char *b); 20 int (*cmp_func)(const char *a, const char *b);
22 void (*free_func)(const char *, int, const char *); 21 void (*free_func)(const char *, int, const char *);
23 } NAME_FUNCS; 22} NAME_FUNCS;
24 23
25DECLARE_STACK_OF(NAME_FUNCS) 24DECLARE_STACK_OF(NAME_FUNCS)
26IMPLEMENT_STACK_OF(NAME_FUNCS) 25IMPLEMENT_STACK_OF(NAME_FUNCS)
@@ -34,58 +33,57 @@ static STACK_OF(NAME_FUNCS) *name_funcs_stack;
34/* static unsigned long obj_name_hash(OBJ_NAME *a); */ 33/* static unsigned long obj_name_hash(OBJ_NAME *a); */
35static unsigned long obj_name_hash(const void *a_void); 34static unsigned long obj_name_hash(const void *a_void);
36/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */ 35/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
37static int obj_name_cmp(const void *a_void,const void *b_void); 36static int obj_name_cmp(const void *a_void, const void *b_void);
38 37
39static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME) 38static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME)
40static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME) 39static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME)
41 40
42int OBJ_NAME_init(void) 41int
43 { 42OBJ_NAME_init(void)
44 if (names_lh != NULL) return(1); 43{
44 if (names_lh != NULL)
45 return (1);
45 MemCheck_off(); 46 MemCheck_off();
46 names_lh=lh_OBJ_NAME_new(); 47 names_lh = lh_OBJ_NAME_new();
47 MemCheck_on(); 48 MemCheck_on();
48 return(names_lh != NULL); 49 return (names_lh != NULL);
49 } 50}
50 51
51int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *), 52int
52 int (*cmp_func)(const char *, const char *), 53OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
53 void (*free_func)(const char *, int, const char *)) 54 int (*cmp_func)(const char *, const char *),
54 { 55 void (*free_func)(const char *, int, const char *))
56{
55 int ret; 57 int ret;
56 int i; 58 int i;
57 NAME_FUNCS *name_funcs; 59 NAME_FUNCS *name_funcs;
58 60
59 if (name_funcs_stack == NULL) 61 if (name_funcs_stack == NULL) {
60 {
61 MemCheck_off(); 62 MemCheck_off();
62 name_funcs_stack=sk_NAME_FUNCS_new_null(); 63 name_funcs_stack = sk_NAME_FUNCS_new_null();
63 MemCheck_on(); 64 MemCheck_on();
64 } 65 }
65 if (name_funcs_stack == NULL) 66 if (name_funcs_stack == NULL) {
66 {
67 /* ERROR */ 67 /* ERROR */
68 return(0); 68 return (0);
69 } 69 }
70 ret=names_type_num; 70 ret = names_type_num;
71 names_type_num++; 71 names_type_num++;
72 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++) 72 for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
73 {
74 MemCheck_off(); 73 MemCheck_off();
75 name_funcs = malloc(sizeof(NAME_FUNCS)); 74 name_funcs = malloc(sizeof(NAME_FUNCS));
76 MemCheck_on(); 75 MemCheck_on();
77 if (!name_funcs) 76 if (!name_funcs) {
78 { 77 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
79 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX,ERR_R_MALLOC_FAILURE); 78 return (0);
80 return(0); 79 }
81 }
82 name_funcs->hash_func = lh_strhash; 80 name_funcs->hash_func = lh_strhash;
83 name_funcs->cmp_func = strcmp; 81 name_funcs->cmp_func = strcmp;
84 name_funcs->free_func = NULL; 82 name_funcs->free_func = NULL;
85 MemCheck_off(); 83 MemCheck_off();
86 sk_NAME_FUNCS_push(name_funcs_stack,name_funcs); 84 sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
87 MemCheck_on(); 85 MemCheck_on();
88 } 86 }
89 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret); 87 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
90 if (hash_func != NULL) 88 if (hash_func != NULL)
91 name_funcs->hash_func = hash_func; 89 name_funcs->hash_func = hash_func;
@@ -93,265 +91,266 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
93 name_funcs->cmp_func = cmp_func; 91 name_funcs->cmp_func = cmp_func;
94 if (free_func != NULL) 92 if (free_func != NULL)
95 name_funcs->free_func = free_func; 93 name_funcs->free_func = free_func;
96 return(ret); 94 return (ret);
97 } 95}
98 96
99/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */ 97/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */
100static int obj_name_cmp(const void *a_void, const void *b_void) 98static int
101 { 99obj_name_cmp(const void *a_void, const void *b_void)
100{
102 int ret; 101 int ret;
103 const OBJ_NAME *a = (const OBJ_NAME *)a_void; 102 const OBJ_NAME *a = (const OBJ_NAME *)a_void;
104 const OBJ_NAME *b = (const OBJ_NAME *)b_void; 103 const OBJ_NAME *b = (const OBJ_NAME *)b_void;
105 104
106 ret=a->type-b->type; 105 ret = a->type - b->type;
107 if (ret == 0) 106 if (ret == 0) {
108 { 107 if ((name_funcs_stack != NULL) &&
109 if ((name_funcs_stack != NULL) 108 (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
110 && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) 109 ret = sk_NAME_FUNCS_value(name_funcs_stack,
111 { 110 a->type)->cmp_func(a->name, b->name);
112 ret=sk_NAME_FUNCS_value(name_funcs_stack, 111 } else
113 a->type)->cmp_func(a->name,b->name); 112 ret = strcmp(a->name, b->name);
114 }
115 else
116 ret=strcmp(a->name,b->name);
117 }
118 return(ret);
119 } 113 }
114 return (ret);
115}
120 116
121/* static unsigned long obj_name_hash(OBJ_NAME *a) */ 117/* static unsigned long obj_name_hash(OBJ_NAME *a) */
122static unsigned long obj_name_hash(const void *a_void) 118static unsigned long
123 { 119obj_name_hash(const void *a_void)
120{
124 unsigned long ret; 121 unsigned long ret;
125 const OBJ_NAME *a = (const OBJ_NAME *)a_void; 122 const OBJ_NAME *a = (const OBJ_NAME *)a_void;
126 123
127 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) 124 if ((name_funcs_stack != NULL) &&
128 { 125 (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
129 ret=sk_NAME_FUNCS_value(name_funcs_stack, 126 ret = sk_NAME_FUNCS_value(name_funcs_stack,
130 a->type)->hash_func(a->name); 127 a->type)->hash_func(a->name);
131 } 128 } else {
132 else 129 ret = lh_strhash(a->name);
133 {
134 ret=lh_strhash(a->name);
135 }
136 ret^=a->type;
137 return(ret);
138 } 130 }
139 131 ret ^= a->type;
140const char *OBJ_NAME_get(const char *name, int type) 132 return (ret);
141 { 133}
142 OBJ_NAME on,*ret; 134
143 int num=0,alias; 135const char *
144 136OBJ_NAME_get(const char *name, int type)
145 if (name == NULL) return(NULL); 137{
146 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL); 138 OBJ_NAME on, *ret;
147 139 int num = 0, alias;
148 alias=type&OBJ_NAME_ALIAS; 140
141 if (name == NULL)
142 return (NULL);
143 if ((names_lh == NULL) && !OBJ_NAME_init())
144 return (NULL);
145
146 alias = type&OBJ_NAME_ALIAS;
149 type&= ~OBJ_NAME_ALIAS; 147 type&= ~OBJ_NAME_ALIAS;
150 148
151 on.name=name; 149 on.name = name;
152 on.type=type; 150 on.type = type;
153 151
154 for (;;) 152 for (;;) {
155 { 153 ret = lh_OBJ_NAME_retrieve(names_lh, &on);
156 ret=lh_OBJ_NAME_retrieve(names_lh,&on); 154 if (ret == NULL)
157 if (ret == NULL) return(NULL); 155 return (NULL);
158 if ((ret->alias) && !alias) 156 if ((ret->alias) && !alias) {
159 { 157 if (++num > 10)
160 if (++num > 10) return(NULL); 158 return (NULL);
161 on.name=ret->data; 159 on.name = ret->data;
162 } 160 } else {
163 else 161 return (ret->data);
164 {
165 return(ret->data);
166 }
167 } 162 }
168 } 163 }
164}
169 165
170int OBJ_NAME_add(const char *name, int type, const char *data) 166int
171 { 167OBJ_NAME_add(const char *name, int type, const char *data)
172 OBJ_NAME *onp,*ret; 168{
169 OBJ_NAME *onp, *ret;
173 int alias; 170 int alias;
174 171
175 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0); 172 if ((names_lh == NULL) && !OBJ_NAME_init())
173 return (0);
176 174
177 alias=type&OBJ_NAME_ALIAS; 175 alias = type & OBJ_NAME_ALIAS;
178 type&= ~OBJ_NAME_ALIAS; 176 type &= ~OBJ_NAME_ALIAS;
179 177
180 onp=(OBJ_NAME *)malloc(sizeof(OBJ_NAME)); 178 onp = (OBJ_NAME *)malloc(sizeof(OBJ_NAME));
181 if (onp == NULL) 179 if (onp == NULL) {
182 {
183 /* ERROR */ 180 /* ERROR */
184 return(0); 181 return (0);
185 } 182 }
186 183
187 onp->name=name; 184 onp->name = name;
188 onp->alias=alias; 185 onp->alias = alias;
189 onp->type=type; 186 onp->type = type;
190 onp->data=data; 187 onp->data = data;
191 188
192 ret=lh_OBJ_NAME_insert(names_lh,onp); 189 ret = lh_OBJ_NAME_insert(names_lh, onp);
193 if (ret != NULL) 190 if (ret != NULL) {
194 {
195 /* free things */ 191 /* free things */
196 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) 192 if ((name_funcs_stack != NULL) &&
197 { 193 (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) {
198 /* XXX: I'm not sure I understand why the free 194 /* XXX: I'm not sure I understand why the free
199 * function should get three arguments... 195 * function should get three arguments...
200 * -- Richard Levitte 196 * -- Richard Levitte
201 */ 197 */
202 sk_NAME_FUNCS_value(name_funcs_stack, 198 sk_NAME_FUNCS_value(
203 ret->type)->free_func(ret->name,ret->type,ret->data); 199 name_funcs_stack, ret->type)->free_func(
204 } 200 ret->name, ret->type, ret->data);
205 free(ret);
206 } 201 }
207 else 202 free(ret);
208 { 203 } else {
209 if (lh_OBJ_NAME_error(names_lh)) 204 if (lh_OBJ_NAME_error(names_lh)) {
210 {
211 /* ERROR */ 205 /* ERROR */
212 return(0); 206 return (0);
213 }
214 } 207 }
215 return(1);
216 } 208 }
217 209 return (1);
218int OBJ_NAME_remove(const char *name, int type) 210}
219 { 211
220 OBJ_NAME on,*ret; 212int
221 213OBJ_NAME_remove(const char *name, int type)
222 if (names_lh == NULL) return(0); 214{
223 215 OBJ_NAME on, *ret;
224 type&= ~OBJ_NAME_ALIAS; 216
225 on.name=name; 217 if (names_lh == NULL)
226 on.type=type; 218 return (0);
227 ret=lh_OBJ_NAME_delete(names_lh,&on); 219
228 if (ret != NULL) 220 type &= ~OBJ_NAME_ALIAS;
229 { 221 on.name = name;
222 on.type = type;
223 ret = lh_OBJ_NAME_delete(names_lh, &on);
224 if (ret != NULL) {
230 /* free things */ 225 /* free things */
231 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) 226 if ((name_funcs_stack != NULL) &&
232 { 227 (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) {
233 /* XXX: I'm not sure I understand why the free 228 /* XXX: I'm not sure I understand why the free
234 * function should get three arguments... 229 * function should get three arguments...
235 * -- Richard Levitte 230 * -- Richard Levitte
236 */ 231 */
237 sk_NAME_FUNCS_value(name_funcs_stack, 232 sk_NAME_FUNCS_value(
238 ret->type)->free_func(ret->name,ret->type,ret->data); 233 name_funcs_stack, ret->type)->free_func(
239 } 234 ret->name, ret->type, ret->data);
240 free(ret);
241 return(1);
242 } 235 }
243 else 236 free(ret);
244 return(0); 237 return (1);
245 } 238 } else
239 return (0);
240}
246 241
247struct doall 242struct doall {
248 {
249 int type; 243 int type;
250 void (*fn)(const OBJ_NAME *,void *arg); 244 void (*fn)(const OBJ_NAME *, void *arg);
251 void *arg; 245 void *arg;
252 }; 246};
253 247
254static void do_all_fn_doall_arg(const OBJ_NAME *name,struct doall *d) 248static void
255 { 249do_all_fn_doall_arg(const OBJ_NAME *name, struct doall *d)
256 if(name->type == d->type) 250{
257 d->fn(name,d->arg); 251 if (name->type == d->type)
258 } 252 d->fn(name, d->arg);
253}
259 254
260static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall) 255static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall)
261 256
262void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg) 257void
263 { 258OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg), void *arg)
259{
264 struct doall d; 260 struct doall d;
265 261
266 d.type=type; 262 d.type = type;
267 d.fn=fn; 263 d.fn = fn;
268 d.arg=arg; 264 d.arg = arg;
269 265
270 lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn), 266 lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn),
271 struct doall, &d); 267 struct doall, &d);
272 } 268}
273 269
274struct doall_sorted 270struct doall_sorted {
275 {
276 int type; 271 int type;
277 int n; 272 int n;
278 const OBJ_NAME **names; 273 const OBJ_NAME **names;
279 }; 274};
280 275
281static void do_all_sorted_fn(const OBJ_NAME *name,void *d_) 276static void
282 { 277do_all_sorted_fn(const OBJ_NAME *name, void *d_)
283 struct doall_sorted *d=d_; 278{
279 struct doall_sorted *d = d_;
284 280
285 if(name->type != d->type) 281 if (name->type != d->type)
286 return; 282 return;
287 283
288 d->names[d->n++]=name; 284 d->names[d->n++] = name;
289 } 285}
290 286
291static int do_all_sorted_cmp(const void *n1_,const void *n2_) 287static int
292 { 288do_all_sorted_cmp(const void *n1_, const void *n2_)
293 const OBJ_NAME * const *n1=n1_; 289{
294 const OBJ_NAME * const *n2=n2_; 290 const OBJ_NAME * const *n1 = n1_;
291 const OBJ_NAME * const *n2 = n2_;
295 292
296 return strcmp((*n1)->name,(*n2)->name); 293 return strcmp((*n1)->name, (*n2)->name);
297 } 294}
298 295
299void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), 296void
300 void *arg) 297OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg),
301 { 298 void *arg)
299{
302 struct doall_sorted d; 300 struct doall_sorted d;
303 int n; 301 int n;
304 302
305 d.type=type; 303 d.type = type;
306 d.names=malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names); 304 d.names = malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names);
307 d.n=0; 305 d.n = 0;
308 OBJ_NAME_do_all(type,do_all_sorted_fn,&d); 306 OBJ_NAME_do_all(type, do_all_sorted_fn, &d);
309 307
310 qsort((void *)d.names,d.n,sizeof *d.names,do_all_sorted_cmp); 308 qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp);
311 309
312 for(n=0 ; n < d.n ; ++n) 310 for (n = 0; n < d.n; ++n)
313 fn(d.names[n],arg); 311 fn(d.names[n], arg);
314 312
315 free((void *)d.names); 313 free((void *)d.names);
316 } 314}
317 315
318static int free_type; 316static int free_type;
319 317
320static void names_lh_free_doall(OBJ_NAME *onp) 318static void
321 { 319names_lh_free_doall(OBJ_NAME *onp)
320{
322 if (onp == NULL) 321 if (onp == NULL)
323 return; 322 return;
324 323
325 if (free_type < 0 || free_type == onp->type) 324 if (free_type < 0 || free_type == onp->type)
326 OBJ_NAME_remove(onp->name,onp->type); 325 OBJ_NAME_remove(onp->name, onp->type);
327 } 326}
328 327
329static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME) 328static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME)
330 329
331static void name_funcs_free(NAME_FUNCS *ptr) 330static void
332 { 331name_funcs_free(NAME_FUNCS *ptr)
332{
333 free(ptr); 333 free(ptr);
334 } 334}
335 335
336void OBJ_NAME_cleanup(int type) 336void
337 { 337OBJ_NAME_cleanup(int type)
338{
338 unsigned long down_load; 339 unsigned long down_load;
339 340
340 if (names_lh == NULL) return; 341 if (names_lh == NULL)
342 return;
341 343
342 free_type=type; 344 free_type = type;
343 down_load=lh_OBJ_NAME_down_load(names_lh); 345 down_load = lh_OBJ_NAME_down_load(names_lh);
344 lh_OBJ_NAME_down_load(names_lh)=0; 346 lh_OBJ_NAME_down_load(names_lh) = 0;
345 347
346 lh_OBJ_NAME_doall(names_lh,LHASH_DOALL_FN(names_lh_free)); 348 lh_OBJ_NAME_doall(names_lh, LHASH_DOALL_FN(names_lh_free));
347 if (type < 0) 349 if (type < 0) {
348 {
349 lh_OBJ_NAME_free(names_lh); 350 lh_OBJ_NAME_free(names_lh);
350 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free); 351 sk_NAME_FUNCS_pop_free(name_funcs_stack, name_funcs_free);
351 names_lh=NULL; 352 names_lh = NULL;
352 name_funcs_stack = NULL; 353 name_funcs_stack = NULL;
353 } 354 } else
354 else 355 lh_OBJ_NAME_down_load(names_lh) = down_load;
355 lh_OBJ_NAME_down_load(names_lh)=down_load; 356}
356 }
357
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index cc007f1206..9fa23ae916 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -90,117 +90,134 @@ DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
90#define ADDED_LNAME 2 90#define ADDED_LNAME 2
91#define ADDED_NID 3 91#define ADDED_NID 3
92 92
93typedef struct added_obj_st 93typedef struct added_obj_st {
94 {
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); 97DECLARE_LHASH_OF(ADDED_OBJ);
99 98
100static int new_nid=NUM_NID; 99static int new_nid = NUM_NID;
101static LHASH_OF(ADDED_OBJ) *added=NULL; 100static LHASH_OF(ADDED_OBJ) *added = NULL;
102 101
103static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) 102static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
104 { return(strcmp((*a)->sn,nid_objs[*b].sn)); } 103{
104 return (strcmp((*a)->sn, nid_objs[*b].sn));
105}
105 106
106IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); 107IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
107 108
108static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) 109static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
109 { return(strcmp((*a)->ln,nid_objs[*b].ln)); } 110{
111 return (strcmp((*a)->ln, nid_objs[*b].ln));
112}
110 113
111IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); 114IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
112 115
113static unsigned long added_obj_hash(const ADDED_OBJ *ca) 116static unsigned long
114 { 117added_obj_hash(const ADDED_OBJ *ca)
118{
115 const ASN1_OBJECT *a; 119 const ASN1_OBJECT *a;
116 int i; 120 int i;
117 unsigned long ret=0; 121 unsigned long ret = 0;
118 unsigned char *p; 122 unsigned char *p;
119 123
120 a=ca->obj; 124 a = ca->obj;
121 switch (ca->type) 125 switch (ca->type) {
122 {
123 case ADDED_DATA: 126 case ADDED_DATA:
124 ret=a->length<<20L; 127 ret = a->length << 20L;
125 p=(unsigned char *)a->data; 128 p = (unsigned char *)a->data;
126 for (i=0; i<a->length; i++) 129 for (i = 0; i < a->length; i++)
127 ret^=p[i]<<((i*3)%24); 130 ret ^= p[i] << ((i * 3) % 24);
128 break; 131 break;
129 case ADDED_SNAME: 132 case ADDED_SNAME:
130 ret=lh_strhash(a->sn); 133 ret = lh_strhash(a->sn);
131 break; 134 break;
132 case ADDED_LNAME: 135 case ADDED_LNAME:
133 ret=lh_strhash(a->ln); 136 ret = lh_strhash(a->ln);
134 break; 137 break;
135 case ADDED_NID: 138 case ADDED_NID:
136 ret=a->nid; 139 ret = a->nid;
137 break; 140 break;
138 default: 141 default:
139 /* abort(); */ 142 /* abort(); */
140 return 0; 143 return 0;
141 }
142 ret&=0x3fffffffL;
143 ret|=ca->type<<30L;
144 return(ret);
145 } 144 }
145 ret &= 0x3fffffffL;
146 ret |= ca->type << 30L;
147 return (ret);
148}
146static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ) 149static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ)
147 150
148static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb) 151static int
149 { 152added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
150 ASN1_OBJECT *a,*b; 153{
154 ASN1_OBJECT *a, *b;
151 int i; 155 int i;
152 156
153 i=ca->type-cb->type; 157 i = ca->type - cb->type;
154 if (i) return(i); 158 if (i)
155 a=ca->obj; 159 return (i);
156 b=cb->obj; 160 a = ca->obj;
157 switch (ca->type) 161 b = cb->obj;
158 { 162 switch (ca->type) {
159 case ADDED_DATA: 163 case ADDED_DATA:
160 i=(a->length - b->length); 164 i = (a->length - b->length);
161 if (i) return(i); 165 if (i)
162 return(memcmp(a->data,b->data,(size_t)a->length)); 166 return (i);
167 return (memcmp(a->data, b->data, (size_t)a->length));
163 case ADDED_SNAME: 168 case ADDED_SNAME:
164 if (a->sn == NULL) return(-1); 169 if (a->sn == NULL)
165 else if (b->sn == NULL) return(1); 170 return (-1);
166 else return(strcmp(a->sn,b->sn)); 171 else if (b->sn == NULL)
172 return (1);
173 else
174 return (strcmp(a->sn, b->sn));
167 case ADDED_LNAME: 175 case ADDED_LNAME:
168 if (a->ln == NULL) return(-1); 176 if (a->ln == NULL)
169 else if (b->ln == NULL) return(1); 177 return (-1);
170 else return(strcmp(a->ln,b->ln)); 178 else if (b->ln == NULL)
179 return (1);
180 else
181 return (strcmp(a->ln, b->ln));
171 case ADDED_NID: 182 case ADDED_NID:
172 return(a->nid-b->nid); 183 return (a->nid - b->nid);
173 default: 184 default:
174 /* abort(); */ 185 /* abort(); */
175 return 0; 186 return 0;
176 }
177 } 187 }
188}
178static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ) 189static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
179 190
180static int init_added(void) 191static int
181 { 192init_added(void)
182 if (added != NULL) return(1); 193{
183 added=lh_ADDED_OBJ_new(); 194 if (added != NULL)
184 return(added != NULL); 195 return (1);
185 } 196 added = lh_ADDED_OBJ_new();
197 return (added != NULL);
198}
186 199
187static void cleanup1_doall(ADDED_OBJ *a) 200static void
188 { 201cleanup1_doall(ADDED_OBJ *a)
189 a->obj->nid=0; 202{
190 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| 203 a->obj->nid = 0;
191 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 204 a->obj->flags |= ASN1_OBJECT_FLAG_DYNAMIC |
192 ASN1_OBJECT_FLAG_DYNAMIC_DATA; 205 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
193 } 206 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
207}
194 208
195static void cleanup2_doall(ADDED_OBJ *a) 209static void cleanup2_doall(ADDED_OBJ *a)
196 { a->obj->nid++; } 210{
211 a->obj->nid++;
212}
197 213
198static void cleanup3_doall(ADDED_OBJ *a) 214static void
199 { 215cleanup3_doall(ADDED_OBJ *a)
216{
200 if (--a->obj->nid == 0) 217 if (--a->obj->nid == 0)
201 ASN1_OBJECT_free(a->obj); 218 ASN1_OBJECT_free(a->obj);
202 free(a); 219 free(a);
203 } 220}
204 221
205static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ) 222static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ)
206static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ) 223static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ)
@@ -213,210 +230,213 @@ static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ)
213 230
214int obj_cleanup_defer = 0; 231int obj_cleanup_defer = 0;
215 232
216void check_defer(int nid) 233void
217 { 234check_defer(int nid)
235{
218 if (!obj_cleanup_defer && nid >= NUM_NID) 236 if (!obj_cleanup_defer && nid >= NUM_NID)
219 obj_cleanup_defer = 1; 237 obj_cleanup_defer = 1;
220 } 238}
221 239
222void OBJ_cleanup(void) 240void
223 { 241OBJ_cleanup(void)
224 if (obj_cleanup_defer) 242{
225 { 243 if (obj_cleanup_defer) {
226 obj_cleanup_defer = 2; 244 obj_cleanup_defer = 2;
227 return ; 245 return;
228 } 246 }
229 if (added == NULL) return; 247 if (added == NULL)
248 return;
230 lh_ADDED_OBJ_down_load(added) = 0; 249 lh_ADDED_OBJ_down_load(added) = 0;
231 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */ 250 lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup1)); /* zero counters */
232 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */ 251 lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup2)); /* set counters */
233 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */ 252 lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup3)); /* free objects */
234 lh_ADDED_OBJ_free(added); 253 lh_ADDED_OBJ_free(added);
235 added=NULL; 254 added = NULL;
236 } 255}
237 256
238int OBJ_new_nid(int num) 257int
239 { 258OBJ_new_nid(int num)
259{
240 int i; 260 int i;
241 261
242 i=new_nid; 262 i = new_nid;
243 new_nid+=num; 263 new_nid += num;
244 return(i); 264 return (i);
245 } 265}
246 266
247int OBJ_add_object(const ASN1_OBJECT *obj) 267int
248 { 268OBJ_add_object(const ASN1_OBJECT *obj)
269{
249 ASN1_OBJECT *o; 270 ASN1_OBJECT *o;
250 ADDED_OBJ *ao[4]={NULL,NULL,NULL,NULL},*aop; 271 ADDED_OBJ *ao[4] = {NULL, NULL, NULL, NULL}, *aop;
251 int i; 272 int i;
252 273
253 if (added == NULL) 274 if (added == NULL)
254 if (!init_added()) return(0); 275 if (!init_added())
255 if ((o=OBJ_dup(obj)) == NULL) goto err; 276 return (0);
256 if (!(ao[ADDED_NID]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 277 if ((o = OBJ_dup(obj)) == NULL)
278 goto err;
279 if (!(ao[ADDED_NID] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
280 goto err2;
257 if ((o->length != 0) && (obj->data != NULL)) 281 if ((o->length != 0) && (obj->data != NULL))
258 if (!(ao[ADDED_DATA]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 282 if (!(ao[ADDED_DATA] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
283 goto err2;
259 if (o->sn != NULL) 284 if (o->sn != NULL)
260 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 285 if (!(ao[ADDED_SNAME] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
286 goto err2;
261 if (o->ln != NULL) 287 if (o->ln != NULL)
262 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 288 if (!(ao[ADDED_LNAME] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
263 289 goto err2;
264 for (i=ADDED_DATA; i<=ADDED_NID; i++) 290
265 { 291 for (i = ADDED_DATA; i <= ADDED_NID; i++) {
266 if (ao[i] != NULL) 292 if (ao[i] != NULL) {
267 { 293 ao[i]->type = i;
268 ao[i]->type=i; 294 ao[i]->obj = o;
269 ao[i]->obj=o; 295 aop = lh_ADDED_OBJ_insert(added, ao[i]);
270 aop=lh_ADDED_OBJ_insert(added,ao[i]);
271 /* memory leak, buit should not normally matter */ 296 /* memory leak, buit should not normally matter */
272 if (aop != NULL) 297 if (aop != NULL)
273 free(aop); 298 free(aop);
274 }
275 } 299 }
276 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 300 }
277 ASN1_OBJECT_FLAG_DYNAMIC_DATA); 301 o->flags &= ~(ASN1_OBJECT_FLAG_DYNAMIC |
302 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
303 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
304
305 return (o->nid);
278 306
279 return(o->nid);
280err2: 307err2:
281 OBJerr(OBJ_F_OBJ_ADD_OBJECT,ERR_R_MALLOC_FAILURE); 308 OBJerr(OBJ_F_OBJ_ADD_OBJECT, ERR_R_MALLOC_FAILURE);
282err: 309err:
283 for (i=ADDED_DATA; i<=ADDED_NID; i++) 310 for (i = ADDED_DATA; i <= ADDED_NID; i++)
284 if (ao[i] != NULL) free(ao[i]); 311 if (ao[i] != NULL)
285 if (o != NULL) free(o); 312 free(ao[i]);
286 return(NID_undef); 313 if (o != NULL)
287 } 314 free(o);
315 return (NID_undef);
316}
288 317
289ASN1_OBJECT *OBJ_nid2obj(int n) 318ASN1_OBJECT *
290 { 319OBJ_nid2obj(int n)
291 ADDED_OBJ ad,*adp; 320{
321 ADDED_OBJ ad, *adp;
292 ASN1_OBJECT ob; 322 ASN1_OBJECT ob;
293 323
294 if ((n >= 0) && (n < NUM_NID)) 324 if ((n >= 0) && (n < NUM_NID)) {
295 { 325 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
296 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) 326 OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);
297 { 327 return (NULL);
298 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
299 return(NULL);
300 }
301 return((ASN1_OBJECT *)&(nid_objs[n]));
302 } 328 }
303 else if (added == NULL) 329 return ((ASN1_OBJECT *)&(nid_objs[n]));
304 return(NULL); 330 } else if (added == NULL)
305 else 331 return (NULL);
306 { 332 else {
307 ad.type=ADDED_NID; 333 ad.type = ADDED_NID;
308 ad.obj= &ob; 334 ad.obj = &ob;
309 ob.nid=n; 335 ob.nid = n;
310 adp=lh_ADDED_OBJ_retrieve(added,&ad); 336 adp = lh_ADDED_OBJ_retrieve(added, &ad);
311 if (adp != NULL) 337 if (adp != NULL)
312 return(adp->obj); 338 return (adp->obj);
313 else 339 else {
314 { 340 OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);
315 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID); 341 return (NULL);
316 return(NULL);
317 }
318 } 342 }
319 } 343 }
344}
320 345
321const char *OBJ_nid2sn(int n) 346const char *
322 { 347OBJ_nid2sn(int n)
323 ADDED_OBJ ad,*adp; 348{
349 ADDED_OBJ ad, *adp;
324 ASN1_OBJECT ob; 350 ASN1_OBJECT ob;
325 351
326 if ((n >= 0) && (n < NUM_NID)) 352 if ((n >= 0) && (n < NUM_NID)) {
327 { 353 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
328 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) 354 OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);
329 { 355 return (NULL);
330 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
331 return(NULL);
332 }
333 return(nid_objs[n].sn);
334 } 356 }
335 else if (added == NULL) 357 return (nid_objs[n].sn);
336 return(NULL); 358 } else if (added == NULL)
337 else 359 return (NULL);
338 { 360 else {
339 ad.type=ADDED_NID; 361 ad.type = ADDED_NID;
340 ad.obj= &ob; 362 ad.obj = &ob;
341 ob.nid=n; 363 ob.nid = n;
342 adp=lh_ADDED_OBJ_retrieve(added,&ad); 364 adp = lh_ADDED_OBJ_retrieve(added, &ad);
343 if (adp != NULL) 365 if (adp != NULL)
344 return(adp->obj->sn); 366 return (adp->obj->sn);
345 else 367 else {
346 { 368 OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);
347 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID); 369 return (NULL);
348 return(NULL);
349 }
350 } 370 }
351 } 371 }
372}
352 373
353const char *OBJ_nid2ln(int n) 374const char *
354 { 375OBJ_nid2ln(int n)
355 ADDED_OBJ ad,*adp; 376{
377 ADDED_OBJ ad, *adp;
356 ASN1_OBJECT ob; 378 ASN1_OBJECT ob;
357 379
358 if ((n >= 0) && (n < NUM_NID)) 380 if ((n >= 0) && (n < NUM_NID)) {
359 { 381 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
360 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) 382 OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID);
361 { 383 return (NULL);
362 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
363 return(NULL);
364 }
365 return(nid_objs[n].ln);
366 } 384 }
367 else if (added == NULL) 385 return (nid_objs[n].ln);
368 return(NULL); 386 } else if (added == NULL)
369 else 387 return (NULL);
370 { 388 else {
371 ad.type=ADDED_NID; 389 ad.type = ADDED_NID;
372 ad.obj= &ob; 390 ad.obj = &ob;
373 ob.nid=n; 391 ob.nid = n;
374 adp=lh_ADDED_OBJ_retrieve(added,&ad); 392 adp = lh_ADDED_OBJ_retrieve(added, &ad);
375 if (adp != NULL) 393 if (adp != NULL)
376 return(adp->obj->ln); 394 return (adp->obj->ln);
377 else 395 else {
378 { 396 OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID);
379 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID); 397 return (NULL);
380 return(NULL);
381 }
382 } 398 }
383 } 399 }
400}
384 401
385static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp) 402static int
386 { 403obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
404{
387 int j; 405 int j;
388 const ASN1_OBJECT *a= *ap; 406 const ASN1_OBJECT *a= *ap;
389 const ASN1_OBJECT *b= &nid_objs[*bp]; 407 const ASN1_OBJECT *b = &nid_objs[*bp];
390 408
391 j=(a->length - b->length); 409 j = (a->length - b->length);
392 if (j) return(j); 410 if (j)
393 return(memcmp(a->data,b->data,a->length)); 411 return (j);
394 } 412 return (memcmp(a->data, b->data, a->length));
413}
395 414
396IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); 415IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
397 416
398int OBJ_obj2nid(const ASN1_OBJECT *a) 417int
399 { 418OBJ_obj2nid(const ASN1_OBJECT *a)
419{
400 const unsigned int *op; 420 const unsigned int *op;
401 ADDED_OBJ ad,*adp; 421 ADDED_OBJ ad, *adp;
402 422
403 if (a == NULL) 423 if (a == NULL)
404 return(NID_undef); 424 return (NID_undef);
405 if (a->nid != 0) 425 if (a->nid != 0)
406 return(a->nid); 426 return (a->nid);
407 427
408 if (added != NULL) 428 if (added != NULL) {
409 { 429 ad.type = ADDED_DATA;
410 ad.type=ADDED_DATA;
411 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */ 430 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
412 adp=lh_ADDED_OBJ_retrieve(added,&ad); 431 adp = lh_ADDED_OBJ_retrieve(added, &ad);
413 if (adp != NULL) return (adp->obj->nid); 432 if (adp != NULL)
414 } 433 return (adp->obj->nid);
415 op=OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
416 if (op == NULL)
417 return(NID_undef);
418 return(nid_objs[*op].nid);
419 } 434 }
435 op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
436 if (op == NULL)
437 return (NID_undef);
438 return (nid_objs[*op].nid);
439}
420 440
421/* Convert an object name into an ASN1_OBJECT 441/* Convert an object name into an ASN1_OBJECT
422 * if "noname" is not set then search for short and long names first. 442 * if "noname" is not set then search for short and long names first.
@@ -424,371 +444,351 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
424 * it can be used with any objects, not just registered ones. 444 * it can be used with any objects, not just registered ones.
425 */ 445 */
426 446
427ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) 447ASN1_OBJECT *
428 { 448OBJ_txt2obj(const char *s, int no_name)
449{
429 int nid = NID_undef; 450 int nid = NID_undef;
430 ASN1_OBJECT *op=NULL; 451 ASN1_OBJECT *op = NULL;
431 unsigned char *buf; 452 unsigned char *buf;
432 unsigned char *p; 453 unsigned char *p;
433 const unsigned char *cp; 454 const unsigned char *cp;
434 int i, j; 455 int i, j;
435 456
436 if(!no_name) { 457 if (!no_name) {
437 if( ((nid = OBJ_sn2nid(s)) != NID_undef) || 458 if (((nid = OBJ_sn2nid(s)) != NID_undef) ||
438 ((nid = OBJ_ln2nid(s)) != NID_undef) ) 459 ((nid = OBJ_ln2nid(s)) != NID_undef) )
439 return OBJ_nid2obj(nid); 460 return OBJ_nid2obj(nid);
440 } 461 }
441 462
442 /* Work out size of content octets */ 463 /* Work out size of content octets */
443 i=a2d_ASN1_OBJECT(NULL,0,s,-1); 464 i = a2d_ASN1_OBJECT(NULL, 0, s, -1);
444 if (i <= 0) { 465 if (i <= 0) {
445 /* Don't clear the error */ 466 /* Don't clear the error */
446 /*ERR_clear_error();*/ 467 /*ERR_clear_error();*/
447 return NULL; 468 return NULL;
448 } 469 }
449 /* Work out total size */ 470 /* Work out total size */
450 j = ASN1_object_size(0,i,V_ASN1_OBJECT); 471 j = ASN1_object_size(0, i, V_ASN1_OBJECT);
451 472
452 if((buf=(unsigned char *)malloc(j)) == NULL) return NULL; 473 if ((buf = (unsigned char *)malloc(j)) == NULL)
474 return NULL;
453 475
454 p = buf; 476 p = buf;
455 /* Write out tag+length */ 477 /* Write out tag+length */
456 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); 478 ASN1_put_object(&p, 0, i, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
457 /* Write out contents */ 479 /* Write out contents */
458 a2d_ASN1_OBJECT(p,i,s,-1); 480 a2d_ASN1_OBJECT(p, i, s, -1);
459 481
460 cp=buf; 482 cp = buf;
461 op=d2i_ASN1_OBJECT(NULL,&cp,j); 483 op = d2i_ASN1_OBJECT(NULL, &cp, j);
462 free(buf); 484 free(buf);
463 return op; 485 return op;
464 } 486}
465 487
466int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) 488int
489OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
467{ 490{
468 int i,n=0,len,nid, first, use_bn; 491 int i, n = 0, len, nid, first, use_bn;
469 BIGNUM *bl; 492 BIGNUM *bl;
470 unsigned long l; 493 unsigned long l;
471 const unsigned char *p; 494 const unsigned char *p;
472 char tbuf[DECIMAL_SIZE(l) + 1]; 495 char tbuf[DECIMAL_SIZE(l) + 1];
473 496
474 if ((a == NULL) || (a->data == NULL)) { 497 if ((a == NULL) || (a->data == NULL)) {
475 buf[0]='\0'; 498 buf[0] = '\0';
476 return(0); 499 return (0);
477 } 500 }
478 501
479 502 if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) {
480 if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef)
481 {
482 const char *s; 503 const char *s;
483 s=OBJ_nid2ln(nid); 504 s = OBJ_nid2ln(nid);
484 if (s == NULL) 505 if (s == NULL)
485 s=OBJ_nid2sn(nid); 506 s = OBJ_nid2sn(nid);
486 if (s) 507 if (s) {
487 {
488 if (buf) 508 if (buf)
489 strlcpy(buf,s,buf_len); 509 strlcpy(buf, s, buf_len);
490 n=strlen(s); 510 n = strlen(s);
491 return n; 511 return n;
492 }
493 } 512 }
513 }
494 514
495 515 len = a->length;
496 len=a->length; 516 p = a->data;
497 p=a->data;
498 517
499 first = 1; 518 first = 1;
500 bl = NULL; 519 bl = NULL;
501 520
502 while (len > 0) 521 while (len > 0) {
503 { 522 l = 0;
504 l=0;
505 use_bn = 0; 523 use_bn = 0;
506 for (;;) 524 for (;;) {
507 {
508 unsigned char c = *p++; 525 unsigned char c = *p++;
509 len--; 526 len--;
510 if ((len == 0) && (c & 0x80)) 527 if ((len == 0) && (c & 0x80))
511 goto err; 528 goto err;
512 if (use_bn) 529 if (use_bn) {
513 {
514 if (!BN_add_word(bl, c & 0x7f)) 530 if (!BN_add_word(bl, c & 0x7f))
515 goto err; 531 goto err;
516 } 532 } else
517 else 533 l |= c & 0x7f;
518 l |= c & 0x7f;
519 if (!(c & 0x80)) 534 if (!(c & 0x80))
520 break; 535 break;
521 if (!use_bn && (l > (ULONG_MAX >> 7L))) 536 if (!use_bn && (l > (ULONG_MAX >> 7L))) {
522 {
523 if (!bl && !(bl = BN_new())) 537 if (!bl && !(bl = BN_new()))
524 goto err; 538 goto err;
525 if (!BN_set_word(bl, l)) 539 if (!BN_set_word(bl, l))
526 goto err; 540 goto err;
527 use_bn = 1; 541 use_bn = 1;
528 } 542 }
529 if (use_bn) 543 if (use_bn) {
530 {
531 if (!BN_lshift(bl, bl, 7)) 544 if (!BN_lshift(bl, bl, 7))
532 goto err; 545 goto err;
533 } 546 } else
534 else 547 l <<= 7L;
535 l<<=7L; 548 }
536 }
537 549
538 if (first) 550 if (first) {
539 {
540 first = 0; 551 first = 0;
541 if (l >= 80) 552 if (l >= 80) {
542 {
543 i = 2; 553 i = 2;
544 if (use_bn) 554 if (use_bn) {
545 {
546 if (!BN_sub_word(bl, 80)) 555 if (!BN_sub_word(bl, 80))
547 goto err; 556 goto err;
548 } 557 } else
549 else
550 l -= 80; 558 l -= 80;
551 } 559 } else {
552 else 560 i = (int)(l / 40);
553 { 561 l -= (long)(i * 40);
554 i=(int)(l/40); 562 }
555 l-=(long)(i*40); 563 if (buf && (buf_len > 0)) {
556 }
557 if (buf && (buf_len > 0))
558 {
559 *buf++ = i + '0'; 564 *buf++ = i + '0';
560 buf_len--; 565 buf_len--;
561 }
562 n++;
563 } 566 }
567 n++;
568 }
564 569
565 if (use_bn) 570 if (use_bn) {
566 {
567 char *bndec; 571 char *bndec;
568 bndec = BN_bn2dec(bl); 572 bndec = BN_bn2dec(bl);
569 if (!bndec) 573 if (!bndec)
570 goto err; 574 goto err;
571 i = strlen(bndec); 575 i = strlen(bndec);
572 if (buf) 576 if (buf) {
573 { 577 if (buf_len > 0) {
574 if (buf_len > 0)
575 {
576 *buf++ = '.'; 578 *buf++ = '.';
577 buf_len--; 579 buf_len--;
578 } 580 }
579 strlcpy(buf,bndec,buf_len); 581 strlcpy(buf, bndec, buf_len);
580 if (i > buf_len) 582 if (i > buf_len) {
581 {
582 buf += buf_len; 583 buf += buf_len;
583 buf_len = 0; 584 buf_len = 0;
584 } 585 } else {
585 else 586 buf += i;
586 { 587 buf_len -= i;
587 buf+=i;
588 buf_len-=i;
589 }
590 } 588 }
589 }
591 n++; 590 n++;
592 n += i; 591 n += i;
593 free(bndec); 592 free(bndec);
594 } 593 } else {
595 else 594 snprintf(tbuf, sizeof tbuf, ".%lu", l);
596 { 595 i = strlen(tbuf);
597 snprintf(tbuf,sizeof tbuf,".%lu",l); 596 if (buf && (buf_len > 0)) {
598 i=strlen(tbuf); 597 strlcpy(buf, tbuf, buf_len);
599 if (buf && (buf_len > 0)) 598 if (i > buf_len) {
600 {
601 strlcpy(buf,tbuf,buf_len);
602 if (i > buf_len)
603 {
604 buf += buf_len; 599 buf += buf_len;
605 buf_len = 0; 600 buf_len = 0;
606 } 601 } else {
607 else 602 buf += i;
608 { 603 buf_len -= i;
609 buf+=i;
610 buf_len-=i;
611 }
612 } 604 }
613 n+=i;
614 l=0;
615 } 605 }
606 n += i;
607 l = 0;
616 } 608 }
609 }
617 610
618 if (bl) 611 if (bl)
619 BN_free(bl); 612 BN_free(bl);
620 return n; 613 return n;
621 614
622 err: 615err:
623 if (bl) 616 if (bl)
624 BN_free(bl); 617 BN_free(bl);
625 return -1; 618 return -1;
626} 619}
627 620
628int OBJ_txt2nid(const char *s) 621int
622OBJ_txt2nid(const char *s)
629{ 623{
630 ASN1_OBJECT *obj; 624 ASN1_OBJECT *obj;
631 int nid; 625 int nid;
626
632 obj = OBJ_txt2obj(s, 0); 627 obj = OBJ_txt2obj(s, 0);
633 nid = OBJ_obj2nid(obj); 628 nid = OBJ_obj2nid(obj);
634 ASN1_OBJECT_free(obj); 629 ASN1_OBJECT_free(obj);
635 return nid; 630 return nid;
636} 631}
637 632
638int OBJ_ln2nid(const char *s) 633int
639 { 634OBJ_ln2nid(const char *s)
635{
640 ASN1_OBJECT o; 636 ASN1_OBJECT o;
641 const ASN1_OBJECT *oo= &o; 637 const ASN1_OBJECT *oo = &o;
642 ADDED_OBJ ad,*adp; 638 ADDED_OBJ ad, *adp;
643 const unsigned int *op; 639 const unsigned int *op;
644 640
645 o.ln=s; 641 o.ln = s;
646 if (added != NULL) 642 if (added != NULL) {
647 { 643 ad.type = ADDED_LNAME;
648 ad.type=ADDED_LNAME; 644 ad.obj = &o;
649 ad.obj= &o; 645 adp = lh_ADDED_OBJ_retrieve(added, &ad);
650 adp=lh_ADDED_OBJ_retrieve(added,&ad); 646 if (adp != NULL)
651 if (adp != NULL) return (adp->obj->nid); 647 return (adp->obj->nid);
652 }
653 op=OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
654 if (op == NULL) return(NID_undef);
655 return(nid_objs[*op].nid);
656 } 648 }
649 op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
650 if (op == NULL)
651 return (NID_undef);
652 return (nid_objs[*op].nid);
653}
657 654
658int OBJ_sn2nid(const char *s) 655int
659 { 656OBJ_sn2nid(const char *s)
657{
660 ASN1_OBJECT o; 658 ASN1_OBJECT o;
661 const ASN1_OBJECT *oo= &o; 659 const ASN1_OBJECT *oo = &o;
662 ADDED_OBJ ad,*adp; 660 ADDED_OBJ ad, *adp;
663 const unsigned int *op; 661 const unsigned int *op;
664 662
665 o.sn=s; 663 o.sn = s;
666 if (added != NULL) 664 if (added != NULL) {
667 { 665 ad.type = ADDED_SNAME;
668 ad.type=ADDED_SNAME; 666 ad.obj = &o;
669 ad.obj= &o; 667 adp = lh_ADDED_OBJ_retrieve(added, &ad);
670 adp=lh_ADDED_OBJ_retrieve(added,&ad); 668 if (adp != NULL)
671 if (adp != NULL) return (adp->obj->nid); 669 return (adp->obj->nid);
672 }
673 op=OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
674 if (op == NULL) return(NID_undef);
675 return(nid_objs[*op].nid);
676 } 670 }
671 op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
672 if (op == NULL)
673 return (NID_undef);
674 return (nid_objs[*op].nid);
675}
677 676
678const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, 677const void *
679 int (*cmp)(const void *, const void *)) 678OBJ_bsearch_(const void *key, const void *base, int num, int size,
680 { 679 int (*cmp)(const void *, const void *))
680{
681 return OBJ_bsearch_ex_(key, base, num, size, cmp, 0); 681 return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
682 } 682}
683 683
684const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num, 684const void *
685 int size, 685OBJ_bsearch_ex_(const void *key, const void *base_, int num, int size,
686 int (*cmp)(const void *, const void *), 686 int (*cmp)(const void *, const void *), int flags)
687 int flags) 687{
688 { 688 const char *base = base_;
689 const char *base=base_; 689 int l, h, i = 0, c = 0;
690 int l,h,i=0,c=0;
691 const char *p = NULL; 690 const char *p = NULL;
692 691
693 if (num == 0) return(NULL); 692 if (num == 0)
694 l=0; 693 return (NULL);
695 h=num; 694 l = 0;
696 while (l < h) 695 h = num;
697 { 696 while (l < h) {
698 i=(l+h)/2; 697 i = (l + h) / 2;
699 p= &(base[i*size]); 698 p = &(base[i * size]);
700 c=(*cmp)(key,p); 699 c = (*cmp)(key, p);
701 if (c < 0) 700 if (c < 0)
702 h=i; 701 h = i;
703 else if (c > 0) 702 else if (c > 0)
704 l=i+1; 703 l = i + 1;
705 else 704 else
706 break; 705 break;
707 } 706 }
708 if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)) 707 if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH))
709 p = NULL; 708 p = NULL;
710 else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) 709 else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) {
711 { 710 while (i > 0 && (*cmp)(key, &(base[(i - 1) * size])) == 0)
712 while(i > 0 && (*cmp)(key,&(base[(i-1)*size])) == 0)
713 i--; 711 i--;
714 p = &(base[i*size]); 712 p = &(base[i * size]);
715 }
716 return(p);
717 } 713 }
714 return (p);
715}
718 716
719int OBJ_create_objects(BIO *in) 717int
720 { 718OBJ_create_objects(BIO *in)
719{
721 char buf[512]; 720 char buf[512];
722 int i,num=0; 721 int i, num = 0;
723 char *o,*s,*l=NULL; 722 char *o, *s, *l = NULL;
724 723
725 for (;;) 724 for (;;) {
726 { 725 s = o = NULL;
727 s=o=NULL; 726 i = BIO_gets(in, buf, 512);
728 i=BIO_gets(in,buf,512); 727 if (i <= 0)
729 if (i <= 0) return(num); 728 return (num);
730 buf[i-1]='\0'; 729 buf[i - 1] = '\0';
731 if (!isalnum((unsigned char)buf[0])) return(num); 730 if (!isalnum((unsigned char)buf[0]))
732 o=s=buf; 731 return (num);
732 o = s=buf;
733 while (isdigit((unsigned char)*s) || (*s == '.')) 733 while (isdigit((unsigned char)*s) || (*s == '.'))
734 s++; 734 s++;
735 if (*s != '\0') 735 if (*s != '\0') {
736 { 736 *(s++) = '\0';
737 *(s++)='\0';
738 while (isspace((unsigned char)*s)) 737 while (isspace((unsigned char)*s))
739 s++; 738 s++;
740 if (*s == '\0') 739 if (*s == '\0')
741 s=NULL; 740 s = NULL;
742 else 741 else {
743 { 742 l = s;
744 l=s; 743 while ((*l != '\0') &&
745 while ((*l != '\0') && !isspace((unsigned char)*l)) 744 !isspace((unsigned char)*l))
746 l++; 745 l++;
747 if (*l != '\0') 746 if (*l != '\0') {
748 { 747 *(l++) = '\0';
749 *(l++)='\0';
750 while (isspace((unsigned char)*l)) 748 while (isspace((unsigned char)*l))
751 l++; 749 l++;
752 if (*l == '\0') l=NULL; 750 if (*l == '\0')
753 } 751 l = NULL;
754 else 752 } else
755 l=NULL; 753 l = NULL;
756 }
757 } 754 }
758 else 755 } else
759 s=NULL; 756 s = NULL;
760 if ((o == NULL) || (*o == '\0')) return(num); 757 if ((o == NULL) || (*o == '\0'))
761 if (!OBJ_create(o,s,l)) return(num); 758 return (num);
759 if (!OBJ_create(o, s, l))
760 return (num);
762 num++; 761 num++;
763 }
764 /* return(num); */
765 } 762 }
763 /* return(num); */
764}
766 765
767int OBJ_create(const char *oid, const char *sn, const char *ln) 766int
768 { 767OBJ_create(const char *oid, const char *sn, const char *ln)
769 int ok=0; 768{
770 ASN1_OBJECT *op=NULL; 769 int ok = 0;
770 ASN1_OBJECT *op = NULL;
771 unsigned char *buf; 771 unsigned char *buf;
772 int i; 772 int i;
773 773
774 i=a2d_ASN1_OBJECT(NULL,0,oid,-1); 774 i = a2d_ASN1_OBJECT(NULL, 0, oid, -1);
775 if (i <= 0) return(0); 775 if (i <= 0)
776 return (0);
776 777
777 if ((buf=(unsigned char *)malloc(i)) == NULL) 778 if ((buf = (unsigned char *)malloc(i)) == NULL) {
778 { 779 OBJerr(OBJ_F_OBJ_CREATE, ERR_R_MALLOC_FAILURE);
779 OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE); 780 return (0);
780 return(0); 781 }
781 } 782 i = a2d_ASN1_OBJECT(buf, i, oid, -1);
782 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
783 if (i == 0) 783 if (i == 0)
784 goto err; 784 goto err;
785 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); 785 op = (ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1), buf, i, sn, ln);
786 if (op == NULL) 786 if (op == NULL)
787 goto err; 787 goto err;
788 ok=OBJ_add_object(op); 788 ok = OBJ_add_object(op);
789
789err: 790err:
790 ASN1_OBJECT_free(op); 791 ASN1_OBJECT_free(op);
791 free(buf); 792 free(buf);
792 return(ok); 793 return (ok);
793 } 794}
794
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
index 2e7a034c3f..47597dbfe4 100644
--- a/src/lib/libcrypto/objects/obj_err.c
+++ b/src/lib/libcrypto/objects/obj_err.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -68,35 +68,32 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_OBJ,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_OBJ,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason)
70 70
71static ERR_STRING_DATA OBJ_str_functs[]= 71static ERR_STRING_DATA OBJ_str_functs[] = {
72 { 72 {ERR_FUNC(OBJ_F_OBJ_ADD_OBJECT), "OBJ_add_object"},
73{ERR_FUNC(OBJ_F_OBJ_ADD_OBJECT), "OBJ_add_object"}, 73 {ERR_FUNC(OBJ_F_OBJ_CREATE), "OBJ_create"},
74{ERR_FUNC(OBJ_F_OBJ_CREATE), "OBJ_create"}, 74 {ERR_FUNC(OBJ_F_OBJ_DUP), "OBJ_dup"},
75{ERR_FUNC(OBJ_F_OBJ_DUP), "OBJ_dup"}, 75 {ERR_FUNC(OBJ_F_OBJ_NAME_NEW_INDEX), "OBJ_NAME_new_index"},
76{ERR_FUNC(OBJ_F_OBJ_NAME_NEW_INDEX), "OBJ_NAME_new_index"}, 76 {ERR_FUNC(OBJ_F_OBJ_NID2LN), "OBJ_nid2ln"},
77{ERR_FUNC(OBJ_F_OBJ_NID2LN), "OBJ_nid2ln"}, 77 {ERR_FUNC(OBJ_F_OBJ_NID2OBJ), "OBJ_nid2obj"},
78{ERR_FUNC(OBJ_F_OBJ_NID2OBJ), "OBJ_nid2obj"}, 78 {ERR_FUNC(OBJ_F_OBJ_NID2SN), "OBJ_nid2sn"},
79{ERR_FUNC(OBJ_F_OBJ_NID2SN), "OBJ_nid2sn"}, 79 {0, NULL}
80{0,NULL} 80};
81 };
82 81
83static ERR_STRING_DATA OBJ_str_reasons[]= 82static ERR_STRING_DATA OBJ_str_reasons[] = {
84 { 83 {ERR_REASON(OBJ_R_MALLOC_FAILURE) , "malloc failure"},
85{ERR_REASON(OBJ_R_MALLOC_FAILURE) ,"malloc failure"}, 84 {ERR_REASON(OBJ_R_UNKNOWN_NID) , "unknown nid"},
86{ERR_REASON(OBJ_R_UNKNOWN_NID) ,"unknown nid"}, 85 {0, NULL}
87{0,NULL} 86};
88 };
89 87
90#endif 88#endif
91 89
92void ERR_load_OBJ_strings(void) 90void
93 { 91ERR_load_OBJ_strings(void)
92{
94#ifndef OPENSSL_NO_ERR 93#ifndef OPENSSL_NO_ERR
95 94 if (ERR_func_error_string(OBJ_str_functs[0].error) == NULL) {
96 if (ERR_func_error_string(OBJ_str_functs[0].error) == NULL) 95 ERR_load_strings(0, OBJ_str_functs);
97 { 96 ERR_load_strings(0, OBJ_str_reasons);
98 ERR_load_strings(0,OBJ_str_functs);
99 ERR_load_strings(0,OBJ_str_reasons);
100 }
101#endif
102 } 97 }
98#endif
99}
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
index 338fe851fc..57f0b28cc0 100644
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -62,68 +62,76 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64 64
65ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) 65ASN1_OBJECT *
66 { 66OBJ_dup(const ASN1_OBJECT *o)
67{
67 ASN1_OBJECT *r; 68 ASN1_OBJECT *r;
68 int i; 69 int i;
69 char *ln=NULL,*sn=NULL; 70 char *ln = NULL, *sn = NULL;
70 unsigned char *data=NULL; 71 unsigned char *data = NULL;
71 72
72 if (o == NULL) return(NULL); 73 if (o == NULL)
74 return (NULL);
73 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) 75 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
74 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of 76 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of
75 duplication is this??? */ 77 duplication is this??? */
76 78
77 r=ASN1_OBJECT_new(); 79 r = ASN1_OBJECT_new();
78 if (r == NULL) 80 if (r == NULL) {
79 { 81 OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);
80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); 82 return (NULL);
81 return(NULL); 83 }
82 } 84 data = malloc(o->length);
83 data=malloc(o->length);
84 if (data == NULL) 85 if (data == NULL)
85 goto err; 86 goto err;
86 if (o->data != NULL) 87 if (o->data != NULL)
87 memcpy(data,o->data,o->length); 88 memcpy(data, o->data, o->length);
88 /* once data attached to object it remains const */ 89 /* once data attached to object it remains const */
89 r->data = data; 90 r->data = data;
90 r->length=o->length; 91 r->length = o->length;
91 r->nid=o->nid; 92 r->nid = o->nid;
92 r->ln=r->sn=NULL; 93 r->ln = r->sn = NULL;
93 if (o->ln != NULL) 94 if (o->ln != NULL) {
94 { 95 i = strlen(o->ln) + 1;
95 i=strlen(o->ln)+1; 96 ln = malloc(i);
96 ln=malloc(i); 97 if (ln == NULL)
97 if (ln == NULL) goto err; 98 goto err;
98 memcpy(ln,o->ln,i); 99 memcpy(ln, o->ln, i);
99 r->ln=ln; 100 r->ln = ln;
100 } 101 }
101 102
102 if (o->sn != NULL) 103 if (o->sn != NULL) {
103 { 104 i = strlen(o->sn) + 1;
104 i=strlen(o->sn)+1; 105 sn = malloc(i);
105 sn=malloc(i); 106 if (sn == NULL)
106 if (sn == NULL) goto err; 107 goto err;
107 memcpy(sn,o->sn,i); 108 memcpy(sn, o->sn, i);
108 r->sn=sn; 109 r->sn = sn;
109 }
110 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
111 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
112 return(r);
113err:
114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
115 if (ln != NULL) free(ln);
116 if (sn != NULL) free(sn);
117 if (data != NULL) free(data);
118 if (r != NULL) free(r);
119 return(NULL);
120 } 110 }
111 r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |
112 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | ASN1_OBJECT_FLAG_DYNAMIC_DATA);
113 return (r);
121 114
122int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b) 115err:
123 { 116 OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);
117 if (ln != NULL)
118 free(ln);
119 if (sn != NULL)
120 free(sn);
121 if (data != NULL)
122 free(data);
123 if (r != NULL)
124 free(r);
125 return (NULL);
126}
127
128int
129OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
130{
124 int ret; 131 int ret;
125 132
126 ret=(a->length-b->length); 133 ret = (a->length - b->length);
127 if (ret) return(ret); 134 if (ret)
128 return(memcmp(a->data,b->data,a->length)); 135 return (ret);
129 } 136 return (memcmp(a->data, b->data, a->length));
137}
diff --git a/src/lib/libcrypto/objects/obj_xref.c b/src/lib/libcrypto/objects/obj_xref.c
index 797adc8d10..25aed74ff1 100644
--- a/src/lib/libcrypto/objects/obj_xref.c
+++ b/src/lib/libcrypto/objects/obj_xref.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -62,51 +62,54 @@
62DECLARE_STACK_OF(nid_triple) 62DECLARE_STACK_OF(nid_triple)
63STACK_OF(nid_triple) *sig_app, *sigx_app; 63STACK_OF(nid_triple) *sig_app, *sigx_app;
64 64
65static int sig_cmp(const nid_triple *a, const nid_triple *b) 65static int
66 { 66sig_cmp(const nid_triple *a, const nid_triple *b)
67{
67 return a->sign_id - b->sign_id; 68 return a->sign_id - b->sign_id;
68 } 69}
69 70
70DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig); 71DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig);
71IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig); 72IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig);
72 73
73static int sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b) 74static int
74 { 75sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b)
76{
75 return (*a)->sign_id - (*b)->sign_id; 77 return (*a)->sign_id - (*b)->sign_id;
76 } 78}
77 79
78DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx); 80DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx);
79 81
80static int sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) 82static int
81 { 83sigx_cmp(const nid_triple * const *a, const nid_triple * const *b)
84{
82 int ret; 85 int ret;
86
83 ret = (*a)->hash_id - (*b)->hash_id; 87 ret = (*a)->hash_id - (*b)->hash_id;
84 if (ret) 88 if (ret)
85 return ret; 89 return ret;
86 return (*a)->pkey_id - (*b)->pkey_id; 90 return (*a)->pkey_id - (*b)->pkey_id;
87 } 91}
88 92
89IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx); 93IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx);
90 94
91int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid) 95int
92 { 96OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
97{
93 nid_triple tmp; 98 nid_triple tmp;
94 const nid_triple *rv = NULL; 99 const nid_triple *rv = NULL;
95 tmp.sign_id = signid; 100 tmp.sign_id = signid;
96 101
97 if (sig_app) 102 if (sig_app) {
98 {
99 int idx = sk_nid_triple_find(sig_app, &tmp); 103 int idx = sk_nid_triple_find(sig_app, &tmp);
100 if (idx >= 0) 104 if (idx >= 0)
101 rv = sk_nid_triple_value(sig_app, idx); 105 rv = sk_nid_triple_value(sig_app, idx);
102 } 106 }
103 107
104#ifndef OBJ_XREF_TEST2 108#ifndef OBJ_XREF_TEST2
105 if (rv == NULL) 109 if (rv == NULL) {
106 {
107 rv = OBJ_bsearch_sig(&tmp, sigoid_srt, 110 rv = OBJ_bsearch_sig(&tmp, sigoid_srt,
108 sizeof(sigoid_srt) / sizeof(nid_triple)); 111 sizeof(sigoid_srt) / sizeof(nid_triple));
109 } 112 }
110#endif 113#endif
111 if (rv == NULL) 114 if (rv == NULL)
112 return 0; 115 return 0;
@@ -115,45 +118,44 @@ int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
115 if (ppkey_nid) 118 if (ppkey_nid)
116 *ppkey_nid = rv->pkey_id; 119 *ppkey_nid = rv->pkey_id;
117 return 1; 120 return 1;
118 } 121}
119 122
120int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid) 123int
121 { 124OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
125{
122 nid_triple tmp; 126 nid_triple tmp;
123 const nid_triple *t=&tmp; 127 const nid_triple *t = &tmp;
124 const nid_triple **rv = NULL; 128 const nid_triple **rv = NULL;
125 129
126 tmp.hash_id = dig_nid; 130 tmp.hash_id = dig_nid;
127 tmp.pkey_id = pkey_nid; 131 tmp.pkey_id = pkey_nid;
128 132
129 if (sigx_app) 133 if (sigx_app) {
130 {
131 int idx = sk_nid_triple_find(sigx_app, &tmp); 134 int idx = sk_nid_triple_find(sigx_app, &tmp);
132 if (idx >= 0) 135 if (idx >= 0) {
133 {
134 t = sk_nid_triple_value(sigx_app, idx); 136 t = sk_nid_triple_value(sigx_app, idx);
135 rv = &t; 137 rv = &t;
136 }
137 } 138 }
139 }
138 140
139#ifndef OBJ_XREF_TEST2 141#ifndef OBJ_XREF_TEST2
140 if (rv == NULL) 142 if (rv == NULL) {
141 {
142 rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, 143 rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref,
143 sizeof(sigoid_srt_xref) / sizeof(nid_triple *) 144 sizeof(sigoid_srt_xref) / sizeof(nid_triple *));
144 ); 145 }
145 }
146#endif 146#endif
147 if (rv == NULL) 147 if (rv == NULL)
148 return 0; 148 return 0;
149 if (psignid) 149 if (psignid)
150 *psignid = (*rv)->sign_id; 150 *psignid = (*rv)->sign_id;
151 return 1; 151 return 1;
152 } 152}
153 153
154int OBJ_add_sigid(int signid, int dig_id, int pkey_id) 154int
155 { 155OBJ_add_sigid(int signid, int dig_id, int pkey_id)
156{
156 nid_triple *ntr; 157 nid_triple *ntr;
158
157 if (!sig_app) 159 if (!sig_app)
158 sig_app = sk_nid_triple_new(sig_sk_cmp); 160 sig_app = sk_nid_triple_new(sig_sk_cmp);
159 if (!sig_app) 161 if (!sig_app)
@@ -169,11 +171,10 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
169 ntr->hash_id = dig_id; 171 ntr->hash_id = dig_id;
170 ntr->pkey_id = pkey_id; 172 ntr->pkey_id = pkey_id;
171 173
172 if (!sk_nid_triple_push(sig_app, ntr)) 174 if (!sk_nid_triple_push(sig_app, ntr)) {
173 {
174 free(ntr); 175 free(ntr);
175 return 0; 176 return 0;
176 } 177 }
177 178
178 if (!sk_nid_triple_push(sigx_app, ntr)) 179 if (!sk_nid_triple_push(sigx_app, ntr))
179 return 0; 180 return 0;
@@ -182,53 +183,51 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
182 sk_nid_triple_sort(sigx_app); 183 sk_nid_triple_sort(sigx_app);
183 184
184 return 1; 185 return 1;
185 } 186}
186 187
187static void sid_free(nid_triple *tt) 188static void
188 { 189sid_free(nid_triple *tt)
190{
189 free(tt); 191 free(tt);
190 } 192}
191 193
192void OBJ_sigid_free(void) 194void
193 { 195OBJ_sigid_free(void)
194 if (sig_app) 196{
195 { 197 if (sig_app) {
196 sk_nid_triple_pop_free(sig_app, sid_free); 198 sk_nid_triple_pop_free(sig_app, sid_free);
197 sig_app = NULL; 199 sig_app = NULL;
198 } 200 }
199 if (sigx_app) 201 if (sigx_app) {
200 {
201 sk_nid_triple_free(sigx_app); 202 sk_nid_triple_free(sigx_app);
202 sigx_app = NULL; 203 sigx_app = NULL;
203 }
204 } 204 }
205 205}
206
206#ifdef OBJ_XREF_TEST 207#ifdef OBJ_XREF_TEST
207 208
208main() 209main()
209 { 210{
210 int n1, n2, n3; 211 int n1, n2, n3;
211 212
212 int i, rv; 213 int i, rv;
213#ifdef OBJ_XREF_TEST2 214#ifdef OBJ_XREF_TEST2
214 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) 215 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) {
215 {
216 OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1], 216 OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1],
217 sigoid_srt[i][2]); 217 sigoid_srt[i][2]);
218 } 218 }
219#endif 219#endif
220 220
221 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) 221 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) {
222 {
223 n1 = sigoid_srt[i][0]; 222 n1 = sigoid_srt[i][0];
224 rv = OBJ_find_sigid_algs(n1, &n2, &n3); 223 rv = OBJ_find_sigid_algs(n1, &n2, &n3);
225 printf("Forward: %d, %s %s %s\n", rv, 224 printf("Forward: %d, %s %s %s\n", rv,
226 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3)); 225 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
227 n1=0; 226 n1 = 0;
228 rv = OBJ_find_sigid_by_algs(&n1, n2, n3); 227 rv = OBJ_find_sigid_by_algs(&n1, n2, n3);
229 printf("Reverse: %d, %s %s %s\n", rv, 228 printf("Reverse: %d, %s %s %s\n", rv,
230 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3)); 229 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
231 }
232 } 230 }
233 231}
232
234#endif 233#endif
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
index bd0ee52feb..fa84b67182 100644
--- a/src/lib/libcrypto/objects/objects.h
+++ b/src/lib/libcrypto/objects/objects.h
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -387,7 +387,7 @@
387#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" 387#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
388#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" 388#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
389#define NID_pbeWithSHA1AndRC2_CBC 68 389#define NID_pbeWithSHA1AndRC2_CBC 68
390#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L 390#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
391 391
392/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now 392/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
393 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something 393 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
@@ -395,7 +395,7 @@
395 */ 395 */
396#define LN_id_pbkdf2 "PBKDF2" 396#define LN_id_pbkdf2 "PBKDF2"
397#define NID_id_pbkdf2 69 397#define NID_id_pbkdf2 69
398#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L 398#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
399 399
400#define SN_dsaWithSHA1_2 "DSA-SHA1-old" 400#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
401#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" 401#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
@@ -976,29 +976,28 @@
976extern "C" { 976extern "C" {
977#endif 977#endif
978 978
979typedef struct obj_name_st 979typedef struct obj_name_st {
980 {
981 int type; 980 int type;
982 int alias; 981 int alias;
983 const char *name; 982 const char *name;
984 const char *data; 983 const char *data;
985 } OBJ_NAME; 984} OBJ_NAME;
986 985
987#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) 986#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
988 987
989 988
990int OBJ_NAME_init(void); 989int OBJ_NAME_init(void);
991int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *), 990int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
992 int (*cmp_func)(const char *, const char *), 991 int (*cmp_func)(const char *, const char *),
993 void (*free_func)(const char *, int, const char *)); 992 void (*free_func)(const char *, int, const char *));
994const char *OBJ_NAME_get(const char *name,int type); 993const char *OBJ_NAME_get(const char *name, int type);
995int OBJ_NAME_add(const char *name,int type,const char *data); 994int OBJ_NAME_add(const char *name, int type, const char *data);
996int OBJ_NAME_remove(const char *name,int type); 995int OBJ_NAME_remove(const char *name, int type);
997void OBJ_NAME_cleanup(int type); /* -1 for everything */ 996void OBJ_NAME_cleanup(int type); /* -1 for everything */
998void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg), 997void OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg),
999 void *arg); 998 void *arg);
1000void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), 999void OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg),
1001 void *arg); 1000 void *arg);
1002 1001
1003ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o); 1002ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
1004ASN1_OBJECT * OBJ_nid2obj(int n); 1003ASN1_OBJECT * OBJ_nid2obj(int n);
@@ -1010,13 +1009,12 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
1010int OBJ_txt2nid(const char *s); 1009int OBJ_txt2nid(const char *s);
1011int OBJ_ln2nid(const char *s); 1010int OBJ_ln2nid(const char *s);
1012int OBJ_sn2nid(const char *s); 1011int OBJ_sn2nid(const char *s);
1013int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); 1012int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
1014const void * OBJ_bsearch_(const void *key,const void *base,int num,int size, 1013const void * OBJ_bsearch_(const void *key, const void *base, int num,
1015 int (*cmp)(const void *, const void *)); 1014 int size, int (*cmp)(const void *, const void *));
1016const void * OBJ_bsearch_ex_(const void *key,const void *base,int num, 1015const void * OBJ_bsearch_ex_(const void *key, const void *base, int num,
1017 int size, 1016 int size, int (*cmp)(const void *, const void *),
1018 int (*cmp)(const void *, const void *), 1017 int flags);
1019 int flags);
1020 1018
1021#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ 1019#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \
1022 static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ 1020 static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
@@ -1099,7 +1097,7 @@ const void * OBJ_bsearch_ex_(const void *key,const void *base,int num,
1099 1097
1100int OBJ_new_nid(int num); 1098int OBJ_new_nid(int num);
1101int OBJ_add_object(const ASN1_OBJECT *obj); 1099int OBJ_add_object(const ASN1_OBJECT *obj);
1102int OBJ_create(const char *oid,const char *sn,const char *ln); 1100int OBJ_create(const char *oid, const char *sn, const char *ln);
1103void OBJ_cleanup(void ); 1101void OBJ_cleanup(void );
1104int OBJ_create_objects(BIO *in); 1102int OBJ_create_objects(BIO *in);
1105 1103
diff --git a/src/lib/libssl/src/crypto/objects/o_names.c b/src/lib/libssl/src/crypto/objects/o_names.c
index c238a8b266..9ed1de92c9 100644
--- a/src/lib/libssl/src/crypto/objects/o_names.c
+++ b/src/lib/libssl/src/crypto/objects/o_names.c
@@ -12,15 +12,14 @@
12 * that applications may define. I only really use the free function field. 12 * that applications may define. I only really use the free function field.
13 */ 13 */
14DECLARE_LHASH_OF(OBJ_NAME); 14DECLARE_LHASH_OF(OBJ_NAME);
15static LHASH_OF(OBJ_NAME) *names_lh=NULL; 15static LHASH_OF(OBJ_NAME) *names_lh = NULL;
16static int names_type_num=OBJ_NAME_TYPE_NUM; 16static int names_type_num = OBJ_NAME_TYPE_NUM;
17 17
18typedef struct name_funcs_st 18typedef struct name_funcs_st {
19 {
20 unsigned long (*hash_func)(const char *name); 19 unsigned long (*hash_func)(const char *name);
21 int (*cmp_func)(const char *a,const char *b); 20 int (*cmp_func)(const char *a, const char *b);
22 void (*free_func)(const char *, int, const char *); 21 void (*free_func)(const char *, int, const char *);
23 } NAME_FUNCS; 22} NAME_FUNCS;
24 23
25DECLARE_STACK_OF(NAME_FUNCS) 24DECLARE_STACK_OF(NAME_FUNCS)
26IMPLEMENT_STACK_OF(NAME_FUNCS) 25IMPLEMENT_STACK_OF(NAME_FUNCS)
@@ -34,58 +33,57 @@ static STACK_OF(NAME_FUNCS) *name_funcs_stack;
34/* static unsigned long obj_name_hash(OBJ_NAME *a); */ 33/* static unsigned long obj_name_hash(OBJ_NAME *a); */
35static unsigned long obj_name_hash(const void *a_void); 34static unsigned long obj_name_hash(const void *a_void);
36/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */ 35/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
37static int obj_name_cmp(const void *a_void,const void *b_void); 36static int obj_name_cmp(const void *a_void, const void *b_void);
38 37
39static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME) 38static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME)
40static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME) 39static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME)
41 40
42int OBJ_NAME_init(void) 41int
43 { 42OBJ_NAME_init(void)
44 if (names_lh != NULL) return(1); 43{
44 if (names_lh != NULL)
45 return (1);
45 MemCheck_off(); 46 MemCheck_off();
46 names_lh=lh_OBJ_NAME_new(); 47 names_lh = lh_OBJ_NAME_new();
47 MemCheck_on(); 48 MemCheck_on();
48 return(names_lh != NULL); 49 return (names_lh != NULL);
49 } 50}
50 51
51int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *), 52int
52 int (*cmp_func)(const char *, const char *), 53OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
53 void (*free_func)(const char *, int, const char *)) 54 int (*cmp_func)(const char *, const char *),
54 { 55 void (*free_func)(const char *, int, const char *))
56{
55 int ret; 57 int ret;
56 int i; 58 int i;
57 NAME_FUNCS *name_funcs; 59 NAME_FUNCS *name_funcs;
58 60
59 if (name_funcs_stack == NULL) 61 if (name_funcs_stack == NULL) {
60 {
61 MemCheck_off(); 62 MemCheck_off();
62 name_funcs_stack=sk_NAME_FUNCS_new_null(); 63 name_funcs_stack = sk_NAME_FUNCS_new_null();
63 MemCheck_on(); 64 MemCheck_on();
64 } 65 }
65 if (name_funcs_stack == NULL) 66 if (name_funcs_stack == NULL) {
66 {
67 /* ERROR */ 67 /* ERROR */
68 return(0); 68 return (0);
69 } 69 }
70 ret=names_type_num; 70 ret = names_type_num;
71 names_type_num++; 71 names_type_num++;
72 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++) 72 for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
73 {
74 MemCheck_off(); 73 MemCheck_off();
75 name_funcs = malloc(sizeof(NAME_FUNCS)); 74 name_funcs = malloc(sizeof(NAME_FUNCS));
76 MemCheck_on(); 75 MemCheck_on();
77 if (!name_funcs) 76 if (!name_funcs) {
78 { 77 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
79 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX,ERR_R_MALLOC_FAILURE); 78 return (0);
80 return(0); 79 }
81 }
82 name_funcs->hash_func = lh_strhash; 80 name_funcs->hash_func = lh_strhash;
83 name_funcs->cmp_func = strcmp; 81 name_funcs->cmp_func = strcmp;
84 name_funcs->free_func = NULL; 82 name_funcs->free_func = NULL;
85 MemCheck_off(); 83 MemCheck_off();
86 sk_NAME_FUNCS_push(name_funcs_stack,name_funcs); 84 sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
87 MemCheck_on(); 85 MemCheck_on();
88 } 86 }
89 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret); 87 name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
90 if (hash_func != NULL) 88 if (hash_func != NULL)
91 name_funcs->hash_func = hash_func; 89 name_funcs->hash_func = hash_func;
@@ -93,265 +91,266 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
93 name_funcs->cmp_func = cmp_func; 91 name_funcs->cmp_func = cmp_func;
94 if (free_func != NULL) 92 if (free_func != NULL)
95 name_funcs->free_func = free_func; 93 name_funcs->free_func = free_func;
96 return(ret); 94 return (ret);
97 } 95}
98 96
99/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */ 97/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */
100static int obj_name_cmp(const void *a_void, const void *b_void) 98static int
101 { 99obj_name_cmp(const void *a_void, const void *b_void)
100{
102 int ret; 101 int ret;
103 const OBJ_NAME *a = (const OBJ_NAME *)a_void; 102 const OBJ_NAME *a = (const OBJ_NAME *)a_void;
104 const OBJ_NAME *b = (const OBJ_NAME *)b_void; 103 const OBJ_NAME *b = (const OBJ_NAME *)b_void;
105 104
106 ret=a->type-b->type; 105 ret = a->type - b->type;
107 if (ret == 0) 106 if (ret == 0) {
108 { 107 if ((name_funcs_stack != NULL) &&
109 if ((name_funcs_stack != NULL) 108 (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
110 && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) 109 ret = sk_NAME_FUNCS_value(name_funcs_stack,
111 { 110 a->type)->cmp_func(a->name, b->name);
112 ret=sk_NAME_FUNCS_value(name_funcs_stack, 111 } else
113 a->type)->cmp_func(a->name,b->name); 112 ret = strcmp(a->name, b->name);
114 }
115 else
116 ret=strcmp(a->name,b->name);
117 }
118 return(ret);
119 } 113 }
114 return (ret);
115}
120 116
121/* static unsigned long obj_name_hash(OBJ_NAME *a) */ 117/* static unsigned long obj_name_hash(OBJ_NAME *a) */
122static unsigned long obj_name_hash(const void *a_void) 118static unsigned long
123 { 119obj_name_hash(const void *a_void)
120{
124 unsigned long ret; 121 unsigned long ret;
125 const OBJ_NAME *a = (const OBJ_NAME *)a_void; 122 const OBJ_NAME *a = (const OBJ_NAME *)a_void;
126 123
127 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) 124 if ((name_funcs_stack != NULL) &&
128 { 125 (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
129 ret=sk_NAME_FUNCS_value(name_funcs_stack, 126 ret = sk_NAME_FUNCS_value(name_funcs_stack,
130 a->type)->hash_func(a->name); 127 a->type)->hash_func(a->name);
131 } 128 } else {
132 else 129 ret = lh_strhash(a->name);
133 {
134 ret=lh_strhash(a->name);
135 }
136 ret^=a->type;
137 return(ret);
138 } 130 }
139 131 ret ^= a->type;
140const char *OBJ_NAME_get(const char *name, int type) 132 return (ret);
141 { 133}
142 OBJ_NAME on,*ret; 134
143 int num=0,alias; 135const char *
144 136OBJ_NAME_get(const char *name, int type)
145 if (name == NULL) return(NULL); 137{
146 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL); 138 OBJ_NAME on, *ret;
147 139 int num = 0, alias;
148 alias=type&OBJ_NAME_ALIAS; 140
141 if (name == NULL)
142 return (NULL);
143 if ((names_lh == NULL) && !OBJ_NAME_init())
144 return (NULL);
145
146 alias = type&OBJ_NAME_ALIAS;
149 type&= ~OBJ_NAME_ALIAS; 147 type&= ~OBJ_NAME_ALIAS;
150 148
151 on.name=name; 149 on.name = name;
152 on.type=type; 150 on.type = type;
153 151
154 for (;;) 152 for (;;) {
155 { 153 ret = lh_OBJ_NAME_retrieve(names_lh, &on);
156 ret=lh_OBJ_NAME_retrieve(names_lh,&on); 154 if (ret == NULL)
157 if (ret == NULL) return(NULL); 155 return (NULL);
158 if ((ret->alias) && !alias) 156 if ((ret->alias) && !alias) {
159 { 157 if (++num > 10)
160 if (++num > 10) return(NULL); 158 return (NULL);
161 on.name=ret->data; 159 on.name = ret->data;
162 } 160 } else {
163 else 161 return (ret->data);
164 {
165 return(ret->data);
166 }
167 } 162 }
168 } 163 }
164}
169 165
170int OBJ_NAME_add(const char *name, int type, const char *data) 166int
171 { 167OBJ_NAME_add(const char *name, int type, const char *data)
172 OBJ_NAME *onp,*ret; 168{
169 OBJ_NAME *onp, *ret;
173 int alias; 170 int alias;
174 171
175 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0); 172 if ((names_lh == NULL) && !OBJ_NAME_init())
173 return (0);
176 174
177 alias=type&OBJ_NAME_ALIAS; 175 alias = type & OBJ_NAME_ALIAS;
178 type&= ~OBJ_NAME_ALIAS; 176 type &= ~OBJ_NAME_ALIAS;
179 177
180 onp=(OBJ_NAME *)malloc(sizeof(OBJ_NAME)); 178 onp = (OBJ_NAME *)malloc(sizeof(OBJ_NAME));
181 if (onp == NULL) 179 if (onp == NULL) {
182 {
183 /* ERROR */ 180 /* ERROR */
184 return(0); 181 return (0);
185 } 182 }
186 183
187 onp->name=name; 184 onp->name = name;
188 onp->alias=alias; 185 onp->alias = alias;
189 onp->type=type; 186 onp->type = type;
190 onp->data=data; 187 onp->data = data;
191 188
192 ret=lh_OBJ_NAME_insert(names_lh,onp); 189 ret = lh_OBJ_NAME_insert(names_lh, onp);
193 if (ret != NULL) 190 if (ret != NULL) {
194 {
195 /* free things */ 191 /* free things */
196 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) 192 if ((name_funcs_stack != NULL) &&
197 { 193 (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) {
198 /* XXX: I'm not sure I understand why the free 194 /* XXX: I'm not sure I understand why the free
199 * function should get three arguments... 195 * function should get three arguments...
200 * -- Richard Levitte 196 * -- Richard Levitte
201 */ 197 */
202 sk_NAME_FUNCS_value(name_funcs_stack, 198 sk_NAME_FUNCS_value(
203 ret->type)->free_func(ret->name,ret->type,ret->data); 199 name_funcs_stack, ret->type)->free_func(
204 } 200 ret->name, ret->type, ret->data);
205 free(ret);
206 } 201 }
207 else 202 free(ret);
208 { 203 } else {
209 if (lh_OBJ_NAME_error(names_lh)) 204 if (lh_OBJ_NAME_error(names_lh)) {
210 {
211 /* ERROR */ 205 /* ERROR */
212 return(0); 206 return (0);
213 }
214 } 207 }
215 return(1);
216 } 208 }
217 209 return (1);
218int OBJ_NAME_remove(const char *name, int type) 210}
219 { 211
220 OBJ_NAME on,*ret; 212int
221 213OBJ_NAME_remove(const char *name, int type)
222 if (names_lh == NULL) return(0); 214{
223 215 OBJ_NAME on, *ret;
224 type&= ~OBJ_NAME_ALIAS; 216
225 on.name=name; 217 if (names_lh == NULL)
226 on.type=type; 218 return (0);
227 ret=lh_OBJ_NAME_delete(names_lh,&on); 219
228 if (ret != NULL) 220 type &= ~OBJ_NAME_ALIAS;
229 { 221 on.name = name;
222 on.type = type;
223 ret = lh_OBJ_NAME_delete(names_lh, &on);
224 if (ret != NULL) {
230 /* free things */ 225 /* free things */
231 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) 226 if ((name_funcs_stack != NULL) &&
232 { 227 (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) {
233 /* XXX: I'm not sure I understand why the free 228 /* XXX: I'm not sure I understand why the free
234 * function should get three arguments... 229 * function should get three arguments...
235 * -- Richard Levitte 230 * -- Richard Levitte
236 */ 231 */
237 sk_NAME_FUNCS_value(name_funcs_stack, 232 sk_NAME_FUNCS_value(
238 ret->type)->free_func(ret->name,ret->type,ret->data); 233 name_funcs_stack, ret->type)->free_func(
239 } 234 ret->name, ret->type, ret->data);
240 free(ret);
241 return(1);
242 } 235 }
243 else 236 free(ret);
244 return(0); 237 return (1);
245 } 238 } else
239 return (0);
240}
246 241
247struct doall 242struct doall {
248 {
249 int type; 243 int type;
250 void (*fn)(const OBJ_NAME *,void *arg); 244 void (*fn)(const OBJ_NAME *, void *arg);
251 void *arg; 245 void *arg;
252 }; 246};
253 247
254static void do_all_fn_doall_arg(const OBJ_NAME *name,struct doall *d) 248static void
255 { 249do_all_fn_doall_arg(const OBJ_NAME *name, struct doall *d)
256 if(name->type == d->type) 250{
257 d->fn(name,d->arg); 251 if (name->type == d->type)
258 } 252 d->fn(name, d->arg);
253}
259 254
260static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall) 255static IMPLEMENT_LHASH_DOALL_ARG_FN(do_all_fn, const OBJ_NAME, struct doall)
261 256
262void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg) 257void
263 { 258OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg), void *arg)
259{
264 struct doall d; 260 struct doall d;
265 261
266 d.type=type; 262 d.type = type;
267 d.fn=fn; 263 d.fn = fn;
268 d.arg=arg; 264 d.arg = arg;
269 265
270 lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn), 266 lh_OBJ_NAME_doall_arg(names_lh, LHASH_DOALL_ARG_FN(do_all_fn),
271 struct doall, &d); 267 struct doall, &d);
272 } 268}
273 269
274struct doall_sorted 270struct doall_sorted {
275 {
276 int type; 271 int type;
277 int n; 272 int n;
278 const OBJ_NAME **names; 273 const OBJ_NAME **names;
279 }; 274};
280 275
281static void do_all_sorted_fn(const OBJ_NAME *name,void *d_) 276static void
282 { 277do_all_sorted_fn(const OBJ_NAME *name, void *d_)
283 struct doall_sorted *d=d_; 278{
279 struct doall_sorted *d = d_;
284 280
285 if(name->type != d->type) 281 if (name->type != d->type)
286 return; 282 return;
287 283
288 d->names[d->n++]=name; 284 d->names[d->n++] = name;
289 } 285}
290 286
291static int do_all_sorted_cmp(const void *n1_,const void *n2_) 287static int
292 { 288do_all_sorted_cmp(const void *n1_, const void *n2_)
293 const OBJ_NAME * const *n1=n1_; 289{
294 const OBJ_NAME * const *n2=n2_; 290 const OBJ_NAME * const *n1 = n1_;
291 const OBJ_NAME * const *n2 = n2_;
295 292
296 return strcmp((*n1)->name,(*n2)->name); 293 return strcmp((*n1)->name, (*n2)->name);
297 } 294}
298 295
299void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), 296void
300 void *arg) 297OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg),
301 { 298 void *arg)
299{
302 struct doall_sorted d; 300 struct doall_sorted d;
303 int n; 301 int n;
304 302
305 d.type=type; 303 d.type = type;
306 d.names=malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names); 304 d.names = malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names);
307 d.n=0; 305 d.n = 0;
308 OBJ_NAME_do_all(type,do_all_sorted_fn,&d); 306 OBJ_NAME_do_all(type, do_all_sorted_fn, &d);
309 307
310 qsort((void *)d.names,d.n,sizeof *d.names,do_all_sorted_cmp); 308 qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp);
311 309
312 for(n=0 ; n < d.n ; ++n) 310 for (n = 0; n < d.n; ++n)
313 fn(d.names[n],arg); 311 fn(d.names[n], arg);
314 312
315 free((void *)d.names); 313 free((void *)d.names);
316 } 314}
317 315
318static int free_type; 316static int free_type;
319 317
320static void names_lh_free_doall(OBJ_NAME *onp) 318static void
321 { 319names_lh_free_doall(OBJ_NAME *onp)
320{
322 if (onp == NULL) 321 if (onp == NULL)
323 return; 322 return;
324 323
325 if (free_type < 0 || free_type == onp->type) 324 if (free_type < 0 || free_type == onp->type)
326 OBJ_NAME_remove(onp->name,onp->type); 325 OBJ_NAME_remove(onp->name, onp->type);
327 } 326}
328 327
329static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME) 328static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME)
330 329
331static void name_funcs_free(NAME_FUNCS *ptr) 330static void
332 { 331name_funcs_free(NAME_FUNCS *ptr)
332{
333 free(ptr); 333 free(ptr);
334 } 334}
335 335
336void OBJ_NAME_cleanup(int type) 336void
337 { 337OBJ_NAME_cleanup(int type)
338{
338 unsigned long down_load; 339 unsigned long down_load;
339 340
340 if (names_lh == NULL) return; 341 if (names_lh == NULL)
342 return;
341 343
342 free_type=type; 344 free_type = type;
343 down_load=lh_OBJ_NAME_down_load(names_lh); 345 down_load = lh_OBJ_NAME_down_load(names_lh);
344 lh_OBJ_NAME_down_load(names_lh)=0; 346 lh_OBJ_NAME_down_load(names_lh) = 0;
345 347
346 lh_OBJ_NAME_doall(names_lh,LHASH_DOALL_FN(names_lh_free)); 348 lh_OBJ_NAME_doall(names_lh, LHASH_DOALL_FN(names_lh_free));
347 if (type < 0) 349 if (type < 0) {
348 {
349 lh_OBJ_NAME_free(names_lh); 350 lh_OBJ_NAME_free(names_lh);
350 sk_NAME_FUNCS_pop_free(name_funcs_stack,name_funcs_free); 351 sk_NAME_FUNCS_pop_free(name_funcs_stack, name_funcs_free);
351 names_lh=NULL; 352 names_lh = NULL;
352 name_funcs_stack = NULL; 353 name_funcs_stack = NULL;
353 } 354 } else
354 else 355 lh_OBJ_NAME_down_load(names_lh) = down_load;
355 lh_OBJ_NAME_down_load(names_lh)=down_load; 356}
356 }
357
diff --git a/src/lib/libssl/src/crypto/objects/obj_dat.c b/src/lib/libssl/src/crypto/objects/obj_dat.c
index cc007f1206..9fa23ae916 100644
--- a/src/lib/libssl/src/crypto/objects/obj_dat.c
+++ b/src/lib/libssl/src/crypto/objects/obj_dat.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -90,117 +90,134 @@ DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
90#define ADDED_LNAME 2 90#define ADDED_LNAME 2
91#define ADDED_NID 3 91#define ADDED_NID 3
92 92
93typedef struct added_obj_st 93typedef struct added_obj_st {
94 {
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); 97DECLARE_LHASH_OF(ADDED_OBJ);
99 98
100static int new_nid=NUM_NID; 99static int new_nid = NUM_NID;
101static LHASH_OF(ADDED_OBJ) *added=NULL; 100static LHASH_OF(ADDED_OBJ) *added = NULL;
102 101
103static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) 102static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
104 { return(strcmp((*a)->sn,nid_objs[*b].sn)); } 103{
104 return (strcmp((*a)->sn, nid_objs[*b].sn));
105}
105 106
106IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn); 107IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
107 108
108static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b) 109static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
109 { return(strcmp((*a)->ln,nid_objs[*b].ln)); } 110{
111 return (strcmp((*a)->ln, nid_objs[*b].ln));
112}
110 113
111IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln); 114IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
112 115
113static unsigned long added_obj_hash(const ADDED_OBJ *ca) 116static unsigned long
114 { 117added_obj_hash(const ADDED_OBJ *ca)
118{
115 const ASN1_OBJECT *a; 119 const ASN1_OBJECT *a;
116 int i; 120 int i;
117 unsigned long ret=0; 121 unsigned long ret = 0;
118 unsigned char *p; 122 unsigned char *p;
119 123
120 a=ca->obj; 124 a = ca->obj;
121 switch (ca->type) 125 switch (ca->type) {
122 {
123 case ADDED_DATA: 126 case ADDED_DATA:
124 ret=a->length<<20L; 127 ret = a->length << 20L;
125 p=(unsigned char *)a->data; 128 p = (unsigned char *)a->data;
126 for (i=0; i<a->length; i++) 129 for (i = 0; i < a->length; i++)
127 ret^=p[i]<<((i*3)%24); 130 ret ^= p[i] << ((i * 3) % 24);
128 break; 131 break;
129 case ADDED_SNAME: 132 case ADDED_SNAME:
130 ret=lh_strhash(a->sn); 133 ret = lh_strhash(a->sn);
131 break; 134 break;
132 case ADDED_LNAME: 135 case ADDED_LNAME:
133 ret=lh_strhash(a->ln); 136 ret = lh_strhash(a->ln);
134 break; 137 break;
135 case ADDED_NID: 138 case ADDED_NID:
136 ret=a->nid; 139 ret = a->nid;
137 break; 140 break;
138 default: 141 default:
139 /* abort(); */ 142 /* abort(); */
140 return 0; 143 return 0;
141 }
142 ret&=0x3fffffffL;
143 ret|=ca->type<<30L;
144 return(ret);
145 } 144 }
145 ret &= 0x3fffffffL;
146 ret |= ca->type << 30L;
147 return (ret);
148}
146static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ) 149static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ)
147 150
148static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb) 151static int
149 { 152added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
150 ASN1_OBJECT *a,*b; 153{
154 ASN1_OBJECT *a, *b;
151 int i; 155 int i;
152 156
153 i=ca->type-cb->type; 157 i = ca->type - cb->type;
154 if (i) return(i); 158 if (i)
155 a=ca->obj; 159 return (i);
156 b=cb->obj; 160 a = ca->obj;
157 switch (ca->type) 161 b = cb->obj;
158 { 162 switch (ca->type) {
159 case ADDED_DATA: 163 case ADDED_DATA:
160 i=(a->length - b->length); 164 i = (a->length - b->length);
161 if (i) return(i); 165 if (i)
162 return(memcmp(a->data,b->data,(size_t)a->length)); 166 return (i);
167 return (memcmp(a->data, b->data, (size_t)a->length));
163 case ADDED_SNAME: 168 case ADDED_SNAME:
164 if (a->sn == NULL) return(-1); 169 if (a->sn == NULL)
165 else if (b->sn == NULL) return(1); 170 return (-1);
166 else return(strcmp(a->sn,b->sn)); 171 else if (b->sn == NULL)
172 return (1);
173 else
174 return (strcmp(a->sn, b->sn));
167 case ADDED_LNAME: 175 case ADDED_LNAME:
168 if (a->ln == NULL) return(-1); 176 if (a->ln == NULL)
169 else if (b->ln == NULL) return(1); 177 return (-1);
170 else return(strcmp(a->ln,b->ln)); 178 else if (b->ln == NULL)
179 return (1);
180 else
181 return (strcmp(a->ln, b->ln));
171 case ADDED_NID: 182 case ADDED_NID:
172 return(a->nid-b->nid); 183 return (a->nid - b->nid);
173 default: 184 default:
174 /* abort(); */ 185 /* abort(); */
175 return 0; 186 return 0;
176 }
177 } 187 }
188}
178static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ) 189static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
179 190
180static int init_added(void) 191static int
181 { 192init_added(void)
182 if (added != NULL) return(1); 193{
183 added=lh_ADDED_OBJ_new(); 194 if (added != NULL)
184 return(added != NULL); 195 return (1);
185 } 196 added = lh_ADDED_OBJ_new();
197 return (added != NULL);
198}
186 199
187static void cleanup1_doall(ADDED_OBJ *a) 200static void
188 { 201cleanup1_doall(ADDED_OBJ *a)
189 a->obj->nid=0; 202{
190 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| 203 a->obj->nid = 0;
191 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 204 a->obj->flags |= ASN1_OBJECT_FLAG_DYNAMIC |
192 ASN1_OBJECT_FLAG_DYNAMIC_DATA; 205 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
193 } 206 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
207}
194 208
195static void cleanup2_doall(ADDED_OBJ *a) 209static void cleanup2_doall(ADDED_OBJ *a)
196 { a->obj->nid++; } 210{
211 a->obj->nid++;
212}
197 213
198static void cleanup3_doall(ADDED_OBJ *a) 214static void
199 { 215cleanup3_doall(ADDED_OBJ *a)
216{
200 if (--a->obj->nid == 0) 217 if (--a->obj->nid == 0)
201 ASN1_OBJECT_free(a->obj); 218 ASN1_OBJECT_free(a->obj);
202 free(a); 219 free(a);
203 } 220}
204 221
205static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ) 222static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ)
206static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ) 223static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ)
@@ -213,210 +230,213 @@ static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ)
213 230
214int obj_cleanup_defer = 0; 231int obj_cleanup_defer = 0;
215 232
216void check_defer(int nid) 233void
217 { 234check_defer(int nid)
235{
218 if (!obj_cleanup_defer && nid >= NUM_NID) 236 if (!obj_cleanup_defer && nid >= NUM_NID)
219 obj_cleanup_defer = 1; 237 obj_cleanup_defer = 1;
220 } 238}
221 239
222void OBJ_cleanup(void) 240void
223 { 241OBJ_cleanup(void)
224 if (obj_cleanup_defer) 242{
225 { 243 if (obj_cleanup_defer) {
226 obj_cleanup_defer = 2; 244 obj_cleanup_defer = 2;
227 return ; 245 return;
228 } 246 }
229 if (added == NULL) return; 247 if (added == NULL)
248 return;
230 lh_ADDED_OBJ_down_load(added) = 0; 249 lh_ADDED_OBJ_down_load(added) = 0;
231 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */ 250 lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup1)); /* zero counters */
232 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */ 251 lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup2)); /* set counters */
233 lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */ 252 lh_ADDED_OBJ_doall(added, LHASH_DOALL_FN(cleanup3)); /* free objects */
234 lh_ADDED_OBJ_free(added); 253 lh_ADDED_OBJ_free(added);
235 added=NULL; 254 added = NULL;
236 } 255}
237 256
238int OBJ_new_nid(int num) 257int
239 { 258OBJ_new_nid(int num)
259{
240 int i; 260 int i;
241 261
242 i=new_nid; 262 i = new_nid;
243 new_nid+=num; 263 new_nid += num;
244 return(i); 264 return (i);
245 } 265}
246 266
247int OBJ_add_object(const ASN1_OBJECT *obj) 267int
248 { 268OBJ_add_object(const ASN1_OBJECT *obj)
269{
249 ASN1_OBJECT *o; 270 ASN1_OBJECT *o;
250 ADDED_OBJ *ao[4]={NULL,NULL,NULL,NULL},*aop; 271 ADDED_OBJ *ao[4] = {NULL, NULL, NULL, NULL}, *aop;
251 int i; 272 int i;
252 273
253 if (added == NULL) 274 if (added == NULL)
254 if (!init_added()) return(0); 275 if (!init_added())
255 if ((o=OBJ_dup(obj)) == NULL) goto err; 276 return (0);
256 if (!(ao[ADDED_NID]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 277 if ((o = OBJ_dup(obj)) == NULL)
278 goto err;
279 if (!(ao[ADDED_NID] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
280 goto err2;
257 if ((o->length != 0) && (obj->data != NULL)) 281 if ((o->length != 0) && (obj->data != NULL))
258 if (!(ao[ADDED_DATA]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 282 if (!(ao[ADDED_DATA] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
283 goto err2;
259 if (o->sn != NULL) 284 if (o->sn != NULL)
260 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 285 if (!(ao[ADDED_SNAME] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
286 goto err2;
261 if (o->ln != NULL) 287 if (o->ln != NULL)
262 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2; 288 if (!(ao[ADDED_LNAME] = (ADDED_OBJ *)malloc(sizeof(ADDED_OBJ))))
263 289 goto err2;
264 for (i=ADDED_DATA; i<=ADDED_NID; i++) 290
265 { 291 for (i = ADDED_DATA; i <= ADDED_NID; i++) {
266 if (ao[i] != NULL) 292 if (ao[i] != NULL) {
267 { 293 ao[i]->type = i;
268 ao[i]->type=i; 294 ao[i]->obj = o;
269 ao[i]->obj=o; 295 aop = lh_ADDED_OBJ_insert(added, ao[i]);
270 aop=lh_ADDED_OBJ_insert(added,ao[i]);
271 /* memory leak, buit should not normally matter */ 296 /* memory leak, buit should not normally matter */
272 if (aop != NULL) 297 if (aop != NULL)
273 free(aop); 298 free(aop);
274 }
275 } 299 }
276 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 300 }
277 ASN1_OBJECT_FLAG_DYNAMIC_DATA); 301 o->flags &= ~(ASN1_OBJECT_FLAG_DYNAMIC |
302 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
303 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
304
305 return (o->nid);
278 306
279 return(o->nid);
280err2: 307err2:
281 OBJerr(OBJ_F_OBJ_ADD_OBJECT,ERR_R_MALLOC_FAILURE); 308 OBJerr(OBJ_F_OBJ_ADD_OBJECT, ERR_R_MALLOC_FAILURE);
282err: 309err:
283 for (i=ADDED_DATA; i<=ADDED_NID; i++) 310 for (i = ADDED_DATA; i <= ADDED_NID; i++)
284 if (ao[i] != NULL) free(ao[i]); 311 if (ao[i] != NULL)
285 if (o != NULL) free(o); 312 free(ao[i]);
286 return(NID_undef); 313 if (o != NULL)
287 } 314 free(o);
315 return (NID_undef);
316}
288 317
289ASN1_OBJECT *OBJ_nid2obj(int n) 318ASN1_OBJECT *
290 { 319OBJ_nid2obj(int n)
291 ADDED_OBJ ad,*adp; 320{
321 ADDED_OBJ ad, *adp;
292 ASN1_OBJECT ob; 322 ASN1_OBJECT ob;
293 323
294 if ((n >= 0) && (n < NUM_NID)) 324 if ((n >= 0) && (n < NUM_NID)) {
295 { 325 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
296 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) 326 OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);
297 { 327 return (NULL);
298 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
299 return(NULL);
300 }
301 return((ASN1_OBJECT *)&(nid_objs[n]));
302 } 328 }
303 else if (added == NULL) 329 return ((ASN1_OBJECT *)&(nid_objs[n]));
304 return(NULL); 330 } else if (added == NULL)
305 else 331 return (NULL);
306 { 332 else {
307 ad.type=ADDED_NID; 333 ad.type = ADDED_NID;
308 ad.obj= &ob; 334 ad.obj = &ob;
309 ob.nid=n; 335 ob.nid = n;
310 adp=lh_ADDED_OBJ_retrieve(added,&ad); 336 adp = lh_ADDED_OBJ_retrieve(added, &ad);
311 if (adp != NULL) 337 if (adp != NULL)
312 return(adp->obj); 338 return (adp->obj);
313 else 339 else {
314 { 340 OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);
315 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID); 341 return (NULL);
316 return(NULL);
317 }
318 } 342 }
319 } 343 }
344}
320 345
321const char *OBJ_nid2sn(int n) 346const char *
322 { 347OBJ_nid2sn(int n)
323 ADDED_OBJ ad,*adp; 348{
349 ADDED_OBJ ad, *adp;
324 ASN1_OBJECT ob; 350 ASN1_OBJECT ob;
325 351
326 if ((n >= 0) && (n < NUM_NID)) 352 if ((n >= 0) && (n < NUM_NID)) {
327 { 353 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
328 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) 354 OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);
329 { 355 return (NULL);
330 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
331 return(NULL);
332 }
333 return(nid_objs[n].sn);
334 } 356 }
335 else if (added == NULL) 357 return (nid_objs[n].sn);
336 return(NULL); 358 } else if (added == NULL)
337 else 359 return (NULL);
338 { 360 else {
339 ad.type=ADDED_NID; 361 ad.type = ADDED_NID;
340 ad.obj= &ob; 362 ad.obj = &ob;
341 ob.nid=n; 363 ob.nid = n;
342 adp=lh_ADDED_OBJ_retrieve(added,&ad); 364 adp = lh_ADDED_OBJ_retrieve(added, &ad);
343 if (adp != NULL) 365 if (adp != NULL)
344 return(adp->obj->sn); 366 return (adp->obj->sn);
345 else 367 else {
346 { 368 OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID);
347 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID); 369 return (NULL);
348 return(NULL);
349 }
350 } 370 }
351 } 371 }
372}
352 373
353const char *OBJ_nid2ln(int n) 374const char *
354 { 375OBJ_nid2ln(int n)
355 ADDED_OBJ ad,*adp; 376{
377 ADDED_OBJ ad, *adp;
356 ASN1_OBJECT ob; 378 ASN1_OBJECT ob;
357 379
358 if ((n >= 0) && (n < NUM_NID)) 380 if ((n >= 0) && (n < NUM_NID)) {
359 { 381 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
360 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) 382 OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID);
361 { 383 return (NULL);
362 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
363 return(NULL);
364 }
365 return(nid_objs[n].ln);
366 } 384 }
367 else if (added == NULL) 385 return (nid_objs[n].ln);
368 return(NULL); 386 } else if (added == NULL)
369 else 387 return (NULL);
370 { 388 else {
371 ad.type=ADDED_NID; 389 ad.type = ADDED_NID;
372 ad.obj= &ob; 390 ad.obj = &ob;
373 ob.nid=n; 391 ob.nid = n;
374 adp=lh_ADDED_OBJ_retrieve(added,&ad); 392 adp = lh_ADDED_OBJ_retrieve(added, &ad);
375 if (adp != NULL) 393 if (adp != NULL)
376 return(adp->obj->ln); 394 return (adp->obj->ln);
377 else 395 else {
378 { 396 OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID);
379 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID); 397 return (NULL);
380 return(NULL);
381 }
382 } 398 }
383 } 399 }
400}
384 401
385static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp) 402static int
386 { 403obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
404{
387 int j; 405 int j;
388 const ASN1_OBJECT *a= *ap; 406 const ASN1_OBJECT *a= *ap;
389 const ASN1_OBJECT *b= &nid_objs[*bp]; 407 const ASN1_OBJECT *b = &nid_objs[*bp];
390 408
391 j=(a->length - b->length); 409 j = (a->length - b->length);
392 if (j) return(j); 410 if (j)
393 return(memcmp(a->data,b->data,a->length)); 411 return (j);
394 } 412 return (memcmp(a->data, b->data, a->length));
413}
395 414
396IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj); 415IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
397 416
398int OBJ_obj2nid(const ASN1_OBJECT *a) 417int
399 { 418OBJ_obj2nid(const ASN1_OBJECT *a)
419{
400 const unsigned int *op; 420 const unsigned int *op;
401 ADDED_OBJ ad,*adp; 421 ADDED_OBJ ad, *adp;
402 422
403 if (a == NULL) 423 if (a == NULL)
404 return(NID_undef); 424 return (NID_undef);
405 if (a->nid != 0) 425 if (a->nid != 0)
406 return(a->nid); 426 return (a->nid);
407 427
408 if (added != NULL) 428 if (added != NULL) {
409 { 429 ad.type = ADDED_DATA;
410 ad.type=ADDED_DATA;
411 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */ 430 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
412 adp=lh_ADDED_OBJ_retrieve(added,&ad); 431 adp = lh_ADDED_OBJ_retrieve(added, &ad);
413 if (adp != NULL) return (adp->obj->nid); 432 if (adp != NULL)
414 } 433 return (adp->obj->nid);
415 op=OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
416 if (op == NULL)
417 return(NID_undef);
418 return(nid_objs[*op].nid);
419 } 434 }
435 op = OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
436 if (op == NULL)
437 return (NID_undef);
438 return (nid_objs[*op].nid);
439}
420 440
421/* Convert an object name into an ASN1_OBJECT 441/* Convert an object name into an ASN1_OBJECT
422 * if "noname" is not set then search for short and long names first. 442 * if "noname" is not set then search for short and long names first.
@@ -424,371 +444,351 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
424 * it can be used with any objects, not just registered ones. 444 * it can be used with any objects, not just registered ones.
425 */ 445 */
426 446
427ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) 447ASN1_OBJECT *
428 { 448OBJ_txt2obj(const char *s, int no_name)
449{
429 int nid = NID_undef; 450 int nid = NID_undef;
430 ASN1_OBJECT *op=NULL; 451 ASN1_OBJECT *op = NULL;
431 unsigned char *buf; 452 unsigned char *buf;
432 unsigned char *p; 453 unsigned char *p;
433 const unsigned char *cp; 454 const unsigned char *cp;
434 int i, j; 455 int i, j;
435 456
436 if(!no_name) { 457 if (!no_name) {
437 if( ((nid = OBJ_sn2nid(s)) != NID_undef) || 458 if (((nid = OBJ_sn2nid(s)) != NID_undef) ||
438 ((nid = OBJ_ln2nid(s)) != NID_undef) ) 459 ((nid = OBJ_ln2nid(s)) != NID_undef) )
439 return OBJ_nid2obj(nid); 460 return OBJ_nid2obj(nid);
440 } 461 }
441 462
442 /* Work out size of content octets */ 463 /* Work out size of content octets */
443 i=a2d_ASN1_OBJECT(NULL,0,s,-1); 464 i = a2d_ASN1_OBJECT(NULL, 0, s, -1);
444 if (i <= 0) { 465 if (i <= 0) {
445 /* Don't clear the error */ 466 /* Don't clear the error */
446 /*ERR_clear_error();*/ 467 /*ERR_clear_error();*/
447 return NULL; 468 return NULL;
448 } 469 }
449 /* Work out total size */ 470 /* Work out total size */
450 j = ASN1_object_size(0,i,V_ASN1_OBJECT); 471 j = ASN1_object_size(0, i, V_ASN1_OBJECT);
451 472
452 if((buf=(unsigned char *)malloc(j)) == NULL) return NULL; 473 if ((buf = (unsigned char *)malloc(j)) == NULL)
474 return NULL;
453 475
454 p = buf; 476 p = buf;
455 /* Write out tag+length */ 477 /* Write out tag+length */
456 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); 478 ASN1_put_object(&p, 0, i, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
457 /* Write out contents */ 479 /* Write out contents */
458 a2d_ASN1_OBJECT(p,i,s,-1); 480 a2d_ASN1_OBJECT(p, i, s, -1);
459 481
460 cp=buf; 482 cp = buf;
461 op=d2i_ASN1_OBJECT(NULL,&cp,j); 483 op = d2i_ASN1_OBJECT(NULL, &cp, j);
462 free(buf); 484 free(buf);
463 return op; 485 return op;
464 } 486}
465 487
466int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) 488int
489OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
467{ 490{
468 int i,n=0,len,nid, first, use_bn; 491 int i, n = 0, len, nid, first, use_bn;
469 BIGNUM *bl; 492 BIGNUM *bl;
470 unsigned long l; 493 unsigned long l;
471 const unsigned char *p; 494 const unsigned char *p;
472 char tbuf[DECIMAL_SIZE(l) + 1]; 495 char tbuf[DECIMAL_SIZE(l) + 1];
473 496
474 if ((a == NULL) || (a->data == NULL)) { 497 if ((a == NULL) || (a->data == NULL)) {
475 buf[0]='\0'; 498 buf[0] = '\0';
476 return(0); 499 return (0);
477 } 500 }
478 501
479 502 if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) {
480 if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef)
481 {
482 const char *s; 503 const char *s;
483 s=OBJ_nid2ln(nid); 504 s = OBJ_nid2ln(nid);
484 if (s == NULL) 505 if (s == NULL)
485 s=OBJ_nid2sn(nid); 506 s = OBJ_nid2sn(nid);
486 if (s) 507 if (s) {
487 {
488 if (buf) 508 if (buf)
489 strlcpy(buf,s,buf_len); 509 strlcpy(buf, s, buf_len);
490 n=strlen(s); 510 n = strlen(s);
491 return n; 511 return n;
492 }
493 } 512 }
513 }
494 514
495 515 len = a->length;
496 len=a->length; 516 p = a->data;
497 p=a->data;
498 517
499 first = 1; 518 first = 1;
500 bl = NULL; 519 bl = NULL;
501 520
502 while (len > 0) 521 while (len > 0) {
503 { 522 l = 0;
504 l=0;
505 use_bn = 0; 523 use_bn = 0;
506 for (;;) 524 for (;;) {
507 {
508 unsigned char c = *p++; 525 unsigned char c = *p++;
509 len--; 526 len--;
510 if ((len == 0) && (c & 0x80)) 527 if ((len == 0) && (c & 0x80))
511 goto err; 528 goto err;
512 if (use_bn) 529 if (use_bn) {
513 {
514 if (!BN_add_word(bl, c & 0x7f)) 530 if (!BN_add_word(bl, c & 0x7f))
515 goto err; 531 goto err;
516 } 532 } else
517 else 533 l |= c & 0x7f;
518 l |= c & 0x7f;
519 if (!(c & 0x80)) 534 if (!(c & 0x80))
520 break; 535 break;
521 if (!use_bn && (l > (ULONG_MAX >> 7L))) 536 if (!use_bn && (l > (ULONG_MAX >> 7L))) {
522 {
523 if (!bl && !(bl = BN_new())) 537 if (!bl && !(bl = BN_new()))
524 goto err; 538 goto err;
525 if (!BN_set_word(bl, l)) 539 if (!BN_set_word(bl, l))
526 goto err; 540 goto err;
527 use_bn = 1; 541 use_bn = 1;
528 } 542 }
529 if (use_bn) 543 if (use_bn) {
530 {
531 if (!BN_lshift(bl, bl, 7)) 544 if (!BN_lshift(bl, bl, 7))
532 goto err; 545 goto err;
533 } 546 } else
534 else 547 l <<= 7L;
535 l<<=7L; 548 }
536 }
537 549
538 if (first) 550 if (first) {
539 {
540 first = 0; 551 first = 0;
541 if (l >= 80) 552 if (l >= 80) {
542 {
543 i = 2; 553 i = 2;
544 if (use_bn) 554 if (use_bn) {
545 {
546 if (!BN_sub_word(bl, 80)) 555 if (!BN_sub_word(bl, 80))
547 goto err; 556 goto err;
548 } 557 } else
549 else
550 l -= 80; 558 l -= 80;
551 } 559 } else {
552 else 560 i = (int)(l / 40);
553 { 561 l -= (long)(i * 40);
554 i=(int)(l/40); 562 }
555 l-=(long)(i*40); 563 if (buf && (buf_len > 0)) {
556 }
557 if (buf && (buf_len > 0))
558 {
559 *buf++ = i + '0'; 564 *buf++ = i + '0';
560 buf_len--; 565 buf_len--;
561 }
562 n++;
563 } 566 }
567 n++;
568 }
564 569
565 if (use_bn) 570 if (use_bn) {
566 {
567 char *bndec; 571 char *bndec;
568 bndec = BN_bn2dec(bl); 572 bndec = BN_bn2dec(bl);
569 if (!bndec) 573 if (!bndec)
570 goto err; 574 goto err;
571 i = strlen(bndec); 575 i = strlen(bndec);
572 if (buf) 576 if (buf) {
573 { 577 if (buf_len > 0) {
574 if (buf_len > 0)
575 {
576 *buf++ = '.'; 578 *buf++ = '.';
577 buf_len--; 579 buf_len--;
578 } 580 }
579 strlcpy(buf,bndec,buf_len); 581 strlcpy(buf, bndec, buf_len);
580 if (i > buf_len) 582 if (i > buf_len) {
581 {
582 buf += buf_len; 583 buf += buf_len;
583 buf_len = 0; 584 buf_len = 0;
584 } 585 } else {
585 else 586 buf += i;
586 { 587 buf_len -= i;
587 buf+=i;
588 buf_len-=i;
589 }
590 } 588 }
589 }
591 n++; 590 n++;
592 n += i; 591 n += i;
593 free(bndec); 592 free(bndec);
594 } 593 } else {
595 else 594 snprintf(tbuf, sizeof tbuf, ".%lu", l);
596 { 595 i = strlen(tbuf);
597 snprintf(tbuf,sizeof tbuf,".%lu",l); 596 if (buf && (buf_len > 0)) {
598 i=strlen(tbuf); 597 strlcpy(buf, tbuf, buf_len);
599 if (buf && (buf_len > 0)) 598 if (i > buf_len) {
600 {
601 strlcpy(buf,tbuf,buf_len);
602 if (i > buf_len)
603 {
604 buf += buf_len; 599 buf += buf_len;
605 buf_len = 0; 600 buf_len = 0;
606 } 601 } else {
607 else 602 buf += i;
608 { 603 buf_len -= i;
609 buf+=i;
610 buf_len-=i;
611 }
612 } 604 }
613 n+=i;
614 l=0;
615 } 605 }
606 n += i;
607 l = 0;
616 } 608 }
609 }
617 610
618 if (bl) 611 if (bl)
619 BN_free(bl); 612 BN_free(bl);
620 return n; 613 return n;
621 614
622 err: 615err:
623 if (bl) 616 if (bl)
624 BN_free(bl); 617 BN_free(bl);
625 return -1; 618 return -1;
626} 619}
627 620
628int OBJ_txt2nid(const char *s) 621int
622OBJ_txt2nid(const char *s)
629{ 623{
630 ASN1_OBJECT *obj; 624 ASN1_OBJECT *obj;
631 int nid; 625 int nid;
626
632 obj = OBJ_txt2obj(s, 0); 627 obj = OBJ_txt2obj(s, 0);
633 nid = OBJ_obj2nid(obj); 628 nid = OBJ_obj2nid(obj);
634 ASN1_OBJECT_free(obj); 629 ASN1_OBJECT_free(obj);
635 return nid; 630 return nid;
636} 631}
637 632
638int OBJ_ln2nid(const char *s) 633int
639 { 634OBJ_ln2nid(const char *s)
635{
640 ASN1_OBJECT o; 636 ASN1_OBJECT o;
641 const ASN1_OBJECT *oo= &o; 637 const ASN1_OBJECT *oo = &o;
642 ADDED_OBJ ad,*adp; 638 ADDED_OBJ ad, *adp;
643 const unsigned int *op; 639 const unsigned int *op;
644 640
645 o.ln=s; 641 o.ln = s;
646 if (added != NULL) 642 if (added != NULL) {
647 { 643 ad.type = ADDED_LNAME;
648 ad.type=ADDED_LNAME; 644 ad.obj = &o;
649 ad.obj= &o; 645 adp = lh_ADDED_OBJ_retrieve(added, &ad);
650 adp=lh_ADDED_OBJ_retrieve(added,&ad); 646 if (adp != NULL)
651 if (adp != NULL) return (adp->obj->nid); 647 return (adp->obj->nid);
652 }
653 op=OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
654 if (op == NULL) return(NID_undef);
655 return(nid_objs[*op].nid);
656 } 648 }
649 op = OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
650 if (op == NULL)
651 return (NID_undef);
652 return (nid_objs[*op].nid);
653}
657 654
658int OBJ_sn2nid(const char *s) 655int
659 { 656OBJ_sn2nid(const char *s)
657{
660 ASN1_OBJECT o; 658 ASN1_OBJECT o;
661 const ASN1_OBJECT *oo= &o; 659 const ASN1_OBJECT *oo = &o;
662 ADDED_OBJ ad,*adp; 660 ADDED_OBJ ad, *adp;
663 const unsigned int *op; 661 const unsigned int *op;
664 662
665 o.sn=s; 663 o.sn = s;
666 if (added != NULL) 664 if (added != NULL) {
667 { 665 ad.type = ADDED_SNAME;
668 ad.type=ADDED_SNAME; 666 ad.obj = &o;
669 ad.obj= &o; 667 adp = lh_ADDED_OBJ_retrieve(added, &ad);
670 adp=lh_ADDED_OBJ_retrieve(added,&ad); 668 if (adp != NULL)
671 if (adp != NULL) return (adp->obj->nid); 669 return (adp->obj->nid);
672 }
673 op=OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
674 if (op == NULL) return(NID_undef);
675 return(nid_objs[*op].nid);
676 } 670 }
671 op = OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
672 if (op == NULL)
673 return (NID_undef);
674 return (nid_objs[*op].nid);
675}
677 676
678const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, 677const void *
679 int (*cmp)(const void *, const void *)) 678OBJ_bsearch_(const void *key, const void *base, int num, int size,
680 { 679 int (*cmp)(const void *, const void *))
680{
681 return OBJ_bsearch_ex_(key, base, num, size, cmp, 0); 681 return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
682 } 682}
683 683
684const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num, 684const void *
685 int size, 685OBJ_bsearch_ex_(const void *key, const void *base_, int num, int size,
686 int (*cmp)(const void *, const void *), 686 int (*cmp)(const void *, const void *), int flags)
687 int flags) 687{
688 { 688 const char *base = base_;
689 const char *base=base_; 689 int l, h, i = 0, c = 0;
690 int l,h,i=0,c=0;
691 const char *p = NULL; 690 const char *p = NULL;
692 691
693 if (num == 0) return(NULL); 692 if (num == 0)
694 l=0; 693 return (NULL);
695 h=num; 694 l = 0;
696 while (l < h) 695 h = num;
697 { 696 while (l < h) {
698 i=(l+h)/2; 697 i = (l + h) / 2;
699 p= &(base[i*size]); 698 p = &(base[i * size]);
700 c=(*cmp)(key,p); 699 c = (*cmp)(key, p);
701 if (c < 0) 700 if (c < 0)
702 h=i; 701 h = i;
703 else if (c > 0) 702 else if (c > 0)
704 l=i+1; 703 l = i + 1;
705 else 704 else
706 break; 705 break;
707 } 706 }
708 if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)) 707 if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH))
709 p = NULL; 708 p = NULL;
710 else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) 709 else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) {
711 { 710 while (i > 0 && (*cmp)(key, &(base[(i - 1) * size])) == 0)
712 while(i > 0 && (*cmp)(key,&(base[(i-1)*size])) == 0)
713 i--; 711 i--;
714 p = &(base[i*size]); 712 p = &(base[i * size]);
715 }
716 return(p);
717 } 713 }
714 return (p);
715}
718 716
719int OBJ_create_objects(BIO *in) 717int
720 { 718OBJ_create_objects(BIO *in)
719{
721 char buf[512]; 720 char buf[512];
722 int i,num=0; 721 int i, num = 0;
723 char *o,*s,*l=NULL; 722 char *o, *s, *l = NULL;
724 723
725 for (;;) 724 for (;;) {
726 { 725 s = o = NULL;
727 s=o=NULL; 726 i = BIO_gets(in, buf, 512);
728 i=BIO_gets(in,buf,512); 727 if (i <= 0)
729 if (i <= 0) return(num); 728 return (num);
730 buf[i-1]='\0'; 729 buf[i - 1] = '\0';
731 if (!isalnum((unsigned char)buf[0])) return(num); 730 if (!isalnum((unsigned char)buf[0]))
732 o=s=buf; 731 return (num);
732 o = s=buf;
733 while (isdigit((unsigned char)*s) || (*s == '.')) 733 while (isdigit((unsigned char)*s) || (*s == '.'))
734 s++; 734 s++;
735 if (*s != '\0') 735 if (*s != '\0') {
736 { 736 *(s++) = '\0';
737 *(s++)='\0';
738 while (isspace((unsigned char)*s)) 737 while (isspace((unsigned char)*s))
739 s++; 738 s++;
740 if (*s == '\0') 739 if (*s == '\0')
741 s=NULL; 740 s = NULL;
742 else 741 else {
743 { 742 l = s;
744 l=s; 743 while ((*l != '\0') &&
745 while ((*l != '\0') && !isspace((unsigned char)*l)) 744 !isspace((unsigned char)*l))
746 l++; 745 l++;
747 if (*l != '\0') 746 if (*l != '\0') {
748 { 747 *(l++) = '\0';
749 *(l++)='\0';
750 while (isspace((unsigned char)*l)) 748 while (isspace((unsigned char)*l))
751 l++; 749 l++;
752 if (*l == '\0') l=NULL; 750 if (*l == '\0')
753 } 751 l = NULL;
754 else 752 } else
755 l=NULL; 753 l = NULL;
756 }
757 } 754 }
758 else 755 } else
759 s=NULL; 756 s = NULL;
760 if ((o == NULL) || (*o == '\0')) return(num); 757 if ((o == NULL) || (*o == '\0'))
761 if (!OBJ_create(o,s,l)) return(num); 758 return (num);
759 if (!OBJ_create(o, s, l))
760 return (num);
762 num++; 761 num++;
763 }
764 /* return(num); */
765 } 762 }
763 /* return(num); */
764}
766 765
767int OBJ_create(const char *oid, const char *sn, const char *ln) 766int
768 { 767OBJ_create(const char *oid, const char *sn, const char *ln)
769 int ok=0; 768{
770 ASN1_OBJECT *op=NULL; 769 int ok = 0;
770 ASN1_OBJECT *op = NULL;
771 unsigned char *buf; 771 unsigned char *buf;
772 int i; 772 int i;
773 773
774 i=a2d_ASN1_OBJECT(NULL,0,oid,-1); 774 i = a2d_ASN1_OBJECT(NULL, 0, oid, -1);
775 if (i <= 0) return(0); 775 if (i <= 0)
776 return (0);
776 777
777 if ((buf=(unsigned char *)malloc(i)) == NULL) 778 if ((buf = (unsigned char *)malloc(i)) == NULL) {
778 { 779 OBJerr(OBJ_F_OBJ_CREATE, ERR_R_MALLOC_FAILURE);
779 OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE); 780 return (0);
780 return(0); 781 }
781 } 782 i = a2d_ASN1_OBJECT(buf, i, oid, -1);
782 i=a2d_ASN1_OBJECT(buf,i,oid,-1);
783 if (i == 0) 783 if (i == 0)
784 goto err; 784 goto err;
785 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); 785 op = (ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1), buf, i, sn, ln);
786 if (op == NULL) 786 if (op == NULL)
787 goto err; 787 goto err;
788 ok=OBJ_add_object(op); 788 ok = OBJ_add_object(op);
789
789err: 790err:
790 ASN1_OBJECT_free(op); 791 ASN1_OBJECT_free(op);
791 free(buf); 792 free(buf);
792 return(ok); 793 return (ok);
793 } 794}
794
diff --git a/src/lib/libssl/src/crypto/objects/obj_err.c b/src/lib/libssl/src/crypto/objects/obj_err.c
index 2e7a034c3f..47597dbfe4 100644
--- a/src/lib/libssl/src/crypto/objects/obj_err.c
+++ b/src/lib/libssl/src/crypto/objects/obj_err.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -68,35 +68,32 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_OBJ,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_OBJ,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason)
70 70
71static ERR_STRING_DATA OBJ_str_functs[]= 71static ERR_STRING_DATA OBJ_str_functs[] = {
72 { 72 {ERR_FUNC(OBJ_F_OBJ_ADD_OBJECT), "OBJ_add_object"},
73{ERR_FUNC(OBJ_F_OBJ_ADD_OBJECT), "OBJ_add_object"}, 73 {ERR_FUNC(OBJ_F_OBJ_CREATE), "OBJ_create"},
74{ERR_FUNC(OBJ_F_OBJ_CREATE), "OBJ_create"}, 74 {ERR_FUNC(OBJ_F_OBJ_DUP), "OBJ_dup"},
75{ERR_FUNC(OBJ_F_OBJ_DUP), "OBJ_dup"}, 75 {ERR_FUNC(OBJ_F_OBJ_NAME_NEW_INDEX), "OBJ_NAME_new_index"},
76{ERR_FUNC(OBJ_F_OBJ_NAME_NEW_INDEX), "OBJ_NAME_new_index"}, 76 {ERR_FUNC(OBJ_F_OBJ_NID2LN), "OBJ_nid2ln"},
77{ERR_FUNC(OBJ_F_OBJ_NID2LN), "OBJ_nid2ln"}, 77 {ERR_FUNC(OBJ_F_OBJ_NID2OBJ), "OBJ_nid2obj"},
78{ERR_FUNC(OBJ_F_OBJ_NID2OBJ), "OBJ_nid2obj"}, 78 {ERR_FUNC(OBJ_F_OBJ_NID2SN), "OBJ_nid2sn"},
79{ERR_FUNC(OBJ_F_OBJ_NID2SN), "OBJ_nid2sn"}, 79 {0, NULL}
80{0,NULL} 80};
81 };
82 81
83static ERR_STRING_DATA OBJ_str_reasons[]= 82static ERR_STRING_DATA OBJ_str_reasons[] = {
84 { 83 {ERR_REASON(OBJ_R_MALLOC_FAILURE) , "malloc failure"},
85{ERR_REASON(OBJ_R_MALLOC_FAILURE) ,"malloc failure"}, 84 {ERR_REASON(OBJ_R_UNKNOWN_NID) , "unknown nid"},
86{ERR_REASON(OBJ_R_UNKNOWN_NID) ,"unknown nid"}, 85 {0, NULL}
87{0,NULL} 86};
88 };
89 87
90#endif 88#endif
91 89
92void ERR_load_OBJ_strings(void) 90void
93 { 91ERR_load_OBJ_strings(void)
92{
94#ifndef OPENSSL_NO_ERR 93#ifndef OPENSSL_NO_ERR
95 94 if (ERR_func_error_string(OBJ_str_functs[0].error) == NULL) {
96 if (ERR_func_error_string(OBJ_str_functs[0].error) == NULL) 95 ERR_load_strings(0, OBJ_str_functs);
97 { 96 ERR_load_strings(0, OBJ_str_reasons);
98 ERR_load_strings(0,OBJ_str_functs);
99 ERR_load_strings(0,OBJ_str_reasons);
100 }
101#endif
102 } 97 }
98#endif
99}
diff --git a/src/lib/libssl/src/crypto/objects/obj_lib.c b/src/lib/libssl/src/crypto/objects/obj_lib.c
index 338fe851fc..57f0b28cc0 100644
--- a/src/lib/libssl/src/crypto/objects/obj_lib.c
+++ b/src/lib/libssl/src/crypto/objects/obj_lib.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -62,68 +62,76 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64 64
65ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) 65ASN1_OBJECT *
66 { 66OBJ_dup(const ASN1_OBJECT *o)
67{
67 ASN1_OBJECT *r; 68 ASN1_OBJECT *r;
68 int i; 69 int i;
69 char *ln=NULL,*sn=NULL; 70 char *ln = NULL, *sn = NULL;
70 unsigned char *data=NULL; 71 unsigned char *data = NULL;
71 72
72 if (o == NULL) return(NULL); 73 if (o == NULL)
74 return (NULL);
73 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) 75 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
74 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of 76 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of
75 duplication is this??? */ 77 duplication is this??? */
76 78
77 r=ASN1_OBJECT_new(); 79 r = ASN1_OBJECT_new();
78 if (r == NULL) 80 if (r == NULL) {
79 { 81 OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);
80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); 82 return (NULL);
81 return(NULL); 83 }
82 } 84 data = malloc(o->length);
83 data=malloc(o->length);
84 if (data == NULL) 85 if (data == NULL)
85 goto err; 86 goto err;
86 if (o->data != NULL) 87 if (o->data != NULL)
87 memcpy(data,o->data,o->length); 88 memcpy(data, o->data, o->length);
88 /* once data attached to object it remains const */ 89 /* once data attached to object it remains const */
89 r->data = data; 90 r->data = data;
90 r->length=o->length; 91 r->length = o->length;
91 r->nid=o->nid; 92 r->nid = o->nid;
92 r->ln=r->sn=NULL; 93 r->ln = r->sn = NULL;
93 if (o->ln != NULL) 94 if (o->ln != NULL) {
94 { 95 i = strlen(o->ln) + 1;
95 i=strlen(o->ln)+1; 96 ln = malloc(i);
96 ln=malloc(i); 97 if (ln == NULL)
97 if (ln == NULL) goto err; 98 goto err;
98 memcpy(ln,o->ln,i); 99 memcpy(ln, o->ln, i);
99 r->ln=ln; 100 r->ln = ln;
100 } 101 }
101 102
102 if (o->sn != NULL) 103 if (o->sn != NULL) {
103 { 104 i = strlen(o->sn) + 1;
104 i=strlen(o->sn)+1; 105 sn = malloc(i);
105 sn=malloc(i); 106 if (sn == NULL)
106 if (sn == NULL) goto err; 107 goto err;
107 memcpy(sn,o->sn,i); 108 memcpy(sn, o->sn, i);
108 r->sn=sn; 109 r->sn = sn;
109 }
110 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
111 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
112 return(r);
113err:
114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
115 if (ln != NULL) free(ln);
116 if (sn != NULL) free(sn);
117 if (data != NULL) free(data);
118 if (r != NULL) free(r);
119 return(NULL);
120 } 110 }
111 r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |
112 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | ASN1_OBJECT_FLAG_DYNAMIC_DATA);
113 return (r);
121 114
122int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b) 115err:
123 { 116 OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);
117 if (ln != NULL)
118 free(ln);
119 if (sn != NULL)
120 free(sn);
121 if (data != NULL)
122 free(data);
123 if (r != NULL)
124 free(r);
125 return (NULL);
126}
127
128int
129OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
130{
124 int ret; 131 int ret;
125 132
126 ret=(a->length-b->length); 133 ret = (a->length - b->length);
127 if (ret) return(ret); 134 if (ret)
128 return(memcmp(a->data,b->data,a->length)); 135 return (ret);
129 } 136 return (memcmp(a->data, b->data, a->length));
137}
diff --git a/src/lib/libssl/src/crypto/objects/obj_xref.c b/src/lib/libssl/src/crypto/objects/obj_xref.c
index 797adc8d10..25aed74ff1 100644
--- a/src/lib/libssl/src/crypto/objects/obj_xref.c
+++ b/src/lib/libssl/src/crypto/objects/obj_xref.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -62,51 +62,54 @@
62DECLARE_STACK_OF(nid_triple) 62DECLARE_STACK_OF(nid_triple)
63STACK_OF(nid_triple) *sig_app, *sigx_app; 63STACK_OF(nid_triple) *sig_app, *sigx_app;
64 64
65static int sig_cmp(const nid_triple *a, const nid_triple *b) 65static int
66 { 66sig_cmp(const nid_triple *a, const nid_triple *b)
67{
67 return a->sign_id - b->sign_id; 68 return a->sign_id - b->sign_id;
68 } 69}
69 70
70DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig); 71DECLARE_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig);
71IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig); 72IMPLEMENT_OBJ_BSEARCH_CMP_FN(nid_triple, nid_triple, sig);
72 73
73static int sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b) 74static int
74 { 75sig_sk_cmp(const nid_triple * const *a, const nid_triple * const *b)
76{
75 return (*a)->sign_id - (*b)->sign_id; 77 return (*a)->sign_id - (*b)->sign_id;
76 } 78}
77 79
78DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx); 80DECLARE_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx);
79 81
80static int sigx_cmp(const nid_triple * const *a, const nid_triple * const *b) 82static int
81 { 83sigx_cmp(const nid_triple * const *a, const nid_triple * const *b)
84{
82 int ret; 85 int ret;
86
83 ret = (*a)->hash_id - (*b)->hash_id; 87 ret = (*a)->hash_id - (*b)->hash_id;
84 if (ret) 88 if (ret)
85 return ret; 89 return ret;
86 return (*a)->pkey_id - (*b)->pkey_id; 90 return (*a)->pkey_id - (*b)->pkey_id;
87 } 91}
88 92
89IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx); 93IMPLEMENT_OBJ_BSEARCH_CMP_FN(const nid_triple *, const nid_triple *, sigx);
90 94
91int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid) 95int
92 { 96OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
97{
93 nid_triple tmp; 98 nid_triple tmp;
94 const nid_triple *rv = NULL; 99 const nid_triple *rv = NULL;
95 tmp.sign_id = signid; 100 tmp.sign_id = signid;
96 101
97 if (sig_app) 102 if (sig_app) {
98 {
99 int idx = sk_nid_triple_find(sig_app, &tmp); 103 int idx = sk_nid_triple_find(sig_app, &tmp);
100 if (idx >= 0) 104 if (idx >= 0)
101 rv = sk_nid_triple_value(sig_app, idx); 105 rv = sk_nid_triple_value(sig_app, idx);
102 } 106 }
103 107
104#ifndef OBJ_XREF_TEST2 108#ifndef OBJ_XREF_TEST2
105 if (rv == NULL) 109 if (rv == NULL) {
106 {
107 rv = OBJ_bsearch_sig(&tmp, sigoid_srt, 110 rv = OBJ_bsearch_sig(&tmp, sigoid_srt,
108 sizeof(sigoid_srt) / sizeof(nid_triple)); 111 sizeof(sigoid_srt) / sizeof(nid_triple));
109 } 112 }
110#endif 113#endif
111 if (rv == NULL) 114 if (rv == NULL)
112 return 0; 115 return 0;
@@ -115,45 +118,44 @@ int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
115 if (ppkey_nid) 118 if (ppkey_nid)
116 *ppkey_nid = rv->pkey_id; 119 *ppkey_nid = rv->pkey_id;
117 return 1; 120 return 1;
118 } 121}
119 122
120int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid) 123int
121 { 124OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
125{
122 nid_triple tmp; 126 nid_triple tmp;
123 const nid_triple *t=&tmp; 127 const nid_triple *t = &tmp;
124 const nid_triple **rv = NULL; 128 const nid_triple **rv = NULL;
125 129
126 tmp.hash_id = dig_nid; 130 tmp.hash_id = dig_nid;
127 tmp.pkey_id = pkey_nid; 131 tmp.pkey_id = pkey_nid;
128 132
129 if (sigx_app) 133 if (sigx_app) {
130 {
131 int idx = sk_nid_triple_find(sigx_app, &tmp); 134 int idx = sk_nid_triple_find(sigx_app, &tmp);
132 if (idx >= 0) 135 if (idx >= 0) {
133 {
134 t = sk_nid_triple_value(sigx_app, idx); 136 t = sk_nid_triple_value(sigx_app, idx);
135 rv = &t; 137 rv = &t;
136 }
137 } 138 }
139 }
138 140
139#ifndef OBJ_XREF_TEST2 141#ifndef OBJ_XREF_TEST2
140 if (rv == NULL) 142 if (rv == NULL) {
141 {
142 rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, 143 rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref,
143 sizeof(sigoid_srt_xref) / sizeof(nid_triple *) 144 sizeof(sigoid_srt_xref) / sizeof(nid_triple *));
144 ); 145 }
145 }
146#endif 146#endif
147 if (rv == NULL) 147 if (rv == NULL)
148 return 0; 148 return 0;
149 if (psignid) 149 if (psignid)
150 *psignid = (*rv)->sign_id; 150 *psignid = (*rv)->sign_id;
151 return 1; 151 return 1;
152 } 152}
153 153
154int OBJ_add_sigid(int signid, int dig_id, int pkey_id) 154int
155 { 155OBJ_add_sigid(int signid, int dig_id, int pkey_id)
156{
156 nid_triple *ntr; 157 nid_triple *ntr;
158
157 if (!sig_app) 159 if (!sig_app)
158 sig_app = sk_nid_triple_new(sig_sk_cmp); 160 sig_app = sk_nid_triple_new(sig_sk_cmp);
159 if (!sig_app) 161 if (!sig_app)
@@ -169,11 +171,10 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
169 ntr->hash_id = dig_id; 171 ntr->hash_id = dig_id;
170 ntr->pkey_id = pkey_id; 172 ntr->pkey_id = pkey_id;
171 173
172 if (!sk_nid_triple_push(sig_app, ntr)) 174 if (!sk_nid_triple_push(sig_app, ntr)) {
173 {
174 free(ntr); 175 free(ntr);
175 return 0; 176 return 0;
176 } 177 }
177 178
178 if (!sk_nid_triple_push(sigx_app, ntr)) 179 if (!sk_nid_triple_push(sigx_app, ntr))
179 return 0; 180 return 0;
@@ -182,53 +183,51 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
182 sk_nid_triple_sort(sigx_app); 183 sk_nid_triple_sort(sigx_app);
183 184
184 return 1; 185 return 1;
185 } 186}
186 187
187static void sid_free(nid_triple *tt) 188static void
188 { 189sid_free(nid_triple *tt)
190{
189 free(tt); 191 free(tt);
190 } 192}
191 193
192void OBJ_sigid_free(void) 194void
193 { 195OBJ_sigid_free(void)
194 if (sig_app) 196{
195 { 197 if (sig_app) {
196 sk_nid_triple_pop_free(sig_app, sid_free); 198 sk_nid_triple_pop_free(sig_app, sid_free);
197 sig_app = NULL; 199 sig_app = NULL;
198 } 200 }
199 if (sigx_app) 201 if (sigx_app) {
200 {
201 sk_nid_triple_free(sigx_app); 202 sk_nid_triple_free(sigx_app);
202 sigx_app = NULL; 203 sigx_app = NULL;
203 }
204 } 204 }
205 205}
206
206#ifdef OBJ_XREF_TEST 207#ifdef OBJ_XREF_TEST
207 208
208main() 209main()
209 { 210{
210 int n1, n2, n3; 211 int n1, n2, n3;
211 212
212 int i, rv; 213 int i, rv;
213#ifdef OBJ_XREF_TEST2 214#ifdef OBJ_XREF_TEST2
214 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) 215 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) {
215 {
216 OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1], 216 OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1],
217 sigoid_srt[i][2]); 217 sigoid_srt[i][2]);
218 } 218 }
219#endif 219#endif
220 220
221 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) 221 for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) {
222 {
223 n1 = sigoid_srt[i][0]; 222 n1 = sigoid_srt[i][0];
224 rv = OBJ_find_sigid_algs(n1, &n2, &n3); 223 rv = OBJ_find_sigid_algs(n1, &n2, &n3);
225 printf("Forward: %d, %s %s %s\n", rv, 224 printf("Forward: %d, %s %s %s\n", rv,
226 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3)); 225 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
227 n1=0; 226 n1 = 0;
228 rv = OBJ_find_sigid_by_algs(&n1, n2, n3); 227 rv = OBJ_find_sigid_by_algs(&n1, n2, n3);
229 printf("Reverse: %d, %s %s %s\n", rv, 228 printf("Reverse: %d, %s %s %s\n", rv,
230 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3)); 229 OBJ_nid2ln(n1), OBJ_nid2ln(n2), OBJ_nid2ln(n3));
231 }
232 } 230 }
233 231}
232
234#endif 233#endif
diff --git a/src/lib/libssl/src/crypto/objects/objects.h b/src/lib/libssl/src/crypto/objects/objects.h
index bd0ee52feb..fa84b67182 100644
--- a/src/lib/libssl/src/crypto/objects/objects.h
+++ b/src/lib/libssl/src/crypto/objects/objects.h
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -387,7 +387,7 @@
387#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" 387#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
388#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" 388#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
389#define NID_pbeWithSHA1AndRC2_CBC 68 389#define NID_pbeWithSHA1AndRC2_CBC 68
390#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L 390#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
391 391
392/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now 392/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
393 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something 393 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
@@ -395,7 +395,7 @@
395 */ 395 */
396#define LN_id_pbkdf2 "PBKDF2" 396#define LN_id_pbkdf2 "PBKDF2"
397#define NID_id_pbkdf2 69 397#define NID_id_pbkdf2 69
398#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L 398#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
399 399
400#define SN_dsaWithSHA1_2 "DSA-SHA1-old" 400#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
401#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" 401#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
@@ -976,29 +976,28 @@
976extern "C" { 976extern "C" {
977#endif 977#endif
978 978
979typedef struct obj_name_st 979typedef struct obj_name_st {
980 {
981 int type; 980 int type;
982 int alias; 981 int alias;
983 const char *name; 982 const char *name;
984 const char *data; 983 const char *data;
985 } OBJ_NAME; 984} OBJ_NAME;
986 985
987#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) 986#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
988 987
989 988
990int OBJ_NAME_init(void); 989int OBJ_NAME_init(void);
991int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *), 990int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
992 int (*cmp_func)(const char *, const char *), 991 int (*cmp_func)(const char *, const char *),
993 void (*free_func)(const char *, int, const char *)); 992 void (*free_func)(const char *, int, const char *));
994const char *OBJ_NAME_get(const char *name,int type); 993const char *OBJ_NAME_get(const char *name, int type);
995int OBJ_NAME_add(const char *name,int type,const char *data); 994int OBJ_NAME_add(const char *name, int type, const char *data);
996int OBJ_NAME_remove(const char *name,int type); 995int OBJ_NAME_remove(const char *name, int type);
997void OBJ_NAME_cleanup(int type); /* -1 for everything */ 996void OBJ_NAME_cleanup(int type); /* -1 for everything */
998void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg), 997void OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg),
999 void *arg); 998 void *arg);
1000void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg), 999void OBJ_NAME_do_all_sorted(int type, void (*fn)(const OBJ_NAME *, void *arg),
1001 void *arg); 1000 void *arg);
1002 1001
1003ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o); 1002ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
1004ASN1_OBJECT * OBJ_nid2obj(int n); 1003ASN1_OBJECT * OBJ_nid2obj(int n);
@@ -1010,13 +1009,12 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
1010int OBJ_txt2nid(const char *s); 1009int OBJ_txt2nid(const char *s);
1011int OBJ_ln2nid(const char *s); 1010int OBJ_ln2nid(const char *s);
1012int OBJ_sn2nid(const char *s); 1011int OBJ_sn2nid(const char *s);
1013int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); 1012int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
1014const void * OBJ_bsearch_(const void *key,const void *base,int num,int size, 1013const void * OBJ_bsearch_(const void *key, const void *base, int num,
1015 int (*cmp)(const void *, const void *)); 1014 int size, int (*cmp)(const void *, const void *));
1016const void * OBJ_bsearch_ex_(const void *key,const void *base,int num, 1015const void * OBJ_bsearch_ex_(const void *key, const void *base, int num,
1017 int size, 1016 int size, int (*cmp)(const void *, const void *),
1018 int (*cmp)(const void *, const void *), 1017 int flags);
1019 int flags);
1020 1018
1021#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ 1019#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \
1022 static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ 1020 static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
@@ -1099,7 +1097,7 @@ const void * OBJ_bsearch_ex_(const void *key,const void *base,int num,
1099 1097
1100int OBJ_new_nid(int num); 1098int OBJ_new_nid(int num);
1101int OBJ_add_object(const ASN1_OBJECT *obj); 1099int OBJ_add_object(const ASN1_OBJECT *obj);
1102int OBJ_create(const char *oid,const char *sn,const char *ln); 1100int OBJ_create(const char *oid, const char *sn, const char *ln);
1103void OBJ_cleanup(void ); 1101void OBJ_cleanup(void );
1104int OBJ_create_objects(BIO *in); 1102int OBJ_create_objects(BIO *in);
1105 1103