feat(libSceLibreSsl3): implement o2i_ECPublicKey #18946
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18946"
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 MatteoSid on 2026-11-12T15:16:50Z.
What
Implements
o2i_ECPublicKeyin libSceLibreSsl3 (NIDOpC9gfPLl5g), following LibreSSL 4.0.0'so2i_ECPublicKey:ECERR_R_PASSED_NULL_PARAMETERand returns null;EC_POINT_new; if that fails it queuesERR_R_MALLOC_FAILUREand returns null;EC_POINT_oct2point. On failure it queuesERR_R_EC_LIBand returns null, leaving*inand the conversion form unchanged, and the newly created point stays on the key, as upstream. An off-curve uncompressed or hybrid point still overwrites the key's existing point, as LibreSSL'sEC_POINT_set_affine_coordinatesstores the coordinates before its on-curve check; every earlier rejection leaves it unchanged;*inadvances bylenand the key is returned. An existing public point is reused, not replaced.The key, group and point are libSceLibreSsl's (
EC_KEY_new_by_curve_name,EC_POINT_new,EC_POINT_oct2pointinlibSceLibreSsl/src/Ec.cpp), which share the 64-byte LibreSSLEC_KEYlayout already used byEC_KEY_set_asn1_flagandEC_KEY_up_ref. A nullinthrowsinvalid_argumentinstead of faulting.src/EcAsn1.cppfollows the control flow ofec_asn1.c, so it carries that file's notice.Gaps, in a new debt entry: a failed decode queues only
ERR_R_EC_LIB, because libSceLibreSsl'sEC_POINT_oct2pointqueues no reason of its own where LibreSSL first queues the decoder's (such asEC_R_INVALID_ENCODING); a compressed point on a curve whose prime is not 3 mod 4 (secp224r1, secp224k1) throws in that function; nothing is checked on the console.Export.cppgoes from 36 to 35NotImplemented_nid_no_patchstubs.d2i_ECParametersis not included: it needs a DER decoder forECPKParameterswith the ASN.1 error queue, which is larger than this change.Tested
Linux (Ubuntu 24.04 container, GCC 13.3), configure with
-DBUILD_TESTING=ON, Release, on headd4a8574a32based onmain5e7ec34f68: built every LibreSSL test target and the patched.prxfiles.ctest -R 'libressl|libre_ssl|crypto_memcmp|public_headers'passes 212 of 212.Windows: JJenkx ran
guest_libressl3_ec_public_keyon headd4a8574a32merged ontomain(Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped (comment).The new
guest_libressl3_ec_public_keyuses the public keys of RFC 6979 A.2.5 (P-256) and A.2.6 (P-384), cross-checked with Pythoncryptography46.0.2, and checks:*inadvances by exactlyleninside a longer buffer, the conversion form is 4, 2 or 6, the point re-encodes to the RFC's uncompressed point,EC_KEY_check_keyreturns 1 and the error queue stays empty;0x10fff043, create no point, leave the form and*inunchanged;0x10fff010, leave*inand the conversion form unchanged, and leave the key's existing point at the RFC point; an off-curve uncompressed or hybrid point does the same but leaves its own coordinates in that point, re-encoded byte for byte, and a point created for the attempt stays on the key;inthrows without creating a point.Every one of these mutations makes the test fail: keeping the low bit in the conversion form, not advancing
*in, storing the form before decoding,ERR_R_MALLOC_FAILUREinstead of either queued reason, no error on a decode failure, no group check, no point created, a new point on every call, and decoding uncompressed points into a temporary in libSceLibreSsl'sEC_POINT_oct2point.nm -Don the patchedlibSceLibreSsl3.prxlistsOpC9gfPLl5g.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchfinds no overlap with the open PRs it could compare. The 25 that share files and conflict withmainwere checked by hand, and none changeso2i_ECPublicKey: none has a hunk next to itsExport.cppstub,Api.hppdeclaration or the newCMakeLists.txtblock (placed after the RSA setters block, away from the end of the file where several open PRs append), and only #14212, which adds a blank line between all debt entries, has the neighbouring debt entry as context. No title tested.The second commit,
d4a8574a32, follows MarcZX10's review: it adds the point checks after each rejection and states the overwrite in the debt entry (937 characters). The code is unchanged.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)CMakeLists.txtblock at the same place, and rebased onto it if #19024 merges first (comment)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T15:21:01Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
Head reviewed:
30cbfaec6646d60cbc15829e62bbeac0f2612301(PR #18946, basemain).What I ran
Read-only checks against the pinned head, with the repository reader (
repo_read.py). No build, no tests.Results
ctestcheck_conventions.py,pr_overlap.pyFindings
Blocking
None.
Non-blocking
core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp:94— when the key already has a public point, a failed uncompressed or hybrid decode leaves that point changed.EC_POINT_oct2pointwrites intopoint->point(core/libs/prx/libSceLibreSsl/src/Ec.cpp:584) and only then checks it is on the curve (Ec.cpp:585), so the rejected coordinates stay on the key. The compressed branch decodes into a temporary and copies only on success (Ec.cpp:573-576). The description says the existing point is "reused, not replaced" and does not say its value survives a failed call.core/libs/prx/libSceLibreSsl3/tests/EcPublicKey.cpp:147checks only that the point is non-null after rejections, so the tests would not catch this. Either decode into a temporary and copy on success, or add a test that the point's bytes are unchanged after a rejected decode and name the behaviour in the debt entry.Sources
EC_POINT_oct2point_nid_postfixo2i_ECPublicKey_nid_postfixNot verified
ctestrun (212 of 212 on the stated head), and thecheck_conventions.pyandpr_overlap.pyruns are the author's report. I did not run them.cryptographycross-check were not checked.EcAsn1.cpp(16, 65, 67) were not checked against the LibreSSL headers.docs/dev/debt/libSceLibreSsl3.mdat head found no "Silent" text, so that placement is not verified.EcAsn1.cppmatches the notice headers already inAes.cpp,Key.cppandStack.cpp. The rule inCONTRIBUTING.mdwas not read.files.jsonunderreviewed(CMakeLists.txt,Export.cpp,include/Api.hpp,src/EcAsn1.cpp,tests/EcPublicKey.cpp,docs/dev/debt/libSceLibreSsl3.md). Outside the hunks, onlyEcAsn1.cppand the test file were read in full, since both are new files. Thefiles/folder was not read. Test helpers (EC_POINT_point2oct,ERR_clear_error) and the CMake link list were not compared with other targets.To get this to a good state
Nothing is required. The non-blocking point above is optional.