Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluating the differences in CRC-32 implementations

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?

like image 283
user407896 Avatar asked Dec 10 '25 08:12

user407896


1 Answers

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.

like image 51
CodesInChaos Avatar answered Dec 13 '25 01:12

CodesInChaos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!