Are there any slow Javascript hashing algorithms like bcrypt?

我与影子孤独终老i 提交于 2019-12-04 10:02:05

There are currently three key-derivation functions widely considered to be secure against brute force cracking attempts. Key-derivation functions are slightly different from regular hashing algorithms in that they are designed to be slow, even in the face of modern GPU-based computation.

I'll list them in order of theoretical security:

  • PBKDF2 is designed by RSA, based on SHA, and is the algorithm recommended by NIST. There's a couple implementations that you could use in a browser.

    Note to Node users: Node's crypto module has a built-in PBKDF2 function. Use that.

  • bcrypt, based on Blowfish, is slightly more secure than PBKDF2. It has been relatively well-tested and verified secure, but does not have a stamp of approval from any standards bodies, if that's a consideration for you. There's a generic JS implementation here.

    Note to Node users: Use node.bcrypt, which performs the computationally expensive stuff on a separate thread.

  • Finally, scrypt is far and away the most theoretically secure (slowest) KDF. Unfortunately, the algorithm is very new, so it has not been validated by rigorous study and testing by the cryptographic community. It is, however, on track to become a IETF standard.

    Because the algorithm is so new, it is hard to find implementations. I could only find this half-baked one. While the security benefits are very promising, I would not recommend scrypt until both the algorithm itself and its implementations are verified secure.

How do these three actually compare? The scrypt paper has a comparison:

Realistically, even PBKDF2 makes it cost-prohibitive for anyone but a government to crack a single 8-character password.

You can always ignore the last 10 characters of the fast SHA-256. Or xor the first 10 characters to be included.

SHA has a variable number of rounds. Two rounds of SHA should be reversible somewhat. I have a vague idea that 20 rounds is considered "safe". 30 rounds should be "highly secure" and 50 rounds doesn't practically improve at all the security.

SHA is designed to be secure -- not by hoping that the cracker has a slow enough machine -- but by mathematical proof. If and when the number of irreversible bits in each round is increased and permuted to the 256 bit hash code, there will never be enough computer power to try all possible sequences that generate that particular hash code. Not even enough energy in the universe to wrap a 256-bit counter.

Unless the string that produces the hash is very small or written on a post-it on somebody's monitor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!