From a1df5b66c7ad477a535e56a504d8da47e1998cfa Mon Sep 17 00:00:00 2001 From: tedu <> Date: Fri, 18 Apr 2014 00:58:49 +0000 Subject: lob a few more knf grenades in here to soften things up. --- src/lib/libcrypto/asn1/a_int.c | 80 +++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 51 deletions(-) (limited to 'src/lib/libcrypto/asn1/a_int.c') diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index f41d462ffe..cc2b985fa1 100644 --- a/src/lib/libcrypto/asn1/a_int.c +++ b/src/lib/libcrypto/asn1/a_int.c @@ -69,8 +69,7 @@ int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y) int neg, ret; /* Compare signs */ neg = x->type & V_ASN1_NEG; - if (neg != (y->type & V_ASN1_NEG)) - { + if (neg != (y->type & V_ASN1_NEG)) { if (neg) return -1; else @@ -120,8 +119,7 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) neg=a->type & V_ASN1_NEG; if (a->length == 0) ret=1; - else - { + else { ret=a->length; i=a->data[0]; if (!neg && (i > 127)) { @@ -183,8 +181,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, unsigned char *to,*s; int i; - if ((a == NULL) || ((*a) == NULL)) - { + if ((a == NULL) || ((*a) == NULL)) { if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); ret->type=V_ASN1_INTEGER; } @@ -197,8 +194,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, /* We must malloc stuff, even for 0 bytes otherwise it * signifies a missing NULL parameter. */ s=(unsigned char *)malloc((int)len+1); - if (s == NULL) - { + if (s == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } @@ -208,13 +204,12 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, * tolerate it. */ ret->type=V_ASN1_INTEGER; -} else if (*p & 0x80) /* a negative number */ - { + } else if (*p & 0x80) /* a negative number */ { ret->type=V_ASN1_NEG_INTEGER; if ((*p == 0xff) && (len != 1)) { p++; len--; - } + } i = len; p += i - 1; to += i - 1; @@ -222,7 +217,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, *(to--) = 0; i--; p--; - } + } /* Special case: if all zeros then the number will be of * the form FF followed by n zero bytes: this corresponds to * 1 followed by n zero bytes. We've already written n zeros @@ -234,20 +229,19 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, *s = 1; s[len] = 0; len++; - } else { + } else { *(to--) = (*(p--) ^ 0xff) + 1; i--; for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; - } -} else { + } + } else { ret->type=V_ASN1_INTEGER; - if ((*p == 0) && (len != 1)) - { + if ((*p == 0) && (len != 1)) { p++; len--; } memcpy(s,p,(int)len); -} + } if (ret->data != NULL) free(ret->data); ret->data=s; @@ -278,24 +272,20 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, int inf,tag,xclass; int i; - if ((a == NULL) || ((*a) == NULL)) - { + if ((a == NULL) || ((*a) == NULL)) { if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); ret->type=V_ASN1_INTEGER; - } - else + } else ret=(*a); p= *pp; inf=ASN1_get_object(&p,&len,&tag,&xclass,length); - if (inf & 0x80) - { + if (inf & 0x80) { i=ASN1_R_BAD_OBJECT_HEADER; goto err; } - if (tag != V_ASN1_INTEGER) - { + if (tag != V_ASN1_INTEGER) { i=ASN1_R_EXPECTING_AN_INTEGER; goto err; } @@ -303,21 +293,19 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, /* We must malloc stuff, even for 0 bytes otherwise it * signifies a missing NULL parameter. */ s=(unsigned char *)malloc((int)len+1); - if (s == NULL) - { + if (s == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } ret->type=V_ASN1_INTEGER; if(len) { - if ((*p == 0) && (len != 1)) - { + if ((*p == 0) && (len != 1)) { p++; len--; } memcpy(s,p,(int)len); p+=len; -} + } if (ret->data != NULL) free(ret->data); ret->data=s; @@ -340,27 +328,23 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) long d; a->type=V_ASN1_INTEGER; - if (a->length < (int)(sizeof(long)+1)) - { + if (a->length < (int)(sizeof(long)+1)) { if (a->data != NULL) free(a->data); if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL) memset((char *)a->data,0,sizeof(long)+1); } - if (a->data == NULL) - { + if (a->data == NULL) { ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); return(0); } d=v; - if (d < 0) - { + if (d < 0) { d= -d; a->type=V_ASN1_NEG_INTEGER; } - for (i=0; i>=8; @@ -384,16 +368,14 @@ long ASN1_INTEGER_get(const ASN1_INTEGER *a) else if (i != V_ASN1_INTEGER) return -1; - if (a->length > (int)sizeof(long)) - { + if (a->length > (int)sizeof(long)) { /* hmm... a bit ugly, return all ones */ return -1; } if (a->data == NULL) return 0; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { r<<=8; r|=(unsigned char)a->data[i]; } @@ -410,8 +392,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) ret=M_ASN1_INTEGER_new(); else ret=ai; - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); goto err; } @@ -420,11 +401,9 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) else ret->type=V_ASN1_INTEGER; j=BN_num_bits(bn); len=((j == 0)?0:((j/8)+1)); - if (ret->length < len+4) - { + if (ret->length < len+4) { unsigned char *new_data=realloc(ret->data, len+4); - if (!new_data) - { + if (!new_data) { ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); goto err; } @@ -432,8 +411,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai) } ret->length=BN_bn2bin(bn,ret->data); /* Correct zero case */ - if(!ret->length) - { + if(!ret->length) { ret->data[0] = 0; ret->length = 1; } -- cgit v1.2.3-55-g6feb