diff --git a/poly.rs b/poly.rs index 427832e..c019ab8 100644 --- a/poly.rs +++ b/poly.rs @@ -18,6 +18,7 @@ use std::borrow::Borrow; use std::hash::{Hash, Hasher}; +use std::ptr::write_volatile; use std::{cmp, iter, ops}; use pairing::bls12_381::{Fr, FrRepr, G1, G1Affine}; @@ -123,6 +124,18 @@ impl> ops::MulAssign for Poly { } } +impl Drop for Poly { + fn drop(&mut self) { + let start = self.coeff.as_mut_ptr(); + unsafe { + for i in 0..self.coeff.len() { + let ptr = start.offset(i as isize); + write_volatile(ptr, Fr::zero()); + } + } + } +} + impl Poly { /// Creates a random polynomial. pub fn random(degree: usize, rng: &mut R) -> Self { @@ -327,6 +340,18 @@ pub struct BivarPoly { coeff: Vec, } +impl Drop for BivarPoly { + fn drop(&mut self) { + let start = self.coeff.as_mut_ptr(); + unsafe { + for i in 0..self.coeff.len() { + let ptr = start.offset(i as isize); + write_volatile(ptr, Fr::zero()); + } + } + } +} + impl BivarPoly { /// Creates a random polynomial. pub fn random(degree: usize, rng: &mut R) -> Self {