pgen_safetest: Use a separate witness for each test.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 11 Feb 2006 12:41:26 +0000 (12:41 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Feb 2006 12:41:26 +0000 (12:41 +0000)
I have a suspicion that not doing this can do bad things to the
probability of returning a non-prime.

pgen-safe.c

index 115f7b4..bd644dc 100644 (file)
@@ -180,10 +180,12 @@ int pgen_safetest(int rq, pgen_event *ev, void *p)
       rc = PGEN_TRY;
       break;
     case PGEN_TRY: {
-      mp *m = mprand_range(MP_NEW, c->c.q.m, ev->r, 0);
+      mp *m = mprand_range(MP_NEW, c->c.p.m, ev->r, 0);
       rc = rabin_test(&c->p, m);
-      if (rc == PGEN_PASS)
+      if (rc == PGEN_PASS) {
+       m = mprand_range(m, c->c.q.m, ev->r, 0);
        rc = rabin_test(&c->q, m);
+      }
       mp_drop(m);
     } break;
     case PGEN_DONE: