libtommath: Condition fast_s_mp_mul_digs() on LTM_FAST

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>
This commit is contained in:
Solomon Peachy 2013-03-16 12:01:03 +02:00 committed by Jouni Malinen
parent d963f03772
commit de718493b4

View file

@ -42,6 +42,9 @@
/* Include faster sqr at the cost of about 0.5 kB in code */ /* Include faster sqr at the cost of about 0.5 kB in code */
#define BN_FAST_S_MP_SQR_C #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 */ #else /* LTM_FAST */
#define BN_MP_DIV_SMALL #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_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); static int s_mp_mul_high_digs(mp_int * a, mp_int * b, mp_int * c, int digs);
#ifdef BN_FAST_S_MP_MUL_DIGS_C
static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs); 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 #ifdef BN_MP_INIT_MULTI_C
static int mp_init_multi(mp_int *mp, ...); 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_word r;
mp_digit tmpx, *tmpt, *tmpy; mp_digit tmpx, *tmpt, *tmpy;
#ifdef BN_FAST_S_MP_MUL_DIGS_C
/* can we use the fast multiplier? */ /* can we use the fast multiplier? */
if (((digs) < MP_WARRAY) && if (((digs) < MP_WARRAY) &&
MIN (a->used, b->used) < MIN (a->used, b->used) <
(1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
return fast_s_mp_mul_digs (a, b, c, digs); return fast_s_mp_mul_digs (a, b, c, digs);
} }
#endif
if ((res = mp_init_size (&t, digs)) != MP_OKAY) { if ((res = mp_init_size (&t, digs)) != MP_OKAY) {
return res; 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 /* Fast (comba) multiplier
* *
* This is the fast column-array [comba] multiplier. It is * 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); mp_clamp (c);
return MP_OKAY; return MP_OKAY;
} }
#endif /* BN_FAST_S_MP_MUL_DIGS_C */
/* init an mp_init for a given size */ /* init an mp_init for a given size */