Update milagro_bls to new release (#1183)

* Update milagro_bls to new release

Signed-off-by: Kirk Baird <baird.k@outlook.com>

* Tidy up fake cryptos

Signed-off-by: Kirk Baird <baird.k@outlook.com>

* move SecretHash to bls and put plaintext back

Signed-off-by: Kirk Baird <baird.k@outlook.com>
This commit is contained in:
Kirk Baird
2020-05-29 14:39:33 +10:00
committed by GitHub
parent 08e6b4961d
commit dceab5e6ea
26 changed files with 182 additions and 132 deletions

View File

@@ -11,6 +11,7 @@ rust-crypto = "0.2.36"
zeroize = { version = "1.0.0", features = ["zeroize_derive"] }
num-bigint-dig = { version = "0.6.0", features = ["zeroize"] }
ring = "0.16.9"
bls = { path = "../bls" }
[dev-dependencies]
hex = "0.3"

View File

@@ -1,6 +1,4 @@
use crate::{
lamport_secret_key::LamportSecretKey, secret_bytes::SecretBytes, secret_hash::SecretHash,
};
use crate::{lamport_secret_key::LamportSecretKey, secret_bytes::SecretBytes, SecretHash};
use crypto::{digest::Digest, sha2::Sha256};
use num_bigint_dig::BigUint;
use ring::hkdf::{KeyType, Prk, Salt, HKDF_SHA256};

View File

@@ -3,7 +3,9 @@
mod derived_key;
mod lamport_secret_key;
mod plain_text;
mod secret_bytes;
mod secret_hash;
pub use bls::SecretHash;
pub use derived_key::DerivedKey;
pub use plain_text::PlainText;

View File

@@ -0,0 +1,40 @@
use zeroize::Zeroize;
/// Provides wrapper around `Vec<u8>` that implements `Zeroize`.
#[derive(Zeroize, Clone, PartialEq)]
#[zeroize(drop)]
pub struct PlainText(Vec<u8>);
impl PlainText {
/// Instantiate self with `len` zeros.
pub fn zero(len: usize) -> Self {
Self(vec![0; len])
}
/// The byte-length of `self`
pub fn len(&self) -> usize {
self.0.len()
}
/// Returns a reference to the underlying bytes.
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
/// Returns a mutable reference to the underlying bytes.
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
&mut self.0
}
}
impl From<Vec<u8>> for PlainText {
fn from(vec: Vec<u8>) -> Self {
Self(vec)
}
}
impl AsRef<[u8]> for PlainText {
fn as_ref(&self) -> &[u8] {
&self.0
}
}

View File

@@ -1,24 +0,0 @@
use crate::derived_key::HASH_SIZE;
use zeroize::Zeroize;
/// Provides a wrapper around a `[u8; HASH_SIZE]` that implements `Zeroize` on `Drop`.
#[derive(Zeroize)]
#[zeroize(drop)]
pub struct SecretHash([u8; HASH_SIZE]);
impl SecretHash {
/// Instantiates `Self` with all zeros.
pub fn zero() -> Self {
Self([0; HASH_SIZE])
}
/// Returns a reference to the underlying bytes.
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
/// Returns a mutable reference to the underlying bytes.
pub fn as_mut_bytes(&mut self) -> &mut [u8] {
&mut self.0
}
}