Docsity

Checksum Functions for TCP: Design of a New Scheme, Study notes of Design

Toggle sidebar
bg1
Appendix: IEN-45
TCP Checksum Function Design
William W. Plummer
5 June 1978
1.
Introduction
Checksums are included in packets in order that errors encountered during transmission may be detected.
For Internet protocols such as TCP [1,9] this is especially important because packets may have to cross
wireless networks such as the Packet Radio Network [2] and Atlantic Satellite Network [3] where packets
may be corrupted. Internet protocols (e.g., those for real time speech transmission) can tolerate a certain
level of transmission errors and forward error correction techniques or possibly no checksum at all might
be better. The focus in this paper is on checksum functions for protocols such as TCP where the required
reliable delivery is achieved by retransmission.
Even if the checksum appears good on a message which has been received, the message may still contain
an undetected error. The probability of this is bounded by 2 <-c) where C is the number of checksum bits.
Errors can arise from hardware (and software) malfunctions as well as transmission errors. Hardware
induced errors are usually manifested in certain well known ways and it is desirable to account for this in
the design of the checksum function. Ideally no error of the "common hardware failure" type would go
undetected.
An example of a failure that the current checksum function handles successfully is picking up a bit in the
network interface (or I/O buss, memory channel, etc.). This will always render the checksum bad. For an
example of how the current function is inadequate, assume that a control signal stops functioning in the
network interface and the interface stores zeros in place of the real data. These "all zero" messages appear
to have valid checksums. Noise on the "There's Your Bit" line of the ARPANET Interface [4] may go
undetected because the extra bits input may cause the checksum to be perturbed (i.e., shifted) in the same
way as the data was.
Although messages containing undetected errors will occasionally be passed to higher levels of protocol, it
is likely that they will not make sense at that level. In the case of TCP most such messages will be ignored,
but some could cause a connection to be aborted. Garbled data could be viewed as a problem for a layer of
protocol above TCP which itself may have a checksuming scheme.
This paper is the first step in design of a new checksum function for TCP and some other Internet proto-
cols. Several useful properties of the current function are identified. If possible these should be retained in
any new function. A number of plausible checksum schemes are investigated. Of these only the "product
code" seems to be simple enough for consideration.
2. The Current TCP Checksum Function
The current function is oriented towards sixteen-bit machines such as the PDP-11 but can be computed
easily on other machines (e.g., PDP-10). A packet is thought of as a string of I6-bit bytes and the check-
sum function is the one's complement sum (add with end-around carry) of those bytes. It is the one's com-
plement of this sum which is stored in the checksum field of the TCP header. Before computing the check-
sum value, the sender places a zero in the checksum field of the packet. If the checksum value computed by
a receiver of the packet is zero, the packet is assumed to be valid, This is a consequence of the "negative"
number in the checksum field exactly cancelling the contribution of the rest of the packet.
-gS-
pf3
pf4
pf5

Partial preview of the text

Download Checksum Functions for TCP: Design of a New Scheme and more Study notes Design in PDF only on Docsity!

A p p e n d i x : I E N - 4 5

T C P C h e c k s u m F u n c t i o n D e s i g n

William W. Plummer

5 June 1978

1. Introduction Checksums are included in packets in order that errors encountered during transmission may be detected. For Internet protocols such as TCP [1,9] this is especially important because packets may have to cross wireless networks such as the Packet Radio Network [2] and Atlantic Satellite Network [3] where packets may be corrupted. Internet protocols (e.g., those for real time speech transmission) can tolerate a certain level of transmission errors and forward error correction techniques or possibly no checksum at all might be better. The focus in this paper is on checksum functions for protocols such as TCP where the required reliable delivery is achieved by retransmission. Even if the checksum appears good on a message which has been received, the message may still contain an undetected error. The probability of this is bounded by 2 <-c) where C is the number of checksum bits. Errors can arise from hardware (and software) malfunctions as well as transmission errors. Hardware induced errors are usually manifested in certain well known ways and it is desirable to account for this in the design of the checksum function. Ideally no error of the "common hardware failure" type would go undetected. An example of a failure that the current checksum function handles successfully is picking up a bit in the network interface (or I/O buss, memory channel, etc.). This will always render the checksum bad. For an example of how the current function is inadequate, assume that a control signal stops functioning in the network interface and the interface stores zeros in place of the real data. These "all zero" messages appear to have valid checksums. Noise on the "There's Your Bit" line of the ARPANET Interface [4] may go undetected because the extra bits input may cause the checksum to be perturbed (i.e., shifted) in the same way as the data was. Although messages containing undetected errors will occasionally be passed to higher levels of protocol, it is likely that they will not make sense at that level. In the case of TCP most such messages will be ignored, but some could cause a connection to be aborted. Garbled data could be viewed as a problem for a layer of protocol above TCP which itself may have a checksuming scheme. This paper is the first step in design of a new checksum function for TCP and some other Internet proto- cols. Several useful properties of the current function are identified. If possible these should be retained in any new function. A number of plausible checksum schemes are investigated. Of these only the "product code" seems to be simple enough for consideration. 2. The Current TCP Checksum Function The current function is oriented towards sixteen-bit machines such as the PDP-11 but can be computed easily on other machines (e.g., PDP-10). A packet is thought of as a string of I6-bit bytes and the check- sum function is the one's complement sum (add with end-around carry) of those bytes. It is the one's com- plement of this sum which is stored in the checksum field of the TCP header. Before computing the check- sum value, the sender places a zero in the checksum field of the packet. If the checksum value computed by a receiver of the packet is zero, the packet is assumed to be valid, This is a consequence of the "negative" number in the checksum field exactly cancelling the contribution of the rest of the packet.

