feat(libSceLibreSsl3): implement EVP_PKEY_CTX RSA encryption, signing and verification #17528
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17528"
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 MarrasFederico on 2026-11-08T20:27:54Z.
What
Real RSA public-key encryption, signing and verification through
EVP_PKEY_CTXin libSceLibreSsl3. It is built on the module's native 32-byteEVP_PKEYand 152-byteRSAobjects, with mbedTLS doing the big-number work. Behaviour, return values and error-queue codes follow LibreSSL 4.0.0:evp/pmeth_lib.c,evp/pmeth_fn.c,evp/m_sigver.c,evp/p_sign.c,evp/p_verify.c,rsa/rsa_pmeth.c,rsa/rsa_eay.c,rsa/rsa_pk1.c,rsa/rsa_oaep.c,rsa/rsa_sign.c,rsa/rsa_pss.c,rsa/rsa_chk.candrsa/rsa_lib.c.Implemented exports:
EVP_PKEY_CTX_newandEVP_PKEY_CTX_free, with a native RSA / RSA-PSS key method and ASN.1 method;EVP_PKEY_CTX_ctrlandRSA_pkey_ctx_ctrl, covering padding, signature digest, PSS salt length, MGF1 digest, OAEP digest and label, and the matching getters.EVP_PKEY_encrypt_init,EVP_PKEY_encrypt,EVP_PKEY_decrypt_initandEVP_PKEY_decrypt, with PKCS#1 v1.5, OAEP and no padding, theout == NULLlength query and too-small buffers.EVP_PKEY_sign_init,EVP_PKEY_sign,EVP_PKEY_verify_initandEVP_PKEY_verify, with PKCS#1 v1.5 (DigestInfo), PSS (salt length digest/auto/max/fixed, separate MGF1 digest) and raw signatures;EVP_DigestSignInitandEVP_DigestSignFinal(with the key's default SHA-256 digest when none is given),EVP_SignFinalandEVP_VerifyFinal, which finalize a copy of the digest context as LibreSSL does;RSA_padding_add_PKCS1_PSS_mgf1.RSA_check_key;RSA_new(_nid_disambig1).Native RSA keys are freed through the ASN.1 key-free callback in
EVP_PKEY_free, andEVP_MD_CTX_freereleases a nativeEVP_PKEY_CTXattached byEVP_DigestSignInit.The following keep throwing
NotImplemented_nid_no_patchand are listed in the technical debt:EVP_DigestSignInit.EVP_DigestVerifyInitandEVP_DigestVerifyFinalare still forwarded to the parent module: #17299 and #17303 are editing those forwarders. The overlapping null-only PR #16690 is closed. Key decoding (DER/PEM/PKCS#8) is not part of this PR.Tested
Ubuntu 26.04.1 LTS, kernel 7.0.0-43-generic, GCC 15.2.0, Release,
BUILD_TESTING=ON, CMake 4.4.4 with Ninja 1.13 from a virtualenv. Mergedupstream/maininto the published head56af0fba3awith normal merge commits7285751da1(main3b7f31fa70) and then622487a245(main714de16abf); the published history was not rebased, squashed or force-pushed. On top of the merges the branch adds local commit(s):702707574e(fix(libSceLibreSsl3): keep RSA pkey helpers distinct from libSceLibreSsl). Final head:82fd15af14(full82fd15af1431b18df84bd7c2f151f24a6c6b83cd). The final commit corrects only the inventory summary; executable sources are identical to tested head93d05b3c3c. Windows and macOS were not compiled here; no game title was run.On the merged head, built the 7
guest_libressl3_pkey*test executables (includingguest_libressl3_pkey_bits, whose executable target isguest_libressl3_key_reference_tests) and ranctest -R '^guest_libressl3_pkey' --output-on-failure --repeat until-fail:3: 100% tests passed out of 7, 3 runs each,Not Run= 0 (exit 0).On the pre-merge head, the whole module was built (
core/libs/prx/libSceLibreSsl3/allplus every libSceLibreSsl3 test executable) andctest -R libressl3passed 100% of 42 tests.Absorbing
main(which merged #17138) pulled in three helpers thatlibSceLibreSsl/src/DigestVerify.cppalready exports under the same names, so they would have been real duplicate exports between the two modules; commit702707574erenames our internal copies toPkeyRsaVerify,PkeyRsaContextCopyandPkeyRsaControl(used only insidesrc/PkeyContext.cpp). Verified afterwards: one definition per library for both name sets, and the inventory summary is corrected to match 68 throwing AdditionalExports.cpp definitions and 68 table rows: 64 named and 4 known only by NID.python3 tools/check_conventions.py --base upstream/main: "All conventions checks passed" (exit 0, 0 errors).Windows: the run reported earlier by JJenkx (Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT,
guest_libressl3_pkey_context3 of 3) is on head95a512a39b, not on this merged head; the hosted Windows check was not re-run here.guest_libressl3_pkey_contextuses a fixed 2048-bit key. For encryption it covers:For signatures it covers:
cryptographyoutput for the same key and digest, also when the key has only CRT components;cryptography, with automatic, digest-length and fixed salt lengths;RSA_padding_add_PKCS1_PSS_mgf1blocks that verify after a raw private operation;EVP_DigestSignInit/Final,EVP_SignFinalandEVP_VerifyFinalon a streamed message.Error and lifecycle checks:
RSA_check_keyis tested on valid keys, a missing component, an alteredd, an alterediqmpand a compositep;Negative controls:
While wiring signatures I found that the private-key encryption and public-key decryption helpers added in the first commit used PKCS#1 block type 2. LibreSSL
rsa_eay.cuses block type 1 there and rejects OAEP; they now do the same.ctest -R '^guest_libressl3_(pkey|rsa|key_reference|evp)' --output-on-failure --repeat until-fail:3: 100% tests passed out of 12, 3 runs each,Not Run= 0 (exit 0).Upstream
decf2615a3 feat(libSceLibreSsl3): implement X509_get0_pubkeywas absorbed by the merge: the parameterless placeholder inAdditionalExports.cppis gone, and the implementation, declaration and tests come from upstream only (no duplicate definition).python3 tools/check_conventions.py --base upstream/main: "All conventions checks passed" (exit 0, 0 errors).Publication checks: head
82fd15af1431b18df84bd7c2f151f24a6c6b83cdpassed an independent conventions/diff check and a clean merge-tree check against upstream mainfa289273974bb03ffcf6c6432f0b15a2cb65f46d. Linux execution results above come from the recorded verification runs, reviewed rather than rerun during publication.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)