comparison etc/drprime.c @ 282:91fbc376f010libtommath-origlibtommath-0.35

Import of libtommath 0.35 From ltm-0.35.tar.bz2 SHA1 of 3f193dbae9351e92d02530994fa18236f7fde01c
author Matt Johnston Wed, 08 Mar 2006 13:16:18 +0000 97db060d0ef5
comparison
equal inserted replaced
-1:000000000000 282:91fbc376f010
1 /* Makes safe primes of a DR nature */
2 #include <tommath.h>
3
4 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 };
5 int main(void)
6 {
7 int res, x, y;
8 char buf[4096];
9 FILE *out;
10 mp_int a, b;
11
12 mp_init(&a);
13 mp_init(&b);
14
15 out = fopen("drprimes.txt", "w");
16 for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
17 top:
18 printf("Seeking a %d-bit safe prime\n", sizes[x] * DIGIT_BIT);
19 mp_grow(&a, sizes[x]);
20 mp_zero(&a);
21 for (y = 1; y < sizes[x]; y++) {
23 }
24
25 /* make a DR modulus */
26 a.dp[0] = -1;
27 a.used = sizes[x];
28
29 /* now loop */
30 res = 0;
31 for (;;) {
32 a.dp[0] += 4;
33 if (a.dp[0] >= MP_MASK) break;
34 mp_prime_is_prime(&a, 1, &res);
35 if (res == 0) continue;
36 printf("."); fflush(stdout);
37 mp_sub_d(&a, 1, &b);
38 mp_div_2(&b, &b);
39 mp_prime_is_prime(&b, 3, &res);
40 if (res == 0) continue;
41 mp_prime_is_prime(&a, 3, &res);
42 if (res == 1) break;
43 }
44
45 if (res != 1) {
46 printf("Error not DR modulus\n"); sizes[x] += 1; goto top;
47 } else {