feat(libSceNKWebKit): implement WTF::SHA1 construction and hex digest #15866

Merged
KernelPanicNT merged 2 commits from upstream-pr/15866 into main 2026-11-09 19:33:57 +00:00
KernelPanicNT commented 2026-11-04 20:29:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-11-04T20:29:10Z.


What

Implements three libSceNKWebKit exports that called NotImplemented_nid_no_patch: WTF::SHA1::SHA1() (C1 f4Y+BVScAcc and C2 Dq5bk2mU2xw) and WTF::SHA1::computeHexDigest() (Ow27qMGiCBU). They follow WebKit's non-Cocoa SHA1.h and SHA1.cpp:

  • The 104-byte object is uint8_t m_buffer[64] at 0, size_t m_cursor at 64, uint64_t m_totalBytes at 72 and uint32_t m_hash[5] at 80, modelled as NKWebKit::WtfAbi::SHA1 in WtfStringAbi.hpp and pinned with static_assert.
  • The constructor runs reset(): cursor and byte count 0, the RFC 3174 initial hash, buffer cleared.
  • computeHexDigest() runs computeHash(): it pads the current state (the buffer up to the cursor, the byte count and the hash words), processes the last block or blocks, writes the big-endian digest and resets the object. Then hexDigest() returns a 40-character uppercase CString. The CString goes through the hidden return pointer, as the tree's other CString-returning WTF exports do, and is allocated with CString::newUninitialized.
  • A null object, or a cursor of 64 or more, throws std::invalid_argument before anything is written. Upstream has only a debug ASSERT there, and a release build writes past m_buffer. This follows how the tree already handles WTF assertions over invalid memory, for example in the FastBitVector entry of the debt file.

addBytes and computeHash are not in the module's export inventory, so a guest only reaches the digest through an object it filled through this layout. A new debt entry says the layout and digest were not checked against a console module. The three NID rows leave the list of throwing inventory exports.

These three stubs sit next to the WTF::Lock and WTF::Mutex stubs that #14921, #14922 and #14923 remove. Those PRs leave these functions as they are, but whichever PR merges second will need a small rebase of Export.cpp and InventoryExports.hpp.

Source of the behaviour

Tested

Linux (GitHub Codespace, GCC), on main 9ab6a281ea. The new nkwebkit_sha1 test passes and nkwebkit_wtf still passes; the new files build without warnings. The test checks:

  • Both constructors give the reset state inside a 0xCC-filled object with guard words on each side. That state hashes to the SHA-1 of the empty input, the object is back in the reset state afterwards, and a second call gives the same digest.
  • The returned CString has length 40, a reference count of 1 and a terminating NUL.
  • Objects filled through the layout give the expected digests:
    • abc, 55 and 63 bytes, and the 56-byte FIPS message, each with zero and with stale bytes after the cursor. These cover both padding branches.
    • A state after one processed block, with the intermediate hash words, cursor 3 and 67 bytes.
    • A byte count whose bit length wraps modulo 2^64, and the maximum byte count with edge hash words.
  • Expected values come from hashlib, or, for the hand-built states, from a separate model of the cited source that was checked against hashlib.
  • Null objects throw for all three exports, and cursors of 64, 65 and SIZE_MAX throw with the object unchanged.

