Merge pull request #139 from fperrad/20181226_lint

some linting
This commit is contained in:
Steffen Jaeckel 2018-12-26 13:14:55 +01:00 committed by GitHub
commit bd14983023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 96 deletions

View File

@ -34,7 +34,7 @@ int mp_get_bit(const mp_int *a, int b)
* otherwise (limb >= a->used) would be true for a = 0 * otherwise (limb >= a->used) would be true for a = 0
*/ */
if (mp_iszero(a)) { if (mp_iszero(a) != MP_NO) {
return MP_NO; return MP_NO;
} }
@ -45,7 +45,7 @@ int mp_get_bit(const mp_int *a, int b)
bit = (mp_digit)(1) << (b % DIGIT_BIT); bit = (mp_digit)(1) << (b % DIGIT_BIT);
isset = a->dp[limb] & bit; isset = a->dp[limb] & bit;
return (isset != 0) ? MP_YES : MP_NO; return (isset != 0u) ? MP_YES : MP_NO;
} }
#endif #endif

View File

@ -34,10 +34,10 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
int e = MP_OKAY; int e = MP_OKAY;
int v, k; int v, k;
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_iszero(p)) { if (mp_iszero(p) != MP_NO) {
if (a->used == 1 && a->dp[0] == 1) { if ((a->used == 1) && (a->dp[0] == 1u)) {
*c = 1; *c = 1;
return e; return e;
} else { } else {
@ -46,7 +46,7 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
} }
} }
if (mp_iseven(a) && mp_iseven(p)) { if ((mp_iseven(a) != MP_NO) && (mp_iseven(p) != MP_NO)) {
*c = 0; *c = 0;
return e; return e;
} }
@ -66,7 +66,7 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
if ((v & 0x1) == 0) { if ((v & 0x1) == 0) {
k = 1; k = 1;
} else { } else {
k = table[a->dp[0] & 7]; k = table[a->dp[0] & 7u];
} }
if (p1.sign == MP_NEG) { if (p1.sign == MP_NEG) {
@ -81,8 +81,8 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
} }
for (;;) { for (;;) {
if (mp_iszero(&a1)) { if (mp_iszero(&a1) != MP_NO) {
if (mp_cmp_d(&p1, 1) == MP_EQ) { if (mp_cmp_d(&p1, 1uL) == MP_EQ) {
*c = k; *c = k;
goto LBL_KRON; goto LBL_KRON;
} else { } else {
@ -97,7 +97,7 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
} }
if ((v & 0x1) == 1) { if ((v & 0x1) == 1) {
k = k * table[p1.dp[0] & 7]; k = k * table[p1.dp[0] & 7u];
} }
if (a1.sign == MP_NEG) { if (a1.sign == MP_NEG) {
@ -106,12 +106,12 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
* a1.dp[0] + 1 cannot overflow because the MSB * a1.dp[0] + 1 cannot overflow because the MSB
* of the type mp_digit is not set by definition * of the type mp_digit is not set by definition
*/ */
if ((a1.dp[0] + 1) & p1.dp[0] & 2u) { if (((a1.dp[0] + 1u) & p1.dp[0] & 2u) != 0u) {
k = -k; k = -k;
} }
} else { } else {
/* compute k = (-1)^((a1-1)*(p1-1)/4) * k */ /* compute k = (-1)^((a1-1)*(p1-1)/4) * k */
if (a1.dp[0] & p1.dp[0] & 2u) { if ((a1.dp[0] & p1.dp[0] & 2u) != 0u) {
k = -k; k = -k;
} }
} }

View File

@ -38,7 +38,7 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
mp_int T1z, T2z, Np1z, sz, tz; mp_int T1z, T2z, Np1z, sz, tz;
int a, ap2, length, i, j, isset; int a, ap2, length, i, j, isset;
int e = MP_OKAY; int e;
*result = MP_NO; *result = MP_NO;
@ -48,7 +48,8 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
for (a = 0; a < LTM_FROBENIUS_UNDERWOOD_A; a++) { for (a = 0; a < LTM_FROBENIUS_UNDERWOOD_A; a++) {
/* TODO: That's ugly! No, really, it is! */ /* TODO: That's ugly! No, really, it is! */
if (a==2||a==4||a==7||a==8||a==10||a==14||a==18||a==23||a==26||a==28) { if ((a==2) || (a==4) || (a==7) || (a==8) || (a==10) ||
(a==14) || (a==18) || (a==23) || (a==26) || (a==28)) {
continue; continue;
} }
/* (32764^2 - 4) < 2^31, no bigint for >MP_8BIT needed) */ /* (32764^2 - 4) < 2^31, no bigint for >MP_8BIT needed) */
@ -60,7 +61,7 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
if ((e = mp_sub_d(&T1z,4,&T1z)) != MP_OKAY) { if ((e = mp_sub_d(&T1z, 4uL, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
@ -83,7 +84,7 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
/* Composite if N and (a+4)*(2*a+5) are not coprime */ /* Composite if N and (a+4)*(2*a+5) are not coprime */
if ((e = mp_set_long(&T1z, (unsigned long)((a+4)*(2*a+5)))) != MP_OKAY) { if ((e = mp_set_long(&T1z, (unsigned long)((a+4)*((2*a)+5)))) != MP_OKAY) {
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
@ -91,17 +92,17 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
if (!(T1z.used == 1 && T1z.dp[0] == 1u)) { if (!((T1z.used == 1) && (T1z.dp[0] == 1u))) {
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
ap2 = a + 2; ap2 = a + 2;
if ((e = mp_add_d(N,1u,&Np1z)) != MP_OKAY) { if ((e = mp_add_d(N, 1uL, &Np1z)) != MP_OKAY) {
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
mp_set(&sz,1u); mp_set(&sz, 1uL);
mp_set(&tz,2u); mp_set(&tz, 2uL);
length = mp_count_bits(&Np1z); length = mp_count_bits(&Np1z);
for (i = length - 2; i >= 0; i--) { for (i = length - 2; i >= 0; i--) {
@ -174,13 +175,13 @@ int mp_prime_frobenius_underwood(const mp_int *N, int *result)
} }
} }
if ((e = mp_set_long(&T1z, (unsigned long)(2 * a + 5))) != MP_OKAY) { if ((e = mp_set_long(&T1z, (unsigned long)((2 * a) + 5))) != MP_OKAY) {
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
if ((e = mp_mod(&T1z, N, &T1z)) != MP_OKAY) { if ((e = mp_mod(&T1z, N, &T1z)) != MP_OKAY) {
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }
if (mp_iszero(&sz) && (mp_cmp(&tz, &T1z) == MP_EQ)) { if ((mp_iszero(&sz) != MP_NO) && (mp_cmp(&tz, &T1z) == MP_EQ)) {
*result = MP_YES; *result = MP_YES;
goto LBL_FU_ERR; goto LBL_FU_ERR;
} }

View File

@ -41,11 +41,11 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
/* Some shortcuts */ /* Some shortcuts */
/* N > 3 */ /* N > 3 */
if (a->used == 1) { if (a->used == 1) {
if (a->dp[0] == 0 || a->dp[0] == 1) { if ((a->dp[0] == 0u) || (a->dp[0] == 1u)) {
*result = 0; *result = 0;
return MP_OKAY; return MP_OKAY;
} }
if (a->dp[0] == 2) { if (a->dp[0] == 2u) {
*result = 1; *result = 1;
return MP_OKAY; return MP_OKAY;
} }
@ -90,7 +90,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
/* /*
Run the Miller-Rabin test with base 2 for the BPSW test. Run the Miller-Rabin test with base 2 for the BPSW test.
*/ */
if ((err = mp_init_set(&b,2)) != MP_OKAY) { if ((err = mp_init_set(&b, 2uL)) != MP_OKAY) {
return err; return err;
} }
@ -307,7 +307,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
} }
#endif #endif
/* Ceil, because small numbers have a right to live, too, */ /* Ceil, because small numbers have a right to live, too, */
len = (int)((fips_rand + DIGIT_BIT) / DIGIT_BIT); len = (((int)fips_rand + DIGIT_BIT) / DIGIT_BIT);
/* Unlikely. */ /* Unlikely. */
if (len < 0) { if (len < 0) {
ix--; ix--;
@ -339,7 +339,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
} }
/* Although the chance for b <= 3 is miniscule, try again. */ /* Although the chance for b <= 3 is miniscule, try again. */
if (mp_cmp_d(&b,3) != MP_GT) { if (mp_cmp_d(&b, 3uL) != MP_GT) {
ix--; ix--;
continue; continue;
} }

View File

@ -85,7 +85,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
mp_int Dz, gcd, Np1, Uz, Vz, U2mz, V2mz, Qmz, Q2mz, Qkdz, T1z, T2z, T3z, T4z, Q2kdz; mp_int Dz, gcd, Np1, Uz, Vz, U2mz, V2mz, Qmz, Q2mz, Qkdz, T1z, T2z, T3z, T4z, Q2kdz;
/* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */ /* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */
int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits; int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits;
int e = MP_OKAY; int e;
int isset; int isset;
*result = MP_NO; *result = MP_NO;
@ -118,7 +118,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
/* if 1 < GCD < N then N is composite with factor "D", and /* if 1 < GCD < N then N is composite with factor "D", and
Jacobi(D,N) is technically undefined (but often returned Jacobi(D,N) is technically undefined (but often returned
as zero). */ as zero). */
if ((mp_cmp_d(&gcd,1u) == MP_GT) && (mp_cmp(&gcd,a) == MP_LT)) { if ((mp_cmp_d(&gcd, 1uL) == MP_GT) && (mp_cmp(&gcd, a) == MP_LT)) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
if (Ds < 0) { if (Ds < 0) {
@ -133,7 +133,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
} }
D += 2; D += 2;
if (D > INT_MAX - 2) { if (D > (INT_MAX - 2)) {
e = MP_VAL; e = MP_VAL;
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
@ -172,7 +172,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
Baillie-PSW test based on the strong Lucas-Selfridge test Baillie-PSW test based on the strong Lucas-Selfridge test
should be more reliable. */ should be more reliable. */
if ((e = mp_add_d(a,1u,&Np1)) != MP_OKAY) { if ((e = mp_add_d(a, 1uL, &Np1)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
s = mp_cnt_lsb(&Np1); s = mp_cnt_lsb(&Np1);
@ -198,9 +198,9 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
combined with the previous totals for U and V, using the combined with the previous totals for U and V, using the
composition formulas for addition of indices. */ composition formulas for addition of indices. */
mp_set(&Uz, 1u); /* U=U_1 */ mp_set(&Uz, 1uL); /* U=U_1 */
mp_set(&Vz, (mp_digit)P); /* V=V_1 */ mp_set(&Vz, (mp_digit)P); /* V=V_1 */
mp_set(&U2mz, 1u); /* U_1 */ mp_set(&U2mz, 1uL); /* U_1 */
mp_set(&V2mz, (mp_digit)P); /* V_1 */ mp_set(&V2mz, (mp_digit)P); /* V_1 */
if (Q < 0) { if (Q < 0) {
@ -300,7 +300,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
if ((e = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) { if ((e = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
if (mp_isodd(&Uz)) { if (mp_isodd(&Uz) != MP_NO) {
if ((e = mp_add(&Uz, a, &Uz)) != MP_OKAY) { if ((e = mp_add(&Uz, a, &Uz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
@ -313,15 +313,15 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
if ((e = mp_div_2(&Uz, &Uz)) != MP_OKAY) { if ((e = mp_div_2(&Uz, &Uz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
if ((Uz.sign == MP_NEG) && mp_isodd(&Uz)) { if ((Uz.sign == MP_NEG) && (mp_isodd(&Uz) != MP_NO)) {
if ((e = mp_sub_d(&Uz,1u,&Uz)) != MP_OKAY) { if ((e = mp_sub_d(&Uz, 1uL, &Uz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
} }
if ((e = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) { if ((e = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
if (mp_isodd(&Vz)) { if (mp_isodd(&Vz) != MP_NO) {
if ((e = mp_add(&Vz, a, &Vz)) != MP_OKAY) { if ((e = mp_add(&Vz, a, &Vz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
@ -329,8 +329,8 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
if ((e = mp_div_2(&Vz, &Vz)) != MP_OKAY) { if ((e = mp_div_2(&Vz, &Vz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
if (Vz.sign == MP_NEG && mp_isodd(&Vz)) { if ((Vz.sign == MP_NEG) && (mp_isodd(&Vz) != MP_NO)) {
if ((e = mp_sub_d(&Vz,1,&Vz)) != MP_OKAY) { if ((e = mp_sub_d(&Vz, 1uL, &Vz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
} }
@ -352,7 +352,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *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_iszero(&Uz) || mp_iszero(&Vz)) { if ((mp_iszero(&Uz) != MP_NO) || (mp_iszero(&Vz) != MP_NO)) {
*result = MP_YES; *result = MP_YES;
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
@ -383,7 +383,7 @@ int mp_prime_strong_lucas_selfridge(const mp_int *a, int *result)
if ((e = mp_mod(&Vz, a, &Vz)) != MP_OKAY) { if ((e = mp_mod(&Vz, a, &Vz)) != MP_OKAY) {
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }
if (mp_iszero(&Vz)) { if (mp_iszero(&Vz) != MP_NO) {
*result = MP_YES; *result = MP_YES;
goto LBL_LS_ERR; goto LBL_LS_ERR;
} }