# Can a compressed checksum be considered unique

I'm kind of guessing that the answer may be no. Since the compression is trying to reduce the output size using various optimization methods, this may cancel the properties of a hash algorithm.

But take the following Python code:

>>> import zlib
>>> import hashlib
>>> zlib.compress(hashlib.sha256('data'.encode('utf-8')).digest())


Can the output from the zlib compression be considered unique?

Note that since the hash value is quite random, it cannot be compressed efficiently:

>>> len(zlib.compress(hashlib.sha256('data'.encode('utf-8')).digest()))
41
>>> len(hashlib.sha256('data'.encode('utf-8')).digest())
32


TL;DR: The zlib output is at least as unique as the SHA-256 output.

Compression libraries like zlib have to encode the data in such a way that it is recoverably, which implies that they can not reduce the uncertainity (entropy) of the data.

Because of this logic, the entropy of the encoded hash has to be the same as the one of the hash. Now as hashes tend to have near-perfect entropy, this means that the the encoded data has the at least same entropy and thus must be at least as unique as the hash itself. Additionally, the compression may work non-deterministically when encoding data and thus even add entropy resulting in multiple unique encodings of the same hash (thus "increasing" the uniqueness).

• On average (and most of the time) the result will of course also be larger than the uncompressed hash, so there is little point in "compressing" the hash value. – Maarten Bodewes May 22 '16 at 23:19
• ... and it may in fact hurt depending on the use case of the hash. A compressed hash is no longer pseudorandom in all its bits, a truncation may be less secure than expected, etc. – otus May 23 '16 at 12:20