feat: add zeroize feature

This commit is contained in:
dignifiedquire 2019-03-16 11:38:05 +01:00
parent 666cdc6f2c
commit 5fbee1da4d
4 changed files with 33 additions and 4 deletions

View File

@ -44,15 +44,16 @@ version = "0.5"
default-features = false
features = ["std"]
[dependencies.zeroize]
version = "0.5"
optional = true
[dependencies.serde]
optional = true
version = "1.0"
default-features = false
features = ["std"]
[dev-dependencies.serde_test]
version = "1.0"
[dependencies.lazy_static]
version = "1.2.0"
@ -63,9 +64,12 @@ version = "1.2.7"
criterion = "0.2"
rand_chacha = "0.1"
[dev-dependencies.serde_test]
version = "1.0"
[features]
default = ["std", "i128", "u64_digit"]
i128 = ["num-integer/i128", "num-traits/i128"]
std = ["num-integer/std", "num-traits/std", "smallvec/std"]
u64_digit = []
prime = ["rand"]
prime = ["rand"]

View File

@ -17,6 +17,9 @@ use std::{i64, u64};
#[cfg(feature = "serde")]
use serde;
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
use integer::{Integer, Roots};
use num_traits::{
CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Num, One, Pow, Signed,
@ -119,6 +122,15 @@ pub struct BigInt {
pub(crate) data: BigUint,
}
#[cfg(feature = "zeroize")]
impl Zeroize for BigInt {
fn zeroize(&mut self) {
// TODO: Figure out how to better clear the sign.
self.sign = Sign::NoSign;
self.data.zeroize();
}
}
/// Return the magnitude of a `BigInt`.
///
/// This is in a private module, pseudo pub(crate)

View File

@ -18,6 +18,9 @@ use std::{u64, u8};
#[cfg(feature = "serde")]
use serde;
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
use integer::{Integer, Roots};
use num_traits::{
CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Float, FromPrimitive, Num, One, Pow,
@ -50,6 +53,13 @@ pub struct BigUint {
pub(crate) data: SmallVec<[BigDigit; VEC_SIZE]>,
}
#[cfg(feature = "zeroize")]
impl Zeroize for BigUint {
fn zeroize(&mut self) {
self.data.zeroize();
}
}
impl PartialEq for BigUint {
#[inline]
fn eq(&self, other: &BigUint) -> bool {

View File

@ -90,6 +90,9 @@ extern crate rand;
#[cfg(feature = "serde")]
extern crate serde;
#[cfg(feature = "zeroize")]
extern crate zeroize;
#[macro_use]
extern crate smallvec;