Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/field/crypto_bigint_const_monty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ impl<Mod: Params<LIMBS>, const LIMBS: usize> Neg for ConstMontyField<Mod, LIMBS>
type Output = Self;

#[inline(always)]
fn neg(self) -> Self::Output {
Self(self.0.neg())
fn neg(mut self) -> Self::Output {
*self.0.as_montgomery_mut() = self
.0
.as_montgomery()
.neg_mod(Mod::PARAMS.modulus().as_nz_ref());
self
}
}

Expand Down Expand Up @@ -291,14 +295,20 @@ impl_op_assign_boilerplate!(DivAssign, div_assign);
impl<Mod: Params<LIMBS>, const LIMBS: usize> AddAssign<&Self> for ConstMontyField<Mod, LIMBS> {
#[inline(always)]
fn add_assign(&mut self, rhs: &Self) {
self.0.add_assign(&rhs.0);
*self.0.as_montgomery_mut() = self
.0
.as_montgomery()
.add_mod(rhs.0.as_montgomery(), Mod::PARAMS.modulus().as_nz_ref());
}
}

impl<Mod: Params<LIMBS>, const LIMBS: usize> SubAssign<&Self> for ConstMontyField<Mod, LIMBS> {
#[inline(always)]
fn sub_assign(&mut self, rhs: &Self) {
self.0.sub_assign(&rhs.0);
*self.0.as_montgomery_mut() = self
.0
.as_montgomery()
.sub_mod(rhs.0.as_montgomery(), Mod::PARAMS.modulus().as_nz_ref());
}
}

Expand Down
18 changes: 14 additions & 4 deletions src/field/crypto_bigint_monty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ impl<const LIMBS: usize> Hash for MontyField<LIMBS> {
impl<const LIMBS: usize> Neg for MontyField<LIMBS> {
type Output = Self;

fn neg(self) -> Self::Output {
Self(self.0.neg())
fn neg(mut self) -> Self::Output {
*self.0.as_montgomery_mut() = self
.0
.as_montgomery()
.neg_mod(self.0.params().modulus().as_nz_ref());
self
}
}

Expand Down Expand Up @@ -243,14 +247,20 @@ impl_op_assign_boilerplate!(DivAssign, div_assign);
impl<const LIMBS: usize> AddAssign<&Self> for MontyField<LIMBS> {
#[inline(always)]
fn add_assign(&mut self, rhs: &Self) {
self.0.add_assign(&rhs.0);
*self.0.as_montgomery_mut() = self
.0
.as_montgomery()
.add_mod(rhs.0.as_montgomery(), self.0.params().modulus().as_nz_ref());
}
}

impl<const LIMBS: usize> SubAssign<&Self> for MontyField<LIMBS> {
#[inline(always)]
fn sub_assign(&mut self, rhs: &Self) {
self.0.sub_assign(&rhs.0);
*self.0.as_montgomery_mut() = self
.0
.as_montgomery()
.sub_mod(rhs.0.as_montgomery(), self.0.params().modulus().as_nz_ref());
}
}

Expand Down