feat(libSceLibreSsl): implement the MD4, MD5, SHA-1 and SHA-2 digests #9025

Merged
HQasper merged 1 commit from upstream-pr/9025 into main 2026-10-22 22:45:13 +00:00
HQasper commented 2026-10-21 10:03:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HQasper on 2026-10-21T10:03:23Z.


What

All 399 libSceLibreSsl exports threw. This implements the 22 message digest exports, whose signatures and caller-allocated contexts are public and fixed in LibreSSL: MD4, MD5, SHA1, SHA224, SHA256, SHA384 and SHA512 _Init/_Update/_Final, plus the SHA256 one-shot.

  • The functions work on the caller's MD4_CTX, MD5_CTX, SHA_CTX, SHA256_CTX and SHA512_CTX, laid out as in LibreSSL's md4.h, md5.h and sha.h (92, 92, 96, 112 and 216 bytes, checked with static_assert). The bit count is kept in Nl/Nh, the partial block in data with its byte count in num, and md_len selects the digest length. A context the title copies or inspects therefore stays valid.
  • Buffering, padding and Final follow LibreSSL's sources. The 32-bit Final functions clear num and the buffer. SHA256_Final returns 0 when md_len is over 32 and truncates shorter lengths. SHA512_Final returns 0 for a null digest buffer or an unknown length. Update with length 0 returns 1 without reading data.
  • Behaviour that differs between LibreSSL versions throws through NotImplemented_nid_no_patch: SHA256 with a null digest buffer (older versions return a static buffer, newer ones crash) and SHA512_Final with the SHA-512/224 or SHA-512/256 length (not in older versions). Null contexts, null input with a nonzero length, null digest buffers in the 32-bit Final functions and a num that is not below the block size throw. LibreSSL does not check these and would crash or overrun the buffer.
  • The rounds are written from RFC 1320, RFC 1321 and FIPS 180-4. No third-party code is added.
  • The debt entry now counts 377 pending exports and records that the module's LibreSSL version is unknown and nothing was checked on the console.

Tested

Linux (Ubuntu 24.04 container, GCC 13, Release, BUILD_TESTING=ON):

  • New guest_libressl_digest: passed. It covers each algorithm on the empty string, abc, the 448- and 896-bit FIPS messages, the 80-digit RFC message and one million a. Each message is fed in chunks of 1, block size - 1, block size, block size + 1, 1000 and the whole message, and the results match the RFC 1320/1321 and FIPS 180 values, with the others cross-checked against Python hashlib and OpenSSL 3.0.13. The test also checks the num and Nl fields after a partial update, a context copied mid-stream, the md_len cases and the throwing cases. With a mutated MD5 constant the test aborts.
  • patched_libraries: passed. The patched libSceLibreSsl.prx exports the same 394 _nid_postfix names as before.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • Not tested: Windows, and any title or homebrew (no title using libSceLibreSsl is known).

