Upgrade to Rust 1.31.0 and edition 2018.

master
Andreas Fackler 6 years ago committed by Andreas Fackler
parent c2d63b214a
commit 1b1df40c67
  1. 2
      .travis.yml
  2. 1
      Cargo.toml
  3. 12
      benches/bench.rs
  4. 4
      examples/basic_pkc.rs
  5. 6
      examples/threshold_enc.rs
  6. 9
      examples/threshold_sig.rs
  7. 46
      src/lib.rs
  8. 4
      src/mock/mod.rs
  9. 8
      src/mock/ms8.rs
  10. 25
      src/poly.rs
  11. 2
      src/secret.rs
  12. 13
      src/serde_impl.rs

@ -1,6 +1,6 @@
language: rust language: rust
rust: rust:
- 1.30.0 - 1.31.0
cache: cache:
cargo: true cargo: true
timeout: 1200 timeout: 1200

@ -16,6 +16,7 @@ license = "MIT/Apache-2.0"
readme = "README.md" readme = "README.md"
repository = "https://github.com/poanetwork/threshold_crypto" repository = "https://github.com/poanetwork/threshold_crypto"
description = "Pairing threshold cryptography" description = "Pairing threshold cryptography"
edition = "2018"
[dependencies] [dependencies]
byteorder = "1.2.7" byteorder = "1.2.7"

