Вы находитесь на странице: 1из 37

12/30/12

CRC Explained

A c q u i r e df r o m : f t p . a d e l a i d e . e d u . a u : / p u b / r o c k s o f t / c r c _ v 3 . t x t o rf t p : / / f t p . r o c k s o f t . c o m / p a p e r s / c r c _ v 3 . t x t o rh t t p : / / w w w . r e p a i r f a q . o r g / f i l i p g / L I N K / F _ c r c _ v 3 . h t m l

AP A I N L E S SG U I D ET OC R CE R R O RD E T E C T I O NA L G O R I T H M S = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " E v e r y t h i n gy o uw a n t e dt ok n o wa b o u tC R Ca l g o r i t h m s ,b u tw e r ea f r a i d t oa s kf o rf e a rt h a te r r o r si ny o u ru n d e r s t a n d i n gm i g h tb ed e t e c t e d . " V e r s i o n:3 . D a t e :1 9A u g u s t1 9 9 3 . A u t h o r :R o s sN .W i l l i a m s . N e t :r o s s @ g u e s t . a d e l a i d e . e d u . a u . F T P :f t p . a d e l a i d e . e d u . a u / p u b / r o c k s o f t / c r c _ v 3 . t x t C o m p a n y:R o c k s o f t ^ t mP t yL t d . S n a i l :1 6L e r w i c kA v e n u e ,H a z e l w o o dP a r k5 0 6 6 ,A u s t r a l i a . F a x :+ 6 183 7 3 4 9 1 1( c / -I n t e r n o d eS y s t e m sP t yL t d ) . P h o n e :+ 6 183 7 9 9 2 1 7( 1 0 a mt o1 0 p mA d e l a i d eA u s t r a l i at i m e ) . N o t e :" R o c k s o f t "i sat r a d e m a r ko fR o c k s o f tP t yL t d ,A u s t r a l i a . S t a t u s :C o p y r i g h t( C )R o s sW i l l i a m s ,1 9 9 3 .H o w e v e r ,p e r m i s s i o ni s g r a n t e dt om a k ea n dd i s t r i b u t ev e r b a t i mc o p i e so ft h i s d o c u m e n tp r o v i d e dt h a tt h i si n f o r m a t i o nb l o c ka n dc o p y r i g h t n o t i c ei si n c l u d e d .A l s o ,t h eCc o d em o d u l e si n c l u d e d i nt h i sd o c u m e n ta r ef u l l yp u b l i cd o m a i n . T h a n k s :T h a n k st oJ e a n l o u pG a i l l y( j l o u p @ c h o r u s . f r )a n dM a r kA d l e r ( m e @ q u e s t . j p l . n a s a . g o v )w h ob o t hp r o o fr e a dt h i sd o c u m e n t a n dp i c k e do u tl o t so fn i t sa sw e l la ss o m eb i gf a tb u g s . T a b l eo fC o n t e n t s A b s t r a c t 1 .I n t r o d u c t i o n :E r r o rD e t e c t i o n 2 .T h eN e e dF o rC o m p l e x i t y 3 .T h eB a s i cI d e aB e h i n dC R CA l g o r i t h m s 4 .P o l y n o m i c a lA r i t h m e t i c 5 .B i n a r yA r i t h m e t i cw i t hN oC a r r i e s 6 .AF u l l yW o r k e dE x a m p l e 7 .C h o o s i n gAP o l y 8 .AS t r a i g h t f o r w a r dC R CI m p l e m e n t a t i o n 9 .AT a b l e D r i v e nI m p l e m e n t a t i o n 1 0 .AS l i g h t l yM a n g l e dT a b l e D r i v e nI m p l e m e n t a t i o n 1 1 ." R e f l e c t e d "T a b l e D r i v e nI m p l e m e n t a t i o n s 1 2 ." R e v e r s e d "P o l y s 1 3 .I n i t i a la n dF i n a lV a l u e s 1 4 .D e f i n i n gA l g o r i t h m sA b s o l u t e l y 1 5 .AP a r a m e t e r i z e dM o d e lF o rC R CA l g o r i t h m s 1 6 .AC a t a l o go fP a r a m e t e rS e t sf o rS t a n d a r d s 1 7 .A nI m p l e m e n t a t i o no ft h eM o d e lA l g o r i t h m 1 8 .R o l lY o u rO w nT a b l e D r i v e nI m p l e m e n t a t i o n 1 9 .G e n e r a t i n gAL o o k u pT a b l e 2 0 .S u m m a r y 2 1 .C o r r e c t i o n s
www.csm.ornl.gov /~dunigan/crc.html 1/37

12/30/12

CRC Explained

A .G l o s s a r y B .R e f e r e n c e s C .R e f e r e n c e sIH a v eD e t e c t e dB u tH a v e n ' tY e tS i g h t e d

A b s t r a c t T h i sd o c u m e n te x p l a i n sC R C s( C y c l i cR e d u n d a n c yC o d e s )a n dt h e i r t a b l e d r i v e ni m p l e m e n t a t i o n si nf u l l ,p r e c i s ed e t a i l .M u c ho ft h e l i t e r a t u r eo nC R C s ,a n di np a r t i c u l a ro nt h e i rt a b l e d r i v e n i m p l e m e n t a t i o n s ,i sal i t t l eo b s c u r e( o ra tl e a s ts e e m ss ot om e ) . T h i sd o c u m e n ti sa na t t e m p tt op r o v i d eac l e a ra n ds i m p l en o n o n s e n s e e x p l a n a t i o no fC R C sa n dt oa b s o l u t e l yn a i ld o w ne v e r yd e t a i lo ft h e o p e r a t i o no ft h e i rh i g h s p e e di m p l e m e n t a t i o n s .I na d d i t i o nt ot h i s , t h i sd o c u m e n tp r e s e n t sap a r a m e t e r i z e dm o d e lC R Ca l g o r i t h mc a l l e dt h e " R o c k s o f t ^ t mM o d e lC R CA l g o r i t h m " .T h em o d e la l g o r i t h mc a nb e p a r a m e t e r i z e dt ob e h a v el i k em o s to ft h eC R Ci m p l e m e n t a t i o n sa r o u n d , a n ds oa c t sa sag o o dr e f e r e n c ef o rd e s c r i b i n gp a r t i c u l a ra l g o r i t h m s . Al o w s p e e di m p l e m e n t a t i o no ft h em o d e lC R Ca l g o r i t h mi sp r o v i d e di n t h eCp r o g r a m m i n gl a n g u a g e .L a s t l yt h e r ei sas e c t i o ng i v i n gt w of o r m s o fh i g h s p e e dt a b l ed r i v e ni m p l e m e n t a t i o n s ,a n dp r o v i d i n gap r o g r a m t h a tg e n e r a t e sC R Cl o o k u pt a b l e s .

1 .I n t r o d u c t i o n :E r r o rD e t e c t i o n T h ea i mo fa ne r r o rd e t e c t i o nt e c h n i q u ei st oe n a b l et h er e c e i v e ro fa m e s s a g et r a n s m i t t e dt h r o u g han o i s y( e r r o r i n t r o d u c i n g )c h a n n e lt o d e t e r m i n ew h e t h e rt h em e s s a g eh a sb e e nc o r r u p t e d .T od ot h i s ,t h e t r a n s m i t t e rc o n s t r u c t sav a l u e( c a l l e dac h e c k s u m )t h a ti saf u n c t i o n o ft h em e s s a g e ,a n da p p e n d si tt ot h em e s s a g e .T h er e c e i v e rc a nt h e n u s et h es a m ef u n c t i o nt oc a l c u l a t et h ec h e c k s u mo ft h er e c e i v e d m e s s a g ea n dc o m p a r ei tw i t ht h ea p p e n d e dc h e c k s u mt os e ei ft h e m e s s a g ew a sc o r r e c t l yr e c e i v e d .F o re x a m p l e ,i fw ec h o s eac h e c k s u m f u n c t i o nw h i c hw a ss i m p l yt h es u mo ft h eb y t e si nt h em e s s a g em o d2 5 6 ( i . e .m o d u l o2 5 6 ) ,t h e ni tm i g h tg os o m e t h i n ga sf o l l o w s .A l ln u m b e r s a r ei nd e c i m a l . M e s s a g e : 62 3 4 M e s s a g ew i t hc h e c k s u m : 62 3 43 3 M e s s a g ea f t e rt r a n s m i s s i o n: 62 7 43 3 I nt h ea b o v e ,t h es e c o n db y t eo ft h em e s s a g ew a sc o r r u p t e df r o m2 3t o 2 7b yt h ec o m m u n i c a t i o n sc h a n n e l .H o w e v e r ,t h er e c e i v e rc a nd e t e c t t h i sb yc o m p a r i n gt h et r a n s m i t t e dc h e c k s u m( 3 3 )w i t ht h ec o m p u t e r c h e c k s u mo f3 7( 6+2 7+4 ) .I ft h ec h e c k s u mi t s e l fi sc o r r u p t e d ,a c o r r e c t l yt r a n s m i t t e dm e s s a g em i g h tb ei n c o r r e c t l yi d e n t i f i e da sa c o r r u p t e do n e .H o w e v e r ,t h i si sas a f e s i d ef a i l u r e .Ad a n g e r o u s s i d e f a i l u r eo c c u r sw h e r et h em e s s a g ea n d / o rc h e c k s u mi sc o r r u p t e di na m a n n e rt h a tr e s u l t si nat r a n s m i s s i o nt h a ti si n t e r n a l l yc o n s i s t e n t . U n f o r t u n a t e l y ,t h i sp o s s i b i l i t yi sc o m p l e t e l yu n a v o i d a b l ea n dt h eb e s t t h a tc a nb ed o n ei st om i n i m i z ei t sp r o b a b i l i t yb yi n c r e a s i n gt h e a m o u n to fi n f o r m a t i o ni nt h ec h e c k s u m( e . g .w i d e n i n gt h ec h e c k s u mf r o m o n eb y t et ot w ob y t e s ) . O t h e re r r o rd e t e c t i o nt e c h n i q u e se x i s tt h a ti n v o l v ep e r f o r m i n gc o m p l e x t r a n s f o r m a t i o n so nt h em e s s a g et oi n j e c ti tw i t hr e d u n d a n t
www.csm.ornl.gov /~dunigan/crc.html 2/37

12/30/12

CRC Explained

i n f o r m a t i o n .H o w e v e r ,t h i sd o c u m e n ta d d r e s s e so n l yC R Ca l g o r i t h m s , w h i c hf a l li n t ot h ec l a s so fe r r o rd e t e c t i o na l g o r i t h m st h a tl e a v et h e d a t ai n t a c ta n da p p e n dac h e c k s u mo nt h ee n d .i . e . : < o r i g i n a li n t a c tm e s s a g e >< c h e c k s u m >

2 .T h eN e e dF o rC o m p l e x i t y I nt h ec h e c k s u me x a m p l ei nt h ep r e v i o u ss e c t i o n ,w es a wh o wa c o r r u p t e dm e s s a g ew a sd e t e c t e du s i n gac h e c k s u ma l g o r i t h mt h a ts i m p l y s u m st h eb y t e si nt h em e s s a g em o d2 5 6 : M e s s a g e : 62 3 4 M e s s a g ew i t hc h e c k s u m : 62 3 43 3 M e s s a g ea f t e rt r a n s m i s s i o n: 62 7 43 3 Ap r o b l e mw i t ht h i sa l g o r i t h mi st h a ti ti st o os i m p l e .I fan u m b e ro f r a n d o mc o r r u p t i o n so c c u r ,t h e r ei sa1i n2 5 6c h a n c et h a tt h e yw i l l n o tb ed e t e c t e d .F o re x a m p l e : M e s s a g e : 62 3 4 M e s s a g ew i t hc h e c k s u m : 62 3 43 3 M e s s a g ea f t e rt r a n s m i s s i o n: 82 0 53 3 T os t r e n g t h e nt h ec h e c k s u m ,w ec o u l dc h a n g ef r o ma n8 b i tr e g i s t e rt o a1 6 b i tr e g i s t e r( i . e .s u mt h eb y t e sm o d6 5 5 3 6i n s t e a do fm o d2 5 6 )s o a st oa p p a r e n t l yr e d u c et h ep r o b a b i l i t yo ff a i l u r ef r o m1 / 2 5 6t o 1 / 6 5 5 3 6 .W h i l eb a s i c a l l yag o o di d e a ,i tf a i l si nt h i sc a s eb e c a u s e t h ef o r m u l au s e di sn o ts u f f i c i e n t l y" r a n d o m " ;w i t has i m p l es u m m i n g f o r m u l a ,e a c hi n c o m i n gb y t ea f f e c t sr o u g h l yo n l yo n eb y t eo ft h e s u m m i n gr e g i s t e rn om a t t e rh o ww i d ei ti s .F o re x a m p l e ,i nt h es e c o n d e x a m p l ea b o v e ,t h es u m m i n gr e g i s t e rc o u l db eaM e g a b y t ew i d e ,a n dt h e e r r o rw o u l ds t i l lg ou n d e t e c t e d .T h i sp r o b l e mc a no n l yb es o l v e db y r e p l a c i n gt h es i m p l es u m m i n gf o r m u l aw i t ham o r es o p h i s t i c a t e df o r m u l a t h a tc a u s e se a c hi n c o m i n gb y t et oh a v ea ne f f e c to nt h ee n t i r e c h e c k s u mr e g i s t e r . T h u s ,w es e et h a ta tl e a s tt w oa s p e c t sa r er e q u i r e dt of o r mas t r o n g c h e c k s u mf u n c t i o n : W I D T H :Ar e g i s t e rw i d t hw i d ee n o u g ht op r o v i d eal o wa p r i o r i p r o b a b i l i t yo ff a i l u r e( e . g .3 2 b i t sg i v e sa1 / 2 ^ 3 2c h a n c e o ff a i l u r e ) . C H A O S :Af o r m u l at h a tg i v e se a c hi n p u tb y t et h ep o t e n t i a lt oc h a n g e a n yn u m b e ro fb i t si nt h er e g i s t e r . N o t e :T h et e r m" c h e c k s u m "w a sp r e s u m a b l yu s e dt od e s c r i b ee a r l y s u m m i n gf o r m u l a s ,b u th a sn o wt a k e no nam o r eg e n e r a lm e a n i n g e n c o m p a s s i n gm o r es o p h i s t i c a t e da l g o r i t h m ss u c ha st h eC R Co n e s .T h e C R Ca l g o r i t h m st ob ed e s c r i b e ds a t i s f yt h es e c o n dc o n d i t i o nv e r yw e l l , a n dc a nb ec o n f i g u r e dt oo p e r a t ew i t hav a r i e t yo fc h e c k s u mw i d t h s .

3 .T h eB a s i cI d e aB e h i n dC R CA l g o r i t h m s www.csm.ornl.gov /~dunigan/crc.html 3/37

12/30/12

CRC Explained

W h e r em i g h tw eg oi no u rs e a r c hf o ram o r ec o m p l e xf u n c t i o nt h a n s u m m i n g ?A l ls o r t so fs c h e m e ss p r i n gt om i n d .W ec o u l dc o n s t r u c t t a b l e su s i n gt h ed i g i t so fp i ,o rh a s he a c hi n c o m i n gb y t ew i t ha l lt h e b y t e si nt h er e g i s t e r .W ec o u l de v e nk e e pal a r g et e l e p h o n eb o o k o n l i n e ,a n du s ee a c hi n c o m i n gb y t ec o m b i n e dw i t ht h er e g i s t e rb y t e s t oi n d e xan e wp h o n en u m b e rw h i c hw o u l db et h en e x tr e g i s t e rv a l u e . T h ep o s s i b i l i t i e sa r el i m i t l e s s . H o w e v e r ,w ed on o tn e e dt og os of a r ;t h en e x ta r i t h m e t i cs t e p s u f f i c e s .W h i l ea d d i t i o ni sc l e a r l yn o ts t r o n ge n o u g ht of o r ma n e f f e c t i v ec h e c k s u m ,i tt u r n so u tt h a td i v i s i o ni s ,s ol o n ga st h e d i v i s o ri sa b o u ta sw i d ea st h ec h e c k s u mr e g i s t e r . T h eb a s i ci d e ao fC R Ca l g o r i t h m si ss i m p l yt ot r e a tt h em e s s a g ea sa n e n o r m o u sb i n a r yn u m b e r ,t od i v i d ei tb ya n o t h e rf i x e db i n a r yn u m b e r , a n dt om a k et h er e m a i n d e rf r o mt h i sd i v i s i o nt h ec h e c k s u m .U p o n r e c e i p to ft h em e s s a g e ,t h er e c e i v e rc a np e r f o r mt h es a m ed i v i s i o na n d c o m p a r et h er e m a i n d e rw i t ht h e" c h e c k s u m "( t r a n s m i t t e dr e m a i n d e r ) . E x a m p l e :S u p p o s et h et h em e s s a g ec o n s i s t e do ft h et w ob y t e s( 6 , 2 3 )a s i nt h ep r e v i o u se x a m p l e .T h e s ec a nb ec o n s i d e r e dt ob et h eh e x a d e c i m a l n u m b e r0 6 1 7w h i c hc a nb ec o n s i d e r e dt ob et h eb i n a r yn u m b e r 0 0 0 0 0 1 1 0 0 0 0 1 0 1 1 1 .S u p p o s et h a tw eu s eac h e c k s u mr e g i s t e ro n e b y t e w i d ea n du s eac o n s t a n td i v i s o ro f1 0 0 1 ,t h e nt h ec h e c k s u mi st h e r e m a i n d e ra f t e r0 0 0 0 0 1 1 0 0 0 0 1 0 1 1 1i sd i v i d e db y1 0 0 1 .W h i l ei nt h i s c a s e ,t h i sc a l c u l a t i o nc o u l do b v i o u s l yb ep e r f o r m e du s i n gc o m m o n g a r d e nv a r i e t y3 2 b i tr e g i s t e r s ,i nt h eg e n e r a lc a s et h i si sm e s s y .S o i n s t e a d ,w e ' l ld ot h ed i v i s i o nu s i n gg o o d ' o ll o n gd i v i s i o nw h i c hy o u l e a r n ti ns c h o o l( r e m e m b e r ? ) .E x c e p tt h i st i m e ,i t ' si nb i n a r y : . . . 0 0 0 0 0 1 0 1 0 1 1 0 1=0 0 A D= 1 7 3=Q U O T I E N T _ _ _ _ _ _ _ _ _ _ _ _ _ 9 =1 0 0 1)0 0 0 0 0 1 1 0 0 0 0 1 0 1 1 1=0 6 1 7=1 5 5 9=D I V I D E N D D I V I S O R 0 0 0 0 . , , . . . . , . , , , . , , . . . . , . , , , 0 0 0 0 , , . . . . , . , , , 0 0 0 0 , , . . . . , . , , , , , . . . . , . , , , 0 0 0 1 , . . . . , . , , , 0 0 0 0 , . . . . , . , , , , . . . . , . , , , 0 0 1 1 . . . . , . , , , 0 0 0 0 . . . . , . , , , . . . . , . , , , 0 1 1 0 . . . , . , , , 0 0 0 0 . . . , . , , , . . . , . , , , 1 1 0 0 . . , . , , , 1 0 0 1 . . , . , , , = = = = . . , . , , , 0 1 1 0 . , . , , , 0 0 0 0 . , . , , , . , . , , , 1 1 0 0 , . , , , 1 0 0 1 , . , , , = = = = , . , , , 0 1 1 1 . , , ,
www.csm.ornl.gov /~dunigan/crc.html

