Repository navigation
Replace BigInt in the 32-bit Poly1305 and make the final reduction constant-time - #43
Merged
Merged
Conversation
Base automatically changed from
ccr-3e9bf447-zsxg7p-uint64-sha512-keccak
to
master
November 28, 2026 22:24
Codecov Report✅ All modified and coverable lines are covered by tests.
|
…constant-time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo
dipu-bd
force-pushed
the
ccr-3e9bf447-zsxg7p-poly1305
branch
from
November 29, 2026 20:34
8a445e9 to
7798ca6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
poly1305_32bit.dart):BigIntarithmetic is replaced with the 16-bit layout of poly1305-donna (also used by tweetnacl-js).rand the accumulator are each held as ten 13-bit limbs.~/rather than>>>, because the sums can exceed 32 bits.h mod pstep now picks betweenhandh - pwith a mask instead of anif. Its timing no longer depends on the accumulated value. The 32-bit code is written that way from the start;poly1305_64bit.dartpreviously used a branch there. This only touches$finalize, so it adds a few operations per message, not per block.AGENTS.md: lists the new differential test.The branch is a single commit on top of
master.Performance (web)
Node, dart2js
-O2, same script before and after. Single runs in a cloud container, not the reference machine.cipherlib's Poly1305-based AEADs (ChaCha20-Poly1305, XSalsa20-Poly1305) should get faster on the web once it picks up a hashlib release with this change.
Tests
test/poly1305_test.dart, all platforms): 9 new vectors aimed at the final reduction and carry handling.dart runthandart compile && .exe#6–Implementation of OTPAuth: HOTP, TOTP #11): wraparound past 2^130, a carry out of 2^128, h reaching p exactly, h becoming 0, and a carry out of limb 9. All-ones keys and messages are added on top.cryptography50.0.1, and they agree with the results published in the RFC. The command is recorded in the test.test/poly1305_32bit_test.dart, vm-only): the 32-bit code against the 64-bit code. It covers 300 random keys (16- and 32-byte) and keys saturated with single byte values, each at 14 message lengths up to 4099 bytes, plus a reset check. All matched.Verification
dart format --output=none --set-exit-if-changed .makes no changesdart analyze --fatal-infosreports no issuesdart test -p vm: all tests passdart test -p node: all tests passdart test -P wasm: all tests passdart test -p chromeand the integration smoke test also passed on the same code.No CHANGELOG entry: the version heading is left to the maintainer. Suggested bullets:
Poly1305on the web 13–27x by replacingBigIntwith 13-bit limb arithmetic"Poly1305final reduction constant-time"🤖 Generated with Claude Code
https://claude.ai/code/session_01KmuCbukmnH9zJJPoxX3tGo