/* -*-c-*-
*
- * $Id: mpmont.c,v 1.4 1999/11/21 12:27:06 mdw Exp $
+ * $Id: mpmont.c,v 1.5 1999/11/22 13:58:40 mdw Exp $
*
* Montgomery reduction
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mpmont.c,v $
+ * Revision 1.5 1999/11/22 13:58:40 mdw
+ * Add an option to disable Montgomery reduction, so that performance
+ * comparisons can be done.
+ *
* Revision 1.4 1999/11/21 12:27:06 mdw
* Remove a division from the Montgomery setup by calculating
* %$R^2 \bmod m$% first and then %$R \bmod m$% by Montgomery reduction of
#include "mp.h"
#include "mpmont.h"
+/*----- Tweakables --------------------------------------------------------*/
+
+/* --- @MPMONT_DISABLE@ --- *
+ *
+ * Replace all the clever Montgomery reduction with good old-fashioned long
+ * division.
+ */
+
+/* #define MPMONT_DISABLE */
+
/*----- Main code ---------------------------------------------------------*/
/* --- @mpmont_create@ --- *
* Use: Initializes a Montgomery reduction context ready for use.
*/
+#ifdef MPMONT_DISABLE
+
+void mpmont_create(mpmont *mm, mp *m)
+{
+ mp_shrink(m);
+ mm->m = MP_COPY(m);
+ mm->r = MP_ONE;
+ mm->r2 = MP_ONE;
+}
+
+#else
+
void mpmont_create(mpmont *mm, mp *m)
{
/* --- Take a copy of the modulus --- */
}
}
+#endif
+
/* --- @mpmont_destroy@ --- *
*
* Arguments: @mpmont *mm@ = pointer to a Montgomery reduction context
* Returns: Result, %$a R^{-1} \bmod m$%.
*/
+#ifdef MPMONT_DISABLE
+
+mp *mpmont_reduce(mpmont *mm, mp *d, const mp *a)
+{
+ mp_div(0, &d, a, mm->m);
+ return (d);
+}
+
+#else
+
mp *mpmont_reduce(mpmont *mm, mp *d, const mp *a)
{
mpw *dv, *dvl;
return (d);
}
+#endif
+
/* --- @mpmont_mul@ --- *
*
* Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
* Returns: Result, %$a b R^{-1} \bmod m$%.
*/
+#ifdef MPMONT_DISABLE
+
+mp *mpmont_mul(mpmont *mm, mp *d, const mp *a, const mp *b)
+{
+ d = mp_mul(d, a, b);
+ mp_div(0, &d, d, mm->m);
+ return (d);
+}
+
+#else
+
mp *mpmont_mul(mpmont *mm, mp *d, const mp *a, const mp *b)
{
mpw *dv, *dvl;
return (d);
}
+#endif
+
/* --- @mpmont_expr@ --- *
*
* Arguments: @mpmont *mm@ = pointer to Montgomery reduction context