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, 55 insertions, 18 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 97b9b35f4b..5af559ef8d 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(unsigned char **pp,int *inf,long *rl,int max); | 65 | static int asn1_get_length(const 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 | int ASN1_check_infinite_end(unsigned char **p, long len) | 69 | static int _asn1_check_infinite_end(const 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,13 +80,23 @@ int ASN1_check_infinite_end(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 | } | ||
83 | 87 | ||
84 | int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, | 88 | int ASN1_const_check_infinite_end(const unsigned char **p, long len) |
85 | long omax) | 89 | { |
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) | ||
86 | { | 96 | { |
87 | int i,ret; | 97 | int i,ret; |
88 | long l; | 98 | long l; |
89 | unsigned char *p= *pp; | 99 | const unsigned char *p= *pp; |
90 | int tag,xclass,inf; | 100 | int tag,xclass,inf; |
91 | long max=omax; | 101 | long max=omax; |
92 | 102 | ||
@@ -141,11 +151,11 @@ err: | |||
141 | return(0x80); | 151 | return(0x80); |
142 | } | 152 | } |
143 | 153 | ||
144 | static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) | 154 | static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) |
145 | { | 155 | { |
146 | unsigned char *p= *pp; | 156 | const unsigned char *p= *pp; |
147 | unsigned long ret=0; | 157 | unsigned long ret=0; |
148 | int i; | 158 | unsigned int i; |
149 | 159 | ||
150 | if (max-- < 1) return(0); | 160 | if (max-- < 1) return(0); |
151 | if (*p == 0x80) | 161 | if (*p == 0x80) |
@@ -205,13 +215,22 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | |||
205 | } | 215 | } |
206 | p += ttag; | 216 | p += ttag; |
207 | } | 217 | } |
208 | if ((constructed == 2) && (length == 0)) | 218 | if (constructed == 2) |
209 | *(p++)=0x80; /* der_put_length would output 0 instead */ | 219 | *(p++)=0x80; |
210 | else | 220 | else |
211 | asn1_put_length(&p,length); | 221 | asn1_put_length(&p,length); |
212 | *pp=p; | 222 | *pp=p; |
213 | } | 223 | } |
214 | 224 | ||
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 | |||
215 | static void asn1_put_length(unsigned char **pp, int length) | 234 | static void asn1_put_length(unsigned char **pp, int length) |
216 | { | 235 | { |
217 | unsigned char *p= *pp; | 236 | unsigned char *p= *pp; |
@@ -249,8 +268,8 @@ int ASN1_object_size(int constructed, int length, int tag) | |||
249 | ret++; | 268 | ret++; |
250 | } | 269 | } |
251 | } | 270 | } |
252 | if ((length == 0) && (constructed == 2)) | 271 | if (constructed == 2) |
253 | ret+=2; | 272 | return ret + 3; |
254 | ret++; | 273 | ret++; |
255 | if (length > 127) | 274 | if (length > 127) |
256 | { | 275 | { |
@@ -263,11 +282,11 @@ int ASN1_object_size(int constructed, int length, int tag) | |||
263 | return(ret); | 282 | return(ret); |
264 | } | 283 | } |
265 | 284 | ||
266 | int asn1_Finish(ASN1_CTX *c) | 285 | static int _asn1_Finish(ASN1_const_CTX *c) |
267 | { | 286 | { |
268 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | 287 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) |
269 | { | 288 | { |
270 | if (!ASN1_check_infinite_end(&c->p,c->slen)) | 289 | if (!ASN1_const_check_infinite_end(&c->p,c->slen)) |
271 | { | 290 | { |
272 | c->error=ERR_R_MISSING_ASN1_EOS; | 291 | c->error=ERR_R_MISSING_ASN1_EOS; |
273 | return(0); | 292 | return(0); |
@@ -282,9 +301,19 @@ int asn1_Finish(ASN1_CTX *c) | |||
282 | return(1); | 301 | return(1); |
283 | } | 302 | } |
284 | 303 | ||
285 | int asn1_GetSequence(ASN1_CTX *c, long *length) | 304 | int asn1_Finish(ASN1_CTX *c) |
305 | { | ||
306 | return _asn1_Finish((ASN1_const_CTX *)c); | ||
307 | } | ||
308 | |||
309 | int asn1_const_Finish(ASN1_const_CTX *c) | ||
286 | { | 310 | { |
287 | unsigned char *q; | 311 | return _asn1_Finish(c); |
312 | } | ||
313 | |||
314 | int asn1_GetSequence(ASN1_const_CTX *c, long *length) | ||
315 | { | ||
316 | const unsigned char *q; | ||
288 | 317 | ||
289 | q=c->p; | 318 | q=c->p; |
290 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | 319 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), |
@@ -364,6 +393,14 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | |||
364 | return(1); | 393 | return(1); |
365 | } | 394 | } |
366 | 395 | ||
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 | |||
367 | ASN1_STRING *ASN1_STRING_new(void) | 404 | ASN1_STRING *ASN1_STRING_new(void) |
368 | { | 405 | { |
369 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | 406 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); |
@@ -411,7 +448,7 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) | |||
411 | return(i); | 448 | return(i); |
412 | } | 449 | } |
413 | 450 | ||
414 | void asn1_add_error(unsigned char *address, int offset) | 451 | void asn1_add_error(const unsigned char *address, int offset) |
415 | { | 452 | { |
416 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; | 453 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; |
417 | 454 | ||