Just curious if out of the box does Tor use a Gzip or any other kind of compression? I have done some searches but find only discussions about the Hidden Service directory.

  • github.com/katmagic/Tor/search?q=gzip&ref=cmdform this seems to suggest it's only used by the directory – Kristopher Ives Feb 24 '14 at 6:57
  • Leaving compression to tor makes little sense conceptually. Whatever you are transmitting should be compressed properly (and if appropriate encrypted) before tor gets its hands on it. – Caleb Mar 1 '14 at 9:09
  • @Calbeb I am just trying to know if it compresses it already or not. – Kristopher Ives Mar 6 '14 at 21:49

From the source code on GitHub I did a search for "gzip" and found the compression code:


After searching a bit more I was unable to find their compression routines called from anywhere but within the directory. It appears Tor is only using compression for the directory tables


Tor encrypts its connections from the client to relays or from relay to another. Encrypted data looks like random data to an outsider. This is a very bad case for compression, because the compression algorithm finds very few similarities to put together. So encrypted data can hardly be compressed. It is more the opposite. Usually encrypted and then compressed data are usually bigger than encrypted data alone. Thatswhy it makes no sense for Tor to compress its data during transport.

It was asked in the comments if Tor couldn't compress first and than encrypt. Tor operates on TCP packets. This is the transport level. Tor doesn't know about protocols at the application layer, like HTTP. But data compression is handled on the application level. For instance a browser could tell the server that it supports gzip compression and the server sends compressed data. If Tor should handle those things it must know every protocol at the application level (HTTP, SMTP, IMAP, DNS etc.), negotiate compression and so on. This would heavily enlarge the binary, probably introduce a large number of bugs and Tor has to do things what an application like a browser, mail client etc. could do better.

  • 1. You showed that compression after encryption does not make sense. That is the reason encryption after compression is being used. The first paragraph does not show arguments against compression. --- 2. Tor operates with the TCP data stream (not packets). You are right that Tor does not know which parts of the stream are data but the stream could be compressed completely including the application protocol headers. You do not need to know the application protocol because after lossless decompression you will get exactly the same data as before the compression. – pabouk Feb 28 '14 at 21:17

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.