/* -*-c-*-
*
- * $Id: mpmont.h,v 1.1 1999/11/17 18:02:16 mdw Exp $
+ * $Id: mpmont.h,v 1.2 1999/11/19 13:17:43 mdw Exp $
*
* Montgomery reduction
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mpmont.h,v $
+ * Revision 1.2 1999/11/19 13:17:43 mdw
+ * Add extra interface to exponentiation which returns a Montgomerized
+ * result. Add simultaneous exponentiation interface.
+ *
* Revision 1.1 1999/11/17 18:02:16 mdw
* New multiprecision integer arithmetic suite.
*
mp *r, *r2; /* %$R \bmod m$%, %$R^2 \bmod m$% */
} mpmont;
+/* --- A base/exponent pair for @mpmont_mexp@ --- */
+
+typedef struct mpmont_factor {
+ mp *base;
+ mp *exp;
+} mpmont_factor;
+
/*----- Functions provided ------------------------------------------------*/
/* --- @mpmont_create@ --- *
extern void mpmont_create(mpmont */*mm*/, mp */*m*/);
+/* --- @mpmont_destroy@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to a Montgomery reduction context
+ *
+ * Returns: ---
+ *
+ * Use: Disposes of a context when it's no longer of any use to
+ * anyone.
+ */
+
+extern void mpmont_destroy(mpmont */*mm*/);
+
+/* --- @mpmont_reduce@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * @mp *d@ = destination
+ * @const mp *a@ = source, assumed positive
+ *
+ * Returns: Result, %$a R^{-1} \bmod m$%.
+ */
+
+extern mp *mpmont_reduce(mpmont */*mm*/, mp */*d*/, const mp */*a*/);
+
+/* --- @mpmont_mul@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * @mp *d@ = destination
+ * @const mp *a, *b@ = sources, assumed positive
+ *
+ * Returns: Result, %$a b R^{-1} \bmod m$%.
+ */
+
+extern mp *mpmont_mul(mpmont */*mm*/, mp */*d*/,
+ const mp */*a*/, const mp */*b*/);
+
+/* --- @mpmont_expr@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * @const mp *a@ = base
+ * @const mp *e@ = exponent
+ *
+ * Returns: Result, %$a^e R \bmod m$%. This is useful if further modular
+ * arithmetic is to be performed on the result.
+ */
+
+extern mp *mpmont_expr(mpmont */*mm*/, const mp */*a*/, const mp */*e*/);
+
+/* --- @mpmont_exp@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * @const mp *a@ = base
+ * @const mp *e@ = exponent
+ *
+ * Returns: Result, %$a^e \bmod m$%.
+ */
+
+extern mp *mpmont_exp(mpmont */*mm*/, const mp */*a*/, const mp */*e*/);
+
+/* --- @mpmont_mexpr@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * @mpmont_factor *f@ = pointer to array of factors
+ * @size_t n@ = number of factors supplied
+ *
+ * Returns: If the bases are %$g_0, g_1, \ldots, g_{n-1}$% and the
+ * exponents are %$e_0, e_1, \ldots, e_{n-1}$% then the result
+ * is:
+ *
+ * %$g_0^{e_0} g_1^{e_1} \ldots g_{n-1}^{e_{n-1}} R \bmod m$%
+ */
+
+extern mp *mpmont_mexpr(mpmont */*mm*/, mpmont_factor */*f*/, size_t /*n*/);
+
+/* --- @mpmont_mexp@ --- *
+ *
+ * Arguments: @mpmont *mm@ = pointer to Montgomery reduction context
+ * @mpmont_factor *f@ = pointer to array of factors
+ * @size_t n@ = number of factors supplied
+ *
+ * Returns: Product of bases raised to exponents, all mod @m@.
+ *
+ * Use: Convenient interface over @mpmont_mexpr@.
+ */
+
+extern mp *mpmont_mexp(mpmont */*mm*/, mpmont_factor */*f*/, size_t /*n*/);
+
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus