From fbfcb6c0ffbad26c7eae30a7590e9d7897331a31 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 28 Apr 2022 18:39:07 +0100 Subject: [PATCH] prime generation: Deploy the new Baillie--PSW testers. --- math/limlee.c | 5 ++--- math/strongprime.c | 10 ++++------ misc/share.c | 3 +-- pub/bbs-gen.c | 5 ++--- pub/dh-gen.c | 7 +++---- pub/dh-kcdsa.c | 5 ++--- pub/dsa-gen.c | 5 ++--- pub/rsa-gen.c | 3 +-- 8 files changed, 17 insertions(+), 26 deletions(-) diff --git a/math/limlee.c b/math/limlee.c index c99ba7bd..55959cc7 100644 --- a/math/limlee.c +++ b/math/limlee.c @@ -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) { diff --git a/math/strongprime.c b/math/strongprime.c index 4ea62537..958cd285 100644 --- a/math/strongprime.c +++ b/math/strongprime.c @@ -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); diff --git a/misc/share.c b/misc/share.c index e99781e7..69316309 100644 --- a/misc/share.c +++ b/misc/share.c @@ -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 --- */ diff --git a/pub/bbs-gen.c b/pub/bbs-gen.c index 6ec65e2d..3239674f 100644 --- a/pub/bbs-gen.c +++ b/pub/bbs-gen.c @@ -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); diff --git a/pub/dh-gen.c b/pub/dh-gen.c index 17b34f68..f20c286d 100644 --- a/pub/dh-gen.c +++ b/pub/dh-gen.c @@ -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) diff --git a/pub/dh-kcdsa.c b/pub/dh-kcdsa.c index d27bc7d8..d1567402 100644 --- a/pub/dh-kcdsa.c +++ b/pub/dh-kcdsa.c @@ -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) diff --git a/pub/dsa-gen.c b/pub/dsa-gen.c index 8802003f..5505beaf 100644 --- a/pub/dsa-gen.c +++ b/pub/dsa-gen.c @@ -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) diff --git a/pub/rsa-gen.c b/pub/rsa-gen.c index b381bcd0..ec16a122 100644 --- a/pub/rsa-gen.c +++ b/pub/rsa-gen.c @@ -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; -- 2.11.0