feat(libSceLibreSsl3): implement EC_POINT_get/set_affine_coordinates_GFp #17622

Open
GalaxyGamingFR wants to merge 2 commits from upstream-pr/17622 into main
GalaxyGamingFR commented 2026-11-09 03:36:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GalaxyGamingFR on 2026-11-09T03:36:14Z.


What

Implement EC_POINT_get_affine_coordinates_GFp and EC_POINT_set_affine_coordinates_GFp in libSceLibreSsl3, replacing their parameterless throwing placeholders in AdditionalExports.cpp.

  • Source: LibreSSL 4.0.0 at ce488b78, the revision the library's debt file already uses. In ec_lib.c both _GFp names forward to EC_POINT_{get,set}_affine_coordinates, which reject a group/point method mismatch with EC_R_INCOMPATIBLE_OBJECTS. In ecp_smpl.c the getter returns 0 with EC_R_POINT_AT_INFINITY for the point at infinity and writes only the non-NULL x/y. The setter returns 0 with ERR_R_PASSED_NULL_PARAMETER if x or y is NULL, sets the point through EC_POINT_set_Jprojective_coordinates with Z = 1, and returns 0 with EC_R_POINT_IS_NOT_ON_CURVE if the result is not on the curve. The point keeps the rejected coordinates in that case. Each coordinate goes through ec_encode_scalar, which reduces it with BN_nnmod(x, p).
  • The new src/EcPointCoordinates.cpp does not touch the layout of EcPoint/EcGroup and does not include Ec.hpp. It only calls libSceLibreSsl's exported EC_POINT_point2oct, EC_POINT_oct2point, EC_GROUP_get_degree, BN_bin2bn, BN_bn2bin and BN_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 builds 0x04 || X || Y, with each coordinate right-aligned in (degree + 7) / 8 bytes, and decodes it into the point. libSceLibreSsl's oct2point rejects a coordinate of at least p and runs mbedtls_ecp_check_pubkey, so an off-curve pair returns 0. Like upstream, the point then holds the rejected coordinates.
  • Api.hpp now declares them with LibreSSL's parameters. BIGNUM and BN_CTX are libSceLibreSsl's Bignum and BignumContext, as BN_* are forwarded to the parent and ECDSA_SIG_set0 and BN_div already use them. The local LibreSsl3Bignum is only used by the RSA setters. The context is accepted and unused.

