-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signed-digit multi-comb ecmult_gen algorithm #1057
Conversation
Just out of curiosity, some perf. numbers (best Min of 3
("experimental" is this PR plus the other PRs for normalize, group formulae, and the "vector" modinv). |
This introduces a new secp256k1_scalar_half function which multiplies a scalar with the multiplicative inverse of 2 (modulo order).
Instead of having the starting point of the ecmult_gen computation be offset, do it with the final point. This enables reasoning over the set of points reachable in intermediary computations, which can be leveraged by potential future optimization. Because the final point is in affine coordinates, its projective blinding is no longer possible. It will be reintroduced again in a different way, in a later commit. Also introduce some more comments and more descriptive names.
@peterdettman Care to redo benchmarks for the latest commit (I've removed the incomplete comb optimization, and re-added the uint32_t[9] recoded approach)? |
These were the best min I got (running the benchmark thrice) on my machine (64-bit, i7-8750H).
|
Updated perf. numbers (-O3, best Min of 3
("experimental" is this PR plus the other PRs for normalize, group formulae, and the "vector" modinv). So this looks just slightly slower than before, but perfectly fine if we are merge-focused. We can go hunting the extra 2% once we've booked the 20%. |
This introduces the signed-digit multi-comb multiplication algorithm for constant-time G multiplications (ecmult_gen). It is based on section 3.3 of "Fast and compact elliptic-curve cryptography" by Mike Hamburg (see https://eprint.iacr.org/2012/309). Original implementation by Peter Dettman, with changes by Pieter Wuille to use scalars for recoding, and additional comments.
It is unnecessary to recompute the 2^COMB_BITS-1 scalar offset needed by the SDMC algorithm for every multiplication; move it into the context scalar_offset value instead.
The existing code needs to deal with the edge case that bit_pos >= 256, which would lead to an out-of-bounds read from secp256k1_scalar. Instead, recode the scalar into an array of uint32_t with enough zero padding at the end to alleviate the issue. This also simplifies the code, and is necessary for a security improvement in a follow-up commit. Original code by Peter Dettman, with modifications by Pieter Wuille.
Restarting this in a new PR to avoid the WIP discussion: #1058. |
A third iteration of the signed-digit multi-comb ecmult_gen algorithm (earlier attempts: #693, and #546 by Peter Dettman). Short summary:
Compared with the previous PR #693: