Method and apparatus for verifying CRC codes by combination of partial CRC codes

Abstract: Apparatus for verifying a CRC code of a message transmitted as a succession of sub-blocks comprises dedicated hardware including a linear feedback shift register (14) for deriving a 'partial' CRC code for each individual sub-block. These partial CRC codes are held in a store (16) for subsequent combination under software program control. The combination is performed in a iterative manner, each partial CRC code being added modulo 2 to values selected from look-up tables in accordance with the result of the previous step of the iteration. The division of the CRC verification into two operations and the use of pre-calculated look-up tables facilitate the efficient, simultaneous reception of many messages having interleaved sub-blocks without incurring serious time penalties.

Description: Technical Field This invention relates to methods and apparatus for verifying cyclic redundancy check (CRC) codes. Background Art CRC codes are used extensively in digital data communications for detection of errors which can occur during the communications process. Typically a message to be communicated is assembled and encoded in binary digital form, and a CRC code is derived from it using a predetermined algorithm together with a predetermined multi-bit number. One particular number in widespread use for this purpose can be represented by the following polynomial of degree thirty-two: g(x)=x 32 +x 26 +x 23 +x 22 +x 16 +x 12 +x 11 +x 10 +x 8 +x 7 +x 5 +x 4 +x 2 +x+1. In one implementation of this technique, a 32-stage shift register is provided with an exclusive-OR gate at its output (stage 31, numbering from zero) to add the output signal, modulo 2, to successive bits of the message to be communicated, in synchronism with shifting of the contents of the register. The output of this exclusive-OR gate is fed directly to the first stage (stage 0), and to further exclusive-OR gates coupling each of the remaining stages corresponding to the terms of g ( x ) (that is stages 26, 23, ..., 2 and 1) to its preceding stage (see Figure 1). The shift register is initially loaded with all ones, and then receives the message to be communicated as described; when the whole message has been input, the contents of the shift register are output and inverted to produce the CRC code, which is conventionally appended to the message. Upon reception the message and its appended CRC code are input in the same manner into a similarly-arranged shift register pre-loaded with all ones; when the whole message and the CRC code have been input, the shift register should contain the binary value 1100 0111 0000 0100 1101 1101 0111 1011 (C704DD7B H ), corresponding to the remainder of dividing the polynomial x 63 +x 62 +...+x 33 +x 32 by the polynomial g ( x ). If any other value results, the message has sustained one or more errors. Although such an implementation is effective and reliable, there are circumstances where it is disadvantageous. One technique currently being implemented for high-speed data transfer is known as Asynchronous Transfer Mode (ATM). In implementations of ATM for 'local' use, e.g. within buildings, a single message may be relatively large (up to 65568 bytes for example). For transmission purposes, this message is padded to an exact multiple of 48 bytes in length and then split into consecutive 48-byte segments. Although in accordance with the ATM protocol these segments are received in the same order in which they are transmitted, they may be interspersed with segments from other transmissions, intended for the same or another recipient. One possible approach to verifying the CRC code for the received message would be to derive the CRC verification result as part of general processing of the message. However, such processing is typically carried out by data processing equipment under software program control, imposing a serious time penalty on the speed of processing of each message. In principle it would be possible to derive the CRC verification result for each message in real time by supplying its successive segments to a shift register as they are received; interspersed segments for other messages could be handled either by providing an individual shift register for each distinct message, or by saving and restoring the contents of the shift register each time a segment for a different message is received. However, the first option is very expensive in terms of circuit hardware, while the second imposes an undesirable delay as the current contents of the shift register for one message and the message's identity are saved, and the message whose next segment has arrived is identified and the previously-saved contents for that message are retrieved and loaded into the register. Furthermore, both approaches require setting some arbitrary limit to the number of different messages which may be received simultaneously. The IBM Technical Disclosure Bulletin, vol.30, no.12, 05.88, pages 458-464, discloses a bytewise parallel CRC determination method. In this method, each byte of input data is combined (XORed) with the current content of a register. The result of the XOR operation is used for addressing a plurality of tables, the output of which is used for updating the register. European patent application no. A-0 465 006 discloses a method of calculating a checksum involving the determination of partial checksums. However, this document does not relate to the calculation of a cyclic checksum. Disclosure of Invention According to one aspect of this invention there is provided a method of verifying a CRC code relating to a block of data transferred as a plurality of sub-blocks via a communications medium, said CRC code including a remainder after division by a predetermined polynomial of an operand derived from said data block, comprising the steps -of: deriving for each received sub-block of data, from a predetermined initializing value and using said predetermined polynomial, a respective partial CRC code; combining said partial CRC codes to derive a CRC verification value for the complete data block as received and which is indicative of whether the data block received is consistent with a CRC code which would be derived using said predetermined polynomial for said data block considered as a whole; and testing validity of said verification value for the complete received data block. Using this method a separate partial CRC code is derived for each ATM segment and saved in association with it; the starting value for CRC code generation (e.g. the contents of the shift register described above) is then reset to a predetermined initializing value (e.g. all zeroes). Subsequently the partial CRC codes for all the segments comprising a complete message are combined, as described herein, to derive a CRC verification value which relates to the complete message and which can be used to check whether the mess age has been affected by errors. The derivation of the partial CRC codes can conveniently be accomplished at high speed in dedicated hardware circuitry, whilst the combination of partial CRC codes can be accomplished using circuitry under software program control without incurring a serious time penalty. With this invention there is no need to identify which message a segment belongs to as part of the partial CRC code derivation, and there is no limit in principle to the number of messages which may be received simultaneously. According to another aspect of this invention apparatus for verifying a CRC code relating to a block of data transferred as a plurality of sub-blocks via a communications medium, said CRC code including a remainder after division by a predetermined polynomial of an operand derived from said data block, comprising: means for deriving for each received sub-block of data, from a predetermined initializing value and using said predetermined polynomial, a respective partial CRC code; means for combining said partial CRC codes to derive a CRC verification value for the complete data block as received and which is indicative of whether the data block received is consistent with a CRC code which would be derived using said predetermined polynomial for said data block considered as a whole; and means for testing validity of said verification value for the complete received data block. Brief Description of Drawings A method and apparatus in accordance with this invention for verifying CRC codes will now be described, by way of example, with reference to the accompanying drawings, in which: Figure 1 shows a shift register for deriving a CRC code based on the polynomial g (x); Figure 2 is a block diagram of apparatus for verifying CRC codes in accordance with this invention; Figure 3 is a flow chart of a procedure implemented in part of the apparatus of Figure 2; and Figures 4 a to 7 b are look-up tables of hexadecimal values used in the procedure of Figure 3. Best Mode for Carrying Out the Invention. & Industrial Applicability Referring to Figure 2, apparatus for receiving an ATM data stream on an optical fibre input line 10 and for verifying CRC codes of messages in the data stre am has an input interface 12 coupled to the line 10. As shown in Figure 2, the ATM data stream is treated as comprising a sequence of cells, each cell having a five-byte header H which carries system operating information and a 48-byte payload comprising one segment of a complete ATM message. Successive cells may contain segments for different messages, and the identity of the message to which a segment belongs is included in the information in the header H of the cell containing that segment. The input interface 12 converts the signal from the line 10 from optical form to electrical form, produces a data signal containing the segment data in each cell, produces a clock signal synchronized with the occurrence of binary digits in the signal (clock recovery), locates the boundaries between ATM cells in the received data stream to produce a start-of-cell (SOC) signal, and extracts from the cell header the identity of the message to which each segment belongs. Techniques and circuitry for performing these functions are well known to those skilled in the art and do not form part of this invention, and so will not be described here. The data signal, clock signal and SOC signal are supplied to a 32-bit shift register 14 arranged to implement a CRC code as described above and as shown in Figure 1. In addition to the connections shown in Figure 1, the shift register 14 has two further inputs: a clock input which receives the clock signal and synchronizes shifting of data through the register; and a control input which receives the SOC signal and causes the current contents of the shift register to be output (saved) and the shift register to be reset to a predetermined initializing value of all zeroes. Implementation of these inputs will also be evident to those skilled in the art. The output of the shift register 14 is coupled to a store 16 which also receives the data signal, clock signal and message identity from the input interface 12. When an SOC signal occurs the current contents of the shift register 14 (a 'partial' CRC code, PCRC) are output to the store 16 which stores them in conjunction with the corresponding segment data and the identity of the message (MsgID) to which that segment belongs. The store 16 may have as large a capacity as desired, typically several thousands of segments and associated PCRC's and MsgID's. Although the derivation of partial CRC codes by the shift register 14 and the transfer of data through the circuitry have been described and illustrated in terms of serial techniques for the sake of clarity, it will be understood by those skilled in the art that these operations may equally be implemented using parallel mechanisms to operate on several bits simultaneously if desired. When all the segments comprising a message have been received, the complete message is assembled and its CRC code is verified by a verification device 18. This device may conveniently be implemented by means of a data processor unit controlled by an appropriate software program; the data processor unit may also be used to implement further processing of the received messages, for example in accordance with higher-level communication protocols. The verification device 18 extracts from the store 16 the PCRC for each segment having the MsgID for that message, and combines it with the PCRC's for the other segments of the message in accordance with the procedure shown in Figure 3. Referring to Figure 3, the procedure starts at step 30 by setting a counter s equal to one, and initializing a four-byte hexadecimal variable CRC to a value of FFFFFFFF H . At the next step 32 the procedure derives a value for an index I into each of four look-up tables in accordance with the values of respective bytes of the variable CRC. Thus an index I 408 is set equal to the value of the most significant byte of CRC, an index I 400 is set equal to the second most significant byte, an index I 392 is set equal to the third most significant byte and an index I 384 is set equal to the least significant byte. Each look-up table has 256 entries, the values of which will depend upon the particular polynomial upon which the CRC code algorithm is based and can be calculated as described hereinafter. A set of tables T 384 , T 392 , T 400 and T 408 for the polynomial g ( x ) are given in Figures 4 a to 7 b . At step 34 the procedure retrieves the value of the PCRC for segment s , the segments being numbered in the order in which they were received; thus the first PCRC retrieved ( s =1) is for the most significant segment, which is the first segment to be received; the last segment retrieved is the least significant segment, for s equal to the total number of segments in the message. An updated value for CRC is derived at step 36, in accordance with the relationship CRC = PCRC(s) ⊕ T 408 (I 408 ) ⊕ T 400 (I 400 ) ⊕ T 392 (I 392 ) ⊕ T 384 (I 384 ) where ⊕ indicates a bit-wise exclusive-OR operation and T 408 (I 408 ) indicates the entry in the table T 408 for the current value of the index I 408 . The value of s is incremented by one at step 38, and the incremented value is tested at step 40. If s is less than or equal to the total number of segments in the message, the procedure returns to step 32 to derive new values for the indexes I 384 , I 392 , I 400 and I 408 in accordance with the respective bytes comprising the updated value of CRC. If the incremented value of s is greater than the total number of segments in the message the value of CRC is the CRC verification value for the complete message. This is tested at step 42 for equality with the expected value of C704DD7B H for an error-free message. If CRC has this value, then a valid CRC code is indicated at step 44; otherwise an invalid CRC code, and therefore the occurrence of one or more errors in the received message, is indicated at step 46. In the latter case appropriate steps would be taken, such as requesting retransmission of the message, depending on the particular communication protocol being used. Although the procedure of Figure 3 has been described in the context of completing reception of an entire message before derivation of the overall CRC verification value commences, it should be noted that the procedure may equally be applied to derivation of the CRC verification value contemporaneously with reception of each successive segment. By way of example, a three-segment message and appended CRC code may be received having successive segments with partial CRC's derived by the shift register 14 as follows: PCRC(1) = A07C4DD8 H PCRC(2) = 072FEB03 H PCRC(3) = 2E24F35D H . The values of I 384 , I 392 , I 400 and I 408 for the initial value of CRC of FFFFFFFF H are I 384 = I 392 = I 400 = I 408 = FF H for which the look-up table entries are T 384 = 580FA91E H , T 392 = 513658BF H , T 400 = 4A0E09B0 H and T 408 = 150516A1 H . The first calculation of CRC at step 36 yields CRC = A07C4DD8⊕580FA91E⊕513658BF⊕4A0E09B0⊕150516A1 = F64EA368 H . The next values of I 384 , I 392 , I 400 and I 408 are I 384 = 68 H , I 392 = A3 H , I 400 = 4E H and I 408 = F6 H and the look-up table entries are T 384 = 267A5A62 H , T 392 = D5B60D44 H , T 400 = 859250AC H and T 408 = 1EE6098C H . So the next calculation of CRC at step 36 yields CRC = 072FEB03⊕267A5A62⊕D5B60D44⊕859250AC⊕1EE6098C = 6F97E505 H . The new values of I 384 , I 392 , I 400 and I 408 are therefore I 384 = 05 H , I 392 = E5 H , I 400 = 97 H and I 408 = 6F H and the corresponding look-up table entries are T 384 = B55AB166 H , T 392 = ED693030 H , T 400 = 1A274B01 H and T 408 = AB34E471 H . So the final calculation of CRC at step 36 yields CRC = 2E24F35D⊕B55AB166⊕ED693030⊕1A274B01⊕AB34E471 = C704DD7B H . This is the expected value for CRC verification, so the CRC process does not indicate any transmission errors. The look-up tables T 384 , T 392 , T 400 and T 408 contain values calculated according to the following relationships, for 0 ≤ i < 256: T 384 [ i ] = ( x 384 i ( x )) mod g ( x ) T 392 [ i ] = (x 392 i ( x )) mod g ( x ) T 400 [ i ] = ( x 400 i ( x )) mod g ( x ) T 408 [ i ] = ( x 408 i ( x )) mod g ( x ) wher e i ( x ) is the polynomial corresponding to the eight-bit value i . The following routine in C program code may be used for this purpose:

