Add debug_assert that Scalar::batch_invert inputs are nonzero

This commit is contained in:
Henry de Valence 2018-03-22 11:31:14 -07:00
parent 0e7d872ad0
commit b48d568f47

View file

@ -464,6 +464,9 @@ impl Scalar {
tree[i] = UnpackedScalar::montgomery_mul(&tree[2*i], &tree[2*i+1]);
}
// tree[1] is zero iff any of the inputs are zero.
debug_assert!(tree[1].from_montgomery().pack() != Scalar::zero());
let allinv = tree[1].montgomery_invert();
for i in 0..inputs.len() {
@ -977,6 +980,15 @@ mod test {
let parsed: Scalar = serde_cbor::from_slice(&output).unwrap();
assert_eq!(parsed, X);
}
#[test]
#[should_panic]
fn batch_invert_with_a_zero_input_panics() {
let mut xs = vec![Scalar::one(); 16];
xs[3] = Scalar::zero();
// This should panic in debug mode.
Scalar::batch_invert(&mut xs);
}
}
#[cfg(all(test, feature = "bench"))]