This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
Fix KEY_LENGTH for PBKDF2 by specifying it in bits rather than bytes #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The KEY_LENGTH constant defined in the KDF.java file is set to 32, in order to stretch the user-supplied password into a 32 byte hash (256 bits) that can be used as the secret key for the ChaCha20 encryption algorithm.
However, with the current code, the PBKDF2_HMAC_SHA256 function only returns a 4 byte hash on line 43.
So, it seems that this function (but not SCRYPT and BCRYPT) requires the key length to be specified in bits rather than bytes, although this fact is not documented anywhere.
I don't think the "case PBKDF2_HMAC_SHA256" block has actually ever been tested before in context, because the ChaCha20 algorithm immediately returns an error if it is not provided with a 256 bits key.
By multiplying the KEY_LENGTH with 8, the PBKDF2_HMAC_SHA256 function returns a 256 bit key, as required, and the hash value is also identical to the one produced by the Python-implementation of Crypt4GH.