Skip to content

fix(libSceLibreSsl): build the AES substitution table within the constexpr step limit - #10562

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
krishalivaibhav:fix/macos-libressl-aes-constexpr
Oct 25, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
krishalivaibhav:fix/macos-libressl-aes-constexpr

Conversation

@krishalivaibhav

Copy link
Copy Markdown
Contributor

What

libSceLibreSsl/src/Aes.cpp did not compile with AppleClang: MakeSubstitution() builds the AES S-box at compile time and found each multiplicative inverse in GF(2^8) by trying all 255 candidates for each of the 256 values (about 65k Multiply calls), which exceeds clang's constexpr step limit.

The inverse is now computed directly as x^254 (6 square-and-multiply steps, then one square; 0 still maps to 0). This builds the same table: the existing static_asserts on entries 0x00, 0x53 and 0xff still hold. No compiler flag is needed, and the code is the same on all platforms.

Tested

macOS: Apple Silicon M2, macOS 27.2, AppleClang, x86_64 Release, on a local integration of main (ca9543e) + the open macOS build PRs (#10419, #10366, #10369, #7631, #7804, #4630, #10552):

  • Aes.cpp compiles (it failed before with the constexpr step limit); ninja libs -k 0 no longer lists it.
  • guest_libressl_aes passes.

Linux/Windows: not built locally; CI will build them.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

…texpr step limit

The table searched all 255 candidates for each inverse, which exceeds the
constexpr step limit of AppleClang. The inverse is now computed as x^254 in
GF(2^8), which gives the same table.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@krishalivaibhav

Copy link
Copy Markdown
Contributor Author

Linux check: Ubuntu 24.04, g++ 13.3.0, x86-64 Release (x86-64 chroot under Rosetta in an Apple Silicon VM), on main 60465af + this commit + #10552. libSceLibreSsl builds with no warnings from Aes.cpp, and guest_libressl_aes passes.

@MarcZX10 MarcZX10 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.

Reviewed the exponentiation chain: starting at x, six rounds of x = x²·a produce a^127, and the final square produces a^254; zero remains zero, as required for the AES inverse map. I compared the complete fast-generated 256-byte S-box against the prior exhaustive-search algorithm in a standalone GCC C++20 check; every entry matched, and the published static-assert entries passed. Hosted eligibility, conventions, intake, labels, and report pass; platform build jobs were skipped by eligibility. No correctness issue found.

@github-actions github-actions Bot added the prx label Oct 24, 2026
@maximilianfv

Copy link
Copy Markdown
Contributor

Tested at 7f4d4aff8 on Apple M1 Pro, macOS 27.0.1 (Apple clang, x86_64 build under Rosetta 2)

Applied to mugurc's macOS series (27e968974) merged with main at 522e32e3b6, with other open macOS fixes, then toggled only this PR.

build guest_libressl_aes
Without this PR Aes.cpp:51:16: error: constexpr variable 'Substitution' must be initialized by a constant expression (note: constexpr evaluation hit maximum step limit), so libSceLibreSsl does not build not built
With this PR builds Passes

The other five guest_libressl* tests pass with this PR as well.

AI-assisted: yes (Claude Code applied the PR, built both ways, ran the tests and wrote this report).

@github-actions

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 10834 core/libs/prx/libSceLibreSsl/src/Aes.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants