1 /* $NetBSD: bn_mp_mul.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
14 * The library is free for all purposes without any express
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
20 /* high level multiplication (handles sign) */
21 int mp_mul (mp_int
* a
, mp_int
* b
, mp_int
* c
)
24 neg
= (a
->sign
== b
->sign
) ? MP_ZPOS
: MP_NEG
;
27 #ifdef BN_MP_TOOM_MUL_C
28 if (MIN (a
->used
, b
->used
) >= TOOM_MUL_CUTOFF
) {
29 res
= mp_toom_mul(a
, b
, c
);
32 #ifdef BN_MP_KARATSUBA_MUL_C
34 if (MIN (a
->used
, b
->used
) >= KARATSUBA_MUL_CUTOFF
) {
35 res
= mp_karatsuba_mul (a
, b
, c
);
39 /* can we use the fast multiplier?
41 * The fast multiplier can be used if the output will
42 * have less than MP_WARRAY digits and the number of
43 * digits won't affect carry propagation
45 int digs
= a
->used
+ b
->used
+ 1;
47 #ifdef BN_FAST_S_MP_MUL_DIGS_C
48 if ((digs
< MP_WARRAY
) &&
49 MIN(a
->used
, b
->used
) <=
50 (1 << ((CHAR_BIT
* sizeof (mp_word
)) - (2 * DIGIT_BIT
)))) {
51 res
= fast_s_mp_mul_digs (a
, b
, c
, digs
);
54 #ifdef BN_S_MP_MUL_DIGS_C
55 res
= s_mp_mul (a
, b
, c
); /* uses s_mp_mul_digs */
61 c
->sign
= (c
->used
> 0) ? neg
: MP_ZPOS
;
66 /* Source: /cvs/libtom/libtommath/bn_mp_mul.c,v */
68 /* Date: 2006/12/28 01:25:13 */