Skip to content

Use math/bits.RotateLeft64 for word rotations - #6

Merged
schultz-is merged 1 commit into
trunkfrom
refactor/rotate-left64
Aug 3, 2026
Merged

Use math/bits.RotateLeft64 for word rotations#6
schultz-is merged 1 commit into
trunkfrom
refactor/rotate-left64

Conversation

@schultz-is

Copy link
Copy Markdown
Owner

Replace the manual ((x << r) | (x >> (64-r))) rotate-left idiom in the encrypt paths, and its ((x << (64-r)) | (x >> r)) rotate-right inverse in the decrypt paths, with bits.RotateLeft64(x, r) and bits.RotateLeft64(x, -r) respectively. With constant rotation amounts this compiles to a single ROL/ROR instruction (identical codegen, constant-time), while reading far closer to the spec.

Purely mechanical: every changed line is a rotation, and the unchanged known-answer test vectors confirm the behavior is identical.

Replace the manual ((x << r) | (x >> (64-r))) rotate-left idiom in the encrypt
paths, and its ((x << (64-r)) | (x >> r)) rotate-right inverse in the decrypt
paths, with bits.RotateLeft64(x, r) and bits.RotateLeft64(x, -r) respectively.
With constant rotation amounts this compiles to a single ROL/ROR instruction
(identical codegen, constant-time), while reading far closer to the spec.

Purely mechanical: every changed line is a rotation, and the unchanged
known-answer test vectors confirm the behavior is identical.
@schultz-is
schultz-is merged commit 59ef6c9 into trunk Aug 3, 2026
5 checks passed
@schultz-is
schultz-is deleted the refactor/rotate-left64 branch August 3, 2026 01:13
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.

1 participant