From 9aba39727212908817074118d3a8a9ed870e7254 Mon Sep 17 00:00:00 2001 From: porcuquine Date: Thu, 20 Jan 2022 22:23:04 -0800 Subject: [PATCH] Clippy --- src/circuit.rs | 2 +- src/matrix.rs | 14 +++++++------- src/mds.rs | 2 +- src/poseidon.rs | 10 +++++----- src/preprocessing.rs | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/circuit.rs b/src/circuit.rs index f65fa4c1..a44581f5 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -274,7 +274,7 @@ where let index = self.current_round - sparse_offset - 1; let sparse_matrix = &self.constants.sparse_matrixes[index]; - self.product_mds_with_sparse_matrix::(&sparse_matrix)?; + self.product_mds_with_sparse_matrix::(sparse_matrix)?; } else { self.product_mds_m::()?; } diff --git a/src/matrix.rs b/src/matrix.rs index 4062900b..4043f757 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -70,7 +70,7 @@ pub fn mat_mul(a: &Matrix, b: &Matrix) -> Option> .iter() .map(|input_row| { b_t.iter() - .map(|transposed_column| vec_mul(&input_row, &transposed_column)) + .map(|transposed_column| vec_mul(input_row, transposed_column)) .collect() }) .collect(); @@ -251,7 +251,7 @@ fn eliminate( let mut factor = val; factor.mul_assign(&inv_pivot); - let scaled_pivot = scalar_vec_mul(factor, &pivot); + let scaled_pivot = scalar_vec_mul(factor, pivot); let eliminated = vec_sub(row, &scaled_pivot); result.push(eliminated); @@ -271,7 +271,7 @@ fn eliminate( // `matrix` must be square. fn upper_triangular( matrix: &Matrix, - mut shadow: &mut Matrix, + shadow: &mut Matrix, ) -> Option> { assert!(is_square(matrix)); let mut result = Vec::with_capacity(matrix.len()); @@ -282,7 +282,7 @@ fn upper_triangular( while curr.len() > 1 { let initial_rows = curr.len(); - curr = eliminate(&curr, column, &mut shadow)?; + curr = eliminate(&curr, column, shadow)?; result.push(curr[0].clone()); shadow_result.push(shadow[0].clone()); column += 1; @@ -323,8 +323,8 @@ fn reduce_to_identity( inv.unwrap() }; - let mut normalized = scalar_vec_mul(inv, &row); - let mut shadow_normalized = scalar_vec_mul(inv, &shadow_row); + let mut normalized = scalar_vec_mul(inv, row); + let mut shadow_normalized = scalar_vec_mul(inv, shadow_row); for j in 0..i { let idx = size - j - 1; @@ -350,7 +350,7 @@ fn reduce_to_identity( // pub(crate) fn invert(matrix: &Matrix) -> Option> { let mut shadow = make_identity(columns(matrix)); - let ut = upper_triangular(&matrix, &mut shadow); + let ut = upper_triangular(matrix, &mut shadow); ut.and_then(|x| reduce_to_identity(&x, &mut shadow)) .and(Some(shadow)) diff --git a/src/mds.rs b/src/mds.rs index 6c49a0fd..04700318 100644 --- a/src/mds.rs +++ b/src/mds.rs @@ -64,7 +64,7 @@ impl SparseMatrix { } pub fn is_sparse_matrix(m: &Matrix) -> bool { - is_square(&m) && is_identity(&minor(&m, 0, 0)) + is_square(m) && is_identity(&minor(m, 0, 0)) } pub fn size(&self) -> usize { diff --git a/src/poseidon.rs b/src/poseidon.rs index 7ac7b70d..fd4bc9ce 100644 --- a/src/poseidon.rs +++ b/src/poseidon.rs @@ -315,7 +315,7 @@ where /// Panics if the provided slice is bigger than the arity. pub fn set_preimage(&mut self, preimage: &[F]) { self.reset(); - self.elements[1..].copy_from_slice(&preimage); + self.elements[1..].copy_from_slice(preimage); self.pos = self.elements.len(); } @@ -497,7 +497,7 @@ where let index = self.current_round - sparse_offset - 1; let sparse_matrix = &self.constants.sparse_matrixes[index]; - self.product_mds_with_sparse_matrix(&sparse_matrix); + self.product_mds_with_sparse_matrix(sparse_matrix); } else { self.product_mds(); } @@ -606,7 +606,7 @@ where pub fn encrypt(&mut self, key: &[F], plaintext: &[F]) -> Result<(Vec, F), Error> { // https://link.springer.com/content/pdf/10.1007%2F978-3-642-28496-0_19.pdf let arity = A::to_usize(); - assert!(key.len() > 0); + assert!(!key.is_empty()); self.shared_initialize(key, plaintext.len())?; @@ -625,7 +625,7 @@ where pub fn decrypt(&mut self, key: &[F], ciphertext: &[F], tag: &F) -> Result, Error> { let arity = A::to_usize(); - assert!(key.len() > 0); + assert!(!key.is_empty()); self.shared_initialize(key, ciphertext.len())?; let mut plaintext = Vec::with_capacity(ciphertext.len()); @@ -682,7 +682,7 @@ where fn hash(&mut self, preimages: &[GenericArray]) -> Result, Error> { Ok(preimages .iter() - .map(|preimage| Poseidon::new_with_preimage(&preimage, &self.constants).hash()) + .map(|preimage| Poseidon::new_with_preimage(preimage, &self.constants).hash()) .collect()) } diff --git a/src/preprocessing.rs b/src/preprocessing.rs index e68b1b67..4dda965f 100644 --- a/src/preprocessing.rs +++ b/src/preprocessing.rs @@ -66,7 +66,7 @@ pub(crate) fn compress_round_constants( partial_keys.push(inverted[0]); inverted[0] = F::zero(); - vec_add(&previous_round_keys, &inverted) + vec_add(previous_round_keys, &inverted) }); // Everything in here is dev-driven testing. @@ -95,7 +95,7 @@ pub(crate) fn compress_round_constants( inv[0] = F::zero(); // (M^-1(T) - pk) - I - let result_key = vec_add(&initial_round_keys, &inv); + let result_key = vec_add(initial_round_keys, &inv); assert_eq!(&result_key, &round_acc, "Acc assumption failed."); assert_eq!(pk, partial_keys[0], "Partial-key assumption failed."); @@ -144,7 +144,7 @@ pub(crate) fn compress_round_constants( quintic_s_box(&mut p_state[0], None, Some(&pk)); - let preprocessed_result = apply_matrix(&mds_matrix, &p_state); + let preprocessed_result = apply_matrix(mds_matrix, &p_state); assert_eq!( plain_result, preprocessed_result,