fix(libSceLibreSsl3): run cipher updates with the LibreSSL 4.0.0 prologue #18861
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18861"
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-12T12:39:56Z.
What
Give
libSceLibreSsl3its ownEVP_EncryptUpdate,EVP_DecryptUpdateandEVP_CipherUpdate(NIDsOnoZKqFGNjA,IXiXAHDFjeU,w03a1pfG8oM) with the LibreSSL 4.0.0 prologue, instead of forwarding them to libSceLibreSsl's 2.5.4 updates. This is the follow-up #16249 left open. Source: LibreSSL 4.0.0evp/evp_cipher.catce488b78, the revision the library's debt file already uses and the versionOpenSSL_versionreports.The forwarded 2.5.4 updates differ from 4.0.0 in ways that callers of libSceLibreSsl3 can see:
EVP_aes_*_gcmandEVP_chacha20_poly1305take it as the final call and compute or check the tag early. 4.0.0 returns 1 without calling the cipher, except in CCM mode.do_ciphercast tosize_t. 4.0.0 returns 0.*outl: 4.0.0 sets it to 0 first, so it is 0 whenever the call fails. 2.5.4 leaves it unset on several failure paths.final_usedbefore the inner update, so a failed update drops the held block.EVP_R_BAD_BLOCK_LENGTH(136) for an out-of-range buffered count instead of failing silently. It also queuesEVP_R_TOO_LARGE(164) for its overflow checks.The code is a line-for-line port over libSceLibreSsl's
EVP_CIPHER_CTX, which libSceLibreSsl3 already shares (buf_lenstands for 4.0.0'spartial_len;buf,final,final_usedandflagsmatch). It calls the cipher'sdo_cipherdirectly and never the parent's update exports, so the Linux NID patcher cannot turn a call to the parent into a call to itself.src/EvpCipherUpdate.cpp. The exports use the_nid_disambig1_nid_postfixnames, asEVP_PKEY_freeandEVP_PKEY_get1_RSAalready do, so they hash to the same NIDs as the parent's (checked withtools/nid_names.py). They are declared once ininclude/Api.hpp.ParentExports.cpp, so the NIDs are defined only once in the DLL. That leaves 387 forwarders, the count the existing debt entry already gives.outl, a cipher withoutdo_cipher, and a null buffer that a non-custom cipher or amemcpywould read or write throwstd::invalid_argument. LibreSSL dereferences null in these cases.docs/dev/debt/libSceLibreSsl3.mdgets an entry for the new file. The ChaCha entry loses its zero-length-update gap, and the AES-CCM entry now names only the forwarded finals.Known gap, recorded in the new entry: on Linux and macOS, imports bind by NID alone. So libSceLibreSsl importers and libSceLibreSsl3 importers both reach whichever of the two modules the loader searches first. The overrides that already exist (
EVP_PKEY_free,EVP_PKEY_new) have the same limitation. The finals (EVP_EncryptFinal_ex,EVP_DecryptFinal_ex,EVP_CipherFinal_ex) stay forwarded here; #18942, stacked on this one, ports them.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 1755 open pull requests. Only #17299 and #17303 touch these three NIDs: they rename the same
ParentExports.cppforwarders that this PR removes. That is a line conflict, not the same function. Whichever merges second drops or rebases those six lines, and I will rebase this one as needed.pr_overlap --branchreports the same two pull requests and no other with the same exports or new files. It also flags these three exports as defined in libSceLibreSsl too, which is intentional: that is the override. 33 pull requests that conflict withmaincould not be compared by the tool. I scanned the lines each of them adds: none mentions these exports, their NIDs or anEvpCipherUpdatefile. Their shared files areApi.hpp,CMakeLists.txtand the debt file, so the conflicts there are adjacent-line ones.Tested
Rebased onto
main4e4132f468. No title or homebrew. Release builds of everyguest_libressl*andguest_crypto_memcmptest target and their dependencies, on two systems:Results:
ctest -R '^guest_(libressl|crypto_memcmp)'passes 142/142, including the newguest_libressl3_evp_cipher_update.guest_libressl3_mixed_evpandguest_libressl3_pkey_lifecycle, which load the NID-patchedlibSceLibreSsl3.prxtogether withlibSceLibreSsl.prx.guest_libressl3_chacha,guest_libressl3_aes_ccm,guest_libressl3_evp_cipher_init,guest_libressl_evp_cipher*). Their checks call libSceLibreSsl's own updates.objdump -pon the NID-patchedlibSceLibreSsl3.prxlistsOnoZKqFGNjA,IXiXAHDFjeUandw03a1pfG8oMonce each, and noEVP_*Updatename. On Linux,nm -D --defined-onlyon the patched module lists the same three NIDs as defined symbols.public_headers*tests, allconventions_*anddebt_*tests,export_gap,unbuilt_exports,tools_nid_name_audit,nid_elf_duplicatesand thepr_overlap_*tests pass;debt_split_DebtSplitTests_test_main_reports_non_git_repositoryfails only because this checkout keeps its temporary directory inside the repository;guest_export_lookup,windows_guest_export_aliasesandstrict_nid_filterneed the relinker executable, which was not built.python3 tools/check_conventions.py --base upstream/mainpasses.mainf0c378b784: the same Windows (141/141) and Linux (143/143) runs passed before the rebase.*outl = 0, thefinal_usedclear, the power-of-two check, thebuf_lenadvance, the input advance, the tail buffering, the no-padding path, the held block and the error queueing. The thirteenth inverts theEVP_CipherUpdatedispatch.evp_cipher.ccovered check order, block sizes 0, 1, 12, negative andINT_MIN, the signed/unsigned size comparisons, the overflow checks and when state changes on failure. It found no difference outside the documented throws.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