3
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
4
/* SPDX-License-Identifier: Unlicense */
5
5
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
+
6
15
/* reduces x mod m, assumes 0 < x < m**2, mu is
7
16
* precomputed via mp_reduce_setup.
8
17
* 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)
26
35
if ((err = mp_mul (& q , mu , & q )) != MP_OKAY ) {
27
36
goto LBL_ERR ;
28
37
}
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
- }
33
38
} else if (MP_HAS (S_MP_MUL_HIGH_COMBA )) {
34
39
if ((err = s_mp_mul_high_comba (& q , mu , & q , um )) != MP_OKAY ) {
35
40
goto LBL_ERR ;
36
41
}
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
+ }
37
46
} else {
38
47
err = MP_VAL ;
39
48
goto LBL_ERR ;
@@ -48,7 +57,7 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
48
57
}
49
58
50
59
/* 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 ) {
52
61
goto LBL_ERR ;
53
62
}
54
63
0 commit comments