run astyle

This commit is contained in:
Francois Perrad 2017-10-18 10:44:06 +02:00
parent 32e710ae07
commit 08741a141c
10 changed files with 1486 additions and 1338 deletions

View File

@ -76,8 +76,7 @@ int myrng(unsigned char *dst, int len, void *dat)
# if !defined(_WIN32)
fprintf(stderr, "\nno /dev/urandom\n");
# endif
}
else {
} else {
return fread(dst, 1, len, fd_urandom);
}
#endif
@ -472,15 +471,17 @@ int main(void)
mp_mulmod(&c, &b, &a, &c);
if (mp_cmp(&c, &d) != MP_EQ) {
/* *INDENT-OFF* */
printf("d = e mod a, c = e MOD a\n");
mp_todecimal(&a, buf); printf("a = %s\n", buf);
mp_todecimal(&e, buf); printf("e = %s\n", buf);
mp_todecimal(&d, buf); printf("d = %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* */
}
/* only one big montgomery reduction */
if (i > 10)
{
if (i > 10) {
n = 1000;
ix = 100;
}
@ -554,8 +555,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
for (cnt = 0; cnt < 10000;) {
mp_digit r2;
if (!(++cnt & 127))
{
if (!(++cnt & 127)) {
printf("%9d\r", cnt);
fflush(stdout);
}
@ -659,10 +659,8 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
# endif /* LTM_DEMO_TEST_REDUCE_2K_L */
#else
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 = cnt = add_d_n = sub_d_n = 0;
/* force KARA and TOOM to enable despite cutoffs */
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
@ -700,21 +698,32 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
printf
("%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu ",
printf("%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu ",
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);
ret=fgets(cmd, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(cmd, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
cmd[strlen(cmd) - 1] = 0;
printf("%-6s ]\r", cmd);
fflush(stdout);
if (!strcmp(cmd, "mul2d")) {
++mul2d_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
sscanf(buf, "%d", &rr);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_mul_2d(&a, rr, &a);
@ -727,11 +736,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "div2d")) {
++div2d_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
sscanf(buf, "%d", &rr);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_div_2d(&a, rr, &a, &e);
@ -747,11 +765,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "add")) {
++add_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
mp_copy(&a, &d);
mp_add(&d, &b, &d);
@ -791,11 +818,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
} else if (!strcmp(cmd, "sub")) {
++sub_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
mp_copy(&a, &d);
mp_sub(&d, &b, &d);
@ -809,11 +845,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "mul")) {
++mul_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
mp_copy(&a, &d);
mp_mul(&d, &b, &d);
@ -827,13 +872,25 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "div")) {
++div_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&d, buf, 64);
mp_div(&a, &b, &e, &f);
@ -851,9 +908,15 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
} else if (!strcmp(cmd, "sqr")) {
++sqr_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_copy(&a, &c);
mp_sqr(&c, &c);
@ -866,11 +929,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "gcd")) {
++gcd_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
mp_copy(&a, &d);
mp_gcd(&d, &b, &d);
@ -885,11 +957,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "lcm")) {
++lcm_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
mp_copy(&a, &d);
mp_lcm(&d, &b, &d);
@ -904,13 +985,25 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "expt")) {
++expt_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&d, buf, 64);
mp_copy(&a, &e);
mp_exptmod(&e, &b, &c, &e);
@ -925,11 +1018,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "invmod")) {
++inv_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&c, buf, 64);
mp_invmod(&a, &b, &d);
mp_mulmod(&d, &a, &b, &e);
@ -947,9 +1049,15 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
} else if (!strcmp(cmd, "div2")) {
++div2_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_div_2(&a, &c);
if (mp_cmp(&c, &b) != MP_EQ) {
@ -961,9 +1069,15 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "mul2")) {
++mul2_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_mul_2(&a, &c);
if (mp_cmp(&c, &b) != MP_EQ) {
@ -975,11 +1089,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "add_d")) {
++add_d_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
sscanf(buf, "%d", &ix);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_add_d(&a, ix, &c);
if (mp_cmp(&b, &c) != MP_EQ) {
@ -992,11 +1115,20 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
}
} else if (!strcmp(cmd, "sub_d")) {
++sub_d_n;
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&a, buf, 64);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
sscanf(buf, "%d", &ix);
ret=fgets(buf, 4095, stdin); if(!ret){_panic(__LINE__);}
ret=fgets(buf, 4095, stdin);
if (!ret) {
_panic(__LINE__);
}
mp_read_radix(&b, buf, 64);
mp_sub_d(&a, ix, &c);
if (mp_cmp(&b, &c) != MP_EQ) {

View File

@ -33,7 +33,8 @@ int main(void)
}
if (clock() - t1 > CLOCKS_PER_SEC) {
printf("."); fflush(stdout);
printf(".");
fflush(stdout);
// sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC);
t1 = clock();
}
@ -68,7 +69,8 @@ int main(void)
mp_toradix(&q, buf, 10);
printf("\n\n%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf); fflush(out);
fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
fflush(out);
}
return 0;

View File