12/30/12

CRC Explained

0 0 0 0 . , , , . , , , 1 1 1 0 , , , 1 0 0 1 , , , = = = = , , , 1 0 1 1 , , 1 0 0 1 , , = = = = , , 0 1 0 1 , 0 0 0 0 , 1 0 1 1 1 0 0 1 = = = = 0 0 1 0=0 2=2=R E M A I N D E R

I nd e c i m a lt h i si s" 1 5 5 9d i v i d e db y9i s1 7 3w i t har e m a i n d e ro f2 " . A l t h o u g ht h ee f f e c to fe a c hb i to ft h ei n p u tm e s s a g eo nt h eq u o t i e n t i sn o ta l lt h a ts i g n i f i c a n t ,t h e4 b i tr e m a i n d e rg e t sk i c k e da b o u t q u i t eal o td u r i n gt h ec a l c u l a t i o n ,a n di fm o r eb y t e sw e r ea d d e dt o t h em e s s a g e( d i v i d e n d )i t ' sv a l u ec o u l dc h a n g er a d i c a l l ya g a i nv e r y q u i c k l y .T h i si sw h yd i v i s i o nw o r k sw h e r ea d d i t i o nd o e s n ' t . I nc a s ey o u ' r ew o n d e r i n g ,u s i n gt h i s4 b i tc h e c k s u mt h et r a n s m i t t e d m e s s a g ew o u l dl o o kl i k et h i s( i nh e x a d e c i m a l ) :0 6 1 7 2( w h e r et h e0 6 1 7 i st h em e s s a g ea n dt h e2i st h ec h e c k s u m ) .T h er e c e i v e rw o u l dd i v i d e 0 6 1 7b y9a n ds e ew h e t h e rt h er e m a i n d e rw a s2 .

4 .P o l y n o m i c a lA r i t h m e t i c W h i l et h ed i v i s i o ns c h e m ed e s c r i b e di nt h ep r e v i o u ss e c t i o ni sv e r y v e r ys i m i l a rt ot h ec h e c k s u m m i n gs c h e m e sc a l l e dC R Cs c h e m e s ,t h eC R C s c h e m e sa r ei nf a c tab i tw e i r d e r ,a n dw en e e dt od e l v ei n t os o m e s t r a n g en u m b e rs y s t e m st ou n d e r s t a n dt h e m . T h ew o r dy o uw i l lh e a ra l lt h et i m ew h e nd e a l i n gw i t hC R Ca l g o r i t h m s i st h ew o r d" p o l y n o m i a l " .Ag i v e nC R Ca l g o r i t h mw i l lb es a i dt ob e u s i n gap a r t i c u l a rp o l y n o m i a l ,a n dC R Ca l g o r i t h m si ng e n e r a la r es a i d t ob eo p e r a t i n gu s i n gp o l y n o m i a la r i t h m e t i c .W h a td o e st h i sm e a n ? I n s t e a do ft h ed i v i s o r ,d i v i d e n d( m e s s a g e ) ,q u o t i e n t ,a n dr e m a i n d e r ( a sd e s c r i b e di nt h ep r e v i o u ss e c t i o n )b e i n gv i e w e da sp o s i t i v e i n t e g e r s ,t h e ya r ev i e w e da sp o l y n o m i a l sw i t hb i n a r yc o e f f i c i e n t s . T h i si sd o n eb yt r e a t i n ge a c hn u m b e ra sab i t s t r i n gw h o s eb i t sa r e t h ec o e f f i c i e n t so fap o l y n o m i a l .F o re x a m p l e ,t h eo r d i n a r yn u m b e r2 3 ( d e c i m a l )i s1 7( h e x )a n d1 0 1 1 1b i n a r ya n ds oi tc o r r e s p o n d st ot h e p o l y n o m i a l : 1 * x ^ 4+0 * x ^ 3+1 * x ^ 2+1 * x ^ 1+1 * x ^ 0 o r ,m o r es i m p l y : x ^ 4+x ^ 2+x ^ 1+x ^ 0
www.csm.ornl.gov /~dunigan/crc.html 5/37

12/30/12

CRC Explained

U s i n gt h i st e c h n i q u e ,t h em e s s a g e ,a n dt h ed i v i s o rc a nb er e p r e s e n t e d a sp o l y n o m i a l sa n dw ec a nd oa l lo u ra r i t h m e t i cj u s ta sb e f o r e ,e x c e p t t h a tn o wi t ' sa l lc l u t t e r e du pw i t hX s .F o re x a m p l e ,s u p p o s ew ew a n t e d t om u l t i p l y1 1 0 1b y1 0 1 1 .W ec a nd ot h i ss i m p l yb ym u l t i p l y i n gt h e p o l y n o m i a l s : ( x ^ 3+x ^ 2+x ^ 0 ) ( x ^ 3+x ^ 1+x ^ 0 ) =( x ^ 6+x ^ 4+x ^ 3 +x ^ 5+x ^ 3+x ^ 2 +x ^ 3+x ^ 1+x ^ 0 )=x ^ 6+x ^ 5+x ^ 4+3 * x ^ 3+x ^ 2+x ^ 1+x ^ 0 A tt h i sp o i n t ,t og e tt h er i g h ta n s w e r ,w eh a v et op r e t e n dt h a txi s2 a n dp r o p a g a t eb i n a r yc a r r i e sf r o mt h e3 * x ^ 3y i e l d i n g x ^ 7+x ^ 3+x ^ 2+x ^ 1+x ^ 0 I t ' sj u s tl i k eo r d i n a r ya r i t h m e t i ce x c e p tt h a tt h eb a s ei sa b s t r a c t e d a n db r o u g h ti n t oa l lt h ec a l c u l a t i o n se x p l i c i t l yi n s t e a do fb e i n g t h e r ei m p l i c i t l y .S ow h a t ' st h ep o i n t ? T h ep o i n ti st h a tI Fw ep r e t e n dt h a tw eD O N ' Tk n o ww h a txi s ,w eC A N ' T p e r f o r mt h ec a r r i e s .W ed o n ' tk n o wt h a t3 * x ^ 3i st h es a m ea sx ^ 4+x ^ 3 b e c a u s ew ed o n ' tk n o wt h a txi s2 .I nt h i st r u ep o l y n o m i a la r i t h m e t i c t h er e l a t i o n s h i pb e t w e e na l lt h ec o e f f i c i e n t si su n k n o w na n ds ot h e c o e f f i c i e n t so fe a c hp o w e re f f e c t i v e l yb e c o m es t r o n g l yt y p e d ; c o e f f i c i e n t so fx ^ 2a r ee f f e c t i v e l yo fad i f f e r e n tt y p et o c o e f f i c i e n t so fx ^ 3 . W i t ht h ec o e f f i c i e n t so fe a c hp o w e rn i c e l yi s o l a t e d ,m a t h e m a t i c i a n s c a m eu pw i t ha l ls o r t so fd i f f e r e n tk i n d so fp o l y n o m i a la r i t h m e t i c s s i m p l yb yc h a n g i n gt h er u l e sa b o u th o wc o e f f i c i e n t sw o r k .O ft h e s e s c h e m e s ,o n ei np a r t i c u l a ri sr e l e v a n th e r e ,a n dt h a ti sap o l y n o m i a l a r i t h m e t i cw h e r et h ec o e f f i c i e n t sa r ec a l c u l a t e dM O D2a n dt h e r ei sn o c a r r y ;a l lc o e f f i c i e n t sm u s tb ee i t h e r0o r1a n dn oc a r r i e sa r e c a l c u l a t e d .T h i si sc a l l e d" p o l y n o m i a la r i t h m e t i cm o d2 " .T h u s , r e t u r n i n gt ot h ee a r l i e re x a m p l e : ( x ^ 3+x ^ 2+x ^ 0 ) ( x ^ 3+x ^ 1+x ^ 0 ) =( x ^ 6+x ^ 4+x ^ 3 +x ^ 5+x ^ 3+x ^ 2 +x ^ 3+x ^ 1+x ^ 0 ) =x ^ 6+x ^ 5+x ^ 4+3 * x ^ 3+x ^ 2+x ^ 1+x ^ 0 U n d e rt h eo t h e ra r i t h m e t i c ,t h e3 * x ^ 3t e r mw a sp r o p a g a t e du s i n gt h e c a r r ym e c h a n i s mu s i n gt h ek n o w l e d g et h a tx = 2 .U n d e r" p o l y n o m i a l a r i t h m e t i cm o d2 " ,w ed o n ' tk n o ww h a txi s ,t h e r ea r en oc a r r i e s ,a n d a l lc o e f f i c i e n t sh a v et ob ec a l c u l a t e dm o d2 .T h u s ,t h er e s u l t b e c o m e s : =x ^ 6+x ^ 5+x ^ 4+x ^ 3+x ^ 2+x ^ 1+x ^ 0 A sK n u t h[ K n u t h 8 1 ]s a y s( p . 4 0 0 ) : " T h er e a d e rs h o u l dn o t et h es i m i l a r i t yb e t w e e np o l y n o m i a l a r i t h m e t i ca n dm u l t i p l e p r e c i s i o na r i t h m e t i c( S e c t i o n4 . 3 . 1 ) ,w h e r e t h er a d i xbi ss u b s t i t u t e df o rx .T h ec h i e fd i f f e r e n c ei st h a tt h e c o e f f i c i e n tu _ ko fx ^ ki np o l y n o m i a la r i t h m e t i cb e a r sl i t t l eo rn o
www.csm.ornl.gov /~dunigan/crc.html 6/37

12/30/12

CRC Explained

r e l a t i o nt oi t sn e i g h b o r i n gc o e f f i c i e n t sx ^ { k 1 }[ a n dx ^ { k + 1 } ] ,s o t h ei d e ao f" c a r r y i n g "f r o mo n ep l a c et oa n o t h e ri sa b s e n t .I nf a c t p o l y n o m i a la r i t h m e t i cm o d u l obi se s s e n t i a l l yi d e n t i c a lt om u l t i p l e p r e c i s i o na r i t h m e t i cw i t hr a d i xb ,e x c e p tt h a ta l lc a r r i e sa r e s u p p r e s s e d . " T h u sp o l y n o m i c a la r i t h m e t i cm o d2i sj u s tb i n a r ya r i t h m e t i cm o d2w i t h n oc a r r i e s .W h i l ep o l y n o m i a l sp r o v i d eu s e f u lm a t h e m a t i c a lm a c h i n e r yi n m o r ea n a l y t i c a la p p r o a c h e st oC R Ca n de r r o r c o r r e c t i o na l g o r i t h m s ,f o r t h ep u r p o s e so fe x p o s i t i o nt h e yp r o v i d en oe x t r ai n s i g h ta n ds o m e e n c u m b r a n c ea n dh a v eb e e nd i s c a r d e di nt h er e m a i n d e ro ft h i sd o c u m e n t i nf a v o u ro fd i r e c tm a n i p u l a t i o no ft h ea r i t h m e t i c a ls y s t e mw i t hw h i c h t h e ya r ei s o m o r p h i c :b i n a r ya r i t h m e t i cw i t hn oc a r r y .

5 .B i n a r yA r i t h m e t i cw i t hN oC a r r i e s H a v i n gd i s p e n s e dw i t hp o l y n o m i a l s ,w ec a nf o c u so nt h er e a la r i t h m e t i c i s s u e ,w h i c hi st h a ta l lt h ea r i t h m e t i cp e r f o r m e dd u r i n gC R C c a l c u l a t i o n si sp e r f o r m e di nb i n a r yw i t hn oc a r r i e s .O f t e nt h i si s c a l l e dp o l y n o m i a la r i t h m e t i c ,b u ta sIh a v ed e c l a r e dt h er e s to ft h i s d o c u m e n tap o l y n o m i a lf r e ez o n e ,w e ' l lh a v et oc a l li tC R Ca r i t h m e t i c i n s t e a d .A st h i sa r i t h m e t i ci sak e yp a r to fC R Cc a l c u l a t i o n s ,w e ' d b e t t e rg e tu s e dt oi t .H e r ew eg o : A d d i n gt w on u m b e r si nC R Ca r i t h m e t i ci st h es a m ea sa d d i n gn u m b e r si n o r d i n a r yb i n a r ya r i t h m e t i ce x c e p tt h e r ei sn oc a r r y .T h i sm e a n st h a t e a c hp a i ro fc o r r e s p o n d i n gb i t sd e t e r m i n et h ec o r r e s p o n d i n go u t p u tb i t w i t h o u tr e f e r e n c et oa n yo t h e rb i tp o s i t i o n s .F o re x a m p l e : 1 0 0 1 1 0 1 1 + 1 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 T h e r ea r eo n l yf o u rc a s e sf o re a c hb i tp o s i t i o n : 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 ( n oc a r r y ) S u b t r a c t i o ni si d e n t i c a l : 1 0 0 1 1 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 w i t h 0 0 = 0 0 1 = 1 ( w r a p a r o u n d ) 1 0 = 1 1 1 = 0


www.csm.ornl.gov /~dunigan/crc.html 7/37

12/30/12

CRC Explained

I nf a c t ,b o t ha d d i t i o na n ds u b t r a c t i o ni nC R Ca r i t h m e t i ci se q u i v a l e n t t ot h eX O Ro p e r a t i o n ,a n dt h eX O Ro p e r a t i o ni si t so w ni n v e r s e .T h i s e f f e c t i v e l yr e d u c e st h eo p e r a t i o n so ft h ef i r s tl e v e lo fp o w e r ( a d d i t i o n ,s u b t r a c t i o n )t oas i n g l eo p e r a t i o nt h a ti si t so w ni n v e r s e . T h i si sav e r yc o n v e n i e n tp r o p e r t yo ft h ea r i t h m e t i c . B yc o l l a p s i n go fa d d i t i o na n ds u b t r a c t i o n ,t h ea r i t h m e t i cd i s c a r d sa n y n o t i o no fm a g n i t u d eb e y o n dt h ep o w e ro fi t sh i g h e s to n eb i t .W h i l ei t s e e m sc l e a rt h a t1 0 1 0i sg r e a t e rt h a n1 0 ,i ti sn ol o n g e rt h ec a s e t h a t1 0 1 0c a nb ec o n s i d e r e dt ob eg r e a t e rt h a n1 0 0 1 .T os e et h i s ,n o t e t h a ty o uc a ng e tf r o m1 0 1 0t o1 0 0 1b yb o t ha d d i n ga n ds u b t r a c t i n gt h e s a m eq u a n t i t y : 1 0 1 0=1 0 1 0+0 0 1 1 1 0 1 0=1 0 1 0-0 0 1 1 T h i sm a k e sn o n s e n s eo fa n yn o t i o no fo r d e r . H a v i n gd e f i n e da d d i t i o n ,w ec a nm o v et om u l t i p l i c a t i o na n dd i v i s i o n . M u l t i p l i c a t i o ni sa b s o l u t e l ys t r a i g h t f o r w a r d ,b e i n gt h es u mo ft h e f i r s tn u m b e r ,s h i f t e di na c c o r d a n c ew i t ht h es e c o n dn u m b e r . 1 1 0 1 x1 0 1 1 1 1 0 1 1 1 0 1 . 0 0 0 0 . . 1 1 0 1 . . . 1 1 1 1 1 1 1 N o t e :T h es u mu s e sC R Ca d d i t i o n D i v i s i o ni sal i t t l em e s s i e ra sw en e e dt ok n o ww h e n" an u m b e rg o e s i n t oa n o t h e rn u m b e r " .T od ot h i s ,w ei n v o k et h ew e a kd e f i n i t i o no f m a g n i t u d ed e f i n e de a r l i e r :t h a tXi sg r e a t e rt h a no re q u a lt oYi f f t h ep o s i t i o no ft h eh i g h e s t1b i to fXi st h es a m eo rg r e a t e rt h a nt h e p o s i t i o no ft h eh i g h e s t1b i to fY .H e r e ' saf u l l yw o r k e dd i v i s i o n ( n i c k e df r o m[ T a n e n b a u m 8 1 ] ) . 1 1 0 0 0 0 1 0 1 0 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1 0 0 1 1)1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 1 , , . , , . . . . , , . , , . . . . 1 0 0 1 1 , . , , . . . . 1 0 0 1 1 , . , , . . . . , . , , . . . . 0 0 0 0 1 . , , . . . . 0 0 0 0 0 . , , . . . . . , , . . . . 0 0 0 1 0 , , . . . . 0 0 0 0 0 , , . . . . , , . . . . 0 0 1 0 1 , . . . . 0 0 0 0 0 , . . . .
www.csm.ornl.gov /~dunigan/crc.html 8/37

12/30/12

CRC Explained

, . . . . 0 1 0 1 1 . . . . 0 0 0 0 0 . . . . . . . . 1 0 1 1 0 . . . 1 0 0 1 1 . . . . . . 0 1 0 1 0 . . 0 0 0 0 0 . . . . 1 0 1 0 0 . 1 0 0 1 1 . . 0 1 1 1 0 0 0 0 0 0 1 1 1 0=R e m a i n d e r T h a t ' sr e a l l yi t .B e f o r ep r o c e e d i n gf u r t h e r ,h o w e v e r ,i t ' sw o r t ho u r w h i l ep l a y i n gw i t ht h i sa r i t h m e t i cab i tt og e tu s e dt oi t . W e ' v ea l r e a d yp l a y e dw i t ha d d i t i o na n ds u b t r a c t i o n ,n o t i c i n gt h a tt h e y a r et h es a m et h i n g .H e r e ,t h o u g h ,w es h o u l dn o t et h a ti nt h i s a r i t h m e t i cA + 0 = Aa n dA 0 = A .T h i so b v i o u sp r o p e r t yi sv e r yu s e f u l l a t e r . I nd e a l i n gw i t hC R Cm u l t i p l i c a t i o na n dd i v i s i o n ,i t ' sw o r t hg e t t i n ga f e e lf o rt h ec o n c e p t so fM U L T I P L Ea n dD I V I S I B L E . I fan u m b e rAi sam u l t i p l eo fBt h e nw h a tt h i sm e a n si nC R C a r i t h m e t i ci st h a ti ti sp o s s i b l et oc o n s t r u c tAf r o mz e r ob yX O R i n g i nv a r i o u ss h i f t so fB .F o re x a m p l e ,i fAw a s0 1 1 1 0 1 0 1 1 0a n dBw a s1 1 , w ec o u l dc o n s t r u c tAf r o mBa sf o l l o w s : 0 1 1 1 0 1 0 1 1 0 =. . . . . . . 1 1 . +. . . . 1 1 . . . . +. . . 1 1 . . . . . . 1 1 . . . . . . . H o w e v e r ,i fAi s0 1 1 1 0 1 0 1 1 1 ,i ti sn o tp o s s i b l et oc o n s t r u c ti to u to f v a r i o u ss h i f t so fB( c a ny o us e ew h y ?-s e el a t e r )s oi ti ss a i dt ob e n o td i v i s i b l eb yBi nC R Ca r i t h m e t i c . T h u sw es e et h a tC R Ca r i t h m e t i ci sp r i m a r i l ya b o u tX O R i n gp a r t i c u l a r v a l u e sa tv a r i o u ss h i f t i n go f f s e t s .

