mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Add debug_assert that Scalar::batch_invert inputs are nonzero
This commit is contained in:
parent
0e7d872ad0
commit
b48d568f47
1 changed files with 12 additions and 0 deletions
|
|
@ -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"))]
|
||||
|
|
|
|||
Loading…
Reference in a new issue