Skip to content

Commit

Permalink
Merge c515cf7 into 38f98ff
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Jul 9, 2020
2 parents 38f98ff + c515cf7 commit 932a00d
Show file tree
Hide file tree
Showing 43 changed files with 366 additions and 368 deletions.
246 changes: 128 additions & 118 deletions Cargo.lock

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions Cargo.toml
@@ -1,5 +1,5 @@
[package]
name = "rusty_secrets"
name = "rusty_secrets"
version = "0.2.3-pre"
authors = [
"Frederic Jacobs <github@fredericjacobs.com>",
Expand All @@ -8,62 +8,62 @@ authors = [
"Noah Vesely <fowlslegs@riseup.net>",
"sellibitze"
]
description = "Implementation of threshold Shamir's secret sharing in the Rust programming language."
homepage = "https://github.com/freedomofpress/RustySecrets"
license = "BSD-3-Clause"
readme = "README.md"
build = "build.rs"

exclude = ["Cargo.lock"]
description = "Implementation of threshold Shamir's secret sharing in the Rust programming language."
homepage = "https://github.com/freedomofpress/RustySecrets"
license = "BSD-3-Clause"
readme = "README.md"
build = "build.rs"
edition = "2018"
exclude = ["Cargo.lock"]

[badges]
travis-ci = { repository = "SpinResearch/RustySecrets", branch = "master" }
coveralls = { repository = "SpinResearch/RustySecrets", branch = "master", service = "github" }

[features]
default = []
dss = []
default = ["dss"]
dss = []

[dependencies]
base64 = "0.9.0"
rand = "^0.4.2"
ring = "^0.12"
merkle_sigs = "^1.4"
protobuf = ">= 1.4, < 1.6"
base64 = "0.12"
rand = "0.7"
ring = "0.12"
merkle_sigs = "1.4"
protobuf = ">= 1.4, < 1.6"
rand_chacha = "0.2.2"

[dependencies.error-chain]
version = "0.11.0"
version = "0.12.0"
default-features = false

[dev-dependencies]
itertools = "^0.7"
quickcheck = "^0.4"
flate2 = "^0.2"
rand = "^0.4.2"
itertools = "0.9"
quickcheck = "0.9"
flate2 = "0.2"

[profile.bench]
opt-level = 3
debug = false
rpath = false
lto = true
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
codegen-units = 1

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
codegen-units = 1

[package.metadata.release]
sign-commit = true
upload-doc = true
doc-branch = "gh-pages"
pre-release-commit-message = "Release version {{version}}."
pro-release-commit-message = "Start next development iteration {{version}}."
tag-prefix = "v"
tag-message = "Release version {{version}}."
doc-commit-message = "Update documentation."
dev-version-ext = "pre"
sign-commit = true
sign-tag = true
pre-release-commit-message = "Release version {{version}}."
post-release-commit-message = "Start next development iteration {{version}}."
tag-prefix = "v"
tag-message = "Release version {{version}}."
doc-commit-message = "Update documentation."
dev-version-ext = "pre"
6 changes: 3 additions & 3 deletions benches/ss1.rs
Expand Up @@ -8,9 +8,9 @@ extern crate test;
mod shared;

mod ss1 {
use super::shared;

use rusty_secrets::dss::ss1;
use shared;
use test::{black_box, Bencher};

macro_rules! bench_generate {
Expand All @@ -26,7 +26,8 @@ mod ss1 {
&secret,
ss1::Reproducibility::reproducible(),
&None,
).unwrap();
)
.unwrap();
black_box(shares);
});
}
Expand Down Expand Up @@ -56,5 +57,4 @@ mod ss1 {

bench_generate!(generate_1kb_10_25, 10, 25, secret_1kb);
bench_recover!(recover_1kb_10_25, 10, 25, secret_1kb);

}
3 changes: 1 addition & 2 deletions benches/sss.rs
Expand Up @@ -7,9 +7,9 @@ extern crate test;
mod shared;

mod sss {
use super::shared;

use rusty_secrets::sss;
use shared;
use test::{black_box, Bencher};

macro_rules! bench_generate {
Expand Down Expand Up @@ -53,5 +53,4 @@ mod sss {

bench_generate!(generate_1kb_10_25_signed, 10, 25, secret_1kb, true);
bench_recover!(recover_1kb_10_25_signed, 10, 25, secret_1kb, true);

}
3 changes: 1 addition & 2 deletions benches/thss.rs
Expand Up @@ -8,9 +8,9 @@ extern crate test;
mod shared;

mod thss {
use super::shared;

use rusty_secrets::dss::thss;
use shared;
use test::{black_box, Bencher};

macro_rules! bench_generate {
Expand Down Expand Up @@ -48,5 +48,4 @@ mod thss {

bench_generate!(generate_1kb_10_25, 10, 25, secret_1kb);
bench_recover!(recover_1kb_10_25, 10, 25, secret_1kb);

}
3 changes: 1 addition & 2 deletions benches/wrapped_secrets.rs
Expand Up @@ -7,9 +7,9 @@ extern crate test;
mod shared;

mod wrapped_secrets {
use super::shared;

use rusty_secrets::wrapped_secrets;
use shared;
use test::{black_box, Bencher};

macro_rules! bench_generate {
Expand Down Expand Up @@ -55,5 +55,4 @@ mod wrapped_secrets {

bench_generate!(generate_1kb_10_25_signed, 10, 25, secret_1kb, true);
bench_recover!(recover_1kb_10_25_signed, 10, 25, secret_1kb, true);

}
21 changes: 11 additions & 10 deletions build.rs
Expand Up @@ -25,6 +25,7 @@ struct Tables {
log: [u8; 256],
}

#[allow(clippy::match_wild_err_arm)]
fn generate_tables(mut file: &File) {
let mut tabs = Tables {
exp: [0; 256],
Expand All @@ -46,24 +47,24 @@ fn generate_tables(mut file: &File) {
}

fn farray(array: [u8; 256], f: &mut fmt::Formatter) -> fmt::Result {
for (index, value) in array.into_iter().enumerate() {
try!(write!(f, "{}", value));
for (index, value) in array.iter().enumerate() {
write!(f, "{}", value)?;
if index != array.len() - 1 {
try!(write!(f, ","));
write!(f, ",")?;
}
}
Ok(())
}

impl fmt::Display for Tables {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "Tables {{\n"));
try!(write!(f, " exp: ["));
try!(farray(self.exp, f));
try!(write!(f, "],\n"));
try!(write!(f, " log: ["));
try!(farray(self.log, f));
try!(write!(f, "]\n"));
writeln!(f, "Tables {{")?;
write!(f, " exp: [")?;
farray(self.exp, f)?;
writeln!(f, "],")?;
write!(f, " log: [")?;
farray(self.log, f)?;
writeln!(f, "]")?;
write!(f, "}};")
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
@@ -1 +1 @@
1.24.1
1.44.1
9 changes: 3 additions & 6 deletions src/dss/format.rs
@@ -1,10 +1,7 @@
use std::error::Error;

use base64;
use protobuf::{self, Message};

use errors::*;
use proto::dss::ShareProto;
use crate::errors::*;
use crate::proto::dss::ShareProto;

const BASE64_CONFIG: base64::Config = base64::STANDARD_NO_PAD;

Expand All @@ -24,7 +21,7 @@ pub(crate) fn parse_share_protobuf(raw: &str) -> Result<ShareProto> {
let share_proto = protobuf::parse_from_bytes::<ShareProto>(data.as_slice()).map_err(|e| {
ErrorKind::ShareParsingError(format!(
"Protobuf decoding of data block failed with error: {} .",
e.description()
e
))
})?;

Expand Down
6 changes: 2 additions & 4 deletions src/dss/random.rs
@@ -1,6 +1,4 @@
use std;

use errors::*;
use crate::errors::*;

use ring::error::Unspecified;
use ring::rand::SecureRandom;
Expand All @@ -23,7 +21,7 @@ pub(crate) fn random_bytes_count(threshold: u8, message_size: usize) -> usize {
}

/// Attempts to read `count` random bytes from the given secure random generator.
pub(crate) fn random_bytes(random: &SecureRandom, count: usize) -> Result<Vec<u8>> {
pub(crate) fn random_bytes(random: &dyn SecureRandom, count: usize) -> Result<Vec<u8>> {
if count == 0 {
return Ok(Vec::new());
}
Expand Down
8 changes: 3 additions & 5 deletions src/dss/ss1/mod.rs
Expand Up @@ -21,7 +21,7 @@
//!
//! - *New Directions in Secret Sharing* (TODO: Full reference)

use errors::*;
use crate::errors::*;

mod serialize;

Expand All @@ -32,7 +32,7 @@ mod scheme;
pub use self::scheme::Reproducibility;
use self::scheme::SS1;

use dss::AccessStructure;
use crate::dss::AccessStructure;

/// Performs threshold k-out-of-n deterministic secret sharing.
///
Expand Down Expand Up @@ -185,10 +185,8 @@ mod tests {
let seed = vec![1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16u8];
let shares_1 =
split_secret(7, 10, &secret, Reproducibility::seeded(seed.clone()), &None).unwrap();
let shares_2 =
split_secret(7, 10, &secret, Reproducibility::seeded(seed.clone()), &None).unwrap();
let shares_2 = split_secret(7, 10, &secret, Reproducibility::seeded(seed), &None).unwrap();

assert_eq!(shares_1, shares_2);
}

}
33 changes: 14 additions & 19 deletions src/dss/ss1/scheme.rs
@@ -1,18 +1,18 @@
use std::collections::HashSet;

use rand::{ChaChaRng, Rng, SeedableRng};
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;
use ring::digest::{Context, SHA256};
use ring::rand::{SecureRandom, SystemRandom};
use ring::{hkdf, hmac};

use super::share::*;
use dss::random::{random_bytes_count, FixedRandom, MAX_MESSAGE_SIZE};
use dss::thss::{MetaData, ThSS};
use dss::utils;
use dss::{thss, AccessStructure};
use errors::*;
use share::validation::{validate_share_count, validate_shares};
use vol_hash::VOLHash;
use crate::dss::random::{random_bytes_count, FixedRandom, MAX_MESSAGE_SIZE};
use crate::dss::thss::{MetaData, ThSS};
use crate::dss::{thss, AccessStructure};
use crate::errors::*;
use crate::share::validation::{validate_share_count, validate_shares};
use crate::vol_hash::VOLHash;

/// We bound the message size at about 16MB to avoid overflow in `random_bytes_count`.
/// Moreover, given the current performances, it is almost unpractical to run
Expand Down Expand Up @@ -175,7 +175,7 @@ impl SS1 {
shares_count: share.shares_count,
data: share.data,
hash: hash.to_vec(),
metadata: share.metadata.clone(),
metadata: share.metadata,
})
.collect();

Expand All @@ -198,14 +198,14 @@ impl SS1 {
}
Reproducibility::Reproducible => {
let seed = self.generate_seed(DEFAULT_PRESEED, secret, metadata);
let mut rng = ChaChaRng::from_seed(&seed);
let mut rng = ChaCha20Rng::from_seed(seed);
let mut result = vec![0u8; self.random_padding_len];
rng.fill_bytes(result.as_mut_slice());
Ok(result)
}
Reproducibility::Seeded(preseed) => {
let seed = self.generate_seed(&preseed, secret, metadata);
let mut rng = ChaChaRng::from_seed(&seed);
let mut rng = ChaCha20Rng::from_seed(seed);
let mut result = vec![0u8; self.random_padding_len];
rng.fill_bytes(result.as_mut_slice());
Ok(result)
Expand All @@ -222,7 +222,7 @@ impl SS1 {
preseed: &[u8],
secret: &[u8],
metadata: &Option<MetaData>,
) -> Vec<u32> {
) -> [u8; 32] {
let mut ctx = Context::new(&SHA256);
ctx.update(preseed);
ctx.update(secret);
Expand All @@ -232,14 +232,9 @@ impl SS1 {
let preseed_hash = ctx.finish();

let salt = hmac::SigningKey::new(&SHA256, &[]);
let mut seed_bytes = vec![0u8; 32];
let mut seed_bytes = [0u8; 32];
hkdf::extract_and_expand(&salt, preseed_hash.as_ref(), &[], &mut seed_bytes);

// We can safely call `utils::slice_u8_to_slice_u32` because
// the `digest` produced with `SHA256` is 256 bits long, as is
// `seed_bytes`, and the latter can thus be represented both as a
// slice of 32 bytes or as a slice of 8 32-bit words.
utils::slice_u8_to_slice_u32(&seed_bytes).to_vec()
seed_bytes
}

/// Recover the secret from the given set of shares
Expand Down
8 changes: 4 additions & 4 deletions src/dss/ss1/serialize.rs
@@ -1,8 +1,8 @@
use super::{MetaData, Share};
use dss::format::{format_share_protobuf, parse_share_protobuf};
use dss::utils::{btreemap_to_hashmap, hashmap_to_btreemap};
use errors::*;
use proto::dss::{MetaDataProto, ShareProto};
use crate::dss::format::{format_share_protobuf, parse_share_protobuf};
use crate::dss::utils::{btreemap_to_hashmap, hashmap_to_btreemap};
use crate::errors::*;
use crate::proto::dss::{MetaDataProto, ShareProto};

pub(crate) fn share_to_string(share: Share) -> String {
let proto = share_to_protobuf(share);
Expand Down

0 comments on commit 932a00d

Please sign in to comment.