12. Compression

Optional compression of data is one element of OpenPGP’s composable functionality. Compression within OpenPGP can be convenient to applications.

In one use case, this functionality is particularly helpful: When encrypting a message, the encrypted output is by definition high-entropy, and cannot be compressed anymore - even if the plaintext message was low-entropy, and could have been compressed well (like, for example, a text-file).

This means that to use whatever potential for compression exists, the message must be compressed before encryption. OpenPGP offers an integrated compression mechanism to make this convenient (otherwise, messages would need to be compressed and decompressed before and after encryption, to achieve the same space-efficiency).

12.1. Decompression yields a ‘wrapped’ OpenPGP packet stream

Compression in OpenPGP is a simple mechanism: A Compressed Data packet acts as a compressed container for a series of OpenPGP packets.

The compressed data packet consists of the specification of which compression algorithm is used, followed by a compressed representation of the contained data.

The series of OpenPGP packets inside the Compressed Data packet can be handled like any stream of OpenPGP packets.

12.2. Typical usage

Compressed data packets are often used inside encrypted data packets, or wrapping the data of an inline-signed message.