X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/0f3faccdf5f2f0cfa40bd9bec495c4930052a51f..a69a3efddbe1261f55e90d4ff477053ab80663a5:/g-prime.c diff --git a/g-prime.c b/g-prime.c index 97f455f..6b9d28b 100644 --- a/g-prime.c +++ b/g-prime.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: g-prime.c,v 1.3 2004/04/04 19:04:11 mdw Exp $ + * $Id$ * * Abstraction for prime groups * @@ -27,24 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: g-prime.c,v $ - * Revision 1.3 2004/04/04 19:04:11 mdw - * Raw I/O of elliptic curve points and group elements. - * - * Revision 1.2 2004/04/03 03:32:05 mdw - * General robustification. - * - * Revision 1.1 2004/04/01 12:50:09 mdw - * Add cyclic group abstraction, with test code. Separate off exponentation - * functions for better static linking. Fix a buttload of bugs on the way. - * Generally ensure that negative exponents do inversion correctly. Add - * table of standard prime-field subgroups. (Binary field subgroups are - * currently unimplemented but easy to add if anyone ever finds a good one.) - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -109,7 +91,7 @@ static void gsqr(group *gg, mp **d, mp **x) { static void ginv(group *gg, mp **d, mp **x) { gctx *g = (gctx *)gg; mp *r = mpmont_reduce(&g->mm, *d, *x); - mp_gcd(0, 0, &r, g->mm.m, r); *d = mpmont_mul(&g->mm, r, r, g->mm.r2); + r = mp_modinv(r, r, g->mm.m); *d = mpmont_mul(&g->mm, r, r, g->mm.r2); } static void gexp(group *gg, mp **d, mp **x, mp *n) @@ -137,8 +119,8 @@ static mp *gtoint(group *gg, mp *d, mp **x) { gctx *g = (gctx *)gg; return (mpmont_reduce(&g->mm, d, *x)); } static int gfromint(group *gg, mp **d, mp *x) { - gctx *g = (gctx *)gg; mp_div(0, &x, x, g->mm.m); mp_drop(*d); - *d = mpmont_mul(&g->mm, x, x, g->mm.r2); return (0); + gctx *g = (gctx *)gg; mp_div(0, d, x, g->mm.m); + *d = mpmont_mul(&g->mm, *d, *d, g->mm.r2); return (0); } static int gtobuf(group *gg, buf *b, mp **x) { @@ -191,7 +173,7 @@ group *group_prime(const gprime_param *gp) { gctx *g; - if (!MP_ISPOS(gp->p) || !MP_ISODD(gp->p)) + if (!MP_POSP(gp->p) || !MP_ODDP(gp->p)) return (0); g = CREATE(gctx); g->g.ops = &gops;