1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* multiplies |a| * |b| and does not compute the lower digs digits
7 * [meant to get the higher part of the product]
9 mp_err
s_mp_mul_high(const mp_int
*a
, const mp_int
*b
, mp_int
*c
, int digs
)
19 /* can we use the fast multiplier? */
20 if (MP_HAS(S_MP_MUL_HIGH_COMBA
)
21 && ((a
->used
+ b
->used
+ 1) < MP_WARRAY
)
22 && (MP_MIN(a
->used
, b
->used
) < MP_MAX_COMBA
)) {
23 return s_mp_mul_high_comba(a
, b
, c
, digs
);
26 if ((err
= mp_init_size(&t
, a
->used
+ b
->used
+ 1)) != MP_OKAY
) {
29 t
.used
= a
->used
+ b
->used
+ 1;
33 for (ix
= 0; ix
< pa
; ix
++) {
37 for (iy
= digs
- ix
; iy
< pb
; iy
++) {
38 /* calculate the double precision result */
39 mp_word r
= (mp_word
)t
.dp
[ix
+ iy
] +
40 ((mp_word
)a
->dp
[ix
] * (mp_word
)b
->dp
[iy
]) +
43 /* get the lower part */
44 t
.dp
[ix
+ iy
] = (mp_digit
)(r
& (mp_word
)MP_MASK
);
47 u
= (mp_digit
)(r
>> (mp_word
)MP_DIGIT_BIT
);