@ -34,7 +34,8 @@ int main(void)
if (a.dp[0] >= MP_MASK) break;
mp_prime_is_prime(&a, 1, &res);
if (res == 0) continue;
printf("."); fflush(stdout);
printf(".");
fflush(stdout);
mp_sub_d(&a, 1, &b);
mp_div_2(&b, &b);
mp_prime_is_prime(&b, 3, &res);
@ -44,11 +45,14 @@ int main(void)
}
if (res != 1) {
printf("Error not DR modulus\n"); sizes[x] += 1; goto top;
printf("Error not DR modulus\n");
sizes[x] += 1;
goto top;
} else {
mp_toradix(&a, buf, 10);
printf("\n\np == %s\n\n", buf);
fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf); fflush(out);
fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf);
fflush(out);
}
}
fclose(out);

View File

@ -5,8 +5,7 @@
#include <time.h>
#include <tommath.h>
int
is_mersenne (long s, int *pp)
int is_mersenne(long s, int *pp)
{
mp_int n, u;
int res, k;
@ -62,14 +61,15 @@ is_mersenne (long s, int *pp)
}
res = MP_OKAY;
LBL_MU:mp_clear (&u);
LBL_N:mp_clear (&n);
LBL_MU:
mp_clear(&u);
LBL_N:
mp_clear(&n);
return res;
}
/* square root of a long < 65536 */
long
i_sqrt (long x)
long i_sqrt(long x)
{
long x1, x2;
@ -87,8 +87,7 @@ i_sqrt (long x)
}
/* is the long prime by brute force */
int
isprime (long k)
int isprime(long k)
{
long y, z;
@ -101,8 +100,7 @@ isprime (long k)
}
int
main (void)
int main(void)
{
int pp;
long k;

View File

@ -12,7 +12,8 @@ int main(void)
/* loop through various sizes */
for (x = 4; x < 256; x++) {
printf("DIGITS == %3ld...", x); fflush(stdout);
printf("DIGITS == %3ld...", x);
fflush(stdout);
/* make up the odd modulus */
mp_rand(&modulus, x);

View File

@ -11,8 +11,7 @@ int n_prime;
FILE *primes;
/* fast square root */
static mp_digit
i_sqrt (mp_word x)
static mp_digit i_sqrt(mp_word x)
{
mp_word x1, x2;
@ -39,6 +38,7 @@ static void gen_prime (void)
out = fopen("pprime.dat", "wb");
/* 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);
@ -49,6 +49,7 @@ static void gen_prime (void)
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);
/* *INDENT-ON* */
/* get square root, since if 'r' is composite its factors must be < than this */
y = i_sqrt(r);
@ -140,7 +141,11 @@ static void gen_prime (void)
}
}
} while (x == 0);
if (r > 31) { fwrite(&r, 1, sizeof(mp_digit), out); printf("%9d\r", r); fflush(stdout); }
if (r > 31) {
fwrite(&r, 1, sizeof(mp_digit), out);
printf("%9d\r", r);
fflush(stdout);
}
if (r < 31) break;
}
@ -171,8 +176,7 @@ mp_digit prime_digit(void)
/* makes a prime of at least k bits */
int
pprime (int k, int li, mp_int * p, mp_int * q)
int pprime(int k, int li, mp_int *p, mp_int *q)
{
mp_int a, b, c, n, x, y, z, v;
int res, ii;
@ -346,20 +350,27 @@ pprime (int k, int li, mp_int * p, mp_int * q)
mp_exch(&n, p);
res = MP_OKAY;
LBL_Z:mp_clear (&z);
LBL_Y:mp_clear (&y);
LBL_X:mp_clear (&x);
LBL_N:mp_clear (&n);
LBL_B:mp_clear (&b);
LBL_A:mp_clear (&a);
LBL_V:mp_clear (&v);
LBL_C:mp_clear (&c);
LBL_Z:
mp_clear(&z);
LBL_Y:
mp_clear(&y);
LBL_X:
mp_clear(&x);
LBL_N:
mp_clear(&n);
LBL_B:
mp_clear(&b);
LBL_A:
mp_clear(&a);
LBL_V:
mp_clear(&v);
LBL_C:
mp_clear(&c);
return res;
}
int
main (void)
int main(void)
{
mp_int p, q;
char buf[4096];

View File

@ -48,10 +48,12 @@ static uint64_t TIMFUNC (void)
}
/* *INDENT-OFF* */
/* generic ISO C timer */
uint64_t LBL_T;
void t_start(void) { LBL_T = TIMFUNC(); }
uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
/* *INDENT-ON* */
#else
extern void t_start(void);
@ -115,8 +117,7 @@ uint64_t time_sqr(int size, int s)
return t1;
}
int
main (void)
int main(void)
{
uint64_t t1, t2;
int x, y;

View File

@ -147,4 +147,4 @@ perlcritic:
perlcritic *.pl
astyle:
astyle --options=astylerc $(OBJECTS:.o=.c)
astyle --options=astylerc $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c

View File

@ -123,8 +123,7 @@ int main(int argc, char *argv[])
} else if (max == 0) {
max = 1;
}
}
else {
} else {
max = 0;
}