6 .AF u l l yW o r k e dE x a m p l e H a v i n gd e f i n e dC R Ca r i t h m e t i c ,w ec a nn o wf r a m eaC R Cc a l c u l a t i o na s s i m p l yad i v i s i o n ,b e c a u s et h a t ' sa l li ti s !T h i ss e c t i o nf i l l si nt h e d e t a i l sa n dg i v e sa ne x a m p l e . T op e r f o r maC R Cc a l c u l a t i o n ,w en e e dt oc h o o s ead i v i s o r .I nm a t h s m a r k e t i n gs p e a kt h ed i v i s o ri sc a l l e dt h e" g e n e r a t o rp o l y n o m i a l "o r s i m p l yt h e" p o l y n o m i a l " ,a n di sak e yp a r a m e t e ro fa n yC R Ca l g o r i t h m .
www.csm.ornl.gov /~dunigan/crc.html

12/30/12

CRC Explained

I tw o u l dp r o b a b l yb em o r ef r i e n d l yt oc a l lt h ed i v i s o rs o m e t h i n ge l s e , b u tt h ep o l yt a l ki ss od e e p l yi n g r a i n e di nt h ef i e l dt h a ti tw o u l d n o wb ec o n f u s i n gt oa v o i di t .A sac o m p r o m i s e ,w ew i l lr e f e rt ot h e C R Cp o l y n o m i a la st h e" p o l y " .J u s tt h i n ko ft h i sn u m b e ra sas o r to f p a r r o t ." H e l l op o l y ! " Y o uc a nc h o o s ea n yp o l ya n dc o m eu pw i t haC R Ca l g o r i t h m .H o w e v e r , s o m ep o l y sa r eb e t t e rt h a no t h e r s ,a n ds oi ti sw i s et os t i c kw i t ht h e t r i e da nt e s t e do n e s .Al a t e rs e c t i o na d d r e s s e st h i si s s u e . T h ew i d t h( p o s i t i o no ft h eh i g h e s t1b i t )o ft h ep o l yi sv e r y i m p o r t a n ta si td o m i n a t e st h ew h o l ec a l c u l a t i o n .T y p i c a l l y ,w i d t h so f 1 6o r3 2a r ec h o s e ns oa st os i m p l i f yi m p l e m e n t a t i o no nm o d e r n c o m p u t e r s .T h ew i d t ho fap o l yi st h ea c t u a lb i tp o s i t i o no ft h e h i g h e s tb i t .F o re x a m p l e ,t h ew i d t ho f1 0 0 1 1i s4 ,n o t5 .F o rt h e p u r p o s e so fe x a m p l e ,w ew i l lc h o s eap o l yo f1 0 0 1 1( o fw i d t hWo f4 ) . H a v i n gc h o s e nap o l y ,w ec a np r o c e e dw i t ht h ec a l c u l a t i o n .T h i si s s i m p l yad i v i s i o n( i nC R Ca r i t h m e t i c )o ft h em e s s a g eb yt h ep o l y .T h e o n l yt r i c ki st h a tWz e r ob i t sa r ea p p e n d e dt ot h em e s s a g eb e f o r et h e C R Ci sc a l c u l a t e d .T h u sw eh a v e : O r i g i n a lm e s s a g e :1 1 0 1 0 1 1 0 1 1 P o l y : 1 0 0 1 1 M e s s a g ea f t e ra p p e n d i n gWz e r o s:1 1 0 1 0 1 1 0 1 1 0 0 0 0 N o ww es i m p l yd i v i d et h ea u g m e n t e dm e s s a g eb yt h ep o l yu s i n gC R C a r i t h m e t i c .T h i si st h es a m ed i v i s i o na sb e f o r e : 1 1 0 0 0 0 1 0 1 0=Q u o t i e n t( n o b o d yc a r e sa b o u tt h eq u o t i e n t ) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1 0 0 1 1)1 1 0 1 0 1 1 0 1 1 0 0 0 0=A u g m e n t e dm e s s a g e( 1 1 0 1 0 1 1 0 1 1+0 0 0 0 ) = P o l y 1 0 0 1 1 , , . , , . . . . , , . , , . . . . 1 0 0 1 1 , . , , . . . . 1 0 0 1 1 , . , , . . . . , . , , . . . . 0 0 0 0 1 . , , . . . . 0 0 0 0 0 . , , . . . . . , , . . . . 0 0 0 1 0 , , . . . . 0 0 0 0 0 , , . . . . , , . . . . 0 0 1 0 1 , . . . . 0 0 0 0 0 , . . . . , . . . . 0 1 0 1 1 . . . . 0 0 0 0 0 . . . . . . . . 1 0 1 1 0 . . . 1 0 0 1 1 . . . . . . 0 1 0 1 0 . . 0 0 0 0 0 . . . . 1 0 1 0 0 . 1 0 0 1 1 .
www.csm.ornl.gov /~dunigan/crc.html 10/37

12/30/12

CRC Explained

. 0 1 1 1 0 0 0 0 0 0 1 1 1 0=R e m a i n d e r=T H EC H E C K S U M ! ! ! ! T h ed i v i s i o ny i e l d saq u o t i e n t ,w h i c hw et h r o wa w a y ,a n dar e m a i n d e r , w h i c hi st h ec a l c u l a t e dc h e c k s u m .T h i se n d st h ec a l c u l a t i o n . U s u a l l y ,t h ec h e c k s u mi st h e na p p e n d e dt ot h em e s s a g ea n dt h er e s u l t t r a n s m i t t e d .I nt h i sc a s et h et r a n s m i s s i o nw o u l db e :1 1 0 1 0 1 1 0 1 1 1 1 1 0 . A tt h eo t h e re n d ,t h er e c e i v e rc a nd oo n eo ft w ot h i n g s : a .S e p a r a t et h em e s s a g ea n dc h e c k s u m .C a l c u l a t et h ec h e c k s u mf o r t h em e s s a g e( a f t e ra p p e n d i n gWz e r o s )a n dc o m p a r et h et w o c h e c k s u m s . b .C h e c k s u mt h ew h o l el o t( w i t h o u ta p p e n d i n gz e r o s )a n ds e ei fi t c o m e so u ta sz e r o ! T h e s et w oo p t i o n sa r ee q u i v a l e n t .H o w e v e r ,i nt h en e x ts e c t i o n ,w e w i l lb ea s s u m i n go p t i o nbb e c a u s ei ti sm a r g i n a l l ym a t h e m a t i c a l l y c l e a n e r . As u m m a r yo ft h eo p e r a t i o no ft h ec l a s so fC R Ca l g o r i t h m s : 1 .C h o o s eaw i d t hW ,a n dap o l yG( o fw i d t hW ) . 2 .A p p e n dWz e r ob i t st ot h em e s s a g e .C a l lt h i sM ' . 3 .D i v i d eM 'b yGu s i n gC R Ca r i t h m e t i c .T h er e m a i n d e ri st h ec h e c k s u m . T h a t ' sa l lt h e r ei st oi t . 7 .C h o o s i n gAP o l y C h o o s i n gap o l yi ss o m e w h a to fab l a c ka r ta n dt h er e a d e ri sr e f e r r e d t o[ T a n e n b a u m 8 1 ]( p . 1 3 0 1 3 2 )w h i c hh a sav e r yc l e a rd i s c u s s i o no ft h i s i s s u e .T h i ss e c t i o nm e r e l ya i m st op u tt h ef e a ro fd e a t hi n t oa n y o n e w h os om u c ha st o y sw i t ht h ei d e ao fm a k i n gu pt h e i ro w np o l y .I fy o u d o n ' tc a r ea b o u tw h yo n ep o l ym i g h tb eb e t t e rt h a na n o t h e ra n dj u s t w a n tt of i n do u ta b o u th i g h s p e e di m p l e m e n t a t i o n s ,c h o o s eo n eo ft h e a r i t h m e t i c a l l ys o u n dp o l y sl i s t e da tt h ee n do ft h i ss e c t i o na n ds k i p t ot h en e x ts e c t i o n . F i r s tn o t et h a tt h et r a n s m i t t e dm e s s a g eTi sam u l t i p l eo ft h ep o l y . T os e et h i s ,n o t et h a t1 )t h el a s tWb i t so fTi st h er e m a i n d e ra f t e r d i v i d i n gt h ea u g m e n t e d( b yz e r o sr e m e m b e r )m e s s a g eb yt h ep o l y ,a n d2 ) a d d i t i o ni st h es a m ea ss u b t r a c t i o ns oa d d i n gt h er e m a i n d e rp u s h e st h e v a l u eu pt ot h en e x tm u l t i p l e .N o wn o t et h a ti ft h et r a n s m i t t e d m e s s a g ei sc o r r u p t e di nt r a n s m i s s i o nt h a tw ew i l lr e c e i v eT + Ew h e r eE i sa ne r r o rv e c t o r( a n d+i sC R Ca d d i t i o n( i . e .X O R ) ) .U p o nr e c e i p to f t h i sm e s s a g e ,t h er e c e i v e rd i v i d e sT + Eb yG .A sTm o dGi s0 ,( T + E ) m o dG=Em o dG .T h u s ,t h ec a p a c i t yo ft h ep o l yw ec h o o s et oc a t c h p a r t i c u l a rk i n d so fe r r o r sw i l lb ed e t e r m i n e db yt h es e to fm u l t i p l e s o fG ,f o ra n yc o r r u p t i o nEt h a ti sam u l t i p l eo fGw i l lb eu n d e t e c t e d . O u rt a s kt h e ni st of i n dc l a s s e so fGw h o s em u l t i p l e sl o o ka sl i t t l e l i k et h ek i n do fl i n en o i s e( t h a tw i l lb ec r e a t i n gt h ec o r r u p t i o n s )a s
www.csm.ornl.gov /~dunigan/crc.html 11/37

p o s s i b l e .S ol e t ' se x a m i n et h ek i n d so fl i n en o i s ew ec a ne x p e c t . S I N G L EB I TE R R O R S :As i n g l eb i te r r o rm e a n sE = 1 0 0 0 . . . 0 0 0 0 .W ec a n e n s u r et h a tt h i sc l a s so fe r r o ri sa l w a y sd e t e c t e db ym a k i n gs u r et h a t Gh a sa tl e a s tt w ob i t ss e tt o1 .A n ym u l t i p l eo fGw i l lb e c o n s t r u c t e du s i n gs h i f t i n ga n da d d i n ga n di ti si m p o s s i b l et o c o n s t r u c tav a l u ew i t has i n g l eb i tb ys h i f t i n ga na d d i n gas i n g l e v a l u ew i t hm o r et h a no n eb i ts e t ,a st h et w oe n db i t sw i l la l w a y s p e r s i s t . T W O B I TE R R O R S :T od e t e c ta l le r r o r so ft h ef o r m1 0 0 . . . 0 0 0 1 0 0 . . . 0 0 0 ( i . e .Ec o n t a i n st w o1b i t s )c h o o s eaGt h a td o e sn o th a v em u l t i p l e s t h a ta r e1 1 ,1 0 1 ,1 0 0 1 ,1 0 0 0 1 ,1 0 0 0 0 1 ,e t c .I ti sn o tc l e a rt om eh o w o n eg o e sa b o u td o i n gt h i s( Id o n ' th a v et h ep u r em a t h sb a c k g r o u n d ) , b u tT a n e n b a u ma s s u r e su st h a ts u c hGd oe x i s t ,a n dc i t e sGw i t h1b i t s ( 1 5 , 1 4 , 1 )t u r n e do na sa ne x a m p l eo fo n eGt h a tw o n ' td i v i d ea n y t h i n g l e s st h a n1 . . . 1w h e r e. . .i s3 2 7 6 7z e r o s . E R R O R SW I T HA NO D DN U M B E RO FB I T S :W ec a nc a t c ha l lc o r r u p t i o n sw h e r e Eh a sa no d dn u m b e ro fb i t sb yc h o o s i n gaGt h a th a sa ne v e nn u m b e ro f b i t s .T os e et h i s ,n o t et h a t1 )C R Cm u l t i p l i c a t i o ni ss i m p l yX O R i n ga c o n s t a n tv a l u ei n t oar e g i s t e ra tv a r i o u so f f s e t s ,2 )X O R i n gi ss i m p l y ab i t f l i po p e r a t i o n ,a n d3 )i fy o uX O Rav a l u ew i t ha ne v e nn u m b e ro f b i t si n t oar e g i s t e r ,t h eo d d n e s so ft h en u m b e ro f1b i t si nt h e r e g i s t e rr e m a i n si n v a r i a n t .E x a m p l e :S t a r t i n gw i t hE = 1 1 1 ,a t t e m p tt o f l i pa l lt h r e eb i t st oz e r ob yt h er e p e a t e da p p l i c a t i o no fX O R i n gi n 1 1a to n eo ft h et w oo f f s e t s( i . e ." E = EX O R0 1 1 "a n d" E = EX O R1 1 0 " ) T h i si sn e a r l yi s o m o r p h i ct ot h e" g l a s st u m b l e r s "p a r t yp u z z l ew h e r e y o uc h a l l e n g es o m e o n et of l i pt h r e et u m b l e r sb yt h er e p e a t e d a p p l i c a t i o no ft h eo p e r a t i o no ff l i p p i n ga n yt w o .M o s to ft h ep o p u l a r C R Cp o l y sc o n t a i na ne v e nn u m b e ro f1b i t s .( N o t e :T a n e n b a u ms t a t e s m o r es p e c i f i c a l l yt h a ta l le r r o r sw i t ha no d dn u m b e ro fb i t sc a nb e c a u g h tb ym a k i n gGam u l t i p l eo f1 1 ) . B U R S TE R R O R S :Ab u r s te r r o rl o o k sl i k eE = 0 0 0 . . . 0 0 0 1 1 1 . . . 1 1 1 1 0 0 0 0 . . . 0 0 . T h a ti s ,Ec o n s i s t so fa l lz e r o se x c e p tf o rar u no f1 ss o m e w h e r e i n s i d e .T h i sc a nb er e c a s ta sE = ( 1 0 0 0 0 . . . 0 0 ) ( 1 1 1 1 1 1 1 . . . 1 1 1 )w h e r e t h e r ea r ezz e r o si nt h eL E F Tp a r ta n dno n e si nt h eR I G H Tp a r t .T o c a t c he r r o r so ft h i sk i n d ,w es i m p l ys e tt h el o w e s tb i to fGt o1 . D o i n gt h i se n s u r e st h a tL E F Tc a n n o tb eaf a c t o ro fG .T h e n ,s ol o n ga s Gi sw i d e rt h a nR I G H T ,t h ee r r o rw i l lb ed e t e c t e d .S e eT a n e n b a u mf o ra c l e a r e re x p l a n a t i o no ft h i s ;I ' mal i t t l ef u z z yo nt h i so n e .N o t e : T a n e n b a u ma s s e r t st h a tt h ep r o b a b i l i t yo fab u r s to fl e n g t hg r e a t e r t h a nWg e t t i n gt h r o u g hi s( 0 . 5 ) ^ W . T h a tc o n c l u d e st h es e c t i o no nt h ef i n ea r to fs e l e c t i n gp o l y s . S o m ep o p u l a rp o l y sa r e : 1 6b i t s :( 1 6 , 1 2 , 5 , 0 ) ( 1 6 , 1 5 , 2 , 0 ) 3 2b i t s :( 3 2 , 2 6 , 2 3 , 2 2 , 1 6 , 1 2 , 1 1 , 1 0 , 8 , 7 , 5 , 4 , 2 , 1 , 0 )

[ X 2 5s t a n d a r d ] [ " C R C 1 6 " ] [ E t h e r n e t ]

8 .AS t r a i g h t f o r w a r dC R CI m p l e m e n t a t i o n T h a t ' st h ee n do ft h et h e o r y ;n o ww et u r nt oi m p l e m e n t a t i o n s .T os t a r t w i t h ,w ee x a m i n ea na b s o l u t e l ys t r a i g h t d o w n t h e m i d d l eb o r i n g
12/37

12/30/12

CRC Explained

s t r a i g h t f o r w a r dl o w s p e e di m p l e m e n t a t i o nt h a td o e s n ' tu s ea n ys p e e d t r i c k sa ta l l .W e ' l lt h e nt r a n s f o r mt h a tp r o g r a mp r o g e s s i v e l yu n t i lw e e n du pw i t ht h ec o m p a c tt a b l e d r i v e nc o d ew ea l lk n o wa n dl o v ea n d w h i c hs o m eo fu sw o u l dl i k et ou n d e r s t a n d . T oi m p l e m e n taC R Ca l g o r i t h ma l lw eh a v et od oi si m p l e m e n tC R C d i v i s i o n .T h e r ea r et w or e a s o n sw h yw ec a n n o ts i m p l yu s et h ed i v i d e i n s t r u c t i o no fw h a t e v e rm a c h i n ew ea r eo n .T h ef i r s ti st h a tw eh a v e t od ot h ed i v i d ei nC R Ca r i t h m e t i c .T h es e c o n di st h a tt h ed i v i d e n d m i g h tb et e nm e g a b y t e sl o n g ,a n dt o d a y sp r o c e s s o r sd on o th a v e r e g i s t e r st h a tb i g . S ot oi m p l e m e n tC R Cd i v i s i o n ,w eh a v et of e e dt h em e s s a g et h r o u g ha d i v i s i o nr e g i s t e r .A tt h i sp o i n t ,w eh a v et ob ea b s o l u t e l yp r e c i s e a b o u tt h em e s s a g ed a t a .I na l lt h ef o l l o w i n ge x a m p l e st h em e s s a g ew i l l b ec o n s i d e r e dt ob eas t r e a mo fb y t e s( e a c ho f8b i t s )w i t hb i t7o f e a c hb y t eb e i n gc o n s i d e r e dt ob et h em o s ts i g n i f i c a n tb i t( M S B ) .T h e b i ts t r e a mf o r m e df r o mt h e s eb y t e sw i l lb et h eb i ts t r e a mw i t ht h eM S B ( b i t7 )o ft h ef i r s tb y t ef i r s t ,g o i n gd o w nt ob i t0o ft h ef i r s t b y t e ,a n dt h e nt h eM S Bo ft h es e c o n db y t ea n ds oo n . W i t ht h i si nm i n d ,w ec a ns k e t c ha ni m p l e m e n t a t i o no ft h eC R C d i v i s i o n .F o rt h ep u r p o s e so fe x a m p l e ,c o n s i d e rap o l yw i t hW = 4a n d t h ep o l y = 1 0 1 1 1 .T h e n ,t h ep e r f o r mt h ed i v i s i o n ,w en e e dt ou s ea4 b i t r e g i s t e r : 3 2 1 0 B i t s + + + + + P o p !< -| | | | |< -A u g m e n t e dm e s s a g e + + + + + 1 0 1 1 1 =T h eP o l y

