refactor with macros MP_NO/MP_YES

This commit is contained in:
Francois Perrad 2015-10-25 16:34:43 +01:00 committed by Steffen Jaeckel
parent 0522eef288
commit b9abe0a316
14 changed files with 28 additions and 28 deletions

View File

@ -27,7 +27,7 @@ int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
int res, neg;
/* 2. [modified] b must be odd */
if (mp_iseven (b) == 1) {
if (mp_iseven (b) == MP_YES) {
return MP_VAL;
}
@ -57,13 +57,13 @@ int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
top:
/* 4. while u is even do */
while (mp_iseven (&u) == 1) {
while (mp_iseven (&u) == MP_YES) {
/* 4.1 u = u/2 */
if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
goto LBL_ERR;
}
/* 4.2 if B is odd then */
if (mp_isodd (&B) == 1) {
if (mp_isodd (&B) == MP_YES) {
if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
goto LBL_ERR;
}
@ -75,13 +75,13 @@ top:
}
/* 5. while v is even do */
while (mp_iseven (&v) == 1) {
while (mp_iseven (&v) == MP_YES) {
/* 5.1 v = v/2 */
if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
goto LBL_ERR;
}
/* 5.2 if D is odd then */
if (mp_isodd (&D) == 1) {
if (mp_isodd (&D) == MP_YES) {
/* D = (D-x)/2 */
if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
goto LBL_ERR;
@ -115,7 +115,7 @@ top:
}
/* if not zero goto step 4 */
if (mp_iszero (&u) == 0) {
if (mp_iszero (&u) == MP_NO) {
goto top;
}

View File

@ -26,7 +26,7 @@ int mp_cnt_lsb(mp_int *a)
mp_digit q, qq;
/* easy out */
if (mp_iszero(a) == 1) {
if (mp_iszero(a) == MP_YES) {
return 0;
}

View File

@ -24,7 +24,7 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
int res, n, n2;
/* is divisor zero ? */
if (mp_iszero (b) == 1) {
if (mp_iszero (b) == MP_YES) {
return MP_VAL;
}
@ -106,7 +106,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
int res, n, t, i, norm, neg;
/* is divisor zero ? */
if (mp_iszero (b) == 1) {
if (mp_iszero (b) == MP_YES) {
return MP_VAL;
}

View File

@ -47,7 +47,7 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
}
/* quick outs */
if (b == 1 || mp_iszero(a) == 1) {
if (b == 1 || mp_iszero(a) == MP_YES) {
if (d != NULL) {
*d = 0;
}

View File

@ -89,7 +89,7 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
/* if the modulus is odd or dr != 0 use the montgomery method */
#ifdef BN_MP_EXPTMOD_FAST_C
if (mp_isodd (P) == 1 || dr != 0) {
if (mp_isodd (P) == MP_YES || dr != 0) {
return mp_exptmod_fast (G, X, P, Y, dr);
} else {
#endif

View File

@ -70,7 +70,7 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
}
}
while (mp_iszero(&v) == 0) {
while (mp_iszero(&v) == MP_NO) {
/* make sure v is the largest */
if (mp_cmp_mag(&u, &v) == MP_GT) {
/* swap u and v to make sure v is >= u */

View File

@ -19,13 +19,13 @@
int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
{
/* b cannot be negative */
if (b->sign == MP_NEG || mp_iszero(b) == 1) {
if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) {
return MP_VAL;
}
#ifdef BN_FAST_MP_INVMOD_C
/* if the modulus is odd we can use a faster routine instead */
if (mp_isodd (b) == 1) {
if (mp_isodd (b) == MP_YES) {
return fast_mp_invmod (a, b, c);
}
#endif

View File

@ -22,7 +22,7 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
int res;
/* b cannot be negative */
if (b->sign == MP_NEG || mp_iszero(b) == 1) {
if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) {
return MP_VAL;
}
@ -41,7 +41,7 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
}
/* 2. [modified] if x,y are both even then return an error! */
if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
if (mp_iseven (&x) == MP_YES && mp_iseven (&y) == MP_YES) {
res = MP_VAL;
goto LBL_ERR;
}
@ -58,13 +58,13 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
top:
/* 4. while u is even do */
while (mp_iseven (&u) == 1) {
while (mp_iseven (&u) == MP_YES) {
/* 4.1 u = u/2 */
if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
goto LBL_ERR;
}
/* 4.2 if A or B is odd then */
if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
if (mp_isodd (&A) == MP_YES || mp_isodd (&B) == MP_YES) {
/* A = (A+y)/2, B = (B-x)/2 */
if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
goto LBL_ERR;
@ -83,13 +83,13 @@ top:
}
/* 5. while v is even do */
while (mp_iseven (&v) == 1) {
while (mp_iseven (&v) == MP_YES) {
/* 5.1 v = v/2 */
if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
goto LBL_ERR;
}
/* 5.2 if C or D is odd then */
if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
if (mp_isodd (&C) == MP_YES || mp_isodd (&D) == MP_YES) {
/* C = (C+y)/2, D = (D-x)/2 */
if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
goto LBL_ERR;
@ -137,7 +137,7 @@ top:
}
/* if not zero goto step 4 */
if (mp_iszero (&u) == 0)
if (mp_iszero (&u) == MP_NO)
goto top;
/* now a = C, b = D, gcd == g*v */

View File

@ -30,7 +30,7 @@ int mp_jacobi (mp_int * a, mp_int * p, int *c)
}
/* step 1. if a == 0, return 0 */
if (mp_iszero (a) == 1) {
if (mp_iszero (a) == MP_YES) {
*c = 0;
return MP_OKAY;
}

View File

@ -84,7 +84,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
if ((err = mp_sub_d(a, (a->dp[0] & 3) + 1, a)) != MP_OKAY) { return err; };
}
} else {
if (mp_iseven(a) == 1) {
if (mp_iseven(a) == MP_YES) {
/* force odd */
if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
return err;

View File

@ -73,7 +73,7 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
}
/* set the sign only if a != 0 */
if (mp_iszero(a) != 1) {
if (mp_iszero(a) != MP_YES) {
a->sign = neg;
}
return MP_OKAY;

View File

@ -26,7 +26,7 @@ int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
}
x = 0;
while (mp_iszero (&t) == 0) {
while (mp_iszero (&t) == MP_NO) {
#ifndef MP_8BIT
b[x++] = (unsigned char) (t.dp[0] & 255);
#else

View File

@ -29,7 +29,7 @@ int mp_toradix (mp_int * a, char *str, int radix)
}
/* quick out if its zero */
if (mp_iszero(a) == 1) {
if (mp_iszero(a) == MP_YES) {
*str++ = '0';
*str = '\0';
return MP_OKAY;
@ -47,7 +47,7 @@ int mp_toradix (mp_int * a, char *str, int radix)
}
digs = 0;
while (mp_iszero (&t) == 0) {
while (mp_iszero (&t) == MP_NO) {
if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
mp_clear (&t);
return res;

View File

@ -56,7 +56,7 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
}
digs = 0;
while (mp_iszero (&t) == 0) {
while (mp_iszero (&t) == MP_NO) {
if (--maxlen < 1) {
/* no more room */
break;