summaryrefslogtreecommitdiff
path: root/moduli.c
diff options
context:
space:
mode:
Diffstat (limited to 'moduli.c')
-rw-r--r--moduli.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/moduli.c b/moduli.c
index d454c30dc..f72baab3e 100644
--- a/moduli.c
+++ b/moduli.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: moduli.c,v 1.6 2004/04/22 11:56:57 djm Exp $ */ 1/* $OpenBSD: moduli.c,v 1.7 2004/05/09 00:06:47 djm Exp $ */
2/* 2/*
3 * Copyright 1994 Phil Karn <karn@qualcomm.com> 3 * Copyright 1994 Phil Karn <karn@qualcomm.com>
4 * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com> 4 * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com>
@@ -38,7 +38,6 @@
38 */ 38 */
39 39
40#include "includes.h" 40#include "includes.h"
41#include "moduli.h"
42#include "xmalloc.h" 41#include "xmalloc.h"
43#include "log.h" 42#include "log.h"
44 43
@@ -91,6 +90,19 @@
91#define SHIFT_MEGAWORD (SHIFT_MEGABYTE-SHIFT_BYTE) 90#define SHIFT_MEGAWORD (SHIFT_MEGABYTE-SHIFT_BYTE)
92 91
93/* 92/*
93 * Using virtual memory can cause thrashing. This should be the largest
94 * number that is supported without a large amount of disk activity --
95 * that would increase the run time from hours to days or weeks!
96 */
97#define LARGE_MINIMUM (8UL) /* megabytes */
98
99/*
100 * Do not increase this number beyond the unsigned integer bit size.
101 * Due to a multiple of 4, it must be LESS than 128 (yielding 2**30 bits).
102 */
103#define LARGE_MAXIMUM (127UL) /* megabytes */
104
105/*
94 * Constant: when used with 32-bit integers, the largest sieve prime 106 * Constant: when used with 32-bit integers, the largest sieve prime
95 * has to be less than 2**32. 107 * has to be less than 2**32.
96 */ 108 */
@@ -114,6 +126,9 @@
114 * Prime testing defines 126 * Prime testing defines
115 */ 127 */
116 128
129/* Minimum number of primality tests to perform */
130#define TRIAL_MINIMUM (4)
131
117/* 132/*
118 * Sieving data (XXX - move to struct) 133 * Sieving data (XXX - move to struct)
119 */ 134 */
@@ -235,6 +250,13 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start)
235 250
236 largememory = memory; 251 largememory = memory;
237 252
253 if (memory != 0 &&
254 (memory < LARGE_MINIMUM || memory > LARGE_MAXIMUM)) {
255 error("Invalid memory amount (min %ld, max %ld)",
256 LARGE_MINIMUM, LARGE_MAXIMUM);
257 return (-1);
258 }
259
238 /* 260 /*
239 * Set power to the length in bits of the prime to be generated. 261 * Set power to the length in bits of the prime to be generated.
240 * This is changed to 1 less than the desired safe prime moduli p. 262 * This is changed to 1 less than the desired safe prime moduli p.
@@ -430,8 +452,7 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start)
430 * The result is a list of so-call "safe" primes 452 * The result is a list of so-call "safe" primes
431 */ 453 */
432int 454int
433prime_test(FILE *in, FILE *out, u_int32_t trials, 455prime_test(FILE *in, FILE *out, u_int32_t trials, u_int32_t generator_wanted)
434 u_int32_t generator_wanted)
435{ 456{
436 BIGNUM *q, *p, *a; 457 BIGNUM *q, *p, *a;
437 BN_CTX *ctx; 458 BN_CTX *ctx;
@@ -441,6 +462,11 @@ prime_test(FILE *in, FILE *out, u_int32_t trials,
441 time_t time_start, time_stop; 462 time_t time_start, time_stop;
442 int res; 463 int res;
443 464
465 if (trials < TRIAL_MINIMUM) {
466 error("Minimum primality trials is %d", TRIAL_MINIMUM);
467 return (-1);
468 }
469
444 time(&time_start); 470 time(&time_start);
445 471
446 p = BN_new(); 472 p = BN_new();