News for hackers. Stuff that matters.
Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @11:34AM (#652869)
First, I'll quibble with some of these recommendations --- even though Colin (and Alex Ross, and probably Bruce) is more qualified to have an opinion here.

For instance, CTR+HMAC is a weird recommendation. Not because of speed (though HMAC does pessimize speed) and not because of cryptographic strength, but because it introduces another moving part in your design. Colin can deal with the junction between plaintext, ciphertext, and HMAC, because this is mostly all he thinks about. You can't.

A simpler recommendation would have been to use CCM or EAX mode. These have the advantages of being NIST standards-tracked and heavily vetted, and of providing both authentication and encryption in the same construction. If your libraries are good, you get both these features just by switching the name of your block mode.

Second, I'll quibble with the content of the post: these recommendations are exactly what Nate was talking about in his Yahoo talk about how bad cryptographic guidance has gotten. Key size and hash function selection (as long as you're not using MD5) are the least important design considerations you have.

Here's a design consideration this post doesn't even touch on: renewability. How do you safely design a system so that your selection of algorithms, modes, and key sizes isn't set in stone? Because if you don't get that right today, what you inevitably do to handle it 2 years from now is going to be a vulnerability.

Finally, a real concern about the structure of these recommendations: telling people to keep group negotiation out of Diffie-Hellman protocols is fine --- a good recommendation, since there's a really scary sounding, really easily-exploitable vulnerability that eliminates. But that's --- I think --- the only place in this post where Colin actually addresses something that actually does go wrong in crypto protocols.

If you follow all of Colin's recommendations here from scratch in a reasonably complicated, and you have never found a crypto vulnerability or fixed two reported crypto vulnerabilities, I will bet $500 that you end up with a broken system. Colin won't. But you will.

Re:Cryptographic Right Answers by cperciva on Thursday June 11, 2009 @11:52AM (#652923)
CTR+HMAC is a weird recommendation

Encrypt-then-HMAC has been a widely used standard for the past decade, and has been extensively studied.

A simpler recommendation would have been to use CCM or EAX mode.

AES-CTR and HMAC-SHA256 are far more simple than AES-CCM or AES-EAX. AES-CTR plus HMAC-SHA256 is also far more secure against side channel attacks, and has the advantage of allowing you to separate authentication from encryption -- useful if, say, you want to include some unencrypted data in an authenticated packet as well.

Key size and hash function selection (as long as you're not using MD5) are the least important design considerations you have.

I didn't mean to imply that all of the issues I mentioned were very important. My selection was more or less done on the basis of "what questions have people asked me recently?"

If you follow all of Colin's recommendations here from scratch in a reasonably complicated, and you have never found a crypto vulnerability or fixed two reported crypto vulnerabilities, I will bet $500 that you end up with a broken system.

That's probably a safe bet. I think it would be an even safer bet if you made it with someone who didn't follow my recommendations.

Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @01:01PM (#653092)
Your first point, about how well-studied HMAC is vs. CCM, is one of those points that makes a lot of sense in an academic context and much less sense in practice. In an academic context you assume both implementations are sound. In a practical context, you have to consider how likely it is that the implementor is going to make unsound choices.

The same goes double for your second point. Yes, if you have to implement the MAC yourself, you clearly want to use HMAC rather than trying to get CBC-MAC right. But if you're in a place where you have to implement your own MAC, you are doomed for a bunch of other reasons. CCM is preferable to HMAC because it's likely you're going to simply be able to change CTR to CCM and have it.

Re:Cryptographic Right Answers by cperciva on Thursday June 11, 2009 @01:09PM (#653109)
Yes, if you have to implement the MAC yourself...

I didn't say anything about implementing the MAC yourself. Someone has to implement it, though -- and no matter who writes the code, HMAC-SHA256 is far more likely to be right and not leaking data via side channels than CBC-MAC is.

Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @02:43PM (#653330)
Bespoke CBC-MAC is an almost-certain disaster. HMAC-SHA256 has some obvious implementation failure modes. It's less easy to see how someone screws up typing "CCM" into their library.

The point is that there are already shrink-wrapped AE constructions (like CCM or EAX) that you can pick up off the shelf and use; HMAC designs are more likely to be bespoke.

Re:Cryptographic Right Answers by cperciva on Thursday June 11, 2009 @03:26PM (#653413)
It's less easy to see how someone screws up typing "CCM" into their library.

If you trust the library, sure. But I've found that the same rules apply to crypto libraries as to everything else: Obscure and complicated features are far more likely to be buggy.

No crypto library is ever going to ship with a broken HMAC-SHA256 -- but I can't say the same thing about AES-CCM.

Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @03:58PM (#653491)
Seriously, Colin? You're talking about people that don't know to use AES-256 instead of Blowfish, but do know enough to homebrew instead of using a library?

CCM and EAX aren't obscure. AE crypto has been in 3 of the last 4 designs I've had to review. The fourth prompted a recent blog post of mine.

Re:Cryptographic Right Answers by dfranke on Thursday June 11, 2009 @03:54PM (#653484)
I'm with you on CTR mode: it's a uniquely dangerous recommendation to anyone who needs to be soliciting recommendations in the first place. If you're encrypting a file, then the obvious, elegant thing to do is to use position in the file as your counter. But then the moment you encrypt two files using the same key, you're screwed: you've just committed the equivalent of reusing a one-time pad. I feel like ever mentioning CTR mode to a novice without bringing this up is like inviting a guest into your house and forgetting to mention that you've rigged the door handle to explode if you turn it in the wrong direction.
Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @04:08PM (#653513)
I'm actually not anti-CTR mode; my recommendation (use EAX mode) has basically the same problem --- EAX is just CTR + OMAC.

You're right that stream ciphers blow up more spectacularly than block encryption does. You have to be sure not to re-use anything (counters, nonces, keys, etc). If "don't overfill a buffer" is an easy prescription that cost industry $4+bn USD, it's hard to imagine how unlikely it is people can avoid screwing up "don't reuse anything".

On the other hand, differentiatable errors cause spectacular problems with block encryption. See: the "bad padding" error message that decrypts entire AES blocks a byte at a time.

Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @11:41AM (#652893)
Oh and another thing Colin, you jerk:

All of your recommendations die in embedded applications, where nobody will use HMAC-SHA256 (or SHA256 at all) or RSA.

;)

Re:Cryptographic Right Answers by cperciva on Thursday June 11, 2009 @11:57AM (#652934)
This depends on how small your embedded systems are. If your system is too small to run RSA, it's probably too small to use any asymmetric crypto; and if it's too small to use HMAC-SHA256, it's probably too small to use any crypto at all.

There are certainly applications where I would revise my recommendations, but embedded isn't particularly one of them.

Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @11:59AM (#652939)
Systems that are too small to use RSA routinely use ECC.
Re:Cryptographic Right Answers by cperciva on Thursday June 11, 2009 @12:08PM (#652963)
I don't think that's quite right. The systems you're thinking of are almost certainly not too small to use RSA -- rather, they're too slow to use RSA. As I wrote in the article, ECC has advantages where speed is an important consideration.
Re:Cryptographic Right Answers by tptacek on Thursday June 11, 2009 @12:59PM (#653083)
I've definitely heard both objections --- space and time --- but my real point is, one of the app domains that most commonly hosts bespoke cryptography is largely incompatible with your recommendations.