feat(libSceLibreSsl3): implement EC_POINT_get/set_affine_coordinates_GFp #17622
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17622"
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 GalaxyGamingFR on 2026-11-09T03:36:14Z.
What
Implement
EC_POINT_get_affine_coordinates_GFpandEC_POINT_set_affine_coordinates_GFpinlibSceLibreSsl3, replacing their parameterless throwing placeholders inAdditionalExports.cpp.ce488b78, the revision the library's debt file already uses. Inec_lib.cboth_GFpnames forward toEC_POINT_{get,set}_affine_coordinates, which reject a group/point method mismatch withEC_R_INCOMPATIBLE_OBJECTS. Inecp_smpl.cthe getter returns 0 withEC_R_POINT_AT_INFINITYfor the point at infinity and writes only the non-NULLx/y. The setter returns 0 withERR_R_PASSED_NULL_PARAMETERifxoryis NULL, sets the point throughEC_POINT_set_Jprojective_coordinateswith Z = 1, and returns 0 withEC_R_POINT_IS_NOT_ON_CURVEif the result is not on the curve. The point keeps the rejected coordinates in that case. Each coordinate goes throughec_encode_scalar, which reduces it withBN_nnmod(x, p).src/EcPointCoordinates.cppdoes not touch the layout ofEcPoint/EcGroupand does not includeEc.hpp. It only calls libSceLibreSsl's exportedEC_POINT_point2oct,EC_POINT_oct2point,EC_GROUP_get_degree,BN_bin2bn,BN_bn2binandBN_num_bits. The getter encodes the point uncompressed. A one-byte encoding (infinity) returns 0 and leaves the outputs unchanged. Otherwise it loads the X and Y halves into the non-null outputs. The setter builds0x04 || X || Y, with each coordinate right-aligned in(degree + 7) / 8bytes, and decodes it into the point. libSceLibreSsl'soct2pointrejects a coordinate of at least p and runsmbedtls_ecp_check_pubkey, so an off-curve pair returns 0. Like upstream, the point then holds the rejected coordinates.Api.hppnow declares them with LibreSSL's parameters.BIGNUMandBN_CTXare libSceLibreSsl'sBignumandBignumContext, asBN_*are forwarded to the parent andECDSA_SIG_set0andBN_divalready use them. The localLibreSsl3Bignumis only used by the RSA setters. The context is accepted and unused.Gaps, recorded in
docs/dev/debt/libSceLibreSsl3.md:BN_bn2bindrops the sign), or one of at least p, returns 0. LibreSSL reduces it modulo p first and may accept it. No libSceLibreSsl export gives p (only the degree), so this cannot be matched without reaching intoEcGroup. A coordinate wider than the degree is caught before encoding.NotImplemented_nid_no_patch) through libSceLibreSsl's same-curve check, like the other point functions. LibreSSL only compares the method, which all prime curves share.The export inventory is updated (112 exports, 103 named).
No title's trace or disassembly was used, and the exports were not measured on a PS5.
Tested
Windows 11, WinLibs GCC 15.2.0 UCRT. This is not a full CMake build. I compiled the new
tests/EcPointCoordinates.cppinto one executable withsrc/EcPointCoordinates.cpp, libSceLibreSsl'sEc.cppandBignum.cpp, and the3rdparty/mbedtlslibrary sources.APS5_VABIwas defined empty, and I added a stand-in shim:NotImplementedAt_nid_no_patchthrows,HostEntropy_nid_no_patchis seeded for key generation, andApplicationHeapRegister_nid_no_patch/calloc_nid_postfix/free_nid_postfixroute to the registered allocator and abort if none is registered. No title or homebrew, and not built on Linux or macOS.The test passes. Since
BN_newallocates from the application heap, it registers a counting heap astests/BignumDivide.cppdoes. On P-256 (NID 415) it checks the following:0x04 || Gx || GyxNULL,yNULL or bothx, NULLyor both return 0 and leave the point unchangedFor NIDs 409, 415, 715 and 716 it reads the coordinates of eight generated public keys each. It checks that they match the key's uncompressed encoding (P-521 covers coordinates shorter than the field). It sets them into a point of a separate group, checks the encoding, and reads them back. Every block allocated on the heap is freed at the end.
Three deliberate bugs make the test fail: dropping the negative-coordinate check (line 153), accepting the one-byte infinity encoding in the getter (line 160), and not registering the heap ("application heap: process metadata is missing").
-Wall -Wextrais clean for the new files.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Just before opening this, I searched open and merged pull requests for
affine_coordinatesand found none. This PR is independent of #17621 (EC_POINT_dup): it uses a separate source file, and its CMake lines go in other places. Both PRs change the export inventory count line in the debt file, as do #16586, #16588, #16589, #16848 and #16918, so whichever lands later needs a one-line rebase.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 MarcZX10 on 2026-11-18T07:32:07Z.
Review: APPROVED
Reviewed — looks good
The implementation and added test cover the described coordinate conversion behavior; review is limited to the changed files and targeted EC/BIGNUM helper code at head
590f1836798b6fe3775af20e4be35d9cbe7fd578.What I ran
No commands or tests were run. I read the prepared diff and the changed files, then inspected the forwarded EC and BIGNUM helper implementations.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build or test was run during this review. The author's Windows test report was not independently verified. Console ABI and behavior remain unverified. Related code read:
core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/src/Ec.cpp, andcore/libs/prx/libSceLibreSsl/src/Bignum.cpp.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.