Skip to content

SipHash: keep jumps within a single inline asm statement - #12284

Open
julek-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
julek-wolfssl:siphash-asm-one-statement
Open

julek-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
julek-wolfssl:siphash-asm-one-statement

Conversation

@julek-wolfssl

Copy link
Copy Markdown
Member

wc_SipHash() splits its inline assembly over several asm statements to stay under the C99 4095 character limit for string literals. Some jumps went from one statement into a label in the next. GCC does not support that, because the compiler may place register moves between the statements that the jump skips. An msys2 build with GCC 16 produced wrong digests.

  • Keep the split, but move the boundaries so every jump stays inside its own statement.
  • On x86_64, the first statement now ends after the block loop.
  • On aarch64, the 8 byte output check moves into the second statement.
  • Add the "cc" clobber, since the assembly changes the flags.
  • Use the plain C code under Fil-C, which does not allow pointers in inline assembly.

wc_SipHash() splits its inline assembly over several asm statements to
keep each string under the C99 4095 char limit. Some jumps went from one
statement into a label of the next. GCC does not support that: the
compiler may place register moves between the statements that the jump
skips. An msys2 build with GCC 16 got wrong digests.

Keep the split, but move the boundaries so every jump stays in its own
statement. On x86_64 the first statement now ends after the block loop.
On aarch64 the 8 byte output check moves into the second statement.

Add the "cc" clobber, since the assembly changes the flags. Fil-C does
not allow pointers in inline assembly, so use the C code there.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:15
@julek-wolfssl julek-wolfssl self-assigned this Nov 26, 2026

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues are reported for the SipHash assembly-boundary changes.

No open issues 🎉

What changed in this PR

Fixes inline assembly boundaries in wc_SipHash() to prevent compiler-generated register moves from being skipped, addressing incorrect digests observed with GCC 16 on MSYS2.

Changes:

  • Moves x86_64 and AArch64 assembly boundaries so jumps remain within one statement while preserving the string-length limit.
  • Adds "cc" clobbers to declare condition-flag changes.
  • Selects the portable C implementation for Fil-C.
File Description
wolfcrypt/​src/​siphash.c Adjusts assembly boundaries and clobbers, adds Fil-C guards, and documents the constraints.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,864 B (+4.9%, 296,444 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@julek-wolfssl

Copy link
Copy Markdown
Member Author

retest this please

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