5

Assumed knowledge
Hashing, Salting, PBKDF[1-2]

Problem
I am storing passwords in my database using a scaled hashing/salting algorithm like PBKDF2. I thought 'Hey, if i hash my passwords 20000 times, that should be secure enough against brute force attacks right?' and its true. until next year when better computers come out.

Possible solution

Leaving aside the issue of encryption key length, and salt length (which can be incorporated into this solution as well) I thought, what if every N days, i re-hash all the passwords in the database. So they are hashed 20,000 times, then a week later, i hash them a further 500 times, making them a total of 20,500 times. Store the number of times it has been hashed in the database somewhere. The idea is to increase the hash count as technology progresses.

Existing similar implementations
BCrypt introduces a work factor to increase time taken to hash a password:
PBKDF2 uses a number of iterations to do the same thing. This is used by Mac OS-X, windows and linux for file level encryption. Wi-Fi networks also use implementations of it.

Can anyone see a problem with this? Has this already been tried? Is there an algorithm out there that accepts a pre-hashed password and re-hashes it 'N' times?

Edit
The question is not if multiple hashing is secure (this has been tried and tested). The question is around re-hashing to increase security without having to make the users re-set their passwords

Solution: courtesy of discussion with JVestry

So re-hashing all the passwords every 'N' days is a waste of time since the hacker can just crack it by using an old copy of the database. However, if you combine the concept of increasing the hash count over time to a password renewal policy, the concept is sound.

Implementation
All passwords expire every 30 days. When they are renewed, their hash counter is increased. So a password reset yesterday will be harder to crack than one set 20 days ago. Hash counter can either be stored or derived from an algorithm using the last modified date.

Thanks!

TTD

7
  • So then when someone logs into your site/application it takes 1 minute to hash their password a ridiculous amount of times? Aug 19, 2011 at 0:35
  • If you hash it 20,000 times, it takes an average server ~1 second to re-hash. The advantage is, now instead of a hacker being able to try 20,000 passwords in a second, they can only try 1. The cost to the user is miniscule (network latency will still be a greater consideration) Aug 19, 2011 at 0:42
  • 2
    "That should be secure enough against brute force attacks..." That's a dangerous attitude, where security is concerned. If you can't PROVE your method is secure, you're far better off using a well-known method that's already been thoroughly vetted by experts.
    – Jim Lewis
    Aug 19, 2011 at 0:43
  • Read the page on PBKDF2, it is used by all major operating systems and network security companies. I am talking about increasing it as time progresses to keep up with Moore's law Aug 19, 2011 at 0:45
  • How is what you're doing keeping up with Moore's law, exactly?
    – Joe
    Aug 19, 2011 at 0:47

2 Answers 2

3
Can anyone see a problem with this?

Yes. Assuming that you would rehash weekly with the salt (which I believe is what you mean), there is still an issue. If someone manages to have access to a hashed password at week x, then any further hashing at week x + n does not provide any extra security.

The hacker only has to work on so much iteration at week x. Once a key is broken, he/she just has to hash it a little more like you do each week. This is dead easy and goes completely unnoticed.

If you rehash, do it with a new salt and from scratch with more iterations. Your shortcut does not bring extra safety.

6
  • +1 for getting the time latency issue. But this means the hacker is still working on an old database, so your password timeout policies is what comes into play here. I am looking more at 1 year down the track, where computers have advanced significantly. the change over a month or two months is a non issue since computers dont change THAT quick :) Aug 19, 2011 at 1:19
  • Also, given you dont know the original password, how can you re-hash from scratch with more iterations? Aug 19, 2011 at 1:20
  • Brute force attack will reveal the password. If it is cracked once, it is cracked until the renewal. Collision attacks are also possible. By rehashing the hashes, you provide more and more information too. Still not a good idea. If password timeouts, then you will have to hash with x + n iterations anyway. So no benefit from the shortcut. Just the illusion of a benefit. Aug 19, 2011 at 1:24
  • I was kind of assuming that the hacker got access to your database, and knows your hashing algorithm, the salt etc already. Is that a stupid assumption to make? Aug 19, 2011 at 1:27
  • @TechTestDude If you anticipate that 100 iterations are necessary a year from now for security, make sure that ALL passwords that have not been hash 100 times a year from now are automatically disactivated a year from now. Hence, you won't be hashing over and over unnecessarily. Aug 19, 2011 at 1:31
2

This would make brute-force breaking harder, but also makes your login process slower.

You're better off using more salt.

1
  • 1
    Increasing salt length can be done in addition to this, but given the hacker knows your salt, the brute force attack will be able to get a single hashed password fairly quickly. I always assume the hacker knows the salt. Aug 19, 2011 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.