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

Build fails for wasm32-unknown-unknown target #657

Closed
sallar opened this issue May 27, 2018 · 9 comments
Closed

Build fails for wasm32-unknown-unknown target #657

sallar opened this issue May 27, 2018 · 9 comments

Comments

@sallar
Copy link

@sallar sallar commented May 27, 2018

Hi,

I'm trying to use Ring in WebAssembly, but when I try to build it for wasm32-unknown-unknown I get this error:

› cargo build --target wasm32-unknown-unknown
   Compiling unicode-xid v0.1.0
   Compiling serde v1.0.62
   Compiling wasm-bindgen-shared v0.2.11
   Compiling itoa v0.4.1
   Compiling dtoa v0.4.2
   Compiling cc v1.0.15
   Compiling libc v0.2.41
   Compiling untrusted v0.6.1
   Compiling proc-macro2 v0.4.3
   Compiling ring v0.13.0-alpha3
   Compiling quote v0.6.2
   Compiling syn v0.14.0
error: failed to run custom build command for `ring v0.13.0-alpha3`
process didn't exit successfully: `/Users/sallar/Projects/buttercup/wasmcane/target/debug/build/ring-66839d4f06759801/build-script-build` (exit code: 101)
--- stdout
Apple_PubSub_Socket_Render: /private/tmp/com.apple.launchd.MhcIwTZlPI/Render
CARGO: /Users/sallar/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/cargo
CARGO_CFG_DEBUG_ASSERTIONS:
CARGO_CFG_PROC_MACRO:
CARGO_CFG_TARGET_ARCH: wasm32
CARGO_CFG_TARGET_ENDIAN: little
CARGO_CFG_TARGET_ENV:
CARGO_CFG_TARGET_HAS_ATOMIC: 16,32,8,ptr
CARGO_CFG_TARGET_OS: unknown
CARGO_CFG_TARGET_POINTER_WIDTH: 32
CARGO_CFG_TARGET_VENDOR: unknown
CARGO_FEATURE_DEFAULT: 1
CARGO_FEATURE_DEV_URANDOM_FALLBACK: 1
CARGO_FEATURE_USE_HEAP: 1
CARGO_HOME: /Users/sallar/.cargo
CARGO_MAKEFLAGS: --jobserver-fds=3,8 -j --jobserver-auth=3,8 -j
CARGO_MANIFEST_DIR: /Users/sallar/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.13.0-alpha3
CARGO_MANIFEST_LINKS: ring-asm
CARGO_PKG_AUTHORS: Brian Smith <brian@briansmith.org>
CARGO_PKG_DESCRIPTION: Safe, fast, small crypto using Rust.
CARGO_PKG_HOMEPAGE:
CARGO_PKG_NAME: ring
CARGO_PKG_VERSION: 0.13.0-alpha3
CARGO_PKG_VERSION_MAJOR: 0
CARGO_PKG_VERSION_MINOR: 13
CARGO_PKG_VERSION_PATCH: 0
CARGO_PKG_VERSION_PRE: alpha3
CLICOLOR: true
COLORFGBG: 15;0
COLORTERM: truecolor
COMMAND_MODE: unix2003
DEBUG: true
DYLD_LIBRARY_PATH: /Users/sallar/Projects/buttercup/wasmcane/target/debug/deps:/Users/sallar/.rustup/toolchains/nightly-x86_64-apple-darwin/lib:/Users/sallar/.rustup/toolchains/nightly-x86_64-apple-darwin/lib
HOME: /Users/sallar
HOST: x86_64-apple-darwin
ITERM_PROFILE: Sallar / zsh
ITERM_SESSION_ID: w0t0p0:267EC4C8-76AC-45D6-A280-2C37C9654288
LC_CTYPE: UTF-8
LOGNAME: sallar
LSCOLORS: exfxcxdxbxegedabagacad
NUM_JOBS: 8
OLDPWD: /Users/sallar/Projects/buttercup
OPT_LEVEL: 0
OUT_DIR: /Users/sallar/Projects/buttercup/wasmcane/target/wasm32-unknown-unknown/debug/build/ring-8e10f066167cde5e/out
PATH: /Users/sallar/.cargo/bin:/Users/sallar/.cargo/bin:/Users/sallar/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PROFILE: debug
PROJECTS: /Users/sallar/Projects
PROMPT:
$(battery_status)in $(directory_name) $(git_dirty)$(need_push)
›
PWD: /Users/sallar/Projects/buttercup/wasmcane
RPROMPT: %{%}%{%}
RUSTC: rustc
RUSTDOC: rustdoc
RUSTUP_HOME: /Users/sallar/.rustup
RUSTUP_TOOLCHAIN: nightly-x86_64-apple-darwin
RUST_RECURSION_COUNT: 1
SECURITYSESSIONID: 186b1
SHELL: /usr/local/bin/zsh
SHLVL: 1
SSH_AUTH_SOCK: /private/tmp/com.apple.launchd.ZfUlNApE83/Listeners
TARGET: wasm32-unknown-unknown
TERM: xterm-256color
TERM_PROGRAM: iTerm.app
TERM_PROGRAM_VERSION: 3.1.6beta5
TERM_SESSION_ID: w0t0p0:267EC4C8-76AC-45D6-A280-2C37C9654288
TMPDIR: /var/folders/jc/c9wh_v4178l6tchxbklvjtgc0000gn/T/
USER: sallar
XPC_FLAGS: 0x0
XPC_SERVICE_NAME: 0
ZSH: /Users/sallar/.dotfiles
_: /Users/sallar/.cargo/bin/cargo
__CF_USER_TEXT_ENCODING: 0x1F5:0x0:0x0

--- stderr
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed

I even updated to the latest alpha, but didn't work.

Thank you :)

@eupp

This comment has been minimized.

Copy link

@eupp eupp commented Jun 11, 2018

I got same for wasm32-unknown-emscripten

Backtrace

--- stderr
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:511
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:426
   6: rust_begin_unwind
             at libstd/panicking.rs:337
   7: core::panicking::panic_fmt
             at libcore/panicking.rs:92
   8: core::panicking::panic
             at libcore/panicking.rs:53
   9: <core::option::Option<T>>::unwrap
             at /checkout/src/libcore/macros.rs:20
  10: build_script_build::build_c_code
             at ./build.rs:375
  11: build_script_build::ring_build_rs_main
             at ./build.rs:305
  12: build_script_build::main
             at ./build.rs:272
  13: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  14: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  15: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  16: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:374
             at libstd/rt.rs:58
  17: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  18: main
  19: __libc_start_main
  20: _start

@briansmith

This comment has been minimized.

Copy link
Owner

@briansmith briansmith commented Jun 11, 2018

I'm trying to use Ring in WebAssembly

Why are you trying to use ring in WebAssembly?

ring's performance and side-channel attack resistance come largely from its hand-coded native (x86_64, x86, ARM, Aarch64) assembly language code, which can't work in WebAssembly. Web browsers expose a standard crypto API to web content, and web content should generally use that crypto API, the Web Crypto API, instead of providing its own.

ring can't simply wrap the Web Crypto API because the Web Crypto API is asynchronous and ring's API is synchronous.

@sallar

This comment has been minimized.

Copy link
Author

@sallar sallar commented Jun 12, 2018

@briansmith I have anyway fixed my issue by not using ring and instead using the new RustCrypto packages that are being developed since those are all WASM-ready.

But anyway the point of using Ring in WebAssembly was using the same stack and functions across all of our products in Browser, ElectronJS, ReactNative etc. For ReactNative we are not using WASM and instead compile the rust code to staticlib.

@briansmith

This comment has been minimized.

Copy link
Owner

@briansmith briansmith commented Jun 12, 2018

Can you implement crypto in WebAssembly safely? AFAICT WebAssembly doesn't make any guarantees that are necessary for cryptography w.r.t. side channel resistance. That's why I recommend people use the web crypto API instead, within a browser.

@briansmith

This comment has been minimized.

Copy link
Owner

@briansmith briansmith commented Jan 31, 2019

Can you implement crypto in WebAssembly safely? AFAICT WebAssembly doesn't make any guarantees that are necessary for cryptography w.r.t. side channel resistance. That's why I recommend people use the web crypto API instead, within a browser.

So, after researching, it seems the web crypto API isn't really a workable solution for many applications. So, I am open to adding WebAssembly support to ring. My expectation is that we'd do it by writing pure Rust implementations of the algorithms for which we have only assembly language implementations now. Anybody who is interested in potentially sponsoring that work should email me at brian@briansmith.org.

Repository owner deleted a comment from sallar Feb 3, 2019
@josephlr

This comment has been minimized.

Copy link
Contributor

@josephlr josephlr commented Jun 18, 2019

It's worth noting that even a pure Rust implementation still has to get it's randomness from somewhere. The getrandom crate on wasm32-unknown-unknown uses either:

Both of these require calling out to JavaScript to call the browser APIs. So if we have to call out to the browser anyway, we might as well use the browser's built-in crypto.

wasm32-wasi is another matter. Here we have __wasi_random_get().

@vhnatyk

This comment has been minimized.

Copy link

@vhnatyk vhnatyk commented Jun 28, 2019

glad ring going to be on wasm soon

@briansmith

This comment has been minimized.

Copy link
Owner

@briansmith briansmith commented Jul 1, 2019

PR #863 implements SHA-2 in Rust to complement the Rust SHA-1 implementation. It should kick in automatically for the wasm32-unknown-unknown target if/when the build support for wasm32-unknown-unknown is added. PTAL if you are interested in a wasm32 port.

@briansmith

This comment has been minimized.

Copy link
Owner

@briansmith briansmith commented Jul 10, 2019

Closing this since the build doesn't fail for wasm32-unknown-unknown. Not all the functionality is implemented for this target yet, but that's a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.