Make elliptic curve stuff build.
[u/mdw/catacomb] / ec.c
diff --git a/ec.c b/ec.c
index ce4e428..47c01a9 100644 (file)
--- a/ec.c
+++ b/ec.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: ec.c,v 1.3 2002/01/13 13:48:44 mdw Exp $
+ * $Id: ec.c,v 1.4 2003/05/15 23:25:59 mdw Exp $
  *
  * Elliptic curve definitions
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: ec.c,v $
+ * Revision 1.4  2003/05/15 23:25:59  mdw
+ * Make elliptic curve stuff build.
+ *
  * Revision 1.3  2002/01/13 13:48:44  mdw
  * Further progress.
  *
  *
  * Arguments:  @ec *p@ = pointer to an elliptic-curve point
  *
- * Returns:    ---
+ * Returns:    The argument @p@.
  *
  * Use:                Initializes a new point.  The initial value is the additive
  *             identity (which is universal for all curves).
  */
 
-void ec_create(ec *p) { EC_CREATE(p); }
+ec *ec_create(ec *p) { EC_CREATE(p); return (p); }
 
 /* --- @ec_destroy@ --- *
  *
@@ -86,24 +89,24 @@ int ec_atinf(const ec *p) { return (EC_ATINF(p)); }
  *
  * Arguments:  @ec *p@ = pointer to a point
  *
- * Returns:    ---
+ * Returns:    The argument @p@.
  *
  * Use:                Sets the given point to be the point %$O$% at infinity.
  */
 
-void ec_setinf(ec *p) { EC_SETINF(p); }
+ec *ec_setinf(ec *p) { EC_SETINF(p); return (p); }
 
 /* --- @ec_copy@ --- *
  *
  * Arguments:  @ec *d@ = pointer to destination point
  *             @const ec *p@ = pointer to source point
  *
- * Returns:    ---
+ * Returns:    The destination @d@.
  *
  * Use:                Creates a copy of an elliptic curve point.
  */
 
-void ec_copy(ec *d, const ec *p) { EC_COPY(d, p); }
+ec *ec_copy(ec *d, const ec *p) { EC_COPY(d, p); return (d); }
 
 /*----- Standard curve operations -----------------------------------------*/
 
@@ -194,7 +197,7 @@ ec *ec_projout(ec_curve *c, ec *d, const ec *p)
  *
  * Arguments:  @ec_curve *c@ = pointer to an elliptic curve
  *             @ec *d@ = pointer to the destination
- *             @const ec *a, *b@ = the operand points
+ *             @const ec *p, *q@ = the operand points
  *
  * Returns:    The destination @d@.
  *
@@ -203,15 +206,28 @@ ec *ec_projout(ec_curve *c, ec *d, const ec *p)
  *             subtraction operator.
  */
 
-ec *ec_stdsub(ec_curve *c, ec *d, const ec *a, const ec *b)
+ec *ec_stdsub(ec_curve *c, ec *d, const ec *p, const ec *q)
 {
   ec t = EC_INIT;
-  EC_NEG(c, &t, b);
-  EC_SUB(c, d, a, &t);
+  EC_NEG(c, &t, q);
+  EC_ADD(c, d, p, &t);
   EC_DESTROY(&t);
   return (d);
 }
 
+/*----- Creating curves ---------------------------------------------------*/
+
+/* --- @ec_destroycurve@ --- *
+ *
+ * Arguments:  @ec_curve *c@ = pointer to an ellptic curve
+ *
+ * Returns:    ---
+ *
+ * Use:                Destroys a description of an elliptic curve.
+ */
+
+void ec_destroycurve(ec_curve *c) { c->ops->destroy(c); }
+
 /*----- Real arithmetic ---------------------------------------------------*/
 
 /* --- @ec_find@ --- *
@@ -301,9 +317,9 @@ ec *ec_imul(ec_curve *c, ec *d, const ec *p, mp *n)
   if (MP_LEN(n) == 0)
     ;
   else if (MP_LEN(n) < EXP_THRESH)
-    EXP_SIMPLE(&d, t, n);
+    EXP_SIMPLE(*d, t, n);
   else
-    EXP_WINDOW(&d, t, n);
+    EXP_WINDOW(*d, t, n);
   return (d);
 }