X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/f94b972d1c0389e4e9203cc9919ceaadbe655b61..b2776fdf2a98ea586bbdad50eca4ed95e967b0d7:/f-prime.c diff --git a/f-prime.c b/f-prime.c index 9b1ceb6..31638f5 100644 --- a/f-prime.c +++ b/f-prime.c @@ -7,7 +7,7 @@ * (c) 2001 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,12 +15,12 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, @@ -111,20 +111,20 @@ static mp *fsqrt(field *ff, mp *d, mp *x) { static mp *fdbl(field *ff, mp *d, mp *x) { fctx_prime *f = (fctx_prime *)ff; d = mp_lsl(d, x, 1); - if (MP_CMP(d, >, f->mm.m)) d = mp_sub(d, d, f->mm.m); + if (MP_CMP(d, >=, f->mm.m)) d = mp_sub(d, d, f->mm.m); return (d); } static mp *ftpl(field *ff, mp *d, mp *x) { fctx_prime *f = (fctx_prime *)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->mm.m)) d = mp_sub(d, d, f->mm.m); + MPX_UMULN(d->v, d->vl, x->v, x->vl, 3); d->f &= ~MP_UNDEF; + while (MP_CMP(d, >=, f->mm.m)) d = mp_sub(d, d, f->mm.m); return (d); } static mp *fqdl(field *ff, mp *d, mp *x) { fctx_prime *f = (fctx_prime *)ff; d = mp_lsl(d, x, 2); - while (MP_CMP(d, >, f->mm.m)) d = mp_sub(d, d, f->mm.m); + while (MP_CMP(d, >=, f->mm.m)) d = mp_sub(d, d, f->mm.m); return (d); } @@ -160,16 +160,18 @@ field *field_prime(mp *p) { fctx_prime *f; - if (!MP_POSP(p) || !MP_ODDP(p)) - return (0); f = CREATE(fctx_prime); f->f.ops = &fops; - mpmont_create(&f->mm, p); + if (mpmont_create(&f->mm, p)) { + DESTROY(f); + return (0); + } f->f.zero = MP_ZERO; f->f.one = f->mm.r; f->f.m = f->mm.m; f->f.nbits = mp_bits(p); f->f.noctets = (f->f.nbits + 7) >> 3; + f->f.q = f->mm.m; return (&f->f); }