fix(libSceLibreSsl3): finish ciphers with the LibreSSL 4.0.0 epilogue #18942

Merged
Ducengarth merged 6 commits from upstream-pr/18942 into main 2026-11-21 16:48:14 +00:00
Ducengarth commented 2026-11-12 14:56:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-12T14:56:51Z.


What

Give libSceLibreSsl3 its own EVP_EncryptFinal_ex, EVP_DecryptFinal_ex and EVP_CipherFinal_ex (NIDs 9x78-Zpc+XE, urpDB9rHb4s, FgP0jMzeUU0) with the LibreSSL 4.0.0 epilogue, instead of forwarding them to libSceLibreSsl's 2.5.4 finals. This is the follow-up to #18861, which did the same for the three updates. Those six, plus the inits, are the cipher entry points libSceLibreSsl3 exports in the PS5 3.20 inventory; there is no EVP_EncryptFinal, EVP_DecryptFinal, EVP_CipherFinal or EVP_Cipher. Source: LibreSSL 4.0.0 evp/evp_cipher.c at ce488b78.

Differences from the forwarded 2.5.4 finals that callers can see:

  • EVP_EncryptFinal_ex clears *outl first. 2.5.4 leaves it unset when a custom cipher fails, when the block size is too large and when an unpadded encryption ends with buffered bytes.
  • Errors are queued where 2.5.4 fails silently or goes on:
    • EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH (138) for an unpadded encryption with buffered bytes, where 2.5.4 returns 0 with an empty queue;
    • EVP_R_BAD_BLOCK_LENGTH (136) for a block size above the buffer, where 2.5.4 also returns 0 silently, and for a buffered count of the block size or more, where 2.5.4 skips the padding and encrypts the stale buffer.
  • Check order follows 4.0.0. In EVP_EncryptFinal_ex, the custom-cipher call comes before the block checks, and the buffered-count check comes before the block-size-1 shortcut.
  • EVP_DecryptFinal_ex already matched. It gets the same port for consistency; the only differences are at block size 0. Without a held block, 4.0.0 queues EVP_R_WRONG_FINAL_BLOCK_LENGTH (109) where 2.5.4 returns 1. With a held block, 4.0.0 reads final[-1] and this port throws.

The code is in a new src/EvpCipherFinal.cpp, over the same shared EVP_CIPHER_CTX as #18861. It calls do_cipher directly and never the parent's exports. The exports use _nid_disambig1_nid_postfix names (NIDs checked with tools/nid_names.py), are declared once in include/Api.hpp, and their three Windows forwarders are removed from ParentExports.cpp, which now holds 384.

  • Undefined upstream cases: a null context, cipher or outl, a cipher without do_cipher, a null output for a padded block or for plaintext, and a held block with block size 0 throw std::invalid_argument. LibreSSL dereferences null or reads out of bounds in these cases.
  • Debt: a new entry in docs/dev/debt/libSceLibreSsl3.md, and the AES-CCM entry loses its last forwarded-*outl gap.

Known gap, as in #18861: on Linux and macOS imports bind by NID alone, so libSceLibreSsl and libSceLibreSsl3 importers reach whichever module the loader searches first.

No title's trace or disassembly was used, and nothing was measured on a PS5.

Overlap: before writing the code I indexed the diffs of all open pull requests. Only #17299 and #17303 touch these three NIDs: they rename the same forwarders this PR removes, which is a line conflict. pr_overlap --branch also lists:

  • #18861, which this one stacks on;
  • #16918 (EC_GROUP_cmp), which adds an entry next to the one this PR edits in the debt file.

It flags the six exports as defined in libSceLibreSsl too, which is the intended override. It could not compare 29 pull requests that conflict with main. I scanned the lines each of them adds: none mentions these exports, their NIDs or an EvpCipherUpdate/EvpCipherFinal file.

Tested

