Skip to content

Commit bbc8344

Browse files
committed
Avoid secp256k1_ge_set_gej_zinv with uninitialized z
1 parent 0a2e0b2 commit bbc8344

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/group_impl.h

+18-8
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,26 @@ static void secp256k1_gej_verify(const secp256k1_gej *a) {
9292
(void)a;
9393
}
9494

95+
/* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */
9596
static void secp256k1_ge_set_gej_zinv(secp256k1_ge *r, const secp256k1_gej *a, const secp256k1_fe *zi) {
9697
secp256k1_fe zi2;
9798
secp256k1_fe zi3;
98-
/* Do not call secp256k1_ge_verify, as we do not require a->z to be initialized. */
99-
secp256k1_fe_verify(&a->x);
100-
secp256k1_fe_verify(&a->y);
99+
secp256k1_gej_verify(a);
100+
secp256k1_fe_verify(zi);
101+
VERIFY_CHECK(!a->infinity);
102+
secp256k1_fe_sqr(&zi2, zi);
103+
secp256k1_fe_mul(&zi3, &zi2, zi);
104+
secp256k1_fe_mul(&r->x, &a->x, &zi2);
105+
secp256k1_fe_mul(&r->y, &a->y, &zi3);
106+
r->infinity = a->infinity;
107+
secp256k1_ge_verify(r);
108+
}
109+
110+
/* Set r to the affine coordinates of Jacobian point (a.x, a.y, 1/zi). */
111+
static void secp256k1_ge_set_ge_zinv(secp256k1_ge *r, const secp256k1_ge *a, const secp256k1_fe *zi) {
112+
secp256k1_fe zi2;
113+
secp256k1_fe zi3;
114+
secp256k1_ge_verify(a);
101115
secp256k1_fe_verify(zi);
102116
VERIFY_CHECK(!a->infinity);
103117
secp256k1_fe_sqr(&zi2, zi);
@@ -221,18 +235,14 @@ static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const se
221235

222236
/* Work our way backwards, using the z-ratios to scale the x/y values. */
223237
while (i > 0) {
224-
secp256k1_gej tmpa;
225238
/* Verify all inputs a[i] and zr[i]. */
226239
secp256k1_fe_verify(&zr[i]);
227240
secp256k1_ge_verify(&a[i]);
228241
if (i != len - 1) {
229242
secp256k1_fe_mul(&zs, &zs, &zr[i]);
230243
}
231244
i--;
232-
tmpa.x = a[i].x;
233-
tmpa.y = a[i].y;
234-
tmpa.infinity = 0;
235-
secp256k1_ge_set_gej_zinv(&a[i], &tmpa, &zs);
245+
secp256k1_ge_set_ge_zinv(&a[i], &a[i], &zs);
236246
/* Verify the output a[i]. */
237247
secp256k1_ge_verify(&a[i]);
238248
}

0 commit comments

Comments
 (0)