( R e m i n d e r :T h ea u g m e n t e dm e s s a g ei st h em e s s a g ef o l l o w e db yWz e r ob i t s . ) T op e r f o r mt h ed i v i s i o np e r f o r mt h ef o l l o w i n g : L o a dt h er e g i s t e rw i t hz e r ob i t s . A u g m e n tt h em e s s a g eb ya p p e n d i n gWz e r ob i t st ot h ee n do fi t . W h i l e( m o r em e s s a g eb i t s ) B e g i n S h i f tt h er e g i s t e rl e f tb yo n eb i t ,r e a d i n gt h en e x tb i to ft h e a u g m e n t e dm e s s a g ei n t or e g i s t e rb i tp o s i t i o n0 . I f( a1b i tp o p p e do u to ft h er e g i s t e rd u r i n gs t e p3 ) R e g i s t e r=R e g i s t e rX O RP o l y . E n d T h er e g i s t e rn o wc o n t a i n st h er e m a i n d e r . ( N o t e :I np r a c t i c e ,t h eI Fc o n d i t i o nc a nb et e s t e db yt e s t i n gt h et o p b i to fRb e f o r ep e r f o r m i n gt h es h i f t . ) W ew i l lc a l lt h i sa l g o r i t h m" S I M P L E " . T h i sm i g h tl o o kab i tm e s s y ,b u ta l lw ea r er e a l l yd o i n gi s " s u b t r a c t i n g "v a r i o u sp o w e r s( i . e .s h i f t i n g s )o ft h ep o l yf r o mt h e m e s s a g eu n t i lt h e r ei sn o t h i n gl e f tb u tt h er e m a i n d e r .S t u d yt h e m a n u a le x a m p l e so fl o n gd i v i s i o ni fy o ud o n ' tu n d e r s t a n dt h i s .
www.csm.ornl.gov /~dunigan/crc.html 13/37

12/30/12

I ts h o u l db ec l e a rt h a tt h ea b o v ea l g o r i t h mw i l lw o r kf o ra n yw i d t hW .

9 .AT a b l e D r i v e nI m p l e m e n t a t i o n T h eS I M P L Ea l g o r i t h ma b o v ei sag o o ds t a r t i n gp o i n tb e c a u s ei t c o r r e s p o n d sd i r e c t l yt ot h et h e o r yp r e s e n t e ds of a r ,a n db e c a u s ei ti s s oS I M P L E .H o w e v e r ,b e c a u s ei to p e r a t e sa tt h eb i tl e v e l ,i ti sr a t h e r a w k w a r dt oc o d e( e v e ni nC ) ,a n di n e f f i c i e n tt oe x e c u t e( i th a st o l o o po n c ef o re a c hb i t ) .T os p e e di tu p ,w en e e dt of i n daw a yt o e n a b l et h ea l g o r i t h mt op r o c e s st h em e s s a g ei nu n i t sl a r g e rt h a no n e b i t .C a n d i d a t eq u a n t i t i e sa r en i b b l e s( 4b i t s ) ,b y t e s( 8b i t s ) ,w o r d s ( 1 6b i t s )a n dl o n g w o r d s( 3 2b i t s )a n dh i g h e ri fw ec a na c h i e v ei t .O f t h e s e ,4b i t si sb e s ta v o i d e db e c a u s ei td o e sn o tc o r r e s p o n dt oab y t e b o u n d a r y .A tt h ev e r yl e a s t ,a n ys p e e d u ps h o u l da l l o wu st oo p e r a t ea t b y t eb o u n d a r i e s ,a n di nf a c tm o s to ft h et a b l ed r i v e na l g o r i t h m s o p e r a t eab y t ea tat i m e . F o rt h ep u r p o s e so fd i s c u s s i o n ,l e tu ss w i t c hf r o ma4 b i tp o l yt oa 3 2 b i to n e .O u rr e g i s t e rl o o k sm u c ht h es a m e ,e x c e p tt h eb o x e s r e p r e s e n tb y t e si n s t e a do fb i t s ,a n dt h eP o l yi s3 3b i t s( o n ei m p l i c i t 1b i ta tt h et o pa n d3 2" a c t i v e "b i t s )( W = 3 2 ) . 3 2 1 0 B y t e s + + + + + P o p !< -| | | | |< -A u g m e n t e dm e s s a g e + + + + + 1 < 3 2b i t s > T h eS I M P L Ea l g o r i t h mi ss t i l la p p l i c a b l e .L e tu se x a m i n ew h a ti td o e s . I m a g i n et h a tt h eS I M P L Ea l g o r i t h mi si nf u l ls w i n ga n dc o n s i d e rt h e t o p8b i t so ft h e3 2 b i tr e g i s t e r( b y t e3 )t oh a v et h ev a l u e s : t 7t 6t 5t 4t 3t 2t 1t 0 I nt h en e x ti t e r a t i o no fS I M P L E ,t 7w i l ld e t e r m i n ew h e t h e rt h eP o l y w i l lb eX O R e di n t ot h ee n t i r er e g i s t e r .I ft 7 = 1 ,t h i sw i l lh a p p e n , o t h e r w i s ei tw i l ln o t .S u p p o s et h a tt h et o p8b i t so ft h ep o l ya r eg 7 g 6 . .g 0 ,t h e na f t e rt h en e x ti t e r a t i o n ,t h et o pb y t ew i l lb e : t 6t 5t 4t 3t 2t 1t 0? ? +t 7*( g 7g 6g 5g 4g 3g 2g 1g 0 )

[ R e m i n d e r :+i sX O R ]

T h eN E Wt o pb i t( t h a tw i l lc o n t r o lw h a th a p p e n si nt h en e x ti t e r a t i o n ) n o wh a st h ev a l u et 6+t 7 * g 7 .T h ei m p o r t a n tt h i n gt on o t i c eh e r ei s t h a tf r o ma ni n f o r m a t i o n a lp o i n to fv i e w ,a l lt h ei n f o r m a t i o nr e q u i r e d t oc a l c u l a t et h eN E Wt o pb i tw a sp r e s e n ti nt h et o pT W Ob i t so ft h e o r i g i n a lt o pb y t e .S i m i l a r l y ,t h eN E X Tt o pb i tc a nb ec a l c u l a t e di n a d v a n c eS O L E L Yf r o mt h et o pT H R E Eb i t st 7 ,t 6 ,a n dt 5 .I nf a c t ,i n g e n e r a l ,t h ev a l u eo ft h et o pb i ti nt h er e g i s t e ri nki t e r a t i o n sc a n b ec a l c u l a t e df r o mt h et o pkb i t so ft h er e g i s t e r .L e tu st a k et h i s f o rg r a n t e df o ram o m e n t . C o n s i d e rf o ram o m e n tt h a tw eu s et h et o p8b i t so ft h er e g i s t e rt o c a l c u l a t et h ev a l u eo ft h et o pb i to ft h er e g i s t e rd u r i n gt h en e x t8


www.csm.ornl.gov /~dunigan/crc.html 14/37

12/30/12

CRC Explained

i t e r a t i o n s .S u p p o s et h a tw ed r i v et h en e x t8i t e r a t i o n su s i n gt h e c a l c u l a t e dv a l u e s( w h i c hw ec o u l dp e r h a p ss t o r ei nas i n g l eb y t e r e g i s t e ra n ds h i f to u tt op i c ko f fe a c hb i t ) .T h e nw en o t et h r e e t h i n g s : *T h et o pb y t eo ft h er e g i s t e rn o wd o e s n ' tm a t t e r .N om a t t e rh o w m a n yt i m e sa n da tw h a to f f s e tt h ep o l yi sX O R e dt ot h et o p8 b i t s ,t h e yw i l la l lb es h i f t e do u tt h er i g h th a n ds i d ed u r i n gt h e n e x t8i t e r a t i o n sa n y w a y .

*T h er e m a i n i n gb i t sw i l lb es h i f t e dl e f to n ep o s i t i o na n dt h e r i g h t m o s tb y t eo ft h er e g i s t e rw i l lb es h i f t e di nt h en e x tb y t e A N D *W h i l ea l lt h i si sg o i n go n ,t h er e g i s t e rw i l lb es u b j e c t e dt oa s e r i e so fX O R ' si na c c o r d a n c ew i t ht h eb i t so ft h ep r e c a l c u l a t e d c o n t r o lb y t e . N o wc o n s i d e rt h ee f f e c to fX O R i n gi nac o n s t a n tv a l u ea tv a r i o u s o f f s e t st oar e g i s t e r .F o re x a m p l e : 0 1 0 0 0 1 0 . . . 0 1 1 0 . . 0 1 1 0 . 0 1 1 0 . . . 0 0 1 1 0 0 0 R e g i s t e r X O Rt h i s X O Rt h i s X O Rt h i s

T h ep o i n to ft h i si st h a ty o uc a nX O Rc o n s t a n tv a l u e si n t oar e g i s t e r t oy o u rh e a r t ' sd e l i g h t ,a n di nt h ee n d ,t h e r ew i l le x i s tav a l u e w h i c hw h e nX O R e di nw i t ht h eo r i g i n a lr e g i s t e rw i l lh a v et h es a m e e f f e c ta sa l lt h eo t h e rX O R s . P e r h a p sy o uc a ns e et h es o l u t i o nn o w .P u t t i n ga l lt h ep i e c e st o g e t h e r w eh a v ea na l g o r i t h mt h a tg o e sl i k et h i s : W h i l e( a u g m e n t e dm e s s a g ei sn o te x h a u s t e d ) B e g i n E x a m i n et h et o pb y t eo ft h er e g i s t e r C a l c u l a t et h ec o n t r o lb y t ef r o mt h et o pb y t eo ft h er e g i s t e r S u ma l lt h eP o l y sa tv a r i o u so f f s e t st h a ta r et ob eX O R e di n t o t h er e g i s t e ri na c c o r d a n c ew i t ht h ec o n t r o lb y t e S h i f tt h er e g i s t e rl e f tb yo n eb y t e ,r e a d i n gan e wm e s s a g eb y t e i n t ot h er i g h t m o s tb y t eo ft h er e g i s t e r X O Rt h es u m m e dp o l y st ot h er e g i s t e r E n d A si ts t a n d st h i si sn o tm u c hb e t t e rt h a nt h eS I M P L Ea l g o r i t h m . H o w e v e r ,i tt u r n so u tt h a tm o s to ft h ec a l c u l a t i o nc a nb ep r e c o m p u t e d a n da s s e m b l e di n t oat a b l e .A sar e s u l t ,t h ea b o v ea l g o r i t h mc a nb e r e d u c e dt o : W h i l e( a u g m e n t e dm e s s a g ei sn o te x h a u s e d ) B e g i n


www.csm.ornl.gov /~dunigan/crc.html 15/37

12/30/12

CRC Explained

T o p=t o p _ b y t e ( R e g i s t e r ) ; R e g i s t e r=( R e g i s t e r< <2 4 )|n e x t _ a u g m e s s a g e _ b y t e ; R e g i s t e r=R e g i s t e rX O Rp r e c o m p u t e d _ t a b l e [ T o p ] ; E n d T h e r e !I fy o uu n d e r s t a n dt h i s ,y o u ' v eg r a s p e dt h em a i ni d e ao f t a b l e d r i v e nC R Ca l g o r i t h m s .T h ea b o v ei sav e r ye f f i c i e n ta l g o r i t h m r e q u i r i n gj u s tas h i f t ,a n dO R ,a nX O R ,a n dat a b l el o o k u pp e rb y t e . G r a p h i c a l l y ,i tl o o k sl i k et h i s : 3 2 1 0 B y t e s + + + + + + < | | | | |< -A u g m e n t e dm e s s a g e | + + + + + | ^ | | | X O R | | | 0 + + + + + A l g o r i t h m v + + + + + | + + + + + 1 .S h i f tt h er e g i s t e rl e f tb y | + + + + + o n eb y t e ,r e a d i n gi nan e w | + + + + + m e s s a g eb y t e . | + + + + + 2 .U s et h et o pb y t ej u s tr o t a t e d | + + + + + o u to ft h er e g i s t e rt oi n d e x + > + + + + + t h et a b l eo f2 5 63 2 b i tv a l u e s . + + + + + 3 .X O Rt h et a b l ev a l u ei n t ot h e + + + + + r e g i s t e r . + + + + + 4 .G o t o1i f fm o r ea u g m e n t e d + + + + + m e s s a g eb y t e s . 2 5 5 + + + + +

I nC ,t h ea l g o r i t h mm a i nl o o pl o o k sl i k et h i s : r = 0 ; w h i l e( l e n ) { b y t et=( r> >2 4 )&0 x F F ; r=( r< <8 )|* p + + ; r ^ = t a b l e [ t ] ; } w h e r el e ni st h el e n g t ho ft h ea u g m e n t e dm e s s a g ei nb y t e s ,pp o i n t st o t h ea u g m e n t e dm e s s a g e ,ri st h er e g i s t e r ,ti sat e m p o r a r y ,a n dt a b l e i st h ec o m p u t e dt a b l e .T h i sc o d ec a nb em a d ee v e nm o r eu n r e a d a b l ea s f o l l o w s : r = 0 ;w h i l e( l e n )r=( ( r< <8 )|* p + + )^t [ ( r> >2 4 )&0 x F F ] ; T h i si sav e r yc l e a n ,e f f i c i e n tl o o p ,a l t h o u g hn o tav e r yo b v i o u so n e t ot h ec a s u a lo b s e r v e rn o tv e r s e di nC R Ct h e o r y .W ew i l lc a l lt h i st h e T A B L Ea l g o r i t h m .

1 0 .AS l i g h t l yM a n g l e dT a b l e D r i v e nI m p l e m e n t a t i o n www.csm.ornl.gov /~dunigan/crc.html 16/37

12/30/12

CRC Explained

D e s p i t et h et e r s eb e a u t yo ft h el i n e r = 0 ;w h i l e( l e n )r=( ( r< <8 )|* p + + )^t [ ( r> >2 4 )&0 x F F ] ; t h o s eo p t i m i z i n gh a c k e r sc o u l d n ' tl e a v ei ta l o n e .T h et r o u b l e ,y o u s e e ,i st h a tt h i sl o o po p e r a t e su p o nt h eA U G M E N T E Dm e s s a g ea n di n o r d e rt ou s et h i sc o d e ,y o uh a v et oa p p e n dW / 8z e r ob y t e st ot h ee n d o ft h em e s s a g eb e f o r ep o i n t i n gpa ti t .D e p e n d i n go nt h er u n t i m e e n v i r o n m e n t ,t h i sm a yo rm a yn o tb eap r o b l e m ;i ft h eb l o c ko fd a t a w a sh a n d e dt ou sb ys o m eo t h e rc o d e ,i tc o u l db eaB I Gp r o b l e m .O n e a l t e r n a t i v ei ss i m p l yt oa p p e n dt h ef o l l o w i n gl i n ea f t e rt h ea b o v e l o o p ,o n c ef o re a c hz e r ob y t e : f o r( i = 0 ;i < W / 4 ;i + + )r=( r< <8 )^t [ ( r> >2 4 )&0 x F F ] ; T h i sl o o k sl i k eas a n ee n o u g hs o l u t i o nt om e .H o w e v e r ,a tt h ef u r t h e r e x p e n s eo fc l a r i t y( w h i c h ,y o um u s ta d m i t ,i sa l r e a d yap r e t t ys c a r e c o m m o d i t yi nt h i sc o d e )w ec a nr e o r g a n i z et h i ss m a l ll o o pf u r t h e rs o a st oa v o i dt h en e e dt oe i t h e ra u g m e n tt h em e s s a g ew i t hz e r ob y t e s ,o r t oe x p l i c i t l yp r o c e s sz e r ob y t e sa tt h ee n da sa b o v e .T oe x p l a i nt h e o p t i m i z a t i o n ,w er e t u r nt ot h ep r o c e s s i n gd i a g r a mg i v e ne a r l i e r . 3 2 1 0 B y t e s + + + + + + < | | | | |< -A u g m e n t e dm e s s a g e | + + + + + | ^ | | | X O R | | | 0 + + + + + A l g o r i t h m v + + + + + | + + + + + 1 .S h i f tt h er e g i s t e rl e f tb y | + + + + + o n eb y t e ,r e a d i n gi nan e w | + + + + + m e s s a g eb y t e . | + + + + + 2 .U s et h et o pb y t ej u s tr o t a t e d | + + + + + o u to ft h er e g i s t e rt oi n d e x + > + + + + + t h et a b l eo f2 5 63 2 b i tv a l u e s . + + + + + 3 .X O Rt h et a b l ev a l u ei n t ot h e + + + + + r e g i s t e r . + + + + + 4 .G o t o1i f fm o r ea u g m e n t e d + + + + + m e s s a g eb y t e s . 2 5 5 + + + + + N o w ,n o t et h ef o l l o w i n gf a c t s : T A I L :T h eW / 4a u g m e n t e dz e r ob y t e st h a ta p p e a ra tt h ee n do ft h e m e s s a g ew i l lb ep u s h e di n t ot h er e g i s t e rf r o mt h er i g h ta sa l l t h eo t h e rb y t e sa r e ,b u tt h e i rv a l u e s( 0 )w i l lh a v en oe f f e c t w h a t s o e v e ro nt h er e g i s t e rb e c a u s e1 )X O R i n gw i t hz e r od o e sn o t c h a n g et h et a r g e tb y t e ,a n d2 )t h ef o u rb y t e sa r en e v e r p r o p a g a t e do u tt h el e f ts i d eo ft h er e g i s t e rw h e r et h e i r z e r o n e s sm i g h th a v es o m es o r to fi n f l u e n c e .T h u s ,t h es o l e f u n c t i o no ft h eW / 4a u g m e n t e dz e r ob y t e si st od r i v et h e c a l c u l a t i o nf o ra n o t h e rW / 4b y t ec y c l e ss ot h a tt h ee n do ft h e R E A Ld a t ap a s s e sa l lt h ew a yt h r o u g ht h er e g i s t e r .
www.csm.ornl.gov /~dunigan/crc.html

12/30/12

CRC Explained

H E A D :I ft h ei n i t i a lv a l u eo ft h er e g i s t e ri sz e r o ,t h ef i r s tf o u r i t e r a t i o n so ft h el o o pw i l lh a v et h es o l ee f f e c to fs h i f t i n gi n t h ef i r s tf o u rb y t e so ft h em e s s a g ef r o mt h er i g h t .T h i si s b e c a u s et h ef i r s t3 2c o n t r o lb i t sa r ea l lz e r oa n ds on o t h i n gi s X O R e di n t ot h er e g i s t e r .E v e ni ft h ei n i t i a lv a l u ei sn o tz e r o , t h ef i r s t4b y t ei t e r a t i o n so ft h ea l g o r i t h mw i l lh a v et h es o l e e f f e c to fs h i f t i n gt h ef i r s t4b y t e so ft h em e s s a g ei n t ot h e r e g i s t e ra n dt h e nX O R i n gt h e mw i t hs o m ec o n s t a n tv a l u e( t h a ti s af u n c t i o no ft h ei n i t i a lv a l u eo ft h er e g i s t e r ) . T h e s ef a c t s ,c o m b i n e dw i t ht h eX O Rp r o p e r t y ( Ax o rB )x o rC=Ax o r( Bx o rC ) m e a nt h a tm e s s a g eb y t e sn e e dn o ta c t u a l l yt r a v e lt h r o u g ht h eW / 4b y t e s o ft h er e g i s t e r .I n s t e a d ,t h e yc a nb eX O R e di n t ot h et o pb y t ej u s t b e f o r ei ti su s e dt oi n d e xt h el o o k u pt a b l e .T h i sl e a d st ot h e f o l l o w i n gm o d i f i e dv e r s i o no ft h ea l g o r i t h m .

