Change header file guard names.
[u/mdw/catacomb] / mpmont.h
index 20ae0ac..6b2b9bd 100644 (file)
--- a/mpmont.h
+++ b/mpmont.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: mpmont.h,v 1.2 1999/11/19 13:17:43 mdw Exp $
+ * $Id: mpmont.h,v 1.3 1999/12/10 23:29:48 mdw Exp $
  *
  * Montgomery reduction
  *
  *
  * Montgomery reduction
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpmont.h,v $
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpmont.h,v $
+ * Revision 1.3  1999/12/10 23:29:48  mdw
+ * Change header file guard names.
+ *
  * 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.2  1999/11/19 13:17:43  mdw
  * Add extra interface to exponentiation which returns a Montgomerized
  * result.  Add simultaneous exponentiation interface.
@@ -39,8 +42,8 @@
  *
  */
 
  *
  */
 
-#ifndef MPMONT_H
-#define MPMONT_H
+#ifndef CATACOMB_MPMONT_H
+#define CATACOMB_MPMONT_H
 
 #ifdef __cplusplus
   extern "C" {
 
 #ifdef __cplusplus
   extern "C" {
 
 /*----- Header files ------------------------------------------------------*/
 
 
 /*----- Header files ------------------------------------------------------*/
 
-#ifndef MP_H
+#ifndef CATACOMB_MP_H
 #  include "mp.h"
 #endif
 
 #  include "mp.h"
 #endif
 
-/*----- What's going on here? ---------------------------------------------*
+/*----- Notes on Montgomery reduction -------------------------------------*
  *
  * Given a little bit of precomputation, Montgomery reduction enables modular
  * reductions of products to be calculated rather rapidly, without recourse
  *
  * Given a little bit of precomputation, Montgomery reduction enables modular
  * reductions of products to be calculated rather rapidly, without recourse
@@ -61,7 +64,9 @@
  * Before starting, you need to do a little work.  In particular, the
  * following things need to be worked out:
  *
  * Before starting, you need to do a little work.  In particular, the
  * following things need to be worked out:
  *
- *   * %$m$%, which is the modulus you'll be working with.
+ *   * %$m$%, which is the modulus you'll be working with.  This must be odd,
+ *     otherwise the whole thing doesn't work.  You're better off using
+ *     Barrett reduction if your modulus might be even.
  *
  *   * %$b$%, the radix of the number system you're in (here, it's
  *     @MPW_MAX + 1@).
  *
  *   * %$b$%, the radix of the number system you're in (here, it's
  *     @MPW_MAX + 1@).
@@ -77,8 +82,8 @@
  * The result of a Montgomery reduction of %$x$% is %$x R^{-1} \bmod m$%,
  * which doesn't look ever-so useful.  The trick is to initially apply a
  * factor of %$R$% to all of your numbers so that when you multiply and
  * The result of a Montgomery reduction of %$x$% is %$x R^{-1} \bmod m$%,
  * which doesn't look ever-so useful.  The trick is to initially apply a
  * factor of %$R$% to all of your numbers so that when you multiply and
- * perform a Montgomery reduction you get %$(xR \cdot yR)R^{-1} \bmod m$%,
- * which is just %$xyR \bmod m$%.  Thanks to distributivity, even additions
+ * perform a Montgomery reduction you get %$(x R \cdot y R) R^{-1} \bmod m$%,
+ * which is just %$x y R \bmod m$%.  Thanks to distributivity, even additions
  * and subtractions can be performed on numbers in this form -- the extra
  * factor of %$R$% just runs through all the calculations until it's finally
  * stripped out by a final reduction operation.
  * and subtractions can be performed on numbers in this form -- the extra
  * factor of %$R$% just runs through all the calculations until it's finally
  * stripped out by a final reduction operation.
@@ -112,6 +117,7 @@ typedef struct mpmont_factor {
  * Returns:    ---
  *
  * Use:                Initializes a Montgomery reduction context ready for use.
  * Returns:    ---
  *
  * Use:                Initializes a Montgomery reduction context ready for use.
+ *             The argument @m@ must be a positive odd integer.
  */
 
 extern void mpmont_create(mpmont */*mm*/, mp */*m*/);
  */
 
 extern void mpmont_create(mpmont */*mm*/, mp */*m*/);
@@ -132,51 +138,53 @@ extern void mpmont_destroy(mpmont */*mm*/);
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
- *             @const mp *a@ = source, assumed positive
+ *             @mp *a@ = source, assumed positive
  *
  * Returns:    Result, %$a R^{-1} \bmod m$%.
  */
 
  *
  * Returns:    Result, %$a R^{-1} \bmod m$%.
  */
 
-extern mp *mpmont_reduce(mpmont */*mm*/, mp */*d*/, const mp */*a*/);
+extern mp *mpmont_reduce(mpmont */*mm*/, mp */*d*/, mp */*a*/);
 
 /* --- @mpmont_mul@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
 
 /* --- @mpmont_mul@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
- *             @const mp *a, *b@ = sources, assumed positive
+ *             @mp *a, *b@ = sources, assumed positive
  *
  * Returns:    Result, %$a b R^{-1} \bmod m$%.
  */
 
  *
  * Returns:    Result, %$a b R^{-1} \bmod m$%.
  */
 
-extern mp *mpmont_mul(mpmont */*mm*/, mp */*d*/,
-                     const mp */*a*/, const mp */*b*/);
+extern mp *mpmont_mul(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*b*/);
 
 /* --- @mpmont_expr@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
 
 /* --- @mpmont_expr@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
- *             @const mp *a@ = base
- *             @const mp *e@ = exponent
+ *             @mp *d@ = fake destination
+ *             @mp *a@ = base
+ *             @mp *e@ = exponent
  *
  * Returns:    Result, %$a^e R \bmod m$%.  This is useful if further modular
  *             arithmetic is to be performed on the result.
  */
 
  *
  * 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*/);
+extern mp *mpmont_expr(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
 
 /* --- @mpmont_exp@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
 
 /* --- @mpmont_exp@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
- *             @const mp *a@ = base
- *             @const mp *e@ = exponent
+ *             @mp *d@ = fake destination
+ *             @mp *a@ = base
+ *             @mp *e@ = exponent
  *
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
  *
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-extern mp *mpmont_exp(mpmont */*mm*/, const mp */*a*/, const mp */*e*/);
+extern mp *mpmont_exp(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
 
 /* --- @mpmont_mexpr@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
 
 /* --- @mpmont_mexpr@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ *             @mp *d@ = fake destination
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
@@ -187,11 +195,13 @@ extern mp *mpmont_exp(mpmont */*mm*/, const mp */*a*/, const mp */*e*/);
  *             %$g_0^{e_0} g_1^{e_1} \ldots g_{n-1}^{e_{n-1}} R \bmod m$%
  */
 
  *             %$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*/);
+extern mp *mpmont_mexpr(mpmont */*mm*/, mp */*d*/,
+                       mpmont_factor */*f*/, size_t /*n*/);
 
 /* --- @mpmont_mexp@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
 
 /* --- @mpmont_mexp@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ *             @mp *d@ = fake destination
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
@@ -200,7 +210,8 @@ extern mp *mpmont_mexpr(mpmont */*mm*/, mpmont_factor */*f*/, size_t /*n*/);
  * Use:                Convenient interface over @mpmont_mexpr@.
  */
 
  * Use:                Convenient interface over @mpmont_mexpr@.
  */
 
-extern mp *mpmont_mexp(mpmont */*mm*/, mpmont_factor */*f*/, size_t /*n*/);
+extern mp *mpmont_mexp(mpmont */*mm*/, mp */*d*/,
+                      mpmont_factor */*f*/, size_t /*n*/);
 
 /*----- That's all, folks -------------------------------------------------*/
 
 
 /*----- That's all, folks -------------------------------------------------*/