diff --git a/synedrion/src/cggmp21/sigma/fac.rs b/synedrion/src/cggmp21/sigma/fac.rs index 6968e38f..49e90455 100644 --- a/synedrion/src/cggmp21/sigma/fac.rs +++ b/synedrion/src/cggmp21/sigma/fac.rs @@ -111,12 +111,18 @@ impl FacProof

{ let p_wide = sk0.p_wide_signed(); - let hat_sigma = sigma - (p_wide * &nu).to_public().to_wide(); + let hat_sigma = sigma + .checked_sub(&(p_wide * &nu).to_public().to_wide()) + .expect("doesn't overflow by construction"); let z1 = (alpha + (p * e).to_wide()).to_public(); let z2 = (beta + (q * e).to_wide()).to_public(); let omega1 = (x + mu * e_wide).to_public(); let omega2 = (nu * e_wide + y).to_public(); - let v = (r + (hat_sigma * e_wide.to_wide())).to_public(); + let v = (r + + (hat_sigma + .checked_mul(&e_wide.to_wide()) + .expect("doesn't overflow by construction"))) + .to_public(); Self { e, diff --git a/synedrion/src/uint/public_signed.rs b/synedrion/src/uint/public_signed.rs index be80de29..356ca1c9 100644 --- a/synedrion/src/uint/public_signed.rs +++ b/synedrion/src/uint/public_signed.rs @@ -1,5 +1,5 @@ use alloc::{boxed::Box, format, string::String}; -use core::ops::{Mul, Neg, Sub}; +use core::ops::Neg; use crypto_bigint::{Bounded, Encoding, Integer, NonZero}; use digest::XofReader; @@ -142,7 +142,7 @@ where self.abs() <= T::one() << bound_bits } - fn checked_sub(&self, rhs: &Self) -> Option { + pub fn checked_sub(&self, rhs: &Self) -> Option { let bound = core::cmp::max(self.bound, rhs.bound) + 1; if bound < T::BITS { Some(Self { @@ -158,7 +158,7 @@ where /// use [`Signed::mul_wide`] if widening is desired. /// Note: when multiplying two [`PublicSigned`], the bound on the result /// is equal to the sum of the bounds of the operands. - fn checked_mul(&self, rhs: &Self) -> Option { + pub fn checked_mul(&self, rhs: &Self) -> Option { let bound = self.bound + rhs.bound; if bound < T::BITS { Some(Self { @@ -229,27 +229,3 @@ where PublicSigned::neg(&self) } } - -impl Sub> for PublicSigned -where - T: Integer + Bounded, -{ - type Output = PublicSigned; - - fn sub(self, rhs: PublicSigned) -> Self::Output { - self.checked_sub(&rhs) - .expect("the calling code ensured the bound is not overflown") - } -} - -impl Mul> for PublicSigned -where - T: Integer + Bounded, -{ - type Output = PublicSigned; - - fn mul(self, rhs: PublicSigned) -> Self::Output { - self.checked_mul(&rhs) - .expect("the calling code ensured the bound is not overflown") - } -}