15 ms·
How To Safely Store A Password
- tzs 15y agoWhy not PBKDF2?
- tptacek 15y agoPBKDF2 is fine. bcrypt has better library support. I'd rather you used a bcrypt library than try to roll your own PBKDF2.
- cperciva 15y agobcrypt is also slightly stronger than PBKDF2, since it requires a larger circuit to compute. The only reason you would want to use PBKDF2 is if (a) you already have a hash and don't want to add blowfish to your code/circuit, or (b) you want to be standards-compliant.
- kogir 15y agoOn .Net this is definitely the way to go. http://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes.aspx http://msdn.microsoft.com/en-us/library/system.security.cryp... Make sure to use the defaults or better in terms of rounds. The salt provided when you don't supply one is cryptographically random.
- bmj 15y agoThere is a .NET implementation of BCrypt: http://bcrypt.codeplex.com/ http://bcrypt.codeplex.com/
- llambda 15y agoAccording to the scrypt website, PBKDF2 is weaker as compared to bcrypt and scrypt: "We estimate that on modern (2009) hardware, if 5 seconds are spent computing a derived key, the cost of a hardware brute-force attack against scrypt is roughly 4000 times greater than the cost of a similar attack against bcrypt (to find the same password), and 20000 times greater than a similar attack against PBKDF2."
- ck2 15y agoand/or stop using a single word and use sentences (phrase) eight characters is easy - try cracking 50
- pavel_lishin 15y agoNot too difficult if it's composed of dictionary words. Why not automatically generate random strings to use? No pattern at all.
- cfgvjkljhgfb 15y agowith cuda and the cloud it's quicker to try all possible passwords (starting with aaaaaaa...) than to search a rainbow table of dictionary words so ":Hy6&z@z" is now no more secure than "password"
- pavel_lishin 15y agoRainbow tables don't apply to salted passwords.
- ylem 15y agoBut you can still do a brute force attack--that's part of why SHA1 has some issues--you can beat it with brute force and enough GPUs.
- tedunangst 15y agoAssuming 5 words selected from a dictionary of 234979, there are 716382975036689591261090899 possibilities. If you have 1000 computers each cracking 10 billion attempts per second, you're looking at about 1135817 years. I'm going to call that difficult.
- Xk 15y ago> and/or stop using a single word and use sentences (phrase) True. This isn't meant for the user, though. This is meant for the developers. No matter how hard the developers try, users will always pick bad passwords. If you use salted SHA-1, then if the database gets compromised there goes 50% of the passwords. If, on the other hand, you use bcrypt, maybe only 5% of the passwords get cracked. Bcrypt turns a massive news event (database leaked; thousands of passwords lost!) in to something much less newsworthy (database leaked; twenty passwords lost).
- Khao 15y agoI have read this article and read the Wikipedia entry on bcrypt and I still cannot understand something. In this article it states that : "As computers get faster you can increase the work factor and the hash will get slower.". How can you make the algorithm slower over time and still be able to validate user passwords that were stored before you changed the speed? Could anyone enlighten me on this?
- mshafrir 15y agoI believe that the work factor is encoded with the hash, so bcrypt can identify which work factor to use.
- Khao 15y agoThanks for your answer. At first I though it didn't make sense because the hash should be one-way and bcrypt should not decrypt the hash or mess around with it other than comparing it with what the user entered but I have searched a bit more and found this post on stackoverflow that explains in detail : http://stackoverflow.com/questions/4443476/optimal-bcrypt-work-factor http://stackoverflow.com/questions/4443476/optimal-bcrypt-wo... Your answer was right, it stores the work factor, the salt and the hash so that at any given time you can change the work factor and it will adjust in the database!
- chops 15y agoThe easy way is to support the previous work factors and increase it next time the user logs in (since you'll have the password in plaintext in memory). Either way, bcrypt with a paltry work factor of 7 or 8 is orders of magnitude slower than md5 and sha. Jack that up to 12 or 13 and you're pretty much good to go for years, the only problem is the near 1-second processing time on semi-current hardware.
- podperson 15y agoIt's a hash function and, at least over an insecure connection, you should not be transferring the plaintext password from client to server so it's not guaranteed that you will have the plaintext password. Assuming you're using a secure connection and you're willing to send plaintext passwords over it then yes, you could re-hash the password when a user logs in.
- firsttimeposter 15y agoPeople keep posting this here. But I think http://www.tarsnap.com/scrypt.html http://www.tarsnap.com/scrypt.html should probably be considered the best way to do this today. Google is even using it in ChromeOS.
- Xk 15y agoIt is true that scrypt is better than bcrypt, but the transition from salt+SHA-1 to bcrypt is significatnly better than from bcrypt to scrypt, and scrypt doesn't have nearly as nice of an interface as bcrypt does.
- pjscott 15y agoThe easy interface and wide availability of language bindings to bcrypt is a big deal. The easier it is to use, the more likely people are to use it, and the less likely they are to mess it up. Scrypt isn't quite there yet, and bcrypt is still very good.
- nonane 15y agoThe article claims it takes bcrypt 0.3 seconds to hash a 4 char password on a laptop. How does a server authenticate users in high volume with bcrypt? ~0.25 secs per auth request might warrant having a separate server just for authentication.
- tedunangst 15y agoMost of your traffic should be coming from people with logged in cookies. If you make people enter their password on every page, you won't have to worry about high volume. :) Note that bcrypt is basically insensitive to length of password. 4 chars, 8 chars, 32 chars, all take the same amount of time. And it's tunable. You could go down to only 0.01s per hash and still be a million times slower than plain MD5.
- darrenkopp 15y agoI don't think he's talking about users... I think he's talking about high volume web services.
- nl 15y agoWebservices usually use signed requested[1][2] for security, not username/password pairs. [1] http://oauth.net/core/1.0/#signing_process http://oauth.net/core/1.0/#signing_process [2] http://en.wikipedia.org/wiki/WS-Security#Features http://en.wikipedia.org/wiki/WS-Security#Features
- chops 15y agoIt depends on the work factor. On my dev server (a pretty old machine), with a work factor of 7, it's about 300 time slower than md5 (about 10ms per bcrypt hash). That's still plenty fast, and much more secure. Bump it to a work factor of 9, and I'm looking at about 1000 times slower (or getting close to 40 ms per hash). Part of its beauty is you can adjust the work factor to match your hardware speed requirements. If you really want ultra-secure, a work factor is 13 is getting pretty slow (about half a second per hash on my crappy machine), and yeah, that might justify an authentication server. (note: my tests were not exhaustive)
- zubisu 15y agothe weaknews is actually storing the salt or code or key with the password. using bcrypt helps a bit but doesnt truly solve the issue. i think thats important to point out. sha1 with a salt u cant find beats bcrypt with a key u know any day
- Xk 15y agoNo. Not at all. If someone managed to break in to your website and get the password hashes, chances are they also have your "secret" salt. There is no reason to separate the salt from the hash, and, in fact, there are no implementations which do that. However, if I can't convince you of that, then if you ever make a website that takes passwords, please use bcrypt. You can do your super-special-salt-separation-scheme, but just use bcrypt instead of SHA-1.
- praptak 15y ago"If someone managed to break in to your website and get the password hashes, chances are they also have your "secret" salt." I believe the GP was referring to the scheme where you don't store the salts at all (or only store some bits of each salt.) The verification needs to brute-force the salt (or the missing bits) each time it verifies the password. The missing bits are quite similar to the bcrypt workfactor - the more you leave out the harder it is for both the attacker and the legitimate verification to verify passwords.
- brown9-2 15y agoThen how in the world does your code know what salt to use when the user presents his or her password? If it is derived in code from some other piece of user data then it is still "known" if your DB leaks - you have to assume someone who stole your database also stole your code.
- roel_v 15y ago"you have to assume someone who stole your database also stole your code." Maybe, but that doesn't mean that a separate salt, not in the database, will prevent certain attacks, and as such is a viable option. Security is about layering, not about 'xyz isn't 100% secure in 100% of the cases, forget about it'.
- giaskaylee 15y agoThe real question should always be how you detect and handle these attacks. Allowing someone to attack your service for 12 years and eating up your resources in the meanwhile just sounds too passive a solution.
- Xk 15y agoThat's not the attack you worry about: instead, consider the case where someone somehow obtains the database and can do an offline attack on it. Be it a SQL injection or account compromise (or sheer negligence and publishing the database), once that happens you'd better handle passwords reasonably well. If the only attack situation you're worried about is a online guessing attack, then there's no need to even hash passwords.
- giaskaylee 15y agoSounds to be the case, thanks for the tips.
- evo_9 15y agoAnother thread where seeing Karma would really help... Maybe it should be optional?
- SkyMarshal 15y agoIf karma is needed to judge the quality of someone's post, then the karma counts are probably inaccurate anyway. At best they'd be interspersed with votes by people who just thought the answer sounded good without really knowing how accurate and informed it is. At worst, the majority of the votes would consist of that type. HN is better without karma, just think of it as a place to find out about concepts you might not have been aware, then drill down on it with some more trusted source.
- stephth 15y agoLooks like Rails 3.1 is using bcrypt: https://github.com/rails/rails/blob/master/activemodel/lib/active_model/secure_password.rb https://github.com/rails/rails/blob/master/activemodel/lib/a...
- bdclimber14 15y agoSo does Devise, one of the most popular authentication Ruby gems.
- tzs 15y agoI'd like to see sites offer the option of not using password-based authentication. Instead I'd like to see public key based authentication as an option. Basically, the site would have a copy of my public key (say my GPG key or an ssh key), and to authenticate I prove that I have access to the corresponding private key.
- caf 15y agoThat's already possible with SSL sites - sign up for an account at www.startssl.com if you want to see a real-life example.
- sunchild 15y agoOops! StartSSL was compromised this month, although they say the issue is remediated now. http://news.netcraft.com/archives/2011/06/22/startssl-suspends-services-after-security-breach.html http://news.netcraft.com/archives/2011/06/22/startssl-suspen...
- caf 15y agoYes, using client certificates for authentication does not make your service immune from security problems.
- InclinedPlane 15y agoWith smartphones this is increasingly feasible. Lots of sites already use smartphone based two factor authentication (similar to rsa keys). There's no reason why a challenge / response system couldn't be set up using smartphones. For example, a website gives you a string of numbers, you input those in your smartphone app and get the response which yiu then input back to the site, the site can't determine the response ahead of time but it can validate it.
- roel_v 15y agoThis is how blizzard (World of Warcraft) authenticators work. It's quite ironic how an online game has strong security mechanisms, yet many tools that people use just as often or more (gmail, facebook, pretty much all SaaS tools, including business) and that are are certainly more 'important' (in an objective sense, I understand that people are more attached to their WoW character than to their customer database) don't.
- tomjen3 15y agoWhat always annoys me with the discussion of passwords is that everybody here focus on a technical solution that allows the user to continue to use insecure passwords. That isn't the problem. Reuse is. And the best way around that is to not let the user select the password, just generate it server side. Technically this is easier to get right than some complex password generation scheme and the end result is properly better too.
- kriardol 15y agoI personally hate it when sites do this. That's probably the best way to make sure I don't come back, as I'm not likely to remember the generated password. Worse, how do you give them the password? Email?
- alanfalcon 15y agoAlso you have to trust the website: They shouldn't know your password, but if they just gave it to you then how do you know they're not keeping a copy themselves somewhere?
- bsiemon 15y agoCan you stop a website that wants to save your password?
- Jach 15y agoReuse is a problem, but weak passwords are the biggest problem. If you have a strong password that never gets cracked/leaked/intercepted but you use it everywhere you're still fine, but that's not recommended. Generating server-side passwords is horrible as well since you're counting on the user to write it down and/or let the browser's password manager save it. What if the user wants to log in with a different machine/browser? I think the best solution is to, first, forbid passwords under 10 characters. 8 is still relatively secure, but not really, 10 at least gives you a fighting chance. Second, run your own dictionary attack (you can load /usr/share/dict/words into a hashtable and check for membership in sub-second times..in fact, here: import sys f = open('/usr/share/dict/words') words = {} for line in f: words[line.replace('\n','')] = None if sys.argv[1] in words: print 'You fail' ) and alert the user if their password sucks and to pick a new one. (You might want to check for membership of their password with an 's' or a '1' or something added on as well.) You might also want to do some sort of complexity analysis as well that requires e.g. at least one uppercase, one lowercase, one number. The infrastructure problem is places like Banks saying "Enter a password between 6 and 12 characters and only use alphanumeric characters!"
- pbreit 15y agoCan someone help me understand what a password cracker does with a list of salted/hashed passwords? How do they know they've figured out the right plain text passwords without bouncing them against the authentication logic?
- rorymccune 15y agoTypically attackers do this during an offline brute-force attack (where they have a copy of the hashed password, probably along with other user information from the database). The attack is done by getting a list of plain text passwords and then running them through the same hashing algorithm as was used originally (adding the salt value if present). Once the attacker has done that they just compare the hashed strings. If they match then it'll be the same password. Commonly the attacker would start with a dictionary of common passwords and submit them along with common variants (eg, password, Password password1 passw0rd). If that's not successful they can move onto pure brute force (eg, a , ab, ac, etc)
- andrewcooke 15y agoi suspect you don't know that the salt is stored with the password [edit: when using standard libraries like crypt and bcrypt - please don't invent your own scheme]. so when someone steals the password list they get the salt too. the salt is not "secret" - it is stored in plain text for each password. it does not need to be secret to do its job (defend against rainbow tables).
- roel_v 15y agoSometimes the salt is stored with the password. I sometimes see having a hardcoded salt referred to as 'security by obscurity', but considering that many attacks result in just a database dump, not giving attackers access to (at least part of) the hash is a useful security layer.
- SaltwaterC 15y agohttp://www.openwall.com/lists/announce/2011/06/21/1 http://www.openwall.com/lists/announce/2011/06/21/1 - some bcrypt implementations out there are still broken if they used this code. You may give the SHA-based scheme a chance.
- peteretep 15y agoI recently put together a commentary + code on how to upgrade passwords hashed insecurely in your DB without user intervention. This was in response to MtGox talking about "slowly migrating users", which presumably means upgrading passwords at the point of login: https://gist.github.com/1051238 https://gist.github.com/1051238
- carbocation 15y agoIf I'm not misunderstanding your purpose, why not just: 1) Take those md5 unsalted passwords and 2) bcrypt them Then upgrade the users to non-pre-hashed bcrypt as they log in? ?
- peteretep 15y agoWhy do you think that isn't what this is doing, only with fault tolerance to allow more than one scheme upgrade?
- carbocation 15y agoBecause the juicy bits got cut off due to the way github is displayed on my phone. Sorry I couldn't see that portion!
- yogsototh 15y agoI am surprised nobody had already talked about scrypt yet. Here is an old hackernews entry about it. http://news.ycombinator.com/item?id=601408 http://news.ycombinator.com/item?id=601408 I would have loved to use scrypt, but there is only a C implementation. I would had loved to have at least a javascript one.
- JoachimSchipper 15y agoJavascript? Have fun securing that one against timing attacks. Also, it's so much slower than the C implementation (remember that crypto algorithms are very carefully designed for 32- or 64-bit words or arbitrary-length integers; Javascript's doubles are a very poor match.)
- SamReidHughes 15y agoTiming attacks are not a problem if you're using it to hash passwords. Also, Javascript implementations don't use doubles for pure integer arithmetic.
- JoachimSchipper 15y agoIf I can observe your (SSL-encrypted) login session, I can time how long the server takes to process your (presumably real) password. What makes you think password hashes don't need to worry about this?
- JonnieCache 15y agoWould you really be able to do timing attacks on a server from the client side? I thought you needed a much greater accuracy of measurement, sub-millisecond, than you would be able to achieve with network latency in the mix.
- VBprogrammer 15y agoApparently it can be done. http://www.cs.cmu.edu/~dbrumley/pubs/openssltiming.pdf http://www.cs.cmu.edu/~dbrumley/pubs/openssltiming.pdf
- klon 15y agoDoes anyone know how Djangos built-in password hashing fares?
- brown9-2 15y agoLooks like the built in stuff uses either sha1, md5, or crypt: https://docs.djangoproject.com/en/dev/topics/auth/ https://docs.djangoproject.com/en/dev/topics/auth/
- lamby 15y agohttp://code.playfire.com/django-bcrypt/ http://code.playfire.com/django-bcrypt/ Backwords-compatible bcrypt support.
- Tichy 15y agoSo I assume if you use bcrypt, you only verify the password once upon login, and then store a cookie that verifies the user is logged in? That brings other security risks. But the alternative seems to be to make every request very slow, because it would require bcrypting the password with every request.
- brown9-2 15y agoIf you were to re-authenticate the user on every request, how do you have the client send the password to the server on every request without making the user enter it every time?
- Tichy 15y agoBy storing it in a cookie - oh :-) I suppose you could come up with some scheme where you create a new cookie with every request, a kind of one-time cookie to prevent session hijacking. Probably not worth it and not 100% reliable, though. I guess just trusting in cookies is the only real option. Or HTTP BasicAuth, it sends the password with every request I think (unencrypted, I know). In either case in theory you need HTTPS.
- praptak 15y agoYou can add the configurable slowness factor to any secure hash. Just use salts but leave out k bits from each when storing them. The more bits you leave out, the more work it takes to verify a password as the verification procedure needs to brute-force the missing k bits.
- dchest 15y agoYou can also write a new cipher, discover a new key derivation function, and invent a new hash function. But that's not the point. Use bcrypt or scrypt.
- praptak 15y agoAny analogy between using a standard technique with a standard hash and going for DYI cryptography is a bit stretched.
- dchest 15y agoReally? You just described a KDF, and advised people to use it without providing any references to implementations. "Just leave out k bits of salt and brute-force it" -- do you really expect non-cryptographers to be able to correctly implement this algorithm? If you insist on using hashes, at least you could tell people to use PBKDF2 to turn a standard hash into KDF.
- llambda 15y agoEven so this doesn't account for another advantage of bcrypt: its "de-optimized" key scheduler, which adds to the difficulty of cracking the hash.
- cperciva 15y agoThe key scheduler in bcrypt is a red herring. I don't know what was going through their minds when they wrote that. They could have used a larger number of iterations and gotten the same result. The only reason why bcrypt is better than PBKDF2 is that blowfish needs a large circuit to compute.
- deleted 15y ago[deleted]
- eneveu 15y agoMany developers need to read and understand this. It is far from mainstream knowledge... The other day, I saw the following post about password hashing in my RSS feed: http://isc.sans.org/diary.html?storyid=11110 http://isc.sans.org/diary.html?storyid=11110 - No mention of bcrypt (though the posts mentions key stretching using SHA1) - "When selecting an algorithm to hash passwords, it is important to select carefully as it is difficult to change the algorithm later. You will have to ask users to change their password if you do as you no longer know what password they picked." --> seriously? you can update the password the next time they log in... - "You could also add a secret, in addition to the salt. If the secret is not stored in the database, it would not be easily reachable via a SQL injection exploit (yes, you can use them to read files, but it requires sufficient privileges)." --> security through obscurity, nice - "For the paranoid, you may want to do the hashing on the client side (javascript) . This way, the server never receives the plain text password. We do this here for the ISC website on our login form [2]." --> oh noes... Note that the blog has ~15k subscribers according to Google Reader... --------- I also launched a debate on StackOverflow the other day. A self-proclaimed "security expert" (he later edited his post to remove this part) was advising against using bcrypt, arguing that it would facilitate DOS attacks against the login page... He prefers security through obscurity, using a secret salt: http://security.stackexchange.com/questions/4781/do-any-security-experts-recommend-bcrypt-for-password-storage/4782#4782 http://security.stackexchange.com/questions/4781/do-any-secu... I thought it was a bad idea to leave this answer unchallenged, so I tried arguing with him. I was met with arguments of authority such as "Wow you are out of your element and could not be more misguided on this topic" or "you disagree because you don't understand. Show me an exploit you have written, then I'll pay attention to you.". Happily, some (more experienced) people got in on the debate. I hope this will help developers make an informed choice, if they stumble upon his answer... (edit: list formatting)
- chalst 15y agoWhat about Debian's reason for not using bcrypt, claiming the time it takes to hash is not a weak point in security of /etc/shadow? http://groups.google.com/group/linux.debian.user/browse_thread/thread/3d1269bc082ad62e/b340dcde052adc6d?show_docid=b340dcde052adc6d&pli=1 http://groups.google.com/group/linux.debian.user/browse_thre...
- 16s 15y agoIt's good to raise awareness of this issue. When more devs began using bcrypt or scrypt, offline password cracking will be much, much more difficult. The only reason GPUs are cited as testing 600 million hashes a second is that the underlying hashes came from a Microsoft Windows Active Directory where they were simply MD4 encoded. That speed is not possible with bcrypt. Devs need to understand this. Edit: Yes, that's MD4 not MD5. Microsoft Windows NT hashes are simply Unicode strings that are MD4'ed. This includes Windows 7 and Windows 2008 server.
- yuhong 15y agoAnd note if you already have this hash you can use it to login directly anyway as most Windows network protocols take this hash directly. The real important thing IMO is NTLM challenge/responses based on the hash, which unfortunately is not much better. In case of NTLMv1/MS-CHAP it is three 56-bit DES operations on separate parts of the 128-bit hash (the third being only 2^16 so it is easy to precompute, as shown by asleap). NTLMv2's HMAC-MD5 is fast too.
- Revisor 15y agoWhat work factor do you recommend to make it reasonably fast and still bruteforce-proof with the current HW?
- d0vs 15y agobcrypt is so flawed...
- bradleyland 15y agoIf you want to stand by that assertion, please provide some information to back it up. You'd become very popular in this community (and the security community at large) if you could provide a good basis for that statement. Otherwise, you're just trolling, and I've committed a cardinal sin.
- antihero 15y agoOr a stretched newer algorithm like Whirlpool. Or stretched SHA-256? What advantages does bcrypt have over them?
- owenmarshall 15y agoIt's been around for years and remained solid. It's implemented in every language under the sun. It can be tuned to be plenty slow, even today. That said, there's nothing wrong with choosing another password derivation scheme. glibc's crypt() provides three: PHK's MD5 scheme, and Ulrich Drepper's stretched SHA-{256,512}. Just don't roll your own and you'll be ahead of the majority of programmers.
- ltamake 15y agoFor PHP users, phpass is a really nice password library. http://www.openwall.com/phpass/ http://www.openwall.com/phpass/
- SaltwaterC 15y agoShameless plug for PHP devs: https://github.com/SaltwaterC/PasswordHash2 https://github.com/SaltwaterC/PasswordHash2 - you may like this as well.
- joejohnson 15y agoNow, how do I explain to my girlfriend that picking longer, more complex passwords is a realistic security precaution and that I'm not just a paranoid nerd?
- falcolas 15y agoHonest question. Why would someone who handles more than a couple-dozen login attempts per second choose to use bcrypt? It would seem that the computational overhead of supporting bcrypt at scale would not make a lot of financial sense.
- dpark 15y agoYou can change the work factor to scale the amount of time it takes to do the processing. Beyond that, there's a cost to security. If you actually need security, you may need to pay for it. How much is it going to cost you to buy an extra server vs the loss of business due to a serious security breach?
- falcolas 15y agoIn the court of public image, simply loosing the data in the first place will cost you business, now matter how secure that data may be. The trust to secure your data will be lost, regardless of whether you used bcrypt or sha or plaintext. If you consider the loss of business to be pretty much constant in the event of a loss of control of the customer's data, what is the value of extra server(s) (plus the cost of maintenance) for one of the least valuable pieces of information a customer can give you? As an example, look at Instapaper. How many people are more concerned that the government has access to their sha1 encrypted passwords as opposed being concerned that the government has free access to their reading history?
- dpark 15y agoFor sure there's going to be loss of confidence either way. You're probably going to have a bigger loss if the security experts are pointing out that you couldn't even get password storage right, though. Obviously they It's up to you whether you care enough about your customers to try to get security right. You gave a reasonable argument for why using bcrypt instead of md5 makes little financial sense. However, that same argument applies to plaintext vs hashed. Or hashed vs hashed with salt. In the end, you need to decide how much you care about security, and also weigh how much security you are morally obligated to provide.
- mildweed 15y agoPrevious post: http://news.ycombinator.com/item?id=1998819 http://news.ycombinator.com/item?id=1998819 Similar discussion: http://chargen.matasano.com/chargen/2007/9/7/enough-with-the-rainbow-tables-what-you-need-to-know-about-s.html http://chargen.matasano.com/chargen/2007/9/7/enough-with-the...
- JustinHoffman 15y agobcrypt is total bullshit. does not work, broken.
- bborud 15y agoIn security the most important thing you can teach people is to be aware when things are harder than they look so they'll take a bit of extra time educating themselves and talking to other people. Learning how to separate good from bad advice is a skill that needs to be maintained. Also, in all software that is supposed to provide some form of security, one has to be prepared for the eventuality that it probably contains errors. I used to read a lot of books on cryptography and the use of cryptography. I've forgotten most of it by today, and to be quite frank: the more I know, the less I want to write crypto software. There is something deeply unsatisifying about work where you know that what will in all likelihood trip you up is some trivial, stupid mistake. It isn't hard because of the crypto itself. Sure, certain cryptographic libraries can be extremely awkward to use (which in itself is a security risk), but the problem usually comes from where you aren't looking for them. I cringe a bit when people advertise software as being secure because it uses this or that encryption scheme. I also cringe when people claim that they "encrypt databases" and their systems are therefore secure -- because, for most usage scenarios, I can't think of any really secure way of doing this. Not without compromises anyway. And while I honestly know that I have just a rudimentary grasp on cryptography, I know a lot more about it than most people who make products that hinge upon correct application of crypto. Just the other day I was trying to determine how many rounds I wanted to use in bcrypt for storing passwords for a given system. I think I spent most of the day pondering this question, writing benchmarks and reading up on what other people said on the topic. A couple of days later a friend of mine emailed me a code snippet that implemented the password hashing scheme of a commercial product they use that makes shameless claims about being secure. (I think he probably just looked at the hashed passwords and made a guess about the method they had used. I don't think he had a look at the original source code). If memory serves the product uses unsalted SHA1 hashing. In other words, the vendor didn't even bother thinking about the problem. What scares me a bit is that even I thought "well, if they claim to have well thought-out password handling and they are in the business of selling security systems, I suppose they have probably given this a lot of thought" the first time I visited their website. After all, large companies give them millions. Right? I wonder what other things they are doing equally badly.
- fleitz 15y agoWhat properties of bcrypt make it better than SHA-512 with more iterations to make the time taken to process it equivalent? Is there something about the algorithm that makes it more difficult to speed up via GPU/hardware?
- jorangreef 15y agoTo see if I understand bcrypt correctly, would this pseudo code achieve a similar adaptable computational cost? function(uniqueSalt128Bit, password, rounds) { var hash = SHA1(uniqueSalt128Bit + password); var length = Math.pow(2, rounds); while (length--) hash = SHA1(hash); return hash; }
- nemeth 15y agoThis is similar to SHA512 crypt: http://packages.python.org/passlib/lib/passlib.hash.sha512_crypt.html http://packages.python.org/passlib/lib/passlib.hash.sha512_c...
- mleonhard 15y agoLet's say I use bcrypt and want to increase the work factor every year. Is it possible to determine the work factor of an existing hash, or will I need to maintain this information alongside the hash? The java and python bcrypt APIs don't have any function that returns the work factor. Can I increase the work factor of an existing hash, or must I wait until the user logs in and then use the plaintext password to generate a new hash? Is there a bcrypt API that provides a hash comparison function that addresses timing attacks? The py-bcrypt example code uses the '==' operator to compare hash strings, leaking timing information: # Check that an unencrypted password matches one that has # previously been hashed if bcrypt.hashpw(password, hashed) == hashed: print "It matches" else: print "It does not match" (from http://www.mindrot.org/projects/py-bcrypt/ http://www.mindrot.org/projects/py-bcrypt/)
- mleonhard 15y agoTo answer my first question, the work factor can be extracted from the hash. It is stored as a 2-digit decimal number in the fifth and sixth bytes of the hash. See http://code.google.com/p/py-bcrypt/source/browse/bcrypt/bcrypt.c#141 http://code.google.com/p/py-bcrypt/source/browse/bcrypt/bcry...