diff options
Diffstat (limited to 'src/lib/libcrypto/objects/obj_dat.c')
-rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 254 |
1 files changed, 68 insertions, 186 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 7fd7433241..f549d078ef 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
@@ -58,12 +58,10 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <ctype.h> | 60 | #include <ctype.h> |
61 | #include <limits.h> | ||
62 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
63 | #include <openssl/lhash.h> | 62 | #include <openssl/lhash.h> |
64 | #include <openssl/asn1.h> | 63 | #include <openssl/asn1.h> |
65 | #include <openssl/objects.h> | 64 | #include <openssl/objects.h> |
66 | #include <openssl/bn.h> | ||
67 | 65 | ||
68 | /* obj_dat.h is generated from objects.h by obj_dat.pl */ | 66 | /* obj_dat.h is generated from objects.h by obj_dat.pl */ |
69 | #ifndef OPENSSL_NO_OBJECT | 67 | #ifndef OPENSSL_NO_OBJECT |
@@ -117,7 +115,7 @@ static unsigned long add_hash(const void *ca_void) | |||
117 | int i; | 115 | int i; |
118 | unsigned long ret=0; | 116 | unsigned long ret=0; |
119 | unsigned char *p; | 117 | unsigned char *p; |
120 | const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void; | 118 | ADDED_OBJ *ca = (ADDED_OBJ *)ca_void; |
121 | 119 | ||
122 | a=ca->obj; | 120 | a=ca->obj; |
123 | switch (ca->type) | 121 | switch (ca->type) |
@@ -151,8 +149,8 @@ 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; | 152 | ADDED_OBJ *ca = (ADDED_OBJ *)ca_void; |
155 | const ADDED_OBJ *cb = (const ADDED_OBJ *)cb_void; | 153 | ADDED_OBJ *cb = (ADDED_OBJ *)cb_void; |
156 | 154 | ||
157 | i=ca->type-cb->type; | 155 | i=ca->type-cb->type; |
158 | if (i) return(i); | 156 | if (i) return(i); |
@@ -163,7 +161,7 @@ static int add_cmp(const void *ca_void, const void *cb_void) | |||
163 | case ADDED_DATA: | 161 | case ADDED_DATA: |
164 | i=(a->length - b->length); | 162 | i=(a->length - b->length); |
165 | if (i) return(i); | 163 | if (i) return(i); |
166 | return(memcmp(a->data,b->data,(size_t)a->length)); | 164 | return(memcmp(a->data,b->data,a->length)); |
167 | case ADDED_SNAME: | 165 | case ADDED_SNAME: |
168 | if (a->sn == NULL) return(-1); | 166 | if (a->sn == NULL) return(-1); |
169 | else if (b->sn == NULL) return(1); | 167 | else if (b->sn == NULL) return(1); |
@@ -384,8 +382,8 @@ int OBJ_obj2nid(const ASN1_OBJECT *a) | |||
384 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); | 382 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
385 | if (adp != NULL) return (adp->obj->nid); | 383 | if (adp != NULL) return (adp->obj->nid); |
386 | } | 384 | } |
387 | op=(ASN1_OBJECT **)OBJ_bsearch((const char *)&a,(const char *)obj_objs, | 385 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ, |
388 | NUM_OBJ, sizeof(ASN1_OBJECT *),obj_cmp); | 386 | sizeof(ASN1_OBJECT *),obj_cmp); |
389 | if (op == NULL) | 387 | if (op == NULL) |
390 | return(NID_undef); | 388 | return(NID_undef); |
391 | return((*op)->nid); | 389 | return((*op)->nid); |
@@ -401,9 +399,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) | |||
401 | { | 399 | { |
402 | int nid = NID_undef; | 400 | int nid = NID_undef; |
403 | ASN1_OBJECT *op=NULL; | 401 | ASN1_OBJECT *op=NULL; |
404 | unsigned char *buf; | 402 | unsigned char *buf,*p; |
405 | unsigned char *p; | ||
406 | const unsigned char *cp; | ||
407 | int i, j; | 403 | int i, j; |
408 | 404 | ||
409 | if(!no_name) { | 405 | if(!no_name) { |
@@ -415,8 +411,8 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) | |||
415 | /* Work out size of content octets */ | 411 | /* Work out size of content octets */ |
416 | i=a2d_ASN1_OBJECT(NULL,0,s,-1); | 412 | i=a2d_ASN1_OBJECT(NULL,0,s,-1); |
417 | if (i <= 0) { | 413 | if (i <= 0) { |
418 | /* Don't clear the error */ | 414 | /* Clear the error */ |
419 | /*ERR_clear_error();*/ | 415 | ERR_get_error(); |
420 | return NULL; | 416 | return NULL; |
421 | } | 417 | } |
422 | /* Work out total size */ | 418 | /* Work out total size */ |
@@ -429,170 +425,75 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) | |||
429 | ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | 425 | ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); |
430 | /* Write out contents */ | 426 | /* Write out contents */ |
431 | a2d_ASN1_OBJECT(p,i,s,-1); | 427 | a2d_ASN1_OBJECT(p,i,s,-1); |
432 | 428 | ||
433 | cp=buf; | 429 | p=buf; |
434 | op=d2i_ASN1_OBJECT(NULL,&cp,j); | 430 | op=d2i_ASN1_OBJECT(NULL,&p,j); |
435 | OPENSSL_free(buf); | 431 | OPENSSL_free(buf); |
436 | return op; | 432 | return op; |
437 | } | 433 | } |
438 | 434 | ||
439 | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | 435 | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) |
440 | { | 436 | { |
441 | int i,n=0,len,nid, first, use_bn; | 437 | int i,idx=0,n=0,len,nid; |
442 | BIGNUM *bl; | ||
443 | unsigned long l; | 438 | unsigned long l; |
444 | unsigned char *p; | 439 | unsigned char *p; |
440 | const char *s; | ||
445 | char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2]; | 441 | char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2]; |
446 | 442 | ||
443 | if (buf_len <= 0) return(0); | ||
444 | |||
447 | if ((a == NULL) || (a->data == NULL)) { | 445 | if ((a == NULL) || (a->data == NULL)) { |
448 | buf[0]='\0'; | 446 | buf[0]='\0'; |
449 | return(0); | 447 | return(0); |
450 | } | 448 | } |
451 | 449 | ||
450 | if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) { | ||
451 | len=a->length; | ||
452 | p=a->data; | ||
452 | 453 | ||
453 | if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef) | 454 | idx=0; |
454 | { | 455 | l=0; |
455 | const char *s; | 456 | while (idx < a->length) { |
456 | s=OBJ_nid2ln(nid); | 457 | l|=(p[idx]&0x7f); |
457 | if (s == NULL) | 458 | if (!(p[idx] & 0x80)) break; |
458 | s=OBJ_nid2sn(nid); | 459 | l<<=7L; |
459 | if (buf) | 460 | idx++; |
460 | BUF_strlcpy(buf,s,buf_len); | ||
461 | n=strlen(s); | ||
462 | return n; | ||
463 | } | 461 | } |
462 | idx++; | ||
463 | i=(int)(l/40); | ||
464 | if (i > 2) i=2; | ||
465 | l-=(long)(i*40); | ||
466 | |||
467 | BIO_snprintf(tbuf,sizeof tbuf,"%d.%lu",i,l); | ||
468 | i=strlen(tbuf); | ||
469 | BUF_strlcpy(buf,tbuf,buf_len); | ||
470 | buf_len-=i; | ||
471 | buf+=i; | ||
472 | n+=i; | ||
464 | 473 | ||
465 | |||
466 | len=a->length; | ||
467 | p=a->data; | ||
468 | |||
469 | first = 1; | ||
470 | bl = NULL; | ||
471 | |||
472 | while (len > 0) | ||
473 | { | ||
474 | l=0; | 474 | l=0; |
475 | use_bn = 0; | 475 | for (; idx<len; idx++) { |
476 | for (;;) | 476 | l|=p[idx]&0x7f; |
477 | { | 477 | if (!(p[idx] & 0x80)) { |
478 | unsigned char c = *p++; | 478 | BIO_snprintf(tbuf,sizeof tbuf,".%lu",l); |
479 | len--; | 479 | i=strlen(tbuf); |
480 | if ((len == 0) && (c & 0x80)) | ||
481 | goto err; | ||
482 | if (use_bn) | ||
483 | { | ||
484 | if (!BN_add_word(bl, c & 0x7f)) | ||
485 | goto err; | ||
486 | } | ||
487 | else | ||
488 | l |= c & 0x7f; | ||
489 | if (!(c & 0x80)) | ||
490 | break; | ||
491 | if (!use_bn && (l > (ULONG_MAX >> 7L))) | ||
492 | { | ||
493 | if (!bl && !(bl = BN_new())) | ||
494 | goto err; | ||
495 | if (!BN_set_word(bl, l)) | ||
496 | goto err; | ||
497 | use_bn = 1; | ||
498 | } | ||
499 | if (use_bn) | ||
500 | { | ||
501 | if (!BN_lshift(bl, bl, 7)) | ||
502 | goto err; | ||
503 | } | ||
504 | else | ||
505 | l<<=7L; | ||
506 | } | ||
507 | |||
508 | if (first) | ||
509 | { | ||
510 | first = 0; | ||
511 | if (l >= 80) | ||
512 | { | ||
513 | i = 2; | ||
514 | if (use_bn) | ||
515 | { | ||
516 | if (!BN_sub_word(bl, 80)) | ||
517 | goto err; | ||
518 | } | ||
519 | else | ||
520 | l -= 80; | ||
521 | } | ||
522 | else | ||
523 | { | ||
524 | i=(int)(l/40); | ||
525 | l-=(long)(i*40); | ||
526 | } | ||
527 | if (buf && (buf_len > 0)) | ||
528 | { | ||
529 | *buf++ = i + '0'; | ||
530 | buf_len--; | ||
531 | } | ||
532 | n++; | ||
533 | } | ||
534 | |||
535 | if (use_bn) | ||
536 | { | ||
537 | char *bndec; | ||
538 | bndec = BN_bn2dec(bl); | ||
539 | if (!bndec) | ||
540 | goto err; | ||
541 | i = strlen(bndec); | ||
542 | if (buf) | ||
543 | { | ||
544 | if (buf_len > 0) | 480 | if (buf_len > 0) |
545 | { | 481 | BUF_strlcpy(buf,tbuf,buf_len); |
546 | *buf++ = '.'; | 482 | buf_len-=i; |
547 | buf_len--; | 483 | buf+=i; |
548 | } | 484 | n+=i; |
549 | BUF_strlcpy(buf,bndec,buf_len); | 485 | l=0; |
550 | if (i > buf_len) | ||
551 | { | ||
552 | buf += buf_len; | ||
553 | buf_len = 0; | ||
554 | } | ||
555 | else | ||
556 | { | ||
557 | buf+=i; | ||
558 | buf_len-=i; | ||
559 | } | ||
560 | } | ||
561 | n++; | ||
562 | n += i; | ||
563 | OPENSSL_free(bndec); | ||
564 | } | ||
565 | else | ||
566 | { | ||
567 | BIO_snprintf(tbuf,sizeof tbuf,".%lu",l); | ||
568 | i=strlen(tbuf); | ||
569 | if (buf && (buf_len > 0)) | ||
570 | { | ||
571 | BUF_strlcpy(buf,tbuf,buf_len); | ||
572 | if (i > buf_len) | ||
573 | { | ||
574 | buf += buf_len; | ||
575 | buf_len = 0; | ||
576 | } | ||
577 | else | ||
578 | { | ||
579 | buf+=i; | ||
580 | buf_len-=i; | ||
581 | } | ||
582 | } | ||
583 | n+=i; | ||
584 | l=0; | ||
585 | } | 486 | } |
487 | l<<=7L; | ||
586 | } | 488 | } |
587 | 489 | } else { | |
588 | if (bl) | 490 | s=OBJ_nid2ln(nid); |
589 | BN_free(bl); | 491 | if (s == NULL) |
590 | return n; | 492 | s=OBJ_nid2sn(nid); |
591 | 493 | BUF_strlcpy(buf,s,buf_len); | |
592 | err: | 494 | n=strlen(s); |
593 | if (bl) | 495 | } |
594 | BN_free(bl); | 496 | return(n); |
595 | return -1; | ||
596 | } | 497 | } |
597 | 498 | ||
598 | int OBJ_txt2nid(const char *s) | 499 | int OBJ_txt2nid(const char *s) |
@@ -618,7 +519,7 @@ int OBJ_ln2nid(const char *s) | |||
618 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); | 519 | adp=(ADDED_OBJ *)lh_retrieve(added,&ad); |
619 | if (adp != NULL) return (adp->obj->nid); | 520 | if (adp != NULL) return (adp->obj->nid); |
620 | } | 521 | } |
621 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN, | 522 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN, |
622 | sizeof(ASN1_OBJECT *),ln_cmp); | 523 | sizeof(ASN1_OBJECT *),ln_cmp); |
623 | if (op == NULL) return(NID_undef); | 524 | if (op == NULL) return(NID_undef); |
624 | return((*op)->nid); | 525 | return((*op)->nid); |
@@ -646,8 +547,8 @@ int OBJ_sn2nid(const char *s) | |||
646 | static int obj_cmp(const void *ap, const void *bp) | 547 | static int obj_cmp(const void *ap, const void *bp) |
647 | { | 548 | { |
648 | int j; | 549 | int j; |
649 | const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap; | 550 | ASN1_OBJECT *a= *(ASN1_OBJECT **)ap; |
650 | const ASN1_OBJECT *b= *(ASN1_OBJECT * const *)bp; | 551 | ASN1_OBJECT *b= *(ASN1_OBJECT **)bp; |
651 | 552 | ||
652 | j=(a->length - b->length); | 553 | j=(a->length - b->length); |
653 | if (j) return(j); | 554 | if (j) return(j); |
@@ -657,14 +558,8 @@ static int obj_cmp(const void *ap, const void *bp) | |||
657 | const char *OBJ_bsearch(const char *key, const char *base, int num, int size, | 558 | const char *OBJ_bsearch(const char *key, const char *base, int num, int size, |
658 | int (*cmp)(const void *, const void *)) | 559 | int (*cmp)(const void *, const void *)) |
659 | { | 560 | { |
660 | return OBJ_bsearch_ex(key, base, num, size, cmp, 0); | 561 | int l,h,i,c; |
661 | } | 562 | const char *p; |
662 | |||
663 | const char *OBJ_bsearch_ex(const char *key, const char *base, int num, | ||
664 | int size, int (*cmp)(const void *, const void *), int flags) | ||
665 | { | ||
666 | int l,h,i=0,c=0; | ||
667 | const char *p = NULL; | ||
668 | 563 | ||
669 | if (num == 0) return(NULL); | 564 | if (num == 0) return(NULL); |
670 | l=0; | 565 | l=0; |
@@ -679,33 +574,20 @@ const char *OBJ_bsearch_ex(const char *key, const char *base, int num, | |||
679 | else if (c > 0) | 574 | else if (c > 0) |
680 | l=i+1; | 575 | l=i+1; |
681 | else | 576 | else |
682 | break; | 577 | return(p); |
683 | } | 578 | } |
684 | #ifdef CHARSET_EBCDIC | 579 | #ifdef CHARSET_EBCDIC |
685 | /* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and | 580 | /* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and |
686 | * I don't have perl (yet), we revert to a *LINEAR* search | 581 | * I don't have perl (yet), we revert to a *LINEAR* search |
687 | * when the object wasn't found in the binary search. | 582 | * when the object wasn't found in the binary search. |
688 | */ | 583 | */ |
689 | if (c != 0) | 584 | for (i=0; i<num; ++i) { |
690 | { | 585 | p= &(base[i*size]); |
691 | for (i=0; i<num; ++i) | 586 | if ((*cmp)(key,p) == 0) |
692 | { | 587 | return p; |
693 | p= &(base[i*size]); | 588 | } |
694 | c = (*cmp)(key,p); | ||
695 | if (c == 0 || (c < 0 && (flags & OBJ_BSEARCH_VALUE_ON_NOMATCH))) | ||
696 | return p; | ||
697 | } | ||
698 | } | ||
699 | #endif | 589 | #endif |
700 | if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)) | 590 | return(NULL); |
701 | p = NULL; | ||
702 | else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH)) | ||
703 | { | ||
704 | while(i > 0 && (*cmp)(key,&(base[(i-1)*size])) == 0) | ||
705 | i--; | ||
706 | p = &(base[i*size]); | ||
707 | } | ||
708 | return(p); | ||
709 | } | 591 | } |
710 | 592 | ||
711 | int OBJ_create_objects(BIO *in) | 593 | int OBJ_create_objects(BIO *in) |