Skip to content

Commit 9bd89c8

Browse files
Optimize secp256k1_fe_normalize_weak calls.
Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead.
1 parent 1e6f1f5 commit 9bd89c8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/ecmult_impl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(int n, secp256k1_ge
166166
if ((n) > 0) { \
167167
*(r) = (pre)[((n)-1)/2]; \
168168
} else { \
169-
secp256k1_ge_neg((r), &(pre)[(-(n)-1)/2]); \
169+
*(r) = (pre)[(-(n)-1)/2]; \
170+
secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \
170171
} \
171172
} while(0)
172173

@@ -178,7 +179,7 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(int n, secp256k1_ge
178179
secp256k1_ge_from_storage((r), &(pre)[((n)-1)/2]); \
179180
} else { \
180181
secp256k1_ge_from_storage((r), &(pre)[(-(n)-1)/2]); \
181-
secp256k1_ge_neg((r), (r)); \
182+
secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \
182183
} \
183184
} while(0)
184185

src/group_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ static void secp256k1_ge_globalz_set_table_gej(size_t len, secp256k1_ge *r, secp
178178
/* The z of the final point gives us the "global Z" for the table. */
179179
r[i].x = a[i].x;
180180
r[i].y = a[i].y;
181+
/* Ensure all y values are in weak normal form for fast negation of points */
182+
secp256k1_fe_normalize_weak(&r[i].y);
181183
*globalz = a[i].z;
182184
r[i].infinity = 0;
183185
zs = zr[i];

0 commit comments

Comments
 (0)