Negative control: the same test with Export.cpp, InventoryExports.hpp, WtfExports.hpp and WtfStringAbi.hpp from main and without WtfSha1.cpp does not build, and ctest fails. Two mutations of the implementation, lowercase hex digits and no reset after the digest, also make the test fail. tools/progress.py: +3 implemented functions (libSceNKWebKit 1309/11248 -> 1312/11248). tools/check_conventions.py passes.

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:5161123439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15866). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-11-04T20:29:10Z. --- ### What Implements three `libSceNKWebKit` exports that called `NotImplemented_nid_no_patch`: `WTF::SHA1::SHA1()` (C1 `f4Y+BVScAcc` and C2 `Dq5bk2mU2xw`) and `WTF::SHA1::computeHexDigest()` (`Ow27qMGiCBU`). They follow WebKit's non-Cocoa `SHA1.h` and `SHA1.cpp`: - The 104-byte object is `uint8_t m_buffer[64]` at 0, `size_t m_cursor` at 64, `uint64_t m_totalBytes` at 72 and `uint32_t m_hash[5]` at 80, modelled as `NKWebKit::WtfAbi::SHA1` in `WtfStringAbi.hpp` and pinned with `static_assert`. - The constructor runs `reset()`: cursor and byte count 0, the RFC 3174 initial hash, buffer cleared. - `computeHexDigest()` runs `computeHash()`: it pads the current state (the buffer up to the cursor, the byte count and the hash words), processes the last block or blocks, writes the big-endian digest and resets the object. Then `hexDigest()` returns a 40-character uppercase CString. The CString goes through the hidden return pointer, as the tree's other CString-returning WTF exports do, and is allocated with `CString::newUninitialized`. - A null object, or a cursor of 64 or more, throws `std::invalid_argument` before anything is written. Upstream has only a debug `ASSERT` there, and a release build writes past `m_buffer`. This follows how the tree already handles WTF assertions over invalid memory, for example in the FastBitVector entry of the debt file. `addBytes` and `computeHash` are not in the module's export inventory, so a guest only reaches the digest through an object it filled through this layout. A new debt entry says the layout and digest were not checked against a console module. The three NID rows leave the list of throwing inventory exports. These three stubs sit next to the `WTF::Lock` and `WTF::Mutex` stubs that #14921, #14922 and #14923 remove. Those PRs leave these functions as they are, but whichever PR merges second will need a small rebase of `Export.cpp` and `InventoryExports.hpp`. **Source of the behaviour** - Object layout: [`SHA1.h#L85-L96`](https://github.com/WebKit/WebKit/blob/9809c1a27c82/Source/WTF/wtf/SHA1.h#L85-L96) (non-Cocoa members). Exported members: [`#L51`](https://github.com/WebKit/WebKit/blob/9809c1a27c82/Source/WTF/wtf/SHA1.h#L51) and [`#L82`](https://github.com/WebKit/WebKit/blob/9809c1a27c82/Source/WTF/wtf/SHA1.h#L82). - Constructor, `computeHash`, `finalize`, `processBlock` and `reset`: [`SHA1.cpp#L100-L202`](https://github.com/WebKit/WebKit/blob/9809c1a27c82/Source/WTF/wtf/SHA1.cpp#L100-L202). `hexDigest` and `computeHexDigest`: [`#L206-L223`](https://github.com/WebKit/WebKit/blob/9809c1a27c82/Source/WTF/wtf/SHA1.cpp#L206-L223). - Revision range: both files are byte-identical (blobs `71faad83f847` for `SHA1.h` and `18c4fe832553` for `SHA1.cpp`) from WebKit `9809c1a27c82` until `SHA1.h` next changes in `c614496679dc`. `SHA1.cpp` is the same blob from `7bab10c8f472` until `484500b2c078`. This is the same text the existing NKWebKit debt entries cite as their pinned WebKit source. - Previous behaviour: [`Export.cpp#L19771-L19781`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/Export.cpp#L19771-L19781), [`InventoryExports.hpp#L1915-L1917`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp#L1915-L1917), and names and NIDs at [`libSceNKWebKit.md#L1859-L1861`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/docs/dev/debt/libSceNKWebKit.md#L1859-L1861). - CString model and hidden-pointer return: [`WtfStringAbi.hpp#L46-L68`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp#L46-L68), [`WtfString.cpp#L694`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L694) (`String::ascii`) and [`#L808`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/core/libs/prx/libSceNKWebKit/src/WtfString.cpp#L808) (`CString::newUninitialized`). - Throwing instead of an assertion over invalid memory: [`libSceNKWebKit.md#L11`](https://github.com/boykopovar/AnyPS5/blob/9ab6a281ea/docs/dev/debt/libSceNKWebKit.md#L11) (FastBitVector). ### 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. --> Linux (GitHub Codespace, GCC), on `main` `9ab6a281ea`. The new `nkwebkit_sha1` test passes and `nkwebkit_wtf` still passes; the new files build without warnings. The test checks: - Both constructors give the reset state inside a 0xCC-filled object with guard words on each side. That state hashes to the SHA-1 of the empty input, the object is back in the reset state afterwards, and a second call gives the same digest. - The returned CString has length 40, a reference count of 1 and a terminating NUL. - Objects filled through the layout give the expected digests: - `abc`, 55 and 63 bytes, and the 56-byte FIPS message, each with zero and with stale bytes after the cursor. These cover both padding branches. - A state after one processed block, with the intermediate hash words, cursor 3 and 67 bytes. - A byte count whose bit length wraps modulo 2^64, and the maximum byte count with edge hash words. - Expected values come from hashlib, or, for the hand-built states, from a separate model of the cited source that was checked against hashlib. - Null objects throw for all three exports, and cursors of 64, 65 and `SIZE_MAX` throw with the object unchanged. Negative control: the same test with `Export.cpp`, `InventoryExports.hpp`, `WtfExports.hpp` and `WtfStringAbi.hpp` from `main` and without `WtfSha1.cpp` does not build, and `ctest` fails. Two mutations of the implementation, lowercase hex digits and no reset after the digest, also make the test fail. `tools/progress.py`: +3 implemented functions (libSceNKWebKit 1309/11248 -> 1312/11248). `tools/check_conventions.py` passes. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
ahmadmuj commented 2026-11-06 12:21:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T12:21:05Z.

Review: COMMENTED


Checked head 6e2453c72ba86df76703a68a7487f7ef46b12b19, PR base 638187daeceacf1fff34c172ebd3f135fd7dbbb8, and main 2d2d60a959a7abc7b3a34b0341a40eae2af1d298.

On Ubuntu 24.04 / WSL2, GCC 13.3, Release:

  • cmake --build builds/anyps5-pr-15866 --target nkwebkit_sha1_tests -j 6 and ctest --test-dir builds/anyps5-pr-15866 -R '^nkwebkit_sha1$' -V pass.
  • An external probe links the actual module through the public ABI declarations. Both constructors pass four binary vectors with zero and 0xA5 unused buffer bytes: 16 payload runs and 32 empty digests after reset. It checks every named reset field, adjacent guards, CString length/refcount/terminator, and exact digest bytes. Each CString leaves scope before the next digest.
  • The same head-header test executables, loaded against the separately built main module, stop at _ZN3WTF4SHA1C1Ev not implemented.
  • Conventions pass. CPU-only scope; GPUs tested: n/a. No Windows, macOS, title, or console run.

I checked the non-Cocoa implementation and layout against WebKit SHA1.cpp and SHA1.h. Expected strings come independently from Python hashlib.sha1.

One regression-test suggestion: add a high-bit payload around the padding boundary. For 55 bytes defined by byte[i] = (i * 37 + 0x80) & 255, the expected digest is 45D049142CD1784AD869A7EE26BB653D8D78CD0C. As a control, I masked only payload bytes with buffer[i] &= 0x7f before Finalize. Your current test still passes, but this vector fails with 7560B6E42942DCE3837BFBDC21FC7C38EAB75916. Restoring the source makes both tests pass. The probe also checks lengths 56 and 63, plus 80 00 ff 41.

The current implementation passes these cases. This is a coverage suggestion, not a production defect. Console layout and execution remain unverified, as the debt entry states.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5799995910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15866#pullrequestreview-5799995910). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T12:21:05Z. **Review:** COMMENTED --- Checked head `6e2453c72ba86df76703a68a7487f7ef46b12b19`, PR base `638187daeceacf1fff34c172ebd3f135fd7dbbb8`, and main `2d2d60a959a7abc7b3a34b0341a40eae2af1d298`. On Ubuntu 24.04 / WSL2, GCC 13.3, Release: - `cmake --build builds/anyps5-pr-15866 --target nkwebkit_sha1_tests -j 6` and `ctest --test-dir builds/anyps5-pr-15866 -R '^nkwebkit_sha1$' -V` pass. - An external probe links the actual module through the public ABI declarations. Both constructors pass four binary vectors with zero and `0xA5` unused buffer bytes: 16 payload runs and 32 empty digests after reset. It checks every named reset field, adjacent guards, CString length/refcount/terminator, and exact digest bytes. Each CString leaves scope before the next digest. - The same head-header test executables, loaded against the separately built main module, stop at `_ZN3WTF4SHA1C1Ev not implemented`. - Conventions pass. CPU-only scope; GPUs tested: n/a. No Windows, macOS, title, or console run. I checked the non-Cocoa implementation and layout against [WebKit SHA1.cpp](https://github.com/WebKit/WebKit/blob/9809c1a27c826cd1bd8b942b2d254de33a288a56/Source/WTF/wtf/SHA1.cpp) and [SHA1.h](https://github.com/WebKit/WebKit/blob/9809c1a27c826cd1bd8b942b2d254de33a288a56/Source/WTF/wtf/SHA1.h). Expected strings come independently from Python `hashlib.sha1`. One regression-test suggestion: add a high-bit payload around the padding boundary. For 55 bytes defined by `byte[i] = (i * 37 + 0x80) & 255`, the expected digest is `45D049142CD1784AD869A7EE26BB653D8D78CD0C`. As a control, I masked only payload bytes with `buffer[i] &= 0x7f` before `Finalize`. Your current test still passes, but this vector fails with `7560B6E42942DCE3837BFBDC21FC7C38EAB75916`. Restoring the source makes both tests pass. The probe also checks lengths 56 and 63, plus `80 00 ff 41`. The current implementation passes these cases. This is a coverage suggestion, not a production defect. Console layout and execution remain unverified, as the debt entry states.
ahmadmuj commented 2026-11-06 17:19:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T17:19:05Z.

