fix(libSceLibreSsl): preserve SHA-512 initialization buffers #13820

Merged
Ninot1Quyi merged 2 commits from upstream-pr/13820 into main 2026-11-01 02:01:26 +00:00
Ninot1Quyi commented 2026-10-31 08:01:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ninot1Quyi on 2026-10-31T08:01:30Z.


What

SHA384_Init and SHA512_Init currently zero all 216 context bytes, including the 128-byte block buffer that LibreSSL 2.5.4 leaves unchanged. Reset only the chaining state, bit counters, buffered-byte count and digest length, preserving the caller-visible working buffer on first initialization and reinitialization. This closes the existing buffer-initialization debt; digest outputs remain unchanged.

The behavior follows LibreSSL 2.5.4 sha512.c, the reference already used by this library. The existing console-verification limitation is retained. The optional oracle now compares every context byte after initialization and each update instead of excluding the unused part of the SHA-384/SHA-512 buffer.

Overlap: tools/pr_overlap.py --branch fix/libressl-sha512-init-buffer scanned 1,603 open PRs and reported 16 debt-file conflicts plus 28 comparisons blocked by unrelated base conflicts. All 44 shared patches were inspected from their merge bases; none changes this production digest implementation or its guest fixture. The four shared Oracle.cpp branches (#13266, #13285, #13546, #13547) add X.509 decode/store/encoding/free comparisons and leave SameContext and CompareDigests unchanged. There is no landing dependency; subsequent merges must retain both the unrelated debt entries and this resolved buffer-initialization change.

Tested

Linux x86-64, GCC 13.3:

  • Full default Release build passes. All 33 regular guest_libressl* tests pass, including the complete digest fixture linked to the actual guest libraries. The standalone production-source fixture also passes the existing known vectors, million-byte message and chunked updates.
  • New regression checks both algorithms with three nonuniform block-buffer patterns, reset counters/digest length, surrounding canaries, reinitialization after partial input and after finalization, and the abc and empty digests after reinitialization.
  • Negative controls: the same new fixture compiles against main's production Digest.cpp and separately links against main's real libSceLibreSsl.prx/libc.prx; both abort with wide init preserves the block buffer (exit 134). Restoring the fixed production source passes.
  • AddressSanitizer and UndefinedBehaviorSanitizer pass with leak detection disabled. The default LeakSanitizer exit check could not inspect /proc/2/task in this traced runtime; no leak-check pass is claimed.
  • python3 tools/check_conventions.py --base origin/main and git diff --check pass.

The optional LibreSSL 2.5.4 oracle runs 46,521 comparisons. SHA-384 and SHA-512 each have zero differences across 600 Init, 600 Update and 600 Final comparisons with the stricter full-context check (3,600 total). The overall oracle still fails on six pre-existing AES key-schedule comparisons: untouched main reproduces the identical six failures. A separate probe confirms that the reference x86 assembly and the existing portable implementation store every active key-schedule word in opposite byte order; result codes, rounds, unused storage and all tested AES mode outputs agree. This SHA initialization PR does not change AES behavior. No Windows, title or PS5 hardware run is claimed.

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:5095769573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13820). Originally posted by [Ninot1Quyi](https://github.com/Ninot1Quyi) on 2026-10-31T08:01:30Z. --- ### What `SHA384_Init` and `SHA512_Init` currently zero all 216 context bytes, including the 128-byte block buffer that LibreSSL 2.5.4 leaves unchanged. Reset only the chaining state, bit counters, buffered-byte count and digest length, preserving the caller-visible working buffer on first initialization and reinitialization. This closes the existing buffer-initialization debt; digest outputs remain unchanged. The behavior follows [LibreSSL 2.5.4 `sha512.c`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/sha/sha512.c), the reference already used by this library. The existing console-verification limitation is retained. The optional oracle now compares every context byte after initialization and each update instead of excluding the unused part of the SHA-384/SHA-512 buffer. Overlap: `tools/pr_overlap.py --branch fix/libressl-sha512-init-buffer` scanned 1,603 open PRs and reported 16 debt-file conflicts plus 28 comparisons blocked by unrelated base conflicts. All 44 shared patches were inspected from their merge bases; none changes this production digest implementation or its guest fixture. The four shared `Oracle.cpp` branches (#13266, #13285, #13546, #13547) add X.509 decode/store/encoding/free comparisons and leave `SameContext` and `CompareDigests` unchanged. There is no landing dependency; subsequent merges must retain both the unrelated debt entries and this resolved buffer-initialization change. ### Tested Linux x86-64, GCC 13.3: - Full default Release build passes. All 33 regular `guest_libressl*` tests pass, including the complete digest fixture linked to the actual guest libraries. The standalone production-source fixture also passes the existing known vectors, million-byte message and chunked updates. - New regression checks both algorithms with three nonuniform block-buffer patterns, reset counters/digest length, surrounding canaries, reinitialization after partial input and after finalization, and the `abc` and empty digests after reinitialization. - Negative controls: the same new fixture compiles against main's production `Digest.cpp` and separately links against main's real `libSceLibreSsl.prx`/`libc.prx`; both abort with `wide init preserves the block buffer` (exit 134). Restoring the fixed production source passes. - AddressSanitizer and UndefinedBehaviorSanitizer pass with leak detection disabled. The default LeakSanitizer exit check could not inspect `/proc/2/task` in this traced runtime; no leak-check pass is claimed. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check` pass. The optional LibreSSL 2.5.4 oracle runs 46,521 comparisons. SHA-384 and SHA-512 each have zero differences across 600 Init, 600 Update and 600 Final comparisons with the stricter full-context check (3,600 total). The overall oracle still fails on six pre-existing AES key-schedule comparisons: untouched main reproduces the identical six failures. A separate probe confirms that the reference x86 assembly and the existing portable implementation store every active key-schedule word in opposite byte order; result codes, rounds, unused storage and all tested AES mode outputs agree. This SHA initialization PR does not change AES behavior. No Windows, title or PS5 hardware run is claimed. <!-- 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. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-31 08:18:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T08:18:19Z.

Review: APPROVED


Reviewed — looks good

The two SHA-384/SHA-512 initializers now reset the same fields as pinned LibreSSL 2.5.4 while preserving the block buffer, and the regression tests cover both initialization and reinitialization.

What I ran

Reviewed head 592aca8e115ccdd0ccb45d5c88a30a89c94c396a against the PR base 828ac0b2ae74aac181ba128fb59b08a1534f2041; a merge preview against current main e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf was clean. Local environment: Linux x86-64, Python 3.11.2; no compiler used. I ran:

python3 tools/pr_precheck.py --pr 13820 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820
python3 tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820/head-592aca8e115c-7911d149 --json core/libs/prx/libSceLibreSsl/tests/Oracle.cpp core/libs/tests/GuestLibreSslDigest.cpp
grep -n -E 'guest_libressl_(digest|oracle)|GuestLibreSslDigest.cpp|Oracle.cpp' /marc/AnyPS5/core/libs/prx/libSceLibreSsl/CMakeLists.txt

I compared the changed initializer fields with the pinned LibreSSL source and manually confirmed both tests’ CMake registration. The heuristic warns about the C++ files because it searches for literal path strings; CMake registers guest_libressl_digest and the optional guest_libressl_oracle targets.

Results

Check Result
Diff and conventions/template Passed
Merge preview against current main Clean
Test registration Confirmed in CMake
Hosted checks Windows, conventions, intake, eligibility, report, labels, and library portability passed; Linux and relinker jobs were skipped
Author-reported tests Linux/GCC 13.3 Release build; all 33 regular guest_libressl* tests passed; sanitizer and SHA oracle results are reported below

The no-build precheck’s optional ABI/test-quality helpers were not present in its isolated checkout. This change does not alter exports or public declarations, so ABI auditing is not applicable. I did not independently run C++ tests.

Raw output from local checks
All conventions checks passed.
/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820/stack/stack-report.md
/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820/stack/stack-report.json

Negative control

Assertion Change reported against Result
Initialization preserves the SHA-384/SHA-512 block buffer Author reports using main’s production Digest.cpp The regression fixture failed at wide init preserves the block buffer (exit 134); not independently reproduced here.
Same assertion against the main guest libraries Author reports linking against main’s libSceLibreSsl.prx and libc.prx The regression fixture failed at the same assertion (exit 134); not independently reproduced here.

Findings

Blocking: None found.

Non-blocking: The PR reports six unrelated AES oracle differences, also reproduced on unchanged main; the SHA-384/SHA-512 oracle comparisons report zero differences. I did not independently reproduce those results.

Sources

Not verified

I did not run the C++ build, guest tests, sanitizer checks, oracle comparisons, or console/title tests locally. The Linux test, sanitizer, oracle, and negative-control results are author-reported; Windows CI passed. The PR head remained 592aca8e115ccdd0ccb45d5c88a30a89c94c396a when I submitted this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721965175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13820#pullrequestreview-5721965175). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T08:18:19Z. **Review:** APPROVED --- # Reviewed — looks good The two SHA-384/SHA-512 initializers now reset the same fields as pinned LibreSSL 2.5.4 while preserving the block buffer, and the regression tests cover both initialization and reinitialization. ## What I ran Reviewed head `592aca8e115ccdd0ccb45d5c88a30a89c94c396a` against the PR base `828ac0b2ae74aac181ba128fb59b08a1534f2041`; a merge preview against current `main` `e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf` was clean. Local environment: Linux x86-64, Python 3.11.2; no compiler used. I ran: ```sh python3 tools/pr_precheck.py --pr 13820 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820 python3 tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820/head-592aca8e115c-7911d149 --json core/libs/prx/libSceLibreSsl/tests/Oracle.cpp core/libs/tests/GuestLibreSslDigest.cpp grep -n -E 'guest_libressl_(digest|oracle)|GuestLibreSslDigest.cpp|Oracle.cpp' /marc/AnyPS5/core/libs/prx/libSceLibreSsl/CMakeLists.txt ``` I compared the changed initializer fields with the pinned LibreSSL source and manually confirmed both tests’ CMake registration. The heuristic warns about the C++ files because it searches for literal path strings; CMake registers `guest_libressl_digest` and the optional `guest_libressl_oracle` targets. ## Results | Check | Result | |---|---| | Diff and conventions/template | Passed | | Merge preview against current `main` | Clean | | Test registration | Confirmed in CMake | | Hosted checks | Windows, conventions, intake, eligibility, report, labels, and library portability passed; Linux and relinker jobs were skipped | | Author-reported tests | Linux/GCC 13.3 Release build; all 33 regular `guest_libressl*` tests passed; sanitizer and SHA oracle results are reported below | The no-build precheck’s optional ABI/test-quality helpers were not present in its isolated checkout. This change does not alter exports or public declarations, so ABI auditing is not applicable. I did not independently run C++ tests. <details><summary>Raw output from local checks</summary> ```text All conventions checks passed. /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820/stack/stack-report.md /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13820/stack/stack-report.json ``` </details> ## Negative control | Assertion | Change reported against | Result | |---|---|---| | Initialization preserves the SHA-384/SHA-512 block buffer | Author reports using `main`’s production `Digest.cpp` | The regression fixture failed at `wide init preserves the block buffer` (exit 134); not independently reproduced here. | | Same assertion against the main guest libraries | Author reports linking against main’s `libSceLibreSsl.prx` and `libc.prx` | The regression fixture failed at the same assertion (exit 134); not independently reproduced here. | ## Findings **Blocking:** None found. **Non-blocking:** The PR reports six unrelated AES oracle differences, also reproduced on unchanged `main`; the SHA-384/SHA-512 oracle comparisons report zero differences. I did not independently reproduce those results. ## Sources - [Reviewed SHA initializer and regression fixture](https://github.com/boykopovar/AnyPS5/blob/592aca8e115ccdd0ccb45d5c88a30a89c94c396a/core/libs/prx/libSceLibreSsl/src/Digest.cpp), [guest tests](https://github.com/boykopovar/AnyPS5/blob/592aca8e115ccdd0ccb45d5c88a30a89c94c396a/core/libs/tests/GuestLibreSslDigest.cpp), and [oracle comparison](https://github.com/boykopovar/AnyPS5/blob/592aca8e115ccdd0ccb45d5c88a30a89c4/core/libs/prx/libSceLibreSsl/tests/Oracle.cpp) - [LibreSSL 2.5.4 `SHA384_Init` and `SHA512_Init`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/sha/sha512.c) ## Not verified I did not run the C++ build, guest tests, sanitizer checks, oracle comparisons, or console/title tests locally. The Linux test, sanitizer, oracle, and negative-control results are author-reported; Windows CI passed. The PR head remained `592aca8e115ccdd0ccb45d5c88a30a89c94c396a` when I submitted this review.
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!13820
No description provided.