libsodium.js icon indicating copy to clipboard operation
libsodium.js copied to clipboard

crypto_pwhash() returns buffer of null bytes

Open paraboul opened this issue 4 years ago • 2 comments

I was testing some code using libsodium-wrappers (not the sumo version) inside Blisk (https://blisk.io/) which uses Chromium.

This code :

sodium.crypto_pwhash(32, password, "0000000000000000",
    sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, 
    sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
    sodium.crypto_pwhash_ALG_DEFAULT)

is returning a buffer of the expected size but filled with only zero bytes. Uint8Array(32) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].

Lowering memlimit makes it work as expected.

The same code works properly on "regular" Chrome, so probably some memory limits triggered on Blisk.

I'd expect it to throw an error in case of memory exhaustion without having me to check the content of the returned buffer. I can see an "Invalid Operation" exception in case of memlimit being too small for instance. So error are being reported.

Any idea?

Thanks!

paraboul avatar Mar 11 '20 21:03 paraboul

Do you know whether it is using the WebAssembly code or the JavaScript one?

jedisct1 avatar Mar 12 '20 14:03 jedisct1

I tried the same test case in chrome w/o wasm (--js-flags=--noexpose_wasm), turns out it exposes the same issue.

Weird thing is that I restarted Blisk and it worked again. It's like when I tried yesterday WebAssembly refused to allocate more memory, or was disabled by Blisk for some reason.

Now, looking at the code, that would mean that argon successfully returned even though it couldn't allocate the requested memory.

paraboul avatar Mar 12 '20 16:03 paraboul

Probably a duplicate of #310

jedisct1 avatar Feb 16 '23 19:02 jedisct1