From 295f4f9060d7a18118b22f737d9140d5bd9306e6 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 26 May 2016 09:26:09 +0100 Subject: [PATCH] math/...: Make a number of functions be const-correct. --- math/ec-info.c | 4 ++-- math/ec.h | 4 ++-- math/gfreduce.c | 28 ++++++++++++++-------------- math/gfreduce.h | 29 +++++++++++++++-------------- math/mpbarrett-exp.c | 4 ++-- math/mpbarrett-mexp.c | 5 +++-- math/mpbarrett.c | 4 ++-- math/mpbarrett.h | 13 +++++++------ math/mpmont-exp.c | 8 ++++---- math/mpmont-mexp.c | 10 +++++----- math/mpmont.c | 17 +++++++++-------- math/mpmont.h | 25 +++++++++++++------------ math/mpreduce.c | 12 ++++++------ math/mpreduce.h | 11 ++++++----- 14 files changed, 90 insertions(+), 84 deletions(-) diff --git a/math/ec-info.c b/math/ec-info.c index 017c4982..f57f92c0 100644 --- a/math/ec-info.c +++ b/math/ec-info.c @@ -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) && diff --git a/math/ec.h b/math/ec.h index 3de2bb51..c6be6aa4 100644 --- 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@ --- * * diff --git a/math/gfreduce.c b/math/gfreduce.c index 83ffeb10..99f3bea5 100644 --- a/math/gfreduce.c +++ b/math/gfreduce.c @@ -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; diff --git a/math/gfreduce.h b/math/gfreduce.h index ef075c45..539b7c14 100644 --- a/math/gfreduce.h +++ b/math/gfreduce.h @@ -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 -------------------------------------------------*/ diff --git a/math/mpbarrett-exp.c b/math/mpbarrett-exp.c index 44cad7ef..27b74da0 100644 --- a/math/mpbarrett-exp.c +++ b/math/mpbarrett-exp.c @@ -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; diff --git a/math/mpbarrett-mexp.c b/math/mpbarrett-mexp.c index ac1e16ae..33818c4c 100644 --- a/math/mpbarrett-mexp.c +++ b/math/mpbarrett-mexp.c @@ -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; diff --git a/math/mpbarrett.c b/math/mpbarrett.c index cadb9b36..dbb16be2 100644 --- a/math/mpbarrett.c +++ b/math/mpbarrett.c @@ -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; diff --git a/math/mpbarrett.h b/math/mpbarrett.h index b3ab798e..ec022516 100644 --- a/math/mpbarrett.h +++ b/math/mpbarrett.h @@ -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 -------------------------------------------------*/ diff --git a/math/mpmont-exp.c b/math/mpmont-exp.c index 0ea554ea..6b5c8c43 100644 --- a/math/mpmont-exp.c +++ b/math/mpmont-exp.c @@ -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); diff --git a/math/mpmont-mexp.c b/math/mpmont-mexp.c index 20a5f73b..9b0506bf 100644 --- a/math/mpmont-mexp.c +++ b/math/mpmont-mexp.c @@ -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; diff --git a/math/mpmont.c b/math/mpmont.c index fe1e6457..f8a26119 100644 --- a/math/mpmont.c +++ b/math/mpmont.c @@ -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; diff --git a/math/mpmont.h b/math/mpmont.h index b0c119af..cd1d3999 100644 --- a/math/mpmont.h +++ b/math/mpmont.h @@ -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 -------------------------------------------------*/ diff --git a/math/mpreduce.c b/math/mpreduce.c index 871d3a42..0fd4b458 100644 --- a/math/mpreduce.c +++ b/math/mpreduce.c @@ -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; diff --git a/math/mpreduce.h b/math/mpreduce.h index efac88f7..b6eb2d7c 100644 --- a/math/mpreduce.h +++ b/math/mpreduce.h @@ -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 -------------------------------------------------*/ -- 2.11.0