Skip to content

Commit

Permalink
Generic InvMod: add Rhs param and associated Output
Browse files Browse the repository at this point in the history
As needed for #737.

This uses a shape similar to the `MulMod` trait.
  • Loading branch information
tarcieri committed Jan 20, 2025
1 parent 65bffd1 commit 934c72e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,12 @@ pub trait MulMod<Rhs = Self> {
}

/// Compute `1 / self mod p`.
pub trait InvMod: Sized {
pub trait InvMod<Rhs = Self>: Sized {
/// Output type.
type Output;

/// Compute `1 / self mod p`.
fn inv_mod(&self, p: &Self) -> CtOption<Self>;
fn inv_mod(&self, p: &Rhs) -> CtOption<Self::Output>;
}

/// Checked addition.
Expand Down
2 changes: 2 additions & 0 deletions src/uint/boxed/inv_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ impl BoxedUint {
}

impl InvMod for BoxedUint {
type Output = Self;

fn inv_mod(&self, modulus: &Self) -> CtOption<Self> {
self.inv_mod(modulus)
}
Expand Down
2 changes: 2 additions & 0 deletions src/uint/inv_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ impl<const LIMBS: usize, const UNSAT_LIMBS: usize> InvMod for Uint<LIMBS>
where
Odd<Self>: PrecomputeInverter<Inverter = SafeGcdInverter<LIMBS, UNSAT_LIMBS>>,
{
type Output = Self;

fn inv_mod(&self, modulus: &Self) -> CtOption<Self> {
self.inv_mod(modulus).into()
}
Expand Down

0 comments on commit 934c72e

Please sign in to comment.