What are services of pgp? How is compression performed between hash function and encryption? How it can be applied in reality?

  • The order of operations I'd use is 1) Sign or Authenticate with DH + MAC 2) Compress 3) Encrypt 4) MAC Nov 1, 2013 at 9:48

1 Answer 1


Compression must occur before encryption, because compression is inefficient on encrypted data: compression algorithms work on detecting redundancies and structure in the data, and encryption is designed to hide redundancies and structure. Basically, compression does not work at all on properly encrypted data. Conversely, if compression works on encrypted data, then the encryption layer should be viewed with deep suspicion...

When hashing occurs in PGP, it is as part of a signature algorithm, or as an integrity check which is generally known as a MAC. There are several ways to do a MAC; the theoretical "good" way is to apply the MAC on the encrypted data. However, PGP dates from an older time where theory was not yet fully worked out, and uses a hash value (i.e. a function which as no key) and then includes the hash in the encrypted data (see section 5.13); the hash value is turned into a MAC by virtue of reusing the encryption key. In the case of such a MAC, the MAC (i.e. the underlying hash) occurs on whatever is encrypted, so that's the compressed data (if compression was used at all). Since you talk about compression "between" the hash and the encryption, then I suppose that you are not talking about that hash at all.

When the hash is part of the signature, it is customary to compute the signature on the cleartext data, because that's what is "morally" signed, and a signature is supposed to be a proof convincing for third parties. An encrypted message is not convincing for anyone except those who can decrypt it. So the idea is that a signed-and-encrypted message is first signed (and hashing occurs as the first step of the signature), and then the whole thing is encrypted; compression, if any, then occurs just before the encryption. The recipient will then decrypt what was received, and uncompress if compression was applied, and thus obtain a cleartext message with signature that he could show to other people. This sequence of operations thus "makes sense".

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.