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

Merged
krishalivaibhav merged 1 commit from upstream-pr/10562 into main 2026-10-25 06:15:02 +00:00
krishalivaibhav commented 2026-10-24 10:11:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-24T10:11:29Z.


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 (ca9543ea5) + 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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4994505161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10562). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-24T10:11:29Z. --- ### 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_assert`s 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` (ca9543ea5) + 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 10:30:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:30:22Z.

Review: APPROVED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637932625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10562#pullrequestreview-5637932625). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T10:30:22Z. **Review:** APPROVED --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10562
No description provided.