Checksums are used among other places in IP transfers while CRCs are often used in internal file integrity checks.
Checksum is a simple addition of all the bytes or words or longs etc. CRC is much more sophisticated and as a result, much more compute intensive and much more reliable at detecting transmition errors. So, which is it? Does cksum produce a checksum or a CRC? I suspect the former as CRC needs more input paramaters in the versions I am familiar with. The most simple way to calculate a checksum is by exclusive-oring adding without carry all bytes.
The next step is by adding them all up. Both methods sometimes use a preset value or a complementing algorithm for mathematical reliability reasons. A more sophisticated calculation is a CRC cyclic redundancy check. If done cleverly it is almost as fast as adding up the bytes. If we want to make things even more reliable we use MD5 or SHA1 checksums ranging from bytes up to several kilobytes. Add up all the numbers including the checksum value and you get 0x00 in the last 8 bits of the accumulator.
Compare that to CRCs where there is no summation. Furthermore, if cksum is really performing a CRC then you should indicate the width of the CRC and the polynomial being used. How is a XOR different from adding? How is shifting different from multiplying? CRC is just a calculation, no different from other methods. It makes no sense to differentiate between calculation methods other than some are stronger than others.
The choice of polynomial depends on your needs. You need to balance performance speed , reliability and security. Save my name, email, and website in this browser for the next time I comment. Notify me of followup comments via e-mail. All rights reserved Terms of Service.
The purpose of these two c-bit constants is similar to the final bit inversion step added to the sum-of-bytes checksum algorithm. Each of these parameters helps eliminate one very special, though perhaps not uncommon, class of ordinarily undetectable difference. In effect, they bulletproof an already strong checksum algorithm. To see what I mean, consider a message that begins with some number of zero bits. The remainder will never contain anything other than zero until the first one in the message is shifted into it.
That's a dangerous situation, since packets beginning with one or more zeros may be completely legitimate and a dropped or added zero would not be noticed by the CRC. In some applications, even a packet of all zeros may be legitimate! The simple way to eliminate this weakness is to start with a nonzero remainder. The parameter called initial remainder tells you what value to use for a particular CRC standard.
And only one small change is required to the crcSlow and crcFast functions:. The final XOR value exists for a similar reason. To implement this capability, simply change the value that's returned by crcSlow and crcFast as follows:. If the final XOR value consists of all ones as it does in the CRC standard , this extra step will have the same effect as complementing the final remainder. However, implementing it this way allows any possible value to be used in your specific application.
In addition to these two simple parameters, two others exist that impact the actual computation. These are the binary values "reflect data" and "reflect remainder". The reason this is sometimes done is that a good number of the hardware CRC implementations operate on the "reflected" bit ordering of bytes that is common with some UARTs.
Two slight modifications of the code are required to prepare for these capabilities. What I've generally done is to implement one function and two macros. This code is shown in Listing 5. The function is responsible for reflecting a given bit pattern.
The macros simply call that function in a certain way. By inserting the macro calls at the two points that reflection may need to be done, it is easier to turn reflection on and off. To turn either kind of reflection off, simply redefine the appropriate macro as X. That way, the unreflected data byte or remainder will be used in the computation, with no overhead cost. Tested, full-featured implementations of both crcSlow and crcFast are available for download.
These implementations include the reflection capabilities just described and can be used to implement any parameterized CRC formula. Simply change the constants and macros as necessary. To test your implementation of a particular standard, simply invoke your CRC computation on that message and check the result:. If checksum has the correct value after this call, then you know your implementation is correct. This is a handy way to ensure compatibility between two communicating devices with different CRC implementations or implementors.
There are a few holes that I've hoped for many years that the author would fill with a fourth edition, but all in all it's the best coverage of a complex topic that I've seen. Many thanks to Ross for sharing his expertise with others and making several of my networking projects possible. Embedded Software Boot Camp. Embedded Linux Customization and Driver Development. This effectively caps the message size at bytes, but I thought that was probably a pretty typical compromise for use on an eight-bit processor.
I also had the compiler optimize the resulting code for speed, at its highest setting. I then looked at the actual assembly code produced by the compiler and counted the instructions inside the outer for loop in both cases.
This column was published in the January issue of Embedded Systems Programming. If you wish to cite the article in your own work, you may find the following MLA-style information helpful:. Barr, Michael. Source Code Review Services. Reverse Engineering Services. Today's Posts. Quick Links. Search Forums. Show Threads. Show Posts. Top Forums Programming crc32 info. Registered User. Join Date: Feb Administrator Emeritus. Join Date: Aug We have a few rules on this site. In particular: 6 Do not post classroom or homework problems.
I suspected that you might be breaking this rule when you posted your previous question on Fibonacci numbers. Now I'm sure of it. I will say that a crc program is a good choice for a class project. You should be able to find plenty of info on crc if you do some research. It is an not obscure algorithm. Last edited by crashnburn; at AM.. Shell Programming and Scripting.
0コメント