Skip to content

Commit a697d82

Browse files
committed
Add trivial ecmult_multi to the benchmark tool
1 parent bade617 commit a697d82

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/bench_ecmult.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,31 @@ int main(int argc, char **argv) {
139139
secp256k1_gej* pubkeys_gej;
140140
size_t scratch_size;
141141

142+
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
143+
scratch_size = secp256k1_strauss_scratch_size(POINTS) + STRAUSS_SCRATCH_OBJECTS*16;
144+
data.scratch = secp256k1_scratch_space_create(data.ctx, scratch_size);
142145
data.ecmult_multi = secp256k1_ecmult_multi_var;
146+
143147
if (argc > 1) {
144148
if(have_flag(argc, argv, "pippenger_wnaf")) {
145149
printf("Using pippenger_wnaf:\n");
146150
data.ecmult_multi = secp256k1_ecmult_pippenger_batch_single;
147151
} else if(have_flag(argc, argv, "strauss_wnaf")) {
148152
printf("Using strauss_wnaf:\n");
149153
data.ecmult_multi = secp256k1_ecmult_strauss_batch_single;
154+
} else if(have_flag(argc, argv, "simple")) {
155+
printf("Using simple algorithm:\n");
156+
data.ecmult_multi = secp256k1_ecmult_multi_var;
157+
secp256k1_scratch_space_destroy(data.scratch);
158+
data.scratch = NULL;
150159
} else {
151160
fprintf(stderr, "%s: unrecognized argument '%s'.\n", argv[0], argv[1]);
152-
fprintf(stderr, "Use 'pippenger_wnaf', 'strauss_wnaf' or no argument to benchmark a combined algorithm.\n");
161+
fprintf(stderr, "Use 'pippenger_wnaf', 'strauss_wnaf', 'simple' or no argument to benchmark a combined algorithm.\n");
153162
return 1;
154163
}
155164
}
156165

157166
/* Allocate stuff */
158-
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
159-
scratch_size = secp256k1_strauss_scratch_size(POINTS) + STRAUSS_SCRATCH_OBJECTS*16;
160-
data.scratch = secp256k1_scratch_space_create(data.ctx, scratch_size);
161167
data.scalars = malloc(sizeof(secp256k1_scalar) * POINTS);
162168
data.seckeys = malloc(sizeof(secp256k1_scalar) * POINTS);
163169
data.pubkeys = malloc(sizeof(secp256k1_ge) * POINTS);
@@ -188,7 +194,9 @@ int main(int argc, char **argv) {
188194
}
189195
}
190196
secp256k1_context_destroy(data.ctx);
191-
secp256k1_scratch_space_destroy(data.scratch);
197+
if (data.scratch != NULL) {
198+
secp256k1_scratch_space_destroy(data.scratch);
199+
}
192200
free(data.scalars);
193201
free(data.pubkeys);
194202
free(data.seckeys);

0 commit comments

Comments
 (0)