+ < M e s s a g e( n o na u g m e n t e d ) | v 3 2 1 0 B y t e s | + + + + + X O R < | | | | | | + + + + + | ^ | | | X O R | | | 0 + + + + + A l g o r i t h m v + + + + + | + + + + + 1 .S h i f tt h er e g i s t e rl e f tb y | + + + + + o n eb y t e ,r e a d i n gi nan e w | + + + + + m e s s a g eb y t e . | + + + + + 2 .X O Rt h et o pb y t ej u s tr o t a t e d | + + + + + o u to ft h er e g i s t e rw i t ht h e + > + + + + + n e x tm e s s a g eb y t et oy i e l da n + + + + + i n d e xi n t ot h et a b l e( [ 0 , 2 5 5 ] ) . + + + + + 3 .X O Rt h et a b l ev a l u ei n t ot h e + + + + + r e g i s t e r . + + + + + 4 .G o t o1i f fm o r ea u g m e n t e d 2 5 5 + + + + + m e s s a g eb y t e s .

N o t e :T h ei n i t i a lr e g i s t e rv a l u ef o rt h i sa l g o r i t h mm u s tb et h e i n i t i a lv a l u eo ft h er e g i s t e rf o rt h ep r e v i o u sa l g o r i t h mf e dt h r o u g h t h et a b l ef o u rt i m e s .N o t e :T h et a b l ei ss u c ht h a ti ft h ep r e v i o u s a l g o r i t h mu s e d0 ,t h en e wa l g o r i t h mw i l lt o o . T h i si sa nI D E N T I C A La l g o r i t h ma n dw i l ly i e l dI D E N T I C A Lr e s u l t s .T h eC c o d el o o k ss o m e t h i n gl i k et h i s : r = 0 ;w h i l e( l e n )r=( r < < 8 )^t [ ( r> >2 4 )^* p + + ] ; a n dT H I Si st h ec o d et h a ty o ua r el i k e l yt of i n di n s i d ec u r r e n t t a b l e d r i v e nC R Ci m p l e m e n t a t i o n s .S o m eF Fm a s k sm i g h th a v et ob eA N D e d


www.csm.ornl.gov /~dunigan/crc.html 18/37

12/30/12

CRC Explained

i nh e r ea n dt h e r ef o rp o r t a b i l i t y ' ss a k e ,b u tb a s i c a l l y ,t h ea b o v e l o o pi sI T .W ew i l lc a l lt h i st h eD I R E C TT A B L EA L G O R I T H M . D u r i n gt h ep r o c e s so ft r y i n gt ou n d e r s t a n da l lt h i ss t u f f ,Im a n a g e d t od e r i v et h eS I M P L Ea l g o r i t h ma n dt h et a b l e d r i v e nv e r s i o nd e r i v e d f r o mt h a t .H o w e v e r ,w h e nIc o m p a r e dm yc o d ew i t ht h ec o d ef o u n di n r e a l i m p l e m e n t a t i o n s ,Iw a st o t a l l yb a m b o o z l e da st ow h yt h eb y t e s w e r eb e i n gX O R e di na tt h ew r o n ge n do ft h er e g i s t e r !I tt o o kq u i t ea w h i l eb e f o r eIf i g u r e do u tt h a tt h e i r sa n dm ya l g o r i t h m sw e r ea c t u a l l y t h es a m e .P a r to fw h yIa mw r i t i n gt h i sd o c u m e n ti st h a t ,w h i l et h e l i n kb e t w e e nd i v i s i o na n dm ye a r l i e rt a b l e d r i v e nc o d ei sv a g u e l y a p p a r e n t ,a n ys u c hl i n ki sf a i r l yw e l le r a s e dw h e ny o us t a r tp u m p i n g b y t e si na tt h e" w r o n ge n d "o ft h er e g i s t e r .I tl o o k sa l lw r o n g ! I fy o u ' v eg o tt h i sf a r ,y o un o to n l yu n d e r s t a n dt h et h e o r y ,t h e p r a c t i c e ,t h eo p t i m i z e dp r a c t i c e ,b u ty o ua l s ou n d e r s t a n dt h er e a l c o d ey o ua r el i k e l yt or u ni n t o .C o u l dg e ta n ym o r ec o m p l i c a t e d ?Y e s i tc a n .

1 1 ." R e f l e c t e d "T a b l e D r i v e nI m p l e m e n t a t i o n s D e s p i t et h ef a c tt h a tt h ea b o v ec o d ei sp r o b a b l yo p t i m i z e da b o u ta s m u c ha si tc o u l db e ,t h i sd i dn o ts t o ps o m ee n t e r p r i s i n gi n d i v i d u a l s f r o mm a k i n gt h i n g se v e nm o r ec o m p l i c a t e d .T ou n d e r s t a n dh o wt h i s h a p p e n e d ,w eh a v et oe n t e rt h ew o r l do fh a r d w a r e . D E F I N I T I O N :Av a l u e / r e g i s t e ri sr e f l e c t e di fi t ' sb i t sa r es w a p p e d a r o u n di t sc e n t r e .F o re x a m p l e :0 1 0 1i st h e4 b i tr e f l e c t i o no f1 0 1 0 . 0 0 1 1i st h er e f l e c t i o no f1 1 0 0 . 0 1 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 1 0 0i st h er e f l e c t i o no f 0 0 1 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 1 1 0 1 0 1 1 0 1 0 1 1 1 0 . T u r n so u tt h a tU A R T s( t h o s eh a n d yl i t t l ec h i p st h a tp e r f o r ms e r i a lI O ) a r ei nt h eh a b i to ft r a n s m i t t i n ge a c hb y t ew i t ht h el e a s ts i g n i f i c a n t b i t( b i t0 )f i r s ta n dt h em o s ts i g n i f i c a n tb i t( b i t7 )l a s t( i . e . r e f l e c t e d ) .A ne f f e c to ft h i sc o n v e n t i o ni st h a th a r d w a r ee n g i n e e r s c o n s t r u c t i n gh a r d w a r eC R Cc a l c u l a t o r st h a to p e r a t ea tt h eb i tl e v e l t o o kt oc a l c u l a t i n gC R C so fb y t e ss t r e a m sw i t he a c ho ft h eb y t e s r e f l e c t e dw i t h i ni t s e l f .T h eb y t e sa r ep r o c e s s e di nt h es a m eo r d e r , b u tt h eb i t si ne a c hb y t ea r es w a p p e d ;b i t0i sn o wb i t7 ,b i t1i s n o wb i t6 ,a n ds oo n .N o wt h i sw o u l d n ' tm a t t e rm u c hi ft h i sc o n v e n t i o n w a sr e s t r i c t e dt oh a r d w a r el a n d .H o w e v e ri ts e e m st h a ta ts o m es t a g e s o m eo ft h e s eC R Cv a l u e sw e r ep r e s e n t e da tt h es o f t w a r el e v e la n d s o m e o n eh a dt ow r i t es o m ec o d et h a tw o u l di n t e r o p e r a t ew i t ht h e h a r d w a r eC R Cc a l c u l a t i o n . I nt h i ss i t u a t i o n ,an o r m a ls a n es o f t w a r ee n g i n e e rw o u l ds i m p l y r e f l e c te a c hb y t eb e f o r ep r o c e s s i n gi t .H o w e v e r ,i tw o u l ds e e mt h a t n o r m a ls a n es o f t w a r ee n g i n e e r sw e r et h i no nt h eg r o u n dw h e nt h i se a r l y g r o u n dw a sb e i n gb r o k e n ,b e c a u s ei n s t e a do fr e f l e c t i n gt h eb y t e s , w h o e v e rw a sr e s p o n s i b l eh e l dd o w nt h eb y t ea n dr e f l e c t e dt h ew o r l d , l e a d i n gt ot h ef o l l o w i n g" r e f l e c t e d "a l g o r i t h mw h i c hi si d e n t i c a lt o t h ep r e v i o u so n ee x c e p tt h a te v e r y t h i n gi sr e f l e c t e de x c e p tt h ei n p u t b y t e s .
www.csm.ornl.gov /~dunigan/crc.html 19/37

M e s s a g e( n o na u g m e n t e d )> + | B y t e s 0 1 2 3 v + + + + + | | | | | | > X O R + + + + + | ^ | | | X O R | | | + + + + + 0 | + + + + + v + + + + + | + + + + + | + + + + + | + + + + + | + + + + + | + + + + + < + + + + + + + + + + + + + + + + + + + + + + + + + + 2 5 5 N o t e s : *T h et a b l ei si d e n t i c a lt ot h eo n ei nt h ep r e v i o u sa l g o r i t h m e x c e p tt h a te a c he n t r yh a sb e e nr e f l e c t e d . *T h ei n i t i a lv a l u eo ft h er e g i s t e ri st h es a m ea si nt h ep r e v i o u s a l g o r i t h me x c e p tt h a ti th a sb e e nr e f l e c t e d . *T h eb y t e so ft h em e s s a g ea r ep r o c e s s e di nt h es a m eo r d e ra s b e f o r e( i . e .t h em e s s a g ei t s e l fi sn o tr e f l e c t e d ) . *T h em e s s a g eb y t e st h e m s e l v e sd o n ' tn e e dt ob ee x p l i c i t l y r e f l e c t e d ,b e c a u s ee v e r y t h i n ge l s eh a sb e e n ! A tt h ee n do fe x e c u t i o n ,t h er e g i s t e rc o n t a i n st h er e f l e c t i o no ft h e f i n a lC R Cv a l u e( r e m a i n d e r ) .A c t u a l l y ,I ' mb e i n gr a t h e rh a r do n w h o e v e rc o o k e dt h i su pb e c a u s ei ts e e m st h a th a r d w a r ei m p l e m e n t a t i o n s o ft h eC R Ca l g o r i t h mu s e dt h er e f l e c t e dc h e c k s u mv a l u ea n ds o p r o d u c i n gar e f l e c t e dC R Cw a sj u s tr i g h t .I nf a c tr e f l e c t i n gt h ew o r l d w a sp r o b a b l yag o o de n g i n e e r i n gs o l u t i o n-i fac o n f u s i n go n e . W ew i l lc a l lt h i st h eR E F L E C T E Da l g o r i t h m . W h e t h e ro rn o ti tm a d es e n s ea tt h et i m e ,t h ee f f e c to fh a v i n g r e f l e c t e da l g o r i t h m sk i c k i n ga r o u n dt h ew o r l d ' sF T Ps i t e si st h a t a b o u th a l ft h eC R Ci m p l e m e n t a t i o n so n er u n si n t oa r er e f l e c t e da n dt h e o t h e rh a l fn o t .I t ' sr e a l l yt e r r i b l yc o n f u s i n g .I np a r t i c u l a r ,i t w o u l ds e e mt om et h a tt h ec a s u a lr e a d e rw h or u n si n t oar e f l e c t e d , t a b l e d r i v e ni m p l e m e n t a t i o nw i t ht h eb y t e s" f e di nt h ew r o n ge n d " w o u l dh a v eB u c k l e y ' sc h a n c eo fe v e rc o n n e c t i n gt h ec o d et ot h ec o n c e p t o fb i n a r ym o d2d i v i s i o n .

12/30/12

CRC Explained

I tc o u l d n ' tg e ta n ym o r ec o n f u s i n gc o u l di t ?Y e si tc o u l d .

1 2 ." R e v e r s e d "P o l y s A si fr e f l e c t e di m p l e m e n t a t i o n sw e r e n ' te n o u g h ,t h e r ei sa n o t h e r c o n c e p tk i c k i n ga r o u n dw h i c hm a k e st h es i t u a t i o nb i z a a r l yc o n f u s i n g . T h ec o n c e p ti sr e v e r s e dP o l y s . I tt u r n so u tt h a tt h er e f l e c t i o no fg o o dp o l y st e n dt ob eg o o dp o l y s t o o !T h a ti s ,i fG = 1 1 1 0 1i sag o o dp o l yv a l u e ,t h e n1 0 1 1 1w i l lb ea s w e l l .A sac o n s e q u e n c e ,i ts e e m st h a te v e r yt i m ea no r g a n i z a t i o n( s u c h a sC C I T T )s t a n d a r d i z e so nap a r t i c u l a r l yg o o dp o l y( " p o l y n o m i a l " ) , t h o s ei nt h er e a lw o r l dc a n ' tl e a v et h ep o l y ' sr e f l e c t i o na l o n e e i t h e r .T h e yj u s tH A V Et ou s ei t .A sar e s u l t ,t h es e to f" s t a n d a r d " p o l y ' sh a sac o r r e s p o n d i n gs e to fr e f l e c t i o n s ,w h i c ha r ea l s oi nu s e . T oa v o i dc o n f u s i o n ,w ew i l lc a l lt h e s et h e" r e v e r s e d "p o l y s . X 2 5 X 2 5 s t a n d a r d :1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 r e v e r s e d :1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1

C R C 1 6s t a n d a r d :1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 C R C 1 6r e v e r s e d :1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 N o t et h a th e r ei ti st h ee n t i r ep o l yt h a ti sb e i n gr e f l e c t e d / r e v e r s e d , n o tj u s tt h eb o t t o mWb i t s .T h i si sa ni m p o r t a n td i s t i n c t i o n .I nt h e r e f l e c t e da l g o r i t h md e s c r i b e di nt h ep r e v i o u ss e c t i o n ,t h ep o l yu s e d i nt h er e f l e c t e da l g o r i t h mw a sa c t u a l l yi d e n t i c a lt ot h a tu s e di nt h e n o n r e f l e c t e da l g o r i t h m ;a l lt h a th a dh a p p e n e di st h a tt h eb y t e sh a d e f f e c t i v e l yb e e nr e f l e c t e d .A ss u c h ,a l lt h e1 6 b i t / 3 2 b i tn u m b e r si n t h ea l g o r i t h mh a dt ob er e f l e c t e d .I nc o n t r a s t ,t h eE N T I R Ep o l y i n c l u d e st h ei m p l i c i to n eb i ta tt h et o p ,a n ds or e v e r s i n gap o l yi s n o tt h es a m ea sr e f l e c t i n gi t sb o t t o m1 6o r3 2b i t s . T h eu p s h o to fa l lt h i si st h a tar e f l e c t e da l g o r i t h mi sn o te q u i v a l e n t t ot h eo r i g i n a la l g o r i t h mw i t ht h ep o l yr e f l e c t e d .A c t u a l l y ,t h i si s p r o b a b l yl e s sc o n f u s i n gt h a ni ft h e yw e r ed u a l s . I fa l lt h i ss e e m sab i tu n c l e a r ,d o n ' tw o r r y ,b e c a u s ew e ' r eg o i n gt o s o r ti ta l lo u t" r e a ls o o nn o w " .J u s to n em o r es e c t i o nt og ob e f o r e t h a t .

1 3 .I n i t i a la n dF i n a lV a l u e s I na d d i t i o nt ot h ec o m p l e x i t ya l r e a d ys e e n ,C R Ca l g o r i t h m sd i f f e rf r o m e a c ho t h e ri nt w oo t h e rr e g a r d s : *T h ei n i t i a lv a l u eo ft h er e g i s t e r . *T h ev a l u et ob eX O R e dw i t ht h ef i n a lr e g i s t e rv a l u e . F o re x a m p l e ,t h e" C R C 3 2 "a l g o r i t h mi n i t i a l i z e si t sr e g i s t e rt o F F F F F F F Fa n dX O R st h ef i n a lr e g i s t e rv a l u ew i t hF F F F F F F F . M o s tC R Ca l g o r i t h m si n i t i a l i z et h e i rr e g i s t e rt oz e r o .H o w e v e r ,s o m e i n i t i a l i z ei tt oan o n z e r ov a l u e .I nt h e o r y( i . e .w i t hn oa s s u m p t i o n s


www.csm.ornl.gov /~dunigan/crc.html 21/37

12/30/12

CRC Explained

a b o u tt h em e s s a g e ) ,t h ei n i t i a lv a l u eh a sn oa f f e c to nt h es t r e n g t ho f t h eC R Ca l g o r i t h m ,t h ei n i t i a lv a l u em e r e l yp r o v i d i n gaf i x e ds t a r t i n g p o i n tf r o mw h i c ht h er e g i s t e rv a l u ec a np r o g r e s s .H o w e v e r ,i n p r a c t i c e ,s o m em e s s a g e sa r em o r el i k e l yt h a no t h e r s ,a n di ti sw i s et o i n i t i a l i z et h eC R Ca l g o r i t h mr e g i s t e rt oav a l u et h a td o e sn o th a v e " b l i n ds p o t s "t h a ta r el i k e l yt oo c c u ri np r a c t i c e .B y" b l i n ds p o t "i s m e a n tas e q u e n c eo fm e s s a g eb y t e st h a td on o tr e s u l ti nt h er e g i s t e r c h a n g i n gi t sv a l u e .I np a r t i c u l a r ,a n yC R Ca l g o r i t h mt h a ti n i t i a l i z e s i t sr e g i s t e rt oz e r ow i l lh a v eab l i n ds p o to fz e r ow h e ni ts t a r t su p a n dw i l lb eu n a b l et o" c o u n t "al e a d i n gr u no fz e r ob y t e s .A sa l e a d i n gr u no fz e r ob y t e si sq u i t ec o m m o ni nr e a lm e s s a g e s ,i ti sw i s e t oi n i t i a l i z et h ea l g o r i t h mr e g i s t e rt oan o n z e r ov a l u e .

1 4 .D e f i n i n gA l g o r i t h m sA b s o l u t e l y A tt h i sp o i n tw eh a v ec o v e r e da l lt h ed i f f e r e n ta s p e c t so f t a b l e d r i v e nC R Ca l g o r i t h m s .A st h e r ea r es om a n yv a r i a t i o n so nt h e s e a l g o r i t h m s ,i ti sw o r t ht r y i n gt oe s t a b l i s han o m e n c l a t u r ef o rt h e m . T h i ss e c t i o na t t e m p t st od ot h a t . W eh a v es e e nt h a tC R Ca l g o r i t h m sv a r yi n : *W i d t ho ft h ep o l y( p o l y n o m i a l ) . *V a l u eo ft h ep o l y . *I n i t i a lv a l u ef o rt h er e g i s t e r . *W h e t h e rt h eb i t so fe a c hb y t ea r er e f l e c t e db e f o r eb e i n gp r o c e s s e d . *W h e t h e rt h ea l g o r i t h mf e e d si n p u tb y t e st h r o u g ht h er e g i s t e ro r x o r st h e mw i t hab y t ef r o mo n ee n da n dt h e ns t r a i g h ti n t ot h et a b l e . *W h e t h e rt h ef i n a lr e g i s t e rv a l u es h o u l db er e v e r s e d( a si nr e f l e c t e d v e r s i o n s ) . *V a l u et oX O Rw i t ht h ef i n a lr e g i s t e rv a l u e . I no r d e rt ob ea b l et ot a l ka b o u tp a r t i c u l a rC R Ca l g o r i t h m s ,w en e e d t oa b l et od e f i n et h e mm o r ep r e c i s e l yt h a nt h i s .F o rt h i sr e a s o n ,t h e n e x ts e c t i o na t t e m p t st op r o v i d eaw e l l d e f i n e dp a r a m e t e r i z e dm o d e l f o rC R Ca l g o r i t h m s .T or e f e rt oap a r t i c u l a ra l g o r i t h m ,w en e e dt h e n s i m p l ys p e c i f yt h ea l g o r i t h mi nt e r m so fp a r a m e t e r st ot h em o d e l .

