diff options
Diffstat (limited to 'lib/libcrypto/asn1/a_object.c')
-rw-r--r-- | lib/libcrypto/asn1/a_object.c | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/lib/libcrypto/asn1/a_object.c b/lib/libcrypto/asn1/a_object.c index c30f32442d1..7e9eeaa2e1c 100644 --- a/lib/libcrypto/asn1/a_object.c +++ b/lib/libcrypto/asn1/a_object.c @@ -65,7 +65,7 @@ #include <openssl/bn.h> int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) - { +{ unsigned char *p; int objsize; @@ -81,10 +81,10 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) *pp=p; return(objsize); - } +} int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) - { +{ int i,first,len=0,c, use_bn; char ftmp[24], *tmp = ftmp; int tmpsize = sizeof ftmp; @@ -101,119 +101,119 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) c= *(p++); num--; if ((c >= '0') && (c <= '2')) - { + { first= c-'0'; - } + } else - { + { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); goto err; - } + } if (num <= 0) - { + { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); goto err; - } + } c= *(p++); num--; for (;;) - { + { if (num <= 0) break; if ((c != '.') && (c != ' ')) - { + { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); goto err; - } + } l=0; use_bn = 0; for (;;) - { + { if (num <= 0) break; num--; c= *(p++); if ((c == ' ') || (c == '.')) break; if ((c < '0') || (c > '9')) - { + { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); goto err; - } + } if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) - { + { use_bn = 1; if (!bl) bl = BN_new(); if (!bl || !BN_set_word(bl, l)) goto err; - } + } if (use_bn) - { + { if (!BN_mul_word(bl, 10L) || !BN_add_word(bl, c-'0')) goto err; - } + } else l=l*10L+(long)(c-'0'); - } + } if (len == 0) - { + { if ((first < 2) && (l >= 40)) - { + { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); goto err; - } + } if (use_bn) - { + { if (!BN_add_word(bl, first * 40)) goto err; - } + } else l+=(long)first*40; - } + } i=0; if (use_bn) - { + { int blsize; blsize = BN_num_bits(bl); blsize = (blsize + 6)/7; if (blsize > tmpsize) - { + { if (tmp != ftmp) free(tmp); tmpsize = blsize + 32; tmp = malloc(tmpsize); if (!tmp) goto err; - } + } while(blsize--) tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); - } + } else - { + { for (;;) - { + { tmp[i++]=(unsigned char)l&0x7f; l>>=7L; if (l == 0L) break; - } - } + + } if (out != NULL) - { + { if (len+i > olen) - { + { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); goto err; - } + } while (--i > 0) out[len++]=tmp[i]|0x80; out[len++]=tmp[0]; - } + } else len+=i; - } + } if (tmp != ftmp) free(tmp); if (bl) @@ -225,7 +225,7 @@ err: if (bl) BN_free(bl); return(0); - } +} int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) { @@ -233,7 +233,7 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) } int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) - { +{ char buf[80], *p = buf; int i; @@ -241,19 +241,19 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) return(BIO_write(bp,"NULL",4)); i=i2t_ASN1_OBJECT(buf,sizeof buf,a); if (i > (int)(sizeof(buf) - 1)) - { + { p = malloc(i + 1); if (!p) return -1; i2t_ASN1_OBJECT(p,i + 1,a); - } + } if (i <= 0) return BIO_write(bp, "<INVALID>", 9); BIO_write(bp,p,i); if (p != buf) free(p); return(i); - } +} ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length) @@ -266,16 +266,16 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, p= *pp; inf=ASN1_get_object(&p,&len,&tag,&xclass,length); if (inf & 0x80) - { + { i=ASN1_R_BAD_OBJECT_HEADER; goto err; - } + } if (tag != V_ASN1_OBJECT) - { + { i=ASN1_R_EXPECTING_AN_OBJECT; goto err; - } + } ret = c2i_ASN1_OBJECT(a, &p, len); if(ret) *pp = p; return ret; @@ -285,7 +285,7 @@ err: } ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) - { +{ ASN1_OBJECT *ret=NULL; const unsigned char *p; unsigned char *data; @@ -294,21 +294,21 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, * subidentifiers, see: X.690 8.19.2 */ for (i = 0, p = *pp; i < len; i++, p++) - { + { if (*p == 0x80 && (!i || !(p[-1] & 0x80))) - { + { ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING); return NULL; - } } + } /* only the ASN1_OBJECTs from the 'table' will have values * for ->sn or ->ln */ if ((a == NULL) || ((*a) == NULL) || !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) - { + { if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); - } + } else ret=(*a); p= *pp; @@ -317,14 +317,14 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, ret->data = NULL; /* once detached we can change it */ if ((data == NULL) || (ret->length < len)) - { + { ret->length=0; if (data != NULL) free(data); data=(unsigned char *)malloc(len ? (int)len : 1); if (data == NULL) - { i=ERR_R_MALLOC_FAILURE; goto err; } + { i=ERR_R_MALLOC_FAILURE; goto err; } ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; - } + } memcpy(data,p,(int)len); /* reattach data to object, after which it remains const */ ret->data =data; @@ -342,18 +342,18 @@ err: if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_OBJECT_free(ret); return(NULL); - } +} ASN1_OBJECT *ASN1_OBJECT_new(void) - { +{ ASN1_OBJECT *ret; ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); if (ret == NULL) - { + { ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); return(NULL); - } + } ret->length=0; ret->data=NULL; ret->nid=0; @@ -361,32 +361,32 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) ret->ln=NULL; ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; return(ret); - } +} void ASN1_OBJECT_free(ASN1_OBJECT *a) - { +{ if (a == NULL) return; if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) - { + { #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ if (a->sn != NULL) free((void *)a->sn); if (a->ln != NULL) free((void *)a->ln); #endif a->sn=a->ln=NULL; - } + } if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) - { + { if (a->data != NULL) free((void *)a->data); a->data=NULL; a->length=0; - } + } if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) free(a); - } +} ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, const char *sn, const char *ln) - { +{ ASN1_OBJECT o; o.sn=sn; @@ -397,7 +397,7 @@ ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| ASN1_OBJECT_FLAG_DYNAMIC_DATA; return(OBJ_dup(&o)); - } +} IMPLEMENT_STACK_OF(ASN1_OBJECT) IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) |