commit
9f41e565bf
38
demo/demo.c
38
demo/demo.c
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "tommath.h"
|
#include "tommath.h"
|
||||||
|
|
||||||
void ndraw(mp_int *a, char *name)
|
static void ndraw(mp_int *a, const char *name)
|
||||||
{
|
{
|
||||||
char buf[16000];
|
char buf[16000];
|
||||||
|
|
||||||
@ -50,10 +50,10 @@ static void draw(mp_int *a)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static unsigned long lfsr = 0xAAAAAAAAUL;
|
||||||
|
|
||||||
unsigned long lfsr = 0xAAAAAAAAUL;
|
static int lbit(void)
|
||||||
|
|
||||||
int lbit(void)
|
|
||||||
{
|
{
|
||||||
if (lfsr & 0x80000000UL) {
|
if (lfsr & 0x80000000UL) {
|
||||||
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
||||||
@ -63,11 +63,13 @@ int lbit(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
|
#if defined(LTM_DEMO_REAL_RAND) && !defined(_WIN32)
|
||||||
static FILE *fd_urandom;
|
static FILE *fd_urandom;
|
||||||
#endif
|
#endif
|
||||||
int myrng(unsigned char *dst, int len, void *dat)
|
#if LTM_DEMO_TEST_VS_MTEST == 0
|
||||||
|
static int myrng(unsigned char *dst, int len, void *dat)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
(void)dat;
|
(void)dat;
|
||||||
@ -89,6 +91,7 @@ int myrng(unsigned char *dst, int len, void *dat)
|
|||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LTM_DEMO_TEST_VS_MTEST != 0
|
#if LTM_DEMO_TEST_VS_MTEST != 0
|
||||||
static void _panic(int l)
|
static void _panic(int l)
|
||||||
@ -104,7 +107,7 @@ static void _panic(int l)
|
|||||||
if (!ret) { _panic(__LINE__); } \
|
if (!ret) { _panic(__LINE__); } \
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_int a, b, c, d, e, f;
|
static mp_int a, b, c, d, e, f;
|
||||||
|
|
||||||
static void _cleanup(void)
|
static void _cleanup(void)
|
||||||
{
|
{
|
||||||
@ -116,12 +119,13 @@ static void _cleanup(void)
|
|||||||
fclose(fd_urandom);
|
fclose(fd_urandom);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#if LTM_DEMO_TEST_VS_MTEST == 0
|
||||||
struct mp_sqrtmod_prime_st {
|
struct mp_sqrtmod_prime_st {
|
||||||
unsigned long p;
|
unsigned long p;
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
mp_digit r;
|
mp_digit r;
|
||||||
};
|
};
|
||||||
struct mp_sqrtmod_prime_st sqrtmod_prime[] = {
|
static struct mp_sqrtmod_prime_st sqrtmod_prime[] = {
|
||||||
{ 5, 14, 3 },
|
{ 5, 14, 3 },
|
||||||
{ 7, 9, 4 },
|
{ 7, 9, 4 },
|
||||||
{ 113, 2, 62 }
|
{ 113, 2, 62 }
|
||||||
@ -130,14 +134,18 @@ struct mp_jacobi_st {
|
|||||||
unsigned long n;
|
unsigned long n;
|
||||||
int c[16];
|
int c[16];
|
||||||
};
|
};
|
||||||
struct mp_jacobi_st jacobi[] = {
|
static struct mp_jacobi_st jacobi[] = {
|
||||||
{ 3, { 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1 } },
|
{ 3, { 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1 } },
|
||||||
{ 5, { 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0 } },
|
{ 5, { 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0, 1, -1, -1, 1, 0 } },
|
||||||
{ 7, { 1, -1, 1, -1, -1, 0, 1, 1, -1, 1, -1, -1, 0, 1, 1, -1 } },
|
{ 7, { 1, -1, 1, -1, -1, 0, 1, 1, -1, 1, -1, -1, 0, 1, 1, -1 } },
|
||||||
{ 9, { -1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 } },
|
{ 9, { -1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 } },
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
char cmd[4096], buf[4096];
|
#if LTM_DEMO_TEST_VS_MTEST != 0
|
||||||
|
static char cmd[4096];
|
||||||
|
#endif
|
||||||
|
static char buf[4096];
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
unsigned rr;
|
unsigned rr;
|
||||||
@ -715,14 +723,14 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
|
|||||||
FGETS(buf, 4095, stdin);
|
FGETS(buf, 4095, stdin);
|
||||||
mp_read_radix(&a, buf, 64);
|
mp_read_radix(&a, buf, 64);
|
||||||
FGETS(buf, 4095, stdin);
|
FGETS(buf, 4095, stdin);
|
||||||
sscanf(buf, "%d", &rr);
|
sscanf(buf, "%u", &rr);
|
||||||
FGETS(buf, 4095, stdin);
|
FGETS(buf, 4095, stdin);
|
||||||
mp_read_radix(&b, buf, 64);
|
mp_read_radix(&b, buf, 64);
|
||||||
|
|
||||||
mp_mul_2d(&a, rr, &a);
|
mp_mul_2d(&a, rr, &a);
|
||||||
a.sign = b.sign;
|
a.sign = b.sign;
|
||||||
if (mp_cmp(&a, &b) != MP_EQ) {
|
if (mp_cmp(&a, &b) != MP_EQ) {
|
||||||
printf("mul2d failed, rr == %d\n", rr);
|
printf("mul2d failed, rr == %u\n", rr);
|
||||||
draw(&a);
|
draw(&a);
|
||||||
draw(&b);
|
draw(&b);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -732,17 +740,17 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
|
|||||||
FGETS(buf, 4095, stdin);
|
FGETS(buf, 4095, stdin);
|
||||||
mp_read_radix(&a, buf, 64);
|
mp_read_radix(&a, buf, 64);
|
||||||
FGETS(buf, 4095, stdin);
|
FGETS(buf, 4095, stdin);
|
||||||
sscanf(buf, "%d", &rr);
|
sscanf(buf, "%u", &rr);
|
||||||
FGETS(buf, 4095, stdin);
|
FGETS(buf, 4095, stdin);
|
||||||
mp_read_radix(&b, buf, 64);
|
mp_read_radix(&b, buf, 64);
|
||||||
|
|
||||||
mp_div_2d(&a, rr, &a, &e);
|
mp_div_2d(&a, rr, &a, &e);
|
||||||
a.sign = b.sign;
|
a.sign = b.sign;
|
||||||
if (a.used == b.used && a.used == 0) {
|
if ((a.used == b.used) && (a.used == 0)) {
|
||||||
a.sign = b.sign = MP_ZPOS;
|
a.sign = b.sign = MP_ZPOS;
|
||||||
}
|
}
|
||||||
if (mp_cmp(&a, &b) != MP_EQ) {
|
if (mp_cmp(&a, &b) != MP_EQ) {
|
||||||
printf("div2d failed, rr == %d\n", rr);
|
printf("div2d failed, rr == %u\n", rr);
|
||||||
draw(&a);
|
draw(&a);
|
||||||
draw(&b);
|
draw(&b);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -839,7 +847,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
|
|||||||
mp_read_radix(&d, buf, 64);
|
mp_read_radix(&d, buf, 64);
|
||||||
|
|
||||||
mp_div(&a, &b, &e, &f);
|
mp_div(&a, &b, &e, &f);
|
||||||
if (mp_cmp(&c, &e) != MP_EQ || mp_cmp(&d, &f) != MP_EQ) {
|
if ((mp_cmp(&c, &e) != MP_EQ) || (mp_cmp(&d, &f) != MP_EQ)) {
|
||||||
printf("div %lu %d, %d, failure!\n", div_n, mp_cmp(&c, &e),
|
printf("div %lu %d, %d, failure!\n", div_n, mp_cmp(&c, &e),
|
||||||
mp_cmp(&d, &f));
|
mp_cmp(&d, &f));
|
||||||
draw(&a);
|
draw(&a);
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
uint64_t _tt;
|
|
||||||
|
|
||||||
#ifdef IOWNANATHLON
|
#ifdef IOWNANATHLON
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#define SLEEP sleep(4)
|
#define SLEEP sleep(4)
|
||||||
@ -19,7 +17,7 @@ uint64_t _tt;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ndraw(mp_int *a, char *name)
|
static void ndraw(mp_int *a, const char *name)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
@ -34,9 +32,9 @@ static void draw(mp_int *a)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long lfsr = 0xAAAAAAAAUL;
|
static unsigned long lfsr = 0xAAAAAAAAUL;
|
||||||
|
|
||||||
int lbit(void)
|
static int lbit(void)
|
||||||
{
|
{
|
||||||
if (lfsr & 0x80000000UL) {
|
if (lfsr & 0x80000000UL) {
|
||||||
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
||||||
@ -181,7 +179,7 @@ int main(void)
|
|||||||
TOOM_SQR_CUTOFF = (ix == 2) ? old_toom_s : 9999;
|
TOOM_SQR_CUTOFF = (ix == 2) ? old_toom_s : 9999;
|
||||||
|
|
||||||
log = FOPEN((ix == 0) ? "logs/mult.log" : (ix == 1) ? "logs/mult_kara.log" : "logs/mult_toom.log", "w");
|
log = FOPEN((ix == 0) ? "logs/mult.log" : (ix == 1) ? "logs/mult_kara.log" : "logs/mult_toom.log", "w");
|
||||||
for (cnt = 4; cnt <= 10240 / DIGIT_BIT; cnt += 2) {
|
for (cnt = 4; cnt <= (10240 / DIGIT_BIT); cnt += 2) {
|
||||||
SLEEP;
|
SLEEP;
|
||||||
mp_rand(&a, cnt);
|
mp_rand(&a, cnt);
|
||||||
mp_rand(&b, cnt);
|
mp_rand(&b, cnt);
|
||||||
@ -202,7 +200,7 @@ int main(void)
|
|||||||
FCLOSE(log);
|
FCLOSE(log);
|
||||||
|
|
||||||
log = FOPEN((ix == 0) ? "logs/sqr.log" : (ix == 1) ? "logs/sqr_kara.log" : "logs/sqr_toom.log", "w");
|
log = FOPEN((ix == 0) ? "logs/sqr.log" : (ix == 1) ? "logs/sqr_kara.log" : "logs/sqr_toom.log", "w");
|
||||||
for (cnt = 4; cnt <= 10240 / DIGIT_BIT; cnt += 2) {
|
for (cnt = 4; cnt <= (10240 / DIGIT_BIT); cnt += 2) {
|
||||||
SLEEP;
|
SLEEP;
|
||||||
mp_rand(&a, cnt);
|
mp_rand(&a, cnt);
|
||||||
rr = 0;
|
rr = 0;
|
||||||
@ -224,7 +222,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *primes[] = {
|
const char *primes[] = {
|
||||||
/* 2K large moduli */
|
/* 2K large moduli */
|
||||||
"179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586239334100047359817950870678242457666208137217",
|
"179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586239334100047359817950870678242457666208137217",
|
||||||
"32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638099733077152121140120031150424541696791951097529546801429027668869927491725169",
|
"32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638099733077152121140120031150424541696791951097529546801429027668869927491725169",
|
||||||
@ -292,7 +290,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
printf("Exponentiating\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
|
printf("Exponentiating\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
|
||||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||||
FPRINTF(n < 4 ? logd : (n < 9) ? logc : (n < 16) ? logb : log,
|
FPRINTF((n < 4) ? logd : (n < 9) ? logc : (n < 16) ? logb : log,
|
||||||
"%d %9" PRIu64 "\n", mp_count_bits(&a), tt);
|
"%d %9" PRIu64 "\n", mp_count_bits(&a), tt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int sizes[] = {256, 512, 768, 1024, 1536, 2048, 3072, 4096};
|
static int sizes[] = {256, 512, 768, 1024, 1536, 2048, 3072, 4096};
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@ -16,6 +16,7 @@ int main(void)
|
|||||||
mp_init_multi(&q, &p, NULL);
|
mp_init_multi(&q, &p, NULL);
|
||||||
|
|
||||||
out = fopen("2kprime.1", "w");
|
out = fopen("2kprime.1", "w");
|
||||||
|
if (out != NULL) {
|
||||||
for (x = 0; x < (int)(sizeof(sizes) / sizeof(sizes[0])); x++) {
|
for (x = 0; x < (int)(sizeof(sizes) / sizeof(sizes[0])); x++) {
|
||||||
top:
|
top:
|
||||||
mp_2expt(&q, sizes[x]);
|
mp_2expt(&q, sizes[x]);
|
||||||
@ -32,7 +33,7 @@ top:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clock() - t1 > CLOCKS_PER_SEC) {
|
if ((clock() - t1) > CLOCKS_PER_SEC) {
|
||||||
printf(".");
|
printf(".");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
// sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC);
|
// sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC);
|
||||||
@ -72,6 +73,8 @@ top:
|
|||||||
fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
|
fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
|
||||||
fflush(out);
|
fflush(out);
|
||||||
}
|
}
|
||||||
|
fclose(out);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* Makes safe primes of a DR nature */
|
/* Makes safe primes of a DR nature */
|
||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
|
|
||||||
int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
|
static int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@ -14,6 +14,7 @@ int main(void)
|
|||||||
mp_init(&b);
|
mp_init(&b);
|
||||||
|
|
||||||
out = fopen("drprimes.txt", "w");
|
out = fopen("drprimes.txt", "w");
|
||||||
|
if (out != NULL) {
|
||||||
for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
|
for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
|
||||||
top:
|
top:
|
||||||
printf("Seeking a %d-bit safe prime\n", sizes[x] * DIGIT_BIT);
|
printf("Seeking a %d-bit safe prime\n", sizes[x] * DIGIT_BIT);
|
||||||
@ -56,6 +57,7 @@ top:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
}
|
||||||
|
|
||||||
mp_clear(&a);
|
mp_clear(&a);
|
||||||
mp_clear(&b);
|
mp_clear(&b);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
|
|
||||||
int is_mersenne(long s, int *pp)
|
static int is_mersenne(long s, int *pp)
|
||||||
{
|
{
|
||||||
mp_int n, u;
|
mp_int n, u;
|
||||||
int res, k;
|
int res, k;
|
||||||
@ -32,7 +32,7 @@ int is_mersenne(long s, int *pp)
|
|||||||
mp_set(&u, 4);
|
mp_set(&u, 4);
|
||||||
|
|
||||||
/* for k=1 to s-2 do */
|
/* for k=1 to s-2 do */
|
||||||
for (k = 1; k <= s - 2; k++) {
|
for (k = 1; k <= (s - 2); k++) {
|
||||||
/* u = u^2 - 2 mod n */
|
/* u = u^2 - 2 mod n */
|
||||||
if ((res = mp_sqr(&u, &u)) != MP_OKAY) {
|
if ((res = mp_sqr(&u, &u)) != MP_OKAY) {
|
||||||
goto LBL_MU;
|
goto LBL_MU;
|
||||||
@ -69,7 +69,7 @@ LBL_N:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* square root of a long < 65536 */
|
/* square root of a long < 65536 */
|
||||||
long i_sqrt(long x)
|
static long i_sqrt(long x)
|
||||||
{
|
{
|
||||||
long x1, x2;
|
long x1, x2;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ long i_sqrt(long x)
|
|||||||
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
|
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
|
||||||
} while (x1 != x2);
|
} while (x1 != x2);
|
||||||
|
|
||||||
if (x1 * x1 > x) {
|
if ((x1 * x1) > x) {
|
||||||
--x1;
|
--x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ long i_sqrt(long x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* is the long prime by brute force */
|
/* is the long prime by brute force */
|
||||||
int isprime(long k)
|
static int isprime(long k)
|
||||||
{
|
{
|
||||||
long y, z;
|
long y, z;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* tests the montgomery routines */
|
/* tests the montgomery routines */
|
||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
16
etc/pprime.c
16
etc/pprime.c
@ -7,8 +7,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "tommath.h"
|
#include "tommath.h"
|
||||||
|
|
||||||
int n_prime;
|
static int n_prime;
|
||||||
FILE *primes;
|
static FILE *primes;
|
||||||
|
|
||||||
/* fast square root */
|
/* fast square root */
|
||||||
static mp_digit i_sqrt(mp_word x)
|
static mp_digit i_sqrt(mp_word x)
|
||||||
@ -21,7 +21,7 @@ static mp_digit i_sqrt(mp_word x)
|
|||||||
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
|
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
|
||||||
} while (x1 != x2);
|
} while (x1 != x2);
|
||||||
|
|
||||||
if (x1 * x1 > x) {
|
if ((x1 * x1) > x) {
|
||||||
--x1;
|
--x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ static void gen_prime(void)
|
|||||||
FILE *out;
|
FILE *out;
|
||||||
|
|
||||||
out = fopen("pprime.dat", "wb");
|
out = fopen("pprime.dat", "wb");
|
||||||
|
if (out != NULL) {
|
||||||
|
|
||||||
/* write first set of primes */
|
/* write first set of primes */
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
@ -143,16 +144,17 @@ static void gen_prime(void)
|
|||||||
} while (x == 0);
|
} while (x == 0);
|
||||||
if (r > 31) {
|
if (r > 31) {
|
||||||
fwrite(&r, 1, sizeof(mp_digit), out);
|
fwrite(&r, 1, sizeof(mp_digit), out);
|
||||||
printf("%9d\r", r);
|
printf("%9u\r", r);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
if (r < 31) break;
|
if (r < 31) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_tab(void)
|
static void load_tab(void)
|
||||||
{
|
{
|
||||||
primes = fopen("pprime.dat", "rb");
|
primes = fopen("pprime.dat", "rb");
|
||||||
if (primes == NULL) {
|
if (primes == NULL) {
|
||||||
@ -163,7 +165,7 @@ void load_tab(void)
|
|||||||
n_prime = ftell(primes) / sizeof(mp_digit);
|
n_prime = ftell(primes) / sizeof(mp_digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_digit prime_digit(void)
|
static mp_digit prime_digit(void)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
mp_digit d;
|
mp_digit d;
|
||||||
@ -176,7 +178,7 @@ mp_digit prime_digit(void)
|
|||||||
|
|
||||||
|
|
||||||
/* makes a prime of at least k bits */
|
/* makes a prime of at least k bits */
|
||||||
int pprime(int k, int li, mp_int *p, mp_int *q)
|
static int pprime(int k, int li, mp_int *p, mp_int *q)
|
||||||
{
|
{
|
||||||
mp_int a, b, c, n, x, y, z, v;
|
mp_int a, b, c, n, x, y, z, v;
|
||||||
int res, ii;
|
int res, ii;
|
||||||
|
11
etc/tune.c
11
etc/tune.c
@ -3,7 +3,6 @@
|
|||||||
* Tom St Denis, tstdenis82@gmail.com
|
* Tom St Denis, tstdenis82@gmail.com
|
||||||
*/
|
*/
|
||||||
#include <tommath.h>
|
#include <tommath.h>
|
||||||
#include <time.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* how many times todo each size mult. Depends on your computer. For slow computers
|
/* how many times todo each size mult. Depends on your computer. For slow computers
|
||||||
@ -50,9 +49,9 @@ static uint64_t TIMFUNC(void)
|
|||||||
|
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
/* generic ISO C timer */
|
/* generic ISO C timer */
|
||||||
uint64_t LBL_T;
|
static uint64_t LBL_T;
|
||||||
void t_start(void) { LBL_T = TIMFUNC(); }
|
static void t_start(void) { LBL_T = TIMFUNC(); }
|
||||||
uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
|
static uint64_t t_read(void) { return TIMFUNC() - LBL_T; }
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -60,7 +59,7 @@ extern void t_start(void);
|
|||||||
extern uint64_t t_read(void);
|
extern uint64_t t_read(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint64_t time_mult(int size, int s)
|
static uint64_t time_mult(int size, int s)
|
||||||
{
|
{
|
||||||
unsigned long x;
|
unsigned long x;
|
||||||
mp_int a, b, c;
|
mp_int a, b, c;
|
||||||
@ -90,7 +89,7 @@ uint64_t time_mult(int size, int s)
|
|||||||
return t1;
|
return t1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t time_sqr(int size, int s)
|
static uint64_t time_sqr(int size, int s)
|
||||||
{
|
{
|
||||||
unsigned long x;
|
unsigned long x;
|
||||||
mp_int a, b;
|
mp_int a, b;
|
||||||
|
Loading…
Reference in New Issue
Block a user