Stacked on #18861, both rebased onto main 4e4132f468. Same machines and toolchains as #18861: Windows 11 with MinGW-w64 GCC 15.2 (WinLibs), and Ubuntu 24.04 under WSL2 with GCC 13.3. Release builds of every guest_libressl* and guest_crypto_memcmp test target. No title or homebrew.

  • Windows: ctest -R '^guest_(libressl|crypto_memcmp)' passes 143/143, including the new guest_libressl3_evp_cipher_final and #18861's guest_libressl3_evp_cipher_update.
  • Linux: the same selection passes 145/145, including guest_libressl3_mixed_evp and guest_libressl3_pkey_lifecycle with the NID-patched modules.
  • Patched modules: on Windows, objdump -p on the NID-patched libSceLibreSsl3.prx lists 9x78-Zpc+XE, urpDB9rHb4s and FgP0jMzeUU0 once each as exports. They no longer appear in its import table from libSceLibreSsl. On Linux, nm -D --defined-only lists all six update and final NIDs as defined symbols.
  • What the new test covers, with fake ciphers:
    • a custom cipher (the final call reaches it with a null input, and its -1 gives 0 with *outl 0);
    • padding a partial block and a full block;
    • a cipher failure;
    • an unpadded final with and without buffered bytes (138);
    • a buffered count equal to the block size (136);
    • a stream cipher;
    • decrypting a held block with 10 bytes of plaintext and with a full padding block;
    • pad bytes 0, 17 and inconsistent (100);
    • no held block and buffered bytes (109);
    • the EVP_CipherFinal_ex dispatch, and null context or outl throwing.
  • Mutations: 11 deliberate mutations each make the new test fail. They drop the upfront *outl = 0, the 136 and 138 queueing, the padding write, the block-size-1 shortcut, the negative custom result, the buffered check of the decrypt, the zero-pad check, the pad-byte check and the plaintext length, and one inverts the dispatch.
  • Repository checks: python core/libs/tests/test_public_headers.py --audit-only passes (34466 exports), and so does python3 tools/check_conventions.py --base upstream/main.

Not covered: macOS, and a run inside a title.

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: #18861
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5279669559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18942). Originally posted by [Ducengarth](https://github.com/Ducengarth) on 2026-11-12T14:56:51Z. --- ### What Give `libSceLibreSsl3` its own `EVP_EncryptFinal_ex`, `EVP_DecryptFinal_ex` and `EVP_CipherFinal_ex` (NIDs `9x78-Zpc+XE`, `urpDB9rHb4s`, `FgP0jMzeUU0`) with the LibreSSL 4.0.0 epilogue, instead of forwarding them to libSceLibreSsl's 2.5.4 finals. This is the follow-up to #18861, which did the same for the three updates. Those six, plus the inits, are the cipher entry points libSceLibreSsl3 exports in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibreSsl3.c); there is no `EVP_EncryptFinal`, `EVP_DecryptFinal`, `EVP_CipherFinal` or `EVP_Cipher`. Source: LibreSSL 4.0.0 [`evp/evp_cipher.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/evp/evp_cipher.c) at `ce488b78`. Differences from the forwarded 2.5.4 finals that callers can see: - **`EVP_EncryptFinal_ex` clears `*outl` first.** 2.5.4 leaves it unset when a custom cipher fails, when the block size is too large and when an unpadded encryption ends with buffered bytes. - **Errors are queued where 2.5.4 fails silently or goes on:** - `EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH` (138) for an unpadded encryption with buffered bytes, where 2.5.4 returns 0 with an empty queue; - `EVP_R_BAD_BLOCK_LENGTH` (136) for a block size above the buffer, where 2.5.4 also returns 0 silently, and for a buffered count of the block size or more, where 2.5.4 skips the padding and encrypts the stale buffer. - **Check order follows 4.0.0.** In `EVP_EncryptFinal_ex`, the custom-cipher call comes before the block checks, and the buffered-count check comes before the block-size-1 shortcut. - **`EVP_DecryptFinal_ex` already matched.** It gets the same port for consistency; the only differences are at block size 0. Without a held block, 4.0.0 queues `EVP_R_WRONG_FINAL_BLOCK_LENGTH` (109) where 2.5.4 returns 1. With a held block, 4.0.0 reads `final[-1]` and this port throws. The code is in a new `src/EvpCipherFinal.cpp`, over the same shared `EVP_CIPHER_CTX` as #18861. It calls `do_cipher` directly and never the parent's exports. The exports use `_nid_disambig1_nid_postfix` names (NIDs checked with `tools/nid_names.py`), are declared once in `include/Api.hpp`, and their three Windows forwarders are removed from `ParentExports.cpp`, which now holds 384. - **Undefined upstream cases**: a null context, cipher or `outl`, a cipher without `do_cipher`, a null output for a padded block or for plaintext, and a held block with block size 0 throw `std::invalid_argument`. LibreSSL dereferences null or reads out of bounds in these cases. - **Debt**: a new entry in `docs/dev/debt/libSceLibreSsl3.md`, and the AES-CCM entry loses its last forwarded-`*outl` gap. **Known gap**, as in #18861: on Linux and macOS imports bind by NID alone, so libSceLibreSsl and libSceLibreSsl3 importers reach whichever module the loader searches first. No title's trace or disassembly was used, and nothing was measured on a PS5. **Overlap**: before writing the code I indexed the diffs of all open pull requests. Only #17299 and #17303 touch these three NIDs: they rename the same forwarders this PR removes, which is a line conflict. `pr_overlap --branch` also lists: - #18861, which this one stacks on; - #16918 (`EC_GROUP_cmp`), which adds an entry next to the one this PR edits in the debt file. It flags the six exports as defined in libSceLibreSsl too, which is the intended override. It could not compare 29 pull requests that conflict with `main`. I scanned the lines each of them adds: none mentions these exports, their NIDs or an `EvpCipherUpdate`/`EvpCipherFinal` file. ### 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. --> Stacked on #18861, both rebased onto `main` `4e4132f468`. Same machines and toolchains as #18861: Windows 11 with MinGW-w64 GCC 15.2 (WinLibs), and Ubuntu 24.04 under WSL2 with GCC 13.3. Release builds of every `guest_libressl*` and `guest_crypto_memcmp` test target. No title or homebrew. - **Windows**: `ctest -R '^guest_(libressl|crypto_memcmp)'` passes 143/143, including the new `guest_libressl3_evp_cipher_final` and #18861's `guest_libressl3_evp_cipher_update`. - **Linux**: the same selection passes 145/145, including `guest_libressl3_mixed_evp` and `guest_libressl3_pkey_lifecycle` with the NID-patched modules. - **Patched modules**: on Windows, `objdump -p` on the NID-patched `libSceLibreSsl3.prx` lists `9x78-Zpc+XE`, `urpDB9rHb4s` and `FgP0jMzeUU0` once each as exports. They no longer appear in its import table from libSceLibreSsl. On Linux, `nm -D --defined-only` lists all six update and final NIDs as defined symbols. - **What the new test covers**, with fake ciphers: - a custom cipher (the final call reaches it with a null input, and its `-1` gives 0 with `*outl` 0); - padding a partial block and a full block; - a cipher failure; - an unpadded final with and without buffered bytes (138); - a buffered count equal to the block size (136); - a stream cipher; - decrypting a held block with 10 bytes of plaintext and with a full padding block; - pad bytes 0, 17 and inconsistent (100); - no held block and buffered bytes (109); - the `EVP_CipherFinal_ex` dispatch, and null context or `outl` throwing. - **Mutations**: 11 deliberate mutations each make the new test fail. They drop the upfront `*outl = 0`, the 136 and 138 queueing, the padding write, the block-size-1 shortcut, the negative custom result, the buffered check of the decrypt, the zero-pad check, the pad-byte check and the plaintext length, and one inverts the dispatch. - **Repository checks**: `python core/libs/tests/test_public_headers.py --audit-only` passes (34466 exports), and so does `python3 tools/check_conventions.py --base upstream/main`. Not covered: macOS, and a run inside a title. ### 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: #18861 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-12 17:11:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T17:11:14Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d8c2a337aa:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_evp_cipher_final_tests, guest_libressl3_evp_cipher_update_tests built cleanly.
  • CTest (guest_libressl3_evp_cipher_update, guest_libressl3_evp_cipher_final):
    1/2 Test #3674: guest_libressl3_evp_cipher_update ...   Passed    0.01 sec
    2/2 Test #3675: guest_libressl3_evp_cipher_final ....   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/ParentExports.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified that Encrypt clears *written = 0 upfront and validates buffer bounds (partial < 0 || partial >= blockSize || static_caststd::size_t(blockSize) > sizeof(context->buf)) before calling cipher.doCipher, queueing BadBlockLength (136) on invalid block lengths and DataNotMultipleOfBlockLength (138) when CipherFlagNoPadding is set with non-zero buffer remainder.
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified that Decrypt validates PKCS#7 padding against context->final, enforcing partial == 0 and context->finalUsed == 1 (queueing WrongFinalBlockLength (109) otherwise), verifying pad byte 1 <= pad <= blockSize and trailing byte consistency, and queueing BadDecrypt (100) on padding corruption.
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified null-pointer and invalid state guards in Checked, Custom, Encrypt, and Decrypt, ensuring null context, missing cipher, null written, missing cipher.doCipher, null out for non-zero plaintext/ciphertext, and zero block size throw std::invalid_argument in accordance with technical debt specifications.
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified that Custom correctly handles CipherFlagCustomCipher for both encryption and decryption, returning 0 with *written = 0 when cipher.doCipher returns negative, and returning 1 with *written = produced for non-negative results matching LibreSSL 4.0.0.
    • core/libs/prx/libSceLibreSsl3/ParentExports.cpp & include/Api.hpp: Verified the removal of the three Windows forwarders (9x78-Zpc+XE, urpDB9rHb4s, FgP0jMzeUU0) from ParentExports.cpp (updating the count from 387 to 384) and verified proper declarations in Api.hpp using APS5_VABI and _nid_disambig1_nid_postfix identifiers.
    • core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp: Verified comprehensive unit test coverage exercising custom ciphers, stream ciphers (blockSize == 1), padded/unpadded encryptions, corrupt buffer lengths, padding verification (bytes 0, 17, and mismatched padding sequences), missing final blocks, and invalid argument exception handling.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5878791269 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18942#pullrequestreview-5878791269). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T17:11:14Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `d8c2a337aa`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_evp_cipher_final_tests`, `guest_libressl3_evp_cipher_update_tests` built cleanly. - **CTest** (`guest_libressl3_evp_cipher_update`, `guest_libressl3_evp_cipher_final`): ``` 1/2 Test #3674: guest_libressl3_evp_cipher_update ... Passed 0.01 sec 2/2 Test #3675: guest_libressl3_evp_cipher_final .... Passed 0.01 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/ParentExports.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified that Encrypt clears *written = 0 upfront and validates buffer bounds (partial < 0 || partial >= blockSize || static_cast<std::size_t>(blockSize) > sizeof(context->buf)) before calling cipher.doCipher, queueing BadBlockLength (136) on invalid block lengths and DataNotMultipleOfBlockLength (138) when CipherFlagNoPadding is set with non-zero buffer remainder. - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified that Decrypt validates PKCS#7 padding against context->final, enforcing partial == 0 and context->finalUsed == 1 (queueing WrongFinalBlockLength (109) otherwise), verifying pad byte 1 <= pad <= blockSize and trailing byte consistency, and queueing BadDecrypt (100) on padding corruption. - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified null-pointer and invalid state guards in Checked, Custom, Encrypt, and Decrypt, ensuring null context, missing cipher, null written, missing cipher.doCipher, null out for non-zero plaintext/ciphertext, and zero block size throw std::invalid_argument in accordance with technical debt specifications. - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: Verified that Custom correctly handles CipherFlagCustomCipher for both encryption and decryption, returning 0 with *written = 0 when cipher.doCipher returns negative, and returning 1 with *written = produced for non-negative results matching LibreSSL 4.0.0. - core/libs/prx/libSceLibreSsl3/ParentExports.cpp & include/Api.hpp: Verified the removal of the three Windows forwarders (9x78-Zpc+XE, urpDB9rHb4s, FgP0jMzeUU0) from ParentExports.cpp (updating the count from 387 to 384) and verified proper declarations in Api.hpp using APS5_VABI and _nid_disambig1_nid_postfix identifiers. - core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp: Verified comprehensive unit test coverage exercising custom ciphers, stream ciphers (blockSize == 1), padded/unpadded encryptions, corrupt buffer lengths, padding verification (bytes 0, 17, and mismatched padding sequences), missing final blocks, and invalid argument exception handling. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Looks Good To Me
PrivacyOnion commented 2026-11-13 19:25:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T19:25:13Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 00f0acbb4b:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_evp_cipher_final_tests, guest_libressl3_evp_cipher_update_tests built cleanly.
  • CTest (guest_libressl3_evp_cipher_update, guest_libressl3_evp_cipher_final):
    1/2 Test #3772: guest_libressl3_evp_cipher_update ...   Passed    0.02 sec
    2/2 Test #3773: guest_libressl3_evp_cipher_final ....   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/ParentExports.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified in core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp that Encrypt and Decrypt initialize *written = 0 upfront and correctly queue LibreSSL 4.0.0 error codes (BadBlockLength 136, DataNotMultipleOfBlockLength 138, WrongFinalBlockLength 109, and BadDecrypt 100) via LibreSslPutError_nid_no_patch(6, 0xfff, ...).
    • Verified in core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp and EvpCipherUpdate.cpp that Checked, Run, and Copy guard all pointer dereferences (context, context->cipher, written, out, in) with explicit std::invalid_argument checks and buffer bounds checks against sizeof(context->buf) and sizeof(context->final).
    • Verified in core/libs/prx/libSceLibreSsl3/ParentExports.cpp that Windows forwarders for all six cipher operations (9x78-Zpc+XE, FgP0jMzeUU0, IXiXAHDFjeU, OnoZKqFGNjA, urpDB9rHb4s, w03a1pfG8oM) were cleanly removed to eliminate delegation to libSceLibreSsl.
    • Verified that export declarations in core/libs/prx/libSceLibreSsl3/include/Api.hpp match the signatures, C linkage, and APS5_VABI calling conventions in src/EvpCipherFinal.cpp and src/EvpCipherUpdate.cpp.
    • Verified that core/libs/prx/libSceLibreSsl3/CMakeLists.txt adds EvpCipherFinal.cpp and EvpCipherUpdate.cpp to libSceLibreSsl3 sources and registers guest_libressl3_evp_cipher_final and guest_libressl3_evp_cipher_update test executables with configure_windows_unwind and PATH staging.
    • Verified that unit tests in core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp and tests/EvpCipherUpdate.cpp exhaustively validate custom ciphers, padding roundtrips, unpadded stream/block checks, error queue inspection, and bidirectional dispatch through EVP_CipherFinal_ex and EVP_CipherUpdate.
    • Verified docs/dev/debt/libSceLibreSsl3.md adds an accurate technical debt entry for EVP_EncryptFinal_ex, EVP_DecryptFinal_ex, and EVP_CipherFinal_ex referencing core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp with correct relative path depth
    • Verified the new debt entry in docs/dev/debt/libSceLibreSsl3.md thoroughly documents the LibreSSL 4.0.0 reference implementation, 2.5.4 EVP_CIPHER_CTX layout usage, NID binding gap, and throw behavior for undefined upstream cases
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5896791059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18942#pullrequestreview-5896791059). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T19:25:13Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `00f0acbb4b`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_evp_cipher_final_tests`, `guest_libressl3_evp_cipher_update_tests` built cleanly. - **CTest** (`guest_libressl3_evp_cipher_update`, `guest_libressl3_evp_cipher_final`): ``` 1/2 Test #3772: guest_libressl3_evp_cipher_update ... Passed 0.02 sec 2/2 Test #3773: guest_libressl3_evp_cipher_final .... Passed 0.03 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/ParentExports.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified in core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp that Encrypt and Decrypt initialize *written = 0 upfront and correctly queue LibreSSL 4.0.0 error codes (BadBlockLength 136, DataNotMultipleOfBlockLength 138, WrongFinalBlockLength 109, and BadDecrypt 100) via LibreSslPutError_nid_no_patch(6, 0xfff, ...). - Verified in core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp and EvpCipherUpdate.cpp that Checked, Run, and Copy guard all pointer dereferences (context, context->cipher, written, out, in) with explicit std::invalid_argument checks and buffer bounds checks against sizeof(context->buf) and sizeof(context->final). - Verified in core/libs/prx/libSceLibreSsl3/ParentExports.cpp that Windows forwarders for all six cipher operations (9x78-Zpc+XE, FgP0jMzeUU0, IXiXAHDFjeU, OnoZKqFGNjA, urpDB9rHb4s, w03a1pfG8oM) were cleanly removed to eliminate delegation to libSceLibreSsl. - Verified that export declarations in core/libs/prx/libSceLibreSsl3/include/Api.hpp match the signatures, C linkage, and APS5_VABI calling conventions in src/EvpCipherFinal.cpp and src/EvpCipherUpdate.cpp. - Verified that core/libs/prx/libSceLibreSsl3/CMakeLists.txt adds EvpCipherFinal.cpp and EvpCipherUpdate.cpp to libSceLibreSsl3 sources and registers guest_libressl3_evp_cipher_final and guest_libressl3_evp_cipher_update test executables with configure_windows_unwind and PATH staging. - Verified that unit tests in core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp and tests/EvpCipherUpdate.cpp exhaustively validate custom ciphers, padding roundtrips, unpadded stream/block checks, error queue inspection, and bidirectional dispatch through EVP_CipherFinal_ex and EVP_CipherUpdate. - Verified docs/dev/debt/libSceLibreSsl3.md adds an accurate technical debt entry for EVP_EncryptFinal_ex, EVP_DecryptFinal_ex, and EVP_CipherFinal_ex referencing core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp with correct relative path depth - Verified the new debt entry in docs/dev/debt/libSceLibreSsl3.md thoroughly documents the LibreSSL 4.0.0 reference implementation, 2.5.4 EVP_CIPHER_CTX layout usage, NID binding gap, and throw behavior for undefined upstream cases - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Looks Good To Me
PrivacyOnion commented 2026-11-17 10:00:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T10:00:14Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against ba0bcd6d66:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl3_evp_cipher_final_tests built cleanly.
  • CTest (guest_libressl3_evp_cipher_final):
    1/1 Test #4312: guest_libressl3_evp_cipher_final ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/ParentExports.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp properly null-checks context, cipher, written, and out before pointer dereference, throwing std::invalid_argument in accordance with AnyPS5 conventions.
    • Verified Checked, Encrypt, Decrypt, and Custom functions correctly handle custom ciphers, stream ciphers (blockSize == 1), and padded block ciphers matching LibreSSL 4.0.0 evp_cipher.c semantics.
    • Verified that error codes BadDecrypt (100), WrongFinalBlockLength (109), BadBlockLength (136), and DataNotMultipleOfBlockLength (138) are correctly queued to the LibreSSL error queue with EvpLibrary (6) and AnyFunction (0xfff).
    • Verified memory bounds checks against sizeof(context->buf) and sizeof(context->final) before calling std::memset and std::memcpy, avoiding out-of-bounds access or buffer overruns.
    • Verified that Windows forwarder jumps for EVP_EncryptFinal_ex, EVP_DecryptFinal_ex, and EVP_CipherFinal_ex were cleanly removed from ParentExports.cpp and replaced with direct implementations in libSceLibreSsl3, while debt fragments reflect the correct export counts (383 and 384).
    • Verified AGENTS.md compliance: licence header adapted verbatim from OpenBSD/LibreSSL 4.0.0, no inline comments in code, debt fragments documented under docs/dev/debt/, and comprehensive unit tests in tests/EvpCipherFinal.cpp.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5936360901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18942#pullrequestreview-5936360901). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T10:00:14Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `ba0bcd6d66`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl3_evp_cipher_final_tests` built cleanly. - **CTest** (`guest_libressl3_evp_cipher_final`): ``` 1/1 Test #4312: guest_libressl3_evp_cipher_final ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/ParentExports.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp properly null-checks context, cipher, written, and out before pointer dereference, throwing std::invalid_argument in accordance with AnyPS5 conventions. - Verified Checked, Encrypt, Decrypt, and Custom functions correctly handle custom ciphers, stream ciphers (blockSize == 1), and padded block ciphers matching LibreSSL 4.0.0 evp_cipher.c semantics. - Verified that error codes BadDecrypt (100), WrongFinalBlockLength (109), BadBlockLength (136), and DataNotMultipleOfBlockLength (138) are correctly queued to the LibreSSL error queue with EvpLibrary (6) and AnyFunction (0xfff). - Verified memory bounds checks against sizeof(context->buf) and sizeof(context->final) before calling std::memset and std::memcpy, avoiding out-of-bounds access or buffer overruns. - Verified that Windows forwarder jumps for EVP_EncryptFinal_ex, EVP_DecryptFinal_ex, and EVP_CipherFinal_ex were cleanly removed from ParentExports.cpp and replaced with direct implementations in libSceLibreSsl3, while debt fragments reflect the correct export counts (383 and 384). - Verified AGENTS.md compliance: licence header adapted verbatim from OpenBSD/LibreSSL 4.0.0, no inline comments in code, debt fragments documented under docs/dev/debt/, and comprehensive unit tests in tests/EvpCipherFinal.cpp. Looks Good To Me
PrivacyOnion commented 2026-11-18 12:41:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T12:41:31Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d35739c4ee:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl3_evp_cipher_final_tests built cleanly.
  • CTest (guest_libressl3_evp_cipher_final):
    1/1 Test #4377: guest_libressl3_evp_cipher_final ...   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/ParentExports.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: verified null/bounds checks on context, cipher, written, out, and buffer capacities (sizeof(context->buf), sizeof(context->final)) matching LibreSSL 4.0.0 evp_cipher.c semantics
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: verified error queuing to LibreSslPutError_nid_no_patch with EvpLibrary (6) and AnyFunction (0xfff) for BadDecrypt (100), WrongFinalBlockLength (109), BadBlockLength (136), and DataNotMultipleOfBlockLength (138)
    • core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: verified custom cipher dispatch (CipherFlagCustomCipher), stream cipher bypass (blockSize == 1), and padding validation (PKCS#7 unpadding and context->finalUsed check)
    • core/libs/prx/libSceLibreSsl3/ParentExports.cpp: verified removal of Windows IAT forwarder tail jumps for EVP_EncryptFinal_ex, EVP_DecryptFinal_ex, and EVP_CipherFinal_ex and export count adjustments in debt documents (384 and 382)
    • core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp: verified exhaustive test coverage for custom ciphers, padded/unpadded encryption/decryption, corruption cases, error codes, and invalid argument handling

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956716769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18942#pullrequestreview-5956716769). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T12:41:31Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `d35739c4ee`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl3_evp_cipher_final_tests` built cleanly. - **CTest** (`guest_libressl3_evp_cipher_final`): ``` 1/1 Test #4377: guest_libressl3_evp_cipher_final ... Passed 0.04 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/ParentExports.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: verified null/bounds checks on context, cipher, written, out, and buffer capacities (sizeof(context->buf), sizeof(context->final)) matching LibreSSL 4.0.0 evp_cipher.c semantics - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: verified error queuing to LibreSslPutError_nid_no_patch with EvpLibrary (6) and AnyFunction (0xfff) for BadDecrypt (100), WrongFinalBlockLength (109), BadBlockLength (136), and DataNotMultipleOfBlockLength (138) - core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp: verified custom cipher dispatch (CipherFlagCustomCipher), stream cipher bypass (blockSize == 1), and padding validation (PKCS#7 unpadding and context->finalUsed check) - core/libs/prx/libSceLibreSsl3/ParentExports.cpp: verified removal of Windows IAT forwarder tail jumps for EVP_EncryptFinal_ex, EVP_DecryptFinal_ex, and EVP_CipherFinal_ex and export count adjustments in debt documents (384 and 382) - core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp: verified exhaustive test coverage for custom ciphers, padded/unpadded encryption/decryption, corruption cases, error codes, and invalid argument handling Looks Good To Me
MarcZX10 commented 2026-11-21 06:13:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T06:13:47Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this change; the optional point below is informational.

What I ran

Reviewed head d35739c4ee8a28e104ccc4c8cfe3c5d4022c441b using the prepared diff and the pinned repo_read.py reader. No build or tests were run in this review.

Results

Check Result Note
Diff and changed code passed All seven changed files read
Build and tests not run Results in the PR description are author-reported

Findings

Blocking

None.

Non-blocking

  • The exception behavior for null inputs and missing cipher callbacks is an intentional safety choice documented in the PR; those paths differ from upstream faulting behavior and are not covered by tests for every case.

Not verified

No tests or builds were run independently, and console behavior was not verified. The description reports Windows and Linux test runs and notes macOS and title execution were not covered. The changed files read were core/libs/prx/libSceLibreSsl3/CMakeLists.txt, core/libs/prx/libSceLibreSsl3/ParentExports.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp, core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp, docs/dev/debt/changes/libressl3-20171-inventory.md, and docs/dev/debt/libSceLibreSsl3.md. files.json was not available; the reader's file listing showed all seven changed files included.

To get this to a good state

Nothing is required. The optional point above is informational.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003419348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18942#pullrequestreview-6003419348). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T06:13:47Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this change; the optional point below is informational. ## What I ran Reviewed head `d35739c4ee8a28e104ccc4c8cfe3c5d4022c441b` using the prepared diff and the pinned `repo_read.py` reader. No build or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | All seven changed files read | | Build and tests | not run | Results in the PR description are author-reported | ## Findings ### Blocking None. ### Non-blocking - The exception behavior for null inputs and missing cipher callbacks is an intentional safety choice documented in the PR; those paths differ from upstream faulting behavior and are not covered by tests for every case. ## Not verified No tests or builds were run independently, and console behavior was not verified. The description reports Windows and Linux test runs and notes macOS and title execution were not covered. The changed files read were `core/libs/prx/libSceLibreSsl3/CMakeLists.txt`, `core/libs/prx/libSceLibreSsl3/ParentExports.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cpp`, `core/libs/prx/libSceLibreSsl3/tests/EvpCipherFinal.cpp`, `docs/dev/debt/changes/libressl3-20171-inventory.md`, and `docs/dev/debt/libSceLibreSsl3.md`. `files.json` was not available; the reader's file listing showed all seven changed files included. ## To get this to a good state Nothing is required. The optional point above is informational.
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!18942
No description provided.