Skip to content

feat(libSceLibreSsl3): implement EVP_CIPHER_CTX_set_flags - #11056

Closed
StoneDC wants to merge 1 commit into
boykopovar:mainfrom
StoneDC:feat/libressl3-cipher-context-flags
Closed

StoneDC wants to merge 1 commit into
boykopovar:mainfrom
StoneDC:feat/libressl3-cipher-context-flags

Conversation

@StoneDC

@StoneDC StoneDC commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

EVP_CIPHER_CTX_set_flags in libSceLibreSsl3 currently throws. Implement its void (EVP_CIPHER_CTX*, int) contract, OR-ing the signed mask into the 64-bit context flags while preserving every other byte. The canonical public declaration exposes the guest calling convention and an explicit LP64 context layout on Windows.

The signature and behavior follow LibreSSL 4.0.0 evp_cipher.c and evp_local.h. A null context throws where the original dereferences it. Console signature/layout equivalence remains unverified and is recorded in the library's debt file.

There is no functional prerequisite. Shared edits to CMake, the public header and the pending-export paragraph overlap #9970, #10452, #10461, #10490, #10491, #10493, #10557, #10631, #10948 and #10960. Their landing order has not been agreed. Depends on: none records the absence of a functional prerequisite; shared-file landing order remains to be coordinated before merging. I can rebase after those changes land.

Tested

Final local commit: 7de7ed5012a100a020bb4d214c7a1f634846b643; base: 636a9c1eecce2e467dba12476e3a42a82e540c7f.

  • Native Windows x86-64, WinLibs GCC 15.2.0 UCRT r7, Release: all 368 runtime libraries, the relinker and focused test targets built after rebasing. Five focused checks passed: flags, LibreSSL3 digests, crypto comparison, patched libraries and public-header audit.
  • Ubuntu 26.04 WSL2 x86-64, GCC 15.2.0, Release: the complete changed module and its real runtime dependencies built through their repository CMake files in an external focused harness. All 12 related CTests passed. No runtime stubs or mocked heap were used. This was not a whole Linux repository build.
  • The same Linux runtime and tests built with AddressSanitizer and UndefinedBehaviorSanitizer (-fsanitize=address,undefined, fail-fast checks and leak detection): 12/12 passed with no sanitizer report.
  • An unmodified official LibreSSL 4.0.0 build independently measured LP64 long as 8 bytes, its context as 160 bytes and flags at offset 104. Full context bytes matched for 100,040 inputs, each called twice: 200,080 comparisons passed, including every mask bit, signed limits and deterministic mixed masks.
  • The existing regression rejected three temporary production mutations: assignment instead of OR, zero-extension through uint32_t, and a write at offset 112. Each failed its behavioral assertion. Original source bytes were restored, rebuilt and the regression passed.
  • Tests cover stack and guest-heap contexts, existing high bits, repeated and zero masks, negative masks, complete-object/neighbor canaries and the null-context exception.
  • Code conventions, whitespace checks and canonical umbrella compilation passed. Final-commit overlap scan covered 1333 open PR refs; no competing implementation was found. feat(libSceLibreSsl): implement numeric ERR formatting and newest peeking #9535, feat(libSceLibreSsl): implement memory BIOs #9536 and feat(libSceLibreSsl): implement CMAC with AES-CBC methods #9571 required manual inspection and still contain the throwing placeholder.

PS5 hardware, games and upstream CI were not run.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

Copy link
Copy Markdown

Progress report (160f659 → 7de7ed5)

➖ System libraries: 49.65% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceLibreSsl3 EVP_CIPHER_CTX_set_flags_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 1/87 (1.15%) 2/87 (2.30%) +1.15 pp

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

I reviewed the implementation and the host-side behavior is consistent with the cited LibreSSL 4.0.0 source. The new regression covers OR semantics, sign extension, writes outside the flags field, and repeat calls. I also ran g++ -std=c++20 -Icore/libs -fsyntax-only on Export.cpp and GuestLibreSsl3CipherFlags.cpp, tools/check_conventions.py --base refs/review/upstream-main, and git diff --check; all passed. A full local CMake configure could not proceed because the SDL2 submodule is absent and SDL XRandR support is unavailable; hosted product jobs are skipped by path policy.

Two items still block approval:

  1. LibreSsl3CipherContext and the write at offset 104 are inferred from LibreSSL 4.0.0, but the PR says the PS5 libSceLibreSsl3 signature and context layout are unverified. The guest passes an existing context created by the target library; host tests against the newly declared struct only prove the adapter against that struct, not that a PS5 context has 64-bit flags at offset 104. Please provide target ABI evidence (for example, a measured console context or disassembly establishing the argument contract and field offset/width). Without it, this write can modify the wrong field or corrupt the context; keep the export on the throwing path until the guest ABI is established.

  2. The description says merge order for the ten shared-file PRs is unresolved. I fetched their current heads and trial-merged them against this head: content conflicts remain with #9970, #10452, #10461, #10490, #10491, #10493, #10557, #10631, #10948 and #10960, in the stated CMake/header/debt files. CONTRIBUTING.md requires author agreement on overlap order and a matching Depends on checklist entry when another PR must land first. Please coordinate the order and update the checklist before this is considered ready. No competing implementation of this exact function appeared in those diffs.

@StoneDC

StoneDC commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the careful review and for identifying the missing target ABI evidence.

I agree that the LibreSSL 4.0.0 source and host-side tests establish the behavior of the proposed adapter, but do not establish the PS5 context layout or justify writing at offset 104. I do not currently have a console measurement or module disassembly that closes that gap, so the export should remain on the existing throwing path.

I prepared a local rollback of the implementation, inferred layout and associated test. After that rollback, the net change against current main is only an additional technical-debt entry, which does not provide enough value to continue pursuing this PR. That rollback has not been pushed. The shared-file merge order also remains unagreed; I am not treating the overlap concern as resolved.

I am therefore closing this PR. I will retain the implementation and host-side validation as reference material and revisit a functional contribution once the PS5 argument contract, field offset/width and update semantics can be verified, with any remaining overlap coordinated at that point.

Thank you again for the review and your time.

@StoneDC StoneDC closed this Oct 25, 2026
@github-actions

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9970 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L17, L19
docs/dev/debt/libSceLibreSsl3.md L5
PR 10452 core/libs/prx/libSceLibreSsl3/include/Api.hpp L4
docs/dev/debt/libSceLibreSsl3.md L5
PR 10461 docs/dev/debt/libSceLibreSsl3.md L5
PR 10490 core/libs/prx/libSceLibreSsl3/include/Api.hpp L4
docs/dev/debt/libSceLibreSsl3.md L5
PR 10491 core/libs/prx/libSceLibreSsl3/include/Api.hpp L4
docs/dev/debt/libSceLibreSsl3.md L5
PR 10493 core/libs/prx/libSceLibreSsl3/include/Api.hpp L4
docs/dev/debt/libSceLibreSsl3.md L5
PR 10557 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L19
docs/dev/debt/libSceLibreSsl3.md L5
PR 10631 docs/dev/debt/libSceLibreSsl3.md L5
PR 10948 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L17, L19
docs/dev/debt/libSceLibreSsl3.md L5
PR 10960 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L17, L19
core/libs/prx/libSceLibreSsl3/include/Api.hpp L3-4, L21-22
docs/dev/debt/libSceLibreSsl3.md L5

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 9535 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 9536 core/libs/prx/libSceLibreSsl3/Export.cpp
docs/dev/debt/libSceLibreSsl3.md
PR 9571 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md

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