fix(libSceLibreSsl3): finish ciphers with the LibreSSL 4.0.0 epilogue #18942
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18942"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-12T14:56:51Z.
What
Give
libSceLibreSsl3its ownEVP_EncryptFinal_ex,EVP_DecryptFinal_exandEVP_CipherFinal_ex(NIDs9x78-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 noEVP_EncryptFinal,EVP_DecryptFinal,EVP_CipherFinalorEVP_Cipher. Source: LibreSSL 4.0.0evp/evp_cipher.catce488b78.Differences from the forwarded 2.5.4 finals that callers can see:
EVP_EncryptFinal_exclears*outlfirst. 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.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.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_exalready matched. It gets the same port for consistency; the only differences are at block size 0. Without a held block, 4.0.0 queuesEVP_R_WRONG_FINAL_BLOCK_LENGTH(109) where 2.5.4 returns 1. With a held block, 4.0.0 readsfinal[-1]and this port throws.The code is in a new
src/EvpCipherFinal.cpp, over the same sharedEVP_CIPHER_CTXas #18861. It callsdo_cipherdirectly and never the parent's exports. The exports use_nid_disambig1_nid_postfixnames (NIDs checked withtools/nid_names.py), are declared once ininclude/Api.hpp, and their three Windows forwarders are removed fromParentExports.cpp, which now holds 384.outl, a cipher withoutdo_cipher, a null output for a padded block or for plaintext, and a held block with block size 0 throwstd::invalid_argument. LibreSSL dereferences null or reads out of bounds in these cases.docs/dev/debt/libSceLibreSsl3.md, and the AES-CCM entry loses its last forwarded-*outlgap.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 --branchalso lists: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 anEvpCipherUpdate/EvpCipherFinalfile.Tested
Stacked on #18861, both rebased onto
main4e4132f468. 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 everyguest_libressl*andguest_crypto_memcmptest target. No title or homebrew.ctest -R '^guest_(libressl|crypto_memcmp)'passes 143/143, including the newguest_libressl3_evp_cipher_finaland #18861'sguest_libressl3_evp_cipher_update.guest_libressl3_mixed_evpandguest_libressl3_pkey_lifecyclewith the NID-patched modules.objdump -pon the NID-patchedlibSceLibreSsl3.prxlists9x78-Zpc+XE,urpDB9rHb4sandFgP0jMzeUU0once each as exports. They no longer appear in its import table from libSceLibreSsl. On Linux,nm -D --defined-onlylists all six update and final NIDs as defined symbols.-1gives 0 with*outl0);EVP_CipherFinal_exdispatch, and null context oroutlthrowing.*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.python core/libs/tests/test_public_headers.py --audit-onlypasses (34466 exports), and so doespython3 tools/check_conventions.py --base upstream/main.Not covered: macOS, and a run inside a title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
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:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl3_evp_cipher_final_tests,guest_libressl3_evp_cipher_update_testsbuilt cleanly.guest_libressl3_evp_cipher_update,guest_libressl3_evp_cipher_final):core/libs/prx/libSceLibreSsl3/ParentExports.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me
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:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl3_evp_cipher_final_tests,guest_libressl3_evp_cipher_update_testsbuilt cleanly.guest_libressl3_evp_cipher_update,guest_libressl3_evp_cipher_final):core/libs/prx/libSceLibreSsl3/ParentExports.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me
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:tools/check_conventions.pypassed.guest_libressl3_evp_cipher_final_testsbuilt cleanly.guest_libressl3_evp_cipher_final):core/libs/prx/libSceLibreSsl3/ParentExports.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hpp,core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
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:tools/check_conventions.pypassed.guest_libressl3_evp_cipher_final_testsbuilt cleanly.guest_libressl3_evp_cipher_final):core/libs/prx/libSceLibreSsl3/ParentExports.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hpp,core/libs/prx/libSceLibreSsl3/src/EvpCipherFinal.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
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
d35739c4ee8a28e104ccc4c8cfe3c5d4022c441busing the prepared diff and the pinnedrepo_read.pyreader. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
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, anddocs/dev/debt/libSceLibreSsl3.md.files.jsonwas 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.