diff options
| author | tedu <> | 2014-04-18 00:58:49 +0000 |
|---|---|---|
| committer | tedu <> | 2014-04-18 00:58:49 +0000 |
| commit | 8ce5191a60e78339477aa03769b244ec94d3a7bd (patch) | |
| tree | b216ca6fba673789f2c494699c4cf41d23337bfa /src/lib/libcrypto/asn1/f_int.c | |
| parent | 966ce64f00531da04d9506f88feeb1ae5745faab (diff) | |
| download | openbsd-8ce5191a60e78339477aa03769b244ec94d3a7bd.tar.gz openbsd-8ce5191a60e78339477aa03769b244ec94d3a7bd.tar.bz2 openbsd-8ce5191a60e78339477aa03769b244ec94d3a7bd.zip | |
lob a few more knf grenades in here to soften things up.
Diffstat (limited to 'src/lib/libcrypto/asn1/f_int.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/f_int.c | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c index 66632f2dc4..6cea1f8485 100644 --- a/src/lib/libcrypto/asn1/f_int.c +++ b/src/lib/libcrypto/asn1/f_int.c | |||
| @@ -69,23 +69,17 @@ int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | |||
| 69 | 69 | ||
| 70 | if (a == NULL) return(0); | 70 | if (a == NULL) return(0); |
| 71 | 71 | ||
| 72 | if (a->type & V_ASN1_NEG) | 72 | if (a->type & V_ASN1_NEG) { |
| 73 | { | ||
| 74 | if (BIO_write(bp, "-", 1) != 1) goto err; | 73 | if (BIO_write(bp, "-", 1) != 1) goto err; |
| 75 | n = 1; | 74 | n = 1; |
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | if (a->length == 0) | 77 | if (a->length == 0) { |
| 79 | { | ||
| 80 | if (BIO_write(bp,"00",2) != 2) goto err; | 78 | if (BIO_write(bp,"00",2) != 2) goto err; |
| 81 | n += 2; | 79 | n += 2; |
| 82 | } | 80 | } else { |
| 83 | else | 81 | for (i=0; i<a->length; i++) { |
| 84 | { | 82 | if ((i != 0) && (i%35 == 0)) { |
| 85 | for (i=0; i<a->length; i++) | ||
| 86 | { | ||
| 87 | if ((i != 0) && (i%35 == 0)) | ||
| 88 | { | ||
| 89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | 83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; |
| 90 | n+=2; | 84 | n+=2; |
| 91 | } | 85 | } |
| @@ -111,8 +105,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
| 111 | bs->type=V_ASN1_INTEGER; | 105 | bs->type=V_ASN1_INTEGER; |
| 112 | 106 | ||
| 113 | bufsize=BIO_gets(bp,buf,size); | 107 | bufsize=BIO_gets(bp,buf,size); |
| 114 | for (;;) | 108 | for (;;) { |
| 115 | { | ||
| 116 | if (bufsize < 1) goto err_sl; | 109 | if (bufsize < 1) goto err_sl; |
| 117 | i=bufsize; | 110 | i=bufsize; |
| 118 | if (buf[i-1] == '\n') buf[--i]='\0'; | 111 | 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) | |||
| 121 | if (i == 0) goto err_sl; | 114 | if (i == 0) goto err_sl; |
| 122 | again=(buf[i-1] == '\\'); | 115 | again=(buf[i-1] == '\\'); |
| 123 | 116 | ||
| 124 | for (j=0; j<i; j++) | 117 | for (j=0; j<i; j++) { |
| 125 | { | ||
| 126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | 118 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || |
| 127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | 119 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || |
| 128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | 120 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) { |
| 129 | { | ||
| 130 | i=j; | 121 | i=j; |
| 131 | break; | 122 | break; |
| 132 | } | 123 | } |
| @@ -137,32 +128,27 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
| 137 | if (i < 2) goto err_sl; | 128 | if (i < 2) goto err_sl; |
| 138 | 129 | ||
| 139 | bufp=(unsigned char *)buf; | 130 | bufp=(unsigned char *)buf; |
| 140 | if (first) | 131 | if (first) { |
| 141 | { | ||
| 142 | first=0; | 132 | first=0; |
| 143 | if ((bufp[0] == '0') && (buf[1] == '0')) | 133 | if ((bufp[0] == '0') && (buf[1] == '0')) { |
| 144 | { | ||
| 145 | bufp+=2; | 134 | bufp+=2; |
| 146 | i-=2; | 135 | i-=2; |
| 147 | } | 136 | } |
| 148 | } | 137 | } |
| 149 | k=0; | 138 | k=0; |
| 150 | i-=again; | 139 | i-=again; |
| 151 | if (i%2 != 0) | 140 | if (i%2 != 0) { |
| 152 | { | ||
| 153 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | 141 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); |
| 154 | goto err; | 142 | goto err; |
| 155 | } | 143 | } |
| 156 | i/=2; | 144 | i/=2; |
| 157 | if (num+i > slen) | 145 | if (num+i > slen) { |
| 158 | { | ||
| 159 | if (s == NULL) | 146 | if (s == NULL) |
| 160 | sp=(unsigned char *)malloc( | 147 | sp=(unsigned char *)malloc( |
| 161 | (unsigned int)num+i*2); | 148 | (unsigned int)num+i*2); |
| 162 | else | 149 | else |
| 163 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | 150 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); |
| 164 | if (sp == NULL) | 151 | if (sp == NULL) { |
| 165 | { | ||
| 166 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 152 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); |
| 167 | if (s != NULL) free(s); | 153 | if (s != NULL) free(s); |
| 168 | goto err; | 154 | goto err; |
| @@ -170,10 +156,8 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
| 170 | s=sp; | 156 | s=sp; |
| 171 | slen=num+i*2; | 157 | slen=num+i*2; |
| 172 | } | 158 | } |
| 173 | for (j=0; j<i; j++,k+=2) | 159 | for (j=0; j<i; j++,k+=2) { |
| 174 | { | 160 | for (n=0; n<2; n++) { |
| 175 | for (n=0; n<2; n++) | ||
| 176 | { | ||
| 177 | m=bufp[k+n]; | 161 | m=bufp[k+n]; |
| 178 | if ((m >= '0') && (m <= '9')) | 162 | if ((m >= '0') && (m <= '9')) |
| 179 | m-='0'; | 163 | m-='0'; |
| @@ -181,8 +165,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
| 181 | m=m-'a'+10; | 165 | m=m-'a'+10; |
| 182 | else if ((m >= 'A') && (m <= 'F')) | 166 | else if ((m >= 'A') && (m <= 'F')) |
| 183 | m=m-'A'+10; | 167 | m=m-'A'+10; |
| 184 | else | 168 | else { |
| 185 | { | ||
| 186 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | 169 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); |
| 187 | goto err; | 170 | goto err; |
| 188 | } | 171 | } |
| @@ -200,8 +183,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
| 200 | bs->data=s; | 183 | bs->data=s; |
| 201 | ret=1; | 184 | ret=1; |
| 202 | err: | 185 | err: |
| 203 | if (0) | 186 | if (0) { |
| 204 | { | ||
| 205 | err_sl: | 187 | err_sl: |
| 206 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | 188 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); |
| 207 | } | 189 | } |
