feat(libSceNKWebKit): implement PAL::CryptoDigest #19330

Merged
B-Howell merged 6 commits from upstream-pr/19330 into main 2026-11-14 21:31:27 +00:00
B-Howell commented 2026-11-13 03:54:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-13T03:54:14Z.


What

Implements the five PAL::CryptoDigest exports that threw: create, addBytes, computeHash and the D1 and D2 destructors. They follow the PS5 WebKit source already pinned in the debt file: PlatformPlayStation.cmake builds crypto/openssl/CryptoDigestOpenSSL.cpp, and CryptoDigest.h gives enum class Algorithm { SHA_1, SHA_224, SHA_256, SHA_384, SHA_512 } and a single std::unique_ptr<CryptoDigestContext> m_context member.

  • PAL::CryptoDigest is the 8-byte m_context pointer (static_asserts on size, alignment and offset). The context type is private to the module, as upstream.

  • create returns the std::unique_ptr through the hidden result pointer. Like CryptoDigestOpenSSL.cpp, it returns null for any other algorithm value. The object is allocated with libc operator new (_Znwm_nid_postfix, as libwebrtc/src/CopyOnWriteBuffer.cpp does), so the caller's delete frees it. The context is allocated with WTF::fastMalloc, as WTF_MAKE_STRUCT_FAST_ALLOCATED does upstream.

  • The hashing reuses the existing libSceLibreSsl SHA1_*, SHA224_*, SHA256_*, SHA384_* and SHA512_* functions, the same OpenSSL calls upstream makes. libSceNKWebKit now links libSceLibreSsl.

  • computeHash returns the existing NKWebKit::WtfAbi::Vector<uint8_t> with size and capacity equal to the digest length (20, 28, 32, 48 or 64).

  • The destructors free the context and leave the object for the caller to free. A null object or context throws std::invalid_argument, where upstream only asserts.

  • The declarations move from InventoryExports.hpp and LegacyExports.hpp to typed prototypes in the new PalCryptoDigestExports.hpp. The four inventory rows are removed from the debt file, and a debt entry records that the behaviour has not been compared with a console module.

Tested

Ubuntu WSL2, GCC 11, Release, Ninja.

  • Red control: with the new test and typed header but the Export.cpp stubs still in place, nkwebkit_palcryptodigest fails: Subprocess aborted, _ZN3PAL12CryptoDigest6createENS0_9AlgorithmE not implemented.

  • With this change, on c3a0b4cfe66 (main a6606d5bab7; the head cd8764bac85 only shortens the debt entry): nkwebkit_palcryptodigest passes 3/3. For each of the five algorithms it checks the published digests of "abc" and the empty message, the 448-bit two-block FIPS 180-2 message (the published example for SHA-1, SHA-224 and SHA-256; Python hashlib values for SHA-384 and SHA-512) and a 1000-byte message against Python hashlib. Each message is also fed in several addBytes calls, including zero-length ones and splits across block boundaries. It also checks the result vector's size and capacity, that algorithm values 5, 6, -1 and INT_MAX return null, that the object is the only guest-heap allocation and the caller's delete frees it, and that D1 and D2 release the context.

  • public_headers passes 65/65; nkwebkit_noops, nkwebkit_palsessionid and nkwebkit_wtf pass.

  • tools/progress.py: libraries done goes from 15578 on main to 15583 (+5) out of 39251.

  • Debt: the table rows of the four inventory declarations this PR implements are removed (create was a LegacyExports.hpp stub).

  • On 2838612d3a1, an ordinary merge of main at 82160bba912 after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 4 removed stubs (5945). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand.

  • On f5340912c1c, an ordinary merge of main at c76eb6a2643 after #19322 and #17764, conventions passed; doc-only union merge of the count line; count is main's stated 5940 minus this change's 4 removed stubs (5936). Main's nearest code change is 200 lines from this PR's hunks, so not rebuilt.

  • On 9bfaa8d6101, an ordinary merge of main at c612c4c9e89 after #19460 (PAL::fileSizeDescription, whose stub removal sits about 20 lines from ours): merged without a code conflict; count is main's stated 5939 minus this change's 4 removed stubs (5935). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: nkwebkit_palcryptodigest and nkwebkit_palfilesizeformatter 3/3; conventions passed.

  • On fa3dcec83cc: merged main after #19603; count line removed. Ordinary merge of main at 9b22c40f49a, conventions passed. The debt diff against main is now only this PR's entry and its 4 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt.

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 (#19305 also adds to PalTypes.hpp at the same place; whichever merges second needs a trivial merge)

  • Fixes: none

  • Unblocks: none

  • GPUs tested: n/a

  • AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5289671913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19330). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-13T03:54:14Z. --- ### What Implements the five `PAL::CryptoDigest` exports that threw: `create`, `addBytes`, `computeHash` and the D1 and D2 destructors. They follow the PS5 WebKit source already pinned in the debt file: [PlatformPlayStation.cmake](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/PAL/pal/PlatformPlayStation.cmake) builds `crypto/openssl/CryptoDigestOpenSSL.cpp`, and [CryptoDigest.h](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/PAL/pal/crypto/CryptoDigest.h) gives `enum class Algorithm { SHA_1, SHA_224, SHA_256, SHA_384, SHA_512 }` and a single `std::unique_ptr<CryptoDigestContext> m_context` member. - `PAL::CryptoDigest` is the 8-byte `m_context` pointer (static_asserts on size, alignment and offset). The context type is private to the module, as upstream. - `create` returns the `std::unique_ptr` through the hidden result pointer. Like [CryptoDigestOpenSSL.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp), it returns null for any other algorithm value. The object is allocated with libc `operator new` (`_Znwm_nid_postfix`, as `libwebrtc/src/CopyOnWriteBuffer.cpp` does), so the caller's `delete` frees it. The context is allocated with `WTF::fastMalloc`, as `WTF_MAKE_STRUCT_FAST_ALLOCATED` does upstream. - The hashing reuses the existing libSceLibreSsl `SHA1_*`, `SHA224_*`, `SHA256_*`, `SHA384_*` and `SHA512_*` functions, the same OpenSSL calls upstream makes. libSceNKWebKit now links libSceLibreSsl. - `computeHash` returns the existing `NKWebKit::WtfAbi::Vector<uint8_t>` with size and capacity equal to the digest length (20, 28, 32, 48 or 64). - The destructors free the context and leave the object for the caller to free. A null object or context throws `std::invalid_argument`, where upstream only asserts. - The declarations move from `InventoryExports.hpp` and `LegacyExports.hpp` to typed prototypes in the new `PalCryptoDigestExports.hpp`. The four inventory rows are removed from the debt file, and a debt entry records that the behaviour has not been compared with a console module. ### 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 WSL2, GCC 11, Release, Ninja. - Red control: with the new test and typed header but the `Export.cpp` stubs still in place, `nkwebkit_palcryptodigest` fails: `Subprocess aborted`, `_ZN3PAL12CryptoDigest6createENS0_9AlgorithmE not implemented`. - With this change, on `c3a0b4cfe66` (main `a6606d5bab7`; the head `cd8764bac85` only shortens the debt entry): `nkwebkit_palcryptodigest` passes 3/3. For each of the five algorithms it checks the published digests of `"abc"` and the empty message, the 448-bit two-block FIPS 180-2 message (the published example for SHA-1, SHA-224 and SHA-256; Python `hashlib` values for SHA-384 and SHA-512) and a 1000-byte message against Python `hashlib`. Each message is also fed in several `addBytes` calls, including zero-length ones and splits across block boundaries. It also checks the result vector's size and capacity, that algorithm values 5, 6, -1 and `INT_MAX` return null, that the object is the only guest-heap allocation and the caller's `delete` frees it, and that D1 and D2 release the context. - `public_headers` passes 65/65; `nkwebkit_noops`, `nkwebkit_palsessionid` and `nkwebkit_wtf` pass. - `tools/progress.py`: libraries done goes from 15578 on main to 15583 (+5) out of 39251. - Debt: the table rows of the four inventory declarations this PR implements are removed (`create` was a `LegacyExports.hpp` stub). - On `2838612d3a1`, an ordinary merge of `main` at `82160bba912` after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 4 removed stubs (5945). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand. - On `f5340912c1c`, an ordinary merge of `main` at `c76eb6a2643` after #19322 and #17764, conventions passed; doc-only union merge of the count line; count is main's stated 5940 minus this change's 4 removed stubs (5936). Main's nearest code change is 200 lines from this PR's hunks, so not rebuilt. - On `9bfaa8d6101`, an ordinary merge of `main` at `c612c4c9e89` after #19460 (PAL::fileSizeDescription, whose stub removal sits about 20 lines from ours): merged without a code conflict; count is main's stated 5939 minus this change's 4 removed stubs (5935). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: `nkwebkit_palcryptodigest` and `nkwebkit_palfilesizeformatter` 3/3; conventions passed. - On `fa3dcec83cc`: merged main after #19603; count line removed. Ordinary merge of `main` at `9b22c40f49a`, conventions passed. The debt diff against main is now only this PR's entry and its 4 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt. ### 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: none (#19305 also adds to `PalTypes.hpp` at the same place; whichever merges second needs a trivial merge) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!19330
No description provided.