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

WASM/no_std support #22

Closed
enfipy opened this issue Dec 9, 2019 · 4 comments
Closed

WASM/no_std support #22

enfipy opened this issue Dec 9, 2019 · 4 comments

Comments

@enfipy
Copy link

enfipy commented Dec 9, 2019

I came here from rust-crypto-wasm because of this error.

I wanted to use this crate with a wasm32-unknown-unknown target and wondering is there any possibility to add wasm support?

I faced the following error when I tried to add scrypt:

error: duplicate lang item in crate `std` (which `scrypt` depends on): `panic_impl`.
  |
  = note: first defined in crate `sr_io` (which `runtime` depends on).

error: duplicate lang item in crate `std` (which `scrypt` depends on): `oom`.
  |
  = note: first defined in crate `sr_io` (which `runtime` depends on).

error: aborting due to 2 previous errors
@newpavlov
Copy link
Member

scrypt depends on std, which causes issues in your case. It can be solved by migrating it to alloc, which will require bumping MSRV and thus releasing v0.3.0.

@newpavlov
Copy link
Member

We have released scrypt v0.3 with no_std support, also we now test that all crates can be built on WASM. So I think we can close this issue.

@slightknack
Copy link
Contributor

slightknack commented Jul 5, 2020

I'm not sure if this is just a simple misconfig-uration on my part, but I'm not able to get scrypt running on wasm32-unknown-unknown. According to this issue for the rand crate, the "wasm-bindgen" feature should be flagged for WASM compilation.

However, from past experience, rand hasn't been the most reliable for WASM for me. The getrandom crate supports WASM reliably; I wonder if it might be a good idea to switch to it. Here's my code:

# Cargo.toml

# ... snip ...

scrypt = "0.3"
// lib.rs
extern crate scrypt;
use scrypt::{ScryptParams, scrypt_check, scrypt_simple};

// ... snip ...

// in some function:
let params = ScryptParams::new(15, 8, 1).unwrap();
let password = "some password";
let hash = scrypt_simple(password, &params).expect("Rng failed");

Compiled with:

$ cargo build --lib --release --target wasm32-unknown-unknown

When run, the script reports that the Rng failed. I'm not exactly sure where this error occurs - I think it might be while filling the salt with random values in scrypt_simple. I'm going to try rewriting my own scrypt_simple that doesn't depend on the same Rng and see if an error is still thrown.

@newpavlov
Copy link
Member

newpavlov commented Jul 5, 2020

Have you tried to add this line to your Cargo.toml?

getrandom = { version = "0.1", features = ["wasm-bindgen"] }

AFAIK rand does not have any WASM-incompatible parts, so issue is usually that the getrandom feature does not get enabled.

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

No branches or pull requests

3 participants