#checksum #internet #tcp #ipv4 #format #rfc1071

no-std internet-checksum

RFC 1071 checksum computation (the "internet checksum")

3 unstable releases

0.2.1 Nov 9, 2021
0.2.0 Aug 29, 2019
0.1.0 Jun 25, 2019

#1674 in Network programming

Download history 7946/week @ 2024-07-21 8696/week @ 2024-07-28 8724/week @ 2024-08-04 11751/week @ 2024-08-11 9495/week @ 2024-08-18 12034/week @ 2024-08-25 8584/week @ 2024-09-01 4965/week @ 2024-09-08 8115/week @ 2024-09-15 10705/week @ 2024-09-22 8126/week @ 2024-09-29 6552/week @ 2024-10-06 8486/week @ 2024-10-13 6619/week @ 2024-10-20 7366/week @ 2024-10-27 6855/week @ 2024-11-03

29,870 downloads per month
Used in 4 crates (3 directly)

Custom license

30KB
411 lines

RFC 1071 "internet checksum" computation.

This crate implements the "internet checksum" defined in RFC 1071 and updated in RFC 1141 and RFC 1624, which is used by many different protocols' packet formats. The checksum operates by computing the 1s complement of the 1s complement sum of successive 16-bit words of the input.

Benchmarks

Checksum::add_bytes

The following microbenchmarks were performed on a 2018 Google Pixelbook. Each benchmark constructs a Checksum object, calls Checksum::add_bytes with an input of the given number of bytes, and then calls Checksum::checksum to finalize. Average values were calculated over 3 trials.

Bytes Time Rate
20 |   2,649 ns |  7.55 MB/s
31 |   3,826 ns |  8.10 MB/s
32 |   3,871 ns |  8.27 MB/s
64 |   1,433 ns |  44.7 MB/s

128 | 2,225 ns | 57.5 MB/s 256 | 3,829 ns | 66.9 MB/s 1023 | 13,802 ns | 74.1 MB/s 1024 | 13,535 ns | 75.7 MB/s

Checksum::add_bytes_small

The following microbenchmarks were performed on a 2018 Google Pixelbook. Each benchmark constructs a Checksum object, calls Checksum::add_bytes_small with an input of the given number of bytes, and then calls Checksum::checksum to finalize. Average values were calculated over 3 trials.

Bytes Time Rate
20 |   2,639 ns |  7.57 MB/s
31 |   3,806 ns |  8.15 MB/s

update

The following microbenchmarks were performed on a 2018 Google Pixelbook. Each benchmark calls update with an original 2 byte checksum, and byteslices of specified lengths to be updated. Average values were calculated over 3 trials.

Bytes Time Rate
 2 |   1,550 ns |  1.29 MB/s
 4 |   1,972 ns |  2.03 MB/s
 8 |   2,892 ns |  2.77 MB/s

No runtime deps