diff options
Diffstat (limited to 'mpi/mpi-mod.c')
-rw-r--r-- | mpi/mpi-mod.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/mpi/mpi-mod.c b/mpi/mpi-mod.c index 795826e7..3d6248b2 100644 --- a/mpi/mpi-mod.c +++ b/mpi/mpi-mod.c @@ -111,7 +111,7 @@ _gcry_mpi_barrett_free (mpi_barrett_t ctx) _gcry_mpi_barrett_init must have been called to do the precalculations. CTX is the context created by this precalculation and also conveys M. If the Barret reduction could no be done a - starightforward reduction method is used. + straightforward reduction method is used. We assume that these conditions are met: Input: x =(x_2k-1 ...x_0)_b @@ -126,6 +126,7 @@ _gcry_mpi_mod_barrett (gcry_mpi_t r, gcry_mpi_t x, mpi_barrett_t ctx) gcry_mpi_t y = ctx->y; gcry_mpi_t r1 = ctx->r1; gcry_mpi_t r2 = ctx->r2; + int sign; mpi_normalize (x); if (mpi_get_nlimbs (x) > 2*k ) @@ -134,6 +135,9 @@ _gcry_mpi_mod_barrett (gcry_mpi_t r, gcry_mpi_t x, mpi_barrett_t ctx) return; } + sign = x->sign; + x->sign = 0; + /* 1. q1 = floor( x / b^k-1) * q2 = q1 * y * q3 = floor( q2 / b^k+1 ) @@ -172,6 +176,7 @@ _gcry_mpi_mod_barrett (gcry_mpi_t r, gcry_mpi_t x, mpi_barrett_t ctx) while ( mpi_cmp( r, m ) >= 0 ) mpi_sub ( r, r, m ); + x->sign = sign; } |