# HG changeset patch # User Matt Johnston # Date 1300458667 0 # Node ID 4fbf9a7556edb725cf59b6b62b4c38ee458e7d9c # Parent aa2f51a6b81d33de5e9898a7f27c792a173d9b26 Use mp_init_size() to avoid some mp_grow()s diff -r aa2f51a6b81d -r 4fbf9a7556ed libtommath/bn_mp_exptmod_fast.c --- a/libtommath/bn_mp_exptmod_fast.c Wed Mar 02 13:23:27 2011 +0000 +++ b/libtommath/bn_mp_exptmod_fast.c Fri Mar 18 14:31:07 2011 +0000 @@ -67,13 +67,13 @@ /* init M array */ /* init first cell */ - if ((err = mp_init(&M[1])) != MP_OKAY) { + if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) { return err; } /* now init the second half of the array */ for (x = 1<<(winsize-1); x < (1 << winsize); x++) { - if ((err = mp_init(&M[x])) != MP_OKAY) { + if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) { for (y = 1<<(winsize-1); y < x; y++) { mp_clear (&M[y]); } @@ -133,7 +133,7 @@ } /* setup result */ - if ((err = mp_init (&res)) != MP_OKAY) { + if ((err = mp_init_size (&res, P->alloc)) != MP_OKAY) { goto LBL_M; } diff -r aa2f51a6b81d -r 4fbf9a7556ed libtommath/bn_mp_init_copy.c --- a/libtommath/bn_mp_init_copy.c Wed Mar 02 13:23:27 2011 +0000 +++ b/libtommath/bn_mp_init_copy.c Fri Mar 18 14:31:07 2011 +0000 @@ -20,7 +20,7 @@ { int res; - if ((res = mp_init (a)) != MP_OKAY) { + if ((res = mp_init_size (a, b->used)) != MP_OKAY) { return res; } return mp_copy (b, a); diff -r aa2f51a6b81d -r 4fbf9a7556ed libtommath/bn_mp_mod.c --- a/libtommath/bn_mp_mod.c Wed Mar 02 13:23:27 2011 +0000 +++ b/libtommath/bn_mp_mod.c Fri Mar 18 14:31:07 2011 +0000 @@ -22,7 +22,7 @@ mp_int t; int res; - if ((res = mp_init (&t)) != MP_OKAY) { + if ((res = mp_init_size (&t, b->used)) != MP_OKAY) { return res; } diff -r aa2f51a6b81d -r 4fbf9a7556ed libtommath/bn_mp_mulmod.c --- a/libtommath/bn_mp_mulmod.c Wed Mar 02 13:23:27 2011 +0000 +++ b/libtommath/bn_mp_mulmod.c Fri Mar 18 14:31:07 2011 +0000 @@ -21,7 +21,7 @@ int res; mp_int t; - if ((res = mp_init (&t)) != MP_OKAY) { + if ((res = mp_init_size (&t, c->used)) != MP_OKAY) { return res; }