Skip to content

feat(libSceLibreSsl3): implement RSA_up_ref - #13267

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
msbutt1:feat/libressl3-rsa-up-ref
Oct 30, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
msbutt1:feat/libressl3-rsa-up-ref

Conversation

@msbutt1

@msbutt1 msbutt1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements RSA_up_ref (NID jmDcorQ80dY) in libSceLibreSsl3.

  • LibreSsl3Rsa in include/Key.hpp follows the LibreSSL 4.0.0 rsa_st layout: 152 bytes, references at offset 104. Unlike libSceLibreSsl's LibreSslRsa, it has no engine field and has pss after iqmp.
  • The export reuses the existing Retain_nid_no_patch helper used by EVP_PKEY_up_ref and EC_KEY_up_ref: an atomic increment that returns previous > 0, matching LibreSSL's CRYPTO_add(&r->references, 1, ...) > 1 in rsa_lib.c. A null key and a count already at INT32_MAX throw without mutation.
  • The stub is removed from Export.cpp and the declaration in Api.hpp takes LibreSsl3Rsa*.
  • guest_libressl3_key_reference gains an rsa case, and its shared check now also covers the overflow and null throws for all three retains.
  • The existing EVP_PKEY_up_ref/EC_KEY_up_ref debt entry is extended to RSA: the console layout and retain/release interoperability remain unverified.

Overlap: #10490 also defines LibreSsl3Rsa in Api.hpp with the same 152-byte layout, collapsing the fields after iqmp into unsigned char rest[64]. Landing order, agreed with @alvaroelpob: #10490 first. After it merges, this PR rebases, drops its own LibreSsl3Rsa from Key.hpp, and replaces #10490's unsigned char rest[64] with the named fields after iqmp (pss, extraData, references, flags, methodModN, methodModP, methodModQ, blinding, mtBlinding), so one definition remains. static_assert(offsetof(LibreSsl3Rsa, references) == 104) moves to src/Key.cpp, next to #10490's size and offset checks in KeyComponents.cpp. That version is prepared on #10490 head 16858710b4 (commit 4ca49b48a2): conventions pass, and all libSceLibreSsl3 tests pass on it, including #10490's guest_libressl3_key_components. The branch is updated once #10490 is in main.

Tested

Ubuntu 22.04, GCC 11.4.0, Release build with BUILD_TESTING=ON, head f1f3ba8ed4 on main 3bc58629fb (same patch-id as the earlier head dd9cf1591b). No title tested.

  • ctest --test-dir build -R "guest_libressl3|guest_crypto_memcmp|^public_headers": 69/69 passed (guest_libressl3_key_reference 0.01 s, public_headers and all 64 public_headers_compile_* batches).
  • python3 -I tools/check_conventions.py --base origin/main --head HEAD: all checks passed; git diff --check clean.
  • Windows 11, WinLibs GCC 15.2.0: guest_libressl3_key_reference 3/3 on dd9cf1591b, run by @JJenkx.
  • Negative controls, headers kept and only RSA_up_ref in src/Key.cpp mutated, guest_libressl3_key_reference_tests rsa:
Mutation Result
none passes
increments flags instead of references aborts: retain changed bytes outside reference count
returns 1 unconditionally aborts: retain return value
no INT32_MAX check (fetch_add) aborts: retain at maximum count did not throw
plain read-modify-write instead of atomic_ref aborts: concurrent count or adjacent bytes changed, 20/20 runs
no null check segfaults on the null call

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: feat(libSceLibreSsl3): implement the RSA, DH and DSA get0 key and parameter accessors #10490
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: No

@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 — changes requested

The current overlap with #10490 leaves duplicate LibreSsl3Rsa definitions unless the landing order and resulting single declaration are coordinated.

What I ran

Reviewed #13267 head dd9cf1591b3f9858084f6ab152042d186945416b; its recorded base is dd6cb90fc6bfffdf0787a4d838e2ad4d0eacc209. Current main is 20d3cd84bc5a9f4a5b1f826cc678849187573d34; the head merges cleanly onto it. I also compared the open #10490 head ad00df544b5893dbe5f5db8ac5eabf9d008e735b with this branch. Environment: Debian 12, x86-64, Python 3.11.2, Git 2.39.5. No build or C++ tests were run locally.

git diff --check 20d3cd84bc5a9f4a5b1f826cc678849187573d34...dd9cf1591b3f9858084f6ab152042d186945416b
python3 tools/pr_precheck.py --base 20d3cd84bc5a9f4a5b1f826cc678849187573d34 --head refs/review/pr-13267 --title 'feat(libSceLibreSsl3): implement RSA_up_ref' --body-file /tmp/anyps5-pr-13267-body.md
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 20d3cd84bc5a9f4a5b1f826cc678849187573d34 --head dd9cf1591b3f9858084f6ab152042d186945416b --json
python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/AnyPS5-pr13267-review --json core/libs/tests/GuestLibreSsl3KeyReference.cpp
git merge-tree --write-tree 20d3cd84bc5a9f4a5b1f826cc678849187573d34 refs/review/pr-13267
git merge-tree --write-tree refs/review/pr-10490 refs/review/pr-13267

Results

Check Result
Patch whitespace and conventions Passed.
No-build precheck Diff/conventions passed, but the report concluded checks failed because the isolated checkout lacks the local-only ABI and test-quality helper scripts. I ran those two focused helpers separately against this exact head. The initial GitHub-mode precheck could not complete because the live main advanced while the PR's recorded base remained dd6cb90f; I then ran local mode against current main.
ABI audit Passed with no findings; lexical audit only, not a compile or runtime ABI proof.
Test-quality heuristic Flagged the changed C++ test as possibly unregistered. Inspection confirms CMakeLists.txt registers GuestLibreSsl3KeyReference.cpp; the warning is a false positive.
Current-main merge preview Clean tree 0d31a3a8c8fe089e0bc252a8980a88b07f9e8054.
#10490 integration preview Textual conflict in docs/dev/debt/libSceLibreSsl3.md; the headers auto-merged. Inspection of the merged tree shows LibreSsl3Rsa defined in both Api.hpp and Key.hpp. No compilation was run.
Hosted CI Intake passed. Conventions and labels were pending at the final refresh.
Tests The PR description reports 69/69 tests on Ubuntu 22.04, but does not identify the tested head SHA; I did not independently run them. No local build/test.
Unedited check output

Diff check produced no output.

Conventions:

All conventions checks passed.

ABI audit summary:

{
  "status": "passed",
  "findings": []
}

Test-quality heuristic:

{
  "findings": [
    {
      "path": "core/libs/tests/GuestLibreSsl3KeyReference.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

Precheck output:

/tmp/anyps5-pr-precheck/local-dd9cf1591b3f/report.md
/tmp/anyps5-pr-precheck/local-dd9cf1591b3f/report.json
Conclusion: checks failed

Current-main merge preview:

0d31a3a8c8fe089e0bc252a8980a88b07f9e8054

Pairwise #10490/#13267 merge preview:

11d36c14e34b4742cfb799be2173cec1a8d97e00
100644 6607b4c8c56a85734d17bae9b2c8243d066f9e51 1 docs/dev/debt/libSceLibreSsl3.md
100644 ac168efdaf96b049aec1891098533256c6863045 2 docs/dev/debt/libSceLibreSsl3.md
100644 47310c5e30d9e8f192c1045aecc5a385fd0903dc 3 docs/dev/debt/libSceLibreSsl3.md

Auto-merging core/libs/prx/libSceLibreSsl3/CMakeLists.txt
Auto-merging core/libs/prx/libSceLibreSsl3/Export.cpp
Auto-merging core/libs/prx/libSceLibreSsl3/include/Api.hpp
Auto-merging docs/dev/debt/libSceLibreSsl3.md
CONFLICT (content): Merge conflict in docs/dev/debt/libSceLibreSsl3.md

Findings

Blocking

#10490's current Api.hpp includes Key.hpp and then defines LibreSsl3Rsa; #13267 adds another definition of the same type to Key.hpp. The two heads therefore produce a duplicate type definition when integrated, even though their individual branches are each mergeable. The PR description recognizes that whichever change lands second must retain the named fields, but neither PR currently declares the agreed order. Please coordinate the order with #10490's author, keep the type defined in one header in the resulting branch, and declare the dependency on the checklist of the PR that follows, as CONTRIBUTING.md requires.

Non-blocking

No additional confirmed findings in the RSA_up_ref implementation or its reference-count tests.

Sources

Not verified

No local build, C++ test run, Windows or Linux runtime test, title/homebrew run, or PS5 console behavior. The hosted Windows/product checks were not present in the current check snapshot. The broad pr_overlap.py scan was interrupted; the known overlap with #10490 was inspected directly.

To get this to a good state

Coordinate and declare the landing order with #10490, remove the duplicate LibreSsl3Rsa definition from the second branch while preserving the named fields needed by RSA_up_ref, and obtain fresh CI. I will rerun the same relevant checks on the updated head.

@JJenkx

JJenkx commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Windows run of this head (dd9cf1591b), merged onto main a5939f10a8 (clean merge, local only). Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, no Vulkan driver visible.

  • This PR: guest_libressl3_key_reference passes 3 of 3 (ctest --repeat until-fail:3).
  • Negative control: not possible. With this PR's source files (core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/include/Key.hpp, core/libs/prx/libSceLibreSsl3/src/Key.cpp) put back to main's version, the build fails against the rest of the PR, so there is no source-only control.

AI-assisted: yes (Claude Code).

@msbutt1

msbutt1 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@JJenkx thanks for the Windows run; it is linked in the description. The rebased head f1f3ba8ed4 carries the same patch (same patch-id as dd9cf1591b). For the negative control, I kept the headers and mutated only RSA_up_ref in src/Key.cpp: the test aborts by its own assertions for a wrong counter, a constant return, a missing INT32_MAX check and a non-atomic increment (20/20 runs), and segfaults without the null check. The table is in the description.

@github-actions

github-actions Bot commented Oct 30, 2026 •

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 10491 docs/dev/debt/libSceLibreSsl3.md L5
PR 10493 docs/dev/debt/libSceLibreSsl3.md L5
PR 10557 docs/dev/debt/libSceLibreSsl3.md L5
PR 10631 docs/dev/debt/libSceLibreSsl3.md L5
PR 10960 docs/dev/debt/libSceLibreSsl3.md L5, L12
PR 12315 docs/dev/debt/libSceLibreSsl3.md L5, L12-13
PR 12578 core/libs/prx/libSceLibreSsl3/include/Key.hpp L26, L30
core/libs/prx/libSceLibreSsl3/src/Key.cpp L37
core/libs/tests/GuestLibreSsl3KeyReference.cpp L66
docs/dev/debt/libSceLibreSsl3.md L5, L12
PR 12580 core/libs/prx/libSceLibreSsl3/include/Key.hpp L26, L30
core/libs/prx/libSceLibreSsl3/src/Key.cpp L37
core/libs/tests/GuestLibreSsl3KeyReference.cpp L66
docs/dev/debt/libSceLibreSsl3.md L5, L12
PR 12582 core/libs/prx/libSceLibreSsl3/include/Key.hpp L26-27, L30
core/libs/prx/libSceLibreSsl3/src/Key.cpp L37
core/libs/tests/GuestLibreSsl3KeyReference.cpp L9, L66
docs/dev/debt/libSceLibreSsl3.md L5, L12
PR 12754 core/libs/prx/libSceLibreSsl3/include/Key.hpp L26, L30
core/libs/prx/libSceLibreSsl3/src/Key.cpp L37
core/libs/tests/GuestLibreSsl3KeyReference.cpp L66
docs/dev/debt/libSceLibreSsl3.md L5, L12

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 12928 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 12945 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
core/libs/prx/libSceLibreSsl3/include/Key.hpp
core/libs/prx/libSceLibreSsl3/src/Key.cpp
core/libs/tests/GuestLibreSsl3KeyReference.cpp
docs/dev/debt/libSceLibreSsl3.md

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Progress report (1b097ab → f1f3ba8)

📈 System libraries: 42.42% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceLibreSsl3 RSA_up_ref_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 8/270 (2.96%) 9/270 (3.33%) +0.37%

@msbutt1

msbutt1 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks, addressed point by point on head f1f3ba8ed4:

@adriadam10
adriadam10 merged commit f5a0356 into boykopovar:main Oct 30, 2026
13 of 14 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the rsa_st layout (152 bytes, references at 104) against LibreSSL 4.0.0, the shared atomic retain with null and INT32_MAX throws, the extended guest_libressl3_key_reference test (each author mutation is covered by an assertion) and the debt entry. The LibreSsl3Rsa overlap with #10490 is resolved by landing this first, as the description says; #10490 drops its definition when it rebases. Merged.

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.

4 participants