I suspect that the bug is here:
private byte[] CryptRaw(byte[] password, byte[] salt, int logRounds) {
// ... snip ...
int rounds = 1 << logRounds;
// ... snip
}
When you specify 31 for the logRounds
, it computes that as 2^32, which can't fit in an int
and overflows, so the hash is actually done in... er, zero passes. The author should have used uint
instead. Easy to fix!
Also wanted to comment on this:
I realize we'll probably not need a randomly generated 30 characters salt to create our password hashes...
Note that the logRounds
parameter does not refer to the number of characters/bytes in the salt, which is always 16. It refers to the logarithmic base of the number of passes that the hash will take to compute; in other words it's a way to make bcrypt scale with Moore's Law, making the function several orders of magnitude more expensive to compute if computers ever get fast enough to crack existing hashes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…