Gaps, recorded in docs/dev/debt/libSceLibreSsl3.md:

  • A negative coordinate (BN_bn2bin drops 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 into EcGroup. A coordinate wider than the degree is caught before encoding.
  • No error code is queued.
  • A point of another curve than the group throws (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.cpp into one executable with src/EcPointCoordinates.cpp, libSceLibreSsl's Ec.cpp and Bignum.cpp, and the 3rdparty/mbedtls library sources. APS5_VABI was defined empty, and I added a stand-in shim: NotImplementedAt_nid_no_patch throws, HostEntropy_nid_no_patch is seeded for key generation, and ApplicationHeapRegister_nid_no_patch/calloc_nid_postfix/free_nid_postfix route 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_new allocates from the application heap, it registers a counting heap as tests/BignumDivide.cpp does. On P-256 (NID 415) it checks the following:

    • setting the known generator coordinates encodes to 0x04 || Gx || Gy
    • the getter returns Gx/Gy (overwriting a prior value) with or without a context, and with x NULL, y NULL or both
    • NULL x, NULL y or both return 0 and leave the point unchanged
    • Gy + 1, x = p, y = p, a 33-byte x and a negative y each return 0
    • the getter returns 0 at infinity and leaves both outputs unchanged

    For 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 -Wextra is clean for the new files. python tools/check_conventions.py --base origin/main and git diff --check pass.

Just before opening this, I searched open and merged pull requests for affine_coordinates and 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5218300634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17622). Originally posted by [GalaxyGamingFR](https://github.com/GalaxyGamingFR) on 2026-11-09T03:36:14Z. --- ### What Implement `EC_POINT_get_affine_coordinates_GFp` and `EC_POINT_set_affine_coordinates_GFp` in `libSceLibreSsl3`, replacing their parameterless throwing placeholders in `AdditionalExports.cpp`. - Source: LibreSSL 4.0.0 at `ce488b78`, the revision the library's debt file already uses. In [`ec_lib.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ec_lib.c#L862-L944) both `_GFp` names forward to `EC_POINT_{get,set}_affine_coordinates`, which reject a group/point method mismatch with `EC_R_INCOMPATIBLE_OBJECTS`. In [`ecp_smpl.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ecp_smpl.c#L372-L470) the getter returns 0 with `EC_R_POINT_AT_INFINITY` for the point at infinity and writes only the non-NULL `x`/`y`. The setter returns 0 with `ERR_R_PASSED_NULL_PARAMETER` if `x` or `y` is NULL, sets the point through `EC_POINT_set_Jprojective_coordinates` with Z = 1, and returns 0 with `EC_R_POINT_IS_NOT_ON_CURVE` if the result is not on the curve. The point keeps the rejected coordinates in that case. Each coordinate goes through [`ec_encode_scalar`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ecp_smpl.c#L129-L139), which reduces it with `BN_nnmod(x, p)`. - The new `src/EcPointCoordinates.cpp` does not touch the layout of `EcPoint`/`EcGroup` and does not include `Ec.hpp`. It only calls libSceLibreSsl's exported `EC_POINT_point2oct`, `EC_POINT_oct2point`, `EC_GROUP_get_degree`, `BN_bin2bn`, `BN_bn2bin` and `BN_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 builds `0x04 || X || Y`, with each coordinate right-aligned in `(degree + 7) / 8` bytes, and decodes it into the point. libSceLibreSsl's `oct2point` rejects a coordinate of at least p and runs `mbedtls_ecp_check_pubkey`, so an off-curve pair returns 0. Like upstream, the point then holds the rejected coordinates. - `Api.hpp` now declares them with LibreSSL's parameters. `BIGNUM` and `BN_CTX` are libSceLibreSsl's `Bignum` and `BignumContext`, as `BN_*` are forwarded to the parent and `ECDSA_SIG_set0` and `BN_div` already use them. The local `LibreSsl3Bignum` is only used by the RSA setters. The context is accepted and unused. Gaps, recorded in `docs/dev/debt/libSceLibreSsl3.md`: - A negative coordinate (`BN_bn2bin` drops 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 into `EcGroup`. A coordinate wider than the degree is caught before encoding. - No error code is queued. - A point of another curve than the group throws (`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.cpp` into one executable with `src/EcPointCoordinates.cpp`, libSceLibreSsl's `Ec.cpp` and `Bignum.cpp`, and the `3rdparty/mbedtls` library sources. `APS5_VABI` was defined empty, and I added a stand-in shim: `NotImplementedAt_nid_no_patch` throws, `HostEntropy_nid_no_patch` is seeded for key generation, and `ApplicationHeapRegister_nid_no_patch`/`calloc_nid_postfix`/`free_nid_postfix` route 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_new` allocates from the application heap, it registers a counting heap as `tests/BignumDivide.cpp` does. On P-256 (NID 415) it checks the following: - setting the known generator coordinates encodes to `0x04 || Gx || Gy` - the getter returns Gx/Gy (overwriting a prior value) with or without a context, and with `x` NULL, `y` NULL or both - NULL `x`, NULL `y` or both return 0 and leave the point unchanged - Gy + 1, x = p, y = p, a 33-byte x and a negative y each return 0 - the getter returns 0 at infinity and leaves both outputs unchanged For 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 -Wextra` is clean for the new files. `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. Just before opening this, I searched open and merged pull requests for `affine_coordinates` and 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-18 07:32:07 +00:00 (Migrated from github.com)

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

Check Result Note
Changed-file review passed All changed files read
Tests not run Author reports a Windows-only test run
Console behavior not run No PS5 measurement supplied

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, and core/libs/prx/libSceLibreSsl/src/Bignum.cpp.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5952384640 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17622#pullrequestreview-5952384640). Originally posted by [MarcZX10](https://github.com/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 | Check | Result | Note | | --- | --- | --- | | Changed-file review | passed | All changed files read | | Tests | not run | Author reports a Windows-only test run | | Console behavior | not run | No PS5 measurement supplied | ## 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`, and `core/libs/prx/libSceLibreSsl/src/Bignum.cpp`. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/17622:upstream-pr/17622'
git switch 'upstream-pr/17622'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/17622'
git switch 'upstream-pr/17622'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/17622'
git switch 'upstream-pr/17622'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/17622'
git switch 'main'
git merge --squash 'upstream-pr/17622'
git switch 'main'
git merge --ff-only 'upstream-pr/17622'
git switch 'main'
git merge 'upstream-pr/17622'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!17622
No description provided.