diff --git a/benches/groups.rs b/benches/groups.rs index 87c80d02..50d6cdea 100644 --- a/benches/groups.rs +++ b/benches/groups.rs @@ -6,6 +6,7 @@ use bls12_381::*; use criterion::{black_box, Criterion}; +#[allow(clippy::many_single_char_names)] fn criterion_benchmark(c: &mut Criterion) { // Pairings { diff --git a/src/fp.rs b/src/fp.rs index 281c66e6..cf968077 100644 --- a/src/fp.rs +++ b/src/fp.rs @@ -679,7 +679,7 @@ fn test_conditional_selection() { fn test_equality() { fn is_equal(a: &Fp, b: &Fp) -> bool { let eq = a == b; - let ct_eq = a.ct_eq(&b); + let ct_eq = a.ct_eq(b); assert_eq!(eq, bool::from(ct_eq)); diff --git a/src/fp2.rs b/src/fp2.rs index 1c3ec502..1ad856fc 100644 --- a/src/fp2.rs +++ b/src/fp2.rs @@ -378,7 +378,7 @@ fn test_conditional_selection() { fn test_equality() { fn is_equal(a: &Fp2, b: &Fp2) -> bool { let eq = a == b; - let ct_eq = a.ct_eq(&b); + let ct_eq = a.ct_eq(b); assert_eq!(eq, bool::from(ct_eq)); diff --git a/src/g1.rs b/src/g1.rs index b7951008..17687495 100644 --- a/src/g1.rs +++ b/src/g1.rs @@ -1760,15 +1760,24 @@ fn test_commutative_scalar_subgroup_multiplication() { let g1_a = G1Affine::generator(); let g1_p = G1Projective::generator(); - // By reference. - assert_eq!(&g1_a * &a, &a * &g1_a); - assert_eq!(&g1_p * &a, &a * &g1_p); + // By reference. In subfunction to avoid "needlessly taken reference" lint. + fn by_ref(g1_a: &G1Affine, g1_p: &G1Projective, a: &Scalar) { + assert_eq!(g1_a * a, a * g1_a); + assert_eq!(g1_p * a, a * g1_p); + } + by_ref(&g1_a, &g1_p, &a); // Mixed - assert_eq!(&g1_a * a.clone(), a.clone() * &g1_a); - assert_eq!(&g1_p * a.clone(), a.clone() * &g1_p); - assert_eq!(g1_a.clone() * &a, &a * g1_a.clone()); - assert_eq!(g1_p.clone() * &a, &a * g1_p.clone()); + fn group_ref(g1_a: &G1Affine, g1_p: &G1Projective, a: Scalar) { + assert_eq!(g1_a * a, a * g1_a); + assert_eq!(g1_p * a, a * g1_p); + } + fn scalar_ref(g1_a: G1Affine, g1_p: G1Projective, a: &Scalar) { + assert_eq!(g1_a * a, a * g1_a); + assert_eq!(g1_p * a, a * g1_p); + } + group_ref(&g1_a, &g1_p, a); + scalar_ref(g1_a, g1_p, &a); // By value. assert_eq!(g1_p * a, a * g1_p); diff --git a/src/g2.rs b/src/g2.rs index e96c3eaa..3a6848ad 100644 --- a/src/g2.rs +++ b/src/g2.rs @@ -2163,15 +2163,24 @@ fn test_commutative_scalar_subgroup_multiplication() { let g2_a = G2Affine::generator(); let g2_p = G2Projective::generator(); - // By reference. - assert_eq!(&g2_a * &a, &a * &g2_a); - assert_eq!(&g2_p * &a, &a * &g2_p); + // By reference. In subfunction to avoid "needlessly taken reference" lint. + fn by_ref(g2_a: &G2Affine, g2_p: &G2Projective, a: &Scalar) { + assert_eq!(g2_a * a, a * g2_a); + assert_eq!(g2_p * a, a * g2_p); + } + by_ref(&g2_a, &g2_p, &a); // Mixed - assert_eq!(&g2_a * a.clone(), a.clone() * &g2_a); - assert_eq!(&g2_p * a.clone(), a.clone() * &g2_p); - assert_eq!(g2_a.clone() * &a, &a * g2_a.clone()); - assert_eq!(g2_p.clone() * &a, &a * g2_p.clone()); + fn group_ref(g2_a: &G2Affine, g2_p: &G2Projective, a: Scalar) { + assert_eq!(g2_a * a, a * g2_a); + assert_eq!(g2_p * a, a * g2_p); + } + fn scalar_ref(g2_a: G2Affine, g2_p: G2Projective, a: &Scalar) { + assert_eq!(g2_a * a, a * g2_a); + assert_eq!(g2_p * a, a * g2_p); + } + group_ref(&g2_a, &g2_p, a); + scalar_ref(g2_a, g2_p, &a); // By value. assert_eq!(g2_p * a, a * g2_p); diff --git a/src/hash_to_curve/map_g1.rs b/src/hash_to_curve/map_g1.rs index e2165709..2f05eb76 100644 --- a/src/hash_to_curve/map_g1.rs +++ b/src/hash_to_curve/map_g1.rs @@ -788,14 +788,14 @@ pub const P_M1_OVER2: Fp = Fp::from_raw_unchecked([ #[test] fn test_sgn0() { - assert_eq!(bool::from(Fp::zero().sgn0()), false); - assert_eq!(bool::from(Fp::one().sgn0()), true); - assert_eq!(bool::from((-Fp::one()).sgn0()), false); - assert_eq!(bool::from((-Fp::zero()).sgn0()), false); - assert_eq!(bool::from(P_M1_OVER2.sgn0()), true); + assert!(!bool::from(Fp::zero().sgn0())); + assert!(bool::from(Fp::one().sgn0())); + assert!(!bool::from((-Fp::one()).sgn0())); + assert!(!bool::from((-Fp::zero()).sgn0())); + assert!(bool::from(P_M1_OVER2.sgn0())); let p_p1_over2 = P_M1_OVER2 + Fp::one(); - assert_eq!(bool::from(p_p1_over2.sgn0()), false); + assert!(!bool::from(p_p1_over2.sgn0())); let neg_p_p1_over2 = { let mut tmp = p_p1_over2; diff --git a/src/hash_to_curve/map_g2.rs b/src/hash_to_curve/map_g2.rs index 5737b29d..aea6f506 100644 --- a/src/hash_to_curve/map_g2.rs +++ b/src/hash_to_curve/map_g2.rs @@ -534,190 +534,136 @@ fn test_osswu_semirandom() { fn test_sgn0() { use super::map_g1::P_M1_OVER2; - assert_eq!(bool::from(Fp2::zero().sgn0()), false); - assert_eq!(bool::from(Fp2::one().sgn0()), true); - assert_eq!( - bool::from( - Fp2 { - c0: P_M1_OVER2, - c1: Fp::zero() - } - .sgn0() - ), - true - ); - assert_eq!( - bool::from( - Fp2 { - c0: P_M1_OVER2, - c1: Fp::one() - } - .sgn0() - ), - true - ); - assert_eq!( - bool::from( - Fp2 { - c0: Fp::zero(), - c1: P_M1_OVER2, - } - .sgn0() - ), - true - ); - assert_eq!( - bool::from( - Fp2 { - c0: Fp::one(), - c1: P_M1_OVER2, - } - .sgn0() - ), - true - ); + assert!(!bool::from(Fp2::zero().sgn0())); + assert!(bool::from(Fp2::one().sgn0())); + assert!(bool::from( + Fp2 { + c0: P_M1_OVER2, + c1: Fp::zero() + } + .sgn0() + )); + assert!(bool::from( + Fp2 { + c0: P_M1_OVER2, + c1: Fp::one() + } + .sgn0() + )); + assert!(bool::from( + Fp2 { + c0: Fp::zero(), + c1: P_M1_OVER2, + } + .sgn0() + )); + assert!(bool::from( + Fp2 { + c0: Fp::one(), + c1: P_M1_OVER2, + } + .sgn0() + )); let p_p1_over2 = P_M1_OVER2 + Fp::one(); - assert_eq!( - bool::from( - Fp2 { - c0: p_p1_over2, - c1: Fp::zero() - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: p_p1_over2, - c1: Fp::one() - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: Fp::zero(), - c1: p_p1_over2, - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: Fp::one(), - c1: p_p1_over2, - } - .sgn0() - ), - true - ); - - assert_eq!( - bool::from( - Fp2 { - c0: P_M1_OVER2, - c1: -Fp::one() - } - .sgn0() - ), - true - ); - assert_eq!( - bool::from( - Fp2 { - c0: p_p1_over2, - c1: -Fp::one() - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: Fp::zero(), - c1: -Fp::one() - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: P_M1_OVER2, - c1: p_p1_over2 - } - .sgn0() - ), - true - ); - assert_eq!( - bool::from( - Fp2 { - c0: p_p1_over2, - c1: P_M1_OVER2 - } - .sgn0() - ), - false - ); - - assert_eq!( - bool::from( - Fp2 { - c0: -Fp::one(), - c1: P_M1_OVER2, - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: -Fp::one(), - c1: p_p1_over2, - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: -Fp::one(), - c1: Fp::zero(), - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: p_p1_over2, - c1: P_M1_OVER2, - } - .sgn0() - ), - false - ); - assert_eq!( - bool::from( - Fp2 { - c0: P_M1_OVER2, - c1: p_p1_over2, - } - .sgn0() - ), - true - ); + assert!(!bool::from( + Fp2 { + c0: p_p1_over2, + c1: Fp::zero() + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: p_p1_over2, + c1: Fp::one() + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: Fp::zero(), + c1: p_p1_over2, + } + .sgn0() + )); + assert!(bool::from( + Fp2 { + c0: Fp::one(), + c1: p_p1_over2, + } + .sgn0() + )); + + assert!(bool::from( + Fp2 { + c0: P_M1_OVER2, + c1: -Fp::one() + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: p_p1_over2, + c1: -Fp::one() + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: Fp::zero(), + c1: -Fp::one() + } + .sgn0() + )); + assert!(bool::from( + Fp2 { + c0: P_M1_OVER2, + c1: p_p1_over2 + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: p_p1_over2, + c1: P_M1_OVER2 + } + .sgn0() + )); + + assert!(!bool::from( + Fp2 { + c0: -Fp::one(), + c1: P_M1_OVER2, + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: -Fp::one(), + c1: p_p1_over2, + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: -Fp::one(), + c1: Fp::zero(), + } + .sgn0() + )); + assert!(!bool::from( + Fp2 { + c0: p_p1_over2, + c1: P_M1_OVER2, + } + .sgn0() + )); + assert!(bool::from( + Fp2 { + c0: P_M1_OVER2, + c1: p_p1_over2, + } + .sgn0() + )); } diff --git a/src/scalar.rs b/src/scalar.rs index 59be5dca..5f08e4b2 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -851,7 +851,10 @@ fn test_debug() { fn test_equality() { assert_eq!(Scalar::zero(), Scalar::zero()); assert_eq!(Scalar::one(), Scalar::one()); - assert_eq!(R2, R2); + #[allow(clippy::eq_op)] + { + assert_eq!(R2, R2); + } assert!(Scalar::zero() != Scalar::one()); assert!(Scalar::one() != R2);