Merge pull request #140 from poanetwork/clear-secret-key-set

Clear 'SecretKeySet' on drop.
This commit is contained in:
Andreas Fackler 2018-07-16 16:01:21 +02:00 committed by GitHub
commit 4b35a8666a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -14,7 +14,7 @@ before_install:
- rustup toolchain install ${RUST_NEXT}
- rustup component add --toolchain=${RUST_NEXT} rustfmt-preview clippy-preview
# Some symlinking is still necessary for clippy to function properly.
- ln -s ${HOME}/.rustup/toolchains/${RUST_NEXT}-x86_64-unknown-linux-gnu/bin/clippy-driver ${HOME}/.rustup/toolchains/${RUST_NEXT}-x86_64-unknown-linux-gnu/bin/cargo-clippy $HOME/.cargo/bin/
- ln -sf ${HOME}/.rustup/toolchains/${RUST_NEXT}-x86_64-unknown-linux-gnu/bin/clippy-driver ${HOME}/.rustup/toolchains/${RUST_NEXT}-x86_64-unknown-linux-gnu/bin/cargo-clippy $HOME/.cargo/bin/
env:
global:
- RUST_BACKTRACE=1

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 {