feat(libSceLibreSsl): implement RSA_flags and RSA_size #10449
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10449"
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 alvaroelpob on 2026-10-24T00:59:31Z.
What
Implements
RSA_flagsandRSA_sizein libSceLibreSsl, which threw and were declared without parameters.The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, layouts and results follow that release's
rsa.handrsa_crpt.c, withbn.handbn_lib.cfor the modulus:int RSA_flags(const RSA*)meth->flagsint RSA_size(const RSA*)BN_num_bytes(n): 0 whenn->topis 0, otherwise((top - 1) * 64 + bits(d[top - 1]) + 7) / 8The layouts are 152 bytes for
RSA(methat 16,nat 32,flagsat 108), 112 forRSA_METHOD(flagsat 72) and 24 forBIGNUM(d,top,dmax,neg,flags), checked withstatic_asserts. LikeBN_num_bits,RSA_sizereads the top word as it is: a zero top word left by a caller isn't skipped, and the sign is ignored.LibreSSL dereferences these without checking them, so these throw: a null method in
RSA_flags, and inRSA_sizea null key, a null modulus, or a positive word count with null words. A negative word count and a bit count that overflowsint, which are undefined there, throw too. No export of this module creates a key yet, so for now only keys built by the caller reach these functions.#9446 and #9571 also define the 2.5.4
BIGNUMlayout for theirBN_*exports. This PR only reads it, in its own file, and changes none of their exports.The debt entry records the source and what is unverified, and the pending-export count drops by 2 (342 to 340 on current
main).Tested
Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with
BUILD_TESTING=ONonmaine2b9700a9. There is one commit per function, and each adds that function with its test block and debt update. Each was built and itsguest_libressl_rsatest andcheck_conventions.pyrun on its own.guest_libressl_rsatest.RSA_flagsreturns 0 for a null key, and for a method it returns 0, a set flag and -1; a null method throws.RSA_sizegives 0 for a zero word count, even with null words, and 1, 1, 2 and 8 bytes for top words 1, 0xFF, 0x100 and 2^63. It gives 9 for two words and 256 for a 2048-bit modulus, unchanged when negative. A 16-word modulus with a 56-bit top word gives 127, and with a zero top word 120. A negative word count, null words, a null modulus and a null key throw. Onmainthe first call throws.ctest -j16at the last commit: 2003/2004 pass.agc_driver_multisample_retirementfails the same way onmainon this machine.main1e740a23a3(after #9033), head 3b76876201: the conflicts were only theadd_librarysource list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build andctest -j16: 2043/2044 pass;agc_driver_multisample_retirementfails the same way on thatmain.check_conventions.py --base upstream/mainpasses.maine7e3e9c198, head0bf45bf1b2, to resolve the conflict from #9529 on the sharedCMakeLists.txtand debt-file lines; both sides are kept and the count is 353 minus this PR's exports.0bf45bf1b2(refactor(libSceLibreSsl): declare the RSA exports in the public header) puts the real signatures and their structs inlibSceLibreSsl/include/Api.hppand drops the test's redeclarations, whichpublic_headersrequires since #10706. Full build andctest -j16: 2202/2203 pass;agc_driver_multisample_retirementfails the same way on thatmain.check_conventions.py --base upstream/mainpasses.mainae7d59258e(after #9949), heade44f645642, to resolve the conflicts withmainon the sharedCMakeLists.txtand debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build andctest -j16: 2275/2276 pass;agc_driver_multisample_retirementfails the same way on thatmain.guest_posix_spawn, a libc test, also failed once in that run and passed 5 of 5 runs on its own.check_conventions.py --base upstream/mainpasses.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)Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T00:59:39Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T01:24:49Z.
Review: DISMISSED
I compiled
Rsa.cppandGuestLibreSslRsa.cppdirectly from exact head7b78f0e069e4f4f02d97bcf14074371b5458d57ewith GCC 12/C++20 and ran the test executable;libSceLibreSsl RSA tests passed. The implementation'sRSA_flagsnull-key behavior andRSA_sizedelegation to the modulus byte count match the pinned LibreSSL 2.5.4 sources cited in the PR. The regression cases cover zero and high-word boundaries, sign handling, layouts, and invalid pointers/counts.I am requesting an update before approval because the repository's current-main check reports this branch is 2 commits ahead and 19 behind
upstream/main(merge basee2b9700a9), although the merge is clean. Please refresh it against currentmainwhen its declared dependencies permit, then rerun the focused RSA test and conventions check on the refreshed exact head. This is the branch-sync requirement; I found no behavior issue in the reviewed change.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-26T05:57:55Z.
Review: APPROVED
Reviewed head
e44f645642d8merged onto currentmain14c99b52ace3(clean merge; PR baseae7d59258ea7, andmainhasn't touchedlibSceLibreSslsince then). Ubuntu 24.04 on WSL2, GCC 13.3, Release, focused build. This is the rerun MarcZX10 asked for, on the refreshed head.What I ran:
guest_libressl_rsa: passes, 5 of 5 runs. The other builtguest_libressl_*tests (digest, des, runtime, aes, error, ocsp, cipher) pass too.public_headersand all 64public_headers_compile_*: 65/65 pass, so the newApi.hppdeclarations compile on their own.check_conventions.py --base origin/main: passes.main'sApi.hpp('LibreSslRsa' does not name a type,RSA_flags_nid_postfix()takes no arguments).Rsa.cpp, each one fails the test: readingrsa->flagsinstead ofmeth->flags, dropping the+ 7round-up, throwing on a null key inRSA_flags, skipping a zero top word, and readingdwhentopis 0.Sources, LibreSSL 2.5.4 at
2e2c6120:rsa_crpt.c:RSA_sizeisBN_num_bytes(r->n)andRSA_flagsisr == NULL ? 0 : r->meth->flags. Matches.bn_lib.cBN_num_bits: returns 0 fortop == 0before it readsd, else(top - 1) * 64 + BN_num_bits_word(d[top - 1]), so a zero top word isn't skipped. Matches, and the 127/120 cases cover it.rsa.h: on LP64rsa_sthasmethat 16,nat 32,flagsat 108, size 152 (CRYPTO_EX_DATAis a single pointer in LibreSSL'scrypto.h).rsa_meth_sthasflagsat 72, size 112.LibreSslRsaandLibreSslRsaMethodinApi.hppmatch field by field, andbignum_stis 24 bytes with a 64-bitBN_ULONG.NotImplemented_nid_no_patchstubs left inExport.cppon the merged tree, same as the debt file.One nit: the What section of the body still says the count drops "from 357 to 355"; the diff and the last Tested bullet have 342 -> 340.
Not checked: Windows, and anything on a console (the debt entry already says so).