Skip to content

Commit

Permalink
Make jacobi benchmarks vary inputs
Browse files Browse the repository at this point in the history
Also make the num_jacobi benchmark use the scalar order as modulus,
instead of a random number.
  • Loading branch information
sipa committed Sep 10, 2020
1 parent d0fdd5f commit 5c6af60
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/bench_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,18 @@ void bench_group_jacobi_var(void* arg, int iters) {

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

void bench_ecmult_wnaf(void* arg, int iters) {
Expand Down Expand Up @@ -347,14 +357,15 @@ void bench_context_sign(void* arg, int iters) {
void bench_num_jacobi(void* arg, int iters) {
int i, j = 0;
bench_inv *data = (bench_inv*)arg;
secp256k1_num nx, norder;
secp256k1_num nx, na, norder;

secp256k1_scalar_get_num(&nx, &data->scalar[0]);
secp256k1_scalar_order_get_num(&norder);
secp256k1_scalar_get_num(&norder, &data->scalar[1]);
secp256k1_scalar_get_num(&na, &data->scalar[1]);

for (i = 0; i < iters; i++) {
j += secp256k1_num_jacobi(&nx, &norder);
secp256k1_num_add(&nx, &nx, &na);
}
CHECK(j <= iters);
}
Expand Down

0 comments on commit 5c6af60

Please sign in to comment.