feat(libSceLibreSsl): implement EVP_PKEY_new and EVP_PKEY_free #10570

Merged
MarcZX10 merged 8 commits from upstream-pr/10570 into main 2026-11-05 22:54:59 +00:00
MarcZX10 commented 2026-10-24 10:22:50 +00:00 (Migrated from github.com)

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


What

Implements EVP_PKEY_new and EVP_PKEY_free in libSceLibreSsl. The 56-byte key follows the LP64 layout of LibreSSL 2.5.4's EVP_PKEY (type, save_type, references, ameth, engine, key, save_parameters, attributes); a new key has type and save_type EVP_PKEY_NONE, one reference and save_parameters set. EVP_PKEY_free accepts null, drops one reference atomically and releases the key on the last one. A key that holds an engine, method, algorithm data or attributes throws through NotImplemented_nid_no_patch, because no export can attach them yet.

Sources are linked in the technical debt file. PS5 behavior has not been independently measured.

Commits: for each function in turn (EVP_PKEY_new, then EVP_PKEY_free), the implementation, its test and its debt entry.

The first field is the key type, so this layout matches the one EVP_PKEY_id reads in #10418. Both PRs edit adjacent lines of Export.cpp and CMakeLists.txt, so expect a textual conflict, with no code dependency.

Tested

On the rebased head, compiled PkeyLifecycle.cpp and GuestLibreSslPkeyLifecycle.cpp with GCC C++20, -Wall -Wextra -Werror, and a local shim for the guest allocator and throw path; the focused lifecycle test exited 0. git diff --check and python3 tools/check_conventions.py --base upstream/main --head HEAD pass. A full CMake configure could not be repeated from this isolated checkout because its SDL2 submodule is not populated and XRandR is unavailable; Windows was 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4994577341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10570). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T10:22:50Z. --- ### What Implements `EVP_PKEY_new` and `EVP_PKEY_free` in libSceLibreSsl. The 56-byte key follows the LP64 layout of LibreSSL 2.5.4's `EVP_PKEY` (type, save_type, references, ameth, engine, key, save_parameters, attributes); a new key has type and save_type `EVP_PKEY_NONE`, one reference and `save_parameters` set. `EVP_PKEY_free` accepts null, drops one reference atomically and releases the key on the last one. A key that holds an engine, method, algorithm data or attributes throws through `NotImplemented_nid_no_patch`, because no export can attach them yet. Sources are linked in the technical debt file. PS5 behavior has not been independently measured. Commits: for each function in turn (`EVP_PKEY_new`, then `EVP_PKEY_free`), the implementation, its test and its debt entry. The first field is the key type, so this layout matches the one `EVP_PKEY_id` reads in #10418. Both PRs edit adjacent lines of `Export.cpp` and `CMakeLists.txt`, so expect a textual conflict, with no code dependency. ### Tested On the rebased head, compiled `PkeyLifecycle.cpp` and `GuestLibreSslPkeyLifecycle.cpp` with GCC C++20, `-Wall -Wextra -Werror`, and a local shim for the guest allocator and throw path; the focused lifecycle test exited 0. `git diff --check` and `python3 tools/check_conventions.py --base upstream/main --head HEAD` pass. A full CMake configure could not be repeated from this isolated checkout because its SDL2 submodule is not populated and XRandR is unavailable; Windows was not run. ### 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](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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 12:29:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:29:19Z.

Review: COMMENTED


Checked against main 87666fc5d6 and LibreSSL 2.5.4 (evp/p_lib.c and evp/evp.h at 2e2c612):

  • The 56-byte layout, the initial values from EVP_PKEY_new, and EVP_PKEY_free's decrement / <= 0 release match p_lib.c:186-205 and 402-418. Using malloc_nid_postfix/free_nid_postfix pairs correctly with main's CRYPTO_free, and throwing (with the reference restored) for keys that carry ameth/engine/key/attributes seems right while nothing can attach them.
  • The evp_local.h link in the debt entry is 404 at 2e2c612; that header was added in later LibreSSL releases. In 2.5.4, struct evp_pkey_st is in src/lib/libcrypto/evp/evp.h (lines 124-149). Could the link point there?
  • Heads-up: this and #10571 both rewrite line 1 of libSceLibreSsl/CMakeLists.txt, insert test blocks at the same spot, and edit the same debt count line, so whichever merges second will need a rebase, and the count should end at 354.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638238312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10570#pullrequestreview-5638238312). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:29:19Z. **Review:** COMMENTED --- Checked against main 87666fc5d6 and LibreSSL 2.5.4 (evp/p_lib.c and evp/evp.h at 2e2c612): - The 56-byte layout, the initial values from `EVP_PKEY_new`, and `EVP_PKEY_free`'s decrement / `<= 0` release match p_lib.c:186-205 and 402-418. Using `malloc_nid_postfix`/`free_nid_postfix` pairs correctly with main's `CRYPTO_free`, and throwing (with the reference restored) for keys that carry ameth/engine/key/attributes seems right while nothing can attach them. - The `evp_local.h` link in the debt entry is 404 at 2e2c612; that header was added in later LibreSSL releases. In 2.5.4, `struct evp_pkey_st` is in `src/lib/libcrypto/evp/evp.h` (lines 124-149). Could the link point there? - Heads-up: this and #10571 both rewrite line 1 of `libSceLibreSsl/CMakeLists.txt`, insert test blocks at the same spot, and edit the same debt count line, so whichever merges second will need a rebase, and the count should end at 354. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
