|
1 | 1 | //! [`BoxedUint`] multiplication operations.
|
2 | 2 |
|
3 |
| -use crate::{uint::mul::mul_limbs, BoxedUint, CheckedMul, Limb, WideningMul, Wrapping, Zero}; |
| 3 | +use crate::{ |
| 4 | + uint::mul::mul_limbs, BoxedUint, CheckedMul, Limb, WideningMul, Wrapping, WrappingMul, Zero, |
| 5 | +}; |
4 | 6 | use core::ops::{Mul, MulAssign};
|
5 | 7 | use subtle::{Choice, CtOption};
|
6 | 8 |
|
@@ -51,21 +53,36 @@ impl CheckedMul<&BoxedUint> for BoxedUint {
|
51 | 53 | }
|
52 | 54 | }
|
53 | 55 |
|
54 |
| -impl WideningMul for BoxedUint { |
55 |
| - type Output = Self; |
| 56 | +impl Mul<BoxedUint> for BoxedUint { |
| 57 | + type Output = BoxedUint; |
56 | 58 |
|
57 |
| - #[inline] |
58 |
| - fn widening_mul(&self, rhs: BoxedUint) -> Self { |
59 |
| - self.mul(&rhs) |
| 59 | + fn mul(self, rhs: BoxedUint) -> Self { |
| 60 | + BoxedUint::mul(&self, &rhs) |
60 | 61 | }
|
61 | 62 | }
|
62 | 63 |
|
63 |
| -impl WideningMul<&BoxedUint> for BoxedUint { |
64 |
| - type Output = Self; |
| 64 | +impl Mul<&BoxedUint> for BoxedUint { |
| 65 | + type Output = BoxedUint; |
65 | 66 |
|
66 |
| - #[inline] |
67 |
| - fn widening_mul(&self, rhs: &BoxedUint) -> Self { |
68 |
| - self.mul(rhs) |
| 67 | + fn mul(self, rhs: &BoxedUint) -> Self { |
| 68 | + BoxedUint::mul(&self, rhs) |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +impl Mul<BoxedUint> for &BoxedUint { |
| 73 | + type Output = BoxedUint; |
| 74 | + |
| 75 | + fn mul(self, rhs: BoxedUint) -> Self::Output { |
| 76 | + BoxedUint::mul(self, &rhs) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +impl Mul<&BoxedUint> for &BoxedUint { |
| 81 | + type Output = BoxedUint; |
| 82 | + |
| 83 | + fn mul(self, rhs: &BoxedUint) -> Self::Output { |
| 84 | + self.checked_mul(rhs) |
| 85 | + .expect("attempted to multiply with overflow") |
69 | 86 | }
|
70 | 87 | }
|
71 | 88 |
|
@@ -113,6 +130,30 @@ impl MulAssign<&Wrapping<BoxedUint>> for Wrapping<BoxedUint> {
|
113 | 130 | }
|
114 | 131 | }
|
115 | 132 |
|
| 133 | +impl WideningMul for BoxedUint { |
| 134 | + type Output = Self; |
| 135 | + |
| 136 | + #[inline] |
| 137 | + fn widening_mul(&self, rhs: BoxedUint) -> Self { |
| 138 | + self.mul(&rhs) |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +impl WideningMul<&BoxedUint> for BoxedUint { |
| 143 | + type Output = Self; |
| 144 | + |
| 145 | + #[inline] |
| 146 | + fn widening_mul(&self, rhs: &BoxedUint) -> Self { |
| 147 | + self.mul(rhs) |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +impl WrappingMul for BoxedUint { |
| 152 | + fn wrapping_mul(&self, v: &Self) -> Self { |
| 153 | + self.wrapping_mul(v) |
| 154 | + } |
| 155 | +} |
| 156 | + |
116 | 157 | #[cfg(test)]
|
117 | 158 | mod tests {
|
118 | 159 | use crate::BoxedUint;
|
|
0 commit comments