Claims: A method of verifying a CRC code relating to a block of data transferred as a plurality of sub-blocks via a communications medium, said CRC code including a remainder after division by a predetermined polynomial of an operand derived from said data block, comprising the steps of: deriving (14) for each received sub-block of data, from a predetermined initializing value and using said predetermined polynomial, a respective partial CRC code; combining (30,32,34,36) said partial CRC codes to derive a CRC verification value for the complete data block as received and which is indicative of whether the data block received is consistent with a CRC code which would be derived using said predetermined polynomial for said data block considered as a whole; and testing (42) validity of said verification value for the complete received data block. The method of claim 1, wherein said partial CRC codes are derived using hardware circuitry (14) dedicated to that purpose, and the verification value for the complete data block is derived using general-purpose hardware circuitry (18) controlled by program instructions. The method of claim 1 or claim 2, wherein said partial CRC codes are derived by: presetting a shift register (14) with said initializing value, said shift register having feedback via exclusive-OR gates from its output to predetermined shift register stages; shifting one data sub-block into said shift register; and storing (16) the resulting contents of said shift register. The method of any one of the preceding claims, wherein said initializing value is zero. The method of any one of the preceding claims, wherein said CRC verification value is derived by combining (36) the partial CRC code for the second and each subsequent data sub-block with one or more values selected (32) from one or more predetermined tables in accordance with the result of such combination step for the preceding partial CRC code, a value or values for combination with the partial CRC code for the first data sub-block bein g selected from said table or tables in accordance with a predetermined starting value (30). The method of claim 5, wherein there are a plurality of predetermined tables and values are selected from said tables in accordance with values of respective portions of the result of said combination step for the preceding partial CRC code or of said predetermined starting value. The method of claim 6, wherein said partial CRC codes and said table or tables are stored as hexadecimal values, said respective portions are adjacent pairs of hexadecimal digits, and said combination step is performed using bit-wise modulo 2 addition. The method of claim 7, wherein said predetermined starting value is all hexadecimal F's, said CRC code is derived in accordance with the polynomial g (x)= x 32 +x 26 +x 23 +x 22 +x 16 +x 12 +x 11 +x 10 +x 8 +x 7 +x 5 +x 4 +x 2 +x+1 and values are selected for said combination step from the tables of Figures 4 a to 7 b . Apparatus for verifying a CRC code relating to a block of data transferred as a plurality of sub-blocks via a communications medium, said CRC code including a remainder after division by a predetermined polynomial of an operand derived from said data block, comprising: means for deriving (14) for each received sub-block of data, from a predetermined initializing value and using said predetermined polynomial, a respective partial CRC code; means for combining (30,32,34,36) said partial CRC codes to derive a CRC verification value for the complete data block as received and which is indicative of whether the data block received is consistent with a CRC code which would be derived using said predetermined polynomial for said data block considered as a whole; and means for testing validity (42) of said verification value for the complete received data block. The apparatus of claim 9, comprising hardware circuitry (14) dedicated to derivation of said partial CRC codes, and general-purpose hardware circuitry (18) controlled by program instructions for deriving the verification value for the complete data block.

Inventors: JEDWAB JONATHAN, JEDWAB, JONATHAN
Applicants: HEWLETT PACKARD CO, HEWLETT-PACKARD COMPANY
Application year: 1993
Main classification: H03M13
IPC codes: H04L1, G06F11, H03M13