diff options
author | Damien Miller <djm@mindrot.org> | 2003-11-21 23:48:55 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2003-11-21 23:48:55 +1100 |
commit | a8e06cef35c205e1aa562513c6d034a10c8c9a6d (patch) | |
tree | cf8bdb4466f553088c020b9179cabd6eaf196075 /moduli.c | |
parent | 8c5e91c03fdd2693f0635f8b2a9904bffc94ce16 (diff) |
- djm@cvs.openbsd.org 2003/11/21 11:57:03
[everything]
unexpand and delete whitespace at EOL; ok markus@
(done locally and RCS IDs synced)
Diffstat (limited to 'moduli.c')
-rw-r--r-- | moduli.c | 62 |
1 files changed, 31 insertions, 31 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: moduli.c,v 1.1 2003/07/28 09:49:56 djm Exp $ */ | 1 | /* $OpenBSD: moduli.c,v 1.2 2003/11/21 11:57:03 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> |
@@ -46,7 +46,7 @@ | |||
46 | 46 | ||
47 | 47 | ||
48 | /* | 48 | /* |
49 | * Debugging defines | 49 | * Debugging defines |
50 | */ | 50 | */ |
51 | 51 | ||
52 | /* define DEBUG_LARGE 1 */ | 52 | /* define DEBUG_LARGE 1 */ |
@@ -244,9 +244,9 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
244 | largememory = memory; | 244 | largememory = memory; |
245 | 245 | ||
246 | /* | 246 | /* |
247 | * Set power to the length in bits of the prime to be generated. | 247 | * Set power to the length in bits of the prime to be generated. |
248 | * This is changed to 1 less than the desired safe prime moduli p. | 248 | * This is changed to 1 less than the desired safe prime moduli p. |
249 | */ | 249 | */ |
250 | if (power > TEST_MAXIMUM) { | 250 | if (power > TEST_MAXIMUM) { |
251 | error("Too many bits: %u > %lu", power, TEST_MAXIMUM); | 251 | error("Too many bits: %u > %lu", power, TEST_MAXIMUM); |
252 | return (-1); | 252 | return (-1); |
@@ -257,16 +257,16 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
257 | power--; /* decrement before squaring */ | 257 | power--; /* decrement before squaring */ |
258 | 258 | ||
259 | /* | 259 | /* |
260 | * The density of ordinary primes is on the order of 1/bits, so the | 260 | * The density of ordinary primes is on the order of 1/bits, so the |
261 | * density of safe primes should be about (1/bits)**2. Set test range | 261 | * density of safe primes should be about (1/bits)**2. Set test range |
262 | * to something well above bits**2 to be reasonably sure (but not | 262 | * to something well above bits**2 to be reasonably sure (but not |
263 | * guaranteed) of catching at least one safe prime. | 263 | * guaranteed) of catching at least one safe prime. |
264 | */ | 264 | */ |
265 | largewords = ((power * power) >> (SHIFT_WORD - TEST_POWER)); | 265 | largewords = ((power * power) >> (SHIFT_WORD - TEST_POWER)); |
266 | 266 | ||
267 | /* | 267 | /* |
268 | * Need idea of how much memory is available. We don't have to use all | 268 | * Need idea of how much memory is available. We don't have to use all |
269 | * of it. | 269 | * of it. |
270 | */ | 270 | */ |
271 | if (largememory > LARGE_MAXIMUM) { | 271 | if (largememory > LARGE_MAXIMUM) { |
272 | logit("Limited memory: %u MB; limit %lu MB", | 272 | logit("Limited memory: %u MB; limit %lu MB", |
@@ -315,8 +315,8 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
315 | q = BN_new(); | 315 | q = BN_new(); |
316 | 316 | ||
317 | /* | 317 | /* |
318 | * Generate random starting point for subprime search, or use | 318 | * Generate random starting point for subprime search, or use |
319 | * specified parameter. | 319 | * specified parameter. |
320 | */ | 320 | */ |
321 | largebase = BN_new(); | 321 | largebase = BN_new(); |
322 | if (start == NULL) | 322 | if (start == NULL) |
@@ -329,13 +329,13 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
329 | 329 | ||
330 | time(&time_start); | 330 | time(&time_start); |
331 | 331 | ||
332 | logit("%.24s Sieve next %u plus %u-bit", ctime(&time_start), | 332 | logit("%.24s Sieve next %u plus %u-bit", ctime(&time_start), |
333 | largenumbers, power); | 333 | largenumbers, power); |
334 | debug2("start point: 0x%s", BN_bn2hex(largebase)); | 334 | debug2("start point: 0x%s", BN_bn2hex(largebase)); |
335 | 335 | ||
336 | /* | 336 | /* |
337 | * TinySieve | 337 | * TinySieve |
338 | */ | 338 | */ |
339 | for (i = 0; i < tinybits; i++) { | 339 | for (i = 0; i < tinybits; i++) { |
340 | if (BIT_TEST(TinySieve, i)) | 340 | if (BIT_TEST(TinySieve, i)) |
341 | continue; /* 2*i+3 is composite */ | 341 | continue; /* 2*i+3 is composite */ |
@@ -351,9 +351,9 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
351 | } | 351 | } |
352 | 352 | ||
353 | /* | 353 | /* |
354 | * Start the small block search at the next possible prime. To avoid | 354 | * Start the small block search at the next possible prime. To avoid |
355 | * fencepost errors, the last pass is skipped. | 355 | * fencepost errors, the last pass is skipped. |
356 | */ | 356 | */ |
357 | for (smallbase = TINY_NUMBER + 3; | 357 | for (smallbase = TINY_NUMBER + 3; |
358 | smallbase < (SMALL_MAXIMUM - TINY_NUMBER); | 358 | smallbase < (SMALL_MAXIMUM - TINY_NUMBER); |
359 | smallbase += TINY_NUMBER) { | 359 | smallbase += TINY_NUMBER) { |
@@ -386,8 +386,8 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
386 | } | 386 | } |
387 | 387 | ||
388 | /* | 388 | /* |
389 | * SmallSieve | 389 | * SmallSieve |
390 | */ | 390 | */ |
391 | for (i = 0; i < smallbits; i++) { | 391 | for (i = 0; i < smallbits; i++) { |
392 | if (BIT_TEST(SmallSieve, i)) | 392 | if (BIT_TEST(SmallSieve, i)) |
393 | continue; /* 2*i+smallbase is composite */ | 393 | continue; /* 2*i+smallbase is composite */ |
@@ -438,7 +438,7 @@ gen_candidates(FILE *out, int memory, int power, BIGNUM *start) | |||
438 | * The result is a list of so-call "safe" primes | 438 | * The result is a list of so-call "safe" primes |
439 | */ | 439 | */ |
440 | int | 440 | int |
441 | prime_test(FILE *in, FILE *out, u_int32_t trials, | 441 | prime_test(FILE *in, FILE *out, u_int32_t trials, |
442 | u_int32_t generator_wanted) | 442 | u_int32_t generator_wanted) |
443 | { | 443 | { |
444 | BIGNUM *q, *p, *a; | 444 | BIGNUM *q, *p, *a; |
@@ -562,10 +562,10 @@ prime_test(FILE *in, FILE *out, u_int32_t trials, | |||
562 | count_possible++; | 562 | count_possible++; |
563 | 563 | ||
564 | /* | 564 | /* |
565 | * The (1/4)^N performance bound on Miller-Rabin is | 565 | * The (1/4)^N performance bound on Miller-Rabin is |
566 | * extremely pessimistic, so don't spend a lot of time | 566 | * extremely pessimistic, so don't spend a lot of time |
567 | * really verifying that q is prime until after we know | 567 | * really verifying that q is prime until after we know |
568 | * that p is also prime. A single pass will weed out the | 568 | * that p is also prime. A single pass will weed out the |
569 | * vast majority of composite q's. | 569 | * vast majority of composite q's. |
570 | */ | 570 | */ |
571 | if (BN_is_prime(q, 1, NULL, ctx, NULL) <= 0) { | 571 | if (BN_is_prime(q, 1, NULL, ctx, NULL) <= 0) { |
@@ -575,9 +575,9 @@ prime_test(FILE *in, FILE *out, u_int32_t trials, | |||
575 | } | 575 | } |
576 | 576 | ||
577 | /* | 577 | /* |
578 | * q is possibly prime, so go ahead and really make sure | 578 | * q is possibly prime, so go ahead and really make sure |
579 | * that p is prime. If it is, then we can go back and do | 579 | * that p is prime. If it is, then we can go back and do |
580 | * the same for q. If p is composite, chances are that | 580 | * the same for q. If p is composite, chances are that |
581 | * will show up on the first Rabin-Miller iteration so it | 581 | * will show up on the first Rabin-Miller iteration so it |
582 | * doesn't hurt to specify a high iteration count. | 582 | * doesn't hurt to specify a high iteration count. |
583 | */ | 583 | */ |
@@ -594,7 +594,7 @@ prime_test(FILE *in, FILE *out, u_int32_t trials, | |||
594 | } | 594 | } |
595 | debug("%10u: q is almost certainly prime", count_in); | 595 | debug("%10u: q is almost certainly prime", count_in); |
596 | 596 | ||
597 | if (qfileout(out, QTYPE_SAFE, (in_tests | QTEST_MILLER_RABIN), | 597 | if (qfileout(out, QTYPE_SAFE, (in_tests | QTEST_MILLER_RABIN), |
598 | in_tries, in_size, generator_known, p)) { | 598 | in_tries, in_size, generator_known, p)) { |
599 | res = -1; | 599 | res = -1; |
600 | break; | 600 | break; |
@@ -610,7 +610,7 @@ prime_test(FILE *in, FILE *out, u_int32_t trials, | |||
610 | BN_CTX_free(ctx); | 610 | BN_CTX_free(ctx); |
611 | 611 | ||
612 | logit("%.24s Found %u safe primes of %u candidates in %ld seconds", | 612 | logit("%.24s Found %u safe primes of %u candidates in %ld seconds", |
613 | ctime(&time_stop), count_out, count_possible, | 613 | ctime(&time_stop), count_out, count_possible, |
614 | (long) (time_stop - time_start)); | 614 | (long) (time_stop - time_start)); |
615 | 615 | ||
616 | return (res); | 616 | return (res); |