feat(libSceLibreSsl3): implement EVP digest contexts and SHA methods #10960

Merged
AZLisme merged 12 commits from upstream-pr/10960 into main 2026-11-05 08:44:50 +00:00
AZLisme commented 2026-10-25 11:21:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AZLisme on 2026-10-25T11:21:36Z.


What

Implement EVP_MD_CTX_new, EVP_MD_CTX_free, EVP_DigestInit, EVP_sha1 and EVP_sha224 with guest-heap ownership and SysV callbacks. The opaque SSL3 types share the legacy provider's 120-byte method / 48-byte context representation so its ordinary digest operations can consume these records. Engine and owned-key-context handling remains explicit throwing debt; the documented host representation differs from native firmware layouts.

Current head 176068deee632b72a753f1495852b8e8e8a3df56 incorporates B-Howell's preserving merge b81773f7 and frozen main 1e24993fa3a7da25e8fc27152af654687ba64552. The CMake/debt resolutions retain both sides, including current main's X509, error and initialization work. The five EVP implementations and their fixtures are unchanged. All declared prerequisites (#10948, #11165 and #9448) are actually merged.

Tested

  • Current head 176068deee632b72a753f1495852b8e8e8a3df56 on frozen main 1e24993fa3a7da25e8fc27152af654687ba64552: normal Linux x86-64/GCC 16.2.1 Release providers and original core fixtures built. 69 runtime CTests and 65 public-header CTests passed, zero failures/skips. The runtime set includes LibreSSL/SSL3, crypto, 10 libSceSsl cases and mixed EVP in both requested load orders (3,824 cases each). It covers main's new X509, OCSP, cipher and initialization fixtures.
  • The normal full libs build and its existing protocol dependencies completed successfully. The two protocol cases and patched_libraries passed 3/3 after the 66 core cases, giving 69 unique runtime passes: each protocol exercised 7,056 generated pairs; 406 patched libraries loaded with zero failures. Dependencies, assertions and timeouts are unchanged.
  • Current-head native Windows run 41985682543, job 127105738142 tested exact 176068de with frozen main 1e24993f, built the full normal libraries and 57 original fixture targets, and passed 68/68 runtime plus 65/65 public-header tests, zero failures/skips/NotRun. This includes both EVP providers, protocol/NID fixtures, current main's added family fixtures and 406 patched libraries loaded, zero failed. Linux-only mixed-EVP has no Windows registration and was not run there. Actual CTest selection, executable targets, source identity and complete unique JUnit results were checked.
  • Independent source review confirmed all five implementations/fixtures preserved, 395 unique parent-library forwarders and 68 remaining SSL3 throwing stubs (current main's 73 minus these five). Main's new X509_PUBKEY_get0_param is retained. python3 tools/check_conventions.py --base origin/main and the topic whitespace check pass.
  • Historical native Windows run 41601926307 tested earlier head 4a33c0bf with frozen main d1ae628b: 59 runtime plus 65 header tests passed; 405 patched libraries loaded. Historical upstream run 41603606859 tested 4a33c0bf with main 4f41f4c3: 2,116 passed, 976 skipped, zero failed; all 63 then-selected SSL-family cases passed. Neither historical run qualifies this current integration; skipped cases remain unexecuted.

No current macOS, title execution, native-console ABI, GPU or full-project test result is claimed. Representation and unsupported-operation gaps remain documented debt.

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: #10948, #11165, #9448
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004249742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10960). Originally posted by [AZLisme](https://github.com/AZLisme) on 2026-10-25T11:21:36Z. --- ### What Implement `EVP_MD_CTX_new`, `EVP_MD_CTX_free`, `EVP_DigestInit`, `EVP_sha1` and `EVP_sha224` with guest-heap ownership and SysV callbacks. The opaque SSL3 types share the legacy provider's 120-byte method / 48-byte context representation so its ordinary digest operations can consume these records. Engine and owned-key-context handling remains explicit throwing debt; the documented host representation differs from native firmware layouts. Current head `176068deee632b72a753f1495852b8e8e8a3df56` incorporates B-Howell's preserving merge `b81773f7` and frozen main `1e24993fa3a7da25e8fc27152af654687ba64552`. The CMake/debt resolutions retain both sides, including current main's X509, error and initialization work. The five EVP implementations and their fixtures are unchanged. All declared prerequisites (#10948, #11165 and #9448) are actually merged. ### 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. --> - Current head `176068deee632b72a753f1495852b8e8e8a3df56` on frozen main `1e24993fa3a7da25e8fc27152af654687ba64552`: normal Linux x86-64/GCC 16.2.1 Release providers and original core fixtures built. **69 runtime CTests and 65 public-header CTests passed**, zero failures/skips. The runtime set includes LibreSSL/SSL3, crypto, 10 libSceSsl cases and mixed EVP in both requested load orders (3,824 cases each). It covers main's new X509, OCSP, cipher and initialization fixtures. - The normal full `libs` build and its existing protocol dependencies completed successfully. The two protocol cases and `patched_libraries` passed 3/3 after the 66 core cases, giving 69 unique runtime passes: each protocol exercised 7,056 generated pairs; 406 patched libraries loaded with zero failures. Dependencies, assertions and timeouts are unchanged. - Current-head native Windows [run 41985682543, job 127105738142](https://github.com/AZLisme/AnyPS5/actions/runs/41985682543/job/127105738142) tested exact `176068de` with frozen main `1e24993f`, built the full normal libraries and 57 original fixture targets, and passed **68/68 runtime plus 65/65 public-header tests**, zero failures/skips/NotRun. This includes both EVP providers, protocol/NID fixtures, current main's added family fixtures and **406 patched libraries loaded, zero failed**. Linux-only mixed-EVP has no Windows registration and was not run there. Actual CTest selection, executable targets, source identity and complete unique JUnit results were checked. - Independent source review confirmed all five implementations/fixtures preserved, 395 unique parent-library forwarders and 68 remaining SSL3 throwing stubs (current main's 73 minus these five). Main's new `X509_PUBKEY_get0_param` is retained. `python3 tools/check_conventions.py --base origin/main` and the topic whitespace check pass. - Historical [native Windows run 41601926307](https://github.com/AZLisme/AnyPS5/actions/runs/41601926307) tested earlier head `4a33c0bf` with frozen main `d1ae628b`: 59 runtime plus 65 header tests passed; 405 patched libraries loaded. Historical [upstream run 41603606859](https://github.com/boykopovar/AnyPS5/actions/runs/41603606859) tested `4a33c0bf` with main `4f41f4c3`: 2,116 passed, 976 skipped, zero failed; all 63 then-selected SSL-family cases passed. Neither historical run qualifies this current integration; skipped cases remain unexecuted. No current macOS, title execution, native-console ABI, GPU or full-project test result is claimed. Representation and unsupported-operation gaps remain documented debt. ### 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: <!-- #PR, or none --> #10948, #11165, #9448 - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-25 12:06:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T12:06:58Z.

Review: APPROVED


Reviewed exact head 1f580e6c39c7c3d5bebaf80d47a602b97da32062 against the pinned LibreSSL evp_digest.c and evp_local.h. The SHA descriptors and context offsets/sizes match the stated 64-bit ABI layout; init/update/final callbacks route to existing SHA implementations with their expected context types. Allocation, secure clearing, cleanup-once, REUSE, CLEANED, and KEEP_PKEY_CTX handling follow the reference cleanup/init rules, with unsupported owned key-context and negative-size cases left explicit as debt. The tests cover known and million-byte vectors, split updates, custom descriptors, callbacks, allocation failure and ownership transitions. Local git diff --check and python3 tools/check_conventions.py --base upstream/main --head refs/review/10960 passed. Hosted eligibility, intake, conventions, labels, and report checks pass; hosted product jobs were skipped. I have not independently rerun the author-reported Linux focused suite or differential checks; Windows, macOS, and console execution remain unverified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643136100 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10960#pullrequestreview-5643136100). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T12:06:58Z. **Review:** APPROVED --- Reviewed exact head `1f580e6c39c7c3d5bebaf80d47a602b97da32062` against the pinned LibreSSL `evp_digest.c` and `evp_local.h`. The SHA descriptors and context offsets/sizes match the stated 64-bit ABI layout; init/update/final callbacks route to existing SHA implementations with their expected context types. Allocation, secure clearing, cleanup-once, REUSE, CLEANED, and KEEP_PKEY_CTX handling follow the reference cleanup/init rules, with unsupported owned key-context and negative-size cases left explicit as debt. The tests cover known and million-byte vectors, split updates, custom descriptors, callbacks, allocation failure and ownership transitions. Local `git diff --check` and `python3 tools/check_conventions.py --base upstream/main --head refs/review/10960` passed. Hosted eligibility, intake, conventions, labels, and report checks pass; hosted product jobs were skipped. I have not independently rerun the author-reported Linux focused suite or differential checks; Windows, macOS, and console execution remain unverified.
ahmadmuj commented 2026-10-25 19:01:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T19:01:47Z.

Review: COMMENTED


Checked head 9e30098fa6c6 (base 5949d8bf924b; also merges clean onto main e1ef22e888d7). Linux, GCC 13.3, Release + an ASan build.

What I ran:

  • guest_libressl3_evp on the head: pass. check_conventions.py --base origin/main: pass.
  • Compiled the 4.0.0 evp_md_st / evp_md_ctx_st from evp_local.h at ce488b78: 80 and 40 bytes, every offset matches your static_asserts. The SHA1/SHA224 descriptor values match m_sha1.c (ctx_size 104/120 = 8 + 96/112).
  • Merged #9448 (head 5994190d7094, 2.5.4 layouts) on top of this branch and ran a probe through both libraries.

The 4.0.0 layout here is right on its own. The issue is what serves the rest of the digest API for a libSceLibreSsl3 title:

  • On the PS5 3.20 table, libSceLibreSsl3 exports all 399 libSceLibreSsl names too, including EVP_DigestInit_ex, EVP_DigestUpdate, EVP_DigestFinal_ex, EVP_Digest, EVP_MD_CTX_cleanup, and EVP_md5. Our libSceLibreSsl3 only implements the 89 extra names.
  • On Linux, those imports bind to libSceLibreSsl. The relinker writes bare NIDs, and libSceLibreSsl3.prx has DT_NEEDED libSceLibreSsl.prx. LD_DEBUG=bindings on an exe that only needs libSceLibreSsl3 shows 6LrAQY0Ka4c (EVP_DigestUpdate) bound to libSceLibreSsl.prx.
  • So the normal call order for an l3 title is l3 EVP_MD_CTX_new + l3 EVP_DigestInit + l1 EVP_DigestUpdate. Once #9448 lands, that l1 code reads its 48-byte/120-byte layout.

Composed run (this PR + #9448), SHA1/SHA224 "abc", 56 and 1000 bytes:

  • l3 new -> l3 EVP_DigestInit(ctx, EVP_sha1()) -> l1 EVP_DigestUpdate: ASan heap-buffer-overflow ... READ of size 8 ... 0 bytes after 40-byte region at libSceLibreSsl Evp.cpp:201 (reads update at 40). The release build crashes.
  • l3 new -> l1 EVP_DigestInit_ex(ctx, EVP_sha1(), NULL): ASan global-buffer-overflow ... 24 bytes after global variable 'Sha1' ... of size 80 at Evp.cpp:183 (reads ctx_size at 104). The release build crashes here too.
  • Pure l3 path (your own callbacks): all 5 digests match, no ASan report.

The reverse also applies (read from the layouts, not run): l3 EVP_DigestInit(ctx, EVP_md5()) gets #9448's 120-byte md5 descriptor and reads ctx_size at 68, which in 2.5.4 is the upper half of sign.

The debt entry says the engine-bearing layout is incompatible. It frames that as a custom-method issue, though. The everyday new/init/update/final path breaks the same way.

Two ways out that I can see:

  1. Use #9448's EvpMd/EvpMdContext layout in l3 too. In 4.0.0 both structs live in evp_local.h, so an l3 guest has no public way to see the size or offsets. Then the shared l1 functions just work. This needs #9448 first.
  2. Keep 4.0.0 and also implement the l3 NIDs for every name that touches EVP_MD/EVP_MD_CTX, so l3 imports stop falling through to l1. That is a much bigger surface.

I'd lean to 1, but either way it's worth settling with #9448 before both merge. Today on main the l1 functions are stubs, so nothing breaks yet; the break comes with whichever of the two lands second.

Small one: the debt text calls negative ctx_size "undefined inputs". Upstream EVP_MD_CTX_free with md_data == NULL frees normally, and EVP_DigestInit gets calloc failure and returns 0. The throw is fine; only the wording is off.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644767069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10960#pullrequestreview-5644767069). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T19:01:47Z. **Review:** COMMENTED --- Checked head `9e30098fa6c6` (base `5949d8bf924b`; also merges clean onto main `e1ef22e888d7`). Linux, GCC 13.3, Release + an ASan build. What I ran: - `guest_libressl3_evp` on the head: pass. `check_conventions.py --base origin/main`: pass. - Compiled the 4.0.0 `evp_md_st` / `evp_md_ctx_st` from `evp_local.h` at ce488b78: 80 and 40 bytes, every offset matches your static_asserts. The SHA1/SHA224 descriptor values match `m_sha1.c` (ctx_size 104/120 = 8 + 96/112). - Merged #9448 (head `5994190d7094`, 2.5.4 layouts) on top of this branch and ran a probe through both libraries. The 4.0.0 layout here is right on its own. The issue is what serves the rest of the digest API for a libSceLibreSsl3 title: - On the PS5 3.20 table, libSceLibreSsl3 exports all 399 libSceLibreSsl names too, including `EVP_DigestInit_ex`, `EVP_DigestUpdate`, `EVP_DigestFinal_ex`, `EVP_Digest`, `EVP_MD_CTX_cleanup`, and `EVP_md5`. Our libSceLibreSsl3 only implements the 89 extra names. - On Linux, those imports bind to libSceLibreSsl. The relinker writes bare NIDs, and `libSceLibreSsl3.prx` has `DT_NEEDED libSceLibreSsl.prx`. `LD_DEBUG=bindings` on an exe that only needs libSceLibreSsl3 shows `6LrAQY0Ka4c` (EVP_DigestUpdate) bound to `libSceLibreSsl.prx`. - So the normal call order for an l3 title is l3 `EVP_MD_CTX_new` + l3 `EVP_DigestInit` + l1 `EVP_DigestUpdate`. Once #9448 lands, that l1 code reads its 48-byte/120-byte layout. Composed run (this PR + #9448), SHA1/SHA224 "abc", 56 and 1000 bytes: - l3 new -> l3 `EVP_DigestInit(ctx, EVP_sha1())` -> l1 `EVP_DigestUpdate`: ASan `heap-buffer-overflow ... READ of size 8 ... 0 bytes after 40-byte region` at libSceLibreSsl `Evp.cpp:201` (reads `update` at 40). The release build crashes. - l3 new -> l1 `EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)`: ASan `global-buffer-overflow ... 24 bytes after global variable 'Sha1' ... of size 80` at `Evp.cpp:183` (reads `ctx_size` at 104). The release build crashes here too. - Pure l3 path (your own callbacks): all 5 digests match, no ASan report. The reverse also applies (read from the layouts, not run): l3 `EVP_DigestInit(ctx, EVP_md5())` gets #9448's 120-byte md5 descriptor and reads `ctx_size` at 68, which in 2.5.4 is the upper half of `sign`. The debt entry says the engine-bearing layout is incompatible. It frames that as a custom-method issue, though. The everyday new/init/update/final path breaks the same way. Two ways out that I can see: 1. Use #9448's `EvpMd`/`EvpMdContext` layout in l3 too. In 4.0.0 both structs live in `evp_local.h`, so an l3 guest has no public way to see the size or offsets. Then the shared l1 functions just work. This needs #9448 first. 2. Keep 4.0.0 and also implement the l3 NIDs for every name that touches `EVP_MD`/`EVP_MD_CTX`, so l3 imports stop falling through to l1. That is a much bigger surface. I'd lean to 1, but either way it's worth settling with #9448 before both merge. Today on main the l1 functions are stubs, so nothing breaks yet; the break comes with whichever of the two lands second. Small one: the debt text calls negative `ctx_size` "undefined inputs". Upstream `EVP_MD_CTX_free` with `md_data == NULL` frees normally, and `EVP_DigestInit` gets `calloc` failure and returns 0. The throw is fine; only the wording is off.
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!10960
No description provided.