评估CRC-32实现的差异 [英] Evaluating the differences in CRC-32 implementations

查看:91
本文介绍了评估CRC-32实现的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了相同的基本CRC-32算法的许多不同实现,如下所示:

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;
}

其中一些在进入收件箱之前对股息进行异或。其他人在进入位循环之前进行XOR,其他人则使用按位反射。

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

在给定用途的不同CRC-32实现之间,我是否需要考虑差异?案件?使用按位反射或XOR-OUT的方法是否一定比不使用按位反射或XOR-OUT的方法更好?为什么仍然有这么多不同的实现?

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?

推荐答案

CRC32绝对不安全,因此从加密角度看不相关。

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.

CRC只是一个校验和,可以防止随机更改(尤其是bitflips),但不能将其更改,但这可能会影响分布属性。用作加密哈希。为此,您应该使用SHA-1或更高版本。

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.

这篇关于评估CRC-32实现的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