diff --git a/src/dss/thss/encode.rs b/src/dss/thss/encode.rs index 2e11400..01fbc59 100644 --- a/src/dss/thss/encode.rs +++ b/src/dss/thss/encode.rs @@ -31,7 +31,7 @@ pub(crate) fn encode_secret_byte(m: u8, j: u8, poly: &Poly) -> u8 { let mut acc = Gf256::from_byte(m); for (l, &r) in poly.coeffs.iter().enumerate() { let s = Gf256::from_byte(j).pow(l as u8 + 1); - acc = acc + r * s; + acc += r * s; } acc.to_byte() } diff --git a/src/gf256.rs b/src/gf256.rs index e491146..23546d9 100644 --- a/src/gf256.rs +++ b/src/gf256.rs @@ -1,7 +1,7 @@ //! This module provides the Gf256 type which is used to represent //! elements of a finite field with 256 elements. -use std::ops::{Add, Div, Mul, Neg, Sub}; +use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; include!(concat!(env!("OUT_DIR"), "/nothinghardcoded.rs")); @@ -74,6 +74,13 @@ impl Add for Gf256 { } } +impl AddAssign for Gf256 { + #[inline] + fn add_assign(&mut self, rhs: Gf256) { + *self = *self + rhs; + } +} + impl Sub for Gf256 { type Output = Gf256; #[inline] @@ -82,6 +89,13 @@ impl Sub for Gf256 { } } +impl SubAssign for Gf256 { + #[inline] + fn sub_assign(&mut self, rhs: Gf256) { + *self = *self - rhs; + } +} + impl Mul for Gf256 { type Output = Gf256; fn mul(self, rhs: Gf256) -> Gf256 { @@ -94,6 +108,12 @@ impl Mul for Gf256 { } } +impl MulAssign for Gf256 { + fn mul_assign(&mut self, rhs: Gf256) { + *self = *self * rhs; + } +} + impl Div for Gf256 { type Output = Gf256; fn div(self, rhs: Gf256) -> Gf256 { @@ -107,6 +127,12 @@ impl Div for Gf256 { } } +impl DivAssign for Gf256 { + fn div_assign(&mut self, rhs: Gf256) { + *self = *self / rhs; + } +} + impl Neg for Gf256 { type Output = Gf256; fn neg(self) -> Gf256 { diff --git a/src/lagrange.rs b/src/lagrange.rs index 9142372..50baf8b 100644 --- a/src/lagrange.rs +++ b/src/lagrange.rs @@ -15,10 +15,10 @@ pub(crate) fn interpolate_at(points: &[(u8, u8)]) -> u8 { let xj = Gf256::from_byte(raw_xj); let delta = xi - xj; assert_ne!(delta.poly, 0, "Duplicate shares"); - prod = prod * xj / delta; + prod *= xj / delta; } } - sum = sum + prod * yi; + sum += prod * yi; } sum.to_byte() } @@ -37,7 +37,7 @@ pub(crate) fn interpolate(points: &[(Gf256, Gf256)]) -> Poly { let mut prod = Gf256::one(); for &(x1, _) in points { if x != x1 { - prod = prod * (x - x1); + prod *= x - x1; let mut prec = Gf256::zero(); coeffs = coeffs diff --git a/src/poly.rs b/src/poly.rs index be8bf95..aaee0b5 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -21,7 +21,7 @@ impl Poly { let mut result = Gf256::zero(); for (i, c) in self.coeffs.iter().enumerate() { - result = result + *c * x.pow(i as u8); + result += *c * x.pow(i as u8); } result diff --git a/src/sss/encode.rs b/src/sss/encode.rs index 204e08c..d2729fb 100644 --- a/src/sss/encode.rs +++ b/src/sss/encode.rs @@ -9,8 +9,8 @@ pub(crate) fn encode_secret_byte(src: &[u8], n: u8, w: &mut W) -> io:: let mut fac = Gf256::one(); let mut acc = Gf256::zero(); for &coeff in src.iter() { - acc = acc + fac * Gf256::from_byte(coeff); - fac = fac * x; + acc += fac * Gf256::from_byte(coeff); + fac *= x; } w.write_all(&[acc.to_byte()])?; }