Skip to content

Commit 40b624c

Browse files
committed
Add tests for _gej_cmov
1 parent 8c13a9b commit 40b624c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/tests.c

+38
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ void random_group_element_jacobian_test(secp256k1_gej *gej, const secp256k1_ge *
100100
gej->infinity = ge->infinity;
101101
}
102102

103+
void random_gej_test(secp256k1_gej *gej) {
104+
secp256k1_ge ge;
105+
random_group_element_test(&ge);
106+
random_group_element_jacobian_test(gej, &ge);
107+
}
108+
103109
void random_scalar_order_test(secp256k1_scalar *num) {
104110
do {
105111
unsigned char b32[32];
@@ -3341,6 +3347,37 @@ void run_ge(void) {
33413347
test_intialized_inf();
33423348
}
33433349

3350+
void test_gej_cmov(const secp256k1_gej *a, const secp256k1_gej *b) {
3351+
secp256k1_gej t = *a;
3352+
secp256k1_gej_cmov(&t, b, 0);
3353+
CHECK(gej_xyz_equals_gej(&t, a));
3354+
secp256k1_gej_cmov(&t, b, 1);
3355+
CHECK(gej_xyz_equals_gej(&t, b));
3356+
}
3357+
3358+
void run_gej(void) {
3359+
int i;
3360+
secp256k1_gej a, b;
3361+
3362+
/* Tests for secp256k1_gej_cmov */
3363+
for (i = 0; i < count; i++) {
3364+
secp256k1_gej_set_infinity(&a);
3365+
secp256k1_gej_set_infinity(&b);
3366+
test_gej_cmov(&a, &b);
3367+
3368+
random_gej_test(&a);
3369+
test_gej_cmov(&a, &b);
3370+
test_gej_cmov(&b, &a);
3371+
3372+
b = a;
3373+
test_gej_cmov(&a, &b);
3374+
3375+
random_gej_test(&b);
3376+
test_gej_cmov(&a, &b);
3377+
test_gej_cmov(&b, &a);
3378+
}
3379+
}
3380+
33443381
void test_ec_combine(void) {
33453382
secp256k1_scalar sum = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0);
33463383
secp256k1_pubkey data[6];
@@ -6808,6 +6845,7 @@ int main(int argc, char **argv) {
68086845

68096846
/* group tests */
68106847
run_ge();
6848+
run_gej();
68116849
run_group_decompress();
68126850

68136851
/* ecmult tests */

0 commit comments

Comments
 (0)