-gS-

Ignoring the difficuhy of actually evalm~dng ~he checksum function for a given packet, the way of using die chexcks~m deseribed a~we is quite simple, but it assumes some prop<:r~ies of the chc(:'ks~m operator (or~e's cc~plement adNt.ion, ~*+" in whm follows):

(PI) + is commutative. Thus, the orde:r in which the 16--bit bytes are '~added" toged~er is u~dm~×:~r-

tent.

(I::'2) + has at least one identity element (The current functior~ has two: +0 and .-0). This allows the sender ~o compare the checksum function by placing a zero in d'~e packet checksum field bet\ore computing the value. (P3) + has an inverse. "Fnus, the receiver may evaluate &e checksum function and expect a zero, (P4) + is assoviative, albwing &e checksum field to be anywhere in the packet aid d~e 16-bit bytes m be .scanned sequentially. Mathematically, these properties of the binary operation " + " over the set of 16-bit numbers forms an Abeliam group [5]. Of course, there are many Abelkm groups but not all would be safisfactov for use as checksum operators. (Another operator readily available in the PDP-11 instruction set that has all of these

properties N exck~sive-OR, but XOR is unsatisfactory ftor other reasons.)

Albeit Lmprecise, ano~er proFerty which must be IXeServed in any future checksum scheme is: (P5) + is fast to compute on a variety of machines with limited storage requirernenks. The cmqcent t~anction is quite good in this respect. On abe PDP-11 the inner loop looks like:

LOOP: ADD (Rt)+,R0 ; A d d the next 1S-bit byte

ADC R0 ; Make carry be end-around

SOB R2,LQQP ; Loop over entire packet.

( 4 memory cycles per 16-b~ byte )

On the PDP-10 properties P 1 4 are exploited furzher and two 16-bit bytes per toop are processed:

LOOP:

CHKSU2:

/LDB THIS,PTR

ADD SUM,TH~S

JUMPGE SUM,CHKSU

LDB THIS,[POiNT 20,SUM,19]

ANDt SUM,

ADD SUM,THIS

SOJG COUNT,LOOP

; Get 2 16-bit bytes ; Add into current sum ; Jump ff fewer than 8 carries ; Get left 16 and carries ; Save just low 16 here ; Fold in carries ; Loop over entire packet

( 3.1 memory cycles per 16-bit byte )

The "extra" instruction in t,he too~s above are required to convert the two's complement ADD ipswuction(s) into a one's complement add by making the carries be end-at(mud. One's complement arith~ merle is bettor than two's complement because it is equally sensitive to errors in nit bit positions. If two's complement addition were used, an even number of l's could be dropped (or picked up) in the most significant bit channel without affecting the value of One checksum. It is just this property that makes some sort (of addition preferable to a simple e×clusive-OR which is fr~.tuently used but p~mits an even number of drops (pick ups) in any bit channel. RIM10B paper tape format used on PDP-10s [10] uses two's com- plement add because space for ~ e loader program is extremely limited. Another property of the current checksum svheme is: (P6) Adding the checksum to a packet does not change t~heinformation bytes, Pemrson [6] calls this a °'systematic" code. This property ~dtows intermediate computers such as gateway machines to act ofx fields (i.e., the Interact Destination Adduces) wiNout having to f~rst decode the packet. Cyclical Redundancy Checks usexl for error correctk)n are not sysmmatic tither. However, most applications of CRCs lend m emphasize error detection rather t.,~an correction and consequently can send the message unchaJlged, with the CRC check bits bei~g a ~ n d e d to the en& The 24.-bit CRC as~.d by ARPANET IMP3; aa~d Very Distant Host Interthces [4] and

For large messages f approaches 3.125 ~;r cent ~s k goes to infinib'.

Multiple pre~cision multiplication and division are normally quite complex operations, es~xecially o~ smaIl machines which typicaUy lack even single precision multiply and divide oIx;ra~.ions. T}m exceptio~~ to this is exactly the case bei.~N dealt with her~: ---.-o.-.the f~)~ctoris 2 ~¢,.-1 on machines with a word length of 16 bits. The remscm for this is due m the following idemity:

(~Q <R

itNat is, any digit Q in hhe >elec~M radix (0o 1.... R-l) multiplied by any ~ w e r of 0~e radix wilt have a remainder of Q when divided by the radix minus 1. Example: In decimal R = 10. Pick Q = 6.

6 = O * 9 + 6 = 6 , mod ~ = 6 * 9 + 6 = 6 , mod 600 = 66 * 9 + 6 = 6, rood 9 etc.

More m the poim, ram(3 I415/9) = rem((36~8+ 1000+400+ 10+5)/9) = (3 rood 9) + (I rood 9)+ (4 rood 9) + (I rood 9) + (5 m~xI 9) = (3+1+4+1+5) rood 9 = 14 rood = 5 So, t~heremainder of' a number divided by the radix minus one can be found by simply summing the digits of the number. Since the radix in tlhe TCP cave has been chosen to be 216 and the check factor is 2:'<.-1, a message can quickly be checked by summing all of the 1&bit words (on a PDP-I 1), with carries being end-around, tf zero is the results the message can be consideFmd valid. 2Nus, checking a pr<~Iuct coded mes- sage is exactly the s,qa~aecomplexity as win the c ~ n t TCP checksum{ In order to fiarm Ms, kbe sender must multiply tbe multiple precision '~number" Mo by 2~6-t. (~, Ms=(2~6)Mo-Mo. This is performed by shifting Mo one whole word's worth of precision and subtracting Mo. Sinc~e carries must propagate between digits, but it is only Ne current digit which is of interest, one's complement arithmetic is used.. (2~%~4o = Mo ~ M o t+Mo2+.... ~MoX + -Mo = %%~doO+Mo 1+ .... +MoX) = 7rr?:g~gg--

A loop which implements ~is function on a PDP- t 1

LOOP: MOV -2(R2),R

SBC R

SUB (R2)+,R MOV R0,(R3)+

SOB R1 ,LOOP

might look like:

; Next byte of (2"*t6)Mo ; Propagate carries from In.st SUB ; 8ubtracl byte o f m o ; Store in Ms ; Loop over entire message ; 8 memory cycles per IS-bit byte

Note ~ t ~ e coding pro(salute is not done in-place sL%e it is no{ systematic. In general uhe original copy, Me, will gave to be remSned by hhe sender for retransmi~ion purposvs and therefore must remain readable. Thus the MOV R0,(R3)+ is requh-ed which accoun~ for 2 of the 8 memory cycles per loop. The coding p r o c ~ r e will add exactly ome 1&bit word to the message since Ms <(2~)Mo This additior~N 16 bits will be at the tail of the m e ~ g e o but may be m o w into the defined location in the TCP header im y before transmission, Tim receiver wit1 have m undo this to put }as back into standard tbnnat ~fbr'e dec~Iing the mes~age. 2~e c ~ in the receiver for :fully decoding Ne message may be inferred by observing that any word in Ms contains the difference between two successive w~rds of Mo minus .the carries from the previous word, and the low order word coakains minus the Iow word of Mo, So the low order (Le,, rightmos0 w o n of Mr is j ~ t ~ e nega*Jve of the low order byte of Ms~ The next word of Mr is the ne×t word of Ms plus ~ e just

computed word of Mr plus the carry from that previous computation.

A slight refinement of the procedure is required in order to protect against an all-zero message passing to the destination, This will appear to have a valid checksum because Ms'/K = 0/K = 0 with 0 remainder. The refinement is to make the coding be Ms = K*Mo + C where C is some arbitrary, well-known constant, Adding this constant requires a second pass over the message, but this will typically be very short since it can stop as soon as carries stop propagating. Choosing C = 1 is sufficient in most cases.

The product code checksum must be evaluated in terms of the desired properties P1 - P7. It has been shown that a factor of two more machine cycles are consumed in computing or verifying a product code checksum (P5 satisfied?). Although the code is not systematic, the checksum can be verified quickly without decoding the message. If the Internet Destination Address is located at the least significant end of the packet (where the product code computation begins) then it is possible for a gateway to decode only enough of the message to see this field without having to decode the entire message. Thus, P6 is at least partially satisfied. The algebraic pro- perties P1 through P4 are not satisfied, but only a small amount of computation is needed to account for this -- the message needs to be reformatted as previously mentioned. P7 is satisfied since the product code checksum can be incrementally updated to account for an added word, although the procedure is somewhat involved. Imagine that the original message has two halves, H

and H2. Thus, Mo =H 1' (Ri)+H2. The timestamp word is to be inserted between these halves to form a

modified Mo" =H 1" (R ~+l))+T* (R J)+H 2. Since K has been chosen to be R-1, the transmitted message Ms'

= Mo'(R-1). Then,

Ms" =Ms*R +T(R -1)(Ri )+P 2((R -1) z)

=MsR +T (R (J+I))+T(R J)+p 2 (R 2)-2"P 2*R - P 2

Recalling that R is 216, the word size on the PDP-11, multiplying by R means copying down one word in memory. So, the first term of Ms' is simply the unmodified message copied down one word. The next term is the new data T added into the Ms' being formed beginning at the (j+l)th word. The addition is fairly easy here since after adding in T all that is left is propagating the carry, and that can stop as soon as no carry is produced. The other terms can be handle similarly.

4. More Complicated Codes

There exists a wealth of theory on error detecting and correcting codes. Peterson [6] is an excellent refer- ence. Most of these " C R C " schemes are designed to be implemented using a shift register with a feedback network composed of exclusive-ORs. Simulating such a logic circuit with a program would be too slow to be useful unless some programming trick is discovered. One such trick has been proposed by Kirstein [8]. Basically, a few bits (four or eight) of the current shift register state are combined with bits from the input stream (from Mo) and the result is used as an index to a table which yields the new shift register state and, if the code is not systematic, bits for the output stream (Ms). A trial coding of an especially "good" CRC function using four-bit bytes showed showed this tech- nique to be about four times as slow as the current checksum function. This was true for both the PDP- and PDP-11 machines. Of the desirable properties listed above, CRC schemes satisfy only P3 (It has an inverse.), and P6 (It is systematic.). Placement of the checksum field in the packet is critical and the CRC

cannot be incrementally modified.

Although the bulk of coding theory deals with binary codes, most of the theory works if the alphabet con- tains q symbols, where q is a power of a prime number. For instance q taken as 216 should make a great deal of the theory useful on a word-by-word basis.

5. Outboard Processing

When a function such as computing an involved checksum requires extensive processing, one solution is to put that processing into an outboard processor. In this way "encode message" and "decode message" become single instructions which do not tax the main host processor. The Digital Equipment Corporation VAX/780 computer is equipped with special hardware for generating and checking CRCs [13]. In general

[4] Bolt Beranek and Newman, Inc. "Specifications for the Interconnection of a Host and an IMP,"

Report 1822, January 1976 edition.

[5] Dean, Richard A., "Elements of Abstract Algebra," John Wyley and Sons, Inc., 1966

[6] Pemrson, W. Wesley, "Error Correcting Codes," M.I.T. Press Cambridge MA, 4th edition, 1968.

[7] Avizienis, Algirdas, "A Study of the Effectiveness of Fault-Detecting Codes for Binary Arith-

metic," Jet Propulsion Laboratory Technical Report No. 32-711, September 1, 1965.

[8] Kirstein, Peter, private communication

[9] Cerf, V. G. and Postel, Jonathan B., "Specification of Internetwork Transmission Control Program

Version 3," University of Southern California Information Sciences Institute, January 1978.

[10] Digital Equipment Corporation, "PDP-10 Reference Handbook," 1970, pp. 114-5.

[11] Swanson, Robert, "Understanding Cyclic Redundancy Codes," Computer Design, November, 1975,

pp. 93-99.

[12] Clements, Robert C., private communication.

[ 13] Conklin, Peter F., and Rodgers, David P., "Advanced Minicomputer Designed by Team Evaluation

of Hardware/Software Tradeoffs," Computer Design, April 1978, pp. 136-7.