Merge pull request #102 from fperrad/20180202_lint

more linting
This commit is contained in:
Steffen Jaeckel 2018-02-27 23:27:45 +01:00 committed by GitHub
commit db1a8b1919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 153 additions and 175 deletions

View File

@ -1,13 +1,6 @@
#include <string.h>
#include <time.h>
#ifdef IOWNANATHLON
#include <unistd.h>
#define SLEEP sleep(4)
#else
#define SLEEP
#endif
/*
* Configuration
*/
@ -50,21 +43,6 @@ static void draw(mp_int *a)
}
#endif
#if 0
static unsigned long lfsr = 0xAAAAAAAAUL;
static int lbit(void)
{
if (lfsr & 0x80000000UL) {
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
return 1;
} else {
lfsr <<= 1;
return 0;
}
}
#endif
#if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
static FILE *fd_urandom;
#endif
@ -79,15 +57,15 @@ static int myrng(unsigned char *dst, int len, void *dat)
fprintf(stderr, "\nno /dev/urandom\n");
# endif
} else {
return fread(dst, 1, len, fd_urandom);
return fread(dst, 1uL, len, fd_urandom);
}
#endif
for (x = 0; x < len;) {
unsigned int r = (unsigned int)rand();
do {
dst[x++] = r & 0xFF;
dst[x++] = r & 0xFFu;
r >>= 8;
} while ((r != 0) && (x < len));
} while ((r != 0u) && (x < len));
}
return len;
}
@ -217,7 +195,7 @@ int main(void)
return EXIT_FAILURE;
}
// a: -5-> b: -4
mp_add_d(&a, 1, &b);
mp_add_d(&a, 1uL, &b);
if (mp_isneg(&b) != MP_YES) {
return EXIT_FAILURE;
}
@ -225,18 +203,18 @@ int main(void)
return EXIT_FAILURE;
}
// a: -5-> b: 1
mp_add_d(&a, 6, &b);
mp_add_d(&a, 6uL, &b);
if (mp_get_int(&b) != 1) {
return EXIT_FAILURE;
}
// a: -5-> a: 1
mp_add_d(&a, 6, &a);
mp_add_d(&a, 6uL, &a);
if (mp_get_int(&a) != 1) {
return EXIT_FAILURE;
}
mp_zero(&a);
// a: 0-> a: 6
mp_add_d(&a, 6, &a);
mp_add_d(&a, 6uL, &a);
if (mp_get_int(&a) != 6) {
return EXIT_FAILURE;
}
@ -286,7 +264,7 @@ int main(void)
// test mp_get_int
printf("\n\nTesting: mp_get_int");
for (i = 0; i < 1000; ++i) {
t = ((unsigned long) rand() * rand() + 1) & 0xFFFFFFFF;
t = (unsigned long)(rand() * rand() + 1) & 0xFFFFFFFFuL;
mp_set_int(&a, t);
if (t != mp_get_int(&a)) {
printf("\nmp_get_int() bad result!");
@ -298,8 +276,8 @@ int main(void)
printf("\nmp_get_int() bad result!");
return EXIT_FAILURE;
}
mp_set_int(&a, 0xffffffff);
if (mp_get_int(&a) != 0xffffffff) {
mp_set_int(&a, 0xFFFFFFFFuL);
if (mp_get_int(&a) != 0xFFFFFFFFuL) {
printf("\nmp_get_int() bad result!");
return EXIT_FAILURE;
}
@ -386,7 +364,7 @@ int main(void)
}
/* test for false positives */
mp_add_d(&a, 1, &a);
mp_add_d(&a, 1uL, &a);
if (mp_is_square(&a, &n) != MP_OKAY) {
printf("\nfp:mp_is_square() error!");
return EXIT_FAILURE;
@ -447,7 +425,7 @@ int main(void)
return EXIT_FAILURE;
}
/* let's see if it's really a safe prime */
mp_sub_d(&a, 1, &a);
mp_sub_d(&a, 1uL, &a);
mp_div_2(&a, &a);
mp_prime_is_prime(&a, 8, &cnt);
if (cnt != MP_YES) {
@ -525,7 +503,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
/* test mp_cnt_lsb */
printf("\n\nTesting: mp_cnt_lsb");
mp_set(&a, 1);
mp_set(&a, 1uL);
for (ix = 0; ix < 1024; ix++) {
if (mp_cnt_lsb(&a) != ix) {
printf("Failed at %d, %d\n", ix, mp_cnt_lsb(&a));
@ -540,7 +518,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_digit tmp;
mp_2expt(&a, cnt);
mp_sub_d(&a, 2, &a); /* a = 2**cnt - 2 */
mp_sub_d(&a, 2uL, &a); /* a = 2**cnt - 2 */
printf("\r %4d bits", cnt);
printf("(%d)", mp_reduce_is_2k(&a));
@ -554,7 +532,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_rand(&b, (cnt / DIGIT_BIT + 1) * 2);
mp_copy(&c, &b);
mp_mod(&c, &a, &c);
mp_reduce_2k(&b, &a, 2);
mp_reduce_2k(&b, &a, 2uL);
if (mp_cmp(&c, &b)) {
printf("FAILED\n");
return EXIT_FAILURE;
@ -564,7 +542,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
/* test mp_div_3 */
printf("\n\nTesting: mp_div_3...\n");
mp_set(&d, 3);
mp_set(&d, 3uL);
for (cnt = 0; cnt < 10000;) {
mp_digit r2;
@ -604,7 +582,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
fflush(stdout);
}
mp_sqr(&b, &b);
mp_add_d(&b, 1, &b);
mp_add_d(&b, 1uL, &b);
mp_copy(&b, &c);
mp_mod(&b, &a, &b);
@ -654,10 +632,10 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
fflush(stdout);
for (cnt = 0; cnt < (int)(1UL << 20); cnt++) {
mp_sqr(&b, &b);
mp_add_d(&b, 1, &b);
mp_add_d(&b, 1uL, &b);
mp_reduce_2k_l(&b, &a, &d);
mp_sqr(&c, &c);
mp_add_d(&c, 1, &c);
mp_add_d(&c, 1uL, &c);
mp_mod(&c, &a, &c);
if (mp_cmp(&b, &c) != MP_EQ) {
printf("mp_reduce_2k_l() failed at step %d\n", cnt);
@ -715,10 +693,10 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
add_n, sub_n, mul_n, div_n, sqr_n, mul2d_n, div2d_n, gcd_n, lcm_n,
expt_n, inv_n, div2_n, mul2_n, add_d_n, sub_d_n);
FGETS(cmd, 4095, stdin);
cmd[strlen(cmd) - 1] = 0;
cmd[strlen(cmd) - 1u] = '\0';
printf("%-6s ]\r", cmd);
fflush(stdout);
if (!strcmp(cmd, "mul2d")) {
if (strcmp(cmd, "mul2d") == 0) {
++mul2d_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -735,7 +713,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&b);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "div2d")) {
} else if (strcmp(cmd, "div2d") == 0) {
++div2d_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -755,7 +733,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&b);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "add")) {
} else if (strcmp(cmd, "add") == 0) {
++add_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -778,7 +756,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
rr = mp_signed_bin_size(&c);
mp_to_signed_bin(&c, (unsigned char *) cmd);
memset(cmd + rr, rand() & 255, sizeof(cmd) - rr);
memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
mp_read_signed_bin(&d, (unsigned char *) cmd, rr);
if (mp_cmp(&c, &d) != MP_EQ) {
printf("mp_signed_bin failure!\n");
@ -790,7 +768,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
rr = mp_unsigned_bin_size(&c);
mp_to_unsigned_bin(&c, (unsigned char *) cmd);
memset(cmd + rr, rand() & 255, sizeof(cmd) - rr);
memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
mp_read_unsigned_bin(&d, (unsigned char *) cmd, rr);
if (mp_cmp_mag(&c, &d) != MP_EQ) {
printf("mp_unsigned_bin failure!\n");
@ -799,7 +777,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "sub")) {
} else if (strcmp(cmd, "sub") == 0) {
++sub_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -817,7 +795,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&d);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "mul")) {
} else if (strcmp(cmd, "mul") == 0) {
++mul_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -835,7 +813,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&d);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "div")) {
} else if (strcmp(cmd, "div") == 0) {
++div_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -859,7 +837,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "sqr")) {
} else if (strcmp(cmd, "sqr") == 0) {
++sqr_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -874,7 +852,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&c);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "gcd")) {
} else if (strcmp(cmd, "gcd") == 0) {
++gcd_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -893,7 +871,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&d);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "lcm")) {
} else if (strcmp(cmd, "lcm") == 0) {
++lcm_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -912,7 +890,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&d);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "expt")) {
} else if (strcmp(cmd, "expt") == 0) {
++expt_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -933,7 +911,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&e);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "invmod")) {
} else if (strcmp(cmd, "invmod") == 0) {
++inv_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -943,7 +921,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_read_radix(&c, buf, 64);
mp_invmod(&a, &b, &d);
mp_mulmod(&d, &a, &b, &e);
if (mp_cmp_d(&e, 1) != MP_EQ) {
if (mp_cmp_d(&e, 1uL) != MP_EQ) {
printf("inv [wrong value from MPI?!] failure\n");
draw(&a);
draw(&b);
@ -955,7 +933,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "div2")) {
} else if (strcmp(cmd, "div2") == 0) {
++div2_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -969,7 +947,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&c);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "mul2")) {
} else if (strcmp(cmd, "mul2") == 0) {
++mul2_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -983,7 +961,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
draw(&c);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "add_d")) {
} else if (strcmp(cmd, "add_d") == 0) {
++add_d_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -1000,7 +978,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
printf("d == %d\n", ix);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "sub_d")) {
} else if (strcmp(cmd, "sub_d") == 0) {
++sub_d_n;
FGETS(buf, 4095, stdin);
mp_read_radix(&a, buf, 64);
@ -1017,7 +995,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
printf("d == %d\n", ix);
return EXIT_FAILURE;
}
} else if (!strcmp(cmd, "exit")) {
} else if (strcmp(cmd, "exit") == 0) {
printf("\nokay, exiting now\n");
break;
}

View File

@ -32,16 +32,16 @@ static void draw(mp_int *a)
}
static unsigned long lfsr = 0xAAAAAAAAUL;
static unsigned long lfsr = 0xAAAAAAAAuL;
static int lbit(void)
static unsigned int lbit(void)
{
if (lfsr & 0x80000000UL) {
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
return 1;
if ((lfsr & 0x80000000uL) != 0uL) {
lfsr = ((lfsr << 1) ^ 0x8000001BuL) & 0xFFFFFFFFuL;
return 1u;
} else {
lfsr <<= 1;
return 0;
return 0u;
}
}
@ -126,15 +126,15 @@ int main(void)
SLEEP;
mp_rand(&a, cnt);
mp_rand(&b, cnt);
rr = 0;
tt = -1;
rr = 0u;
tt = UINT64_MAX;
do {
gg = TIMFUNC();
DO(mp_add(&a, &b, &c));
gg = (TIMFUNC() - gg) >> 1;
if (tt > gg)
tt = gg;
} while (++rr < 100000);
} while (++rr < 100000u);
printf("Adding\t\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
FPRINTF(log, "%d %9" PRIu64 "\n", cnt * DIGIT_BIT, tt);
@ -147,15 +147,15 @@ int main(void)
SLEEP;
mp_rand(&a, cnt);
mp_rand(&b, cnt);
rr = 0;
tt = -1;
rr = 0u;
tt = UINT64_MAX;
do {
gg = TIMFUNC();
DO(mp_sub(&a, &b, &c));
gg = (TIMFUNC() - gg) >> 1;
if (tt > gg)
tt = gg;
} while (++rr < 100000);
} while (++rr < 100000u);
printf("Subtracting\t\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
@ -183,15 +183,15 @@ int main(void)
SLEEP;
mp_rand(&a, cnt);
mp_rand(&b, cnt);
rr = 0;
tt = -1;
rr = 0u;
tt = UINT64_MAX;
do {
gg = TIMFUNC();
DO(mp_mul(&a, &b, &c));
gg = (TIMFUNC() - gg) >> 1;
if (tt > gg)
tt = gg;
} while (++rr < 100);
} while (++rr < 100u);
printf("Multiplying\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
FPRINTF(log, "%d %9" PRIu64 "\n", mp_count_bits(&a), tt);
@ -203,15 +203,15 @@ int main(void)
for (cnt = 4; cnt <= (10240 / DIGIT_BIT); cnt += 2) {
SLEEP;
mp_rand(&a, cnt);
rr = 0;
tt = -1;
rr = 0u;
tt = UINT64_MAX;
do {
gg = TIMFUNC();
DO(mp_sqr(&a, &b));
gg = (TIMFUNC() - gg) >> 1;
if (tt > gg)
tt = gg;
} while (++rr < 100);
} while (++rr < 100u);
printf("Squaring\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
FPRINTF(log, "%d %9" PRIu64 "\n", mp_count_bits(&a), tt);
@ -258,7 +258,7 @@ int main(void)
logb = FOPEN("logs/expt_dr.log", "w");
logc = FOPEN("logs/expt_2k.log", "w");
logd = FOPEN("logs/expt_2kl.log", "w");
for (n = 0; primes[n]; n++) {
for (n = 0; primes[n] != NULL; n++) {
SLEEP;
mp_read_radix(&a, primes[n], 10);
mp_zero(&b);
@ -267,23 +267,23 @@ int main(void)
b.dp[0] |= lbit();
b.used += 1;
}
mp_sub_d(&a, 1, &c);
mp_sub_d(&a, 1uL, &c);
mp_mod(&b, &c, &b);
mp_set(&c, 3);
rr = 0;
tt = -1;
mp_set(&c, 3uL);
rr = 0u;
tt = UINT64_MAX;
do {
gg = TIMFUNC();
DO(mp_exptmod(&c, &b, &a, &d));
gg = (TIMFUNC() - gg) >> 1;
if (tt > gg)
tt = gg;
} while (++rr < 10);
mp_sub_d(&a, 1, &e);
} while (++rr < 10u);
mp_sub_d(&a, 1uL, &e);
mp_sub(&e, &b, &b);
mp_exptmod(&c, &b, &a, &e); /* c^(p-1-b) mod a */
mp_mulmod(&e, &d, &a, &d); /* c^b * c^(p-1-b) == c^p-1 == 1 */
if (mp_cmp_d(&d, 1)) {
if (mp_cmp_d(&d, 1uL) != MP_EQ) {
printf("Different (%d)!!!\n", mp_count_bits(&a));
draw(&d);
exit(0);
@ -306,21 +306,21 @@ int main(void)
mp_rand(&b, cnt);
do {
mp_add_d(&b, 1, &b);
mp_add_d(&b, 1uL, &b);
mp_gcd(&a, &b, &c);
} while (mp_cmp_d(&c, 1) != MP_EQ);
} while (mp_cmp_d(&c, 1uL) != MP_EQ);
rr = 0;
tt = -1;
rr = 0u;
tt = UINT64_MAX;
do {
gg = TIMFUNC();
DO(mp_invmod(&b, &a, &c));
gg = (TIMFUNC() - gg) >> 1;
if (tt > gg)
tt = gg;
} while (++rr < 1000);
} while (++rr < 1000u);
mp_mulmod(&b, &c, &a, &d);
if (mp_cmp_d(&d, 1) != MP_EQ) {
if (mp_cmp_d(&d, 1uL) != MP_EQ) {
printf("Failed to invert\n");
return 0;
}

View File

@ -7,7 +7,8 @@ static int sizes[] = {256, 512, 768, 1024, 1536, 2048, 3072, 4096};
int main(void)
{
char buf[2000];
int x, y;
size_t x;
int y;
mp_int q, p;
FILE *out;
clock_t t1;
@ -17,16 +18,16 @@ int main(void)
out = fopen("2kprime.1", "w");
if (out != NULL) {
for (x = 0; x < (int)(sizeof(sizes) / sizeof(sizes[0])); x++) {
for (x = 0; x < (sizeof(sizes) / sizeof(sizes[0])); x++) {
top:
mp_2expt(&q, sizes[x]);
mp_add_d(&q, 3, &q);
mp_add_d(&q, 3uL, &q);
z = -3;
t1 = clock();
for (;;) {
mp_sub_d(&q, 4, &q);
z += 4;
mp_sub_d(&q, 4uL, &q);
z += 4uL;
if (z > MP_MASK) {
printf("No primes of size %d found\n", sizes[x]);
@ -47,7 +48,7 @@ top:
}
/* find (q-1)/2 */
mp_sub_d(&q, 1, &p);
mp_sub_d(&q, 1uL, &p);
mp_div_2(&p, &p);
mp_prime_is_prime(&p, 3, &y);
if (y == 0) {

View File

@ -31,13 +31,13 @@ top:
/* now loop */
res = 0;
for (;;) {
a.dp[0] += 4;
a.dp[0] += 4uL;
if (a.dp[0] >= MP_MASK) break;
mp_prime_is_prime(&a, 1, &res);
if (res == 0) continue;
printf(".");
fflush(stdout);
mp_sub_d(&a, 1, &b);
mp_sub_d(&a, 1uL, &b);
mp_div_2(&b, &b);
mp_prime_is_prime(&b, 3, &res);
if (res == 0) continue;

View File

@ -21,15 +21,15 @@ static int is_mersenne(long s, int *pp)
}
/* n = 2^s - 1 */
if ((res = mp_2expt(&n, s)) != MP_OKAY) {
if ((res = mp_2expt(&n, (int)s)) != MP_OKAY) {
goto LBL_MU;
}
if ((res = mp_sub_d(&n, 1, &n)) != MP_OKAY) {
if ((res = mp_sub_d(&n, 1uL, &n)) != MP_OKAY) {
goto LBL_MU;
}
/* set u=4 */
mp_set(&u, 4);
mp_set(&u, 4uL);
/* for k=1 to s-2 do */
for (k = 1; k <= (s - 2); k++) {
@ -37,7 +37,7 @@ static int is_mersenne(long s, int *pp)
if ((res = mp_sqr(&u, &u)) != MP_OKAY) {
goto LBL_MU;
}
if ((res = mp_sub_d(&u, 2, &u)) != MP_OKAY) {
if ((res = mp_sub_d(&u, 2uL, &u)) != MP_OKAY) {
goto LBL_MU;
}
@ -49,7 +49,7 @@ static int is_mersenne(long s, int *pp)
}
/* reduce */
if ((res = mp_reduce_2k(&u, &n, 1)) != MP_OKAY) {
if ((res = mp_reduce_2k(&u, &n, 1uL)) != MP_OKAY) {
goto LBL_MU;
}
}
@ -134,7 +134,6 @@ int main(void)
k += 2;
}
}
return 0;
}
/* ref: $Format:%D$ */

View File

@ -6,19 +6,19 @@ int main(void)
{
mp_int modulus, R, p, pp;
mp_digit mp;
long x, y;
int x, y;
srand(time(NULL));
mp_init_multi(&modulus, &R, &p, &pp, NULL);
/* loop through various sizes */
for (x = 4; x < 256; x++) {
printf("DIGITS == %3ld...", x);
printf("DIGITS == %3d...", x);
fflush(stdout);
/* make up the odd modulus */
mp_rand(&modulus, x);
modulus.dp[0] |= 1;
modulus.dp[0] |= 1uL;
/* now find the R value */
mp_montgomery_calc_normalization(&R, &modulus);

View File

@ -18,7 +18,7 @@ static mp_digit i_sqrt(mp_word x)
x2 = x;
do {
x1 = x2;
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
x2 = x1 - ((x1 * x1) - x) / (2u * x1);
} while (x1 != x2);
if ((x1 * x1) > x) {
@ -40,114 +40,114 @@ static void gen_prime(void)
/* write first set of primes */
/* *INDENT-OFF* */
r = 3; fwrite(&r, 1, sizeof(mp_digit), out);
r = 5; fwrite(&r, 1, sizeof(mp_digit), out);
r = 7; fwrite(&r, 1, sizeof(mp_digit), out);
r = 11; fwrite(&r, 1, sizeof(mp_digit), out);
r = 13; fwrite(&r, 1, sizeof(mp_digit), out);
r = 17; fwrite(&r, 1, sizeof(mp_digit), out);
r = 19; fwrite(&r, 1, sizeof(mp_digit), out);
r = 23; fwrite(&r, 1, sizeof(mp_digit), out);
r = 29; fwrite(&r, 1, sizeof(mp_digit), out);
r = 31; fwrite(&r, 1, sizeof(mp_digit), out);
r = 3uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 5uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 7uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 11uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 13uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 17uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 19uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 23uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 29uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
r = 31uL; fwrite(&r, 1uL, sizeof(mp_digit), out);
/* *INDENT-ON* */
/* get square root, since if 'r' is composite its factors must be < than this */
y = i_sqrt(r);
next = (y + 1) * (y + 1);
next = (y + 1uL) * (y + 1uL);
for (;;) {
do {
r += 2; /* next candidate */
r += 2uL; /* next candidate */
r &= MP_MASK;
if (r < 31) break;
if (r < 31uL) break;
/* update sqrt ? */
if (next <= r) {
++y;
next = (y + 1) * (y + 1);
next = (y + 1uL) * (y + 1uL);
}
/* loop if divisible by 3,5,7,11,13,17,19,23,29 */
if ((r % 3) == 0) {
x = 0;
if ((r % 3uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 5) == 0) {
x = 0;
if ((r % 5uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 7) == 0) {
x = 0;
if ((r % 7uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 11) == 0) {
x = 0;
if ((r % 11uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 13) == 0) {
x = 0;
if ((r % 13uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 17) == 0) {
x = 0;
if ((r % 17uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 19) == 0) {
x = 0;
if ((r % 19uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 23) == 0) {
x = 0;
if ((r % 23uL) == 0uL) {
x = 0uL;
continue;
}
if ((r % 29) == 0) {
x = 0;
if ((r % 29uL) == 0uL) {
x = 0uL;
continue;
}
/* now check if r is divisible by x + k={1,7,11,13,17,19,23,29} */
for (x = 30; x <= y; x += 30) {
if ((r % (x + 1)) == 0) {
x = 0;
for (x = 30uL; x <= y; x += 30uL) {
if ((r % (x + 1uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 7)) == 0) {
x = 0;
if ((r % (x + 7uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 11)) == 0) {
x = 0;
if ((r % (x + 11uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 13)) == 0) {
x = 0;
if ((r % (x + 13uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 17)) == 0) {
x = 0;
if ((r % (x + 17uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 19)) == 0) {
x = 0;
if ((r % (x + 19uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 23)) == 0) {
x = 0;
if ((r % (x + 23uL)) == 0uL) {
x = 0uL;
break;
}
if ((r % (x + 29)) == 0) {
x = 0;
if ((r % (x + 29uL)) == 0uL) {
x = 0uL;
break;
}
}
} while (x == 0);
if (r > 31) {
fwrite(&r, 1, sizeof(mp_digit), out);
} while (x == 0uL);
if (r > 31uL) {
fwrite(&r, 1uL, sizeof(mp_digit), out);
printf("%9u\r", r);
fflush(stdout);
}
if (r < 31) break;
if (r < 31uL) break;
}
fclose(out);
@ -161,7 +161,7 @@ static void load_tab(void)
gen_prime();
primes = fopen("pprime.dat", "rb");
}
fseek(primes, 0, SEEK_END);
fseek(primes, 0L, SEEK_END);
n_prime = ftell(primes) / sizeof(mp_digit);
}
@ -172,7 +172,7 @@ static mp_digit prime_digit(void)
n = abs(rand()) % n_prime;
fseek(primes, n * sizeof(mp_digit), SEEK_SET);
fread(&d, 1, sizeof(mp_digit), primes);
fread(&d, 1uL, sizeof(mp_digit), primes);
return d;
}
@ -254,7 +254,7 @@ top:
}
/* n = z + 1 */
if ((res = mp_add_d(&z, 1, &n)) != MP_OKAY) { /* n = z + 1 */
if ((res = mp_add_d(&z, 1uL, &n)) != MP_OKAY) { /* n = z + 1 */
goto LBL_Z;
}
@ -263,7 +263,7 @@ top:
goto LBL_Z;
}
if (mp_cmp_d(&y, 1) != MP_EQ)
if (mp_cmp_d(&y, 1uL) != MP_EQ)
goto top;
/* now try base x=bases[ii] */
@ -276,7 +276,7 @@ top:
}
/* if y == 1 loop */
if (mp_cmp_d(&y, 1) == MP_EQ)
if (mp_cmp_d(&y, 1uL) == MP_EQ)
continue;
/* now x^2a mod n */
@ -284,7 +284,7 @@ top:
goto LBL_Z;
}
if (mp_cmp_d(&y, 1) == MP_EQ)
if (mp_cmp_d(&y, 1uL) == MP_EQ)
continue;
/* compute x^b mod n */
@ -293,7 +293,7 @@ top:
}
/* if y == 1 loop */
if (mp_cmp_d(&y, 1) == MP_EQ)
if (mp_cmp_d(&y, 1uL) == MP_EQ)
continue;
/* now x^2b mod n */
@ -301,7 +301,7 @@ top:
goto LBL_Z;
}
if (mp_cmp_d(&y, 1) == MP_EQ)
if (mp_cmp_d(&y, 1uL) == MP_EQ)
continue;
/* compute x^c mod n == x^ab mod n */
@ -310,7 +310,7 @@ top:
}
/* if y == 1 loop */
if (mp_cmp_d(&y, 1) == MP_EQ)
if (mp_cmp_d(&y, 1uL) == MP_EQ)
continue;
/* now compute (x^c mod n)^2 */
@ -319,7 +319,7 @@ top:
}
/* y should be 1 */
if (mp_cmp_d(&y, 1) != MP_EQ)
if (mp_cmp_d(&y, 1uL) != MP_EQ)
continue;
break;
}
@ -345,7 +345,7 @@ top:
}
/* get q to be the order of the large prime subgroup */
mp_sub_d(&n, 1, q);
mp_sub_d(&n, 1uL, q);
mp_div_2(q, q);
mp_div(q, &b, q, NULL);