From cc777fd461408b419899a04c31acaa3ed6dc4816 Mon Sep 17 00:00:00 2001 From: tedu Date: Fri, 18 Apr 2014 00:58:49 +0000 Subject: [PATCH] lob a few more knf grenades in here to soften things up. --- lib/libcrypto/asn1/a_dup.c | 18 +- lib/libcrypto/asn1/a_enum.c | 24 +- lib/libcrypto/asn1/a_gentm.c | 28 +- lib/libcrypto/asn1/a_i2d_fp.c | 24 +- lib/libcrypto/asn1/a_int.c | 80 ++--- lib/libcrypto/asn1/a_object.c | 89 ++---- lib/libcrypto/asn1/a_print.c | 9 +- lib/libcrypto/asn1/a_sign.c | 34 +- lib/libcrypto/asn1/a_strex.c | 6 +- lib/libcrypto/asn1/a_strnid.c | 26 +- lib/libcrypto/asn1/a_time.c | 15 +- lib/libcrypto/asn1/a_type.c | 17 +- lib/libcrypto/asn1/a_utctm.c | 45 +-- lib/libcrypto/asn1/a_verify.c | 34 +- lib/libcrypto/asn1/ameth_lib.c | 33 +- lib/libcrypto/asn1/asn1_err.c | 3 +- lib/libcrypto/asn1/asn1_gen.c | 213 +++++-------- lib/libcrypto/asn1/asn1_lib.c | 92 ++---- lib/libcrypto/asn1/asn1_par.c | 143 +++------ lib/libcrypto/asn1/asn_mime.c | 56 ++-- lib/libcrypto/asn1/asn_moid.c | 22 +- lib/libcrypto/asn1/bio_asn1.c | 59 ++-- lib/libcrypto/asn1/bio_ndef.c | 3 +- lib/libcrypto/asn1/d2i_pr.c | 59 ++-- lib/libcrypto/asn1/d2i_pu.c | 12 +- lib/libcrypto/asn1/evp_asn1.c | 12 +- lib/libcrypto/asn1/f_enum.c | 49 +-- lib/libcrypto/asn1/f_int.c | 52 +--- lib/libcrypto/asn1/f_string.c | 46 +-- lib/libcrypto/asn1/i2d_pr.c | 3 +- lib/libcrypto/asn1/i2d_pu.c | 3 +- lib/libcrypto/asn1/n_pkey.c | 30 +- lib/libcrypto/asn1/p5_pbe.c | 15 +- lib/libcrypto/asn1/p5_pbev2.c | 30 +- lib/libcrypto/asn1/p8_pkey.c | 22 +- lib/libcrypto/asn1/t_crl.c | 3 +- lib/libcrypto/asn1/t_pkey.c | 16 +- lib/libcrypto/asn1/t_req.c | 69 ++--- lib/libcrypto/asn1/t_spki.c | 12 +- lib/libcrypto/asn1/t_x509.c | 101 ++---- lib/libcrypto/asn1/tasn_dec.c | 409 +++++++++---------------- lib/libcrypto/asn1/tasn_enc.c | 168 ++++------ lib/libcrypto/asn1/tasn_fre.c | 71 ++--- lib/libcrypto/asn1/tasn_new.c | 94 +++--- lib/libcrypto/asn1/tasn_prn.c | 139 ++++----- lib/libcrypto/asn1/tasn_utl.c | 15 +- lib/libcrypto/asn1/x_algor.c | 18 +- lib/libcrypto/asn1/x_crl.c | 79 ++--- lib/libcrypto/asn1/x_info.c | 3 +- lib/libcrypto/asn1/x_name.c | 98 +++--- lib/libcrypto/asn1/x_pkey.c | 9 +- lib/libcrypto/asn1/x_pubkey.c | 73 ++--- lib/libcrypto/asn1/x_x509.c | 6 +- lib/libcrypto/asn1/x_x509a.c | 6 +- lib/libssl/src/crypto/asn1/a_dup.c | 18 +- lib/libssl/src/crypto/asn1/a_enum.c | 24 +- lib/libssl/src/crypto/asn1/a_gentm.c | 28 +- lib/libssl/src/crypto/asn1/a_i2d_fp.c | 24 +- lib/libssl/src/crypto/asn1/a_int.c | 80 ++--- lib/libssl/src/crypto/asn1/a_object.c | 89 ++---- lib/libssl/src/crypto/asn1/a_print.c | 9 +- lib/libssl/src/crypto/asn1/a_sign.c | 34 +- lib/libssl/src/crypto/asn1/a_strex.c | 6 +- lib/libssl/src/crypto/asn1/a_strnid.c | 26 +- lib/libssl/src/crypto/asn1/a_time.c | 15 +- lib/libssl/src/crypto/asn1/a_type.c | 17 +- lib/libssl/src/crypto/asn1/a_utctm.c | 45 +-- lib/libssl/src/crypto/asn1/a_verify.c | 34 +- lib/libssl/src/crypto/asn1/ameth_lib.c | 33 +- lib/libssl/src/crypto/asn1/asn1_err.c | 3 +- lib/libssl/src/crypto/asn1/asn1_gen.c | 213 +++++-------- lib/libssl/src/crypto/asn1/asn1_lib.c | 92 ++---- lib/libssl/src/crypto/asn1/asn1_par.c | 143 +++------ lib/libssl/src/crypto/asn1/asn_mime.c | 56 ++-- lib/libssl/src/crypto/asn1/asn_moid.c | 22 +- lib/libssl/src/crypto/asn1/bio_asn1.c | 59 ++-- lib/libssl/src/crypto/asn1/bio_ndef.c | 3 +- lib/libssl/src/crypto/asn1/d2i_pr.c | 59 ++-- lib/libssl/src/crypto/asn1/d2i_pu.c | 12 +- lib/libssl/src/crypto/asn1/evp_asn1.c | 12 +- lib/libssl/src/crypto/asn1/f_enum.c | 49 +-- lib/libssl/src/crypto/asn1/f_int.c | 52 +--- lib/libssl/src/crypto/asn1/f_string.c | 46 +-- lib/libssl/src/crypto/asn1/i2d_pr.c | 3 +- lib/libssl/src/crypto/asn1/i2d_pu.c | 3 +- lib/libssl/src/crypto/asn1/n_pkey.c | 30 +- lib/libssl/src/crypto/asn1/p5_pbe.c | 15 +- lib/libssl/src/crypto/asn1/p5_pbev2.c | 30 +- lib/libssl/src/crypto/asn1/p8_pkey.c | 22 +- lib/libssl/src/crypto/asn1/t_crl.c | 3 +- lib/libssl/src/crypto/asn1/t_pkey.c | 16 +- lib/libssl/src/crypto/asn1/t_req.c | 69 ++--- lib/libssl/src/crypto/asn1/t_spki.c | 12 +- lib/libssl/src/crypto/asn1/t_x509.c | 101 ++---- lib/libssl/src/crypto/asn1/tasn_dec.c | 409 +++++++++---------------- lib/libssl/src/crypto/asn1/tasn_enc.c | 168 ++++------ lib/libssl/src/crypto/asn1/tasn_fre.c | 71 ++--- lib/libssl/src/crypto/asn1/tasn_new.c | 94 +++--- lib/libssl/src/crypto/asn1/tasn_prn.c | 139 ++++----- lib/libssl/src/crypto/asn1/tasn_utl.c | 15 +- lib/libssl/src/crypto/asn1/x_algor.c | 18 +- lib/libssl/src/crypto/asn1/x_crl.c | 79 ++--- lib/libssl/src/crypto/asn1/x_info.c | 3 +- lib/libssl/src/crypto/asn1/x_name.c | 98 +++--- lib/libssl/src/crypto/asn1/x_pkey.c | 9 +- lib/libssl/src/crypto/asn1/x_pubkey.c | 73 ++--- lib/libssl/src/crypto/asn1/x_x509.c | 6 +- lib/libssl/src/crypto/asn1/x_x509a.c | 6 +- 108 files changed, 1998 insertions(+), 3592 deletions(-) diff --git a/lib/libcrypto/asn1/a_dup.c b/lib/libcrypto/asn1/a_dup.c index 4482a893373..409bdcf2d1e 100644 --- a/lib/libcrypto/asn1/a_dup.c +++ b/lib/libcrypto/asn1/a_dup.c @@ -69,13 +69,14 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) int i; char *ret; - if (x == NULL) return(NULL); + if (x == NULL) + return(NULL); i=i2d(x,NULL); b=malloc(i+10); - if (b == NULL) - { - ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); + if (b == NULL) { + ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); + return(NULL); } p= b; i=i2d(x,&p); @@ -99,12 +100,13 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x) long i; void *ret; - if (x == NULL) return(NULL); + if (x == NULL) + return(NULL); i=ASN1_item_i2d(x,&b,it); - if (b == NULL) - { - ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); + if (b == NULL) { + ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); + return(NULL); } p= b; ret=ASN1_item_d2i(NULL,&p,i, it); diff --git a/lib/libcrypto/asn1/a_enum.c b/lib/libcrypto/asn1/a_enum.c index 77c7c2cd88a..70cea0aad21 100644 --- a/lib/libcrypto/asn1/a_enum.c +++ b/lib/libcrypto/asn1/a_enum.c @@ -74,27 +74,23 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) long d; a->type=V_ASN1_ENUMERATED; - 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_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); return(0); } d=v; - if (d < 0) - { + if (d < 0) { d= -d; a->type=V_ASN1_NEG_ENUMERATED; } - for (i=0; i>=8; @@ -118,16 +114,14 @@ long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) else if (i != V_ASN1_ENUMERATED) return -1; - if (a->length > (int)sizeof(long)) - { + if (a->length > (int)sizeof(long)) { /* hmm... a bit ugly */ return(0xffffffffL); } if (a->data == NULL) return 0; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { r<<=8; r|=(unsigned char)a->data[i]; } @@ -144,8 +138,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) ret=M_ASN1_ENUMERATED_new(); else ret=ai; - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); goto err; } @@ -153,8 +146,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) else ret->type=V_ASN1_ENUMERATED; 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) { diff --git a/lib/libcrypto/asn1/a_gentm.c b/lib/libcrypto/asn1/a_gentm.c index 54016dc8e7b..2ef6e6bc228 100644 --- a/lib/libcrypto/asn1/a_gentm.c +++ b/lib/libcrypto/asn1/a_gentm.c @@ -116,8 +116,7 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) * field so make first two fields 00 to 99 */ if (l < 13) goto err; - for (i=0; i<7; i++) - { + for (i=0; i<7; i++) { if ((i == 6) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) { i++; break; } @@ -146,12 +145,10 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) if (a[o] == 'Z') o++; - else if ((a[o] == '+') || (a[o] == '-')) - { + else if ((a[o] == '+') || (a[o] == '-')) { o++; if (o+4 > l) goto err; - for (i=7; i<9; i++) - { + for (i=7; i<9; i++) { if ((a[o] < '0') || (a[o] > '9')) goto err; n= a[o]-'0'; o++; @@ -160,9 +157,7 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) if ((n < min[i]) || (n > max[i])) goto err; o++; } - } - else - { + } else { /* Missing time zone information. */ goto err; } @@ -178,10 +173,8 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) t.type=V_ASN1_GENERALIZEDTIME; t.length=strlen(str); t.data=(unsigned char *)str; - if (ASN1_GENERALIZEDTIME_check(&t)) - { - if (s != NULL) - { + if (ASN1_GENERALIZEDTIME_check(&t)) { + if (s != NULL) { if (!ASN1_STRING_set((ASN1_STRING *)s, (unsigned char *)str,t.length)) return 0; @@ -216,18 +209,15 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, if (ts == NULL) return(NULL); - if (offset_day || offset_sec) - { + if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) return NULL; } p=(char *)s->data; - if ((p == NULL) || ((size_t)s->length < len)) - { + if ((p == NULL) || ((size_t)s->length < len)) { p=malloc(len); - if (p == NULL) - { + if (p == NULL) { ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE); return(NULL); diff --git a/lib/libcrypto/asn1/a_i2d_fp.c b/lib/libcrypto/asn1/a_i2d_fp.c index 52bedb3f737..93e6d8351bd 100644 --- a/lib/libcrypto/asn1/a_i2d_fp.c +++ b/lib/libcrypto/asn1/a_i2d_fp.c @@ -69,8 +69,7 @@ int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) BIO *b; int ret; - if ((b=BIO_new(BIO_s_file())) == NULL) - { + if ((b=BIO_new(BIO_s_file())) == NULL) { ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); return(0); } @@ -89,8 +88,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) n=i2d(x,NULL); b=(char *)malloc(n); - if (b == NULL) - { + if (b == NULL) { ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); return(0); } @@ -98,12 +96,10 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) p=(unsigned char *)b; i2d(x,&p); - for (;;) - { + for (;;) { i=BIO_write(out,&(b[j]),n); if (i == n) break; - if (i <= 0) - { + if (i <= 0) { ret=0; break; } @@ -122,8 +118,7 @@ int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) BIO *b; int ret; - if ((b=BIO_new(BIO_s_file())) == NULL) - { + if ((b=BIO_new(BIO_s_file())) == NULL) { ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); return(0); } @@ -140,18 +135,15 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) int i,j=0,n,ret=1; n = ASN1_item_i2d(x, &b, it); - if (b == NULL) - { + if (b == NULL) { ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); return(0); } - for (;;) - { + for (;;) { i=BIO_write(out,&(b[j]),n); if (i == n) break; - if (i <= 0) - { + if (i <= 0) { ret=0; break; } diff --git a/lib/libcrypto/asn1/a_int.c b/lib/libcrypto/asn1/a_int.c index f41d462ffe0..cc2b985fa10 100644 --- a/lib/libcrypto/asn1/a_int.c +++ b/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; } diff --git a/lib/libcrypto/asn1/a_object.c b/lib/libcrypto/asn1/a_object.c index 7e9eeaa2e1c..e73b1223ded 100644 --- a/lib/libcrypto/asn1/a_object.c +++ b/lib/libcrypto/asn1/a_object.c @@ -100,55 +100,45 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) p=buf; c= *(p++); num--; - if ((c >= '0') && (c <= '2')) - { + if ((c >= '0') && (c <= '2')) { first= c-'0'; - } - else - { + } else { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); goto err; } - if (num <= 0) - { + if (num <= 0) { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); goto err; } c= *(p++); num--; - for (;;) - { + for (;;) { if (num <= 0) break; - if ((c != '.') && (c != ' ')) - { + if ((c != '.') && (c != ' ')) { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); goto err; } l=0; use_bn = 0; - for (;;) - { + for (;;) { if (num <= 0) break; num--; c= *(p++); if ((c == ' ') || (c == '.')) break; - if ((c < '0') || (c > '9')) - { + 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)) - { + 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 (use_bn) { if (!BN_mul_word(bl, 10L) || !BN_add_word(bl, c-'0')) goto err; @@ -156,15 +146,12 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) else l=l*10L+(long)(c-'0'); } - if (len == 0) - { - if ((first < 2) && (l >= 40)) - { + 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 (use_bn) { if (!BN_add_word(bl, first * 40)) goto err; } @@ -172,13 +159,11 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) l+=(long)first*40; } i=0; - if (use_bn) - { + if (use_bn) { int blsize; blsize = BN_num_bits(bl); blsize = (blsize + 6)/7; - if (blsize > tmpsize) - { + if (blsize > tmpsize) { if (tmp != ftmp) free(tmp); tmpsize = blsize + 32; @@ -188,22 +173,17 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) } while(blsize--) tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); - } - else - { + } else { - for (;;) - { + for (;;) { tmp[i++]=(unsigned char)l&0x7f; l>>=7L; if (l == 0L) break; } } - if (out != NULL) - { - if (len+i > olen) - { + if (out != NULL) { + if (len+i > olen) { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); goto err; } @@ -240,8 +220,7 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) if ((a == NULL) || (a->data == NULL)) return(BIO_write(bp,"NULL",4)); i=i2t_ASN1_OBJECT(buf,sizeof buf,a); - if (i > (int)(sizeof(buf) - 1)) - { + if (i > (int)(sizeof(buf) - 1)) { p = malloc(i + 1); if (!p) return -1; @@ -265,14 +244,12 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, ASN1_OBJECT *ret = NULL; 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_OBJECT) - { + if (tag != V_ASN1_OBJECT) { i=ASN1_R_EXPECTING_AN_OBJECT; goto err; } @@ -293,10 +270,8 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, /* Sanity check OID encoding: can't have leading 0x80 in * subidentifiers, see: X.690 8.19.2 */ - for (i = 0, p = *pp; i < len; i++, p++) - { - if (*p == 0x80 && (!i || !(p[-1] & 0x80))) - { + 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; } @@ -305,8 +280,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, /* 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)) - { + !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); } else ret=(*a); @@ -316,13 +290,11 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, data = (unsigned char *)ret->data; ret->data = NULL; /* once detached we can change it */ - if ((data == NULL) || (ret->length < len)) - { + 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; } + if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; } memcpy(data,p,(int)len); @@ -349,8 +321,7 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) ASN1_OBJECT *ret; ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); return(NULL); } @@ -366,16 +337,14 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) void ASN1_OBJECT_free(ASN1_OBJECT *a) { if (a == NULL) return; - if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) - { + 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->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { if (a->data != NULL) free((void *)a->data); a->data=NULL; a->length=0; diff --git a/lib/libcrypto/asn1/a_print.c b/lib/libcrypto/asn1/a_print.c index cfd0452f13a..9e421dba668 100644 --- a/lib/libcrypto/asn1/a_print.c +++ b/lib/libcrypto/asn1/a_print.c @@ -69,8 +69,7 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len) if (len <= 0) len= -1; if (s == NULL) return(V_ASN1_PRINTABLESTRING); - while ((*s) && (len-- != 0)) - { + while ((*s) && (len-- != 0)) { c= *(s++); if (!( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || @@ -99,8 +98,7 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) if (s->type != V_ASN1_UNIVERSALSTRING) return(0); if ((s->length%4) != 0) return(0); p=s->data; - for (i=0; ilength; i+=4) - { + for (i=0; ilength; i+=4) { if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) break; else @@ -108,8 +106,7 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) } if (i < s->length) return(0); p=s->data; - for (i=3; ilength; i+=4) - { + for (i=3; ilength; i+=4) { *(p++)=s->data[i]; } *(p)='\0'; diff --git a/lib/libcrypto/asn1/a_sign.c b/lib/libcrypto/asn1/a_sign.c index 349422fe9ab..046f3b4a99a 100644 --- a/lib/libcrypto/asn1/a_sign.c +++ b/lib/libcrypto/asn1/a_sign.c @@ -131,8 +131,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, { EVP_MD_CTX ctx; EVP_MD_CTX_init(&ctx); - if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) - { + if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) { EVP_MD_CTX_cleanup(&ctx); return 0; } @@ -154,14 +153,12 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, type = EVP_MD_CTX_md(ctx); pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); - if (!type || !pkey) - { + if (!type || !pkey) { ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); return 0; } - if (pkey->ameth->item_sign) - { + if (pkey->ameth->item_sign) { rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, signature); if (rv == 1) @@ -180,15 +177,12 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, else rv = 2; - if (rv == 2) - { - if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) - { + if (rv == 2) { + if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { if (!pkey->ameth || !OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type), - pkey->ameth->pkey_id)) - { + pkey->ameth->pkey_id)) { ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); return 0; @@ -212,16 +206,14 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, inl=ASN1_item_i2d(asn,&buf_in, it); outll=outl=EVP_PKEY_size(pkey); buf_out=malloc((unsigned int)outl); - if ((buf_in == NULL) || (buf_out == NULL)) - { + if ((buf_in == NULL) || (buf_out == NULL)) { outl=0; ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); goto err; } if (!EVP_DigestSignUpdate(ctx, buf_in, inl) - || !EVP_DigestSignFinal(ctx, buf_out, &outl)) - { + || !EVP_DigestSignFinal(ctx, buf_out, &outl)) { outl=0; ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); goto err; @@ -237,9 +229,11 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; err: EVP_MD_CTX_cleanup(ctx); - if (buf_in != NULL) - { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); } - if (buf_out != NULL) - { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); } + if (buf_in != NULL) { + OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); + } + if (buf_out != NULL) { + OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); + } return(outl); } diff --git a/lib/libcrypto/asn1/a_strex.c b/lib/libcrypto/asn1/a_strex.c index 65f95532a33..7dc531a2d8b 100644 --- a/lib/libcrypto/asn1/a_strex.c +++ b/lib/libcrypto/asn1/a_strex.c @@ -405,8 +405,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, if(indent < 0) indent = 0; outlen = indent; if(!do_indent(io_ch, arg, indent)) return -1; - switch (flags & XN_FLAG_SEP_MASK) - { + switch (flags & XN_FLAG_SEP_MASK) { case XN_FLAG_SEP_MULTILINE: sep_dn = "\n"; sep_dn_len = 1; @@ -526,8 +525,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) #ifndef OPENSSL_NO_FP_API int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) { - if(flags == XN_FLAG_COMPAT) - { + if(flags == XN_FLAG_COMPAT) { BIO *btmp; int ret; btmp = BIO_new_fp(fp, BIO_NOCLOSE); diff --git a/lib/libcrypto/asn1/a_strnid.c b/lib/libcrypto/asn1/a_strnid.c index 74bc7b316cc..6c59dcc8ec6 100644 --- a/lib/libcrypto/asn1/a_strnid.c +++ b/lib/libcrypto/asn1/a_strnid.c @@ -264,26 +264,24 @@ main() int i, last_nid = -1; for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) - { - if (tmp->nid < last_nid) - { - last_nid = 0; - break; - } - last_nid = tmp->nid; + i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { + if (tmp->nid < last_nid) { + last_nid = 0; + break; } + last_nid = tmp->nid; + } - if (last_nid != 0) - { + if (last_nid != 0) { printf("Table order OK\n"); exit(0); - } + } for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) - printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, - OBJ_nid2ln(tmp->nid)); + i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { + printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, + OBJ_nid2ln(tmp->nid)); + } } diff --git a/lib/libcrypto/asn1/a_time.c b/lib/libcrypto/asn1/a_time.c index 3461660b5f9..13fd3245171 100644 --- a/lib/libcrypto/asn1/a_time.c +++ b/lib/libcrypto/asn1/a_time.c @@ -95,13 +95,11 @@ ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, struct tm data; ts=OPENSSL_gmtime(&t,&data); - if (ts == NULL) - { + if (ts == NULL) { ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); return NULL; } - if (offset_day || offset_sec) - { + if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) return NULL; } @@ -128,8 +126,7 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE if (!ASN1_TIME_check(t)) return NULL; - if (!out || !*out) - { + if (!out || !*out) { if (!(ret = ASN1_GENERALIZEDTIME_new ())) return NULL; if (out) *out = ret; @@ -137,8 +134,7 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE else ret = *out; /* If already GeneralizedTime just copy across */ - if (t->type == V_ASN1_GENERALIZEDTIME) - { + if (t->type == V_ASN1_GENERALIZEDTIME) { if(!ASN1_STRING_set(ret, t->data, t->length)) return NULL; return ret; @@ -169,8 +165,7 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) t.type = V_ASN1_UTCTIME; - if (!ASN1_TIME_check(&t)) - { + if (!ASN1_TIME_check(&t)) { t.type = V_ASN1_GENERALIZEDTIME; if (!ASN1_TIME_check(&t)) return 0; diff --git a/lib/libcrypto/asn1/a_type.c b/lib/libcrypto/asn1/a_type.c index c790d74d609..dd746e925ea 100644 --- a/lib/libcrypto/asn1/a_type.c +++ b/lib/libcrypto/asn1/a_type.c @@ -71,8 +71,7 @@ int ASN1_TYPE_get(ASN1_TYPE *a) void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) { - if (a->value.ptr != NULL) - { + if (a->value.ptr != NULL) { ASN1_TYPE **tmp_a = &a; ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); } @@ -85,21 +84,16 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) { - if (!value || (type == V_ASN1_BOOLEAN)) - { + if (!value || (type == V_ASN1_BOOLEAN)) { void *p = (void *)value; ASN1_TYPE_set(a, type, p); - } - else if (type == V_ASN1_OBJECT) - { + } else if (type == V_ASN1_OBJECT) { ASN1_OBJECT *odup; odup = OBJ_dup(value); if (!odup) return 0; ASN1_TYPE_set(a, type, odup); - } - else - { + } else { ASN1_STRING *sdup; sdup = ASN1_STRING_dup(value); if (!sdup) @@ -119,8 +113,7 @@ int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) if (!a || !b || a->type != b->type) return -1; - switch (a->type) - { + switch (a->type) { case V_ASN1_OBJECT: result = OBJ_cmp(a->value.object, b->value.object); break; diff --git a/lib/libcrypto/asn1/a_utctm.c b/lib/libcrypto/asn1/a_utctm.c index e75f2ecbb6f..d8135d04572 100644 --- a/lib/libcrypto/asn1/a_utctm.c +++ b/lib/libcrypto/asn1/a_utctm.c @@ -77,13 +77,11 @@ ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); return(NULL); } - if (!ASN1_UTCTIME_check(ret)) - { + if (!ASN1_UTCTIME_check(ret)) { ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); goto err; } @@ -110,11 +108,12 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) o=0; if (l < 11) goto err; - for (i=0; i<6; i++) - { + for (i=0; i<6; i++) { if ((i == 5) && ((a[o] == 'Z') || - (a[o] == '+') || (a[o] == '-'))) - { i++; break; } + (a[o] == '+') || (a[o] == '-'))) { + i++; + break; + } if ((a[o] < '0') || (a[o] > '9')) goto err; n= a[o]-'0'; if (++o > l) goto err; @@ -127,12 +126,10 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) } if (a[o] == 'Z') o++; - else if ((a[o] == '+') || (a[o] == '-')) - { + else if ((a[o] == '+') || (a[o] == '-')) { o++; if (o+4 > l) goto err; - for (i=6; i<8; i++) - { + for (i=6; i<8; i++) { if ((a[o] < '0') || (a[o] > '9')) goto err; n= a[o]-'0'; o++; @@ -154,18 +151,15 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) t.type=V_ASN1_UTCTIME; t.length=strlen(str); t.data=(unsigned char *)str; - if (ASN1_UTCTIME_check(&t)) - { - if (s != NULL) - { + if (ASN1_UTCTIME_check(&t)) { + if (s != NULL) { if (!ASN1_STRING_set((ASN1_STRING *)s, (unsigned char *)str,t.length)) return 0; s->type = V_ASN1_UTCTIME; } return(1); - } - else + } else return(0); } @@ -191,8 +185,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, if (ts == NULL) return(NULL); - if (offset_day || offset_sec) - { + if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) return NULL; } @@ -201,11 +194,9 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, return NULL; p=(char *)s->data; - if ((p == NULL) || ((size_t)s->length < len)) - { + if ((p == NULL) || ((size_t)s->length < len)) { p=malloc(len); - if (p == NULL) - { + if (p == NULL) { ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); return(NULL); } @@ -233,8 +224,7 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) if (s->data[12] == 'Z') offset=0; - else - { + else { offset = g2(s->data+13)*60+g2(s->data+15); if (s->data[12] == '-') offset = -offset; @@ -280,8 +270,7 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) tm.tm_sec=g2(s->data+10); if(s->data[12] == 'Z') offset=0; - else - { + else { offset=g2(s->data+13)*60+g2(s->data+15); if(s->data[12] == '-') offset= -offset; diff --git a/lib/libcrypto/asn1/a_verify.c b/lib/libcrypto/asn1/a_verify.c index 59c5b876b5f..8df0b038d15 100644 --- a/lib/libcrypto/asn1/a_verify.c +++ b/lib/libcrypto/asn1/a_verify.c @@ -81,8 +81,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, int mdnid, pknid; - if (!pkey) - { + if (!pkey) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); return -1; } @@ -90,15 +89,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, EVP_MD_CTX_init(&ctx); /* Convert signature OID into digest and public key OIDs */ - if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) - { + if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); goto err; } - if (mdnid == NID_undef) - { - if (!pkey->ameth || !pkey->ameth->item_verify) - { + if (mdnid == NID_undef) { + if (!pkey->ameth || !pkey->ameth->item_verify) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); goto err; } @@ -111,26 +107,21 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, if (ret != 2) goto err; ret = -1; - } - else - { + } else { const EVP_MD *type; type=EVP_get_digestbynid(mdnid); - if (type == NULL) - { + if (type == NULL) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); goto err; } /* Check public key OID matches public key type */ - if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) - { + if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE); goto err; } - if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) - { + if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); ret=0; goto err; @@ -140,14 +131,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, inl = ASN1_item_i2d(asn, &buf_in, it); - if (buf_in == NULL) - { + if (buf_in == NULL) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); goto err; } - if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) - { + if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); ret=0; goto err; @@ -157,8 +146,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, free(buf_in); if (EVP_DigestVerifyFinal(&ctx,signature->data, - (size_t)signature->length) <= 0) - { + (size_t)signature->length) <= 0) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); ret=0; goto err; diff --git a/lib/libcrypto/asn1/ameth_lib.c b/lib/libcrypto/asn1/ameth_lib.c index 8f96e00c932..bbaf6b4dfbd 100644 --- a/lib/libcrypto/asn1/ameth_lib.c +++ b/lib/libcrypto/asn1/ameth_lib.c @@ -150,8 +150,7 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) EVP_PKEY_ASN1_METHOD tmp; const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; tmp.pkey_id = type; - if (app_methods) - { + if (app_methods) { int idx; idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); if (idx >= 0) @@ -175,21 +174,18 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) { const EVP_PKEY_ASN1_METHOD *t; - for (;;) - { + for (;;) { t = pkey_asn1_find(type); if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS)) break; type = t->pkey_base_id; } - if (pe) - { + if (pe) { #ifndef OPENSSL_NO_ENGINE ENGINE *e; /* type will contain the final unaliased type */ e = ENGINE_get_pkey_asn1_meth_engine(type); - if (e) - { + if (e) { *pe = e; return ENGINE_get_pkey_asn1_meth(e, type); } @@ -206,13 +202,11 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const EVP_PKEY_ASN1_METHOD *ameth; if (len == -1) len = strlen(str); - if (pe) - { + if (pe) { #ifndef OPENSSL_NO_ENGINE ENGINE *e; ameth = ENGINE_pkey_asn1_find_str(&e, str, len); - if (ameth) - { + if (ameth) { /* Convert structural into * functional reference */ @@ -225,8 +219,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, #endif *pe = NULL; } - for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) - { + for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { ameth = EVP_PKEY_asn1_get0(i); if (ameth->pkey_flags & ASN1_PKEY_ALIAS) continue; @@ -239,8 +232,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) { - if (app_methods == NULL) - { + if (app_methods == NULL) { app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); if (!app_methods) return 0; @@ -299,8 +291,7 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, ameth->pkey_base_id = id; ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; - if (info) - { + if (info) { ameth->info = BUF_strdup(info); if (!ameth->info) goto err; @@ -308,8 +299,7 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, else ameth->info = NULL; - if (pem_str) - { + if (pem_str) { ameth->pem_str = BUF_strdup(pem_str); if (!ameth->pem_str) goto err; @@ -390,8 +380,7 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) { - if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) - { + if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) { if (ameth->pem_str) free(ameth->pem_str); if (ameth->info) diff --git a/lib/libcrypto/asn1/asn1_err.c b/lib/libcrypto/asn1/asn1_err.c index 582f6137444..c229c4b4dbc 100644 --- a/lib/libcrypto/asn1/asn1_err.c +++ b/lib/libcrypto/asn1/asn1_err.c @@ -323,8 +323,7 @@ void ERR_load_ASN1_strings(void) { #ifndef OPENSSL_NO_ERR - if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) - { + if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) { ERR_load_strings(0,ASN1_str_functs); ERR_load_strings(0,ASN1_str_reasons); } diff --git a/lib/libcrypto/asn1/asn1_gen.c b/lib/libcrypto/asn1/asn1_gen.c index f78aac71485..314df379f96 100644 --- a/lib/libcrypto/asn1/asn1_gen.c +++ b/lib/libcrypto/asn1/asn1_gen.c @@ -156,10 +156,8 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) return NULL; - if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) - { - if (!cnf) - { + if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) { + if (!cnf) { ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); return NULL; } @@ -183,8 +181,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) cpy_start = orig_der; /* Do we need IMPLICIT tagging? */ - if (asn1_tags.imp_tag != -1) - { + if (asn1_tags.imp_tag != -1) { /* If IMPLICIT we will replace the underlying tag */ /* Skip existing tag+len */ r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); @@ -196,8 +193,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) * original length and constructed flag should be * consistent. */ - if (r & 0x1) - { + if (r & 0x1) { /* Indefinite length constructed */ hdr_constructed = 2; hdr_len = 0; @@ -215,8 +211,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) /* Work out length in any EXPLICIT, starting from end */ - for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) - { + for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) { /* Content length: number of content octets + any padding */ len += etmp->exp_pad; etmp->exp_len = len; @@ -236,8 +231,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) /* Output explicit tags first */ - for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) - { + for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) { ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, etmp->exp_tag, etmp->exp_class); if (etmp->exp_pad) @@ -246,8 +240,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) /* If IMPLICIT, output tag */ - if (asn1_tags.imp_tag != -1) - { + if (asn1_tags.imp_tag != -1) { if (asn1_tags.imp_class == V_ASN1_UNIVERSAL && (asn1_tags.imp_tag == V_ASN1_SEQUENCE || asn1_tags.imp_tag == V_ASN1_SET) ) @@ -284,11 +277,9 @@ static int asn1_cb(const char *elem, int len, void *bitstr) int tmp_tag, tmp_class; - for(i = 0, p = elem; i < len; p++, i++) - { + for(i = 0, p = elem; i < len; p++, i++) { /* Look for the ':' in name value pairs */ - if (*p == ':') - { + if (*p == ':') { vstart = p + 1; vlen = len - (vstart - elem); len = p - elem; @@ -298,34 +289,29 @@ static int asn1_cb(const char *elem, int len, void *bitstr) utype = asn1_str2tag(elem, len); - if (utype == -1) - { + if (utype == -1) { ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); ERR_add_error_data(2, "tag=", elem); return -1; } /* If this is not a modifier mark end of string and exit */ - if (!(utype & ASN1_GEN_FLAG)) - { + if (!(utype & ASN1_GEN_FLAG)) { arg->utype = utype; arg->str = vstart; /* If no value and not end of string, error */ - if (!vstart && elem[len]) - { + if (!vstart && elem[len]) { ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); return -1; } return 0; } - switch(utype) - { + switch(utype) { - case ASN1_GEN_FLAG_IMP: + case ASN1_GEN_FLAG_IMP: /* Check for illegal multiple IMPLICIT tagging */ - if (arg->imp_tag != -1) - { + if (arg->imp_tag != -1) { ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); return -1; } @@ -333,7 +319,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr) return -1; break; - case ASN1_GEN_FLAG_EXP: + case ASN1_GEN_FLAG_EXP: if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class)) return -1; @@ -341,27 +327,27 @@ static int asn1_cb(const char *elem, int len, void *bitstr) return -1; break; - case ASN1_GEN_FLAG_SEQWRAP: + case ASN1_GEN_FLAG_SEQWRAP: if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1)) return -1; break; - case ASN1_GEN_FLAG_SETWRAP: + case ASN1_GEN_FLAG_SETWRAP: if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1)) return -1; break; - case ASN1_GEN_FLAG_BITWRAP: + case ASN1_GEN_FLAG_BITWRAP: if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1)) return -1; break; - case ASN1_GEN_FLAG_OCTWRAP: + case ASN1_GEN_FLAG_OCTWRAP: if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1)) return -1; break; - case ASN1_GEN_FLAG_FORMAT: + case ASN1_GEN_FLAG_FORMAT: if (!strncmp(vstart, "ASCII", 5)) arg->format = ASN1_GEN_FORMAT_ASCII; else if (!strncmp(vstart, "UTF8", 4)) @@ -370,8 +356,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr) arg->format = ASN1_GEN_FORMAT_HEX; else if (!strncmp(vstart, "BITLIST", 7)) arg->format = ASN1_GEN_FORMAT_BITLIST; - else - { + else { ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); return -1; } @@ -394,8 +379,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) /* Check we haven't gone past max length: should be impossible */ if (eptr && *eptr && (eptr > vstart + vlen)) return 0; - if (tag_num < 0) - { + if (tag_num < 0) { ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); return 0; } @@ -405,24 +389,22 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) vlen -= eptr - vstart; else vlen = 0; - if (vlen) - { - switch (*eptr) - { + if (vlen) { + switch (*eptr) { - case 'U': + case 'U': *pclass = V_ASN1_UNIVERSAL; break; - case 'A': + case 'A': *pclass = V_ASN1_APPLICATION; break; - case 'P': + case 'P': *pclass = V_ASN1_PRIVATE; break; - case 'C': + case 'C': *pclass = V_ASN1_CONTEXT_SPECIFIC; break; @@ -456,15 +438,13 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) sk = sk_ASN1_TYPE_new_null(); if (!sk) goto bad; - if (section) - { + if (section) { if (!cnf) goto bad; sect = X509V3_get_section(cnf, (char *)section); if (!sect) goto bad; - for (i = 0; i < sk_CONF_VALUE_num(sect); i++) - { + for (i = 0; i < sk_CONF_VALUE_num(sect); i++) { ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); if (!typ) goto bad; @@ -513,14 +493,12 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons { tag_exp_type *exp_tmp; /* Can only have IMPLICIT if permitted */ - if ((arg->imp_tag != -1) && !imp_ok) - { + if ((arg->imp_tag != -1) && !imp_ok) { ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); return 0; } - if (arg->exp_count == ASN1_FLAG_EXP_MAX) - { + if (arg->exp_count == ASN1_FLAG_EXP_MAX) { ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); return 0; } @@ -530,15 +508,12 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons /* If IMPLICIT set tag to implicit value then * reset implicit tag since it has been used. */ - if (arg->imp_tag != -1) - { + if (arg->imp_tag != -1) { exp_tmp->exp_tag = arg->imp_tag; exp_tmp->exp_class = arg->imp_class; arg->imp_tag = -1; arg->imp_class = -1; - } - else - { + } else { exp_tmp->exp_tag = exp_tag; exp_tmp->exp_class = exp_class; } @@ -617,8 +592,7 @@ static int asn1_str2tag(const char *tagstr, int len) len = strlen(tagstr); tntmp = tnst; - for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) - { + for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) { if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) return tntmp->tag; } @@ -637,8 +611,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) int no_unused = 1; - if (!(atmp = ASN1_TYPE_new())) - { + if (!(atmp = ASN1_TYPE_new())) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); return NULL; } @@ -646,110 +619,96 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) if (!str) str = ""; - switch(utype) - { + switch(utype) { - case V_ASN1_NULL: - if (str && *str) - { + case V_ASN1_NULL: + if (str && *str) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); goto bad_form; } break; - case V_ASN1_BOOLEAN: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_BOOLEAN: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); goto bad_form; } vtmp.name = NULL; vtmp.section = NULL; vtmp.value = (char *)str; - if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) - { + if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); goto bad_str; } break; - case V_ASN1_INTEGER: - case V_ASN1_ENUMERATED: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_INTEGER: + case V_ASN1_ENUMERATED: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) - { + if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); goto bad_str; } break; - case V_ASN1_OBJECT: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_OBJECT: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.object = OBJ_txt2obj(str, 0))) - { + if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); goto bad_str; } break; - case V_ASN1_UTCTIME: - case V_ASN1_GENERALIZEDTIME: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_UTCTIME: + case V_ASN1_GENERALIZEDTIME: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.asn1_string = ASN1_STRING_new())) - { + if (!(atmp->value.asn1_string = ASN1_STRING_new())) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } - if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) - { + if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } atmp->value.asn1_string->type = utype; - if (!ASN1_TIME_check(atmp->value.asn1_string)) - { + if (!ASN1_TIME_check(atmp->value.asn1_string)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); goto bad_str; } break; - case V_ASN1_BMPSTRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_IA5STRING: - case V_ASN1_T61STRING: - case V_ASN1_UTF8STRING: - case V_ASN1_VISIBLESTRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_GENERALSTRING: - case V_ASN1_NUMERICSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_PRINTABLESTRING: + case V_ASN1_IA5STRING: + case V_ASN1_T61STRING: + case V_ASN1_UTF8STRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_NUMERICSTRING: if (format == ASN1_GEN_FORMAT_ASCII) format = MBSTRING_ASC; else if (format == ASN1_GEN_FORMAT_UTF8) format = MBSTRING_UTF8; - else - { + else { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); goto bad_form; } if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, - -1, format, ASN1_tag2bit(utype)) <= 0) - { + -1, format, ASN1_tag2bit(utype)) <= 0) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } @@ -757,21 +716,18 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) break; - case V_ASN1_BIT_STRING: + case V_ASN1_BIT_STRING: - case V_ASN1_OCTET_STRING: + case V_ASN1_OCTET_STRING: - if (!(atmp->value.asn1_string = ASN1_STRING_new())) - { + if (!(atmp->value.asn1_string = ASN1_STRING_new())) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_form; } - if (format == ASN1_GEN_FORMAT_HEX) - { + if (format == ASN1_GEN_FORMAT_HEX) { - if (!(rdata = string_to_hex((char *)str, &rdlen))) - { + if (!(rdata = string_to_hex((char *)str, &rdlen))) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); goto bad_str; } @@ -783,24 +739,19 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) } else if (format == ASN1_GEN_FORMAT_ASCII) ASN1_STRING_set(atmp->value.asn1_string, str, -1); - else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) - { - if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) - { + else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) { + if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); goto bad_str; } no_unused = 0; - } - else - { + } else { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); goto bad_form; } - if ((utype == V_ASN1_BIT_STRING) && no_unused) - { + if ((utype == V_ASN1_BIT_STRING) && no_unused) { atmp->value.asn1_string->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); atmp->value.asn1_string->flags @@ -810,7 +761,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) break; - default: + default: ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); goto bad_str; break; @@ -821,9 +772,9 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) return atmp; - bad_str: +bad_str: ERR_add_error_data(2, "string=", str); - bad_form: +bad_form: ASN1_TYPE_free(atmp); return NULL; @@ -839,13 +790,11 @@ static int bitstr_cb(const char *elem, int len, void *bitstr) bitnum = strtoul(elem, &eptr, 10); if (eptr && *eptr && (eptr != elem + len)) return 0; - if (bitnum < 0) - { + if (bitnum < 0) { ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); return 0; } - if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) - { + if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) { ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/lib/libcrypto/asn1/asn1_lib.c b/lib/libcrypto/asn1/asn1_lib.c index 6ec383859fc..7693556281e 100644 --- a/lib/libcrypto/asn1/asn1_lib.c +++ b/lib/libcrypto/asn1/asn1_lib.c @@ -72,8 +72,7 @@ static int _asn1_check_infinite_end(const unsigned char **p, long len) * things up */ if (len <= 0) return(1); - else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) - { + else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) { (*p)+=2; return(1); } @@ -104,13 +103,11 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMITIVE_TAG; - if (i == V_ASN1_PRIMITIVE_TAG) - { /* high-tag */ + if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */ p++; if (--max == 0) goto err; l=0; - while (*p&0x80) - { + while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; @@ -120,9 +117,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, l|= *(p++)&0x7f; tag=(int)l; if (--max == 0) goto err; - } - else - { + } else { tag=i; p++; if (--max == 0) goto err; @@ -137,8 +132,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, (int)(omax+ *pp)); #endif - if (*plength > (omax - (p - *pp))) - { + if (*plength > (omax - (p - *pp))) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); /* Set this so that even if things are not long enough * the values are set correctly */ @@ -158,23 +152,18 @@ static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max unsigned int i; if (max-- < 1) return(0); - if (*p == 0x80) - { + if (*p == 0x80) { *inf=1; ret=0; p++; - } - else - { + } else { *inf=0; i= *p&0x7f; - if (*(p++) & 0x80) - { + if (*(p++) & 0x80) { if (i > sizeof(long)) return 0; if (max-- == 0) return(0); - while (i-- > 0) - { + while (i-- > 0) { ret<<=8L; ret|= *(p++); if (max-- == 0) return(0); @@ -202,13 +191,11 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, i|=(xclass&V_ASN1_PRIVATE); if (tag < 31) *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); - else - { + else { *(p++)=i|V_ASN1_PRIMITIVE_TAG; for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; ttag = i; - while(i-- > 0) - { + while(i-- > 0) { p[i] = tag & 0x7f; if(i != (ttag - 1)) p[i] |= 0x80; tag >>= 7; @@ -237,15 +224,13 @@ static void asn1_put_length(unsigned char **pp, int length) int i,l; if (length <= 127) *(p++)=(unsigned char)length; - else - { + else { l=length; for (i=0; l > 0; i++) l>>=8; *(p++)=i|0x80; l=i; - while (i-- > 0) - { + while (i-- > 0) { p[i]=length&0xff; length>>=8; } @@ -260,10 +245,8 @@ int ASN1_object_size(int constructed, int length, int tag) ret=length; ret++; - if (tag >= 31) - { - while (tag > 0) - { + if (tag >= 31) { + while (tag > 0) { tag>>=7; ret++; } @@ -271,10 +254,8 @@ int ASN1_object_size(int constructed, int length, int tag) if (constructed == 2) return ret + 3; ret++; - if (length > 127) - { - while (length > 0) - { + if (length > 127) { + while (length > 0) { length>>=8; ret++; } @@ -284,17 +265,14 @@ int ASN1_object_size(int constructed, int length, int tag) static int _asn1_Finish(ASN1_const_CTX *c) { - if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) - { - if (!ASN1_const_check_infinite_end(&c->p,c->slen)) - { + if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) { + if (!ASN1_const_check_infinite_end(&c->p,c->slen)) { c->error=ERR_R_MISSING_ASN1_EOS; return(0); } } if ( ((c->slen != 0) && !(c->inf & 1)) || - ((c->slen < 0) && (c->inf & 1))) - { + ((c->slen < 0) && (c->inf & 1))) { c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } @@ -318,19 +296,16 @@ int asn1_GetSequence(ASN1_const_CTX *c, long *length) q=c->p; c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), *length); - if (c->inf & 0x80) - { + if (c->inf & 0x80) { c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; return(0); } - if (c->tag != V_ASN1_SEQUENCE) - { + if (c->tag != V_ASN1_SEQUENCE) { c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; return(0); } (*length)-=(c->p-q); - if (c->max && (*length < 0)) - { + if (c->max && (*length < 0)) { c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } @@ -359,8 +334,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) ret=ASN1_STRING_new(); if (!ret) return NULL; - if (!ASN1_STRING_copy(ret,str)) - { + if (!ASN1_STRING_copy(ret,str)) { ASN1_STRING_free(ret); return NULL; } @@ -372,31 +346,27 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) unsigned char *c; const char *data=_data; - if (len < 0) - { + if (len < 0) { if (data == NULL) return(0); else len=strlen(data); } - if ((str->length < len) || (str->data == NULL)) - { + if ((str->length < len) || (str->data == NULL)) { c=str->data; if (c == NULL) str->data=malloc(len+1); else str->data=realloc(c,len+1); - if (str->data == NULL) - { + if (str->data == NULL) { ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); str->data=c; return(0); } } str->length=len; - if (data != NULL) - { + if (data != NULL) { memcpy(str->data,data,len); /* an allowance for strings :-) */ str->data[len]='\0'; @@ -423,8 +393,7 @@ ASN1_STRING *ASN1_STRING_type_new(int type) ASN1_STRING *ret; ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); return(NULL); } @@ -448,8 +417,7 @@ int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) int i; i=(a->length-b->length); - if (i == 0) - { + if (i == 0) { i=memcmp(a->data,b->data,a->length); if (i == 0) return(a->type-b->type); diff --git a/lib/libcrypto/asn1/asn1_par.c b/lib/libcrypto/asn1/asn1_par.c index d68d4a82984..d3d2f524819 100644 --- a/lib/libcrypto/asn1/asn1_par.c +++ b/lib/libcrypto/asn1/asn1_par.c @@ -129,15 +129,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse p= *pp; tot=p+length; op=p-1; - while ((p < tot) && (op < p)) - { + while ((p < tot) && (op < p)) { op=p; j=ASN1_get_object(&p,&len,&tag,&xclass,length); #ifdef LINT j=j; #endif - if (j & 0x80) - { + if (j & 0x80) { if (BIO_write(bp,"Error in encoding\n",18) <= 0) goto end; ret=0; @@ -149,35 +147,28 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp)) <= 0) goto end; - if (j != (V_ASN1_CONSTRUCTED | 1)) - { + if (j != (V_ASN1_CONSTRUCTED | 1)) { if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", depth,(long)hl,len) <= 0) goto end; - } - else - { + } else { if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", depth,(long)hl) <= 0) goto end; } if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) goto end; - if (j & V_ASN1_CONSTRUCTED) - { + if (j & V_ASN1_CONSTRUCTED) { ep=p+len; if (BIO_write(bp,"\n",1) <= 0) goto end; - if (len > length) - { + if (len > length) { BIO_printf(bp, "length is greater than %ld\n",length); ret=0; goto end; } - if ((j == 0x21) && (len == 0)) - { - for (;;) - { + if ((j == 0x21) && (len == 0)) { + for (;;) { r=asn1_parse2(bp,&p,(long)(tot-p), offset+(p - *pp),depth+1, indent,dump); @@ -186,21 +177,16 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse } } else - while (p < ep) - { + while (p < ep) { r=asn1_parse2(bp,&p,(long)len, offset+(p - *pp),depth+1, indent,dump); if (r == 0) { ret=0; goto end; } } - } - else if (xclass != 0) - { + } else if (xclass != 0) { p+=len; if (BIO_write(bp,"\n",1) <= 0) goto end; - } - else - { + } else { nl=0; if ( (tag == V_ASN1_PRINTABLESTRING) || (tag == V_ASN1_T61STRING) || @@ -209,95 +195,72 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse (tag == V_ASN1_NUMERICSTRING) || (tag == V_ASN1_UTF8STRING) || (tag == V_ASN1_UTCTIME) || - (tag == V_ASN1_GENERALIZEDTIME)) - { + (tag == V_ASN1_GENERALIZEDTIME)) { if (BIO_write(bp,":",1) <= 0) goto end; if ((len > 0) && BIO_write(bp,(const char *)p,(int)len) != (int)len) goto end; - } - else if (tag == V_ASN1_OBJECT) - { + } else if (tag == V_ASN1_OBJECT) { opp=op; - if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) - { + if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) { if (BIO_write(bp,":",1) <= 0) goto end; i2a_ASN1_OBJECT(bp,o); - } - else - { + } else { if (BIO_write(bp,":BAD OBJECT",11) <= 0) goto end; } - } - else if (tag == V_ASN1_BOOLEAN) - { + } else if (tag == V_ASN1_BOOLEAN) { int ii; opp=op; ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); - if (ii < 0) - { + if (ii < 0) { if (BIO_write(bp,"Bad boolean\n",12) <= 0) goto end; } BIO_printf(bp,":%d",ii); - } - else if (tag == V_ASN1_BMPSTRING) - { + } else if (tag == V_ASN1_BMPSTRING) { /* do the BMP thang */ - } - else if (tag == V_ASN1_OCTET_STRING) - { + } else if (tag == V_ASN1_OCTET_STRING) { int i,printable=1; opp=op; os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); - if (os != NULL && os->length > 0) - { + if (os != NULL && os->length > 0) { opp = os->data; /* testing whether the octet string is * printable */ - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (( (opp[i] < ' ') && (opp[i] != '\n') && (opp[i] != '\r') && (opp[i] != '\t')) || - (opp[i] > '~')) - { + (opp[i] > '~')) { printable=0; break; } } - if (printable) + if (printable) { /* printable string */ - { if (BIO_write(bp,":",1) <= 0) goto end; if (BIO_write(bp,(const char *)opp, os->length) <= 0) goto end; - } - else if (!dump) + } else if (!dump) { /* not printable => print octet string * as hex dump */ - { if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) goto end; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02X" , opp[i]) <= 0) goto end; } - } - else + } else { /* print the normal dump */ - { - if (!nl) - { + if (!nl) { if (BIO_write(bp,"\n",1) <= 0) goto end; } @@ -310,80 +273,62 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse nl=1; } } - if (os != NULL) - { + if (os != NULL) { M_ASN1_OCTET_STRING_free(os); os=NULL; } - } - else if (tag == V_ASN1_INTEGER) - { + } else if (tag == V_ASN1_INTEGER) { ASN1_INTEGER *bs; int i; opp=op; bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); - if (bs != NULL) - { + if (bs != NULL) { if (BIO_write(bp,":",1) <= 0) goto end; if (bs->type == V_ASN1_NEG_INTEGER) if (BIO_write(bp,"-",1) <= 0) goto end; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02X", bs->data[i]) <= 0) goto end; } - if (bs->length == 0) - { + if (bs->length == 0) { if (BIO_write(bp,"00",2) <= 0) goto end; } - } - else - { + } else { if (BIO_write(bp,"BAD INTEGER",11) <= 0) goto end; } M_ASN1_INTEGER_free(bs); - } - else if (tag == V_ASN1_ENUMERATED) - { + } else if (tag == V_ASN1_ENUMERATED) { ASN1_ENUMERATED *bs; int i; opp=op; bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); - if (bs != NULL) - { + if (bs != NULL) { if (BIO_write(bp,":",1) <= 0) goto end; if (bs->type == V_ASN1_NEG_ENUMERATED) if (BIO_write(bp,"-",1) <= 0) goto end; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02X", bs->data[i]) <= 0) goto end; } - if (bs->length == 0) - { + if (bs->length == 0) { if (BIO_write(bp,"00",2) <= 0) goto end; } - } - else - { + } else { if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) goto end; } M_ASN1_ENUMERATED_free(bs); - } - else if (len > 0 && dump) - { - if (!nl) - { + } else if (len > 0 && dump) { + if (!nl) { if (BIO_write(bp,"\n",1) <= 0) goto end; } @@ -394,13 +339,11 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse nl=1; } - if (!nl) - { + if (!nl) { if (BIO_write(bp,"\n",1) <= 0) goto end; } p+=len; - if ((tag == V_ASN1_EOC) && (xclass == 0)) - { + if ((tag == V_ASN1_EOC) && (xclass == 0)) { ret=2; /* End of sequence */ goto end; } @@ -429,7 +372,7 @@ const char *ASN1_tag2str(int tag) }; if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) - tag &= ~0x100; + tag &= ~0x100; if(tag < 0 || tag > 30) return "(unknown)"; return tag2str[tag]; diff --git a/lib/libcrypto/asn1/asn_mime.c b/lib/libcrypto/asn1/asn_mime.c index 011b97ff920..6cde8fd44e3 100644 --- a/lib/libcrypto/asn1/asn_mime.c +++ b/lib/libcrypto/asn1/asn_mime.c @@ -116,20 +116,17 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, const ASN1_ITEM *it) { /* If streaming create stream BIO and copy all content through it */ - if (flags & SMIME_STREAM) - { + if (flags & SMIME_STREAM) { BIO *bio, *tbio; bio = BIO_new_NDEF(out, val, it); - if (!bio) - { + if (!bio) { ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); return 0; } SMIME_crlf_copy(in, bio, flags); (void)BIO_flush(bio); /* Free up successive BIOs until we hit the old output BIO */ - do - { + do { tbio = BIO_pop(bio); BIO_free(bio); bio = tbio; @@ -151,8 +148,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, BIO *b64; int r; b64 = BIO_new(BIO_f_base64()); - if(!b64) - { + if(!b64) { ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); return 0; } @@ -205,20 +201,17 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) int i, have_unknown = 0, write_comma, ret = 0, md_nid; have_unknown = 0; write_comma = 0; - for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) - { + for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) { if (write_comma) BIO_write(out, ",", 1); write_comma = 1; md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); md = EVP_get_digestbynid(md_nid); - if (md && md->md_ctrl) - { + if (md && md->md_ctrl) { int rv; char *micstr; rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); - if (rv > 0) - { + if (rv > 0) { BIO_puts(out, micstr); free(micstr); continue; @@ -226,8 +219,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) if (rv != -2) goto err; } - switch(md_nid) - { + switch(md_nid) { case NID_sha1: BIO_puts(out, "sha1"); break; @@ -256,8 +248,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) default: if (have_unknown) write_comma = 0; - else - { + else { BIO_puts(out, "unknown"); have_unknown = 1; } @@ -338,17 +329,14 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, if (ctype_nid == NID_pkcs7_enveloped) msg_type = "enveloped-data"; - else if (ctype_nid == NID_pkcs7_signed) - { + else if (ctype_nid == NID_pkcs7_signed) { if (econt_nid == NID_id_smime_ct_receipt) msg_type = "signed-receipt"; else if (sk_X509_ALGOR_num(mdalgs) >= 0) msg_type = "signed-data"; else msg_type = "certs-only"; - } - else if (ctype_nid == NID_id_smime_ct_compressedData) - { + } else if (ctype_nid == NID_id_smime_ct_compressedData) { msg_type = "compressed-data"; cname = "smime.p7z"; } @@ -382,14 +370,12 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, /* If data is not deteched or resigning then the output BIO is * already set up to finalise when it is written through. */ - if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) - { + if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) { SMIME_crlf_copy(data, out, flags); return 1; } - if (!aux || !aux->asn1_cb) - { + if (!aux || !aux->asn1_cb) { ASN1err(ASN1_F_ASN1_OUTPUT_DATA, ASN1_R_STREAMING_NOT_SUPPORTED); return 0; @@ -413,8 +399,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, /* Now remove any digests prepended to the BIO */ - while (sarg.ndef_bio != out) - { + while (sarg.ndef_bio != out) { tmpbio = BIO_pop(sarg.ndef_bio); BIO_free(sarg.ndef_bio); sarg.ndef_bio = tmpbio; @@ -547,17 +532,13 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) if (!bf) return 0; out = BIO_push(bf, out); - if(flags & SMIME_BINARY) - { + if(flags & SMIME_BINARY) { while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) BIO_write(out, linebuf, len); - } - else - { + } else { if(flags & SMIME_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); - while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) - { + while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) { eol = strip_eol(linebuf, &len); if (len) BIO_write(out, linebuf, len); @@ -944,8 +925,7 @@ static int strip_eol(char *linebuf, int *plen) char *p, c; int is_eol = 0; p = linebuf + len - 1; - for (p = linebuf + len - 1; len > 0; len--, p--) - { + for (p = linebuf + len - 1; len > 0; len--, p--) { c = *p; if (c == '\n') is_eol = 1; diff --git a/lib/libcrypto/asn1/asn_moid.c b/lib/libcrypto/asn1/asn_moid.c index 7521496d676..0c09a8e9347 100644 --- a/lib/libcrypto/asn1/asn_moid.c +++ b/lib/libcrypto/asn1/asn_moid.c @@ -75,16 +75,13 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *oval; oid_section = CONF_imodule_get_value(md); - if(!(sktmp = NCONF_get_section(cnf, oid_section))) - { + if(!(sktmp = NCONF_get_section(cnf, oid_section))) { ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); return 0; } - for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) - { + for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { oval = sk_CONF_VALUE_value(sktmp, i); - if(!do_create(oval->value, oval->name)) - { + if(!do_create(oval->value, oval->name)) { ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); return 0; } @@ -114,13 +111,10 @@ static int do_create(char *value, char *name) ASN1_OBJECT *oid; char *ln, *ostr, *p, *lntmp; p = strrchr(value, ','); - if (!p) - { + if (!p) { ln = name; ostr = value; - } - else - { + } else { ln = NULL; ostr = p + 1; if (!*ostr) @@ -133,13 +127,11 @@ static int do_create(char *value, char *name) if (nid == NID_undef) return 0; - if (p) - { + if (p) { ln = value; while(isspace((unsigned char)*ln)) ln++; p--; - while(isspace((unsigned char)*p)) - { + while(isspace((unsigned char)*p)) { if (p == ln) return 0; p--; diff --git a/lib/libcrypto/asn1/bio_asn1.c b/lib/libcrypto/asn1/bio_asn1.c index a6ad850e46e..8ebac02a00a 100644 --- a/lib/libcrypto/asn1/bio_asn1.c +++ b/lib/libcrypto/asn1/bio_asn1.c @@ -210,20 +210,18 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) wrlen = 0; ret = -1; - for(;;) - { - switch (ctx->state) - { + for(;;) { + switch (ctx->state) { /* Setup prefix data, call it */ - case ASN1_STATE_START: + case ASN1_STATE_START: if (!asn1_bio_setup_ex(b, ctx, ctx->prefix, ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER)) return 0; break; /* Copy any pre data first */ - case ASN1_STATE_PRE_COPY: + case ASN1_STATE_PRE_COPY: ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free, ASN1_STATE_HEADER); @@ -233,7 +231,7 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) break; - case ASN1_STATE_HEADER: + case ASN1_STATE_HEADER: ctx->buflen = ASN1_object_size(0, inl, ctx->asn1_tag) - inl; OPENSSL_assert(ctx->buflen <= ctx->bufsize); @@ -245,7 +243,7 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) break; - case ASN1_STATE_HEADER_COPY: + case ASN1_STATE_HEADER_COPY: ret = BIO_write(b->next_bio, ctx->buf + ctx->bufpos, ctx->buflen); if (ret <= 0) @@ -254,15 +252,14 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) ctx->buflen -= ret; if (ctx->buflen) ctx->bufpos += ret; - else - { + else { ctx->bufpos = 0; ctx->state = ASN1_STATE_DATA_COPY; } break; - case ASN1_STATE_DATA_COPY: + case ASN1_STATE_DATA_COPY: if (inl > ctx->copylen) wrmax = ctx->copylen; @@ -306,8 +303,7 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, int ret; if (ctx->ex_len <= 0) return 1; - for(;;) - { + for(;;) { ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, ctx->ex_len); if (ret <= 0) @@ -315,8 +311,7 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, ctx->ex_len -= ret; if (ctx->ex_len > 0) ctx->ex_pos += ret; - else - { + else { if(cleanup) cleanup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg); @@ -333,8 +328,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_bio_state_t ex_state, asn1_bio_state_t other_state) { - if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) - { + if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) { BIO_clear_retry_flags(b); return 0; } @@ -378,55 +372,52 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) ctx = (BIO_ASN1_BUF_CTX *) b->ptr; if (ctx == NULL) return 0; - switch(cmd) - { + switch(cmd) { - case BIO_C_SET_PREFIX: + case BIO_C_SET_PREFIX: ex_func = arg2; ctx->prefix = ex_func->ex_func; ctx->prefix_free = ex_func->ex_free_func; break; - case BIO_C_GET_PREFIX: + case BIO_C_GET_PREFIX: ex_func = arg2; ex_func->ex_func = ctx->prefix; ex_func->ex_free_func = ctx->prefix_free; break; - case BIO_C_SET_SUFFIX: + case BIO_C_SET_SUFFIX: ex_func = arg2; ctx->suffix = ex_func->ex_func; ctx->suffix_free = ex_func->ex_free_func; break; - case BIO_C_GET_SUFFIX: + case BIO_C_GET_SUFFIX: ex_func = arg2; ex_func->ex_func = ctx->suffix; ex_func->ex_free_func = ctx->suffix_free; break; - case BIO_C_SET_EX_ARG: + case BIO_C_SET_EX_ARG: ctx->ex_arg = arg2; break; - case BIO_C_GET_EX_ARG: + case BIO_C_GET_EX_ARG: *(void **)arg2 = ctx->ex_arg; break; - case BIO_CTRL_FLUSH: + case BIO_CTRL_FLUSH: if (!b->next_bio) return 0; /* Call post function if possible */ - if (ctx->state == ASN1_STATE_HEADER) - { + if (ctx->state == ASN1_STATE_HEADER) { if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) return 0; } - if (ctx->state == ASN1_STATE_POST_COPY) - { + if (ctx->state == ASN1_STATE_POST_COPY) { ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, ASN1_STATE_DONE); if (ret <= 0) @@ -435,15 +426,14 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) if (ctx->state == ASN1_STATE_DONE) return BIO_ctrl(b->next_bio, cmd, arg1, arg2); - else - { + else { BIO_clear_retry_flags(b); return 0; } break; - default: + default: if (!b->next_bio) return 0; return BIO_ctrl(b->next_bio, cmd, arg1, arg2); @@ -468,8 +458,7 @@ static int asn1_bio_get_ex(BIO *b, int cmd, BIO_ASN1_EX_FUNCS extmp; int ret; ret = BIO_ctrl(b, cmd, 0, &extmp); - if (ret > 0) - { + if (ret > 0) { *ex_func = extmp.ex_func; *ex_free_func = extmp.ex_free_func; } diff --git a/lib/libcrypto/asn1/bio_ndef.c b/lib/libcrypto/asn1/bio_ndef.c index b8dc80a7b23..595e6471c29 100644 --- a/lib/libcrypto/asn1/bio_ndef.c +++ b/lib/libcrypto/asn1/bio_ndef.c @@ -105,8 +105,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) const ASN1_AUX *aux = it->funcs; ASN1_STREAM_ARG sarg; - if (!aux || !aux->asn1_cb) - { + if (!aux || !aux->asn1_cb) { ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); return NULL; } diff --git a/lib/libcrypto/asn1/d2i_pr.c b/lib/libcrypto/asn1/d2i_pr.c index cbbcdae7df5..5e6003ca5b1 100644 --- a/lib/libcrypto/asn1/d2i_pr.c +++ b/lib/libcrypto/asn1/d2i_pr.c @@ -73,37 +73,29 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, { EVP_PKEY *ret; - if ((a == NULL) || (*a == NULL)) - { - if ((ret=EVP_PKEY_new()) == NULL) - { + if ((a == NULL) || (*a == NULL)) { + if ((ret=EVP_PKEY_new()) == NULL) { ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); return(NULL); } - } - else - { + } else { ret= *a; #ifndef OPENSSL_NO_ENGINE - if (ret->engine) - { + if (ret->engine) { ENGINE_finish(ret->engine); ret->engine = NULL; } #endif } - if (!EVP_PKEY_set_type(ret, type)) - { + if (!EVP_PKEY_set_type(ret, type)) { ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; } if (!ret->ameth->old_priv_decode || - !ret->ameth->old_priv_decode(ret, pp, length)) - { - if (ret->ameth->priv_decode) - { + !ret->ameth->old_priv_decode(ret, pp, length)) { + if (ret->ameth->priv_decode) { PKCS8_PRIV_KEY_INFO *p8=NULL; p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); if (!p8) goto err; @@ -111,9 +103,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, ret = EVP_PKCS82PKEY(p8); PKCS8_PRIV_KEY_INFO_free(p8); - } - else - { + } else { ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); goto err; } @@ -146,25 +136,24 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, keytype = EVP_PKEY_DSA; else if (sk_ASN1_TYPE_num(inkey) == 4) keytype = EVP_PKEY_EC; - else if (sk_ASN1_TYPE_num(inkey) == 3) - { /* This seems to be PKCS8, not traditional format */ - PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); - EVP_PKEY *ret; + else if (sk_ASN1_TYPE_num(inkey) == 3) { + /* This seems to be PKCS8, not traditional format */ + PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); + EVP_PKEY *ret; - sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); - if (!p8) - { - ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); - return NULL; - } - ret = EVP_PKCS82PKEY(p8); - PKCS8_PRIV_KEY_INFO_free(p8); - if (a) { - *a = ret; + sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); + if (!p8) { + ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); + return NULL; + } + ret = EVP_PKCS82PKEY(p8); + PKCS8_PRIV_KEY_INFO_free(p8); + if (a) { + *a = ret; } - return ret; - } - else keytype = EVP_PKEY_RSA; + return ret; + } else + keytype = EVP_PKEY_RSA; sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); return d2i_PrivateKey(keytype, a, pp, length); } diff --git a/lib/libcrypto/asn1/d2i_pu.c b/lib/libcrypto/asn1/d2i_pu.c index f04d230d706..ccd03c066f3 100644 --- a/lib/libcrypto/asn1/d2i_pu.c +++ b/lib/libcrypto/asn1/d2i_pu.c @@ -77,24 +77,20 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, { EVP_PKEY *ret; - if ((a == NULL) || (*a == NULL)) - { - if ((ret=EVP_PKEY_new()) == NULL) - { + if ((a == NULL) || (*a == NULL)) { + if ((ret=EVP_PKEY_new()) == NULL) { ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); return(NULL); } } else ret= *a; - if (!EVP_PKEY_set_type(ret, type)) - { + if (!EVP_PKEY_set_type(ret, type)) { ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); goto err; } - switch (EVP_PKEY_id(ret)) - { + switch (EVP_PKEY_id(ret)) { #ifndef OPENSSL_NO_RSA case EVP_PKEY_RSA: if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, diff --git a/lib/libcrypto/asn1/evp_asn1.c b/lib/libcrypto/asn1/evp_asn1.c index 631924f88e8..d4ea675f89b 100644 --- a/lib/libcrypto/asn1/evp_asn1.c +++ b/lib/libcrypto/asn1/evp_asn1.c @@ -78,8 +78,7 @@ int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int ret,num; unsigned char *p; - if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) - { + if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); return(-1); } @@ -115,8 +114,7 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, if ((osp=ASN1_STRING_new()) == NULL) return(0); /* Grow the 'string' */ - if (!ASN1_STRING_set(osp,NULL,size)) - { + if (!ASN1_STRING_set(osp,NULL,size)) { ASN1_STRING_free(osp); return(0); } @@ -145,8 +143,7 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, long length; ASN1_const_CTX c; - if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) - { + if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { goto err; } p=M_ASN1_STRING_data(a->value.sequence); @@ -177,8 +174,7 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, if (data != NULL) memcpy(data,M_ASN1_STRING_data(os),n); - if (0) - { + if (0) { err: ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); } diff --git a/lib/libcrypto/asn1/f_enum.c b/lib/libcrypto/asn1/f_enum.c index b6e66ab194c..4ccfbddf2a9 100644 --- a/lib/libcrypto/asn1/f_enum.c +++ b/lib/libcrypto/asn1/f_enum.c @@ -71,17 +71,12 @@ int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) if (a == NULL) return(0); - if (a->length == 0) - { + if (a->length == 0) { if (BIO_write(bp,"00",2) != 2) goto err; n=2; - } - else - { - for (i=0; ilength; i++) - { - if ((i != 0) && (i%35 == 0)) - { + } else { + for (i=0; ilength; i++) { + if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } @@ -107,8 +102,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) bs->type=V_ASN1_ENUMERATED; bufsize=BIO_gets(bp,buf,size); - for (;;) - { + for (;;) { if (bufsize < 1) goto err_sl; i=bufsize; if (buf[i-1] == '\n') buf[--i]='\0'; @@ -117,12 +111,10 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) if (i == 0) goto err_sl; again=(buf[i-1] == '\\'); - for (j=0; j= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || - ((buf[j] >= 'A') && (buf[j] <= 'F')))) - { + ((buf[j] >= 'A') && (buf[j] <= 'F')))) { i=j; break; } @@ -133,33 +125,28 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) if (i < 2) goto err_sl; bufp=(unsigned char *)buf; - if (first) - { + if (first) { first=0; - if ((bufp[0] == '0') && (buf[1] == '0')) - { + if ((bufp[0] == '0') && (buf[1] == '0')) { bufp+=2; i-=2; } } k=0; i-=again; - if (i%2 != 0) - { + if (i%2 != 0) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); goto err; } i/=2; - if (num+i > slen) - { + if (num+i > slen) { if (s == NULL) sp=(unsigned char *)malloc( (unsigned int)num+i*2); else sp=(unsigned char *)realloc(s, (unsigned int)num+i*2); - if (sp == NULL) - { + if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); if (s != NULL) free(s); goto err; @@ -167,10 +154,8 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) s=sp; slen=num+i*2; } - for (j=0; j= '0') && (m <= '9')) m-='0'; @@ -178,8 +163,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) m=m-'a'+10; else if ((m >= 'A') && (m <= 'F')) m=m-'A'+10; - else - { + else { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); goto err; } @@ -197,8 +181,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) bs->data=s; ret=1; err: - if (0) - { + if (0) { err_sl: ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); } diff --git a/lib/libcrypto/asn1/f_int.c b/lib/libcrypto/asn1/f_int.c index 66632f2dc44..6cea1f8485a 100644 --- a/lib/libcrypto/asn1/f_int.c +++ b/lib/libcrypto/asn1/f_int.c @@ -69,23 +69,17 @@ int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) if (a == NULL) return(0); - if (a->type & V_ASN1_NEG) - { + if (a->type & V_ASN1_NEG) { if (BIO_write(bp, "-", 1) != 1) goto err; n = 1; } - if (a->length == 0) - { + if (a->length == 0) { if (BIO_write(bp,"00",2) != 2) goto err; n += 2; - } - else - { - for (i=0; ilength; i++) - { - if ((i != 0) && (i%35 == 0)) - { + } else { + for (i=0; ilength; i++) { + if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } @@ -111,8 +105,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) bs->type=V_ASN1_INTEGER; bufsize=BIO_gets(bp,buf,size); - for (;;) - { + for (;;) { if (bufsize < 1) goto err_sl; i=bufsize; if (buf[i-1] == '\n') buf[--i]='\0'; @@ -121,12 +114,10 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) if (i == 0) goto err_sl; again=(buf[i-1] == '\\'); - for (j=0; j= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || - ((buf[j] >= 'A') && (buf[j] <= 'F')))) - { + ((buf[j] >= 'A') && (buf[j] <= 'F')))) { i=j; break; } @@ -137,32 +128,27 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) if (i < 2) goto err_sl; bufp=(unsigned char *)buf; - if (first) - { + if (first) { first=0; - if ((bufp[0] == '0') && (buf[1] == '0')) - { + if ((bufp[0] == '0') && (buf[1] == '0')) { bufp+=2; i-=2; } } k=0; i-=again; - if (i%2 != 0) - { + if (i%2 != 0) { ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); goto err; } i/=2; - if (num+i > slen) - { + if (num+i > slen) { if (s == NULL) sp=(unsigned char *)malloc( (unsigned int)num+i*2); else sp=OPENSSL_realloc_clean(s,slen,num+i*2); - if (sp == NULL) - { + if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); if (s != NULL) free(s); goto err; @@ -170,10 +156,8 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) s=sp; slen=num+i*2; } - for (j=0; j= '0') && (m <= '9')) m-='0'; @@ -181,8 +165,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) m=m-'a'+10; else if ((m >= 'A') && (m <= 'F')) m=m-'A'+10; - else - { + else { ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); goto err; } @@ -200,8 +183,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) bs->data=s; ret=1; err: - if (0) - { + if (0) { err_sl: ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); } diff --git a/lib/libcrypto/asn1/f_string.c b/lib/libcrypto/asn1/f_string.c index 7a59fa9f4f4..87d7aaa0dde 100644 --- a/lib/libcrypto/asn1/f_string.c +++ b/lib/libcrypto/asn1/f_string.c @@ -69,17 +69,12 @@ int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) if (a == NULL) return(0); - if (a->length == 0) - { + if (a->length == 0) { if (BIO_write(bp,"0",1) != 1) goto err; n=1; - } - else - { - for (i=0; ilength; i++) - { - if ((i != 0) && (i%35 == 0)) - { + } else { + for (i=0; ilength; i++) { + if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } @@ -103,10 +98,8 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) int num=0,slen=0,first=1; bufsize=BIO_gets(bp,buf,size); - for (;;) - { - if (bufsize < 1) - { + for (;;) { + if (bufsize < 1) { if (first) break; else @@ -121,12 +114,10 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) if (i == 0) goto err_sl; again=(buf[i-1] == '\\'); - for (j=i-1; j>0; j--) - { + for (j=i-1; j>0; j--) { if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || - ((buf[j] >= 'A') && (buf[j] <= 'F')))) - { + ((buf[j] >= 'A') && (buf[j] <= 'F')))) { i=j; break; } @@ -140,22 +131,19 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) k=0; i-=again; - if (i%2 != 0) - { + if (i%2 != 0) { ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); goto err; } i/=2; - if (num+i > slen) - { + if (num+i > slen) { if (s == NULL) sp=(unsigned char *)malloc( (unsigned int)num+i*2); else sp=(unsigned char *)realloc(s, (unsigned int)num+i*2); - if (sp == NULL) - { + if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); if (s != NULL) free(s); goto err; @@ -163,10 +151,8 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) s=sp; slen=num+i*2; } - for (j=0; j= '0') && (m <= '9')) m-='0'; @@ -174,8 +160,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) m=m-'a'+10; else if ((m >= 'A') && (m <= 'F')) m=m-'A'+10; - else - { + else { ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); goto err; } @@ -193,8 +178,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) bs->data=s; ret=1; err: - if (0) - { + if (0) { err_sl: ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); } diff --git a/lib/libcrypto/asn1/i2d_pr.c b/lib/libcrypto/asn1/i2d_pr.c index 9332c4d2ec5..71757486011 100644 --- a/lib/libcrypto/asn1/i2d_pr.c +++ b/lib/libcrypto/asn1/i2d_pr.c @@ -64,8 +64,7 @@ int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) { - if (a->ameth && a->ameth->old_priv_encode) - { + if (a->ameth && a->ameth->old_priv_encode) { return a->ameth->old_priv_encode(a, pp); } if (a->ameth && a->ameth->priv_encode) { diff --git a/lib/libcrypto/asn1/i2d_pu.c b/lib/libcrypto/asn1/i2d_pu.c index ed8ec0753b5..08b438115df 100644 --- a/lib/libcrypto/asn1/i2d_pu.c +++ b/lib/libcrypto/asn1/i2d_pu.c @@ -73,8 +73,7 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) { - switch (a->type) - { + switch (a->type) { #ifndef OPENSSL_NO_RSA case EVP_PKEY_RSA: return(i2d_RSAPublicKey(a->pkey.rsa,pp)); diff --git a/lib/libcrypto/asn1/n_pkey.c b/lib/libcrypto/asn1/n_pkey.c index a59640582e4..0a378759f9d 100644 --- a/lib/libcrypto/asn1/n_pkey.c +++ b/lib/libcrypto/asn1/n_pkey.c @@ -159,8 +159,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; enckey->enckey->algor->parameter->type=V_ASN1_NULL; - if (pp == NULL) - { + if (pp == NULL) { olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); NETSCAPE_PKEY_free(pkey); NETSCAPE_ENCRYPTED_PKEY_free(enckey); @@ -169,8 +168,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, /* Since its RC4 encrypted length is actual length */ - if ((zz=(unsigned char *)malloc(rsalen)) == NULL) - { + if ((zz=(unsigned char *)malloc(rsalen)) == NULL) { ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); goto err; } @@ -179,14 +177,12 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, /* Write out private key encoding */ i2d_RSAPrivateKey(a,&zz); - if ((zz=malloc(pkeylen)) == NULL) - { + if ((zz=malloc(pkeylen)) == NULL) { ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); goto err; } - if (!ASN1_STRING_set(enckey->os, "private-key", -1)) - { + if (!ASN1_STRING_set(enckey->os, "private-key", -1)) { ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); goto err; } @@ -199,8 +195,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, if (cb == NULL) cb=EVP_read_pw_string; i=cb((char *)buf,256,"Enter Private Key password:",1); - if (i != 0) - { + if (i != 0) { ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); goto err; } @@ -259,14 +254,12 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, } if ((enckey->os->length != 11) || (strncmp("private-key", - (char *)enckey->os->data,11) != 0)) - { + (char *)enckey->os->data,11) != 0)) { ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); NETSCAPE_ENCRYPTED_PKEY_free(enckey); return NULL; } - if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) - { + if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) { ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); goto err; } @@ -296,8 +289,7 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, EVP_CIPHER_CTX_init(&ctx); i=cb((char *)buf,256,"Enter Private Key password:",0); - if (i != 0) - { + if (i != 0) { ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); goto err; } @@ -324,15 +316,13 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, zz=os->data; - if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) - { + if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) { ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); goto err; } zz=pkey->private_key->data; - if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) - { + if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) { ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); goto err; } diff --git a/lib/libcrypto/asn1/p5_pbe.c b/lib/libcrypto/asn1/p5_pbe.c index f0f23c668d9..390305ad38f 100644 --- a/lib/libcrypto/asn1/p5_pbe.c +++ b/lib/libcrypto/asn1/p5_pbe.c @@ -82,22 +82,19 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, unsigned char *sstr; pbe = PBEPARAM_new(); - if (!pbe) - { + if (!pbe) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } if(iter <= 0) iter = PKCS5_DEFAULT_ITER; - if (!ASN1_INTEGER_set(pbe->iter, iter)) - { + if (!ASN1_INTEGER_set(pbe->iter, iter)) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } if (!saltlen) saltlen = PKCS5_SALT_LEN; - if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) - { + if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } @@ -107,8 +104,7 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, else if (RAND_pseudo_bytes(sstr, saltlen) < 0) goto err; - if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) - { + if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } @@ -134,8 +130,7 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, { X509_ALGOR *ret; ret = X509_ALGOR_new(); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/lib/libcrypto/asn1/p5_pbev2.c b/lib/libcrypto/asn1/p5_pbev2.c index 2d80334e011..01563a68fdb 100644 --- a/lib/libcrypto/asn1/p5_pbev2.c +++ b/lib/libcrypto/asn1/p5_pbev2.c @@ -114,13 +114,12 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, if(!(scheme->parameter = ASN1_TYPE_new())) goto merr; /* Create random IV */ - if (EVP_CIPHER_iv_length(cipher)) - { + if (EVP_CIPHER_iv_length(cipher)) { if (aiv) memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); else if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0) goto err; - } + } EVP_CIPHER_CTX_init(&ctx); @@ -137,11 +136,10 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, * An error is OK here: just means use default PRF. */ if ((prf_nid == -1) && - EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) - { + EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) { ERR_clear_error(); prf_nid = NID_hmacWithSHA1; - } + } EVP_CIPHER_CTX_cleanup(&ctx); /* If its RC2 then we'd better setup the key length */ @@ -178,7 +176,7 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, return ret; - merr: +merr: ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,ERR_R_MALLOC_FAILURE); err: @@ -193,13 +191,13 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, unsigned char *salt, int saltlen) - { +{ return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1); - } +} X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid, int keylen) - { +{ X509_ALGOR *keyfunc = NULL; PBKDF2PARAM *kdf = NULL; ASN1_OCTET_STRING *osalt = NULL; @@ -232,8 +230,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* If have a key len set it up */ - if(keylen > 0) - { + if(keylen > 0) { if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr; if(!ASN1_INTEGER_set (kdf->keylength, keylen)) @@ -241,14 +238,13 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, } /* prf can stay NULL if we are using hmacWithSHA1 */ - if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) - { + if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) { kdf->prf = X509_ALGOR_new(); if (!kdf->prf) goto merr; X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid), V_ASN1_NULL, NULL); - } + } /* Finally setup the keyfunc structure */ @@ -271,10 +267,10 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, PBKDF2PARAM_free(kdf); return keyfunc; - merr: +merr: ASN1err(ASN1_F_PKCS5_PBKDF2_SET,ERR_R_MALLOC_FAILURE); PBKDF2PARAM_free(kdf); X509_ALGOR_free(keyfunc); return NULL; - } +} diff --git a/lib/libcrypto/asn1/p8_pkey.c b/lib/libcrypto/asn1/p8_pkey.c index 9d26cf51ecb..c95d7e55a07 100644 --- a/lib/libcrypto/asn1/p8_pkey.c +++ b/lib/libcrypto/asn1/p8_pkey.c @@ -90,13 +90,11 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, unsigned char *penc, int penclen) { unsigned char **ppenc = NULL; - if (version >= 0) - { + if (version >= 0) { if (!ASN1_INTEGER_set(priv->version, version)) return 0; } - if (penc) - { + if (penc) { int pmtype; ASN1_OCTET_STRING *oct; oct = ASN1_OCTET_STRING_new(); @@ -111,8 +109,7 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, pmtype = V_ASN1_OCTET_STRING; ASN1_TYPE_set(priv->pkey, pmtype, oct); } - if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) - { + if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) { /* If call fails do not swallow 'enc' */ if (ppenc) *ppenc = NULL; @@ -128,20 +125,15 @@ int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, { if (ppkalg) *ppkalg = p8->pkeyalg->algorithm; - if(p8->pkey->type == V_ASN1_OCTET_STRING) - { + if(p8->pkey->type == V_ASN1_OCTET_STRING) { p8->broken = PKCS8_OK; - if (pk) - { + if (pk) { *pk = p8->pkey->value.octet_string->data; *ppklen = p8->pkey->value.octet_string->length; } - } - else if (p8->pkey->type == V_ASN1_SEQUENCE) - { + } else if (p8->pkey->type == V_ASN1_SEQUENCE) { p8->broken = PKCS8_NO_OCTET; - if (pk) - { + if (pk) { *pk = p8->pkey->value.sequence->data; *ppklen = p8->pkey->value.sequence->length; } diff --git a/lib/libcrypto/asn1/t_crl.c b/lib/libcrypto/asn1/t_crl.c index 1624cc5fcc0..c665a26bce4 100644 --- a/lib/libcrypto/asn1/t_crl.c +++ b/lib/libcrypto/asn1/t_crl.c @@ -70,8 +70,7 @@ int X509_CRL_print_fp(FILE *fp, X509_CRL *x) BIO *b; int ret; - if ((b=BIO_new(BIO_s_file())) == NULL) - { + if ((b=BIO_new(BIO_s_file())) == NULL) { X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); return(0); } diff --git a/lib/libcrypto/asn1/t_pkey.c b/lib/libcrypto/asn1/t_pkey.c index 61f5cd61f18..12674e0125c 100644 --- a/lib/libcrypto/asn1/t_pkey.c +++ b/lib/libcrypto/asn1/t_pkey.c @@ -72,21 +72,17 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, neg = (BN_is_negative(num))?"-":""; if(!BIO_indent(bp,off,128)) return 0; - if (BN_is_zero(num)) - { + if (BN_is_zero(num)) { if (BIO_printf(bp, "%s 0\n", number) <= 0) return 0; return 1; } - if (BN_num_bytes(num) <= BN_BYTES) - { + if (BN_num_bytes(num) <= BN_BYTES) { if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) <= 0) return(0); - } - else - { + } else { buf[0]=0; if (BIO_printf(bp,"%s%s",number, (neg[0] == '-')?" (Negative)":"") <= 0) @@ -97,10 +93,8 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, n++; else buf++; - for (i=0; ireq_info; - if(!(cflag & X509_FLAG_NO_HEADER)) - { + if(!(cflag & X509_FLAG_NO_HEADER)) { if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; if (BIO_write(bp," Data:\n",10) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_VERSION)) - { + if(!(cflag & X509_FLAG_NO_VERSION)) { neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; l=0; - for (i=0; iversion->length; i++) - { l<<=8; l+=ri->version->data[i]; } + for (i=0; iversion->length; i++) { + l<<=8; l+=ri->version->data[i]; + } if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, l) <= 0) goto err; @@ -131,8 +129,7 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_PUBKEY)) - { + if(!(cflag & X509_FLAG_NO_PUBKEY)) { if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) goto err; if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) @@ -143,34 +140,26 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long goto err; pkey=X509_REQ_get_pubkey(x); - if (pkey == NULL) - { + if (pkey == NULL) { BIO_printf(bp,"%12sUnable to load Public Key\n",""); ERR_print_errors(bp); - } - else - { + } else { EVP_PKEY_print_public(bp, pkey, 16, NULL); EVP_PKEY_free(pkey); } } - if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) - { + if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) { /* may not be */ if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) goto err; sk=x->req_info->attributes; - if (sk_X509_ATTRIBUTE_num(sk) == 0) - { + if (sk_X509_ATTRIBUTE_num(sk) == 0) { if(BIO_printf(bp,"%12sa0:00\n","") <= 0) goto err; - } - else - { - for (i=0; iobject)) > 0) - { - if (a->single) - { + if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) { + if (a->single) { t=a->value.single; type=t->type; bs=t->value.bit_string; - } - else - { + } else { ii=0; count=sk_ASN1_TYPE_num(a->value.set); get_next: @@ -205,29 +190,23 @@ get_next: if (BIO_puts(bp,":") <= 0) goto err; if ( (type == V_ASN1_PRINTABLESTRING) || (type == V_ASN1_T61STRING) || - (type == V_ASN1_IA5STRING)) - { + (type == V_ASN1_IA5STRING)) { if (BIO_write(bp,(char *)bs->data,bs->length) != bs->length) goto err; BIO_puts(bp,"\n"); - } - else - { + } else { BIO_puts(bp,"unable to print attribute\n"); } if (++ii < count) goto get_next; } } } - if(!(cflag & X509_FLAG_NO_EXTENSIONS)) - { + if(!(cflag & X509_FLAG_NO_EXTENSIONS)) { exts = X509_REQ_get_extensions(x); - if(exts) - { + if(exts) { BIO_printf(bp,"%8sRequested Extensions:\n",""); - for (i=0; ivalue); } @@ -249,8 +227,7 @@ get_next: } } - if(!(cflag & X509_FLAG_NO_SIGDUMP)) - { + if(!(cflag & X509_FLAG_NO_SIGDUMP)) { if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; } diff --git a/lib/libcrypto/asn1/t_spki.c b/lib/libcrypto/asn1/t_spki.c index 016eb2fc2e3..f135754535e 100644 --- a/lib/libcrypto/asn1/t_spki.c +++ b/lib/libcrypto/asn1/t_spki.c @@ -81,9 +81,9 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) BIO_printf(out," Public Key Algorithm: %s\n", (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); pkey = X509_PUBKEY_get(spki->spkac->pubkey); - if(!pkey) BIO_printf(out, " Unable to load public key\n"); - else - { + if(!pkey) + BIO_printf(out, " Unable to load public key\n"); + else { EVP_PKEY_print_public(out, pkey, 4, NULL); EVP_PKEY_free(pkey); } @@ -96,9 +96,9 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) n=spki->signature->length; s=(char *)spki->signature->data; - for (i=0; icert_info; - if(!(cflag & X509_FLAG_NO_HEADER)) - { + if(!(cflag & X509_FLAG_NO_HEADER)) { if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; if (BIO_write(bp," Data:\n",10) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_VERSION)) - { + if(!(cflag & X509_FLAG_NO_VERSION)) { l=X509_get_version(x); if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_SERIAL)) - { + if(!(cflag & X509_FLAG_NO_SERIAL)) { if (BIO_write(bp," Serial Number:",22) <= 0) goto err; bs=X509_get_serialNumber(x); - if (bs->length <= (int)sizeof(long)) - { + if (bs->length <= (int)sizeof(long)) { l=ASN1_INTEGER_get(bs); - if (bs->type == V_ASN1_NEG_INTEGER) - { + if (bs->type == V_ASN1_NEG_INTEGER) { l= -l; neg="-"; - } - else + } else neg=""; if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) goto err; - } - else - { + } else { neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02x%c",bs->data[i], ((i+1 == bs->length)?'\n':':')) <= 0) goto err; @@ -166,8 +156,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) } - if(!(cflag & X509_FLAG_NO_SIGNAME)) - { + if(!(cflag & X509_FLAG_NO_SIGNAME)) { if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) goto err; #if 0 @@ -180,14 +169,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) #endif } - if(!(cflag & X509_FLAG_NO_ISSUER)) - { + if(!(cflag & X509_FLAG_NO_ISSUER)) { if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_VALIDITY)) - { + if(!(cflag & X509_FLAG_NO_VALIDITY)) { if (BIO_write(bp," Validity\n",17) <= 0) goto err; if (BIO_write(bp," Not Before: ",24) <= 0) goto err; if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; @@ -195,14 +182,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_SUBJECT)) - { + if(!(cflag & X509_FLAG_NO_SUBJECT)) { if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_PUBKEY)) - { + if(!(cflag & X509_FLAG_NO_PUBKEY)) { if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) goto err; if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) @@ -213,13 +198,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) goto err; pkey=X509_get_pubkey(x); - if (pkey == NULL) - { + if (pkey == NULL) { BIO_printf(bp,"%12sUnable to load Public Key\n",""); ERR_print_errors(bp); - } - else - { + } else { EVP_PKEY_print_public(bp, pkey, 16, NULL); EVP_PKEY_free(pkey); } @@ -229,12 +211,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) X509V3_extensions_print(bp, "X509v3 extensions", ci->extensions, cflag, 8); - if(!(cflag & X509_FLAG_NO_SIGDUMP)) - { + if(!(cflag & X509_FLAG_NO_SIGDUMP)) { if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_AUX)) - { + if(!(cflag & X509_FLAG_NO_AUX)) { if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; } ret=1; @@ -262,8 +242,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) goto err; - for (i=0; i < SHA_DIGEST_LENGTH; i++) - { + for (i=0; i < SHA_DIGEST_LENGTH; i++) { if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; } free (der); @@ -278,8 +257,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL)) goto err; - for (i=0; i < SHA_DIGEST_LENGTH; i++) - { + for (i=0; i < SHA_DIGEST_LENGTH; i++) { if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; } @@ -298,10 +276,8 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) n=sig->length; s=sig->data; - for (i=0; ialgorithm) <= 0) return 0; sig_nid = OBJ_obj2nid(sigalg->algorithm); - if (sig_nid != NID_undef) - { + if (sig_nid != NID_undef) { int pkey_nid, dig_nid; const EVP_PKEY_ASN1_METHOD *ameth; - if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) - { + if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) { ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); if (ameth && ameth->sig_print) return ameth->sig_print(bp, sigalg, sig, 9, 0); @@ -347,16 +321,14 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) if (v == NULL) return(0); n=0; p=(const char *)v->data; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if ((p[i] > '~') || ((p[i] < ' ') && (p[i] != '\n') && (p[i] != '\r'))) buf[n]='.'; else buf[n]=p[i]; n++; - if (n >= 80) - { + if (n >= 80) { if (BIO_write(bp,buf,n) <= 0) return(0); n=0; @@ -407,12 +379,10 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) m= (v[10]-'0')*10+(v[11]-'0'); if (tm->length >= 14 && (v[12] >= '0') && (v[12] <= '9') && - (v[13] >= '0') && (v[13] <= '9')) - { + (v[13] >= '0') && (v[13] <= '9')) { s= (v[12]-'0')*10+(v[13]-'0'); /* Check for fractions of seconds. */ - if (tm->length >= 15 && v[14] == '.') - { + if (tm->length >= 15 && v[14] == '.') { int l = tm->length; f = &v[14]; /* The decimal point. */ f_len = 1; @@ -475,29 +445,25 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) l=80-2-obase; b=X509_NAME_oneline(name,NULL,0); - if (!*b) - { + if (!*b) { free(b); return 1; } s=b+1; /* skip the first slash */ c=s; - for (;;) - { + for (;;) { if ( ((*s == '/') && ((s[1] >= 'A') && (s[1] <= 'Z') && ( (s[2] == '=') || ((s[2] >= 'A') && (s[2] <= 'Z') && (s[3] == '=')) ))) || - (*s == '\0')) - { + (*s == '\0')) { i=s-c; if (BIO_write(bp,c,i) != i) goto err; c=s+1; /* skip following slash */ - if (*s != '\0') - { + if (*s != '\0') { if (BIO_write(bp,", ",2) != 2) goto err; } l--; @@ -508,8 +474,7 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) } ret=1; - if (0) - { + if (0) { err: X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); } diff --git a/lib/libcrypto/asn1/tasn_dec.c b/lib/libcrypto/asn1/tasn_dec.c index 0df42a4a93c..1a06ddc1850 100644 --- a/lib/libcrypto/asn1/tasn_dec.c +++ b/lib/libcrypto/asn1/tasn_dec.c @@ -175,19 +175,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, asn1_cb = aux->asn1_cb; else asn1_cb = 0; - switch(it->itype) - { - case ASN1_ITYPE_PRIMITIVE: - if (it->templates) - { + switch(it->itype) { + case ASN1_ITYPE_PRIMITIVE: + if (it->templates) { /* tagging or OPTIONAL is currently illegal on an item * template because the flags can't get passed down. * In practice this isn't a problem: we include the * relevant flags from the item template in the * template itself. */ - if ((tag != -1) || opt) - { + if ((tag != -1) || opt) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); goto err; @@ -199,21 +196,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, tag, aclass, opt, ctx); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: p = *in; /* Just read in tag and class */ ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* Must be UNIVERSAL class */ - if (oclass != V_ASN1_UNIVERSAL) - { + if (oclass != V_ASN1_UNIVERSAL) { /* If OPTIONAL, assume this is OK */ if (opt) return -1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, @@ -221,8 +216,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto err; } /* Check tag matches bit map */ - if (!(ASN1_tag2bit(otag) & it->utype)) - { + if (!(ASN1_tag2bit(otag) & it->utype)) { /* If OPTIONAL, assume this is OK */ if (opt) return -1; @@ -233,19 +227,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx); - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: /* Use new style d2i */ ef = it->funcs; return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx); - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: /* we must resort to old style evil hackery */ cf = it->funcs; /* If OPTIONAL see if it is there */ - if (opt) - { + if (opt) { int exptag; p = *in; if (tag == -1) @@ -256,8 +249,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -281,12 +273,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, * buffer. */ - if (tag != -1) - { + if (tag != -1) { wp = *(unsigned char **)in; imphack = *wp; - if (p == NULL) - { + if (p == NULL) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -307,21 +297,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto err; - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; /* Allocate structure */ - if (!*pval && !ASN1_item_ex_new(pval, it)) - { + if (!*pval && !ASN1_item_ex_new(pval, it)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* CHOICE type, try each possibility in turn */ p = *in; - for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) - { + for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) { pchptr = asn1_get_field_ptr(pval, tt); /* We mark field as OPTIONAL so its absence * can be recognised. @@ -341,11 +329,9 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, } /* Did we fall off the end without reading anything? */ - if (i == it->tcount) - { + if (i == it->tcount) { /* If OPTIONAL, this is OK */ - if (opt) - { + if (opt) { /* Free and zero it */ ASN1_item_ex_free(pval, it); return -1; @@ -361,44 +347,39 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto auxerr; return 1; - case ASN1_ITYPE_NDEF_SEQUENCE: - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: p = *in; tmplen = len; /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ - if (tag == -1) - { + if (tag == -1) { tag = V_ASN1_SEQUENCE; aclass = V_ASN1_UNIVERSAL; } /* Get SEQUENCE length and update len, p */ ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } else if (ret == -1) return -1; - if (aux && (aux->flags & ASN1_AFLG_BROKEN)) - { + if (aux && (aux->flags & ASN1_AFLG_BROKEN)) { len = tmplen - (p - *in); seq_nolen = 1; } /* If indefinite we don't do a length check */ else seq_nolen = seq_eoc; - if (!cst) - { + if (!cst) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); goto err; } - if (!*pval && !ASN1_item_ex_new(pval, it)) - { + if (!*pval && !ASN1_item_ex_new(pval, it)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -408,8 +389,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto auxerr; /* Get each field entry */ - for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) - { + for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -420,10 +400,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, if (!len) break; q = p; - if (asn1_check_eoc(&p, len)) - { - if (!seq_eoc) - { + if (asn1_check_eoc(&p, len)) { + if (!seq_eoc) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC); goto err; @@ -447,13 +425,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx); - if (!ret) - { + if (!ret) { errtt = seqtt; goto err; - } - else if (ret == -1) - { + } else if (ret == -1) { /* OPTIONAL component absent. * Free and zero the field. */ @@ -465,14 +440,12 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, } /* Check for EOC if expecting one */ - if (seq_eoc && !asn1_check_eoc(&p, len)) - { + if (seq_eoc && !asn1_check_eoc(&p, len)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); goto err; } /* Check all data read */ - if (!seq_nolen && len) - { + if (!seq_nolen && len) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH); goto err; @@ -482,20 +455,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, * however we may not have read all fields so check all * remaining are OPTIONAL and clear any that are. */ - for (; i < it->tcount; tt++, i++) - { + for (; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) goto err; - if (seqtt->flags & ASN1_TFLG_OPTIONAL) - { + if (seqtt->flags & ASN1_TFLG_OPTIONAL) { ASN1_VALUE **pseqval; pseqval = asn1_get_field_ptr(pval, seqtt); ASN1_template_free(pseqval, seqtt); - } - else - { + } else { errtt = seqtt; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING); @@ -547,8 +516,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, p = *in; /* Check if EXPLICIT tag expected */ - if (flags & ASN1_TFLG_EXPTAG) - { + if (flags & ASN1_TFLG_EXPTAG) { char cst; /* Need to work out amount of data available to the inner * content and where it starts: so read in EXPLICIT header to @@ -557,46 +525,37 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx); q = p; - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; - } - else if (ret == -1) + } else if (ret == -1) return -1; - if (!cst) - { + if (!cst) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); return 0; } /* We've found the field so it can't be OPTIONAL now */ ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; } /* We read the field in OK so update length */ len -= p - q; - if (exp_eoc) - { + if (exp_eoc) { /* If NDEF we must have an EOC here */ - if (!asn1_check_eoc(&p, len)) - { + if (!asn1_check_eoc(&p, len)) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_MISSING_EOC); goto err; } - } - else - { + } else { /* Otherwise we must hit the EXPLICIT tag end or its * an error */ - if (len) - { + if (len) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH); goto err; @@ -631,19 +590,15 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, p = *in; q = p; - if (flags & ASN1_TFLG_SK_MASK) - { + if (flags & ASN1_TFLG_SK_MASK) { /* SET OF, SEQUENCE OF */ int sktag, skaclass; char sk_eoc; /* First work out expected inner tag value */ - if (flags & ASN1_TFLG_IMPTAG) - { + if (flags & ASN1_TFLG_IMPTAG) { sktag = tt->tag; skaclass = aclass; - } - else - { + } else { skaclass = V_ASN1_UNIVERSAL; if (flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET; @@ -653,8 +608,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, /* Get the tag */ ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; @@ -663,37 +617,31 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, return -1; if (!*val) *val = (ASN1_VALUE *)sk_new_null(); - else - { + else { /* We've got a valid STACK: free up any items present */ STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val; ASN1_VALUE *vtmp; - while(sk_ASN1_VALUE_num(sktmp) > 0) - { + while(sk_ASN1_VALUE_num(sktmp) > 0) { vtmp = sk_ASN1_VALUE_pop(sktmp); ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item)); } } - if (!*val) - { + if (!*val) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); goto err; } /* Read as many items as we can */ - while(len > 0) - { + while(len > 0) { ASN1_VALUE *skfield; q = p; /* See if EOC found */ - if (asn1_check_eoc(&p, len)) - { - if (!sk_eoc) - { + if (asn1_check_eoc(&p, len)) { + if (!sk_eoc) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_UNEXPECTED_EOC); goto err; @@ -705,48 +653,39 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, skfield = NULL; if (!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), - -1, 0, 0, ctx)) - { + -1, 0, 0, ctx)) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } len -= p - q; if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, - skfield)) - { + skfield)) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); goto err; } } - if (sk_eoc) - { + if (sk_eoc) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); goto err; } - } - else if (flags & ASN1_TFLG_IMPTAG) - { + } else if (flags & ASN1_TFLG_IMPTAG) { /* IMPLICIT tagging */ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } else if (ret == -1) return -1; - } - else - { + } else { /* Nothing special */ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -775,32 +714,27 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, BUF_MEM buf; const unsigned char *cont = NULL; long len; - if (!pval) - { + if (!pval) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); return 0; /* Should never happen */ } - if (it->itype == ASN1_ITYPE_MSTRING) - { + if (it->itype == ASN1_ITYPE_MSTRING) { utype = tag; tag = -1; } else utype = it->utype; - if (utype == V_ASN1_ANY) - { + if (utype == V_ASN1_ANY) { /* If type is ANY need to figure out type from tag */ unsigned char oclass; - if (tag >= 0) - { + if (tag >= 0) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY); return 0; } - if (opt) - { + if (opt) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY); return 0; @@ -808,8 +742,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, p = *in; ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; @@ -817,8 +750,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, if (oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER; } - if (tag == -1) - { + if (tag == -1) { tag = utype; aclass = V_ASN1_UNIVERSAL; } @@ -826,8 +758,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, /* Check header */ ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; } @@ -836,18 +767,15 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, ret = 0; /* SEQUENCE, SET and "OTHER" are left in encoded form */ if ((utype == V_ASN1_SEQUENCE) - || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) - { + || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) { /* Clear context cache for type OTHER because the auto clear * when we have a exact match wont work */ - if (utype == V_ASN1_OTHER) - { + if (utype == V_ASN1_OTHER) { asn1_tlc_clear(ctx); } /* SEQUENCE and SET must be constructed */ - else if (!cst) - { + else if (!cst) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED); return 0; @@ -855,21 +783,16 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, cont = *in; /* If indefinite length constructed find the real end */ - if (inf) - { + if (inf) { if (!asn1_find_end(&p, plen, inf)) goto err; len = p - cont; - } - else - { + } else { len = p - cont + plen; p += plen; buf.data = NULL; } - } - else if (cst) - { + } else if (cst) { buf.length = 0; buf.max = 0; buf.data = NULL; @@ -879,15 +802,13 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, * internally irrespective of the type. So instead just check * for UNIVERSAL class and ignore the tag. */ - if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) - { + if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) { free_cont = 1; goto err; } len = buf.length; /* Append a final null to string */ - if (!BUF_MEM_grow_clean(&buf, len + 1)) - { + if (!BUF_MEM_grow_clean(&buf, len + 1)) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); return 0; @@ -895,9 +816,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, buf.data[len] = 0; cont = (const unsigned char *)buf.data; free_cont = 1; - } - else - { + } else { cont = p; len = plen; p += plen; @@ -930,10 +849,8 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, if (pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it); /* If ANY type clear type and set pointer to internal value */ - if (it->utype == V_ASN1_ANY) - { - if (!*pval) - { + if (it->utype == V_ASN1_ANY) { + if (!*pval) { typ = ASN1_TYPE_new(); if (typ == NULL) goto err; @@ -947,16 +864,14 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, opval = pval; pval = &typ->value.asn1_value; } - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err; break; - case V_ASN1_NULL: - if (len) - { + case V_ASN1_NULL: + if (len) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_NULL_IS_WRONG_LENGTH); goto err; @@ -964,30 +879,27 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, *pval = (ASN1_VALUE *)1; break; - case V_ASN1_BOOLEAN: - if (len != 1) - { + case V_ASN1_BOOLEAN: + if (len != 1) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BOOLEAN_IS_WRONG_LENGTH); goto err; - } - else - { + } else { ASN1_BOOLEAN *tbool; tbool = (ASN1_BOOLEAN *)pval; *tbool = *cont; } break; - case V_ASN1_BIT_STRING: + case V_ASN1_BIT_STRING: if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err; break; - case V_ASN1_INTEGER: - case V_ASN1_NEG_INTEGER: - case V_ASN1_ENUMERATED: - case V_ASN1_NEG_ENUMERATED: + case V_ASN1_INTEGER: + case V_ASN1_NEG_INTEGER: + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: tint = (ASN1_INTEGER **)pval; if (!c2i_ASN1_INTEGER(tint, &cont, len)) goto err; @@ -995,66 +907,56 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG); break; - case V_ASN1_OCTET_STRING: - case V_ASN1_NUMERICSTRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_T61STRING: - case V_ASN1_VIDEOTEXSTRING: - case V_ASN1_IA5STRING: - case V_ASN1_UTCTIME: - case V_ASN1_GENERALIZEDTIME: - case V_ASN1_GRAPHICSTRING: - case V_ASN1_VISIBLESTRING: - case V_ASN1_GENERALSTRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_BMPSTRING: - case V_ASN1_UTF8STRING: - case V_ASN1_OTHER: - case V_ASN1_SET: - case V_ASN1_SEQUENCE: - default: - if (utype == V_ASN1_BMPSTRING && (len & 1)) - { + case V_ASN1_OCTET_STRING: + case V_ASN1_NUMERICSTRING: + case V_ASN1_PRINTABLESTRING: + case V_ASN1_T61STRING: + case V_ASN1_VIDEOTEXSTRING: + case V_ASN1_IA5STRING: + case V_ASN1_UTCTIME: + case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GRAPHICSTRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_UTF8STRING: + case V_ASN1_OTHER: + case V_ASN1_SET: + case V_ASN1_SEQUENCE: + default: + if (utype == V_ASN1_BMPSTRING && (len & 1)) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BMPSTRING_IS_WRONG_LENGTH); goto err; } - if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) - { + if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); goto err; } /* All based on ASN1_STRING and handled the same */ - if (!*pval) - { + if (!*pval) { stmp = ASN1_STRING_type_new(utype); - if (!stmp) - { + if (!stmp) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); goto err; } *pval = (ASN1_VALUE *)stmp; - } - else - { + } else { stmp = (ASN1_STRING *)*pval; stmp->type = utype; } /* If we've already allocated a buffer use it */ - if (*free_cont) - { + if (*free_cont) { if (stmp->data) free(stmp->data); stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ stmp->length = len; *free_cont = 0; - } - else - { - if (!ASN1_STRING_set(stmp, cont, len)) - { + } else { + if (!ASN1_STRING_set(stmp, cont, len)) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); ASN1_STRING_free(stmp); @@ -1070,8 +972,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, ret = 1; err: - if (!ret) - { + if (!ret) { ASN1_TYPE_free(typ); if (opval) *opval = NULL; @@ -1092,8 +993,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) long plen; const unsigned char *p = *in, *q; /* If not indefinite length constructed just add length */ - if (inf == 0) - { + if (inf == 0) { *in += len; return 1; } @@ -1103,10 +1003,8 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) * are encountered increment the expected eoc count otherwise just * skip to the end of the data. */ - while (len > 0) - { - if(asn1_check_eoc(&p, len)) - { + while (len > 0) { + if(asn1_check_eoc(&p, len)) { expected_eoc--; if (expected_eoc == 0) break; @@ -1116,8 +1014,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) q = p; /* Just read in a header: only care about the length */ if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, - -1, 0, 0, NULL)) - { + -1, 0, 0, NULL)) { ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); return 0; } @@ -1127,8 +1024,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) p += plen; len -= p - q; } - if (expected_eoc) - { + if (expected_eoc) { ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); return 0; } @@ -1161,21 +1057,17 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, inf &= 1; /* If no buffer and not indefinite length constructed just pass over * the encoded data */ - if (!buf && !inf) - { + if (!buf && !inf) { *in += len; return 1; } - while(len > 0) - { + while(len > 0) { q = p; /* Check for EOC */ - if (asn1_check_eoc(&p, len)) - { + if (asn1_check_eoc(&p, len)) { /* EOC is illegal outside indefinite length * constructed form */ - if (!inf) - { + if (!inf) { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC); return 0; @@ -1185,17 +1077,14 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, } if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, - len, tag, aclass, 0, NULL)) - { + len, tag, aclass, 0, NULL)) { ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); return 0; } /* If indefinite length constructed update max length */ - if (cst) - { - if (depth >= ASN1_MAX_STRING_NEST) - { + if (cst) { + if (depth >= ASN1_MAX_STRING_NEST) { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING); return 0; @@ -1208,8 +1097,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, return 0; len -= p - q; } - if (inf) - { + if (inf) { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); return 0; } @@ -1220,11 +1108,9 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) { int len; - if (buf) - { + if (buf) { len = buf->length; - if (!BUF_MEM_grow_clean(buf, len + plen)) - { + if (!BUF_MEM_grow_clean(buf, len + plen)) { ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); return 0; } @@ -1241,8 +1127,7 @@ static int asn1_check_eoc(const unsigned char **in, long len) const unsigned char *p; if (len < 2) return 0; p = *in; - if (!p[0] && !p[1]) - { + if (!p[0] && !p[1]) { *in += 2; return 1; } @@ -1269,19 +1154,15 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, p = *in; q = p; - if (ctx && ctx->valid) - { + if (ctx && ctx->valid) { i = ctx->ret; plen = ctx->plen; pclass = ctx->pclass; ptag = ctx->ptag; p += ctx->hdrlen; - } - else - { + } else { i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); - if (ctx) - { + if (ctx) { ctx->ret = i; ctx->plen = plen; ctx->pclass = pclass; @@ -1291,8 +1172,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, /* If definite length, and no error, length + * header can't exceed total amount of data available. */ - if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) - { + if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); asn1_tlc_clear(ctx); @@ -1301,16 +1181,13 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, } } - if (i & 0x80) - { + if (i & 0x80) { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); asn1_tlc_clear(ctx); return 0; } - if (exptag >= 0) - { - if ((exptag != ptag) || (expclass != pclass)) - { + if (exptag >= 0) { + if ((exptag != ptag) || (expclass != pclass)) { /* If type is OPTIONAL, not an error: * indicate missing type. */ diff --git a/lib/libcrypto/asn1/tasn_enc.c b/lib/libcrypto/asn1/tasn_enc.c index 230164107df..f7bdd11edfa 100644 --- a/lib/libcrypto/asn1/tasn_enc.c +++ b/lib/libcrypto/asn1/tasn_enc.c @@ -103,8 +103,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it, int flags) { - if (out && !*out) - { + if (out && !*out) { unsigned char *p, *buf; int len; len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); @@ -144,25 +143,23 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, if (aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_PRIMITIVE: + case ASN1_ITYPE_PRIMITIVE: if (it->templates) return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass); return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) return 0; i = asn1_get_choice_selector(pval, it); - if ((i >= 0) && (i < it->tcount)) - { + if ((i >= 0) && (i < it->tcount)) { ASN1_VALUE **pchval; const ASN1_TEMPLATE *chtt; chtt = it->templates + i; @@ -175,12 +172,12 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return 0; break; - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: /* If new style i2d it does all the work */ ef = it->funcs; return ef->asn1_ex_i2d(pval, out, it, tag, aclass); - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: /* old style hackery... */ cf = it->funcs; if (out) @@ -193,12 +190,12 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED); return i; - case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: /* Use indefinite length constructed if requested */ if (aclass & ASN1_TFLG_NDEF) ndef = 2; /* fall through */ - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: i = asn1_enc_restore(&seqcontlen, out, pval, it); /* An error occurred */ if (i < 0) @@ -209,8 +206,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Otherwise carry on */ seqcontlen = 0; /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ - if (tag == -1) - { + if (tag == -1) { tag = V_ASN1_SEQUENCE; /* Retain any other flags in aclass */ aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) @@ -219,8 +215,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) return 0; /* First work out sequence content length */ - for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) - { + for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -237,8 +232,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return seqlen; /* Output SEQUENCE header */ ASN1_put_object(out, ndef, seqcontlen, tag, aclass); - for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) - { + for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -278,8 +272,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, * the iclass argument may contain some additional flags * which should be noted and passed down to other levels. */ - if (flags & ASN1_TFLG_TAG_MASK) - { + if (flags & ASN1_TFLG_TAG_MASK) { /* Error if argument and template tagging */ if (tag != -1) /* FIXME: error code here */ @@ -287,15 +280,11 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Get tagging from template */ ttag = tt->tag; tclass = flags & ASN1_TFLG_TAG_CLASS; - } - else if (tag != -1) - { + } else if (tag != -1) { /* No template tagging, get from arguments */ ttag = tag; tclass = iclass & ASN1_TFLG_TAG_CLASS; - } - else - { + } else { ttag = -1; tclass = 0; } @@ -314,8 +303,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, ndef = 2; else ndef = 1; - if (flags & ASN1_TFLG_SK_MASK) - { + if (flags & ASN1_TFLG_SK_MASK) { /* SET OF, SEQUENCE OF */ STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; int isset, sktag, skaclass; @@ -325,8 +313,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, if (!*pval) return 0; - if (flags & ASN1_TFLG_SET_OF) - { + if (flags & ASN1_TFLG_SET_OF) { isset = 1; /* 2 means we reorder */ if (flags & ASN1_TFLG_SEQUENCE_OF) @@ -337,13 +324,10 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Work out inner tag value: if EXPLICIT * or no tagging use underlying type. */ - if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) - { + if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) { sktag = ttag; skaclass = tclass; - } - else - { + } else { skaclass = V_ASN1_UNIVERSAL; if (isset) sktag = V_ASN1_SET; @@ -352,8 +336,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Determine total length of items */ skcontlen = 0; - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) - { + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { skitem = sk_ASN1_VALUE_value(sk, i); skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), @@ -377,8 +360,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* And the stuff itself */ asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset, iclass); - if (ndef == 2) - { + if (ndef == 2) { ASN1_put_eoc(out); if (flags & ASN1_TFLG_EXPTAG) ASN1_put_eoc(out); @@ -387,8 +369,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return ret; } - if (flags & ASN1_TFLG_EXPTAG) - { + if (flags & ASN1_TFLG_EXPTAG) { /* EXPLICIT tagging */ /* Find length of tagged item */ i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), @@ -397,8 +378,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return 0; /* Find length of EXPLICIT tag */ ret = ASN1_object_size(ndef, i, ttag); - if (out) - { + if (out) { /* Output tag and item */ ASN1_put_object(out, ndef, i, ttag, tclass); ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), @@ -449,8 +429,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, /* Don't need to sort less than 2 items */ if (sk_ASN1_VALUE_num(sk) < 2) do_sort = 0; - else - { + else { derlst = malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst)); tmpdat = malloc(skcontlen); @@ -461,10 +440,8 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, } } /* If not sorting just output each item */ - if (!do_sort) - { - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) - { + if (!do_sort) { + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { skitem = sk_ASN1_VALUE_value(sk, i); ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); } @@ -473,8 +450,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, p = tmpdat; /* Doing sort: build up a list of each member's DER encoding */ - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) - { + for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { skitem = sk_ASN1_VALUE_value(sk, i); tder->data = p; tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); @@ -485,17 +461,14 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); /* Output sorted DER encoding */ p = *out; - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) - { + for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { memcpy(p, tder->data, tder->length); p += tder->length; } *out = p; /* If do_sort is 2 then reorder the STACK */ - if (do_sort == 2) - { - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); - i++, tder++) + if (do_sort == 2) { + for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) (void)sk_ASN1_VALUE_set(sk, i, tder->field); } free(derlst); @@ -536,8 +509,7 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, return 0; /* -2 return is special meaning use ndef */ - if (len == -2) - { + if (len == -2) { ndef = 2; len = 0; } @@ -546,8 +518,7 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, if (tag == -1) tag = utype; /* Output tag+length followed by content octets */ - if (out) - { + if (out) { if (usetag) ASN1_put_object(out, ndef, len, tag, aclass); asn1_ex_i2c(pval, *out, &utype, it); @@ -580,21 +551,16 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, return pf->prim_i2c(pval, cout, putype, it); /* Should type be omitted? */ - if ((it->itype != ASN1_ITYPE_PRIMITIVE) - || (it->utype != V_ASN1_BOOLEAN)) - { + if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) { if (!*pval) return -1; } - if (it->itype == ASN1_ITYPE_MSTRING) - { + if (it->itype == ASN1_ITYPE_MSTRING) { /* If MSTRING type set the underlying type */ strtmp = (ASN1_STRING *)*pval; utype = strtmp->type; *putype = utype; - } - else if (it->utype == V_ASN1_ANY) - { + } else if (it->utype == V_ASN1_ANY) { /* If ANY set type and pointer to value */ ASN1_TYPE *typ; typ = (ASN1_TYPE *)*pval; @@ -604,25 +570,23 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, } else utype = *putype; - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: otmp = (ASN1_OBJECT *)*pval; cont = otmp->data; len = otmp->length; break; - case V_ASN1_NULL: + case V_ASN1_NULL: cont = NULL; len = 0; break; - case V_ASN1_BOOLEAN: + case V_ASN1_BOOLEAN: tbool = (ASN1_BOOLEAN *)pval; if (*tbool == -1) return -1; - if (it->utype != V_ASN1_ANY) - { + if (it->utype != V_ASN1_ANY) { /* Default handling if value == size field then omit */ if (*tbool && (it->size > 0)) return -1; @@ -634,15 +598,15 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, len = 1; break; - case V_ASN1_BIT_STRING: + case V_ASN1_BIT_STRING: return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL); break; - case V_ASN1_INTEGER: - case V_ASN1_NEG_INTEGER: - case V_ASN1_ENUMERATED: - case V_ASN1_NEG_ENUMERATED: + case V_ASN1_INTEGER: + case V_ASN1_NEG_INTEGER: + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: /* These are all have the same content format * as ASN1_INTEGER */ @@ -650,31 +614,29 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, cout ? &cout : NULL); break; - case V_ASN1_OCTET_STRING: - case V_ASN1_NUMERICSTRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_T61STRING: - case V_ASN1_VIDEOTEXSTRING: - case V_ASN1_IA5STRING: - case V_ASN1_UTCTIME: - case V_ASN1_GENERALIZEDTIME: - case V_ASN1_GRAPHICSTRING: - case V_ASN1_VISIBLESTRING: - case V_ASN1_GENERALSTRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_BMPSTRING: - case V_ASN1_UTF8STRING: - case V_ASN1_SEQUENCE: - case V_ASN1_SET: - default: + case V_ASN1_OCTET_STRING: + case V_ASN1_NUMERICSTRING: + case V_ASN1_PRINTABLESTRING: + case V_ASN1_T61STRING: + case V_ASN1_VIDEOTEXSTRING: + case V_ASN1_IA5STRING: + case V_ASN1_UTCTIME: + case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GRAPHICSTRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_UTF8STRING: + case V_ASN1_SEQUENCE: + case V_ASN1_SET: + default: /* All based on ASN1_STRING and handled the same */ strtmp = (ASN1_STRING *)*pval; /* Special handling for NDEF */ if ((it->size == ASN1_TFLG_NDEF) - && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) - { - if (cout) - { + && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) { + if (cout) { strtmp->data = cout; strtmp->length = 0; } diff --git a/lib/libcrypto/asn1/tasn_fre.c b/lib/libcrypto/asn1/tasn_fre.c index b321de6615c..5211276efe6 100644 --- a/lib/libcrypto/asn1/tasn_fre.c +++ b/lib/libcrypto/asn1/tasn_fre.c @@ -93,30 +93,27 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c else asn1_cb = 0; - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_PRIMITIVE: + case ASN1_ITYPE_PRIMITIVE: if (it->templates) ASN1_template_free(pval, it->templates); else ASN1_primitive_free(pval, it); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: ASN1_primitive_free(pval, it); break; - case ASN1_ITYPE_CHOICE: - if (asn1_cb) - { + case ASN1_ITYPE_CHOICE: + if (asn1_cb) { i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); if (i == 2) return; } i = asn1_get_choice_selector(pval, it); - if ((i >= 0) && (i < it->tcount)) - { + if ((i >= 0) && (i < it->tcount)) { ASN1_VALUE **pchval; tt = it->templates + i; pchval = asn1_get_field_ptr(pval, tt); @@ -124,31 +121,29 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c } if (asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); - if (!combine) - { + if (!combine) { free(*pval); *pval = NULL; } break; - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: cf = it->funcs; if (cf && cf->asn1_free) cf->asn1_free(*pval); break; - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: ef = it->funcs; if (ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it); break; - case ASN1_ITYPE_NDEF_SEQUENCE: - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: if (asn1_do_lock(pval, -1, it) > 0) return; - if (asn1_cb) - { + if (asn1_cb) { i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); if (i == 2) return; @@ -160,8 +155,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c * free up in reverse order. */ tt = it->templates + it->tcount - 1; - for (i = 0; i < it->tcount; tt--, i++) - { + for (i = 0; i < it->tcount; tt--, i++) { ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 0); if (!seqtt) @@ -171,8 +165,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c } if (asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); - if (!combine) - { + if (!combine) { free(*pval); *pval = NULL; } @@ -183,11 +176,9 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) { int i; - if (tt->flags & ASN1_TFLG_SK_MASK) - { + if (tt->flags & ASN1_TFLG_SK_MASK) { STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) - { + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { ASN1_VALUE *vtmp; vtmp = sk_ASN1_VALUE_value(sk, i); asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), @@ -204,60 +195,52 @@ void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { int utype; - if (it) - { + if (it) { const ASN1_PRIMITIVE_FUNCS *pf; pf = it->funcs; - if (pf && pf->prim_free) - { + if (pf && pf->prim_free) { pf->prim_free(pval, it); return; } } /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ - if (!it) - { + if (!it) { ASN1_TYPE *typ = (ASN1_TYPE *)*pval; utype = typ->type; pval = &typ->value.asn1_value; if (!*pval) return; - } - else if (it->itype == ASN1_ITYPE_MSTRING) - { + } else if (it->itype == ASN1_ITYPE_MSTRING) { utype = -1; if (!*pval) return; - } - else - { + } else { utype = it->utype; if ((utype != V_ASN1_BOOLEAN) && !*pval) return; } - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: ASN1_OBJECT_free((ASN1_OBJECT *)*pval); break; - case V_ASN1_BOOLEAN: + case V_ASN1_BOOLEAN: if (it) *(ASN1_BOOLEAN *)pval = it->size; else *(ASN1_BOOLEAN *)pval = -1; return; - case V_ASN1_NULL: + case V_ASN1_NULL: break; - case V_ASN1_ANY: + case V_ASN1_ANY: ASN1_primitive_free(pval, NULL); free(*pval); break; - default: + default: ASN1_STRING_free((ASN1_STRING *)*pval); *pval = NULL; break; diff --git a/lib/libcrypto/asn1/tasn_new.c b/lib/libcrypto/asn1/tasn_new.c index f5d7c690b86..00aa31dd635 100644 --- a/lib/libcrypto/asn1/tasn_new.c +++ b/lib/libcrypto/asn1/tasn_new.c @@ -107,30 +107,27 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, CRYPTO_push_info(it->sname); #endif - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: ef = it->funcs; - if (ef && ef->asn1_ex_new) - { + if (ef && ef->asn1_ex_new) { if (!ef->asn1_ex_new(pval, it)) goto memerr; } break; - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: cf = it->funcs; if (cf && cf->asn1_new) { *pval = cf->asn1_new(); if (!*pval) goto memerr; - } + } break; - case ASN1_ITYPE_PRIMITIVE: - if (it->templates) - { + case ASN1_ITYPE_PRIMITIVE: + if (it->templates) { if (!ASN1_template_new(pval, it->templates)) goto memerr; } @@ -138,19 +135,17 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, goto memerr; break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: if (!ASN1_primitive_new(pval, it)) goto memerr; break; - case ASN1_ITYPE_CHOICE: - if (asn1_cb) - { + case ASN1_ITYPE_CHOICE: + if (asn1_cb) { i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); if (!i) goto auxerr; - if (i==2) - { + if (i==2) { #ifdef CRYPTO_MDEBUG if (it->sname) CRYPTO_pop_info(); @@ -158,8 +153,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, return 1; } } - if (!combine) - { + if (!combine) { *pval = malloc(it->size); if (!*pval) goto memerr; @@ -170,15 +164,13 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, goto auxerr; break; - case ASN1_ITYPE_NDEF_SEQUENCE: - case ASN1_ITYPE_SEQUENCE: - if (asn1_cb) - { + case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: + if (asn1_cb) { i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); if (!i) goto auxerr; - if (i==2) - { + if (i==2) { #ifdef CRYPTO_MDEBUG if (it->sname) CRYPTO_pop_info(); @@ -186,8 +178,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, return 1; } } - if (!combine) - { + if (!combine) { *pval = malloc(it->size); if (!*pval) goto memerr; @@ -195,8 +186,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, asn1_do_lock(pval, 0, it); asn1_enc_init(pval, it); } - for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) - { + for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { pseqval = asn1_get_field_ptr(pval, tt); if (!ASN1_template_new(pseqval, tt)) goto memerr; @@ -231,10 +221,9 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) { const ASN1_EXTERN_FUNCS *ef; - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: ef = it->funcs; if (ef && ef->asn1_ex_clear) ef->asn1_ex_clear(pval, it); @@ -242,21 +231,21 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) break; - case ASN1_ITYPE_PRIMITIVE: + case ASN1_ITYPE_PRIMITIVE: if (it->templates) asn1_template_clear(pval, it->templates); else asn1_primitive_clear(pval, it); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: asn1_primitive_clear(pval, it); break; - case ASN1_ITYPE_COMPAT: - case ASN1_ITYPE_CHOICE: - case ASN1_ITYPE_SEQUENCE: - case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: *pval = NULL; break; } @@ -267,15 +256,13 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) { const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); int ret; - if (tt->flags & ASN1_TFLG_OPTIONAL) - { + if (tt->flags & ASN1_TFLG_OPTIONAL) { asn1_template_clear(pval, tt); return 1; } /* If ANY DEFINED BY nothing to do */ - if (tt->flags & ASN1_TFLG_ADB_MASK) - { + if (tt->flags & ASN1_TFLG_ADB_MASK) { *pval = NULL; return 1; } @@ -284,12 +271,10 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) CRYPTO_push_info(tt->field_name); #endif /* If SET OF or SEQUENCE OF, its a STACK */ - if (tt->flags & ASN1_TFLG_SK_MASK) - { + if (tt->flags & ASN1_TFLG_SK_MASK) { STACK_OF(ASN1_VALUE) *skval; skval = sk_ASN1_VALUE_new_null(); - if (!skval) - { + if (!skval) { ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); ret = 0; goto done; @@ -328,8 +313,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) ASN1_STRING *str; int utype; - if (it && it->funcs) - { + if (it && it->funcs) { const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; if (pf->prim_new) return pf->prim_new(pval, it); @@ -339,21 +323,20 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) utype = -1; else utype = it->utype; - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); return 1; - case V_ASN1_BOOLEAN: + case V_ASN1_BOOLEAN: *(ASN1_BOOLEAN *)pval = it->size; return 1; - case V_ASN1_NULL: + case V_ASN1_NULL: *pval = (ASN1_VALUE *)1; return 1; - case V_ASN1_ANY: + case V_ASN1_ANY: typ = malloc(sizeof(ASN1_TYPE)); if (!typ) return 0; @@ -362,7 +345,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) *pval = (ASN1_VALUE *)typ; break; - default: + default: str = ASN1_STRING_type_new(utype); if (it->itype == ASN1_ITYPE_MSTRING && str) str->flags |= ASN1_STRING_FLAG_MSTRING; @@ -377,8 +360,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) { int utype; - if (it && it->funcs) - { + if (it && it->funcs) { const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; if (pf->prim_clear) pf->prim_clear(pval, it); diff --git a/lib/libcrypto/asn1/tasn_prn.c b/lib/libcrypto/asn1/tasn_prn.c index f62c085f3b9..345daeb0f35 100644 --- a/lib/libcrypto/asn1/tasn_prn.c +++ b/lib/libcrypto/asn1/tasn_prn.c @@ -86,8 +86,7 @@ ASN1_PCTX *ASN1_PCTX_new(void) { ASN1_PCTX *ret; ret = malloc(sizeof(ASN1_PCTX)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); return NULL; } @@ -199,8 +198,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, ASN1_aux_cb *asn1_cb; ASN1_PRINT_ARG parg; int i; - if (aux && aux->asn1_cb) - { + if (aux && aux->asn1_cb) { parg.out = out; parg.indent = indent; parg.pctx = pctx; @@ -208,10 +206,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, } else asn1_cb = 0; - if(*fld == NULL) - { - if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) - { + if(*fld == NULL) { + if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) { if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; @@ -221,29 +217,26 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 1; } - switch(it->itype) - { - case ASN1_ITYPE_PRIMITIVE: - if(it->templates) - { + switch(it->itype) { + case ASN1_ITYPE_PRIMITIVE: + if(it->templates) { if (!asn1_template_print_ctx(out, fld, indent, it->templates, pctx)) return 0; } /* fall thru */ - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: if (!asn1_primitive_print(out, fld, it, indent, fname, sname,pctx)) return 0; break; - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; /* Use new style print routine if possible */ ef = it->funcs; - if (ef && ef->asn1_ex_print) - { + if (ef && ef->asn1_ex_print) { i = ef->asn1_ex_print(out, fld, indent, "", pctx); if (!i) return 0; @@ -256,7 +249,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 0; break; - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: #if 0 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; @@ -264,8 +257,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, /* CHOICE type, get selector */ i = asn1_get_choice_selector(fld, it); /* This should never happen... */ - if((i < 0) || (i >= it->tcount)) - { + if((i < 0) || (i >= it->tcount)) { if (BIO_printf(out, "ERROR: selector [%d] invalid\n", i) <= 0) return 0; @@ -277,26 +269,21 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 0; break; - case ASN1_ITYPE_SEQUENCE: - case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; - if (fname || sname) - { - if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) - { + if (fname || sname) { + if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { if (BIO_puts(out, " {\n") <= 0) return 0; - } - else - { + } else { if (BIO_puts(out, "\n") <= 0) return 0; } } - if (asn1_cb) - { + if (asn1_cb) { i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); if (i == 0) return 0; @@ -305,8 +292,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, } /* Print each field entry */ - for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) - { + for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) { const ASN1_TEMPLATE *seqtt; seqtt = asn1_do_adb(fld, tt, 1); tmpfld = asn1_get_field_ptr(fld, seqtt); @@ -314,14 +300,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, indent + 2, seqtt, pctx)) return 0; } - if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) - { + if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { if (BIO_printf(out, "%*s}\n", indent, "") < 0) return 0; } - if (asn1_cb) - { + if (asn1_cb) { i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); if (i == 0) return 0; @@ -350,17 +334,14 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, fname = NULL; else fname = tt->field_name; - if(flags & ASN1_TFLG_SK_MASK) - { + if(flags & ASN1_TFLG_SK_MASK) { char *tname; ASN1_VALUE *skitem; STACK_OF(ASN1_VALUE) *stack; /* SET OF, SEQUENCE OF */ - if (fname) - { - if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) - { + if (fname) { + if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) { if(flags & ASN1_TFLG_SET_OF) tname = "SET"; else @@ -374,8 +355,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 0; } stack = (STACK_OF(ASN1_VALUE) *)*fld; - for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) - { + for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) { if ((i > 0) && (BIO_puts(out, "\n") <= 0)) return 0; @@ -386,8 +366,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, } if (!i && BIO_printf(out, "%*s\n", indent + 2, "") <= 0) return 0; - if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) - { + if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { if (BIO_printf(out, "%*s}\n", indent, "") <= 0) return 0; } @@ -409,8 +388,7 @@ static int asn1_print_fsname(BIO *out, int indent, return 1; #endif - while (indent > nspaces) - { + while (indent > nspaces) { if (BIO_write(out, spaces, nspaces) != nspaces) return 0; indent -= nspaces; @@ -423,20 +401,15 @@ static int asn1_print_fsname(BIO *out, int indent, fname = NULL; if (!sname && !fname) return 1; - if (fname) - { + if (fname) { if (BIO_puts(out, fname) <= 0) return 0; } - if (sname) - { - if (fname) - { + if (sname) { + if (fname) { if (BIO_printf(out, " (%s)", sname) <= 0) return 0; - } - else - { + } else { if (BIO_puts(out, sname) <= 0) return 0; } @@ -450,13 +423,12 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval, const ASN1_PCTX *pctx) { const char *str; - switch (boolval) - { - case -1: + switch (boolval) { + case -1: str = "BOOL ABSENT"; break; - case 0: + case 0: str = "FALSE"; break; @@ -501,8 +473,7 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, const ASN1_PCTX *pctx) { - if (str->type == V_ASN1_BIT_STRING) - { + if (str->type == V_ASN1_BIT_STRING) { if (BIO_printf(out, " (%ld unused bits)\n", str->flags & 0x7) <= 0) return 0; @@ -536,8 +507,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, utype = str->type & ~V_ASN1_NEG; else utype = it->utype; - if (utype == V_ASN1_ANY) - { + if (utype == V_ASN1_ANY) { ASN1_TYPE *atype = (ASN1_TYPE *)*fld; utype = atype->type; fld = &atype->value.asn1_value; @@ -546,33 +516,28 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, pname = NULL; else pname = ASN1_tag2str(utype); - } - else - { + } else { if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) pname = ASN1_tag2str(utype); else pname = NULL; } - if (utype == V_ASN1_NULL) - { + if (utype == V_ASN1_NULL) { if (BIO_puts(out, "NULL\n") <= 0) return 0; return 1; } - if (pname) - { + if (pname) { if (BIO_puts(out, pname) <= 0) return 0; if (BIO_puts(out, ":") <= 0) return 0; } - switch (utype) - { - case V_ASN1_BOOLEAN: + switch (utype) { + case V_ASN1_BOOLEAN: { int boolval = *(int *)fld; if (boolval == -1) @@ -581,32 +546,32 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, } break; - case V_ASN1_INTEGER: - case V_ASN1_ENUMERATED: + case V_ASN1_INTEGER: + case V_ASN1_ENUMERATED: ret = asn1_print_integer_ctx(out, str, pctx); break; - case V_ASN1_UTCTIME: + case V_ASN1_UTCTIME: ret = ASN1_UTCTIME_print(out, str); break; - case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GENERALIZEDTIME: ret = ASN1_GENERALIZEDTIME_print(out, str); break; - case V_ASN1_OBJECT: + case V_ASN1_OBJECT: ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx); break; - case V_ASN1_OCTET_STRING: - case V_ASN1_BIT_STRING: + case V_ASN1_OCTET_STRING: + case V_ASN1_BIT_STRING: ret = asn1_print_obstring_ctx(out, str, indent, pctx); needlf = 0; break; - case V_ASN1_SEQUENCE: - case V_ASN1_SET: - case V_ASN1_OTHER: + case V_ASN1_SEQUENCE: + case V_ASN1_SET: + case V_ASN1_OTHER: if (BIO_puts(out, "\n") <= 0) return 0; if (ASN1_parse_dump(out, str->data, str->length, @@ -615,7 +580,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, needlf = 0; break; - default: + default: ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); } diff --git a/lib/libcrypto/asn1/tasn_utl.c b/lib/libcrypto/asn1/tasn_utl.c index 37c86c6af88..9715dac931d 100644 --- a/lib/libcrypto/asn1/tasn_utl.c +++ b/lib/libcrypto/asn1/tasn_utl.c @@ -109,8 +109,7 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0; lck = offset2ptr(*pval, aux->ref_offset); - if (op == 0) - { + if (op == 0) { *lck = 1; return 1; } @@ -133,8 +132,7 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) { ASN1_ENCODING *enc; enc = asn1_get_enc_ptr(pval, it); - if (enc) - { + if (enc) { enc->enc = NULL; enc->len = 0; enc->modified = 1; @@ -145,8 +143,7 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { ASN1_ENCODING *enc; enc = asn1_get_enc_ptr(pval, it); - if (enc) - { + if (enc) { if (enc->enc) free(enc->enc); enc->enc = NULL; @@ -182,8 +179,7 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, enc = asn1_get_enc_ptr(pval, it); if (!enc || enc->modified) return 0; - if (out) - { + if (out) { memcpy(*out, enc->enc, enc->len); *out += enc->len; } @@ -228,8 +224,7 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, sfld = offset2ptr(*pval, adb->offset); /* Check if NULL */ - if (!sfld) - { + if (!sfld) { if (!adb->null_tt) goto err; return adb->null_tt; diff --git a/lib/libcrypto/asn1/x_algor.c b/lib/libcrypto/asn1/x_algor.c index 6f6fbb112a5..7ae473485c1 100644 --- a/lib/libcrypto/asn1/x_algor.c +++ b/lib/libcrypto/asn1/x_algor.c @@ -81,25 +81,21 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) { if (!alg) return 0; - if (ptype != V_ASN1_UNDEF) - { + if (ptype != V_ASN1_UNDEF) { if (alg->parameter == NULL) alg->parameter = ASN1_TYPE_new(); if (alg->parameter == NULL) return 0; } - if (alg) - { + if (alg) { if (alg->algorithm) ASN1_OBJECT_free(alg->algorithm); alg->algorithm = aobj; } if (ptype == 0) return 1; - if (ptype == V_ASN1_UNDEF) - { - if (alg->parameter) - { + if (ptype == V_ASN1_UNDEF) { + if (alg->parameter) { ASN1_TYPE_free(alg->parameter); alg->parameter = NULL; } @@ -114,10 +110,8 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, { if (paobj) *paobj = algor->algorithm; - if (pptype) - { - if (algor->parameter == NULL) - { + if (pptype) { + if (algor->parameter == NULL) { *pptype = V_ASN1_UNDEF; return; } diff --git a/lib/libcrypto/asn1/x_crl.c b/lib/libcrypto/asn1/x_crl.c index b3a6355795a..ea94f026b20 100644 --- a/lib/libcrypto/asn1/x_crl.c +++ b/lib/libcrypto/asn1/x_crl.c @@ -101,10 +101,10 @@ static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, /* Just set cmp function here. We don't sort because that * would affect the output of X509_CRL_print(). */ - case ASN1_OP_D2I_POST: + case ASN1_OP_D2I_POST: (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); break; -} + } return 1; } @@ -133,8 +133,7 @@ static int crl_set_issuers(X509_CRL *crl) revoked = X509_CRL_get_REVOKED(crl); gens = NULL; - for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) - { + for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) { X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); STACK_OF(X509_EXTENSION) *exts; ASN1_ENUMERATED *reason; @@ -142,17 +141,14 @@ static int crl_set_issuers(X509_CRL *crl) gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer, &j, NULL); - if (!gtmp && (j != -1)) - { + if (!gtmp && (j != -1)) { crl->flags |= EXFLAG_INVALID; return 1; } - if (gtmp) - { + if (gtmp) { gens = gtmp; - if (!crl->issuers) - { + if (!crl->issuers) { crl->issuers = sk_GENERAL_NAMES_new_null(); if (!crl->issuers) return 0; @@ -164,29 +160,24 @@ static int crl_set_issuers(X509_CRL *crl) reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL); - if (!reason && (j != -1)) - { + if (!reason && (j != -1)) { crl->flags |= EXFLAG_INVALID; return 1; } - if (reason) - { + if (reason) { rev->reason = ASN1_ENUMERATED_get(reason); ASN1_ENUMERATED_free(reason); - } - else + } else rev->reason = CRL_REASON_NONE; /* Check for critical CRL entry extensions */ exts = rev->extensions; - for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) - { + for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) { ext = sk_X509_EXTENSION_value(exts, j); - if (ext->critical > 0) - { + if (ext->critical > 0) { if (OBJ_obj2nid(ext->object) == NID_certificate_issuer) continue; @@ -213,9 +204,8 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, X509_EXTENSION *ext; int idx; - switch(operation) - { - case ASN1_OP_NEW_POST: + switch(operation) { + case ASN1_OP_NEW_POST: crl->idp = NULL; crl->akid = NULL; crl->flags = 0; @@ -228,7 +218,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, crl->base_crl_number = NULL; break; - case ASN1_OP_D2I_POST: + case ASN1_OP_D2I_POST: #ifndef OPENSSL_NO_SHA X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL); #endif @@ -259,15 +249,13 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, exts = crl->crl->extensions; - for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) - { + for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) { int nid; ext = sk_X509_EXTENSION_value(exts, idx); nid = OBJ_obj2nid(ext->object); if (nid == NID_freshest_crl) crl->flags |= EXFLAG_FRESHEST; - if (ext->critical > 0) - { + if (ext->critical > 0) { /* We handle IDP and deltas */ if ((nid == NID_issuing_distribution_point) || (nid == NID_delta_crl)) @@ -281,16 +269,14 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, if (!crl_set_issuers(crl)) return 0; - if (crl->meth->crl_init) - { + if (crl->meth->crl_init) { if (crl->meth->crl_init(crl) == 0) return 0; } break; - case ASN1_OP_FREE_POST: - if (crl->meth->crl_free) - { + case ASN1_OP_FREE_POST: + if (crl->meth->crl_free) { if (!crl->meth->crl_free(crl)) return 0; } @@ -313,18 +299,15 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) int idp_only = 0; /* Set various flags according to IDP */ crl->idp_flags |= IDP_PRESENT; - if (idp->onlyuser > 0) - { + if (idp->onlyuser > 0) { idp_only++; crl->idp_flags |= IDP_ONLYUSER; } - if (idp->onlyCA > 0) - { + if (idp->onlyCA > 0) { idp_only++; crl->idp_flags |= IDP_ONLYCA; } - if (idp->onlyattr > 0) - { + if (idp->onlyattr > 0) { idp_only++; crl->idp_flags |= IDP_ONLYATTR; } @@ -335,8 +318,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) if (idp->indirectCRL > 0) crl->idp_flags |= IDP_INDIRECT; - if (idp->onlysomereasons) - { + if (idp->onlysomereasons) { crl->idp_flags |= IDP_REASONS; if (idp->onlysomereasons->length > 0) crl->idp_reasons = idp->onlysomereasons->data[0]; @@ -417,8 +399,7 @@ static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, { int i; - if (!rev->issuer) - { + if (!rev->issuer) { if (!nm) return 1; if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) @@ -429,8 +410,7 @@ static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, if (!nm) nm = X509_CRL_get_issuer(crl); - for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) - { + for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) { GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); if (gen->type != GEN_DIRNAME) continue; @@ -450,8 +430,7 @@ static int def_crl_lookup(X509_CRL *crl, /* Sort revoked into serial number order if not already sorted. * Do this under a lock to avoid race condition. */ - if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) - { + if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) { CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); sk_X509_REVOKED_sort(crl->crl->revoked); CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); @@ -460,13 +439,11 @@ static int def_crl_lookup(X509_CRL *crl, if(idx < 0) return 0; /* Need to look for matching name */ - for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) - { + for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) { rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) return 0; - if (crl_revoked_issuer_match(crl, issuer, rev)) - { + if (crl_revoked_issuer_match(crl, issuer, rev)) { if (ret) *ret = rev; if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) diff --git a/lib/libcrypto/asn1/x_info.c b/lib/libcrypto/asn1/x_info.c index c1b6058d587..07ce15dbd7a 100644 --- a/lib/libcrypto/asn1/x_info.c +++ b/lib/libcrypto/asn1/x_info.c @@ -67,8 +67,7 @@ X509_INFO *X509_INFO_new(void) X509_INFO *ret=NULL; ret=(X509_INFO *)malloc(sizeof(X509_INFO)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); return(NULL); } diff --git a/lib/libcrypto/asn1/x_name.c b/lib/libcrypto/asn1/x_name.c index dfd4363aa00..d10ac5acd1e 100644 --- a/lib/libcrypto/asn1/x_name.c +++ b/lib/libcrypto/asn1/x_name.c @@ -145,8 +145,7 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) memerr: ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); - if (ret) - { + if (ret) { if (ret->entries) sk_X509_NAME_ENTRY_free(ret->entries); free(ret); @@ -242,14 +241,14 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT } static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne) - { +{ sk_X509_NAME_ENTRY_free(ne); - } +} static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne) - { +{ sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free); - } +} static int x509_name_encode(X509_NAME *a) { @@ -295,12 +294,12 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent, const char *fname, const ASN1_PCTX *pctx) - { +{ if (X509_NAME_print_ex(out, (X509_NAME *)*pval, indent, pctx->nm_flags) <= 0) return 0; return 2; - } +} /* This function generates the canonical encoding of the Name structure. * In it all strings are converted to UTF8, leading, trailing and @@ -316,39 +315,35 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, */ static int x509_name_canon(X509_NAME *a) - { +{ unsigned char *p; STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL; STACK_OF(X509_NAME_ENTRY) *entries = NULL; X509_NAME_ENTRY *entry, *tmpentry = NULL; int i, set = -1, ret = 0; - if (a->canon_enc) - { + if (a->canon_enc) { free(a->canon_enc); a->canon_enc = NULL; } /* Special case: empty X509_NAME => null encoding */ - if (sk_X509_NAME_ENTRY_num(a->entries) == 0) - { + if (sk_X509_NAME_ENTRY_num(a->entries) == 0) { a->canon_enclen = 0; return 1; - } + } intname = sk_STACK_OF_X509_NAME_ENTRY_new_null(); if(!intname) goto err; - for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) - { + for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { entry = sk_X509_NAME_ENTRY_value(a->entries, i); - if(entry->set != set) - { + if(entry->set != set) { entries = sk_X509_NAME_ENTRY_new_null(); if(!entries) goto err; if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) goto err; set = entry->set; - } + } tmpentry = X509_NAME_ENTRY_new(); tmpentry->object = OBJ_dup(entry->object); if (!asn1_string_canon(tmpentry->value, entry->value)) @@ -356,7 +351,7 @@ static int x509_name_canon(X509_NAME *a) if(!sk_X509_NAME_ENTRY_push(entries, tmpentry)) goto err; tmpentry = NULL; - } + } /* Finally generate encoding */ @@ -381,7 +376,7 @@ static int x509_name_canon(X509_NAME *a) sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, local_sk_X509_NAME_ENTRY_pop_free); return ret; - } +} /* Bitmap of all the types of string that will be canonicalized. */ @@ -392,17 +387,16 @@ static int x509_name_canon(X509_NAME *a) static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) - { +{ unsigned char *to, *from; int len, i; /* If type not in bitmask just copy string across */ - if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) - { + if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) { if (!ASN1_STRING_copy(out, in)) return 0; return 1; - } + } out->type = V_ASN1_UTF8STRING; out->length = ASN1_STRING_to_UTF8(&out->data, in); @@ -421,99 +415,87 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) */ /* Ignore leading spaces */ - while((len > 0) && !(*from & 0x80) && isspace(*from)) - { + while((len > 0) && !(*from & 0x80) && isspace(*from)) { from++; len--; - } + } to = from + len - 1; /* Ignore trailing spaces */ - while ((len > 0) && !(*to & 0x80) && isspace(*to)) - { + while ((len > 0) && !(*to & 0x80) && isspace(*to)) { to--; len--; - } + } to = out->data; i = 0; - while(i < len) - { + while(i < len) { /* If MSB set just copy across */ - if (*from & 0x80) - { + if (*from & 0x80) { *to++ = *from++; i++; } /* Collapse multiple spaces */ - else if (isspace(*from)) - { + else if (isspace(*from)) { /* Copy one space across */ *to++ = ' '; /* Ignore subsequent spaces. Note: don't need to * check len here because we know the last * character is a non-space so we can't overflow. */ - do - { + do { from++; i++; - } - while(!(*from & 0x80) && isspace(*from)); - } - else - { + } while(!(*from & 0x80) && isspace(*from)); + } else { *to++ = tolower(*from); from++; i++; - } } + } out->length = to - out->data; return 1; - } +} static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, unsigned char **in) - { +{ int i, len, ltmp; ASN1_VALUE *v; STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname; len = 0; - for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) - { + for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) { v = sk_ASN1_VALUE_value(intname, i); ltmp = ASN1_item_ex_i2d(&v, in, ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1); if (ltmp < 0) return ltmp; len += ltmp; - } - return len; } + return len; +} int X509_NAME_set(X509_NAME **xn, X509_NAME *name) - { +{ X509_NAME *in; if (!xn || !name) return(0); - if (*xn != name) - { + if (*xn != name) { in=X509_NAME_dup(name); - if (in != NULL) - { + if (in != NULL) { X509_NAME_free(*xn); *xn=in; - } } - return(*xn != NULL); } + return(*xn != NULL); +} IMPLEMENT_STACK_OF(X509_NAME_ENTRY) IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) diff --git a/lib/libcrypto/asn1/x_pkey.c b/lib/libcrypto/asn1/x_pkey.c index 37d2d93968c..eac134a1ee4 100644 --- a/lib/libcrypto/asn1/x_pkey.c +++ b/lib/libcrypto/asn1/x_pkey.c @@ -81,17 +81,14 @@ X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) ret->cipher.cipher=EVP_get_cipherbyname( OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); - if (ret->cipher.cipher == NULL) - { + if (ret->cipher.cipher == NULL) { c.error=ASN1_R_UNSUPPORTED_CIPHER; c.line=__LINE__; goto err; } - if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) - { + if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) { i=ret->enc_algor->parameter->value.octet_string->length; - if (i > EVP_MAX_IV_LENGTH) - { + if (i > EVP_MAX_IV_LENGTH) { c.error=ASN1_R_IV_TOO_LARGE; c.line=__LINE__; goto err; diff --git a/lib/libcrypto/asn1/x_pubkey.c b/lib/libcrypto/asn1/x_pubkey.c index 454d50f24cf..1d6ab6580a8 100644 --- a/lib/libcrypto/asn1/x_pubkey.c +++ b/lib/libcrypto/asn1/x_pubkey.c @@ -72,8 +72,7 @@ static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) { - if (operation == ASN1_OP_FREE_POST) - { + if (operation == ASN1_OP_FREE_POST) { X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; EVP_PKEY_free(pubkey->pkey); } @@ -95,26 +94,19 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) if ((pk=X509_PUBKEY_new()) == NULL) goto error; - if (pkey->ameth) - { - if (pkey->ameth->pub_encode) - { - if (!pkey->ameth->pub_encode(pk, pkey)) - { + if (pkey->ameth) { + if (pkey->ameth->pub_encode) { + if (!pkey->ameth->pub_encode(pk, pkey)) { X509err(X509_F_X509_PUBKEY_SET, X509_R_PUBLIC_KEY_ENCODE_ERROR); goto error; } - } - else - { + } else { X509err(X509_F_X509_PUBKEY_SET, X509_R_METHOD_NOT_SUPPORTED); goto error; } - } - else - { + } else { X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); goto error; } @@ -136,51 +128,41 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) if (key == NULL) goto error; - if (key->pkey != NULL) - { + if (key->pkey != NULL) { CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); return key->pkey; } if (key->public_key == NULL) goto error; - if ((ret = EVP_PKEY_new()) == NULL) - { + if ((ret = EVP_PKEY_new()) == NULL) { X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); goto error; } - if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) - { + if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) { X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); goto error; } - if (ret->ameth->pub_decode) - { - if (!ret->ameth->pub_decode(ret, key)) - { + if (ret->ameth->pub_decode) { + if (!ret->ameth->pub_decode(ret, key)) { X509err(X509_F_X509_PUBKEY_GET, X509_R_PUBLIC_KEY_DECODE_ERROR); goto error; } - } - else - { + } else { X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); goto error; } /* Check to see if another thread set key->pkey first */ CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); - if (key->pkey) - { + if (key->pkey) { CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); EVP_PKEY_free(ret); ret = key->pkey; - } - else - { + } else { key->pkey = ret; CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); } @@ -208,8 +190,7 @@ EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, pktmp = X509_PUBKEY_get(xpk); X509_PUBKEY_free(xpk); if(!pktmp) return NULL; - if(a) - { + if(a) { EVP_PKEY_free(*a); *a = pktmp; } @@ -244,8 +225,7 @@ RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, EVP_PKEY_free(pkey); if (!key) return NULL; *pp = q; - if (a) - { + if (a) { RSA_free(*a); *a = key; } @@ -258,8 +238,7 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) int ret; if (!a) return 0; pktmp = EVP_PKEY_new(); - if (!pktmp) - { + if (!pktmp) { ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -284,8 +263,7 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, EVP_PKEY_free(pkey); if (!key) return NULL; *pp = q; - if (a) - { + if (a) { DSA_free(*a); *a = key; } @@ -298,8 +276,7 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) int ret; if(!a) return 0; pktmp = EVP_PKEY_new(); - if(!pktmp) - { + if(!pktmp) { ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -323,8 +300,7 @@ EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) EVP_PKEY_free(pkey); if (!key) return(NULL); *pp = q; - if (a) - { + if (a) { EC_KEY_free(*a); *a = key; } @@ -336,8 +312,7 @@ int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) EVP_PKEY *pktmp; int ret; if (!a) return(0); - if ((pktmp = EVP_PKEY_new()) == NULL) - { + if ((pktmp = EVP_PKEY_new()) == NULL) { ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); return(0); } @@ -354,8 +329,7 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, { if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) return 0; - if (penc) - { + if (penc) { if (pub->public_key->data) free(pub->public_key->data); pub->public_key->data = penc; @@ -374,8 +348,7 @@ int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, { if (ppkalg) *ppkalg = pub->algor->algorithm; - if (pk) - { + if (pk) { *pk = pub->public_key->data; *ppklen = pub->public_key->length; } diff --git a/lib/libcrypto/asn1/x_x509.c b/lib/libcrypto/asn1/x_x509.c index ff8bd77024a..20448a8e3b1 100644 --- a/lib/libcrypto/asn1/x_x509.c +++ b/lib/libcrypto/asn1/x_x509.c @@ -88,7 +88,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, switch(operation) { - case ASN1_OP_NEW_POST: + case ASN1_OP_NEW_POST: ret->valid=0; ret->name = NULL; ret->ex_flags = 0; @@ -104,12 +104,12 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); break; - case ASN1_OP_D2I_POST: + case ASN1_OP_D2I_POST: if (ret->name != NULL) free(ret->name); ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); break; - case ASN1_OP_FREE_POST: + case ASN1_OP_FREE_POST: CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); X509_CERT_AUX_free(ret->aux); ASN1_OCTET_STRING_free(ret->skid); diff --git a/lib/libcrypto/asn1/x_x509a.c b/lib/libcrypto/asn1/x_x509a.c index 9449f517be1..287d780830b 100644 --- a/lib/libcrypto/asn1/x_x509a.c +++ b/lib/libcrypto/asn1/x_x509a.c @@ -91,8 +91,7 @@ static X509_CERT_AUX *aux_get(X509 *x) int X509_alias_set1(X509 *x, unsigned char *name, int len) { X509_CERT_AUX *aux; - if (!name) - { + if (!name) { if (!x || !x->aux || !x->aux->alias) return 1; ASN1_UTF8STRING_free(x->aux->alias); @@ -107,8 +106,7 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len) int X509_keyid_set1(X509 *x, unsigned char *id, int len) { X509_CERT_AUX *aux; - if (!id) - { + if (!id) { if (!x || !x->aux || !x->aux->keyid) return 1; ASN1_OCTET_STRING_free(x->aux->keyid); diff --git a/lib/libssl/src/crypto/asn1/a_dup.c b/lib/libssl/src/crypto/asn1/a_dup.c index 4482a893373..409bdcf2d1e 100644 --- a/lib/libssl/src/crypto/asn1/a_dup.c +++ b/lib/libssl/src/crypto/asn1/a_dup.c @@ -69,13 +69,14 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) int i; char *ret; - if (x == NULL) return(NULL); + if (x == NULL) + return(NULL); i=i2d(x,NULL); b=malloc(i+10); - if (b == NULL) - { - ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); + if (b == NULL) { + ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); + return(NULL); } p= b; i=i2d(x,&p); @@ -99,12 +100,13 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x) long i; void *ret; - if (x == NULL) return(NULL); + if (x == NULL) + return(NULL); i=ASN1_item_i2d(x,&b,it); - if (b == NULL) - { - ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); + if (b == NULL) { + ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); + return(NULL); } p= b; ret=ASN1_item_d2i(NULL,&p,i, it); diff --git a/lib/libssl/src/crypto/asn1/a_enum.c b/lib/libssl/src/crypto/asn1/a_enum.c index 77c7c2cd88a..70cea0aad21 100644 --- a/lib/libssl/src/crypto/asn1/a_enum.c +++ b/lib/libssl/src/crypto/asn1/a_enum.c @@ -74,27 +74,23 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) long d; a->type=V_ASN1_ENUMERATED; - 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_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); return(0); } d=v; - if (d < 0) - { + if (d < 0) { d= -d; a->type=V_ASN1_NEG_ENUMERATED; } - for (i=0; i>=8; @@ -118,16 +114,14 @@ long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) else if (i != V_ASN1_ENUMERATED) return -1; - if (a->length > (int)sizeof(long)) - { + if (a->length > (int)sizeof(long)) { /* hmm... a bit ugly */ return(0xffffffffL); } if (a->data == NULL) return 0; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { r<<=8; r|=(unsigned char)a->data[i]; } @@ -144,8 +138,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) ret=M_ASN1_ENUMERATED_new(); else ret=ai; - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); goto err; } @@ -153,8 +146,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) else ret->type=V_ASN1_ENUMERATED; 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) { diff --git a/lib/libssl/src/crypto/asn1/a_gentm.c b/lib/libssl/src/crypto/asn1/a_gentm.c index 54016dc8e7b..2ef6e6bc228 100644 --- a/lib/libssl/src/crypto/asn1/a_gentm.c +++ b/lib/libssl/src/crypto/asn1/a_gentm.c @@ -116,8 +116,7 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) * field so make first two fields 00 to 99 */ if (l < 13) goto err; - for (i=0; i<7; i++) - { + for (i=0; i<7; i++) { if ((i == 6) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) { i++; break; } @@ -146,12 +145,10 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) if (a[o] == 'Z') o++; - else if ((a[o] == '+') || (a[o] == '-')) - { + else if ((a[o] == '+') || (a[o] == '-')) { o++; if (o+4 > l) goto err; - for (i=7; i<9; i++) - { + for (i=7; i<9; i++) { if ((a[o] < '0') || (a[o] > '9')) goto err; n= a[o]-'0'; o++; @@ -160,9 +157,7 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) if ((n < min[i]) || (n > max[i])) goto err; o++; } - } - else - { + } else { /* Missing time zone information. */ goto err; } @@ -178,10 +173,8 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) t.type=V_ASN1_GENERALIZEDTIME; t.length=strlen(str); t.data=(unsigned char *)str; - if (ASN1_GENERALIZEDTIME_check(&t)) - { - if (s != NULL) - { + if (ASN1_GENERALIZEDTIME_check(&t)) { + if (s != NULL) { if (!ASN1_STRING_set((ASN1_STRING *)s, (unsigned char *)str,t.length)) return 0; @@ -216,18 +209,15 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, if (ts == NULL) return(NULL); - if (offset_day || offset_sec) - { + if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) return NULL; } p=(char *)s->data; - if ((p == NULL) || ((size_t)s->length < len)) - { + if ((p == NULL) || ((size_t)s->length < len)) { p=malloc(len); - if (p == NULL) - { + if (p == NULL) { ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE); return(NULL); diff --git a/lib/libssl/src/crypto/asn1/a_i2d_fp.c b/lib/libssl/src/crypto/asn1/a_i2d_fp.c index 52bedb3f737..93e6d8351bd 100644 --- a/lib/libssl/src/crypto/asn1/a_i2d_fp.c +++ b/lib/libssl/src/crypto/asn1/a_i2d_fp.c @@ -69,8 +69,7 @@ int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) BIO *b; int ret; - if ((b=BIO_new(BIO_s_file())) == NULL) - { + if ((b=BIO_new(BIO_s_file())) == NULL) { ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); return(0); } @@ -89,8 +88,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) n=i2d(x,NULL); b=(char *)malloc(n); - if (b == NULL) - { + if (b == NULL) { ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); return(0); } @@ -98,12 +96,10 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) p=(unsigned char *)b; i2d(x,&p); - for (;;) - { + for (;;) { i=BIO_write(out,&(b[j]),n); if (i == n) break; - if (i <= 0) - { + if (i <= 0) { ret=0; break; } @@ -122,8 +118,7 @@ int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) BIO *b; int ret; - if ((b=BIO_new(BIO_s_file())) == NULL) - { + if ((b=BIO_new(BIO_s_file())) == NULL) { ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); return(0); } @@ -140,18 +135,15 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) int i,j=0,n,ret=1; n = ASN1_item_i2d(x, &b, it); - if (b == NULL) - { + if (b == NULL) { ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); return(0); } - for (;;) - { + for (;;) { i=BIO_write(out,&(b[j]),n); if (i == n) break; - if (i <= 0) - { + if (i <= 0) { ret=0; break; } diff --git a/lib/libssl/src/crypto/asn1/a_int.c b/lib/libssl/src/crypto/asn1/a_int.c index f41d462ffe0..cc2b985fa10 100644 --- a/lib/libssl/src/crypto/asn1/a_int.c +++ b/lib/libssl/src/crypto/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; } diff --git a/lib/libssl/src/crypto/asn1/a_object.c b/lib/libssl/src/crypto/asn1/a_object.c index 7e9eeaa2e1c..e73b1223ded 100644 --- a/lib/libssl/src/crypto/asn1/a_object.c +++ b/lib/libssl/src/crypto/asn1/a_object.c @@ -100,55 +100,45 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) p=buf; c= *(p++); num--; - if ((c >= '0') && (c <= '2')) - { + if ((c >= '0') && (c <= '2')) { first= c-'0'; - } - else - { + } else { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); goto err; } - if (num <= 0) - { + if (num <= 0) { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); goto err; } c= *(p++); num--; - for (;;) - { + for (;;) { if (num <= 0) break; - if ((c != '.') && (c != ' ')) - { + if ((c != '.') && (c != ' ')) { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); goto err; } l=0; use_bn = 0; - for (;;) - { + for (;;) { if (num <= 0) break; num--; c= *(p++); if ((c == ' ') || (c == '.')) break; - if ((c < '0') || (c > '9')) - { + 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)) - { + 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 (use_bn) { if (!BN_mul_word(bl, 10L) || !BN_add_word(bl, c-'0')) goto err; @@ -156,15 +146,12 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) else l=l*10L+(long)(c-'0'); } - if (len == 0) - { - if ((first < 2) && (l >= 40)) - { + 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 (use_bn) { if (!BN_add_word(bl, first * 40)) goto err; } @@ -172,13 +159,11 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) l+=(long)first*40; } i=0; - if (use_bn) - { + if (use_bn) { int blsize; blsize = BN_num_bits(bl); blsize = (blsize + 6)/7; - if (blsize > tmpsize) - { + if (blsize > tmpsize) { if (tmp != ftmp) free(tmp); tmpsize = blsize + 32; @@ -188,22 +173,17 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) } while(blsize--) tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); - } - else - { + } else { - for (;;) - { + for (;;) { tmp[i++]=(unsigned char)l&0x7f; l>>=7L; if (l == 0L) break; } } - if (out != NULL) - { - if (len+i > olen) - { + if (out != NULL) { + if (len+i > olen) { ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); goto err; } @@ -240,8 +220,7 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) if ((a == NULL) || (a->data == NULL)) return(BIO_write(bp,"NULL",4)); i=i2t_ASN1_OBJECT(buf,sizeof buf,a); - if (i > (int)(sizeof(buf) - 1)) - { + if (i > (int)(sizeof(buf) - 1)) { p = malloc(i + 1); if (!p) return -1; @@ -265,14 +244,12 @@ ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, ASN1_OBJECT *ret = NULL; 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_OBJECT) - { + if (tag != V_ASN1_OBJECT) { i=ASN1_R_EXPECTING_AN_OBJECT; goto err; } @@ -293,10 +270,8 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, /* Sanity check OID encoding: can't have leading 0x80 in * subidentifiers, see: X.690 8.19.2 */ - for (i = 0, p = *pp; i < len; i++, p++) - { - if (*p == 0x80 && (!i || !(p[-1] & 0x80))) - { + 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; } @@ -305,8 +280,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, /* 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)) - { + !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) { if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); } else ret=(*a); @@ -316,13 +290,11 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, data = (unsigned char *)ret->data; ret->data = NULL; /* once detached we can change it */ - if ((data == NULL) || (ret->length < len)) - { + 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; } + if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; } ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; } memcpy(data,p,(int)len); @@ -349,8 +321,7 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) ASN1_OBJECT *ret; ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); return(NULL); } @@ -366,16 +337,14 @@ ASN1_OBJECT *ASN1_OBJECT_new(void) void ASN1_OBJECT_free(ASN1_OBJECT *a) { if (a == NULL) return; - if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) - { + 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->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) { if (a->data != NULL) free((void *)a->data); a->data=NULL; a->length=0; diff --git a/lib/libssl/src/crypto/asn1/a_print.c b/lib/libssl/src/crypto/asn1/a_print.c index cfd0452f13a..9e421dba668 100644 --- a/lib/libssl/src/crypto/asn1/a_print.c +++ b/lib/libssl/src/crypto/asn1/a_print.c @@ -69,8 +69,7 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len) if (len <= 0) len= -1; if (s == NULL) return(V_ASN1_PRINTABLESTRING); - while ((*s) && (len-- != 0)) - { + while ((*s) && (len-- != 0)) { c= *(s++); if (!( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || @@ -99,8 +98,7 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) if (s->type != V_ASN1_UNIVERSALSTRING) return(0); if ((s->length%4) != 0) return(0); p=s->data; - for (i=0; ilength; i+=4) - { + for (i=0; ilength; i+=4) { if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) break; else @@ -108,8 +106,7 @@ int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) } if (i < s->length) return(0); p=s->data; - for (i=3; ilength; i+=4) - { + for (i=3; ilength; i+=4) { *(p++)=s->data[i]; } *(p)='\0'; diff --git a/lib/libssl/src/crypto/asn1/a_sign.c b/lib/libssl/src/crypto/asn1/a_sign.c index 349422fe9ab..046f3b4a99a 100644 --- a/lib/libssl/src/crypto/asn1/a_sign.c +++ b/lib/libssl/src/crypto/asn1/a_sign.c @@ -131,8 +131,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, { EVP_MD_CTX ctx; EVP_MD_CTX_init(&ctx); - if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) - { + if (!EVP_DigestSignInit(&ctx, NULL, type, NULL, pkey)) { EVP_MD_CTX_cleanup(&ctx); return 0; } @@ -154,14 +153,12 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, type = EVP_MD_CTX_md(ctx); pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); - if (!type || !pkey) - { + if (!type || !pkey) { ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED); return 0; } - if (pkey->ameth->item_sign) - { + if (pkey->ameth->item_sign) { rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, signature); if (rv == 1) @@ -180,15 +177,12 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, else rv = 2; - if (rv == 2) - { - if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) - { + if (rv == 2) { + if (type->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) { if (!pkey->ameth || !OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type), - pkey->ameth->pkey_id)) - { + pkey->ameth->pkey_id)) { ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); return 0; @@ -212,16 +206,14 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, inl=ASN1_item_i2d(asn,&buf_in, it); outll=outl=EVP_PKEY_size(pkey); buf_out=malloc((unsigned int)outl); - if ((buf_in == NULL) || (buf_out == NULL)) - { + if ((buf_in == NULL) || (buf_out == NULL)) { outl=0; ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_MALLOC_FAILURE); goto err; } if (!EVP_DigestSignUpdate(ctx, buf_in, inl) - || !EVP_DigestSignFinal(ctx, buf_out, &outl)) - { + || !EVP_DigestSignFinal(ctx, buf_out, &outl)) { outl=0; ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); goto err; @@ -237,9 +229,11 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; err: EVP_MD_CTX_cleanup(ctx); - if (buf_in != NULL) - { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); } - if (buf_out != NULL) - { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); } + if (buf_in != NULL) { + OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); + } + if (buf_out != NULL) { + OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); + } return(outl); } diff --git a/lib/libssl/src/crypto/asn1/a_strex.c b/lib/libssl/src/crypto/asn1/a_strex.c index 65f95532a33..7dc531a2d8b 100644 --- a/lib/libssl/src/crypto/asn1/a_strex.c +++ b/lib/libssl/src/crypto/asn1/a_strex.c @@ -405,8 +405,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, if(indent < 0) indent = 0; outlen = indent; if(!do_indent(io_ch, arg, indent)) return -1; - switch (flags & XN_FLAG_SEP_MASK) - { + switch (flags & XN_FLAG_SEP_MASK) { case XN_FLAG_SEP_MULTILINE: sep_dn = "\n"; sep_dn_len = 1; @@ -526,8 +525,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) #ifndef OPENSSL_NO_FP_API int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) { - if(flags == XN_FLAG_COMPAT) - { + if(flags == XN_FLAG_COMPAT) { BIO *btmp; int ret; btmp = BIO_new_fp(fp, BIO_NOCLOSE); diff --git a/lib/libssl/src/crypto/asn1/a_strnid.c b/lib/libssl/src/crypto/asn1/a_strnid.c index 74bc7b316cc..6c59dcc8ec6 100644 --- a/lib/libssl/src/crypto/asn1/a_strnid.c +++ b/lib/libssl/src/crypto/asn1/a_strnid.c @@ -264,26 +264,24 @@ main() int i, last_nid = -1; for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) - { - if (tmp->nid < last_nid) - { - last_nid = 0; - break; - } - last_nid = tmp->nid; + i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { + if (tmp->nid < last_nid) { + last_nid = 0; + break; } + last_nid = tmp->nid; + } - if (last_nid != 0) - { + if (last_nid != 0) { printf("Table order OK\n"); exit(0); - } + } for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) - printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, - OBJ_nid2ln(tmp->nid)); + i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) { + printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, + OBJ_nid2ln(tmp->nid)); + } } diff --git a/lib/libssl/src/crypto/asn1/a_time.c b/lib/libssl/src/crypto/asn1/a_time.c index 3461660b5f9..13fd3245171 100644 --- a/lib/libssl/src/crypto/asn1/a_time.c +++ b/lib/libssl/src/crypto/asn1/a_time.c @@ -95,13 +95,11 @@ ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, struct tm data; ts=OPENSSL_gmtime(&t,&data); - if (ts == NULL) - { + if (ts == NULL) { ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); return NULL; } - if (offset_day || offset_sec) - { + if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) return NULL; } @@ -128,8 +126,7 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE if (!ASN1_TIME_check(t)) return NULL; - if (!out || !*out) - { + if (!out || !*out) { if (!(ret = ASN1_GENERALIZEDTIME_new ())) return NULL; if (out) *out = ret; @@ -137,8 +134,7 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE else ret = *out; /* If already GeneralizedTime just copy across */ - if (t->type == V_ASN1_GENERALIZEDTIME) - { + if (t->type == V_ASN1_GENERALIZEDTIME) { if(!ASN1_STRING_set(ret, t->data, t->length)) return NULL; return ret; @@ -169,8 +165,7 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) t.type = V_ASN1_UTCTIME; - if (!ASN1_TIME_check(&t)) - { + if (!ASN1_TIME_check(&t)) { t.type = V_ASN1_GENERALIZEDTIME; if (!ASN1_TIME_check(&t)) return 0; diff --git a/lib/libssl/src/crypto/asn1/a_type.c b/lib/libssl/src/crypto/asn1/a_type.c index c790d74d609..dd746e925ea 100644 --- a/lib/libssl/src/crypto/asn1/a_type.c +++ b/lib/libssl/src/crypto/asn1/a_type.c @@ -71,8 +71,7 @@ int ASN1_TYPE_get(ASN1_TYPE *a) void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) { - if (a->value.ptr != NULL) - { + if (a->value.ptr != NULL) { ASN1_TYPE **tmp_a = &a; ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); } @@ -85,21 +84,16 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) { - if (!value || (type == V_ASN1_BOOLEAN)) - { + if (!value || (type == V_ASN1_BOOLEAN)) { void *p = (void *)value; ASN1_TYPE_set(a, type, p); - } - else if (type == V_ASN1_OBJECT) - { + } else if (type == V_ASN1_OBJECT) { ASN1_OBJECT *odup; odup = OBJ_dup(value); if (!odup) return 0; ASN1_TYPE_set(a, type, odup); - } - else - { + } else { ASN1_STRING *sdup; sdup = ASN1_STRING_dup(value); if (!sdup) @@ -119,8 +113,7 @@ int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) if (!a || !b || a->type != b->type) return -1; - switch (a->type) - { + switch (a->type) { case V_ASN1_OBJECT: result = OBJ_cmp(a->value.object, b->value.object); break; diff --git a/lib/libssl/src/crypto/asn1/a_utctm.c b/lib/libssl/src/crypto/asn1/a_utctm.c index e75f2ecbb6f..d8135d04572 100644 --- a/lib/libssl/src/crypto/asn1/a_utctm.c +++ b/lib/libssl/src/crypto/asn1/a_utctm.c @@ -77,13 +77,11 @@ ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); return(NULL); } - if (!ASN1_UTCTIME_check(ret)) - { + if (!ASN1_UTCTIME_check(ret)) { ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); goto err; } @@ -110,11 +108,12 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) o=0; if (l < 11) goto err; - for (i=0; i<6; i++) - { + for (i=0; i<6; i++) { if ((i == 5) && ((a[o] == 'Z') || - (a[o] == '+') || (a[o] == '-'))) - { i++; break; } + (a[o] == '+') || (a[o] == '-'))) { + i++; + break; + } if ((a[o] < '0') || (a[o] > '9')) goto err; n= a[o]-'0'; if (++o > l) goto err; @@ -127,12 +126,10 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *d) } if (a[o] == 'Z') o++; - else if ((a[o] == '+') || (a[o] == '-')) - { + else if ((a[o] == '+') || (a[o] == '-')) { o++; if (o+4 > l) goto err; - for (i=6; i<8; i++) - { + for (i=6; i<8; i++) { if ((a[o] < '0') || (a[o] > '9')) goto err; n= a[o]-'0'; o++; @@ -154,18 +151,15 @@ int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) t.type=V_ASN1_UTCTIME; t.length=strlen(str); t.data=(unsigned char *)str; - if (ASN1_UTCTIME_check(&t)) - { - if (s != NULL) - { + if (ASN1_UTCTIME_check(&t)) { + if (s != NULL) { if (!ASN1_STRING_set((ASN1_STRING *)s, (unsigned char *)str,t.length)) return 0; s->type = V_ASN1_UTCTIME; } return(1); - } - else + } else return(0); } @@ -191,8 +185,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, if (ts == NULL) return(NULL); - if (offset_day || offset_sec) - { + if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) return NULL; } @@ -201,11 +194,9 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, return NULL; p=(char *)s->data; - if ((p == NULL) || ((size_t)s->length < len)) - { + if ((p == NULL) || ((size_t)s->length < len)) { p=malloc(len); - if (p == NULL) - { + if (p == NULL) { ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); return(NULL); } @@ -233,8 +224,7 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) if (s->data[12] == 'Z') offset=0; - else - { + else { offset = g2(s->data+13)*60+g2(s->data+15); if (s->data[12] == '-') offset = -offset; @@ -280,8 +270,7 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s) tm.tm_sec=g2(s->data+10); if(s->data[12] == 'Z') offset=0; - else - { + else { offset=g2(s->data+13)*60+g2(s->data+15); if(s->data[12] == '-') offset= -offset; diff --git a/lib/libssl/src/crypto/asn1/a_verify.c b/lib/libssl/src/crypto/asn1/a_verify.c index 59c5b876b5f..8df0b038d15 100644 --- a/lib/libssl/src/crypto/asn1/a_verify.c +++ b/lib/libssl/src/crypto/asn1/a_verify.c @@ -81,8 +81,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, int mdnid, pknid; - if (!pkey) - { + if (!pkey) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); return -1; } @@ -90,15 +89,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, EVP_MD_CTX_init(&ctx); /* Convert signature OID into digest and public key OIDs */ - if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) - { + if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); goto err; } - if (mdnid == NID_undef) - { - if (!pkey->ameth || !pkey->ameth->item_verify) - { + if (mdnid == NID_undef) { + if (!pkey->ameth || !pkey->ameth->item_verify) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM); goto err; } @@ -111,26 +107,21 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, if (ret != 2) goto err; ret = -1; - } - else - { + } else { const EVP_MD *type; type=EVP_get_digestbynid(mdnid); - if (type == NULL) - { + if (type == NULL) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); goto err; } /* Check public key OID matches public key type */ - if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) - { + if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_WRONG_PUBLIC_KEY_TYPE); goto err; } - if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) - { + if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); ret=0; goto err; @@ -140,14 +131,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, inl = ASN1_item_i2d(asn, &buf_in, it); - if (buf_in == NULL) - { + if (buf_in == NULL) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); goto err; } - if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) - { + if (!EVP_DigestVerifyUpdate(&ctx,buf_in,inl)) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); ret=0; goto err; @@ -157,8 +146,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, free(buf_in); if (EVP_DigestVerifyFinal(&ctx,signature->data, - (size_t)signature->length) <= 0) - { + (size_t)signature->length) <= 0) { ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); ret=0; goto err; diff --git a/lib/libssl/src/crypto/asn1/ameth_lib.c b/lib/libssl/src/crypto/asn1/ameth_lib.c index 8f96e00c932..bbaf6b4dfbd 100644 --- a/lib/libssl/src/crypto/asn1/ameth_lib.c +++ b/lib/libssl/src/crypto/asn1/ameth_lib.c @@ -150,8 +150,7 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) EVP_PKEY_ASN1_METHOD tmp; const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; tmp.pkey_id = type; - if (app_methods) - { + if (app_methods) { int idx; idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); if (idx >= 0) @@ -175,21 +174,18 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) { const EVP_PKEY_ASN1_METHOD *t; - for (;;) - { + for (;;) { t = pkey_asn1_find(type); if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS)) break; type = t->pkey_base_id; } - if (pe) - { + if (pe) { #ifndef OPENSSL_NO_ENGINE ENGINE *e; /* type will contain the final unaliased type */ e = ENGINE_get_pkey_asn1_meth_engine(type); - if (e) - { + if (e) { *pe = e; return ENGINE_get_pkey_asn1_meth(e, type); } @@ -206,13 +202,11 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const EVP_PKEY_ASN1_METHOD *ameth; if (len == -1) len = strlen(str); - if (pe) - { + if (pe) { #ifndef OPENSSL_NO_ENGINE ENGINE *e; ameth = ENGINE_pkey_asn1_find_str(&e, str, len); - if (ameth) - { + if (ameth) { /* Convert structural into * functional reference */ @@ -225,8 +219,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, #endif *pe = NULL; } - for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) - { + for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { ameth = EVP_PKEY_asn1_get0(i); if (ameth->pkey_flags & ASN1_PKEY_ALIAS) continue; @@ -239,8 +232,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) { - if (app_methods == NULL) - { + if (app_methods == NULL) { app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); if (!app_methods) return 0; @@ -299,8 +291,7 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, ameth->pkey_base_id = id; ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; - if (info) - { + if (info) { ameth->info = BUF_strdup(info); if (!ameth->info) goto err; @@ -308,8 +299,7 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, else ameth->info = NULL; - if (pem_str) - { + if (pem_str) { ameth->pem_str = BUF_strdup(pem_str); if (!ameth->pem_str) goto err; @@ -390,8 +380,7 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) { - if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) - { + if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) { if (ameth->pem_str) free(ameth->pem_str); if (ameth->info) diff --git a/lib/libssl/src/crypto/asn1/asn1_err.c b/lib/libssl/src/crypto/asn1/asn1_err.c index 582f6137444..c229c4b4dbc 100644 --- a/lib/libssl/src/crypto/asn1/asn1_err.c +++ b/lib/libssl/src/crypto/asn1/asn1_err.c @@ -323,8 +323,7 @@ void ERR_load_ASN1_strings(void) { #ifndef OPENSSL_NO_ERR - if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) - { + if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) { ERR_load_strings(0,ASN1_str_functs); ERR_load_strings(0,ASN1_str_reasons); } diff --git a/lib/libssl/src/crypto/asn1/asn1_gen.c b/lib/libssl/src/crypto/asn1/asn1_gen.c index f78aac71485..314df379f96 100644 --- a/lib/libssl/src/crypto/asn1/asn1_gen.c +++ b/lib/libssl/src/crypto/asn1/asn1_gen.c @@ -156,10 +156,8 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) return NULL; - if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) - { - if (!cnf) - { + if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) { + if (!cnf) { ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); return NULL; } @@ -183,8 +181,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) cpy_start = orig_der; /* Do we need IMPLICIT tagging? */ - if (asn1_tags.imp_tag != -1) - { + if (asn1_tags.imp_tag != -1) { /* If IMPLICIT we will replace the underlying tag */ /* Skip existing tag+len */ r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); @@ -196,8 +193,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) * original length and constructed flag should be * consistent. */ - if (r & 0x1) - { + if (r & 0x1) { /* Indefinite length constructed */ hdr_constructed = 2; hdr_len = 0; @@ -215,8 +211,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) /* Work out length in any EXPLICIT, starting from end */ - for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) - { + for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) { /* Content length: number of content octets + any padding */ len += etmp->exp_pad; etmp->exp_len = len; @@ -236,8 +231,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) /* Output explicit tags first */ - for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) - { + for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) { ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, etmp->exp_tag, etmp->exp_class); if (etmp->exp_pad) @@ -246,8 +240,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) /* If IMPLICIT, output tag */ - if (asn1_tags.imp_tag != -1) - { + if (asn1_tags.imp_tag != -1) { if (asn1_tags.imp_class == V_ASN1_UNIVERSAL && (asn1_tags.imp_tag == V_ASN1_SEQUENCE || asn1_tags.imp_tag == V_ASN1_SET) ) @@ -284,11 +277,9 @@ static int asn1_cb(const char *elem, int len, void *bitstr) int tmp_tag, tmp_class; - for(i = 0, p = elem; i < len; p++, i++) - { + for(i = 0, p = elem; i < len; p++, i++) { /* Look for the ':' in name value pairs */ - if (*p == ':') - { + if (*p == ':') { vstart = p + 1; vlen = len - (vstart - elem); len = p - elem; @@ -298,34 +289,29 @@ static int asn1_cb(const char *elem, int len, void *bitstr) utype = asn1_str2tag(elem, len); - if (utype == -1) - { + if (utype == -1) { ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); ERR_add_error_data(2, "tag=", elem); return -1; } /* If this is not a modifier mark end of string and exit */ - if (!(utype & ASN1_GEN_FLAG)) - { + if (!(utype & ASN1_GEN_FLAG)) { arg->utype = utype; arg->str = vstart; /* If no value and not end of string, error */ - if (!vstart && elem[len]) - { + if (!vstart && elem[len]) { ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); return -1; } return 0; } - switch(utype) - { + switch(utype) { - case ASN1_GEN_FLAG_IMP: + case ASN1_GEN_FLAG_IMP: /* Check for illegal multiple IMPLICIT tagging */ - if (arg->imp_tag != -1) - { + if (arg->imp_tag != -1) { ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); return -1; } @@ -333,7 +319,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr) return -1; break; - case ASN1_GEN_FLAG_EXP: + case ASN1_GEN_FLAG_EXP: if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class)) return -1; @@ -341,27 +327,27 @@ static int asn1_cb(const char *elem, int len, void *bitstr) return -1; break; - case ASN1_GEN_FLAG_SEQWRAP: + case ASN1_GEN_FLAG_SEQWRAP: if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1)) return -1; break; - case ASN1_GEN_FLAG_SETWRAP: + case ASN1_GEN_FLAG_SETWRAP: if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1)) return -1; break; - case ASN1_GEN_FLAG_BITWRAP: + case ASN1_GEN_FLAG_BITWRAP: if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1)) return -1; break; - case ASN1_GEN_FLAG_OCTWRAP: + case ASN1_GEN_FLAG_OCTWRAP: if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1)) return -1; break; - case ASN1_GEN_FLAG_FORMAT: + case ASN1_GEN_FLAG_FORMAT: if (!strncmp(vstart, "ASCII", 5)) arg->format = ASN1_GEN_FORMAT_ASCII; else if (!strncmp(vstart, "UTF8", 4)) @@ -370,8 +356,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr) arg->format = ASN1_GEN_FORMAT_HEX; else if (!strncmp(vstart, "BITLIST", 7)) arg->format = ASN1_GEN_FORMAT_BITLIST; - else - { + else { ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); return -1; } @@ -394,8 +379,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) /* Check we haven't gone past max length: should be impossible */ if (eptr && *eptr && (eptr > vstart + vlen)) return 0; - if (tag_num < 0) - { + if (tag_num < 0) { ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); return 0; } @@ -405,24 +389,22 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) vlen -= eptr - vstart; else vlen = 0; - if (vlen) - { - switch (*eptr) - { + if (vlen) { + switch (*eptr) { - case 'U': + case 'U': *pclass = V_ASN1_UNIVERSAL; break; - case 'A': + case 'A': *pclass = V_ASN1_APPLICATION; break; - case 'P': + case 'P': *pclass = V_ASN1_PRIVATE; break; - case 'C': + case 'C': *pclass = V_ASN1_CONTEXT_SPECIFIC; break; @@ -456,15 +438,13 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) sk = sk_ASN1_TYPE_new_null(); if (!sk) goto bad; - if (section) - { + if (section) { if (!cnf) goto bad; sect = X509V3_get_section(cnf, (char *)section); if (!sect) goto bad; - for (i = 0; i < sk_CONF_VALUE_num(sect); i++) - { + for (i = 0; i < sk_CONF_VALUE_num(sect); i++) { ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); if (!typ) goto bad; @@ -513,14 +493,12 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons { tag_exp_type *exp_tmp; /* Can only have IMPLICIT if permitted */ - if ((arg->imp_tag != -1) && !imp_ok) - { + if ((arg->imp_tag != -1) && !imp_ok) { ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); return 0; } - if (arg->exp_count == ASN1_FLAG_EXP_MAX) - { + if (arg->exp_count == ASN1_FLAG_EXP_MAX) { ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); return 0; } @@ -530,15 +508,12 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons /* If IMPLICIT set tag to implicit value then * reset implicit tag since it has been used. */ - if (arg->imp_tag != -1) - { + if (arg->imp_tag != -1) { exp_tmp->exp_tag = arg->imp_tag; exp_tmp->exp_class = arg->imp_class; arg->imp_tag = -1; arg->imp_class = -1; - } - else - { + } else { exp_tmp->exp_tag = exp_tag; exp_tmp->exp_class = exp_class; } @@ -617,8 +592,7 @@ static int asn1_str2tag(const char *tagstr, int len) len = strlen(tagstr); tntmp = tnst; - for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) - { + for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) { if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) return tntmp->tag; } @@ -637,8 +611,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) int no_unused = 1; - if (!(atmp = ASN1_TYPE_new())) - { + if (!(atmp = ASN1_TYPE_new())) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); return NULL; } @@ -646,110 +619,96 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) if (!str) str = ""; - switch(utype) - { + switch(utype) { - case V_ASN1_NULL: - if (str && *str) - { + case V_ASN1_NULL: + if (str && *str) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); goto bad_form; } break; - case V_ASN1_BOOLEAN: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_BOOLEAN: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); goto bad_form; } vtmp.name = NULL; vtmp.section = NULL; vtmp.value = (char *)str; - if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) - { + if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); goto bad_str; } break; - case V_ASN1_INTEGER: - case V_ASN1_ENUMERATED: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_INTEGER: + case V_ASN1_ENUMERATED: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) - { + if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); goto bad_str; } break; - case V_ASN1_OBJECT: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_OBJECT: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.object = OBJ_txt2obj(str, 0))) - { + if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); goto bad_str; } break; - case V_ASN1_UTCTIME: - case V_ASN1_GENERALIZEDTIME: - if (format != ASN1_GEN_FORMAT_ASCII) - { + case V_ASN1_UTCTIME: + case V_ASN1_GENERALIZEDTIME: + if (format != ASN1_GEN_FORMAT_ASCII) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); goto bad_form; } - if (!(atmp->value.asn1_string = ASN1_STRING_new())) - { + if (!(atmp->value.asn1_string = ASN1_STRING_new())) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } - if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) - { + if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } atmp->value.asn1_string->type = utype; - if (!ASN1_TIME_check(atmp->value.asn1_string)) - { + if (!ASN1_TIME_check(atmp->value.asn1_string)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); goto bad_str; } break; - case V_ASN1_BMPSTRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_IA5STRING: - case V_ASN1_T61STRING: - case V_ASN1_UTF8STRING: - case V_ASN1_VISIBLESTRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_GENERALSTRING: - case V_ASN1_NUMERICSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_PRINTABLESTRING: + case V_ASN1_IA5STRING: + case V_ASN1_T61STRING: + case V_ASN1_UTF8STRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_NUMERICSTRING: if (format == ASN1_GEN_FORMAT_ASCII) format = MBSTRING_ASC; else if (format == ASN1_GEN_FORMAT_UTF8) format = MBSTRING_UTF8; - else - { + else { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); goto bad_form; } if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, - -1, format, ASN1_tag2bit(utype)) <= 0) - { + -1, format, ASN1_tag2bit(utype)) <= 0) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_str; } @@ -757,21 +716,18 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) break; - case V_ASN1_BIT_STRING: + case V_ASN1_BIT_STRING: - case V_ASN1_OCTET_STRING: + case V_ASN1_OCTET_STRING: - if (!(atmp->value.asn1_string = ASN1_STRING_new())) - { + if (!(atmp->value.asn1_string = ASN1_STRING_new())) { ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); goto bad_form; } - if (format == ASN1_GEN_FORMAT_HEX) - { + if (format == ASN1_GEN_FORMAT_HEX) { - if (!(rdata = string_to_hex((char *)str, &rdlen))) - { + if (!(rdata = string_to_hex((char *)str, &rdlen))) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); goto bad_str; } @@ -783,24 +739,19 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) } else if (format == ASN1_GEN_FORMAT_ASCII) ASN1_STRING_set(atmp->value.asn1_string, str, -1); - else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) - { - if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) - { + else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) { + if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); goto bad_str; } no_unused = 0; - } - else - { + } else { ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); goto bad_form; } - if ((utype == V_ASN1_BIT_STRING) && no_unused) - { + if ((utype == V_ASN1_BIT_STRING) && no_unused) { atmp->value.asn1_string->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); atmp->value.asn1_string->flags @@ -810,7 +761,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) break; - default: + default: ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); goto bad_str; break; @@ -821,9 +772,9 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) return atmp; - bad_str: +bad_str: ERR_add_error_data(2, "string=", str); - bad_form: +bad_form: ASN1_TYPE_free(atmp); return NULL; @@ -839,13 +790,11 @@ static int bitstr_cb(const char *elem, int len, void *bitstr) bitnum = strtoul(elem, &eptr, 10); if (eptr && *eptr && (eptr != elem + len)) return 0; - if (bitnum < 0) - { + if (bitnum < 0) { ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); return 0; } - if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) - { + if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) { ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/lib/libssl/src/crypto/asn1/asn1_lib.c b/lib/libssl/src/crypto/asn1/asn1_lib.c index 6ec383859fc..7693556281e 100644 --- a/lib/libssl/src/crypto/asn1/asn1_lib.c +++ b/lib/libssl/src/crypto/asn1/asn1_lib.c @@ -72,8 +72,7 @@ static int _asn1_check_infinite_end(const unsigned char **p, long len) * things up */ if (len <= 0) return(1); - else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) - { + else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) { (*p)+=2; return(1); } @@ -104,13 +103,11 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMITIVE_TAG; - if (i == V_ASN1_PRIMITIVE_TAG) - { /* high-tag */ + if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */ p++; if (--max == 0) goto err; l=0; - while (*p&0x80) - { + while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; @@ -120,9 +117,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, l|= *(p++)&0x7f; tag=(int)l; if (--max == 0) goto err; - } - else - { + } else { tag=i; p++; if (--max == 0) goto err; @@ -137,8 +132,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, (int)(omax+ *pp)); #endif - if (*plength > (omax - (p - *pp))) - { + if (*plength > (omax - (p - *pp))) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); /* Set this so that even if things are not long enough * the values are set correctly */ @@ -158,23 +152,18 @@ static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max unsigned int i; if (max-- < 1) return(0); - if (*p == 0x80) - { + if (*p == 0x80) { *inf=1; ret=0; p++; - } - else - { + } else { *inf=0; i= *p&0x7f; - if (*(p++) & 0x80) - { + if (*(p++) & 0x80) { if (i > sizeof(long)) return 0; if (max-- == 0) return(0); - while (i-- > 0) - { + while (i-- > 0) { ret<<=8L; ret|= *(p++); if (max-- == 0) return(0); @@ -202,13 +191,11 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, i|=(xclass&V_ASN1_PRIVATE); if (tag < 31) *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); - else - { + else { *(p++)=i|V_ASN1_PRIMITIVE_TAG; for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; ttag = i; - while(i-- > 0) - { + while(i-- > 0) { p[i] = tag & 0x7f; if(i != (ttag - 1)) p[i] |= 0x80; tag >>= 7; @@ -237,15 +224,13 @@ static void asn1_put_length(unsigned char **pp, int length) int i,l; if (length <= 127) *(p++)=(unsigned char)length; - else - { + else { l=length; for (i=0; l > 0; i++) l>>=8; *(p++)=i|0x80; l=i; - while (i-- > 0) - { + while (i-- > 0) { p[i]=length&0xff; length>>=8; } @@ -260,10 +245,8 @@ int ASN1_object_size(int constructed, int length, int tag) ret=length; ret++; - if (tag >= 31) - { - while (tag > 0) - { + if (tag >= 31) { + while (tag > 0) { tag>>=7; ret++; } @@ -271,10 +254,8 @@ int ASN1_object_size(int constructed, int length, int tag) if (constructed == 2) return ret + 3; ret++; - if (length > 127) - { - while (length > 0) - { + if (length > 127) { + while (length > 0) { length>>=8; ret++; } @@ -284,17 +265,14 @@ int ASN1_object_size(int constructed, int length, int tag) static int _asn1_Finish(ASN1_const_CTX *c) { - if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) - { - if (!ASN1_const_check_infinite_end(&c->p,c->slen)) - { + if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) { + if (!ASN1_const_check_infinite_end(&c->p,c->slen)) { c->error=ERR_R_MISSING_ASN1_EOS; return(0); } } if ( ((c->slen != 0) && !(c->inf & 1)) || - ((c->slen < 0) && (c->inf & 1))) - { + ((c->slen < 0) && (c->inf & 1))) { c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } @@ -318,19 +296,16 @@ int asn1_GetSequence(ASN1_const_CTX *c, long *length) q=c->p; c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), *length); - if (c->inf & 0x80) - { + if (c->inf & 0x80) { c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; return(0); } - if (c->tag != V_ASN1_SEQUENCE) - { + if (c->tag != V_ASN1_SEQUENCE) { c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; return(0); } (*length)-=(c->p-q); - if (c->max && (*length < 0)) - { + if (c->max && (*length < 0)) { c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } @@ -359,8 +334,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) ret=ASN1_STRING_new(); if (!ret) return NULL; - if (!ASN1_STRING_copy(ret,str)) - { + if (!ASN1_STRING_copy(ret,str)) { ASN1_STRING_free(ret); return NULL; } @@ -372,31 +346,27 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) unsigned char *c; const char *data=_data; - if (len < 0) - { + if (len < 0) { if (data == NULL) return(0); else len=strlen(data); } - if ((str->length < len) || (str->data == NULL)) - { + if ((str->length < len) || (str->data == NULL)) { c=str->data; if (c == NULL) str->data=malloc(len+1); else str->data=realloc(c,len+1); - if (str->data == NULL) - { + if (str->data == NULL) { ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE); str->data=c; return(0); } } str->length=len; - if (data != NULL) - { + if (data != NULL) { memcpy(str->data,data,len); /* an allowance for strings :-) */ str->data[len]='\0'; @@ -423,8 +393,7 @@ ASN1_STRING *ASN1_STRING_type_new(int type) ASN1_STRING *ret; ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); return(NULL); } @@ -448,8 +417,7 @@ int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) int i; i=(a->length-b->length); - if (i == 0) - { + if (i == 0) { i=memcmp(a->data,b->data,a->length); if (i == 0) return(a->type-b->type); diff --git a/lib/libssl/src/crypto/asn1/asn1_par.c b/lib/libssl/src/crypto/asn1/asn1_par.c index d68d4a82984..d3d2f524819 100644 --- a/lib/libssl/src/crypto/asn1/asn1_par.c +++ b/lib/libssl/src/crypto/asn1/asn1_par.c @@ -129,15 +129,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse p= *pp; tot=p+length; op=p-1; - while ((p < tot) && (op < p)) - { + while ((p < tot) && (op < p)) { op=p; j=ASN1_get_object(&p,&len,&tag,&xclass,length); #ifdef LINT j=j; #endif - if (j & 0x80) - { + if (j & 0x80) { if (BIO_write(bp,"Error in encoding\n",18) <= 0) goto end; ret=0; @@ -149,35 +147,28 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp)) <= 0) goto end; - if (j != (V_ASN1_CONSTRUCTED | 1)) - { + if (j != (V_ASN1_CONSTRUCTED | 1)) { if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", depth,(long)hl,len) <= 0) goto end; - } - else - { + } else { if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", depth,(long)hl) <= 0) goto end; } if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) goto end; - if (j & V_ASN1_CONSTRUCTED) - { + if (j & V_ASN1_CONSTRUCTED) { ep=p+len; if (BIO_write(bp,"\n",1) <= 0) goto end; - if (len > length) - { + if (len > length) { BIO_printf(bp, "length is greater than %ld\n",length); ret=0; goto end; } - if ((j == 0x21) && (len == 0)) - { - for (;;) - { + if ((j == 0x21) && (len == 0)) { + for (;;) { r=asn1_parse2(bp,&p,(long)(tot-p), offset+(p - *pp),depth+1, indent,dump); @@ -186,21 +177,16 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse } } else - while (p < ep) - { + while (p < ep) { r=asn1_parse2(bp,&p,(long)len, offset+(p - *pp),depth+1, indent,dump); if (r == 0) { ret=0; goto end; } } - } - else if (xclass != 0) - { + } else if (xclass != 0) { p+=len; if (BIO_write(bp,"\n",1) <= 0) goto end; - } - else - { + } else { nl=0; if ( (tag == V_ASN1_PRINTABLESTRING) || (tag == V_ASN1_T61STRING) || @@ -209,95 +195,72 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse (tag == V_ASN1_NUMERICSTRING) || (tag == V_ASN1_UTF8STRING) || (tag == V_ASN1_UTCTIME) || - (tag == V_ASN1_GENERALIZEDTIME)) - { + (tag == V_ASN1_GENERALIZEDTIME)) { if (BIO_write(bp,":",1) <= 0) goto end; if ((len > 0) && BIO_write(bp,(const char *)p,(int)len) != (int)len) goto end; - } - else if (tag == V_ASN1_OBJECT) - { + } else if (tag == V_ASN1_OBJECT) { opp=op; - if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) - { + if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) { if (BIO_write(bp,":",1) <= 0) goto end; i2a_ASN1_OBJECT(bp,o); - } - else - { + } else { if (BIO_write(bp,":BAD OBJECT",11) <= 0) goto end; } - } - else if (tag == V_ASN1_BOOLEAN) - { + } else if (tag == V_ASN1_BOOLEAN) { int ii; opp=op; ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); - if (ii < 0) - { + if (ii < 0) { if (BIO_write(bp,"Bad boolean\n",12) <= 0) goto end; } BIO_printf(bp,":%d",ii); - } - else if (tag == V_ASN1_BMPSTRING) - { + } else if (tag == V_ASN1_BMPSTRING) { /* do the BMP thang */ - } - else if (tag == V_ASN1_OCTET_STRING) - { + } else if (tag == V_ASN1_OCTET_STRING) { int i,printable=1; opp=op; os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); - if (os != NULL && os->length > 0) - { + if (os != NULL && os->length > 0) { opp = os->data; /* testing whether the octet string is * printable */ - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (( (opp[i] < ' ') && (opp[i] != '\n') && (opp[i] != '\r') && (opp[i] != '\t')) || - (opp[i] > '~')) - { + (opp[i] > '~')) { printable=0; break; } } - if (printable) + if (printable) { /* printable string */ - { if (BIO_write(bp,":",1) <= 0) goto end; if (BIO_write(bp,(const char *)opp, os->length) <= 0) goto end; - } - else if (!dump) + } else if (!dump) { /* not printable => print octet string * as hex dump */ - { if (BIO_write(bp,"[HEX DUMP]:",11) <= 0) goto end; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02X" , opp[i]) <= 0) goto end; } - } - else + } else { /* print the normal dump */ - { - if (!nl) - { + if (!nl) { if (BIO_write(bp,"\n",1) <= 0) goto end; } @@ -310,80 +273,62 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse nl=1; } } - if (os != NULL) - { + if (os != NULL) { M_ASN1_OCTET_STRING_free(os); os=NULL; } - } - else if (tag == V_ASN1_INTEGER) - { + } else if (tag == V_ASN1_INTEGER) { ASN1_INTEGER *bs; int i; opp=op; bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); - if (bs != NULL) - { + if (bs != NULL) { if (BIO_write(bp,":",1) <= 0) goto end; if (bs->type == V_ASN1_NEG_INTEGER) if (BIO_write(bp,"-",1) <= 0) goto end; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02X", bs->data[i]) <= 0) goto end; } - if (bs->length == 0) - { + if (bs->length == 0) { if (BIO_write(bp,"00",2) <= 0) goto end; } - } - else - { + } else { if (BIO_write(bp,"BAD INTEGER",11) <= 0) goto end; } M_ASN1_INTEGER_free(bs); - } - else if (tag == V_ASN1_ENUMERATED) - { + } else if (tag == V_ASN1_ENUMERATED) { ASN1_ENUMERATED *bs; int i; opp=op; bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); - if (bs != NULL) - { + if (bs != NULL) { if (BIO_write(bp,":",1) <= 0) goto end; if (bs->type == V_ASN1_NEG_ENUMERATED) if (BIO_write(bp,"-",1) <= 0) goto end; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02X", bs->data[i]) <= 0) goto end; } - if (bs->length == 0) - { + if (bs->length == 0) { if (BIO_write(bp,"00",2) <= 0) goto end; } - } - else - { + } else { if (BIO_write(bp,"BAD ENUMERATED",14) <= 0) goto end; } M_ASN1_ENUMERATED_free(bs); - } - else if (len > 0 && dump) - { - if (!nl) - { + } else if (len > 0 && dump) { + if (!nl) { if (BIO_write(bp,"\n",1) <= 0) goto end; } @@ -394,13 +339,11 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse nl=1; } - if (!nl) - { + if (!nl) { if (BIO_write(bp,"\n",1) <= 0) goto end; } p+=len; - if ((tag == V_ASN1_EOC) && (xclass == 0)) - { + if ((tag == V_ASN1_EOC) && (xclass == 0)) { ret=2; /* End of sequence */ goto end; } @@ -429,7 +372,7 @@ const char *ASN1_tag2str(int tag) }; if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) - tag &= ~0x100; + tag &= ~0x100; if(tag < 0 || tag > 30) return "(unknown)"; return tag2str[tag]; diff --git a/lib/libssl/src/crypto/asn1/asn_mime.c b/lib/libssl/src/crypto/asn1/asn_mime.c index 011b97ff920..6cde8fd44e3 100644 --- a/lib/libssl/src/crypto/asn1/asn_mime.c +++ b/lib/libssl/src/crypto/asn1/asn_mime.c @@ -116,20 +116,17 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, const ASN1_ITEM *it) { /* If streaming create stream BIO and copy all content through it */ - if (flags & SMIME_STREAM) - { + if (flags & SMIME_STREAM) { BIO *bio, *tbio; bio = BIO_new_NDEF(out, val, it); - if (!bio) - { + if (!bio) { ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); return 0; } SMIME_crlf_copy(in, bio, flags); (void)BIO_flush(bio); /* Free up successive BIOs until we hit the old output BIO */ - do - { + do { tbio = BIO_pop(bio); BIO_free(bio); bio = tbio; @@ -151,8 +148,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, BIO *b64; int r; b64 = BIO_new(BIO_f_base64()); - if(!b64) - { + if(!b64) { ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); return 0; } @@ -205,20 +201,17 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) int i, have_unknown = 0, write_comma, ret = 0, md_nid; have_unknown = 0; write_comma = 0; - for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) - { + for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) { if (write_comma) BIO_write(out, ",", 1); write_comma = 1; md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); md = EVP_get_digestbynid(md_nid); - if (md && md->md_ctrl) - { + if (md && md->md_ctrl) { int rv; char *micstr; rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); - if (rv > 0) - { + if (rv > 0) { BIO_puts(out, micstr); free(micstr); continue; @@ -226,8 +219,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) if (rv != -2) goto err; } - switch(md_nid) - { + switch(md_nid) { case NID_sha1: BIO_puts(out, "sha1"); break; @@ -256,8 +248,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) default: if (have_unknown) write_comma = 0; - else - { + else { BIO_puts(out, "unknown"); have_unknown = 1; } @@ -338,17 +329,14 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, if (ctype_nid == NID_pkcs7_enveloped) msg_type = "enveloped-data"; - else if (ctype_nid == NID_pkcs7_signed) - { + else if (ctype_nid == NID_pkcs7_signed) { if (econt_nid == NID_id_smime_ct_receipt) msg_type = "signed-receipt"; else if (sk_X509_ALGOR_num(mdalgs) >= 0) msg_type = "signed-data"; else msg_type = "certs-only"; - } - else if (ctype_nid == NID_id_smime_ct_compressedData) - { + } else if (ctype_nid == NID_id_smime_ct_compressedData) { msg_type = "compressed-data"; cname = "smime.p7z"; } @@ -382,14 +370,12 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, /* If data is not deteched or resigning then the output BIO is * already set up to finalise when it is written through. */ - if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) - { + if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) { SMIME_crlf_copy(data, out, flags); return 1; } - if (!aux || !aux->asn1_cb) - { + if (!aux || !aux->asn1_cb) { ASN1err(ASN1_F_ASN1_OUTPUT_DATA, ASN1_R_STREAMING_NOT_SUPPORTED); return 0; @@ -413,8 +399,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, /* Now remove any digests prepended to the BIO */ - while (sarg.ndef_bio != out) - { + while (sarg.ndef_bio != out) { tmpbio = BIO_pop(sarg.ndef_bio); BIO_free(sarg.ndef_bio); sarg.ndef_bio = tmpbio; @@ -547,17 +532,13 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) if (!bf) return 0; out = BIO_push(bf, out); - if(flags & SMIME_BINARY) - { + if(flags & SMIME_BINARY) { while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) BIO_write(out, linebuf, len); - } - else - { + } else { if(flags & SMIME_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); - while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) - { + while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) { eol = strip_eol(linebuf, &len); if (len) BIO_write(out, linebuf, len); @@ -944,8 +925,7 @@ static int strip_eol(char *linebuf, int *plen) char *p, c; int is_eol = 0; p = linebuf + len - 1; - for (p = linebuf + len - 1; len > 0; len--, p--) - { + for (p = linebuf + len - 1; len > 0; len--, p--) { c = *p; if (c == '\n') is_eol = 1; diff --git a/lib/libssl/src/crypto/asn1/asn_moid.c b/lib/libssl/src/crypto/asn1/asn_moid.c index 7521496d676..0c09a8e9347 100644 --- a/lib/libssl/src/crypto/asn1/asn_moid.c +++ b/lib/libssl/src/crypto/asn1/asn_moid.c @@ -75,16 +75,13 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) STACK_OF(CONF_VALUE) *sktmp; CONF_VALUE *oval; oid_section = CONF_imodule_get_value(md); - if(!(sktmp = NCONF_get_section(cnf, oid_section))) - { + if(!(sktmp = NCONF_get_section(cnf, oid_section))) { ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); return 0; } - for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) - { + for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { oval = sk_CONF_VALUE_value(sktmp, i); - if(!do_create(oval->value, oval->name)) - { + if(!do_create(oval->value, oval->name)) { ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); return 0; } @@ -114,13 +111,10 @@ static int do_create(char *value, char *name) ASN1_OBJECT *oid; char *ln, *ostr, *p, *lntmp; p = strrchr(value, ','); - if (!p) - { + if (!p) { ln = name; ostr = value; - } - else - { + } else { ln = NULL; ostr = p + 1; if (!*ostr) @@ -133,13 +127,11 @@ static int do_create(char *value, char *name) if (nid == NID_undef) return 0; - if (p) - { + if (p) { ln = value; while(isspace((unsigned char)*ln)) ln++; p--; - while(isspace((unsigned char)*p)) - { + while(isspace((unsigned char)*p)) { if (p == ln) return 0; p--; diff --git a/lib/libssl/src/crypto/asn1/bio_asn1.c b/lib/libssl/src/crypto/asn1/bio_asn1.c index a6ad850e46e..8ebac02a00a 100644 --- a/lib/libssl/src/crypto/asn1/bio_asn1.c +++ b/lib/libssl/src/crypto/asn1/bio_asn1.c @@ -210,20 +210,18 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) wrlen = 0; ret = -1; - for(;;) - { - switch (ctx->state) - { + for(;;) { + switch (ctx->state) { /* Setup prefix data, call it */ - case ASN1_STATE_START: + case ASN1_STATE_START: if (!asn1_bio_setup_ex(b, ctx, ctx->prefix, ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER)) return 0; break; /* Copy any pre data first */ - case ASN1_STATE_PRE_COPY: + case ASN1_STATE_PRE_COPY: ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free, ASN1_STATE_HEADER); @@ -233,7 +231,7 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) break; - case ASN1_STATE_HEADER: + case ASN1_STATE_HEADER: ctx->buflen = ASN1_object_size(0, inl, ctx->asn1_tag) - inl; OPENSSL_assert(ctx->buflen <= ctx->bufsize); @@ -245,7 +243,7 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) break; - case ASN1_STATE_HEADER_COPY: + case ASN1_STATE_HEADER_COPY: ret = BIO_write(b->next_bio, ctx->buf + ctx->bufpos, ctx->buflen); if (ret <= 0) @@ -254,15 +252,14 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) ctx->buflen -= ret; if (ctx->buflen) ctx->bufpos += ret; - else - { + else { ctx->bufpos = 0; ctx->state = ASN1_STATE_DATA_COPY; } break; - case ASN1_STATE_DATA_COPY: + case ASN1_STATE_DATA_COPY: if (inl > ctx->copylen) wrmax = ctx->copylen; @@ -306,8 +303,7 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, int ret; if (ctx->ex_len <= 0) return 1; - for(;;) - { + for(;;) { ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, ctx->ex_len); if (ret <= 0) @@ -315,8 +311,7 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, ctx->ex_len -= ret; if (ctx->ex_len > 0) ctx->ex_pos += ret; - else - { + else { if(cleanup) cleanup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg); @@ -333,8 +328,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, asn1_bio_state_t ex_state, asn1_bio_state_t other_state) { - if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) - { + if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) { BIO_clear_retry_flags(b); return 0; } @@ -378,55 +372,52 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) ctx = (BIO_ASN1_BUF_CTX *) b->ptr; if (ctx == NULL) return 0; - switch(cmd) - { + switch(cmd) { - case BIO_C_SET_PREFIX: + case BIO_C_SET_PREFIX: ex_func = arg2; ctx->prefix = ex_func->ex_func; ctx->prefix_free = ex_func->ex_free_func; break; - case BIO_C_GET_PREFIX: + case BIO_C_GET_PREFIX: ex_func = arg2; ex_func->ex_func = ctx->prefix; ex_func->ex_free_func = ctx->prefix_free; break; - case BIO_C_SET_SUFFIX: + case BIO_C_SET_SUFFIX: ex_func = arg2; ctx->suffix = ex_func->ex_func; ctx->suffix_free = ex_func->ex_free_func; break; - case BIO_C_GET_SUFFIX: + case BIO_C_GET_SUFFIX: ex_func = arg2; ex_func->ex_func = ctx->suffix; ex_func->ex_free_func = ctx->suffix_free; break; - case BIO_C_SET_EX_ARG: + case BIO_C_SET_EX_ARG: ctx->ex_arg = arg2; break; - case BIO_C_GET_EX_ARG: + case BIO_C_GET_EX_ARG: *(void **)arg2 = ctx->ex_arg; break; - case BIO_CTRL_FLUSH: + case BIO_CTRL_FLUSH: if (!b->next_bio) return 0; /* Call post function if possible */ - if (ctx->state == ASN1_STATE_HEADER) - { + if (ctx->state == ASN1_STATE_HEADER) { if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) return 0; } - if (ctx->state == ASN1_STATE_POST_COPY) - { + if (ctx->state == ASN1_STATE_POST_COPY) { ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, ASN1_STATE_DONE); if (ret <= 0) @@ -435,15 +426,14 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) if (ctx->state == ASN1_STATE_DONE) return BIO_ctrl(b->next_bio, cmd, arg1, arg2); - else - { + else { BIO_clear_retry_flags(b); return 0; } break; - default: + default: if (!b->next_bio) return 0; return BIO_ctrl(b->next_bio, cmd, arg1, arg2); @@ -468,8 +458,7 @@ static int asn1_bio_get_ex(BIO *b, int cmd, BIO_ASN1_EX_FUNCS extmp; int ret; ret = BIO_ctrl(b, cmd, 0, &extmp); - if (ret > 0) - { + if (ret > 0) { *ex_func = extmp.ex_func; *ex_free_func = extmp.ex_free_func; } diff --git a/lib/libssl/src/crypto/asn1/bio_ndef.c b/lib/libssl/src/crypto/asn1/bio_ndef.c index b8dc80a7b23..595e6471c29 100644 --- a/lib/libssl/src/crypto/asn1/bio_ndef.c +++ b/lib/libssl/src/crypto/asn1/bio_ndef.c @@ -105,8 +105,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) const ASN1_AUX *aux = it->funcs; ASN1_STREAM_ARG sarg; - if (!aux || !aux->asn1_cb) - { + if (!aux || !aux->asn1_cb) { ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); return NULL; } diff --git a/lib/libssl/src/crypto/asn1/d2i_pr.c b/lib/libssl/src/crypto/asn1/d2i_pr.c index cbbcdae7df5..5e6003ca5b1 100644 --- a/lib/libssl/src/crypto/asn1/d2i_pr.c +++ b/lib/libssl/src/crypto/asn1/d2i_pr.c @@ -73,37 +73,29 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, { EVP_PKEY *ret; - if ((a == NULL) || (*a == NULL)) - { - if ((ret=EVP_PKEY_new()) == NULL) - { + if ((a == NULL) || (*a == NULL)) { + if ((ret=EVP_PKEY_new()) == NULL) { ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); return(NULL); } - } - else - { + } else { ret= *a; #ifndef OPENSSL_NO_ENGINE - if (ret->engine) - { + if (ret->engine) { ENGINE_finish(ret->engine); ret->engine = NULL; } #endif } - if (!EVP_PKEY_set_type(ret, type)) - { + if (!EVP_PKEY_set_type(ret, type)) { ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; } if (!ret->ameth->old_priv_decode || - !ret->ameth->old_priv_decode(ret, pp, length)) - { - if (ret->ameth->priv_decode) - { + !ret->ameth->old_priv_decode(ret, pp, length)) { + if (ret->ameth->priv_decode) { PKCS8_PRIV_KEY_INFO *p8=NULL; p8=d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); if (!p8) goto err; @@ -111,9 +103,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, ret = EVP_PKCS82PKEY(p8); PKCS8_PRIV_KEY_INFO_free(p8); - } - else - { + } else { ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); goto err; } @@ -146,25 +136,24 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, keytype = EVP_PKEY_DSA; else if (sk_ASN1_TYPE_num(inkey) == 4) keytype = EVP_PKEY_EC; - else if (sk_ASN1_TYPE_num(inkey) == 3) - { /* This seems to be PKCS8, not traditional format */ - PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); - EVP_PKEY *ret; + else if (sk_ASN1_TYPE_num(inkey) == 3) { + /* This seems to be PKCS8, not traditional format */ + PKCS8_PRIV_KEY_INFO *p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL,pp,length); + EVP_PKEY *ret; - sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); - if (!p8) - { - ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); - return NULL; - } - ret = EVP_PKCS82PKEY(p8); - PKCS8_PRIV_KEY_INFO_free(p8); - if (a) { - *a = ret; + sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); + if (!p8) { + ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); + return NULL; + } + ret = EVP_PKCS82PKEY(p8); + PKCS8_PRIV_KEY_INFO_free(p8); + if (a) { + *a = ret; } - return ret; - } - else keytype = EVP_PKEY_RSA; + return ret; + } else + keytype = EVP_PKEY_RSA; sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); return d2i_PrivateKey(keytype, a, pp, length); } diff --git a/lib/libssl/src/crypto/asn1/d2i_pu.c b/lib/libssl/src/crypto/asn1/d2i_pu.c index f04d230d706..ccd03c066f3 100644 --- a/lib/libssl/src/crypto/asn1/d2i_pu.c +++ b/lib/libssl/src/crypto/asn1/d2i_pu.c @@ -77,24 +77,20 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, { EVP_PKEY *ret; - if ((a == NULL) || (*a == NULL)) - { - if ((ret=EVP_PKEY_new()) == NULL) - { + if ((a == NULL) || (*a == NULL)) { + if ((ret=EVP_PKEY_new()) == NULL) { ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); return(NULL); } } else ret= *a; - if (!EVP_PKEY_set_type(ret, type)) - { + if (!EVP_PKEY_set_type(ret, type)) { ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); goto err; } - switch (EVP_PKEY_id(ret)) - { + switch (EVP_PKEY_id(ret)) { #ifndef OPENSSL_NO_RSA case EVP_PKEY_RSA: if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, diff --git a/lib/libssl/src/crypto/asn1/evp_asn1.c b/lib/libssl/src/crypto/asn1/evp_asn1.c index 631924f88e8..d4ea675f89b 100644 --- a/lib/libssl/src/crypto/asn1/evp_asn1.c +++ b/lib/libssl/src/crypto/asn1/evp_asn1.c @@ -78,8 +78,7 @@ int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int ret,num; unsigned char *p; - if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) - { + if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); return(-1); } @@ -115,8 +114,7 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, if ((osp=ASN1_STRING_new()) == NULL) return(0); /* Grow the 'string' */ - if (!ASN1_STRING_set(osp,NULL,size)) - { + if (!ASN1_STRING_set(osp,NULL,size)) { ASN1_STRING_free(osp); return(0); } @@ -145,8 +143,7 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, long length; ASN1_const_CTX c; - if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) - { + if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { goto err; } p=M_ASN1_STRING_data(a->value.sequence); @@ -177,8 +174,7 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, if (data != NULL) memcpy(data,M_ASN1_STRING_data(os),n); - if (0) - { + if (0) { err: ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); } diff --git a/lib/libssl/src/crypto/asn1/f_enum.c b/lib/libssl/src/crypto/asn1/f_enum.c index b6e66ab194c..4ccfbddf2a9 100644 --- a/lib/libssl/src/crypto/asn1/f_enum.c +++ b/lib/libssl/src/crypto/asn1/f_enum.c @@ -71,17 +71,12 @@ int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) if (a == NULL) return(0); - if (a->length == 0) - { + if (a->length == 0) { if (BIO_write(bp,"00",2) != 2) goto err; n=2; - } - else - { - for (i=0; ilength; i++) - { - if ((i != 0) && (i%35 == 0)) - { + } else { + for (i=0; ilength; i++) { + if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } @@ -107,8 +102,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) bs->type=V_ASN1_ENUMERATED; bufsize=BIO_gets(bp,buf,size); - for (;;) - { + for (;;) { if (bufsize < 1) goto err_sl; i=bufsize; if (buf[i-1] == '\n') buf[--i]='\0'; @@ -117,12 +111,10 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) if (i == 0) goto err_sl; again=(buf[i-1] == '\\'); - for (j=0; j= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || - ((buf[j] >= 'A') && (buf[j] <= 'F')))) - { + ((buf[j] >= 'A') && (buf[j] <= 'F')))) { i=j; break; } @@ -133,33 +125,28 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) if (i < 2) goto err_sl; bufp=(unsigned char *)buf; - if (first) - { + if (first) { first=0; - if ((bufp[0] == '0') && (buf[1] == '0')) - { + if ((bufp[0] == '0') && (buf[1] == '0')) { bufp+=2; i-=2; } } k=0; i-=again; - if (i%2 != 0) - { + if (i%2 != 0) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); goto err; } i/=2; - if (num+i > slen) - { + if (num+i > slen) { if (s == NULL) sp=(unsigned char *)malloc( (unsigned int)num+i*2); else sp=(unsigned char *)realloc(s, (unsigned int)num+i*2); - if (sp == NULL) - { + if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); if (s != NULL) free(s); goto err; @@ -167,10 +154,8 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) s=sp; slen=num+i*2; } - for (j=0; j= '0') && (m <= '9')) m-='0'; @@ -178,8 +163,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) m=m-'a'+10; else if ((m >= 'A') && (m <= 'F')) m=m-'A'+10; - else - { + else { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); goto err; } @@ -197,8 +181,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) bs->data=s; ret=1; err: - if (0) - { + if (0) { err_sl: ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); } diff --git a/lib/libssl/src/crypto/asn1/f_int.c b/lib/libssl/src/crypto/asn1/f_int.c index 66632f2dc44..6cea1f8485a 100644 --- a/lib/libssl/src/crypto/asn1/f_int.c +++ b/lib/libssl/src/crypto/asn1/f_int.c @@ -69,23 +69,17 @@ int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) if (a == NULL) return(0); - if (a->type & V_ASN1_NEG) - { + if (a->type & V_ASN1_NEG) { if (BIO_write(bp, "-", 1) != 1) goto err; n = 1; } - if (a->length == 0) - { + if (a->length == 0) { if (BIO_write(bp,"00",2) != 2) goto err; n += 2; - } - else - { - for (i=0; ilength; i++) - { - if ((i != 0) && (i%35 == 0)) - { + } else { + for (i=0; ilength; i++) { + if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } @@ -111,8 +105,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) bs->type=V_ASN1_INTEGER; bufsize=BIO_gets(bp,buf,size); - for (;;) - { + for (;;) { if (bufsize < 1) goto err_sl; i=bufsize; if (buf[i-1] == '\n') buf[--i]='\0'; @@ -121,12 +114,10 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) if (i == 0) goto err_sl; again=(buf[i-1] == '\\'); - for (j=0; j= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || - ((buf[j] >= 'A') && (buf[j] <= 'F')))) - { + ((buf[j] >= 'A') && (buf[j] <= 'F')))) { i=j; break; } @@ -137,32 +128,27 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) if (i < 2) goto err_sl; bufp=(unsigned char *)buf; - if (first) - { + if (first) { first=0; - if ((bufp[0] == '0') && (buf[1] == '0')) - { + if ((bufp[0] == '0') && (buf[1] == '0')) { bufp+=2; i-=2; } } k=0; i-=again; - if (i%2 != 0) - { + if (i%2 != 0) { ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); goto err; } i/=2; - if (num+i > slen) - { + if (num+i > slen) { if (s == NULL) sp=(unsigned char *)malloc( (unsigned int)num+i*2); else sp=OPENSSL_realloc_clean(s,slen,num+i*2); - if (sp == NULL) - { + if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); if (s != NULL) free(s); goto err; @@ -170,10 +156,8 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) s=sp; slen=num+i*2; } - for (j=0; j= '0') && (m <= '9')) m-='0'; @@ -181,8 +165,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) m=m-'a'+10; else if ((m >= 'A') && (m <= 'F')) m=m-'A'+10; - else - { + else { ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); goto err; } @@ -200,8 +183,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) bs->data=s; ret=1; err: - if (0) - { + if (0) { err_sl: ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); } diff --git a/lib/libssl/src/crypto/asn1/f_string.c b/lib/libssl/src/crypto/asn1/f_string.c index 7a59fa9f4f4..87d7aaa0dde 100644 --- a/lib/libssl/src/crypto/asn1/f_string.c +++ b/lib/libssl/src/crypto/asn1/f_string.c @@ -69,17 +69,12 @@ int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) if (a == NULL) return(0); - if (a->length == 0) - { + if (a->length == 0) { if (BIO_write(bp,"0",1) != 1) goto err; n=1; - } - else - { - for (i=0; ilength; i++) - { - if ((i != 0) && (i%35 == 0)) - { + } else { + for (i=0; ilength; i++) { + if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } @@ -103,10 +98,8 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) int num=0,slen=0,first=1; bufsize=BIO_gets(bp,buf,size); - for (;;) - { - if (bufsize < 1) - { + for (;;) { + if (bufsize < 1) { if (first) break; else @@ -121,12 +114,10 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) if (i == 0) goto err_sl; again=(buf[i-1] == '\\'); - for (j=i-1; j>0; j--) - { + for (j=i-1; j>0; j--) { if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || - ((buf[j] >= 'A') && (buf[j] <= 'F')))) - { + ((buf[j] >= 'A') && (buf[j] <= 'F')))) { i=j; break; } @@ -140,22 +131,19 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) k=0; i-=again; - if (i%2 != 0) - { + if (i%2 != 0) { ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); goto err; } i/=2; - if (num+i > slen) - { + if (num+i > slen) { if (s == NULL) sp=(unsigned char *)malloc( (unsigned int)num+i*2); else sp=(unsigned char *)realloc(s, (unsigned int)num+i*2); - if (sp == NULL) - { + if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); if (s != NULL) free(s); goto err; @@ -163,10 +151,8 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) s=sp; slen=num+i*2; } - for (j=0; j= '0') && (m <= '9')) m-='0'; @@ -174,8 +160,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) m=m-'a'+10; else if ((m >= 'A') && (m <= 'F')) m=m-'A'+10; - else - { + else { ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); goto err; } @@ -193,8 +178,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) bs->data=s; ret=1; err: - if (0) - { + if (0) { err_sl: ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); } diff --git a/lib/libssl/src/crypto/asn1/i2d_pr.c b/lib/libssl/src/crypto/asn1/i2d_pr.c index 9332c4d2ec5..71757486011 100644 --- a/lib/libssl/src/crypto/asn1/i2d_pr.c +++ b/lib/libssl/src/crypto/asn1/i2d_pr.c @@ -64,8 +64,7 @@ int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) { - if (a->ameth && a->ameth->old_priv_encode) - { + if (a->ameth && a->ameth->old_priv_encode) { return a->ameth->old_priv_encode(a, pp); } if (a->ameth && a->ameth->priv_encode) { diff --git a/lib/libssl/src/crypto/asn1/i2d_pu.c b/lib/libssl/src/crypto/asn1/i2d_pu.c index ed8ec0753b5..08b438115df 100644 --- a/lib/libssl/src/crypto/asn1/i2d_pu.c +++ b/lib/libssl/src/crypto/asn1/i2d_pu.c @@ -73,8 +73,7 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) { - switch (a->type) - { + switch (a->type) { #ifndef OPENSSL_NO_RSA case EVP_PKEY_RSA: return(i2d_RSAPublicKey(a->pkey.rsa,pp)); diff --git a/lib/libssl/src/crypto/asn1/n_pkey.c b/lib/libssl/src/crypto/asn1/n_pkey.c index a59640582e4..0a378759f9d 100644 --- a/lib/libssl/src/crypto/asn1/n_pkey.c +++ b/lib/libssl/src/crypto/asn1/n_pkey.c @@ -159,8 +159,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; enckey->enckey->algor->parameter->type=V_ASN1_NULL; - if (pp == NULL) - { + if (pp == NULL) { olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); NETSCAPE_PKEY_free(pkey); NETSCAPE_ENCRYPTED_PKEY_free(enckey); @@ -169,8 +168,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, /* Since its RC4 encrypted length is actual length */ - if ((zz=(unsigned char *)malloc(rsalen)) == NULL) - { + if ((zz=(unsigned char *)malloc(rsalen)) == NULL) { ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); goto err; } @@ -179,14 +177,12 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, /* Write out private key encoding */ i2d_RSAPrivateKey(a,&zz); - if ((zz=malloc(pkeylen)) == NULL) - { + if ((zz=malloc(pkeylen)) == NULL) { ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); goto err; } - if (!ASN1_STRING_set(enckey->os, "private-key", -1)) - { + if (!ASN1_STRING_set(enckey->os, "private-key", -1)) { ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); goto err; } @@ -199,8 +195,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, if (cb == NULL) cb=EVP_read_pw_string; i=cb((char *)buf,256,"Enter Private Key password:",1); - if (i != 0) - { + if (i != 0) { ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); goto err; } @@ -259,14 +254,12 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, } if ((enckey->os->length != 11) || (strncmp("private-key", - (char *)enckey->os->data,11) != 0)) - { + (char *)enckey->os->data,11) != 0)) { ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); NETSCAPE_ENCRYPTED_PKEY_free(enckey); return NULL; } - if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) - { + if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) { ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); goto err; } @@ -296,8 +289,7 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, EVP_CIPHER_CTX_init(&ctx); i=cb((char *)buf,256,"Enter Private Key password:",0); - if (i != 0) - { + if (i != 0) { ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); goto err; } @@ -324,15 +316,13 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, zz=os->data; - if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) - { + if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) { ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); goto err; } zz=pkey->private_key->data; - if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) - { + if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) { ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); goto err; } diff --git a/lib/libssl/src/crypto/asn1/p5_pbe.c b/lib/libssl/src/crypto/asn1/p5_pbe.c index f0f23c668d9..390305ad38f 100644 --- a/lib/libssl/src/crypto/asn1/p5_pbe.c +++ b/lib/libssl/src/crypto/asn1/p5_pbe.c @@ -82,22 +82,19 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, unsigned char *sstr; pbe = PBEPARAM_new(); - if (!pbe) - { + if (!pbe) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } if(iter <= 0) iter = PKCS5_DEFAULT_ITER; - if (!ASN1_INTEGER_set(pbe->iter, iter)) - { + if (!ASN1_INTEGER_set(pbe->iter, iter)) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } if (!saltlen) saltlen = PKCS5_SALT_LEN; - if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) - { + if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } @@ -107,8 +104,7 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, else if (RAND_pseudo_bytes(sstr, saltlen) < 0) goto err; - if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) - { + if(!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR,ERR_R_MALLOC_FAILURE); goto err; } @@ -134,8 +130,7 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, { X509_ALGOR *ret; ret = X509_ALGOR_new(); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/lib/libssl/src/crypto/asn1/p5_pbev2.c b/lib/libssl/src/crypto/asn1/p5_pbev2.c index 2d80334e011..01563a68fdb 100644 --- a/lib/libssl/src/crypto/asn1/p5_pbev2.c +++ b/lib/libssl/src/crypto/asn1/p5_pbev2.c @@ -114,13 +114,12 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, if(!(scheme->parameter = ASN1_TYPE_new())) goto merr; /* Create random IV */ - if (EVP_CIPHER_iv_length(cipher)) - { + if (EVP_CIPHER_iv_length(cipher)) { if (aiv) memcpy(iv, aiv, EVP_CIPHER_iv_length(cipher)); else if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0) goto err; - } + } EVP_CIPHER_CTX_init(&ctx); @@ -137,11 +136,10 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, * An error is OK here: just means use default PRF. */ if ((prf_nid == -1) && - EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) - { + EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_PBE_PRF_NID, 0, &prf_nid) <= 0) { ERR_clear_error(); prf_nid = NID_hmacWithSHA1; - } + } EVP_CIPHER_CTX_cleanup(&ctx); /* If its RC2 then we'd better setup the key length */ @@ -178,7 +176,7 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, return ret; - merr: +merr: ASN1err(ASN1_F_PKCS5_PBE2_SET_IV,ERR_R_MALLOC_FAILURE); err: @@ -193,13 +191,13 @@ X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, unsigned char *salt, int saltlen) - { +{ return PKCS5_pbe2_set_iv(cipher, iter, salt, saltlen, NULL, -1); - } +} X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid, int keylen) - { +{ X509_ALGOR *keyfunc = NULL; PBKDF2PARAM *kdf = NULL; ASN1_OCTET_STRING *osalt = NULL; @@ -232,8 +230,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* If have a key len set it up */ - if(keylen > 0) - { + if(keylen > 0) { if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr; if(!ASN1_INTEGER_set (kdf->keylength, keylen)) @@ -241,14 +238,13 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, } /* prf can stay NULL if we are using hmacWithSHA1 */ - if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) - { + if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) { kdf->prf = X509_ALGOR_new(); if (!kdf->prf) goto merr; X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid), V_ASN1_NULL, NULL); - } + } /* Finally setup the keyfunc structure */ @@ -271,10 +267,10 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, PBKDF2PARAM_free(kdf); return keyfunc; - merr: +merr: ASN1err(ASN1_F_PKCS5_PBKDF2_SET,ERR_R_MALLOC_FAILURE); PBKDF2PARAM_free(kdf); X509_ALGOR_free(keyfunc); return NULL; - } +} diff --git a/lib/libssl/src/crypto/asn1/p8_pkey.c b/lib/libssl/src/crypto/asn1/p8_pkey.c index 9d26cf51ecb..c95d7e55a07 100644 --- a/lib/libssl/src/crypto/asn1/p8_pkey.c +++ b/lib/libssl/src/crypto/asn1/p8_pkey.c @@ -90,13 +90,11 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, unsigned char *penc, int penclen) { unsigned char **ppenc = NULL; - if (version >= 0) - { + if (version >= 0) { if (!ASN1_INTEGER_set(priv->version, version)) return 0; } - if (penc) - { + if (penc) { int pmtype; ASN1_OCTET_STRING *oct; oct = ASN1_OCTET_STRING_new(); @@ -111,8 +109,7 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, pmtype = V_ASN1_OCTET_STRING; ASN1_TYPE_set(priv->pkey, pmtype, oct); } - if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) - { + if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) { /* If call fails do not swallow 'enc' */ if (ppenc) *ppenc = NULL; @@ -128,20 +125,15 @@ int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, { if (ppkalg) *ppkalg = p8->pkeyalg->algorithm; - if(p8->pkey->type == V_ASN1_OCTET_STRING) - { + if(p8->pkey->type == V_ASN1_OCTET_STRING) { p8->broken = PKCS8_OK; - if (pk) - { + if (pk) { *pk = p8->pkey->value.octet_string->data; *ppklen = p8->pkey->value.octet_string->length; } - } - else if (p8->pkey->type == V_ASN1_SEQUENCE) - { + } else if (p8->pkey->type == V_ASN1_SEQUENCE) { p8->broken = PKCS8_NO_OCTET; - if (pk) - { + if (pk) { *pk = p8->pkey->value.sequence->data; *ppklen = p8->pkey->value.sequence->length; } diff --git a/lib/libssl/src/crypto/asn1/t_crl.c b/lib/libssl/src/crypto/asn1/t_crl.c index 1624cc5fcc0..c665a26bce4 100644 --- a/lib/libssl/src/crypto/asn1/t_crl.c +++ b/lib/libssl/src/crypto/asn1/t_crl.c @@ -70,8 +70,7 @@ int X509_CRL_print_fp(FILE *fp, X509_CRL *x) BIO *b; int ret; - if ((b=BIO_new(BIO_s_file())) == NULL) - { + if ((b=BIO_new(BIO_s_file())) == NULL) { X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); return(0); } diff --git a/lib/libssl/src/crypto/asn1/t_pkey.c b/lib/libssl/src/crypto/asn1/t_pkey.c index 61f5cd61f18..12674e0125c 100644 --- a/lib/libssl/src/crypto/asn1/t_pkey.c +++ b/lib/libssl/src/crypto/asn1/t_pkey.c @@ -72,21 +72,17 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, neg = (BN_is_negative(num))?"-":""; if(!BIO_indent(bp,off,128)) return 0; - if (BN_is_zero(num)) - { + if (BN_is_zero(num)) { if (BIO_printf(bp, "%s 0\n", number) <= 0) return 0; return 1; } - if (BN_num_bytes(num) <= BN_BYTES) - { + if (BN_num_bytes(num) <= BN_BYTES) { if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) <= 0) return(0); - } - else - { + } else { buf[0]=0; if (BIO_printf(bp,"%s%s",number, (neg[0] == '-')?" (Negative)":"") <= 0) @@ -97,10 +93,8 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, n++; else buf++; - for (i=0; ireq_info; - if(!(cflag & X509_FLAG_NO_HEADER)) - { + if(!(cflag & X509_FLAG_NO_HEADER)) { if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; if (BIO_write(bp," Data:\n",10) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_VERSION)) - { + if(!(cflag & X509_FLAG_NO_VERSION)) { neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; l=0; - for (i=0; iversion->length; i++) - { l<<=8; l+=ri->version->data[i]; } + for (i=0; iversion->length; i++) { + l<<=8; l+=ri->version->data[i]; + } if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, l) <= 0) goto err; @@ -131,8 +129,7 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_PUBKEY)) - { + if(!(cflag & X509_FLAG_NO_PUBKEY)) { if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) goto err; if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) @@ -143,34 +140,26 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long goto err; pkey=X509_REQ_get_pubkey(x); - if (pkey == NULL) - { + if (pkey == NULL) { BIO_printf(bp,"%12sUnable to load Public Key\n",""); ERR_print_errors(bp); - } - else - { + } else { EVP_PKEY_print_public(bp, pkey, 16, NULL); EVP_PKEY_free(pkey); } } - if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) - { + if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) { /* may not be */ if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) goto err; sk=x->req_info->attributes; - if (sk_X509_ATTRIBUTE_num(sk) == 0) - { + if (sk_X509_ATTRIBUTE_num(sk) == 0) { if(BIO_printf(bp,"%12sa0:00\n","") <= 0) goto err; - } - else - { - for (i=0; iobject)) > 0) - { - if (a->single) - { + if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) { + if (a->single) { t=a->value.single; type=t->type; bs=t->value.bit_string; - } - else - { + } else { ii=0; count=sk_ASN1_TYPE_num(a->value.set); get_next: @@ -205,29 +190,23 @@ get_next: if (BIO_puts(bp,":") <= 0) goto err; if ( (type == V_ASN1_PRINTABLESTRING) || (type == V_ASN1_T61STRING) || - (type == V_ASN1_IA5STRING)) - { + (type == V_ASN1_IA5STRING)) { if (BIO_write(bp,(char *)bs->data,bs->length) != bs->length) goto err; BIO_puts(bp,"\n"); - } - else - { + } else { BIO_puts(bp,"unable to print attribute\n"); } if (++ii < count) goto get_next; } } } - if(!(cflag & X509_FLAG_NO_EXTENSIONS)) - { + if(!(cflag & X509_FLAG_NO_EXTENSIONS)) { exts = X509_REQ_get_extensions(x); - if(exts) - { + if(exts) { BIO_printf(bp,"%8sRequested Extensions:\n",""); - for (i=0; ivalue); } @@ -249,8 +227,7 @@ get_next: } } - if(!(cflag & X509_FLAG_NO_SIGDUMP)) - { + if(!(cflag & X509_FLAG_NO_SIGDUMP)) { if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; } diff --git a/lib/libssl/src/crypto/asn1/t_spki.c b/lib/libssl/src/crypto/asn1/t_spki.c index 016eb2fc2e3..f135754535e 100644 --- a/lib/libssl/src/crypto/asn1/t_spki.c +++ b/lib/libssl/src/crypto/asn1/t_spki.c @@ -81,9 +81,9 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) BIO_printf(out," Public Key Algorithm: %s\n", (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); pkey = X509_PUBKEY_get(spki->spkac->pubkey); - if(!pkey) BIO_printf(out, " Unable to load public key\n"); - else - { + if(!pkey) + BIO_printf(out, " Unable to load public key\n"); + else { EVP_PKEY_print_public(out, pkey, 4, NULL); EVP_PKEY_free(pkey); } @@ -96,9 +96,9 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) n=spki->signature->length; s=(char *)spki->signature->data; - for (i=0; icert_info; - if(!(cflag & X509_FLAG_NO_HEADER)) - { + if(!(cflag & X509_FLAG_NO_HEADER)) { if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; if (BIO_write(bp," Data:\n",10) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_VERSION)) - { + if(!(cflag & X509_FLAG_NO_VERSION)) { l=X509_get_version(x); if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_SERIAL)) - { + if(!(cflag & X509_FLAG_NO_SERIAL)) { if (BIO_write(bp," Serial Number:",22) <= 0) goto err; bs=X509_get_serialNumber(x); - if (bs->length <= (int)sizeof(long)) - { + if (bs->length <= (int)sizeof(long)) { l=ASN1_INTEGER_get(bs); - if (bs->type == V_ASN1_NEG_INTEGER) - { + if (bs->type == V_ASN1_NEG_INTEGER) { l= -l; neg="-"; - } - else + } else neg=""; if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) goto err; - } - else - { + } else { neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if (BIO_printf(bp,"%02x%c",bs->data[i], ((i+1 == bs->length)?'\n':':')) <= 0) goto err; @@ -166,8 +156,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) } - if(!(cflag & X509_FLAG_NO_SIGNAME)) - { + if(!(cflag & X509_FLAG_NO_SIGNAME)) { if(X509_signature_print(bp, x->sig_alg, NULL) <= 0) goto err; #if 0 @@ -180,14 +169,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) #endif } - if(!(cflag & X509_FLAG_NO_ISSUER)) - { + if(!(cflag & X509_FLAG_NO_ISSUER)) { if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_VALIDITY)) - { + if(!(cflag & X509_FLAG_NO_VALIDITY)) { if (BIO_write(bp," Validity\n",17) <= 0) goto err; if (BIO_write(bp," Not Before: ",24) <= 0) goto err; if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; @@ -195,14 +182,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_SUBJECT)) - { + if(!(cflag & X509_FLAG_NO_SUBJECT)) { if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; if (BIO_write(bp,"\n",1) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_PUBKEY)) - { + if(!(cflag & X509_FLAG_NO_PUBKEY)) { if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) goto err; if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) @@ -213,13 +198,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) goto err; pkey=X509_get_pubkey(x); - if (pkey == NULL) - { + if (pkey == NULL) { BIO_printf(bp,"%12sUnable to load Public Key\n",""); ERR_print_errors(bp); - } - else - { + } else { EVP_PKEY_print_public(bp, pkey, 16, NULL); EVP_PKEY_free(pkey); } @@ -229,12 +211,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) X509V3_extensions_print(bp, "X509v3 extensions", ci->extensions, cflag, 8); - if(!(cflag & X509_FLAG_NO_SIGDUMP)) - { + if(!(cflag & X509_FLAG_NO_SIGDUMP)) { if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; } - if(!(cflag & X509_FLAG_NO_AUX)) - { + if(!(cflag & X509_FLAG_NO_AUX)) { if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; } ret=1; @@ -262,8 +242,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) goto err; - for (i=0; i < SHA_DIGEST_LENGTH; i++) - { + for (i=0; i < SHA_DIGEST_LENGTH; i++) { if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; } free (der); @@ -278,8 +257,7 @@ int X509_ocspid_print (BIO *bp, X509 *x) x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL)) goto err; - for (i=0; i < SHA_DIGEST_LENGTH; i++) - { + for (i=0; i < SHA_DIGEST_LENGTH; i++) { if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; } @@ -298,10 +276,8 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) n=sig->length; s=sig->data; - for (i=0; ialgorithm) <= 0) return 0; sig_nid = OBJ_obj2nid(sigalg->algorithm); - if (sig_nid != NID_undef) - { + if (sig_nid != NID_undef) { int pkey_nid, dig_nid; const EVP_PKEY_ASN1_METHOD *ameth; - if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) - { + if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) { ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); if (ameth && ameth->sig_print) return ameth->sig_print(bp, sigalg, sig, 9, 0); @@ -347,16 +321,14 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v) if (v == NULL) return(0); n=0; p=(const char *)v->data; - for (i=0; ilength; i++) - { + for (i=0; ilength; i++) { if ((p[i] > '~') || ((p[i] < ' ') && (p[i] != '\n') && (p[i] != '\r'))) buf[n]='.'; else buf[n]=p[i]; n++; - if (n >= 80) - { + if (n >= 80) { if (BIO_write(bp,buf,n) <= 0) return(0); n=0; @@ -407,12 +379,10 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) m= (v[10]-'0')*10+(v[11]-'0'); if (tm->length >= 14 && (v[12] >= '0') && (v[12] <= '9') && - (v[13] >= '0') && (v[13] <= '9')) - { + (v[13] >= '0') && (v[13] <= '9')) { s= (v[12]-'0')*10+(v[13]-'0'); /* Check for fractions of seconds. */ - if (tm->length >= 15 && v[14] == '.') - { + if (tm->length >= 15 && v[14] == '.') { int l = tm->length; f = &v[14]; /* The decimal point. */ f_len = 1; @@ -475,29 +445,25 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) l=80-2-obase; b=X509_NAME_oneline(name,NULL,0); - if (!*b) - { + if (!*b) { free(b); return 1; } s=b+1; /* skip the first slash */ c=s; - for (;;) - { + for (;;) { if ( ((*s == '/') && ((s[1] >= 'A') && (s[1] <= 'Z') && ( (s[2] == '=') || ((s[2] >= 'A') && (s[2] <= 'Z') && (s[3] == '=')) ))) || - (*s == '\0')) - { + (*s == '\0')) { i=s-c; if (BIO_write(bp,c,i) != i) goto err; c=s+1; /* skip following slash */ - if (*s != '\0') - { + if (*s != '\0') { if (BIO_write(bp,", ",2) != 2) goto err; } l--; @@ -508,8 +474,7 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) } ret=1; - if (0) - { + if (0) { err: X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); } diff --git a/lib/libssl/src/crypto/asn1/tasn_dec.c b/lib/libssl/src/crypto/asn1/tasn_dec.c index 0df42a4a93c..1a06ddc1850 100644 --- a/lib/libssl/src/crypto/asn1/tasn_dec.c +++ b/lib/libssl/src/crypto/asn1/tasn_dec.c @@ -175,19 +175,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, asn1_cb = aux->asn1_cb; else asn1_cb = 0; - switch(it->itype) - { - case ASN1_ITYPE_PRIMITIVE: - if (it->templates) - { + switch(it->itype) { + case ASN1_ITYPE_PRIMITIVE: + if (it->templates) { /* tagging or OPTIONAL is currently illegal on an item * template because the flags can't get passed down. * In practice this isn't a problem: we include the * relevant flags from the item template in the * template itself. */ - if ((tag != -1) || opt) - { + if ((tag != -1) || opt) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); goto err; @@ -199,21 +196,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, tag, aclass, opt, ctx); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: p = *in; /* Just read in tag and class */ ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* Must be UNIVERSAL class */ - if (oclass != V_ASN1_UNIVERSAL) - { + if (oclass != V_ASN1_UNIVERSAL) { /* If OPTIONAL, assume this is OK */ if (opt) return -1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, @@ -221,8 +216,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto err; } /* Check tag matches bit map */ - if (!(ASN1_tag2bit(otag) & it->utype)) - { + if (!(ASN1_tag2bit(otag) & it->utype)) { /* If OPTIONAL, assume this is OK */ if (opt) return -1; @@ -233,19 +227,18 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx); - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: /* Use new style d2i */ ef = it->funcs; return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx); - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: /* we must resort to old style evil hackery */ cf = it->funcs; /* If OPTIONAL see if it is there */ - if (opt) - { + if (opt) { int exptag; p = *in; if (tag == -1) @@ -256,8 +249,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -281,12 +273,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, * buffer. */ - if (tag != -1) - { + if (tag != -1) { wp = *(unsigned char **)in; imphack = *wp; - if (p == NULL) - { + if (p == NULL) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -307,21 +297,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto err; - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; /* Allocate structure */ - if (!*pval && !ASN1_item_ex_new(pval, it)) - { + if (!*pval && !ASN1_item_ex_new(pval, it)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* CHOICE type, try each possibility in turn */ p = *in; - for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) - { + for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) { pchptr = asn1_get_field_ptr(pval, tt); /* We mark field as OPTIONAL so its absence * can be recognised. @@ -341,11 +329,9 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, } /* Did we fall off the end without reading anything? */ - if (i == it->tcount) - { + if (i == it->tcount) { /* If OPTIONAL, this is OK */ - if (opt) - { + if (opt) { /* Free and zero it */ ASN1_item_ex_free(pval, it); return -1; @@ -361,44 +347,39 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto auxerr; return 1; - case ASN1_ITYPE_NDEF_SEQUENCE: - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: p = *in; tmplen = len; /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ - if (tag == -1) - { + if (tag == -1) { tag = V_ASN1_SEQUENCE; aclass = V_ASN1_UNIVERSAL; } /* Get SEQUENCE length and update len, p */ ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } else if (ret == -1) return -1; - if (aux && (aux->flags & ASN1_AFLG_BROKEN)) - { + if (aux && (aux->flags & ASN1_AFLG_BROKEN)) { len = tmplen - (p - *in); seq_nolen = 1; } /* If indefinite we don't do a length check */ else seq_nolen = seq_eoc; - if (!cst) - { + if (!cst) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); goto err; } - if (!*pval && !ASN1_item_ex_new(pval, it)) - { + if (!*pval && !ASN1_item_ex_new(pval, it)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -408,8 +389,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, goto auxerr; /* Get each field entry */ - for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) - { + for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -420,10 +400,8 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, if (!len) break; q = p; - if (asn1_check_eoc(&p, len)) - { - if (!seq_eoc) - { + if (asn1_check_eoc(&p, len)) { + if (!seq_eoc) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC); goto err; @@ -447,13 +425,10 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx); - if (!ret) - { + if (!ret) { errtt = seqtt; goto err; - } - else if (ret == -1) - { + } else if (ret == -1) { /* OPTIONAL component absent. * Free and zero the field. */ @@ -465,14 +440,12 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, } /* Check for EOC if expecting one */ - if (seq_eoc && !asn1_check_eoc(&p, len)) - { + if (seq_eoc && !asn1_check_eoc(&p, len)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); goto err; } /* Check all data read */ - if (!seq_nolen && len) - { + if (!seq_nolen && len) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH); goto err; @@ -482,20 +455,16 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, * however we may not have read all fields so check all * remaining are OPTIONAL and clear any that are. */ - for (; i < it->tcount; tt++, i++) - { + for (; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) goto err; - if (seqtt->flags & ASN1_TFLG_OPTIONAL) - { + if (seqtt->flags & ASN1_TFLG_OPTIONAL) { ASN1_VALUE **pseqval; pseqval = asn1_get_field_ptr(pval, seqtt); ASN1_template_free(pseqval, seqtt); - } - else - { + } else { errtt = seqtt; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING); @@ -547,8 +516,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, p = *in; /* Check if EXPLICIT tag expected */ - if (flags & ASN1_TFLG_EXPTAG) - { + if (flags & ASN1_TFLG_EXPTAG) { char cst; /* Need to work out amount of data available to the inner * content and where it starts: so read in EXPLICIT header to @@ -557,46 +525,37 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx); q = p; - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; - } - else if (ret == -1) + } else if (ret == -1) return -1; - if (!cst) - { + if (!cst) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); return 0; } /* We've found the field so it can't be OPTIONAL now */ ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; } /* We read the field in OK so update length */ len -= p - q; - if (exp_eoc) - { + if (exp_eoc) { /* If NDEF we must have an EOC here */ - if (!asn1_check_eoc(&p, len)) - { + if (!asn1_check_eoc(&p, len)) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_MISSING_EOC); goto err; } - } - else - { + } else { /* Otherwise we must hit the EXPLICIT tag end or its * an error */ - if (len) - { + if (len) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH); goto err; @@ -631,19 +590,15 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, p = *in; q = p; - if (flags & ASN1_TFLG_SK_MASK) - { + if (flags & ASN1_TFLG_SK_MASK) { /* SET OF, SEQUENCE OF */ int sktag, skaclass; char sk_eoc; /* First work out expected inner tag value */ - if (flags & ASN1_TFLG_IMPTAG) - { + if (flags & ASN1_TFLG_IMPTAG) { sktag = tt->tag; skaclass = aclass; - } - else - { + } else { skaclass = V_ASN1_UNIVERSAL; if (flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET; @@ -653,8 +608,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, /* Get the tag */ ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; @@ -663,37 +617,31 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, return -1; if (!*val) *val = (ASN1_VALUE *)sk_new_null(); - else - { + else { /* We've got a valid STACK: free up any items present */ STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val; ASN1_VALUE *vtmp; - while(sk_ASN1_VALUE_num(sktmp) > 0) - { + while(sk_ASN1_VALUE_num(sktmp) > 0) { vtmp = sk_ASN1_VALUE_pop(sktmp); ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item)); } } - if (!*val) - { + if (!*val) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); goto err; } /* Read as many items as we can */ - while(len > 0) - { + while(len > 0) { ASN1_VALUE *skfield; q = p; /* See if EOC found */ - if (asn1_check_eoc(&p, len)) - { - if (!sk_eoc) - { + if (asn1_check_eoc(&p, len)) { + if (!sk_eoc) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_UNEXPECTED_EOC); goto err; @@ -705,48 +653,39 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, skfield = NULL; if (!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), - -1, 0, 0, ctx)) - { + -1, 0, 0, ctx)) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } len -= p - q; if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, - skfield)) - { + skfield)) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); goto err; } } - if (sk_eoc) - { + if (sk_eoc) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); goto err; } - } - else if (flags & ASN1_TFLG_IMPTAG) - { + } else if (flags & ASN1_TFLG_IMPTAG) { /* IMPLICIT tagging */ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } else if (ret == -1) return -1; - } - else - { + } else { /* Nothing special */ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; @@ -775,32 +714,27 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, BUF_MEM buf; const unsigned char *cont = NULL; long len; - if (!pval) - { + if (!pval) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); return 0; /* Should never happen */ } - if (it->itype == ASN1_ITYPE_MSTRING) - { + if (it->itype == ASN1_ITYPE_MSTRING) { utype = tag; tag = -1; } else utype = it->utype; - if (utype == V_ASN1_ANY) - { + if (utype == V_ASN1_ANY) { /* If type is ANY need to figure out type from tag */ unsigned char oclass; - if (tag >= 0) - { + if (tag >= 0) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY); return 0; } - if (opt) - { + if (opt) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY); return 0; @@ -808,8 +742,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, p = *in; ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; @@ -817,8 +750,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, if (oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER; } - if (tag == -1) - { + if (tag == -1) { tag = utype; aclass = V_ASN1_UNIVERSAL; } @@ -826,8 +758,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, /* Check header */ ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx); - if (!ret) - { + if (!ret) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); return 0; } @@ -836,18 +767,15 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, ret = 0; /* SEQUENCE, SET and "OTHER" are left in encoded form */ if ((utype == V_ASN1_SEQUENCE) - || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) - { + || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) { /* Clear context cache for type OTHER because the auto clear * when we have a exact match wont work */ - if (utype == V_ASN1_OTHER) - { + if (utype == V_ASN1_OTHER) { asn1_tlc_clear(ctx); } /* SEQUENCE and SET must be constructed */ - else if (!cst) - { + else if (!cst) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED); return 0; @@ -855,21 +783,16 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, cont = *in; /* If indefinite length constructed find the real end */ - if (inf) - { + if (inf) { if (!asn1_find_end(&p, plen, inf)) goto err; len = p - cont; - } - else - { + } else { len = p - cont + plen; p += plen; buf.data = NULL; } - } - else if (cst) - { + } else if (cst) { buf.length = 0; buf.max = 0; buf.data = NULL; @@ -879,15 +802,13 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, * internally irrespective of the type. So instead just check * for UNIVERSAL class and ignore the tag. */ - if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) - { + if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) { free_cont = 1; goto err; } len = buf.length; /* Append a final null to string */ - if (!BUF_MEM_grow_clean(&buf, len + 1)) - { + if (!BUF_MEM_grow_clean(&buf, len + 1)) { ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); return 0; @@ -895,9 +816,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, buf.data[len] = 0; cont = (const unsigned char *)buf.data; free_cont = 1; - } - else - { + } else { cont = p; len = plen; p += plen; @@ -930,10 +849,8 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, if (pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it); /* If ANY type clear type and set pointer to internal value */ - if (it->utype == V_ASN1_ANY) - { - if (!*pval) - { + if (it->utype == V_ASN1_ANY) { + if (!*pval) { typ = ASN1_TYPE_new(); if (typ == NULL) goto err; @@ -947,16 +864,14 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, opval = pval; pval = &typ->value.asn1_value; } - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err; break; - case V_ASN1_NULL: - if (len) - { + case V_ASN1_NULL: + if (len) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_NULL_IS_WRONG_LENGTH); goto err; @@ -964,30 +879,27 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, *pval = (ASN1_VALUE *)1; break; - case V_ASN1_BOOLEAN: - if (len != 1) - { + case V_ASN1_BOOLEAN: + if (len != 1) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BOOLEAN_IS_WRONG_LENGTH); goto err; - } - else - { + } else { ASN1_BOOLEAN *tbool; tbool = (ASN1_BOOLEAN *)pval; *tbool = *cont; } break; - case V_ASN1_BIT_STRING: + case V_ASN1_BIT_STRING: if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err; break; - case V_ASN1_INTEGER: - case V_ASN1_NEG_INTEGER: - case V_ASN1_ENUMERATED: - case V_ASN1_NEG_ENUMERATED: + case V_ASN1_INTEGER: + case V_ASN1_NEG_INTEGER: + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: tint = (ASN1_INTEGER **)pval; if (!c2i_ASN1_INTEGER(tint, &cont, len)) goto err; @@ -995,66 +907,56 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG); break; - case V_ASN1_OCTET_STRING: - case V_ASN1_NUMERICSTRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_T61STRING: - case V_ASN1_VIDEOTEXSTRING: - case V_ASN1_IA5STRING: - case V_ASN1_UTCTIME: - case V_ASN1_GENERALIZEDTIME: - case V_ASN1_GRAPHICSTRING: - case V_ASN1_VISIBLESTRING: - case V_ASN1_GENERALSTRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_BMPSTRING: - case V_ASN1_UTF8STRING: - case V_ASN1_OTHER: - case V_ASN1_SET: - case V_ASN1_SEQUENCE: - default: - if (utype == V_ASN1_BMPSTRING && (len & 1)) - { + case V_ASN1_OCTET_STRING: + case V_ASN1_NUMERICSTRING: + case V_ASN1_PRINTABLESTRING: + case V_ASN1_T61STRING: + case V_ASN1_VIDEOTEXSTRING: + case V_ASN1_IA5STRING: + case V_ASN1_UTCTIME: + case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GRAPHICSTRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_UTF8STRING: + case V_ASN1_OTHER: + case V_ASN1_SET: + case V_ASN1_SEQUENCE: + default: + if (utype == V_ASN1_BMPSTRING && (len & 1)) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BMPSTRING_IS_WRONG_LENGTH); goto err; } - if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) - { + if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); goto err; } /* All based on ASN1_STRING and handled the same */ - if (!*pval) - { + if (!*pval) { stmp = ASN1_STRING_type_new(utype); - if (!stmp) - { + if (!stmp) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); goto err; } *pval = (ASN1_VALUE *)stmp; - } - else - { + } else { stmp = (ASN1_STRING *)*pval; stmp->type = utype; } /* If we've already allocated a buffer use it */ - if (*free_cont) - { + if (*free_cont) { if (stmp->data) free(stmp->data); stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ stmp->length = len; *free_cont = 0; - } - else - { - if (!ASN1_STRING_set(stmp, cont, len)) - { + } else { + if (!ASN1_STRING_set(stmp, cont, len)) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); ASN1_STRING_free(stmp); @@ -1070,8 +972,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, ret = 1; err: - if (!ret) - { + if (!ret) { ASN1_TYPE_free(typ); if (opval) *opval = NULL; @@ -1092,8 +993,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) long plen; const unsigned char *p = *in, *q; /* If not indefinite length constructed just add length */ - if (inf == 0) - { + if (inf == 0) { *in += len; return 1; } @@ -1103,10 +1003,8 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) * are encountered increment the expected eoc count otherwise just * skip to the end of the data. */ - while (len > 0) - { - if(asn1_check_eoc(&p, len)) - { + while (len > 0) { + if(asn1_check_eoc(&p, len)) { expected_eoc--; if (expected_eoc == 0) break; @@ -1116,8 +1014,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) q = p; /* Just read in a header: only care about the length */ if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, - -1, 0, 0, NULL)) - { + -1, 0, 0, NULL)) { ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); return 0; } @@ -1127,8 +1024,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf) p += plen; len -= p - q; } - if (expected_eoc) - { + if (expected_eoc) { ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); return 0; } @@ -1161,21 +1057,17 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, inf &= 1; /* If no buffer and not indefinite length constructed just pass over * the encoded data */ - if (!buf && !inf) - { + if (!buf && !inf) { *in += len; return 1; } - while(len > 0) - { + while(len > 0) { q = p; /* Check for EOC */ - if (asn1_check_eoc(&p, len)) - { + if (asn1_check_eoc(&p, len)) { /* EOC is illegal outside indefinite length * constructed form */ - if (!inf) - { + if (!inf) { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC); return 0; @@ -1185,17 +1077,14 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, } if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, - len, tag, aclass, 0, NULL)) - { + len, tag, aclass, 0, NULL)) { ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); return 0; } /* If indefinite length constructed update max length */ - if (cst) - { - if (depth >= ASN1_MAX_STRING_NEST) - { + if (cst) { + if (depth >= ASN1_MAX_STRING_NEST) { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING); return 0; @@ -1208,8 +1097,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, return 0; len -= p - q; } - if (inf) - { + if (inf) { ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); return 0; } @@ -1220,11 +1108,9 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) { int len; - if (buf) - { + if (buf) { len = buf->length; - if (!BUF_MEM_grow_clean(buf, len + plen)) - { + if (!BUF_MEM_grow_clean(buf, len + plen)) { ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); return 0; } @@ -1241,8 +1127,7 @@ static int asn1_check_eoc(const unsigned char **in, long len) const unsigned char *p; if (len < 2) return 0; p = *in; - if (!p[0] && !p[1]) - { + if (!p[0] && !p[1]) { *in += 2; return 1; } @@ -1269,19 +1154,15 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, p = *in; q = p; - if (ctx && ctx->valid) - { + if (ctx && ctx->valid) { i = ctx->ret; plen = ctx->plen; pclass = ctx->pclass; ptag = ctx->ptag; p += ctx->hdrlen; - } - else - { + } else { i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); - if (ctx) - { + if (ctx) { ctx->ret = i; ctx->plen = plen; ctx->pclass = pclass; @@ -1291,8 +1172,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, /* If definite length, and no error, length + * header can't exceed total amount of data available. */ - if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) - { + if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); asn1_tlc_clear(ctx); @@ -1301,16 +1181,13 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, } } - if (i & 0x80) - { + if (i & 0x80) { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); asn1_tlc_clear(ctx); return 0; } - if (exptag >= 0) - { - if ((exptag != ptag) || (expclass != pclass)) - { + if (exptag >= 0) { + if ((exptag != ptag) || (expclass != pclass)) { /* If type is OPTIONAL, not an error: * indicate missing type. */ diff --git a/lib/libssl/src/crypto/asn1/tasn_enc.c b/lib/libssl/src/crypto/asn1/tasn_enc.c index 230164107df..f7bdd11edfa 100644 --- a/lib/libssl/src/crypto/asn1/tasn_enc.c +++ b/lib/libssl/src/crypto/asn1/tasn_enc.c @@ -103,8 +103,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it, int flags) { - if (out && !*out) - { + if (out && !*out) { unsigned char *p, *buf; int len; len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); @@ -144,25 +143,23 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, if (aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_PRIMITIVE: + case ASN1_ITYPE_PRIMITIVE: if (it->templates) return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass); return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) return 0; i = asn1_get_choice_selector(pval, it); - if ((i >= 0) && (i < it->tcount)) - { + if ((i >= 0) && (i < it->tcount)) { ASN1_VALUE **pchval; const ASN1_TEMPLATE *chtt; chtt = it->templates + i; @@ -175,12 +172,12 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return 0; break; - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: /* If new style i2d it does all the work */ ef = it->funcs; return ef->asn1_ex_i2d(pval, out, it, tag, aclass); - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: /* old style hackery... */ cf = it->funcs; if (out) @@ -193,12 +190,12 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED); return i; - case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: /* Use indefinite length constructed if requested */ if (aclass & ASN1_TFLG_NDEF) ndef = 2; /* fall through */ - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: i = asn1_enc_restore(&seqcontlen, out, pval, it); /* An error occurred */ if (i < 0) @@ -209,8 +206,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Otherwise carry on */ seqcontlen = 0; /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ - if (tag == -1) - { + if (tag == -1) { tag = V_ASN1_SEQUENCE; /* Retain any other flags in aclass */ aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) @@ -219,8 +215,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) return 0; /* First work out sequence content length */ - for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) - { + for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -237,8 +232,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return seqlen; /* Output SEQUENCE header */ ASN1_put_object(out, ndef, seqcontlen, tag, aclass); - for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) - { + for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); @@ -278,8 +272,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, * the iclass argument may contain some additional flags * which should be noted and passed down to other levels. */ - if (flags & ASN1_TFLG_TAG_MASK) - { + if (flags & ASN1_TFLG_TAG_MASK) { /* Error if argument and template tagging */ if (tag != -1) /* FIXME: error code here */ @@ -287,15 +280,11 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Get tagging from template */ ttag = tt->tag; tclass = flags & ASN1_TFLG_TAG_CLASS; - } - else if (tag != -1) - { + } else if (tag != -1) { /* No template tagging, get from arguments */ ttag = tag; tclass = iclass & ASN1_TFLG_TAG_CLASS; - } - else - { + } else { ttag = -1; tclass = 0; } @@ -314,8 +303,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, ndef = 2; else ndef = 1; - if (flags & ASN1_TFLG_SK_MASK) - { + if (flags & ASN1_TFLG_SK_MASK) { /* SET OF, SEQUENCE OF */ STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; int isset, sktag, skaclass; @@ -325,8 +313,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, if (!*pval) return 0; - if (flags & ASN1_TFLG_SET_OF) - { + if (flags & ASN1_TFLG_SET_OF) { isset = 1; /* 2 means we reorder */ if (flags & ASN1_TFLG_SEQUENCE_OF) @@ -337,13 +324,10 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Work out inner tag value: if EXPLICIT * or no tagging use underlying type. */ - if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) - { + if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) { sktag = ttag; skaclass = tclass; - } - else - { + } else { skaclass = V_ASN1_UNIVERSAL; if (isset) sktag = V_ASN1_SET; @@ -352,8 +336,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* Determine total length of items */ skcontlen = 0; - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) - { + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { skitem = sk_ASN1_VALUE_value(sk, i); skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), @@ -377,8 +360,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* And the stuff itself */ asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset, iclass); - if (ndef == 2) - { + if (ndef == 2) { ASN1_put_eoc(out); if (flags & ASN1_TFLG_EXPTAG) ASN1_put_eoc(out); @@ -387,8 +369,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return ret; } - if (flags & ASN1_TFLG_EXPTAG) - { + if (flags & ASN1_TFLG_EXPTAG) { /* EXPLICIT tagging */ /* Find length of tagged item */ i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), @@ -397,8 +378,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, return 0; /* Find length of EXPLICIT tag */ ret = ASN1_object_size(ndef, i, ttag); - if (out) - { + if (out) { /* Output tag and item */ ASN1_put_object(out, ndef, i, ttag, tclass); ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), @@ -449,8 +429,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, /* Don't need to sort less than 2 items */ if (sk_ASN1_VALUE_num(sk) < 2) do_sort = 0; - else - { + else { derlst = malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst)); tmpdat = malloc(skcontlen); @@ -461,10 +440,8 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, } } /* If not sorting just output each item */ - if (!do_sort) - { - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) - { + if (!do_sort) { + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { skitem = sk_ASN1_VALUE_value(sk, i); ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); } @@ -473,8 +450,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, p = tmpdat; /* Doing sort: build up a list of each member's DER encoding */ - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) - { + for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { skitem = sk_ASN1_VALUE_value(sk, i); tder->data = p; tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); @@ -485,17 +461,14 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); /* Output sorted DER encoding */ p = *out; - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) - { + for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { memcpy(p, tder->data, tder->length); p += tder->length; } *out = p; /* If do_sort is 2 then reorder the STACK */ - if (do_sort == 2) - { - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); - i++, tder++) + if (do_sort == 2) { + for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) (void)sk_ASN1_VALUE_set(sk, i, tder->field); } free(derlst); @@ -536,8 +509,7 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, return 0; /* -2 return is special meaning use ndef */ - if (len == -2) - { + if (len == -2) { ndef = 2; len = 0; } @@ -546,8 +518,7 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, if (tag == -1) tag = utype; /* Output tag+length followed by content octets */ - if (out) - { + if (out) { if (usetag) ASN1_put_object(out, ndef, len, tag, aclass); asn1_ex_i2c(pval, *out, &utype, it); @@ -580,21 +551,16 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, return pf->prim_i2c(pval, cout, putype, it); /* Should type be omitted? */ - if ((it->itype != ASN1_ITYPE_PRIMITIVE) - || (it->utype != V_ASN1_BOOLEAN)) - { + if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) { if (!*pval) return -1; } - if (it->itype == ASN1_ITYPE_MSTRING) - { + if (it->itype == ASN1_ITYPE_MSTRING) { /* If MSTRING type set the underlying type */ strtmp = (ASN1_STRING *)*pval; utype = strtmp->type; *putype = utype; - } - else if (it->utype == V_ASN1_ANY) - { + } else if (it->utype == V_ASN1_ANY) { /* If ANY set type and pointer to value */ ASN1_TYPE *typ; typ = (ASN1_TYPE *)*pval; @@ -604,25 +570,23 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, } else utype = *putype; - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: otmp = (ASN1_OBJECT *)*pval; cont = otmp->data; len = otmp->length; break; - case V_ASN1_NULL: + case V_ASN1_NULL: cont = NULL; len = 0; break; - case V_ASN1_BOOLEAN: + case V_ASN1_BOOLEAN: tbool = (ASN1_BOOLEAN *)pval; if (*tbool == -1) return -1; - if (it->utype != V_ASN1_ANY) - { + if (it->utype != V_ASN1_ANY) { /* Default handling if value == size field then omit */ if (*tbool && (it->size > 0)) return -1; @@ -634,15 +598,15 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, len = 1; break; - case V_ASN1_BIT_STRING: + case V_ASN1_BIT_STRING: return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL); break; - case V_ASN1_INTEGER: - case V_ASN1_NEG_INTEGER: - case V_ASN1_ENUMERATED: - case V_ASN1_NEG_ENUMERATED: + case V_ASN1_INTEGER: + case V_ASN1_NEG_INTEGER: + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: /* These are all have the same content format * as ASN1_INTEGER */ @@ -650,31 +614,29 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, cout ? &cout : NULL); break; - case V_ASN1_OCTET_STRING: - case V_ASN1_NUMERICSTRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_T61STRING: - case V_ASN1_VIDEOTEXSTRING: - case V_ASN1_IA5STRING: - case V_ASN1_UTCTIME: - case V_ASN1_GENERALIZEDTIME: - case V_ASN1_GRAPHICSTRING: - case V_ASN1_VISIBLESTRING: - case V_ASN1_GENERALSTRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_BMPSTRING: - case V_ASN1_UTF8STRING: - case V_ASN1_SEQUENCE: - case V_ASN1_SET: - default: + case V_ASN1_OCTET_STRING: + case V_ASN1_NUMERICSTRING: + case V_ASN1_PRINTABLESTRING: + case V_ASN1_T61STRING: + case V_ASN1_VIDEOTEXSTRING: + case V_ASN1_IA5STRING: + case V_ASN1_UTCTIME: + case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GRAPHICSTRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_UTF8STRING: + case V_ASN1_SEQUENCE: + case V_ASN1_SET: + default: /* All based on ASN1_STRING and handled the same */ strtmp = (ASN1_STRING *)*pval; /* Special handling for NDEF */ if ((it->size == ASN1_TFLG_NDEF) - && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) - { - if (cout) - { + && (strtmp->flags & ASN1_STRING_FLAG_NDEF)) { + if (cout) { strtmp->data = cout; strtmp->length = 0; } diff --git a/lib/libssl/src/crypto/asn1/tasn_fre.c b/lib/libssl/src/crypto/asn1/tasn_fre.c index b321de6615c..5211276efe6 100644 --- a/lib/libssl/src/crypto/asn1/tasn_fre.c +++ b/lib/libssl/src/crypto/asn1/tasn_fre.c @@ -93,30 +93,27 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c else asn1_cb = 0; - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_PRIMITIVE: + case ASN1_ITYPE_PRIMITIVE: if (it->templates) ASN1_template_free(pval, it->templates); else ASN1_primitive_free(pval, it); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: ASN1_primitive_free(pval, it); break; - case ASN1_ITYPE_CHOICE: - if (asn1_cb) - { + case ASN1_ITYPE_CHOICE: + if (asn1_cb) { i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); if (i == 2) return; } i = asn1_get_choice_selector(pval, it); - if ((i >= 0) && (i < it->tcount)) - { + if ((i >= 0) && (i < it->tcount)) { ASN1_VALUE **pchval; tt = it->templates + i; pchval = asn1_get_field_ptr(pval, tt); @@ -124,31 +121,29 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c } if (asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); - if (!combine) - { + if (!combine) { free(*pval); *pval = NULL; } break; - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: cf = it->funcs; if (cf && cf->asn1_free) cf->asn1_free(*pval); break; - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: ef = it->funcs; if (ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it); break; - case ASN1_ITYPE_NDEF_SEQUENCE: - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: if (asn1_do_lock(pval, -1, it) > 0) return; - if (asn1_cb) - { + if (asn1_cb) { i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); if (i == 2) return; @@ -160,8 +155,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c * free up in reverse order. */ tt = it->templates + it->tcount - 1; - for (i = 0; i < it->tcount; tt--, i++) - { + for (i = 0; i < it->tcount; tt--, i++) { ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 0); if (!seqtt) @@ -171,8 +165,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c } if (asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); - if (!combine) - { + if (!combine) { free(*pval); *pval = NULL; } @@ -183,11 +176,9 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) { int i; - if (tt->flags & ASN1_TFLG_SK_MASK) - { + if (tt->flags & ASN1_TFLG_SK_MASK) { STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) - { + for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { ASN1_VALUE *vtmp; vtmp = sk_ASN1_VALUE_value(sk, i); asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), @@ -204,60 +195,52 @@ void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { int utype; - if (it) - { + if (it) { const ASN1_PRIMITIVE_FUNCS *pf; pf = it->funcs; - if (pf && pf->prim_free) - { + if (pf && pf->prim_free) { pf->prim_free(pval, it); return; } } /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ - if (!it) - { + if (!it) { ASN1_TYPE *typ = (ASN1_TYPE *)*pval; utype = typ->type; pval = &typ->value.asn1_value; if (!*pval) return; - } - else if (it->itype == ASN1_ITYPE_MSTRING) - { + } else if (it->itype == ASN1_ITYPE_MSTRING) { utype = -1; if (!*pval) return; - } - else - { + } else { utype = it->utype; if ((utype != V_ASN1_BOOLEAN) && !*pval) return; } - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: ASN1_OBJECT_free((ASN1_OBJECT *)*pval); break; - case V_ASN1_BOOLEAN: + case V_ASN1_BOOLEAN: if (it) *(ASN1_BOOLEAN *)pval = it->size; else *(ASN1_BOOLEAN *)pval = -1; return; - case V_ASN1_NULL: + case V_ASN1_NULL: break; - case V_ASN1_ANY: + case V_ASN1_ANY: ASN1_primitive_free(pval, NULL); free(*pval); break; - default: + default: ASN1_STRING_free((ASN1_STRING *)*pval); *pval = NULL; break; diff --git a/lib/libssl/src/crypto/asn1/tasn_new.c b/lib/libssl/src/crypto/asn1/tasn_new.c index f5d7c690b86..00aa31dd635 100644 --- a/lib/libssl/src/crypto/asn1/tasn_new.c +++ b/lib/libssl/src/crypto/asn1/tasn_new.c @@ -107,30 +107,27 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, CRYPTO_push_info(it->sname); #endif - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: ef = it->funcs; - if (ef && ef->asn1_ex_new) - { + if (ef && ef->asn1_ex_new) { if (!ef->asn1_ex_new(pval, it)) goto memerr; } break; - case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_COMPAT: cf = it->funcs; if (cf && cf->asn1_new) { *pval = cf->asn1_new(); if (!*pval) goto memerr; - } + } break; - case ASN1_ITYPE_PRIMITIVE: - if (it->templates) - { + case ASN1_ITYPE_PRIMITIVE: + if (it->templates) { if (!ASN1_template_new(pval, it->templates)) goto memerr; } @@ -138,19 +135,17 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, goto memerr; break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: if (!ASN1_primitive_new(pval, it)) goto memerr; break; - case ASN1_ITYPE_CHOICE: - if (asn1_cb) - { + case ASN1_ITYPE_CHOICE: + if (asn1_cb) { i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); if (!i) goto auxerr; - if (i==2) - { + if (i==2) { #ifdef CRYPTO_MDEBUG if (it->sname) CRYPTO_pop_info(); @@ -158,8 +153,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, return 1; } } - if (!combine) - { + if (!combine) { *pval = malloc(it->size); if (!*pval) goto memerr; @@ -170,15 +164,13 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, goto auxerr; break; - case ASN1_ITYPE_NDEF_SEQUENCE: - case ASN1_ITYPE_SEQUENCE: - if (asn1_cb) - { + case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: + if (asn1_cb) { i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); if (!i) goto auxerr; - if (i==2) - { + if (i==2) { #ifdef CRYPTO_MDEBUG if (it->sname) CRYPTO_pop_info(); @@ -186,8 +178,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, return 1; } } - if (!combine) - { + if (!combine) { *pval = malloc(it->size); if (!*pval) goto memerr; @@ -195,8 +186,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, asn1_do_lock(pval, 0, it); asn1_enc_init(pval, it); } - for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) - { + for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { pseqval = asn1_get_field_ptr(pval, tt); if (!ASN1_template_new(pseqval, tt)) goto memerr; @@ -231,10 +221,9 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) { const ASN1_EXTERN_FUNCS *ef; - switch(it->itype) - { + switch(it->itype) { - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: ef = it->funcs; if (ef && ef->asn1_ex_clear) ef->asn1_ex_clear(pval, it); @@ -242,21 +231,21 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) break; - case ASN1_ITYPE_PRIMITIVE: + case ASN1_ITYPE_PRIMITIVE: if (it->templates) asn1_template_clear(pval, it->templates); else asn1_primitive_clear(pval, it); break; - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: asn1_primitive_clear(pval, it); break; - case ASN1_ITYPE_COMPAT: - case ASN1_ITYPE_CHOICE: - case ASN1_ITYPE_SEQUENCE: - case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_COMPAT: + case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: *pval = NULL; break; } @@ -267,15 +256,13 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) { const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); int ret; - if (tt->flags & ASN1_TFLG_OPTIONAL) - { + if (tt->flags & ASN1_TFLG_OPTIONAL) { asn1_template_clear(pval, tt); return 1; } /* If ANY DEFINED BY nothing to do */ - if (tt->flags & ASN1_TFLG_ADB_MASK) - { + if (tt->flags & ASN1_TFLG_ADB_MASK) { *pval = NULL; return 1; } @@ -284,12 +271,10 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) CRYPTO_push_info(tt->field_name); #endif /* If SET OF or SEQUENCE OF, its a STACK */ - if (tt->flags & ASN1_TFLG_SK_MASK) - { + if (tt->flags & ASN1_TFLG_SK_MASK) { STACK_OF(ASN1_VALUE) *skval; skval = sk_ASN1_VALUE_new_null(); - if (!skval) - { + if (!skval) { ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); ret = 0; goto done; @@ -328,8 +313,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) ASN1_STRING *str; int utype; - if (it && it->funcs) - { + if (it && it->funcs) { const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; if (pf->prim_new) return pf->prim_new(pval, it); @@ -339,21 +323,20 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) utype = -1; else utype = it->utype; - switch(utype) - { - case V_ASN1_OBJECT: + switch(utype) { + case V_ASN1_OBJECT: *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); return 1; - case V_ASN1_BOOLEAN: + case V_ASN1_BOOLEAN: *(ASN1_BOOLEAN *)pval = it->size; return 1; - case V_ASN1_NULL: + case V_ASN1_NULL: *pval = (ASN1_VALUE *)1; return 1; - case V_ASN1_ANY: + case V_ASN1_ANY: typ = malloc(sizeof(ASN1_TYPE)); if (!typ) return 0; @@ -362,7 +345,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) *pval = (ASN1_VALUE *)typ; break; - default: + default: str = ASN1_STRING_type_new(utype); if (it->itype == ASN1_ITYPE_MSTRING && str) str->flags |= ASN1_STRING_FLAG_MSTRING; @@ -377,8 +360,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) { int utype; - if (it && it->funcs) - { + if (it && it->funcs) { const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; if (pf->prim_clear) pf->prim_clear(pval, it); diff --git a/lib/libssl/src/crypto/asn1/tasn_prn.c b/lib/libssl/src/crypto/asn1/tasn_prn.c index f62c085f3b9..345daeb0f35 100644 --- a/lib/libssl/src/crypto/asn1/tasn_prn.c +++ b/lib/libssl/src/crypto/asn1/tasn_prn.c @@ -86,8 +86,7 @@ ASN1_PCTX *ASN1_PCTX_new(void) { ASN1_PCTX *ret; ret = malloc(sizeof(ASN1_PCTX)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); return NULL; } @@ -199,8 +198,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, ASN1_aux_cb *asn1_cb; ASN1_PRINT_ARG parg; int i; - if (aux && aux->asn1_cb) - { + if (aux && aux->asn1_cb) { parg.out = out; parg.indent = indent; parg.pctx = pctx; @@ -208,10 +206,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, } else asn1_cb = 0; - if(*fld == NULL) - { - if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) - { + if(*fld == NULL) { + if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT) { if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; @@ -221,29 +217,26 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 1; } - switch(it->itype) - { - case ASN1_ITYPE_PRIMITIVE: - if(it->templates) - { + switch(it->itype) { + case ASN1_ITYPE_PRIMITIVE: + if(it->templates) { if (!asn1_template_print_ctx(out, fld, indent, it->templates, pctx)) return 0; } /* fall thru */ - case ASN1_ITYPE_MSTRING: + case ASN1_ITYPE_MSTRING: if (!asn1_primitive_print(out, fld, it, indent, fname, sname,pctx)) return 0; break; - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; /* Use new style print routine if possible */ ef = it->funcs; - if (ef && ef->asn1_ex_print) - { + if (ef && ef->asn1_ex_print) { i = ef->asn1_ex_print(out, fld, indent, "", pctx); if (!i) return 0; @@ -256,7 +249,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 0; break; - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: #if 0 if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; @@ -264,8 +257,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, /* CHOICE type, get selector */ i = asn1_get_choice_selector(fld, it); /* This should never happen... */ - if((i < 0) || (i >= it->tcount)) - { + if((i < 0) || (i >= it->tcount)) { if (BIO_printf(out, "ERROR: selector [%d] invalid\n", i) <= 0) return 0; @@ -277,26 +269,21 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 0; break; - case ASN1_ITYPE_SEQUENCE: - case ASN1_ITYPE_NDEF_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_NDEF_SEQUENCE: if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx)) return 0; - if (fname || sname) - { - if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) - { + if (fname || sname) { + if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { if (BIO_puts(out, " {\n") <= 0) return 0; - } - else - { + } else { if (BIO_puts(out, "\n") <= 0) return 0; } } - if (asn1_cb) - { + if (asn1_cb) { i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg); if (i == 0) return 0; @@ -305,8 +292,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, } /* Print each field entry */ - for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) - { + for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) { const ASN1_TEMPLATE *seqtt; seqtt = asn1_do_adb(fld, tt, 1); tmpfld = asn1_get_field_ptr(fld, seqtt); @@ -314,14 +300,12 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, indent + 2, seqtt, pctx)) return 0; } - if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) - { + if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { if (BIO_printf(out, "%*s}\n", indent, "") < 0) return 0; } - if (asn1_cb) - { + if (asn1_cb) { i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg); if (i == 0) return 0; @@ -350,17 +334,14 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, fname = NULL; else fname = tt->field_name; - if(flags & ASN1_TFLG_SK_MASK) - { + if(flags & ASN1_TFLG_SK_MASK) { char *tname; ASN1_VALUE *skitem; STACK_OF(ASN1_VALUE) *stack; /* SET OF, SEQUENCE OF */ - if (fname) - { - if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) - { + if (fname) { + if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SSOF) { if(flags & ASN1_TFLG_SET_OF) tname = "SET"; else @@ -374,8 +355,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, return 0; } stack = (STACK_OF(ASN1_VALUE) *)*fld; - for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) - { + for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) { if ((i > 0) && (BIO_puts(out, "\n") <= 0)) return 0; @@ -386,8 +366,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, } if (!i && BIO_printf(out, "%*s\n", indent + 2, "") <= 0) return 0; - if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) - { + if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_SEQUENCE) { if (BIO_printf(out, "%*s}\n", indent, "") <= 0) return 0; } @@ -409,8 +388,7 @@ static int asn1_print_fsname(BIO *out, int indent, return 1; #endif - while (indent > nspaces) - { + while (indent > nspaces) { if (BIO_write(out, spaces, nspaces) != nspaces) return 0; indent -= nspaces; @@ -423,20 +401,15 @@ static int asn1_print_fsname(BIO *out, int indent, fname = NULL; if (!sname && !fname) return 1; - if (fname) - { + if (fname) { if (BIO_puts(out, fname) <= 0) return 0; } - if (sname) - { - if (fname) - { + if (sname) { + if (fname) { if (BIO_printf(out, " (%s)", sname) <= 0) return 0; - } - else - { + } else { if (BIO_puts(out, sname) <= 0) return 0; } @@ -450,13 +423,12 @@ static int asn1_print_boolean_ctx(BIO *out, int boolval, const ASN1_PCTX *pctx) { const char *str; - switch (boolval) - { - case -1: + switch (boolval) { + case -1: str = "BOOL ABSENT"; break; - case 0: + case 0: str = "FALSE"; break; @@ -501,8 +473,7 @@ static int asn1_print_oid_ctx(BIO *out, const ASN1_OBJECT *oid, static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent, const ASN1_PCTX *pctx) { - if (str->type == V_ASN1_BIT_STRING) - { + if (str->type == V_ASN1_BIT_STRING) { if (BIO_printf(out, " (%ld unused bits)\n", str->flags & 0x7) <= 0) return 0; @@ -536,8 +507,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, utype = str->type & ~V_ASN1_NEG; else utype = it->utype; - if (utype == V_ASN1_ANY) - { + if (utype == V_ASN1_ANY) { ASN1_TYPE *atype = (ASN1_TYPE *)*fld; utype = atype->type; fld = &atype->value.asn1_value; @@ -546,33 +516,28 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, pname = NULL; else pname = ASN1_tag2str(utype); - } - else - { + } else { if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_TYPE) pname = ASN1_tag2str(utype); else pname = NULL; } - if (utype == V_ASN1_NULL) - { + if (utype == V_ASN1_NULL) { if (BIO_puts(out, "NULL\n") <= 0) return 0; return 1; } - if (pname) - { + if (pname) { if (BIO_puts(out, pname) <= 0) return 0; if (BIO_puts(out, ":") <= 0) return 0; } - switch (utype) - { - case V_ASN1_BOOLEAN: + switch (utype) { + case V_ASN1_BOOLEAN: { int boolval = *(int *)fld; if (boolval == -1) @@ -581,32 +546,32 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, } break; - case V_ASN1_INTEGER: - case V_ASN1_ENUMERATED: + case V_ASN1_INTEGER: + case V_ASN1_ENUMERATED: ret = asn1_print_integer_ctx(out, str, pctx); break; - case V_ASN1_UTCTIME: + case V_ASN1_UTCTIME: ret = ASN1_UTCTIME_print(out, str); break; - case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GENERALIZEDTIME: ret = ASN1_GENERALIZEDTIME_print(out, str); break; - case V_ASN1_OBJECT: + case V_ASN1_OBJECT: ret = asn1_print_oid_ctx(out, (const ASN1_OBJECT *)*fld, pctx); break; - case V_ASN1_OCTET_STRING: - case V_ASN1_BIT_STRING: + case V_ASN1_OCTET_STRING: + case V_ASN1_BIT_STRING: ret = asn1_print_obstring_ctx(out, str, indent, pctx); needlf = 0; break; - case V_ASN1_SEQUENCE: - case V_ASN1_SET: - case V_ASN1_OTHER: + case V_ASN1_SEQUENCE: + case V_ASN1_SET: + case V_ASN1_OTHER: if (BIO_puts(out, "\n") <= 0) return 0; if (ASN1_parse_dump(out, str->data, str->length, @@ -615,7 +580,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld, needlf = 0; break; - default: + default: ret = ASN1_STRING_print_ex(out, str, pctx->str_flags); } diff --git a/lib/libssl/src/crypto/asn1/tasn_utl.c b/lib/libssl/src/crypto/asn1/tasn_utl.c index 37c86c6af88..9715dac931d 100644 --- a/lib/libssl/src/crypto/asn1/tasn_utl.c +++ b/lib/libssl/src/crypto/asn1/tasn_utl.c @@ -109,8 +109,7 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0; lck = offset2ptr(*pval, aux->ref_offset); - if (op == 0) - { + if (op == 0) { *lck = 1; return 1; } @@ -133,8 +132,7 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) { ASN1_ENCODING *enc; enc = asn1_get_enc_ptr(pval, it); - if (enc) - { + if (enc) { enc->enc = NULL; enc->len = 0; enc->modified = 1; @@ -145,8 +143,7 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { ASN1_ENCODING *enc; enc = asn1_get_enc_ptr(pval, it); - if (enc) - { + if (enc) { if (enc->enc) free(enc->enc); enc->enc = NULL; @@ -182,8 +179,7 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, enc = asn1_get_enc_ptr(pval, it); if (!enc || enc->modified) return 0; - if (out) - { + if (out) { memcpy(*out, enc->enc, enc->len); *out += enc->len; } @@ -228,8 +224,7 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, sfld = offset2ptr(*pval, adb->offset); /* Check if NULL */ - if (!sfld) - { + if (!sfld) { if (!adb->null_tt) goto err; return adb->null_tt; diff --git a/lib/libssl/src/crypto/asn1/x_algor.c b/lib/libssl/src/crypto/asn1/x_algor.c index 6f6fbb112a5..7ae473485c1 100644 --- a/lib/libssl/src/crypto/asn1/x_algor.c +++ b/lib/libssl/src/crypto/asn1/x_algor.c @@ -81,25 +81,21 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) { if (!alg) return 0; - if (ptype != V_ASN1_UNDEF) - { + if (ptype != V_ASN1_UNDEF) { if (alg->parameter == NULL) alg->parameter = ASN1_TYPE_new(); if (alg->parameter == NULL) return 0; } - if (alg) - { + if (alg) { if (alg->algorithm) ASN1_OBJECT_free(alg->algorithm); alg->algorithm = aobj; } if (ptype == 0) return 1; - if (ptype == V_ASN1_UNDEF) - { - if (alg->parameter) - { + if (ptype == V_ASN1_UNDEF) { + if (alg->parameter) { ASN1_TYPE_free(alg->parameter); alg->parameter = NULL; } @@ -114,10 +110,8 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, { if (paobj) *paobj = algor->algorithm; - if (pptype) - { - if (algor->parameter == NULL) - { + if (pptype) { + if (algor->parameter == NULL) { *pptype = V_ASN1_UNDEF; return; } diff --git a/lib/libssl/src/crypto/asn1/x_crl.c b/lib/libssl/src/crypto/asn1/x_crl.c index b3a6355795a..ea94f026b20 100644 --- a/lib/libssl/src/crypto/asn1/x_crl.c +++ b/lib/libssl/src/crypto/asn1/x_crl.c @@ -101,10 +101,10 @@ static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, /* Just set cmp function here. We don't sort because that * would affect the output of X509_CRL_print(). */ - case ASN1_OP_D2I_POST: + case ASN1_OP_D2I_POST: (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); break; -} + } return 1; } @@ -133,8 +133,7 @@ static int crl_set_issuers(X509_CRL *crl) revoked = X509_CRL_get_REVOKED(crl); gens = NULL; - for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) - { + for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) { X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); STACK_OF(X509_EXTENSION) *exts; ASN1_ENUMERATED *reason; @@ -142,17 +141,14 @@ static int crl_set_issuers(X509_CRL *crl) gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer, &j, NULL); - if (!gtmp && (j != -1)) - { + if (!gtmp && (j != -1)) { crl->flags |= EXFLAG_INVALID; return 1; } - if (gtmp) - { + if (gtmp) { gens = gtmp; - if (!crl->issuers) - { + if (!crl->issuers) { crl->issuers = sk_GENERAL_NAMES_new_null(); if (!crl->issuers) return 0; @@ -164,29 +160,24 @@ static int crl_set_issuers(X509_CRL *crl) reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL); - if (!reason && (j != -1)) - { + if (!reason && (j != -1)) { crl->flags |= EXFLAG_INVALID; return 1; } - if (reason) - { + if (reason) { rev->reason = ASN1_ENUMERATED_get(reason); ASN1_ENUMERATED_free(reason); - } - else + } else rev->reason = CRL_REASON_NONE; /* Check for critical CRL entry extensions */ exts = rev->extensions; - for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) - { + for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) { ext = sk_X509_EXTENSION_value(exts, j); - if (ext->critical > 0) - { + if (ext->critical > 0) { if (OBJ_obj2nid(ext->object) == NID_certificate_issuer) continue; @@ -213,9 +204,8 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, X509_EXTENSION *ext; int idx; - switch(operation) - { - case ASN1_OP_NEW_POST: + switch(operation) { + case ASN1_OP_NEW_POST: crl->idp = NULL; crl->akid = NULL; crl->flags = 0; @@ -228,7 +218,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, crl->base_crl_number = NULL; break; - case ASN1_OP_D2I_POST: + case ASN1_OP_D2I_POST: #ifndef OPENSSL_NO_SHA X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL); #endif @@ -259,15 +249,13 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, exts = crl->crl->extensions; - for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) - { + for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) { int nid; ext = sk_X509_EXTENSION_value(exts, idx); nid = OBJ_obj2nid(ext->object); if (nid == NID_freshest_crl) crl->flags |= EXFLAG_FRESHEST; - if (ext->critical > 0) - { + if (ext->critical > 0) { /* We handle IDP and deltas */ if ((nid == NID_issuing_distribution_point) || (nid == NID_delta_crl)) @@ -281,16 +269,14 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, if (!crl_set_issuers(crl)) return 0; - if (crl->meth->crl_init) - { + if (crl->meth->crl_init) { if (crl->meth->crl_init(crl) == 0) return 0; } break; - case ASN1_OP_FREE_POST: - if (crl->meth->crl_free) - { + case ASN1_OP_FREE_POST: + if (crl->meth->crl_free) { if (!crl->meth->crl_free(crl)) return 0; } @@ -313,18 +299,15 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) int idp_only = 0; /* Set various flags according to IDP */ crl->idp_flags |= IDP_PRESENT; - if (idp->onlyuser > 0) - { + if (idp->onlyuser > 0) { idp_only++; crl->idp_flags |= IDP_ONLYUSER; } - if (idp->onlyCA > 0) - { + if (idp->onlyCA > 0) { idp_only++; crl->idp_flags |= IDP_ONLYCA; } - if (idp->onlyattr > 0) - { + if (idp->onlyattr > 0) { idp_only++; crl->idp_flags |= IDP_ONLYATTR; } @@ -335,8 +318,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) if (idp->indirectCRL > 0) crl->idp_flags |= IDP_INDIRECT; - if (idp->onlysomereasons) - { + if (idp->onlysomereasons) { crl->idp_flags |= IDP_REASONS; if (idp->onlysomereasons->length > 0) crl->idp_reasons = idp->onlysomereasons->data[0]; @@ -417,8 +399,7 @@ static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, { int i; - if (!rev->issuer) - { + if (!rev->issuer) { if (!nm) return 1; if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) @@ -429,8 +410,7 @@ static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, if (!nm) nm = X509_CRL_get_issuer(crl); - for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) - { + for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) { GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); if (gen->type != GEN_DIRNAME) continue; @@ -450,8 +430,7 @@ static int def_crl_lookup(X509_CRL *crl, /* Sort revoked into serial number order if not already sorted. * Do this under a lock to avoid race condition. */ - if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) - { + if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) { CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); sk_X509_REVOKED_sort(crl->crl->revoked); CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); @@ -460,13 +439,11 @@ static int def_crl_lookup(X509_CRL *crl, if(idx < 0) return 0; /* Need to look for matching name */ - for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) - { + for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) { rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) return 0; - if (crl_revoked_issuer_match(crl, issuer, rev)) - { + if (crl_revoked_issuer_match(crl, issuer, rev)) { if (ret) *ret = rev; if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) diff --git a/lib/libssl/src/crypto/asn1/x_info.c b/lib/libssl/src/crypto/asn1/x_info.c index c1b6058d587..07ce15dbd7a 100644 --- a/lib/libssl/src/crypto/asn1/x_info.c +++ b/lib/libssl/src/crypto/asn1/x_info.c @@ -67,8 +67,7 @@ X509_INFO *X509_INFO_new(void) X509_INFO *ret=NULL; ret=(X509_INFO *)malloc(sizeof(X509_INFO)); - if (ret == NULL) - { + if (ret == NULL) { ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); return(NULL); } diff --git a/lib/libssl/src/crypto/asn1/x_name.c b/lib/libssl/src/crypto/asn1/x_name.c index dfd4363aa00..d10ac5acd1e 100644 --- a/lib/libssl/src/crypto/asn1/x_name.c +++ b/lib/libssl/src/crypto/asn1/x_name.c @@ -145,8 +145,7 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) memerr: ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); - if (ret) - { + if (ret) { if (ret->entries) sk_X509_NAME_ENTRY_free(ret->entries); free(ret); @@ -242,14 +241,14 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT } static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne) - { +{ sk_X509_NAME_ENTRY_free(ne); - } +} static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne) - { +{ sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free); - } +} static int x509_name_encode(X509_NAME *a) { @@ -295,12 +294,12 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent, const char *fname, const ASN1_PCTX *pctx) - { +{ if (X509_NAME_print_ex(out, (X509_NAME *)*pval, indent, pctx->nm_flags) <= 0) return 0; return 2; - } +} /* This function generates the canonical encoding of the Name structure. * In it all strings are converted to UTF8, leading, trailing and @@ -316,39 +315,35 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, */ static int x509_name_canon(X509_NAME *a) - { +{ unsigned char *p; STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL; STACK_OF(X509_NAME_ENTRY) *entries = NULL; X509_NAME_ENTRY *entry, *tmpentry = NULL; int i, set = -1, ret = 0; - if (a->canon_enc) - { + if (a->canon_enc) { free(a->canon_enc); a->canon_enc = NULL; } /* Special case: empty X509_NAME => null encoding */ - if (sk_X509_NAME_ENTRY_num(a->entries) == 0) - { + if (sk_X509_NAME_ENTRY_num(a->entries) == 0) { a->canon_enclen = 0; return 1; - } + } intname = sk_STACK_OF_X509_NAME_ENTRY_new_null(); if(!intname) goto err; - for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) - { + for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { entry = sk_X509_NAME_ENTRY_value(a->entries, i); - if(entry->set != set) - { + if(entry->set != set) { entries = sk_X509_NAME_ENTRY_new_null(); if(!entries) goto err; if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) goto err; set = entry->set; - } + } tmpentry = X509_NAME_ENTRY_new(); tmpentry->object = OBJ_dup(entry->object); if (!asn1_string_canon(tmpentry->value, entry->value)) @@ -356,7 +351,7 @@ static int x509_name_canon(X509_NAME *a) if(!sk_X509_NAME_ENTRY_push(entries, tmpentry)) goto err; tmpentry = NULL; - } + } /* Finally generate encoding */ @@ -381,7 +376,7 @@ static int x509_name_canon(X509_NAME *a) sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, local_sk_X509_NAME_ENTRY_pop_free); return ret; - } +} /* Bitmap of all the types of string that will be canonicalized. */ @@ -392,17 +387,16 @@ static int x509_name_canon(X509_NAME *a) static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) - { +{ unsigned char *to, *from; int len, i; /* If type not in bitmask just copy string across */ - if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) - { + if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) { if (!ASN1_STRING_copy(out, in)) return 0; return 1; - } + } out->type = V_ASN1_UTF8STRING; out->length = ASN1_STRING_to_UTF8(&out->data, in); @@ -421,99 +415,87 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) */ /* Ignore leading spaces */ - while((len > 0) && !(*from & 0x80) && isspace(*from)) - { + while((len > 0) && !(*from & 0x80) && isspace(*from)) { from++; len--; - } + } to = from + len - 1; /* Ignore trailing spaces */ - while ((len > 0) && !(*to & 0x80) && isspace(*to)) - { + while ((len > 0) && !(*to & 0x80) && isspace(*to)) { to--; len--; - } + } to = out->data; i = 0; - while(i < len) - { + while(i < len) { /* If MSB set just copy across */ - if (*from & 0x80) - { + if (*from & 0x80) { *to++ = *from++; i++; } /* Collapse multiple spaces */ - else if (isspace(*from)) - { + else if (isspace(*from)) { /* Copy one space across */ *to++ = ' '; /* Ignore subsequent spaces. Note: don't need to * check len here because we know the last * character is a non-space so we can't overflow. */ - do - { + do { from++; i++; - } - while(!(*from & 0x80) && isspace(*from)); - } - else - { + } while(!(*from & 0x80) && isspace(*from)); + } else { *to++ = tolower(*from); from++; i++; - } } + } out->length = to - out->data; return 1; - } +} static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, unsigned char **in) - { +{ int i, len, ltmp; ASN1_VALUE *v; STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname; len = 0; - for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) - { + for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) { v = sk_ASN1_VALUE_value(intname, i); ltmp = ASN1_item_ex_i2d(&v, in, ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1); if (ltmp < 0) return ltmp; len += ltmp; - } - return len; } + return len; +} int X509_NAME_set(X509_NAME **xn, X509_NAME *name) - { +{ X509_NAME *in; if (!xn || !name) return(0); - if (*xn != name) - { + if (*xn != name) { in=X509_NAME_dup(name); - if (in != NULL) - { + if (in != NULL) { X509_NAME_free(*xn); *xn=in; - } } - return(*xn != NULL); } + return(*xn != NULL); +} IMPLEMENT_STACK_OF(X509_NAME_ENTRY) IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) diff --git a/lib/libssl/src/crypto/asn1/x_pkey.c b/lib/libssl/src/crypto/asn1/x_pkey.c index 37d2d93968c..eac134a1ee4 100644 --- a/lib/libssl/src/crypto/asn1/x_pkey.c +++ b/lib/libssl/src/crypto/asn1/x_pkey.c @@ -81,17 +81,14 @@ X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) ret->cipher.cipher=EVP_get_cipherbyname( OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); - if (ret->cipher.cipher == NULL) - { + if (ret->cipher.cipher == NULL) { c.error=ASN1_R_UNSUPPORTED_CIPHER; c.line=__LINE__; goto err; } - if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) - { + if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) { i=ret->enc_algor->parameter->value.octet_string->length; - if (i > EVP_MAX_IV_LENGTH) - { + if (i > EVP_MAX_IV_LENGTH) { c.error=ASN1_R_IV_TOO_LARGE; c.line=__LINE__; goto err; diff --git a/lib/libssl/src/crypto/asn1/x_pubkey.c b/lib/libssl/src/crypto/asn1/x_pubkey.c index 454d50f24cf..1d6ab6580a8 100644 --- a/lib/libssl/src/crypto/asn1/x_pubkey.c +++ b/lib/libssl/src/crypto/asn1/x_pubkey.c @@ -72,8 +72,7 @@ static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) { - if (operation == ASN1_OP_FREE_POST) - { + if (operation == ASN1_OP_FREE_POST) { X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; EVP_PKEY_free(pubkey->pkey); } @@ -95,26 +94,19 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) if ((pk=X509_PUBKEY_new()) == NULL) goto error; - if (pkey->ameth) - { - if (pkey->ameth->pub_encode) - { - if (!pkey->ameth->pub_encode(pk, pkey)) - { + if (pkey->ameth) { + if (pkey->ameth->pub_encode) { + if (!pkey->ameth->pub_encode(pk, pkey)) { X509err(X509_F_X509_PUBKEY_SET, X509_R_PUBLIC_KEY_ENCODE_ERROR); goto error; } - } - else - { + } else { X509err(X509_F_X509_PUBKEY_SET, X509_R_METHOD_NOT_SUPPORTED); goto error; } - } - else - { + } else { X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); goto error; } @@ -136,51 +128,41 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) if (key == NULL) goto error; - if (key->pkey != NULL) - { + if (key->pkey != NULL) { CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); return key->pkey; } if (key->public_key == NULL) goto error; - if ((ret = EVP_PKEY_new()) == NULL) - { + if ((ret = EVP_PKEY_new()) == NULL) { X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); goto error; } - if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) - { + if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) { X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); goto error; } - if (ret->ameth->pub_decode) - { - if (!ret->ameth->pub_decode(ret, key)) - { + if (ret->ameth->pub_decode) { + if (!ret->ameth->pub_decode(ret, key)) { X509err(X509_F_X509_PUBKEY_GET, X509_R_PUBLIC_KEY_DECODE_ERROR); goto error; } - } - else - { + } else { X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); goto error; } /* Check to see if another thread set key->pkey first */ CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); - if (key->pkey) - { + if (key->pkey) { CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); EVP_PKEY_free(ret); ret = key->pkey; - } - else - { + } else { key->pkey = ret; CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); } @@ -208,8 +190,7 @@ EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, pktmp = X509_PUBKEY_get(xpk); X509_PUBKEY_free(xpk); if(!pktmp) return NULL; - if(a) - { + if(a) { EVP_PKEY_free(*a); *a = pktmp; } @@ -244,8 +225,7 @@ RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, EVP_PKEY_free(pkey); if (!key) return NULL; *pp = q; - if (a) - { + if (a) { RSA_free(*a); *a = key; } @@ -258,8 +238,7 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) int ret; if (!a) return 0; pktmp = EVP_PKEY_new(); - if (!pktmp) - { + if (!pktmp) { ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -284,8 +263,7 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, EVP_PKEY_free(pkey); if (!key) return NULL; *pp = q; - if (a) - { + if (a) { DSA_free(*a); *a = key; } @@ -298,8 +276,7 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) int ret; if(!a) return 0; pktmp = EVP_PKEY_new(); - if(!pktmp) - { + if(!pktmp) { ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -323,8 +300,7 @@ EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) EVP_PKEY_free(pkey); if (!key) return(NULL); *pp = q; - if (a) - { + if (a) { EC_KEY_free(*a); *a = key; } @@ -336,8 +312,7 @@ int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) EVP_PKEY *pktmp; int ret; if (!a) return(0); - if ((pktmp = EVP_PKEY_new()) == NULL) - { + if ((pktmp = EVP_PKEY_new()) == NULL) { ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); return(0); } @@ -354,8 +329,7 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, { if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) return 0; - if (penc) - { + if (penc) { if (pub->public_key->data) free(pub->public_key->data); pub->public_key->data = penc; @@ -374,8 +348,7 @@ int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, { if (ppkalg) *ppkalg = pub->algor->algorithm; - if (pk) - { + if (pk) { *pk = pub->public_key->data; *ppklen = pub->public_key->length; } diff --git a/lib/libssl/src/crypto/asn1/x_x509.c b/lib/libssl/src/crypto/asn1/x_x509.c index ff8bd77024a..20448a8e3b1 100644 --- a/lib/libssl/src/crypto/asn1/x_x509.c +++ b/lib/libssl/src/crypto/asn1/x_x509.c @@ -88,7 +88,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, switch(operation) { - case ASN1_OP_NEW_POST: + case ASN1_OP_NEW_POST: ret->valid=0; ret->name = NULL; ret->ex_flags = 0; @@ -104,12 +104,12 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); break; - case ASN1_OP_D2I_POST: + case ASN1_OP_D2I_POST: if (ret->name != NULL) free(ret->name); ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); break; - case ASN1_OP_FREE_POST: + case ASN1_OP_FREE_POST: CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); X509_CERT_AUX_free(ret->aux); ASN1_OCTET_STRING_free(ret->skid); diff --git a/lib/libssl/src/crypto/asn1/x_x509a.c b/lib/libssl/src/crypto/asn1/x_x509a.c index 9449f517be1..287d780830b 100644 --- a/lib/libssl/src/crypto/asn1/x_x509a.c +++ b/lib/libssl/src/crypto/asn1/x_x509a.c @@ -91,8 +91,7 @@ static X509_CERT_AUX *aux_get(X509 *x) int X509_alias_set1(X509 *x, unsigned char *name, int len) { X509_CERT_AUX *aux; - if (!name) - { + if (!name) { if (!x || !x->aux || !x->aux->alias) return 1; ASN1_UTF8STRING_free(x->aux->alias); @@ -107,8 +106,7 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len) int X509_keyid_set1(X509 *x, unsigned char *id, int len) { X509_CERT_AUX *aux; - if (!id) - { + if (!id) { if (!x || !x->aux || !x->aux->keyid) return 1; ASN1_OCTET_STRING_free(x->aux->keyid); -- 2.20.1