Skip to content

Commit

Permalink
Slightly extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed May 4, 2024
1 parent 3499e9c commit 9184234
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crypto/ff-group-tests/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,24 @@ pub fn test_mul<G: Group>() {
"generator * 2 != generator + generator"
);
assert_eq!(G::identity() * G::Scalar::from(2), G::identity(), "identity * 2 != identity");

let s = rand_core::OsRng.next_u64() >> 56;
let mut res = G::identity();
for _ in 0 .. s {
res += G::generator();
}
assert_eq!(
G::generator() * G::Scalar::from(s),
res,
"generator * rand_u8() != generator + .. + generator"
);
}

/// Test `((order - 1) * G) + G == identity`.
pub fn test_order<G: Group>() {
let minus_one = G::generator() * (G::Scalar::ZERO - G::Scalar::ONE);
assert!(minus_one != G::identity(), "(modulus - 1) * G was identity");
assert_eq!(minus_one, -G::generator(), "((modulus - 1) * G) wasn't -G");
assert_eq!(minus_one + G::generator(), G::identity(), "((modulus - 1) * G) + G wasn't identity");
}

Expand Down

0 comments on commit 9184234

Please sign in to comment.