Skip to content

Commit d009dc5

Browse files
Remove ecmult_context.
These tables stored in this context are now statically available from the generated ecmult_static_pre_g.h file.
1 parent 58cca2c commit d009dc5

16 files changed

+173
-414
lines changed

src/bench_ecmult.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static void bench_ecmult_1(void* arg, int iters) {
129129
int i;
130130

131131
for (i = 0; i < iters; ++i) {
132-
secp256k1_ecmult(&data->ctx->ecmult_ctx, &data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], NULL);
132+
secp256k1_ecmult(&data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], NULL);
133133
}
134134
}
135135

@@ -145,7 +145,7 @@ static void bench_ecmult_1g(void* arg, int iters) {
145145

146146
secp256k1_scalar_set_int(&zero, 0);
147147
for (i = 0; i < iters; ++i) {
148-
secp256k1_ecmult(&data->ctx->ecmult_ctx, &data->output[i], NULL, &zero, &data->scalars[(data->offset1+i) % POINTS]);
148+
secp256k1_ecmult(&data->output[i], NULL, &zero, &data->scalars[(data->offset1+i) % POINTS]);
149149
}
150150
}
151151

@@ -159,7 +159,7 @@ static void bench_ecmult_2g(void* arg, int iters) {
159159
int i;
160160

161161
for (i = 0; i < iters/2; ++i) {
162-
secp256k1_ecmult(&data->ctx->ecmult_ctx, &data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], &data->scalars[(data->offset1+i) % POINTS]);
162+
secp256k1_ecmult(&data->output[i], &data->pubkeys_gej[(data->offset1+i) % POINTS], &data->scalars[(data->offset2+i) % POINTS], &data->scalars[(data->offset1+i) % POINTS]);
163163
}
164164
}
165165

@@ -207,7 +207,7 @@ static void bench_ecmult_multi(void* arg, int iters) {
207207
iters = iters / data->count;
208208

209209
for (iter = 0; iter < iters; ++iter) {
210-
data->ecmult_multi(&data->ctx->error_callback, &data->ctx->ecmult_ctx, data->scratch, &data->output[iter], data->includes_g ? &data->scalars[data->offset1] : NULL, bench_ecmult_multi_callback, arg, count - includes_g);
210+
data->ecmult_multi(&data->ctx->error_callback, data->scratch, &data->output[iter], data->includes_g ? &data->scalars[data->offset1] : NULL, bench_ecmult_multi_callback, arg, count - includes_g);
211211
data->offset1 = (data->offset1 + count) % POINTS;
212212
data->offset2 = (data->offset2 + count - 1) % POINTS;
213213
}
@@ -266,7 +266,7 @@ static void run_ecmult_multi_bench(bench_data* data, size_t count, int includes_
266266
secp256k1_scalar_add(&total, &total, &tmp);
267267
}
268268
secp256k1_scalar_negate(&total, &total);
269-
secp256k1_ecmult(&data->ctx->ecmult_ctx, &data->expected_output[iter], NULL, &zero, &total);
269+
secp256k1_ecmult(&data->expected_output[iter], NULL, &zero, &total);
270270
}
271271

272272
/* Run the benchmark. */

src/ecdsa.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size);
1717
static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s);
18-
static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message);
18+
static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message);
1919
static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid);
2020

2121
#endif /* SECP256K1_ECDSA_H */

src/ecdsa_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const
204204
return 1;
205205
}
206206

207-
static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar *sigr, const secp256k1_scalar *sigs, const secp256k1_ge *pubkey, const secp256k1_scalar *message) {
207+
static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar *sigr, const secp256k1_scalar *sigs, const secp256k1_ge *pubkey, const secp256k1_scalar *message) {
208208
unsigned char c[32];
209209
secp256k1_scalar sn, u1, u2;
210210
#if !defined(EXHAUSTIVE_TEST_ORDER)
@@ -221,7 +221,7 @@ static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const
221221
secp256k1_scalar_mul(&u1, &sn, message);
222222
secp256k1_scalar_mul(&u2, &sn, sigr);
223223
secp256k1_gej_set_ge(&pubkeyj, pubkey);
224-
secp256k1_ecmult(ctx, &pr, &pubkeyj, &u2, &u1);
224+
secp256k1_ecmult(&pr, &pubkeyj, &u2, &u1);
225225
if (secp256k1_gej_is_infinity(&pr)) {
226226
return 0;
227227
}

src/eckey.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char
1818
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed);
1919

2020
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak);
21-
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak);
21+
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak);
2222
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak);
23-
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak);
23+
static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak);
2424

2525
#endif /* SECP256K1_ECKEY_H */

src/eckey_impl.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp25
5757
return !secp256k1_scalar_is_zero(key);
5858
}
5959

60-
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak) {
60+
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak) {
6161
secp256k1_gej pt;
6262
secp256k1_scalar one;
6363
secp256k1_gej_set_ge(&pt, key);
6464
secp256k1_scalar_set_int(&one, 1);
65-
secp256k1_ecmult(ctx, &pt, &pt, &one, tweak);
65+
secp256k1_ecmult(&pt, &pt, &one, tweak);
6666

6767
if (secp256k1_gej_is_infinity(&pt)) {
6868
return 0;
@@ -79,7 +79,7 @@ static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp25
7979
return ret;
8080
}
8181

82-
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak) {
82+
static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak) {
8383
secp256k1_scalar zero;
8484
secp256k1_gej pt;
8585
if (secp256k1_scalar_is_zero(tweak)) {
@@ -88,7 +88,7 @@ static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx,
8888

8989
secp256k1_scalar_set_int(&zero, 0);
9090
secp256k1_gej_set_ge(&pt, key);
91-
secp256k1_ecmult(ctx, &pt, &pt, tweak, &zero);
91+
secp256k1_ecmult(&pt, &pt, tweak, &zero);
9292
secp256k1_ge_set_gej(key, &pt);
9393
return 1;
9494
}

src/ecmult.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,8 @@
2929
/** The number of entries a table with precomputed multiples needs to have. */
3030
#define ECMULT_TABLE_SIZE(w) (1L << ((w)-2))
3131

32-
typedef struct {
33-
/* For accelerating the computation of a*P + b*G: */
34-
secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */
35-
secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */
36-
} secp256k1_ecmult_context;
37-
38-
static const size_t SECP256K1_ECMULT_CONTEXT_PREALLOCATED_SIZE;
39-
static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx);
40-
static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, void **prealloc);
41-
static void secp256k1_ecmult_context_finalize_memcpy(secp256k1_ecmult_context *dst, const secp256k1_ecmult_context *src);
42-
static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx);
43-
static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx);
44-
4532
/** Double multiply: R = na*A + ng*G */
46-
static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);
33+
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng);
4734

4835
typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data);
4936

@@ -58,6 +45,6 @@ typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge
5845
* 0 if there is not enough scratch space for a single point or
5946
* callback returns 0
6047
*/
61-
static int secp256k1_ecmult_multi_var(const secp256k1_callback* error_callback, const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n);
48+
static int secp256k1_ecmult_multi_var(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n);
6249

6350
#endif /* SECP256K1_ECMULT_H */

0 commit comments

Comments
 (0)