BCrypt implementation #76
Closed
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.
Implementation of raw and OpenBSD/crypt style bcrypt password hash functions.
Raw and OpenBSD style are separated.
The OpenBSD/crypt style is most useful for compatibility with existing uses or clients wanting a simple hash+params encoding.
The raw style could be plugged into a future password hash API quite easily (i.e. based on the PHC API).
To reuse the existing Blowfish implementation (having an unverified copy is the cause of at least one major bug in crypt_blowfish) BlowfishEngine is extended slightly with hooks to allow the key schedule to be overridden and for salt to be mixed in during table processing in key setup. Performance impact should be negligible given the existing cost of the Blowfish key setup.
In the OpenBSD implementation the 2 (original), 2a, 2b and 2y formats are supported (a/b/y are algorithmically equivalent, but represent bug fixes in various crypt implementations). The crypt_blowfish 2x and 'safe 2a' modes are not implemented since they require borking the BlowfishEngine (where the bug was identified).
Cross tested with JBCrypt and OpenWall crypt_blowfish test vectors (links in unit tests).
Also added checking for defined key sizes in BlowfishEngine, with a constructor/factory for uses needing unrestricted key lengths (bcrypt being one of them). That's in a separate commit, so feel free to drop/amend.