-
Notifications
You must be signed in to change notification settings - Fork 27
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
SCryptFunction.check() should honor derived0.length #24
Comments
Hi @dpatriarche that sounds a great feature! |
Okay, I'll do that. |
Looking at the code further, I believe that Do you agree that this is the case? If so, then I can address this too in One last thing: Is there a reason the algorithms keep a persistent |
When checking scrypt hash, respect the input hash's derived key length When checking bcrypt, scrypt, argon2, and compressed pkdf2 hashes, accept "non-standard" parameters
Yes that was done on purpose: the system configurations determine the way the password are checked, not the data retrieved from database. Password.check(userPassword, hashFromDB).with(SCrypt.getInstanceFromHash(hashFromDB)); or Password.check(userPassword, hashFromDB).with(SCrypt.getInstance(N, r, p)); The problem in both approaches, as you correctly pointed out, is that there is no way to explicit a key length different from 64 bytes. A new method A few thoughts about the persistent
|
Ah okay, thanks for the insight! I will rework my pull request to conform to the above, with the new method |
Thank you for your work @dpatriarche! |
My pleasure, happy to contribute! |
Hi @dpatriarche release 1.5.1 contains your fix and it has been published in maven central. |
Thanks very much, I have updated my project to use the new version. |
Describe the bug
I am considering migrating from com.lambdaworks:scrypt to com.password4j:password4j. The derived key length of hashes generated by the lambdaworks implementation is 32 bytes, while password4j's scrypt implementation produces 64 byte derived keys. This is fine. The problem is that when checking against an existing hash, password4j's scrypt's check() method requires that the input hash's derived key be 64 bytes. If the derived key length of the input hash is not 64 bytes then check() returns false (com.password4j.SCryptFunction line 151).
To Reproduce
Verify with these (valid) hashes generated by com.lambdaworks:scrypt:
Test hash 1: password = "Hello world!"
$s0$e0801$fl+gNAicpGG4gLMkUTCvLw==$N5wE1IKsr4LPBoetJVW6jLzEH4kTVXuKGafvAA8Z+88=
Test hash 2: password = "!@#$%^&*()_+";
$s0$e0801$1uFqXES/I17Wj6W85SLXNA==$GvPgo5L9KMtde+jpR5rRd5U7Qa6mcRMFAoy5E50iBro=
Expected behavior
I would expect that password4j's HashingFunction.check() methods respect the derived key lengths of the input hashes they are checking against. Looking at the code for password4j's argon2 implementation it does in fact appear to respect the derived key length of the input hash.
It would also be nice if password4j's scrypt had a configurable derived key length, similar to argon2's "hash.argon2.length".
Environment:
Additional context
n/a
NOTE
If you agree with the above change then I would be happy to submit a pull request.
The text was updated successfully, but these errors were encountered: