Search code examples
databasesecurityhashsalt-cryptographyrainbowtable

Salting a secret with itself before storing in a DB, what are the weaknesses?


I've heard of people using this approach and would like to know what the implications are. I just know it's a bad idea!

From what I understand, salting a password before storing the hash in a DB has the primary purpose of making every hashing algorithm unique, and thus requiring a new rainbow table for every user when trying to crack it.

How is a hash weakened in this context if the plain text was just salted with itself?

An example:

plainText = input();
saltedText = plainText + plainText;
hashedText = hash(saltedText);
db.store(hashedText);

And would the following approach have the same weaknesses or any other weaknesses?

plainText = input();
saltedText = hash(plainText) + plainText;
hashedText = hash(saltedText);
db.store(hashedText);

Solution

  • I think you have misunderstood the purpose of the salt. The salt means that the same data, hashed twice would (usually) give two different results. This prevents attacks where knowing what values can create a given hash gives you the login to everyone who uses the same password.

    As such duplicating the test to be hashed will not give you any benefits other than the perf hit of hashing more data.