Evaluating the differences in CRC-32 implementations

点点圈 提交于 2020-01-15 02:55:12

问题


I have seen many different implementations of the same basic CRC-32 algorithm shown below:

int remain;
int sbox[SIZESBOX];
int dividend;
int bit;

for(dividend = 0; dividend < SIZESBOX; dividend++)
{
    remain = dividend << 24;
    for(bit = 0; bit < 8; bit++)
    {
        if(remain & TOPBIT)
        {
            remain = (remain << 1) ^ POLYNOMIAL;
        }
        else
        {
            remain = (remain << 1);
        }
    }
    sbox[dividend] = remain;
}

Some of them XOR the dividend before going into the sbox. Others XOR before going into the bit loop, and others use bitwise reflection.

Are there differences that I need to consider between the varying implementations of CRC-32 for a given use case? Is one that uses bitwise reflection or XOR-OUT necessarily better than one that doesn't? Why are there so many different implementations anyway?


回答1:


CRC32 isn't secure in any way, so from a crypto standpoint the variations aren't relevant. It might affect the distribution properties, but I doubt that's relevant either.

A CRC is just a checksum, protecting against random changed(in particular bitflips) but can't be used as a cryptographic hash. You should use SHA-1 or better for that.




回答2:


CRC32 is not a cryptographic algorithm, so your question makes me think you need to consider what you're using it for long and hard.



来源:https://stackoverflow.com/questions/4208028/evaluating-the-differences-in-crc-32-implementations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!