Skip to content

Commit d8a2463

Browse files
committed
Merge #899: Reduce stratch space needed by ecmult_strauss_wnaf.
b797a50 Create a SECP256K1_ECMULT_TABLE_VERIFY macro. (Russell O'Connor) a731200 Replace ECMULT_TABLE_GET_GE_STORAGE macro with a function. (Russell O'Connor) fe34d9f Eliminate input_pos state field from ecmult_strauss_wnaf. (Russell O'Connor) 0397d00 Eliminate na_1 and na_lam state fields from ecmult_strauss_wnaf. (Russell O'Connor) 7ba3ffc Remove the unused pre_a_lam allocations. (Russell O'Connor) b3b57ad Eliminate the pre_a_lam array from ecmult_strauss_wnaf. (Russell O'Connor) ae7ba0f Remove the unused prej allocations. (Russell O'Connor) e5c1889 Eliminate the prej array from ecmult_strauss_wnaf. (Russell O'Connor) c9da1ba Move secp256k1_fe_one to field.h (Russell O'Connor) Pull request description: ACKs for top commit: sipa: ACK b797a50 jonasnick: ACK b797a50 Tree-SHA512: 6742469979c306104a0861be76c2be86bf8ab14116b00afbd24f91b9e3ea843bf9b9a74552b367bd06ee617090019ad4df6be037d58937c8c869f8b37ddaa6cc
2 parents 0a40a48 + b797a50 commit d8a2463

File tree

6 files changed

+155
-127
lines changed

6 files changed

+155
-127
lines changed

src/ecmult_const_impl.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
* It only operates on tables sized for WINDOW_A wnaf multiples.
2020
*/
2121
static void secp256k1_ecmult_odd_multiples_table_globalz_windowa(secp256k1_ge *pre, secp256k1_fe *globalz, const secp256k1_gej *a) {
22-
secp256k1_gej prej[ECMULT_TABLE_SIZE(WINDOW_A)];
2322
secp256k1_fe zr[ECMULT_TABLE_SIZE(WINDOW_A)];
2423

25-
/* Compute the odd multiples in Jacobian form. */
26-
secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), prej, zr, a);
27-
/* Bring them to the same Z denominator. */
28-
secp256k1_ge_globalz_set_table_gej(ECMULT_TABLE_SIZE(WINDOW_A), pre, globalz, prej, zr);
24+
secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), pre, zr, globalz, a);
25+
secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A), pre, zr);
2926
}
3027

3128
/* This is like `ECMULT_TABLE_GET_GE` but is constant time */

src/ecmult_impl.h

+113-97
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
/* The number of objects allocated on the scratch space for ecmult_multi algorithms */
4949
#define PIPPENGER_SCRATCH_OBJECTS 6
50-
#define STRAUSS_SCRATCH_OBJECTS 7
50+
#define STRAUSS_SCRATCH_OBJECTS 5
5151

5252
#define PIPPENGER_MAX_BUCKET_WINDOW 12
5353

@@ -56,71 +56,98 @@
5656

5757
#define ECMULT_MAX_POINTS_PER_BATCH 5000000
5858

