Skip to content

Commit 867fe34

Browse files
pippenger/geh step 2: Use geh in entire accumulation
1 parent 2ccc5e0 commit 867fe34

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/ecmult_impl.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,13 @@ struct secp256k1_pippenger_state {
497497
* to the point's wnaf[i]. Second, the buckets are added together such that
498498
* r += 1*bucket[0] + 3*bucket[1] + 5*bucket[2] + ...
499499
*/
500-
static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_window, struct secp256k1_pippenger_state *state, secp256k1_gej *r, const secp256k1_scalar *sc, const secp256k1_ge *pt, size_t num) {
500+
static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_window, struct secp256k1_pippenger_state *state, secp256k1_gej *rj, const secp256k1_scalar *sc, const secp256k1_ge *pt, size_t num) {
501501
size_t n_wnaf = WNAF_SIZE(bucket_window+1);
502502
size_t np;
503503
size_t no = 0;
504504
int i;
505505
int j;
506+
secp256k1_geh r;
506507

507508
for (np = 0; np < num; ++np) {
508509
if (secp256k1_scalar_is_zero(&sc[np]) || secp256k1_ge_is_infinity(&pt[np])) {
@@ -512,17 +513,15 @@ static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_wi
512513
state->ps[no].skew_na = secp256k1_wnaf_fixed(&state->wnaf_na[no*n_wnaf], &sc[np], bucket_window+1);
513514
no++;
514515
}
515-
secp256k1_gej_set_infinity(r);
516+
secp256k1_geh_set_infinity(&r);
516517

517518
if (no == 0) {
518519
return 1;
519520
}
520521

521522
for (i = n_wnaf - 1; i >= 0; i--) {
522-
secp256k1_geh running_sumh;
523-
secp256k1_geh rh;
524-
secp256k1_gej running_sum;
525-
secp256k1_gej rj;
523+
secp256k1_geh running_sum;
524+
secp256k1_geh tmph;
526525

527526
for(j = 0; j < ECMULT_TABLE_SIZE(bucket_window+2); j++) {
528527
secp256k1_gej_set_infinity(&buckets[j]);
@@ -553,11 +552,10 @@ static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_wi
553552
}
554553

555554
for(j = 0; j < bucket_window; j++) {
556-
secp256k1_gej_double_var(r, r, NULL);
555+
secp256k1_geh_double_var(&r, &r);
557556
}
558557

559-
secp256k1_geh_set_infinity(&running_sumh);
560-
secp256k1_geh_set_infinity(&rh);
558+
secp256k1_geh_set_infinity(&running_sum);
561559
/* Accumulate the sum: bucket[0] + 3*bucket[1] + 5*bucket[2] + 7*bucket[3] + ...
562560
* = bucket[0] + bucket[1] + bucket[2] + bucket[3] + ...
563561
* + 2 * (bucket[1] + 2*bucket[2] + 3*bucket[3] + ...)
@@ -567,19 +565,18 @@ static int secp256k1_ecmult_pippenger_wnaf(secp256k1_gej *buckets, int bucket_wi
567565
* The doubling is done implicitly by deferring the final window doubling (of 'r').
568566
*/
569567
for(j = ECMULT_TABLE_SIZE(bucket_window+2) - 1; j > 0; j--) {
570-
secp256k1_geh tmp;
571-
secp256k1_geh_set_gej_var(&tmp, &buckets[j]);
572-
secp256k1_geh_add_var(&running_sumh, &running_sumh, &tmp);
573-
secp256k1_geh_add_var(&rh, &rh, &running_sumh);
568+
secp256k1_geh_set_gej_var(&tmph, &buckets[j]);
569+
secp256k1_geh_add_var(&running_sum, &running_sum, &tmph);
570+
secp256k1_geh_add_var(&r, &r, &running_sum);
574571
}
575-
secp256k1_gej_set_geh_var(&running_sum, &running_sumh);
576-
secp256k1_gej_add_var(&running_sum, &running_sum, &buckets[0], NULL);
572+
secp256k1_geh_set_gej_var(&tmph, &buckets[0]);
573+
secp256k1_geh_add_var(&running_sum, &running_sum, &tmph);
577574

578-
secp256k1_gej_set_geh_var(&rj, &rh);
579-
secp256k1_gej_add_var(r, r, &rj, NULL);
580-
secp256k1_gej_double_var(r, r, NULL);
581-
secp256k1_gej_add_var(r, r, &running_sum, NULL);
575+
secp256k1_geh_double_var(&r, &r);
576+
secp256k1_geh_add_var(&r, &r, &running_sum);
582577
}
578+
/* TODO Return geh instead */
579+
secp256k1_gej_set_geh_var(rj, &r);
583580
return 1;
584581
}
585582

0 commit comments

Comments
 (0)