Skip to content
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

make wasm32 compatible #2

Merged
merged 29 commits into from
Sep 20, 2024
Merged

Conversation

DougAnderson444
Copy link
Contributor

While trying to use multikey in WebAssembly code, I realized sodiumoxide doesn't compile to that target, and should be upgraded to the RustCrypto crates as it uses the older 8 bytes nonce instead of the latest 12 byte nonce.

I took some liberty to make some small clippy clean ups too.

I changed the serde tests, but didn't look too deeply into the details as they seem a bit fragile with the hard-coded checks in there. Recommend those serde tests be made into something a bit more robust eventually, like roundtrip or somehow codify the encoding to automate the checking. Anyway, the tests pass but should be looked at further I think.

In the meanime, this fixes issue #1 and compiles to wasm32 =)

@DougAnderson444
Copy link
Contributor Author

I also ran into the issue of using ssh-key and ssh-encoding.

This cannot compile to wasm32* either, so I placed it behind a feature flag.

I also switch new_from_random_bytes to using dalek directly to remove it's dependency on ssh-key which is not needed.

@DougAnderson444
Copy link
Contributor Author

Last blocking issue should be cryptidtech/multisig#1

Once that is merged, that dependency can be updated and this crate will compile to wasm32

@DougAnderson444 DougAnderson444 changed the title replace sodiumoxide with chacha20 and poly1305 crates make wasm32 compatible Aug 13, 2024
@DougAnderson444 DougAnderson444 marked this pull request as draft August 13, 2024 13:27
@DougAnderson444
Copy link
Contributor Author

DougAnderson444 commented Aug 22, 2024

I have excluded default-features on ssh-key & encoding, as that way we keep ssh but can build to wasm targets

@DougAnderson444
Copy link
Contributor Author

When cryptidtech/multisig#1 get merged, I'll update this PR and make it no longer Draft

@dhuseby
Copy link
Member

dhuseby commented Aug 27, 2024

Your multisig PR was just landed. Flip this one out of Draft so we can move forward.

@DougAnderson444
Copy link
Contributor Author

I updated to test test_serde_encrypted_secret_key_compact to reflect the new 12 byte chacha2-poly1305 nonce and 32 byte key.

I added various target checks in the CI, including wasm32

All tests passing now, should be good to go!

@DougAnderson444 DougAnderson444 marked this pull request as ready for review August 27, 2024 17:16
…ha20"

This reverts commit f9746b7, reversing
changes made to 9e11324.
@DougAnderson444
Copy link
Contributor Author

DougAnderson444 commented Aug 28, 2024

Sorry, fighting with Git a bit this morning. Github was showing conflicts, which I tried to resolve and now there's no conflicts showing. Weird.

Recommend running the CI again to confirm it's still good to merge and there are no conflicts.

Somewhere in my merge and revert, the clippy fixes were lost. This commit ensures all the clippy corrections are back. Git!
Copy link
Member

@dhuseby dhuseby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there was a merge/clippy --fix error in all of these changes. Duplicated code everywhere. BTW, I like fn from(mk: Multikey) better than fn from(val: Multikey). This may be my fault because I was pushing clippy fixes this week but it's in your PR so you get to fix it 😂

src/mk.rs Outdated Show resolved Hide resolved
src/mk.rs Outdated Show resolved Hide resolved
src/mk.rs Outdated Show resolved Hide resolved
src/mk.rs Outdated Show resolved Hide resolved
src/views/bls12381.rs Outdated Show resolved Hide resolved
src/views/bls12381.rs Outdated Show resolved Hide resolved
because Dave likes it better
Copy link
Member

@dhuseby dhuseby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the SshError derivation to use thiserror and a lot of the changes go away because the error elision is possible at compile time. There's also a few changes you made that are incorrect. I think using standard macros like vec! and matches! produces faster code IIRC.

Cargo.toml Outdated Show resolved Hide resolved
src/cipher.rs Show resolved Hide resolved
src/error.rs Show resolved Hide resolved
src/error.rs Show resolved Hide resolved
src/mk.rs Show resolved Hide resolved
src/mk.rs Outdated Show resolved Hide resolved
src/nonce.rs Outdated Show resolved Hide resolved
src/views/bls12381.rs Outdated Show resolved Hide resolved
src/views/bls12381.rs Show resolved Hide resolved
src/views/chacha20.rs Show resolved Hide resolved
@DougAnderson444
Copy link
Contributor Author

@dhuseby I believe I have addressed and changed all your points, can you have another look with the latest commits?

Copy link
Member

@dhuseby dhuseby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/error.rs Show resolved Hide resolved
@dhuseby
Copy link
Member

dhuseby commented Sep 20, 2024

🚀

@dhuseby dhuseby merged commit 66eb925 into cryptidtech:main Sep 20, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants