Expunge revision histories in files.
[u/mdw/catacomb] / g-prime.c
index 97f455f..aa17685 100644 (file)
--- 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
  *
  * 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 <mLib/sub.h>
@@ -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) {