Live data from Hacker News

“Should you encrypt or compress first?”

blog.appcanary.com

11–20 of 249 posts

Re: “Should you encrypt or compress first?”

#11
post #2

I don't understand... Why couldn't you do CRIME with no compression as well? Assuming you can control (parts of) the plaintext, surely plaintext+encrypt gives you more information than plaintext+compress+encrypt?

Nope, secure ciphers are resistant against attack-controlled plaintext attacks.

The reason that plaintext -> compress -> encrypt has issues is because the length of the ciphertext gives away the plaintext if the attacker can control parts of the plaintext.

Re: “Should you encrypt or compress first?”

#12
post #2

I don't understand... Why couldn't you do CRIME with no compression as well? Assuming you can control (parts of) the plaintext, surely plaintext+encrypt gives you more information than plaintext+compress+encrypt?

No, because the length of the plaintext+encrypt depends only on the length of the plaintext and not on the contents of the plaintext; whereas the length of the plaintext+compress+encrypt depends on the length of the compressed plaintext, and the length of the compressed plaintext depends on the contents of the plaintext.

So, different plaintext of the same lengths, which would've resulted in plaintext+encrypt of the same length, instead results in compressed plaintext of different lengths which results in plaintext+compress+encrypt of different lengths, leaking additional information!

Re: “Should you encrypt or compress first?”

#13

I thought this was common sense. Compress then encrypt. Encryption leads to higher entropy, therefore less effective compression.

Compressing then encrypting gives you more effective compression and (somewhat) less effective encryption. Encrypting then compressing gives you more effective encryption and less effective (almost ineffective) compression. So, depends which one you want more. :)

Re: “Should you encrypt or compress first?”

#14
There's no compress or encrypt _first_.

It's just compress or not, before encrypting. If security is important, the answer to that is no, unless you're an expert and familiar with CRIME and related attacks.

Compression after encryption is useless, as there should be NO recognizable patterns to exploit after the encryption.

Re: “Should you encrypt or compress first?”

#15
post #2

I don't understand... Why couldn't you do CRIME with no compression as well? Assuming you can control (parts of) the plaintext, surely plaintext+encrypt gives you more information than plaintext+compress+encrypt?

Not at all - with compression thrown in, you get a measure of the entropy of the original plaintext from the length of the compressed message.

Re: “Should you encrypt or compress first?”

#16
post #5

Logically speaking, an encrypted file should have a high entropy set of bits within it. Compressing it would be low return, but higher security since the input file contained more "random" bits. Compressing the source material will yield smaller results but will be more predictable as the file will always contain ZIP headers and other metadata that would possibly make decryption of your file much easier.

Most (good) encryption schemes have the property that knowing part of the message, or some other information like message length, will not help you decrypt the message.

Re: “Should you encrypt or compress first?”

#17
post #2

I don't understand... Why couldn't you do CRIME with no compression as well? Assuming you can control (parts of) the plaintext, surely plaintext+encrypt gives you more information than plaintext+compress+encrypt?

If you control parts of the plaintext, a well-designed cipher doesn't tell you anything about the rest of the plaintext.

But if you control parts of the plaintext, a compression algorithm will absolutely tell you information about the rest of the plaintext. That's its job—identifying similarities between different parts of the plaintext.

And it will leak that information in the form of the size of its output, and the standard definition of "well-designed cipher" doesn't do anything to mask sizes; the size of the encrypted data is the same as the size of the data passed to the cipher. So now both the data and its size are sensitive, and nobody's encrypting the size.

(You could sort of work around this by padding, but then you've basically removed the point of compression.)

Re: “Should you encrypt or compress first?”

#19
So what does this mean if I am using an encrypted SSL connection that is correctly configured?

Is this kind of problem not already dealt with for me by the secure transport layer? It would be a shame if the abstraction were leaky. My understanding of the contract is that whatever bits I supply will be securely transported within the limits of the configuration I have selected.

If I pick a bad configuration then yes shame on me, but a good configuration won't care if I compress right?

Post reply on HN