summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_lib.c')
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c121
1 files changed, 45 insertions, 76 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index ff30b25836..95e54ed626 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -58,22 +58,14 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63
64#ifndef NOPROTO
65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); 64static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length); 65static void asn1_put_length(unsigned char **pp, int length);
67#else 66const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
68static int asn1_get_length();
69static void asn1_put_length();
70#endif
71
72char *ASN1_version="ASN1 part of SSLeay 0.9.0b 29-Jun-1998";
73 67
74int ASN1_check_infinite_end(p,len) 68int ASN1_check_infinite_end(unsigned char **p, long len)
75unsigned char **p;
76long len;
77 { 69 {
78 /* If there is 0 or 1 byte left, the length check should pick 70 /* If there is 0 or 1 byte left, the length check should pick
79 * things up */ 71 * things up */
@@ -88,12 +80,8 @@ long len;
88 } 80 }
89 81
90 82
91int ASN1_get_object(pp, plength, ptag, pclass, omax) 83int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
92unsigned char **pp; 84 long omax)
93long *plength;
94int *ptag;
95int *pclass;
96long omax;
97 { 85 {
98 int i,ret; 86 int i,ret;
99 long l; 87 long l;
@@ -104,8 +92,8 @@ long omax;
104 if (!max) goto err; 92 if (!max) goto err;
105 ret=(*p&V_ASN1_CONSTRUCTED); 93 ret=(*p&V_ASN1_CONSTRUCTED);
106 xclass=(*p&V_ASN1_PRIVATE); 94 xclass=(*p&V_ASN1_PRIVATE);
107 i= *p&V_ASN1_PRIMATIVE_TAG; 95 i= *p&V_ASN1_PRIMITIVE_TAG;
108 if (i == V_ASN1_PRIMATIVE_TAG) 96 if (i == V_ASN1_PRIMITIVE_TAG)
109 { /* high-tag */ 97 { /* high-tag */
110 p++; 98 p++;
111 if (--max == 0) goto err; 99 if (--max == 0) goto err;
@@ -130,11 +118,13 @@ long omax;
130 *pclass=xclass; 118 *pclass=xclass;
131 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; 119 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
132 120
133#ifdef undef 121#if 0
134 fprintf(stderr,"p=%d + *plength=%d > omax=%d + *pp=%d (%d > %d)\n", 122 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
135 p,*plength,omax,*pp,(p+ *plength),omax+ *pp); 123 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
124 (int)(omax+ *pp));
136 125
137#endif 126#endif
127#if 0
138 if ((p+ *plength) > (omax+ *pp)) 128 if ((p+ *plength) > (omax+ *pp))
139 { 129 {
140 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); 130 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
@@ -142,18 +132,15 @@ long omax;
142 * the values are set correctly */ 132 * the values are set correctly */
143 ret|=0x80; 133 ret|=0x80;
144 } 134 }
135#endif
145 *pp=p; 136 *pp=p;
146 return(ret+inf); 137 return(ret|inf);
147err: 138err:
148 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); 139 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
149 return(0x80); 140 return(0x80);
150 } 141 }
151 142
152static int asn1_get_length(pp,inf,rl,max) 143static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
153unsigned char **pp;
154int *inf;
155long *rl;
156int max;
157 { 144 {
158 unsigned char *p= *pp; 145 unsigned char *p= *pp;
159 long ret=0; 146 long ret=0;
@@ -190,12 +177,8 @@ int max;
190 177
191/* class 0 is constructed 178/* class 0 is constructed
192 * constructed == 2 for indefinitle length constructed */ 179 * constructed == 2 for indefinitle length constructed */
193void ASN1_put_object(pp,constructed,length,tag,xclass) 180void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
194unsigned char **pp; 181 int xclass)
195int constructed;
196int length;
197int tag;
198int xclass;
199 { 182 {
200 unsigned char *p= *pp; 183 unsigned char *p= *pp;
201 int i; 184 int i;
@@ -203,10 +186,10 @@ int xclass;
203 i=(constructed)?V_ASN1_CONSTRUCTED:0; 186 i=(constructed)?V_ASN1_CONSTRUCTED:0;
204 i|=(xclass&V_ASN1_PRIVATE); 187 i|=(xclass&V_ASN1_PRIVATE);
205 if (tag < 31) 188 if (tag < 31)
206 *(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG); 189 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
207 else 190 else
208 { 191 {
209 *(p++)=i|V_ASN1_PRIMATIVE_TAG; 192 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
210 while (tag > 0x7f) 193 while (tag > 0x7f)
211 { 194 {
212 *(p++)=(tag&0x7f)|0x80; 195 *(p++)=(tag&0x7f)|0x80;
@@ -221,9 +204,7 @@ int xclass;
221 *pp=p; 204 *pp=p;
222 } 205 }
223 206
224static void asn1_put_length(pp, length) 207static void asn1_put_length(unsigned char **pp, int length)
225unsigned char **pp;
226int length;
227 { 208 {
228 unsigned char *p= *pp; 209 unsigned char *p= *pp;
229 int i,l; 210 int i,l;
@@ -246,10 +227,7 @@ int length;
246 *pp=p; 227 *pp=p;
247 } 228 }
248 229
249int ASN1_object_size(constructed, length, tag) 230int ASN1_object_size(int constructed, int length, int tag)
250int constructed;
251int length;
252int tag;
253 { 231 {
254 int ret; 232 int ret;
255 233
@@ -277,29 +255,26 @@ int tag;
277 return(ret); 255 return(ret);
278 } 256 }
279 257
280int asn1_Finish(c) 258int asn1_Finish(ASN1_CTX *c)
281ASN1_CTX *c;
282 { 259 {
283 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) 260 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
284 { 261 {
285 if (!ASN1_check_infinite_end(&c->p,c->slen)) 262 if (!ASN1_check_infinite_end(&c->p,c->slen))
286 { 263 {
287 c->error=ASN1_R_MISSING_EOS; 264 c->error=ERR_R_MISSING_ASN1_EOS;
288 return(0); 265 return(0);
289 } 266 }
290 } 267 }
291 if ( ((c->slen != 0) && !(c->inf & 1)) || 268 if ( ((c->slen != 0) && !(c->inf & 1)) ||
292 ((c->slen < 0) && (c->inf & 1))) 269 ((c->slen < 0) && (c->inf & 1)))
293 { 270 {
294 c->error=ASN1_R_LENGTH_MISMATCH; 271 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
295 return(0); 272 return(0);
296 } 273 }
297 return(1); 274 return(1);
298 } 275 }
299 276
300int asn1_GetSequence(c,length) 277int asn1_GetSequence(ASN1_CTX *c, long *length)
301ASN1_CTX *c;
302long *length;
303 { 278 {
304 unsigned char *q; 279 unsigned char *q;
305 280
@@ -308,18 +283,18 @@ long *length;
308 *length); 283 *length);
309 if (c->inf & 0x80) 284 if (c->inf & 0x80)
310 { 285 {
311 c->error=ASN1_R_BAD_GET_OBJECT; 286 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
312 return(0); 287 return(0);
313 } 288 }
314 if (c->tag != V_ASN1_SEQUENCE) 289 if (c->tag != V_ASN1_SEQUENCE)
315 { 290 {
316 c->error=ASN1_R_EXPECTING_A_SEQUENCE; 291 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
317 return(0); 292 return(0);
318 } 293 }
319 (*length)-=(c->p-q); 294 (*length)-=(c->p-q);
320 if (c->max && (*length < 0)) 295 if (c->max && (*length < 0))
321 { 296 {
322 c->error=ASN1_R_LENGTH_MISMATCH; 297 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
323 return(0); 298 return(0);
324 } 299 }
325 if (c->inf == (1|V_ASN1_CONSTRUCTED)) 300 if (c->inf == (1|V_ASN1_CONSTRUCTED))
@@ -328,8 +303,7 @@ long *length;
328 return(1); 303 return(1);
329 } 304 }
330 305
331ASN1_STRING *ASN1_STRING_dup(str) 306ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
332ASN1_STRING *str;
333 { 307 {
334 ASN1_STRING *ret; 308 ASN1_STRING *ret;
335 309
@@ -341,34 +315,33 @@ ASN1_STRING *str;
341 ASN1_STRING_free(ret); 315 ASN1_STRING_free(ret);
342 return(NULL); 316 return(NULL);
343 } 317 }
318 ret->flags = str->flags;
344 return(ret); 319 return(ret);
345 } 320 }
346 321
347int ASN1_STRING_set(str,data,len) 322int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
348ASN1_STRING *str;
349unsigned char *data;
350int len;
351 { 323 {
352 char *c; 324 unsigned char *c;
325 const char *data=_data;
353 326
354 if (len < 0) 327 if (len < 0)
355 { 328 {
356 if (data == NULL) 329 if (data == NULL)
357 return(0); 330 return(0);
358 else 331 else
359 len=strlen((char *)data); 332 len=strlen(data);
360 } 333 }
361 if ((str->length < len) || (str->data == NULL)) 334 if ((str->length < len) || (str->data == NULL))
362 { 335 {
363 c=(char *)str->data; 336 c=str->data;
364 if (c == NULL) 337 if (c == NULL)
365 str->data=(unsigned char *)Malloc(len+1); 338 str->data=Malloc(len+1);
366 else 339 else
367 str->data=(unsigned char *)Realloc(c,len+1); 340 str->data=Realloc(c,len+1);
368 341
369 if (str->data == NULL) 342 if (str->data == NULL)
370 { 343 {
371 str->data=(unsigned char *)c; 344 str->data=c;
372 return(0); 345 return(0);
373 } 346 }
374 } 347 }
@@ -382,14 +355,13 @@ int len;
382 return(1); 355 return(1);
383 } 356 }
384 357
385ASN1_STRING *ASN1_STRING_new() 358ASN1_STRING *ASN1_STRING_new(void)
386 { 359 {
387 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); 360 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
388 } 361 }
389 362
390 363
391ASN1_STRING *ASN1_STRING_type_new(type) 364ASN1_STRING *ASN1_STRING_type_new(int type)
392int type;
393 { 365 {
394 ASN1_STRING *ret; 366 ASN1_STRING *ret;
395 367
@@ -402,19 +374,18 @@ int type;
402 ret->length=0; 374 ret->length=0;
403 ret->type=type; 375 ret->type=type;
404 ret->data=NULL; 376 ret->data=NULL;
377 ret->flags=0;
405 return(ret); 378 return(ret);
406 } 379 }
407 380
408void ASN1_STRING_free(a) 381void ASN1_STRING_free(ASN1_STRING *a)
409ASN1_STRING *a;
410 { 382 {
411 if (a == NULL) return; 383 if (a == NULL) return;
412 if (a->data != NULL) Free((char *)a->data); 384 if (a->data != NULL) Free((char *)a->data);
413 Free((char *)a); 385 Free((char *)a);
414 } 386 }
415 387
416int ASN1_STRING_cmp(a,b) 388int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
417ASN1_STRING *a,*b;
418 { 389 {
419 int i; 390 int i;
420 391
@@ -431,9 +402,7 @@ ASN1_STRING *a,*b;
431 return(i); 402 return(i);
432 } 403 }
433 404
434void asn1_add_error(address,offset) 405void asn1_add_error(unsigned char *address, int offset)
435unsigned char *address;
436int offset;
437 { 406 {
438 char buf1[16],buf2[16]; 407 char buf1[16],buf2[16];
439 408