Skip to content

Commit 91faf6a

Browse files
committed
Do the same with negation
1 parent dbd22fa commit 91faf6a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/field/crypto_bigint_const_monty.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ impl<Mod: Params<LIMBS>, const LIMBS: usize> Neg for ConstMontyField<Mod, LIMBS>
187187
type Output = Self;
188188

189189
#[inline(always)]
190-
fn neg(self) -> Self::Output {
191-
Self(self.0.neg())
190+
fn neg(mut self) -> Self::Output {
191+
*self.0.as_montgomery_mut() = self
192+
.0
193+
.as_montgomery()
194+
.neg_mod(Mod::PARAMS.modulus().as_nz_ref());
195+
self
192196
}
193197
}
194198

src/field/crypto_bigint_monty.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ impl<const LIMBS: usize> Hash for MontyField<LIMBS> {
133133
impl<const LIMBS: usize> Neg for MontyField<LIMBS> {
134134
type Output = Self;
135135

136-
fn neg(self) -> Self::Output {
137-
Self(self.0.neg())
136+
fn neg(mut self) -> Self::Output {
137+
*self.0.as_montgomery_mut() = self
138+
.0
139+
.as_montgomery()
140+
.neg_mod(self.0.params().modulus().as_nz_ref());
141+
self
138142
}
139143
}
140144

0 commit comments

Comments
 (0)