Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: openssl/crypto/objects/obj_dat.c

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/crypto/objects/obj_dat.h ('k') | openssl/crypto/objects/obj_dat.pl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* crypto/objects/obj_dat.c */ 1 /* crypto/objects/obj_dat.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
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
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 /* obj_dat.h is generated from objects.h by obj_dat.pl */ 68 /* obj_dat.h is generated from objects.h by obj_dat.pl */
69 #ifndef OPENSSL_NO_OBJECT 69 #ifndef OPENSSL_NO_OBJECT
70 #include "obj_dat.h" 70 #include "obj_dat.h"
71 #else 71 #else
72 /* You will have to load all the objects needed manually in the application */ 72 /* You will have to load all the objects needed manually in the application */
73 #define NUM_NID 0 73 #define NUM_NID 0
74 #define NUM_SN 0 74 #define NUM_SN 0
75 #define NUM_LN 0 75 #define NUM_LN 0
76 #define NUM_OBJ 0 76 #define NUM_OBJ 0
77 static unsigned char lvalues[1]; 77 static const unsigned char lvalues[1];
78 static ASN1_OBJECT nid_objs[1]; 78 static const ASN1_OBJECT nid_objs[1];
79 static ASN1_OBJECT *sn_objs[1]; 79 static const unsigned int sn_objs[1];
80 static ASN1_OBJECT *ln_objs[1]; 80 static const unsigned int ln_objs[1];
81 static ASN1_OBJECT *obj_objs[1]; 81 static const unsigned int obj_objs[1];
82 #endif 82 #endif
83 83
84 static int sn_cmp(const void *a, const void *b); 84 DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
85 static int ln_cmp(const void *a, const void *b); 85 DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
86 static int obj_cmp(const void *a, const void *b); 86 DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
87
87 #define ADDED_DATA 0 88 #define ADDED_DATA 0
88 #define ADDED_SNAME 1 89 #define ADDED_SNAME 1
89 #define ADDED_LNAME 2 90 #define ADDED_LNAME 2
90 #define ADDED_NID 3 91 #define ADDED_NID 3
91 92
92 typedef struct added_obj_st 93 typedef struct added_obj_st
93 { 94 {
94 int type; 95 int type;
95 ASN1_OBJECT *obj; 96 ASN1_OBJECT *obj;
96 } ADDED_OBJ; 97 } ADDED_OBJ;
98 DECLARE_LHASH_OF(ADDED_OBJ);
97 99
98 static int new_nid=NUM_NID; 100 static int new_nid=NUM_NID;
99 static LHASH *added=NULL; 101 static LHASH_OF(ADDED_OBJ) *added=NULL;
100 102
101 static int sn_cmp(const void *a, const void *b) 103 static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
102 » { 104 » { return(strcmp((*a)->sn,nid_objs[*b].sn)); }
103 » const ASN1_OBJECT * const *ap = a, * const *bp = b;
104 » return(strcmp((*ap)->sn,(*bp)->sn));
105 » }
106 105
107 static int ln_cmp(const void *a, const void *b) 106 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
108 » {
109 » const ASN1_OBJECT * const *ap = a, * const *bp = b;
110 » return(strcmp((*ap)->ln,(*bp)->ln));
111 » }
112 107
113 /* static unsigned long add_hash(ADDED_OBJ *ca) */ 108 static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
114 static unsigned long add_hash(const void *ca_void) 109 » { return(strcmp((*a)->ln,nid_objs[*b].ln)); }
110
111 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
112
113 static unsigned long added_obj_hash(const ADDED_OBJ *ca)
115 { 114 {
116 const ASN1_OBJECT *a; 115 const ASN1_OBJECT *a;
117 int i; 116 int i;
118 unsigned long ret=0; 117 unsigned long ret=0;
119 unsigned char *p; 118 unsigned char *p;
120 const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void;
121 119
122 a=ca->obj; 120 a=ca->obj;
123 switch (ca->type) 121 switch (ca->type)
124 { 122 {
125 case ADDED_DATA: 123 case ADDED_DATA:
126 ret=a->length<<20L; 124 ret=a->length<<20L;
127 p=(unsigned char *)a->data; 125 p=(unsigned char *)a->data;
128 for (i=0; i<a->length; i++) 126 for (i=0; i<a->length; i++)
129 ret^=p[i]<<((i*3)%24); 127 ret^=p[i]<<((i*3)%24);
130 break; 128 break;
131 case ADDED_SNAME: 129 case ADDED_SNAME:
132 ret=lh_strhash(a->sn); 130 ret=lh_strhash(a->sn);
133 break; 131 break;
134 case ADDED_LNAME: 132 case ADDED_LNAME:
135 ret=lh_strhash(a->ln); 133 ret=lh_strhash(a->ln);
136 break; 134 break;
137 case ADDED_NID: 135 case ADDED_NID:
138 ret=a->nid; 136 ret=a->nid;
139 break; 137 break;
140 default: 138 default:
141 /* abort(); */ 139 /* abort(); */
142 return 0; 140 return 0;
143 } 141 }
144 ret&=0x3fffffffL; 142 ret&=0x3fffffffL;
145 ret|=ca->type<<30L; 143 ret|=ca->type<<30L;
146 return(ret); 144 return(ret);
147 } 145 }
146 static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ)
148 147
149 /* static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) */ 148 static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
150 static int add_cmp(const void *ca_void, const void *cb_void)
151 { 149 {
152 ASN1_OBJECT *a,*b; 150 ASN1_OBJECT *a,*b;
153 int i; 151 int i;
154 const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void;
155 const ADDED_OBJ *cb = (const ADDED_OBJ *)cb_void;
156 152
157 i=ca->type-cb->type; 153 i=ca->type-cb->type;
158 if (i) return(i); 154 if (i) return(i);
159 a=ca->obj; 155 a=ca->obj;
160 b=cb->obj; 156 b=cb->obj;
161 switch (ca->type) 157 switch (ca->type)
162 { 158 {
163 case ADDED_DATA: 159 case ADDED_DATA:
164 i=(a->length - b->length); 160 i=(a->length - b->length);
165 if (i) return(i); 161 if (i) return(i);
166 return(memcmp(a->data,b->data,(size_t)a->length)); 162 return(memcmp(a->data,b->data,(size_t)a->length));
167 case ADDED_SNAME: 163 case ADDED_SNAME:
168 if (a->sn == NULL) return(-1); 164 if (a->sn == NULL) return(-1);
169 else if (b->sn == NULL) return(1); 165 else if (b->sn == NULL) return(1);
170 else return(strcmp(a->sn,b->sn)); 166 else return(strcmp(a->sn,b->sn));
171 case ADDED_LNAME: 167 case ADDED_LNAME:
172 if (a->ln == NULL) return(-1); 168 if (a->ln == NULL) return(-1);
173 else if (b->ln == NULL) return(1); 169 else if (b->ln == NULL) return(1);
174 else return(strcmp(a->ln,b->ln)); 170 else return(strcmp(a->ln,b->ln));
175 case ADDED_NID: 171 case ADDED_NID:
176 return(a->nid-b->nid); 172 return(a->nid-b->nid);
177 default: 173 default:
178 /* abort(); */ 174 /* abort(); */
179 return 0; 175 return 0;
180 } 176 }
181 } 177 }
178 static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
182 179
183 static int init_added(void) 180 static int init_added(void)
184 { 181 {
185 if (added != NULL) return(1); 182 if (added != NULL) return(1);
186 » added=lh_new(add_hash,add_cmp); 183 » added=lh_ADDED_OBJ_new();
187 return(added != NULL); 184 return(added != NULL);
188 } 185 }
189 186
190 static void cleanup1(ADDED_OBJ *a) 187 static void cleanup1_doall(ADDED_OBJ *a)
191 { 188 {
192 a->obj->nid=0; 189 a->obj->nid=0;
193 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| 190 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
194 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 191 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
195 ASN1_OBJECT_FLAG_DYNAMIC_DATA; 192 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
196 } 193 }
197 194
198 static void cleanup2(ADDED_OBJ *a) 195 static void cleanup2_doall(ADDED_OBJ *a)
199 { a->obj->nid++; } 196 { a->obj->nid++; }
200 197
201 static void cleanup3(ADDED_OBJ *a) 198 static void cleanup3_doall(ADDED_OBJ *a)
202 { 199 {
203 if (--a->obj->nid == 0) 200 if (--a->obj->nid == 0)
204 ASN1_OBJECT_free(a->obj); 201 ASN1_OBJECT_free(a->obj);
205 OPENSSL_free(a); 202 OPENSSL_free(a);
206 } 203 }
207 204
208 static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ *) 205 static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ)
209 static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ *) 206 static IMPLEMENT_LHASH_DOALL_FN(cleanup2, ADDED_OBJ)
210 static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ *) 207 static IMPLEMENT_LHASH_DOALL_FN(cleanup3, ADDED_OBJ)
208
209 /* The purpose of obj_cleanup_defer is to avoid EVP_cleanup() attempting
210 * to use freed up OIDs. If neccessary the actual freeing up of OIDs is
211 * delayed.
212 */
213
214 int obj_cleanup_defer = 0;
215
216 void check_defer(int nid)
217 » {
218 » if (!obj_cleanup_defer && nid >= NUM_NID)
219 » » » obj_cleanup_defer = 1;
220 » }
211 221
212 void OBJ_cleanup(void) 222 void OBJ_cleanup(void)
213 { 223 {
224 if (obj_cleanup_defer)
225 {
226 obj_cleanup_defer = 2;
227 return ;
228 }
214 if (added == NULL) return; 229 if (added == NULL) return;
215 » added->down_load=0; 230 » lh_ADDED_OBJ_down_load(added) = 0;
216 » lh_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */ 231 » lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup1)); /* zero counters */
217 » lh_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */ 232 » lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup2)); /* set counters */
218 » lh_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */ 233 » lh_ADDED_OBJ_doall(added,LHASH_DOALL_FN(cleanup3)); /* free objects */
219 » lh_free(added); 234 » lh_ADDED_OBJ_free(added);
220 added=NULL; 235 added=NULL;
221 } 236 }
222 237
223 int OBJ_new_nid(int num) 238 int OBJ_new_nid(int num)
224 { 239 {
225 int i; 240 int i;
226 241
227 i=new_nid; 242 i=new_nid;
228 new_nid+=num; 243 new_nid+=num;
229 return(i); 244 return(i);
(...skipping 15 matching lines...) Expand all
245 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_O BJ)))) goto err2; 260 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_O BJ)))) goto err2;
246 if (o->ln != NULL) 261 if (o->ln != NULL)
247 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_O BJ)))) goto err2; 262 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_O BJ)))) goto err2;
248 263
249 for (i=ADDED_DATA; i<=ADDED_NID; i++) 264 for (i=ADDED_DATA; i<=ADDED_NID; i++)
250 { 265 {
251 if (ao[i] != NULL) 266 if (ao[i] != NULL)
252 { 267 {
253 ao[i]->type=i; 268 ao[i]->type=i;
254 ao[i]->obj=o; 269 ao[i]->obj=o;
255 » » » aop=(ADDED_OBJ *)lh_insert(added,ao[i]); 270 » » » aop=lh_ADDED_OBJ_insert(added,ao[i]);
256 /* memory leak, buit should not normally matter */ 271 /* memory leak, buit should not normally matter */
257 if (aop != NULL) 272 if (aop != NULL)
258 OPENSSL_free(aop); 273 OPENSSL_free(aop);
259 } 274 }
260 } 275 }
261 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 276 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
262 ASN1_OBJECT_FLAG_DYNAMIC_DATA); 277 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
263 278
264 return(o->nid); 279 return(o->nid);
265 err2: 280 err2:
(...skipping 19 matching lines...) Expand all
285 } 300 }
286 return((ASN1_OBJECT *)&(nid_objs[n])); 301 return((ASN1_OBJECT *)&(nid_objs[n]));
287 } 302 }
288 else if (added == NULL) 303 else if (added == NULL)
289 return(NULL); 304 return(NULL);
290 else 305 else
291 { 306 {
292 ad.type=ADDED_NID; 307 ad.type=ADDED_NID;
293 ad.obj= &ob; 308 ad.obj= &ob;
294 ob.nid=n; 309 ob.nid=n;
295 » » adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 310 » » adp=lh_ADDED_OBJ_retrieve(added,&ad);
296 if (adp != NULL) 311 if (adp != NULL)
297 return(adp->obj); 312 return(adp->obj);
298 else 313 else
299 { 314 {
300 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID); 315 OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);
301 return(NULL); 316 return(NULL);
302 } 317 }
303 } 318 }
304 } 319 }
305 320
(...skipping 11 matching lines...) Expand all
317 } 332 }
318 return(nid_objs[n].sn); 333 return(nid_objs[n].sn);
319 } 334 }
320 else if (added == NULL) 335 else if (added == NULL)
321 return(NULL); 336 return(NULL);
322 else 337 else
323 { 338 {
324 ad.type=ADDED_NID; 339 ad.type=ADDED_NID;
325 ad.obj= &ob; 340 ad.obj= &ob;
326 ob.nid=n; 341 ob.nid=n;
327 » » adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 342 » » adp=lh_ADDED_OBJ_retrieve(added,&ad);
328 if (adp != NULL) 343 if (adp != NULL)
329 return(adp->obj->sn); 344 return(adp->obj->sn);
330 else 345 else
331 { 346 {
332 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID); 347 OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);
333 return(NULL); 348 return(NULL);
334 } 349 }
335 } 350 }
336 } 351 }
337 352
(...skipping 11 matching lines...) Expand all
349 } 364 }
350 return(nid_objs[n].ln); 365 return(nid_objs[n].ln);
351 } 366 }
352 else if (added == NULL) 367 else if (added == NULL)
353 return(NULL); 368 return(NULL);
354 else 369 else
355 { 370 {
356 ad.type=ADDED_NID; 371 ad.type=ADDED_NID;
357 ad.obj= &ob; 372 ad.obj= &ob;
358 ob.nid=n; 373 ob.nid=n;
359 » » adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 374 » » adp=lh_ADDED_OBJ_retrieve(added,&ad);
360 if (adp != NULL) 375 if (adp != NULL)
361 return(adp->obj->ln); 376 return(adp->obj->ln);
362 else 377 else
363 { 378 {
364 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID); 379 OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);
365 return(NULL); 380 return(NULL);
366 } 381 }
367 } 382 }
368 } 383 }
369 384
385 static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
386 {
387 int j;
388 const ASN1_OBJECT *a= *ap;
389 const ASN1_OBJECT *b= &nid_objs[*bp];
390
391 j=(a->length - b->length);
392 if (j) return(j);
393 return(memcmp(a->data,b->data,a->length));
394 }
395
396 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
397
370 int OBJ_obj2nid(const ASN1_OBJECT *a) 398 int OBJ_obj2nid(const ASN1_OBJECT *a)
371 { 399 {
372 » ASN1_OBJECT **op; 400 » const unsigned int *op;
373 ADDED_OBJ ad,*adp; 401 ADDED_OBJ ad,*adp;
374 402
375 if (a == NULL) 403 if (a == NULL)
376 return(NID_undef); 404 return(NID_undef);
377 if (a->nid != 0) 405 if (a->nid != 0)
378 return(a->nid); 406 return(a->nid);
379 407
380 if (added != NULL) 408 if (added != NULL)
381 { 409 {
382 ad.type=ADDED_DATA; 410 ad.type=ADDED_DATA;
383 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */ 411 ad.obj=(ASN1_OBJECT *)a; /* XXX: ugly but harmless */
384 » » adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 412 » » adp=lh_ADDED_OBJ_retrieve(added,&ad);
385 if (adp != NULL) return (adp->obj->nid); 413 if (adp != NULL) return (adp->obj->nid);
386 } 414 }
387 » op=(ASN1_OBJECT **)OBJ_bsearch((const char *)&a,(const char *)obj_objs, 415 » op=OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
388 » » NUM_OBJ, sizeof(ASN1_OBJECT *),obj_cmp);
389 if (op == NULL) 416 if (op == NULL)
390 return(NID_undef); 417 return(NID_undef);
391 » return((*op)->nid); 418 » return(nid_objs[*op].nid);
392 } 419 }
393 420
394 /* Convert an object name into an ASN1_OBJECT 421 /* Convert an object name into an ASN1_OBJECT
395 * if "noname" is not set then search for short and long names first. 422 * if "noname" is not set then search for short and long names first.
396 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid 423 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
397 * it can be used with any objects, not just registered ones. 424 * it can be used with any objects, not just registered ones.
398 */ 425 */
399 426
400 ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) 427 ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
401 { 428 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 op=d2i_ASN1_OBJECT(NULL,&cp,j); 461 op=d2i_ASN1_OBJECT(NULL,&cp,j);
435 OPENSSL_free(buf); 462 OPENSSL_free(buf);
436 return op; 463 return op;
437 } 464 }
438 465
439 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) 466 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
440 { 467 {
441 int i,n=0,len,nid, first, use_bn; 468 int i,n=0,len,nid, first, use_bn;
442 BIGNUM *bl; 469 BIGNUM *bl;
443 unsigned long l; 470 unsigned long l;
444 » unsigned char *p; 471 » const unsigned char *p;
445 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2]; 472 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
446 473
447 if ((a == NULL) || (a->data == NULL)) { 474 if ((a == NULL) || (a->data == NULL)) {
448 buf[0]='\0'; 475 buf[0]='\0';
449 return(0); 476 return(0);
450 } 477 }
451 478
452 479
453 if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef) 480 if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef)
454 { 481 {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 ASN1_OBJECT *obj; 630 ASN1_OBJECT *obj;
604 int nid; 631 int nid;
605 obj = OBJ_txt2obj(s, 0); 632 obj = OBJ_txt2obj(s, 0);
606 nid = OBJ_obj2nid(obj); 633 nid = OBJ_obj2nid(obj);
607 ASN1_OBJECT_free(obj); 634 ASN1_OBJECT_free(obj);
608 return nid; 635 return nid;
609 } 636 }
610 637
611 int OBJ_ln2nid(const char *s) 638 int OBJ_ln2nid(const char *s)
612 { 639 {
613 » ASN1_OBJECT o,*oo= &o,**op; 640 » ASN1_OBJECT o;
641 » const ASN1_OBJECT *oo= &o;
614 ADDED_OBJ ad,*adp; 642 ADDED_OBJ ad,*adp;
643 const unsigned int *op;
615 644
616 o.ln=s; 645 o.ln=s;
617 if (added != NULL) 646 if (added != NULL)
618 { 647 {
619 ad.type=ADDED_LNAME; 648 ad.type=ADDED_LNAME;
620 ad.obj= &o; 649 ad.obj= &o;
621 » » adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 650 » » adp=lh_ADDED_OBJ_retrieve(added,&ad);
622 if (adp != NULL) return (adp->obj->nid); 651 if (adp != NULL) return (adp->obj->nid);
623 } 652 }
624 » op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN, 653 » op=OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
625 » » sizeof(ASN1_OBJECT *),ln_cmp);
626 if (op == NULL) return(NID_undef); 654 if (op == NULL) return(NID_undef);
627 » return((*op)->nid); 655 » return(nid_objs[*op].nid);
628 } 656 }
629 657
630 int OBJ_sn2nid(const char *s) 658 int OBJ_sn2nid(const char *s)
631 { 659 {
632 » ASN1_OBJECT o,*oo= &o,**op; 660 » ASN1_OBJECT o;
661 » const ASN1_OBJECT *oo= &o;
633 ADDED_OBJ ad,*adp; 662 ADDED_OBJ ad,*adp;
663 const unsigned int *op;
634 664
635 o.sn=s; 665 o.sn=s;
636 if (added != NULL) 666 if (added != NULL)
637 { 667 {
638 ad.type=ADDED_SNAME; 668 ad.type=ADDED_SNAME;
639 ad.obj= &o; 669 ad.obj= &o;
640 » » adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 670 » » adp=lh_ADDED_OBJ_retrieve(added,&ad);
641 if (adp != NULL) return (adp->obj->nid); 671 if (adp != NULL) return (adp->obj->nid);
642 } 672 }
643 » op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN, 673 » op=OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
644 » » sizeof(ASN1_OBJECT *),sn_cmp);
645 if (op == NULL) return(NID_undef); 674 if (op == NULL) return(NID_undef);
646 » return((*op)->nid); 675 » return(nid_objs[*op].nid);
647 } 676 }
648 677
649 static int obj_cmp(const void *ap, const void *bp) 678 const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
679 » » » int (*cmp)(const void *, const void *))
650 { 680 {
651 » int j; 681 » return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
652 » const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap;
653 » const ASN1_OBJECT *b= *(ASN1_OBJECT * const *)bp;
654
655 » j=(a->length - b->length);
656 if (j) return(j);
657 » return(memcmp(a->data,b->data,a->length));
658 }
659
660 const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
661 » int (*cmp)(const void *, const void *))
662 » {
663 » return OBJ_bsearch_ex(key, base, num, size, cmp, 0);
664 } 682 }
665 683
666 const char *OBJ_bsearch_ex(const char *key, const char *base, int num, 684 const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num,
667 » int size, int (*cmp)(const void *, const void *), int flags) 685 » » » int size,
686 » » » int (*cmp)(const void *, const void *),
687 » » » int flags)
668 { 688 {
689 const char *base=base_;
669 int l,h,i=0,c=0; 690 int l,h,i=0,c=0;
670 const char *p = NULL; 691 const char *p = NULL;
671 692
672 if (num == 0) return(NULL); 693 if (num == 0) return(NULL);
673 l=0; 694 l=0;
674 h=num; 695 h=num;
675 while (l < h) 696 while (l < h)
676 { 697 {
677 i=(l+h)/2; 698 i=(l+h)/2;
678 p= &(base[i*size]); 699 p= &(base[i*size]);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); 801 op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
781 if (op == NULL) 802 if (op == NULL)
782 goto err; 803 goto err;
783 ok=OBJ_add_object(op); 804 ok=OBJ_add_object(op);
784 err: 805 err:
785 ASN1_OBJECT_free(op); 806 ASN1_OBJECT_free(op);
786 OPENSSL_free(buf); 807 OPENSSL_free(buf);
787 return(ok); 808 return(ok);
788 } 809 }
789 810
OLDNEW
« no previous file with comments | « openssl/crypto/objects/obj_dat.h ('k') | openssl/crypto/objects/obj_dat.pl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698