diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_lib.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_lib.c | 73 |
1 files changed, 18 insertions, 55 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 5af559ef8d..97b9b35f4b 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -62,11 +62,11 @@ | |||
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | #include <openssl/asn1_mac.h> | 63 | #include <openssl/asn1_mac.h> |
64 | 64 | ||
65 | static int asn1_get_length(const unsigned char **pp,int *inf,long *rl,int max); | 65 | static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); |
66 | static void asn1_put_length(unsigned char **pp, int length); | 66 | static void asn1_put_length(unsigned char **pp, int length); |
67 | const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; | 67 | const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT; |
68 | 68 | ||
69 | static int _asn1_check_infinite_end(const unsigned char **p, long len) | 69 | int ASN1_check_infinite_end(unsigned char **p, long len) |
70 | { | 70 | { |
71 | /* If there is 0 or 1 byte left, the length check should pick | 71 | /* If there is 0 or 1 byte left, the length check should pick |
72 | * things up */ | 72 | * things up */ |
@@ -80,23 +80,13 @@ static int _asn1_check_infinite_end(const unsigned char **p, long len) | |||
80 | return(0); | 80 | return(0); |
81 | } | 81 | } |
82 | 82 | ||
83 | int ASN1_check_infinite_end(unsigned char **p, long len) | ||
84 | { | ||
85 | return _asn1_check_infinite_end((const unsigned char **)p, len); | ||
86 | } | ||
87 | 83 | ||
88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) | 84 | int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, |
89 | { | 85 | long omax) |
90 | return _asn1_check_infinite_end(p, len); | ||
91 | } | ||
92 | |||
93 | |||
94 | int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, | ||
95 | int *pclass, long omax) | ||
96 | { | 86 | { |
97 | int i,ret; | 87 | int i,ret; |
98 | long l; | 88 | long l; |
99 | const unsigned char *p= *pp; | 89 | unsigned char *p= *pp; |
100 | int tag,xclass,inf; | 90 | int tag,xclass,inf; |
101 | long max=omax; | 91 | long max=omax; |
102 | 92 | ||
@@ -151,11 +141,11 @@ err: | |||
151 | return(0x80); | 141 | return(0x80); |
152 | } | 142 | } |
153 | 143 | ||
154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) | 144 | static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) |
155 | { | 145 | { |
156 | const unsigned char *p= *pp; | 146 | unsigned char *p= *pp; |
157 | unsigned long ret=0; | 147 | unsigned long ret=0; |
158 | unsigned int i; | 148 | int i; |
159 | 149 | ||
160 | if (max-- < 1) return(0); | 150 | if (max-- < 1) return(0); |
161 | if (*p == 0x80) | 151 | if (*p == 0x80) |
@@ -215,22 +205,13 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | |||
215 | } | 205 | } |
216 | p += ttag; | 206 | p += ttag; |
217 | } | 207 | } |
218 | if (constructed == 2) | 208 | if ((constructed == 2) && (length == 0)) |
219 | *(p++)=0x80; | 209 | *(p++)=0x80; /* der_put_length would output 0 instead */ |
220 | else | 210 | else |
221 | asn1_put_length(&p,length); | 211 | asn1_put_length(&p,length); |
222 | *pp=p; | 212 | *pp=p; |
223 | } | 213 | } |
224 | 214 | ||
225 | int ASN1_put_eoc(unsigned char **pp) | ||
226 | { | ||
227 | unsigned char *p = *pp; | ||
228 | *p++ = 0; | ||
229 | *p++ = 0; | ||
230 | *pp = p; | ||
231 | return 2; | ||
232 | } | ||
233 | |||
234 | static void asn1_put_length(unsigned char **pp, int length) | 215 | static void asn1_put_length(unsigned char **pp, int length) |
235 | { | 216 | { |
236 | unsigned char *p= *pp; | 217 | unsigned char *p= *pp; |
@@ -268,8 +249,8 @@ int ASN1_object_size(int constructed, int length, int tag) | |||
268 | ret++; | 249 | ret++; |
269 | } | 250 | } |
270 | } | 251 | } |
271 | if (constructed == 2) | 252 | if ((length == 0) && (constructed == 2)) |
272 | return ret + 3; | 253 | ret+=2; |
273 | ret++; | 254 | ret++; |
274 | if (length > 127) | 255 | if (length > 127) |
275 | { | 256 | { |
@@ -282,11 +263,11 @@ int ASN1_object_size(int constructed, int length, int tag) | |||
282 | return(ret); | 263 | return(ret); |
283 | } | 264 | } |
284 | 265 | ||
285 | static int _asn1_Finish(ASN1_const_CTX *c) | 266 | int asn1_Finish(ASN1_CTX *c) |
286 | { | 267 | { |
287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | 268 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) |
288 | { | 269 | { |
289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) | 270 | if (!ASN1_check_infinite_end(&c->p,c->slen)) |
290 | { | 271 | { |
291 | c->error=ERR_R_MISSING_ASN1_EOS; | 272 | c->error=ERR_R_MISSING_ASN1_EOS; |
292 | return(0); | 273 | return(0); |
@@ -301,19 +282,9 @@ static int _asn1_Finish(ASN1_const_CTX *c) | |||
301 | return(1); | 282 | return(1); |
302 | } | 283 | } |
303 | 284 | ||
304 | int asn1_Finish(ASN1_CTX *c) | 285 | int asn1_GetSequence(ASN1_CTX *c, long *length) |
305 | { | ||
306 | return _asn1_Finish((ASN1_const_CTX *)c); | ||
307 | } | ||
308 | |||
309 | int asn1_const_Finish(ASN1_const_CTX *c) | ||
310 | { | 286 | { |
311 | return _asn1_Finish(c); | 287 | unsigned char *q; |
312 | } | ||
313 | |||
314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) | ||
315 | { | ||
316 | const unsigned char *q; | ||
317 | 288 | ||
318 | q=c->p; | 289 | q=c->p; |
319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | 290 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), |
@@ -393,14 +364,6 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | |||
393 | return(1); | 364 | return(1); |
394 | } | 365 | } |
395 | 366 | ||
396 | void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | ||
397 | { | ||
398 | if (str->data) | ||
399 | OPENSSL_free(str->data); | ||
400 | str->data = data; | ||
401 | str->length = len; | ||
402 | } | ||
403 | |||
404 | ASN1_STRING *ASN1_STRING_new(void) | 367 | ASN1_STRING *ASN1_STRING_new(void) |
405 | { | 368 | { |
406 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | 369 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); |
@@ -448,7 +411,7 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) | |||
448 | return(i); | 411 | return(i); |
449 | } | 412 | } |
450 | 413 | ||
451 | void asn1_add_error(const unsigned char *address, int offset) | 414 | void asn1_add_error(unsigned char *address, int offset) |
452 | { | 415 | { |
453 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; | 416 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; |
454 | 417 | ||