Add simple public-key encryption program `catcrypt'.
[u/mdw/catacomb] / ec-info.c
index cf65584..4f852c2 100644 (file)
--- a/ec-info.c
+++ b/ec-info.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: ec-info.c,v 1.6 2004/04/08 16:17:32 mdw Exp $
+ * $Id: ec-info.c,v 1.7 2004/04/17 09:58:37 mdw Exp $
  *
  * Elliptic curve information management
  *
  *
  * Elliptic curve information management
  *
@@ -372,11 +372,6 @@ static const char *primecheck(const ec_info *ei, grand *gr)
 
   if (!pgen_primep(ei->r, gr)) return ("generator order not prime");
 
 
   if (!pgen_primep(ei->r, gr)) return ("generator order not prime");
 
-  /* --- Check %$0 < h \le 4$% --- */
-
-  if (MP_CMP(ei->h, <, MP_ONE) || MP_CMP(ei->h, >, MP_FOUR))
-    return ("cofactor out of range");
-
   /* --- Check %$h = \lfloor (\sqrt{p} + 1)^2/r \rlfoor$% --- *
    *
    * This seems to work with the approximate-sqrt in the library, but might
   /* --- Check %$h = \lfloor (\sqrt{p} + 1)^2/r \rlfoor$% --- *
    *
    * This seems to work with the approximate-sqrt in the library, but might
@@ -421,6 +416,11 @@ static const char *primecheck(const ec_info *ei, grand *gr)
   MP_DROP(x);
   if (i) return ("curve is weak");
 
   MP_DROP(x);
   if (i) return ("curve is weak");
 
+  /* --- Check %$0 < h \le 4$% --- */
+
+  if (MP_CMP(ei->h, <, MP_ONE) || MP_CMP(ei->h, >, MP_FOUR))
+    return ("cofactor out of range");
+
   /* --- Done --- */
 
   return (0);
   /* --- Done --- */
 
   return (0);
@@ -459,11 +459,6 @@ static const char *bincheck(const ec_info *ei, grand *gr)
 
   if (!pgen_primep(ei->r, gr)) return ("generator order not prime");
 
 
   if (!pgen_primep(ei->r, gr)) return ("generator order not prime");
 
-  /* --- Check %$0 < h \le 4$% --- */
-
-  if (MP_CMP(ei->h, <, MP_ONE) || MP_CMP(ei->h, >, MP_FOUR))
-    return ("cofactor out of range");
-
   /* --- Check %$h = \lfloor (\sqrt{2^m} + 1)^2/r \rlfoor$% --- *
    *
    * This seems to work with the approximate-sqrt in the library, but might
   /* --- Check %$h = \lfloor (\sqrt{2^m} + 1)^2/r \rlfoor$% --- *
    *
    * This seems to work with the approximate-sqrt in the library, but might
@@ -505,6 +500,11 @@ static const char *bincheck(const ec_info *ei, grand *gr)
   MP_DROP(x);
   if (i) return ("curve is weak");
 
   MP_DROP(x);
   if (i) return ("curve is weak");
 
+  /* --- Check %$0 < h \le 4$% --- */
+
+  if (MP_CMP(ei->h, <, MP_ONE) || MP_CMP(ei->h, >, MP_FOUR))
+    return ("cofactor out of range");
+
   /* --- Done --- */
 
   return (0);
   /* --- Done --- */
 
   return (0);