Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / bn_mp_mul.c
blob732a12dbe37728306cd0b2e2d19738515f39f126
1 /* $NetBSD: bn_mp_mul.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
3 #include <tommath.h>
4 #ifdef BN_MP_MUL_C
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
15 * guarantee it works.
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)
23 int res, neg;
24 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
26 /* use Toom-Cook? */
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);
30 } else
31 #endif
32 #ifdef BN_MP_KARATSUBA_MUL_C
33 /* use Karatsuba? */
34 if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) {
35 res = mp_karatsuba_mul (a, b, c);
36 } else
37 #endif
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);
52 } else
53 #endif
54 #ifdef BN_S_MP_MUL_DIGS_C
55 res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */
56 #else
57 res = MP_VAL;
58 #endif
61 c->sign = (c->used > 0) ? neg : MP_ZPOS;
62 return res;
64 #endif
66 /* Source: /cvs/libtom/libtommath/bn_mp_mul.c,v */
67 /* Revision: 1.4 */
68 /* Date: 2006/12/28 01:25:13 */