/* -*-c-*-
*
- * $Id: ec-info.c,v 1.7 2004/04/17 09:58:37 mdw Exp $
+ * $Id$
*
* Elliptic curve information management
*
#include "gf.h"
#include "pgen.h"
#include "mprand.h"
+#include "mpint.h"
#include "rabin.h"
/*----- Main code ---------------------------------------------------------*/
return (0);
}
-/* --- @getinfo@ --- *
+/* --- @ec_infofromdata@ --- *
*
* Arguments: @ec_info *ei@ = where to write the information
* @ecdata *ed@ = raw data
* curves.
*/
-static void getinfo(ec_info *ei, ecdata *ed)
+void ec_infofromdata(ec_info *ei, ecdata *ed)
{
field *f;
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) {
+ ec_infofromdata(ei, ee->data);
+ goto found;
+ }
+ }
if ((c = ec_curveparse(qd)) == 0) goto fail;
qd_delim(qd, '/'); if (!ec_ptparse(qd, &g)) goto fail;
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)
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");
}
}
} else {
- fputs("checking standard curves: ", stdout);
+ fputs("checking standard curves:", stdout);
+ fflush(stdout);
for (ee = ectab; ee->name; ee++) {
ec_info ei;
- getinfo(&ei, ee->data);
+ ec_infofromdata(&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(" [%s fails: %s]", ee->name, e);
ok = 0;
- }
- putchar('.');
+ } else
+ printf(" %s", ee->name);
fflush(stdout);
}
fputs(ok ? " ok\n" : " failed\n", stdout);