lazysodium-android: Failing to use cryptoPwHash ()
Hi!
I Have a problem and question.
in server side the files become encrypted with secretstream and I download them in android client.
what is the best way to get header and the salt (that is using in generating key)? currently it is stored in the encrypted file, is it correct way?
but the actual problem is this:
the server side generate a secretkey using this function:
$secret_key = sodium_crypto_pwhash(SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES,
$password,$salt, $opslimit, $memlimit, $alg);
the password is something we both know, so I think for generating the same key, it just need salt and the others are constants that we both know too. but the problem is the corresponding function in android doesn’t work with any parameter!:
byte[] pass = "123456".getBytes();
salt = ls.randomBytesBuf(PwHash.SALTBYTES);
byte[] pwhashbytes = new byte[ls.getSodium().crypto_secretstream_xchacha20poly1305_keybytes()];
Boolean pTrue = ls.cryptoPwHash(pwhashbytes, ls.getSodium().crypto_secretstream_xchacha20poly1305_keybytes(),
pass, pass.length, salt,
PwHash.OPSLIMIT_INTERACTIVE, PwHash.MEMLIMIT_INTERACTIVE, PwHash.Alg.getDefault());
e("pTrue ", "" + pTrue);
and the log prints false! Thanks…
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 39 (20 by maintainers)
Commits related to this issue
- Updated Sodium #13 — committed to terl/lazysodium-android by gurpreet- 8 years ago
Hey @Hosseinyzr, @PaulSeiziger, @bodoss,
The the following should work:
In order for the fix to work please note that the only thing that I have changed is use of the “raw” sodium functions using
getSodium. So usinglazysodium.getSodium().crypto_pwhash(...)should resolve this bug for all of you. Remember to uselazysodium.toHexStr(outputHash)if you will be interacting with Lazysodium’s Lazy APIs in the future (for example, you may want to decrypt with lazysodium.cryptoPwHashStrVerify(…)).I will implement a fix in the pipeline if this works for all of you.
Hi all,
3.5.0includes a better fix along with some code improvements.Cheers 👍
@gurpreet- We noticed that crypto_pwhash() doesn’t work on ALL devices with CPU which doesn’t support AES. We use: ‘net.java.dev.jna:jna:4.5.1@aar’ ‘com.goterl.lazycode:lazysodium-android:3.3.0@aar’
@gurpreet- We use Android API 21+. On Android 6.0 with ARMV8 everything is ok, but all Android 7.1.1 (ver. doesn’t matter) ARMV7 fails. SectretBOX seems working. But with ARMV8 all schema works great. Crypt, decrypt pwhashing etc. I’ve build my own sodium .so files, named them libmysodium and load like this:
val lazySodium = LazySodiumAndroid(SodiumAndroid("mysodium"))@gurpreet- BUG reproduces for me if I run the code on armV7 devices. ArmV8 runs ok and return 0. crypto_pwhash returns -1. PwHash.Alg.getDefault() which is PWHASH_ALG_ARGON2ID13 . I’ve already tried to build my own libsodium .so files, but problem didn’t disappear. Help, Please 😃