#checksum #internet #ipv4 #tcp #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

#1425 in Network programming

Download history 4282/week @ 2024-01-06 3696/week @ 2024-01-13 2969/week @ 2024-01-20 3930/week @ 2024-01-27 5694/week @ 2024-02-03 5164/week @ 2024-02-10 3213/week @ 2024-02-17 3958/week @ 2024-02-24 5764/week @ 2024-03-02 7199/week @ 2024-03-09 8368/week @ 2024-03-16 9665/week @ 2024-03-23 7475/week @ 2024-03-30 7593/week @ 2024-04-06 7516/week @ 2024-04-13 5210/week @ 2024-04-20

28,563 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