summaryrefslogtreecommitdiffhomepage
path: root/libtommath
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2011-03-18 14:31:07 +0000
committerMatt Johnston <matt@ucc.asn.au>2011-03-18 14:31:07 +0000
commit9a007c30d47dad0eb052cd83c45c84b7b2320dce (patch)
treea3c71d34db4d2b66c293014685709ba03635be15 /libtommath
parent8a545a0d0467ce01d974ec7da0a7bd4ca316fab8 (diff)
Use mp_init_size() to avoid some mp_grow()s
--HG-- extra : convert_revision : 94b7dd79a8e970e9641d4e655b3db48190ac2531
Diffstat (limited to 'libtommath')
-rw-r--r--libtommath/bn_mp_exptmod_fast.c6
-rw-r--r--libtommath/bn_mp_init_copy.c2
-rw-r--r--libtommath/bn_mp_mod.c2
-rw-r--r--libtommath/bn_mp_mulmod.c2
4 files changed, 6 insertions, 6 deletions
diff --git a/libtommath/bn_mp_exptmod_fast.c b/libtommath/bn_mp_exptmod_fast.c
index 32f8f16..47669f9 100644
--- a/libtommath/bn_mp_exptmod_fast.c
+++ b/libtommath/bn_mp_exptmod_fast.c
@@ -67,13 +67,13 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode
/* 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 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode
}
/* setup result */
- if ((err = mp_init (&res)) != MP_OKAY) {
+ if ((err = mp_init_size (&res, P->alloc)) != MP_OKAY) {
goto LBL_M;
}
diff --git a/libtommath/bn_mp_init_copy.c b/libtommath/bn_mp_init_copy.c
index 8e7329c..1fca6a1 100644
--- a/libtommath/bn_mp_init_copy.c
+++ b/libtommath/bn_mp_init_copy.c
@@ -20,7 +20,7 @@ int mp_init_copy (mp_int * a, mp_int * b)
{
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 --git a/libtommath/bn_mp_mod.c b/libtommath/bn_mp_mod.c
index be1f36d..87c8b0a 100644
--- a/libtommath/bn_mp_mod.c
+++ b/libtommath/bn_mp_mod.c
@@ -22,7 +22,7 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c)
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 --git a/libtommath/bn_mp_mulmod.c b/libtommath/bn_mp_mulmod.c
index 46818b6..24c9749 100644
--- a/libtommath/bn_mp_mulmod.c
+++ b/libtommath/bn_mp_mulmod.c
@@ -21,7 +21,7 @@ int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
int res;
mp_int t;
- if ((res = mp_init (&t)) != MP_OKAY) {
+ if ((res = mp_init_size (&t, c->used)) != MP_OKAY) {
return res;
}