Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / etc / drprime.c
blob328ff53769bc8394ffcef701d970d6b2c28aa952
1 /* $NetBSD: drprime.c,v 1.1.1.2 2014/04/24 12:45:39 pettai Exp $ */
3 /* Makes safe primes of a DR nature */
4 #include <tommath.h>
6 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 };
7 int main(void)
9 int res, x, y;
10 char buf[4096];
11 FILE *out;
12 mp_int a, b;
14 mp_init(&a);
15 mp_init(&b);
17 out = fopen("drprimes.txt", "w");
18 for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
19 top:
20 printf("Seeking a %d-bit safe prime\n", sizes[x] * DIGIT_BIT);
21 mp_grow(&a, sizes[x]);
22 mp_zero(&a);
23 for (y = 1; y < sizes[x]; y++) {
24 a.dp[y] = MP_MASK;
27 /* make a DR modulus */
28 a.dp[0] = -1;
29 a.used = sizes[x];
31 /* now loop */
32 res = 0;
33 for (;;) {
34 a.dp[0] += 4;
35 if (a.dp[0] >= MP_MASK) break;
36 mp_prime_is_prime(&a, 1, &res);
37 if (res == 0) continue;
38 printf("."); fflush(stdout);
39 mp_sub_d(&a, 1, &b);
40 mp_div_2(&b, &b);
41 mp_prime_is_prime(&b, 3, &res);
42 if (res == 0) continue;
43 mp_prime_is_prime(&a, 3, &res);
44 if (res == 1) break;
47 if (res != 1) {
48 printf("Error not DR modulus\n"); sizes[x] += 1; goto top;
49 } else {
50 mp_toradix(&a, buf, 10);
51 printf("\n\np == %s\n\n", buf);
52 fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf); fflush(out);
55 fclose(out);
57 mp_clear(&a);
58 mp_clear(&b);
60 return 0;
64 /* Source: /cvs/libtom/libtommath/etc/drprime.c,v */
65 /* Revision: 1.2 */
66 /* Date: 2005/05/05 14:38:47 */