Review: COMMENTED


Follow-up on head 6e2453c72ba86df76703a68a7487f7ef46b12b19 with main 4c03784113f5378f87a198aa6d9f330611f24421 (integration tree efd21d3aee1c4f6d08f12146dfc5791dbcf283e4).

The source merge applies, but the integrated module fails to compile on Ubuntu 24.04/WSL2, GCC 13.3, Release. The isolated existing production object fails without compiling the new regression test:

ninja -C builds/anyps5-nkwebkit-sha1-binary-regression/integrated core/libs/prx/libSceNKWebKit/CMakeFiles/libSceNKWebKit.dir/src/WtfValues.cpp.o
include/WtfValueExports.hpp:51:8: error: redefinition of 'struct NKWebKit::WtfAbi::SHA1'
src/WtfStringAbi.hpp:111:8: note: previous definition of 'struct NKWebKit::WtfAbi::SHA1'

Both paths are under core/libs/prx/libSceNKWebKit/. WtfValueExports.hpp includes WtfStringAbi.hpp through WtfExports.hpp, so both definitions reach the same translation unit. Main commit 7287e745b011e32c1c03b117fccd1655e01c2b03 adds the definition in WtfValueExports.hpp.

I checked the saved compile command, failure log, and snapshot bytes against the integration tree. Main 8fa2f2f8881b537b24062bd377badebae8d97abf changes only Audiodec files since that pin. I did not repeat the unchanged build.

This blocks my test-only follow-up for the binary vectors from the earlier review. The new test does not cause the failure. No GPU or console claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5804148180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15866#pullrequestreview-5804148180). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T17:19:05Z. **Review:** COMMENTED --- Follow-up on head `6e2453c72ba86df76703a68a7487f7ef46b12b19` with main `4c03784113f5378f87a198aa6d9f330611f24421` (integration tree `efd21d3aee1c4f6d08f12146dfc5791dbcf283e4`). The source merge applies, but the integrated module fails to compile on Ubuntu 24.04/WSL2, GCC 13.3, Release. The isolated existing production object fails without compiling the new regression test: ```sh ninja -C builds/anyps5-nkwebkit-sha1-binary-regression/integrated core/libs/prx/libSceNKWebKit/CMakeFiles/libSceNKWebKit.dir/src/WtfValues.cpp.o ``` ```text include/WtfValueExports.hpp:51:8: error: redefinition of 'struct NKWebKit::WtfAbi::SHA1' src/WtfStringAbi.hpp:111:8: note: previous definition of 'struct NKWebKit::WtfAbi::SHA1' ``` Both paths are under `core/libs/prx/libSceNKWebKit/`. `WtfValueExports.hpp` includes `WtfStringAbi.hpp` through `WtfExports.hpp`, so both definitions reach the same translation unit. Main commit `7287e745b011e32c1c03b117fccd1655e01c2b03` adds the definition in `WtfValueExports.hpp`. I checked the saved compile command, failure log, and snapshot bytes against the integration tree. Main `8fa2f2f8881b537b24062bd377badebae8d97abf` changes only Audiodec files since that pin. I did not repeat the unchanged build. This blocks my test-only follow-up for the binary vectors from the earlier review. The new test does not cause the failure. No GPU or console claim.
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!15866
No description provided.