netpkt/checksum.rs#
Source: lib/netpkt/checksum.rs
checksum -- the Internet checksum (RFC 1071, 1624) and the Ethernet CRC-32
sum(acc, data) -> u32 ones' complement sum of 16-bit big-endian words; only the
last piece of a message may have an odd length
finish(acc) -> u16 the checksum to write (complement of the folded sum)
checksum(data) -> u16 finish(sum(0, data))
verify(data) -> bool a block that contains its checksum sums to 0xFFFF
pseudo_v4 / pseudo_v6 the pseudo-header sums of UDP, TCP and ICMPv6
update16(ck, old, new) -> u16 incremental update after a 16-bit field changed (RFC 1624)
crc32(data) -> u32 IEEE 802.3 FCS (reflected 0x04C11DB7, as zlib)
update(ck, old, new) -> u16 incremental update after a run of bytes changed (an address,
a whole quoted packet): update16 for every word that differs
fn sum(acc: u32, data: &[u8]) -> u32addsdatato a running ones' complement sum (the result is folded to 17 bits at most)fn fold(acc: u32) -> u16folds a sum to 16 bits (without the final complement)fn finish(acc: u32) -> u16the checksum value to store: the complement of the folded sumfn checksum(data: &[u8]) -> u16the Internet checksum of a blockfn verify(data: &[u8]) -> boola block that includes its checksum field is intactfn pseudo_v4(src: Ipv4, dst: Ipv4, proto: u8, len: u16) -> u32the IPv4 pseudo header of UDP / TCP: addresses, protocol, length of the segmentfn pseudo_v6(src: Ipv6, dst: Ipv6, next: u8, len: u32) -> u32the IPv6 pseudo header (RFC 8200 8.1): addresses, upper-layer length, next headerfn update16(ck: u16, old: u16, new: u16) -> u16the new checksum after one 16-bit word changed fromoldtonew(RFC 1624 eqn. 3)fn crc32(data: &[u8]) -> u32CRC-32 of IEEE 802.3 (the Ethernet frame check sequence; also zlib's and PNG's)fn update(ck: u16, old: &[u8], new: &[u8]) -> u16the new checksum after the bytesoldbecamenew(of the same length, starting at an even offset of the data the checksum covers; an odd last byte is the high byte of its word, as in sum): RFC 1624 eqn. 3 for every 16-bit word that changed