59-
/** Fill a table 'prej' with precomputed odd multiples of a. Prej will contain
60-
* the values [1*a,3*a,...,(2*n-1)*a], so it space for n values. zr[0] will
61-
* contain prej[0].z / a.z. The other zr[i] values = prej[i].z / prej[i-1].z.
62-
* Prej's Z values are undefined, except for the last value.
59+
/** Fill a table 'pre_a' with precomputed odd multiples of a.
60+
* pre_a will contain [1*a,3*a,...,(2*n-1)*a], so it needs space for n group elements.
61+
* zr needs space for n field elements.
62+
*
63+
* Although pre_a is an array of _ge rather than _gej, it actually represents elements
64+
* in Jacobian coordinates with their z coordinates omitted. The omitted z-coordinates
65+
* can be recovered using z and zr. Using the notation z(b) to represent the omitted
66+
* z coordinate of b:
67+
* - z(pre_a[n-1]) = 'z'
68+
* - z(pre_a[i-1]) = z(pre_a[i]) / zr[i] for n > i > 0
69+
*
70+
* Lastly the zr[0] value, which isn't used above, is set so that:
71+
* - a.z = z(pre_a[0]) / zr[0]
6372
*/
64-
static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_gej *prej, secp256k1_fe *zr, const secp256k1_gej *a) {
65-
secp256k1_gej d;
66-
secp256k1_ge a_ge, d_ge;
73+
static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, secp256k1_fe *zr, secp256k1_fe *z, const secp256k1_gej *a) {
74+
secp256k1_gej d, ai;
75+
secp256k1_ge d_ge;
6776
int i;
6877

6978
VERIFY_CHECK(!a->infinity);
7079

7180
secp256k1_gej_double_var(&d, a, NULL);
7281

7382
/*
74-
* Perform the additions on an isomorphism where 'd' is affine: drop the z coordinate
75-
* of 'd', and scale the 1P starting value's x/y coordinates without changing its z.
83+
* Perform the additions using an isomorphic curve Y^2 = X^3 + 7*C^6 where C := d.z.
84+
* The isomorphism, phi, maps a secp256k1 point (x, y) to the point (x*C^2, y*C^3) on the other curve.
85+
* In Jacobian coordinates phi maps (x, y, z) to (x*C^2, y*C^3, z) or, equivalently to (x, y, z/C).
86+
*
87+
* phi(x, y, z) = (x*C^2, y*C^3, z) = (x, y, z/C)
88+
* d_ge := phi(d) = (d.x, d.y, 1)
89+
* ai := phi(a) = (a.x*C^2, a.y*C^3, a.z)
90+
*
91+
* The group addition functions work correctly on these isomorphic curves.
92+
* In particular phi(d) is easy to represent in affine coordinates under this isomorphism.
93+
* This lets us use the faster secp256k1_gej_add_ge_var group addition function that we wouldn't be able to use otherwise.
7694
*/
77-
d_ge.x = d.x;
78-
d_ge.y = d.y;
79-
d_ge.infinity = 0;
80-
81-
secp256k1_ge_set_gej_zinv(&a_ge, a, &d.z);
82-
prej[0].x = a_ge.x;
83-
prej[0].y = a_ge.y;
84-
prej[0].z = a->z;
85-
prej[0].infinity = 0;
95+
secp256k1_ge_set_xy(&d_ge, &d.x, &d.y);
96+
secp256k1_ge_set_gej_zinv(&pre_a[0], a, &d.z);
97+
secp256k1_gej_set_ge(&ai, &pre_a[0]);
98+
ai.z = a->z;
8699

100+
/* pre_a[0] is the point (a.x*C^2, a.y*C^3, a.z*C) which is equvalent to a.
101+
* Set zr[0] to C, which is the ratio between the omitted z(pre_a[0]) value and a.z.
102+
*/
87103
zr[0] = d.z;
104+
88105
for (i = 1; i < n; i++) {
89-
secp256k1_gej_add_ge_var(&prej[i], &prej[i-1], &d_ge, &zr[i]);
106+
secp256k1_gej_add_ge_var(&ai, &ai, &d_ge, &zr[i]);
107+
secp256k1_ge_set_xy(&pre_a[i], &ai.x, &ai.y);
90108
}
91109

92-
/*
93-
* Each point in 'prej' has a z coordinate too small by a factor of 'd.z'. Only
94-
* the final point's z coordinate is actually used though, so just update that.
110+
/* Multiply the last z-coordinate by C to undo the isomorphism.
111+
* Since the z-coordinates of the pre_a values are implied by the zr array of z-coordinate ratios,
112+
* undoing the isomorphism here undoes the isomorphism for all pre_a values.
95113
*/
96-
secp256k1_fe_mul(&prej[n-1].z, &prej[n-1].z, &d.z);
114+
secp256k1_fe_mul(z, &ai.z, &d.z);
97115
}
98116

99-
/** The following two macro retrieves a particular odd multiple from a table
100-
* of precomputed multiples. */
101-
#define ECMULT_TABLE_GET_GE(r,pre,n,w) do { \
117+
#define SECP256K1_ECMULT_TABLE_VERIFY(n,w) \
102118
VERIFY_CHECK(((n) & 1) == 1); \
103119
VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \
104-
VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \
105-
if ((n) > 0) { \
106-
*(r) = (pre)[((n)-1)/2]; \
107-
} else { \
108-
*(r) = (pre)[(-(n)-1)/2]; \
109-
secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \
110-
} \
111-
} while(0)
112-
113-
#define ECMULT_TABLE_GET_GE_STORAGE(r,pre,n,w) do { \
114-
VERIFY_CHECK(((n) & 1) == 1); \
115-
VERIFY_CHECK((n) >= -((1 << ((w)-1)) - 1)); \
116-
VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1)); \
117-
if ((n) > 0) { \
118-
secp256k1_ge_from_storage((r), &(pre)[((n)-1)/2]); \
119-
} else { \
120-
secp256k1_ge_from_storage((r), &(pre)[(-(n)-1)/2]); \
121-
secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \
122-
} \
123-
} while(0)
120+
VERIFY_CHECK((n) <= ((1 << ((w)-1)) - 1));
121+
122+
SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge(secp256k1_ge *r, const secp256k1_ge *pre, int n, int w) {
123+
SECP256K1_ECMULT_TABLE_VERIFY(n,w)
124+
if (n > 0) {
125+
*r = pre[(n-1)/2];
126+
} else {
127+
*r = pre[(-n-1)/2];
128+
secp256k1_fe_negate(&(r->y), &(r->y), 1);
129+
}
130+
}
131+
132+
SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_lambda(secp256k1_ge *r, const secp256k1_ge *pre, const secp256k1_fe *x, int n, int w) {
133+
SECP256K1_ECMULT_TABLE_VERIFY(n,w)
134+
if (n > 0) {
135+
secp256k1_ge_set_xy(r, &x[(n-1)/2], &pre[(n-1)/2].y);
136+
} else {
137+
secp256k1_ge_set_xy(r, &x[(-n-1)/2], &pre[(-n-1)/2].y);
138+
secp256k1_fe_negate(&(r->y), &(r->y), 1);
139+
}
140+
}
141+
142+
SECP256K1_INLINE static void secp256k1_ecmult_table_get_ge_storage(secp256k1_ge *r, const secp256k1_ge_storage *pre, int n, int w) {
143+
SECP256K1_ECMULT_TABLE_VERIFY(n,w)
144+
if (n > 0) {
145+
secp256k1_ge_from_storage(r, &pre[(n-1)/2]);
146+
} else {
147+
secp256k1_ge_from_storage(r, &pre[(-n-1)/2]);
148+
secp256k1_fe_negate(&(r->y), &(r->y), 1);
149+
}
150+
}
124151

125152
/** Convert a number to WNAF notation. The number becomes represented by sum(2^i * wnaf[i], i=0..bits),
126153
* with the following guarantees:
@@ -182,19 +209,16 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
182209
}
183210

184211
struct secp256k1_strauss_point_state {
185-
secp256k1_scalar na_1, na_lam;
186212
int wnaf_na_1[129];
187213
int wnaf_na_lam[129];
188214
int bits_na_1;
189215
int bits_na_lam;
190-
size_t input_pos;
191216
};
192217

193218
struct secp256k1_strauss_state {
194-
secp256k1_gej* prej;
195-
secp256k1_fe* zr;
219+
/* aux is used to hold z-ratios, and then used to hold pre_a[i].x * BETA values. */
220+
secp256k1_fe* aux;
196221
secp256k1_ge* pre_a;
197-
secp256k1_ge* pre_a_lam;
198222
struct secp256k1_strauss_point_state* ps;
199223
};
200224

@@ -212,17 +236,19 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
212236
size_t np;
213237
size_t no = 0;
214238

239+
secp256k1_fe_set_int(&Z, 1);
215240
for (np = 0; np < num; ++np) {
241+
secp256k1_gej tmp;
242+
secp256k1_scalar na_1, na_lam;
216243
if (secp256k1_scalar_is_zero(&na[np]) || secp256k1_gej_is_infinity(&a[np])) {
217244
continue;
218245
}
219-
state->ps[no].input_pos = np;
220246
/* split na into na_1 and na_lam (where na = na_1 + na_lam*lambda, and na_1 and na_lam are ~128 bit) */
221-
secp256k1_scalar_split_lambda(&state->ps[no].na_1, &state->ps[no].na_lam, &na[np]);
247+
secp256k1_scalar_split_lambda(&na_1, &na_lam, &na[np]);
222248

223249
/* build wnaf representation for na_1 and na_lam. */
224-
state->ps[no].bits_na_1 = secp256k1_ecmult_wnaf(state->ps[no].wnaf_na_1, 129, &state->ps[no].na_1, WINDOW_A);
225-
state->ps[no].bits_na_lam = secp256k1_ecmult_wnaf(state->ps[no].wnaf_na_lam, 129, &state->ps[no].na_lam, WINDOW_A);
250+
state->ps[no].bits_na_1 = secp256k1_ecmult_wnaf(state->ps[no].wnaf_na_1, 129, &na_1, WINDOW_A);
251+
state->ps[no].bits_na_lam = secp256k1_ecmult_wnaf(state->ps[no].wnaf_na_lam, 129, &na_lam, WINDOW_A);
226252
VERIFY_CHECK(state->ps[no].bits_na_1 <= 129);
227253
VERIFY_CHECK(state->ps[no].bits_na_lam <= 129);
228254
if (state->ps[no].bits_na_1 > bits) {
@@ -231,40 +257,36 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
231257
if (state->ps[no].bits_na_lam > bits) {
232258
bits = state->ps[no].bits_na_lam;
233259
}
234-
++no;
235-
}
236260

237-
/* Calculate odd multiples of a.
238-
* All multiples are brought to the same Z 'denominator', which is stored
239-
* in Z. Due to secp256k1' isomorphism we can do all operations pretending
240-
* that the Z coordinate was 1, use affine addition formulae, and correct
241-
* the Z coordinate of the result once at the end.
242-
* The exception is the precomputed G table points, which are actually
243-
* affine. Compared to the base used for other points, they have a Z ratio
244-
* of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
245-
* isomorphism to efficiently add with a known Z inverse.
246-
*/
247-
if (no > 0) {
248-
/* Compute the odd multiples in Jacobian form. */
249-
secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->prej, state->zr, &a[state->ps[0].input_pos]);
250-
for (np = 1; np < no; ++np) {
251-
secp256k1_gej tmp = a[state->ps[np].input_pos];
261+
/* Calculate odd multiples of a.
262+
* All multiples are brought to the same Z 'denominator', which is stored
263+
* in Z. Due to secp256k1' isomorphism we can do all operations pretending
264+
* that the Z coordinate was 1, use affine addition formulae, and correct
265+
* the Z coordinate of the result once at the end.
266+
* The exception is the precomputed G table points, which are actually
267+
* affine. Compared to the base used for other points, they have a Z ratio
268+
* of 1/Z, so we can use secp256k1_gej_add_zinv_var, which uses the same
269+
* isomorphism to efficiently add with a known Z inverse.
270+
*/
271+
tmp = a[np];
272+
if (no) {
252273
#ifdef VERIFY
253-
secp256k1_fe_normalize_var(&(state->prej[(np - 1) * ECMULT_TABLE_SIZE(WINDOW_A) + ECMULT_TABLE_SIZE(WINDOW_A) - 1].z));
274+
secp256k1_fe_normalize_var(&Z);
254275
#endif
255-
secp256k1_gej_rescale(&tmp, &(state->prej[(np - 1) * ECMULT_TABLE_SIZE(WINDOW_A) + ECMULT_TABLE_SIZE(WINDOW_A) - 1].z));
256-
secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->prej + np * ECMULT_TABLE_SIZE(WINDOW_A), state->zr + np * ECMULT_TABLE_SIZE(WINDOW_A), &tmp);
257-
secp256k1_fe_mul(state->zr + np * ECMULT_TABLE_SIZE(WINDOW_A), state->zr + np * ECMULT_TABLE_SIZE(WINDOW_A), &(a[state->ps[np].input_pos].z));
276+
secp256k1_gej_rescale(&tmp, &Z);
258277
}
259-
/* Bring them to the same Z denominator. */
260-
secp256k1_ge_globalz_set_table_gej(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, &Z, state->prej, state->zr);
261-
} else {
262-
secp256k1_fe_set_int(&Z, 1);
278+
secp256k1_ecmult_odd_multiples_table(ECMULT_TABLE_SIZE(WINDOW_A), state->pre_a + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &Z, &tmp);
279+
if (no) secp256k1_fe_mul(state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + no * ECMULT_TABLE_SIZE(WINDOW_A), &(a[np].z));
280+
281+
++no;
263282
}
264283

284+
/* Bring them to the same Z denominator. */
285+
secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
286+
265287
for (np = 0; np < no; ++np) {
266288
for (i = 0; i < ECMULT_TABLE_SIZE(WINDOW_A); i++) {
267-
secp256k1_ge_mul_lambda(&state->pre_a_lam[np * ECMULT_TABLE_SIZE(WINDOW_A) + i], &state->pre_a[np * ECMULT_TABLE_SIZE(WINDOW_A) + i]);
289+
secp256k1_fe_mul(&state->aux[np * ECMULT_TABLE_SIZE(WINDOW_A) + i], &state->pre_a[np * ECMULT_TABLE_SIZE(WINDOW_A) + i].x, &secp256k1_const_beta);
268290
}
269291
}
270292

@@ -290,20 +312,20 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
290312
secp256k1_gej_double_var(r, r, NULL);
291313
for (np = 0; np < no; ++np) {
292314
if (i < state->ps[np].bits_na_1 && (n = state->ps[np].wnaf_na_1[i])) {
293-
ECMULT_TABLE_GET_GE(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A);
315+
secp256k1_ecmult_table_get_ge(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A);
294316
secp256k1_gej_add_ge_var(r, r, &tmpa, NULL);
295317
}
296318
if (i < state->ps[np].bits_na_lam && (n = state->ps[np].wnaf_na_lam[i])) {
297-
ECMULT_TABLE_GET_GE(&tmpa, state->pre_a_lam + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A);
319+
secp256k1_ecmult_table_get_ge_lambda(&tmpa, state->pre_a + np * ECMULT_TABLE_SIZE(WINDOW_A), state->aux + np * ECMULT_TABLE_SIZE(WINDOW_A), n, WINDOW_A);
298320
secp256k1_gej_add_ge_var(r, r, &tmpa, NULL);
299321
}
300322
}
301323
if (i < bits_ng_1 && (n = wnaf_ng_1[i])) {
302-
ECMULT_TABLE_GET_GE_STORAGE(&tmpa, secp256k1_pre_g, n, WINDOW_G);
324+
secp256k1_ecmult_table_get_ge_storage(&tmpa, secp256k1_pre_g, n, WINDOW_G);
303325
secp256k1_gej_add_zinv_var(r, r, &tmpa, &Z);
304326
}
305327
if (i < bits_ng_128 && (n = wnaf_ng_128[i])) {
306-
ECMULT_TABLE_GET_GE_STORAGE(&tmpa, secp256k1_pre_g_128, n, WINDOW_G);
328+
secp256k1_ecmult_table_get_ge_storage(&tmpa, secp256k1_pre_g_128, n, WINDOW_G);
307329
secp256k1_gej_add_zinv_var(r, r, &tmpa, &Z);
308330
}
309331
}
@@ -314,23 +336,19 @@ static void secp256k1_ecmult_strauss_wnaf(const struct secp256k1_strauss_state *
314336
}
315337

316338
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng) {
317-
secp256k1_gej prej[ECMULT_TABLE_SIZE(WINDOW_A)];
318-
secp256k1_fe zr[ECMULT_TABLE_SIZE(WINDOW_A)];
339+
secp256k1_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)];
319340
secp256k1_ge pre_a[ECMULT_TABLE_SIZE(WINDOW_A)];
320341
struct secp256k1_strauss_point_state ps[1];
321-
secp256k1_ge pre_a_lam[ECMULT_TABLE_SIZE(WINDOW_A)];
322342
struct secp256k1_strauss_state state;
323343

324-
state.prej = prej;
325-
state.zr = zr;
344+
state.aux = aux;
326345
state.pre_a = pre_a;
327-
state.pre_a_lam = pre_a_lam;
328346
state.ps = ps;
329347
secp256k1_ecmult_strauss_wnaf(&state, r, 1, a, na, ng);
330348
}
331349

332350
static size_t secp256k1_strauss_scratch_size(size_t n_points) {
333-
static const size_t point_size = (2 * sizeof(secp256k1_ge) + sizeof(secp256k1_gej) + sizeof(secp256k1_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct secp256k1_strauss_point_state) + sizeof(secp256k1_gej) + sizeof(secp256k1_scalar);
351+
static const size_t point_size = (sizeof(secp256k1_ge) + sizeof(secp256k1_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct secp256k1_strauss_point_state) + sizeof(secp256k1_gej) + sizeof(secp256k1_scalar);
334352
return n_points*point_size;
335353
}
336354

@@ -351,13 +369,11 @@ static int secp256k1_ecmult_strauss_batch(const secp256k1_callback* error_callba
351369
* constant and strauss_scratch_size accordingly. */
352370
points = (secp256k1_gej*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_gej));
353371
scalars = (secp256k1_scalar*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_scalar));
354-
state.prej = (secp256k1_gej*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_gej));
355-
state.zr = (secp256k1_fe*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_fe));
372+
state.aux = (secp256k1_fe*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_fe));
356373
state.pre_a = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));
357-
state.pre_a_lam = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));
358374
state.ps = (struct secp256k1_strauss_point_state*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(struct secp256k1_strauss_point_state));
359375

360-
if (points == NULL || scalars == NULL || state.prej == NULL || state.zr == NULL || state.pre_a == NULL || state.pre_a_lam == NULL || state.ps == NULL) {
376+
if (points == NULL || scalars == NULL || state.aux == NULL || state.pre_a == NULL || state.ps == NULL) {
361377
secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);
362378
return 0;
363379
}

src/field.h

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
#error "Please select wide multiplication implementation"
3333
#endif
3434

35+
static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1);
36+
static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST(
37+
0x7ae96a2bul, 0x657c0710ul, 0x6e64479eul, 0xac3434e9ul,
38+
0x9cf04975ul, 0x12f58995ul, 0xc1396c28ul, 0x719501eeul
39+
);
40+
3541
/** Normalize a field element. This brings the field element to a canonical representation, reduces
3642
* its magnitude to 1, and reduces it modulo field size `p`.
3743
*/

src/field_impl.h

-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,4 @@ static int secp256k1_fe_sqrt(secp256k1_fe *r, const secp256k1_fe *a) {
135135
return secp256k1_fe_equal(&t1, a);
136136
}
137137

138-
static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1);
139-
140138
#endif /* SECP256K1_FIELD_IMPL_H */

0 commit comments

Comments
 (0)