JFLib

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]) -> u32 adds data to a running ones' complement sum (the result is folded to 17 bits at most)

  • fn fold(acc: u32) -> u16 folds a sum to 16 bits (without the final complement)

  • fn finish(acc: u32) -> u16 the checksum value to store: the complement of the folded sum

  • fn checksum(data: &[u8]) -> u16 the Internet checksum of a block

  • fn verify(data: &[u8]) -> bool a block that includes its checksum field is intact

  • fn pseudo_v4(src: Ipv4, dst: Ipv4, proto: u8, len: u16) -> u32 the IPv4 pseudo header of UDP / TCP: addresses, protocol, length of the segment

  • fn pseudo_v6(src: Ipv6, dst: Ipv6, next: u8, len: u32) -> u32 the IPv6 pseudo header (RFC 8200 8.1): addresses, upper-layer length, next header

  • fn update16(ck: u16, old: u16, new: u16) -> u16 the new checksum after one 16-bit word changed from old to new (RFC 1624 eqn. 3)

  • fn crc32(data: &[u8]) -> u32 CRC-32 of IEEE 802.3 (the Ethernet frame check sequence; also zlib's and PNG's)

  • fn update(ck: u16, old: &[u8], new: &[u8]) -> u16 the new checksum after the bytes old became new (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

Source: docs/API.md in the JFLib repository.