Skip to content

Commit

Permalink
fix clippy warns
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas committed Sep 4, 2019
1 parent c33f00d commit 9a93c9f
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 118 deletions.
3 changes: 1 addition & 2 deletions examples/pedersen_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 2 additions & 4 deletions examples/proof_of_knowledge_of_dlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions examples/verifiable_secret_sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());

Expand All @@ -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);
}

Expand Down
12 changes: 4 additions & 8 deletions src/cryptographic_primitives/hashing/blake2b512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 7 additions & 7 deletions src/cryptographic_primitives/hashing/hash_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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(),
]);
Expand All @@ -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"
Expand All @@ -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);
}
}
14 changes: 7 additions & 7 deletions src/cryptographic_primitives/hashing/hash_sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand All @@ -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"
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/cryptographic_primitives/hashing/hmac_sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
6 changes: 2 additions & 4 deletions src/cryptographic_primitives/proofs/sigma_dlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
8 changes: 4 additions & 4 deletions src/cryptographic_primitives/proofs/sigma_ec_ddh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/cryptographic_primitives/proofs/sigma_valid_pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ 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();
let mut s2: FE = ECScalar::new_random();
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(&[
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 9a93c9f

Please sign in to comment.