Skip to content

Conversation

@implicitfield
Copy link
Contributor

Previously, there were two slightly different implementations of this in the Kernel and in LibCrypto.

This patch removes those, and replaces them with an implementation that seeks to combine the best aspects of both while not being a drop-in replacement for either.

Two new tests are also included.


FWIW I'm not sure why the old kernel-side implementation had this logic in the core loop:

if (m_checksum & 0x80000000)
    m_checksum = (m_checksum & 0xffff) | (m_checksum >> 16);

That kind of looks like an attempt to prevent unsigned 32-bit integer overflow, but I can't see that realistically happening (you'd have to sum up at least 131075 (UINT32_MAX/UINT16_MAX*2+1) bytes before that'd happen, and even that's a worst-case scenario). The example C implementation in RFC1071 does no such thing either. It seems like this part originated from the old LibC internet_checksum function, so I guess it can go.


This also gets rid of all the endianness conversions in the checksumming process (since the checksum is actually byte-order independent, see 2.B of the aforementioned RFC).

Previously, there were two slightly different implementations of this in
the Kernel and in LibCrypto.

This patch removes those, and replaces them with an implementation that
seeks to combine the best aspects of both while not being a drop-in
replacement for either.

Two new tests are also included.
@github-actions github-actions bot added 👀 pr-needs-review PR needs review from a maintainer or community member labels Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👀 pr-needs-review PR needs review from a maintainer or community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant