feat(libSceLibreSsl): implement RSA_generate_key_ex #18396
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18396"
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 SHOnnay on 2026-11-11T13:23:18Z.
What
Implements
RSA_generate_key_exin libSceLibreSsl. It is a port of the library's pinned LibreSSL 2.5.4 sources:BN_generate_prime_ex,probable_prime)bn_rand.cBehaviour, as in 2.5.4:
rsa_keygenslot is called when set; otherwise missing components are created withBN_new.BN_prime_checks_for_sizeMiller-Rabin rounds.KEY_SIZE_TOO_SMALLis raised after three equal primes.p > qis enforced by swapping, then d mod (p-1)(q-1), dmp1, dmq1 and iqmp are computed.Implementation.
BIGNUMlayout (written throughBN_bin2bn) and its ErrorQueue with the 2.5.4 reason codes.src/RsaKeygen.cpp. The stub is removed fromExport.cpp, and theinclude/Api.hppdeclaration gets the real signature(LibreSslRsa*, int, Bignum*, void*).Still throws (recorded in
docs/dev/debt/libSceLibreSsl.md):BN_GENCBThe debt file also records that Miller-Rabin uses mbedtls with host entropy instead of LibreSSL's own code.
Tested
macOS 27 on Apple M1. The registered
GuestLibreSslRsatest is a full-build test and was not run: the full build does not run on macOS. A Linux or Windows run is needed.New test.
TestGenerateKeyincore/libs/tests/GuestLibreSslRsa.cpp. The test now also linksmbedcrypto, to check results independently. It covers:KEY_SIZE_TOO_SMALLfor an 18-bit requestHarness. A temporary host harness, not committed, built the unchanged
RsaKeygen.cpp,Bignum.cpp,Rsa.cpp,Error.cppandErrorQueue.cppagainst a host-built mbedtls 3.6.7, with the test code copied verbatim. It passed 8 of 8 repeated runs on x86-64 under Rosetta and on arm64.Mutation check. All 6 hand mutations failed the harness: wrong phi, weakened sieve, wrong error reason, e not stored, wrong top bits, dropped callback.
Syntax.
clang++ -arch x86_64 -fsyntax-onlypasses onRsaKeygen.cpp,Export.cppand the test file.Overlap. No open PR implements this export.
pr_overlap.pyfailed closed with 33 unconfirmed PRs. All their diffs were grepped.RSA_generate_key_exonly as unchanged stub context.NOsUmPti3g4already forwards to this export. Whether 4.0.0 RSA objects match the 2.5.4 layout was unverified before this change and remains so.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-11T14:50:40Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
639ab6150a:tools/check_conventions.pyfailed;git diff --checkclean.guest_libressl_rsa_testsbuilt cleanly.guest_libressl_rsa_private,guest_libressl_rsa_pss,guest_libressl_rsa):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:43:17Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
639ab6150a:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl_rsa_testsbuilt cleanly.guest_libressl_rsa_private,guest_libressl_rsa_pss,guest_libressl_rsa):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/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.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T19:45:33Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
95a5beaf8b:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl_rsa_testsbuilt cleanly.guest_libressl_rsa_private,guest_libressl_rsa_sign_errors,guest_libressl_rsa_pss,guest_libressl_rsa):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/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.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T21:04:49Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e46d9f581b:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl_rsa_testsbuilt cleanly.guest_libressl_rsa_private,guest_libressl_rsa_sign_errors,guest_libressl_rsa_pss,guest_libressl_rsa):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Store(rsa.e, exponent, function);ignores the boolean return value ofStore(). Unlike every other BIGNUM field (rsa.p,rsa.q,rsa.n,rsa.d,rsa.dmp1,rsa.dmq1,rsa.iqmp), which checksif (!Store(...)) return fail();, ifrsa->eis pre-populated with a BIGNUM that cannot expand (e.g.,BN_FLG_STATIC_DATA) orBN_bin2bn_nid_postfixfails,Store(rsa.e, ...)returnsfalseand the failure is silently ignored.BuiltinKeygenthen proceeds to generate primes and returns1(success) withrsa->eleft unmodified/invalid instead of callingfail()to queue theERR_LIB_RSA/ERR_LIB_BNerror and return0.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T09:16:09Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
63804d8804:tools/check_conventions.pypassed.guest_libressl_rsa_testsbuilt cleanly.guest_libressl_rsa):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/src/RsaKeygen.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Store(rsa.e, exponent, function);ignores the boolean return value ofStore(). Ifrsa.eis pre-populated with a static/non-expandable BIGNUM (such as one withBN_FLG_STATIC_DATA) orBN_bin2bn_nid_postfixfails,Storereturnsfalse, but execution proceeds, generating primes and returning1(success) withrsa.einvalid or unmodified instead of callingif (!Store(rsa.e, exponent, function)) return fail();to pushERR_LIB_RSA/ERR_LIB_BNto the error queue and return0.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T17:05:32Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ca35c34749:tools/check_conventions.pypassed.guest_libressl_rsa_testsbuilt cleanly.guest_libressl_rsa):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/src/RsaKeygen.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me