33/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44/* SPDX-License-Identifier: Unlicense */
55
6+ static mp_err s_mul (const mp_int * a , const mp_int * b , mp_int * c , int digs )
7+ {
8+ if (MP_HAS (S_MP_MUL_COMBA )
9+ && (MP_MIN (a -> used , b -> used ) < MP_MAX_COMBA )) {
10+ return s_mp_mul_comba (a , b , c , digs );
11+ }
12+ return s_mp_mul (a , b , c , digs );
13+ }
14+
615/* reduces x mod m, assumes 0 < x < m**2, mu is
716 * precomputed via mp_reduce_setup.
817 * From HAC pp.604 Algorithm 14.42
@@ -26,14 +35,14 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
2635 if ((err = mp_mul (& q , mu , & q )) != MP_OKAY ) {
2736 goto LBL_ERR ;
2837 }
29- } else if (MP_HAS (S_MP_MUL_HIGH )) {
30- if ((err = s_mp_mul_high (& q , mu , & q , um )) != MP_OKAY ) {
31- goto LBL_ERR ;
32- }
3338 } else if (MP_HAS (S_MP_MUL_HIGH_COMBA )) {
3439 if ((err = s_mp_mul_high_comba (& q , mu , & q , um )) != MP_OKAY ) {
3540 goto LBL_ERR ;
3641 }
42+ } else if (MP_HAS (S_MP_MUL_HIGH )) {
43+ if ((err = s_mp_mul_high (& q , mu , & q , um )) != MP_OKAY ) {
44+ goto LBL_ERR ;
45+ }
3746 } else {
3847 err = MP_VAL ;
3948 goto LBL_ERR ;
@@ -48,7 +57,7 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
4857 }
4958
5059 /* q = q * m mod b**(k+1), quick (no division) */
51- if ((err = s_mp_mul (& q , m , & q , um + 1 )) != MP_OKAY ) {
60+ if ((err = s_mul (& q , m , & q , um + 1 )) != MP_OKAY ) {
5261 goto LBL_ERR ;
5362 }
5463
0 commit comments