crc32 - zlib crc32 结合端格式
问题描述
我只是浏览了 Zlib CRC32 combine 函数的代码,但我对 CRC32 输入的字节序感到困惑。它只适用于大端吗?如果我有小端格式,我应该在使用该功能之前先进行字节交换吗?提前致谢。
/* ========================================================================= */
local uLong crc32_combine_(crc1, crc2, len2)
uLong crc1;
uLong crc2;
z_off64_t len2;
{
int n;
unsigned long row;
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
/* degenerate case (also disallow negative lengths) */
if (len2 <= 0)
return crc1;
/* put operator for one zero bit in odd */
odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
row = 1;
for (n = 1; n < GF2_DIM; n++) {
odd[n] = row;
row <<= 1;
}
/* put operator for two zero bits in even */
gf2_matrix_square(even, odd);
/* put operator for four zero bits in odd */
gf2_matrix_square(odd, even);
/* apply len2 zeros to crc1 (first square will put the operator for one
zero byte, eight zero bits, in even) */
do {
/* apply zeros operator for this bit of len2 */
gf2_matrix_square(even, odd);
if (len2 & 1)
crc1 = gf2_matrix_times(even, crc1);
len2 >>= 1;
/* if no more bits set, then done */
if (len2 == 0)
break;
/* another iteration of the loop with odd and even swapped */
gf2_matrix_square(odd, even);
if (len2 & 1)
crc1 = gf2_matrix_times(odd, crc1);
len2 >>= 1;
/* if no more bits set, then done */
} while (len2 != 0);
/* return combined crc */
crc1 ^= crc2;
return crc1;
}
解决方案
所有 zlib 都适用于小端或大端架构。
的论点没有“字节顺序” crc32_combine()
。crc1
和参数作为 32 位整数传递,crc2
而不是字节序列,因此没有字节序。
顺便说一句,有更新的代码crc32_combine()
更有效。
推荐阅读
- load-testing - 负载测试的断点
- powershell - 是否有任何解决方法可以在没有管理员用户权限的情况下执行文件签名?
- android - 应用中心构建,错误:/usr/bin/jarsigner 失败,返回码:1
- php - 包含来自另一个 linux 帐户的 PHP 文件
- typescript - 如何避免 Firebase 中的冗余
- version-control - 如何通过dql获取特定用户对象的所有版本?
- php - PHP 高级 HTMLDOM 错误
- sql - 在 SQL Server 2016 的一列中插入英语和阿拉伯语数据
- javascript - 使用带有formik的react-select时无法读取未定义的属性“类型”
- java - 警报对话未显示