static mp *fdbl(field *ff, mp *d, mp *x) {
fctx_niceprime *f = (fctx_niceprime *)ff; d = mp_lsl(d, x, 1);
- if (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p);
+ if (MP_CMP(d, >=, f->r.p)) d = mp_sub(d, d, f->r.p);
return (d);
}
static mp *ftpl(field *ff, mp *d, mp *x) {
fctx_niceprime *f = (fctx_niceprime *)ff; MP_DEST(d, MP_LEN(x) + 1, x->f);
- MPX_UMULN(d->v, d->vl, x->v, x->vl, 3);
- while (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p);
+ MPX_UMULN(d->v, d->vl, x->v, x->vl, 3); d->f &= ~MP_UNDEF;
+ while (MP_CMP(d, >=, f->r.p)) d = mp_sub(d, d, f->r.p);
return (d);
}
static mp *fqdl(field *ff, mp *d, mp *x) {
fctx_niceprime *f = (fctx_niceprime *)ff; d = mp_lsl(d, x, 2);
- while (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p);
+ while (MP_CMP(d, >=, f->r.p)) d = mp_sub(d, d, f->r.p);
return (d);
}
*
* Arguments: @mp *p@ = the characteristic of the field
*
- * Returns: A pointer to the field.
+ * Returns: A pointer to the field, or null.
*
* Use: Creates a field structure for a prime field of size %$p$%,
* using efficient reduction for nice primes.
f->f.one = MP_ONE;
f->f.nbits = mp_bits(p);
f->f.noctets = (f->f.nbits + 7) >> 3;
- mpreduce_create(&f->r, p);
+ if (mpreduce_create(&f->r, p)) {
+ DESTROY(f);
+ return (0);
+ }
f->f.m = f->r.p;
+ f->f.q = f->r.p;
return (&f->f);
}