num_bigint_dig/traits.rs
1use crate::BigInt;
2
3/// Generic trait to implement modular inverse.
4pub trait ModInverse<R: Sized>: Sized {
5 type Output: Sized;
6
7 /// Function to calculate the [modular multiplicative
8 /// inverse](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse) of an integer *a* modulo *m*.
9 ///
10 /// TODO: references
11 /// Returns the modular inverse of `self`.
12 /// If none exists it returns `None`.
13 fn mod_inverse(self, m: R) -> Option<Self::Output>;
14}
15
16/// Generic trait to implement extended GCD.
17/// Calculates the extended eucledian algorithm.
18/// See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm for details.
19/// The returned values are
20/// - greatest common divisor (1)
21/// - Bezout coefficients (2)
22pub trait ExtendedGcd<R: Sized>: Sized {
23 fn extended_gcd(self, other: R) -> (BigInt, BigInt, BigInt);
24}