fix(libSceLibreSsl): queue LibreSSL errors in EVP digest and HMAC functions #16079
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16079"
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 puridanish284 on 2026-11-05T15:38:55Z.
What
libSceLibreSsl's EVP digest and HMAC functions returned their failure values without queuing an error, where LibreSSL 2.5.4, the version libSceLibreSsl reports, queues one through
EVPerror, that isERR_PACK(ERR_LIB_EVP (6), 0xfff, reason). Every such path now queues the same code throughLibreSslPutError_nid_no_patch. The return values are unchanged.EVP_MD_size(NULL), returns -1EVP_R_MESSAGE_DIGEST_IS_NULL(159)evp_lib.cL289-L296EVP_DigestInit_exwithout a type on a context without a digestEVP_R_NO_DIGEST_SET(139)digest.cL188-L191EVP_DigestInit_exfailing to allocatemd_dataERR_R_MALLOC_FAILURE(65)digest.cL203-L209EVP_DigestFinal_exwithmd_sizeaboveEVP_MAX_MD_SIZEEVP_R_TOO_LARGE(164)digest.cL250-L253EVP_MD_CTX_copy_ex) that HMAC andEVP_DigestVerifyFinaluse, from a context without a digestEVP_R_INPUT_NOT_INITIALIZED(111)digest.cL277-L280ERR_R_MALLOC_FAILURE(65)digest.cL300-L305HMAC_Init_exwith a block size above the 128-byte keyEVP_R_BAD_BLOCK_LENGTH(136)hmac.cL88-L91HMAC_Init_exwith a negative key length on its current digestEVP_R_BAD_KEY_LENGTH(137)hmac.cL101-L104The values come from
evp.handerr.hat the same commit, which defines onlyOPENSSL_NO_DYNAMIC_ENGINE, so the ENGINE block that holds theEVP_R_NO_DIGEST_SETcheck is compiled.Each failure queues one code. Nested calls pass the inner failure on without adding another, as in LibreSSL: an allocation failure inside
HMAC_Init_exorHMACqueues oneERR_R_MALLOC_FAILURE. Paths where LibreSSL queues nothing still queue nothing:HMAC_Init_exchanging the digest without a key or with no digest at all,HMAC_UpdateandHMAC_Finalwithout a digest, andEVP_MD_CTX_create's failedcalloc. The ENGINE and null-context paths still throw.libSceLibreSsl3 forwards
EVP_MD_size,EVP_DigestInit_ex,EVP_DigestFinal_ex,EVP_Digest,HMAC_Init_ex,HMAC_FinalandHMACto these functions, and itsERR_get_error,ERR_peek_errorandERR_clear_errorread the same queue. LibreSSL 4.0.0 queues the same codes on these paths, with one exception: 4.0.0 has no ENGINE code, soEVP_DigestInit_ex(ctx, NULL, NULL)on an empty context dereferences the null digest there. The forwarded export keeps 2.5.4's return of 0 and now itsEVP_R_NO_DIGEST_SET.Callers: in
core/, the changed functions are called by the libSceLibreSsl3 forwarders, byHMACthroughHMAC_Init, byRSA_padding_add_PKCS1_PSSandRSA_verify_PKCS1_PSS, which boykopovar/AnyPS5#11175 merged after this PR was opened, and byEVP_DigestVerifyInitandEVP_DigestVerifyFinal, which boykopovar/AnyPS5#16719 merged on 2026-11-10.EVP_DigestVerifyFinalqueuedEVP_R_INPUT_NOT_INITIALIZEDitself after a failed context copy; the fourth merge ofmainremoves that, because the copy now queues it, and LibreSSL 2.5.4'sm_sigver.cL182-L183 returns -1 afterEVP_MD_CTX_copy_exwithout adding one. A failed digest data allocation inEVP_DigestVerifyInitand a failed digest data copy inEVP_DigestVerifyFinalnow queueERR_R_MALLOC_FAILURE, whichm_sigver.cL108-L109 passes on unchanged; a failed key context copy still queues nothing, as inEVP_PKEY_CTX_dupandpkey_rsa_init. With that, none of the callers adds an error after a failed call, as in LibreSSL, so no path queues a duplicate error. The PSS calls useEVP_MD_size,EVP_DigestInit_exandEVP_DigestFinal_exas LibreSSL 2.5.4'srsa_pss.c(L96-L98, L202-L204) andPKCS1_MGF1do, so a null digest there now queuesEVP_R_MESSAGE_DIGEST_IS_NULLand a digest above 64 bytesEVP_R_TOO_LARGE, the codes LibreSSL queues.Debt: the EVP digest and HMAC entry no longer lists failures that queue nothing, and the RSA PSS entry no longer says the EVP errors for a null or over-64-byte digest are missing. The "Error publication" entry names EVP cipher instead of EVP/HMAC among the implementations without error publication, because main's EVP cipher functions still queue no error. Main's
EVP_DigestVerifyInitandEVP_DigestVerifyFinalentry no longer lists the digest and copy malloc failures among the errors not queued.The branch has two commits,
EVP_MD_sizefirst and then the context and HMAC paths; two merges ofmain, which resolve debt-file conflicts next to the EC entry and then next to the RSA PSS entry; a test commit that makes the RSA PSS test require those EVP codes where it only checked that no RSA error was queued; a third merge ofmain, which resolves the debt-file conflict with the EC entries that boykopovar/AnyPS5#15827 reworded and added below the EVP entry; and a fourth merge ofmain, which resolves the include and debt-file conflicts with boykopovar/AnyPS5#16719, removes the duplicate error fromEVP_DigestVerifyFinaland makesguest_libressl_digest_verify_allocatorcheck the queue after each failed allocation.Overlap: no open PR shares an export or a new file with this one. In the debt file, six open PRs edit lines next to the three entries this branch changes, none of them the same entry, and a merge keeps both sides: boykopovar/AnyPS5#12729 and boykopovar/AnyPS5#12730 edit the
SSL_get_ex_new_indexentry above the RSA PSS entry; boykopovar/AnyPS5#11146 edits or moves the EC entry below the EVP entries; and boykopovar/AnyPS5#16694, boykopovar/AnyPS5#16717 and boykopovar/AnyPS5#16718 add an entry directly before "Error publication". boykopovar/AnyPS5#15827, which edited the EC entry and added one after it, merged on 2026-11-08, and boykopovar/AnyPS5#16719, which added theEVP_DigestVerifyandEVP_PKEY_CTXentries after the EVP entry, merged on 2026-11-10; the third and fourth merges ofmainkeep both sides. Five libSceLibreSsl3 PRs add calls to the changed functions; four of them have merged intomainsince, so the fourth merge includes them and their tests pass on it. boykopovar/AnyPS5#15622 (PBKDF2, merged) checks for a null digest itself and queues0x06fff09fbefore callingEVP_MD_size, and its failingHMAC_Init_excalls change the digest without a key or with a negative key length, which still queue nothing, so its empty-queue checks hold. boykopovar/AnyPS5#16535 (PBKDF2, merged) returns 0 whenEVP_MD_sizefails; for a null digest that call now queues0x06fff09f, as LibreSSL'sPKCS5_PBKDF2_HMACdoes, and its test does not read the queue. boykopovar/AnyPS5#16819 (HKDF, open) queuesERR_R_CRYPTO_LIBafter a failedHMAC, and its failingHMACcalls have no digest, or a negative key length on a new context, which still queue nothing, so its single-error checks hold. boykopovar/AnyPS5#15514 and boykopovar/AnyPS5#15625 (merged) call them only in tests that expect success, as does boykopovar/AnyPS5#16258.Tested
Windows 11 Pro 25H2 (build 26200.9711) with WSL2 Ubuntu 24.04.5 LTS, gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0,
-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON, full build of headf685673242(maine8b1bd3d7fmerged in). No title or console.ctest --test-dir build -R "libressl|libre_ssl|crypto_memcmp|digest_extents|^public_headers$": 93 of 93 pass. These are all tests whose executables link or load libSceLibreSsl or libSceLibreSsl3, pluspublic_headers.guest_libressl_evpasserts every code above withERR_get_errorand an empty queue afterwards, and that a non-nullEVP_MD_sizeandEVP_MD_CTX_create's failed allocation queue nothing.guest_libressl_rsa_pssnow requiresEVP_R_MESSAGE_DIGEST_IS_NULLalone for a null digest andEVP_R_TOO_LARGEalone for a 65-byte digest. Againstmain'sEvp.cppthey abort at lines 208 and 604.return Fail(...)back intoreturn 0failsguest_libressl_evpat that code's own assertion (Evp.cppline → test line: 307NoDigestSet→ 289, 318MallocFailure→ 396, 337TooLarge→ 327, 353InputNotInitialized→ 355, 369MallocFailure→ 422, 406BadBlockLength→ 353, 412BadKeyLength→ 342). TheTooLargeone also failsguest_libressl_rsa_pssat line 837, and leavingEVP_MD_size(NULL)without its error fails it at line 604.python3 tools/check_conventions.py --base origin/main: all conventions checks passed.tools/pr_overlap.py --branch claude/zealous-brown-h1u67r(2026-11-06): againstmaine8b1bd3d7fand the 1869 open PRs it reported seven adjacent debt-file conflicts and no shared exports or new files. It failed closed on 19 PRs that already conflict withmain; merging each of them intomainand into this branch gives the same conflicts.mainc06e4c075f(same compiler and options, test targets only): the filter above selects 100 tests and all pass, andmain'scheck_conventions.pypasses. With each of the five libSceLibreSsl3 PRs above merged on top as well, the filter and their new tests (guest_libressl3_pbkdf2,guest_libressl3_sha512_256,guest_libressl3_hkdf,guest_libressl3_hmac_context) pass; boykopovar/AnyPS5#16535 extendsguest_libressl3_digestinstead, and boykopovar/AnyPS5#15514 was built with its debt-file conflict withmainleft in place. Each of the eight debt-file neighbours conflicts with that merge only indocs/dev/debt/libSceLibreSsl.md.76432389fc(mainf5fe807353merged in; same compiler and options, test targets only): the filter above selects 107 tests and all pass, andcheck_conventions.py --base upstream/mainpasses. Against that head, the seven debt-file neighbours still conflict indocs/dev/debt/libSceLibreSsl.mdonly on adjacent lines, which a merge keeps from both sides, and the five libSceLibreSsl3 PRs conflict in the same files as they do withmain.9c1c7f233b(mainc5488026abmerged in; same compiler and options, test targets only): the filter above selects 128 tests and all pass, among themguest_libressl_digest_verify,guest_libressl_digest_verify_allocatorand the tests of the four merged libSceLibreSsl3 PRs above (guest_libressl3_pbkdf2,guest_libressl3_sha512_256,guest_libressl3_hmac_context,guest_libressl3_digest). Putting back boykopovar/AnyPS5#16719's ownEVP_R_INPUT_NOT_INITIALIZEDinEVP_DigestVerifyFinalfailsguest_libressl_digest_verifywith "a context without a digest queues the input not initialized error".check_conventions.py --base upstream/mainpasses, and the head merges cleanly withmainb8194198cf. Against that head, the six open debt-file neighbours conflict indocs/dev/debt/libSceLibreSsl.mdonly on adjacent lines, which a merge keeps from both sides, and boykopovar/AnyPS5#11146 and boykopovar/AnyPS5#16819 conflict in the same files as they do withmain.ANYPS5_LIBRESSL_ORACLEwas not run. The reference behaviour comes from the LibreSSL sources linked above.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