-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
WebAssembly #103
Comments
@cekvenich Curious about the thumbs down, do you think this is a bad idea? |
Part of the reason I haven't tried to build anything requiring security in JS is I haven't wanted to deal with external dependencies (as in node.bcrypt.js) but I don't want the slowness of a pure JS implementation (like this). WASM is the future for things like this. |
WASM with a fallback to js would be amazing (https://caniuse.com/?search=wasm). But is this project even active? |
in terms of performance, I found this wasm library https://github.com/styladev/bcrypt-fast-wasm and tested it under node@14 by comparing pwd const bcryptfast = require('bcrypt-fast');
const bcryptjs = require('bcryptjs');
const bcrypt = require('bcrypt');
const pwd = 'B9qY1mIQYqmUZSeuoPD7';
const hash = '$2a$18$7FBSfQmfL/xxL5i6SGmAKOafa/9RduerptAbTDQcFHEvet5lDuYrm';
console.time('bcrypt-fast');
console.log(bcryptfast.verify(pwd, hash));
console.timeEnd('bcrypt-fast');
console.time('bcrypt');
console.log(bcrypt.compareSync(pwd, hash));
console.timeEnd('bcrypt');
console.time('bcryptjs');
console.log(bcryptjs.compareSync(pwd, hash));
console.timeEnd('bcryptjs'); the result I got was
I also compiled the bcrypt library used by The original
So probably it's not worth that much using wasm, in terms of performance. |
It would probably make a difference, if you use a c++ implementation instead of importing a rust module, which has probably some additional overhead?! |
Rust is the same sort of compiled language that C/C++ are. There won't be any overhead. |
Yeah, I am aware of that. But read the code of bcrypt-fast. It just imports the crate of bcrypt in rust. |
|
What we could actually do is to use wasm and use simd support to improve the blowfish calculations. See: Back in january I tried to do it but my wasm skills are not that great to figure it out how to migrate that asm code to simd of wasm. Even paid some people on fiver to integrate the code into c++, but basically got only scammed by shabby devs. LOL |
I actually compiled two bcrypt libraries to wasm the other day, the OpenBSD and Openwall ones. The On my M1 MacBook Air, the OpenBSD library in WASM is almost exactly as fast as this package. And the Openwall version is almost as fast as the Here is the raw data from my machine:
There is a PR to add these two new libraries to the benchmark here: napi-rs/node-rs#649 Regarding SIMD, it would certainly be interesting to use that to speed up the process. Are you aware of any C/C++/Rust code that does this? The code you linked is x86 assembly that requires AVX2, and I'm not too familiar with it in order to be able to map it over to WASM SIMD instincts without some serious work. It would probably be fun to take a crack at it though 😄 As of right now, if you want an ~11% speed increase, you can use the |
There is even a avx version of the blowfish algorithm wasm simd is 128 bit but avx is afaik 256 bit. But still. Maybe someone with assembler avx skills can do a wasm simd port. If you want we can try it together.... |
would that break servers or js running on mobiles? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions! |
I've searched through the issues in this repository and the bcrypt repository: https://github.com/kelektiv/node.bcrypt.js, and it seems like no one is discussing this.
I think it could be useful to compile bcrypt to WebAssembly. Benefits:
WebAssembly could simplify a lot of installation and distribution requirements, and still maintain good performance. I hope it will be considered.
The text was updated successfully, but these errors were encountered: