Skip to content

Commit 46c7c8f

Browse files
group: Avoid using infinity field directly in other modules
1 parent 7a2fff8 commit 46c7c8f

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

src/ecmult_const_impl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,15 @@ static void secp256k1_ecmult_const_odd_multiples_table_globalz(secp256k1_ge *pre
8787
secp256k1_fe neg_y; \
8888
VERIFY_CHECK((n) < (1U << ECMULT_CONST_GROUP_SIZE)); \
8989
VERIFY_CHECK(index < (1U << (ECMULT_CONST_GROUP_SIZE - 1))); \
90-
/* Unconditionally set r->x = (pre)[m].x. r->y = (pre)[m].y. because it's either the correct one
90+
/* Unconditionally set r->x = (pre)[m].x and r->y = (pre)[m].y because it's either the correct one
9191
* or will get replaced in the later iterations, this is needed to make sure `r` is initialized. */ \
92-
(r)->x = (pre)[m].x; \
93-
(r)->y = (pre)[m].y; \
92+
secp256k1_ge_set_xy((r), &(pre)[m].x, &(pre)[m].y); \
9493
for (m = 1; m < ECMULT_CONST_TABLE_SIZE; m++) { \
9594
/* This loop is used to avoid secret data in array indices. See
9695
* the comment in ecmult_gen_impl.h for rationale. */ \
9796
secp256k1_fe_cmov(&(r)->x, &(pre)[m].x, m == index); \
9897
secp256k1_fe_cmov(&(r)->y, &(pre)[m].y, m == index); \
9998
} \
100-
(r)->infinity = 0; \
10199
secp256k1_fe_negate(&neg_y, &(r)->y, 1); \
102100
secp256k1_fe_cmov(&(r)->y, &neg_y, negative); \
103101
} while(0)

src/ecmult_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, sec
7575
secp256k1_ge d_ge;
7676
int i;
7777

78-
VERIFY_CHECK(!a->infinity);
78+
VERIFY_CHECK(!secp256k1_gej_is_infinity(a));
7979

8080
secp256k1_gej_double_var(&d, a, NULL);
8181

@@ -341,7 +341,7 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
341341
}
342342
}
343343

344-
if (!r->infinity) {
344+
if (!secp256k1_gej_is_infinity(r)) {
345345
secp256k1_fe_mul(&r->z, &r->z, &Z);
346346
}
347347
}

src/tests.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,8 +4152,8 @@ static void test_group_decompress(const secp256k1_fe* x) {
41524152
secp256k1_fe_normalize_var(&ge_even.y);
41534153

41544154
/* No infinity allowed. */
4155-
CHECK(!ge_even.infinity);
4156-
CHECK(!ge_odd.infinity);
4155+
CHECK(!secp256k1_ge_is_infinity(&ge_even));
4156+
CHECK(!secp256k1_ge_is_infinity(&ge_odd));
41574157

41584158
/* Check that the x coordinates check out. */
41594159
CHECK(secp256k1_fe_equal(&ge_even.x, x));

src/testutil.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,13 @@ static void testutil_random_ge_test(secp256k1_ge *ge) {
9696
break;
9797
}
9898
} while(1);
99-
ge->infinity = 0;
10099
}
101100

102101
static void testutil_random_ge_jacobian_test(secp256k1_gej *gej, const secp256k1_ge *ge) {
103-
secp256k1_fe z2, z3;
104-
testutil_random_fe_non_zero_test(&gej->z);
105-
secp256k1_fe_sqr(&z2, &gej->z);
106-
secp256k1_fe_mul(&z3, &z2, &gej->z);
107-
secp256k1_fe_mul(&gej->x, &ge->x, &z2);
108-
secp256k1_fe_mul(&gej->y, &ge->y, &z3);
109-
gej->infinity = ge->infinity;
102+
secp256k1_fe z;
103+
testutil_random_fe_non_zero_test(&z);
104+
secp256k1_gej_set_ge(gej, ge);
105+
secp256k1_gej_rescale(gej, &z);
110106
}
111107

112108
static void testutil_random_gej_test(secp256k1_gej *gej) {

0 commit comments

Comments
 (0)