Clear 'Poly' and 'BivarPoly' coeffs on drop.

This commit is contained in:
Peter van Nostrand 2018-07-16 08:28:36 -04:00 committed by Vladimir Komendantskiy
parent 77a5829c1d
commit bd10494d5d
1 changed files with 25 additions and 0 deletions

25
poly.rs
View File

@ -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<B: Borrow<Self>> ops::MulAssign<B> 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<R: Rng>(degree: usize, rng: &mut R) -> Self {
@ -327,6 +340,18 @@ pub struct BivarPoly {
coeff: Vec<Fr>,
}
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<R: Rng>(degree: usize, rng: &mut R) -> Self {