Skip to content

Commit

Permalink
Add unit tests for group.h equality functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Dec 1, 2023
1 parent a47cd97 commit 60525f6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -3706,11 +3706,12 @@ static void test_ge(void) {
secp256k1_ge_clear(&ge[0]);
secp256k1_ge_set_gej_var(&ge[0], &gej[0]);
for (i = 0; i < runs; i++) {
int j;
int j, k;
secp256k1_ge g;
random_group_element_test(&g);
if (i >= runs - 2) {
secp256k1_ge_mul_lambda(&g, &ge[1]);
CHECK(!secp256k1_ge_eq_var(&g, &ge[1]));
}
if (i >= runs - 1) {
secp256k1_ge_mul_lambda(&g, &g);
Expand All @@ -3730,6 +3731,16 @@ static void test_ge(void) {
random_gej_y_magnitude(&gej[1 + j + 4 * i]);
random_gej_z_magnitude(&gej[1 + j + 4 * i]);
}

for (j = 0; j < 4; ++j) {
for (k = 0; k < 4; ++k) {
int expect_equal = (j >> 1) == (k >> 1);
CHECK(secp256k1_ge_eq_var(&ge[1 + j + 4 * i], &ge[1 + k + 4 * i]) == expect_equal);
CHECK(secp256k1_gej_eq_var(&gej[1 + j + 4 * i], &gej[1 + k + 4 * i]) == expect_equal);
CHECK(secp256k1_gej_eq_ge_var(&gej[1 + j + 4 * i], &ge[1 + k + 4 * i]) == expect_equal);
CHECK(secp256k1_gej_eq_ge_var(&gej[1 + k + 4 * i], &ge[1 + j + 4 * i]) == expect_equal);
}
}
}

/* Generate random zf, and zfi2 = 1/zf^2, zfi3 = 1/zf^3 */
Expand Down

0 comments on commit 60525f6

Please sign in to comment.