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