diff options
Diffstat (limited to 'crypto/asn1')
75 files changed, 1044 insertions, 425 deletions
diff --git a/crypto/asn1/Makefile.ssl b/crypto/asn1/Makefile.ssl index a39e009d27..30751bd156 100644 --- a/crypto/asn1/Makefile.ssl +++ b/crypto/asn1/Makefile.ssl @@ -35,7 +35,8 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ a_hdr.c x_pkey.c a_bool.c x_exten.c \ - asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c + asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ + evp_asn1.c LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ a_sign.o a_digest.o a_verify.o \ @@ -49,7 +50,8 @@ LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ a_hdr.o x_pkey.o a_bool.o x_exten.o \ - asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o + asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o \ + evp_asn1.o SRC= $(LIBSRC) @@ -113,6 +115,6 @@ clean: errors: perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl $(ERR).h $(ERRC).c + perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c # DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c index eb99ebca2f..2c10120651 100644 --- a/crypto/asn1/a_bitstr.c +++ b/crypto/asn1/a_bitstr.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_bitstr.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -156,3 +156,49 @@ err: return(NULL); } +/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> + */ +int ASN1_BIT_STRING_set_bit(a,n,value) +ASN1_BIT_STRING *a; +int n; +int value; + { + int w,v,iv; + unsigned char *c; + + w=n/8; + v=1<<(7-(n&0x07)); + iv= ~v; + + if (a == NULL) return(0); + if ((a->length < (w+1)) || (a->data == NULL)) + { + if (!value) return(1); /* Don't need to set */ + if (a->data == NULL) + c=(unsigned char *)Malloc(w+1); + else + c=(unsigned char *)Realloc(a->data,w+1); + if (c == NULL) return(0); + a->data=c; + a->length=w+1; + c[w]=0; + } + a->data[w]=((a->data[w])&iv)|v; + while ((a->length > 0) && (a->data[a->length-1] == 0)) + a->length--; + return(1); + } + +int ASN1_BIT_STRING_get_bit(a,n) +ASN1_BIT_STRING *a; +int n; + { + int w,v; + + w=n/8; + v=1<<(7-(n&0x07)); + if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) + return(0); + return((a->data[w]&v) != 0); + } + diff --git a/crypto/asn1/a_bmp.c b/crypto/asn1/a_bmp.c new file mode 100644 index 0000000000..774502b1fc --- /dev/null +++ b/crypto/asn1/a_bmp.c @@ -0,0 +1,90 @@ +/* crypto/asn1/a_bmp.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "asn1.h" + +/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); + */ + +int i2d_ASN1_BMPSTRING(a, pp) +ASN1_BMPSTRING *a; +unsigned char **pp; + { + return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, + V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL)); + } + +ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(a, pp, length) +ASN1_BMPSTRING **a; +unsigned char **pp; +long length; + { + ASN1_BMPSTRING *ret=NULL; + + ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, + pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); + if (ret == NULL) + { + ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_ERROR_STACK); + return(NULL); + } + return(ret); + } + diff --git a/crypto/asn1/a_bool.c b/crypto/asn1/a_bool.c index 83607b58ef..41a95aa278 100644 --- a/crypto/asn1/a_bool.c +++ b/crypto/asn1/a_bool.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_bool.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/asn1/a_bytes.c b/crypto/asn1/a_bytes.c index 0c9132498c..14168d61ad 100644 --- a/crypto/asn1/a_bytes.c +++ b/crypto/asn1/a_bytes.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_bytes.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -67,14 +67,14 @@ */ static unsigned long tag2bit[32]={ -0, 0, 0, 0, /* tags 0 - 3 */ +0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */ 0, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0, 0,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, -B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN, +B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, }; #ifndef NOPROTO @@ -97,13 +97,6 @@ int type; int inf,tag,xclass; int i=0; - if ((a == NULL) || ((*a) == NULL)) - { - if ((ret=ASN1_STRING_new()) == NULL) return(NULL); - } - else - ret=(*a); - p= *pp; inf=ASN1_get_object(&p,&len,&tag,&xclass,length); if (inf & 0x80) goto err; @@ -118,6 +111,18 @@ int type; i=ASN1_R_WRONG_TYPE; goto err; } + + /* If a bit-string, exit early */ + if (tag == V_ASN1_BIT_STRING) + return(d2i_ASN1_BIT_STRING(a,pp,length)); + + if ((a == NULL) || ((*a) == NULL)) + { + if ((ret=ASN1_STRING_new()) == NULL) return(NULL); + } + else + ret=(*a); + if (len != 0) { s=(unsigned char *)Malloc((int)len+1); @@ -157,6 +162,10 @@ int xclass; unsigned char *p; if (a == NULL) return(0); + + if (tag == V_ASN1_BIT_STRING) + return(i2d_ASN1_BIT_STRING(a,pp)); + ret=a->length; r=ASN1_object_size(0,ret,tag); if (pp == NULL) return(r); @@ -229,7 +238,7 @@ int Pclass; { if (len != 0) { - if (ret->length < len) + if ((ret->length < len) || (ret->data == NULL)) { if (ret->data != NULL) Free((char *)ret->data); s=(unsigned char *)Malloc((int)len); diff --git a/crypto/asn1/a_d2i_fp.c b/crypto/asn1/a_d2i_fp.c index 5c9c9cf09b..d952836a91 100644 --- a/crypto/asn1/a_d2i_fp.c +++ b/crypto/asn1/a_d2i_fp.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_d2i_fp.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -63,7 +63,7 @@ #define HEADER_SIZE 8 -#ifndef WIN16 +#ifndef NO_FP_API char *ASN1_d2i_fp(xnew,d2i,in,x) char *(*xnew)(); char *(*d2i)(); @@ -108,6 +108,7 @@ unsigned char **x; return(NULL); } + ERR_clear_error(); for (;;) { if (want >= (len-off)) diff --git a/crypto/asn1/a_digest.c b/crypto/asn1/a_digest.c index 8f395d958a..8ddb65b0dc 100644 --- a/crypto/asn1/a_digest.c +++ b/crypto/asn1/a_digest.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_digest.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/asn1/a_dup.c b/crypto/asn1/a_dup.c index 51ed105ff2..961b4cb069 100644 --- a/crypto/asn1/a_dup.c +++ b/crypto/asn1/a_dup.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_dup.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/asn1/a_hdr.c b/crypto/asn1/a_hdr.c index b7de335fc1..4fb7a5fa75 100644 --- a/crypto/asn1/a_hdr.c +++ b/crypto/asn1/a_hdr.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_hdr.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c index eab127e6e0..66c3df68d5 100644 --- a/crypto/asn1/a_i2d_fp.c +++ b/crypto/asn1/a_i2d_fp.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_i2d_fp.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -61,7 +61,7 @@ #include "buffer.h" #include "asn1_mac.h" -#ifndef WIN16 +#ifndef NO_FP_API int ASN1_i2d_fp(i2d,out,x) int (*i2d)(); FILE *out; diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c index ce0921d59a..df79cf99bb 100644 --- a/crypto/asn1/a_int.c +++ b/crypto/asn1/a_int.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_int.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -251,7 +251,8 @@ ASN1_INTEGER *a; if (a->length > sizeof(long)) { - return(0xFFFFFFFFL); + /* hmm... a bit ugly */ + return(0xffffffffL); } if (a->data == NULL) return(0); diff --git a/crypto/asn1/a_meth.c b/crypto/asn1/a_meth.c index 0beb958aa6..513625c305 100644 --- a/crypto/asn1/a_meth.c +++ b/crypto/asn1/a_meth.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_meth.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c index 897915cf49..5a7eeef8d8 100644 --- a/crypto/asn1/a_object.c +++ b/crypto/asn1/a_object.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_object.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -64,7 +64,7 @@ /* ASN1err(ASN1_F_ASN1_OBJECT_NEW,ASN1_R_EXPECTING_AN_OBJECT); * ASN1err(ASN1_F_D2I_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); - * ASN1err(ASN1_F_I2A_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); + * ASN1err(ASN1_F_I2T_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); */ int i2d_ASN1_OBJECT(a, pp) @@ -180,19 +180,23 @@ err: return(0); } -int i2a_ASN1_OBJECT(bp,a) -BIO *bp; +int i2t_ASN1_OBJECT(buf,buf_len,a) +char *buf; +int buf_len; ASN1_OBJECT *a; { - int j,i,idx=0,n=0,len,nid,reason=ERR_R_BUF_LIB; + int i,idx=0,n=0,len,nid; unsigned long l; unsigned char *p; - char buf[20]; char *s; + char tbuf[32]; + + if (buf_len <= 0) return(0); if ((a == NULL) || (a->data == NULL)) { - return(BIO_write(bp,"NULL",4)); + buf[0]='\0'; + return(0); } nid=OBJ_obj2nid(a); @@ -215,10 +219,11 @@ ASN1_OBJECT *a; if (i > 2) i=2; l-=(long)(i*40); - sprintf(buf,"%d.%ld",i,l); - i=strlen(buf); - if (BIO_write(bp,buf,i) != i) - goto err; + sprintf(tbuf,"%d.%ld",i,l); + i=strlen(tbuf); + strncpy(buf,tbuf,buf_len); + buf_len-=i; + buf+=i; n+=i; l=0; @@ -227,9 +232,12 @@ ASN1_OBJECT *a; l|=p[idx]&0x7f; if (!(p[idx] & 0x80)) { - sprintf(buf,".%ld",l); - i=strlen(buf); - if (BIO_write(bp,buf,i) != i) goto err; + sprintf(tbuf,".%ld",l); + i=strlen(tbuf); + if (buf_len > 0) + strncpy(buf,tbuf,buf_len); + buf_len-=i; + buf+=i; n+=i; l=0; } @@ -241,14 +249,26 @@ ASN1_OBJECT *a; s=(char *)OBJ_nid2ln(nid); if (s == NULL) s=(char *)OBJ_nid2sn(nid); - j=strlen(s); - if (BIO_write(bp,s,j) != j) goto err; - n=j; + strncpy(buf,s,buf_len); + n=strlen(s); } + buf[buf_len-1]='\0'; return(n); -err: - ASN1err(ASN1_F_I2A_ASN1_OBJECT,reason); - return(-1); + } + +int i2a_ASN1_OBJECT(bp,a) +BIO *bp; +ASN1_OBJECT *a; + { + char buf[80]; + int i; + + if ((a == NULL) || (a->data == NULL)) + return(BIO_write(bp,"NULL",4)); + i=i2t_ASN1_OBJECT(buf,80,a); + if (i > 80) i=80; + BIO_write(bp,buf,i); + return(i); } ASN1_OBJECT *d2i_ASN1_OBJECT(a, pp, length) diff --git a/crypto/asn1/a_octet.c b/crypto/asn1/a_octet.c index e4ef15a995..be3f172a8c 100644 --- a/crypto/asn1/a_octet.c +++ b/crypto/asn1/a_octet.c @@ -1,5 +1,5 @@ /* crypto/asn1/a_octet.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written diff --git a/crypto/asn1/a_prin |