2 #ifdef BN_S_MP_MUL_HIGH_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 /* multiplies |a| * |b| and does not compute the lower digs digits
19 * [meant to get the higher part of the product]
22 s_mp_mul_high_digs (mp_int
* a
, mp_int
* b
, mp_int
* c
, int digs
)
25 int res
, pa
, pb
, ix
, iy
;
28 mp_digit tmpx
, *tmpt
, *tmpy
;
30 /* can we use the fast multiplier? */
31 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
32 if (((a
->used
+ b
->used
+ 1) < MP_WARRAY
)
33 && MIN (a
->used
, b
->used
) < (1 << ((CHAR_BIT
* sizeof (mp_word
)) - (2 * DIGIT_BIT
)))) {
34 return fast_s_mp_mul_high_digs (a
, b
, c
, digs
);
38 if ((res
= mp_init_size (&t
, a
->used
+ b
->used
+ 1)) != MP_OKAY
) {
41 t
.used
= a
->used
+ b
->used
+ 1;
45 for (ix
= 0; ix
< pa
; ix
++) {
49 /* left hand side of A[ix] * B[iy] */
52 /* alias to the address of where the digits will be stored */
55 /* alias for where to read the right hand side from */
56 tmpy
= b
->dp
+ (digs
- ix
);
58 for (iy
= digs
- ix
; iy
< pb
; iy
++) {
59 /* calculate the double precision result */
60 r
= ((mp_word
)*tmpt
) +
61 ((mp_word
)tmpx
) * ((mp_word
)*tmpy
++) +
64 /* get the lower part */
65 *tmpt
++ = (mp_digit
) (r
& ((mp_word
) MP_MASK
));
68 u
= (mp_digit
) (r
>> ((mp_word
) DIGIT_BIT
));
79 /* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
80 /* $Revision: 1.4 $ */
81 /* $Date: 2006/12/28 01:25:13 $ */