chiark
/
gitweb
/
~mdw
/
catacomb
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
01f3ef9
)
pub/bbs-gen.c: Carefully generate numbers of the correct sizes.
author
Mark Wooding
<mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000
(09:26 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Sun, 26 Jun 2016 10:44:36 +0000
(11:44 +0100)
pub/bbs-gen.c
patch
|
blob
|
blame
|
history
diff --git
a/pub/bbs-gen.c
b/pub/bbs-gen.c
index d2b4b6e5be4f979ac3c9cf8eab91de51904894a4..4796cf5c719942c0bb65f95133a1aa8a05249b48 100644
(file)
--- a/
pub/bbs-gen.c
+++ b/
pub/bbs-gen.c
@@
-65,7
+65,7
@@
int bbs_gen(bbs_priv *bp, unsigned nbits, grand *r, unsigned n,
pgen_jumpctx j;
pgen_gcdstepctx g;
unsigned nb = nbits/2;
pgen_jumpctx j;
pgen_gcdstepctx g;
unsigned nb = nbits/2;
- mp *x = MP_NEWSEC;
+ mp *x = MP_NEWSEC
, *t = MP_NEW
;
/* --- Generate @p@ --- */
/* --- Generate @p@ --- */
@@
-88,11
+88,15
@@
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;
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);
pfilt_destroy(&g.jp);
mp_drop(g.r);
mp_drop(g.g);
bp->q = pgen("q", MP_NEWSEC, x, event, ectx, n, pgen_gcdstep, &g,
rabin_iters(nb), pgen_test, &rb);
pfilt_destroy(&g.jp);
mp_drop(g.r);
mp_drop(g.g);
+ mp_drop(t);
if (!bp->q) goto fail_q;
/* --- Compute @n@ --- */
if (!bp->q) goto fail_q;
/* --- Compute @n@ --- */