Features of Internet checksum

Source: Internet
Author: User

Internet checksum algorithm features

Fortune 10.20

Exchange rate and combination Law: In the process of accumulation, it is important that the location of the byte is an odd digit or an even number, so as long as the parity of the byte is not chaotic, the addition can be performed in any order, you can also combine them as needed.

([A, B] + '[c, d] + '... + '[g, 0]) +' ([0, H] + '... + '[y, z])

Byte order independence: During the accumulation process, the positions of the 16-bit high 8-bit and the low 8-bit can be exchanged, that is, the high byte priority order can be used, you can also use the low-byte-first sequence to accumulate data. You only need to ensure that the 16-bit binary numbers involved in the calculation use the same representation sequence. If the High and Low bytes are exchanged during the operation, the final result also needs to be flipped.

[B, A] + '[D, C] +'... + '[Z, y]

Why is such a result? Because the carry values obtained in the two orders are the same. Both carry from 15th bits to 0th bits and carry from 7th bits to 8th bits. That is to say, the location of the exchanged bytes only changes the order of the high and low bytes, but does not change their internal relationship.

Parallel Computing: In a machine with a word width multiple of 16 bits, the preceding algorithm can be more effectively implemented using parallel computing. For example, on a 32-bit machine, four bytes can be calculated:

[A, B, c, d] + '[E, F, G, H] + '...

Finally, fold the 32-bit result into 16 bits. Of course, the newly generated carry still needs to be accumulated to the low position cyclically.

Similarly, the order of bytes is not important. [D, C, B, A] + '[h, G, F, E] +'... can be used for calculation. You can also use [B, A, D, C] + '[F, E, H, G] + '... computing, you only need to swap the byte order with it.

Carry Delay: Delayed carry means that after all data is accumulated, the carry value loop is accumulated to a low level. One of its implementation methods is to use the 32-bit accumulators to obtain the 16-bit checksum, so that the carry is saved on the high 16-bit. This method avoids the setup of the inbound sensor in the accumulators, but it requires twice the capacity of the original accumulators. Therefore, more low depends on hardware conditions.

Data Reading and verification are combined into one: Because both Data Reading and computing checksum require data retrieval, both require the bandwidth of the storage bus, so their bottleneck lies in the speed at which the storage bus data is read. If you combine the Data Reading Process with the verification process, that is, you can calculate the checksum while reading the data. This saves a Data Reading Process and improves the checksum calculation efficiency.

Incremental update: If the value of some bytes changes for the data that has already been computed, the checksum needs to be re-calculated without all the data being computed. The only thing to do is to subtract the original value of the changed byte from the original accumulation and the new value, that is, add the difference between the two values. Assume that C is the checksum before modification, M is the value before modification, and m is the modified value. Then, the checksum C is:

C' = C + (-m) + M' = C + (M'-m)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.