diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3a8d3f7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 7316468..236c55b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,6 @@ # Will have compiled files and executables /target/ -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock -Cargo.lock - # These are backup files generated by rustfmt **/*.rs.bk diff --git a/.travis.yml b/.travis.yml index 13be6b3..909ff02 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,38 +1,62 @@ - -sudo: required - language: rust +cache: + directories: + - $HOME/protobuf + - $HOME/.cargo + - $TRAVIS_BUILD_DIR/target rust: - stable - beta - - nightly matrix: + # Since this item is allowed to fail, don't wait for it's result to mark the + # build complete. + fast_finish: true allow_failures: - - rust: nightly + - env: NAME='nightly' + - env: NAME='kcov' + - env: NAME='rustfmt' + include: + - env: NAME='nightly' + rust: nightly + - env: NAME='rustfmt' + rust: nightly + before_script: + - rustup component add rustfmt-preview + - touch src/proto/version.rs + - touch src/proto/dss/metadata.rs src/proto/dss/secret.rs src/proto/dss/share.rs + - touch src/proto/wrapped/secret.rs src/proto/wrapped/share.rs + script: + - cargo fmt --all -- --check + - env: NAME='kcov' + sudo: required # travis-ci/travis-ci#9061 + before_script: + - cargo install cargo-update || echo "cargo-update already installed" + - cargo install cargo-kcov || echo "cargo-kcov already installed" + - cargo install-update -a + script: + - cargo kcov --print-install-kcov-sh | sh + - cargo update # Creates `Cargo.lock` needed by next command + - cargo kcov --verbose --features dss --coveralls -- --verify --exclude-pattern=/.cargo,/usr/lib,src/proto + addons: + apt: + packages: + - libcurl4-openssl-dev + - libdw-dev + - binutils-dev + - libiberty-dev + - zlib1g-dev env: global: - RUSTFLAGS="-C link-dead-code" -addons: - apt: - packages: - - libcurl4-openssl-dev - - libdw-dev - - cmake - - g++ - - pkg-config - - binutils-dev - - libiberty-dev - script: + - export PATH=$PATH:$HOME/protobuf/bin - cargo build --verbose --all-features - cargo test --verbose --all-features + - cargo doc --verbose --all-features -after_success: - - cargo install cargo-kcov - - cargo kcov --print-install-kcov-sh | sh - - cargo kcov --verbose --features dss --coveralls -- --verify --exclude-pattern=/.cargo,/usr/lib,src/proto - +before_install: + - bash install_protobuf.sh diff --git a/Cargo.toml b/Cargo.toml index 9baeef1..5ae3a7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = [ "Frederic Jacobs ", "Romain Ruetschi ", "Dylan Bourgeois ", + "Noah Vesely ", "sellibitze" ] description = "Implementation of threshold Shamir's secret sharing in the Rust programming language." @@ -13,6 +14,8 @@ license = "BSD-3-Clause" readme = "README.md" build = "build.rs" +exclude = ["Cargo.lock"] + [badges] travis-ci = { repository = "SpinResearch/RustySecrets", branch = "master" } coveralls = { repository = "SpinResearch/RustySecrets", branch = "master", service = "github" } @@ -23,10 +26,13 @@ dss = [] [dependencies] base64 = "0.9.0" -rand = "^0.3" +rand = "^0.4.2" ring = "^0.12" -merkle_sigs = "^1.4" -protobuf = "^1.4" +merkle_sigs = "1.5.0" +protobuf = "^2.0.2" + +[build-dependencies] +protoc-rust = "^2.0.2" [dependencies.error-chain] version = "0.11.0" @@ -36,6 +42,7 @@ default-features = false itertools = "^0.7" quickcheck = "^0.4" flate2 = "^0.2" +rand = "^0.4.2" [profile.bench] opt-level = 3 @@ -63,4 +70,3 @@ tag-prefix = "v" tag-message = "Release version {{version}}." doc-commit-message = "Update documentation." dev-version-ext = "pre" - diff --git a/LICENSE b/LICENSE index b2e6f8f..aab64d9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2016, Spin Research +Copyright (c) 2016-2018, Spin Research All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 4b6451f..e6a7a1b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ any security vulnerability in this code privately to anybody.** ## License -See [LICENSE](LICENSE). +RustySecrets is distributed under the BSD 3-Clause license. See the [LICENSE](LICENSE) file for more information. ## Vocabulary diff --git a/benches/ss1.rs b/benches/ss1.rs index 601e92f..f6e993a 100644 --- a/benches/ss1.rs +++ b/benches/ss1.rs @@ -1,5 +1,6 @@ #![cfg(test)] #![feature(test)] +#![cfg(feature = "dss")] extern crate rusty_secrets; extern crate test; @@ -9,29 +10,37 @@ mod shared; mod ss1 { use rusty_secrets::dss::ss1; - use test::{black_box, Bencher}; use shared; + use test::{black_box, Bencher}; macro_rules! bench_generate { - ($name:ident, $k:expr, $n:expr, $secret:ident) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); b.iter(move || { - let shares = ss1::split_secret($k, $n, &secret, ss1::Reproducibility::reproducible(), &None).unwrap(); + let shares = ss1::split_secret( + $k, + $n, + &secret, + ss1::Reproducibility::reproducible(), + &None, + ).unwrap(); black_box(shares); }); } - ) + }; } macro_rules! bench_recover { - ($name:ident, $k:expr, $n:expr, $secret:ident) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); - let all_shares = ss1::split_secret($k, $n, &secret, ss1::Reproducibility::reproducible(), &None).unwrap(); + let all_shares = + ss1::split_secret($k, $n, &secret, ss1::Reproducibility::reproducible(), &None) + .unwrap(); let shares = &all_shares.into_iter().take($k).collect::>().clone(); b.iter(|| { @@ -39,7 +48,7 @@ mod ss1 { black_box(result); }); } - ) + }; } bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb); diff --git a/benches/sss.rs b/benches/sss.rs index b48b6aa..65ead56 100644 --- a/benches/sss.rs +++ b/benches/sss.rs @@ -8,12 +8,12 @@ mod shared; mod sss { - use test::{black_box, Bencher}; use rusty_secrets::sss; use shared; + use test::{black_box, Bencher}; macro_rules! bench_generate { - ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); @@ -23,11 +23,11 @@ mod sss { black_box(shares); }); } - ) + }; } macro_rules! bench_recover { - ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); @@ -39,7 +39,7 @@ mod sss { black_box(result); }); } - ) + }; } bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb, false); diff --git a/benches/thss.rs b/benches/thss.rs index 95dc79c..c4dd97d 100644 --- a/benches/thss.rs +++ b/benches/thss.rs @@ -1,5 +1,6 @@ #![cfg(test)] #![feature(test)] +#![cfg(feature = "dss")] extern crate rusty_secrets; extern crate test; @@ -9,11 +10,11 @@ mod shared; mod thss { use rusty_secrets::dss::thss; - use test::{black_box, Bencher}; use shared; + use test::{black_box, Bencher}; macro_rules! bench_generate { - ($name:ident, $k:expr, $n:expr, $secret:ident) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); @@ -23,11 +24,11 @@ mod thss { black_box(shares); }); } - ) + }; } macro_rules! bench_recover { - ($name:ident, $k:expr, $n:expr, $secret:ident) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); @@ -39,7 +40,7 @@ mod thss { black_box(result); }); } - ) + }; } bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb); diff --git a/benches/wrapped_secrets.rs b/benches/wrapped_secrets.rs index 627f376..af57141 100644 --- a/benches/wrapped_secrets.rs +++ b/benches/wrapped_secrets.rs @@ -8,30 +8,32 @@ mod shared; mod wrapped_secrets { - use test::{black_box, Bencher}; use rusty_secrets::wrapped_secrets; use shared; + use test::{black_box, Bencher}; macro_rules! bench_generate { - ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); b.iter(move || { - let shares = wrapped_secrets::split_secret($k, $n, secret, None, $signed).unwrap(); + let shares = + wrapped_secrets::split_secret($k, $n, secret, None, $signed).unwrap(); black_box(shares); }); } - ) + }; } macro_rules! bench_recover { - ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => ( + ($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => { #[bench] fn $name(b: &mut Bencher) { let secret = shared::$secret(); - let all_shares = wrapped_secrets::split_secret($k, $n, &secret, None, $signed).unwrap(); + let all_shares = + wrapped_secrets::split_secret($k, $n, &secret, None, $signed).unwrap(); let shares = all_shares.into_iter().take($k).collect::>(); b.iter(|| { @@ -39,7 +41,7 @@ mod wrapped_secrets { black_box(result); }); } - ) + }; } bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb, false); diff --git a/build.rs b/build.rs index f1488f4..5b80827 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,10 @@ +extern crate protoc_rust; use std::env; +use std::fmt; use std::fs::File; use std::io::Write; -use std::path::Path; -use std::fmt; use std::num::Wrapping; +use std::path::Path; const POLY: u8 = 0x1D; @@ -68,8 +69,16 @@ impl fmt::Display for Tables { } } -#[allow(unused_must_use)] -fn main() { +fn build_protobuf<'a>(out_dir: &'a str, input: &'a [&'a str], includes: &'a [&'a str]) { + use self::protoc_rust::{run, Args}; + run(Args { + out_dir, + input, + includes, + }).expect("protoc"); +} + +fn generate_gf256_table() { let out_dir = env::var("OUT_DIR").unwrap(); let dest = Path::new(&out_dir).join("nothinghardcoded.rs"); @@ -78,8 +87,8 @@ fn main() { write!( f, "pub struct Tables {{ \ - pub exp: [u8; 256], \ - pub log: [u8; 256] \ + pub exp: [u8; 256], \ + pub log: [u8; 256] \ }} \ \ pub static TABLES: Tables = " @@ -87,3 +96,26 @@ fn main() { generate_tables(&f); } + +#[allow(unused_must_use)] +fn main() { + generate_gf256_table(); + build_protobuf("src/proto", &["protobuf/version.proto"], &[]); + build_protobuf( + "src/proto/dss", + &[ + "protobuf/dss/metadata.proto", + "protobuf/dss/secret.proto", + "protobuf/dss/share.proto", + ], + &["protobuf", "protobuf/dss"], + ); + build_protobuf( + "src/proto/wrapped", + &[ + "protobuf/wrapped/secret.proto", + "protobuf/wrapped/share.proto", + ], + &["protobuf", "protobuf/dss"], + ); +} diff --git a/install_protobuf.sh b/install_protobuf.sh new file mode 100644 index 0000000..0a1432a --- /dev/null +++ b/install_protobuf.sh @@ -0,0 +1,22 @@ +#!/usr/bin/bash +set -e + +check_protoc_version () { + version="libprotoc $1" + PROTOC="$HOME/protobuf/bin/protoc" + if [ -f $PROTOC ]; then + this_version=`$PROTOC --version` + return `[ "$version" = "$this_version" ]` + else + return 1 + fi +} + +if check_protoc_version '3.5.1'; then + echo protoc version 3.5.1 detected. + exit +fi + +wget https://github.com/google/protobuf/archive/v3.5.1.tar.gz +tar -xzvf v3.5.1.tar.gz +cd protobuf-3.5.1 && ./autogen.sh && ./configure --prefix=$HOME/protobuf && make && make install diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..f9e8384 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +1.24.1 diff --git a/src/dss/format.rs b/src/dss/format.rs index 70669b5..c4d0386 100644 --- a/src/dss/format.rs +++ b/src/dss/format.rs @@ -1,7 +1,7 @@ use std::error::Error; -use protobuf::{self, Message}; use base64; +use protobuf::{self, Message}; use errors::*; use proto::dss::ShareProto; diff --git a/src/dss/metadata.rs b/src/dss/metadata.rs index 86c3f92..fa11f24 100644 --- a/src/dss/metadata.rs +++ b/src/dss/metadata.rs @@ -1,5 +1,5 @@ -use std::collections::BTreeMap; use ring::digest; +use std::collections::BTreeMap; /// A share's public metadata. #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Default)] diff --git a/src/dss/mod.rs b/src/dss/mod.rs index ab45caa..f7739d2 100644 --- a/src/dss/mod.rs +++ b/src/dss/mod.rs @@ -27,8 +27,8 @@ //! **ErrDet** | An inauthentic set of shares produced by an adversary will be flagged as such when fed to the recovery algorithm. //! **Repro** | Share reproducible: The scheme can produce shares in a deterministic way. -pub mod thss; pub mod ss1; +pub mod thss; mod metadata; diff --git a/src/dss/ss1/mod.rs b/src/dss/ss1/mod.rs index 78335d2..18a4b06 100644 --- a/src/dss/ss1/mod.rs +++ b/src/dss/ss1/mod.rs @@ -29,8 +29,8 @@ mod share; pub use self::share::*; mod scheme; -use self::scheme::SS1; pub use self::scheme::Reproducibility; +use self::scheme::SS1; use dss::AccessStructure; diff --git a/src/dss/ss1/scheme.rs b/src/dss/ss1/scheme.rs index 0801a28..49c9e4e 100644 --- a/src/dss/ss1/scheme.rs +++ b/src/dss/ss1/scheme.rs @@ -1,17 +1,17 @@ use std::collections::HashSet; -use ring::{hkdf, hmac}; -use ring::rand::{SecureRandom, SystemRandom}; -use ring::digest::{Context, SHA256}; use rand::{ChaChaRng, Rng, SeedableRng}; +use ring::digest::{Context, SHA256}; +use ring::rand::{SecureRandom, SystemRandom}; +use ring::{hkdf, hmac}; -use errors::*; -use dss::{thss, AccessStructure}; -use dss::thss::{MetaData, ThSS}; -use dss::random::{random_bytes_count, FixedRandom, MAX_MESSAGE_SIZE}; -use share::validation::{validate_share_count, validate_shares}; 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; /// We bound the message size at about 16MB to avoid overflow in `random_bytes_count`. @@ -247,7 +247,8 @@ impl SS1 { &self, shares: &[Share], ) -> Result<(Vec, AccessStructure, Option)> { - let (_, shares) = validate_shares(shares.to_vec())?; + let shares = shares.to_vec(); + validate_shares(&shares)?; let underlying_shares = shares .iter() diff --git a/src/dss/ss1/serialize.rs b/src/dss/ss1/serialize.rs index ca040df..15b48d9 100644 --- a/src/dss/ss1/serialize.rs +++ b/src/dss/ss1/serialize.rs @@ -1,8 +1,8 @@ -use errors::*; use super::{MetaData, Share}; use dss::format::{format_share_protobuf, parse_share_protobuf}; -use proto::dss::{MetaDataProto, ShareProto}; use dss::utils::{btreemap_to_hashmap, hashmap_to_btreemap}; +use errors::*; +use proto::dss::{MetaDataProto, ShareProto}; pub(crate) fn share_to_string(share: Share) -> String { let proto = share_to_protobuf(share); diff --git a/src/dss/ss1/share.rs b/src/dss/ss1/share.rs index 4ca4178..d1f6fcc 100644 --- a/src/dss/ss1/share.rs +++ b/src/dss/ss1/share.rs @@ -1,6 +1,6 @@ +use super::serialize::{share_from_string, share_to_string}; use errors::*; use share::IsShare; -use super::serialize::{share_from_string, share_to_string}; pub use dss::metadata::MetaData; diff --git a/src/dss/thss/scheme.rs b/src/dss/thss/scheme.rs index c11cfd7..e7d0d1e 100644 --- a/src/dss/thss/scheme.rs +++ b/src/dss/thss/scheme.rs @@ -4,15 +4,15 @@ use std::fmt; use ring::rand::{SecureRandom, SystemRandom}; +use dss::random::{random_bytes, random_bytes_count, MAX_MESSAGE_SIZE}; use errors::*; use gf256::Gf256; -use dss::random::{random_bytes, random_bytes_count, MAX_MESSAGE_SIZE}; -use share::validation::{validate_share_count, validate_shares}; use lagrange; +use share::validation::{validate_share_count, validate_shares}; use super::AccessStructure; -use super::share::*; use super::encode::encode_secret; +use super::share::*; /// 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 @@ -89,9 +89,8 @@ impl ThSS { &self, shares: &[Share], ) -> Result<(Vec, AccessStructure, Option)> { - let (threshold, shares) = validate_shares(shares.to_vec())?; - - let cypher_len = shares[0].data.len(); + let shares = shares.to_vec(); + let (threshold, cypher_len) = validate_shares(&shares)?; let polys = (0..cypher_len) .map(|i| { diff --git a/src/dss/thss/serialize.rs b/src/dss/thss/serialize.rs index 7190934..1111f55 100644 --- a/src/dss/thss/serialize.rs +++ b/src/dss/thss/serialize.rs @@ -1,8 +1,8 @@ -use errors::*; use super::{MetaData, Share}; use dss::format::{format_share_protobuf, parse_share_protobuf}; -use proto::dss::{MetaDataProto, ShareProto}; use dss::utils::{btreemap_to_hashmap, hashmap_to_btreemap}; +use errors::*; +use proto::dss::{MetaDataProto, ShareProto}; pub(crate) fn share_to_string(share: Share) -> String { let proto = share_to_protobuf(share); diff --git a/src/dss/thss/share.rs b/src/dss/thss/share.rs index 15a942b..f68bf15 100644 --- a/src/dss/thss/share.rs +++ b/src/dss/thss/share.rs @@ -1,6 +1,6 @@ +use super::serialize::{share_from_string, share_to_string}; use errors::*; use share::IsShare; -use super::serialize::{share_from_string, share_to_string}; pub use dss::metadata::MetaData; diff --git a/src/dss/utils.rs b/src/dss/utils.rs index 59a2362..20a0fed 100644 --- a/src/dss/utils.rs +++ b/src/dss/utils.rs @@ -1,7 +1,7 @@ use std; -use std::hash::Hash; use std::collections::{BTreeMap, HashMap}; +use std::hash::Hash; /// Transmutes a `&[u8]` into a `&[u32]`. /// Despite `std::mem::transmute` being very unsafe in diff --git a/src/errors.rs b/src/errors.rs index c2b7496..1fbe12b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,6 +3,7 @@ #![allow(unknown_lints, missing_docs)] use std::collections::HashSet; +use std::fmt; #[cfg(feature = "dss")] use dss::ss1; @@ -59,12 +60,7 @@ error_chain! { display("The shares are incompatible with each other.") } - ShareIdentifierTooBig(id: u8, n: u8) { - description("Share identifier too big") - display("Found share identifier ({}) bigger than the maximum number of shares ({}).", id, n) - } - - MissingShares(provided: usize, required: usize) { + MissingShares(provided: usize, required: u8) { description("The number of shares provided is insufficient to recover the secret.") display("{} shares are required to recover the secret, found only {}.", required, provided) } @@ -97,6 +93,11 @@ error_chain! { display("Found invalid share identifier ({})", share_id) } + ShareParsingInvalidShareThreshold(k: u8, id: u8) { + description("Threshold k must be bigger than or equal to 2") + display("Threshold k must be bigger than or equal to 2. Got k = {} for share identifier {}.", k, id) + } + InvalidSS1Parameters(r: usize, s: usize) { description("Invalid parameters for the SS1 sharing scheme") display("Invalid parameters for the SS1 sharing scheme: r = {}, s = {}.", r, s) @@ -123,15 +124,21 @@ error_chain! { display("This share number ({}) has already been used by a previous share.", share_id) } - DuplicateShareData(share_id: u8) { - description("The data encoded in this share is the same as the one found in a previous share") - display("The data encoded in share #{} is the same as the one found in a previous share.", share_id) + InconsistentSecretLengths(id: u8, slen_: usize, ids: Vec, slen: usize) { + description("The shares are incompatible with each other because they do not all have the same secret length.") + display("The share identifier {} had secret length {}, while the secret length {} was found for share identifier(s): {}.", id, slen_, slen, no_more_than_five(ids)) } InconsistentShares { description("The shares are inconsistent") display("The shares are inconsistent") } + + InconsistentThresholds(id: u8, k_: u8, ids: Vec, k: u8) { + description("The shares are incompatible with each other because they do not all have the same threshold.") + display("The share identifier {} had k = {}, while k = {} was found for share identifier(s): {}.", id, k_, k, no_more_than_five(ids)) + } + } foreign_links { @@ -139,3 +146,19 @@ error_chain! { IntegerParsingError(::std::num::ParseIntError); } } + +/// Takes a `Vec` and formats it like the normal `fmt::Debug` implementation, unless it has more +//than five elements, in which case the rest are replaced by ellipsis. +fn no_more_than_five(vec: &Vec) -> String { + let len = vec.len(); + if len > 5 { + let mut string = String::from("["); + for item in vec.iter().take(5) { + string += &format!("{}, ", item); + } + string.push_str("...]"); + string + } else { + format!("{:?}", vec) + } +} diff --git a/src/gf256.rs b/src/gf256.rs index 23546d9..49ad57e 100644 --- a/src/gf256.rs +++ b/src/gf256.rs @@ -143,7 +143,9 @@ impl Neg for Gf256 { #[macro_export] #[doc(hidden)] macro_rules! gf256 { - ($e:expr) => (Gf256::from_byte($e)) + ($e:expr) => { + Gf256::from_byte($e) + }; } #[macro_export] @@ -178,10 +180,10 @@ mod tests { mod vectors { use super::*; + use flate2::read::GzDecoder; + use itertools::Itertools; use std::fs::File; use std::io::{BufRead, BufReader}; - use itertools::Itertools; - use flate2::read::GzDecoder; macro_rules! mk_test { ($id:ident, $op:expr, $val:expr) => { @@ -196,7 +198,8 @@ mod tests { }); let ref_path = format!("tests/fixtures/gf256/gf256_{}.txt.gz", stringify!($id)); - let reference = BufReader::new(GzDecoder::new(File::open(ref_path).unwrap()).unwrap()); + let reference = + BufReader::new(GzDecoder::new(File::open(ref_path).unwrap()).unwrap()); for ((i, j, k), line) in results.zip(reference.lines()) { let left = format!("{} {} {} = {}", i, $op, j, k); @@ -204,7 +207,7 @@ mod tests { assert_eq!(left, right); } } - } + }; } mk_test!(add, "+", |i: Gf256, j: Gf256| i + j); diff --git a/src/lagrange.rs b/src/lagrange.rs index 50baf8b..b49a91f 100644 --- a/src/lagrange.rs +++ b/src/lagrange.rs @@ -2,25 +2,46 @@ use gf256::Gf256; use poly::Poly; /// Evaluates an interpolated polynomial at `Gf256::zero()` where -/// the polynomial is determined using Lagrangian interpolation -/// based on the given `points` in the G(2^8) Galois field. -pub(crate) fn interpolate_at(points: &[(u8, u8)]) -> u8 { - let mut sum = Gf256::zero(); - for (i, &(raw_xi, raw_yi)) in points.iter().enumerate() { - let xi = Gf256::from_byte(raw_xi); - let yi = Gf256::from_byte(raw_yi); - let mut prod = Gf256::one(); - for (j, &(raw_xj, _)) in points.iter().enumerate() { - if i != j { - let xj = Gf256::from_byte(raw_xj); - let delta = xi - xj; - assert_ne!(delta.poly, 0, "Duplicate shares"); - prod *= xj / delta; - } +/// the polynomial is determined using barycentric Lagrange +/// interpolation based on the given `points` in +/// the G(2^8) Galois field. +pub(crate) fn interpolate_at(k: u8, points: &[(u8, u8)]) -> u8 { + barycentric_interpolate_at(k as usize, points) +} + +/// Barycentric Lagrange interpolation algorithm from "Polynomial +/// Interpolation: Langrange vs Newton" by Wilhelm Werner. Evaluates +/// the polynomial at `Gf256::zero()`. +#[inline] +fn barycentric_interpolate_at(k: usize, points: &[(u8, u8)]) -> u8 { + // Compute the barycentric weights `w`. + let mut w = vec![Gf256::zero(); k]; + w[0] = Gf256::one(); + + let mut x = Vec::with_capacity(k); + x.push(Gf256::from_byte(points[0].0)); + + for i in 1..k { + x.push(Gf256::from_byte(points[i].0)); + for j in 0..i { + let delta = x[j] - x[i]; + assert_ne!(delta.poly, 0, "Duplicate shares"); + w[j] /= delta; + w[i] -= w[j]; } - sum += prod * yi; } - sum.to_byte() + + // Evaluate the second or "true" form of the barycentric + // interpolation formula at `Gf256::zero()`. + let (mut num, mut denom) = (Gf256::zero(), Gf256::zero()); + for i in 0..k { + assert_ne!(x[i].poly, 0, "Invalid share x = 0"); + let diff = w[i] / x[i]; + num += diff * Gf256::from_byte(points[i].1); + denom += diff; + } + + (num / denom).to_byte() } /// Computeds the coefficient of the Lagrange polynomial interpolated @@ -31,6 +52,7 @@ pub(crate) fn interpolate(points: &[(Gf256, Gf256)]) -> Poly { let mut poly = vec![Gf256::zero(); len]; for &(x, y) in points { + assert_ne!(x.poly, 0, "Invalid share x = 0"); let mut coeffs = vec![Gf256::zero(); len]; coeffs[0] = y; @@ -64,31 +86,22 @@ pub(crate) fn interpolate(points: &[(Gf256, Gf256)]) -> Poly { #[allow(trivial_casts)] mod tests { - use std; use super::*; use gf256::*; use quickcheck::*; + use std; quickcheck! { - fn evaluate_at_works(ys: Vec) -> TestResult { - if ys.is_empty() || ys.len() > std::u8::MAX as usize { - return TestResult::discard(); - } - - let points = ys.iter().enumerate().map(|(x, y)| (x as u8, *y)).collect::>(); - let equals = interpolate_at(points.as_slice()) == ys[0]; - - TestResult::from_bool(equals) - } - - fn interpolate_evaluate_at_works(ys: Vec) -> TestResult { if ys.is_empty() || ys.len() > std::u8::MAX as usize { return TestResult::discard(); } - let points = ys.into_iter().enumerate().map(|(x, y)| (gf256!(x as u8), y)).collect::>(); + let points = ys.into_iter() + .zip(1..std::u8::MAX) + .map(|(y, x)| (gf256!(x), y)) + .collect::>(); let poly = interpolate(&points); for (x, y) in points { @@ -101,11 +114,14 @@ mod tests { } fn interpolate_evaluate_at_0_eq_evaluate_at(ys: Vec) -> TestResult { - if ys.len() > std::u8::MAX as usize { + if ys.is_empty() || ys.len() > std::u8::MAX as usize { return TestResult::discard(); } - let points = ys.into_iter().enumerate().map(|(x, y)| (x as u8, y)).collect::>(); + let points = ys.into_iter() + .zip(1..std::u8::MAX) + .map(|(y, x)| (x, y)) + .collect::>(); let elems = points .iter() @@ -114,7 +130,8 @@ mod tests { let poly = interpolate(&elems); - let equals = poly.evaluate_at(Gf256::zero()).to_byte() == interpolate_at(points.as_slice()); + let equals = poly.evaluate_at(Gf256::zero()).to_byte() + == interpolate_at(points.len() as u8, points.as_slice()); TestResult::from_bool(equals) } diff --git a/src/lib.rs b/src/lib.rs index 4b88428..90d5c3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,15 +18,15 @@ extern crate ring; #[macro_use] mod gf256; -mod share; -mod poly; mod lagrange; +mod poly; +mod share; mod vol_hash; pub mod errors; +pub mod proto; pub mod sss; pub mod wrapped_secrets; -pub mod proto; #[cfg(feature = "dss")] pub mod dss; diff --git a/src/proto/dss/metadata.rs b/src/proto/dss/metadata.rs deleted file mode 100644 index 0b27f5d..0000000 --- a/src/proto/dss/metadata.rs +++ /dev/null @@ -1,253 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq, Clone, Default)] -pub struct MetaDataProto { - // message fields - pub tags: ::std::collections::HashMap<::std::string::String, ::std::string::String>, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for MetaDataProto {} - -impl MetaDataProto { - pub fn new() -> MetaDataProto { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static MetaDataProto { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const MetaDataProto, - }; - unsafe { instance.get(MetaDataProto::new) } - } - - // repeated .dss.MetaDataProto.TagsEntry tags = 1; - - pub fn clear_tags(&mut self) { - self.tags.clear(); - } - - // Param is passed by value, moved - pub fn set_tags( - &mut self, - v: ::std::collections::HashMap<::std::string::String, ::std::string::String>, - ) { - self.tags = v; - } - - // Mutable pointer to the field. - pub fn mut_tags( - &mut self, - ) -> &mut ::std::collections::HashMap<::std::string::String, ::std::string::String> { - &mut self.tags - } - - // Take field - pub fn take_tags( - &mut self, - ) -> ::std::collections::HashMap<::std::string::String, ::std::string::String> { - ::std::mem::replace(&mut self.tags, ::std::collections::HashMap::new()) - } - - pub fn get_tags( - &self, - ) -> &::std::collections::HashMap<::std::string::String, ::std::string::String> { - &self.tags - } - - fn get_tags_for_reflect( - &self, - ) -> &::std::collections::HashMap<::std::string::String, ::std::string::String> { - &self.tags - } - - fn mut_tags_for_reflect( - &mut self, - ) -> &mut ::std::collections::HashMap<::std::string::String, ::std::string::String> { - &mut self.tags - } -} - -impl ::protobuf::Message for MetaDataProto { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from( - &mut self, - is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_map_into::< - ::protobuf::types::ProtobufTypeString, - ::protobuf::types::ProtobufTypeString, - >(wire_type, is, &mut self.tags)?; - } - _ => { - ::protobuf::rt::read_unknown_or_skip_group( - field_number, - wire_type, - is, - self.mut_unknown_fields(), - )?; - } - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - my_size += ::protobuf::rt::compute_map_size::< - ::protobuf::types::ProtobufTypeString, - ::protobuf::types::ProtobufTypeString, - >(1, &self.tags); - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes( - &self, - os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - ::protobuf::rt::write_map_with_cached_sizes::< - ::protobuf::types::ProtobufTypeString, - ::protobuf::types::ProtobufTypeString, - >(1, &self.tags, os)?; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for MetaDataProto { - fn new() -> MetaDataProto { - MetaDataProto::new() - } - - fn descriptor_static( - _: ::std::option::Option, - ) -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = - ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_map_accessor::<_, ::protobuf::types::ProtobufTypeString, ::protobuf::types::ProtobufTypeString>( - "tags", - MetaDataProto::get_tags_for_reflect, - MetaDataProto::mut_tags_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "MetaDataProto", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for MetaDataProto { - fn clear(&mut self) { - self.clear_tags(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for MetaDataProto { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for MetaDataProto { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x12dss/metadata.proto\x12\x03dss\"z\n\rMetaDataProto\x120\n\x04tags\ - \x18\x01\x20\x03(\x0b2\x1c.dss.MetaDataProto.TagsEntryR\x04tags\x1a7\n\t\ - TagsEntry\x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12\x14\n\x05value\ - \x18\x02\x20\x01(\tR\x05value:\x028\x01Jz\n\x06\x12\x04\0\0\x06\x01\n\ - \x08\n\x01\x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x02\x08\x0b\n\n\n\ - \x02\x04\0\x12\x04\x04\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x04\x08\x15\ - \n\x0b\n\x04\x04\0\x02\0\x12\x03\x05\x02\x1f\n\r\n\x05\x04\0\x02\0\x04\ - \x12\x04\x05\x02\x04\x17\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x05\x02\x15\ - \n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x05\x16\x1a\n\x0c\n\x05\x04\0\x02\0\ - \x03\x12\x03\x05\x1d\x1eb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { file_descriptor_proto_lazy.get(|| parse_descriptor_proto()) } -} diff --git a/src/proto/dss/secret.rs b/src/proto/dss/secret.rs deleted file mode 100644 index 7b7a4c0..0000000 --- a/src/proto/dss/secret.rs +++ /dev/null @@ -1,369 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq, Clone, Default)] -pub struct SecretProto { - // message fields - pub version: super::version::VersionProto, - pub secret: ::std::vec::Vec, - pub meta_data: ::protobuf::SingularPtrField, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for SecretProto {} - -impl SecretProto { - pub fn new() -> SecretProto { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static SecretProto { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SecretProto, - }; - unsafe { instance.get(SecretProto::new) } - } - - // .VersionProto version = 1; - - pub fn clear_version(&mut self) { - self.version = super::version::VersionProto::INITIAL_RELEASE; - } - - // Param is passed by value, moved - pub fn set_version(&mut self, v: super::version::VersionProto) { - self.version = v; - } - - pub fn get_version(&self) -> super::version::VersionProto { - self.version - } - - fn get_version_for_reflect(&self) -> &super::version::VersionProto { - &self.version - } - - fn mut_version_for_reflect(&mut self) -> &mut super::version::VersionProto { - &mut self.version - } - - // bytes secret = 2; - - pub fn clear_secret(&mut self) { - self.secret.clear(); - } - - // Param is passed by value, moved - pub fn set_secret(&mut self, v: ::std::vec::Vec) { - self.secret = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_secret(&mut self) -> &mut ::std::vec::Vec { - &mut self.secret - } - - // Take field - pub fn take_secret(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.secret, ::std::vec::Vec::new()) - } - - pub fn get_secret(&self) -> &[u8] { - &self.secret - } - - fn get_secret_for_reflect(&self) -> &::std::vec::Vec { - &self.secret - } - - fn mut_secret_for_reflect(&mut self) -> &mut ::std::vec::Vec { - &mut self.secret - } - - // .dss.MetaDataProto meta_data = 3; - - pub fn clear_meta_data(&mut self) { - self.meta_data.clear(); - } - - pub fn has_meta_data(&self) -> bool { - self.meta_data.is_some() - } - - // Param is passed by value, moved - pub fn set_meta_data(&mut self, v: super::metadata::MetaDataProto) { - self.meta_data = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_meta_data(&mut self) -> &mut super::metadata::MetaDataProto { - if self.meta_data.is_none() { - self.meta_data.set_default(); - } - self.meta_data.as_mut().unwrap() - } - - // Take field - pub fn take_meta_data(&mut self) -> super::metadata::MetaDataProto { - self.meta_data.take().unwrap_or_else(|| { - super::metadata::MetaDataProto::new() - }) - } - - pub fn get_meta_data(&self) -> &super::metadata::MetaDataProto { - self.meta_data.as_ref().unwrap_or_else(|| { - super::metadata::MetaDataProto::default_instance() - }) - } - - fn get_meta_data_for_reflect( - &self, - ) -> &::protobuf::SingularPtrField { - &self.meta_data - } - - fn mut_meta_data_for_reflect( - &mut self, - ) -> &mut ::protobuf::SingularPtrField { - &mut self.meta_data - } -} - -impl ::protobuf::Message for SecretProto { - fn is_initialized(&self) -> bool { - for v in &self.meta_data { - if !v.is_initialized() { - return false; - } - } - true - } - - fn merge_from( - &mut self, - is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err( - ::protobuf::rt::unexpected_wire_type(wire_type), - ); - } - let tmp = is.read_enum()?; - self.version = tmp; - } - 2 => { - ::protobuf::rt::read_singular_proto3_bytes_into( - wire_type, - is, - &mut self.secret, - )?; - } - 3 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.meta_data)?; - } - _ => { - ::protobuf::rt::read_unknown_or_skip_group( - field_number, - wire_type, - is, - self.mut_unknown_fields(), - )?; - } - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.version != super::version::VersionProto::INITIAL_RELEASE { - my_size += ::protobuf::rt::enum_size(1, self.version); - } - if !self.secret.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.secret); - } - if let Some(ref v) = self.meta_data.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes( - &self, - os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - if self.version != super::version::VersionProto::INITIAL_RELEASE { - os.write_enum(1, self.version.value())?; - } - if !self.secret.is_empty() { - os.write_bytes(2, &self.secret)?; - } - if let Some(ref v) = self.meta_data.as_ref() { - os.write_tag( - 3, - ::protobuf::wire_format::WireTypeLengthDelimited, - )?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for SecretProto { - fn new() -> SecretProto { - SecretProto::new() - } - - fn descriptor_static( - _: ::std::option::Option, - ) -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = - ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "version", - SecretProto::get_version_for_reflect, - SecretProto::mut_version_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "secret", - SecretProto::get_secret_for_reflect, - SecretProto::mut_secret_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "meta_data", - SecretProto::get_meta_data_for_reflect, - SecretProto::mut_meta_data_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SecretProto", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for SecretProto { - fn clear(&mut self) { - self.clear_version(); - self.clear_secret(); - self.clear_meta_data(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SecretProto { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SecretProto { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10dss/secret.proto\x1a\rversion.proto\x1a\x12dss/metadata.proto\"\ - \x7f\n\x0bSecretProto\x12'\n\x07version\x18\x01\x20\x01(\x0e2\r.VersionP\ - rotoR\x07version\x12\x16\n\x06secret\x18\x02\x20\x01(\x0cR\x06secret\x12\ - /\n\tmeta_data\x18\x03\x20\x01(\x0b2\x12.dss.MetaDataProtoR\x08metaDataJ\ - \x92\x02\n\x06\x12\x04\0\0\t\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\t\n\ - \x02\x03\0\x12\x03\x02\x07\x16\n\t\n\x02\x03\x01\x12\x03\x03\x07\x1b\n\n\ - \n\x02\x04\0\x12\x04\x05\0\t\x01\n\n\n\x03\x04\0\x01\x12\x03\x05\x08\x13\ - \n\x0b\n\x04\x04\0\x02\0\x12\x03\x06\x08!\n\r\n\x05\x04\0\x02\0\x04\x12\ - \x04\x06\x08\x05\x15\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x06\x08\x14\n\ - \x0c\n\x05\x04\0\x02\0\x01\x12\x03\x06\x15\x1c\n\x0c\n\x05\x04\0\x02\0\ - \x03\x12\x03\x06\x1f\x20\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x07\x08\x19\n\ - \r\n\x05\x04\0\x02\x01\x04\x12\x04\x07\x08\x06!\n\x0c\n\x05\x04\0\x02\ - \x01\x05\x12\x03\x07\x08\r\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x07\x0e\ - \x14\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x07\x17\x18\n\x0b\n\x04\x04\0\ - \x02\x02\x12\x03\x08\x08(\n\r\n\x05\x04\0\x02\x02\x04\x12\x04\x08\x08\ - \x07\x19\n\x0c\n\x05\x04\0\x02\x02\x06\x12\x03\x08\x08\x19\n\x0c\n\x05\ - \x04\0\x02\x02\x01\x12\x03\x08\x1a#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\ - \x03\x08&'b\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { file_descriptor_proto_lazy.get(|| parse_descriptor_proto()) } -} diff --git a/src/proto/dss/share.rs b/src/proto/dss/share.rs deleted file mode 100644 index 4eb8e40..0000000 --- a/src/proto/dss/share.rs +++ /dev/null @@ -1,492 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq,Clone,Default)] -pub struct ShareProto { - // message fields - pub id: u32, - pub threshold: u32, - pub shares_count: u32, - pub data: ::std::vec::Vec, - pub hash: ::std::vec::Vec, - pub meta_data: ::protobuf::SingularPtrField, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for ShareProto {} - -impl ShareProto { - pub fn new() -> ShareProto { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static ShareProto { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ShareProto, - }; - unsafe { - instance.get(ShareProto::new) - } - } - - // uint32 id = 1; - - pub fn clear_id(&mut self) { - self.id = 0; - } - - // Param is passed by value, moved - pub fn set_id(&mut self, v: u32) { - self.id = v; - } - - pub fn get_id(&self) -> u32 { - self.id - } - - fn get_id_for_reflect(&self) -> &u32 { - &self.id - } - - fn mut_id_for_reflect(&mut self) -> &mut u32 { - &mut self.id - } - - // uint32 threshold = 2; - - pub fn clear_threshold(&mut self) { - self.threshold = 0; - } - - // Param is passed by value, moved - pub fn set_threshold(&mut self, v: u32) { - self.threshold = v; - } - - pub fn get_threshold(&self) -> u32 { - self.threshold - } - - fn get_threshold_for_reflect(&self) -> &u32 { - &self.threshold - } - - fn mut_threshold_for_reflect(&mut self) -> &mut u32 { - &mut self.threshold - } - - // uint32 shares_count = 3; - - pub fn clear_shares_count(&mut self) { - self.shares_count = 0; - } - - // Param is passed by value, moved - pub fn set_shares_count(&mut self, v: u32) { - self.shares_count = v; - } - - pub fn get_shares_count(&self) -> u32 { - self.shares_count - } - - fn get_shares_count_for_reflect(&self) -> &u32 { - &self.shares_count - } - - fn mut_shares_count_for_reflect(&mut self) -> &mut u32 { - &mut self.shares_count - } - - // bytes data = 4; - - pub fn clear_data(&mut self) { - self.data.clear(); - } - - // Param is passed by value, moved - pub fn set_data(&mut self, v: ::std::vec::Vec) { - self.data = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_data(&mut self) -> &mut ::std::vec::Vec { - &mut self.data - } - - // Take field - pub fn take_data(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) - } - - pub fn get_data(&self) -> &[u8] { - &self.data - } - - fn get_data_for_reflect(&self) -> &::std::vec::Vec { - &self.data - } - - fn mut_data_for_reflect(&mut self) -> &mut ::std::vec::Vec { - &mut self.data - } - - // bytes hash = 5; - - pub fn clear_hash(&mut self) { - self.hash.clear(); - } - - // Param is passed by value, moved - pub fn set_hash(&mut self, v: ::std::vec::Vec) { - self.hash = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_hash(&mut self) -> &mut ::std::vec::Vec { - &mut self.hash - } - - // Take field - pub fn take_hash(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.hash, ::std::vec::Vec::new()) - } - - pub fn get_hash(&self) -> &[u8] { - &self.hash - } - - fn get_hash_for_reflect(&self) -> &::std::vec::Vec { - &self.hash - } - - fn mut_hash_for_reflect(&mut self) -> &mut ::std::vec::Vec { - &mut self.hash - } - - // .dss.MetaDataProto meta_data = 6; - - pub fn clear_meta_data(&mut self) { - self.meta_data.clear(); - } - - pub fn has_meta_data(&self) -> bool { - self.meta_data.is_some() - } - - // Param is passed by value, moved - pub fn set_meta_data(&mut self, v: super::metadata::MetaDataProto) { - self.meta_data = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_meta_data(&mut self) -> &mut super::metadata::MetaDataProto { - if self.meta_data.is_none() { - self.meta_data.set_default(); - } - self.meta_data.as_mut().unwrap() - } - - // Take field - pub fn take_meta_data(&mut self) -> super::metadata::MetaDataProto { - self.meta_data.take().unwrap_or_else(|| super::metadata::MetaDataProto::new()) - } - - pub fn get_meta_data(&self) -> &super::metadata::MetaDataProto { - self.meta_data.as_ref().unwrap_or_else(|| super::metadata::MetaDataProto::default_instance()) - } - - fn get_meta_data_for_reflect(&self) -> &::protobuf::SingularPtrField { - &self.meta_data - } - - fn mut_meta_data_for_reflect(&mut self) -> &mut ::protobuf::SingularPtrField { - &mut self.meta_data - } -} - -impl ::protobuf::Message for ShareProto { - fn is_initialized(&self) -> bool { - for v in &self.meta_data { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint32()?; - self.id = tmp; - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint32()?; - self.threshold = tmp; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint32()?; - self.shares_count = tmp; - }, - 4 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.data)?; - }, - 5 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.hash)?; - }, - 6 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.meta_data)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.id != 0 { - my_size += ::protobuf::rt::value_size(1, self.id, ::protobuf::wire_format::WireTypeVarint); - } - if self.threshold != 0 { - my_size += ::protobuf::rt::value_size(2, self.threshold, ::protobuf::wire_format::WireTypeVarint); - } - if self.shares_count != 0 { - my_size += ::protobuf::rt::value_size(3, self.shares_count, ::protobuf::wire_format::WireTypeVarint); - } - if !self.data.is_empty() { - my_size += ::protobuf::rt::bytes_size(4, &self.data); - } - if !self.hash.is_empty() { - my_size += ::protobuf::rt::bytes_size(5, &self.hash); - } - if let Some(ref v) = self.meta_data.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if self.id != 0 { - os.write_uint32(1, self.id)?; - } - if self.threshold != 0 { - os.write_uint32(2, self.threshold)?; - } - if self.shares_count != 0 { - os.write_uint32(3, self.shares_count)?; - } - if !self.data.is_empty() { - os.write_bytes(4, &self.data)?; - } - if !self.hash.is_empty() { - os.write_bytes(5, &self.hash)?; - } - if let Some(ref v) = self.meta_data.as_ref() { - os.write_tag(6, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for ShareProto { - fn new() -> ShareProto { - ShareProto::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "id", - ShareProto::get_id_for_reflect, - ShareProto::mut_id_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "threshold", - ShareProto::get_threshold_for_reflect, - ShareProto::mut_threshold_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "shares_count", - ShareProto::get_shares_count_for_reflect, - ShareProto::mut_shares_count_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "data", - ShareProto::get_data_for_reflect, - ShareProto::mut_data_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "hash", - ShareProto::get_hash_for_reflect, - ShareProto::mut_hash_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "meta_data", - ShareProto::get_meta_data_for_reflect, - ShareProto::mut_meta_data_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ShareProto", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for ShareProto { - fn clear(&mut self) { - self.clear_id(); - self.clear_threshold(); - self.clear_shares_count(); - self.clear_data(); - self.clear_hash(); - self.clear_meta_data(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ShareProto { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ShareProto { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0fdss/share.proto\x12\x03dss\x1a\x12dss/metadata.proto\"\xb6\x01\n\n\ - ShareProto\x12\x0e\n\x02id\x18\x01\x20\x01(\rR\x02id\x12\x1c\n\tthreshol\ - d\x18\x02\x20\x01(\rR\tthreshold\x12!\n\x0cshares_count\x18\x03\x20\x01(\ - \rR\x0bsharesCount\x12\x12\n\x04data\x18\x04\x20\x01(\x0cR\x04data\x12\ - \x12\n\x04hash\x18\x05\x20\x01(\x0cR\x04hash\x12/\n\tmeta_data\x18\x06\ - \x20\x01(\x0b2\x12.dss.MetaDataProtoR\x08metaDataJ\xe3\x03\n\x06\x12\x04\ - \0\0\r\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x02\ - \x08\x0b\n\t\n\x02\x03\0\x12\x03\x04\x07\x1b\n\n\n\x02\x04\0\x12\x04\x06\ - \0\r\x01\n\n\n\x03\x04\0\x01\x12\x03\x06\x08\x12\n\x0b\n\x04\x04\0\x02\0\ - \x12\x03\x07\x02\x10\n\r\n\x05\x04\0\x02\0\x04\x12\x04\x07\x02\x06\x14\n\ - \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x07\x02\x08\n\x0c\n\x05\x04\0\x02\0\ - \x01\x12\x03\x07\t\x0b\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x07\x0e\x0f\n\ - \x0b\n\x04\x04\0\x02\x01\x12\x03\x08\x02\x17\n\r\n\x05\x04\0\x02\x01\x04\ - \x12\x04\x08\x02\x07\x10\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x08\x02\ - \x08\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x08\t\x12\n\x0c\n\x05\x04\0\ - \x02\x01\x03\x12\x03\x08\x15\x16\n\x0b\n\x04\x04\0\x02\x02\x12\x03\t\x02\ - \x1a\n\r\n\x05\x04\0\x02\x02\x04\x12\x04\t\x02\x08\x17\n\x0c\n\x05\x04\0\ - \x02\x02\x05\x12\x03\t\x02\x08\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\t\t\ - \x15\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\t\x18\x19\n\x0b\n\x04\x04\0\ - \x02\x03\x12\x03\n\x02\x11\n\r\n\x05\x04\0\x02\x03\x04\x12\x04\n\x02\t\ - \x1a\n\x0c\n\x05\x04\0\x02\x03\x05\x12\x03\n\x02\x07\n\x0c\n\x05\x04\0\ - \x02\x03\x01\x12\x03\n\x08\x0c\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\n\ - \x0f\x10\n\x0b\n\x04\x04\0\x02\x04\x12\x03\x0b\x02\x11\n\r\n\x05\x04\0\ - \x02\x04\x04\x12\x04\x0b\x02\n\x11\n\x0c\n\x05\x04\0\x02\x04\x05\x12\x03\ - \x0b\x02\x07\n\x0c\n\x05\x04\0\x02\x04\x01\x12\x03\x0b\x08\x0c\n\x0c\n\ - \x05\x04\0\x02\x04\x03\x12\x03\x0b\x0f\x10\n\x0b\n\x04\x04\0\x02\x05\x12\ - \x03\x0c\x02\"\n\r\n\x05\x04\0\x02\x05\x04\x12\x04\x0c\x02\x0b\x11\n\x0c\ - \n\x05\x04\0\x02\x05\x06\x12\x03\x0c\x02\x13\n\x0c\n\x05\x04\0\x02\x05\ - \x01\x12\x03\x0c\x14\x1d\n\x0c\n\x05\x04\0\x02\x05\x03\x12\x03\x0c\x20!b\ - \x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/src/proto/version.rs b/src/proto/version.rs deleted file mode 100644 index 9680b35..0000000 --- a/src/proto/version.rs +++ /dev/null @@ -1,100 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum VersionProto { - INITIAL_RELEASE = 0, -} - -impl ::protobuf::ProtobufEnum for VersionProto { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(VersionProto::INITIAL_RELEASE), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [VersionProto] = &[ - VersionProto::INITIAL_RELEASE, - ]; - values - } - - fn enum_descriptor_static(_: ::std::option::Option) -> &'static ::protobuf::reflect::EnumDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::EnumDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::EnumDescriptor, - }; - unsafe { - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new("VersionProto", file_descriptor_proto()) - }) - } - } -} - -impl ::std::marker::Copy for VersionProto { -} - -impl ::std::default::Default for VersionProto { - fn default() -> Self { - VersionProto::INITIAL_RELEASE - } -} - -impl ::protobuf::reflect::ProtobufValue for VersionProto { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rversion.proto*#\n\x0cVersionProto\x12\x13\n\x0fINITIAL_RELEASE\x10\0\ - JS\n\x06\x12\x04\x01\0\x05\x01\n\x08\n\x01\x0c\x12\x03\x01\0\x12\n\n\n\ - \x02\x05\0\x12\x04\x03\0\x05\x01\n\n\n\x03\x05\0\x01\x12\x03\x03\x05\x11\ - \n\x0b\n\x04\x05\0\x02\0\x12\x03\x04\x02\x16\n\x0c\n\x05\x05\0\x02\0\x01\ - \x12\x03\x04\x02\x11\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x04\x14\x15b\ - \x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/src/proto/wrapped/secret.rs b/src/proto/wrapped/secret.rs deleted file mode 100644 index 3906856..0000000 --- a/src/proto/wrapped/secret.rs +++ /dev/null @@ -1,328 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq,Clone,Default)] -pub struct SecretProto { - // message fields - pub version: super::version::VersionProto, - pub secret: ::std::vec::Vec, - pub mime_type: ::std::string::String, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for SecretProto {} - -impl SecretProto { - pub fn new() -> SecretProto { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static SecretProto { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SecretProto, - }; - unsafe { - instance.get(SecretProto::new) - } - } - - // .VersionProto version = 1; - - pub fn clear_version(&mut self) { - self.version = super::version::VersionProto::INITIAL_RELEASE; - } - - // Param is passed by value, moved - pub fn set_version(&mut self, v: super::version::VersionProto) { - self.version = v; - } - - pub fn get_version(&self) -> super::version::VersionProto { - self.version - } - - fn get_version_for_reflect(&self) -> &super::version::VersionProto { - &self.version - } - - fn mut_version_for_reflect(&mut self) -> &mut super::version::VersionProto { - &mut self.version - } - - // bytes secret = 2; - - pub fn clear_secret(&mut self) { - self.secret.clear(); - } - - // Param is passed by value, moved - pub fn set_secret(&mut self, v: ::std::vec::Vec) { - self.secret = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_secret(&mut self) -> &mut ::std::vec::Vec { - &mut self.secret - } - - // Take field - pub fn take_secret(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.secret, ::std::vec::Vec::new()) - } - - pub fn get_secret(&self) -> &[u8] { - &self.secret - } - - fn get_secret_for_reflect(&self) -> &::std::vec::Vec { - &self.secret - } - - fn mut_secret_for_reflect(&mut self) -> &mut ::std::vec::Vec { - &mut self.secret - } - - // string mime_type = 3; - - pub fn clear_mime_type(&mut self) { - self.mime_type.clear(); - } - - // Param is passed by value, moved - pub fn set_mime_type(&mut self, v: ::std::string::String) { - self.mime_type = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_mime_type(&mut self) -> &mut ::std::string::String { - &mut self.mime_type - } - - // Take field - pub fn take_mime_type(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.mime_type, ::std::string::String::new()) - } - - pub fn get_mime_type(&self) -> &str { - &self.mime_type - } - - fn get_mime_type_for_reflect(&self) -> &::std::string::String { - &self.mime_type - } - - fn mut_mime_type_for_reflect(&mut self) -> &mut ::std::string::String { - &mut self.mime_type - } -} - -impl ::protobuf::Message for SecretProto { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_enum()?; - self.version = tmp; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.secret)?; - }, - 3 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.mime_type)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.version != super::version::VersionProto::INITIAL_RELEASE { - my_size += ::protobuf::rt::enum_size(1, self.version); - } - if !self.secret.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.secret); - } - if !self.mime_type.is_empty() { - my_size += ::protobuf::rt::string_size(3, &self.mime_type); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if self.version != super::version::VersionProto::INITIAL_RELEASE { - os.write_enum(1, self.version.value())?; - } - if !self.secret.is_empty() { - os.write_bytes(2, &self.secret)?; - } - if !self.mime_type.is_empty() { - os.write_string(3, &self.mime_type)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for SecretProto { - fn new() -> SecretProto { - SecretProto::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "version", - SecretProto::get_version_for_reflect, - SecretProto::mut_version_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "secret", - SecretProto::get_secret_for_reflect, - SecretProto::mut_secret_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "mime_type", - SecretProto::get_mime_type_for_reflect, - SecretProto::mut_mime_type_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SecretProto", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for SecretProto { - fn clear(&mut self) { - self.clear_version(); - self.clear_secret(); - self.clear_mime_type(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SecretProto { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SecretProto { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x14wrapped/secret.proto\x12\x07wrapped\x1a\rversion.proto\"k\n\x0bSec\ - retProto\x12'\n\x07version\x18\x01\x20\x01(\x0e2\r.VersionProtoR\x07vers\ - ion\x12\x16\n\x06secret\x18\x02\x20\x01(\x0cR\x06secret\x12\x1b\n\tmime_\ - type\x18\x03\x20\x01(\tR\x08mimeTypeJ\x91\x02\n\x06\x12\x04\0\0\n\x01\n\ - \x08\n\x01\x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x02\x08\x0f\n\t\n\ - \x02\x03\0\x12\x03\x04\x07\x16\n\n\n\x02\x04\0\x12\x04\x06\0\n\x01\n\n\n\ - \x03\x04\0\x01\x12\x03\x06\x08\x13\n\x0b\n\x04\x04\0\x02\0\x12\x03\x07\ - \x08!\n\r\n\x05\x04\0\x02\0\x04\x12\x04\x07\x08\x06\x15\n\x0c\n\x05\x04\ - \0\x02\0\x06\x12\x03\x07\x08\x14\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x07\ - \x15\x1c\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x07\x1f\x20\n\x0b\n\x04\x04\ - \0\x02\x01\x12\x03\x08\x08\x19\n\r\n\x05\x04\0\x02\x01\x04\x12\x04\x08\ - \x08\x07!\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x08\x08\r\n\x0c\n\x05\ - \x04\0\x02\x01\x01\x12\x03\x08\x0e\x14\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ - \x03\x08\x17\x18\n\x0b\n\x04\x04\0\x02\x02\x12\x03\t\x08\x1d\n\r\n\x05\ - \x04\0\x02\x02\x04\x12\x04\t\x08\x08\x19\n\x0c\n\x05\x04\0\x02\x02\x05\ - \x12\x03\t\x08\x0e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\t\x0f\x18\n\x0c\ - \n\x05\x04\0\x02\x02\x03\x12\x03\t\x1b\x1cb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/src/proto/wrapped/share.rs b/src/proto/wrapped/share.rs deleted file mode 100644 index 3bbdbb6..0000000 --- a/src/proto/wrapped/share.rs +++ /dev/null @@ -1,333 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq,Clone,Default)] -pub struct ShareProto { - // message fields - pub shamir_data: ::std::vec::Vec, - pub signature: ::protobuf::RepeatedField<::std::vec::Vec>, - pub proof: ::std::vec::Vec, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for ShareProto {} - -impl ShareProto { - pub fn new() -> ShareProto { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static ShareProto { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ShareProto, - }; - unsafe { - instance.get(ShareProto::new) - } - } - - // bytes shamir_data = 1; - - pub fn clear_shamir_data(&mut self) { - self.shamir_data.clear(); - } - - // Param is passed by value, moved - pub fn set_shamir_data(&mut self, v: ::std::vec::Vec) { - self.shamir_data = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_shamir_data(&mut self) -> &mut ::std::vec::Vec { - &mut self.shamir_data - } - - // Take field - pub fn take_shamir_data(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.shamir_data, ::std::vec::Vec::new()) - } - - pub fn get_shamir_data(&self) -> &[u8] { - &self.shamir_data - } - - fn get_shamir_data_for_reflect(&self) -> &::std::vec::Vec { - &self.shamir_data - } - - fn mut_shamir_data_for_reflect(&mut self) -> &mut ::std::vec::Vec { - &mut self.shamir_data - } - - // repeated bytes signature = 2; - - pub fn clear_signature(&mut self) { - self.signature.clear(); - } - - // Param is passed by value, moved - pub fn set_signature(&mut self, v: ::protobuf::RepeatedField<::std::vec::Vec>) { - self.signature = v; - } - - // Mutable pointer to the field. - pub fn mut_signature(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec> { - &mut self.signature - } - - // Take field - pub fn take_signature(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { - ::std::mem::replace(&mut self.signature, ::protobuf::RepeatedField::new()) - } - - pub fn get_signature(&self) -> &[::std::vec::Vec] { - &self.signature - } - - fn get_signature_for_reflect(&self) -> &::protobuf::RepeatedField<::std::vec::Vec> { - &self.signature - } - - fn mut_signature_for_reflect(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec> { - &mut self.signature - } - - // bytes proof = 3; - - pub fn clear_proof(&mut self) { - self.proof.clear(); - } - - // Param is passed by value, moved - pub fn set_proof(&mut self, v: ::std::vec::Vec) { - self.proof = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_proof(&mut self) -> &mut ::std::vec::Vec { - &mut self.proof - } - - // Take field - pub fn take_proof(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.proof, ::std::vec::Vec::new()) - } - - pub fn get_proof(&self) -> &[u8] { - &self.proof - } - - fn get_proof_for_reflect(&self) -> &::std::vec::Vec { - &self.proof - } - - fn mut_proof_for_reflect(&mut self) -> &mut ::std::vec::Vec { - &mut self.proof - } -} - -impl ::protobuf::Message for ShareProto { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.shamir_data)?; - }, - 2 => { - ::protobuf::rt::read_repeated_bytes_into(wire_type, is, &mut self.signature)?; - }, - 3 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.proof)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.shamir_data.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.shamir_data); - } - for value in &self.signature { - my_size += ::protobuf::rt::bytes_size(2, &value); - }; - if !self.proof.is_empty() { - my_size += ::protobuf::rt::bytes_size(3, &self.proof); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if !self.shamir_data.is_empty() { - os.write_bytes(1, &self.shamir_data)?; - } - for v in &self.signature { - os.write_bytes(2, &v)?; - }; - if !self.proof.is_empty() { - os.write_bytes(3, &self.proof)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for ShareProto { - fn new() -> ShareProto { - ShareProto::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "shamir_data", - ShareProto::get_shamir_data_for_reflect, - ShareProto::mut_shamir_data_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "signature", - ShareProto::get_signature_for_reflect, - ShareProto::mut_signature_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "proof", - ShareProto::get_proof_for_reflect, - ShareProto::mut_proof_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ShareProto", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for ShareProto { - fn clear(&mut self) { - self.clear_shamir_data(); - self.clear_signature(); - self.clear_proof(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ShareProto { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ShareProto { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x13wrapped/share.proto\x12\x07wrapped\"a\n\nShareProto\x12\x1f\n\x0bs\ - hamir_data\x18\x01\x20\x01(\x0cR\nshamirData\x12\x1c\n\tsignature\x18\ - \x02\x20\x03(\x0cR\tsignature\x12\x14\n\x05proof\x18\x03\x20\x01(\x0cR\ - \x05proofJ\x85\x02\n\x06\x12\x04\0\0\x08\x01\n\x08\n\x01\x0c\x12\x03\0\0\ - \x12\n\x08\n\x01\x02\x12\x03\x02\x08\x0f\n\n\n\x02\x04\0\x12\x04\x04\0\ - \x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x04\x08\x12\n\x0b\n\x04\x04\0\x02\0\ - \x12\x03\x05\x08\x1e\n\r\n\x05\x04\0\x02\0\x04\x12\x04\x05\x08\x04\x14\n\ - \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x05\x08\r\n\x0c\n\x05\x04\0\x02\0\x01\ - \x12\x03\x05\x0e\x19\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x05\x1c\x1d\n\ - \x0b\n\x04\x04\0\x02\x01\x12\x03\x06\x08%\n\x0c\n\x05\x04\0\x02\x01\x04\ - \x12\x03\x06\x08\x10\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x06\x11\x16\n\ - \x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x06\x17\x20\n\x0c\n\x05\x04\0\x02\ - \x01\x03\x12\x03\x06#$\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x07\x08\x18\n\r\ - \n\x05\x04\0\x02\x02\x04\x12\x04\x07\x08\x06%\n\x0c\n\x05\x04\0\x02\x02\ - \x05\x12\x03\x07\x08\r\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x07\x0e\x13\ - \n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x07\x16\x17b\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/src/share/validation.rs b/src/share/validation.rs index f8f94ad..1b894cf 100644 --- a/src/share/validation.rs +++ b/src/share/validation.rs @@ -1,5 +1,3 @@ -use std::collections::{HashMap, HashSet}; - use errors::*; use share::{IsShare, IsSignedShare}; @@ -11,92 +9,81 @@ use share::{IsShare, IsSignedShare}; /// TODO: Doc pub(crate) fn validate_signed_shares( - shares: Vec, + shares: &Vec, verify_signatures: bool, -) -> Result<(u8, Vec)> { - let (threshold, shares) = validate_shares(shares)?; +) -> Result<(u8, usize)> { + let result = validate_shares(shares)?; if verify_signatures { S::verify_signatures(&shares)?; } - Ok((threshold, shares)) + Ok(result) } /// TODO: Doc -pub(crate) fn validate_shares(shares: Vec) -> Result<(u8, Vec)> { +pub(crate) fn validate_shares(shares: &Vec) -> Result<(u8, usize)> { if shares.is_empty() { bail!(ErrorKind::EmptyShares); } let shares_count = shares.len(); - let mut result: Vec = Vec::with_capacity(shares_count); - let mut k_compatibility_sets = HashMap::new(); + let mut ids = Vec::with_capacity(shares_count); + let mut threshold = 0; + let mut slen = 0; for share in shares { - let (id, threshold) = (share.get_id(), share.get_threshold()); - - if id > MAX_SHARES { - bail!(ErrorKind::ShareIdentifierTooBig(id, MAX_SHARES)) - } + let id = share.get_id(); + let threshold_ = share.get_threshold(); + let slen_ = share.get_data().len(); + // Public-facing `Share::share_from_string` performs these three tests, but in case another + // type which implements `IsShare` is implemented later that doesn't do that validation, + // we'll leave them. if id < 1 { bail!(ErrorKind::ShareParsingInvalidShareId(id)) + } else if threshold_ < 2 { + bail!(ErrorKind::ShareParsingInvalidShareThreshold(threshold, id)) + } else if slen_ < 1 { + bail!(ErrorKind::ShareParsingErrorEmptyShare(id)) } - k_compatibility_sets - .entry(threshold) - .or_insert_with(HashSet::new); - let k_set = k_compatibility_sets.get_mut(&threshold).unwrap(); - k_set.insert(id); - - if result.iter().any(|s| s.get_id() == id) { + if ids.iter().any(|&x| x == id) { bail!(ErrorKind::DuplicateShareId(id)); } - if share.get_data().is_empty() { - bail!(ErrorKind::ShareParsingErrorEmptyShare(id)) + if threshold == 0 { + threshold = threshold_; + } else if threshold_ != threshold { + bail!(ErrorKind::InconsistentThresholds( + id, + threshold_, + ids, + threshold + )) } - if result.iter().any(|s| s.get_data() == share.get_data()) && share.get_threshold() != 1 { - // When threshold = 1, shares data can be the same - bail!(ErrorKind::DuplicateShareData(id)); + if slen == 0 { + slen = slen_; + } else if slen_ != slen { + bail!(ErrorKind::InconsistentSecretLengths(id, slen_, ids, slen)) } - result.push(share); + ids.push(id); } - // Validate threshold - let k_sets = k_compatibility_sets.keys().count(); - - match k_sets { - 0 => bail!(ErrorKind::EmptyShares), - 1 => {} // All shares have the same roothash. - _ => { - bail! { - ErrorKind::IncompatibleSets( - k_compatibility_sets - .values() - .map(|x| x.to_owned()) - .collect(), - ) - } - } - } - - // It is safe to unwrap because k_sets == 1 - let threshold = k_compatibility_sets.keys().last().unwrap().to_owned(); - + // Only once the threshold is confirmed as consistent should we determine if shares are + // missing. if shares_count < threshold as usize { - bail!(ErrorKind::MissingShares(threshold as usize, shares_count)); + bail!(ErrorKind::MissingShares(shares_count, threshold)) } - Ok((threshold, result)) + Ok((threshold, slen)) } pub(crate) fn validate_share_count(threshold: u8, shares_count: u8) -> Result<(u8, u8)> { - if threshold < MIN_SHARES { + if threshold < MIN_THRESHOLD { bail!(ErrorKind::ThresholdTooSmall(threshold)); } if shares_count > MAX_SHARES { diff --git a/src/sss/encode.rs b/src/sss/encode.rs index d2729fb..abfe549 100644 --- a/src/sss/encode.rs +++ b/src/sss/encode.rs @@ -2,17 +2,15 @@ use gf256::Gf256; use std::io; use std::io::prelude::*; -/// evaluates a polynomial at x=1, 2, 3, ... n (inclusive) +/// Evaluates a polynomial at x=1, 2, 3, ... n (inclusive) using +/// Horner's method. pub(crate) fn encode_secret_byte(src: &[u8], n: u8, w: &mut W) -> io::Result<()> { for raw_x in 1..(u16::from(n) + 1) { let x = Gf256::from_byte(raw_x as u8); - let mut fac = Gf256::one(); - let mut acc = Gf256::zero(); - for &coeff in src.iter() { - acc += fac * Gf256::from_byte(coeff); - fac *= x; - } - w.write_all(&[acc.to_byte()])?; + let sum = src.iter().rev().fold(Gf256::zero(), |acc, &coeff| { + Gf256::from_byte(coeff) + acc * x + }); + w.write_all(&[sum.to_byte()])?; } Ok(()) } diff --git a/src/sss/format.rs b/src/sss/format.rs index 0e7c3ea..e6cb2a7 100644 --- a/src/sss/format.rs +++ b/src/sss/format.rs @@ -1,9 +1,9 @@ +use base64; use errors::*; use merkle_sigs::{MerklePublicKey, Proof, PublicKey}; +use proto::wrapped::ShareProto; use protobuf::{self, Message, RepeatedField}; -use base64; use sss::{Share, HASH_ALGO}; -use proto::wrapped::ShareProto; use std::error::Error; const BASE64_CONFIG: base64::Config = base64::STANDARD_NO_PAD; @@ -49,12 +49,12 @@ pub(crate) fn share_from_string(s: &str, is_signed: bool) -> Result { (k, i, p3) }; - if k < 1 || i < 1 { - bail! { - ErrorKind::ShareParsingError( - format!("Found illegal share info: threshold = {}, identifier = {}.", k, i), - ) - } + if i < 1 { + bail!(ErrorKind::ShareParsingInvalidShareId(i)) + } else if k < 2 { + bail!(ErrorKind::ShareParsingInvalidShareThreshold(k, i)) + } else if p3.is_empty() { + bail!(ErrorKind::ShareParsingErrorEmptyShare(i)) } let raw_data = base64::decode_config(p3, BASE64_CONFIG).chain_err(|| { diff --git a/src/sss/mod.rs b/src/sss/mod.rs index 7709d1b..1cb8f3a 100644 --- a/src/sss/mod.rs +++ b/src/sss/mod.rs @@ -13,11 +13,14 @@ pub(crate) use self::scheme::*; mod encode; +use rand::{OsRng, Rng}; use ring::digest::{Algorithm, SHA512}; static HASH_ALGO: &'static Algorithm = &SHA512; /// Performs threshold k-out-of-n Shamir's secret sharing. /// +/// Uses a `rand::OsRng` as a source of entropy. +/// /// # Examples /// /// ``` @@ -37,7 +40,53 @@ static HASH_ALGO: &'static Algorithm = &SHA512; /// ``` pub fn split_secret(k: u8, n: u8, secret: &[u8], sign_shares: bool) -> Result> { SSS::default() - .split_secret(k, n, secret, sign_shares) + .split_secret(&mut OsRng::new()?, k, n, secret, sign_shares) + .map(|shares| shares.into_iter().map(Share::into_string).collect()) +} + +/// Performs threshold k-out-of-n Shamir's secret sharing with a custom RNG. +/// +/// # Examples +/// +/// ``` +/// # extern crate rusty_secrets; +/// # extern crate rand; +/// # +/// # use rand::ChaChaRng; +/// # +/// # fn some_custom_rng() -> ChaChaRng { +/// # let mut rng = ChaChaRng::new_unseeded(); +/// # rng.set_counter(42, 42); +/// # rng +/// # } +/// # +/// # fn main() { +/// use rusty_secrets::sss::split_secret_rng; +/// +/// let secret = "These programs were never about terrorism: they’re about economic spying, \ +/// social control, and diplomatic manipulation. They’re about power."; +/// +/// let mut rng = some_custom_rng(); +/// +/// match split_secret_rng(&mut rng, 7, 10, &secret.as_bytes(), true) { +/// Ok(shares) => { +/// // Do something with the shares +/// }, +/// Err(_) => { +/// // Deal with error +/// } +/// } +/// # } +/// ``` +pub fn split_secret_rng( + rng: &mut R, + k: u8, + n: u8, + secret: &[u8], + sign_shares: bool, +) -> Result> { + SSS::default() + .split_secret(rng, k, n, secret, sign_shares) .map(|shares| shares.into_iter().map(Share::into_string).collect()) } diff --git a/src/sss/scheme.rs b/src/sss/scheme.rs index acb3723..3cbc8e6 100644 --- a/src/sss/scheme.rs +++ b/src/sss/scheme.rs @@ -1,13 +1,13 @@ //! SSS provides Shamir's secret sharing with raw data. -use rand::{OsRng, Rng}; use merkle_sigs::sign_data_vec; +use rand::Rng; use errors::*; -use sss::{Share, HASH_ALGO}; -use sss::format::format_share_for_signing; -use share::validation::{validate_share_count, validate_signed_shares}; use lagrange::interpolate_at; +use share::validation::{validate_share_count, validate_signed_shares}; +use sss::format::format_share_for_signing; +use sss::{Share, HASH_ALGO}; use super::encode::encode_secret_byte; @@ -17,15 +17,16 @@ pub(crate) struct SSS; impl SSS { /// Performs threshold k-out-of-n Shamir's secret sharing. - pub fn split_secret( + pub fn split_secret( &self, + rng: &mut R, threshold: u8, shares_count: u8, secret: &[u8], sign_shares: bool, ) -> Result> { let (threshold, shares_count) = validate_share_count(threshold, shares_count)?; - let shares = Self::secret_share(secret, threshold, shares_count)?; + let shares = Self::secret_share(rng, secret, threshold, shares_count)?; let signatures = if sign_shares { let shares_to_sign = shares @@ -67,17 +68,23 @@ impl SSS { Ok(result.collect()) } - fn secret_share(src: &[u8], threshold: u8, shares_count: u8) -> Result>> { + fn secret_share( + rng: &mut R, + src: &[u8], + threshold: u8, + shares_count: u8, + ) -> Result>> { let mut result = Vec::with_capacity(shares_count as usize); for _ in 0..(shares_count as usize) { result.push(vec![0u8; src.len()]); } let mut col_in = vec![0u8; threshold as usize]; let mut col_out = Vec::with_capacity(shares_count as usize); - let mut osrng = OsRng::new()?; for (c, &s) in src.iter().enumerate() { col_in[0] = s; - osrng.fill_bytes(&mut col_in[1..]); + // NOTE: switch to `try_fill_bytes` when it lands in a stable release: + // https://github.com/rust-lang-nursery/rand/commit/230b2258dbd99ff8bd991008c972d923d4b5d10c + rng.fill_bytes(&mut col_in[1..]); col_out.clear(); encode_secret_byte(&*col_in, shares_count, &mut col_out)?; for (&y, share) in col_out.iter().zip(result.iter_mut()) { @@ -91,9 +98,8 @@ impl SSS { /// /// At least `k` distinct shares need to be provided to recover the share. pub fn recover_secret(shares: Vec, verify_signatures: bool) -> Result> { - let (threshold, shares) = validate_signed_shares(shares, verify_signatures)?; + let (threshold, slen) = validate_signed_shares(&shares, verify_signatures)?; - let slen = shares[0].data.len(); let mut col_in = Vec::with_capacity(threshold as usize); let mut secret = Vec::with_capacity(slen); for byteindex in 0..slen { @@ -101,7 +107,7 @@ impl SSS { for s in shares.iter().take(threshold as usize) { col_in.push((s.id, s.data[byteindex])); } - secret.push(interpolate_at(&*col_in)); + secret.push(interpolate_at(threshold, &*col_in)); } Ok(secret) diff --git a/src/sss/share.rs b/src/sss/share.rs index f46ad67..e3ff1ca 100644 --- a/src/sss/share.rs +++ b/src/sss/share.rs @@ -1,8 +1,8 @@ -use std::error::Error; use std::collections::{HashMap, HashSet}; +use std::error::Error; -use merkle_sigs::{MerklePublicKey, Proof}; use merkle_sigs::verify_data_vec_signature; +use merkle_sigs::{MerklePublicKey, Proof}; use errors::*; use share::{IsShare, IsSignedShare}; diff --git a/src/wrapped_secrets/mod.rs b/src/wrapped_secrets/mod.rs index 3a797fd..5be7e08 100644 --- a/src/wrapped_secrets/mod.rs +++ b/src/wrapped_secrets/mod.rs @@ -3,11 +3,15 @@ use errors::*; use proto::wrapped::SecretProto; +use rand::{OsRng, Rng}; + mod scheme; pub(crate) use self::scheme::*; /// Performs threshold k-out-of-n Shamir's secret sharing. /// +/// Uses an `OsRng` as a source of entropy. +/// /// # Examples /// /// ``` @@ -41,7 +45,54 @@ pub fn split_secret( sign_shares: bool, ) -> Result> { WrappedSecrets::default() - .split_secret(k, n, secret, mime_type, sign_shares) + .split_secret(&mut OsRng::new()?, k, n, secret, mime_type, sign_shares) + .map(|shares| shares.into_iter().map(Share::into_string).collect()) +} + +/// Performs threshold k-out-of-n Shamir's secret sharing with a custom RNG. +/// +/// # Examples +/// +/// ``` +/// # extern crate rusty_secrets; +/// # extern crate rand; +/// # +/// # fn main() { +/// use rusty_secrets::wrapped_secrets::split_secret_rng; +/// use rand::ChaChaRng; +/// +/// let secret = "These programs were never about terrorism: they’re about economic spying, \ +/// social control, and diplomatic manipulation. They’re about power."; +/// +/// let result = split_secret_rng( +/// &mut ChaChaRng::new_unseeded(), +/// 7, +/// 10, +/// &secret.as_bytes(), +/// Some("text/html".to_string()), +/// true, +/// ); +/// +/// match result { +/// Ok(shares) => { +/// // Do something with the shares +/// }, +/// Err(_) => { +/// // Deal with error +/// } +/// } +/// # } +/// ``` +pub fn split_secret_rng( + rng: &mut R, + k: u8, + n: u8, + secret: &[u8], + mime_type: Option, + sign_shares: bool, +) -> Result> { + WrappedSecrets::default() + .split_secret(rng, k, n, secret, mime_type, sign_shares) .map(|shares| shares.into_iter().map(Share::into_string).collect()) } diff --git a/src/wrapped_secrets/scheme.rs b/src/wrapped_secrets/scheme.rs index 40c50f8..a704e39 100644 --- a/src/wrapped_secrets/scheme.rs +++ b/src/wrapped_secrets/scheme.rs @@ -1,8 +1,9 @@ use errors::*; +use proto::VersionProto; +use proto::wrapped::SecretProto; use protobuf; use protobuf::Message; -use proto::wrapped::SecretProto; -use proto::VersionProto; +use rand::Rng; use sss::SSS; pub(crate) use sss::Share; @@ -12,8 +13,9 @@ pub(crate) struct WrappedSecrets; impl WrappedSecrets { /// Performs threshold k-out-of-n Shamir's secret sharing. - pub fn split_secret( + pub fn split_secret( &self, + rng: &mut R, k: u8, n: u8, secret: &[u8], @@ -30,7 +32,7 @@ impl WrappedSecrets { let data = rusty_secret.write_to_bytes().unwrap(); - SSS::default().split_secret(k, n, data.as_slice(), sign_shares) + SSS::default().split_secret(rng, k, n, data.as_slice(), sign_shares) } /// Recovers the secret from a k-out-of-n Shamir's secret sharing. diff --git a/tests/recovery_errors.rs b/tests/recovery_errors.rs index 7a36dbe..0e1e8f5 100644 --- a/tests/recovery_errors.rs +++ b/tests/recovery_errors.rs @@ -11,6 +11,13 @@ fn test_recover_no_shares() { } } +#[test] +#[should_panic(expected = "ShareParsingErrorEmptyShare")] +fn test_share_parsing_error_empty_share() { + let shares = vec!["2-1-".to_string()]; + recover_secret(&shares, false).unwrap(); +} + #[test] #[should_panic(expected = "ShareParsingError")] fn test_recover_2_parts_share() { @@ -34,13 +41,9 @@ fn test_recover_incorrect_share_num() { } #[test] -#[should_panic(expected = "ShareParsingError")] +#[should_panic(expected = "ShareParsingInvalidShareId")] fn test_recover_0_share_num() { - let share1 = "2-0-1YAYwmOHqZ69jA".to_string(); - let share2 = "2-1-YJZQDGm22Y77Gw".to_string(); - - let shares = vec![share1, share2]; - + let shares = vec!["2-0-1YAYwmOHqZ69jA".to_string()]; recover_secret(&shares, false).unwrap(); } @@ -67,10 +70,21 @@ fn test_recover_duplicate_shares_number() { } #[test] -#[should_panic(expected = "DuplicateShareData")] -fn test_recover_duplicate_shares_data() { +#[should_panic(expected = "InconsistentSecretLengths")] +fn test_recover_inconsistent_secret_lengths() { let share1 = "2-1-CgnlCxRNtnkzENE".to_string(); - let share2 = "2-2-CgnlCxRNtnkzENE".to_string(); + let share2 = "2-2-ChbG46L1zRszs0PPn63XnnupmZTcgYJ3".to_string(); + + let shares = vec![share1, share2]; + + recover_secret(&shares, false).unwrap(); +} + +#[test] +#[should_panic(expected = "InconsistentThresholds")] +fn test_inconsistent_thresholds() { + let share1 = "2-1-CgnlCxRNtnkzENE".to_string(); + let share2 = "3-2-CgkAnUgP3lfwjyM".to_string(); let shares = vec![share1, share2]; @@ -88,6 +102,17 @@ fn test_recover_too_few_shares() { recover_secret(&shares, false).unwrap(); } +#[test] +#[should_panic(expected = "ShareParsingInvalidShareThreshold")] +fn test_recover_invalid_share_threshold() { + let share1 = "1-1-CgnlCxRNtnkzENE".to_string(); + let share2 = "1-1-CgkAnUgP3lfwjyM".to_string(); + + let shares = vec![share1, share2]; + + recover_secret(&shares, false).unwrap(); +} + // See https://github.com/SpinResearch/RustySecrets/issues/43 #[test] fn test_recover_too_few_shares_bug() { diff --git a/tests/ss1_recovery_errors.rs b/tests/ss1_recovery_errors.rs index 4ab71a2..1ad4d11 100644 --- a/tests/ss1_recovery_errors.rs +++ b/tests/ss1_recovery_errors.rs @@ -135,32 +135,6 @@ fn test_recover_duplicate_shares_number() { recover_secret(&shares).unwrap(); } -#[test] -#[should_panic(expected = "DuplicateShareData")] -fn test_recover_duplicate_shares_data() { - let hash = get_test_hash(); - let share1 = Share { - id: 1, - threshold: TEST_THRESHOLD, - shares_count: TEST_SHARES_COUNT, - data: "1YAYwmOHqZ69jA".to_string().into_bytes(), - hash: hash.clone(), - metadata: None, - }; - let share2 = Share { - id: 2, - threshold: TEST_THRESHOLD, - shares_count: TEST_SHARES_COUNT, - data: "1YAYwmOHqZ69jA".to_string().into_bytes(), - hash: hash.clone(), - metadata: None, - }; - - let shares = vec![share1, share2]; - - recover_secret(&shares).unwrap(); -} - #[test] #[should_panic(expected = "MissingShares")] fn test_recover_too_few_shares() { diff --git a/tests/thss_recovery_errors.rs b/tests/thss_recovery_errors.rs index 4c6c58a..173680a 100644 --- a/tests/thss_recovery_errors.rs +++ b/tests/thss_recovery_errors.rs @@ -106,29 +106,6 @@ fn test_recover_duplicate_shares_number() { recover_secret(&shares).unwrap(); } -#[test] -#[should_panic(expected = "DuplicateShareData")] -fn test_recover_duplicate_shares_data() { - let share1 = Share { - id: 1, - threshold: 2, - shares_count: 2, - data: "1YAYwmOHqZ69jA".to_string().into_bytes(), - metadata: None, - }; - let share2 = Share { - id: 2, - threshold: 2, - shares_count: 2, - data: "1YAYwmOHqZ69jA".to_string().into_bytes(), - metadata: None, - }; - - let shares = vec![share1, share2]; - - recover_secret(&shares).unwrap(); -} - #[test] #[should_panic(expected = "MissingShares")] fn test_recover_too_few_shares() {