prime generation: Deploy the new Baillie--PSW testers. mdw/cfd-subtree
authorMark Wooding <mdw@distorted.org.uk>
Thu, 28 Apr 2022 17:39:07 +0000 (18:39 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 1 May 2022 17:54:55 +0000 (18:54 +0100)
math/limlee.c
math/strongprime.c
misc/share.c
pub/bbs-gen.c
pub/dh-gen.c
pub/dh-kcdsa.c
pub/dsa-gen.c
pub/rsa-gen.c

index c99ba7b..55959cc 100644 (file)
@@ -111,13 +111,12 @@ static int comb_next(octet *c, unsigned n, unsigned r)
 static void llgen(limlee_factor *f, unsigned pl, limlee_stepctx *l)
 {
   pgen_filterctx pf;
-  rabin r;
   mp *p;
 
   p = mprand(l->newp, pl, l->r, 1);
   pf.step = 2;
   p = pgen(l->u.s.name, p, p, l->iev, l->iec, 0, pgen_filter, &pf,
-          rabin_iters(pl), pgen_test, &r);
+          PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   f->p = p;
 }
 
@@ -402,7 +401,7 @@ mp *limlee(const char *name, mp *d, mp *newp,
   l.r = r;
 
   d = pgen(name, d, 0, oev, oec, on, limlee_step, &l,
-          rabin_iters(pl), pgen_test, &rr);
+          PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, &rr);
 
   if (f) {
     if (!d) {
index 4ea6253..958cd28 100644 (file)
@@ -79,7 +79,6 @@ mp *strongprime_setup(const char *name, mp *d, pfilt *f, unsigned nbits,
   mp *rr = d;
   pgen_filterctx c;
   pgen_jumpctx j;
-  rabin rb;
 
   /* --- Figure out how large the smaller primes should be --- *
    *
@@ -116,13 +115,13 @@ mp *strongprime_setup(const char *name, mp *d, pfilt *f, unsigned nbits,
   rr = mprand(rr, nb, r, 1);
   DRESET(&dn); dstr_putf(&dn, "%s [s]", name);
   if ((s = pgen(dn.buf, MP_NEWSEC, rr, event, ectx, n, pgen_filter, &c,
-               rabin_iters(nb), pgen_test, &rb)) == 0)
+               PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0)) == 0)
     goto fail_s;
 
   rr = mprand(rr, nb, r, 1);
   DRESET(&dn); dstr_putf(&dn, "%s [t]", name);
   if ((t = pgen(dn.buf, MP_NEWSEC, rr, event, ectx, n, pgen_filter, &c,
-               rabin_iters(nb), pgen_test, &rb)) == 0)
+               PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0)) == 0)
     goto fail_t;
 
   /* --- Choose a suitable value for %$r = 2it + 1$% for some %$i$% --- *
@@ -137,7 +136,7 @@ mp *strongprime_setup(const char *name, mp *d, pfilt *f, unsigned nbits,
   DRESET(&dn); dstr_putf(&dn, "%s [r]", name);
   j.j = &c.f;
   q = pgen(dn.buf, MP_NEW, rr, event, ectx, n, pgen_jump, &j,
-          rabin_iters(nb + slop), pgen_test, &rb);
+          PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   pfilt_destroy(&c.f);
   if (!q)
     goto fail_r;
@@ -219,14 +218,13 @@ mp *strongprime(const char *name, mp *d, unsigned nbits, grand *r,
   mp *p;
   pfilt f;
   pgen_jumpctx j;
-  rabin rb;
 
   if (d) mp_copy(d);
   p = strongprime_setup(name, d, &f, nbits, r, n, event, ectx);
   if (!p) { mp_drop(d); return (0); }
   j.j = &f;
   p = pgen(name, p, p, event, ectx, n, pgen_jump, &j,
-          rabin_iters(nbits), pgen_test, &rb);
+          PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   if (mp_bits(p) != nbits) { mp_drop(p); return (0); }
   pfilt_destroy(&f);
   mp_drop(d);
index e99781e..6931630 100644 (file)
@@ -112,14 +112,13 @@ void share_mkshares(share *s, grand *r, mp *n)
 
   if (!s->p) {
     pgen_filterctx pf;
-    rabin pr;
     mp *p;
     unsigned bits = (mp_octets(n) + 1) * 8;
 
     pf.step = 2;
     p = mprand(MP_NEW, bits, r, 1);
     s->p = pgen("p", p, p, 0, 0, 0, pgen_filter, &pf,
-               rabin_iters(bits), pgen_test, &pr);
+               PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   }
 
   /* --- Construct the polynomial --- */
index 6ec65e2..3239674 100644 (file)
@@ -60,7 +60,6 @@
 int bbs_gen(bbs_priv *bp, unsigned nbits, grand *r, unsigned n,
            pgen_proc *event, void *ectx)
 {
-  rabin rb;
   pfilt jp;
   pgen_jumpctx j;
   pgen_gcdstepctx g;
@@ -73,7 +72,7 @@ int bbs_gen(bbs_priv *bp, unsigned nbits, grand *r, unsigned n,
     goto fail_x;
   j.j = &jp;
   bp->p = pgen("p", MP_NEWSEC, x, event, ectx, n, pgen_jump, &j,
-              rabin_iters(nb), pgen_test, &rb);
+              PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   pfilt_destroy(&jp);
   if (!bp->p) goto fail_p;
 
@@ -89,7 +88,7 @@ int bbs_gen(bbs_priv *bp, unsigned nbits, grand *r, unsigned n,
   g.g = MP_NEW;
   g.max = MP_ONE;
   bp->q = pgen("q", MP_NEWSEC, x, event, ectx, n, pgen_gcdstep, &g,
-              rabin_iters(nb), pgen_test, &rb);
+              PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   pfilt_destroy(&g.jp);
   mp_drop(g.r);
   mp_drop(g.g);
index 17b34f6..f20c286 100644 (file)
@@ -80,7 +80,7 @@ int dh_gen(dh_param *dp, unsigned ql, unsigned pl, unsigned steps, grand *r,
     sp[1].mul = MP_TWO; sp[1].add = MP_ONE; sp[1].f = PGENF_KEEP;
     ss.v = sp; ss.n = N(sp);
     dp->q = pgen("p", MP_NEW, m, event, ectx, steps, pgen_simulstep, &ss,
-                rabin_iters(pl), pgen_simultest, &ss);
+                PGEN_BAILLIEPSWNTESTS, pgen_simulbailliepswtest, &ss);
     mp_drop(m);
     if (!dp->q) {
       mp_drop(sp[1].u.x);
@@ -99,7 +99,6 @@ int dh_gen(dh_param *dp, unsigned ql, unsigned pl, unsigned steps, grand *r,
   else {
     pgen_filterctx c;
     pgen_jumpctx j;
-    rabin rb;
     prim_ctx p;
     int i;
     mp *m = MP_NEW;
@@ -110,7 +109,7 @@ int dh_gen(dh_param *dp, unsigned ql, unsigned pl, unsigned steps, grand *r,
     c.step = 2;
     m = mprand(MP_NEW, ql, r, 1);
     dp->q = pgen("q", MP_NEW, m, event, ectx, steps, pgen_filter, &c,
-                rabin_iters(ql), pgen_test, &rb);
+                PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
     if (!dp->q)
       goto fail_q;
 
@@ -125,7 +124,7 @@ int dh_gen(dh_param *dp, unsigned ql, unsigned pl, unsigned steps, grand *r,
     pfilt_create(&c.f, m);
     j.j = &c.f;
     dp->p = pgen("p", MP_NEW, x, event, ectx, steps, pgen_jump, &j,
-                rabin_iters(pl), pgen_test, &rb);
+                PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
     pfilt_destroy(&c.f);
     mp_drop(x);
     if (!dp->p)
index d27bc7d..d156740 100644 (file)
@@ -63,7 +63,6 @@ int dh_kcdsagen(dh_param *dp, unsigned ql, unsigned pl,
   pgen_simulprime sp[2];
   pgen_simulctx ss;
   prim_ctx pc;
-  rabin rb;
   int rc = PGEN_ABORT;
   int i;
   mp *x = MP_NEW, *t = MP_NEW;
@@ -75,7 +74,7 @@ retry:
   x = mprand(x, pl - ql - 1, r, 1);
   x = pgen("v", x, x, ev, ec,
           steps, pgen_filter, &pf,
-          rabin_iters(pl - ql), pgen_test, &rb);
+          PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
   if (!x)
     goto fail_0;
 
@@ -91,7 +90,7 @@ retry:
   } while (mp_bits(t) != pl);
   dp->q = pgen("p", MP_NEW, x, ev, ec,
               steps, pgen_simulstep, &ss,
-              rabin_iters(ql), pgen_simultest, &ss);
+              PGEN_BAILLIEPSWNTESTS, pgen_simulbailliepswtest, &ss);
   mp_drop(sp[1].mul);
   dp->p = sp[1].u.x;
   if (!dp->q)
index 8802003..5505bea 100644 (file)
@@ -137,7 +137,6 @@ int dsa_gen(dsa_param *dp, unsigned ql, unsigned pl, unsigned steps,
   dsa_stepctx s;
   prim_ctx p;
   int i;
-  rabin r;
   mp *qc;
 
   /* --- Initialize the stepping context --- */
@@ -158,7 +157,7 @@ int dsa_gen(dsa_param *dp, unsigned ql, unsigned pl, unsigned steps,
     ds->p = s.seedbuf = xmalloc(sz);
   }
   if ((dp->q = pgen("q", MP_NEW, MP_NEW, event, ectx, steps, dsa_step, &s,
-                   rabin_iters(ql), pgen_test, &r)) == 0)
+                   PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0)) == 0)
     goto fail_q;
 
   /* --- Find @p@ --- */
@@ -169,7 +168,7 @@ int dsa_gen(dsa_param *dp, unsigned ql, unsigned pl, unsigned steps,
   s.bits = pl;
   s.seedbuf = 0;
   if ((dp->p = pgen("p", MP_NEW, MP_NEW, event, ectx, 4096, dsa_step, &s,
-                   rabin_iters(pl), pgen_test, &r)) == 0)
+                   PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0)) == 0)
     goto fail_p;
   mp_drop(s.q);
   if (ds)
index b381bcd..ec16a12 100644 (file)
@@ -61,7 +61,6 @@ static int genprime(mp **pp, mp **dd, const char *name,
 {
   pgen_jumpctx jctx; pfilt j;
   mp *p = MP_NEWSEC, *t = MP_NEW, *u = MP_NEW;
-  rabin rb;
   mpw p3, j3, a;
   int rc = -1;
 
@@ -105,7 +104,7 @@ static int genprime(mp **pp, mp **dd, const char *name,
   jctx.j = &j;
   p = pgen(name, p, p, event, ectx,
           nsteps, pgen_jump, &jctx,
-          rabin_iters(nbits), pgen_test, &rb);
+          PGEN_BAILLIEPSWNTESTS, pgen_bailliepswtest, 0);
 
   if (!p) goto end;