X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/898a4e2555438ff8adb08b4d82690d08715e1048..b817bfc642225b8c3c0b6a7e42d1fb949b61a606:/g-prime.c diff --git a/g-prime.c b/g-prime.c index 97f455f..aa17685 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: g-prime.c,v 1.4 2004/04/08 01:36:15 mdw Exp $ * * 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) {