/* -*-c-*-
*
- * $Id: f-prime.c,v 1.10 2004/04/02 01:03:49 mdw Exp $
+ * $Id: f-prime.c,v 1.11 2004/04/03 03:32:05 mdw Exp $
*
* Prime fields with Montgomery arithmetic
*
/*----- Revision history --------------------------------------------------*
*
* $Log: f-prime.c,v $
+ * Revision 1.11 2004/04/03 03:32:05 mdw
+ * General robustification.
+ *
* Revision 1.10 2004/04/02 01:03:49 mdw
* Miscellaneous constification.
*
*
* Arguments: @mp *p@ = the characteristic of the field
*
- * Returns: A pointer to the field.
+ * Returns: A pointer to the field or null.
*
* Use: Creates a field structure for a prime field of size %$p$%,
* using Montgomery reduction for arithmetic.
field *field_prime(mp *p)
{
- fctx *f = CREATE(fctx);
+ fctx *f;
+
+ if (!MP_ISPOS(p) || !MP_ISODD(p))
+ return (0);
+ f = CREATE(fctx);
f->f.ops = &fops;
mpmont_create(&f->mm, p);
f->f.zero = MP_ZERO;