Skip to content

Commit

Permalink
Add tests for _gej_cmov
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman committed Dec 26, 2021
1 parent 8c13a9b commit 40b624c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ void random_group_element_jacobian_test(secp256k1_gej *gej, const secp256k1_ge *
gej->infinity = ge->infinity;
}

void random_gej_test(secp256k1_gej *gej) {
secp256k1_ge ge;
random_group_element_test(&ge);
random_group_element_jacobian_test(gej, &ge);
}

void random_scalar_order_test(secp256k1_scalar *num) {
do {
unsigned char b32[32];
Expand Down Expand Up @@ -3341,6 +3347,37 @@ void run_ge(void) {
test_intialized_inf();
}

void test_gej_cmov(const secp256k1_gej *a, const secp256k1_gej *b) {
secp256k1_gej t = *a;
secp256k1_gej_cmov(&t, b, 0);
CHECK(gej_xyz_equals_gej(&t, a));
secp256k1_gej_cmov(&t, b, 1);
CHECK(gej_xyz_equals_gej(&t, b));
}

void run_gej(void) {
int i;
secp256k1_gej a, b;

/* Tests for secp256k1_gej_cmov */
for (i = 0; i < count; i++) {
secp256k1_gej_set_infinity(&a);
secp256k1_gej_set_infinity(&b);
test_gej_cmov(&a, &b);

random_gej_test(&a);
test_gej_cmov(&a, &b);
test_gej_cmov(&b, &a);

b = a;
test_gej_cmov(&a, &b);

random_gej_test(&b);
test_gej_cmov(&a, &b);
test_gej_cmov(&b, &a);
}
}

void test_ec_combine(void) {
secp256k1_scalar sum = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0);
secp256k1_pubkey data[6];
Expand Down Expand Up @@ -6808,6 +6845,7 @@ int main(int argc, char **argv) {

/* group tests */
run_ge();
run_gej();
run_group_decompress();

/* ecmult tests */
Expand Down

0 comments on commit 40b624c

Please sign in to comment.