From 8af4b502ae6d63901d1a1f33c3f0bb255f25685c Mon Sep 17 00:00:00 2001 From: Marc Brinkmann Date: Thu, 5 Jul 2018 18:20:53 +0200 Subject: [PATCH] Added `RandomAdversary` and the necessary auxiliary functions. Random adversaries are created for `broadcast` and `honey_badger`. Random value generation was added for all type-dependencies of these algorithms, causing the `Rand` trait to be implement for a large portion of the codebase. Additionally, `MessageWithSender` turned into an actual struct, making it much easier to handle. Tuple-like construction is still available through `MessageWithSender::new()`. --- mod.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mod.rs b/mod.rs index d25a40d..a5ce582 100644 --- a/mod.rs +++ b/mod.rs @@ -16,7 +16,7 @@ use clear_on_drop::ClearOnDrop; use init_with::InitWith; use pairing::bls12_381::{Bls12, Fr, FrRepr, G1, G1Affine, G2, G2Affine}; use pairing::{CurveAffine, CurveProjective, Engine, Field, PrimeField}; -use rand::{ChaChaRng, OsRng, Rand, Rng, SeedableRng}; +use rand::{ChaChaRng, OsRng, Rng, SeedableRng}; use ring::digest; use self::error::{ErrorKind, Result}; @@ -83,7 +83,8 @@ impl PublicKey { } /// A signature, or a signature share. -#[derive(Deserialize, Serialize, Clone, PartialEq, Eq)] +// note: random signatures can be generated for testing +#[derive(Deserialize, Serialize, Clone, PartialEq, Eq, Rand)] pub struct Signature(#[serde(with = "serde_impl::projective")] G2); impl fmt::Debug for Signature { @@ -112,7 +113,7 @@ impl Signature { } /// A secret key, or a secret key share. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Rand)] pub struct SecretKey(Fr); impl fmt::Debug for SecretKey { @@ -129,12 +130,6 @@ impl Default for SecretKey { } } -impl Rand for SecretKey { - fn rand(rng: &mut R) -> Self { - SecretKey(rng.gen()) - } -} - impl SecretKey { /// Creates a secret key from an existing value pub fn from_value(f: Fr) -> Self { @@ -203,7 +198,7 @@ impl Ciphertext { } /// A decryption share. A threshold of decryption shares can be used to decrypt a message. -#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)] +#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq, Rand)] pub struct DecryptionShare(#[serde(with = "serde_impl::projective")] G1); impl Hash for DecryptionShare {