CRC32(Cyclic Redundancy Check)循环冗余校验:推导

您所在的位置:网站首页 crc循环冗余校验的工作原理 CRC32(Cyclic Redundancy Check)循环冗余校验:推导

CRC32(Cyclic Redundancy Check)循环冗余校验:推导

2024-07-12 17:20| 来源: 网络整理| 查看: 265

Table of Contents

什么是循环冗余校验和CRC-32?

CRC-32输出的长度是多少?

CRC-8,CRC-16,CRC-32和CRC-64有什么区别?

CRC32源代码

CRC32算法详细推导

CRC 算法的数学基础

CRC 校验的基本过程

原始的 CRC 校验算法

改进一小步——从 r+1 到 r

从 bit 扩张到 byte 的桥梁

CRC32示例

 

什么是循环冗余校验和CRC-32?

循环冗余校验(CRC)是用于检测数据损坏的错误检测码。发送数据时,会根据数据内容生成简短的校验和,并将其与数据一起发送。接收数据时,将再次生成校验和并将其与发送的校验和进行比较。如果两者相等,则没有数据损坏。所述CRC-32算法本身转换可变长度字符串转换成8个字符的字符串。

CRC(Cyclic Redundancy Check)校验实用程序库在数据存储和数据通讯领域,为了保证数据的正确,就不得不采用检错的手段。在诸多检错手段中,CRC是最著名的一种。CRC的全称是循环冗余校验。

检错能力极强,开销小,易于用编码器及检测电路实现。从其检错能力来看,它所不能发现的错误的几率仅为0.0047%以下。从性能上和开销上考虑,均远远优于奇偶校验及算术和校验等方式。因而,在数据存储和数据通讯领域,CRC无处不在:著名的通讯协议X.25的FCS(帧检错序列)采用的是CRC-CCITT,ARJ、LHA等压缩工具软件采用的是CRC32,磁盘驱动器的读写采用了CRC16,通用的图像存储格式GIF、TIFF等也都用CRC作为检错手段。

 

CRC-32输出的长度是多少?

校验值的长度固定为8个字符,因此,生成该值的函数有时会用作哈希函数。

 

CRC-8,CRC-16,CRC-32和CRC-64有什么区别?

生成多项式的选择是实现CRC算法的最重要部分。必须选择多项式以最大化错误检测能力,同时使总体碰撞概率最小。

多项式的最重要属性是其长度(多项式中任何一项的最大次数(指数)+1),因为它直接影响所计算校验值的长度。

最常用的多项式长度为:

9位(CRC-8)17位(CRC-16)33位(CRC-32)65位(CRC-64)

 

CRC32源代码

https://github.com/gcc-mirror/gcc/blob/master/libiberty/crc32.c

/* crc32.c Copyright (C) 2009-2020 Free Software Foundation, Inc. This file is part of the libiberty library. This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. In addition to the permissions in the GNU General Public License, the Free Software Foundation gives you unlimited permission to link the compiled version of this file into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover modification of the file, and distribution when not linked into a combined executable.) This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "libiberty.h" /* This table was generated by the following program. #include int main () { unsigned int i, j; unsigned int c; int table[256]; for (i = 0; i < 256; i++) { for (c = i 0; --j) c = c & 0x80000000 ? (c


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3