Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hashing Passwords With Multiple Algorithms

Tags:

security

hash

Does using multiple algorithms make passwords more secure? (Or less?)

Just to be clear, I'm NOT talking about doing anything like this:

key = Hash(Hash(salt + password))

I'm talking about using two separate algorithms and matching both:

key1 = Hash1(user_salt1 + password)
key2 = Hash2(user_salt2 + password)

Then requiring both to match when authenticating. I've seen this suggested as a way eliminate collision matches, but I'm wondering about unintended consequences, such as creating a 'weakest link' scenario or providing information that makes the user database easier to crack, since this method provides more data than a single key does. E.g. something like combining information the hash to find them more easily. Also if collisions were truly eliminated, you could theoretically brute force the actual password not just a matching password. In fact, you'd have to in order to brute force the system at all.

I'm not actually planning to implement this, but I'm curious whether or not this is actually an improvement over the standard practice of single key = Hash(user_salt + password).

EDIT:

Many good answers, so just to surmise here, this should have been obvious looking back, but you do create a weakest link by using both, because the matches of weaker of the two algorithms can be tried against the other. Example if you used a weak (fast) MD5 and a PBKDF2, I'd brute force the MD5 first, then try any match I found against the other, so by having the MD5 (or whatever) you actual make the situation worse. Also even if both are among the more secure set (bcrypt+PBKDF2 for example), you double your exposure to one of them breaking.

like image 976
Paul Avatar asked Jan 15 '13 15:01

Paul


People also ask

Which algorithm is best for hashing passwords?

To protect passwords, experts suggest using a strong and slow hashing algorithm like Argon2 or Bcrypt, combined with salt (or even better, with salt and pepper). (Basically, avoid faster algorithms for this usage.) To verify file signatures and certificates, SHA-256 is among your best hashing algorithm choices.

Can I use SHA256 for passwords?

According to the crackstation link you posted, SHA256 is a cryptographic hash function and is suitable for passwords due to low collision probability.

How many times should you hash password?

To achieve any kind of useful key stretching, you need to iterate the hash at least 1,000 times, and preferably closer to 1,000,000 times (or however many iterations the user is willing to wait for).

Can two passwords have same hash?

Two passwords can produce the same hash, it's named a “hash collision”. In this case, both passwords can be used to log in to the corresponding account. It's extremely rare for most hashing algorithms, but it may happen.


2 Answers

The only thing this would help with would be reducing the possibility of collisions. As you mention, there are several drawbacks (weakest link being a big one).

If the goal is to reduce the possibility of collisions, the best solution would simply be to use a single secure algorithm (e.g. bcrypt) with a larger hash.

like image 86
Eric Petroelje Avatar answered Sep 27 '22 00:09

Eric Petroelje


Collisions are not a concern with modern hashing algorithms. The point isn't to ensure that every hash in the database is unique. The real point is to ensure that, in the event your database is stolen or accidentally given away, the attacker has a tough time determining a user's actual password. And the chance of a modern hashing algorithm recognizing the wrong password as the right password is effectively zero -- which may be more what you're getting at here.

To be clear, there are two big reasons you might be concerned about collisions.

  1. A collision between the "right" password and a supplied "wrong" password could allow a user with the "wrong" password to authenticate.
  2. A collision between two users' passwords could "reveals" user A's password if user B's password is known.

Concern 1 is addressed by using a strong/modern hashing algorithm (and avoiding terribly anti-brilliant things, like looking for user records based solely on their password hash). Concern 2 is addressed with proper salting -- a "lengthy" unique salt for each password. Let me stress, proper salting is still necessary.

But, if you add hashes to the mix, you're just giving potential attackers more information. I'm not sure there's currently any known way to "triangulate" message data (passwords) from a pair of hashes, but you're not making significant gains by including another hash. It's not worth the risk that there is a way to leverage the additional information.

like image 29
svidgen Avatar answered Sep 27 '22 00:09

svidgen