math/...: Make a number of functions be const-correct.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 22 Apr 2017 19:15:24 +0000 (20:15 +0100)
14 files changed:
math/ec-info.c
math/ec.h
math/gfreduce.c
math/gfreduce.h
math/mpbarrett-exp.c
math/mpbarrett-mexp.c
math/mpbarrett.c
math/mpbarrett.h
math/mpmont-exp.c
math/mpmont-mexp.c
math/mpmont.c
math/mpmont.h
math/mpreduce.c
math/mpreduce.h

index 017c498..f57f92c 100644 (file)
@@ -494,14 +494,14 @@ const char *ec_getinfo(ec_info *ei, const char *p)
 
 /* --- @ec_sameinfop@ --- *
  *
- * Arguments:  @ec_info *ei, *ej@ = two elliptic curve parameter sets
+ * Arguments:  @const ec_info *ei, *ej@ = two elliptic curve parameter sets
  *
  * Returns:    Nonzero if the curves are identical (not just isomorphic).
  *
  * Use:                Checks for sameness of curve parameters.
  */
 
-int ec_sameinfop(ec_info *ei, ec_info *ej)
+int ec_sameinfop(const ec_info *ei, const ec_info *ej)
 {
   return (ec_samep(ei->c, ej->c) &&
          MP_EQ(ei->r, ej->r) && MP_EQ(ei->h, ej->h) &&
index 3de2bb5..c6be6aa 100644 (file)
--- a/math/ec.h
+++ b/math/ec.h
@@ -580,14 +580,14 @@ extern const char *ec_getinfo(ec_info */*ei*/, const char */*p*/);
 
 /* --- @ec_sameinfop@ --- *
  *
- * Arguments:  @ec_info *ei, *ej@ = two elliptic curve parameter sets
+ * Arguments:  @const ec_info *ei, *ej@ = two elliptic curve parameter sets
  *
  * Returns:    Nonzero if the curves are identical (not just isomorphic).
  *
  * Use:                Checks for sameness of curve parameters.
  */
 
-extern int ec_sameinfop(ec_info */*ei*/, ec_info */*ej*/);
+extern int ec_sameinfop(const ec_info */*ei*/, const ec_info */*ej*/);
 
 /* --- @ec_freeinfo@ --- *
  *
index 83ffeb1..99f3bea 100644 (file)
@@ -297,7 +297,7 @@ void gfreduce_destroy(gfreduce *r)
 
 /* --- @gfreduce_dump@ --- *
  *
- * Arguments:  @gfreduce *r@ = structure to dump
+ * Arguments:  @const gfreduce *r@ = structure to dump
  *             @FILE *fp@ = file to dump on
  *
  * Returns:    ---
@@ -305,7 +305,7 @@ void gfreduce_destroy(gfreduce *r)
  * Use:                Dumps a reduction context.
  */
 
-void gfreduce_dump(gfreduce *r, FILE *fp)
+void gfreduce_dump(const gfreduce *r, FILE *fp)
 {
   size_t i;
 
@@ -327,7 +327,7 @@ void gfreduce_dump(gfreduce *r, FILE *fp)
 
 /* --- @gfreduce_do@ --- *
  *
- * Arguments:  @gfreduce *r@ = reduction context
+ * Arguments:  @const gfreduce *r@ = reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = source
  *
@@ -350,7 +350,7 @@ static void run(const gfreduce_instr *i, const gfreduce_instr *il,
   }
 }
 
-mp *gfreduce_do(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_do(const gfreduce *r, mp *d, mp *x)
 {
   mpw *v, *vl;
   const gfreduce_instr *il;
@@ -392,14 +392,14 @@ mp *gfreduce_do(gfreduce *r, mp *d, mp *x)
 
 /* --- @gfreduce_sqrt@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = some polynomial
  *
  * Returns:    The square root of @x@ modulo @r->p@, or null.
  */
 
-mp *gfreduce_sqrt(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_sqrt(const gfreduce *r, mp *d, mp *x)
 {
   mp *y = MP_COPY(x);
   mp *z, *spare = MP_NEW;
@@ -430,7 +430,7 @@ mp *gfreduce_sqrt(gfreduce *r, mp *d, mp *x)
 
 /* --- @gfreduce_trace@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *x@ = some polynomial
  *
  * Returns:    The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
@@ -440,7 +440,7 @@ mp *gfreduce_sqrt(gfreduce *r, mp *d, mp *x)
  *             we only need a single bit to represent it.
  */
 
-int gfreduce_trace(gfreduce *r, mp *x)
+int gfreduce_trace(const gfreduce *r, mp *x)
 {
   mp *y = MP_COPY(x);
   mp *spare = MP_NEW;
@@ -462,7 +462,7 @@ int gfreduce_trace(gfreduce *r, mp *x)
 
 /* --- @gfreduce_halftrace@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = some polynomial
  *
@@ -471,7 +471,7 @@ int gfreduce_trace(gfreduce *r, mp *x)
  *             if %$x \in \gf{2^m}$% with %$m$% odd).
  */
 
-mp *gfreduce_halftrace(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_halftrace(const gfreduce *r, mp *d, mp *x)
 {
   mp *y = MP_COPY(x);
   mp *spare = MP_NEW;
@@ -494,7 +494,7 @@ mp *gfreduce_halftrace(gfreduce *r, mp *d, mp *x)
 
 /* --- @gfreduce_quadsolve@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = some polynomial
  *
@@ -512,7 +512,7 @@ mp *gfreduce_halftrace(gfreduce *r, mp *d, mp *x)
  *             returns the one with zero scalar coefficient.
  */
 
-mp *gfreduce_quadsolve(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_quadsolve(const gfreduce *r, mp *d, mp *x)
 {
   unsigned long m = mp_bits(r->p) - 1;
   mp *t;
@@ -616,7 +616,7 @@ mp *gfreduce_quadsolve(gfreduce *r, mp *d, mp *x)
 
 /* --- @gfreduce_exp@ --- *
  *
- * Arguments:  @gfreduce *gr@ = pointer to reduction context
+ * Arguments:  @const gfreduce *gr@ = pointer to reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -624,7 +624,7 @@ mp *gfreduce_quadsolve(gfreduce *r, mp *d, mp *x)
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-mp *gfreduce_exp(gfreduce *gr, mp *d, mp *a, mp *e)
+mp *gfreduce_exp(const gfreduce *gr, mp *d, mp *a, mp *e)
 {
   mp *x = MP_ONE;
   mp *spare = (e->f & MP_BURN) ? MP_NEWSEC : MP_NEW;
index ef075c4..539b7c1 100644 (file)
@@ -91,7 +91,7 @@ extern void gfreduce_destroy(gfreduce */*r*/);
 
 /* --- @gfreduce_dump@ --- *
  *
- * Arguments:  @gfreduce *r@ = structure to dump
+ * Arguments:  @const gfreduce *r@ = structure to dump
  *             @FILE *fp@ = file to dump on
  *
  * Returns:    ---
@@ -99,33 +99,33 @@ extern void gfreduce_destroy(gfreduce */*r*/);
  * Use:                Dumps a reduction context.
  */
 
-extern void gfreduce_dump(gfreduce */*r*/, FILE */*fp*/);
+extern void gfreduce_dump(const gfreduce */*r*/, FILE */*fp*/);
 
 /* --- @gfreduce_do@ --- *
  *
- * Arguments:  @gfreduce *r@ = reduction context
+ * Arguments:  @const gfreduce *r@ = reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = source
  *
  * Returns:    Destination, @x@ reduced modulo the reduction poly.
  */
 
-extern mp *gfreduce_do(gfreduce */*r*/, mp */*d*/, mp */*x*/);
+extern mp *gfreduce_do(const gfreduce */*r*/, mp */*d*/, mp */*x*/);
 
 /* --- @gfreduce_sqrt@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = some polynomial
  *
  * Returns:    The square root of @x@ modulo @r->p@, or null.
  */
 
-extern mp *gfreduce_sqrt(gfreduce */*r*/, mp */*d*/, mp */*x*/);
+extern mp *gfreduce_sqrt(const gfreduce */*r*/, mp */*d*/, mp */*x*/);
 
 /* --- @gfreduce_trace@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *x@ = some polynomial
  *
  * Returns:    The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
@@ -135,11 +135,11 @@ extern mp *gfreduce_sqrt(gfreduce */*r*/, mp */*d*/, mp */*x*/);
  *             we only need a single bit to represent it.
  */
 
-extern int gfreduce_trace(gfreduce */*r*/, mp */*x*/);
+extern int gfreduce_trace(const gfreduce */*r*/, mp */*x*/);
 
 /* --- @gfreduce_halftrace@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = some polynomial
  *
@@ -148,11 +148,11 @@ extern int gfreduce_trace(gfreduce */*r*/, mp */*x*/);
  *             if %$x \in \gf{2^m}$% with %$m$% odd).
  */
 
-extern mp *gfreduce_halftrace(gfreduce */*r*/, mp */*d*/, mp */*x*/);
+extern mp *gfreduce_halftrace(const gfreduce */*r*/, mp */*d*/, mp */*x*/);
 
 /* --- @gfreduce_quadsolve@ --- *
  *
- * Arguments:  @gfreduce *r@ = pointer to reduction context
+ * Arguments:  @const gfreduce *r@ = pointer to reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = some polynomial
  *
@@ -170,11 +170,11 @@ extern mp *gfreduce_halftrace(gfreduce */*r*/, mp */*d*/, mp */*x*/);
  *             returns the one with zero scalar coefficient.
  */
 
-extern mp *gfreduce_quadsolve(gfreduce */*r*/, mp */*d*/, mp */*x*/);
+extern mp *gfreduce_quadsolve(const gfreduce */*r*/, mp */*d*/, mp */*x*/);
 
 /* --- @gfreduce_exp@ --- *
  *
- * Arguments:  @gfreduce *gr@ = pointer to reduction context
+ * Arguments:  @const gfreduce *gr@ = pointer to reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -182,7 +182,8 @@ extern mp *gfreduce_quadsolve(gfreduce */*r*/, mp */*d*/, mp */*x*/);
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-extern mp *gfreduce_exp(gfreduce */*gr*/, mp */*d*/, mp */*a*/, mp */*e*/);
+extern mp *gfreduce_exp(const gfreduce */*gr*/, mp */*d*/,
+                       mp */*a*/, mp */*e*/);
 
 /*----- That's all, folks -------------------------------------------------*/
 
index 44cad7e..27b74da 100644 (file)
@@ -35,7 +35,7 @@
 
 /* --- @mpbarrett_exp@ --- *
  *
- * Arguments:  @mpbarrett *mb@ = pointer to Barrett reduction context
+ * Arguments:  @const mpbarrett *mb@ = pointer to Barrett reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -43,7 +43,7 @@
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-mp *mpbarrett_exp(mpbarrett *mb, mp *d, mp *a, mp *e)
+mp *mpbarrett_exp(const mpbarrett *mb, mp *d, mp *a, mp *e)
 {
   mp *x = MP_ONE;
   mp *spare = (e->f & MP_BURN) ? MP_NEWSEC : MP_NEW;
index ac1e16a..33818c4 100644 (file)
@@ -37,7 +37,7 @@
 
 /* --- @mpbarrett_mexp@ --- *
  *
- * Arguments:  @mpbarrett *mb@ = pointer to Barrett reduction context
+ * Arguments:  @const mpbarrett *mb@ = pointer to Barrett reduction context
  *             @mp *d@ = fake destination
  *             @const mp_expfactor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
@@ -49,7 +49,8 @@
  *             %$g_0^{e_0} g_1^{e_1} \ldots g_{n-1}^{e_{n-1}} \bmod m$%
  */
 
-mp *mpbarrett_mexp(mpbarrett *mb, mp *d, const mp_expfactor *f, size_t n)
+mp *mpbarrett_mexp(const mpbarrett *mb, mp *d,
+                  const mp_expfactor *f, size_t n)
 {
   mp_expfactor *ff = xmalloc(n * sizeof(mp_expfactor));
   mp *a = MP_ONE;
index cadb9b3..dbb16be 100644 (file)
@@ -83,7 +83,7 @@ void mpbarrett_destroy(mpbarrett *mb)
 
 /* --- @mpbarrett_reduce@ --- *
  *
- * Arguments:  @mpbarrett *mb@ = pointer to Barrett reduction context
+ * Arguments:  @const mpbarrett *mb@ = pointer to Barrett reduction context
  *             @mp *d@ = destination for result
  *             @mp *m@ = number to reduce
  *
@@ -93,7 +93,7 @@ void mpbarrett_destroy(mpbarrett *mb)
  * Use:                Performs an efficient modular reduction.
  */
 
-mp *mpbarrett_reduce(mpbarrett *mb, mp *d, mp *m)
+mp *mpbarrett_reduce(const mpbarrett *mb, mp *d, mp *m)
 {
   mp *q;
   size_t k = mb->k;
index b3ab798..ec02251 100644 (file)
@@ -113,7 +113,7 @@ extern void mpbarrett_destroy(mpbarrett */*mb*/);
 
 /* --- @mpbarrett_reduce@ --- *
  *
- * Arguments:  @mpbarrett *mb@ = pointer to Barrett reduction context
+ * Arguments:  @const mpbarrett *mb@ = pointer to Barrett reduction context
  *             @mp *d@ = destination for result
  *             @mp *m@ = number to reduce
  *
@@ -123,11 +123,11 @@ extern void mpbarrett_destroy(mpbarrett */*mb*/);
  * Use:                Performs an efficient modular reduction.
  */
 
-extern mp *mpbarrett_reduce(mpbarrett */*mb*/, mp */*d*/, mp */*m*/);
+extern mp *mpbarrett_reduce(const mpbarrett */*mb*/, mp */*d*/, mp */*m*/);
 
 /* --- @mpbarrett_exp@ --- *
  *
- * Arguments:  @mpbarrett *mb@ = pointer to Barrett reduction context
+ * Arguments:  @const mpbarrett *mb@ = pointer to Barrett reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -135,11 +135,12 @@ extern mp *mpbarrett_reduce(mpbarrett */*mb*/, mp */*d*/, mp */*m*/);
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-extern mp *mpbarrett_exp(mpbarrett */*mb*/, mp */*d*/, mp */*a*/, mp */*e*/);
+extern mp *mpbarrett_exp(const mpbarrett */*mb*/, mp */*d*/,
+                        mp */*a*/, mp */*e*/);
 
 /* --- @mpbarrett_mexp@ --- *
  *
- * Arguments:  @mpbarrett *mb@ = pointer to Barrett reduction context
+ * Arguments:  @const mpbarrett *mb@ = pointer to Barrett reduction context
  *             @mp *d@ = fake destination
  *             @const mp_expfactor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
@@ -151,7 +152,7 @@ extern mp *mpbarrett_exp(mpbarrett */*mb*/, mp */*d*/, mp */*a*/, mp */*e*/);
  *             %$g_0^{e_0} g_1^{e_1} \ldots g_{n-1}^{e_{n-1}} \bmod m$%
  */
 
-extern mp *mpbarrett_mexp(mpbarrett */*mb*/, mp */*d*/,
+extern mp *mpbarrett_mexp(const mpbarrett */*mb*/, mp */*d*/,
                          const mp_expfactor */*f*/, size_t /*n*/);
 
 /*----- That's all, folks -------------------------------------------------*/
index 0ea554e..6b5c8c4 100644 (file)
@@ -35,7 +35,7 @@
 
 /* --- @mpmont_expr@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -43,7 +43,7 @@
  * Returns:    Result, %$(a R^{-1})^e R \bmod m$%.
  */
 
-mp *mpmont_expr(mpmont *mm, mp *d, mp *a, mp *e)
+mp *mpmont_expr(const mpmont *mm, mp *d, mp *a, mp *e)
 {
   mp *x = MP_COPY(mm->r);
   mp *spare = (e->f & MP_BURN) ? MP_NEWSEC : MP_NEW;
@@ -71,7 +71,7 @@ mp *mpmont_expr(mpmont *mm, mp *d, mp *a, mp *e)
 
 /* --- @mpmont_exp@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -79,7 +79,7 @@ mp *mpmont_expr(mpmont *mm, mp *d, mp *a, mp *e)
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-mp *mpmont_exp(mpmont *mm, mp *d, mp *a, mp *e)
+mp *mpmont_exp(const mpmont *mm, mp *d, mp *a, mp *e)
 {
   e = MP_COPY(e);
   d = mpmont_mul(mm, d, a, mm->r2);
index 20a5f73..9b0506b 100644 (file)
@@ -37,7 +37,7 @@
 
 /* --- @mpmont_mexpr@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @const mp_expfactor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
@@ -51,7 +51,7 @@
  *             except that the %$g_i$% and result are in Montgomery form.
  */
 
-static mp *mexpr(mpmont *mm, mp *d, mp_expfactor *f, size_t n)
+static mp *mexpr(const mpmont *mm, mp *d, mp_expfactor *f, size_t n)
 {
   mp *a = MP_COPY(mm->r);
   mp *spare = MP_NEW;
@@ -76,7 +76,7 @@ static mp *mexpr(mpmont *mm, mp *d, mp_expfactor *f, size_t n)
   return (a);
 }
 
-mp *mpmont_mexpr(mpmont *mm, mp *d, const mp_expfactor *f, size_t n)
+mp *mpmont_mexpr(const mpmont *mm, mp *d, const mp_expfactor *f, size_t n)
 {
   mp_expfactor *ff = xmalloc(n * sizeof(mp_expfactor));
   size_t i;
@@ -90,7 +90,7 @@ mp *mpmont_mexpr(mpmont *mm, mp *d, const mp_expfactor *f, size_t n)
 
 /* --- @mpmont_mexp@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @const mp_expfactor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
@@ -100,7 +100,7 @@ mp *mpmont_mexpr(mpmont *mm, mp *d, const mp_expfactor *f, size_t n)
  * Use:                Convenient interface over @mpmont_mexpr@.
  */
 
-mp *mpmont_mexp(mpmont *mm, mp *d, const mp_expfactor *f, size_t n)
+mp *mpmont_mexp(const mpmont *mm, mp *d, const mp_expfactor *f, size_t n)
 {
   mp_expfactor *ff = xmalloc(n * sizeof(mp_expfactor));
   size_t i;
index fe1e645..f8a2611 100644 (file)
@@ -211,7 +211,8 @@ static mulcore__functype *pick_mulcore(void)
 
 /* --- @finish@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to a Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to a Montgomery reduction
+ *                     context
  *             *mp *d@ = pointer to mostly-reduced operand
  *
  * Returns:    ---
@@ -223,7 +224,7 @@ static mulcore__functype *pick_mulcore(void)
  *             need to do an additional subtraction if %$d$% is negative.
  */
 
-static void finish(mpmont *mm, mp *d)
+static void finish(const mpmont *mm, mp *d)
 {
   mpw *dv = d->v, *dvl = d->vl;
   size_t n = mm->n;
@@ -328,7 +329,7 @@ void mpmont_destroy(mpmont *mm)
 
 /* --- @mpmont_reduce@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
  *             @mp *a@ = source, assumed positive
  *
@@ -337,7 +338,7 @@ void mpmont_destroy(mpmont *mm)
 
 #ifdef MPMONT_DISABLE
 
-mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
+mp *mpmont_reduce(const mpmont *mm, mp *d, mp *a)
 {
   mp_div(0, &d, a, mm->m);
   return (d);
@@ -345,7 +346,7 @@ mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
 
 #else
 
-mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
+mp *mpmont_reduce(const mpmont *mm, mp *d, mp *a)
 {
   size_t n = mm->n;
 
@@ -387,7 +388,7 @@ mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
 
 /* --- @mpmont_mul@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
  *             @mp *a, *b@ = sources, assumed positive
  *
@@ -396,7 +397,7 @@ mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
 
 #ifdef MPMONT_DISABLE
 
-mp *mpmont_mul(mpmont *mm, mp *d, mp *a, mp *b)
+mp *mpmont_mul(const mpmont *mm, mp *d, mp *a, mp *b)
 {
   d = mp_mul(d, a, b);
   mp_div(0, &d, d, mm->m);
@@ -405,7 +406,7 @@ mp *mpmont_mul(mpmont *mm, mp *d, mp *a, mp *b)
 
 #else
 
-mp *mpmont_mul(mpmont *mm, mp *d, mp *a, mp *b)
+mp *mpmont_mul(const mpmont *mm, mp *d, mp *a, mp *b)
 {
   size_t n = mm->n;
 
index b0c119a..cd1d399 100644 (file)
@@ -126,29 +126,29 @@ extern void mpmont_destroy(mpmont */*mm*/);
 
 /* --- @mpmont_reduce@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
  *             @mp *a@ = source, assumed positive
  *
  * Returns:    Result, %$a R^{-1} \bmod m$%.
  */
 
-extern mp *mpmont_reduce(mpmont */*mm*/, mp */*d*/, mp */*a*/);
+extern mp *mpmont_reduce(const mpmont */*mm*/, mp */*d*/, mp */*a*/);
 
 /* --- @mpmont_mul@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = destination
  *             @mp *a, *b@ = sources, assumed positive
  *
  * Returns:    Result, %$a b R^{-1} \bmod m$%.
  */
 
-extern mp *mpmont_mul(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*b*/);
+extern mp *mpmont_mul(const mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*b*/);
 
 /* --- @mpmont_expr@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -157,11 +157,12 @@ extern mp *mpmont_mul(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*b*/);
  *             further modular arithmetic is to be performed on the result.
  */
 
-extern mp *mpmont_expr(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
+extern mp *mpmont_expr(const mpmont */*mm*/, mp */*d*/,
+                      mp */*a*/, mp */*e*/);
 
 /* --- @mpmont_exp@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -169,11 +170,11 @@ extern mp *mpmont_expr(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-extern mp *mpmont_exp(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
+extern mp *mpmont_exp(const mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
 
 /* --- @mpmont_mexpr@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @const mp_expfactor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
@@ -188,12 +189,12 @@ extern mp *mpmont_exp(mpmont */*mm*/, mp */*d*/, mp */*a*/, mp */*e*/);
  *             except that the %$g_i$% and result are in Montgomery form.
  */
 
-extern mp *mpmont_mexpr(mpmont */*mm*/, mp */*d*/,
+extern mp *mpmont_mexpr(const mpmont */*mm*/, mp */*d*/,
                        const mp_expfactor */*f*/, size_t /*n*/);
 
 /* --- @mpmont_mexp@ --- *
  *
- * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ * Arguments:  @const mpmont *mm@ = pointer to Montgomery reduction context
  *             @mp *d@ = fake destination
  *             @const mp_expfactor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
@@ -203,7 +204,7 @@ extern mp *mpmont_mexpr(mpmont */*mm*/, mp */*d*/,
  * Use:                Convenient interface over @mpmont_mexpr@.
  */
 
-extern mp *mpmont_mexp(mpmont */*mm*/, mp */*d*/,
+extern mp *mpmont_mexp(const mpmont */*mm*/, mp */*d*/,
                       const mp_expfactor */*f*/, size_t /*n*/);
 
 /*----- That's all, folks -------------------------------------------------*/
index 871d3a4..0fd4b45 100644 (file)
@@ -295,7 +295,7 @@ void mpreduce_destroy(mpreduce *r)
 
 /* --- @mpreduce_dump@ --- *
  *
- * Arguments:  @mpreduce *r@ = structure to dump
+ * Arguments:  @const mpreduce *r@ = structure to dump
  *             @FILE *fp@ = file to dump on
  *
  * Returns:    ---
@@ -303,7 +303,7 @@ void mpreduce_destroy(mpreduce *r)
  * Use:                Dumps a reduction context.
  */
 
-void mpreduce_dump(mpreduce *r, FILE *fp)
+void mpreduce_dump(const mpreduce *r, FILE *fp)
 {
   size_t i;
   static const char *opname[] = { "add", "addshift", "sub", "subshift" };
@@ -331,7 +331,7 @@ void mpreduce_dump(mpreduce *r, FILE *fp)
 
 /* --- @mpreduce_do@ --- *
  *
- * Arguments:  @mpreduce *r@ = reduction context
+ * Arguments:  @const mpreduce *r@ = reduction context
  *             @mp *d@ = destination
  *             @mp *x@ = source
  *
@@ -353,7 +353,7 @@ static void run(const mpreduce_instr *i, const mpreduce_instr *il,
   }
 }
 
-mp *mpreduce_do(mpreduce *r, mp *d, mp *x)
+mp *mpreduce_do(const mpreduce *r, mp *d, mp *x)
 {
   mpw *v, *vl;
   const mpreduce_instr *il;
@@ -410,7 +410,7 @@ mp *mpreduce_do(mpreduce *r, mp *d, mp *x)
 
 /* --- @mpreduce_exp@ --- *
  *
- * Arguments:  @mpreduce *mr@ = pointer to reduction context
+ * Arguments:  @const mpreduce *mr@ = pointer to reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -418,7 +418,7 @@ mp *mpreduce_do(mpreduce *r, mp *d, mp *x)
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-mp *mpreduce_exp(mpreduce *mr, mp *d, mp *a, mp *e)
+mp *mpreduce_exp(const mpreduce *mr, mp *d, mp *a, mp *e)
 {
   mp *x = MP_ONE;
   mp *spare = (e->f & MP_BURN) ? MP_NEWSEC : MP_NEW;
index efac88f..b6eb2d7 100644 (file)
@@ -93,7 +93,7 @@ extern void mpreduce_destroy(mpreduce */*r*/);
 
 /* --- @mpreduce_dump@ --- *
  *
- * Arguments:  @mpreduce *r@ = structure to dump
+ * Arguments:  @const mpreduce *r@ = structure to dump
  *             @FILE *fp@ = file to dump on
  *
  * Returns:    ---
@@ -101,7 +101,7 @@ extern void mpreduce_destroy(mpreduce */*r*/);
  * Use:                Dumps a reduction context.
  */
 
-extern void mpreduce_dump(mpreduce */*r*/, FILE */*fp*/);
+extern void mpreduce_dump(const mpreduce */*r*/, FILE */*fp*/);
 
 /* --- @mpreduce_do@ --- *
  *
@@ -112,11 +112,11 @@ extern void mpreduce_dump(mpreduce */*r*/, FILE */*fp*/);
  * Returns:    Destination, @x@ reduced modulo the reduction poly.
  */
 
-extern mp *mpreduce_do(mpreduce */*r*/, mp */*d*/, mp */*x*/);
+extern mp *mpreduce_do(const mpreduce */*r*/, mp */*d*/, mp */*x*/);
 
 /* --- @mpreduce_exp@ --- *
  *
- * Arguments:  @mpreduce *mr@ = pointer to reduction context
+ * Arguments:  @const mpreduce *mr@ = pointer to reduction context
  *             @mp *d@ = fake destination
  *             @mp *a@ = base
  *             @mp *e@ = exponent
@@ -124,7 +124,8 @@ extern mp *mpreduce_do(mpreduce */*r*/, mp */*d*/, mp */*x*/);
  * Returns:    Result, %$a^e \bmod m$%.
  */
 
-extern mp *mpreduce_exp(mpreduce */*mr*/, mp */*d*/, mp */*a*/, mp */*e*/);
+extern mp *mpreduce_exp(const mpreduce */*mr*/, mp */*d*/,
+                       mp */*a*/, mp */*e*/);
 
 /*----- That's all, folks -------------------------------------------------*/