1 5 .AP a r a m e t e r i z e dM o d e lF o rC R CA l g o r i t h m s I nt h i ss e c t i o nw ed e f i n eap r e c i s ep a r a m e t e r i z e dm o d e lC R Ca l g o r i t h m w h i c h ,f o rw a n to fab e t t e rn a m e ,w ew i l lc a l lt h e" R o c k s o f t ^ t mM o d e l C R CA l g o r i t h m "( a n dw h yn o t ?R o c k s o f t ^ t mc o u l dd ow i t hs o m ef r e e a d v e r t i s i n g: ) . T h em o s ti m p o r t a n ta s p e c to ft h em o d e la l g o r i t h mi st h a ti tf o c u s s e s e x c l u s i v e l yo nf u n c t i o n a l i t y ,i g n o r i n ga l li m p l e m e n t a t i o nd e t a i l s .T h e a i mo ft h ee x e r c i s ei st oc o n s t r u c taw a yo fr e f e r r i n gp r e c i s e l yt o p a r t i c u l a rC R Ca l g o r i t h m s ,r e g a r d l e s so fh o wc o n f u s i n g l yt h e ya r e i m p l e m e n t e d .T ot h i se n d ,t h em o d e lm u s tb ea ss i m p l ea n dp r e c i s ea s p o s s i b l e ,w i t ha sl i t t l ec o n f u s i o na sp o s s i b l e . T h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h mi sb a s e de s s e n t i a l l yo nt h eD I R E C T T A B L EA L G O R I T H Ms p e c i f i e de a r l i e r .H o w e v e r ,t h ea l g o r i t h mh a st ob e f u r t h e rp a r a m e t e r i z e dt oe n a b l ei tt ob e h a v ei nt h es a m ew a ya ss o m e


www.csm.ornl.gov /~dunigan/crc.html 22/37

12/30/12

CRC Explained

o ft h em e s s i e ra l g o r i t h m so u ti nt h er e a lw o r l d . T oe n a b l et h ea l g o r i t h mt ob e h a v el i k er e f l e c t e da l g o r i t h m s ,w e p r o v i d eab o o l e a no p t i o nt or e f l e c tt h ei n p u tb y t e s ,a n dab o o l e a n o p t i o nt os p e c i f yw h e t h e rt or e f l e c tt h eo u t p u tc h e c k s u mv a l u e .B y f r a m i n gr e f l e c t i o na sa ni n p u t / o u t p u tt r a n s f o r m a t i o n ,w ea v o i dt h e c o n f u s i o no fh a v i n gt om e n t a l l ym a pt h ep a r a m e t e r so fr e f l e c t e da n d n o n r e f l e c t e da l g o r i t h m s . A ne x t r ap a r a m e t e ra l l o w st h ea l g o r i t h m ' sr e g i s t e rt ob ei n i t i a l i z e d t oap a r t i c u l a rv a l u e .Af u r t h e rp a r a m e t e ri sX O R e dw i t ht h ef i n a l v a l u eb e f o r ei ti sr e t u r n e d . B yp u t t i n ga l lt h e s ep i e c e st o g e t h e rw ee n du pw i t ht h ep a r a m e t e r so f t h ea l g o r i t h m : N A M E :T h i si san a m eg i v e nt ot h ea l g o r i t h m .As t r i n gv a l u e . W I D T H :T h i si st h ew i d t ho ft h ea l g o r i t h me x p r e s s e di nb i t s .T h i s i so n el e s st h a nt h ew i d t ho ft h eP o l y . P O L Y :T h i sp a r a m e t e ri st h ep o l y .T h i si sab i n a r yv a l u et h a t s h o u l db es p e c i f i e da sah e x a d e c i m a ln u m b e r .T h et o pb i to ft h e p o l ys h o u l db eo m i t t e d .F o re x a m p l e ,i ft h ep o l yi s1 0 1 1 0 ,y o u s h o u l ds p e c i f y0 6 .A ni m p o r t a n ta s p e c to ft h i sp a r a m e t e ri st h a ti t r e p r e s e n t st h eu n r e f l e c t e dp o l y ;t h eb o t t o mb i to ft h i sp a r a m e t e r i sa l w a y st h eL S Bo ft h ed i v i s o rd u r i n gt h ed i v i s i o nr e g a r d l e s so f w h e t h e rt h ea l g o r i t h mb e i n gm o d e l l e di sr e f l e c t e d . I N I T :T h i sp a r a m e t e rs p e c i f i e st h ei n i t i a lv a l u eo ft h er e g i s t e r w h e nt h ea l g o r i t h ms t a r t s .T h i si st h ev a l u et h a ti st ob ea s s i g n e d t ot h er e g i s t e ri nt h ed i r e c tt a b l ea l g o r i t h m .I nt h et a b l e a l g o r i t h m ,w em a yt h i n ko ft h er e g i s t e ra l w a y sc o m m e n c i n gw i t ht h e v a l u ez e r o ,a n dt h i sv a l u eb e i n gX O R e di n t ot h er e g i s t e ra f t e rt h e N ' t hb i ti t e r a t i o n .T h i sp a r a m e t e rs h o u l db es p e c i f i e da sa h e x a d e c i m a ln u m b e r . R E F I N :T h i si sab o o l e a np a r a m e t e r .I fi ti sF A L S E ,i n p u tb y t e sa r e p r o c e s s e dw i t hb i t7b e i n gt r e a t e da st h em o s ts i g n i f i c a n tb i t ( M S B )a n db i t0b e i n gt r e a t e da st h el e a s ts i g n i f i c a n tb i t .I ft h i s p a r a m e t e ri sF A L S E ,e a c hb y t ei sr e f l e c t e db e f o r eb e i n gp r o c e s s e d . R E F O U T :T h i si sab o o l e a np a r a m e t e r .I fi ti ss e tt oF A L S E ,t h e f i n a lv a l u ei nt h er e g i s t e ri sf e di n t ot h eX O R O U Ts t a g ed i r e c t l y , o t h e r w i s e ,i ft h i sp a r a m e t e ri sT R U E ,t h ef i n a lr e g i s t e rv a l u ei s r e f l e c t e df i r s t . X O R O U T :T h i si sa nW b i tv a l u et h a ts h o u l db es p e c i f i e da sa h e x a d e c i m a ln u m b e r .I ti sX O R e dt ot h ef i n a lr e g i s t e rv a l u e( a f t e r t h eR E F O U T )s t a g eb e f o r et h ev a l u ei sr e t u r n e da st h eo f f i c i a l c h e c k s u m . C H E C K :T h i sf i e l di sn o ts t r i c t l yp a r to ft h ed e f i n i t i o n ,a n d ,i n t h ee v e n to fa ni n c o n s i s t e n c yb e t w e e nt h i sf i e l da n dt h eo t h e r f i e l d ,t h eo t h e rf i e l d st a k ep r e c e d e n c e .T h i sf i e l di sac h e c k v a l u et h a tc a nb eu s e da saw e a kv a l i d a t o ro fi m p l e m e n t a t i o n so f t h ea l g o r i t h m .T h ef i e l dc o n t a i n st h ec h e c k s u mo b t a i n e dw h e nt h e
www.csm.ornl.gov /~dunigan/crc.html 23/37

12/30/12

CRC Explained

A S C I Is t r i n g" 1 2 3 4 5 6 7 8 9 "i sf e dt h r o u g ht h es p e c i f i e da l g o r i t h m ( i . e .3 1 3 2 3 3 . . .( h e x a d e c i m a l ) ) . W i t ht h e s ep a r a m e t e r sd e f i n e d ,t h em o d e lc a nn o wb eu s e dt os p e c i f ya p a r t i c u l a rC R Ca l g o r i t h me x a c t l y .H e r ei sa ne x a m p l es p e c i f i c a t i o nf o r ap o p u l a rf o r mo ft h eC R C 1 6a l g o r i t h m . N a m e :" C R C 1 6 " W i d t h :1 6 P o l y :8 0 0 5 I n i t :0 0 0 0 R e f I n :T r u e R e f O u t:T r u e X o r O u t:0 0 0 0 C h e c k :B B 3 D

1 6 .AC a t a l o go fP a r a m e t e rS e t sf o rS t a n d a r d s A tt h i sp o i n t ,Iw o u l dl i k et og i v eal i s to ft h es p e c i f i c a t i o n sf o r c o m m o n l yu s e dC R Ca l g o r i t h m s .H o w e v e r ,m o s to ft h ea l g o r i t h m st h a tI h a v ec o m ei n t oc o n t a c tw i t hs of a ra r es p e c i f i e di ns u c hav a g u ew a y t h a tt h i sh a sn o tb e e np o s s i b l e .W h a tIc a np r o v i d ei sal i s to fp o l y s f o rv a r i o u sC R Cs t a n d a r d sIh a v eh e a r do f : X 2 5 X 2 5 s t a n d a r d:1 0 2 1 r e v e r s e d:0 8 1 1 [ C R C C C I T T ,A D C C P ,S D L C / H D L C ]

C R C 1 6s t a n d a r d:8 0 0 5 C R C 1 6r e v e r s e d:4 0 0 3 C R C 3 2 :0 4 C 1 1 D B 7

[ L H A ] [ P K Z I P ,A U T O D I NI I ,E t h e r n e t ,F D D I ]

Iw o u l db ei n t e r e s t e di nh e a r i n gf r o ma n y o n eo u tt h e r ew h oc a nt i e d o w nt h ec o m p l e t es e to fm o d e lp a r a m e t e r sf o ra n yo ft h e s es t a n d a r d s . H o w e v e r ,ap r o g r a mt h a tw a sk i c k i n ga r o u n ds e e m e dt oi m p l yt h e f o l l o w i n gs p e c i f i c a t i o n s .C a na n y o n ec o n f i r mo rd e n yt h e m( o rp r o v i d e t h ec h e c kv a l u e s( w h i c hIc o u l d n ' tb eb o t h e r e dc o d i n gu pa n d c a l c u l a t i n g ) ) . N a m e :" C R C 1 6 / C I T T " W i d t h :1 6 P o l y :1 0 2 1 I n i t :F F F F R e f I n :F a l s e R e f O u t:F a l s e X o r O u t:0 0 0 0 C h e c k :?

N a m e :" X M O D E M " W i d t h :1 6 P o l y :8 4 0 8 I n i t :0 0 0 0 R e f I n :T r u e R e f O u t:T r u e


www.csm.ornl.gov /~dunigan/crc.html 24/37

12/30/12

CRC Explained

X o r O u t:0 0 0 0 C h e c k :?

N a m e :" A R C " W i d t h :1 6 P o l y :8 0 0 5 I n i t :0 0 0 0 R e f I n :T r u e R e f O u t:T r u e X o r O u t:0 0 0 0 C h e c k :? H e r ei st h es p e c i f i c a t i o nf o rt h eC R C 3 2a l g o r i t h mw h i c hi sr e p o r t e d l y u s e di nP K Z i p ,A U T O D I NI I ,E t h e r n e t ,a n dF D D I . N a m e :" C R C 3 2 " W i d t h :3 2 P o l y :0 4 C 1 1 D B 7 I n i t :F F F F F F F F R e f I n :T r u e R e f O u t:T r u e X o r O u t:F F F F F F F F C h e c k :C B F 4 3 9 2 6

1 7 .A nI m p l e m e n t a t i o no ft h eM o d e lA l g o r i t h m H e r ei sa ni m p l e m e n t a t i o no ft h em o d e la l g o r i t h mi nt h eCp r o g r a m m i n g l a n g u a g e .T h ei m p l e m e n t a t i o nc o n s i s t so fah e a d e rf i l e( . h )a n da n i m p l e m e n t a t i o nf i l e( . c ) .I fy o u ' r er e a d i n gt h i sd o c u m e n ti na s e q u e n t i a ls c r o l l e r ,y o uc a ns k i pt h i sc o d eb ys e a r c h i n gf o rt h e s t r i n g" R o l lY o u rO w n " . T oe n s u r et h a tt h ef o l l o w i n gc o d ei sw o r k i n g ,c o n f i g u r ei tf o rt h e C R C 1 6a n dC R C 3 2a l g o r i t h m sg i v e na b o v ea n de n s u r et h a tt h e yp r o d u c e t h es p e c i f i e d" c h e c k "c h e c k s u mw h e nf e dt h et e s ts t r i n g" 1 2 3 4 5 6 7 8 9 " ( s e ee a r l i e r ) . / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * S t a r to fc r c m o d e l . h * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * / / *A u t h o r:R o s sW i l l i a m s( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) . * / / *D a t e :3J u n e1 9 9 3 . * / / *S t a t u s:P u b l i cd o m a i n . * / / * * / / *D e s c r i p t i o n:T h i si st h eh e a d e r( . h )f i l ef o rt h er e f e r e n c e * / / *i m p l e m e n t a t i o no ft h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h m .F o rm o r e * / / *i n f o r m a t i o no nt h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h m ,s e et h ed o c u m e n t * / / *t i t l e d" AP a i n l e s sG u i d et oC R CE r r o rD e t e c t i o nA l g o r i t h m s "b yR o s s * / / *W i l l i a m s( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) .T h i sd o c u m e n ti sl i k e l yt ob ei n * / / *" f t p . a d e l a i d e . e d u . a u / p u b / r o c k s o f t " . * / / * * / / *N o t e :R o c k s o f ti sat r a d e m a r ko fR o c k s o f tP t yL t d ,A d e l a i d e ,A u s t r a l i a . * / / * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
www.csm.ornl.gov /~dunigan/crc.html 25/37

12/30/12

CRC Explained

/ * * / / *H o wt oU s eT h i sP a c k a g e * / / ** / / *S t e p1 :D e c l a r eav a r i a b l eo ft y p ec m _ t .D e c l a r ea n o t h e rv a r i a b l e * / / * ( p _ c ms a y )o ft y p ep _ c m _ ta n di n i t i a l i z ei tt op o i n tt ot h ef i r s t * / / * v a r i a b l e( e . g .p _ c m _ tp _ c m=& c m _ t ) . * / / * * / / *S t e p2 :A s s i g nv a l u e st ot h ep a r a m e t e rf i e l d so ft h es t r u c t u r e . * / / * I fy o ud o n ' tk n o ww h a tt oa s s i g n ,s e et h ed o c u m e n tc i t e de a r l i e r . * / / * F o re x a m p l e : * / / * p _ c m > c m _ w i d t h=1 6 ; * / / * p _ c m > c m _ p o l y =0 x 8 0 0 5 L ; * / / * p _ c m > c m _ i n i t =0 L ; * / / * p _ c m > c m _ r e f i n=T R U E ; * / / * p _ c m > c m _ r e f o t=T R U E ; * / / * p _ c m > c m _ x o r o t=0 L ; * / / * N o t e :P o l yi ss p e c i f i e dw i t h o u ti t st o pb i t( 1 8 0 0 5b e c o m e s8 0 0 5 ) . * / / * N o t e :W i d t hi so n eb i tl e s st h a nt h er a wp o l yw i d t h . * / / * * / / *S t e p3 :I n i t i a l i z et h ei n s t a n c ew i t hac a l lc m _ i n i ( p _ c m ) ; * / / * * / / *S t e p4 :P r o c e s sz e r oo rm o r em e s s a g eb y t e sb yp l a c i n gz e r oo rm o r e * / / * s u c c e s s i v ec a l l st oc m _ n x t .E x a m p l e :c m _ n x t ( p _ c m , c h ) ; * / / * * / / *S t e p5 :E x t r a c tt h eC R Cv a l u ea ta n yt i m eb yc a l l i n gc r c=c m _ c r c ( p _ c m ) ; * / / * I ft h eC R Ci sa1 6 b i tv a l u e ,i tw i l lb ei nt h eb o t t o m1 6b i t s . * / / * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * / / *D e s i g nN o t e s * / / ** / / *P O R T A B I L I T Y :T h i sp a c k a g eh a sb e e nc o d e dv e r yc o n s e r v a t i v e l ys ot h a t * / / *i tw i l lr u no na sm a n ym a c h i n e sa sp o s s i b l e .F o re x a m p l e ,a l le x t e r n a l * / / *i d e n t i f i e r sh a v eb e e nr e s t r i c t e dt o6c h a r a c t e r sa n da l li n t e r n a lo n e st o * / / *8c h a r a c t e r s .T h ep r e f i xc m( f o rC r cM o d e l )i su s e da sa na t t e m p tt oa v o i d* / / *n a m e s p a c ec o l l i s i o n s .T h i sp a c k a g ei se n d i a ni n d e p e n d e n t . * / / * * / / *E F F I C I E N C Y :T h i sp a c k a g e( a n di t si n t e r f a c e )i sn o td e s i g n e df o r * / / *s p e e d .T h ep u r p o s eo ft h i sp a c k a g ei st oa c ta saw e l l d e f i n e dr e f e r e n c e * / / *m o d e lf o rt h es p e c i f i c a t i o no fC R Ca l g o r i t h m s .I fy o uw a n ts p e e d ,c o o ku p * / / *as p e c i f i ct a b l e d r i v e ni m p l e m e n t a t i o na sd e s c r i b e di nt h ed o c u m e n tc i t e d * / / *a b o v e .T h i sp a c k a g ei sd e s i g n e df o rv a l i d a t i o no n l y ;i fy o uh a v ef o u n do r * / / *i m p l e m e n t e daC R Ca l g o r i t h ma n dw i s ht od e s c r i b ei ta sas e to fp a r a m e t e r s* / / *t ot h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h m ,y o u rC R Ca l g o r i t h mi m p l e m e n t a t i o n * / / *s h o u l db e h a v ei d e n t i c a l l yt ot h i sp a c k a g eu n d e rt h o s ep a r a m e t e r s . * / / * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *T h ef o l l o w i n g# i f n d e fe n c l o s e st h i se n t i r e* / / *h e a d e rf i l e ,r e n d e r i n gi ti n d e m p o t e n t . * / # i f n d e fC M _ D O N E # d e f i n eC M _ D O N E / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *T h ef o l l o w i n gd e f i n i t i o n sa r ee x t r a c t e df r o mm ys t y l eh e a d e rf i l ew h i c h * / / *w o u l db ec u m b e r s o m et od i s t r i b u t ew i t ht h i sp a c k a g e .T h eD O N E _ S T Y L Ei st h e* /
www.csm.ornl.gov /~dunigan/crc.html

12/30/12

CRC Explained

/ *i d e m p o t e n c es y m b o lu s e di nm ys t y l eh e a d e rf i l e . # i f n d e fD O N E _ S T Y L E t y p e d e fu n s i g n e dl o n g u l o n g ; t y p e d e fu n s i g n e d b o o l ; t y p e d e fu n s i g n e dc h a r*p _ u b y t e _ ; # i f n d e fT R U E # d e f i n eF A L S E0 # d e f i n eT R U E 1 # e n d i f / *C h a n g et ot h es e c o n dd e f i n i t i o ni fy o ud o n ' th a v ep r o t o t y p e s .* / # d e f i n eP _ ( A )A / *# d e f i n eP _ ( A )( )* / / *U n c o m m e n tt h i sd e f i n i t i o ni fy o ud o n ' th a v ev o i d .* / / *t y p e d e fi n tv o i d ;* / # e n d i f

* /

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *C R CM o d e lA b s t r a c tT y p e* / / *-* / / *T h ef o l l o w i n gt y p es t o r e st h ec o n t e x to fa ne x e c u t i n gi n s t a n c eo ft h e * / / *m o d e la l g o r i t h m .M o s to ft h ef i e l d sa r em o d e lp a r a m e t e r sw h i c hm u s tb e* / / *s e tb e f o r et h ef i r s ti n i t i a l i z i n gc a l lt oc m _ i n i . * / t y p e d e fs t r u c t { i n t c m _ w i d t h ; / *P a r a m e t e r :W i d t hi nb i t s[ 8 , 3 2 ] . * / u l o n gc m _ p o l y ; / *P a r a m e t e r :T h ea l g o r i t h m ' sp o l y n o m i a l .* / u l o n gc m _ i n i t ; / *P a r a m e t e r :I n i t i a lr e g i s t e rv a l u e . * / b o o l c m _ r e f i n ; / *P a r a m e t e r :R e f l e c ti n p u tb y t e s ? * / b o o l c m _ r e f o t ; / *P a r a m e t e r :R e f l e c to u t p u tC R C ? * / u l o n gc m _ x o r o t ; / *P a r a m e t e r :X O Rt h i st oo u t p u tC R C . * / u l o n gc m _ r e g ; / *C o n t e x t :C o n t e x td u r i n ge x e c u t i o n . }c m _ t ; t y p e d e fc m _ t* p _ c m _ t ; * /

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *F u n c t i o n sT h a tI m p l e m e n tT h eM o d e l* / / *-* / / *T h ef o l l o w i n gf u n c t i o n sa n i m a t et h ec m _ ta b s t r a c t i o n .* / v o i dc m _ i n iP _ ( ( p _ c m _ tp _ c m ) ) ; / *I n i t i a l i z e st h ea r g u m e n tC R Cm o d e li n s t a n c e . * / / *A l lp a r a m e t e rf i e l d sm u s tb es e tb e f o r ec a l l i n gt h i s .* / v o i dc m _ n x tP _ ( ( p _ c m _ tp _ c m , i n tc h ) ) ; / *P r o c e s s e sas i n g l em e s s a g eb y t e[ 0 , 2 5 5 ] .* / v o i dc m _ b l kP _ ( ( p _ c m _ tp _ c m , p _ u b y t e _b l k _ a d r , u l o n gb l k _ l e n ) ) ; / *P r o c e s s e sab l o c ko fm e s s a g eb y t e s .* /


www.csm.ornl.gov /~dunigan/crc.html 27/37

u l o n gc m _ c r cP _ ( ( p _ c m _ tp _ c m ) ) ; / *R e t u r n st h eC R Cv a l u ef o rt h em e s s a g eb y t e sp r o c e s s e ds of a r .* / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *F u n c t i o n sF o rT a b l eC a l c u l a t i o n* / / *-* / / *T h ef o l l o w i n gf u n c t i o nc a nb eu s e dt oc a l c u l a t eaC R Cl o o k u pt a b l e . / *I tc a na l s ob eu s e da tr u n t i m et oc r e a t eo rc h e c ks t a t i ct a b l e s . u l o n gc m _ t a bP _ ( ( p _ c m _ tp _ c m , i n ti n d e x ) ) ; / *R e t u r n st h ei ' t he n t r yf o rt h el o o k u pt a b l ef o rt h es p e c i f i e da l g o r i t h m . / *T h ef u n c t i o ne x a m i n e st h ef i e l d sc m _ w i d t h ,c m _ p o l y ,c m _ r e f i n ,a n dt h e / *a r g u m e n tt a b l ei n d e xi nt h er a n g e[ 0 , 2 5 5 ]a n dr e t u r n st h et a b l ee n t r yi n / *t h eb o t t o mc m _ w i d t hb y t e so ft h er e t u r nv a l u e .

* / * /

* / * / * / * /

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *E n do ft h eh e a d e rf i l ei d e m p o t e n c e# i f n d e f* / # e n d i f / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * E n do fc r c m o d e l . h * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * S t a r to fc r c m o d e l . c * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * / / *A u t h o r:R o s sW i l l i a m s( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) . * / / *D a t e :3J u n e1 9 9 3 . * / / *S t a t u s:P u b l i cd o m a i n . * / / * * / / *D e s c r i p t i o n:T h i si st h ei m p l e m e n t a t i o n( . c )f i l ef o rt h er e f e r e n c e * / / *i m p l e m e n t a t i o no ft h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h m .F o rm o r e * / / *i n f o r m a t i o no nt h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h m ,s e et h ed o c u m e n t * / / *t i t l e d" AP a i n l e s sG u i d et oC R CE r r o rD e t e c t i o nA l g o r i t h m s "b yR o s s * / / *W i l l i a m s( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) .T h i sd o c u m e n ti sl i k e l yt ob ei n * / / *" f t p . a d e l a i d e . e d u . a u / p u b / r o c k s o f t " . * / / * * / / *N o t e :R o c k s o f ti sat r a d e m a r ko fR o c k s o f tP t yL t d ,A d e l a i d e ,A u s t r a l i a . * / / * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * / / *I m p l e m e n t a t i o nN o t e s * / / ** / / *T oa v o i di n c o n s i s t e n c i e s ,t h es p e c i f i c a t i o no fe a c hf u n c t i o ni sn o te c h o e d* / / *h e r e .S e et h eh e a d e rf i l ef o rad e s c r i p t i o no ft h e s ef u n c t i o n s . * / / *T h i sp a c k a g ei sl i g h to nc h e c k i n gb e c a u s eIw a n tt ok e e pi ts h o r ta n d * / / *s i m p l ea n dp o r t a b l e( i . e .i tw o u l db et o om e s s yt od i s t r i b u t em ye n t i r e * / / *Cc u l t u r e( e . g .a s s e r t i o n sp a c k a g e )w i t ht h i sp a c k a g e . * / / * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / # i n c l u d e" c r c m o d e l . h "
28/37

12/30/12

CRC Explained

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *T h ef o l l o w i n gd e f i n i t i o n sm a k et h ec o d em o r er e a d a b l e .* / # d e f i n eB I T M A S K ( X )( 1 L< <( X ) ) # d e f i n eM A S K 3 20 x F F F F F F F F L # d e f i n eL O C A Ls t a t i c / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / L O C A Lu l o n gr e f l e c tP _ ( ( u l o n gv , i n tb ) ) ; L O C A Lu l o n gr e f l e c t( v , b ) / *R e t u r n st h ev a l u evw i t ht h eb o t t o mb[ 0 , 3 2 ]b i t sr e f l e c t e d .* / / *E x a m p l e :r e f l e c t ( 0 x 3 e 2 3 L , 3 )= =0 x 3 e 2 6 * / u l o n gv ; i n t b ; { i n t i ; u l o n gt=v ; f o r( i = 0 ;i < b ;i + + ) { i f( t&1 L ) v | = B I T M A S K ( ( b 1 ) i ) ; e l s e v & =~ B I T M A S K ( ( b 1 ) i ) ; t > > = 1 ; } r e t u r nv ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / L O C A Lu l o n gw i d m a s kP _ ( ( p _ c m _ t ) ) ; L O C A Lu l o n gw i d m a s k( p _ c m ) / *R e t u r n sal o n g w o r dw h o s ev a l u ei s( 2 ^ p _ c m > c m _ w i d t h ) 1 . * / / *T h et r i c ki st od ot h i sp o r t a b l y( e . g .w i t h o u td o i n g< < 3 2 ) .* / p _ c m _ tp _ c m ; { r e t u r n( ( ( 1 L < < ( p _ c m > c m _ w i d t h 1 ) ) 1 L ) < < 1 ) | 1 L ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / v o i dc m _ i n i( p _ c m ) p _ c m _ tp _ c m ; { p _ c m > c m _ r e g=p _ c m > c m _ i n i t ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / v o i dc m _ n x t( p _ c m , c h ) p _ c m _ tp _ c m ; i n t c h ; { i n t i ;
www.csm.ornl.gov /~dunigan/crc.html 29/37

12/30/12

CRC Explained

u l o n gu c h =( u l o n g )c h ; u l o n gt o p b i t=B I T M A S K ( p _ c m > c m _ w i d t h 1 ) ; i f( p _ c m > c m _ r e f i n )u c h=r e f l e c t ( u c h , 8 ) ; p _ c m > c m _ r e g^ =( u c h< <( p _ c m > c m _ w i d t h 8 ) ) ; f o r( i = 0 ;i < 8 ;i + + ) { i f( p _ c m > c m _ r e g&t o p b i t ) p _ c m > c m _ r e g=( p _ c m > c m _ r e g< <1 )^p _ c m > c m _ p o l y ; e l s e p _ c m > c m _ r e g< < =1 ; p _ c m > c m _ r e g& =w i d m a s k ( p _ c m ) ; } } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / v o i dc m _ b l k( p _ c m , b l k _ a d r , b l k _ l e n ) p _ c m _ t p _ c m ; p _ u b y t e _b l k _ a d r ; u l o n g b l k _ l e n ; { w h i l e( b l k _ l e n )c m _ n x t ( p _ c m , * b l k _ a d r + + ) ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / u l o n gc m _ c r c( p _ c m ) p _ c m _ tp _ c m ; { i f( p _ c m > c m _ r e f o t ) r e t u r np _ c m > c m _ x o r o t^r e f l e c t ( p _ c m > c m _ r e g , p _ c m > c m _ w i d t h ) ; e l s e r e t u r np _ c m > c m _ x o r o t^p _ c m > c m _ r e g ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / u l o n gc m _ t a b( p _ c m , i n d e x ) p _ c m _ tp _ c m ; i n t i n d e x ; { i n t i ; u l o n gr ; u l o n gt o p b i t=B I T M A S K ( p _ c m > c m _ w i d t h 1 ) ; u l o n gi n b y t e=( u l o n g )i n d e x ; i f( p _ c m > c m _ r e f i n )i n b y t e=r e f l e c t ( i n b y t e , 8 ) ; r=i n b y t e< <( p _ c m > c m _ w i d t h 8 ) ; f o r( i = 0 ;i < 8 ;i + + ) i f( r&t o p b i t ) r=( r< <1 )^p _ c m > c m _ p o l y ; e l s e r < < = 1 ; i f( p _ c m > c m _ r e f i n )r=r e f l e c t ( r , p _ c m > c m _ w i d t h ) ; r e t u r nr&w i d m a s k ( p _ c m ) ; }
www.csm.ornl.gov /~dunigan/crc.html 30/37

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * E n do fc r c m o d e l . c * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

1 8 .R o l lY o u rO w nT a b l e D r i v e nI m p l e m e n t a t i o n D e s p i t ea l lt h ef u s sI ' v em a d ea b o u tu n d e r s t a n d i n ga n dd e f i n i n gC R C a l g o r i t h m s ,t h em e c h a n i c so ft h e i rh i g h s p e e di m p l e m e n t a t i o nr e m a i n s t r i v i a l .T h e r ea r er e a l l yo n l yt w of o r m s :n o r m a la n dr e f l e c t e d .N o r m a l s h i f t st ot h el e f ta n dc o v e r st h ec a s eo fa l g o r i t h m sw i t hR e f i n = F A L S E a n dR e f o t = F A L S E .R e f l e c t e ds h i f t st ot h er i g h ta n dc o v e r sa l g o r i t h m s w i t hb o t ht h o s ep a r a m e t e r st r u e .( I fy o uw a n to n ep a r a m e t e rt r u ea n d t h eo t h e rf a l s e ,y o u ' l lh a v et of i g u r ei to u tf o ry o u r s e l f ! )T h e p o l y n o m i a li se m b e d d e di nt h el o o k u pt a b l e( t ob ed i s c u s s e d ) .T h e o t h e rp a r a m e t e r s ,I n i ta n dX o r O tc a nb ec o d e da sm a c r o s .H e r ei st h e 3 2 b i tn o r m a lf o r m( t h e1 6 b i tf o r mi ss i m i l a r ) . u n s i g n e dl o n gc r c _ n o r m a l( ) ; u n s i g n e dl o n gc r c _ n o r m a l( b l k _ a d r , b l k _ l e n ) u n s i g n e dc h a r* b l k _ a d r ; u n s i g n e dl o n g b l k _ l e n ; { u n s i g n e dl o n gc r c=I N I T ; w h i l e( b l k _ l e n ) c r c=c r c t a b l e [ ( ( c r c > > 2 4 )^* b l k _ a d r + + )&0 x F F L ]^( c r c< <8 ) ; r e t u r nc r c^X O R O T ; } H e r ei st h er e f l e c t e df o r m : u n s i g n e dl o n gc r c _ r e f l e c t e d( ) ; u n s i g n e dl o n gc r c _ r e f l e c t e d( b l k _ a d r , b l k _ l e n ) u n s i g n e dc h a r* b l k _ a d r ; u n s i g n e dl o n g b l k _ l e n ; { u n s i g n e dl o n gc r c=I N I T _ R E F L E C T E D ; w h i l e( b l k _ l e n ) c r c=c r c t a b l e [ ( c r c^* b l k _ a d r + + )&0 x F F L ]^( c r c> >8 ) ) ; r e t u r nc r c^X O R O T ; } N o t e :Ih a v ec a r e f u l l yc h e c k e dt h ea b o v et w oc o d ef r a g m e n t s ,b u tI h a v e n ' ta c t u a l l yc o m p i l e do rt e s t e dt h e m .T h i ss h o u l d n ' tm a t t e rt o y o u ,a s ,n om a t t e rW H A Ty o uc o d e ,y o uw i l la l w a y sb ea b l et ot e l li f y o uh a v eg o ti tr i g h tb yr u n n i n gw h a t e v e ry o uh a v ec r e a t e da g a i n s tt h e r e f e r e n c em o d e lg i v e ne a r l i e r .T h ec o d ef r a g m e n t sa b o v ea r er e a l l y j u s tar o u g hg u i d e .T h er e f e r e n c em o d e li st h ed e f i n i t i v eg u i d e . N o t e :I fy o ud o n ' tc a r em u c ha b o u ts p e e d ,j u s tu s et h er e f e r e n c em o d e l c o d e !

1 9 .G e n e r a t i n gAL o o k u pT a b l e T h eo n l yc o m p o n e n tm i s s i n gf r o mt h en o r m a la n dr e v e r s e dc o d ef r a g m e n t s
31/37

12/30/12

CRC Explained

i nt h ep r e v i o u ss e c t i o ni st h el o o k u pt a b l e .T h el o o k u pt a b l ec a nb e c o m p u t e da tr u nt i m eu s i n gt h ec m _ t a bf u n c t i o no ft h em o d e lp a c k a g e g i v e ne a r l i e r ,o rc a nb ep r e c o m p u t e da n di n s e r t e di n t ot h eCp r o g r a m . I ne i t h e rc a s e ,i ts h o u l db en o t e dt h a tt h el o o k u pt a b l ed e p e n d so n l y o nt h eP O L Ya n dR e f I n( a n dR e f O t )p a r a m e t e r s .B a s i c a l l y ,t h e p o l y n o m i a ld e t e r m i n e st h et a b l e ,b u ty o uc a ng e n e r a t ear e f l e c t e d t a b l et o oi fy o uw a n tt ou s et h er e f l e c t e df o r ma b o v e . T h ef o l l o w i n gp r o g r a mg e n e r a t e sa n yd e s i r e d1 6 b i to r3 2 b i tl o o k u p t a b l e .S k i pt ot h ew o r d" S u m m a r y "i fy o uw a n tt os k i po v e rt h i sc o d e .

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * S t a r to fc r c t a b l e . c * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * / / *A u t h o r :R o s sW i l l i a m s( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) . * / / *D a t e :3J u n e1 9 9 3 . * / / *V e r s i o n:1 . 0 . * / / *S t a t u s :P u b l i cd o m a i n . * / / * * / / *D e s c r i p t i o n:T h i sp r o g r a mw r i t e saC R Cl o o k u pt a b l e( s u i t a b l ef o r * / / *i n c l u s i o ni naCp r o g r a m )t oad e s i g n a t e do u t p u tf i l e .T h ep r o g r a mc a nb e * / / *s t a t i c a l l yc o n f i g u r e dt op r o d u c ea n yt a b l ec o v e r e db yt h eR o c k s o f t ^ t m * / / *M o d e lC R CA l g o r i t h m .F o rm o r ei n f o r m a t i o no nt h eR o c k s o f t ^ t mM o d e lC R C * / / *A l g o r i t h m ,s e et h ed o c u m e n tt i t l e d" AP a i n l e s sG u i d et oC R CE r r o r * / / *D e t e c t i o nA l g o r i t h m s "b yR o s sW i l l i a m s( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) .T h i s* / / *d o c u m e n ti sl i k e l yt ob ei n" f t p . a d e l a i d e . e d u . a u / p u b / r o c k s o f t " . * / / * * / / *N o t e :R o c k s o f ti sat r a d e m a r ko fR o c k s o f tP t yL t d ,A d e l a i d e ,A u s t r a l i a . * / / * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / # i n c l u d e< s t d i o . h > # i n c l u d e< s t d l i b . h > # i n c l u d e" c r c m o d e l . h " / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *T A B L EP A R A M E T E R S * / / *= = = = = = = = = = = = = = = = * / / *T h ef o l l o w i n gp a r a m e t e r se n t i r e l yd e t e r m i n et h et a b l et ob eg e n e r a t e d .Y o u* / / *s h o u l dn e e dt om o d i f yo n l yt h ed e f i n i t i o n si nt h i ss e c t i o nb e f o r er u n n i n g * / / *t h i sp r o g r a m . * / / * * / / * T B _ F I L E i st h en a m eo ft h eo u t p u tf i l e . * / / * T B _ W I D T Hi st h et a b l ew i d t hi nb y t e s( e i t h e r2o r4 ) . * / / * T B _ P O L Y i st h e" p o l y n o m i a l " ,w h i c hm u s tb eT B _ W I D T Hb y t e sw i d e . * / / * T B _ R E V E Ri n d i c a t e sw h e t h e rt h et a b l ei st ob er e v e r s e d( r e f l e c t e d ) . * / / * * / / *E x a m p l e : * / / * * / / * # d e f i n eT B _ F I L E " c r c t a b l e . o u t " * / / * # d e f i n eT B _ W I D T H 2 * / / * # d e f i n eT B _ P O L Y 0 x 8 0 0 5 L * / / * # d e f i n eT B _ R E V E R T R U E * /
www.csm.ornl.gov /~dunigan/crc.html 32/37

12/30/12

CRC Explained

# d e f i n eT B _ F I L E # d e f i n eT B _ W I D T H # d e f i n eT B _ P O L Y # d e f i n eT B _ R E V E R

" c r c t a b l e . o u t " 4 0 x 0 4 C 1 1 D B 7 L T R U E

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / *M i s c e l l a n e o u sd e f i n i t i o n s .* / # d e f i n eL O C A Ls t a t i c F I L E* o u t f i l e ; # d e f i n eW R ( X )f p r i n t f ( o u t f i l e , ( X ) ) # d e f i n eW P ( X , Y )f p r i n t f ( o u t f i l e , ( X ) , ( Y ) ) / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / L O C A Lv o i dc h k _ e r rP _ ( ( c h a r* ) ) ; L O C A Lv o i dc h k _ e r r( m e s s ) / *I fm e s si sn o n e m p t y ,w r i t ei to u ta n da b o r t .O t h e r w i s e ,c h e c kt h ee r r o r / *s t a t u so fo u t f i l ea n da b o r ti fa ne r r o rh a so c c u r r e d . c h a r* m e s s ; { i f( m e s s [ 0 ]! =0 ){ p r i n t f ( " % s \ n " , m e s s ) ;e x i t ( E X I T _ F A I L U R E ) ; } i f( f e r r o r ( o u t f i l e ) ){ p e r r o r ( " c h k _ e r r " ) ; e x i t ( E X I T _ F A I L U R E ) ; } }

* / * /

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / L O C A Lv o i dc h k p a r a mP _ ( ( v o i d ) ) ; L O C A Lv o i dc h k p a r a m( ) { i f( ( T B _ W I D T H! =2 )& &( T B _ W I D T H! =4 ) ) c h k _ e r r ( " c h k p a r a m :W i d t hp a r a m e t e ri si l l e g a l . " ) ; i f( ( T B _ W I D T H= =2 )& &( T B _ P O L Y&0 x F F F F 0 0 0 0 L ) ) c h k _ e r r ( " c h k p a r a m :P o l yp a r a m e t e ri st o ow i d e . " ) ; i f( ( T B _ R E V E R! =F A L S E )& &( T B _ R E V E R! =T R U E ) ) c h k _ e r r ( " c h k p a r a m :R e v e r s ep a r a m e t e ri sn o tb o o l e a n . " ) ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / L O C A Lv o i dg e n t a b l eP _ ( ( v o i d ) ) ; L O C A Lv o i dg e n t a b l e( ) { W R ( " / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / \ n " ) ; W R ( " / * * / \ n " ) ; W R ( " / *C R CL O O K U PT A B L E * / \ n " ) ; W R ( " / *= = = = = = = = = = = = = = = = * / \ n " ) ; W R ( " / *T h ef o l l o w i n gC R Cl o o k u pt a b l ew a sg e n e r a t e da u t o m a g i c a l l y * / \ n " ) ; W R ( " / *b yt h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h mT a b l eG e n e r a t i o n * / \ n " ) ; W R ( " / *P r o g r a mV 1 . 0u s i n gt h ef o l l o w i n gm o d e lp a r a m e t e r s : * / \ n " ) ; W R ( " / * * / \ n " ) ; W P ( " / * W i d t h :% 1 l ub y t e s . * / \ n " , ( u l o n g )T B _ W I D T H ) ; i f( T B _ W I D T H= =2 ) W P ( " / * P o l y :0 x % 0 4 l X * / \ n " ,
www.csm.ornl.gov /~dunigan/crc.html 33/37

12/30/12

CRC Explained

( u l o n g )T B _ P O L Y ) ; e l s e W P ( " / * P o l y :0 x % 0 8 l X L * / \ n " , ( u l o n g )T B _ P O L Y ) ; i f( T B _ R E V E R ) W R ( " / * R e v e r s e:T R U E . * / \ n " ) ; e l s e W R ( " / * R e v e r s e:F A L S E . * / \ n " ) ; W R ( " / * * / \ n " ) ; W R ( " / *F o rm o r ei n f o r m a t i o no nt h eR o c k s o f t ^ t mM o d e lC R CA l g o r i t h m , * / \ n " ) ; W R ( " / *s e et h ed o c u m e n tt i t l e d\ " AP a i n l e s sG u i d et oC R CE r r o r * / \ n " ) ; W R ( " / *D e t e c t i o nA l g o r i t h m s \ "b yR o s sW i l l i a m s * / \ n " ) ; W R ( " / *( r o s s @ g u e s t . a d e l a i d e . e d u . a u . ) .T h i sd o c u m e n ti sl i k e l yt ob e * / \ n " ) ; W R ( " / *i nt h eF T Pa r c h i v e\ " f t p . a d e l a i d e . e d u . a u / p u b / r o c k s o f t \ " . * / \ n " ) ; W R ( " / * * / \ n " ) ; W R ( " / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / \ n " ) ; W R ( " \ n " ) ; s w i t c h( T B _ W I D T H ) { c a s e2 :W R ( " u n s i g n e ds h o r tc r c t a b l e [ 2 5 6 ]= \ n { \ n " ) ;b r e a k ; c a s e4 :W R ( " u n s i g n e dl o n g c r c t a b l e [ 2 5 6 ]= \ n { \ n " ) ;b r e a k ; d e f a u l t :c h k _ e r r ( " g e n t a b l e :T B _ W I D T Hi si n v a l i d . " ) ; } c h k _ e r r ( " " ) ; { i n ti ; c m _ tc m ; c h a r* f o r m =( T B _ W I D T H = = 2 )?" 0 x % 0 4 l X ":" 0 x % 0 8 l X L " ; i n t p e r l i n e=( T B _ W I D T H = = 2 )?8:4 ; c m . c m _ w i d t h=T B _ W I D T H * 8 ; c m . c m _ p o l y =T B _ P O L Y ; c m . c m _ r e f i n=T B _ R E V E R ; f o r( i = 0 ;i < 2 5 6 ;i + + ) { W R ( "" ) ; W P ( f o r m , ( u l o n g )c m _ t a b ( & c m , i ) ) ; i f( i! =2 5 5 )W R ( " , " ) ; i f( ( ( i + 1 )%p e r l i n e )= =0 )W R ( " \ n " ) ; c h k _ e r r ( " " ) ; } W R ( " } ; \ n " ) ; W R ( " \ n " ) ; W R ( " / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / \ n " ) ; W R ( " / * E n do fC R CL o o k u pT a b l e * / \ n " ) ; W R ( " / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / \ n " ) ; W R ( " " ) ; c h k _ e r r ( " " ) ; } } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / m a i n( )
www.csm.ornl.gov /~dunigan/crc.html 34/37

12/30/12

CRC Explained

{ p r i n t f ( " \ n " ) ; p r i n t f ( " R o c k s o f t ^ t mM o d e lC R CA l g o r i t h mT a b l eG e n e r a t i o nP r o g r a mV 1 . 0 \ n " ) ; p r i n t f ( " \ n " ) ; p r i n t f ( " O u t p u tf i l ei s\ " % s \ " . \ n " , T B _ F I L E ) ; c h k p a r a m ( ) ; o u t f i l e=f o p e n ( T B _ F I L E , " w " ) ;c h k _ e r r ( " " ) ; g e n t a b l e ( ) ; i f( f c l o s e ( o u t f i l e )! =0 ) c h k _ e r r ( " m a i n :C o u l d n ' tc l o s eo u t p u tf i l e . " ) ; p r i n t f ( " \ n S U C C E S S :T h et a b l eh a sb e e ns u c c e s s f u l l yw r i t t e n . \ n " ) ; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * E n do fc r c t a b l e . c * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / 2 0 .S u m m a r y T h i sd o c u m e n th a sp r o v i d e dad e t a i l e de x p l a n a t i o no fC R Ca l g o r i t h m s e x p l a i n i n gt h e i rt h e o r ya n ds t e p p i n gt h r o u g hi n c r e a s i n g l y s o p h i s t i c a t e di m p l e m e n t a t i o n sr a n g i n gf r o ms i m p l eb i ts h i f t i n gt h r o u g h t ob y t e a t a t i m et a b l e d r i v e ni m p l e m e n t a t i o n s .T h ev a r i o u s i m p l e m e n t a t i o n so fd i f f e r e n tC R Ca l g o r i t h m st h a tm a k et h e mc o n f u s i n g t od e a lw i t hh a v eb e e ne x p l a i n e d .Ap a r a m e t e r i z e dm o d e la l g o r i t h mh a s b e e nd e s c r i b e dt h a tc a nb eu s e dt op r e c i s e l yd e f i n eap a r t i c u l a rC R C a l g o r i t h m ,a n dar e f e r e n c ei m p l e m e n t a t i o np r o v i d e d .F i n a l l y ,ap r o g r a m t og e n e r a t eC R Ct a b l e sh a sb e e np r o v i d e d . 2 1 .C o r r e c t i o n s I fy o ut h i n kt h a ta n yp a r to ft h i sd o c u m e n ti su n c l e a ro ri n c o r r e c t , o rh a v ea n yo t h e ri n f o r m a t i o n ,o rs u g g e s t i o n so nh o wt h i sd o c u m e n t c o u l db ei m p r o v e d ,p l e a s ec o n t e x tt h ea u t h o r .I np a r t i c u l a r ,Iw o u l d l i k et oh e a rf r o ma n y o n ew h oc a np r o v i d eR o c k s o f t ^ t mM o d e lC R C A l g o r i t h mp a r a m e t e r sf o rs t a n d a r da l g o r i t h m so u tt h e r e . A .G l o s s a r y C H E C K S U M-An u m b e rt h a th a sb e e nc a l c u l a t e da saf u n c t i o no fs o m e m e s s a g e .T h el i t e r a li n t e r p r e t a t i o no ft h i sw o r d" C h e c k S u m "i n d i c a t e s t h a tt h ef u n c t i o ns h o u l di n v o l v es i m p l ya d d i n gu pt h eb y t e si nt h e m e s s a g e .P e r h a p st h i sw a sw h a te a r l yc h e c k s u m sw e r e .T o d a y ,h o w e v e r , a l t h o u g hm o r es o p h i s t i c a t e df o r m u l a ea r eu s e d ,t h et e r m" c h e c k s u m "i s s t i l lu s e d . C R C-T h i ss t a n d sf o r" C y c l i cR e d u n d a n c yC o d e " .W h e r e a st h et e r m " c h e c k s u m "s e e m st ob eu s e dt or e f e rt oa n yn o n c r y p t o g r a p h i cc h e c k i n g i n f o r m a t i o nu n i t ,t h et e r m" C R C "s e e m st ob er e s e r v e do n l yf o r a l g o r i t h m st h a ta r eb a s e do nt h e" p o l y n o m i a l "d i v i s i o ni d e a . G-T h i ss y m b o li su s e di nt h i sd o c u m e n tt or e p r e s e n tt h eP o l y . M E S S A G E-T h ei n p u td a t ab e i n gc h e c k s u m m e d .T h i si su s u a l l ys t r u c t u r e d a sas e q u e n c eo fb y t e s .W h e t h e rt h et o pb i to rt h eb o t t o mb i to fe a c h b y t ei st r e a t e da st h em o s ts i g n i f i c a n to rl e a s ts i g n i f i c a n ti sa p a r a m e t e ro fC R Ca l g o r i t h m s .
www.csm.ornl.gov /~dunigan/crc.html 35/37

P O L Y-T h i si sm yf r i e n d l yt e r mf o rt h ep o l y n o m i a lo faC R C . P O L Y N O M I A L-T h e" p o l y n o m i a l "o faC R Ca l g o r i t h mi ss i m p l yt h ed i v i s o r i nt h ed i v i s i o ni m p l e m e n t i n gt h eC R Ca l g o r i t h m . R E F L E C T-Ab i n a r yn u m b e ri sr e f l e c t e db ys w a p p i n ga l lo fi t sb i t s a r o u n dt h ec e n t r a lp o i n t .F o re x a m p l e ,1 1 0 1i st h er e f l e c t i o no f1 0 1 1 . R O C K S O F T ^ T MM O D E LC R CA L G O R I T H M-Ap a r a m e t e r i z e da l g o r i t h mw h o s e p u r p o s ei st oa c ta sas o l i dr e f e r e n c ef o rd e s c r i b i n gC R Ca l g o r i t h m s . T y p i c a l l yC R Ca l g o r i t h m sa r es p e c i f i e db yq u o t i n gap o l y n o m i a l . H o w e v e r ,i no r d e rt oc o n s t r u c tap r e c i s ei m p l e m e n t a t i o n ,o n ea l s o n e e d st ok n o wi n i t i a l i z a t i o nv a l u e sa n ds oo n . W I D T H-T h ew i d t ho faC R Ca l g o r i t h mi st h ew i d t ho fi t sp o l y n o m i c a l m i n u so n e .F o re x a m p l e ,i ft h ep o l y n o m i a li s1 1 0 1 0 ,t h ew i d t hw o u l db e 4b i t s .T h ew i d t hi su s u a l l ys e tt ob eam u l t i p l eo f8b i t s . B .R e f e r e n c e s [ G r i f f i t h s 8 7 ]G r i f f i t h s ,G . ,C a r l y l eS t o n e s ,G . ," T h eT e a L e a fR e a d e r A l g o r i t h m :A nE f f i c i e n tI m p l e m e n t a t i o no fC R C 1 6a n dC R C 3 2 " , C o m m u n i c a t i o n so ft h eA C M ,3 0 ( 7 ) ,p p . 6 1 7 6 2 0 .C o m m e n t :T h i sp a p e r d e s c r i b e sah i g h s p e e dt a b l e d r i v e ni m p l e m e n t a t i o no fC R Ca l g o r i t h m s . T h et e c h n i q u es e e m st ob eat o u c hm e s s y ,a n di ss u p e r c e d e db yt h e S a r w e t ea l g o r i t h m . [ K n u t h 8 1 ]K n u t h ,D . E . ," T h eA r to fC o m p u t e rP r o g r a m m i n g " ,V o l u m e2 : S e m i n u m e r i c a lA l g o r i t h m s ,S e c t i o n4 . 6 . [ N e l s o n9 1 ]N e l s o n ,M . ," T h eD a t aC o m p r e s s i o nB o o k " ,M & TB o o k s ,( 5 0 1 G a l v e s t o nD r i v e ,R e d w o o dC i t y ,C A9 4 0 6 3 ) ,1 9 9 1 ,I S B N :1 5 5 8 5 1 2 1 4 4 . C o m m e n t :I fy o uw a n tt os e ear e a li m p l e m e n t a t i o no far e a l3 2 b i t c h e c k s u ma l g o r i t h m ,l o o ko np a g e s4 4 0 ,a n d4 4 6 4 4 8 . [ S a r w a t e 8 8 ]S a r w a t e ,D . V . ," C o m p u t a t i o no fC y c l i cR e d u n d a n c yC h e c k s v i aT a b l eL o o k U p " ,C o m m u n i c a t i o n so ft h eA C M ,3 1 ( 8 ) ,p p . 1 0 0 8 1 0 1 3 . C o m m e n t :T h i sp a p e rd e s c r i b e sah i g h s p e e dt a b l e d r i v e ni m p l e m e n t a t i o n f o rC R Ca l g o r i t h m st h a ti ss u p e r i o rt ot h et e a l e a fa l g o r i t h m . A l t h o u g ht h i sp a p e rd e s c r i b e st h et e c h n i q u eu s e db ym o s tm o d e r nC R C i m p l e m e n t a t i o n s ,If o u n dt h ea p p e n d i xo ft h i sp a p e r( w h e r ea l lt h e g o o ds t u f fi s )d i f f i c u l tt ou n d e r s t a n d . [ T a n e n b a u m 8 1 ]T a n e n b a u m ,A . S . ," C o m p u t e rN e t w o r k s " ,P r e n t i c eH a l l , 1 9 8 1 ,I S B N :0 1 3 1 6 4 6 9 9 0 .C o m m e n t :S e c t i o n3 . 5 . 3o np a g e s1 2 8t o1 3 2 p r o v i d e sav e r yc l e a rd e s c r i p t i o no fC R Cc o d e s .H o w e v e r ,i td o e sn o t d e s c r i b et a b l e d r i v e ni m p l e m e n t a t i o nt e c h n i q u e s .

C .R e f e r e n c e sIH a v eD e t e c t e dB u tH a v e n ' tY e tS i g h t e d B o u d r e a u ,S t e e n ," C y c l i cR e d u n d a n c yC h e c k i n gb yP r o g r a m , "A F I P S P r o c e e d i n g s ,V o l .3 9 ,1 9 7 1 . D a v i e s ,B a r b e r ," C o m p u t e rN e t w o r k sa n dT h e i rP r o t o c o l s , "J .W i l e y& S o n s ,1 9 7 9 .

12/30/12

CRC Explained

H i g g i n s o n ,K i r s t e i n ," O nt h eC o m p u t a t i o no fC y c l i cR e d u n d a n c yC h e c k s b yP r o g r a m , "T h eC o m p u t e rJ o u r n a l( B r i t i s h ) ,V o l .1 6 ,N o .1 ,F e b1 9 7 3 . M c N a m a r a ,J .E . ," T e c h n i c a lA s p e c t so fD a t aC o m m u n i c a t i o n , "2 n d E d i t i o n ,D i g i t a lP r e s s ,B e d f o r d ,M a s s a c h u s e t t s ,1 9 8 2 . M a r t o na n dF r a m b s ," AC y c l i cR e d u n d a n c yC h e c k i n g( C R C )A l g o r i t h m , " H o n e y w e l lC o m p u t e rJ o u r n a l ,V o l .5 ,N o .3 ,1 9 7 1 . N e l s o nM . ," F i l ev e r i f i c a t i o nu s i n gC R C " ,D rD o b b sJ o u r n a l ,M a y1 9 9 2 , p p . 6 4 6 7 . R a m a b a d r a nT . V . ,G a i t o n d eS . S . ," At u t o r i a lo nC R Cc o m p u t a t i o n s " ,I E E E M i c r o ,A u g1 9 8 8 . S c h w a d e r e rW . D . ," C R CC a l c u l a t i o n " ,A p r i l8 5P CT e c hJ o u r n a l , p p . 1 1 8 1 3 3 . W a r dR . K ,T a b a n d e hM . ," E r r o rC o r r e c t i o na n dD e t e c t i o n ,AG e o m e t r i c A p p r o a c h "T h eC o m p u t e rJ o u r n a l ,V o l .2 7 ,N o .3 ,1 9 8 4 ,p p . 2 4 6 2 5 3 . W e c k e r ,S . ," AT a b l e L o o k u pA l g o r i t h mf o rS o f t w a r eC o m p u t a t i o no f C y c l i cR e d u n d a n c yC h e c k( C R C ) , "D i g i t a lE q u i p m e n tC o r p o r a t i o n m e m o r a n d u m ,1 9 7 4 . < E n do fD o c u m e n t > < i c d l j @ a s u a c a d . b i t n e t > < i c d l j @ a s u v m . i n r e . a s u . e d u > D a v eJ a n e c e kE l e c t r o n i cF i e l dS e r v i c e T e c h .c / oI . R . M .T e c hS h o p 0 2 0 1 ,A S U , T e m p e ,A r i z o n a 8 5 2 8 7 0 2 0 1: 6 0 2 9 6 5 9 1 2 6 o rh o m e: 6 0 2 8 3 2 7 1 2 7

www.csm.ornl.gov /~dunigan/crc.html

37/37

Вам также может понравиться