changeset 608:4fbf9a7556ed

Use mp_init_size() to avoid some mp_grow()s
author Matt Johnston <matt@ucc.asn.au>
date Fri, 18 Mar 2011 14:31:07 +0000
parents aa2f51a6b81d
children 306a907d23e7
files libtommath/bn_mp_exptmod_fast.c libtommath/bn_mp_init_copy.c libtommath/bn_mp_mod.c libtommath/bn_mp_mulmod.c
diffstat 4 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;
   }
 
--- 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);
--- 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;
   }
 
--- 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;
   }