diff --git a/examples/verifiable_secret_sharing.rs b/examples/verifiable_secret_sharing.rs index 8eed3f2b..d093aa50 100644 --- a/examples/verifiable_secret_sharing.rs +++ b/examples/verifiable_secret_sharing.rs @@ -42,11 +42,11 @@ pub fn secret_sharing_3_out_of_5() { // test map (t,n) - (t',t') let s = &vec![0, 1, 2, 3, 4]; - let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, &s); - let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, &s); - let l2 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 2, &s); - let l3 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 3, &s); - let l4 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 4, &s); + let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, s); + let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, s); + let l2 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 2, s); + let l3 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 3, s); + let l4 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 4, s); let w = l0 * secret_shares[0].clone() + l1 * secret_shares[1].clone() diff --git a/src/cryptographic_primitives/proofs/low_degree_exponent_interpolation.rs b/src/cryptographic_primitives/proofs/low_degree_exponent_interpolation.rs index b7a0193f..bf677815 100644 --- a/src/cryptographic_primitives/proofs/low_degree_exponent_interpolation.rs +++ b/src/cryptographic_primitives/proofs/low_degree_exponent_interpolation.rs @@ -145,7 +145,7 @@ impl LdeiProof { .iter() .zip(&statement.alpha) .zip(&statement.x) - .map(|((g, a), x)| g * self.z.evaluate(&a) + x * &e) + .map(|((g, a), x)| g * self.z.evaluate(a) + x * &e) .collect(); if self.a == expected_a { @@ -197,7 +197,7 @@ mod tests { let poly = Polynomial::::sample_exact(5); let witness = LdeiWitness { w: poly }; - let alpha: Vec> = (1..=10).map(|i| Scalar::from(i)).collect(); + let alpha: Vec> = (1..=10).map(Scalar::from).collect(); let g: Vec> = iter::repeat_with(Scalar::random) .map(|x| Point::generator() * x) .take(10) diff --git a/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs b/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs index 2343cdc8..e0f16c09 100644 --- a/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs +++ b/src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs @@ -73,7 +73,7 @@ impl PedersenProof { let h = Point::::base_point2(); let e = Sha256::new() - .chain_points([&g.to_point(), &h, &proof.com, &proof.a1, &proof.a2]) + .chain_points([&g.to_point(), h, &proof.com, &proof.a1, &proof.a2]) .result_scalar(); let z1g = g * &proof.z1; diff --git a/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs b/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs index 3066616b..8122c316 100644 --- a/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs +++ b/src/cryptographic_primitives/proofs/sigma_valid_pedersen_blind.rs @@ -47,7 +47,7 @@ impl PedersenBlindingProof { let g = Point::::generator(); let e = Sha256::new() .chain_points([g.as_point(), h, &com, &a]) - .chain_scalar(&m) + .chain_scalar(m) .result_scalar(); let er = &e * r; diff --git a/src/cryptographic_primitives/secret_sharing/feldman_vss.rs b/src/cryptographic_primitives/secret_sharing/feldman_vss.rs index e1bd78a8..9b6c29fc 100644 --- a/src/cryptographic_primitives/secret_sharing/feldman_vss.rs +++ b/src/cryptographic_primitives/secret_sharing/feldman_vss.rs @@ -165,7 +165,7 @@ impl VerifiableSS { .iter() .map(|i| Scalar::from(*i + 1)) .collect::>(); - VerifiableSS::::lagrange_interpolation_at_zero(&points, &shares) + VerifiableSS::::lagrange_interpolation_at_zero(&points, shares) } // Performs a Lagrange interpolation in field Zp at the origin @@ -355,11 +355,11 @@ mod tests { // test map (t,n) - (t',t') let s = &vec![0, 1, 2, 3, 4]; - let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, &s); - let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, &s); - let l2 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 2, &s); - let l3 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 3, &s); - let l4 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 4, &s); + let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, s); + let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, s); + let l2 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 2, s); + let l3 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 3, s); + let l4 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 4, s); let w = l0 * &secret_shares[0] + l1 * &secret_shares[1] + l2 * &secret_shares[2] @@ -394,11 +394,11 @@ mod tests { // test map (t,n) - (t',t') let s = &vec![0, 1, 3, 4, 6]; - let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, &s); - let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, &s); - let l3 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 3, &s); - let l4 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 4, &s); - let l6 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 6, &s); + let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, s); + let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, s); + let l3 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 3, s); + let l4 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 4, s); + let l6 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 6, s); let w = l0 * &secret_shares[0] + l1 * &secret_shares[1] @@ -429,8 +429,8 @@ mod tests { // test map (t,n) - (t',t') let s = &vec![0, 1]; - let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, &s); - let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, &s); + let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, s); + let l1 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 1, s); let w = l0 * &secret_shares[0] + l1 * &secret_shares[1]; assert_eq!(w, secret_reconstructed); } @@ -469,8 +469,8 @@ mod tests { // test map (t,n) - (t',t') let s = &vec![0, 2]; - let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, &s); - let l2 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 2, &s); + let l0 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 0, s); + let l2 = VerifiableSS::::map_share_to_new_params(&vss_scheme.parameters, 2, s); 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 749b9f0b..f46b047a 100644 --- a/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs +++ b/src/cryptographic_primitives/twoparty/coin_flip_optimal_rounds.rs @@ -43,7 +43,7 @@ impl Party1FirstMessage { } impl Party2FirstMessage { pub fn share(proof: &PedersenProof) -> Party2FirstMessage { - PedersenProof::verify(&proof).expect("{(m,r),c} proof failed"); + PedersenProof::verify(proof).expect("{(m,r),c} proof failed"); let seed = Scalar::random(); Party2FirstMessage { seed } } @@ -54,7 +54,7 @@ impl Party1SecondMessage { party1seed: &Scalar, party1blinding: &Scalar, ) -> (Party1SecondMessage, Scalar) { - let proof = PedersenBlindingProof::::prove(&party1seed, &party1blinding); + let proof = PedersenBlindingProof::::prove(party1seed, party1blinding); let coin_flip_result = &party1seed.to_bigint() ^ &party2seed.to_bigint(); ( Party1SecondMessage { @@ -72,7 +72,7 @@ pub fn finalize( party2seed: &Scalar, party1comm: &Point, ) -> Scalar { - PedersenBlindingProof::::verify(&proof).expect("{r,(m,c)} proof failed"); + PedersenBlindingProof::::verify(proof).expect("{r,(m,c)} proof failed"); assert_eq!(&proof.com, party1comm); let coin_flip_result = &proof.m.to_bigint() ^ &party2seed.to_bigint(); Scalar::from(&coin_flip_result) diff --git a/src/cryptographic_primitives/twoparty/dh_key_exchange_variant_with_pok_comm.rs b/src/cryptographic_primitives/twoparty/dh_key_exchange_variant_with_pok_comm.rs index b9f2165c..d30b9904 100644 --- a/src/cryptographic_primitives/twoparty/dh_key_exchange_variant_with_pok_comm.rs +++ b/src/cryptographic_primitives/twoparty/dh_key_exchange_variant_with_pok_comm.rs @@ -215,7 +215,7 @@ impl Party2SecondMessage { if party_one_pk_commitment != &HashCommitment::create_commitment_with_user_defined_randomness( &BigInt::from_bytes(&party_one_public_share.to_bytes(true)), - &party_one_pk_commitment_blind_factor, + party_one_pk_commitment_blind_factor, ) { flag = false @@ -224,14 +224,14 @@ impl Party2SecondMessage { if party_one_zk_pok_commitment != &HashCommitment::create_commitment_with_user_defined_randomness( &BigInt::from_bytes(&party_one_d_log_proof.pk_t_rand_commitment.to_bytes(true)), - &party_one_zk_pok_blind_factor, + party_one_zk_pok_blind_factor, ) { flag = false }; assert!(flag); - DLogProof::verify(&party_one_d_log_proof)?; + DLogProof::verify(party_one_d_log_proof)?; Ok(Party2SecondMessage {}) } } diff --git a/src/elliptic/curves/curve_ristretto.rs b/src/elliptic/curves/curve_ristretto.rs index 24cf2bd8..7e88ac79 100644 --- a/src/elliptic/curves/curve_ristretto.rs +++ b/src/elliptic/curves/curve_ristretto.rs @@ -102,7 +102,7 @@ impl ECScalar for RistrettoScalar { fn from_bigint(n: &BigInt) -> RistrettoScalar { let curve_order = RistrettoScalar::group_order(); let mut bytes = n - .modulus(&curve_order) + .modulus(curve_order) .to_bytes_array::<32>() .expect("n mod curve_order must be equal or less than 32 bytes"); bytes.reverse(); diff --git a/src/elliptic/curves/ed25519.rs b/src/elliptic/curves/ed25519.rs index d3140a30..c242b397 100644 --- a/src/elliptic/curves/ed25519.rs +++ b/src/elliptic/curves/ed25519.rs @@ -151,7 +151,7 @@ impl ECScalar for Ed25519Scalar { } fn from_bigint(n: &BigInt) -> Ed25519Scalar { - let mut v = BigInt::to_bytes(&n); + let mut v = BigInt::to_bytes(n); if v.len() > TWO_TIMES_SECRET_KEY_SIZE { v = v[0..TWO_TIMES_SECRET_KEY_SIZE].to_vec(); } @@ -380,10 +380,10 @@ impl ECPoint for Ed25519Point { match byte_len { 0..=32 => { let mut template = vec![0; 32 - byte_len]; - template.extend_from_slice(&bytes); + template.extend_from_slice(bytes); let bytes_vec = template; let bytes_slice = &bytes_vec[0..32]; - bytes_array_32.copy_from_slice(&bytes_slice); + bytes_array_32.copy_from_slice(bytes_slice); let ge_from_bytes = PK::from_bytes_negate_vartime(&bytes_array_32); match ge_from_bytes { Some(_x) => { @@ -402,7 +402,7 @@ impl ECPoint for Ed25519Point { } _ => { let bytes_slice = &bytes_vec[0..32]; - bytes_array_32.copy_from_slice(&bytes_slice); + bytes_array_32.copy_from_slice(bytes_slice); let ge_from_bytes = PK::from_bytes_negate_vartime(bytes); match ge_from_bytes { Some(_x) => { @@ -521,7 +521,7 @@ fn expmod(b: &BigInt, e: &BigInt, m: &BigInt) -> BigInt { let t_temp = expmod(b, &(e.clone() / BigInt::from(2u32)), m); let mut t = BigInt::mod_pow(&t_temp, &BigInt::from(2u32), m); - if BigInt::modulus(&e, &BigInt::from(2)) != BigInt::zero() { + if BigInt::modulus(e, &BigInt::from(2)) != BigInt::zero() { t = BigInt::mod_mul(&t, b, m); } t diff --git a/src/elliptic/curves/p256.rs b/src/elliptic/curves/p256.rs index 2d4e6dfd..9ad20a9b 100644 --- a/src/elliptic/curves/p256.rs +++ b/src/elliptic/curves/p256.rs @@ -115,7 +115,7 @@ impl ECScalar for Secp256r1Scalar { fn from_bigint(n: &BigInt) -> Secp256r1Scalar { let curve_order = Secp256r1Scalar::group_order(); let n_reduced = n - .modulus(&curve_order) + .modulus(curve_order) .to_bytes_array::<32>() .expect("n mod curve_order must be equal or less than 32 bytes"); diff --git a/src/elliptic/curves/secp256_k1.rs b/src/elliptic/curves/secp256_k1.rs index 9724a92c..6055d2b3 100644 --- a/src/elliptic/curves/secp256_k1.rs +++ b/src/elliptic/curves/secp256_k1.rs @@ -443,7 +443,7 @@ impl ECPoint for Secp256k1Point { let ge = scalar .fe .as_ref() - .map(|sk| PK(PublicKey::from_secret_key(&SECP256K1, sk))); + .map(|sk| PK(PublicKey::from_secret_key(SECP256K1, sk))); Secp256k1Point { purpose: "generator_mul", ge, @@ -468,7 +468,7 @@ impl ECPoint for Secp256k1Point { fn neg_point(&self) -> Secp256k1Point { let ge = self.ge.map(|mut ge| { - ge.0.negate_assign(&SECP256K1); + ge.0.negate_assign(SECP256K1); ge }); Secp256k1Point { purpose: "neg", ge } @@ -480,7 +480,7 @@ impl ECPoint for Secp256k1Point { self.ge = None; } (Some(ge), Some(fe)) => { - ge.0.mul_assign(&SECP256K1, &fe.0[..]) + ge.0.mul_assign(SECP256K1, &fe.0[..]) .expect("Can't fail as it's a valid secret"); } }; diff --git a/src/elliptic/curves/test.rs b/src/elliptic/curves/test.rs index 2dc5dccd..3bf4bb27 100644 --- a/src/elliptic/curves/test.rs +++ b/src/elliptic/curves/test.rs @@ -109,7 +109,7 @@ fn generator_mul_curve_order_is_zero() { let g: &E::Point = ECPoint::generator(); let n = E::Scalar::group_order() - 1; let s = E::Scalar::from_bigint(&n); - assert!(g.scalar_mul(&s).add_point(&g).is_zero()); + assert!(g.scalar_mul(&s).add_point(g).is_zero()); } test_for_all_curves!(scalar_behaves_the_same_as_bigint); @@ -134,11 +134,11 @@ fn scalar_behaves_the_same_as_bigint() { n_inv .as_ref() .map(|i| i.to_string()) - .unwrap_or("None".to_string()), + .unwrap_or_else(|| "None".to_string()), s_inv .as_ref() .map(|i| i.to_string()) - .unwrap_or("None".to_string()), + .unwrap_or_else(|| "None".to_string()), ); } else { let n_was = n.clone();