ahmadmuj commented 2026-10-25 18:06:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T18:06:50Z.

Review: APPROVED


Checked head 48b67ca8 merged onto main 7a25f876, Linux, GCC 13, Release. Only the debt file conflicts (I kept main's side locally), so that part still needs the rebase.

What I ran:

  • Built guest_libressl_pkey_lifecycle_tests on the merge. ctest -R guest_libressl_pkey_lifecycle passes. With EVP_PKEY_new swapped back to a NotImplemented_nid_no_patch stub it aborts, so the test really goes red to green.
  • Probed a LibreSSL 2.5.4 build from the release tarball (SHA256 matches the published one): sizeof(EVP_PKEY) 56, offsets 0/4/8/16/24/32/40/48, and EVP_PKEY_new gives type 0, save_type 0, references 1, null pointers, save_parameters 1. The PR's object has the same values at the same offsets, with the padding zeroed.
  • Freeing a 2-ref key leaves 1 on both 2.5.4 and the PR.
  • Throw path: a last free with a non-null ameth, engine, key or attributes throws and leaves references at 1. After clearing the field, the key frees fine.
  • check_conventions.py passes. Export.cpp goes from 345 to 343 NotImplemented_nid_no_patch(__func__) stubs, which matches the debt count.

Two non-blocking test notes:

  • The test only reads bytes 0-11, so dropping pkey->saveParameters = 1; still passes (I tried it). One more read at offset 40 would pin it, e.g. int saveParameters; std::memcpy(&saveParameters, static_cast<std::byte*>(pkey) + 40, sizeof(saveParameters)); Require(saveParameters == 1, "a new key saves parameters");
  • With the throw block gone, deleting the references.fetch_add(1, ...) restore also passes. Main's LibreSSL tests do pin throw paths (RequireThrows in core/libs/prx/libSceLibreSsl/tests/Asn1.cpp), so the old block that set offset 32, caught the throw and checked references == 1 would fit there.

Approving on the evidence above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644556534 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10570#pullrequestreview-5644556534). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T18:06:50Z. **Review:** APPROVED --- Checked head 48b67ca8 merged onto main 7a25f876, Linux, GCC 13, Release. Only the debt file conflicts (I kept main's side locally), so that part still needs the rebase. What I ran: - Built `guest_libressl_pkey_lifecycle_tests` on the merge. `ctest -R guest_libressl_pkey_lifecycle` passes. With `EVP_PKEY_new` swapped back to a `NotImplemented_nid_no_patch` stub it aborts, so the test really goes red to green. - Probed a LibreSSL 2.5.4 build from the release tarball (SHA256 matches the published one): `sizeof(EVP_PKEY)` 56, offsets 0/4/8/16/24/32/40/48, and `EVP_PKEY_new` gives type 0, save_type 0, references 1, null pointers, save_parameters 1. The PR's object has the same values at the same offsets, with the padding zeroed. - Freeing a 2-ref key leaves 1 on both 2.5.4 and the PR. - Throw path: a last free with a non-null ameth, engine, key or attributes throws and leaves references at 1. After clearing the field, the key frees fine. - `check_conventions.py` passes. Export.cpp goes from 345 to 343 `NotImplemented_nid_no_patch(__func__)` stubs, which matches the debt count. Two non-blocking test notes: - The test only reads bytes 0-11, so dropping `pkey->saveParameters = 1;` still passes (I tried it). One more read at offset 40 would pin it, e.g. `int saveParameters; std::memcpy(&saveParameters, static_cast<std::byte*>(pkey) + 40, sizeof(saveParameters)); Require(saveParameters == 1, "a new key saves parameters");` - With the throw block gone, deleting the `references.fetch_add(1, ...)` restore also passes. Main's LibreSSL tests do pin throw paths (`RequireThrows` in `core/libs/prx/libSceLibreSsl/tests/Asn1.cpp`), so the old block that set offset 32, caught the throw and checked references == 1 would fit there. Approving on the evidence above.
MarcZX10 commented 2026-11-02 04:57:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:33Z.

Review: COMMENTED


Reviewed — debt count and conflict requests checked, count not confirmed against main

The head is now mergeable and the debt count matches this head's Export.cpp, but the reviewer's 298 was computed on an older base and is not confirmed here.

What I ran

  • Live head 463b9496289803533c2f892c331385db709950fa (matches batch; merge of main a644edf30c).
  • gh pr view 10570 (headRefOid, mergeable, statusCheckRollup); gh api GET of comments and reviews newer than 2026-10-25T04:02:57Z.
  • git show of docs/dev/debt/libSceLibreSsl.md and core/libs/prx/libSceLibreSsl/Export.cpp at the head; git grep -c of NotImplemented_nid_no_patch(func) in Export.cpp.
  • Nothing was built or run.

Results

Check Result Note
eligibility, conventions, library-portability, labels, report SUCCESS hosted
windows SUCCESS hosted
relinker, relinker-asan, register-context, write-watch SKIPPED hosted
linux SKIPPED hosted
merge state MERGEABLE / CLEAN the 2026-10-28 conflict report no longer applies

Findings

  • oneandonlydean (2026-10-29T05:51:38Z) asks for the pending-exports count to be 298 instead of 299 (or the number removed if #11553 lands first).
    • This head's debt doc line 12 says 288, and Export.cpp has 288 NotImplemented_nid_no_patch(func) lines. The bullet matches this file.
    • The reviewer's 298 was computed on an earlier base; the base changed when main was merged. Not verified against current main.
    • #11553 is still OPEN, so the number stays.
  • The 2026-10-28 conflict report (CMakeLists.txt, debt doc) is resolved at this head per hosted merge state.
  • BunnyFl's firmware-run reports (2026-10-26, 2026-10-27) are not checkable from code.

Sources

Not verified

  • The 298 count against current main.
  • The firmware runs and the Windows run from BunnyFl; not reproduced.
  • No build.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732249718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10570#pullrequestreview-5732249718). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:57:33Z. **Review:** COMMENTED --- # Reviewed — debt count and conflict requests checked, count not confirmed against main The head is now mergeable and the debt count matches this head's Export.cpp, but the reviewer's 298 was computed on an older base and is not confirmed here. ## What I ran - Live head 463b9496289803533c2f892c331385db709950fa (matches batch; merge of main a644edf30c). - gh pr view 10570 (headRefOid, mergeable, statusCheckRollup); gh api GET of comments and reviews newer than 2026-10-25T04:02:57Z. - git show of docs/dev/debt/libSceLibreSsl.md and core/libs/prx/libSceLibreSsl/Export.cpp at the head; git grep -c of NotImplemented_nid_no_patch(__func__) in Export.cpp. - Nothing was built or run. ## Results | Check | Result | Note | |---|---|---| | eligibility, conventions, library-portability, labels, report | SUCCESS | hosted | | windows | SUCCESS | hosted | | relinker, relinker-asan, register-context, write-watch | SKIPPED | hosted | | linux | SKIPPED | hosted | | merge state | MERGEABLE / CLEAN | the 2026-10-28 conflict report no longer applies | ## Findings - oneandonlydean (2026-10-29T05:51:38Z) asks for the pending-exports count to be 298 instead of 299 (or the number removed if #11553 lands first). - This head's debt doc line 12 says 288, and Export.cpp has 288 NotImplemented_nid_no_patch(__func__) lines. The bullet matches this file. - The reviewer's 298 was computed on an earlier base; the base changed when main was merged. Not verified against current main. - #11553 is still OPEN, so the number stays. - The 2026-10-28 conflict report (CMakeLists.txt, debt doc) is resolved at this head per hosted merge state. - BunnyFl's firmware-run reports (2026-10-26, 2026-10-27) are not checkable from code. ## Sources - https://github.com/boykopovar/AnyPS5/blob/463b9496289803533c2f892c331385db709950fa/docs/dev/debt/libSceLibreSsl.md#L12 - https://github.com/boykopovar/AnyPS5/blob/463b9496289803533c2f892c331385db709950fa/core/libs/prx/libSceLibreSsl/Export.cpp#L705-L725 ## Not verified - The 298 count against current main. - The firmware runs and the Windows run from BunnyFl; not reproduced. - No build.
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!10570
No description provided.