Tentative fix for #345 - constant-time scalar mul with endomorphism acceleration wrong result#346
Conversation
…alar decomposition instead of +1 sign bit
mratsim
commented
Jan 20, 2024
| when babai(F)[i][1]: | ||
| # prod_high_words works like logical right shift | ||
| # When negative, we should add 1 to properly round toward -infinity | ||
| alphas[i] += One |
Owner
Author
There was a problem hiding this comment.
This is the main change. Papers that introduce the Babai's rounding unfortunately use shifts but do not go over the negative special case.
Owner
Author
|
Change of fix approach, Adding an extra bit also on scalarMul_vartime fails, which suggest the issue is not in the bit length. When developing endomorphism years ago, the papers didn't special-case Babai's rounding for negative scalars. Now what's curious is that it has not trigger any error so far in Google Ossfuzz. |
Owner
Author
|
The CI failure is due to some Nim upstream bug when declaring Same issue as #332 (comment) Besides removing the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This tentatively fixes #345 with the simple approach explained in #345 (comment) to add an extra bit to hold the decomposed miniscalars.
This will be kept as a fix if we can also relax the requirement for exact bit match for
scalarMul_vartimewhen dispatching to endomorphism.constantine/constantine/math/elliptic/ec_scalar_mul_vartime.nim
Lines 353 to 377 in dbd2630
In that case, we can remove the current way to handle negative mini-scalars by negating the curve point.