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 support? #141
Comments
I tried a prototype, but it turned out that currently it's not faster than the existing pure JS (nacl-fast) implementation. https://twitter.com/dchest/status/935099198583779328 I expect that a different, fully 64-bit X/Ed25519 implementation will be faster, but it will also be larger and, to some extent, out of scope for tweetnacl.js (which is a port of tweetnacl.c, mostly). SHA-512 should also be faster, but it's now shipped with browsers in WebCrypto API (with async interface, so we can't directly plug it into the current library API, unfortunately). So, I'm kinda torn between the choices:
It would also make sense to switch the current API to be async like WebCrypto so whatever the choice, maybe it can be implemented as a separate project instead. |
interesting. I'd be on board with 64bit implementations of everything. :-)
I've been toying with libsodium.js's wasm and it's all async, because the wasm loader has to be async.
I'm with ya here. :-) |
I too would like to see wasm support. The available methods are in tweetnacl.d.ts. Still need to write up tests and verify all of the functionality. I am interested in making this work with the type definitions here. |
Have you tried the benchmarks in firefox? Firefox has been super speedy with most WebASM stuff. |
@sshelton76 I ran the benchmark in node, which supports WASM :- You're welcome to try though: benchmark code is here: https://github.com/NullVoxPopuli/emberclear/tree/master/packages/benchmarks/crypto |
Hi, I just ported the signing part (ed-25519) of tweetnacl-js to Wasm, available here: https://github.com/mitschabaude/watsign Besides rewriting the whole thing in raw WebAssembly, I also jumped on the opportunity to use the Web Crypto API for SHA-512 for some additional speed gains. It might interest you that the result is considerably faster than tweetnacl-js. Here are some benchmarks for signing / verifying:
First run after page load (varies between runs!):
sign (short msg): 3.40 ms
verify (short msg): 2.09 ms
sign (long msg): 1.71 ms
verify (long msg): 2.06 ms
Average of 50x after warm-up of 50x:
sign (short msg): 1.12 ± 0.14 ms
verify (short msg): 1.57 ± 0.23 ms
sign (long msg): 1.48 ± 0.13 ms
verify (long msg): 1.77 ± 0.13 ms
First run after page load (varies between runs!):
sign (short msg): 29.58 ms
verify (short msg): 15.70 ms
sign (long msg): 91.31 ms
verify (long msg): 22.83 ms
Average of 50x after warm-up of 50x:
sign (short msg): 4.13 ± 0.37 ms
verify (short msg): 8.25 ± 0.42 ms
sign (long msg): 8.65 ± 0.42 ms
verify (long msg): 10.87 ± 0.48 ms I also included benchmarks of running immediately after page load, because that is relevant on the web. As you see, fast startup is where Wasm really shines. But the warmed-up benchmarks are also quite good. Even the "short message" version, which doesn't really benefit from faster SHA-512, is more than 3x faster with Wasm. These numbers were done on a medium-end laptop (Intel i7). The performance difference tends to be larger on higher-end machines. Anyway, thanks @dchest for your super useful library which I'm using all the time ❤️ |
I've decided that it wouldn't be wise to add WASM support to TweetNaCl, since proper C/Rust/Zig/etc libraries can be compiled and used instead of this one. |
It'd be great of this library could run in a web-assembly environment for boosted speed.
The text was updated successfully, but these errors were encountered: