in crypto/src/gcd.rs [138:163]
fn check_many_mod_inv_extended_gcd() {
let mut rng = rand::thread_rng();
for _ in 0..1000 {
let mut x = rng.gen_biguint(2048);
let mut y = rng.gen_biguint(2048);
if y > x {
mem::swap(&mut x, &mut y);
}
let (a, b, g) = extended_binary_gcd(&x, &y);
assert_eq!(g, x.gcd(&y));
assert_eq!(
a * x.to_bigint().unwrap() + b * y.to_bigint().unwrap(),
g.to_bigint().unwrap()
);
let t = mod_inverse(&x, &y);
if t.is_some() {
let v = (x.to_bigint().unwrap() * t.clone().unwrap()) % y.to_bigint().unwrap();
assert_eq!(v.is_one(), true);
}
}
}