Robust and fast checksum algorithm?

前端 未结 10 1625
失恋的感觉
失恋的感觉 2020-12-23 20:30

Which checksum algorithm can you recommend in the following use case?

I want to generate checksums of small JPEG files (~8 kB each) to check if the content changed.

10条回答
  •  温柔的废话
    2020-12-23 20:58

    Your most important requirement is "to check if the content changed".

    If it most important that ANY change in the file be detected, MD-5, SHA-1 or even SHA-256 should be your choice.

    Given that you indicated that the checksum NOT be cryptographically good, I would recommend CRC-32 for three reasons. CRC-32 gives good hamming distances over an 8K file. CRC-32 will be at least an order of magnitude faster than MD-5 to calculate (your second requirement). Sometimes as important, CRC-32 only requires 32 bits to store the value to be compared. MD-5 requires 4 times the storage and SHA-1 requires 5 times the storage.

    BTW, any technique will be strengthened by prepending the length of the file when calculating the hash.

提交回复
热议问题