Skip to content

Commit 5c6af60

Browse files
committed
Make jacobi benchmarks vary inputs
Also make the num_jacobi benchmark use the scalar order as modulus, instead of a random number.
1 parent d0fdd5f commit 5c6af60

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/bench_internal.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,18 @@ void bench_group_jacobi_var(void* arg, int iters) {
263263

264264
for (i = 0; i < iters; i++) {
265265
j += secp256k1_gej_has_quad_y_var(&data->gej[0]);
266+
/* Vary the Y and Z coordinates of the input (the X coordinate doesn't matter to
267+
secp256k1_gej_has_quad_y_var). Note that the resulting coordinates will
268+
generally not correspond to a point on the curve, but this is not a problem
269+
for the code being benchmarked here. Adding and normalizing have less
270+
overhead than EC operations (which could guarantee the point remains on the
271+
curve). */
272+
secp256k1_fe_add(&data->gej[0].y, &data->fe[1]);
273+
secp256k1_fe_add(&data->gej[0].z, &data->fe[2]);
274+
secp256k1_fe_normalize_var(&data->gej[0].y);
275+
secp256k1_fe_normalize_var(&data->gej[0].z);
266276
}
267-
CHECK(j == iters);
277+
CHECK(j <= iters);
268278
}
269279

270280
void bench_ecmult_wnaf(void* arg, int iters) {
@@ -347,14 +357,15 @@ void bench_context_sign(void* arg, int iters) {
347357
void bench_num_jacobi(void* arg, int iters) {
348358
int i, j = 0;
349359
bench_inv *data = (bench_inv*)arg;
350-
secp256k1_num nx, norder;
360+
secp256k1_num nx, na, norder;
351361

352362
secp256k1_scalar_get_num(&nx, &data->scalar[0]);
353363
secp256k1_scalar_order_get_num(&norder);
354-
secp256k1_scalar_get_num(&norder, &data->scalar[1]);
364+
secp256k1_scalar_get_num(&na, &data->scalar[1]);
355365

356366
for (i = 0; i < iters; i++) {
357367
j += secp256k1_num_jacobi(&nx, &norder);
368+
secp256k1_num_add(&nx, &nx, &na);
358369
}
359370
CHECK(j <= iters);
360371
}

0 commit comments

Comments
 (0)