diff mbox

libtommath: condition fast_s_mp_mul_digs() on LTM_FAST

Message ID 1363101529-14451-1-git-send-email-pizza@shaftnet.org
State Accepted
Commit de718493b408a30ee3c11f8ce0c226ec14389643
Headers show

Commit Message

Solomon Peachy March 12, 2013, 3:18 p.m. UTC
This function uses ~1.7kB of stack, and since there's a slower alternative,
wrap it with LTM_FAST.

Signed-off-by: Solomon Peachy <pizza@shaftnet.org>
---
 src/tls/libtommath.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Jouni Malinen March 16, 2013, 10:02 a.m. UTC | #1
On Tue, Mar 12, 2013 at 11:18:49AM -0400, Solomon Peachy wrote:
> This function uses ~1.7kB of stack, and since there's a slower alternative,
> wrap it with LTM_FAST.

Thanks, applied.

> diff --git a/src/tls/libtommath.c b/src/tls/libtommath.c
> +#define BN_FAST_S_MP_MUL_DIGS_C

> +#ifdef FAST_S_MP_MUL_DIGS_C
>  static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
> +#endif

Though, I added "BN_" here to make this build with LTM_FAST.
diff mbox

Patch

diff --git a/src/tls/libtommath.c b/src/tls/libtommath.c
index 741b442..89845ab 100644
--- a/src/tls/libtommath.c
+++ b/src/tls/libtommath.c
@@ -42,6 +42,9 @@ 
 /* Include faster sqr at the cost of about 0.5 kB in code */
 #define BN_FAST_S_MP_SQR_C
 
+/* About 0.25 kB of code, but ~1.7kB of stack space! */
+#define BN_FAST_S_MP_MUL_DIGS_C
+
 #else /* LTM_FAST */
 
 #define BN_MP_DIV_SMALL
@@ -139,7 +142,9 @@  static int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
 static int s_mp_sqr(mp_int * a, mp_int * b);
 static int s_mp_mul_high_digs(mp_int * a, mp_int * b, mp_int * c, int digs);
 
+#ifdef FAST_S_MP_MUL_DIGS_C
 static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
+#endif
 
 #ifdef BN_MP_INIT_MULTI_C
 static int mp_init_multi(mp_int *mp, ...);
@@ -2339,12 +2344,14 @@  static int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
   mp_word r;
   mp_digit tmpx, *tmpt, *tmpy;
 
+#ifdef BN_FAST_S_MP_MUL_DIGS_C
   /* can we use the fast multiplier? */
   if (((digs) < MP_WARRAY) &&
       MIN (a->used, b->used) < 
           (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
     return fast_s_mp_mul_digs (a, b, c, digs);
   }
+#endif
 
   if ((res = mp_init_size (&t, digs)) != MP_OKAY) {
     return res;
@@ -2397,6 +2404,7 @@  static int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
 }
 
 
+#ifdef BN_FAST_S_MP_MUL_DIGS_C
 /* Fast (comba) multiplier
  *
  * This is the fast column-array [comba] multiplier.  It is 
@@ -2482,6 +2490,7 @@  static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
   mp_clamp (c);
   return MP_OKAY;
 }
+#endif /* BN_FAST_S_MP_MUL_DIGS_C */
 
 
 /* init an mp_init for a given size */