|
21 | 21 | /// If the number was invertible, the second element of the tuple is the truthy value,
|
22 | 22 | /// otherwise it is the falsy value (in which case the first element's value is unspecified).
|
23 | 23 | pub const fn inv(&self) -> ConstCtOption<Self> {
|
24 |
| - let inverter = <Odd<Uint<SAT_LIMBS>> as PrecomputeInverter>::Inverter::new( |
25 |
| - &self.params.modulus, |
26 |
| - &self.params.r2, |
27 |
| - ); |
28 |
| - |
| 24 | + let inverter = self.params.inverter(); |
29 | 25 | let maybe_inverse = inverter.inv(&self.montgomery_form);
|
30 | 26 | let (inverse, inverse_is_some) = maybe_inverse.components_ref();
|
31 | 27 |
|
|
46 | 42 | /// This version is variable-time with respect to the value of `self`, but constant-time with
|
47 | 43 | /// respect to `self`'s `params`.
|
48 | 44 | pub const fn inv_vartime(&self) -> ConstCtOption<Self> {
|
49 |
| - let inverter = <Odd<Uint<SAT_LIMBS>> as PrecomputeInverter>::Inverter::new( |
50 |
| - &self.params.modulus, |
51 |
| - &self.params.r2, |
52 |
| - ); |
53 |
| - |
| 45 | + let inverter = self.params.inverter(); |
54 | 46 | let maybe_inverse = inverter.inv_vartime(&self.montgomery_form);
|
55 | 47 | let (inverse, inverse_is_some) = maybe_inverse.components_ref();
|
56 | 48 |
|
|
81 | 73 | }
|
82 | 74 | }
|
83 | 75 |
|
| 76 | +impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> MontyParams<SAT_LIMBS> |
| 77 | +where |
| 78 | + Odd<Uint<SAT_LIMBS>>: PrecomputeInverter< |
| 79 | + Inverter = SafeGcdInverter<SAT_LIMBS, UNSAT_LIMBS>, |
| 80 | + Output = Uint<SAT_LIMBS>, |
| 81 | + >, |
| 82 | +{ |
| 83 | + /// Create a modular inverter for the modulus of these params. |
| 84 | + // TODO(tarcieri): make `pub`? |
| 85 | + const fn inverter(&self) -> SafeGcdInverter<SAT_LIMBS, UNSAT_LIMBS> { |
| 86 | + SafeGcdInverter::new(&self.modulus, &self.r2) |
| 87 | + } |
| 88 | +} |
| 89 | + |
84 | 90 | impl<const LIMBS: usize> PrecomputeInverter for MontyParams<LIMBS>
|
85 | 91 | where
|
86 | 92 | Odd<Uint<LIMBS>>:
|
|
0 commit comments