X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/578a86d91941a0f722b87973d88e84ec2cf9a608..a69a3efddbe1261f55e90d4ff477053ab80663a5:/f-niceprime.c diff --git a/f-niceprime.c b/f-niceprime.c index 8645cb6..d9ec1ac 100644 --- a/f-niceprime.c +++ b/f-niceprime.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: f-niceprime.c,v 1.6 2004/04/08 01:36:15 mdw Exp $ + * $Id$ * * Prime fields with efficient reduction for special-form primes * @@ -50,21 +50,21 @@ static void fdestroy(field *ff) static mp *frand(field *ff, mp *d, grand *r) { fctx *f = (fctx *)ff; return (mprand_range(d, f->r.p, r, 0)); } -static int fzerop(field *ff, mp *x) { return (!MP_LEN(x)); } +static int fzerop(field *ff, mp *x) { return (MP_ZEROP(x)); } static mp *fneg(field *ff, mp *d, mp *x) { fctx *f = (fctx *)ff; return (mp_sub(d, f->r.p, x)); } static mp *fadd(field *ff, mp *d, mp *x, mp *y) { fctx *f = (fctx *)ff; d = mp_add(d, x, y); - if (d->f & MP_NEG) d = mp_add(d, d, f->r.p); + if (MP_NEGP(d)) d = mp_add(d, d, f->r.p); else if (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p); return (d); } static mp *fsub(field *ff, mp *d, mp *x, mp *y) { fctx *f = (fctx *)ff; d = mp_sub(d, x, y); - if (d->f & MP_NEG) d = mp_add(d, d, f->r.p); + if (MP_NEGP(d)) d = mp_add(d, d, f->r.p); else if (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p); return (d); } @@ -109,7 +109,7 @@ static mp *fqdl(field *ff, mp *d, mp *x) { static mp *fhlv(field *ff, mp *d, mp *x) { fctx *f = (fctx *)ff; - if (!MP_LEN(x)) { MP_COPY(x); MP_DROP(d); return (x); } + if (MP_ZEROP(x)) { MP_COPY(x); MP_DROP(d); return (x); } if (x->v[0] & 1) { d = mp_add(d, x, f->r.p); x = d; } return (mp_lsr(d, x, 1)); }