CN1633030A - A Fast Calculation Method of Cyclic Redundancy Check - Google Patents
A Fast Calculation Method of Cyclic Redundancy Check Download PDFInfo
- Publication number
- CN1633030A CN1633030A CN 200310122447 CN200310122447A CN1633030A CN 1633030 A CN1633030 A CN 1633030A CN 200310122447 CN200310122447 CN 200310122447 CN 200310122447 A CN200310122447 A CN 200310122447A CN 1633030 A CN1633030 A CN 1633030A
- Authority
- CN
- China
- Prior art keywords
- shift register
- lookup table
- bits
- input sequence
- bit
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000004364 calculation method Methods 0.000 title claims description 27
- 125000004122 cyclic group Chemical group 0.000 title claims description 14
- 238000000034 method Methods 0.000 claims abstract description 53
- 238000012545 processing Methods 0.000 claims description 34
- 239000013598 vector Substances 0.000 claims description 6
- 239000000203 mixture Substances 0.000 claims description 3
- 238000004891 communication Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 5
- 230000005540 biological transmission Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 238000010276 construction Methods 0.000 description 2
- 239000011159 matrix material Substances 0.000 description 2
- 238000010295 mobile communication Methods 0.000 description 2
- 238000007796 conventional method Methods 0.000 description 1
- 238000013524 data verification Methods 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Images
Landscapes
- Error Detection And Correction (AREA)
Abstract
Description
技术领域technical field
本发明涉及循环冗余校验技术,特别是指一种循环冗余校验的快速计算方法。The invention relates to a cyclic redundancy check technology, in particular to a fast calculation method of a cyclic redundancy check.
背景技术Background technique
随着技术的不断进步,各种数据通信的应用越来越广泛,由于传输距离、现场状况、干扰等诸多因素的影响,设备之间的通信数据常会发生一些无法预测的错误。为了降低错误所带来的影响,一般在通信时采用数据校验的方法,循环冗余码校验(CRC)就是常用的重要校验方法之一。With the continuous advancement of technology, various data communication applications are becoming more and more extensive. Due to the influence of transmission distance, site conditions, interference and many other factors, some unpredictable errors often occur in the communication data between devices. In order to reduce the impact of errors, a data verification method is generally used in communication, and a cyclic redundancy check (CRC) is one of the important verification methods commonly used.
CRC校验为数据传输提供了一种简单而有效的突发差错检测方法,可适用于很多方面。CRC校验采用多项式编码方法,被处理的数据块可以看作是一个n阶的二进制多项式。比如:假定待发送的二进制数据段为g(x),生成多项式为m(x),则得到的CRC校验码为c(x),具体说就是,CRC校验码的编码方法是用待发送的二进制数据g(x)除以生成多项式m(x),将最后的余数作为CRC校验码。该CRC编码既可以通过软件实现,也可以通过硬件实现;既可以用结构简单,但处理时延较大的串行方法构造;也可以用结构复杂,但是处理时延较小的并行方法构造。The CRC check provides a simple and effective burst error detection method for data transmission, which can be applied to many aspects. The CRC check adopts a polynomial encoding method, and the processed data block can be regarded as an n-order binary polynomial. For example: assuming that the binary data segment to be sent is g(x), and the generator polynomial is m(x), the obtained CRC check code is c(x). Specifically, the encoding method of the CRC check code is to use The sent binary data g(x) is divided by the generator polynomial m(x), and the final remainder is used as a CRC check code. The CRC code can be implemented by software or hardware; it can be constructed by a serial method with a simple structure but a large processing delay; it can also be constructed by a parallel method with a complex structure but a small processing delay.
目前,CRC编码技术已经较为成熟,主要采用的实现方案有以下三种:At present, the CRC coding technology is relatively mature, and there are three main implementation schemes as follows:
第一种是基本的比特级构造方法,也可以称作直接计算法,这是最简单的CRC计算方法,是通过硬件实现的,如图1所示,该方法在硬件上主要通过线性反馈移位寄存器(LFSR)来实现。移位寄存器由时钟驱动,每个时钟输入数据移位寄存器参与计算,同时也直接输出;当所有的输入比特都处理完成之后,移位寄存器中剩下的就是CRC比特,将该CRC比特依次移出到数据流上,就完成了CRC编码。在实际应用中,可采用以下算法具体实现:The first is the basic bit-level construction method, which can also be called the direct calculation method. This is the simplest CRC calculation method, which is realized by hardware. As shown in Figure 1, this method mainly uses linear feedback shift in hardware. bit register (LFSR) to achieve. The shift register is driven by the clock, and each clock input data shift register participates in the calculation, and also directly outputs; when all the input bits are processed, the rest of the shift register is the CRC bit, and the CRC bits are shifted out in turn To the data stream, the CRC encoding is completed. In practical applications, the following algorithms can be used to implement:
a1.定义一个寄存器R用来存放循环冗余校验码,寄存器的长度一般为处理器的基本存储单元的整数倍,比如8比特、16比特、32比特等等,并且将寄存器R的值置为0;a1. Define a register R to store the cyclic redundancy check code. The length of the register is generally an integer multiple of the basic storage unit of the processor, such as 8 bits, 16 bits, 32 bits, etc., and set the value of the register R to is 0;
a2.如果寄存器R最左边的比特等于1,则将下一个消息比特移入,并且将寄存器R和生成多项式进行异或;否则只将消息比特移入即可;a2. If the leftmost bit of the register R is equal to 1, move the next message bit in, and XOR the register R and the generator polynomial; otherwise, just move the message bit in;
a3.重复步骤a2,直到所有消息比特都被移入处理,留在寄存器R中的就是输入序列的循环冗余校验码。a3. Repeat step a2 until all message bits are shifted in for processing, and what remains in register R is the cyclic redundancy check code of the input sequence.
这种方法所用的模块代码少,不需要存储查找表,计算简单,修改灵活,可移植性好,软硬件实现的复杂度差不多,对任意长度生成多项式m(x)都适用。但如果发送的数据块很长,该方法就不太适合,因为该方法需要逐比特处理,也就是一次只能处理一位数据,效率太低,运算量大,不能满足实时处理的要求,对于高速数据通信更不适用。This method uses less module code, does not need to store a lookup table, is simple to calculate, flexible to modify, and has good portability. The complexity of hardware and software implementation is similar, and it is applicable to generator polynomials of any length m(x). However, if the data block to be sent is very long, this method is not suitable, because this method needs to be processed bit by bit, that is, only one bit of data can be processed at a time, the efficiency is too low, and the amount of calculation is large, which cannot meet the requirements of real-time processing. High-speed data communication is even less applicable.
第二种是标准查找表算法,该方法的CRC计算可认为是输入比特和移位寄存器状态比特构成的多项式对生成多项式的余数,该方法需要预先提供CRC生成表。假定寄存器的宽度为n,输入比特位数为m,则在实际应用中,当m<n时,可采取下面的操作步骤:The second is a standard look-up table algorithm. The CRC calculation of this method can be considered as the remainder of the polynomial pair generator polynomial composed of input bits and shift register status bits. This method needs to provide a CRC generation table in advance. Assuming that the width of the register is n and the number of input bits is m, in practical applications, when m<n, the following steps can be taken:
b1.定义一个宽度为n比特的寄存器R用来存放循环冗余校验码,寄存器的长度一般为处理器的基本存储单元的整数倍,比如8比特、16比特、32比特等等,并且将寄存器R的值置为0,即设置(rn-1,...,r0)比特序列为0;b1. Define a register R with a width of n bits to store the cyclic redundancy check code. The length of the register is generally an integer multiple of the basic storage unit of the processor, such as 8 bits, 16 bits, 32 bits, etc., and the The value of the register R is set to 0, that is, the bit sequence (r n-1 ,...,r 0 ) is set to 0;
b2.将寄存器R右移n-m比特,即得到(Rn-1,...,rn-k-r)序列,然后所得到的序列和m个输入比特异或;b2. Shift register R to the right by nm bits to obtain (R n-1 ,...,r nkr ) sequence, and then XOR the obtained sequence with m input bits;
b3.在查找表中找到对应的值,与寄存器R左移m比特得到的序列(rm-1,...,r0)异或,就得到新的CRC值;b3. Find the corresponding value in the look-up table, XOR with the sequence (r m-1 , ..., r 0 ) obtained by shifting m bits to the left of the register R, and obtain a new CRC value;
b4.重复步骤b2和b3,直到所有消息比特都被移入处理,留在寄存器R中的就是输入序列的循环冗余校验码。b4. Repeat steps b2 and b3 until all message bits are shifted in for processing, and what remains in register R is the cyclic redundancy check code of the input sequence.
当n=m时,步骤b2和步骤b3会有些许改变:When n=m, step b2 and step b3 will be slightly changed:
b2’.将输入的m个比特与寄存器R异或,也就是将输入的m比特与(rn-k-1,...,r0)异或;b2'. XOR the input m bits with the register R, that is, XOR the input m bits with (r nk-1 ,...,r 0 );
b3’.在查找表里面找到对应的值,就得到新的CRC值。b3'. Find the corresponding value in the lookup table to get the new CRC value.
当n<m时,不能采取这种算法。When n<m, this algorithm cannot be adopted.
这种算法需要提供存储2m×n比特大小的查找表,每处理m比特需要执行一次查表和两次异或操作,软硬件实现时复杂度和性能差不多。与直接计算法相反,该方法运算量小,速度快,但是可移植性较差,且应用有局限性,不能处理m>n时的情况,也就是说,每次处理的比特数m不能大于生成多项式的最高阶数n,否则就不能应用该算法。This algorithm needs to provide a lookup table with a size of 2 m × n bits, and it needs to perform a lookup table and two XOR operations for every m bits processed. The complexity and performance of the hardware and software implementation are similar. Contrary to the direct calculation method, this method has a small amount of calculation and fast speed, but its portability is poor, and its application is limited. It cannot handle the situation when m>n, that is, the number of bits m processed each time cannot be greater than The highest degree n of the generator polynomial, otherwise the algorithm cannot be applied.
此外,所存储的查找表随着m的增加而成2的指数增加,比如:每次处理8个比特时,查找表大小为256个存储单元;每次处理16个比特时,查找表大小就变为65536个存储单元,可见,这种方法的并行度不能过高。In addition, the stored look-up table increases with the increase of m by an exponential of 2, for example: when 8 bits are processed each time, the size of the look-up table is 256 storage units; when 16 bits are processed each time, the size of the look-up table is It becomes 65536 storage units. It can be seen that the parallelism of this method cannot be too high.
第三种是并行循环冗余校验编码方法,如图2所示,这是一种基于线性反馈移位寄存器的并行结构,图2中,d0~dm-1表示并行输入序列的m个比特位,er,c为矩阵Fw的第r行第c列,x0~xm-1为输出的系统状态列向量,其中w为并行输入级数。该方法实际是通过硬件门电路来构建当前CRCn生成多项式所对应的各个寄存器之间的关系,最终获取CRC值。The third is the parallel cyclic redundancy check coding method, as shown in Figure 2, which is a parallel structure based on linear feedback shift registers, in Figure 2, d 0 ~ d m-1 represent the m of the parallel input sequence bits, e r, c are the rth row and cth column of the matrix F w , x 0 ~ x m-1 are the output system state column vectors, where w is the number of parallel input stages. This method actually constructs the relationship between the registers corresponding to the current CRCn generator polynomial through the hardware gate circuit, and finally obtains the CRC value.
不难看出,该方法的速度是常规方法的w倍,代价就是存储一个F16矩阵并增加硬件的复杂度。该方法的并行度很高,适合硬件如采用FPGA实现,但该算法并不适合软件比如用DSP芯片实现。原因很简单,图2所示的并行结构并行度为m,一般的处理器都达不到这么高的并行度。It is not difficult to see that the speed of this method is w times that of the conventional method, and the cost is to store an F 16 matrix and increase the complexity of the hardware. This method has a high degree of parallelism and is suitable for hardware such as FPGA implementation, but this algorithm is not suitable for software such as DSP chip implementation. The reason is very simple. The parallelism of the parallel structure shown in Figure 2 is m, and the general processor cannot reach such a high degree of parallelism.
随着第三代移动通信中高速数据业务的发展,CRC校验也在第三代移动通信的数据传输中得以大量应用。但由于3GPP基带处理的时延要求相当严格,基带处理器的性能与单位时间内的业务处理能力紧密相关,这样,CRC编码的效率好坏,就会直接影响到基带处理器的性能。如果没有合适的快速CRC校验的计算方法,将会使高速数据通信中的业务处理能力受到很大影响。With the development of high-speed data services in the third-generation mobile communication, CRC check is also widely used in the data transmission of the third-generation mobile communication. However, due to the strict delay requirements of 3GPP baseband processing, the performance of the baseband processor is closely related to the service processing capability per unit time. In this way, the efficiency of CRC coding will directly affect the performance of the baseband processor. If there is no suitable fast CRC calculation method, the service processing capability in high-speed data communication will be greatly affected.
发明内容Contents of the invention
有鉴于此,本发明的主要目的在于提供一种循环冗余校验的快速计算方法,能大大提高CRC校验的处理速度,降低CRC校验的处理时延,进而一定程度地提高业务处理能力。In view of this, the main purpose of the present invention is to provide a fast calculation method of cyclic redundancy check, which can greatly improve the processing speed of CRC check, reduce the processing delay of CRC check, and then improve the business processing capacity to a certain extent .
本发明进一步的目的是一种循环冗余校验的快速计算方法,使其在保证快速计算速度的同时,达到最佳的存储量/时延配置。A further object of the present invention is a fast calculation method of cyclic redundancy check, so that it can achieve optimal storage capacity/time delay configuration while ensuring fast calculation speed.
为达到上述目的,本发明的技术方案是这样实现的:In order to achieve the above object, technical solution of the present invention is achieved in that way:
一种循环冗余校验的快速计算方法,该方法包括以下步骤:A fast calculation method of cyclic redundancy check, the method comprises the following steps:
a.根据当前所采用CRCn生成器的逻辑结构,获取并存储该生成器中每个移位寄存器在处理每个输入比特时的状态;a. According to the logical structure of the CRCn generator currently used, obtain and store the state of each shift register in the generator when processing each input bit;
b.从步骤a所获取的所有移位寄存器的全部状态中,提取出处理完输入序列每个比特后CRCn生成器中每个移位寄存器的状态;并将所提取出的每个移位寄存器状态组成中的移位寄存器初始状态表示部分和输入序列表示部分分别存储;B. from all the states of all shift registers obtained in step a, extract the state of each shift register in the CRCn generator after processing each bit of the input sequence; and extract each shift register The initial state representation part and the input sequence representation part of the shift register in the state composition are stored separately;
c.以每个分别存储部分包含的自变量为地址索引,生成该存储部分对应的查找表;c. Using the independent variable included in each storage part as an address index, generate a lookup table corresponding to the storage part;
d.以CRCn模式进行CRC校验时,判断当前需处理的比特数是否大于每次能处理的比特数m,如果不是,则按串行方式处理;如果是,则读取m比特,分别以输入比特和移位寄存器变量为地址索引,查找输入序列表示部分对应的查找表和移位寄存器初始状态表示部分对应的查找表,然后将所有查找结果进行异或并保存异或结果;将对应每个移位寄存器的异或结果分别作为该移位寄存器的当前状态,返回步骤d。d. When performing CRC check in CRCn mode, judge whether the current number of bits to be processed is greater than the number m of bits that can be processed each time, if not, process in a serial manner; if yes, read m bits, respectively The input bit and the shift register variable are the address index, look up the corresponding lookup table of the input sequence representation part and the corresponding lookup table of the shift register initial state representation part, and then XOR all the search results and save the XOR result; will correspond to each The XOR results of the shift registers are respectively used as the current state of the shift register, and return to step d.
其中,步骤c和步骤d之间进一步包括:判断分别存储的移位寄存器初始状态表示部分或输入序列表示部分是否需要继续细分,如果需要,则按给定条件将当前的存储部分进一步划分为一个以上存储部分,并对划分后的每个存储部分分别生成对应的查找表;否则,直接执行步骤d。Wherein, between step c and step d, it further includes: judging whether the respectively stored initial state representation part of the shift register or the input sequence representation part needs to be further subdivided, and if necessary, the current storage part is further divided into according to a given condition More than one storage part, and generate a corresponding lookup table for each divided storage part; otherwise, directly execute step d.
该方法进一步包括:预先设置需要进行细分的条件,则所述判断是否需要细分为判断是否符合细分条件,如果符合,则需要细分;否则不需要细分。这里,所述进行细分的条件为:步骤b中所划分的分别存储部分的存储量大于给定存储量。The method further includes: pre-setting the conditions that need to be subdivided, and then judging whether subdivision is required is judging whether the subdivision condition is met, and if so, subdivision is required; otherwise, no subdivision is required. Here, the condition for subdividing is: the storage capacity of the respective storage parts divided in step b is greater than a given storage capacity.
如果将当前存储部分进一步划分为一个以上存储部分,则步骤d中所述查找输入序列表示部分对应的查找表和移位寄存器初始状态表示部分对应的查找表是:分别查找至少一个输入序列表示部分对应的查找表和一个以上移位寄存器初始状态表示部分对应的查找表。If the current storage part is further divided into more than one storage part, then the lookup table corresponding to the input sequence representation part and the lookup table corresponding to the initial state representation part of the shift register described in step d are: respectively search for at least one input sequence representation part The corresponding look-up table and the initial state of one or more shift registers represent partially corresponding look-up tables.
上述方案中,可将每个存储部分的内容分别存储在表中。另外,CRCn生成器中每个移位寄存器的初始状态存储在寄存器中,或放置在向量中。In the above scheme, the content of each storage part can be stored in a table respectively. Additionally, the initial state of each shift register in the CRCn generator is stored in a register, or placed in a vector.
本发明所提供的循环冗余校验的快速计算方法,由于根据当前所采用CRCn生成多项式对应的逻辑结构,预先得出在不同输入比特的处理状态下,CRCn所用到的每个寄存器的当前状态与其他寄存器及输入比特位的关系,生成对应的查找表,使得在进行CRC校验时,可直接根据预先生成的查找表计算出每个寄存器当前状态下的输出,从而大大提高了CRC校验的处理速度,也就是降低了CRC校验的处理时延。The fast calculation method of the cyclic redundancy check provided by the present invention can obtain in advance the current state of each register used by CRCn under the processing state of different input bits according to the logic structure corresponding to the CRCn generating polynomial currently used The relationship with other registers and input bits generates a corresponding lookup table, so that when performing CRC check, the output of each register in the current state can be directly calculated according to the pre-generated lookup table, thus greatly improving the CRC check The processing speed is reduced, that is, the processing delay of the CRC check is reduced.
本发明的方法对所得到的关系按寄存器值和输入比特位值进行划分,并可根据需要或根据算法复杂度的情况,对已划分的寄存器部分或输入比特位部分再细分,如此,可不同程度的减小存储量,以较小的存储代价,换取了很大的处理时延。并且,本发明方法具有相当的灵活性,在保证计算速度快的前提下,可随时根据具体条件,确定最佳的存储量/计算时间配置,能实现很高的并行度。The method of the present invention divides the obtained relationship according to the register value and the input bit value, and can further subdivide the divided register part or the input bit part according to the needs or according to the complexity of the algorithm, so that The amount of storage is reduced to varying degrees, and a large processing delay is exchanged for a small storage cost. Moreover, the method of the present invention has considerable flexibility. On the premise of ensuring fast calculation speed, the optimal storage capacity/calculation time configuration can be determined at any time according to specific conditions, and a high degree of parallelism can be realized.
附图说明Description of drawings
图1为一种LFSR的组成结构示意图;Fig. 1 is a schematic diagram of the composition structure of a LFSR;
图2为并行CRC体系结构示意图;Fig. 2 is a schematic diagram of the parallel CRC architecture;
图3为本发明方法的实现流程图;Fig. 3 is the realization flowchart of the inventive method;
图4为本发明一实施例的逻辑结构示意图;FIG. 4 is a schematic diagram of a logical structure of an embodiment of the present invention;
图5为图4所述实施例的CRC计算过程示意图。FIG. 5 is a schematic diagram of the CRC calculation process of the embodiment shown in FIG. 4 .
具体实施方式Detailed ways
本发明的基本思想就是:根据当前所采用CRCn生成多项式对应的逻辑结构,预先得出在不同输入比特的处理状态下,CRCn所用到的每个移位寄存器的状态更新情况与其它移位寄存器和输入比特位之间的关系,并根据该关系生成对应的查找表;在进行CRCn校验时,直接利用预先生成的查找表获取每个移位寄存器当前状态下的输出。The basic idea of the present invention is exactly: according to the logical structure corresponding to the CRCn generator polynomial that adopts at present, obtain in advance under the processing status of different input bits, the state update situation of each shift register used by CRCn is different from other shift registers and Input the relationship between bits, and generate a corresponding look-up table according to the relationship; when performing CRCn check, directly use the pre-generated look-up table to obtain the output of each shift register in the current state.
如图3所示,本发明方法的具体实现过程包括以下步骤:As shown in Figure 3, the concrete realization process of the inventive method comprises the following steps:
步骤301:根据当前所采用CRCn生成器的逻辑结构,获取并存储该生成器中所涉及的每个移位寄存器在处理每个输入比特时的状态。Step 301: Acquire and store the state of each shift register involved in the generator when processing each input bit according to the logic structure of the currently used CRCn generator.
步骤302:从步骤301所获取的所有移位寄存器的全部状态中,提取出处理完输入序列每个比特后CRCn生成器的每个移位寄存器的状态。Step 302: From all the states of all shift registers acquired in
步骤303~304:将步骤302所提取出的每个移位寄存器状态组成中的移位寄存器初始状态表示部分和输入序列表示部分分别存储;并以每个分别存储部分包含的自变量为地址索引,生成该存储部分对应的查找表。Steps 303-304: Store the initial state representation part and the input sequence representation part of each shift register extracted in
步骤305~306:在以CRCn模式进行CRC校验时,先判断当前需处理的比特数是否大于每次能处理的比特数m,如果不是,则按现有技术中一般的串行方法处理;如果是,则执行步骤307。Steps 305-306: When performing CRC check in CRCn mode, first judge whether the current number of bits to be processed is greater than the number m of bits that can be processed each time, if not, then process according to the general serial method in the prior art; If yes, go to step 307.
步骤307~310:读取m比特的信息,分别以输入比特和移位寄存器变量为地址索引,查找输入序列表示部分对应的查找表和移位寄存器初始状态表示部分对应的查找表,并将所有查找结果进行异或,保存异或结果;并且,将对应每个移位寄存器的异或结果分别作为该移位寄存器的当前状态,然后返回步骤305。Steps 307-310: read m-bit information, respectively use the input bit and the shift register variable as the address index, look up the look-up table corresponding to the input sequence representation part and the look-up table corresponding to the shift register initial state representation part, and set all Execute XOR on the search result, save the XOR result; and use the XOR result corresponding to each shift register as the current state of the shift register, and then return to step 305 .
在步骤304和步骤305之间还可以增加一个判断,判断分别存储的移位寄存器初始状态表示部分或输入序列表示部分是否还需继续细分,如果需要,则按给定条件将当前的存储部分进一步划分为一个以上存储部分,并对划分后的每个存储部分分别生成对应的查找表。可预先设置细分条件,比如:查找表的存储量大于某个给定值就再细分,那么,细分时就按照存储量给定值来决定如何细分,具体说就是,当前存储部分的查找表存储量为64K,而给定值为32K,那么,就会将当前存储部分再进一步划分为两个存储部分。如果进行了细分,则步骤308、或步骤309、或步骤308和步骤309要分别以每个存储部分所含的自变量为地址索引,查找相应的查找表,再将所有查找结果进行异或。A judgment can also be added between
对于上述每个步骤提到的存储,都可以设置一个表进行存储,如果某两个表是从某个表中划分出来的,则这两个表可称为原表的子表。For the storage mentioned in each of the above steps, a table can be set for storage. If two tables are divided from a certain table, these two tables can be called sub-tables of the original table.
为了方便进一步详细说明本发明中CRC的快速计算原理,下面以CRC16为例,同时结合CRC16的生成多项式和逻辑结构图作为参考。For the convenience of further describing the fast calculation principle of CRC in the present invention, CRC16 is taken as an example below, and the generator polynomial and logic structure diagram of CRC16 are used as reference.
CRC16所采用的查找表的生成过程包括以下几个步骤:The generation process of the lookup table adopted by CRC16 includes the following steps:
第一步,根据CRC16生成器的逻辑结构获取每个移位寄存器在处理每个输入比特时的状态。 In the first step , the state of each shift register when processing each input bit is obtained according to the logic structure of the CRC16 generator.
CRC16的生成多项式如公式(1)所示:The generator polynomial of CRC16 is shown in formula (1):
gcrc16(D)=D16+D12+D5+1 (1)g crc16 (D)=D 16 +D 12 +D 5 +1 (1)
CRC16的逻辑结构如图4所示,CRC16的生成器包括16个移位寄存器R1~R16,图4中的表示模2加,也就是异或。假设以R1~R16分别代表这16个移位寄存器的初始状态,并且当前的输入序列为M,Mi代表输入序列的第i比特位,本实施例中,输入序列M由8个比特位组成,即M1~M8。那么,可以根据图4得出每次处理一个输入比特时每个移位寄存器的状态更新情况,其中移位寄存器的所有状态都是由初始状态R1~R16和输入序列M表示的。每个移位寄存器每个时刻的状态具体如表一所示:
表一 Table I
表一中,第一列代表16个移位寄存器,第一行代表处理的输入比特Mi,相应的,第二列为处理第一输入比特M1时16个移位寄存器的当前状态;第二列为处理第二输入比特M2时16个移位寄存器的当前状态,以此类推,表中的“+”表示模2加。In Table 1, the first column represents 16 shift registers, the first row represents the processed input bit Mi, and correspondingly, the second column is the current state of the 16 shift registers when processing the first input bit M1; the second column To process the current state of the 16 shift registers when processing the second input bit M2, and so on, "+" in the table represents modulo 2 addition.
上述表一的具体生成方法包括以下过程:首先,将图4中16个移位寄存器的初始状态存放在表一的第一列;然后,对于每个输入比特执行:根据当前输入比特,用前一时刻的移位寄存器状态和当前输入表示出当前时刻移位寄存器的状态,直至处理完8个比特。比如:移位寄存器R1的当前状态应该等于移位寄存器R16的当前状态与输入序列M的异或,而移位寄存器R2的当前状态就等于移位寄存器R1的当前状态;再比如:根据图4移位寄存器R6的当前状态就等于移位寄存器R5的当前状态与移位寄存器R16当前状态和输入序列M异或结果再异或,CRC16生成器中的移位寄存器状态均以此类推。The specific generation method of the above-mentioned Table 1 includes the following process: First, store the initial states of the 16 shift registers in Figure 4 in the first column of Table 1; then, execute for each input bit: according to the current input bit, use the previous The state of the shift register at a moment and the current input indicate the state of the shift register at the moment until all 8 bits are processed. For example: the current state of the shift register R1 should be equal to the exclusive OR of the current state of the shift register R16 and the input sequence M, and the current state of the shift register R2 is equal to the current state of the shift register R1; another example: according to Figure 4 The current state of the shift register R6 is equal to the current state of the shift register R5 and the current state of the shift register R16 and the XOR result of the input sequence M, and the state of the shift register in the CRC16 generator can be deduced by analogy.
第二步,提取处理完输入序列每个比特后CRC16生成器的每个移位寄存器的状态。 In the second step , the state of each shift register of the CRC16 generator after processing each bit of the input sequence is extracted.
表一生成后,可根据表一的最后一列获得每个移位寄存器处理完8个输入比特后的状态,分别用R’1~R’16来表示,则得到表二,表二为处理完输入序列每个比特后移位寄存器的状态列表:
表二 Table II
第三步,对所获得的处理完输入序列所有比特后每个移位寄存器的状态细成进行划分,并构造相应的查找表。 The third step is to divide the obtained states of each shift register after processing all the bits of the input sequence, and construct a corresponding look-up table.
为了减少存储量和简化构造查找表的复杂度,将表二按照移位寄存器初始状态R1~R16和输入比特序列M1~M8分成两个子表,表三为处理完输入序列后每个移位寄存器状态与其它移位寄存器初始状态相关的部分,表四为处理完输入序列后每个移位寄存器状态与输入比特序列相关的部分。
表三
表四Table 4
这里,所述构造相应的查找表就是:根据表三或表四中所有自变量的不同取值,计算出对应的R’1~R’16值。以表四为例,表四中的自变量为M1~M8,由于M1~M8每个比特位均可取0或取1,所以M1~M8的取值共有256种不同组合。那么,构造查找表的具体过程是:先列出M1~M8的256种取值;再根据表四中R’1~R’16与M1~M8的关系,计算出M1~M8每种不同取值所对应的R’1~R’16的值;以M1~M8为地址索引,将所有的R’1~R’16值都存储到寄存器中,每个字节的地址寻址一个字;最后形成的关于R’1~R’16的256种取值就是所需的查找表。比如:M1~M8的取值为01111010时,由于R’1为M4+M8,这里M4=1,M8=0,则计算出R’1的取值为1;同样R’2为M3+M7,这里M3=1,M7=1,则计算出R’2的取值为0;其它R’i(i=3,4...16)的计算方法类似,不再赘述。如果用于处理的DSP芯片是以字为存储单元的话,就不需要特殊的处理;如果是以字节为存储单元的话,就需要对8比特宽度的M地址索引进行2倍的扩展。Here, the construction of the corresponding lookup table is to calculate the corresponding values of R'1-R'16 according to the different values of all the independent variables in Table 3 or Table 4. Taking Table 4 as an example, the independent variables in Table 4 are M1-M8. Since each bit of M1-M8 can be 0 or 1, there are 256 different combinations of the values of M1-M8. Then, the specific process of constructing the lookup table is: first list 256 values of M1~M8; The value of R'1~R'16 corresponding to the value; with M1~M8 as the address index, all R'1~R'16 values are stored in the register, and the address of each byte addresses a word; The finally formed 256 values of R'1 to R'16 are the required lookup table. For example: when the value of M1~M8 is 01111010, since R'1 is M4+M8, here M4=1, M8=0, then the calculated value of R'1 is 1; similarly, R'2 is M3+M7 , where M3=1, M7=1, then the value of R'2 is calculated to be 0; the calculation methods of other R'i (i=3, 4...16) are similar and will not be repeated here. If the DSP chip used for processing uses words as the storage unit, no special processing is required; if it uses bytes as the storage unit, it is necessary to expand the 8-bit M address index by 2 times.
表三中的自变量是R1~R16,总共有216种组合。如果直接以R1~R16为地址索引,将对应的R’1~R’16存储到存储器中,存储量就是64K字。对于64K字的存储量,可以直接采用;也可以继续将表三进行划分,以减少存储量。如果需要继续划分表三,则执行第四步。The independent variables in Table 3 are R1~R16, and there are 216 combinations in total. If directly using R1-R16 as the address index, and storing the corresponding R'1-R'16 in the memory, the storage capacity is 64K words. As for the storage capacity of 64K words, it can be used directly; Table 3 can also be further divided to reduce the storage capacity. If you need to continue to divide Table 3, go to Step 4.
第四步,进一步细化处理完输入序列后每个移位寄存器状态与其它移位寄存器初始状态相关的部分,也就是将表三进一步划分为两个子表,并构造每个子表相应的查找表。 The fourth step is to further refine the part of each shift register state related to the initial state of other shift registers after the input sequence is processed, that is, to further divide Table 3 into two sub-tables, and construct a corresponding lookup table for each sub-table .
将表三中的自变量R1~R16分成R1~R8和R9~R16两组,相应的,将表三分为与两组自变量对应的两个子表:表五和表六。通常情况下,表五以自变量R1~R8作为地址索引,将相应的R’1~R’16值存储到存储器中,形成查找表;表六以自变量R9~R16作为地址索引,将相应的R’1~R16值存储到存储器中,形成查找表。
表五
表六 Table 6
在实际操作中,如果输入序列M的比特数为16、32等,同样可以将处理完输入序列后每个移位寄存器状态与输入比特序列相关的部分按上述类似的方法划分,即可将表四进一步划分为两个子表,并构造每个子表相应的查找表。这里,形成查找表的过程与第三步中所述构造查找表的过程相同。In actual operation, if the number of bits of the input sequence M is 16, 32, etc., it is also possible to divide the part of each shift register state related to the input bit sequence after processing the input sequence according to the above-mentioned similar method, and the table Four is further divided into two sub-tables, and a corresponding lookup table is constructed for each sub-table. Here, the process of forming the lookup table is the same as the process of constructing the lookup table described in the third step.
经过以上四个步骤,本实施例中所需的查找表就构造完成了。实际上,在本实施例中,表五可以不构造查找表,只要将地址索引R1~R8进行算术移位,即可获得对应的R’1~R’16。After the above four steps, the required lookup table in this embodiment is constructed. In fact, in this embodiment, Table 5 does not need to construct a lookup table, as long as the address indexes R1-R8 are arithmetically shifted, the corresponding R'1-R'16 can be obtained.
基于上面所构造的查找表,以CRC16进行校验时,CRC的计算过程如图5所示包括以下步骤:Based on the lookup table constructed above, when checking with CRC16, the calculation process of CRC includes the following steps as shown in Figure 5:
步骤501:判断当前需要处理的比特数是否小于每次能处理的比特数m,本实施例中m值取8,那么,如果剩余比特大于8,则执行步骤504;否则,执行步骤502。Step 501: Determine whether the number of bits currently to be processed is less than the number m of bits that can be processed each time. In this embodiment, the value of m is 8. If the remaining bits are greater than 8, then perform
步骤502~503:按照一般的串行输入方法对剩余比特进行CRC计算处理,并读出移位寄存器中的值,结束当前CRC计算流程。Steps 502-503: Perform CRC calculation processing on the remaining bits according to the general serial input method, and read out the value in the shift register, ending the current CRC calculation process.
步骤504:将图4所示的移位寄存器初始状态存储到一个16比特长的存储单元R中。这里,如果采用DSP实现,可存储到一个寄存器中;如果采用FPGA实现,可存储在一个16比特的向量中。Step 504: Store the initial state of the shift register shown in FIG. 4 into a 16-bit storage unit R. Here, if implemented by DSP, it can be stored in a register; if implemented by FPGA, it can be stored in a 16-bit vector.
步骤505~506:从待处理的比特流中取出m个比特存储到存储单元M中,其中m常取8、16等值,本实施例中取m=8。以M1~M8为地址索引查找表四生成的查找表,获取对应的R’1~R’16,分别存储于第i个16比特存储单元Ti中。如果M表被划分为多个子表,比如M取16、32等值时,查找每个子表对应的查找表,并将获取的R’1~R’16进行模2加后分别存储于存储单元Ti中。Steps 505-506: Take m bits from the bit stream to be processed and store them in the storage unit M, where m often takes values such as 8 and 16, and takes m=8 in this embodiment. Using M1-M8 as the address index look-up table generated by the look-up table 4, the corresponding R'1-R'16 are obtained and stored in the i-th 16-bit storage unit Ti respectively. If the M table is divided into multiple sub-tables, for example, when M takes values such as 16 and 32, look up the lookup table corresponding to each sub-table, and add the obtained R'1 to R'16 modulo 2 and store them in the storage unit respectively In Ti.
步骤507:以R1~R8为地址索引进行算术移位运算,将获取的R’1~R’16构成的字或向量与对应的存储单元Ti中的值进行模2加,结果再存储到对应的存储单元Ti中;再以R9~R16为地址索引,查找表六对应的查找表,将获取的R’1~R’16构成的字或向量与对应的存储单元Ti中的值进行模2加,结果存储至对应的存储单元Ti中。Step 507: Carry out arithmetic shift operation with R1~R8 as the address index, add the word or vector obtained by R'1~R'16 to the value in the corresponding storage unit Ti modulo 2, and then store the result in the corresponding In the storage unit Ti; then use R9-R16 as the address index, look up the look-up table corresponding to Table 6, and perform modulo 2 on the obtained word or vector formed by R'1-R'16 and the value in the corresponding storage unit Ti Add, and the result is stored in the corresponding storage unit Ti.
如果存在更多的子表,比如CRC24、CRC32时,初始状态有24、32比特宽,这些情况下,查找所有子表对应的查找表,每次将当前所获取的表项与对应的存储单元Ti中的值进行模2加,再存储到对应的Ti中。If there are more sub-tables, such as CRC24 and CRC32, the initial state has a width of 24 and 32 bits. In these cases, look up the lookup tables corresponding to all sub-tables, and compare the currently obtained table entries with the corresponding storage units each time. The value in Ti is added modulo 2, and then stored in the corresponding Ti.
步骤508:将存储单元T1~T16的值存入R1~R16中,作为处理完m个比特后移位寄存器Ri的状态,并作为下一阶段CRC计算移位寄存器Ri的初始状态,返回步骤501。Step 508: Store the values of storage units T1-T16 into R1-R16 as the state of the shift register Ri after m bits are processed, and as the initial state of the shift register Ri in the next stage of CRC calculation, and return to step 501 .
按照本发明方法进行CRC计算,在性能上,如果有T个子表,则需要进行T次查表操作和T-1次异或操作,可以在复杂度不增加的情况下加快CRC计算速度。在存储开销方面,在保证性能不变甚至提高的情况下,可明显降低存储开销。以3GPP中常用的8位、12位、16位和24位CRC模式为例,当m=8,即每次处理8个输入比特时,每个子表大小都为256,单位由CRC长度决定。具体存储开销如表七所示:
表七Table 7
以上所述,仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention.
Claims (7)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNB2003101224478A CN100388629C (en) | 2003-12-22 | 2003-12-22 | A Fast Calculation Method of Cyclic Redundancy Check |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CNB2003101224478A CN100388629C (en) | 2003-12-22 | 2003-12-22 | A Fast Calculation Method of Cyclic Redundancy Check |
Publications (2)
Publication Number | Publication Date |
---|---|
CN1633030A true CN1633030A (en) | 2005-06-29 |
CN100388629C CN100388629C (en) | 2008-05-14 |
Family
ID=34844509
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CNB2003101224478A Expired - Lifetime CN100388629C (en) | 2003-12-22 | 2003-12-22 | A Fast Calculation Method of Cyclic Redundancy Check |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN100388629C (en) |
Cited By (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101847999A (en) * | 2010-05-28 | 2010-09-29 | 清华大学 | Method for performing parallel check by using cyclic redundancy check codes |
CN101976214A (en) * | 2010-09-30 | 2011-02-16 | 西北工业大学 | Self-adaptive rate cyclic redundancy check (CRC) code implementation method and device |
CN101207467B (en) * | 2006-12-19 | 2011-05-18 | 大唐移动通信设备有限公司 | Generation of cyclic redundancy check code as well as method and apparatus for sending and testing data sequence |
CN102612173A (en) * | 2011-01-21 | 2012-07-25 | 芯讯通无线科技(上海)有限公司 | Multi-mode mobile phone and method for communication between communication modules of multi-mode mobile phone |
CN102739258A (en) * | 2011-04-14 | 2012-10-17 | 普天信息技术研究院有限公司 | Method and apparatus for calculating cyclic redundancy check code |
CN102761394A (en) * | 2012-07-05 | 2012-10-31 | 中兴通讯股份有限公司 | Method and device for processing data |
CN103795502A (en) * | 2014-02-28 | 2014-05-14 | 杭州华三通信技术有限公司 | Data frame check code generating method and device |
CN106788878A (en) * | 2015-11-24 | 2017-05-31 | 中国航空工业第六八研究所 | A kind of Parallel CRC error correction method with monobit errro correction function |
CN108574490A (en) * | 2018-05-08 | 2018-09-25 | 华为技术有限公司 | Method and device for calculating cyclic redundancy check CRC code |
CN111740882A (en) * | 2020-07-29 | 2020-10-02 | 江苏金智科技股份有限公司 | Method for automatically checking configuration file of line protection measurement and control device |
CN114942861A (en) * | 2022-03-22 | 2022-08-26 | 安吉芥子科技有限公司 | CRC calculation method, device, computer equipment and storage medium |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6360348B1 (en) * | 1999-08-27 | 2002-03-19 | Motorola, Inc. | Method and apparatus for coding and decoding data |
US6609226B1 (en) * | 2000-04-10 | 2003-08-19 | Nortel Networks Limited | Networking device and method for making cyclic redundancy check (CRC) immune to scrambler error duplication |
CN1112778C (en) * | 2000-08-08 | 2003-06-25 | 深圳市中兴通讯股份有限公司 | Channel circulation redundance code checking method in digital communication system |
US20030093381A1 (en) * | 2001-11-09 | 2003-05-15 | David Hohl | Systems and methods for authorization of data strings |
-
2003
- 2003-12-22 CN CNB2003101224478A patent/CN100388629C/en not_active Expired - Lifetime
Cited By (16)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101207467B (en) * | 2006-12-19 | 2011-05-18 | 大唐移动通信设备有限公司 | Generation of cyclic redundancy check code as well as method and apparatus for sending and testing data sequence |
CN101847999B (en) * | 2010-05-28 | 2012-10-10 | 清华大学 | Method for performing parallel check by using cyclic redundancy check codes |
CN101847999A (en) * | 2010-05-28 | 2010-09-29 | 清华大学 | Method for performing parallel check by using cyclic redundancy check codes |
CN101976214A (en) * | 2010-09-30 | 2011-02-16 | 西北工业大学 | Self-adaptive rate cyclic redundancy check (CRC) code implementation method and device |
CN101976214B (en) * | 2010-09-30 | 2012-12-19 | 西北工业大学 | Self-adaptive rate cyclic redundancy check (CRC) code implementation method and device |
CN102612173B (en) * | 2011-01-21 | 2016-08-10 | 芯讯通无线科技(上海)有限公司 | The means of communication between multi mode terminal and communication module thereof |
CN102612173A (en) * | 2011-01-21 | 2012-07-25 | 芯讯通无线科技(上海)有限公司 | Multi-mode mobile phone and method for communication between communication modules of multi-mode mobile phone |
CN102739258A (en) * | 2011-04-14 | 2012-10-17 | 普天信息技术研究院有限公司 | Method and apparatus for calculating cyclic redundancy check code |
CN102761394A (en) * | 2012-07-05 | 2012-10-31 | 中兴通讯股份有限公司 | Method and device for processing data |
CN103795502A (en) * | 2014-02-28 | 2014-05-14 | 杭州华三通信技术有限公司 | Data frame check code generating method and device |
CN103795502B (en) * | 2014-02-28 | 2017-04-12 | 杭州华三通信技术有限公司 | Data frame check code generating method and device |
CN106788878A (en) * | 2015-11-24 | 2017-05-31 | 中国航空工业第六八研究所 | A kind of Parallel CRC error correction method with monobit errro correction function |
CN106788878B (en) * | 2015-11-24 | 2019-11-15 | 中国航空工业第六一八研究所 | A Parallel CRC Error Correction Method with Single Bit Error Correction Function |
CN108574490A (en) * | 2018-05-08 | 2018-09-25 | 华为技术有限公司 | Method and device for calculating cyclic redundancy check CRC code |
CN111740882A (en) * | 2020-07-29 | 2020-10-02 | 江苏金智科技股份有限公司 | Method for automatically checking configuration file of line protection measurement and control device |
CN114942861A (en) * | 2022-03-22 | 2022-08-26 | 安吉芥子科技有限公司 | CRC calculation method, device, computer equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN100388629C (en) | 2008-05-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN100388630C (en) | cyclic redundancy code calculation method and system with matrix conversion technology | |
CN103795502B (en) | Data frame check code generating method and device | |
CN1633030A (en) | A Fast Calculation Method of Cyclic Redundancy Check | |
JP2003324357A5 (en) | ||
CN108540139B (en) | FPGA implementation method and device of a general quasi-cyclic LDPC code encoder | |
CN1291379A (en) | Interleaving/deinter leaving device and method for communication system | |
CN107239362A (en) | Parallel CRC (Cyclic redundancy check) code calculation method and system | |
CN102356554B (en) | Turbo code data interweaving process method and interweaving device used for interweaving turbo code data | |
CN101043284A (en) | Interleaver of TURBO coder in WCDMA system | |
CN113300716A (en) | Method and device for generating cyclic redundancy check code and computer readable medium | |
CN1714513A (en) | Address generation for the interleaver in the TURBO encoder and decoder | |
CN102739258A (en) | Method and apparatus for calculating cyclic redundancy check code | |
CN1258148C (en) | Encryption, decryption method using high security level symmetry secret key algorithm and its encipherer | |
CN1677921A (en) | The Method of Realizing Data Encryption Through Programmable Device | |
CN1397121A (en) | Method and device for generating OVSF | |
CN1281023C (en) | Discrete Data Block Encryption Method | |
CN114866231A (en) | Cryptosystem based on Classic McElience cryptosystem | |
CN109327276B (en) | Secure encoding method, decoding method and device | |
CN105721107A (en) | Device and method for improving clock frequency by block calculation of CRC (Cyclic Redundancy Check) | |
US20220352901A1 (en) | Cyclic redundancy check, crc,decoding using the inverse crc generator polynomial | |
CN1652075A (en) | Systems and methods for efficient VLSI structures for finite fields | |
CN1192486C (en) | Integrated circuit implementing method and circuit of shortened cyclic code correcting interpretation algorithm | |
CN108566210B (en) | LDPC coding system and method compatible with IEEE 802.11n standard, LDPC encoder | |
CN102130744A (en) | Method and device for calculating cyclic redundancy check code | |
CN116722967A (en) | Lightweight joint coding password implementation method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
ASS | Succession or assignment of patent right |
Owner name: CHINA POTEVIO COMPANY LIMITED Free format text: FORMER OWNER: CHINA PUTIAN INSTITUTE OF TECHNOLOGY CO., LTD. Effective date: 20090508 |
|
C41 | Transfer of patent application or patent right or utility model | ||
C56 | Change in the name or address of the patentee |
Owner name: CHINA PUTIAN INSTITUTE OF TECHNOLOGY CO., LTD. Free format text: FORMER NAME: CHINA PUTIAN INSTITUTE OF TECHNOLOGY |
|
CP03 | Change of name, title or address |
Address after: No. two, 6 North Street, Haidian District, Beijing, Haidian Patentee after: PETEVIO INSTITUTE OF TECHNOLOGY Co.,Ltd. Address before: No. two, 2 street, Beijing information industry base Patentee before: POTEVIO Institute of Information Technology |
|
TR01 | Transfer of patent right |
Effective date of registration: 20090508 Address after: No. two, 2 street, Zhongguancun science and Technology Park, Beijing, Haidian District Patentee after: CHINA POTEVIO CO.,LTD. Address before: No. two, 6 North Street, Haidian District, Beijing, Haidian Patentee before: PETEVIO INSTITUTE OF TECHNOLOGY Co.,Ltd. |
|
CX01 | Expiry of patent term |
Granted publication date: 20080514 |
|
CX01 | Expiry of patent term |