/* -*-c-*-
*
- * $Id: ec.c,v 1.4.4.2 2004/03/20 00:13:31 mdw Exp $
+ * $Id: ec.c,v 1.6 2004/03/23 15:19:32 mdw Exp $
*
* Elliptic curve definitions
*
/*----- Revision history --------------------------------------------------*
*
* $Log: ec.c,v $
+ * Revision 1.6 2004/03/23 15:19:32 mdw
+ * Test elliptic curves more thoroughly.
+ *
+ * Revision 1.5 2004/03/21 22:52:06 mdw
+ * Merge and close elliptic curve branch.
+ *
* Revision 1.4.4.2 2004/03/20 00:13:31 mdw
* Projective coordinates for prime curves
*
ec *ec_copy(ec *d, const ec *p) { EC_COPY(d, p); return (d); }
+/* --- @ec_eq@ --- *
+ *
+ * Arguments: @const ec *p, *q@ = two points
+ *
+ * Returns: Nonzero if the points are equal. Compares external-format
+ * points.
+ */
+
+int ec_eq(const ec *p, const ec *q) { return (EC_EQ(p, q)); }
+
/*----- Standard curve operations -----------------------------------------*/
/* --- @ec_idin@, @ec_idout@, @ec_idfix@ --- *
ec pp, qq;
EC_IN(c, &pp, p);
EC_IN(c, &qq, q);
- EC_SUB(c, d, &qq, &qq);
+ EC_SUB(c, d, &pp, &qq);
EC_OUT(c, d, d);
EC_DESTROY(&pp);
EC_DESTROY(&qq);
return (rc);
}
+/* --- @ec_rand@ --- *
+ *
+ * Arguments: @ec_curve *c@ = pointer to an elliptic curve
+ * @ec *d@ = pointer to the destination point
+ * @grand *r@ = random number source
+ *
+ * Returns: The destination @d@.
+ *
+ * Use: Finds a random point on the given curve.
+ */
+
+ec *ec_rand(ec_curve *c, ec *d, grand *r)
+{
+ mp *x = MP_NEW;
+ do x = F_RAND(c->f, x, r); while (!EC_FIND(c, d, x));
+ mp_drop(x);
+ if (grand_range(r, 2)) EC_NEG(c, d, d);
+ return (EC_OUT(c, d, d));
+}
+
/* --- @ec_imul@, @ec_mul@ --- *
*
* Arguments: @ec_curve *c@ = pointer to an elliptic curve