/* -*-c-*-
*
- * $Id: mpmont.c,v 1.19 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
*
* Montgomery reduction
*
* Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
* @mp *m@ = modulus to use
*
- * Returns: ---
+ * Returns: Zero on success, nonzero on error.
*
* Use: Initializes a Montgomery reduction context ready for use.
* The argument @m@ must be a positive odd integer.
#ifdef MPMONT_DISABLE
-void mpmont_create(mpmont *mm, mp *m)
+int mpmont_create(mpmont *mm, mp *m)
{
mp_shrink(m);
mm->m = MP_COPY(m);
mm->r = MP_ONE;
mm->r2 = MP_ONE;
mm->mi = MP_ONE;
+ return (0);
}
#else
-void mpmont_create(mpmont *mm, mp *m)
+int mpmont_create(mpmont *mm, mp *m)
{
size_t n = MP_LEN(m);
mp *r2 = mp_new(2 * n + 1, 0);
/* --- Take a copy of the modulus --- */
- assert(MP_ISPOS(m) && MP_ISODD(m));
+ if (!MP_POSP(m) || !MP_ODDP(m))
+ return (-1);
mm->m = MP_COPY(m);
/* --- Determine %$R^2$% --- */
mp_div(0, &mm->r2, r2, m);
mm->r = mpmont_reduce(mm, MP_NEW, mm->r2);
MP_DROP(r2);
+ return (0);
}
#endif