Skip to content

Fix the custom-secret XXH3 test vectors and reach 100% coverage - #45

Merged
dipu-bd merged 2 commits into
masterfrom
ccr-3e9bf447-zsxg7p-xxh3-secret-vectors
Nov 29, 2026
Merged

dipu-bd merged 2 commits into
masterfrom
ccr-3e9bf447-zsxg7p-xxh3-secret-vectors

Conversation

@dipu-bd

@dipu-bd dipu-bd commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Two commits. Neither changes any library output.

  1. Fix the custom-secret XXH3 test vectors against the reference implementation (test-only)
  2. Cover the remaining 32-bit code paths for 100% coverage. Line coverage of lib/ goes to 5964/5964.

1. Custom-secret XXH3 test vectors

  • test/xxh3_test.dart: six custom-secret tests (147-byte secret; input lengths 0, 1, 403, 512, 2048 and 2243) were commented out, and their expected values were wrong. They are now active with values from the reference C implementation, with the source cited in a comment. All six pass against the existing 64-bit code, so its output was correct all along.
  • test/xxh_32bit_test.dart: removes two incorrect comments, added in Support XXHash64, XXH3 and XXH128 on the web #41, which claimed the 64-bit XXH3/XXH128 code can't handle secrets whose length isn't a multiple of 8. The 32-bit vs 64-bit comparison now also covers secret lengths 137, 139, 143, 147 and 150.

Correction to #41: #41's description reported a VM crash for such secrets. That was wrong: I inferred it from Uint64List.view(secret.buffer) without running it. The view rounds down to whole 8-byte lanes instead of throwing, and the code never reads past them. I checked the 64-bit code against the reference C library in 112 cases: secret lengths 136–200 bytes (including 137, 139, 143, 147 and 150), inputs from 0 to 2048 bytes, for both XXH3 and XXH128. All matched.

The new values come from the reference C implementation (libxxhash 0.8.4, bundled with Python's xxhash 4.1.0), called through ctypes with data and secret as defined in xxh3_test.dart:

lib = ctypes.CDLL(<xxhash package dir>/_xxhash*.so)
lib.XXH3_64bits_withSecret(cases[:n], n, secret, 147)
Length Old (commented out, wrong) Reference
0 6775fd10343c92c3 3559d64878c5c66c
1 c3382c326e24e3cd 8a52451418b2da4d
403 f9c0ba5ba3af70b8 14546019124d43b8
512 7896e65dcfa09071 7564693dd526e28d
2048 d6545db87ecfd98c d32e975821d6519f
2243 887810081c32460a 27bdd19f2d168989

2. 100% coverage

Every remaining uncovered line was in _32bit web code, which the VM only reaches through the differential tests.

Gap Fix
uint64.dart: the dart2js-only branch of setInt The calculation moves into a static Uint64.highWordOfDouble, which a VM test checks against value >> 32 for 1,000+ values within ±2^53. setInt produces the same value on every platform.
uint64.dart: rotl(32) and shl(n ≥ 32), unused by any algorithm New test/core/uint64_test.dart (vm-only) checks every Uint64 operation against native 64-bit int math, every rotate and shift amount from 1 to 63, and mul128/mul128fold64 against BigInt (including aliased outputs).
poly1305_32bit.dart: the bad-key-length throw New key-length validation test against the 32-bit sink.
keccak_32bit.dart: reset() New reset test.
keccak_32bit.dart: a pos == blockLength check at the start of $finalize Removed as dead code: $process always flushes and resets pos when a block fills, so the check could never be true. The 64-bit twin doesn't have it, and the two $finalize methods are now identical.

Verification

  • dart format --output=none --set-exit-if-changed . makes no changes
  • dart analyze --fatal-infos reports no issues
  • dart test -p vm: all tests pass
  • dart test -p node: all tests pass
  • dart test -P wasm: all tests pass
  • bash scripts/coverage.sh reports 5964/5964 lines of lib/ covered

🤖 Generated with Claude Code

https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo

…ntation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo
@codecov-commenter

codecov-commenter commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
lib/src/algorithms/keccak/keccak_32bit.dart 100.00% <ø> (+7.69%) ⬆️
lib/src/core/uint64.dart 100.00% <100.00%> (+4.16%) ⬆️

... and 1 file with indirect coverage changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo
@dipu-bd dipu-bd changed the title Fix the custom-secret XXH3 test vectors against the reference implementation Fix the custom-secret XXH3 test vectors and reach 100% coverage Nov 29, 2026
@dipu-bd
dipu-bd merged commit a8de490 into master Nov 29, 2026
20 checks passed
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