diff --git a/src/ecmult_impl.h b/src/ecmult_impl.h index c00578beda92a..508bde8ab376a 100644 --- a/src/ecmult_impl.h +++ b/src/ecmult_impl.h @@ -277,7 +277,8 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(const int n, secp25 if ((n) > 0) { \ *(r) = (pre)[((n)-1)/2]; \ } else { \ - secp256k1_ge_neg((r), &(pre)[(-(n)-1)/2]); \ + *(r) = (pre)[(-(n)-1)/2]; \ + secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \ } \ } while(0) @@ -289,7 +290,7 @@ static void secp256k1_ecmult_odd_multiples_table_storage_var(const int n, secp25 secp256k1_ge_from_storage((r), &(pre)[((n)-1)/2]); \ } else { \ secp256k1_ge_from_storage((r), &(pre)[(-(n)-1)/2]); \ - secp256k1_ge_neg((r), (r)); \ + secp256k1_fe_negate(&((r)->y), &((r)->y), 1); \ } \ } while(0) diff --git a/src/group_impl.h b/src/group_impl.h index 5caf421b5e182..bc89718648263 100644 --- a/src/group_impl.h +++ b/src/group_impl.h @@ -175,6 +175,8 @@ static void secp256k1_ge_globalz_set_table_gej(size_t len, secp256k1_ge *r, secp /* The z of the final point gives us the "global Z" for the table. */ r[i].x = a[i].x; r[i].y = a[i].y; + /* Ensure all y values are in weak normal form for fast negation of points */ + secp256k1_fe_normalize_weak(&r[i].y); *globalz = a[i].z; r[i].infinity = 0; zs = zr[i];