feat(libSceJsc): implement WTF::SHA1::computeHash #19188

Merged
c1b3r-p3d1a merged 1 commit from upstream-pr/19188 into main 2026-11-13 20:04:35 +00:00
c1b3r-p3d1a commented 2026-11-12 23:13:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by c1b3r-p3d1a on 2026-11-12T23:13:51Z.


What

Implements WTF::SHA1::computeHash(std::array<uint8_t, 20>&) (ALtdQuwSy0A) in libSceJsc, which threw. It is ported from the non-Cocoa branch of WebKit's SHA1.cpp at c55364d53f97, the revision libSceJsc's string search code already follows. The new src/WtfSha1.cpp starts with that file's licence notice (BSD-3-Clause) under a Derived from line.

  • finalize, processBlock and reset are kept line for line: append 0x80, pad to a second block when the cursor passes 56, write the bit count big-endian at 56, run the 80-round compression, store the five words big-endian in the digest, then reset the object to the initial hash with a zeroed buffer.
  • The object is the 104-byte layout of SHA1.h (64-byte buffer, 64-bit cursor at 64, 64-bit byte count at 72, five 32-bit words at 80), modelled with static_asserts; it is the layout libSceNKWebKit's WTF::SHA1 already uses. libSceJsc exports neither the constructor nor addBytes, so the object comes from guest code or another module.
  • A cursor of 64 or more, where WebKit only asserts and then writes past the buffer, and null arguments throw std::invalid_argument before anything is written.
  • SHA1::hexDigest still throws: it returns a CString, and libSceJsc creates no CString yet.

The debt entry records what is unverified (console WTF version and layout). The "callable NIDs" count drops from 331 to 330 and the export's row leaves the table.

Tested

Windows 11, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh r7), Release.

  • New jsc_wtf_sha1 covers 8 states on a 0xA5-poisoned object and digest. Six are messages that fit in one pending block: empty, abc, 55 bytes (the last length padded in one block), the 56-byte FIPS 180 message (two-block padding) and 63 bytes. Two are mid-stream states: 1000 bytes (15 blocks done, 40 pending) and the million-a message (15625 blocks, none pending). Every expected digest comes from Python hashlib, and the mid-stream hash words from a separate pure-Python SHA-1. An 8th state uses a byte count of 0x2000000000000001, whose bit count wraps to 8. After each call the test checks the reset state, then that a second call hashes the empty message. It also checks that a cursor of 64 throws with the object and digest untouched, and that null arguments throw.
  • The test fails with each of these mutations: the old throwing stub; a little-endian digest; the length written in bytes, not bits; the second-block threshold off by one; no reset; a round-function boundary moved; the cursor check dropped.
  • Disassembly of the built libSceJsc.prx: this in rdi, the digest in rsi, the cursor read at 0x40, the byte count at 0x48, the hash words at 0x50 to 0x60, and the reset stores cover the whole 104 bytes.
  • The licence block is byte-identical to lines 1-30 of the pinned SHA1.cpp (cmp).
  • Rebased on main 3ba8523c06: all libSceJsc and public_headers tests pass (74 total); python tools/check_conventions.py --base origin/main passes.
  • On Windows a rebuilt libSceJsc.prx is not copied over the one staged in build/tests (#17895), so I copied it there before each run.
  • Not run: the full suite, Linux, a console.

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

Note: #18951 removes the neighbouring integerToSixCharacterHashString stub, and every libSceJsc PR changes the "callable NIDs" count line in docs/dev/debt/libSceJsc.md. These are textual conflicts only; no other PR touches SHA1. I will rebase and recompute the count when one of them merges first.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5286831092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19188). Originally posted by [c1b3r-p3d1a](https://github.com/c1b3r-p3d1a) on 2026-11-12T23:13:51Z. --- ### What Implements `WTF::SHA1::computeHash(std::array<uint8_t, 20>&)` (`ALtdQuwSy0A`) in libSceJsc, which threw. It is ported from the non-Cocoa branch of WebKit's [SHA1.cpp](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/SHA1.cpp#L115-L201) at `c55364d53f97`, the revision libSceJsc's string search code already follows. The new `src/WtfSha1.cpp` starts with that file's licence notice (BSD-3-Clause) under a `Derived from` line. - `finalize`, `processBlock` and `reset` are kept line for line: append `0x80`, pad to a second block when the cursor passes 56, write the bit count big-endian at 56, run the 80-round compression, store the five words big-endian in the digest, then reset the object to the initial hash with a zeroed buffer. - The object is the 104-byte layout of [SHA1.h](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/SHA1.h#L81-L84) (64-byte buffer, 64-bit cursor at 64, 64-bit byte count at 72, five 32-bit words at 80), modelled with `static_assert`s; it is the layout libSceNKWebKit's `WTF::SHA1` already uses. libSceJsc exports neither the constructor nor `addBytes`, so the object comes from guest code or another module. - A cursor of 64 or more, where WebKit only asserts and then writes past the buffer, and null arguments throw `std::invalid_argument` before anything is written. - `SHA1::hexDigest` still throws: it returns a `CString`, and libSceJsc creates no `CString` yet. The debt entry records what is unverified (console WTF version and layout). The "callable NIDs" count drops from 331 to 330 and the export's row leaves the table. ### 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. --> Windows 11, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh r7), Release. - New `jsc_wtf_sha1` covers 8 states on a `0xA5`-poisoned object and digest. Six are messages that fit in one pending block: empty, `abc`, 55 bytes (the last length padded in one block), the 56-byte FIPS 180 message (two-block padding) and 63 bytes. Two are mid-stream states: 1000 bytes (15 blocks done, 40 pending) and the million-`a` message (15625 blocks, none pending). Every expected digest comes from Python `hashlib`, and the mid-stream hash words from a separate pure-Python SHA-1. An 8th state uses a byte count of `0x2000000000000001`, whose bit count wraps to 8. After each call the test checks the reset state, then that a second call hashes the empty message. It also checks that a cursor of 64 throws with the object and digest untouched, and that null arguments throw. - The test fails with each of these mutations: the old throwing stub; a little-endian digest; the length written in bytes, not bits; the second-block threshold off by one; no reset; a round-function boundary moved; the cursor check dropped. - Disassembly of the built `libSceJsc.prx`: `this` in `rdi`, the digest in `rsi`, the cursor read at `0x40`, the byte count at `0x48`, the hash words at `0x50` to `0x60`, and the reset stores cover the whole 104 bytes. - The licence block is byte-identical to lines 1-30 of the pinned `SHA1.cpp` (`cmp`). - Rebased on `main` `3ba8523c06`: all libSceJsc and `public_headers` tests pass (74 total); `python tools/check_conventions.py --base origin/main` passes. - On Windows a rebuilt `libSceJsc.prx` is not copied over the one staged in `build/tests` (#17895), so I copied it there before each run. - Not run: the full suite, Linux, a console. ### 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 --> none - [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 Note: #18951 removes the neighbouring `integerToSixCharacterHashString` stub, and every libSceJsc PR changes the "callable NIDs" count line in `docs/dev/debt/libSceJsc.md`. These are textual conflicts only; no other PR touches `SHA1`. I will rebase and recompute the count when one of them merges first.
MarcZX10 commented 2026-11-13 00:24:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T00:24:09Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Reviewed head bcbbd4ecf4beb92e4ccff371100a06e5b15ccdfa against main. No build and no test run in this pass. Repository searches at the pinned head:

python3 repo_read.py search computeHash core
python3 repo_read.py search ALtdQuwSy0A core
python3 repo_read.py search "Derived from" core
python3 repo_read.py search comment docs/dev/CONVENTIONS.md

Results

Check Result Note
Diff read for all 8 reviewed files passed Large files read as diff hunks
SHA-1 port: padding, length, digest, reset passed Read by hand against the code
Export stub removed, one definition left passed Header declaration and WtfSha1.cpp only
Derived-file header convention passed Same form as other Derived from files
Test build and run not run No build in this pass
Repository precheck not run Not part of this pass
Hosted CI not run Not checked
Licence block against pinned WebKit not verified WebKit source is not in the repository

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The test jsc_wtf_sha1 was not built or run here. The author reports 73 libSceJsc tests passing on Windows 11 with GCC 15.2.0; that is the author's run, not mine.
  • The licence block is said to match lines 1-30 of the pinned SHA1.cpp (cmp). The WebKit source is not in the repository, so this is not checked.
  • The callable NID count (337 to 336) was not recounted. The removed table row is confirmed in the diff.
  • Console behaviour, the 104-byte layout and hexDigest are unverified, as the description and debt entry state.
  • Export.cpp, InventoryExports.hpp, libSceJsc.hpp, CMakeLists.txt and docs/dev/debt/libSceJsc.md were read as diff hunks, not in full.
  • Hosted CI was not inspected.

To get this to a good state

Nothing is required. There are no optional points beyond the items under Not verified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5884203263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19188#pullrequestreview-5884203263). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-13T00:24:09Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran Reviewed head `bcbbd4ecf4beb92e4ccff371100a06e5b15ccdfa` against `main`. No build and no test run in this pass. Repository searches at the pinned head: ``` python3 repo_read.py search computeHash core python3 repo_read.py search ALtdQuwSy0A core python3 repo_read.py search "Derived from" core python3 repo_read.py search comment docs/dev/CONVENTIONS.md ``` ## Results | Check | Result | Note | | --- | --- | --- | | Diff read for all 8 reviewed files | passed | Large files read as diff hunks | | SHA-1 port: padding, length, digest, reset | passed | Read by hand against the code | | Export stub removed, one definition left | passed | Header declaration and `WtfSha1.cpp` only | | Derived-file header convention | passed | Same form as other `Derived from` files | | Test build and run | not run | No build in this pass | | Repository precheck | not run | Not part of this pass | | Hosted CI | not run | Not checked | | Licence block against pinned WebKit | not verified | WebKit source is not in the repository | ## Findings **Blocking** None. **Non-blocking** None. ## Not verified - The test `jsc_wtf_sha1` was not built or run here. The author reports 73 libSceJsc tests passing on Windows 11 with GCC 15.2.0; that is the author's run, not mine. - The licence block is said to match lines 1-30 of the pinned `SHA1.cpp` (`cmp`). The WebKit source is not in the repository, so this is not checked. - The callable NID count (337 to 336) was not recounted. The removed table row is confirmed in the diff. - Console behaviour, the 104-byte layout and `hexDigest` are unverified, as the description and debt entry state. - `Export.cpp`, `InventoryExports.hpp`, `libSceJsc.hpp`, `CMakeLists.txt` and `docs/dev/debt/libSceJsc.md` were read as diff hunks, not in full. - Hosted CI was not inspected. ## To get this to a good state Nothing is required. There are no optional points beyond the items under Not verified.
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!19188
No description provided.