diff --git a/Cargo.toml b/Cargo.toml index dda966b6..499041a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "curv" -version = "0.2.0" +version = "0.2.1" edition = "2018" [lib] diff --git a/examples/pedersen_commitment.rs b/examples/pedersen_commitment.rs index 6432c7da..1157b45a 100644 --- a/examples/pedersen_commitment.rs +++ b/examples/pedersen_commitment.rs @@ -19,11 +19,10 @@ pub fn ped_com(message: &BigInt) { let security_bits = 256; let blinding_factor = BigInt::sample(security_bits); - let com = PedersenCommitment::create_commitment_with_user_defined_randomness( + let _com = PedersenCommitment::create_commitment_with_user_defined_randomness( message, &blinding_factor, ); - (com, blinding_factor); } fn main() { diff --git a/examples/proof_of_knowledge_of_dlog.rs b/examples/proof_of_knowledge_of_dlog.rs index 6c0fad74..6fd41a98 100644 --- a/examples/proof_of_knowledge_of_dlog.rs +++ b/examples/proof_of_knowledge_of_dlog.rs @@ -16,10 +16,8 @@ pub fn dlog_proof() { let witness: FE = ECScalar::new_random(); let dlog_proof = DLogProof::prove(&witness); let verified = DLogProof::verify(&dlog_proof); - match verified { - Ok(_t) => assert!(true), - Err(_e) => assert!(false), - } + + assert!(verified.is_ok()); } fn main() { diff --git a/examples/verifiable_secret_sharing.rs b/examples/verifiable_secret_sharing.rs index 2da91442..88adaaee 100644 --- a/examples/verifiable_secret_sharing.rs +++ b/examples/verifiable_secret_sharing.rs @@ -26,7 +26,7 @@ pub fn secret_sharing_3_out_of_5() { shares_vec.push(secret_shares[4].clone()); //test reconstruction - let secret_reconstructed = vss_scheme.reconstruct(&vec![0, 1, 2, 4], &shares_vec); + let secret_reconstructed = vss_scheme.reconstruct(&[0, 1, 2, 4], &shares_vec); assert_eq!(secret, secret_reconstructed); // test secret shares are verifiable @@ -36,7 +36,7 @@ pub fn secret_sharing_3_out_of_5() { assert!(valid1.is_ok()); let g: GE = GE::generator(); - let share1_public = g * &secret_shares[0]; + let share1_public = g * secret_shares[0]; let valid1_public = vss_scheme.validate_share_public(&share1_public, 1); assert!(valid1_public.is_ok()); @@ -47,11 +47,11 @@ pub fn secret_sharing_3_out_of_5() { let l2 = vss_scheme.map_share_to_new_params(2, &s); let l3 = vss_scheme.map_share_to_new_params(3, &s); let l4 = vss_scheme.map_share_to_new_params(4, &s); - let w = l0 * secret_shares[0].clone() - + l1 * secret_shares[1].clone() - + l2 * secret_shares[2].clone() - + l3 * secret_shares[3].clone() - + l4 * secret_shares[4].clone(); + let w = l0 * secret_shares[0] + + l1 * secret_shares[1] + + l2 * secret_shares[2] + + l3 * secret_shares[3] + + l4 * secret_shares[4]; assert_eq!(w, secret_reconstructed); } diff --git a/src/cryptographic_primitives/hashing/blake2b512.rs b/src/cryptographic_primitives/hashing/blake2b512.rs index d3e10427..485954f1 100644 --- a/src/cryptographic_primitives/hashing/blake2b512.rs +++ b/src/cryptographic_primitives/hashing/blake2b512.rs @@ -46,22 +46,18 @@ mod tests { #[test] // Very basic test here, TODO: suggest better testing fn create_hash_test() { - let result = - Blake::create_hash(&vec![&BigInt::one(), &BigInt::zero()], b"Zcash_RedJubjubH"); + let result = Blake::create_hash(&[&BigInt::one(), &BigInt::zero()], b"Zcash_RedJubjubH"); assert!(result > BigInt::zero()); } #[test] fn create_hash_from_ge_test() { let point = GE::base_point2(); - let result1 = - Blake::create_hash_from_ge(&vec![&point, &GE::generator()], b"Zcash_RedJubjubH"); + let result1 = Blake::create_hash_from_ge(&[&point, &GE::generator()], b"Zcash_RedJubjubH"); assert!(result1.to_big_int().to_str_radix(2).len() > 240); - let result2 = - Blake::create_hash_from_ge(&vec![&GE::generator(), &point], b"Zcash_RedJubjubH"); + let result2 = Blake::create_hash_from_ge(&[&GE::generator(), &point], b"Zcash_RedJubjubH"); assert_ne!(result1, result2); - let result3 = - Blake::create_hash_from_ge(&vec![&GE::generator(), &point], b"Zcash_RedJubjubH"); + let result3 = Blake::create_hash_from_ge(&[&GE::generator(), &point], b"Zcash_RedJubjubH"); assert_eq!(result2, result3); } } diff --git a/src/cryptographic_primitives/hashing/hash_sha256.rs b/src/cryptographic_primitives/hashing/hash_sha256.rs index e7b72827..d3b962d6 100644 --- a/src/cryptographic_primitives/hashing/hash_sha256.rs +++ b/src/cryptographic_primitives/hashing/hash_sha256.rs @@ -59,14 +59,14 @@ mod tests { // https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing#shavs fn vector_sha256_test() { // Empty Message - let result: BigInt = HSha256::create_hash(&vec![]); + let result: BigInt = HSha256::create_hash(&[]); assert_eq!( result.to_str_radix(16), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ); // 256 bit message - let result: BigInt = HSha256::create_hash(&vec![&BigInt::from_str_radix( + let result: BigInt = HSha256::create_hash(&[&BigInt::from_str_radix( "09fc1accc230a205e4a208e64a8f204291f581a12756392da4b8c0cf5ef02b95", 16, ) @@ -77,7 +77,7 @@ mod tests { ); // 2x128 bit messages - let result: BigInt = HSha256::create_hash(&vec![ + let result: BigInt = HSha256::create_hash(&[ &BigInt::from_str_radix("09fc1accc230a205e4a208e64a8f2042", 16).unwrap(), &BigInt::from_str_radix("91f581a12756392da4b8c0cf5ef02b95", 16).unwrap(), ]); @@ -87,7 +87,7 @@ mod tests { ); // 512 bit message - let result: BigInt = HSha256::create_hash(&vec![&BigInt::from_str_radix("5a86b737eaea8ee976a0a24da63e7ed7eefad18a101c1211e2b3650c5187c2a8a650547208251f6d4237e661c7bf4c77f335390394c37fa1a9f9be836ac28509", 16).unwrap()]); + let result: BigInt = HSha256::create_hash(&[&BigInt::from_str_radix("5a86b737eaea8ee976a0a24da63e7ed7eefad18a101c1211e2b3650c5187c2a8a650547208251f6d4237e661c7bf4c77f335390394c37fa1a9f9be836ac28509", 16).unwrap()]); assert_eq!( result.to_str_radix(16), "42e61e174fbb3897d6dd6cef3dd2802fe67b331953b06114a65c772859dfc1aa" @@ -97,11 +97,11 @@ mod tests { #[test] fn create_sha256_from_ge_test() { let point = GE::base_point2(); - let result1 = HSha256::create_hash_from_ge(&vec![&point, &GE::generator()]); + let result1 = HSha256::create_hash_from_ge(&[&point, &GE::generator()]); assert!(result1.to_big_int().to_str_radix(2).len() > 240); - let result2 = HSha256::create_hash_from_ge(&vec![&GE::generator(), &point]); + let result2 = HSha256::create_hash_from_ge(&[&GE::generator(), &point]); assert_ne!(result1, result2); - let result3 = HSha256::create_hash_from_ge(&vec![&GE::generator(), &point]); + let result3 = HSha256::create_hash_from_ge(&[&GE::generator(), &point]); assert_eq!(result2, result3); } } diff --git a/src/cryptographic_primitives/hashing/hash_sha512.rs b/src/cryptographic_primitives/hashing/hash_sha512.rs index 3be49fcf..9a366b6c 100644 --- a/src/cryptographic_primitives/hashing/hash_sha512.rs +++ b/src/cryptographic_primitives/hashing/hash_sha512.rs @@ -59,14 +59,14 @@ mod tests { // https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing#shavs fn vector_sha512_test() { // Empty message - let result: BigInt = HSha512::create_hash(&vec![]); + let result: BigInt = HSha512::create_hash(&[]); assert_eq!( result.to_str_radix(16), "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" ); // 2x256 bit message - let result: BigInt = HSha512::create_hash(&vec![ + let result: BigInt = HSha512::create_hash(&[ &BigInt::from_str_radix( "c1ca70ae1279ba0b918157558b4920d6b7fba8a06be515170f202fafd36fb7f7", 16, @@ -84,7 +84,7 @@ mod tests { ); // 512 bit message - let result: BigInt = HSha512::create_hash(&vec![&BigInt::from_str_radix( + let result: BigInt = HSha512::create_hash(&[&BigInt::from_str_radix( "c1ca70ae1279ba0b918157558b4920d6b7fba8a06be515170f202fafd36fb7f79d69fad745dba6150568db1e2b728504113eeac34f527fc82f2200b462ecbf5d", 16, ) @@ -95,7 +95,7 @@ mod tests { ); // 1024 bit message - let result: BigInt = HSha512::create_hash(&vec![&BigInt::from_str_radix("fd2203e467574e834ab07c9097ae164532f24be1eb5d88f1af7748ceff0d2c67a21f4e4097f9d3bb4e9fbf97186e0db6db0100230a52b453d421f8ab9c9a6043aa3295ea20d2f06a2f37470d8a99075f1b8a8336f6228cf08b5942fc1fb4299c7d2480e8e82bce175540bdfad7752bc95b577f229515394f3ae5cec870a4b2f8", 16).unwrap()]); + let result: BigInt = HSha512::create_hash(&[&BigInt::from_str_radix("fd2203e467574e834ab07c9097ae164532f24be1eb5d88f1af7748ceff0d2c67a21f4e4097f9d3bb4e9fbf97186e0db6db0100230a52b453d421f8ab9c9a6043aa3295ea20d2f06a2f37470d8a99075f1b8a8336f6228cf08b5942fc1fb4299c7d2480e8e82bce175540bdfad7752bc95b577f229515394f3ae5cec870a4b2f8", 16).unwrap()]); assert_eq!( result.to_str_radix(16), "a21b1077d52b27ac545af63b32746c6e3c51cb0cb9f281eb9f3580a6d4996d5c9917d2a6e484627a9d5a06fa1b25327a9d710e027387fc3e07d7c4d14c6086cc" @@ -105,11 +105,11 @@ mod tests { #[test] fn create_sha512_from_ge_test() { let point = GE::base_point2(); - let result1 = HSha512::create_hash_from_ge(&vec![&point, &GE::generator()]); + let result1 = HSha512::create_hash_from_ge(&[&point, &GE::generator()]); assert!(result1.to_big_int().to_str_radix(2).len() > 240); - let result2 = HSha512::create_hash_from_ge(&vec![&GE::generator(), &point]); + let result2 = HSha512::create_hash_from_ge(&[&GE::generator(), &point]); assert_ne!(result1, result2); - let result3 = HSha512::create_hash_from_ge(&vec![&GE::generator(), &point]); + let result3 = HSha512::create_hash_from_ge(&[&GE::generator(), &point]); assert_eq!(result2, result3); } } diff --git a/src/cryptographic_primitives/hashing/hmac_sha512.rs b/src/cryptographic_primitives/hashing/hmac_sha512.rs index 503e0846..b4b54030 100644 --- a/src/cryptographic_primitives/hashing/hmac_sha512.rs +++ b/src/cryptographic_primitives/hashing/hmac_sha512.rs @@ -44,16 +44,16 @@ mod tests { #[test] fn create_hmac_test() { let key = BigInt::sample(512); - let result1 = HMacSha512::create_hmac(&key, &vec![&BigInt::from(10)]); + let result1 = HMacSha512::create_hmac(&key, &[&BigInt::from(10)]); let key2 = BigInt::sample(512); // same data , different key - let result2 = HMacSha512::create_hmac(&key2, &vec![&BigInt::from(10)]); + let result2 = HMacSha512::create_hmac(&key2, &[&BigInt::from(10)]); assert_ne!(result1, result2); // same key , different data - let result3 = HMacSha512::create_hmac(&key, &vec![&BigInt::from(10), &BigInt::from(11)]); + let result3 = HMacSha512::create_hmac(&key, &[&BigInt::from(10), &BigInt::from(11)]); assert_ne!(result1, result3); // same key, same data - let result4 = HMacSha512::create_hmac(&key, &vec![&BigInt::from(10)]); + let result4 = HMacSha512::create_hmac(&key, &[&BigInt::from(10)]); assert_eq!(result1, result4) } } diff --git a/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_enc.rs b/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_enc.rs index c83c5814..75f2fc5c 100644 --- a/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_enc.rs +++ b/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_enc.rs @@ -93,11 +93,11 @@ mod tests { }; let G: GE = ECPoint::generator(); let h: FE = ECScalar::new_random(); - let H = &G * &h; + let H = G * h; let y: FE = ECScalar::new_random(); - let Y = &G * &y; - let D = &H * &witness.x + Y.clone() * &witness.r; - let E = G.clone() * &witness.r; + let Y = G * y; + let D = H * witness.x + Y * witness.r; + let E = G * witness.r; let delta = HomoElGamalStatement { G, H, Y, D, E }; let proof = HomoELGamalProof::prove(&witness, &delta); assert!(proof.verify(&delta).is_ok()); @@ -111,16 +111,10 @@ mod tests { }; let G: GE = GE::generator(); let y: FE = FE::new_random(); - let Y = &G * &y; - let D = &G * &witness.x + Y.clone() * &witness.r; - let E = G.clone() * &witness.r; - let delta = HomoElGamalStatement { - G: G.clone(), - H: G, - Y, - D, - E, - }; + let Y = G * y; + let D = G * witness.x + Y * witness.r; + let E = G * witness.r; + let delta = HomoElGamalStatement { G, H: G, Y, D, E }; let proof = HomoELGamalProof::prove(&witness, &delta); assert!(proof.verify(&delta).is_ok()); } @@ -135,11 +129,11 @@ mod tests { }; let G: GE = ECPoint::generator(); let h: FE = ECScalar::new_random(); - let H = &G * &h; + let H = G * h; let y: FE = ECScalar::new_random(); - let Y = &G * &y; - let D = &H * &witness.x + Y.clone() * &witness.r; - let E = &G * &witness.r + G.clone(); + let Y = G * y; + let D = H * witness.x + Y * witness.r; + let E = G * witness.r + G; let delta = HomoElGamalStatement { G, H, Y, D, E }; let proof = HomoELGamalProof::prove(&witness, &delta); assert!(proof.verify(&delta).is_ok()); diff --git a/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_encryption_of_dlog.rs b/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_encryption_of_dlog.rs index efd2ffb7..fb65fb22 100644 --- a/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_encryption_of_dlog.rs +++ b/src/cryptographic_primitives/proofs/sigma_correct_homomorphic_elgamal_encryption_of_dlog.rs @@ -96,10 +96,10 @@ mod tests { }; let G: GE = ECPoint::generator(); let y: FE = ECScalar::new_random(); - let Y = G.clone() * &y; - let D = G.clone() * &witness.x + Y.clone() * &witness.r; - let E = G.clone() * &witness.r; - let Q = G.clone() * &witness.x; + let Y = G * y; + let D = G * witness.x + Y * witness.r; + let E = G * witness.r; + let Q = G * witness.x; let delta = HomoElGamalDlogStatement { G, Y, Q, D, E }; let proof = HomoELGamalDlogProof::prove(&witness, &delta); assert!(proof.verify(&delta).is_ok()); @@ -116,10 +116,10 @@ mod tests { }; let G: GE = ECPoint::generator(); let y: FE = ECScalar::new_random(); - let Y = G.clone() * &y; - let D = G.clone() * &witness.x + Y.clone() * &witness.r; - let E = G.clone() * &witness.r + G.clone(); - let Q = G.clone() * &witness.x + G.clone(); + let Y = G * y; + let D = G * witness.x + Y * witness.r; + let E = G * witness.r + G; + let Q = G * witness.x + G; let delta = HomoElGamalDlogStatement { G, Y, Q, D, E }; let proof = HomoELGamalDlogProof::prove(&witness, &delta); assert!(proof.verify(&delta).is_ok()); diff --git a/src/cryptographic_primitives/proofs/sigma_dlog.rs b/src/cryptographic_primitives/proofs/sigma_dlog.rs index 5052e0c7..dce9fb69 100644 --- a/src/cryptographic_primitives/proofs/sigma_dlog.rs +++ b/src/cryptographic_primitives/proofs/sigma_dlog.rs @@ -99,9 +99,7 @@ mod tests { let witness: FE = ECScalar::new_random(); let dlog_proof = DLogProof::prove(&witness); let verified = DLogProof::verify(&dlog_proof); - match verified { - Ok(_t) => assert!(true), - Err(_e) => assert!(false), - } + + assert!(verified.is_ok()) } } diff --git a/src/cryptographic_primitives/proofs/sigma_ec_ddh.rs b/src/cryptographic_primitives/proofs/sigma_ec_ddh.rs index 8d2cdcea..5a59b969 100644 --- a/src/cryptographic_primitives/proofs/sigma_ec_ddh.rs +++ b/src/cryptographic_primitives/proofs/sigma_ec_ddh.rs @@ -91,8 +91,8 @@ mod tests { let x: FE = ECScalar::new_random(); let g1: GE = ECPoint::generator(); let g2: GE = GE::base_point2(); - let h1 = &g1 * &x; - let h2 = &g2 * &x; + let h1 = g1 * x; + let h2 = g2 * x; let delta = ECDDHStatement { g1, g2, h1, h2 }; let w = ECDDHWitness { x }; let proof = ECDDHProof::prove(&w, &delta); @@ -106,8 +106,8 @@ mod tests { let g1: GE = ECPoint::generator(); let g2: GE = GE::base_point2(); let x2: FE = ECScalar::new_random(); - let h1 = &g1 * &x; - let h2 = &g2 * &x2; + let h1 = g1 * x; + let h2 = g2 * x2; let delta = ECDDHStatement { g1, g2, h1, h2 }; let w = ECDDHWitness { x }; let proof = ECDDHProof::prove(&w, &delta); diff --git a/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs b/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs index 315cb3c1..e26a4407 100644 --- a/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs +++ b/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs @@ -41,7 +41,7 @@ pub trait ProvePederesen { } impl ProvePederesen for PedersenProof { - fn prove(m: &FE, r: &FE) -> PedersenProof { + fn prove(msg: &FE, blind_factor: &FE) -> PedersenProof { let g: GE = ECPoint::generator(); let h = GE::base_point2(); let mut s1: FE = ECScalar::new_random(); @@ -49,8 +49,8 @@ impl ProvePederesen for PedersenProof { let a1 = g.scalar_mul(&s1.get_element()); let a2 = h.scalar_mul(&s2.get_element()); let com = PedersenCommitment::create_commitment_with_user_defined_randomness( - &m.to_big_int(), - &r.to_big_int(), + &msg.to_big_int(), + &blind_factor.to_big_int(), ); let g: GE = ECPoint::generator(); let challenge = HSha256::create_hash(&[ @@ -63,9 +63,9 @@ impl ProvePederesen for PedersenProof { let e: FE = ECScalar::from(&challenge); - let em = e.mul(&m.get_element()); + let em = e.mul(&msg.get_element()); let z1 = s1.add(&em.get_element()); - let er = e.mul(&r.get_element()); + let er = e.mul(&blind_factor.get_element()); let z2 = s2.add(&er.get_element()); s1.zeroize(); s2.zeroize(); diff --git a/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs b/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs index 6eb4a927..c85ea609 100644 --- a/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs +++ b/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs @@ -40,33 +40,33 @@ pub trait ProvePederesenBlind { } impl ProvePederesenBlind for PedersenBlindingProof { //TODO: add self verification to prover proof - fn prove(m: &FE, r: &FE) -> PedersenBlindingProof { - let h = GE::base_point2(); + fn prove(msg: &FE, blind_factor: &FE) -> PedersenBlindingProof { + let base_point = GE::base_point2(); let mut s: FE = ECScalar::new_random(); - let a = h.scalar_mul(&s.get_element()); + let a = base_point.scalar_mul(&s.get_element()); let com = PedersenCommitment::create_commitment_with_user_defined_randomness( - &m.to_big_int(), - &r.to_big_int(), + &msg.to_big_int(), + &blind_factor.to_big_int(), ); let g: GE = ECPoint::generator(); let challenge = HSha256::create_hash(&[ &g.bytes_compressed_to_big_int(), - &h.bytes_compressed_to_big_int(), + &base_point.bytes_compressed_to_big_int(), &com.bytes_compressed_to_big_int(), &a.bytes_compressed_to_big_int(), - &m.to_big_int(), + &msg.to_big_int(), ]); - let e: FE = ECScalar::from(&challenge); - let er = e.mul(&r.get_element()); - let z = s.add(&er.get_element()); + let e: FE = ECScalar::from(&challenge); + let er = e.mul(&blind_factor.get_element()); s.zeroize(); + PedersenBlindingProof { e, - m: *m, + m: *msg, a, com, - z, + z: s.add(&er.get_element()), } } @@ -109,7 +109,6 @@ mod tests { let m: FE = ECScalar::new_random(); let r: FE = ECScalar::new_random(); let pedersen_proof = PedersenBlindingProof::prove(&m, &r); - let _verified = - PedersenBlindingProof::verify(&pedersen_proof).expect("error pedersen blind"); + PedersenBlindingProof::verify(&pedersen_proof).expect("error pedersen blind"); } } diff --git a/src/cryptographic_primitives/secret_sharing/feldman_vss.rs b/src/cryptographic_primitives/secret_sharing/feldman_vss.rs index dbab3eb7..b6d70e36 100644 --- a/src/cryptographic_primitives/secret_sharing/feldman_vss.rs +++ b/src/cryptographic_primitives/secret_sharing/feldman_vss.rs @@ -67,9 +67,7 @@ impl VerifiableSS { let secret_shares = VerifiableSS::evaluate_polynomial(&poly, index_vec); let G: GE = ECPoint::generator(); - let commitments = (0..poly.len()) - .map(|i| G.clone() * &poly[i]) - .collect::>(); + let commitments = (0..poly.len()).map(|i| G * poly[i]).collect::>(); ( VerifiableSS { parameters: ShamirSecretSharing { @@ -197,8 +195,7 @@ impl VerifiableSS { let mut comm_iterator = self.commitments.iter().rev(); let head = comm_iterator.next().unwrap(); let tail = comm_iterator; - let comm_to_point = tail.fold(head.clone(), |acc, x: &GE| *x + acc * index_fe); - comm_to_point + tail.fold(head.clone(), |acc, x: &GE| *x + acc * index_fe) } //compute \lambda_{index,S}, a lagrangian coefficient that change the (t,n) scheme to (|S|,|S|) @@ -255,7 +252,7 @@ mod tests { shares_vec.push(secret_shares[4].clone()); //test reconstruction - let secret_reconstructed = vss_scheme.reconstruct(&vec![0, 1, 4, 5], &shares_vec); + let secret_reconstructed = vss_scheme.reconstruct(&[0, 1, 4, 5], &shares_vec); assert_eq!(secret, secret_reconstructed); } @@ -272,7 +269,7 @@ mod tests { shares_vec.push(secret_shares[4].clone()); //test reconstruction - let secret_reconstructed = vss_scheme.reconstruct(&vec![0, 1, 2, 4], &shares_vec); + let secret_reconstructed = vss_scheme.reconstruct(&[0, 1, 2, 4], &shares_vec); assert_eq!(secret, secret_reconstructed); // test secret shares are verifiable @@ -282,7 +279,7 @@ mod tests { assert!(valid1.is_ok()); let g: GE = GE::generator(); - let share1_public = g * &secret_shares[0]; + let share1_public = g * secret_shares[0]; let valid1_public = vss_scheme.validate_share_public(&share1_public, 1); assert!(valid1_public.is_ok()); @@ -293,11 +290,11 @@ mod tests { let l2 = vss_scheme.map_share_to_new_params(2, &s); let l3 = vss_scheme.map_share_to_new_params(3, &s); let l4 = vss_scheme.map_share_to_new_params(4, &s); - let w = l0 * secret_shares[0].clone() - + l1 * secret_shares[1].clone() - + l2 * secret_shares[2].clone() - + l3 * secret_shares[3].clone() - + l4 * secret_shares[4].clone(); + let w = l0 * secret_shares[0] + + l1 * secret_shares[1] + + l2 * secret_shares[2] + + l3 * secret_shares[3] + + l4 * secret_shares[4]; assert_eq!(w, secret_reconstructed); } @@ -314,7 +311,7 @@ mod tests { shares_vec.push(secret_shares[4].clone()); //test reconstruction - let secret_reconstructed = vss_scheme.reconstruct(&vec![0, 6, 2, 4], &shares_vec); + let secret_reconstructed = vss_scheme.reconstruct(&[0, 6, 2, 4], &shares_vec); assert_eq!(secret, secret_reconstructed); // test secret shares are verifiable @@ -330,11 +327,11 @@ mod tests { let l3 = vss_scheme.map_share_to_new_params(3, &s); let l4 = vss_scheme.map_share_to_new_params(4, &s); let l6 = vss_scheme.map_share_to_new_params(6, &s); - let w = l0 * secret_shares[0].clone() - + l1 * secret_shares[1].clone() - + l3 * secret_shares[3].clone() - + l4 * secret_shares[4].clone() - + l6 * secret_shares[6].clone(); + let w = l0 * secret_shares[0] + + l1 * secret_shares[1] + + l3 * secret_shares[3] + + l4 * secret_shares[4] + + l6 * secret_shares[6]; assert_eq!(w, secret_reconstructed); } @@ -349,7 +346,7 @@ mod tests { shares_vec.push(secret_shares[1].clone()); //test reconstruction - let secret_reconstructed = vss_scheme.reconstruct(&vec![0, 1], &shares_vec); + let secret_reconstructed = vss_scheme.reconstruct(&[0, 1], &shares_vec); assert_eq!(secret, secret_reconstructed); // test secret shares are verifiable @@ -363,7 +360,7 @@ mod tests { let l0 = vss_scheme.map_share_to_new_params(0, &s); let l1 = vss_scheme.map_share_to_new_params(1, &s); - let w = l0 * secret_shares[0].clone() + l1 * secret_shares[1].clone(); + let w = l0 * secret_shares[0] + l1 * secret_shares[1]; assert_eq!(w, secret_reconstructed); } @@ -379,19 +376,19 @@ mod tests { // test commitment to point and sum of commitments let (vss_scheme2, secret_shares2) = VerifiableSS::share(1, 3, &secret); - let sum = secret_shares[0].clone() + secret_shares2[0].clone(); + let sum = secret_shares[0] + secret_shares2[0]; let point_comm1 = vss_scheme.get_point_commitment(1); let point_comm2 = vss_scheme.get_point_commitment(2); let g: GE = GE::generator(); - let g_sum = g.clone() * ∑ - assert_eq!(g.clone() * secret_shares[0].clone(), point_comm1.clone()); - assert_eq!(g.clone() * secret_shares[1].clone(), point_comm2.clone()); + let g_sum = g * sum; + assert_eq!(g * secret_shares[0], point_comm1.clone()); + assert_eq!(g * secret_shares[1], point_comm2.clone()); let point1_sum_com = vss_scheme.get_point_commitment(1) + vss_scheme2.get_point_commitment(1); assert_eq!(point1_sum_com, g_sum); //test reconstruction - let secret_reconstructed = vss_scheme.reconstruct(&vec![0, 1], &shares_vec); + let secret_reconstructed = vss_scheme.reconstruct(&[0, 1], &shares_vec); assert_eq!(secret, secret_reconstructed); // test secret shares are verifiable @@ -405,7 +402,7 @@ mod tests { let l0 = vss_scheme.map_share_to_new_params(0, &s); let l2 = vss_scheme.map_share_to_new_params(2, &s); - let w = l0 * secret_shares[0].clone() + l2 * secret_shares[2].clone(); + let w = l0 * secret_shares[0] + l2 * secret_shares[2]; assert_eq!(w, secret_reconstructed); } } diff --git a/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs b/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs index 8c4ec2b7..363d715c 100644 --- a/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs +++ b/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs @@ -57,7 +57,7 @@ impl Party1SecondMessage { ( Party1SecondMessage { proof, - seed: party1seed.clone(), + seed: *party1seed, }, ECScalar::from(&coin_flip_result), )