Skip to content

Add XXHash64, XXHash3, and XXHash128 to smithy-checksums - #870

Merged
jonathan343 merged 3 commits into
developfrom
feat/smithy-checksums-xxhash
Oct 31, 2026
Merged

jonathan343 merged 3 commits into
developfrom
feat/smithy-checksums-xxhash

Conversation

@jonathan343

@jonathan343 jonathan343 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

S3 also supports XXHash64, XXHash3 (64-bit), and XXHash128 checksums. This PR adds them to smithy-checksums as XXHash64, XXHash3, and XXHash128, also available through new(). The native side uses the twox-hash crate (MIT, added to LICENSE-THIRD-PARTY). The pure-Python side is a port of the xxHash reference implementation, limited to the seed of zero and default secret that checksums use. The second commit speeds it up: XXH3 and XXH128 key whole blocks with one big-integer XOR and accumulate in an unrolled loop, and XXH64 runs its four lanes at once packed into one integer. It now runs at about 47–68 MB/s, depending on the algorithm.

Example

import base64

import smithy_checksums

for name in ("XXHASH64", "XXHASH3", "XXHASH128"):
    checksum = smithy_checksums.new(name)
    checksum.update(b"Hello world")
    print(checksum.name, checksum.digest_size, base64.b64encode(checksum.digest()))

The native and pure-Python builds print the same thing. These are also the x-amz-checksum-xxhash* header values botocore's tests expect for the same input:

xxhash64 8 b'xQCwyRKzdtg='
xxhash3 8 b'tqy52Eo4/3Q='
xxhash128 16 b'c1H4mBL5c4K5HQWzHgTdfw=='

Testing

The known answers include 15 of xxHash's own sanity-test vectors per algorithm, from tests/sanity_test_vectors.h. They cover every XXH3 size class and block boundary. Both implementations are also compared against the CRT and against each other:

uv run pytest packages/smithy-checksums -k "xxhash and (known_answers or matches_crt or native_matches_pure)" --no-cov -q
18 passed, 196 deselected in 0.12s

I also ran all 12,483 seed-zero vectors in that file once, covering every input length from 0 to 4,160 bytes. Both implementations matched every one.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jonathan343
jonathan343 added this pull request to stack #869 October 25, 2026 04:49
@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from bfa1af9 to e1b2e71 Compare October 25, 2026 04:59
@kuhe

kuhe commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

please also review aws/aws-sdk-js-v3#8383 while this is fresh 😄

@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from e1b2e71 to 6dc8617 Compare October 27, 2026 15:47
@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from 6dc8617 to 9c97635 Compare October 27, 2026 19:11
@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from 9c97635 to 6f993da Compare October 27, 2026 19:15
@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from 6f993da to ac36924 Compare October 27, 2026 21:04
Base automatically changed from feat/smithy-checksums-crc64nvme to develop October 31, 2026 20:49
@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from ac36924 to f36d163 Compare October 31, 2026 20:56
@jonathan343
jonathan343 marked this pull request as ready for review October 31, 2026 21:00
@jonathan343
jonathan343 requested a review from a team as a code owner October 31, 2026 21:00
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

================================================================================

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add xxHash’s BSD license here too since the Python implementation is described as a port of the reference code

@jonathan343 jonathan343 Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in a0a9528

Adds the XXHash checksum algorithms S3 supports, backed by the native
extension (twox-hash) with a pure-Python fallback ported from the reference
implementation, and available through new(). The pure-Python
implementations are checked against the native ones and against the CRT.
XXH3 and XXH128 key each block of input with one big-integer XOR, read the
keyed words as 32-bit halves, and accumulate with an unrolled loop that
masks the accumulators once per block instead of after every operation.
That takes them from about 39 MB/s to about 74 MB/s.

XXH64's rounds are a serial chain of 64-bit operations per lane, so instead
its four lanes are packed into one integer, 128 bits apart, and each step
of a round runs on all four at once. Every lane is multiplied by the first
prime in one operation per 64 KiB. Inputs under 512 bytes, where spreading
the input costs more than it saves, use inlined per-lane rounds. That takes
XXH64 from about 35 MB/s to about 57 MB/s.

The native-versus-pure test now covers inputs past 64 KiB.
The pure-Python XXH64, XXH3, and XXH128 are ported from xxHash's reference
implementation, so its copyright notice and license now ship in
LICENSE-THIRD-PARTY next to the crate licenses, and xxhash.py credits it.
The notice is the one in xxhash.h at the commit the port and test vectors
come from.
@jonathan343
jonathan343 force-pushed the feat/smithy-checksums-xxhash branch from 71d7445 to a0a9528 Compare October 31, 2026 21:25
@jonathan343
jonathan343 merged commit 4857275 into develop Oct 31, 2026
26 checks passed
@jonathan343
jonathan343 deleted the feat/smithy-checksums-xxhash branch October 31, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants