3

I would like to run GnuPG elgamal encryption for at least a few minutes. The only way I can think of is to create a large file to be encrypted. So I created my file like this:

dd if=/dev/zero of=output.dat bs=500M count=1

Then I did:

gpg --passphrase-file passphrase.txt -e output.dat

I get:

du -h output.dat.gpg
500K    output.dat.gpg

If I change my file size:

dd if=/dev/zero of=output.dat bs=400M count=1

Then I did:

gpg --passphrase-file passphrase.txt -e output.dat

I get:

du -h output.dat.gpg
400K    output.dat.gpg

Notice in both cases, the files shrinks by a factor of 1000. If I create a 4MB file, then it encrypt into 4KB file.

Why does it shrink my file?

12

GnuPG is applying compression before encryption for reasons of efficiency (compression is cheaper than encryption) and security (compression might prevent some attacks introduced by flaws in the OpenPGP design).

As you're encrypting a series of nothing, this can be compressed very well. Consider using /dev/urandom instead.

You can disable compression using --compress-algo none, but be aware this is not a reasonable default for all-day use.

| improve this answer | |
  • 5
    With properly implemented crypto using strong primitives there are not attacks that compression can prevent. But there are attacks it can cause (famously CRIME against TLS). But PGP and its derivatives were designed before that point of view became prevalent. – CodesInChaos Mar 19 '15 at 9:58
  • 1
    I guess nobody realized compression is a good thing for OpenPGP security before the paper was realized, anyway. I added some words to point out this is not a general issue. – Jens Erat Mar 19 '15 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.