Skip to content

Commit 7bad5f0

Browse files
committed
Add tests from #1282
1 parent a4d1da2 commit 7bad5f0

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎src/uint/boxed/mul_mod.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn mac_by_limb(a: &UintRef, b: &UintRef, c: Limb, carry: Limb) -> (BoxedUint, Li
9898

9999
#[cfg(all(test, feature = "rand_core"))]
100100
mod tests {
101-
use crate::{BoxedUint, ConcatenatingMul, Limb, NonZero, Random, RandomMod};
101+
use crate::{BoxedUint, ConcatenatingMul, Limb, NonZero, Random, RandomMod, Resize};
102102
use rand_core::SeedableRng;
103103

104104
#[test]
@@ -153,4 +153,18 @@ mod tests {
153153
}
154154
}
155155
}
156+
157+
#[test]
158+
fn mul_mod_special_zero_c_is_wrapping_multiplication() {
159+
for bits in [Limb::BITS, 2 * Limb::BITS, 4 * Limb::BITS] {
160+
let a = BoxedUint::from(0x1234_5678u32).resize(bits);
161+
let b = BoxedUint::from(0xfedc_ba91u32).resize(bits);
162+
163+
assert_eq!(
164+
a.mul_mod_special(&b, Limb::ZERO),
165+
a.wrapping_mul(&b),
166+
"c = 0 represents the power-of-two modulus"
167+
);
168+
}
169+
}
156170
}

‎src/uint/mul_mod.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,25 @@ mod tests {
168168
test_size::<16>();
169169
}
170170
}
171+
172+
#[test]
173+
fn mul_mod_special_zero_c_is_wrapping_multiplication() {
174+
let a = Uint::<1>::from_u32(0x1234_5678);
175+
let b = Uint::<1>::from_u32(0xfedc_ba91);
176+
177+
assert_eq!(
178+
a.mul_mod_special(&b, Limb::ZERO),
179+
a.wrapping_mul(&b),
180+
"c = 0 represents the power-of-two modulus"
181+
);
182+
183+
let a = Uint::<2>::from_u32(0x1234_5678);
184+
let b = Uint::<2>::from_u32(0xfedc_ba91);
185+
186+
assert_eq!(
187+
a.mul_mod_special(&b, Limb::ZERO),
188+
a.wrapping_mul(&b),
189+
"c = 0 represents the power-of-two modulus"
190+
);
191+
}
171192
}

0 commit comments

Comments
 (0)