I had a question regarding compression and calculation of checksum/hash of data.
I would like to know if checksum has to be calculated before or after the compression of data before transmission. Could someone please explain this so that I can get a better understanding of it?
5
Normally, a hash is calculated before compression. That way, the receiver can verify the hash after decompression, which verifies not only the data transmission but also the compression and decompression implementations.
2
This sounds similar to encryption and MAC order. The preferred approach in that setting is to encrypt and then add the MAC. There is no reason not to follow the same order in this case. You should compress and then add the checksum/hash. That way the integrity of the compressed payload can be checked before doing any kind of decompression. If you add the checksum/hash and then compress then you force the client to decompress to check the integrity of the payload whereas with compress-then-checksum approach you save the client the trouble of decompression if the integrity of the payload is compromised. Here’s the link about encryption and MAC order: https://crypto.stackexchange.com/questions/202/should-we-mac-then-encrypt-or-encrypt-then-mac.