X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/53cbeae3058cdebd54bf9a6c18d9f46ee52f0595..389d822217b802003674d2085b3b902cbe13cf25:/ec-info.c diff --git a/ec-info.c b/ec-info.c index cf65584..bf9607c 100644 --- a/ec-info.c +++ b/ec-info.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: ec-info.c,v 1.6 2004/04/08 16:17:32 mdw Exp $ + * $Id$ * * Elliptic curve information management * @@ -34,6 +34,7 @@ #include "gf.h" #include "pgen.h" #include "mprand.h" +#include "mpint.h" #include "rabin.h" /*----- Main code ---------------------------------------------------------*/ @@ -325,7 +326,7 @@ void ec_freeinfo(ec_info *ei) static int primeeltp(mp *x, field *f) { - return (!MP_ISNEG(x) && MP_CMP(x, <, f->m)); + return (!MP_NEGP(x) && MP_CMP(x, <, f->m)); } static const char *primecheck(const ec_info *ei, grand *gr) @@ -372,11 +373,6 @@ static const char *primecheck(const ec_info *ei, grand *gr) 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 @@ -421,6 +417,11 @@ static const char *primecheck(const ec_info *ei, grand *gr) 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); @@ -435,6 +436,13 @@ static const char *bincheck(const ec_info *ei, grand *gr) ec p; int rc; + /* --- Check that %$m$% is prime --- */ + + x = mp_fromuint(MP_NEW, f->nbits); + rc = pfilt_smallfactor(x); + mp_drop(x); + if (rc != PGEN_DONE) return ("degree not prime"); + /* --- Check that %$p$% is irreducible --- */ if (!gf_irreduciblep(f->m)) return ("p not irreducible"); @@ -459,11 +467,6 @@ static const char *bincheck(const ec_info *ei, grand *gr) 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 @@ -505,6 +508,11 @@ static const char *bincheck(const ec_info *ei, grand *gr) 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); @@ -551,20 +559,23 @@ int main(int argc, char *argv[]) } } } else { - fputs("checking standard curves: ", stdout); + fputs("checking standard curves...\n", stdout); for (ee = ectab; ee->name; ee++) { ec_info ei; + printf(" %s: ", ee->name); + fflush(stdout); 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); + printf("fails: %s\n", e); ok = 0; - } - putchar('.'); + } else + fputs("ok\n", stdout); fflush(stdout); } - fputs(ok ? " ok\n" : " failed\n", stdout); + if (ok) + fputs("all ok\n", stdout); } gr->ops->destroy(gr); return (!ok);