4

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?

0

1 Answer 1

13

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.

2
  • 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. Mar 19, 2015 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, 2015 at 10:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .