From 2af1930eafd4b2747c3736dec408be25e6a8b737 Mon Sep 17 00:00:00 2001 From: mdw Date: Fri, 19 Nov 1999 13:17:43 +0000 Subject: [PATCH] Add extra interface to exponentiation which returns a Montgomerized result. Add simultaneous exponentiation interface. --- mpmont.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/mpmont.h b/mpmont.h index 42aa17c..20ae0ac 100644 --- a/mpmont.h +++ b/mpmont.h @@ -1,6 +1,6 @@ /* -*-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 * @@ -30,6 +30,10 @@ /*----- 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. * @@ -91,6 +95,13 @@ typedef struct mpmont { 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@ --- * @@ -105,6 +116,92 @@ typedef struct mpmont { 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 -- 2.11.0