diff --git a/.changelog/5928.trivial.md b/.changelog/5928.trivial.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/secret-sharing/src/poly/univariate.rs b/secret-sharing/src/poly/univariate.rs index 307caa7499e..7bd5ab3bab1 100644 --- a/secret-sharing/src/poly/univariate.rs +++ b/secret-sharing/src/poly/univariate.rs @@ -238,7 +238,7 @@ where impl AddAssign for Polynomial where - F: PrimeField, + F: PrimeField + Zeroize, { #[inline] fn add_assign(&mut self, rhs: Polynomial) { @@ -248,9 +248,16 @@ where impl AddAssign<&Polynomial> for Polynomial where - F: PrimeField, + F: PrimeField + Zeroize, { fn add_assign(&mut self, rhs: &Polynomial) { + if self.a.capacity() < rhs.a.len() { + let mut a = Vec::with_capacity(rhs.a.len()); + a.extend_from_slice(&self.a); + self.a.zeroize(); + self.a = a; + } + let min_len = min(self.a.len(), rhs.a.len()); for i in 0..min_len { @@ -321,7 +328,7 @@ where impl SubAssign for Polynomial where - F: PrimeField, + F: PrimeField + Zeroize, { #[inline] fn sub_assign(&mut self, rhs: Polynomial) { @@ -331,9 +338,16 @@ where impl SubAssign<&Polynomial> for Polynomial where - F: PrimeField, + F: PrimeField + Zeroize, { fn sub_assign(&mut self, rhs: &Polynomial) { + if self.a.capacity() < rhs.a.len() { + let mut a = Vec::with_capacity(rhs.a.len()); + a.extend_from_slice(&self.a); + self.a.zeroize(); + self.a = a; + } + let min_len = min(self.a.len(), rhs.a.len()); for i in 0..min_len { @@ -510,7 +524,7 @@ where impl Sum for Polynomial where - F: PrimeField, + F: PrimeField + Zeroize, { fn sum>>(iter: I) -> Polynomial { let mut sum = Polynomial::zero(0); @@ -521,7 +535,7 @@ where impl<'a, F> Sum<&'a Polynomial> for Polynomial where - F: PrimeField, + F: PrimeField + Zeroize, { fn sum>>(iter: I) -> Polynomial { let mut sum = Polynomial::zero(0);