Note: this PR and the digest PR #9033 both add core/libs/prx/libSceLibreSsl/CMakeLists.txt and change the pending-export count in the debt file. Whichever merges second needs a small rebase. Open them in either order.

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:4949809681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9025). Originally posted by [HQasper](https://github.com/HQasper) on 2026-10-21T10:03:23Z. --- ### What All 399 libSceLibreSsl exports threw. This implements the 22 message digest exports, whose signatures and caller-allocated contexts are public and fixed in LibreSSL: `MD4`, `MD5`, `SHA1`, `SHA224`, `SHA256`, `SHA384` and `SHA512` `_Init`/`_Update`/`_Final`, plus the `SHA256` one-shot. - The functions work on the caller's `MD4_CTX`, `MD5_CTX`, `SHA_CTX`, `SHA256_CTX` and `SHA512_CTX`, laid out as in LibreSSL's [md4.h, md5.h and sha.h](https://github.com/libressl/openbsd/blob/bc9483725c5815efb64b6d9acc52fc5fba139212/src/lib/libcrypto/sha/sha.h) (92, 92, 96, 112 and 216 bytes, checked with `static_assert`). The bit count is kept in `Nl`/`Nh`, the partial block in `data` with its byte count in `num`, and `md_len` selects the digest length. A context the title copies or inspects therefore stays valid. - Buffering, padding and `Final` follow LibreSSL's [sources](https://github.com/libressl/openbsd/tree/bc9483725c5815efb64b6d9acc52fc5fba139212/src/lib/libcrypto/sha). The 32-bit `Final` functions clear `num` and the buffer. `SHA256_Final` returns 0 when `md_len` is over 32 and truncates shorter lengths. `SHA512_Final` returns 0 for a null digest buffer or an unknown length. `Update` with length 0 returns 1 without reading `data`. - Behaviour that differs between LibreSSL versions throws through `NotImplemented_nid_no_patch`: `SHA256` with a null digest buffer (older versions return a static buffer, newer ones crash) and `SHA512_Final` with the SHA-512/224 or SHA-512/256 length (not in older versions). Null contexts, null input with a nonzero length, null digest buffers in the 32-bit `Final` functions and a `num` that is not below the block size throw. LibreSSL does not check these and would crash or overrun the buffer. - The rounds are written from RFC 1320, RFC 1321 and FIPS 180-4. No third-party code is added. - The debt entry now counts 377 pending exports and records that the module's LibreSSL version is unknown and nothing was checked on the console. ### Tested Linux (Ubuntu 24.04 container, GCC 13, Release, `BUILD_TESTING=ON`): - New `guest_libressl_digest`: passed. It covers each algorithm on the empty string, `abc`, the 448- and 896-bit FIPS messages, the 80-digit RFC message and one million `a`. Each message is fed in chunks of 1, block size - 1, block size, block size + 1, 1000 and the whole message, and the results match the RFC 1320/1321 and FIPS 180 values, with the others cross-checked against Python `hashlib` and OpenSSL 3.0.13. The test also checks the `num` and `Nl` fields after a partial update, a context copied mid-stream, the `md_len` cases and the throwing cases. With a mutated MD5 constant the test aborts. - `patched_libraries`: passed. The patched `libSceLibreSsl.prx` exports the same 394 `_nid_postfix` names as before. - `python3 tools/check_conventions.py --base origin/main`: passed. - Not tested: Windows, and any title or homebrew (no title using libSceLibreSsl is known). Note: this PR and the digest PR #9033 both add core/libs/prx/libSceLibreSsl/CMakeLists.txt and change the pending-export count in the debt file. Whichever merges second needs a small rebase. Open them in either order. ### Checklist - [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
github-actions[bot] commented 2026-10-21 10:04:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T10:04:14Z.


Progress report (b6fe513 → 52a439b)

📈 System libraries: 50.81% (+0.23%, +20 implemented functions)

✅ 20 implemented
Library Name
libSceLibreSsl MD4_Final_nid_postfix
libSceLibreSsl MD4_Init_nid_postfix
libSceLibreSsl MD4_Update_nid_postfix
libSceLibreSsl MD5_Final_nid_postfix
libSceLibreSsl MD5_Init_nid_postfix
libSceLibreSsl MD5_Update_nid_postfix
libSceLibreSsl SHA1_Final_nid_postfix
libSceLibreSsl SHA1_Init_nid_postfix
libSceLibreSsl SHA1_Update_nid_postfix
libSceLibreSsl SHA224_Final_nid_postfix
libSceLibreSsl SHA224_Init_nid_postfix
libSceLibreSsl SHA224_Update_nid_postfix
libSceLibreSsl SHA256_Final_nid_postfix
libSceLibreSsl SHA256_Init_nid_postfix
libSceLibreSsl SHA256_Update_nid_postfix
libSceLibreSsl SHA384_Final_nid_postfix
libSceLibreSsl SHA384_Init_nid_postfix
libSceLibreSsl SHA384_Update_nid_postfix
libSceLibreSsl SHA512_Init_nid_postfix
libSceLibreSsl SHA512_Update_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313322119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9025#issuecomment-6313322119). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T10:04:14Z. --- <!-- progress-report --> ### Progress report (b6fe513 → 52a439b) 📈 **System libraries**: 50.81% (+0.23%, +20 implemented functions) <details> <summary>✅ 20 implemented</summary> | Library | Name | | - | - | | libSceLibreSsl | `MD4_Final_nid_postfix` | | libSceLibreSsl | `MD4_Init_nid_postfix` | | libSceLibreSsl | `MD4_Update_nid_postfix` | | libSceLibreSsl | `MD5_Final_nid_postfix` | | libSceLibreSsl | `MD5_Init_nid_postfix` | | libSceLibreSsl | `MD5_Update_nid_postfix` | | libSceLibreSsl | `SHA1_Final_nid_postfix` | | libSceLibreSsl | `SHA1_Init_nid_postfix` | | libSceLibreSsl | `SHA1_Update_nid_postfix` | | libSceLibreSsl | `SHA224_Final_nid_postfix` | | libSceLibreSsl | `SHA224_Init_nid_postfix` | | libSceLibreSsl | `SHA224_Update_nid_postfix` | | libSceLibreSsl | `SHA256_Final_nid_postfix` | | libSceLibreSsl | `SHA256_Init_nid_postfix` | | libSceLibreSsl | `SHA256_Update_nid_postfix` | | libSceLibreSsl | `SHA384_Final_nid_postfix` | | libSceLibreSsl | `SHA384_Init_nid_postfix` | | libSceLibreSsl | `SHA384_Update_nid_postfix` | | libSceLibreSsl | `SHA512_Init_nid_postfix` | | libSceLibreSsl | `SHA512_Update_nid_postfix` | </details>
ycbuzi commented 2026-10-21 17:51:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T17:51:15Z.


Windows run of 52a439bc70 merged onto main 745b394629 (8d1afaa92b, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libSceLibreSsl and guest_libressl_digest_tests with no errors or warnings. ctest --repeat until-fail:2 on guest_libressl_digest: passes on both repeats. Not run: a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322741568 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9025#issuecomment-6322741568). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T17:51:15Z. --- Windows run of 52a439bc70 merged onto `main` 745b394629 (8d1afaa92b, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libSceLibreSsl` and `guest_libressl_digest_tests` with no errors or warnings. `ctest --repeat until-fail:2` on `guest_libressl_digest`: passes on both repeats. Not run: a title.
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!9025
No description provided.