提交 27c6d63d 编写于 作者: P Pauli

Improvement the formatting in bn_print.c

Movely removal of unnecessary brackets but some could be bugs addressed too.
Reviewed-by: NRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4202)
上级 0e97f1e1
...@@ -32,14 +32,14 @@ char *BN_bn2hex(const BIGNUM *a) ...@@ -32,14 +32,14 @@ char *BN_bn2hex(const BIGNUM *a)
} }
p = buf; p = buf;
if (a->neg) if (a->neg)
*(p++) = '-'; *p++ = '-';
for (i = a->top - 1; i >= 0; i--) { for (i = a->top - 1; i >= 0; i--) {
for (j = BN_BITS2 - 8; j >= 0; j -= 8) { for (j = BN_BITS2 - 8; j >= 0; j -= 8) {
/* strip leading zeros */ /* strip leading zeros */
v = ((int)(a->d[i] >> (long)j)) & 0xff; v = (int)((a->d[i] >> j) & 0xff);
if (z || (v != 0)) { if (z || v != 0) {
*(p++) = Hex[v >> 4]; *p++ = Hex[v >> 4];
*(p++) = Hex[v & 0x0f]; *p++ = Hex[v & 0x0f];
z = 1; z = 1;
} }
} }
...@@ -71,7 +71,7 @@ char *BN_bn2dec(const BIGNUM *a) ...@@ -71,7 +71,7 @@ char *BN_bn2dec(const BIGNUM *a)
bn_data_num = num / BN_DEC_NUM + 1; bn_data_num = num / BN_DEC_NUM + 1;
bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG)); bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG));
buf = OPENSSL_malloc(tbytes); buf = OPENSSL_malloc(tbytes);
if ((buf == NULL) || (bn_data == NULL)) { if (buf == NULL || bn_data == NULL) {
BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE); BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
...@@ -81,8 +81,8 @@ char *BN_bn2dec(const BIGNUM *a) ...@@ -81,8 +81,8 @@ char *BN_bn2dec(const BIGNUM *a)
p = buf; p = buf;
lp = bn_data; lp = bn_data;
if (BN_is_zero(t)) { if (BN_is_zero(t)) {
*(p++) = '0'; *p++ = '0';
*(p++) = '\0'; *p++ = '\0';
} else { } else {
if (BN_is_negative(t)) if (BN_is_negative(t))
*p++ = '-'; *p++ = '-';
...@@ -130,7 +130,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a) ...@@ -130,7 +130,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
int neg = 0, h, m, i, j, k, c; int neg = 0, h, m, i, j, k, c;
int num; int num;
if ((a == NULL) || (*a == '\0')) if (a == NULL || *a == '\0')
return 0; return 0;
if (*a == '-') { if (*a == '-') {
...@@ -138,10 +138,10 @@ int BN_hex2bn(BIGNUM **bn, const char *a) ...@@ -138,10 +138,10 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
a++; a++;
} }
for (i = 0; i <= (INT_MAX/4) && ossl_isxdigit(a[i]); i++) for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)
continue; continue;
if (i == 0 || i > INT_MAX/4) if (i == 0 || i > INT_MAX / 4)
goto err; goto err;
num = i + neg; num = i + neg;
...@@ -165,7 +165,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a) ...@@ -165,7 +165,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
m = 0; m = 0;
h = 0; h = 0;
while (j > 0) { while (j > 0) {
m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j; m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;
l = 0; l = 0;
for (;;) { for (;;) {
c = a[j - m]; c = a[j - m];
...@@ -179,7 +179,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a) ...@@ -179,7 +179,7 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
break; break;
} }
} }
j -= (BN_BYTES * 2); j -= BN_BYTES * 2;
} }
ret->top = h; ret->top = h;
bn_correct_top(ret); bn_correct_top(ret);
...@@ -203,17 +203,17 @@ int BN_dec2bn(BIGNUM **bn, const char *a) ...@@ -203,17 +203,17 @@ int BN_dec2bn(BIGNUM **bn, const char *a)
int neg = 0, i, j; int neg = 0, i, j;
int num; int num;
if ((a == NULL) || (*a == '\0')) if (a == NULL || *a == '\0')
return 0; return 0;
if (*a == '-') { if (*a == '-') {
neg = 1; neg = 1;
a++; a++;
} }
for (i = 0; i <= (INT_MAX/4) && ossl_isdigit(a[i]); i++) for (i = 0; i <= INT_MAX / 4 && ossl_isdigit(a[i]); i++)
continue; continue;
if (i == 0 || i > INT_MAX/4) if (i == 0 || i > INT_MAX / 4)
goto err; goto err;
num = i + neg; num = i + neg;
...@@ -236,7 +236,7 @@ int BN_dec2bn(BIGNUM **bn, const char *a) ...@@ -236,7 +236,7 @@ int BN_dec2bn(BIGNUM **bn, const char *a)
if (bn_expand(ret, i * 4) == NULL) if (bn_expand(ret, i * 4) == NULL)
goto err; goto err;
j = BN_DEC_NUM - (i % BN_DEC_NUM); j = BN_DEC_NUM - i % BN_DEC_NUM;
if (j == BN_DEC_NUM) if (j == BN_DEC_NUM)
j = 0; j = 0;
l = 0; l = 0;
...@@ -306,16 +306,16 @@ int BN_print(BIO *bp, const BIGNUM *a) ...@@ -306,16 +306,16 @@ int BN_print(BIO *bp, const BIGNUM *a)
int i, j, v, z = 0; int i, j, v, z = 0;
int ret = 0; int ret = 0;
if ((a->neg) && (BIO_write(bp, "-", 1) != 1)) if ((a->neg) && BIO_write(bp, "-", 1) != 1)
goto end; goto end;
if (BN_is_zero(a) && (BIO_write(bp, "0", 1) != 1)) if (BN_is_zero(a) && BIO_write(bp, "0", 1) != 1)
goto end; goto end;
for (i = a->top - 1; i >= 0; i--) { for (i = a->top - 1; i >= 0; i--) {
for (j = BN_BITS2 - 4; j >= 0; j -= 4) { for (j = BN_BITS2 - 4; j >= 0; j -= 4) {
/* strip leading zeros */ /* strip leading zeros */
v = ((int)(a->d[i] >> (long)j)) & 0x0f; v = (int)((a->d[i] >> j) & 0xff);
if (z || (v != 0)) { if (z || v != 0) {
if (BIO_write(bp, &(Hex[v]), 1) != 1) if (BIO_write(bp, &Hex[v], 1) != 1)
goto end; goto end;
z = 1; z = 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册