Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis committed Aug 5, 2021
1 parent 957a29f commit 8c9172e
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions examples/verifiable_secret_sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ pub fn secret_sharing_3_out_of_5<E: Curve>() {

// test map (t,n) - (t',t')
let s = &vec![0, 1, 2, 3, 4];
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, &s);
let l2 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 2, &s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, &s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, &s);
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, s);
let l2 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 2, s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, s);

let w = l0 * secret_shares[0].clone()
+ l1 * secret_shares[1].clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<E: Curve> LdeiProof<E> {
.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 {
Expand Down Expand Up @@ -197,7 +197,7 @@ mod tests {
let poly = Polynomial::<E>::sample_exact(5);
let witness = LdeiWitness { w: poly };

let alpha: Vec<Scalar<E>> = (1..=10).map(|i| Scalar::from(i)).collect();
let alpha: Vec<Scalar<E>> = (1..=10).map(Scalar::from).collect();
let g: Vec<Point<E>> = iter::repeat_with(Scalar::random)
.map(|x| Point::generator() * x)
.take(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<E: Curve> PedersenProof<E> {
let h = Point::<E>::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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<E: Curve> PedersenBlindingProof<E> {
let g = Point::<E>::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;
Expand Down
30 changes: 15 additions & 15 deletions src/cryptographic_primitives/secret_sharing/feldman_vss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<E: Curve> VerifiableSS<E> {
.iter()
.map(|i| Scalar::from(*i + 1))
.collect::<Vec<_>>();
VerifiableSS::<E>::lagrange_interpolation_at_zero(&points, &shares)
VerifiableSS::<E>::lagrange_interpolation_at_zero(&points, shares)
}

// Performs a Lagrange interpolation in field Zp at the origin
Expand Down Expand Up @@ -355,11 +355,11 @@ mod tests {

// test map (t,n) - (t',t')
let s = &vec![0, 1, 2, 3, 4];
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, &s);
let l2 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 2, &s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, &s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, &s);
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, s);
let l2 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 2, s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, s);
let w = l0 * &secret_shares[0]
+ l1 * &secret_shares[1]
+ l2 * &secret_shares[2]
Expand Down Expand Up @@ -394,11 +394,11 @@ mod tests {

// test map (t,n) - (t',t')
let s = &vec![0, 1, 3, 4, 6];
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, &s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, &s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, &s);
let l6 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 6, &s);
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, s);
let l6 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 6, s);

let w = l0 * &secret_shares[0]
+ l1 * &secret_shares[1]
Expand Down Expand Up @@ -429,8 +429,8 @@ mod tests {

// test map (t,n) - (t',t')
let s = &vec![0, 1];
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, &s);
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, s);
let l1 = VerifiableSS::<E>::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);
}
Expand Down Expand Up @@ -469,8 +469,8 @@ mod tests {

// test map (t,n) - (t',t')
let s = &vec![0, 2];
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l2 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 2, &s);
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, s);
let l2 = VerifiableSS::<E>::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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<E: Curve> Party1FirstMessage<E> {
}
impl<E: Curve> Party2FirstMessage<E> {
pub fn share(proof: &PedersenProof<E>) -> Party2FirstMessage<E> {
PedersenProof::verify(&proof).expect("{(m,r),c} proof failed");
PedersenProof::verify(proof).expect("{(m,r),c} proof failed");
let seed = Scalar::random();
Party2FirstMessage { seed }
}
Expand All @@ -54,7 +54,7 @@ impl<E: Curve> Party1SecondMessage<E> {
party1seed: &Scalar<E>,
party1blinding: &Scalar<E>,
) -> (Party1SecondMessage<E>, Scalar<E>) {
let proof = PedersenBlindingProof::<E>::prove(&party1seed, &party1blinding);
let proof = PedersenBlindingProof::<E>::prove(party1seed, party1blinding);
let coin_flip_result = &party1seed.to_bigint() ^ &party2seed.to_bigint();
(
Party1SecondMessage {
Expand All @@ -72,7 +72,7 @@ pub fn finalize<E: Curve>(
party2seed: &Scalar<E>,
party1comm: &Point<E>,
) -> Scalar<E> {
PedersenBlindingProof::<E>::verify(&proof).expect("{r,(m,c)} proof failed");
PedersenBlindingProof::<E>::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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/elliptic/curves/curve_ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/elliptic/curves/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/elliptic/curves/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions src/elliptic/curves/secp256_k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }
Expand All @@ -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");
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/elliptic/curves/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn generator_mul_curve_order_is_zero<E: Curve>() {
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);
Expand All @@ -134,11 +134,11 @@ fn scalar_behaves_the_same_as_bigint<E: Curve>() {
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();
Expand Down

0 comments on commit 8c9172e

Please sign in to comment.