remove MP_IS_* macros

This commit is contained in:
Daniel Mendler 2019-10-24 17:43:31 +02:00
parent f8b2f5d6fe
commit a44e68e652
No known key found for this signature in database
GPG Key ID: D88ADB2A2693CA43
30 changed files with 53 additions and 57 deletions

View File

@ -12,7 +12,7 @@ mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
/* fast path for a == c */ /* fast path for a == c */
if (a == c && if (a == c &&
!MP_IS_ZERO(c) && !mp_iszero(c) &&
c->sign == MP_ZPOS && c->sign == MP_ZPOS &&
c->dp[0] + b < MP_DIGIT_MAX) { c->dp[0] + b < MP_DIGIT_MAX) {
c->dp[0] += b; c->dp[0] += b;

View File

@ -14,7 +14,7 @@ int mp_cnt_lsb(const mp_int *a)
mp_digit q, qq; mp_digit q, qq;
/* easy out */ /* easy out */
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
return 0; return 0;
} }

View File

@ -10,7 +10,7 @@ int mp_count_bits(const mp_int *a)
mp_digit q; mp_digit q;
/* shortcut */ /* shortcut */
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
return 0; return 0;
} }

View File

@ -8,7 +8,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
mp_err err; mp_err err;
/* is divisor zero ? */ /* is divisor zero ? */
if (MP_IS_ZERO(b)) { if (mp_iszero(b)) {
return MP_VAL; return MP_VAL;
} }

View File

@ -18,7 +18,7 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
} }
/* quick outs */ /* quick outs */
if ((b == 1u) || MP_IS_ZERO(a)) { if ((b == 1u) || mp_iszero(a)) {
if (d != NULL) { if (d != NULL) {
*d = 0; *d = 0;
} }

View File

@ -62,7 +62,7 @@ LBL_ERR:
} }
/* if the modulus is odd or dr != 0 use the montgomery method */ /* if the modulus is odd or dr != 0 use the montgomery method */
if (MP_HAS(S_MP_EXPTMOD_FAST) && (MP_IS_ODD(P) || (dr != 0))) { if (MP_HAS(S_MP_EXPTMOD_FAST) && (mp_isodd(P) || (dr != 0))) {
return s_mp_exptmod_fast(G, X, P, Y, dr); return s_mp_exptmod_fast(G, X, P, Y, dr);
} else if (MP_HAS(S_MP_EXPTMOD)) { } else if (MP_HAS(S_MP_EXPTMOD)) {
/* otherwise use the generic Barrett reduction technique */ /* otherwise use the generic Barrett reduction technique */

View File

@ -24,7 +24,7 @@ mp_err mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp
if ((err = mp_copy(b, &v3)) != MP_OKAY) goto LBL_ERR; if ((err = mp_copy(b, &v3)) != MP_OKAY) goto LBL_ERR;
/* loop while v3 != 0 */ /* loop while v3 != 0 */
while (!MP_IS_ZERO(&v3)) { while (!mp_iszero(&v3)) {
/* q = u3/v3 */ /* q = u3/v3 */
if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) goto LBL_ERR; if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) goto LBL_ERR;

View File

@ -11,10 +11,10 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
mp_err err; mp_err err;
/* either zero than gcd is the largest */ /* either zero than gcd is the largest */
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
return mp_abs(b, c); return mp_abs(b, c);
} }
if (MP_IS_ZERO(b)) { if (mp_iszero(b)) {
return mp_abs(a, c); return mp_abs(a, c);
} }
@ -59,7 +59,7 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
} }
} }
while (!MP_IS_ZERO(&v)) { while (!mp_iszero(&v)) {
/* make sure v is the largest */ /* make sure v is the largest */
if (mp_cmp_mag(&u, &v) == MP_GT) { if (mp_cmp_mag(&u, &v) == MP_GT) {
/* swap u and v to make sure v is >= u */ /* swap u and v to make sure v is >= u */

View File

@ -12,7 +12,7 @@ mp_err mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
} }
/* if the modulus is odd we can use a faster routine instead */ /* if the modulus is odd we can use a faster routine instead */
if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) { if (MP_HAS(S_MP_INVMOD_FAST) && mp_isodd(b)) {
return s_mp_invmod_fast(a, b, c); return s_mp_invmod_fast(a, b, c);
} }

View File

@ -40,7 +40,7 @@ mp_err mp_is_square(const mp_int *arg, mp_bool *ret)
return MP_VAL; return MP_VAL;
} }
if (MP_IS_ZERO(arg)) { if (mp_iszero(arg)) {
return MP_OKAY; return MP_OKAY;
} }

View File

@ -25,7 +25,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
static const int table[8] = {0, 1, 0, -1, 0, -1, 0, 1}; static const int table[8] = {0, 1, 0, -1, 0, -1, 0, 1};
if (MP_IS_ZERO(p)) { if (mp_iszero(p)) {
if ((a->used == 1) && (a->dp[0] == 1u)) { if ((a->used == 1) && (a->dp[0] == 1u)) {
*c = 1; *c = 1;
} else { } else {
@ -34,7 +34,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
return MP_OKAY; return MP_OKAY;
} }
if (MP_IS_EVEN(a) && MP_IS_EVEN(p)) { if (mp_iseven(a) && mp_iseven(p)) {
*c = 0; *c = 0;
return MP_OKAY; return MP_OKAY;
} }
@ -69,7 +69,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
} }
for (;;) { for (;;) {
if (MP_IS_ZERO(&a1)) { if (mp_iszero(&a1)) {
if (mp_cmp_d(&p1, 1uL) == MP_EQ) { if (mp_cmp_d(&p1, 1uL) == MP_EQ) {
*c = k; *c = k;
goto LBL_KRON; goto LBL_KRON;

View File

@ -9,7 +9,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
return MP_VAL; return MP_VAL;
} }
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
return MP_VAL; return MP_VAL;
} }

View File

@ -15,7 +15,7 @@ mp_err mp_lshd(mp_int *a, int b)
return MP_OKAY; return MP_OKAY;
} }
/* no need to shift 0 around */ /* no need to shift 0 around */
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
return MP_OKAY; return MP_OKAY;
} }

View File

@ -17,7 +17,7 @@ mp_err mp_mod(const mp_int *a, const mp_int *b, mp_int *c)
goto LBL_ERR; goto LBL_ERR;
} }
if (MP_IS_ZERO(&t) || (t.sign == b->sign)) { if (mp_iszero(&t) || (t.sign == b->sign)) {
err = MP_OKAY; err = MP_OKAY;
mp_exch(&t, c); mp_exch(&t, c);
} else { } else {

View File

@ -13,7 +13,7 @@ mp_err mp_neg(const mp_int *a, mp_int *b)
} }
} }
if (!MP_IS_ZERO(b)) { if (!mp_iszero(b)) {
b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS; b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;
} else { } else {
b->sign = MP_ZPOS; b->sign = MP_ZPOS;

View File

@ -112,7 +112,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
mp_set_u32(&T1z, (uint32_t)((2 * a) + 5)); mp_set_u32(&T1z, (uint32_t)((2 * a) + 5));
if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) goto LBL_FU_ERR; if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) goto LBL_FU_ERR;
if (MP_IS_ZERO(&sz) && (mp_cmp(&tz, &T1z) == MP_EQ)) { if (mp_iszero(&sz) && (mp_cmp(&tz, &T1z) == MP_EQ)) {
*result = MP_YES; *result = MP_YES;
} }

View File

@ -39,7 +39,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
} }
/* N must be odd */ /* N must be odd */
if (MP_IS_EVEN(a)) { if (mp_iseven(a)) {
return MP_OKAY; return MP_OKAY;
} }
/* N is not a perfect square: floor(sqrt(N))^2 != N */ /* N is not a perfect square: floor(sqrt(N))^2 != N */

View File

