WebAssembly / wasi-crypto

WASI Cryptography API Proposal
163 stars 25 forks source link

Some fix on hostcalls and binding #49

Closed sonder-joker closed 2 years ago

sonder-joker commented 2 years ago

2a38ea7f78d9a839 I found that I can't compile, rust hint me to add use 5fa015bf38216 Seem we should link to single module? @jedisct1 Also, are you interested in posting the guest-implementation on crates.io? It seem lack key exchange's encapsulate, I'm glad to contribute on it.

jedisct1 commented 2 years ago

5fa015bf382163acf1fd1f54cd86ca502ae21161 shall we?

These are different modules. wasi_ephemeral_crypto.witx includes other modules, but that doesn't make their content part of its own key space. In wasmtime, each of these module is in its own key space.

Having support for key exchange would indeed be great!

jedisct1 commented 2 years ago

The main issue with these bindings is the raw.rs file.

It was generated from the 0.8 witx files, with a tool that was part of the witx crate. Version 0.9 of the crate changed the witx format; the tool is still here but outputs broken code with incompatible types redefinitions.

So we need to rebuild it with witx-codegen, and adjust the rest of the code first :/

jedisct1 commented 2 years ago

I managed to update the raw.rs file with witx-generate-raw, so at least we get the correct types and identifiers.

jedisct1 commented 2 years ago

2a38ea7f78d9a8391fc3144b5f16d530d27e498b is weird.

That file implements EdDSA, so importing a k256 type or trait doesn't make sense.

What exact error do you get? I was not able to duplicate this.

sonder-joker commented 2 years ago

2a38ea7 is weird.

That file implements EdDSA, so importing a k256 type or trait doesn't make sense.

What exact error do you get? I was not able to duplicate this.

error[E0599]: no function or associated item named `from_bytes` found for struct `ed25519_dalek::Signature` in the current scope
--> src/signatures/eddsa.rs:162:57
|
162 |         let dalek_signature = ed25519_dalek::Signature::from_bytes(&signature_u8)
|                                                         ^^^^^^^^^^ function or associated item not found in `ed25519_dalek::Signature`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
1   | use k256::ecdsa::signature::Signature;
|
help: there is an associated function with a similar name
|
162 |         let dalek_signature = ed25519_dalek::Signature::to_bytes(&signature_u8)
|                                                         ~~~~~~~~

I build hostcall both in nightly(2022.3.28) and stable(1.59.0). I have also reinstall rustup, but also get same error message.

sonder-joker commented 2 years ago

After read ed25519 and ed25519_dalek, I found a solution ed25519_dalek reexport ed25519's signatures, so I read ed25519 source and found this trait will work well.

-        let dalek_signature = ed25519_dalek::Signature::from_bytes(&signature_u8)
+        let dalek_signature = ed25519_dalek::Signature::try_from(signature_u8)

If I add ed25519 in cargo.toml and use ed25519::Signature::from_bytes, it also can be compiled. However, this is still confusing. I'm still not quite sure the reason for the compilation error.

jedisct1 commented 2 years ago

Weird. It compiled fine without that change here. Did you run cargo update first? Anyway, it still compiles fine with try_from as well.

sonder-joker commented 2 years ago

Weird. It compiled fine without that change here. Did you run cargo update first? Anyway, it still compiles fine with try_from as well.

My fault, after cargo update everything worked fine