5 ms·
"It doesn't pass untrusted data to AES" had never occurred to me as an advantage of CTR over CBC. The XORability of CTR always gives me the willies.
by kragen 17y ago
"It doesn't pass untrusted data to AES" had never occurred to me as an advantage of CTR over CBC. The XORability of CTR always gives me the willies.
- tptacek 17y agoECB, CBC, CTR, CFB, and OFB are all "XORable", although if you're pointing out that CTR ciphertexts that share a keystream can be XOR'd to decrypt streams, that's a valid point, and one that a MAC (of any type) doesn't solve. You're so far better off not trying to implement any of this stuff that it's almost not worth studying. PGP at rest, TLS in motion. Spend your time and heartache on something that will make you money, not something that will get you laughed at by asshole pentesters.
- kragen 17y agoThere's the problem with keystream reuse, yes, and also the problem shared to some degree by CBC and OFB (but not ECB) that's at its worst in CTR — that you can flip single bits in the plaintext by flipping arbitrary bits in the ciphertext. (But of course that's why you use a correctly-implemented MAC, right?) I concur with you that new cryptographic protocols are likely to be flawed, and your recent blog post on that subject was excellent reading.
- brl 17y agoIt's probably as superstitious as your XORophobia but the counting part of CTR has always made be a bit uncomfortable.
- tptacek 17y agoIt's not superstition; I have at least 1 looping CTR counter finding in the last year. That definitely happens. Idle meta-point: is it just me, or do algorithms that actually encode lengths and counts have a bad track record? MD5, CTR, CCM...
- brl 17y agoYes, I suppose that's a unique implementation risk for CTR and in that case Kragen's concerns about XOR are valid as well since you've got a stream cipher with a short period. I was more thinking about how the cipher input has a predictable structure, in particular every pair of adjacent blocks differ by only a single fixed bit. This isn't an issue unless the underlying block cipher is badly broken, but it still feels unnecessarily risky.
- tptacek 17y agoOFB has the same problem with IV reuse, but because CTR divides the IV into a nonce and a counter, it basically begs you to make the error by giving you two opportunities to make it.
- weavejester 17y agoCould you explain why untrusted data is passed into AES when CBC is used?
- tptacek 17y agoAttackers get to arbitrarily change the ciphertext, and can watch the recipient carefully to see how it reacts to different altered ciphertexts. With a bad AES implementation, things like timing differences can leak key bits. That's not much of a problem with CTR mode --- CTR encrypts keystream, and XORs your data, so your data doesn't actually influence AES state much --- but it's a potential problem with CBC-MAC or OMAC, which do feed your data through AES.
- weavejester 17y agoPresumably this isn't an issue if you encrypt using AES/CBC then add a MAC to the encrypted data?
- tptacek 17y agoThe issue is that the fastest MACs use AES themselves, usually with the same key as was used to encrypt. CBC-MAC, OMAC, GCM, Poly1305-AES, all generate a MAC block (128 bytes, which you can truncate to whatever) in part using AES with your encrypting key. It feels to me like Colin has a legitimate point --- side channel key extraction would be pretty hard if you had to do it from HMAC instead of with AES --- but that the person who actually came up with a side-channel exploit in a real-world OMAC (EAX) system would get famous over it. The person who breaks your hand-hacked CTR+HMAC code, which will inevitably contain flaws because it will get no real review... that person doesn't get famous. Her win was entirely predictable.
- weavejester 17y agoIs a CTR+HMAC code much more tricky to implement than EAX? I'd imagine it's just: e := encrypt(x) e := e + sep + hmac(e) And for decryption: e, m := split(e, sep) if m = hmac(e): x := decrypt(e) The only thing I'd be particularly worried about is timing attacks on `m = hmac(e)`. Am I just being naive?