Merge pull request #141 from fperrad/20181227_lint

more linting
This commit is contained in:
Steffen Jaeckel 2018-12-27 15:40:50 +01:00 committed by GitHub
commit 13444a8af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 29 deletions

View File

@ -16,12 +16,14 @@
/* two complement and */ /* two complement and */
int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
{ {
int res = MP_OKAY, bits; int res = MP_OKAY, bits, abits, bbits;
int as = mp_isneg(a), bs = mp_isneg(b); int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = NULL, _mx, acpy, bcpy; mp_int *mx = NULL, _mx, acpy, bcpy;
if ((as != MP_NO) || (bs != MP_NO)) { if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b)); abits = mp_count_bits(a);
bbits = mp_count_bits(b);
bits = MAX(abits, bbits);
res = mp_init_set_int(&_mx, 1uL); res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;

View File

@ -16,12 +16,14 @@
/* two complement or */ /* two complement or */
int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
{ {
int res = MP_OKAY, bits; int res = MP_OKAY, bits, abits, bbits;
int as = mp_isneg(a), bs = mp_isneg(b); int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = NULL, _mx, acpy, bcpy; mp_int *mx = NULL, _mx, acpy, bcpy;
if ((as != MP_NO) || (bs != MP_NO)) { if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b)); abits = mp_count_bits(a);
bbits = mp_count_bits(b);
bits = MAX(abits, bbits);
res = mp_init_set_int(&_mx, 1uL); res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;

View File

@ -16,12 +16,14 @@
/* two complement xor */ /* two complement xor */
int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
{ {
int res = MP_OKAY, bits; int res = MP_OKAY, bits, abits, bbits;
int as = mp_isneg(a), bs = mp_isneg(b); int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = NULL, _mx, acpy, bcpy; mp_int *mx = NULL, _mx, acpy, bcpy;
if ((as != MP_NO) || (bs != MP_NO)) { if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b)); abits = mp_count_bits(a);
bbits = mp_count_bits(b);
bits = MAX(abits, bbits);
res = mp_init_set_int(&_mx, 1uL); res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;

View File

@ -36,7 +36,7 @@ static void ndraw(mp_int *a, const char *name)
printf("0x%s\n", buf); printf("0x%s\n", buf);
} }
#if LTM_DEMO_TEST_VS_MTEST #if LTM_DEMO_TEST_VS_MTEST != 0
static void draw(mp_int *a) static void draw(mp_int *a)
{ {
ndraw(a, ""); ndraw(a, "");
@ -77,13 +77,13 @@ static void _panic(int l)
fprintf(stderr, "\n%d: fgets failed\n", l); fprintf(stderr, "\n%d: fgets failed\n", l);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif
#define FGETS(str, size, stream) \ #define FGETS(str, size, stream) \
{ \ { \
char *ret = fgets(str, size, stream); \ char *ret = fgets(str, size, stream); \
if (!ret) { _panic(__LINE__); } \ if (!ret) { _panic(__LINE__); } \
} }
#endif
static mp_int a, b, c, d, e, f; static mp_int a, b, c, d, e, f;
@ -156,8 +156,8 @@ static char buf[4096];
int main(void) int main(void)
{ {
unsigned rr; unsigned rr;
int cnt, ix; int ix;
#if LTM_DEMO_TEST_VS_MTEST #if LTM_DEMO_TEST_VS_MTEST != 0
unsigned long expt_n, add_n, sub_n, mul_n, div_n, sqr_n, mul2d_n, div2d_n, unsigned long expt_n, add_n, sub_n, mul_n, div_n, sqr_n, mul2d_n, div2d_n,
gcd_n, lcm_n, inv_n, div2_n, mul2_n, add_d_n, sub_d_n; gcd_n, lcm_n, inv_n, div2_n, mul2_n, add_d_n, sub_d_n;
#else #else
@ -165,7 +165,7 @@ int main(void)
long k, m; long k, m;
unsigned long long q, r; unsigned long long q, r;
mp_digit mp; mp_digit mp;
int i, n, err, should; int i, n, err, should, cnt;
#endif #endif
if (mp_init_multi(&a, &b, &c, &d, &e, &f, NULL)!= MP_OKAY) if (mp_init_multi(&a, &b, &c, &d, &e, &f, NULL)!= MP_OKAY)
@ -284,7 +284,7 @@ int main(void)
printf("Failed executing mp_jacobi(%d | %lu) %s.\n", n, jacobi[cnt].n, mp_error_to_string(err)); printf("Failed executing mp_jacobi(%d | %lu) %s.\n", n, jacobi[cnt].n, mp_error_to_string(err));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (err == MP_OKAY && i != jacobi[cnt].c[n + 5]) { if ((err == MP_OKAY) && (i != jacobi[cnt].c[n + 5])) {
printf("Failed trivial mp_jacobi(%d | %lu) %d != %d\n", n, jacobi[cnt].n, i, jacobi[cnt].c[n + 5]); printf("Failed trivial mp_jacobi(%d | %lu) %d != %d\n", n, jacobi[cnt].n, i, jacobi[cnt].c[n + 5]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -322,7 +322,7 @@ int main(void)
printf("Failed executing mp_kronecker(%ld | %ld) %s.\n", kronecker[cnt].n, m, mp_error_to_string(err)); printf("Failed executing mp_kronecker(%ld | %ld) %s.\n", kronecker[cnt].n, m, mp_error_to_string(err));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (err == MP_OKAY && i != kronecker[cnt].c[m + 10]) { if ((err == MP_OKAY) && (i != kronecker[cnt].c[m + 10])) {
printf("Failed trivial mp_kronecker(%ld | %ld) %d != %d\n", kronecker[cnt].n, m, i, kronecker[cnt].c[m + 10]); printf("Failed trivial mp_kronecker(%ld | %ld) %d != %d\n", kronecker[cnt].n, m, i, kronecker[cnt].c[m + 10]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -544,7 +544,7 @@ int main(void)
} }
printf("\n\nTesting: mp_get_long\n"); printf("\n\nTesting: mp_get_long\n");
for (i = 0; i < (int)(sizeof(unsigned long)*CHAR_BIT) - 1; ++i) { for (i = 0; i < ((int)(sizeof(unsigned long)*CHAR_BIT) - 1); ++i) {
t = (1ULL << (i+1)) - 1; t = (1ULL << (i+1)) - 1;
if (!t) if (!t)
t = -1; t = -1;
@ -560,11 +560,11 @@ int main(void)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
t <<= 1; t <<= 1;
} while (t); } while (t != 0uL);
} }
printf("\n\nTesting: mp_get_long_long\n"); printf("\n\nTesting: mp_get_long_long\n");
for (i = 0; i < (int)(sizeof(unsigned long long)*CHAR_BIT) - 1; ++i) { for (i = 0; i < ((int)(sizeof(unsigned long long)*CHAR_BIT) - 1); ++i) {
r = (1ULL << (i+1)) - 1; r = (1ULL << (i+1)) - 1;
if (!r) if (!r)
r = -1; r = -1;
@ -580,7 +580,7 @@ int main(void)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
r <<= 1; r <<= 1;
} while (r); } while (r != 0uLL);
} }
/* test mp_sqrt */ /* test mp_sqrt */
@ -745,12 +745,12 @@ int main(void)
if (mp_cmp(&c, &d) != MP_EQ) { if (mp_cmp(&c, &d) != MP_EQ) {
/* *INDENT-OFF* */ /* *INDENT-OFF* */
printf("d = e mod a, c = e MOD a\n"); printf("d = e mod a, c = e MOD a\n");
mp_todecimal(&a, buf); printf("a = %s\n", buf); mp_todecimal(&a, buf); printf("a = %s\n", buf);
mp_todecimal(&e, buf); printf("e = %s\n", buf); mp_todecimal(&e, buf); printf("e = %s\n", buf);
mp_todecimal(&d, buf); printf("d = %s\n", buf); mp_todecimal(&d, buf); printf("d = %s\n", buf);
mp_todecimal(&c, buf); printf("c = %s\n", buf); mp_todecimal(&c, buf); printf("c = %s\n", buf);
printf("compare no compare!\n"); return EXIT_FAILURE; printf("compare no compare!\n"); return EXIT_FAILURE;
/* *INDENT-ON* */ /* *INDENT-ON* */
} }
/* only one big montgomery reduction */ /* only one big montgomery reduction */
@ -815,7 +815,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_copy(&c, &b); mp_copy(&c, &b);
mp_mod(&c, &a, &c); mp_mod(&c, &a, &c);
mp_reduce_2k(&b, &a, 2uL); mp_reduce_2k(&b, &a, 2uL);
if (mp_cmp(&c, &b)) { if (mp_cmp(&c, &b) != MP_EQ) {
printf("FAILED\n"); printf("FAILED\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -868,8 +868,8 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_copy(&b, &c); mp_copy(&b, &c);
mp_mod(&b, &a, &b); mp_mod(&b, &a, &b);
mp_dr_setup(&a, &mp), mp_dr_setup(&a, &mp);
mp_dr_reduce(&c, &a, mp); mp_dr_reduce(&c, &a, mp);
if (mp_cmp(&b, &c) != MP_EQ) { if (mp_cmp(&b, &c) != MP_EQ) {
printf("Failed on trial %u\n", rr); printf("Failed on trial %u\n", rr);
@ -933,7 +933,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
#else #else
div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n = div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n =
sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = cnt = add_d_n = sub_d_n = 0; sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = add_d_n = sub_d_n = 0;
/* force KARA and TOOM to enable despite cutoffs */ /* force KARA and TOOM to enable despite cutoffs */
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8; KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;

View File

@ -144,7 +144,7 @@ static void gen_prime(void)
} while (x == 0uL); } while (x == 0uL);
if (r > 31uL) { if (r > 31uL) {
fwrite(&r, 1uL, sizeof(mp_digit), out); fwrite(&r, 1uL, sizeof(mp_digit), out);
printf("%9u\r", r); printf("%9lu\r", r);
fflush(stdout); fflush(stdout);
} }
if (r < 31uL) break; if (r < 31uL) break;
@ -336,7 +336,7 @@ top:
mp_toradix(&a, buf, 10); mp_toradix(&a, buf, 10);
printf("A == \n%s\n\n", buf); printf("A == \n%s\n\n", buf);
mp_toradix(&b, buf, 10); mp_toradix(&b, buf, 10);
printf("B == \n%s\n\nG == %d\n", buf, bases[ii]); printf("B == \n%s\n\nG == %lu\n", buf, bases[ii]);
printf("----------------------------------------------------------------\n"); printf("----------------------------------------------------------------\n");
} }