diff options
author | markus <> | 2002-09-05 22:44:52 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 22:44:52 +0000 |
commit | 715a204e4615e4a70a466fcb383a9a57cad5e6b8 (patch) | |
tree | 2d2e93c4a34d1f7f04aba73706353332d7700641 /src/lib/libcrypto/asn1 | |
parent | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (diff) | |
download | openbsd-715a204e4615e4a70a466fcb383a9a57cad5e6b8.tar.gz openbsd-715a204e4615e4a70a466fcb383a9a57cad5e6b8.tar.bz2 openbsd-715a204e4615e4a70a466fcb383a9a57cad5e6b8.zip |
import openssl-0.9.7-beta3
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r-- | src/lib/libcrypto/asn1/a_strex.c | 11 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_lib.c | 11 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/n_pkey.c | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/t_pkey.c | 88 |
5 files changed, 82 insertions, 33 deletions
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c index 128aa7e772..8dab29dca1 100644 --- a/src/lib/libcrypto/asn1/a_strex.c +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
@@ -77,8 +77,8 @@ | |||
77 | /* Three IO functions for sending data to memory, a BIO and | 77 | /* Three IO functions for sending data to memory, a BIO and |
78 | * and a FILE pointer. | 78 | * and a FILE pointer. |
79 | */ | 79 | */ |
80 | 80 | #if 0 /* never used */ | |
81 | int send_mem_chars(void *arg, const void *buf, int len) | 81 | static int send_mem_chars(void *arg, const void *buf, int len) |
82 | { | 82 | { |
83 | unsigned char **out = arg; | 83 | unsigned char **out = arg; |
84 | if(!out) return 1; | 84 | if(!out) return 1; |
@@ -86,15 +86,16 @@ int send_mem_chars(void *arg, const void *buf, int len) | |||
86 | *out += len; | 86 | *out += len; |
87 | return 1; | 87 | return 1; |
88 | } | 88 | } |
89 | #endif | ||
89 | 90 | ||
90 | int send_bio_chars(void *arg, const void *buf, int len) | 91 | static int send_bio_chars(void *arg, const void *buf, int len) |
91 | { | 92 | { |
92 | if(!arg) return 1; | 93 | if(!arg) return 1; |
93 | if(BIO_write(arg, buf, len) != len) return 0; | 94 | if(BIO_write(arg, buf, len) != len) return 0; |
94 | return 1; | 95 | return 1; |
95 | } | 96 | } |
96 | 97 | ||
97 | int send_fp_chars(void *arg, const void *buf, int len) | 98 | static int send_fp_chars(void *arg, const void *buf, int len) |
98 | { | 99 | { |
99 | if(!arg) return 1; | 100 | if(!arg) return 1; |
100 | if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; | 101 | if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; |
@@ -240,7 +241,7 @@ static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen | |||
240 | * #01234 format. | 241 | * #01234 format. |
241 | */ | 242 | */ |
242 | 243 | ||
243 | int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | 244 | static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) |
244 | { | 245 | { |
245 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows | 246 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows |
246 | * the DER encoding to readily obtained | 247 | * the DER encoding to readily obtained |
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index 0d1713f8dd..dbb30f4f22 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
@@ -773,6 +773,7 @@ int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b); | |||
773 | int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len); | 773 | int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len); |
774 | 774 | ||
775 | DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) | 775 | DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) |
776 | DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) | ||
776 | DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) | 777 | DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) |
777 | DECLARE_ASN1_FUNCTIONS(ASN1_NULL) | 778 | DECLARE_ASN1_FUNCTIONS(ASN1_NULL) |
778 | DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) | 779 | DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) |
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 830ff2af3c..422685a3b4 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
62 | #include <openssl/asn1_mac.h> | ||
62 | 63 | ||
63 | static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); | 64 | static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); |
64 | static void asn1_put_length(unsigned char **pp, int length); | 65 | static void asn1_put_length(unsigned char **pp, int length); |
@@ -123,15 +124,13 @@ int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, | |||
123 | (int)(omax+ *pp)); | 124 | (int)(omax+ *pp)); |
124 | 125 | ||
125 | #endif | 126 | #endif |
126 | #if 0 | 127 | if (*plength > (omax - (*pp - p))) |
127 | if ((p+ *plength) > (omax+ *pp)) | ||
128 | { | 128 | { |
129 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | 129 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); |
130 | /* Set this so that even if things are not long enough | 130 | /* Set this so that even if things are not long enough |
131 | * the values are set correctly */ | 131 | * the values are set correctly */ |
132 | ret|=0x80; | 132 | ret|=0x80; |
133 | } | 133 | } |
134 | #endif | ||
135 | *pp=p; | 134 | *pp=p; |
136 | return(ret|inf); | 135 | return(ret|inf); |
137 | err: | 136 | err: |
@@ -158,6 +157,8 @@ static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) | |||
158 | i= *p&0x7f; | 157 | i= *p&0x7f; |
159 | if (*(p++) & 0x80) | 158 | if (*(p++) & 0x80) |
160 | { | 159 | { |
160 | if (i > sizeof(long)) | ||
161 | return 0; | ||
161 | if (max-- == 0) return(0); | 162 | if (max-- == 0) return(0); |
162 | while (i-- > 0) | 163 | while (i-- > 0) |
163 | { | 164 | { |
@@ -169,6 +170,8 @@ static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) | |||
169 | else | 170 | else |
170 | ret=i; | 171 | ret=i; |
171 | } | 172 | } |
173 | if (ret < 0) | ||
174 | return 0; | ||
172 | *pp=p; | 175 | *pp=p; |
173 | *rl=ret; | 176 | *rl=ret; |
174 | return(1); | 177 | return(1); |
@@ -406,7 +409,7 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) | |||
406 | 409 | ||
407 | void asn1_add_error(unsigned char *address, int offset) | 410 | void asn1_add_error(unsigned char *address, int offset) |
408 | { | 411 | { |
409 | char buf1[16],buf2[16]; | 412 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; |
410 | 413 | ||
411 | sprintf(buf1,"%lu",(unsigned long)address); | 414 | sprintf(buf1,"%lu",(unsigned long)address); |
412 | sprintf(buf2,"%d",offset); | 415 | sprintf(buf2,"%d",offset); |
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c index 49f80fffd2..9146ee02c9 100644 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
@@ -92,6 +92,8 @@ ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { | |||
92 | ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG) | 92 | ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG) |
93 | } ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY) | 93 | } ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY) |
94 | 94 | ||
95 | DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) | ||
96 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY) | ||
95 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) | 97 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) |
96 | 98 | ||
97 | ASN1_SEQUENCE(NETSCAPE_PKEY) = { | 99 | ASN1_SEQUENCE(NETSCAPE_PKEY) = { |
@@ -100,6 +102,8 @@ ASN1_SEQUENCE(NETSCAPE_PKEY) = { | |||
100 | ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING) | 102 | ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING) |
101 | } ASN1_SEQUENCE_END(NETSCAPE_PKEY) | 103 | } ASN1_SEQUENCE_END(NETSCAPE_PKEY) |
102 | 104 | ||
105 | DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | ||
106 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY) | ||
103 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | 107 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) |
104 | 108 | ||
105 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | 109 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, |
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c index 8060115202..2d46914cb1 100644 --- a/src/lib/libcrypto/asn1/t_pkey.c +++ b/src/lib/libcrypto/asn1/t_pkey.c | |||
@@ -96,10 +96,34 @@ int RSA_print(BIO *bp, const RSA *x, int off) | |||
96 | char str[128]; | 96 | char str[128]; |
97 | const char *s; | 97 | const char *s; |
98 | unsigned char *m=NULL; | 98 | unsigned char *m=NULL; |
99 | int i,ret=0; | 99 | int ret=0; |
100 | size_t buf_len=0, i; | ||
100 | 101 | ||
101 | i=RSA_size(x); | 102 | if (x->n) |
102 | m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10); | 103 | buf_len = (size_t)BN_num_bytes(x->n); |
104 | if (x->e) | ||
105 | if (buf_len < (i = (size_t)BN_num_bytes(x->e))) | ||
106 | buf_len = i; | ||
107 | if (x->d) | ||
108 | if (buf_len < (i = (size_t)BN_num_bytes(x->d))) | ||
109 | buf_len = i; | ||
110 | if (x->p) | ||
111 | if (buf_len < (i = (size_t)BN_num_bytes(x->p))) | ||
112 | buf_len = i; | ||
113 | if (x->q) | ||
114 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
115 | buf_len = i; | ||
116 | if (x->dmp1) | ||
117 | if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1))) | ||
118 | buf_len = i; | ||
119 | if (x->dmq1) | ||
120 | if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1))) | ||
121 | buf_len = i; | ||
122 | if (x->iqmp) | ||
123 | if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp))) | ||
124 | buf_len = i; | ||
125 | |||
126 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
103 | if (m == NULL) | 127 | if (m == NULL) |
104 | { | 128 | { |
105 | RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE); | 129 | RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE); |
@@ -161,22 +185,25 @@ int DSA_print(BIO *bp, const DSA *x, int off) | |||
161 | { | 185 | { |
162 | char str[128]; | 186 | char str[128]; |
163 | unsigned char *m=NULL; | 187 | unsigned char *m=NULL; |
164 | int i,ret=0; | 188 | int ret=0; |
165 | BIGNUM *bn=NULL; | 189 | size_t buf_len=0,i; |
166 | 190 | ||
167 | if (x->p != NULL) | 191 | if (x->p) |
168 | bn=x->p; | 192 | buf_len = (size_t)BN_num_bytes(x->p); |
169 | else if (x->priv_key != NULL) | 193 | if (x->q) |
170 | bn=x->priv_key; | 194 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) |
171 | else if (x->pub_key != NULL) | 195 | buf_len = i; |
172 | bn=x->pub_key; | 196 | if (x->g) |
173 | 197 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | |
174 | /* larger than needed but what the hell :-) */ | 198 | buf_len = i; |
175 | if (bn != NULL) | 199 | if (x->priv_key) |
176 | i=BN_num_bytes(bn)*2; | 200 | if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key))) |
177 | else | 201 | buf_len = i; |
178 | i=256; | 202 | if (x->pub_key) |
179 | m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10); | 203 | if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key))) |
204 | buf_len = i; | ||
205 | |||
206 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
180 | if (m == NULL) | 207 | if (m == NULL) |
181 | { | 208 | { |
182 | DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE); | 209 | DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE); |
@@ -281,10 +308,15 @@ int DHparams_print_fp(FILE *fp, const DH *x) | |||
281 | int DHparams_print(BIO *bp, const DH *x) | 308 | int DHparams_print(BIO *bp, const DH *x) |
282 | { | 309 | { |
283 | unsigned char *m=NULL; | 310 | unsigned char *m=NULL; |
284 | int reason=ERR_R_BUF_LIB,i,ret=0; | 311 | int reason=ERR_R_BUF_LIB,ret=0; |
312 | size_t buf_len=0, i; | ||
285 | 313 | ||
286 | i=BN_num_bytes(x->p); | 314 | if (x->p) |
287 | m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10); | 315 | buf_len = (size_t)BN_num_bytes(x->p); |
316 | if (x->g) | ||
317 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
318 | buf_len = i; | ||
319 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
288 | if (m == NULL) | 320 | if (m == NULL) |
289 | { | 321 | { |
290 | reason=ERR_R_MALLOC_FAILURE; | 322 | reason=ERR_R_MALLOC_FAILURE; |
@@ -334,10 +366,18 @@ int DSAparams_print_fp(FILE *fp, const DSA *x) | |||
334 | int DSAparams_print(BIO *bp, const DSA *x) | 366 | int DSAparams_print(BIO *bp, const DSA *x) |
335 | { | 367 | { |
336 | unsigned char *m=NULL; | 368 | unsigned char *m=NULL; |
337 | int reason=ERR_R_BUF_LIB,i,ret=0; | 369 | int reason=ERR_R_BUF_LIB,ret=0; |
370 | size_t buf_len=0,i; | ||
338 | 371 | ||
339 | i=BN_num_bytes(x->p); | 372 | if (x->p) |
340 | m=(unsigned char *)OPENSSL_malloc((unsigned int)i+10); | 373 | buf_len = (size_t)BN_num_bytes(x->p); |
374 | if (x->q) | ||
375 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
376 | buf_len = i; | ||
377 | if (x->g) | ||
378 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
379 | buf_len = i; | ||
380 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
341 | if (m == NULL) | 381 | if (m == NULL) |
342 | { | 382 | { |
343 | reason=ERR_R_MALLOC_FAILURE; | 383 | reason=ERR_R_MALLOC_FAILURE; |