-
Notifications
You must be signed in to change notification settings - Fork 476
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
Change Scalar::from_canonical_bytes
to return CtOption
#472
Change Scalar::from_canonical_bytes
to return CtOption
#472
Conversation
16abcaf
to
958a20d
Compare
@@ -50,7 +50,7 @@ required-features = ["rand_core"] | |||
cfg-if = "1" | |||
rand_core = { version = "0.6.4", default-features = false, optional = true } | |||
digest = { version = "0.10", default-features = false, optional = true } | |||
subtle = { version = "^2.2.1", default-features = false } | |||
subtle = { version = "2.3.0", default-features = false } |
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.
Note: needed for impl From<CtOption<T>> for Option<T>
[profile.dev] | ||
opt-level = 2 |
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.
This makes the tests run 5 times faster for me with cargo test
, with compile times effectively the same
958a20d
to
5ee3a07
Compare
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'm fine with these API changes, though they are not technically necessary to implement ff::PrimeField
(we can inline these changed methods into that impl if API stability is preferred here).
If we want to keep the |
I opened a similar PR a few months ago: #384 |
This is helpful for implementing `ff::PrimeField::from_repr`. Also changes `Scalar::is_canonical` to return `Choice`.
c51ba24
to
e665a4c
Compare
@elichai oh nice! maybe we can get this straightforward version in then you can rebase your PRs which add the performance improvements? |
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.
utACK, reviewed the changes and they seem correct to my understanding of the library
pub fn is_canonical(&self) -> bool { | ||
*self == self.reduce() | ||
pub fn is_canonical(&self) -> Choice { | ||
self.ct_eq(&self.reduce()) |
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.
Just making certain: is reduce()
constant time itself?
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's supposed to be, and if it weren't, it would be a general security issue.
Here's another argument for making this change: If someone still wants variable-time |
NOTE: includes #470 which should be merged firstMerged!This is helpful for implementing
ff::PrimeField::from_repr
.Also changes
Scalar::is_canonical
to returnChoice
.