When is CRC more appropriate to use than MD5/SHA1?

后端 未结 13 1514
走了就别回头了
走了就别回头了 2020-11-28 01:46

When is it appropriate to use CRC for error detection versus more modern hashing functions such as MD5 or SHA1? Is the former easier to implement on embedded hardware?

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 02:03

    Only use CRC if computation resources are very tight (i.e. some embed environments) or you need to store/transport many output values and space/bandwidth is tight (as CRCs are usually 32-bit where an MD5 output is 128-bit, SHA1 160 bit, and other SHA variants up to 512 bit).

    Never use CRC for security checks as a CRC is very easy to "fake".

    Even for accidental error detection (rather than malicious change detection) hashes are better than a simple CRC. Partly because of the simple way a CRC is calculated (and partly because CRC values are usual shorter than common hash outputs so have a much smaller range of possible values) it is much more likely that, in a situation where there are two or more errors, one error will mask another so you end up with the same CRC despite two errors.

    In short: unless you have reason not to use a decent hash algorithm, avoid simple CRCs.

提交回复
热议问题