Skip to content

Commit a44e68e

Browse files
committed
remove MP_IS_* macros
1 parent f8b2f5d commit a44e68e

30 files changed

+53
-57
lines changed

mp_add_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
1212

1313
/* fast path for a == c */
1414
if (a == c &&
15-
!MP_IS_ZERO(c) &&
15+
!mp_iszero(c) &&
1616
c->sign == MP_ZPOS &&
1717
c->dp[0] + b < MP_DIGIT_MAX) {
1818
c->dp[0] += b;

mp_cnt_lsb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int mp_cnt_lsb(const mp_int *a)
1414
mp_digit q, qq;
1515

1616
/* easy out */
17-
if (MP_IS_ZERO(a)) {
17+
if (mp_iszero(a)) {
1818
return 0;
1919
}
2020

mp_count_bits.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int mp_count_bits(const mp_int *a)
1010
mp_digit q;
1111

1212
/* shortcut */
13-
if (MP_IS_ZERO(a)) {
13+
if (mp_iszero(a)) {
1414
return 0;
1515
}
1616

mp_div.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
88
mp_err err;
99

1010
/* is divisor zero ? */
11-
if (MP_IS_ZERO(b)) {
11+
if (mp_iszero(b)) {
1212
return MP_VAL;
1313
}
1414

mp_div_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
1818
}
1919

2020
/* quick outs */
21-
if ((b == 1u) || MP_IS_ZERO(a)) {
21+
if ((b == 1u) || mp_iszero(a)) {
2222
if (d != NULL) {
2323
*d = 0;
2424
}

mp_exptmod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
6262
}
6363

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

mp_exteuclid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mp_err mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp
2424
if ((err = mp_copy(b, &v3)) != MP_OKAY) goto LBL_ERR;
2525

2626
/* loop while v3 != 0 */
27-
while (!MP_IS_ZERO(&v3)) {
27+
while (!mp_iszero(&v3)) {
2828
/* q = u3/v3 */
2929
if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) goto LBL_ERR;
3030

mp_gcd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
1111
mp_err err;
1212

1313
/* either zero than gcd is the largest */
14-
if (MP_IS_ZERO(a)) {
14+
if (mp_iszero(a)) {
1515
return mp_abs(b, c);
1616
}
17-
if (MP_IS_ZERO(b)) {
17+
if (mp_iszero(b)) {
1818
return mp_abs(a, c);
1919
}
2020

@@ -59,7 +59,7 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
5959
}
6060
}
6161

62-
while (!MP_IS_ZERO(&v)) {
62+
while (!mp_iszero(&v)) {
6363
/* make sure v is the largest */
6464
if (mp_cmp_mag(&u, &v) == MP_GT) {
6565
/* swap u and v to make sure v is >= u */

mp_invmod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mp_err mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
1212
}
1313

1414
/* if the modulus is odd we can use a faster routine instead */
15-
if (MP_HAS(S_MP_INVMOD_FAST) && MP_IS_ODD(b)) {
15+
if (MP_HAS(S_MP_INVMOD_FAST) && mp_isodd(b)) {
1616
return s_mp_invmod_fast(a, b, c);
1717
}
1818

mp_is_square.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mp_err mp_is_square(const mp_int *arg, mp_bool *ret)
4040
return MP_VAL;
4141
}
4242

43-
if (MP_IS_ZERO(arg)) {
43+
if (mp_iszero(arg)) {
4444
return MP_OKAY;
4545
}
4646

mp_kronecker.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
2525

2626
static const int table[8] = {0, 1, 0, -1, 0, -1, 0, 1};
2727

28-
if (MP_IS_ZERO(p)) {
28+
if (mp_iszero(p)) {
2929
if ((a->used == 1) && (a->dp[0] == 1u)) {
3030
*c = 1;
3131
} else {
@@ -34,7 +34,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
3434
return MP_OKAY;
3535
}
3636

37-
if (MP_IS_EVEN(a) && MP_IS_EVEN(p)) {
37+
if (mp_iseven(a) && mp_iseven(p)) {
3838
*c = 0;
3939
return MP_OKAY;
4040
}
@@ -69,7 +69,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
6969
}
7070

7171
for (;;) {
72-
if (MP_IS_ZERO(&a1)) {
72+
if (mp_iszero(&a1)) {
7373
if (mp_cmp_d(&p1, 1uL) == MP_EQ) {
7474
*c = k;
7575
goto LBL_KRON;

mp_log_u32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
99
return MP_VAL;
1010
}
1111

12-
if (MP_IS_ZERO(a)) {
12+
if (mp_iszero(a)) {
1313
return MP_VAL;
1414
}
1515

mp_lshd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mp_err mp_lshd(mp_int *a, int b)
1515
return MP_OKAY;
1616
}
1717
/* no need to shift 0 around */
18-
if (MP_IS_ZERO(a)) {
18+
if (mp_iszero(a)) {
1919
return MP_OKAY;
2020
}
2121

mp_mod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mp_err mp_mod(const mp_int *a, const mp_int *b, mp_int *c)
1717
goto LBL_ERR;
1818
}
1919

20-
if (MP_IS_ZERO(&t) || (t.sign == b->sign)) {
20+
if (mp_iszero(&t) || (t.sign == b->sign)) {
2121
err = MP_OKAY;
2222
mp_exch(&t, c);
2323
} else {

mp_neg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mp_err mp_neg(const mp_int *a, mp_int *b)
1313
}
1414
}
1515

16-
if (!MP_IS_ZERO(b)) {
16+
if (!mp_iszero(b)) {
1717
b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;
1818
} else {
1919
b->sign = MP_ZPOS;

mp_prime_frobenius_underwood.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result)
112112

113113
mp_set_u32(&T1z, (uint32_t)((2 * a) + 5));
114114
if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) goto LBL_FU_ERR;
115-
if (MP_IS_ZERO(&sz) && (mp_cmp(&tz, &T1z) == MP_EQ)) {
115+
if (mp_iszero(&sz) && (mp_cmp(&tz, &T1z) == MP_EQ)) {
116116
*result = MP_YES;
117117
}
118118

mp_prime_is_prime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
3939
}
4040

4141
/* N must be odd */
42-
if (MP_IS_EVEN(a)) {
42+
if (mp_iseven(a)) {
4343
return MP_OKAY;
4444
}
4545
/* N is not a perfect square: floor(sqrt(N))^2 != N */

mp_prime_next_prime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mp_err mp_prime_next_prime(mp_int *a, int t, mp_bool bbs_style)
5858
}
5959
}
6060
} else {
61-
if (MP_IS_EVEN(a)) {
61+
if (mp_iseven(a)) {
6262
/* force odd */
6363
if ((err = mp_sub_d(a, 1uL, a)) != MP_OKAY) {
6464
return err;

mp_prime_strong_lucas_selfridge.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,24 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
206206
if ((err = mp_mul(&U2mz, &Uz, &T4z)) != MP_OKAY) goto LBL_LS_ERR;
207207
if ((err = s_mp_mul_si(&T4z, Ds, &T4z)) != MP_OKAY) goto LBL_LS_ERR;
208208
if ((err = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
209-
if (MP_IS_ODD(&Uz)) {
209+
if (mp_isodd(&Uz)) {
210210
if ((err = mp_add(&Uz, a, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
211211
}
212212
/* CZ
213213
* This should round towards negative infinity because
214214
* Thomas R. Nicely used GMP's mpz_fdiv_q_2exp().
215215
* But mp_div_2() does not do so, it is truncating instead.
216216
*/
217-
oddness = MP_IS_ODD(&Uz) ? MP_YES : MP_NO;
217+
oddness = mp_isodd(&Uz) ? MP_YES : MP_NO;
218218
if ((err = mp_div_2(&Uz, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
219219
if ((Uz.sign == MP_NEG) && (oddness != MP_NO)) {
220220
if ((err = mp_sub_d(&Uz, 1uL, &Uz)) != MP_OKAY) goto LBL_LS_ERR;
221221
}
222222
if ((err = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
223-
if (MP_IS_ODD(&Vz)) {
223+
if (mp_isodd(&Vz)) {
224224
if ((err = mp_add(&Vz, a, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
225225
}
226-
oddness = MP_IS_ODD(&Vz) ? MP_YES : MP_NO;
226+
oddness = mp_isodd(&Vz) ? MP_YES : MP_NO;
227227
if ((err = mp_div_2(&Vz, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
228228
if ((Vz.sign == MP_NEG) && (oddness != MP_NO)) {
229229
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)
239239

240240
/* If U_d or V_d is congruent to 0 mod N, then N is a prime or a
241241
strong Lucas pseudoprime. */
242-
if (MP_IS_ZERO(&Uz) || MP_IS_ZERO(&Vz)) {
242+
if (mp_iszero(&Uz) || mp_iszero(&Vz)) {
243243
*result = MP_YES;
244244
goto LBL_LS_ERR;
245245
}
@@ -262,7 +262,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
262262
if ((err = mp_sqr(&Vz, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
263263
if ((err = mp_sub(&Vz, &Q2kdz, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
264264
if ((err = mp_mod(&Vz, a, &Vz)) != MP_OKAY) goto LBL_LS_ERR;
265-
if (MP_IS_ZERO(&Vz)) {
265+
if (mp_iszero(&Vz)) {
266266
*result = MP_YES;
267267
goto LBL_LS_ERR;
268268
}

mp_radix_size.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mp_err mp_radix_size(const mp_int *a, int radix, size_t *size)
1515
return MP_VAL;
1616
}
1717

18-
if (MP_IS_ZERO(a)) {
18+
if (mp_iszero(a)) {
1919
*size = 2;
2020
return MP_OKAY;
2121
}

mp_read_radix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mp_err mp_read_radix(mp_int *a, const char *str, int radix)
7171
}
7272

7373
/* set the sign only if a != 0 */
74-
if (!MP_IS_ZERO(a)) {
74+
if (!mp_iszero(a)) {
7575
a->sign = neg;
7676
}
7777
return MP_OKAY;

mp_set_double.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mp_err mp_set_double(mp_int *a, double b)
3030
return err;
3131
}
3232

33-
if (((cast.bits >> 63) != 0uLL) && !MP_IS_ZERO(a)) {
33+
if (((cast.bits >> 63) != 0uLL) && !mp_iszero(a)) {
3434
a->sign = MP_NEG;
3535
}
3636

mp_sqrt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret)
1515
}
1616

1717
/* easy out */
18-
if (MP_IS_ZERO(arg)) {
18+
if (mp_iszero(arg)) {
1919
mp_zero(ret);
2020
return MP_OKAY;
2121
}

mp_sqrtmod_prime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
5151
/* Q = prime - 1 */
5252
mp_zero(&S);
5353
/* S = 0 */
54-
while (MP_IS_EVEN(&Q)) {
54+
while (mp_iseven(&Q)) {
5555
if ((err = mp_div_2(&Q, &Q)) != MP_OKAY) goto cleanup;
5656
/* Q = Q / 2 */
5757
if ((err = mp_add_d(&S, 1uL, &S)) != MP_OKAY) goto cleanup;

mp_sub_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mp_err mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
1212

1313
/* fast path for a == c */
1414
if (a == c &&
15-
!MP_IS_ZERO(c) &&
15+
!mp_iszero(c) &&
1616
c->sign == MP_ZPOS &&
1717
c->dp[0] > b) {
1818
c->dp[0] -= b;

mp_to_radix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
4242
}
4343

4444
/* quick out if its zero */
45-
if (MP_IS_ZERO(a)) {
45+
if (mp_iszero(a)) {
4646
*str++ = '0';
4747
*str = '\0';
4848
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
6868
--maxlen;
6969
}
7070
digs = 0u;
71-
while (!MP_IS_ZERO(&t)) {
71+
while (!mp_iszero(&t)) {
7272
if (--maxlen < 1u) {
7373
/* no more room */
7474
err = MP_BUF;

s_mp_div_small.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ mp_err s_mp_div_small(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
3737
sign = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
3838
if (c != NULL) {
3939
mp_exch(c, &q);
40-
c->sign = MP_IS_ZERO(c) ? MP_ZPOS : sign;
40+
c->sign = mp_iszero(c) ? MP_ZPOS : sign;
4141
}
4242
if (d != NULL) {
4343
mp_exch(d, &ta);
44-
d->sign = MP_IS_ZERO(d) ? MP_ZPOS : a->sign;
44+
d->sign = mp_iszero(d) ? MP_ZPOS : a->sign;
4545
}
4646
LBL_ERR:
4747
mp_clear_multi(&ta, &tb, &tq, &q, NULL);

s_mp_invmod_fast.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
1616
mp_err err;
1717

1818
/* 2. [modified] b must be odd */
19-
if (MP_IS_EVEN(b)) {
19+
if (mp_iseven(b)) {
2020
return MP_VAL;
2121
}
2222

@@ -32,7 +32,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
3232
if ((err = mp_mod(a, b, &y)) != MP_OKAY) goto LBL_ERR;
3333

3434
/* if one of x,y is zero return an error! */
35-
if (MP_IS_ZERO(&x) || MP_IS_ZERO(&y)) {
35+
if (mp_iszero(&x) || mp_iszero(&y)) {
3636
err = MP_VAL;
3737
goto LBL_ERR;
3838
}
@@ -44,25 +44,25 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
4444

4545
top:
4646
/* 4. while u is even do */
47-
while (MP_IS_EVEN(&u)) {
47+
while (mp_iseven(&u)) {
4848
/* 4.1 u = u/2 */
4949
if ((err = mp_div_2(&u, &u)) != MP_OKAY) goto LBL_ERR;
5050

5151
/* 4.2 if B is odd then */
52-
if (MP_IS_ODD(&B)) {
52+
if (mp_isodd(&B)) {
5353
if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) goto LBL_ERR;
5454
}
5555
/* B = B/2 */
5656
if ((err = mp_div_2(&B, &B)) != MP_OKAY) goto LBL_ERR;
5757
}
5858

5959
/* 5. while v is even do */
60-
while (MP_IS_EVEN(&v)) {
60+
while (mp_iseven(&v)) {
6161
/* 5.1 v = v/2 */
6262
if ((err = mp_div_2(&v, &v)) != MP_OKAY) goto LBL_ERR;
6363

6464
/* 5.2 if D is odd then */
65-
if (MP_IS_ODD(&D)) {
65+
if (mp_isodd(&D)) {
6666
/* D = (D-x)/2 */
6767
if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) goto LBL_ERR;
6868
}
@@ -84,7 +84,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c)
8484
}
8585

8686
/* if not zero goto step 4 */
87-
if (!MP_IS_ZERO(&u)) {
87+
if (!mp_iszero(&u)) {
8888
goto top;
8989
}
9090

0 commit comments

Comments
 (0)