2
#ifdef BN_FAST_S_MP_MUL_DIGS_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis
5
* LibTomMath is a library that provides multiple-precision
6
* integer arithmetic as well as number theoretic functionality.
8
* The library was designed directly after the MPI library by
9
* Michael Fromberger but has been written from scratch with
10
* additional optimizations in place.
12
* The library is free for all purposes without any express
15
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18
/* Fast (comba) multiplier
20
* This is the fast column-array [comba] multiplier. It is
21
* designed to compute the columns of the product first
22
* then handle the carries afterwards. This has the effect
23
* of making the nested loops that compute the columns very
24
* simple and schedulable on super-scalar processors.
26
* This has been modified to produce a variable number of
27
* digits of output so if say only a half-product is required
28
* you don't have to compute the upper half (a feature
29
* required for fast Barrett reduction).
31
* Based on Algorithm 14.12 on pp.595 of HAC.
34
int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
36
int olduse, res, pa, ix, iz;
37
mp_digit W[MP_WARRAY];
40
/* grow the destination as required */
41
if (c->alloc < digs) {
42
if ((res = mp_grow (c, digs)) != MP_OKAY) {
47
/* number of output digits to produce */
48
pa = MIN(digs, a->used + b->used);
52
for (ix = 0; ix < pa; ix++) {
55
mp_digit *tmpx, *tmpy;
57
/* get offsets into the two bignums */
58
ty = MIN(b->used-1, ix);
61
/* setup temp aliases */
65
/* this is the number of times the loop will iterrate, essentially
66
while (tx++ < a->used && ty-- >= 0) { ... }
68
iy = MIN(a->used-tx, ty+1);
71
for (iz = 0; iz < iy; ++iz) {
72
_W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
77
W[ix] = ((mp_digit)_W) & MP_MASK;
80
_W = _W >> ((mp_word)DIGIT_BIT);
88
register mp_digit *tmpc;
90
for (ix = 0; ix < pa+1; ix++) {
91
/* now extract the previous digit [below the carry] */
95
/* clear unused digits [that existed in the old copy of c] */
96
for (; ix < olduse; ix++) {
105
/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */
106
/* $Revision: 1.8 $ */
107
/* $Date: 2006/12/28 01:25:13 $ */