Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/ecmult_impl.h
Show First 20 Lines • Show All 1,146 Lines • ▼ Show 20 Lines | if (inp_g_sc == NULL && n == 0) { | ||||
secp256k1_scalar_set_int(&szero, 0); | secp256k1_scalar_set_int(&szero, 0); | ||||
secp256k1_ecmult(ctx, r, r, &szero, inp_g_sc); | secp256k1_ecmult(ctx, r, r, &szero, inp_g_sc); | ||||
return 1; | return 1; | ||||
} | } | ||||
if (scratch == NULL) { | if (scratch == NULL) { | ||||
return secp256k1_ecmult_multi_simple_var(ctx, r, inp_g_sc, cb, cbdata, n); | return secp256k1_ecmult_multi_simple_var(ctx, r, inp_g_sc, cb, cbdata, n); | ||||
} | } | ||||
/* Compute the batch sizes for pippenger given a scratch space. If it's greater than a threshold | /* Compute the batch sizes for Pippenger's algorithm given a scratch space. If it's greater than | ||||
* use pippenger. Otherwise use strauss */ | * a threshold use Pippenger's algorithm. Otherwise use Strauss' algorithm. | ||||
* As a first step check if there's enough space for Pippenger's algo (which requires less space | |||||
* than Strauss' algo) and if not, use the simple algorithm. */ | |||||
if (!secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, secp256k1_pippenger_max_points(scratch), n)) { | if (!secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, secp256k1_pippenger_max_points(scratch), n)) { | ||||
return 0; | return secp256k1_ecmult_multi_simple_var(ctx, r, inp_g_sc, cb, cbdata, n); | ||||
} | } | ||||
if (n_batch_points >= ECMULT_PIPPENGER_THRESHOLD) { | if (n_batch_points >= ECMULT_PIPPENGER_THRESHOLD) { | ||||
f = secp256k1_ecmult_pippenger_batch; | f = secp256k1_ecmult_pippenger_batch; | ||||
} else { | } else { | ||||
if (!secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, secp256k1_strauss_max_points(scratch), n)) { | if (!secp256k1_ecmult_multi_batch_size_helper(&n_batches, &n_batch_points, secp256k1_strauss_max_points(scratch), n)) { | ||||
return 0; | return secp256k1_ecmult_multi_simple_var(ctx, r, inp_g_sc, cb, cbdata, n); | ||||
} | } | ||||
f = secp256k1_ecmult_strauss_batch; | f = secp256k1_ecmult_strauss_batch; | ||||
} | } | ||||
for(i = 0; i < n_batches; i++) { | for(i = 0; i < n_batches; i++) { | ||||
size_t nbp = n < n_batch_points ? n : n_batch_points; | size_t nbp = n < n_batch_points ? n : n_batch_points; | ||||
size_t offset = n_batch_points*i; | size_t offset = n_batch_points*i; | ||||
secp256k1_gej tmp; | secp256k1_gej tmp; | ||||
if (!f(ctx, scratch, &tmp, i == 0 ? inp_g_sc : NULL, cb, cbdata, nbp, offset)) { | if (!f(ctx, scratch, &tmp, i == 0 ? inp_g_sc : NULL, cb, cbdata, nbp, offset)) { | ||||
Show All 9 Lines |