-
Notifications
You must be signed in to change notification settings - Fork 180
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
Add skip_while
condition for scalar mul
#124
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe such logic, while relevant to this library, should be in its own function, with the suffix var_time
, as it goes against the expected constant-time implementation of the current scalar multiplication (which will naturally induce overhead).
Also such a bump in rust-toolchain should probably be made in a separate, distinct PR requiring a version bump.
|
Having a distinction between constant-time VS variable-time for operations to be used in critical cryptographic scenarios is worth the overhead, trust me 🙂 Side-channels attacks do exist and can be devastating for a reason.
They are constant-time. The use of
|
@Nashtare Ok I get your point. Just modified, tell me what you think about this, I can even add unit tests to cover this in parallel to const time implementation. |
Yeah unit tests to check consistency between the impls could be a nice add-on. |
@Nashtare Thanks for the review, unit tests are added where needed, waiting for a review/approval :) |
If you're going to make it variable time why not also remove the constant time conditional add? That will save, on average, half of the point addition steps. |
.skip_while(|c| !bool::from(*c)) | ||
{ | ||
acc = acc.double(); | ||
acc = G1Projective::conditional_select(&acc, &(acc + self), bit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you could just use a branch here, rather than conditional_select
, since this is variable-time code?
Likewise you could use a bool
instead of Choice
, which will avoid subtle
's memory barriers and should make the code easier for rustc to optimize.
During the multiplication of of G1/G2 by a scalar, the leading zeros can be skipped in the loop, because they induce unnecessary doubling calculations, giving always the identity value back before the first non zero element is reached in the rhs boolean array.
Skipping these useless calculations can reduce drastically the calculation costs, especially for small numbers.