summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_s_mp_exptmod.c
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2005-04-10 23:54:55 (GMT)
committerKevin B Kenny <kennykb@acm.org>2005-04-10 23:54:55 (GMT)
commitd2b645df1ab7b43093f7553808c64fedaa3b3a49 (patch)
tree99103342350cd1fb4776a60684221ad722fdec52 /libtommath/bn_s_mp_exptmod.c
parentb9cf65a08e6a59e434685e894e3189c201ac6791 (diff)
downloadtcl-d2b645df1ab7b43093f7553808c64fedaa3b3a49.zip
tcl-d2b645df1ab7b43093f7553808c64fedaa3b3a49.tar.gz
tcl-d2b645df1ab7b43093f7553808c64fedaa3b3a49.tar.bz2
Import of tommath 0.35
Diffstat (limited to 'libtommath/bn_s_mp_exptmod.c')
-rw-r--r--libtommath/bn_s_mp_exptmod.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/libtommath/bn_s_mp_exptmod.c b/libtommath/bn_s_mp_exptmod.c
index 01a766f..597e877 100644
--- a/libtommath/bn_s_mp_exptmod.c
+++ b/libtommath/bn_s_mp_exptmod.c
@@ -21,11 +21,12 @@
#define TAB_SIZE 256
#endif
-int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
+int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
{
mp_int M[TAB_SIZE], res, mu;
mp_digit buf;
int err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
+ int (*redux)(mp_int*,mp_int*,mp_int*);
/* find window size */
x = mp_count_bits (X);
@@ -72,9 +73,18 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_init (&mu)) != MP_OKAY) {
goto LBL_M;
}
- if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
- goto LBL_MU;
- }
+
+ if (redmode == 0) {
+ if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
+ goto LBL_MU;
+ }
+ redux = mp_reduce;
+ } else {
+ if ((err = mp_reduce_2k_setup_l (P, &mu)) != MP_OKAY) {
+ goto LBL_MU;
+ }
+ redux = mp_reduce_2k_l;
+ }
/* create M table
*
@@ -96,11 +106,14 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
}
for (x = 0; x < (winsize - 1); x++) {
+ /* square it */
if ((err = mp_sqr (&M[1 << (winsize - 1)],
&M[1 << (winsize - 1)])) != MP_OKAY) {
goto LBL_MU;
}
- if ((err = mp_reduce (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
+
+ /* reduce modulo P */
+ if ((err = redux (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
goto LBL_MU;
}
}
@@ -112,7 +125,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
goto LBL_MU;
}
- if ((err = mp_reduce (&M[x], P, &mu)) != MP_OKAY) {
+ if ((err = redux (&M[x], P, &mu)) != MP_OKAY) {
goto LBL_MU;
}
}
@@ -161,7 +174,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
goto LBL_RES;
}
- if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
+ if ((err = redux (&res, P, &mu)) != MP_OKAY) {
goto LBL_RES;
}
continue;
@@ -178,7 +191,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
goto LBL_RES;
}
- if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
+ if ((err = redux (&res, P, &mu)) != MP_OKAY) {
goto LBL_RES;
}
}
@@ -187,7 +200,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
goto LBL_RES;
}
- if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
+ if ((err = redux (&res, P, &mu)) != MP_OKAY) {
goto LBL_RES;
}
@@ -205,7 +218,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
goto LBL_RES;
}
- if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
+ if ((err = redux (&res, P, &mu)) != MP_OKAY) {
goto LBL_RES;
}
@@ -215,7 +228,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
goto LBL_RES;
}
- if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
+ if ((err = redux (&res, P, &mu)) != MP_OKAY) {
goto LBL_RES;
}
}