feat(libSceLibreSsl3): implement RSA_up_ref #13267

Merged
msbutt1 merged 1 commit from upstream-pr/13267 into main 2026-10-30 17:50:24 +00:00
msbutt1 commented 2026-10-30 10:29:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by msbutt1 on 2026-10-30T10:29:19Z.


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: #10490
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: No
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5082928456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13267). Originally posted by [msbutt1](https://github.com/msbutt1) on 2026-10-30T10:29:19Z. --- ### What Implements `RSA_up_ref` (NID `jmDcorQ80dY`) in libSceLibreSsl3. - `LibreSsl3Rsa` in `include/Key.hpp` follows the [LibreSSL 4.0.0](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/rsa/rsa_local.h) `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](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/rsa/rsa_lib.c#L193-L196). 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](https://github.com/boykopovar/AnyPS5/pull/10490): #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 <!-- 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 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](https://github.com/boykopovar/AnyPS5/pull/13267#issuecomment-6520759020). - 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 <!-- 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: #10490 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: No
MarcZX10 commented 2026-10-30 10:35:42 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5711055012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13267#pullrequestreview-5711055012). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-30T10:35:42Z. **Review:** CHANGES_REQUESTED --- # 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. ```sh 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. | <details><summary>Unedited check output</summary> Diff check produced no output. Conventions: ```text All conventions checks passed. ``` ABI audit summary: ```json { "status": "passed", "findings": [] } ``` Test-quality heuristic: ```json { "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: ```text /tmp/anyps5-pr-precheck/local-dd9cf1591b3f/report.md /tmp/anyps5-pr-precheck/local-dd9cf1591b3f/report.json Conclusion: checks failed ``` Current-main merge preview: ```text 0d31a3a8c8fe089e0bc252a8980a88b07f9e8054 ``` Pairwise #10490/#13267 merge preview: ```text 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 ``` </details> ## 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 - [#13267 `LibreSsl3Rsa` definition at its reviewed head](https://github.com/boykopovar/AnyPS5/blob/dd9cf1591b3f9858084f6ab152042d186945416b/core/libs/prx/libSceLibreSsl3/include/Key.hpp#L27-L54). - [#10490 `Api.hpp` includes `Key.hpp` and defines the same type at its current head](https://github.com/boykopovar/AnyPS5/blob/ad00df544b5893dbe5f5db8ac5eabf9d008e735b/core/libs/prx/libSceLibreSsl3/include/Api.hpp#L3-L20). - [Repository overlap and dependency rule at current `main`](https://github.com/boykopovar/AnyPS5/blob/20d3cd84bc5a9f4a5b1f826cc678849187573d34/CONTRIBUTING.md#L62-L67). - [CMake registration for the changed test at #13267's head](https://github.com/boykopovar/AnyPS5/blob/dd9cf1591b3f9858084f6ab152042d186945416b/core/libs/prx/libSceLibreSsl3/CMakeLists.txt#L29-L34). ## 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.
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!13267
No description provided.