Skip to content

Support incremental checksum update #122

@thomaseizinger

Description

@thomaseizinger

The Internet Checksum can be incrementally updated if one knows the old and new value of a particular field. The details are in https://www.rfc-editor.org/rfc/rfc1624.html.

Effectively, you just subtract the old value from the checksum and add the new one to it.

I wrote a small module for a recent project here that does this: https://github.com/firezone/firezone/blob/main/rust/relay/ebpf-turn-router/src/checksum.rs

Is this something that people are interested in having upstreamed? There is the internet-checksum crate as well which has an update function but it is unnecessarily restrictive (e.g. only works if old and new have the same length).

etherparse already has a pretty solid checksum module. All we'd need is to extend that one to support:

  • Creating a Sum16BitWords from an initial checksum (i.e. taking the one's complement from the sum)
  • Adding functions to subtract a value (which means adding the one's complement of a value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions