X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/3161ce63b657589bb2c48ea49b02a4d42a1d02f5..fbfcb6c0ffbad26c7eae30a7590e9d7897331a31:/pub/bbs-gen.c diff --git a/pub/bbs-gen.c b/pub/bbs-gen.c index 4796cf5c..3239674f 100644 --- a/pub/bbs-gen.c +++ b/pub/bbs-gen.c @@ -60,12 +60,11 @@ 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; unsigned nb = nbits/2; - mp *x = MP_NEWSEC, *t = MP_NEW; + mp *x = MP_NEWSEC; /* --- Generate @p@ --- */ @@ -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; @@ -88,25 +87,24 @@ int bbs_gen(bbs_priv *bp, unsigned nbits, grand *r, unsigned n, g.r = mp_lsr(MP_NEW, bp->p, 1); g.g = MP_NEW; g.max = MP_ONE; - t = mp_lsl(t, MP_ONE, nbits - 1); - mp_div(&t, 0, t, bp->p); - if (MP_CMP(x, <, t)) x = mp_leastcongruent(x, t, x, g.jp.m); 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); - mp_drop(t); if (!bp->q) goto fail_q; /* --- Compute @n@ --- */ bp->n = mp_mul(MP_NEW, bp->p, bp->q); + if (mp_bits(bp->n) != nbits) goto fail_n; mp_drop(x); return (PGEN_DONE); /* --- Tidy up if things went wrong --- */ +fail_n: + mp_drop(bp->n); fail_q: mp_drop(bp->p); fail_p: