feat(libressl3): implement CRYPTO_memcmp #8956

Merged
ynkmyz233 merged 1 commit from upstream-pr/8956 into main 2026-10-23 00:00:11 +00:00
ynkmyz233 commented 2026-10-21 07:04:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ynkmyz233 on 2026-10-21T07:04:19Z.


What

libSceLibreSsl3's CRYPTO_memcmp currently throws for every call. Implement the public LibreSSL contract: compare exactly length bytes, returning zero for equality and nonzero otherwise. Volatile unsigned-byte reads accumulate differences without a content-dependent early return. Update technical debt to retain the unverified PS5 behavior and toolchain-dependent timing guarantees.

Tested

Windows x86-64, MinGW-w64 GCC 15.2.0, Release build:

  • Built the actual shared library and passed the new guest_crypto_memcmp CTest.
  • Covered 65,536 one-byte value pairs, mismatch positions, multiple differences, zero lengths, unaligned/overlapping ranges, unchanged inputs, and read-only buffers ending at inaccessible protection pages.
  • Inspected optimized shared-library assembly: conditional branches depend only on length, not buffer contents.
  • NID export listing/transformation, conventions checks, and whitespace checks passed. tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch feat/libressl3-crypto-memcmp reported no overlap with open pull requests.

PS5 hardware, other platforms, commercial titles, and the full test suite were not tested. Other toolchains still require generated-code inspection.

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 (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4947738801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8956). Originally posted by [ynkmyz233](https://github.com/ynkmyz233) on 2026-10-21T07:04:19Z. --- ### What `libSceLibreSsl3`'s `CRYPTO_memcmp` currently throws for every call. Implement the public [LibreSSL contract](https://man.openbsd.org/CRYPTO_memcmp.3): compare exactly `length` bytes, returning zero for equality and nonzero otherwise. Volatile unsigned-byte reads accumulate differences without a content-dependent early return. Update technical debt to retain the unverified PS5 behavior and toolchain-dependent timing guarantees. ### Tested Windows x86-64, MinGW-w64 GCC 15.2.0, Release build: - Built the actual shared library and passed the new `guest_crypto_memcmp` CTest. - Covered 65,536 one-byte value pairs, mismatch positions, multiple differences, zero lengths, unaligned/overlapping ranges, unchanged inputs, and read-only buffers ending at inaccessible protection pages. - Inspected optimized shared-library assembly: conditional branches depend only on length, not buffer contents. - NID export listing/transformation, conventions checks, and whitespace checks passed. `tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch feat/libressl3-crypto-memcmp` reported no overlap with open pull requests. PS5 hardware, other platforms, commercial titles, and the full test suite were not tested. Other toolchains still require generated-code inspection. ### 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 (Codex)
MarcZX10 commented 2026-10-21 07:08:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T07:08:03Z.

Review: APPROVED


Reviewed the implementation and tests against the documented CRYPTO_memcmp contract. It checks exactly the requested range, returns zero/nonzero as required, has no content-dependent early exit, and documents the toolchain timing caveat. The guard-page and boundary tests are useful, and all current GitHub checks pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5596099052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8956#pullrequestreview-5596099052). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T07:08:03Z. **Review:** APPROVED --- Reviewed the implementation and tests against the documented CRYPTO_memcmp contract. It checks exactly the requested range, returns zero/nonzero as required, has no content-dependent early exit, and documents the toolchain timing caveat. The guard-page and boundary tests are useful, and all current GitHub checks pass.
r1p0N commented 2026-10-21 07:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by r1p0N on 2026-10-21T07:29:02Z.


Reviewed and ran the new test standalone (Export.cpp + GuestCryptoMemcmp.cpp, g++ 13, -O2 and ASan/UBSan): passes, no sanitizer findings.
Semantics match LibreSSL's CRYPTO_memcmp: 0 when equal, nonzero otherwise (not a sign), no early exit, reads through volatile.
Zero length with null pointers returns 0 without dereferencing; the guard-page test confirms no reads past length.
The new CMakeLists.txt duplicates the default rule in core/libs/CMakeLists.txt (same Export.cpp, include dir, unwind) and only adds the test, as libSceOpusDec does.
LGTM from my side. Not covered: full ctest, Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310550412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8956#issuecomment-6310550412). Originally posted by [r1p0N](https://github.com/r1p0N) on 2026-10-21T07:29:02Z. --- Reviewed and ran the new test standalone (Export.cpp + GuestCryptoMemcmp.cpp, g++ 13, -O2 and ASan/UBSan): passes, no sanitizer findings. Semantics match LibreSSL's CRYPTO_memcmp: 0 when equal, nonzero otherwise (not a sign), no early exit, reads through volatile. Zero length with null pointers returns 0 without dereferencing; the guard-page test confirms no reads past length. The new CMakeLists.txt duplicates the default rule in core/libs/CMakeLists.txt (same Export.cpp, include dir, unwind) and only adds the test, as libSceOpusDec does. LGTM from my side. Not covered: full ctest, Windows.
blawesom commented 2026-10-21 17:06:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-21T17:06:38Z.


Heads-up (support triage): #9043 ("feat(libSceLibreSsl3): implement MD5, SHA1 and CRYPTO_memcmp") also implements CRYPTO_memcmp for libSceLibreSsl3 and will conflict with this PR in Export.cpp. Your PR is ~3.5 hours older. Please agree which lands first and declare it with Depends on on the checklist line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321842859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8956#issuecomment-6321842859). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-21T17:06:38Z. --- Heads-up (support triage): #9043 ("feat(libSceLibreSsl3): implement MD5, SHA1 and CRYPTO_memcmp") also implements `CRYPTO_memcmp` for `libSceLibreSsl3` and will conflict with this PR in `Export.cpp`. Your PR is ~3.5 hours older. Please agree which lands first and declare it with `Depends on` on the checklist line.
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!8956
No description provided.