General robustification.
[u/mdw/catacomb] / ec-info.c
index bcc0ab8..0805c26 100644 (file)
--- a/ec-info.c
+++ b/ec-info.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: ec-info.c,v 1.3 2004/04/01 21:28:41 mdw Exp $
+ * $Id: ec-info.c,v 1.4 2004/04/03 03:32:05 mdw Exp $
  *
  * Elliptic curve information management
  *
  *
  * Elliptic curve information management
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: ec-info.c,v $
 /*----- 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
  * 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
@@ -131,6 +134,10 @@ ec_curve *ec_curveparse(qd_parse *qd)
     default:
       goto fail;
   }
     default:
       goto fail;
   }
+  if (!c) {
+    qd->e = "bad curve parameters";
+    goto fail;
+  }
   if (a) MP_DROP(a);
   if (b) MP_DROP(b);
   return (c);
   if (a) MP_DROP(a);
   if (b) MP_DROP(b);
   return (c);
@@ -215,6 +222,7 @@ static void getinfo(ec_info *ei, ecdata *ed)
       abort();
   }
 
       abort();
   }
 
+  assert(f); assert(ei->c);
   EC_CREATE(&ei->g); ei->g.x = &ed->gx; ei->g.y = &ed->gy; ei->g.z = 0;
   ei->r = &ed->r; ei->h = &ed->h;
 }
   EC_CREATE(&ei->g); ei->g.x = &ed->gx; ei->g.y = &ed->gy; ei->g.z = 0;
   ei->r = &ed->r; ei->h = &ed->h;
 }
@@ -248,12 +256,9 @@ int ec_infoparse(qd_parse *qd, ec_info *ei)
   const ecentry *ee;
   mp *r = MP_NEW, *h = MP_NEW;
 
   const ecentry *ee;
   mp *r = MP_NEW, *h = MP_NEW;
 
-  for (ee = ectab; ee->name; ee++) {
-    if (qd_enum(qd, ee->name) >= 0) {
-      getinfo(ei, ee->data);
-      goto found;
-    }
-  }
+  for (ee = ectab; ee->name; ee++)
+    if (qd_enum(qd, ee->name) >= 0) { getinfo(ei, ee->data); goto found; }
+
   if ((c = ec_curveparse(qd)) == 0) goto fail;
   qd_delim(qd, '/'); if (!ec_ptparse(qd, &g)) goto fail;
   qd_delim(qd, ':'); if ((r = qd_getmp(qd)) == 0) goto fail;
   if ((c = ec_curveparse(qd)) == 0) goto fail;
   qd_delim(qd, '/'); if (!ec_ptparse(qd, &g)) goto fail;
   qd_delim(qd, ':'); if ((r = qd_getmp(qd)) == 0) goto fail;