-
Notifications
You must be signed in to change notification settings - Fork 317
Adds a trait for crypto, porting EC first #606
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
Merged
Merged
Conversation
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
ia0
reviewed
Mar 20, 2023
ia0
previously approved these changes
Mar 20, 2023
ia0
approved these changes
Apr 3, 2023
Collaborator
Author
|
The failing tests are unrelated to this PR and seem to be related to a difference in compilation between debug and release mode. Locally, all tests pass. |
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 is the the first PR to introduce a Crypto API for our library.
Summary and thoughts:
p256crate (runcargo +nightly test --release --features std,ed25519,with_ctap1,vendor_hid,rust_cryptoinlibraries/opensk/). I couldn't test it on hardware yet, I didn't find a Rust compiler version that works for both Tock v1 and
p256with its dependencies. Numbers on binary size will be meaningful only after a full port, sincep256usessha2for signing, so we currently have overlap.CoseKeytype doesn't easily translate. I intend to keep all types that are used in parsing commands (rule of thumb: converts to CBOR) free ofEnv.CoseKeyis one of them. TheFromandTryFromreplacements in this PR could be improved in a follow-up PR. Best case the compiler could again ensure that we don't create an ECDHCoseKeyfrom a ECDSA public key and vice versa.TestEnvandTockEnvare currently identical. I was wondering if theyTockEnvshould just importTestEnv, but kept them fully independent for now. This way I don't have to mess with the conditional compilation and it's easier to change only one of them later (e.g. hardware crypto).pub type EcdhSk<E> = <<<E as Env>::Crypto as Crypto>::Ecdh as Ecdh>::SecretKey;Seems to me to be the best way to have less noise. The trait imports still look a bit clunky, as
SecretKeyhas the same name for ECDH and ECDSA. Which makes sense inside its namespace, but needs extra work whenuseing them. One option is to split the traits into multiple, like replacing the ECDSASecretKeywith a generalSecretKeythat has arandomand apublic_keyfunction, together with aSignertrait. But I feels like unncecessary complexity to me.Curious about your thoughts!