Prototype version.
[u/mdw/catacomb] / ec-prime.c
diff --git a/ec-prime.c b/ec-prime.c
new file mode 100644 (file)
index 0000000..5a806da
--- /dev/null
@@ -0,0 +1,72 @@
+/* -*-c-*-
+ *
+ * $Id: ec-prime.c,v 1.1 2001/04/29 18:12:33 mdw Exp $
+ *
+ * Elliptic curves over prime fields
+ *
+ * (c) 2001 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * Catacomb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: ec-prime.c,v $
+ * Revision 1.1  2001/04/29 18:12:33  mdw
+ * Prototype version.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include "ec.h"
+
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct ecctx {
+  ec_curve c;
+  mp *a, *b;
+} ecctx;
+
+/*----- Main code ---------------------------------------------------------*/
+
+static void ecadd(ec_curve *c, ec *d, const ec *a, const ec *b)
+{
+  /* --- Deal with the simple cases --- */
+
+  if (a == b)
+    ecdbl(c, d, a);
+  else if (EC_ATINF(a))
+    EC_COPY(d, b);
+  else if (EC_ATINF(b))
+    EC_COPY(d, a);
+  else if (MP_EQ(a->x, b->x) && MP_EQ(a->z, b->z)) {
+    if ((a->y->f ^ b->y->f) & MP_NEG)
+      EC_SETINF(d);
+    else
+      ecdbl(c, d, a);
+  } else {
+
+    /* --- 
+  }
+}
+
+/*----- That's all, folks -------------------------------------------------*/