aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mpi/mpi-pow.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mpi/mpi-pow.c')
-rw-r--r--lib/mpi/mpi-pow.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/mpi/mpi-pow.c b/lib/mpi/mpi-pow.c
index 82b19e4f1189..2fd7a46d55ec 100644
--- a/lib/mpi/mpi-pow.c
+++ b/lib/mpi/mpi-pow.c
@@ -24,6 +24,7 @@
24int mpi_powm(MPI res, MPI base, MPI exp, MPI mod) 24int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
25{ 25{
26 mpi_ptr_t mp_marker = NULL, bp_marker = NULL, ep_marker = NULL; 26 mpi_ptr_t mp_marker = NULL, bp_marker = NULL, ep_marker = NULL;
27 struct karatsuba_ctx karactx = {};
27 mpi_ptr_t xp_marker = NULL; 28 mpi_ptr_t xp_marker = NULL;
28 mpi_ptr_t tspace = NULL; 29 mpi_ptr_t tspace = NULL;
29 mpi_ptr_t rp, ep, mp, bp; 30 mpi_ptr_t rp, ep, mp, bp;
@@ -150,13 +151,11 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
150 int c; 151 int c;
151 mpi_limb_t e; 152 mpi_limb_t e;
152 mpi_limb_t carry_limb; 153 mpi_limb_t carry_limb;
153 struct karatsuba_ctx karactx;
154 154
155 xp = xp_marker = mpi_alloc_limb_space(2 * (msize + 1)); 155 xp = xp_marker = mpi_alloc_limb_space(2 * (msize + 1));
156 if (!xp) 156 if (!xp)
157 goto enomem; 157 goto enomem;
158 158
159 memset(&karactx, 0, sizeof karactx);
160 negative_result = (ep[0] & 1) && base->sign; 159 negative_result = (ep[0] & 1) && base->sign;
161 160
162 i = esize - 1; 161 i = esize - 1;
@@ -281,8 +280,6 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
281 if (mod_shift_cnt) 280 if (mod_shift_cnt)
282 mpihelp_rshift(rp, rp, rsize, mod_shift_cnt); 281 mpihelp_rshift(rp, rp, rsize, mod_shift_cnt);
283 MPN_NORMALIZE(rp, rsize); 282 MPN_NORMALIZE(rp, rsize);
284
285 mpihelp_release_karatsuba_ctx(&karactx);
286 } 283 }
287 284
288 if (negative_result && rsize) { 285 if (negative_result && rsize) {
@@ -299,6 +296,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
299leave: 296leave:
300 rc = 0; 297 rc = 0;
301enomem: 298enomem:
299 mpihelp_release_karatsuba_ctx(&karactx);
302 if (assign_rp) 300 if (assign_rp)
303 mpi_assign_limb_space(res, rp, size); 301 mpi_assign_limb_space(res, rp, size);
304 if (mp_marker) 302 if (mp_marker)