fix(libSceLibreSsl): report BN_R_NO_INVERSE from BN_mod_inverse #16741
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16741"
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 AlexWhitehouse on 2026-11-07T14:20:42Z.
What
In libSceLibreSsl (the older LibreSSL module),
BN_mod_inverse(NIDGz+I4uxmv7M) returned null when the operand has no inverse, but left the error queue empty. Onmain,BN_mod_inverse(nullptr, 2, 4, ctx)returns null andERR_get_error()returns 0.LibreSSL 2.5.4's
bn_gcd.c, the version the module's other BIGNUM functions follow, handles this case as follows:|n|(A = n; A->neg = 0);BNerror(BN_R_NO_INVERSE)and returns null, leaving a caller-supplied result untouched. The constant-time variant does the same at lines 701–722.err.h,BNerroruses libraryERR_LIB_BN(3, line 160) and function 0xfff (line 241).bn.hdefinesBN_R_NO_INVERSEas 108 (line 705).When
InverseModfinds no inverse,BN_mod_inverseincore/libs/prx/libSceLibreSsl/src/Bignum.cppnow queues that error through the module's existingLibreSslPutError_nid_no_patch, soERR_get_error()returns0x03fff06c. That applies to a nonzero modulus of either sign. Other paths are unchanged:A new debt entry records that this is not measured on the console, and that other BIGNUM error paths still queue nothing.
Tested
guest_libressl_bn(core/libs/tests/GuestLibreSslBn.cpp) already checked that(4, 8)has no inverse. It now also checks:0x03fff06c, after which the queue is empty;(2, 4),(6, 9),(0, 11),(2, -4)and(-6, -9), each with and without a caller-supplied result, whose value must stay unchanged;Every existing assertion is kept.
Linux x86-64 (Ubuntu 26.04, GCC 15, Release), the libSceLibreSsl tests:
main'sBignum.cpp,guest_libressl_bnfails at its first error-queue check (check failed at line 212);Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):
main'sBignum.cpp,guest_libressl_bnfails at the same check.Mutation checks:
python3 tools/check_conventions.py --base origin/main: all conventions checks passed.python3 tools/pr_overlap.py --branch fix/libscelibressl-bn-mod-inverse-error: no open PR changesBN_mod_inverse.main. Trial merges of each add no conflict beyond the ones they already have withmain: #10508, #11466, #13266, #13285, #13546, #13547, #13877, #14115, #14212, #15480, #15737, #15994, #16241, #16242, #16249, #16255, #16529 and #16543.EVP_DecryptFinal_exerrors) touches the same debt file in a different entry.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 gabichuuuuu on 2026-11-09T08:52:41Z.
Review: COMMENTED
Windows run of head
4a05e40a2d, merged ontomain286b14d2f7in one tree with 7 other small open PRs that touch different files. Setup: Windows 11, WinLibs GCC 15.2 r7 (x86_64-ucrt-posix-seh, the CI toolchain), Release,BUILD_TESTING=ON.guest_libressl_bnwith--repeat until-fail:5: 5 / 5 pass.main'sBignum.cppand this PR's test: 5 / 5 runs fail.