INNER CODE UNIT · Rust
modulo_invert
ZenGo-X/curv · src/arithmetic/mod.rs:299
fn modulo_invert(a: u32, m: u32) {
let (a, m) = (BigInt::from(a), BigInt::from(m));
let inv = BigInt::mod_inv(&a, &m).unwrap();
assert!(BigInt::zero() <= inv && inv < m);
let one = BigInt::mod_mul(&a, &inv, &m);
assert_eq!(one, BigInt::one());
}
#[test]
#[should_panic]
fn mod_pow_panics_if_exp_is_negative() {
BigInt::mod_pow(&BigInt::from(3), &(-BigInt::one()), &BigInt::from(7));
}
const PRIMES: &[&str] = &[
"2",
"3",
"5",