keccak: Rework absorption of the final input bytes - #1620
Merged
Conversation
chfast
force-pushed
the
chfast/keccak-tail-no-memcpy
branch
from
August 8, 2026 23:02
aa25d86 to
f332889
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes Keccak input absorption for the final partial (1–7 byte) tail by constructing the last word via shifts instead of a byte-copy loop that GCC may recognize and lower into a small-size memcpy() call (notably affecting some RISC-V targets and zkVM cost models).
Changes:
- Replace the byte-by-byte tail copy into a stack
uint64_t(and subsequentto_le64()swap) with a shift/OR construction of the partial word plus padding byte. - Keep the Keccak padding behavior the same by placing
0x01at byte indexsizeand XORing into the next state lane.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1620 +/- ##
==========================================
- Coverage 97.46% 97.46% -0.01%
==========================================
Files 170 170
Lines 15402 15395 -7
Branches 3604 3604
==========================================
- Hits 15012 15005 -7
Misses 282 282
Partials 108 108
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
chfast
force-pushed
the
chfast/keccak-tail-no-memcpy
branch
from
August 9, 2026 10:16
f332889 to
c2e3966
Compare
In the Keccak input processing loop, rework the code handling the last 0–7 bytes of input and the padding byte. The new code is not spectacularly better than the old one, but it fixes edge case where a compiler may decide to replace the old code with memcpy call.
chfast
force-pushed
the
chfast/keccak-tail-no-memcpy
branch
from
August 9, 2026 10:29
c2e3966 to
87b4530
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.
In the Keccak input processing loop, rework the code handling the last
0–7 bytes of input and the padding byte. The new code is not
spectacularly better than the old one, but it fixes edge case where
a compiler may decide to replace the old code with memcpy call.