-
Notifications
You must be signed in to change notification settings - Fork 267
Not for merge: quick n' dirty ECDSA #57
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #[cfg(feature = "arithmetic")] | ||
| use p256::arithmetic::Scalar; | ||
|
|
||
| #[cfg(not(feature = "arithmetic"))] | ||
| fn main() {} | ||
|
|
||
| #[cfg(feature = "arithmetic")] | ||
| fn main() { | ||
| let secret_seed = [1u8; 32]; | ||
| let secret_maybe_scalar = Scalar::from_bytes(secret_seed); | ||
| let secret_scalar = secret_maybe_scalar.unwrap(); | ||
|
|
||
| let ephemeral_seed = [2u8; 32]; | ||
| let ephemeral_maybe_scalar = Scalar::from_bytes(ephemeral_seed); | ||
| let ephemeral_scalar = ephemeral_maybe_scalar.unwrap(); | ||
|
|
||
| let hashed_msg = [3u8; 32]; | ||
|
|
||
| let masking_seed = [4u8; 32]; | ||
| let masking_maybe_scalar = Scalar::from_bytes(masking_seed); | ||
| let masking_scalar = masking_maybe_scalar.unwrap(); | ||
|
|
||
| let signature = secret_scalar | ||
| .try_sign_prehashed(ephemeral_scalar, Some(masking_scalar), &hashed_msg) | ||
| .unwrap(); | ||
|
|
||
| println!("signature: {:02x?}", signature.as_ref()); | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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'd be nice to figure out a better solution for this sort of gating.
One option would be to make the arithmetic module
mod arithmetic(nopub), and then re-export the types it contains at the toplevel when thearithmeticfeature is enabled.Since
doc_cfgtags everything with the requisite cargo features, I don't think this would be confusing:https://docs.rs/p256/0.3.0/p256/arithmetic/index.html
I might open a separate PR for discussion on that idea (skipping the
expose-arithmeticstuff for now)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 think the easiest solution will be to use the
cfg_ifcrate.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.
Yeah, that would work too.
For what it's worth I opened a PR with my suggested refactoring and I like it:
#58
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.
Mmh, agreed. This is just a hack to allow use of the arithmetic in an experimental/hazmat manner outside the crate while core pieces are missing. I actually think the arithmetic should be public, but that's another topic - this PR is just to exemplify a possible ECDSA implementation.
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.
@nickray now that #58 is merged, you can refactor this to use something like the following in the toplevel of the crate: