feat(libSceLibreSsl): implement EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_new and EVP_CIPHER_CTX_set_padding #10488

Merged
alvaroelpob merged 4 commits from upstream-pr/10488 into main 2026-11-02 10:26:03 +00:00
alvaroelpob commented 2026-10-24 03:12:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-24T03:12:47Z.


What

Implements EVP_CIPHER_CTX_init, EVP_CIPHER_CTX_new and EVP_CIPHER_CTX_set_padding in libSceLibreSsl, which threw and were declared without parameters.

The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, layout and results follow that release's evp.h and evp_enc.c:

Export Behaviour
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX*) zeroes the 168-byte context
EVP_CIPHER_CTX* EVP_CIPHER_CTX_new(void) calloc(1, 168), through the guest calloc as the module would through libc
int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX*, int pad) clears EVP_CIPH_NO_PADDING (0x100) in the 64-bit flags at 112 when pad is nonzero, sets it otherwise, and returns 1

The 168-byte size is the one measured for EVP_CIPHER_CTX_init in #8981. The layout (num at 88, flags at 112, final at 136) was checked with static_asserts and against offsetof from the 2.5.4 headers compiled on x86-64. LibreSSL dereferences a null context in init and set_padding without checking it, so that throws.

#9571 forward-declares its own cipher context type for CMAC. This PR uses its own file and struct name, and changes none of its exports.

The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 354.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main 379b1dca3. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its guest_libressl_evp_cipher_ctx test and check_conventions.py run on its own.

  • New guest_libressl_evp_cipher_ctx test. EVP_CIPHER_CTX_init zeroes exactly 168 bytes of a 0xAA buffer and leaves the next 16 alone. EVP_CIPHER_CTX_new returns four zeroed 168-byte guest heap blocks that are written and freed again. EVP_CIPHER_CTX_set_padding sets 0x100 for 0 (twice) and clears it for 1 and -5, keeps the other flag bits 0xFFFFFFFF000000FF, returns 1, and touches no byte outside flags. A null context throws in init and set_padding.
  • Full ctest -j16 at the last commit: 2005/2006 pass. agc_driver_multisample_retirement fails the same way on main on this machine.
  • Not tested: Windows, a title.
  • Rebased on main 1e740a23a3 (after #9033), head 4f073fa757: the conflicts were only the add_library source list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build and ctest -j16: 2043/2044 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main e7e3e9c198, head 6b1e364fc2, to resolve the conflict from #9529 on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. 6b1e364fc2 (refactor(libSceLibreSsl): declare the EVP_CIPHER_CTX exports in the public header) puts the real signatures and their structs in libSceLibreSsl/include/Api.hpp and drops the test's redeclarations, which public_headers requires since #10706. Full build and ctest -j16: 2202/2203 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main ae7d59258e (after #9949), head 9a3cb4ef57, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build and ctest -j16: 2275/2276 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 2dbe9b99f5 (after #9745, #9870 and #11111), head f9a8c85d8d, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 340 minus this PR's exports. Full build and ctest -j16: 2370/2371 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 88795ed448 (after #10248; head 94203537ac) to resolve the conflicts on the shared debt-file lines; both sides are kept and the count is 335 minus this PR's exports. Full build and ctest -j16: 2383/2384 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main c7b4878fa8 (after #10373, #10376 and #10449), head 4ec014c6b2, to resolve the conflicts with main on the shared CMakeLists.txt, Api.hpp and debt-file lines; both sides are kept and the count is 319 minus this PR's exports. Full build and ctest -j16: 2394/2395 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 474030e584 (after #13562), head acab57400f, to resolve the conflict on the pending-export count in the debt file; the count is 292 minus this PR's exports. Full build and ctest -j16: 3062/3062 pass. check_conventions.py --base upstream/main passes.
  • Rebased on main cf79276fee (after #13820), head 16d0e81b02, to resolve the conflict on the pending-export count in the debt file. main still says 292 although #13820 removed two stubs, leaving 290, so the count is now set to the 287 stubs left in Export.cpp. It also restores the PS5 3.20 export table link, b2a77c09cd71c01f34c790cfbe98c751a13262ad, which the previous rebase had written without its zeros. Full build and ctest -j16: 3107/3107 pass (log_file failed once on #10486 and passed on five reruns and a second full run). check_conventions.py --base upstream/main passes.

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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #9446, #9448, #9571, #10395, #10418, #10448, #10450, #10477, #10478, #10481, #10482, #10483, #10485, #10486
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4992032311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10488). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-24T03:12:47Z. --- ### What Implements `EVP_CIPHER_CTX_init`, `EVP_CIPHER_CTX_new` and `EVP_CIPHER_CTX_set_padding` in libSceLibreSsl, which threw and were declared without parameters. The module is LibreSSL 2.5.4 ([firmware 13.40 measurements in #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214)). Signatures, layout and results follow that release's [`evp.h` and `evp_enc.c`](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/evp): | Export | Behaviour | |---|---| | `void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX*)` | zeroes the 168-byte context | | `EVP_CIPHER_CTX* EVP_CIPHER_CTX_new(void)` | `calloc(1, 168)`, through the guest `calloc` as the module would through libc | | `int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX*, int pad)` | clears `EVP_CIPH_NO_PADDING` (0x100) in the 64-bit `flags` at 112 when `pad` is nonzero, sets it otherwise, and returns 1 | The 168-byte size is the one measured for `EVP_CIPHER_CTX_init` in #8981. The layout (`num` at 88, `flags` at 112, `final` at 136) was checked with `static_assert`s and against `offsetof` from the 2.5.4 headers compiled on x86-64. LibreSSL dereferences a null context in `init` and `set_padding` without checking it, so that throws. #9571 forward-declares its own cipher context type for CMAC. This PR uses its own file and struct name, and changes none of its exports. The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 354. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON` on `main` 379b1dca3. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its `guest_libressl_evp_cipher_ctx` test and `check_conventions.py` run on its own. - New `guest_libressl_evp_cipher_ctx` test. `EVP_CIPHER_CTX_init` zeroes exactly 168 bytes of a 0xAA buffer and leaves the next 16 alone. `EVP_CIPHER_CTX_new` returns four zeroed 168-byte guest heap blocks that are written and freed again. `EVP_CIPHER_CTX_set_padding` sets 0x100 for 0 (twice) and clears it for 1 and -5, keeps the other flag bits `0xFFFFFFFF000000FF`, returns 1, and touches no byte outside `flags`. A null context throws in `init` and `set_padding`. - Full `ctest -j16` at the last commit: 2005/2006 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. - Not tested: Windows, a title. - Rebased on `main` 1e740a23a3 (after #9033), head 4f073fa757: the conflicts were only the `add_library` source list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build and `ctest -j16`: 2043/2044 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` e7e3e9c198, head 6b1e364fc2, to resolve the conflict from #9529 on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. 6b1e364fc2 (`refactor(libSceLibreSsl): declare the EVP_CIPHER_CTX exports in the public header`) puts the real signatures and their structs in `libSceLibreSsl/include/Api.hpp` and drops the test's redeclarations, which `public_headers` requires since #10706. Full build and `ctest -j16`: 2202/2203 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` ae7d59258e (after #9949), head 9a3cb4ef57, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build and `ctest -j16`: 2275/2276 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 2dbe9b99f5 (after #9745, #9870 and #11111), head f9a8c85d8d, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 340 minus this PR's exports. Full build and `ctest -j16`: 2370/2371 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 88795ed448 (after #10248; head 94203537ac) to resolve the conflicts on the shared debt-file lines; both sides are kept and the count is 335 minus this PR's exports. Full build and `ctest -j16`: 2383/2384 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` c7b4878fa8 (after #10373, #10376 and #10449), head 4ec014c6b2, to resolve the conflicts with `main` on the shared `CMakeLists.txt`, `Api.hpp` and debt-file lines; both sides are kept and the count is 319 minus this PR's exports. Full build and `ctest -j16`: 2394/2395 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 474030e584 (after #13562), head acab57400f, to resolve the conflict on the pending-export count in the debt file; the count is 292 minus this PR's exports. Full build and `ctest -j16`: 3062/3062 pass. `check_conventions.py --base upstream/main` passes. - Rebased on `main` cf79276fee (after #13820), head 16d0e81b02, to resolve the conflict on the pending-export count in the debt file. `main` still says 292 although #13820 removed two stubs, leaving 290, so the count is now set to the 287 stubs left in `Export.cpp`. It also restores the PS5 3.20 export table link, `b2a77c09cd71c01f34c790cfbe98c751a13262ad`, which the previous rebase had written without its zeros. Full build and `ctest -j16`: 3107/3107 pass (`log_file` failed once on #10486 and passed on five reruns and a second full run). `check_conventions.py --base upstream/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9446, #9448, #9571, #10395, #10418, #10448, #10450, #10477, #10478, #10481, #10482, #10483, #10485, #10486 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-24 03:14:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T03:14:26Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636575025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10488#pullrequestreview-5636575025). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-24T03:14:26Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
MarcZX10 commented 2026-10-24 12:15:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:15:33Z.

Review: APPROVED


Reviewed head 03cb3efab33b5daf4b3f51e8f4348750967a049f.

I checked the context size/field offsets and the three behaviors against the pinned LibreSSL 2.5.4 declarations and implementation: initialization clears the complete context, creation uses the guest calloc, and set_padding changes only EVP_CIPH_NO_PADDING while returning 1. The overlap with #9571 is in shared files; this diff leaves its CMAC exports untouched. I found no blocking correctness issue in the reviewed code.

The PR reports focused context tests and a 2005/2006 full CTest run, with the remaining failure also present on main; I did not reproduce those runs locally. Current convention, labels, eligibility, and report checks pass. Linux, Windows, register-context, relinker, write-watch, and ASan jobs are skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638204442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10488#pullrequestreview-5638204442). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:15:33Z. **Review:** APPROVED --- Reviewed head `03cb3efab33b5daf4b3f51e8f4348750967a049f`. I checked the context size/field offsets and the three behaviors against the pinned LibreSSL 2.5.4 declarations and implementation: initialization clears the complete context, creation uses the guest `calloc`, and `set_padding` changes only `EVP_CIPH_NO_PADDING` while returning 1. The overlap with #9571 is in shared files; this diff leaves its CMAC exports untouched. I found no blocking correctness issue in the reviewed code. The PR reports focused context tests and a 2005/2006 full CTest run, with the remaining failure also present on main; I did not reproduce those runs locally. Current convention, labels, eligibility, and report checks pass. Linux, Windows, register-context, relinker, write-watch, and ASan jobs are skipped.
MarcZX10 commented 2026-10-29 08:59:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:59:26Z.

Review: CHANGES_REQUESTED


Re-check — changes requested\n\nThe new report is useful: it says the implementation functions were preserved through the merge and the full test suite has the same single known failure as its tested main, with conventions passing. However, the tested integration point is 4c7d275bef; current upstream main is aaccd0ba39, and this PR head is 44 commits behind it.\n\nPlease update onto current main, preserve the implementation and debt-count changes, recount the pending exports against the resulting Export.cpp, and rerun the relevant LibreSSL tests plus conventions on the exact updated head. The earlier approval was for the prior head and does not cover this stale integration point. I did not rerun these checks locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695133653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10488#pullrequestreview-5695133653). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T08:59:26Z. **Review:** CHANGES_REQUESTED --- ## Re-check — changes requested\n\nThe new report is useful: it says the implementation functions were preserved through the merge and the full test suite has the same single known failure as its tested main, with conventions passing. However, the tested integration point is 4c7d275bef; current upstream main is aaccd0ba39, and this PR head is 44 commits behind it.\n\nPlease update onto current main, preserve the implementation and debt-count changes, recount the pending exports against the resulting Export.cpp, and rerun the relevant LibreSSL tests plus conventions on the exact updated head. The earlier approval was for the prior head and does not cover this stale integration point. I did not rerun these checks locally.
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!10488
No description provided.