@ -1,8 +1,3 @@
extern crate criterion;
extern crate pairing;
extern crate rand;
extern crate threshold_crypto;
use criterion::{criterion_group, criterion_main, Criterion}; use criterion::{criterion_group, criterion_main, Criterion};
use threshold_crypto::poly::Poly; use threshold_crypto::poly::Poly;
use threshold_crypto::Fr; use threshold_crypto::Fr;
@ -79,7 +74,7 @@ mod poly_benches {
); );
} }
criterion_group!{ criterion_group! {
name = poly_benches; name = poly_benches;
config = Criterion::default(); config = Criterion::default();
targets = multiplication, interpolate, addition, subtraction, targets = multiplication, interpolate, addition, subtraction,
@ -108,7 +103,8 @@ mod public_key_set_benches {
.map(|&i| { .map(|&i| {
let sig = sk_set.secret_key_share(i).sign(msg); let sig = sk_set.secret_key_share(i).sign(msg);
(i, sig) (i, sig)
}).collect(); })
.collect();
b.iter(|| { b.iter(|| {
pk_set pk_set
.combine_signatures(&sigs) .combine_signatures(&sigs)
@ -119,7 +115,7 @@ mod public_key_set_benches {
); );
} }
criterion_group!{ criterion_group! {
name = public_key_set_benches; name = public_key_set_benches;
config = Criterion::default(); config = Criterion::default();
targets = combine_signatures, targets = combine_signatures,

@ -1,7 +1,3 @@
extern crate bincode;
extern crate serde_derive;
extern crate threshold_crypto;
use bincode::{deserialize, serialize}; use bincode::{deserialize, serialize};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use threshold_crypto::{PublicKey, SecretKey, Signature}; use threshold_crypto::{PublicKey, SecretKey, Signature};

@ -1,6 +1,3 @@
extern crate rand;
extern crate threshold_crypto;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use threshold_crypto::{ use threshold_crypto::{
@ -35,7 +32,8 @@ impl SecretSociety {
let sk_share = sk_set.secret_key_share(id); let sk_share = sk_set.secret_key_share(id);
let pk_share = pk_set.public_key_share(id); let pk_share = pk_set.public_key_share(id);
Actor::new(id, sk_share, pk_share) Actor::new(id, sk_share, pk_share)
}).collect(); })
.collect();
SecretSociety { actors, pk_set } SecretSociety { actors, pk_set }
} }

@ -1,6 +1,3 @@
extern crate rand;
extern crate threshold_crypto;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use threshold_crypto::{ use threshold_crypto::{
@ -53,7 +50,8 @@ impl ChatNetwork {
let sk_share = sk_set.secret_key_share(id); let sk_share = sk_set.secret_key_share(id);
let pk_share = pk_set.public_key_share(id); let pk_share = pk_set.public_key_share(id);
Node::new(id, sk_share, pk_share) Node::new(id, sk_share, pk_share)
}).collect(); })
.collect();
ChatNetwork { ChatNetwork {
pk_set, pk_set,
@ -98,8 +96,7 @@ impl ChatNetwork {
.iter() .iter()
.fold(BTreeMap::new(), |mut all_pending, node| { .fold(BTreeMap::new(), |mut all_pending, node| {
for (user_id, signed_msgs) in &node.pending { for (user_id, signed_msgs) in &node.pending {
let mut user_msgs = let user_msgs = all_pending.entry(*user_id).or_insert_with(BTreeMap::new);
all_pending.entry(*user_id).or_insert_with(BTreeMap::new);
for (msg, sigs) in signed_msgs.iter() { for (msg, sigs) in signed_msgs.iter() {
let sigs = sigs.iter().cloned(); let sigs = sigs.iter().cloned();
user_msgs user_msgs

@ -2,34 +2,15 @@
// Clippy warns that it's dangerous to derive `PartialEq` and explicitly implement `Hash`, but the // Clippy warns that it's dangerous to derive `PartialEq` and explicitly implement `Hash`, but the
// `pairing::bls12_381` types don't implement `Hash`, so we can't derive it. // `pairing::bls12_381` types don't implement `Hash`, so we can't derive it.
#![cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))] #![allow(clippy::derive_hash_xor_eq)]
// When using the mocktography, the resulting field elements become wrapped `u32`s, suddenly // When using the mocktography, the resulting field elements become wrapped `u32`s, suddenly
// triggering pass-by-reference warnings. They are conditionally disabled for this reason: // triggering pass-by-reference warnings. They are conditionally disabled for this reason:
#![cfg_attr( #![cfg_attr(
all( feature = "use-insecure-test-only-mock-crypto",
feature = "cargo-clippy", allow(clippy::trivially_copy_pass_by_ref)
feature = "use-insecure-test-only-mock-crypto"
),
allow(trivially_copy_pass_by_ref)
)] )]
#![warn(missing_docs)] #![warn(missing_docs)]
#[cfg(test)]
extern crate bincode;
extern crate byteorder;
extern crate errno;
extern crate failure;
extern crate hex_fmt;
extern crate init_with;
extern crate lazy_static;
extern crate log;
extern crate memsec;
extern crate rand;
extern crate rand_derive;
extern crate serde;
extern crate serde_derive;
extern crate tiny_keccak;
pub extern crate pairing; pub extern crate pairing;
mod into_fr; mod into_fr;
@ -50,13 +31,13 @@ use log::debug;
use pairing::{CurveAffine, CurveProjective, EncodedPoint, Engine, Field}; use pairing::{CurveAffine, CurveProjective, EncodedPoint, Engine, Field};
use rand::{ChaChaRng, OsRng, Rand, Rng, SeedableRng}; use rand::{ChaChaRng, OsRng, Rand, Rng, SeedableRng};
use rand_derive::Rand; use rand_derive::Rand;
use serde_derive::{Deserialize, Serialize};
use tiny_keccak::sha3_256; use tiny_keccak::sha3_256;
use error::{Error, FromBytesError, FromBytesResult, Result}; use crate::error::{Error, FromBytesError, FromBytesResult, Result};
use into_fr::IntoFr; use crate::into_fr::IntoFr;
use poly::{Commitment, Poly}; use crate::poly::{Commitment, Poly};
use secret::{clear_fr, ContainsSecret, MemRange, FR_SIZE}; use crate::secret::{clear_fr, ContainsSecret, MemRange, FR_SIZE};
use serde_derive::{Deserialize, Serialize};
#[cfg(not(feature = "use-insecure-test-only-mock-crypto"))] #[cfg(not(feature = "use-insecure-test-only-mock-crypto"))]
pub use pairing::bls12_381::{Bls12 as PEngine, Fr, FrRepr, G1Affine, G2Affine, G1, G2}; pub use pairing::bls12_381::{Bls12 as PEngine, Fr, FrRepr, G1Affine, G2Affine, G1, G2};
@ -65,7 +46,7 @@ pub use pairing::bls12_381::{Bls12 as PEngine, Fr, FrRepr, G1Affine, G2Affine, G
mod mock; mod mock;
#[cfg(feature = "use-insecure-test-only-mock-crypto")] #[cfg(feature = "use-insecure-test-only-mock-crypto")]
pub use mock::{ pub use crate::mock::{
Mersenne8 as Fr, Mersenne8 as FrRepr, Mocktography as PEngine, Ms8Affine as G1Affine, Mersenne8 as Fr, Mersenne8 as FrRepr, Mocktography as PEngine, Ms8Affine as G1Affine,
Ms8Affine as G2Affine, Ms8Projective as G1, Ms8Projective as G2, PK_SIZE, SIG_SIZE, Ms8Affine as G2Affine, Ms8Projective as G1, Ms8Projective as G2, PK_SIZE, SIG_SIZE,
}; };
@ -753,7 +734,8 @@ mod tests {
.map(|&i| { .map(|&i| {
let sig = sk_set.secret_key_share(i).sign(msg); let sig = sk_set.secret_key_share(i).sign(msg);
(i, sig) (i, sig)
}).collect(); })
.collect();
// Each of the shares is a valid signature matching its public key share. // Each of the shares is a valid signature matching its public key share.
for (i, sig) in &sigs { for (i, sig) in &sigs {
@ -770,7 +752,8 @@ mod tests {
.map(|&i| { .map(|&i| {
let sig = sk_set.secret_key_share(i).sign(msg); let sig = sk_set.secret_key_share(i).sign(msg);
(i, sig) (i, sig)
}).collect(); })
.collect();
let sig2 = pk_set.combine_signatures(&sigs2).expect("signatures match"); let sig2 = pk_set.combine_signatures(&sigs2).expect("signatures match");
assert_eq!(sig, sig2); assert_eq!(sig, sig2);
} }
@ -824,7 +807,8 @@ mod tests {
.decrypt_share(&ciphertext) .decrypt_share(&ciphertext)
.expect("ciphertext is invalid"); .expect("ciphertext is invalid");
(i, dec_share) (i, dec_share)
}).collect(); })
.collect();
// Each of the shares is valid matching its public key share. // Each of the shares is valid matching its public key share.
for (i, share) in &shares { for (i, share) in &shares {

@ -295,10 +295,10 @@ impl EncodedPoint for Ms8Affine {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
// There are copy & pasted results of calculations from external programs in these tests. // There are copy & pasted results of calculations from external programs in these tests.
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] #![allow(clippy::unreadable_literal)]
use super::{EncodedPoint, Mersenne8, Mocktography, Ms8Affine, PK_SIZE, SIG_SIZE}; use super::{EncodedPoint, Mersenne8, Mocktography, Ms8Affine, PK_SIZE, SIG_SIZE};
use Engine; use pairing::Engine;
#[test] #[test]
fn example_pairings() { fn example_pairings() {

@ -428,13 +428,13 @@ fn ext_euclid(a: u32, b: u32) -> (u32, i64, i64) {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
// There are copy & pasted results of calculations from external programs in these tests. // There are copy & pasted results of calculations from external programs in these tests.
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] #![allow(clippy::unreadable_literal)]
#![cfg_attr(feature = "cargo-clippy", allow(op_ref))] #![allow(clippy::op_ref)]
// We test a few mathematical identities, including `c - c = 0`. Clippy complains about these // We test a few mathematical identities, including `c - c = 0`. Clippy complains about these
// otherwise unusual expressions, so the lint is disabled. // otherwise unusual expressions, so the lint is disabled.
#![cfg_attr(feature = "cargo-clippy", allow(eq_op))] #![allow(clippy::eq_op)]
// Some test functions contain long lists of assertions. Clippy thinks they are too complex. // Some test functions contain long lists of assertions. Clippy thinks they are too complex.
#![cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] #![allow(clippy::cyclomatic_complexity)]
use super::{ext_euclid, modular_pow, Mersenne8}; use super::{ext_euclid, modular_pow, Mersenne8};
use pairing::Field; use pairing::Field;

@ -26,10 +26,10 @@ use pairing::{CurveAffine, CurveProjective, Field};
use rand::Rng; use rand::Rng;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use error::{Error, Result}; use crate::error::{Error, Result};
use into_fr::IntoFr; use crate::into_fr::IntoFr;
use secret::{clear_fr, ContainsSecret, MemRange, Safe}; use crate::secret::{clear_fr, ContainsSecret, MemRange, Safe};
use {Fr, G1Affine, G1}; use crate::{Fr, G1Affine, G1};
/// A univariate polynomial in the prime field. /// A univariate polynomial in the prime field.
#[derive(Serialize, Deserialize, PartialEq, Eq)] #[derive(Serialize, Deserialize, PartialEq, Eq)]
@ -53,7 +53,7 @@ impl Debug for Poly {
} }
} }
#[cfg_attr(feature = "cargo-clippy", allow(suspicious_op_assign_impl))] #[allow(clippy::suspicious_op_assign_impl)]
impl<B: Borrow<Poly>> ops::AddAssign<B> for Poly { impl<B: Borrow<Poly>> ops::AddAssign<B> for Poly {
fn add_assign(&mut self, rhs: B) { fn add_assign(&mut self, rhs: B) {
let len = self.coeff.len(); let len = self.coeff.len();
@ -139,7 +139,7 @@ impl<B: Borrow<Poly>> ops::Sub<B> for Poly {
} }
// Clippy thinks using `+` in a `Sub` implementation is suspicious. // Clippy thinks using `+` in a `Sub` implementation is suspicious.
#[cfg_attr(feature = "cargo-clippy", allow(suspicious_arithmetic_impl))] #[allow(clippy::suspicious_arithmetic_impl)]
impl<'a> ops::Sub<Fr> for Poly { impl<'a> ops::Sub<Fr> for Poly {
type Output = Poly; type Output = Poly;
@ -158,7 +158,7 @@ impl<'a> ops::Sub<u64> for Poly {
} }
// Clippy thinks using any `+` and `-` in a `Mul` implementation is suspicious. // Clippy thinks using any `+` and `-` in a `Mul` implementation is suspicious.
#[cfg_attr(feature = "cargo-clippy", allow(suspicious_arithmetic_impl))] #[allow(clippy::suspicious_arithmetic_impl)]
impl<'a, B: Borrow<Poly>> ops::Mul<B> for &'a Poly { impl<'a, B: Borrow<Poly>> ops::Mul<B> for &'a Poly {
type Output = Poly; type Output = Poly;
@ -406,7 +406,7 @@ impl Poly {
// current value at `x`: Adding it to `poly` will then make it correct for `x`. // current value at `x`: Adding it to `poly` will then make it correct for `x`.
let mut diff = *y; let mut diff = *y;
diff.sub_assign(&poly.evaluate(x)); diff.sub_assign(&poly.evaluate(x));
let mut base_val = base.evaluate(x); let base_val = base.evaluate(x);
diff.mul_assign(&base_val.inverse().expect("sample points must be distinct")); diff.mul_assign(&base_val.inverse().expect("sample points must be distinct"));
base *= diff; base *= diff;
poly += &base; poly += &base;
@ -608,7 +608,8 @@ impl BivarPoly {
result.add_assign(&summand); result.add_assign(&summand);
} }
result result
}).collect(); })
.collect();
Poly::from(coeff) Poly::from(coeff)
} }
@ -692,7 +693,8 @@ impl BivarCommitment {
result.add_assign(&summand); result.add_assign(&summand);
} }
result result
}).collect(); })
.collect();
Commitment { coeff } Commitment { coeff }
} }
@ -710,7 +712,8 @@ fn powers<T: IntoFr>(into_x: T, degree: usize) -> Vec<Fr> {
.chain((0..degree).map(|_| { .chain((0..degree).map(|_| {
x_pow_i.mul_assign(&x); x_pow_i.mul_assign(&x);
x_pow_i x_pow_i
})).collect() }))
.collect()
} }
/// Returns the position of coefficient `(i, j)` in the vector describing a symmetric bivariate /// Returns the position of coefficient `(i, j)` in the vector describing a symmetric bivariate

@ -7,7 +7,7 @@ use std::ops::{Deref, DerefMut};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use memsec::memzero; use memsec::memzero;
use Fr; use crate::Fr;
lazy_static! { lazy_static! {
/// The size in bytes of a single field element. /// The size in bytes of a single field element.

@ -1,11 +1,11 @@
use std::borrow::Cow; use std::borrow::Cow;
use crate::G1;
use serde::de::Error as DeserializeError; use serde::de::Error as DeserializeError;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use G1;
use poly::{coeff_pos, BivarCommitment}; use crate::poly::{coeff_pos, BivarCommitment};
const ERR_DEG: &str = "commitment degree does not match coefficients"; const ERR_DEG: &str = "commitment degree does not match coefficients";
@ -24,7 +24,8 @@ impl Serialize for BivarCommitment {
WireBivarCommitment { WireBivarCommitment {
degree: self.degree, degree: self.degree,
coeff: Cow::Borrowed(&self.coeff), coeff: Cow::Borrowed(&self.coeff),
}.serialize(s) }
.serialize(s)
} }
} }
@ -160,7 +161,7 @@ pub mod field_vec {
use serde::de::Error as DeserializeError; use serde::de::Error as DeserializeError;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use {Fr, FrRepr}; use crate::{Fr, FrRepr};
/// A wrapper type to facilitate serialization and deserialization of field elements. /// A wrapper type to facilitate serialization and deserialization of field elements.
pub struct FieldWrap<B>(B); pub struct FieldWrap<B>(B);
@ -203,8 +204,8 @@ mod tests {
use rand::{self, Rng}; use rand::{self, Rng};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use poly::BivarPoly; use crate::poly::BivarPoly;
use {Fr, G1}; use crate::{Fr, G1};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Vecs { pub struct Vecs {

Loading…
Cancel
Save