Skip to content

keccak: don't assume SHA3 extensions on iOS (SIGILL on A12 and older) - #9

Open
AskAlexSharov wants to merge 4 commits into
masterfrom
fix/ios-sha3-detection
Open

keccak: don't assume SHA3 extensions on iOS (SIGILL on A12 and older)#9
AskAlexSharov wants to merge 4 commits into
masterfrom
fix/ios-sha3-detection

Conversation

@AskAlexSharov

@AskAlexSharov AskAlexSharov commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Bug

keccak_arm64.go enables the SHA3-extension assembly whenever GOOS is darwin or ios:

useASM = runtime.GOOS == "darwin" || runtime.GOOS == "ios" || cpu.ARM64.HasSHA3

x/sys/cpu performs no feature detection on Darwin-family systems — its arm64 doinit() is empty there (cpu_other_arm64.go), so cpu.ARM64.HasSHA3 is always false and the GOOS shortcut alone decides.

  • macOS: fine — arm64 macOS implies M1+, all of which have FEAT_SHA3.
  • iOS: wrong — FEAT_SHA3 first shipped in the Apple A13 (LLVM AArch64 target definitions). A12-class devices (iPhone XS/XR, iPad 8th gen, iPad Air 3, iPad mini 5) are still supported by current iOS, and on them the first permutation hits VEOR3SIGILL.

The Go standard library gates its equivalent assumption with darwin && !ios (internal/cpu/cpu_arm64_darwin.go) for exactly this reason.

Fix

Drop the ios clause. iOS falls back to x/crypto/sha3 (runtime detection is not possible there via x/sys/cpu), matching upstream Go's behavior.

Testing

  • go test ./... + 45s fuzz vs x/crypto on arm64 (native): pass
  • GOOS=ios GOARCH=arm64 go build: compiles
  • go vet: clean

x/sys/cpu performs no CPU feature detection on Darwin-family systems
(its arm64 doinit is empty there), so cpu.ARM64.HasSHA3 is always false
and the GOOS shortcut alone decides whether the SHA3 assembly runs.

That assumption is correct for macOS — arm64 macOS implies M1 or newer,
which all implement FEAT_SHA3 — but wrong for iOS: FEAT_SHA3 first
shipped in the Apple A13, and A12-class devices (iPhone XS/XR, iPad 8th
gen, iPad Air 3, iPad mini 5) are still supported by current iOS. On
those devices the first permutation executes VEOR3 and crashes with
SIGILL.

The Go standard library gates its equivalent assumption with
'darwin && !ios' (internal/cpu/cpu_arm64_darwin.go) for the same
reason. Drop the ios clause so iOS falls back to x/crypto/sha3.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash on older iOS arm64 devices by preventing the SHA3-extension (Armv8.2-A) keccak assembly from being enabled solely based on GOOS=ios, which could otherwise execute unsupported instructions (SIGILL on A12 and older).

Changes:

  • Remove the runtime.GOOS == "ios" shortcut from the assembly gating logic.
  • Expand the comment to document why iOS is excluded and how this matches Go’s standard library behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Go's standard library does not assume SHA3 on darwin — it probes
hw.optional sysctls in internal/cpu under a 'darwin && !ios' build tag.
The accurate statement is that iOS gets no feature detection at all,
so std's SHA3 assembly never runs there either.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@AskAlexSharov
AskAlexSharov force-pushed the fix/ios-sha3-detection branch from 270303a to 0042f38 Compare July 20, 2026 08:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

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.

2 participants