4 ms·
"Do not use MD5" is repeated often in the discussion. But are the weaknesses in MD5 relevant to hashing someone's 17 character password? The problem with MD5
by kazinator 12y ago
"Do not use MD5" is repeated often in the discussion.
But are the weaknesses in MD5 relevant to hashing someone's 17 character password?
The problem with MD5 is that it's possible to alter a document such that the forged document still has the same digest. This is a problem for digital signing.
That doesn't seem directly relevant to password hashing. Nobody wants to find some 596 character string which has the same MD5 hash as your 17 character password, even if it does work in its place.
Your password isn't a document that is being digitally signed by its hash for the sake of certifying its authenticity. Nobody is even supposed to store that document!
(Someone tell me where I went wrong, if so.)
- Someone1234 12y agoLet's make the following assumption: That no matter what algorithm we pick we're utilising per-user salts. So you'll always need to search the full keyspace (e.g. 6-9 character length passwords). The reason why MD5, 3DES, and similar algorithms aren't really recommended in 2014 is that they're very fast/efficient on modern hardware. This is due to utilising GPU cores to do the hashing (which wasn't done back when MD5 was popular). This means the "time to crack" is low. Here is benchmarks of different hashing algorithms (faster is WORSE): http://thepasswordproject.com/oclhashcat_benchmarking http://thepasswordproject.com/oclhashcat_benchmarking But the really nice part about things like BCrypt and PBKDF2(Rfc2898) is that they accept "rounds." Which is number of repeated iterations over the password+salt. So every year you can respond to faster hardware by adding more rounds (e.g. 2014, have 10K rounds, in 2020 have 15K rounds, etc). If MD5 had supported rounds, it might still be safe to use today with enough iterations. Even things like BCrypt and PBKDF2 will eventually fall by the wayside (MD5 used to be a more secure alternative to the much faster DES algorithm). But at least rounds (additional iterations to respond to changes in hardware) will keep them relevant for longer.
- sarciszewski 12y agoThe problem is, simply, that cryptographic hashes are very fast and not meant for user-generated passwords. For that, a special sub-class of cryptographically hashes (called Key Derivation Functions) are recommended to make brute-force computation much more difficult. KDFs are meant to require a great deal more computation (e.g. an example of PBKDF2 might iterate HMAC-SHA256 8,000 times).
- kazinator 12y agoBut then "do not use MD5" is still a cluelessly strong statement. It should be: "do not use any un-iterated message digest function for passwords: password hashing functions iterate a basic hash through numerous rounds, perhaps thousands; and some even encode the number of rounds as part of the salt, so the rounds can be increased in the future without changing the function, so it still recognizes old passwords."
- laumars 12y agoYou raise some good points, but the issue with MD5 are largely down to speed. MD5 is fast - and while computational speed is normally your friend, with cryptography it's your worst enemy. Simply put, the faster the cipher, the more break in attempts a cracker can have per second. This is why password strengths are often represented in duration (ie how many years would it take to crack). Though those figures are hugely estimated - to the point of being practically worthless.
- kazinator 12y agoBut other digest algorithms are also fast, so the argument is stupidly strong; it should be "do not use any fast message digest algorithm in its naked form for password hashing".
- sarciszewski 12y agoThat's essentially what is meant when people say "use a 'password hashing' function, not a mere cryptographic hash"
- kazinator 12y agoThanks folks; I brushed myself up on this thanks to this discussion. An interesting feature of some dedicated password hashes is that the salt input can contain encoded parameters, such as the number of rounds or maybe even choice of algorithm. This means that we can "future proof" a hash to some extent, while allowing it to support existing old passwords, while increasing the number of rounds for new passwords. A plain message digest function doesn't have these features, needless to say.
- sarciszewski 12y agoYou can also encode "version" information (e.g. $2a$ vs $2y$ for bcrypt) so that, if a vulnerability is discovered in a prior implementation, you can re-hash with a safe algorithm transparently without having to go "everyone, reset your passwords!"
- deleted 12y ago[deleted]
- ceejayoz 12y ago> That doesn't seem directly relevant to password hashing. Nobody wants to find some 596 character string which has the same MD5 hash as your 17 character password, even if it does work in its place. A SQL injection vulnerability lets you get the MD5 hashed passwords out of a database. As most people don't use 17 character passwords, you can check the MD5 hashes against a rainbow table (you can even do it online) and probably find a privileged user account pretty quick. I actually broke into a legacy system my predecessor programmed in this manner when I couldn't find documented admin credentials.
- peterwwillis 12y agoMD5 is vulnerable to collision and preimage attacks, which is bad for your password hashes, period. Other functions provide additional computational difficulty in doing exhaustive search of the keyspace. Even more functions prevent hardware implementations from speeding up the process by requiring excessive amounts of memory. This is why everyone suggests using bcrypt or scrypt, or if they're not available, PBKDF2.
- danielweber 12y agoWhat's the smallest message anyone has gotten MD5 collisions on?
- tedunangst 12y agoHow are collisions and preimage attacks relevant for password hashes?
- peterwwillis 12y agoIn really simple terms, if either attack is possible, it potentially becomes easier to find the password. If either attack's implementation becomes slightly faster at finding the password than a full search of the key space, this makes cracking easier. Collisions are the most practical method of attack on password hashes. If you develop a way to find collisions faster than an exhaustive search of the key space, you shorten the time it takes to find a password that matches the hash. Collisions have now been found on MD5 very quickly (on the order of hours). Preimage attacks are not all that useful when password cracking because you don't need to generate a new message that hashes to the same hash you have now, you're looking for any message that hashes to the hash you have now. Second preimage attacks aren't relevant because they assume you know the password already and are looking for a new message/hash that match.
- tedunangst 12y agoCollisions for arbitrary hashes? If I give you an MD5 hash, you can find a collision within hours?
- ownagefool 12y agoJust suggesting you hash a password is pretty poor form as it'll be easy generate a rainbow table for, and likely many already exist. You use a salt to mitigate this but even if you use a salt, it _has_ to be stored somewhere. Once an attacker has it, they'll be able to create rainbow tables with this in mind. You then move to using a different salt for every password so any rainbow table only works for one result but if you use a fast hashing algorithm, attackers will still be-able generate rainbow tables based on those salts. So you pick a slower hashing method but in the future, as computer hardware advances, you'll be in the same situation where it's trivial to brute force some rainbow tables. So you need to keep on top of it and keep updating the stored hashes with something that is non-trivial to brute force, in PHP this gives you these functions: http://php.net/manual/en/ref.password.php http://php.net/manual/en/ref.password.php. In reality though, in the event of a breach, all you're doing is buying time for your users to change their passwords before the relevant rainbow tables are generated, so the next important step is to let your users know their hashed passwords were leaked, you followed best practices, but they should update the passwords wherever they used it.
- marcosdumay 12y agoTechnically, no, it's not relevant. (Things change if you use "only" 13 characters.) In practice, we don't know how crypto analisys will evolve, and non-broken algorithms are free for use, and just as easy as MD5. So, why do you insist on using a broken one?
- danielweber 12y agoIf your 17 characters are distributed equally along just the letters a-z, no one can build a useful codebook during their lifetime. If your 17 characters are 3 lowercase non-archaic English words, maybe with two digits at the end, then a codebook for them already exists in MD5.