4 ms·
Or would it better to use bcrypt or something like PBKDF2? If you're going to use either, use scrypt. However... I tried to come up with my own protocol ...
by cperciva 17y ago
Or would it better to use bcrypt or something like PBKDF2?
If you're going to use either, use scrypt. However...
I tried to come up with my own protocol
...this is a bad idea unless you know what you're doing, and...
one that would use two hash functions (SHA-256 and something else). It would take the password, a random salt for each user and a nonce (their user ID), concatenate the three values together, hash them, then with the second hash function either hash the hash and store it, or hash the values again separately and store both hashes.
... based on this, you either (a) have no clue what you're doing, or (b) utterly fail at explaining what you're doing, given that I haven't a clue what you're trying to do.
Let's start at the beginning: What problem are you trying to solve? Don't try to explain a potential solution -- explain the problem, phrased something like "I have X, and I want to be able to do Y, but want to make sure that an attacker who is able to do Z doesn't become able to do W".
- cryptonewbie 17y agoThanks for the reply. I am building a web application, and I need to be able to store the passwords of its users securely on disk. I know hashing them with a salt and nonce is better than nothing, and that you should avoid older, broken hash functions like MD5 or SHA-1 and opt for something like SHA-256, but beyond that I am kind of at a loss.
- cperciva 17y agoI am building a web application, and I need to be able to store the passwords of its users securely on disk. Define "securely". What sort of attacks are you concerned with? Someone trying passwords via your web application? Someone breaking into your server and reading the hashed passwords from disk? Someone installing a rootkit and grabbing users' passwords as they log in?
- cryptonewbie 17y agoI would like the protocol to be secure to the point that an attacker possessing a stolen hard drive with the database containing users' passwords on it, would be unable to either a) figure out what the plaintext password of any user is, or b) generate a new password such that it, when put through the protocol, results in the same hashed/encrypted password of a user. If they can install a root kit, perform a cold boot attack or something similar (access the RAM), I'm willing to concede to them.
- cperciva 17y agoNow we're getting somewhere. :-) When a user's password is set, generate a random salt, compute K = scrypt(salt, password), and store (user, salt, K) in your database. To verify a password, look up the user's salt value, compute K' = scrypt(salt, password'), and compare K' to K. You don't need this much strength, but as a matter of course I would recommend using a 256-bit salt and a 256-bit output from scrypt -- the reasoning being that using 256 bits isn't going to be a performance-limiting factor, and that if you try to figure out exactly how many bits you need, there's a risk that you'll make a mistake. If you can't use scrypt, I'd recommend PBKDF2-SHA256; if that's also unavailable, use bcrypt.
- cryptonewbie 17y agoThanks!