#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

#1512 in Network programming

Download history 6678/week @ 2024-05-20 6329/week @ 2024-05-27 6469/week @ 2024-06-03 9078/week @ 2024-06-10 7355/week @ 2024-06-17 6686/week @ 2024-06-24 5294/week @ 2024-07-01 5432/week @ 2024-07-08 7115/week @ 2024-07-15 8097/week @ 2024-07-22 8706/week @ 2024-07-29 8789/week @ 2024-08-05 11708/week @ 2024-08-12 9373/week @ 2024-08-19 12063/week @ 2024-08-26 8397/week @ 2024-09-02

42,041 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