@ -58,7 +58,7 @@ mp_err mp_prime_next_prime(mp_int *a, int t, mp_bool bbs_style)
} }
} }
} else { } else {
if (MP_IS_EVEN(a)) { if (mp_iseven(a)) {
/* force odd */ /* force odd */
if ((err = mp_sub_d(a, 1uL, a)) != MP_OKAY) { if ((err = mp_sub_d(a, 1uL, a)) != MP_OKAY) {
return err; return err;

View File

@ -206,7 +206,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
if ((err = mp_mul(&U2mz, &Uz, &T4z)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_mul(&U2mz, &Uz, &T4z)) != MP_OKAY) goto LBL_LS_ERR;
if ((err = s_mp_mul_si(&T4z, Ds, &T4z)) != MP_OKAY) goto LBL_LS_ERR; if ((err = s_mp_mul_si(&T4z, Ds, &T4z)) != MP_OKAY) goto LBL_LS_ERR;
if ((err = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
if (MP_IS_ODD(&Uz)) { if (mp_isodd(&Uz)) {
if ((err = mp_add(&Uz, a, &Uz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_add(&Uz, a, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
} }
/* CZ /* CZ
@ -214,16 +214,16 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
* Thomas R. Nicely used GMP's mpz_fdiv_q_2exp(). * Thomas R. Nicely used GMP's mpz_fdiv_q_2exp().
* But mp_div_2() does not do so, it is truncating instead. * But mp_div_2() does not do so, it is truncating instead.
*/ */
oddness = MP_IS_ODD(&Uz) ? MP_YES : MP_NO; oddness = mp_isodd(&Uz) ? MP_YES : MP_NO;
if ((err = mp_div_2(&Uz, &Uz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_div_2(&Uz, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
if ((Uz.sign == MP_NEG) && (oddness != MP_NO)) { if ((Uz.sign == MP_NEG) && (oddness != MP_NO)) {
if ((err = mp_sub_d(&Uz, 1uL, &Uz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_sub_d(&Uz, 1uL, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
} }
if ((err = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
if (MP_IS_ODD(&Vz)) { if (mp_isodd(&Vz)) {
if ((err = mp_add(&Vz, a, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_add(&Vz, a, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
} }
oddness = MP_IS_ODD(&Vz) ? MP_YES : MP_NO; oddness = mp_isodd(&Vz) ? MP_YES : MP_NO;
if ((err = mp_div_2(&Vz, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_div_2(&Vz, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
if ((Vz.sign == MP_NEG) && (oddness != MP_NO)) { if ((Vz.sign == MP_NEG) && (oddness != MP_NO)) {
if ((err = mp_sub_d(&Vz, 1uL, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_sub_d(&Vz, 1uL, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
@ -239,7 +239,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
/* If U_d or V_d is congruent to 0 mod N, then N is a prime or a /* If U_d or V_d is congruent to 0 mod N, then N is a prime or a
strong Lucas pseudoprime. */ strong Lucas pseudoprime. */
if (MP_IS_ZERO(&Uz) || MP_IS_ZERO(&Vz)) { if (mp_iszero(&Uz) || mp_iszero(&Vz)) {
*result = MP_YES; *result = MP_YES;
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
@ -262,7 +262,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
if ((err = mp_sqr(&Vz, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_sqr(&Vz, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
if ((err = mp_sub(&Vz, &Q2kdz, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_sub(&Vz, &Q2kdz, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
if ((err = mp_mod(&Vz, a, &Vz)) != MP_OKAY) goto LBL_LS_ERR; if ((err = mp_mod(&Vz, a, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
if (MP_IS_ZERO(&Vz)) { if (mp_iszero(&Vz)) {
*result = MP_YES; *result = MP_YES;
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }

View File

@ -15,7 +15,7 @@ mp_err mp_radix_size(const mp_int *a, int radix, size_t *size)
return MP_VAL; return MP_VAL;
} }
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
*size = 2; *size = 2;
return MP_OKAY; return MP_OKAY;
} }

View File

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

View File

@ -30,7 +30,7 @@ mp_err mp_set_double(mp_int *a, double b)
return err; return err;
} }
if (((cast.bits >> 63) != 0uLL) && !MP_IS_ZERO(a)) { if (((cast.bits >> 63) != 0uLL) && !mp_iszero(a)) {
a->sign = MP_NEG; a->sign = MP_NEG;
} }

View File

@ -15,7 +15,7 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret)
} }
/* easy out */ /* easy out */
if (MP_IS_ZERO(arg)) { if (mp_iszero(arg)) {
mp_zero(ret); mp_zero(ret);
return MP_OKAY; return MP_OKAY;
} }

View File

@ -51,7 +51,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
/* Q = prime - 1 */ /* Q = prime - 1 */
mp_zero(&S); mp_zero(&S);
/* S = 0 */ /* S = 0 */
while (MP_IS_EVEN(&Q)) { while (mp_iseven(&Q)) {
if ((err = mp_div_2(&Q, &Q)) != MP_OKAY) goto cleanup; if ((err = mp_div_2(&Q, &Q)) != MP_OKAY) goto cleanup;
/* Q = Q / 2 */ /* Q = Q / 2 */
if ((err = mp_add_d(&S, 1uL, &S)) != MP_OKAY) goto cleanup; if ((err = mp_add_d(&S, 1uL, &S)) != MP_OKAY) goto cleanup;

View File

@ -12,7 +12,7 @@ mp_err mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
/* fast path for a == c */ /* fast path for a == c */
if (a == c && if (a == c &&
!MP_IS_ZERO(c) && !mp_iszero(c) &&
c->sign == MP_ZPOS && c->sign == MP_ZPOS &&
c->dp[0] > b) { c->dp[0] > b) {
c->dp[0] -= b; c->dp[0] -= b;

View File

@ -42,7 +42,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
} }
/* quick out if its zero */ /* quick out if its zero */
if (MP_IS_ZERO(a)) { if (mp_iszero(a)) {
*str++ = '0'; *str++ = '0';
*str = '\0'; *str = '\0';
if (written != NULL) { if (written != NULL) {
@ -68,7 +68,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
--maxlen; --maxlen;
} }
digs = 0u; digs = 0u;
while (!MP_IS_ZERO(&t)) { while (!mp_iszero(&t)) {
if (--maxlen < 1u) { if (--maxlen < 1u) {
/* no more room */ /* no more room */
err = MP_BUF; err = MP_BUF;

View File

@ -37,11 +37,11 @@ mp_err s_mp_div_small(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
sign = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; sign = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
if (c != NULL) { if (c != NULL) {
mp_exch(c, &q); mp_exch(c, &q);
c->sign = MP_IS_ZERO(c) ? MP_ZPOS : sign; c->sign = mp_iszero(c) ? MP_ZPOS : sign;
} }
if (d != NULL) { if (d != NULL) {
mp_exch(d, &ta); mp_exch(d, &ta);
d->sign = MP_IS_ZERO(d) ? MP_ZPOS : a->sign; d->sign = mp_iszero(d) ? MP_ZPOS : a->sign;
} }
LBL_ERR: LBL_ERR:
mp_clear_multi(&ta, &tb, &tq, &q, NULL); mp_clear_multi(&ta, &tb, &tq, &q, NULL);

View File

@ -16,7 +16,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
mp_err err; mp_err err;
/* 2. [modified] b must be odd */ /* 2. [modified] b must be odd */
if (MP_IS_EVEN(b)) { if (mp_iseven(b)) {
return MP_VAL; return MP_VAL;
} }
@ -32,7 +32,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
if ((err = mp_mod(a, b, &y)) != MP_OKAY) goto LBL_ERR; if ((err = mp_mod(a, b, &y)) != MP_OKAY) goto LBL_ERR;
/* if one of x,y is zero return an error! */ /* if one of x,y is zero return an error! */
if (MP_IS_ZERO(&x) || MP_IS_ZERO(&y)) { if (mp_iszero(&x) || mp_iszero(&y)) {
err = MP_VAL; err = MP_VAL;
goto LBL_ERR; goto LBL_ERR;
} }
@ -44,12 +44,12 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
top: top:
/* 4. while u is even do */ /* 4. while u is even do */
while (MP_IS_EVEN(&u)) { while (mp_iseven(&u)) {
/* 4.1 u = u/2 */ /* 4.1 u = u/2 */
if ((err = mp_div_2(&u, &u)) != MP_OKAY) goto LBL_ERR; if ((err = mp_div_2(&u, &u)) != MP_OKAY) goto LBL_ERR;
/* 4.2 if B is odd then */ /* 4.2 if B is odd then */
if (MP_IS_ODD(&B)) { if (mp_isodd(&B)) {
if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) goto LBL_ERR; if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) goto LBL_ERR;
} }
/* B = B/2 */ /* B = B/2 */
@ -57,12 +57,12 @@ top:
} }
/* 5. while v is even do */ /* 5. while v is even do */
while (MP_IS_EVEN(&v)) { while (mp_iseven(&v)) {
/* 5.1 v = v/2 */ /* 5.1 v = v/2 */
if ((err = mp_div_2(&v, &v)) != MP_OKAY) goto LBL_ERR; if ((err = mp_div_2(&v, &v)) != MP_OKAY) goto LBL_ERR;
/* 5.2 if D is odd then */ /* 5.2 if D is odd then */
if (MP_IS_ODD(&D)) { if (mp_isodd(&D)) {
/* D = (D-x)/2 */ /* D = (D-x)/2 */
if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) goto LBL_ERR; if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) goto LBL_ERR;
} }
@ -84,7 +84,7 @@ top:
} }
/* if not zero goto step 4 */ /* if not zero goto step 4 */
if (!MP_IS_ZERO(&u)) { if (!mp_iszero(&u)) {
goto top; goto top;
} }

View File

@ -10,7 +10,7 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
mp_err err; mp_err err;
/* b cannot be negative */ /* b cannot be negative */
if ((b->sign == MP_NEG) || MP_IS_ZERO(b)) { if ((b->sign == MP_NEG) || mp_iszero(b)) {
return MP_VAL; return MP_VAL;
} }
@ -25,7 +25,7 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
if ((err = mp_copy(b, &y)) != MP_OKAY) goto LBL_ERR; if ((err = mp_copy(b, &y)) != MP_OKAY) goto LBL_ERR;
/* 2. [modified] if x,y are both even then return an error! */ /* 2. [modified] if x,y are both even then return an error! */
if (MP_IS_EVEN(&x) && MP_IS_EVEN(&y)) { if (mp_iseven(&x) && mp_iseven(&y)) {
err = MP_VAL; err = MP_VAL;
goto LBL_ERR; goto LBL_ERR;
} }
@ -38,12 +38,12 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
top: top:
/* 4. while u is even do */ /* 4. while u is even do */
while (MP_IS_EVEN(&u)) { while (mp_iseven(&u)) {
/* 4.1 u = u/2 */ /* 4.1 u = u/2 */
if ((err = mp_div_2(&u, &u)) != MP_OKAY) goto LBL_ERR; if ((err = mp_div_2(&u, &u)) != MP_OKAY) goto LBL_ERR;
/* 4.2 if A or B is odd then */ /* 4.2 if A or B is odd then */
if (MP_IS_ODD(&A) || MP_IS_ODD(&B)) { if (mp_isodd(&A) || mp_isodd(&B)) {
/* A = (A+y)/2, B = (B-x)/2 */ /* A = (A+y)/2, B = (B-x)/2 */
if ((err = mp_add(&A, &y, &A)) != MP_OKAY) goto LBL_ERR; if ((err = mp_add(&A, &y, &A)) != MP_OKAY) goto LBL_ERR;
if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) goto LBL_ERR; if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) goto LBL_ERR;
@ -54,12 +54,12 @@ top:
} }
/* 5. while v is even do */ /* 5. while v is even do */
while (MP_IS_EVEN(&v)) { while (mp_iseven(&v)) {
/* 5.1 v = v/2 */ /* 5.1 v = v/2 */
if ((err = mp_div_2(&v, &v)) != MP_OKAY) goto LBL_ERR; if ((err = mp_div_2(&v, &v)) != MP_OKAY) goto LBL_ERR;
/* 5.2 if C or D is odd then */ /* 5.2 if C or D is odd then */
if (MP_IS_ODD(&C) || MP_IS_ODD(&D)) { if (mp_isodd(&C) || mp_isodd(&D)) {
/* C = (C+y)/2, D = (D-x)/2 */ /* C = (C+y)/2, D = (D-x)/2 */
if ((err = mp_add(&C, &y, &C)) != MP_OKAY) goto LBL_ERR; if ((err = mp_add(&C, &y, &C)) != MP_OKAY) goto LBL_ERR;
if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) goto LBL_ERR; if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) goto LBL_ERR;
@ -87,7 +87,7 @@ top:
} }
/* if not zero goto step 4 */ /* if not zero goto step 4 */
if (!MP_IS_ZERO(&u)) { if (!mp_iszero(&u)) {
goto top; goto top;
} }

View File

@ -1,3 +1,4 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */ /* SPDX-License-Identifier: Unlicense */
@ -149,11 +150,6 @@ extern void MP_FREE(void *mem, size_t size);
/* Static assertion */ /* Static assertion */
#define MP_STATIC_ASSERT(msg, cond) typedef char mp_static_assert_##msg[(cond) ? 1 : -1]; #define MP_STATIC_ASSERT(msg, cond) typedef char mp_static_assert_##msg[(cond) ? 1 : -1];
/* ---> Basic Manipulations <--- */
#define MP_IS_ZERO(a) ((a)->used == 0)
#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
#define MP_IS_ODD(a) (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
#define MP_SIZEOF_BITS(type) ((size_t)CHAR_BIT * sizeof(type)) #define MP_SIZEOF_BITS(type) ((size_t)CHAR_BIT * sizeof(type))
#define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))) #define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))