Skip to content

Commit 6247f48

Browse files
peterdettmansipa
authored andcommitted
Optimization: avoid unnecessary doublings in precomputation
1 parent 15d0cca commit 6247f48

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ecmult_gen_compute_table_impl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, cons
5454
secp256k1_gej_set_infinity(&sum);
5555
for (tooth = 0; tooth < teeth; ++tooth) {
5656
/* Here u = 2^((block*teeth + tooth)*spacing) * gen/2. */
57-
int bit_off;
5857
/* Make sum = sum(2^((block*teeth + t)*spacing), t=0..tooth) * gen/2. */
5958
secp256k1_gej_add_var(&sum, &sum, &u, NULL);
6059
/* Make u = 2^((block*teeth + tooth)*spacing + 1) * gen/2. */
6160
secp256k1_gej_double_var(&u, &u, NULL);
6261
/* Make ds[tooth] = u = 2^((block*teeth + tooth)*spacing + 1) * gen/2. */
6362
ds[tooth] = u;
64-
/* Make u = 2^((block*teeth + tooth + 1)*spacing) * gen/2. */
65-
for (bit_off = 1; bit_off < spacing; ++bit_off) {
66-
secp256k1_gej_double_var(&u, &u, NULL);
63+
/* Make u = 2^((block*teeth + tooth + 1)*spacing) * gen/2, unless at the end. */
64+
if (block + tooth != blocks + teeth - 2) {
65+
int bit_off;
66+
for (bit_off = 1; bit_off < spacing; ++bit_off) {
67+
secp256k1_gej_double_var(&u, &u, NULL);
68+
}
6769
}
6870
}
6971
/* Now u = 2^((block*teeth + teeth)*spacing) * gen/2

0 commit comments

Comments
 (0)