chiark
/
gitweb
/
~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
symm/t/sha...: Add official NIST HMAC test vectors.
[catacomb]
/
math
/
limlee.c
diff --git
a/math/limlee.c
b/math/limlee.c
index b20965a90550d69a7d8c2fb89b93ee5856a550f6..13bbc2128465f05346e4f8a1cc54e43fd1d6c69e 100644
(file)
--- a/
math/limlee.c
+++ b/
math/limlee.c
@@
-117,7
+117,7
@@
static void llgen(limlee_factor *f, unsigned pl, limlee_stepctx *l)
again:
p = mprand(l->newp, pl, l->r, 1);
pf.step = 2;
again:
p = mprand(l->newp, pl, l->r, 1);
pf.step = 2;
- p = pgen(l->
d.buf
, p, p, l->iev, l->iec, 0, pgen_filter, &pf,
+ p = pgen(l->
u.s.name
, p, p, l->iev, l->iec, 0, pgen_filter, &pf,
rabin_iters(pl), pgen_test, &r);
if (!p)
goto again;
rabin_iters(pl), pgen_test, &r);
if (!p)
goto again;
@@
-146,18
+146,12
@@
static const limlee_primeops primeops_simple = { llgen, llfree };
static int init(pgen_event *ev, limlee_stepctx *l)
{
size_t i;
static int init(pgen_event *ev, limlee_stepctx *l)
{
size_t i;
- unsigned qql;
/* --- First of all, decide on a number of factors to make --- */
l->nf = l->pl / l->ql;
/* --- First of all, decide on a number of factors to make --- */
l->nf = l->pl / l->ql;
- qql = l->pl % l->ql;
- if (!l->nf)
- return (PGEN_ABORT);
- else if (qql && l->nf > 1) {
- l->nf--;
- qql += l->ql;
- }
+ if (l->nf < 2) return (PGEN_ABORT);
+ l->nf--;
/* --- Now decide on how many primes I'll actually generate --- *
*
/* --- Now decide on how many primes I'll actually generate --- *
*
@@
-180,20
+174,14
@@
static int init(pgen_event *ev, limlee_stepctx *l)
/* --- Other bits of initialization --- */
l->seq = 0;
/* --- Other bits of initialization --- */
l->seq = 0;
- dstr_create(&l->d);
if (!l->pops) {
l->pops = &primeops_simple;
l->pc = 0;
}
if (!l->pops) {
l->pops = &primeops_simple;
l->pc = 0;
}
- /* --- Find a big prime --- */
+ /* --- Find a big prime
later
--- */
- if (!qql)
- l->qq.p = 0;
- else {
- dstr_putf(&l->d, "%s*", ev->name);
- l->pops->pgen(&l->qq, qql, l);
- }
+ l->qq.p = 0;
return (PGEN_TRY);
}
return (PGEN_TRY);
}
@@
-211,8
+199,11
@@
static int init(pgen_event *ev, limlee_stepctx *l)
static int next(int rq, pgen_event *ev, limlee_stepctx *l)
{
static int next(int rq, pgen_event *ev, limlee_stepctx *l)
{
+ dstr d = DSTR_INIT;
mp *p;
int rc;
mp *p;
int rc;
+ int dist;
+ unsigned nb;
mp_drop(ev->m);
mp_drop(ev->m);
@@
-230,32
+221,64
@@
static int next(int rq, pgen_event *ev, limlee_stepctx *l)
}
rq = PGEN_TRY; /* For next time through */
}
rq = PGEN_TRY; /* For next time through */
+ /* --- If the large factor is performing badly, make a new one --- */
+
+ if (l->qq.p) {
+ dist = l->u.s.disp < 0 ? -l->u.s.disp : l->u.s.disp;
+ if (dist && dist > l->u.s.steps/dist) {
+ l->pops->pfree(&l->qq, l);
+ l->qq.p = 0;
+ }
+ }
+
/* --- Gather up some factors --- */
/* --- Gather up some factors --- */
- if (l->qq.p)
- mpmul_add(&mm, l->qq.p);
+ if (l->qq.p) mpmul_add(&mm, l->qq.p);
for (i = 0; i < l->poolsz; i++) {
if (!l->c[i])
continue;
if (!l->v[i].p) {
for (i = 0; i < l->poolsz; i++) {
if (!l->c[i])
continue;
if (!l->v[i].p) {
- DRESET(&l->d);
- dstr_putf(&l->d, "%s_%lu", ev->name, l->seq++);
+ DRESET(&d);
+ dstr_putf(&d, "%s_%lu", ev->name, l->seq++);
+ l->u.s.name = d.buf;
l->pops->pgen(&l->v[i], l->ql, l);
}
mpmul_add(&mm, l->v[i].p);
}
l->pops->pgen(&l->v[i], l->ql, l);
}
mpmul_add(&mm, l->v[i].p);
}
- /* --- Check
it for small factors
--- */
+ /* --- Check
on the large factor
--- */
p = mpmul_done(&mm);
p = mpmul_done(&mm);
+ if (!l->qq.p) {
+ DRESET(&d);
+ dstr_putf(&d, "%s*_%lu", ev->name, l->seq++);
+ l->u.s.name = d.buf;
+ l->pops->pgen(&l->qq, l->pl - mp_bits(p), l);
+ l->u.s.steps = l->u.s.disp = 0;
+ p = mp_mul(p, p, l->qq.p);
+ }
p = mp_lsl(p, p, 1);
p->v[0] |= 1;
p = mp_lsl(p, p, 1);
p->v[0] |= 1;
+
+ nb = mp_bits(p);
+ l->u.s.steps++;
+ if (nb < l->pl) {
+ l->u.s.disp--;
+ continue;
+ } else if (nb > l->pl) {
+ l->u.s.disp++;
+ continue;
+ }
+
+ /* --- Check it for small factors --- */
+
if ((rc = pfilt_smallfactor(p)) != PGEN_FAIL)
break;
mp_drop(p);
}
ev->m = p;
if ((rc = pfilt_smallfactor(p)) != PGEN_FAIL)
break;
mp_drop(p);
}
ev->m = p;
+ DDESTROY(&d);
return (rc);
}
return (rc);
}
@@
-305,7
+328,6
@@
static int done(pgen_event *ev, limlee_stepctx *l)
/* --- Free other resources --- */
xfree(l->c);
/* --- Free other resources --- */
xfree(l->c);
- dstr_destroy(&l->d);
/* --- Done --- */
/* --- Done --- */