fix(libSceLibreSsl): follow LibreSSL 2.5.4 and 4.0.0 for null digest buffers and SHA-512/t lengths #10484

Merged
jacob6769 merged 4 commits from upstream-pr/10484 into main 2026-10-25 16:46:56 +00:00
jacob6769 commented 2026-10-24 03:02:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jacob6769 on 2026-10-24T03:02:24Z.


What

Three digest paths threw because the LibreSSL version of each module was unknown. Console measurements in discussion #8981 pin the versions: libSceLibreSsl is LibreSSL 2.5.4 (the module image holds "LibreSSL 2.5.4"), and libSceLibreSsl3 is LibreSSL 4.0.0 (OpenSSL_version(0) returns "LibreSSL 4.0.0"). The paths now do what those releases do:

  • SHA256 with a null digest buffer (libSceLibreSsl) writes into a static 32-byte buffer and returns it, as LibreSSL 2.5.4's SHA256 does. The buffer is shared between calls, like LibreSSL's.
  • SHA512_Final with a digest length other than 48 or 64 (libSceLibreSsl) returns 0 without writing the digest. LibreSSL 2.5.4's SHA512_Final has cases only for SHA-384 and SHA-512. It returns 0 from default, which includes the SHA-512/224 and SHA-512/256 lengths that used to throw.
  • MD5 and SHA1 with a null digest buffer (libSceLibreSsl3) throw std::invalid_argument instead of NotImplemented. LibreSSL 4.0.0's MD5 and SHA1 have no static buffer and pass the null pointer to *_Final, which writes through it. Other unchecked inputs in these modules already throw std::invalid_argument in this way.

The two debt entries drop the version-dependent paths. The libSceLibreSsl3 entry keeps the null-buffer exception, which differs from the console's crash.

tools/progress.py: libSceLibreSsl 46 to 48 of 399 (SHA256, SHA512_Final), libSceLibreSsl3 1 to 3 of 87 (MD5, SHA1).

No open PR changes these functions or src/Digest.cpp in either module. tools/pr_overlap.py reports no shared exports. Its only overlaps are neighbouring lines in the two debt files: other open LibreSSL PRs add entries next to libSceLibreSsl.md line 6 or libSceLibreSsl3.md line 10. Whichever PR lands second rebases.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release, BUILD_TESTING=ON.

  • guest_libressl_digest:
    • SHA256 with a null buffer returns a pointer that is not the caller's buffer and holds the SHA-256 of "abc". A second call returns the same pointer, now holding the digest of the empty string.
    • SHA512_Final with md_len set to 28 or 32 returns 0 and leaves the output untouched.
  • guest_libressl3_digest: MD5 and SHA1 with a null buffer, and SHA1 with null input of nonzero length, must throw std::invalid_argument specifically.
  • With the two Digest.cpp files reverted to main, both tests fail: SHA512_Final throws not implemented, and MD5 throws an exception that is not std::invalid_argument. With this change, both pass.
  • ctest -R "^guest_(libressl|crypto)": 11/11 passed, including the AES, error-queue, ASN.1 and cipher tests from main. The full suite was not run.
  • tools/check_conventions.py (with this title and body) and tools/check_test_registration.py build pass.
  • No console or title was run.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4991966647 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10484). Originally posted by [jacob6769](https://github.com/jacob6769) on 2026-10-24T03:02:24Z. --- ### What Three digest paths threw because the LibreSSL version of each module was unknown. Console measurements in [discussion #8981](https://github.com/boykopovar/AnyPS5/discussions/8981) pin the versions: `libSceLibreSsl` is LibreSSL 2.5.4 (the module image holds "LibreSSL 2.5.4"), and `libSceLibreSsl3` is LibreSSL 4.0.0 (`OpenSSL_version(0)` returns "LibreSSL 4.0.0"). The paths now do what those releases do: - **`SHA256` with a null digest buffer** (libSceLibreSsl) writes into a static 32-byte buffer and returns it, as LibreSSL 2.5.4's [`SHA256`](https://github.com/libressl/openbsd/blob/libressl-v2.5.4/src/lib/libcrypto/sha/sha256.c#L56-L67) does. The buffer is shared between calls, like LibreSSL's. - **`SHA512_Final` with a digest length other than 48 or 64** (libSceLibreSsl) returns 0 without writing the digest. LibreSSL 2.5.4's [`SHA512_Final`](https://github.com/libressl/openbsd/blob/libressl-v2.5.4/src/lib/libcrypto/sha/sha512.c#L97-L173) has cases only for SHA-384 and SHA-512. It returns 0 from `default`, which includes the SHA-512/224 and SHA-512/256 lengths that used to throw. - **`MD5` and `SHA1` with a null digest buffer** (libSceLibreSsl3) throw `std::invalid_argument` instead of `NotImplemented`. LibreSSL 4.0.0's [`MD5`](https://github.com/libressl/openbsd/blob/libressl-v4.0.0/src/lib/libcrypto/md5/md5.c#L370-L381) and [`SHA1`](https://github.com/libressl/openbsd/blob/libressl-v4.0.0/src/lib/libcrypto/sha/sha1.c#L495-L508) have no static buffer and pass the null pointer to `*_Final`, which writes through it. Other unchecked inputs in these modules already throw `std::invalid_argument` in this way. The two debt entries drop the version-dependent paths. The `libSceLibreSsl3` entry keeps the null-buffer exception, which differs from the console's crash. `tools/progress.py`: `libSceLibreSsl` 46 to 48 of 399 (`SHA256`, `SHA512_Final`), `libSceLibreSsl3` 1 to 3 of 87 (`MD5`, `SHA1`). No open PR changes these functions or `src/Digest.cpp` in either module. `tools/pr_overlap.py` reports no shared exports. Its only overlaps are neighbouring lines in the two debt files: other open LibreSSL PRs add entries next to `libSceLibreSsl.md` line 6 or `libSceLibreSsl3.md` line 10. Whichever PR lands second rebases. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release, `BUILD_TESTING=ON`. - `guest_libressl_digest`: - `SHA256` with a null buffer returns a pointer that is not the caller's buffer and holds the SHA-256 of "abc". A second call returns the same pointer, now holding the digest of the empty string. - `SHA512_Final` with `md_len` set to 28 or 32 returns 0 and leaves the output untouched. - `guest_libressl3_digest`: `MD5` and `SHA1` with a null buffer, and `SHA1` with null input of nonzero length, must throw `std::invalid_argument` specifically. - With the two `Digest.cpp` files reverted to `main`, both tests fail: `SHA512_Final` throws `not implemented`, and `MD5` throws an exception that is not `std::invalid_argument`. With this change, both pass. - `ctest -R "^guest_(libressl|crypto)"`: 11/11 passed, including the AES, error-queue, ASN.1 and cipher tests from `main`. The full suite was not run. - `tools/check_conventions.py` (with this title and body) and `tools/check_test_registration.py build` pass. - No console or title was run. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
harisibrar1 commented 2026-10-24 05:17:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:17:56Z.

Review: APPROVED


Checked against main 7966e590ef, LibreSSL libressl-v2.5.4 (sha/sha256.c, sha/sha512.c) and libressl-v4.0.0 (md5/md5.c, sha/sha1.c):

  • The version split is right: per discussion #8981 (comment 19111214), libSceLibreSsl is 2.5.4 and libSceLibreSsl3 is 4.0.0, so each path follows its own module's release.
  • 2.5.4 SHA256 uses static unsigned char m[...]; if (md == NULL) md=m;, which matches the new static buffer.
  • 2.5.4 SHA512_Final checks md==0 after the final block, then switches on md_len with only the 48 and 64 cases and default: return 0. Returning 0 for 28 and 32 without writing matches it, and so does the existing order of the null check and the length check.
  • 4.0.0 MD5 and SHA1 pass md straight to *_Final, so throwing std::invalid_argument for a null buffer fits the module's "throws where LibreSSL faults" convention.
  • Optional nit: the two debt entries still cite the bc9483725c snapshot. Linking the libressl-v2.5.4 and libressl-v4.0.0 tags would match the behaviour the code now follows.
  • Merges cleanly into current main.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636978328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10484#pullrequestreview-5636978328). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T05:17:56Z. **Review:** APPROVED --- Checked against main 7966e590ef, LibreSSL libressl-v2.5.4 (sha/sha256.c, sha/sha512.c) and libressl-v4.0.0 (md5/md5.c, sha/sha1.c): - The version split is right: per discussion #8981 (comment 19111214), libSceLibreSsl is 2.5.4 and libSceLibreSsl3 is 4.0.0, so each path follows its own module's release. - 2.5.4 `SHA256` uses `static unsigned char m[...]; if (md == NULL) md=m;`, which matches the new static buffer. - 2.5.4 `SHA512_Final` checks `md==0` after the final block, then switches on `md_len` with only the 48 and 64 cases and `default: return 0`. Returning 0 for 28 and 32 without writing matches it, and so does the existing order of the null check and the length check. - 4.0.0 `MD5` and `SHA1` pass `md` straight to `*_Final`, so throwing `std::invalid_argument` for a null buffer fits the module's "throws where LibreSSL faults" convention. - Optional nit: the two debt entries still cite the bc9483725c snapshot. Linking the `libressl-v2.5.4` and `libressl-v4.0.0` tags would match the behaviour the code now follows. - Merges cleanly into current main. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-24 15:57:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:57:58Z.

Review: APPROVED


Reviewed the changed digest paths against the cited LibreSSL 2.5.4 and 4.0.0 behavior and current module split. The static SHA256 fallback, SHA512_Final default return without digest writes, and libSceLibreSsl3 null-output exception behavior match the described sources; the tests cover the relevant output and error cases. The current head merges cleanly with upstream main (3fcb5e4d76), and conventions plus diff checks pass. I compiled and ran both focused digest tests directly with GCC 12.2.0 (linking the shared MD5/SHA1 primitive implementation for the SSL3 test); both passed. The Windows CTest results and broader test results are author-reported, not reproduced here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638868278 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10484#pullrequestreview-5638868278). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:57:58Z. **Review:** APPROVED --- Reviewed the changed digest paths against the cited LibreSSL 2.5.4 and 4.0.0 behavior and current module split. The static SHA256 fallback, SHA512_Final default return without digest writes, and libSceLibreSsl3 null-output exception behavior match the described sources; the tests cover the relevant output and error cases. The current head merges cleanly with upstream main (3fcb5e4d76), and conventions plus diff checks pass. I compiled and ran both focused digest tests directly with GCC 12.2.0 (linking the shared MD5/SHA1 primitive implementation for the SSL3 test); both passed. The Windows CTest results and broader test results are author-reported, not reproduced here.
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!10484
No description provided.