Skip to content

Commit 1120790

Browse files
committed
Add tests for _gej_cmov
1 parent bed4d91 commit 1120790

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/tests.c

Lines changed: 38 additions & 0 deletions
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];
@@ -3338,6 +3344,37 @@ void run_ge(void) {
33383344
test_intialized_inf();
33393345
}
33403346

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

68066843
/* group tests */
68076844
run_ge();
6845+
run_gej();
68086846
run_group_decompress();
68096847

68106848
/* ecmult tests */

0 commit comments

Comments
 (0)