Slightly better factoring.
[u/mdw/catacomb] / ec-info.c
index 0805c26..cf65584 100644 (file)
--- a/ec-info.c
+++ b/ec-info.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: ec-info.c,v 1.4 2004/04/03 03:32:05 mdw Exp $
+ * $Id: ec-info.c,v 1.6 2004/04/08 16:17:32 mdw Exp $
  *
  * Elliptic curve information management
  *
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: ec-info.c,v $
- * Revision 1.4  2004/04/03 03:32:05  mdw
- * General robustification.
- *
- * Revision 1.3  2004/04/01 21:28:41  mdw
- * Normal basis support (translates to poly basis internally).  Rewrite
- * EC and prime group table generators in awk, so that they can reuse data
- * for repeated constants.
- *
- * Revision 1.2  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.)
- *
- * Revision 1.1  2004/03/27 17:54:11  mdw
- * Standard curves and curve checking.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include "ec.h"
@@ -548,29 +525,48 @@ const char *ec_checkinfo(const ec_info *ei, grand *gr)
 
 #include "fibrand.h"
 
-int main(void)
+int main(int argc, char *argv[])
 {
   const ecentry *ee;
   const char *e;
   int ok = 1;
+  int i;
   grand *gr;
 
   gr = fibrand_create(0);
-  fputs("checking standard curves: ", stdout);
-  for (ee = ectab; ee->name; ee++) {
-    ec_info ei;
-    getinfo(&ei, ee->data);
-    e = ec_checkinfo(&ei, gr);
-    ec_freeinfo(&ei);
-    if (e) {
-      fprintf(stderr, "\n*** curve %s fails: %s\n", ee->name, e);
-      ok = 0;
+  if (argc > 1) {
+    for (i = 1; i < argc; i++) {
+      ec_info ei;
+      if ((e = ec_getinfo(&ei, argv[i])) != 0)
+       fprintf(stderr, "bad curve spec `%s': %s", argv[i], e);
+      else {
+       e = ec_checkinfo(&ei, gr);
+       ec_freeinfo(&ei);
+       if (!e)
+         printf("OK %s\n", argv[i]);
+       else {
+         printf("BAD %s: %s\n", argv[i], e);
+         ok = 0;
+       }
+      }
+    }
+  } else {
+    fputs("checking standard curves: ", stdout);
+    for (ee = ectab; ee->name; ee++) {
+      ec_info ei;
+      getinfo(&ei, ee->data);
+      e = ec_checkinfo(&ei, gr);
+      ec_freeinfo(&ei);
+      if (e) {
+       fprintf(stderr, "\n*** curve %s fails: %s\n", ee->name, e);
+       ok = 0;
+      }
+      putchar('.');
+      fflush(stdout);
     }
-    putchar('.');
-    fflush(stdout);
+    fputs(ok ? " ok\n" : " failed\n", stdout);
   }
   gr->ops->destroy(gr);
-  fputs(ok ? " ok\n" : " failed\n", stdout);
   return (!ok);
 }