feat(libSceLibreSsl3): implement EC_GROUP_cmp #16918

Merged
GalaxyGamingFR merged 2 commits from upstream-pr/16918 into main 2026-11-15 06:27:20 +00:00
GalaxyGamingFR commented 2026-11-07 22:31:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GalaxyGamingFR on 2026-11-07T22:31:14Z.


What

Implement EC_GROUP_cmp in libSceLibreSsl3, replacing its parameterless throwing placeholder in AdditionalExports.cpp.

  • Source: LibreSSL 4.0.0 at ce488b78 ec_lib.c, the revision the library's debt file already uses. Upstream returns 1 when both groups have curve names and they differ. Otherwise it compares the field type, a, b, p, the generator, the order and the cofactor, and returns 0 only when all of them match.
  • Every EC_GROUP in this code base comes from libSceLibreSsl EC_GROUP_new_by_curve_name (forwarded by ParentExports.cpp), which builds only the eleven named curves in Ec.cpp. Each NID there has its own parameters, so for these groups "same NID" and "same parameters" are equivalent, and the export returns a nid != b nid ? 1 : 0.
  • libSceLibreSsl3 cannot include Ec.hpp, because mbedcrypto is a private dependency of libSceLibreSsl and its headers are not visible here. The export reads the NID as the leading int of the group: EcGroup begins with NamedCurve curve, which begins with int nid. New static asserts in Ec.hpp pin this: EcGroup is standard-layout, curve is at offset 0 and nid is at offset 0. If the layout ever changes, the parent fails to compile instead of the child reading garbage.
  • Api.hpp now declares it as int EC_GROUP_cmp(const EcGroup* a, const EcGroup* b, void* ctx). The BN_CTX is not used, as upstream only uses it as scratch space.
  • A null group throws std::invalid_argument, where upstream would dereference it.

The gap is recorded in docs/dev/debt/libSceLibreSsl3.md: -1 is never returned, and the shortcut only holds while groups are named curves. The export inventory is updated (138 exports, 128 named).

No title's trace or disassembly was used, and the export was not measured on a PS5.

Tested

Windows 11, WinLibs GCC 15.2.0 UCRT r7. This is not a full CMake build. I compiled the new tests/EcGroup.cpp with src/EcGroup.cpp, libSceLibreSsl's Ec.cpp and Error.cpp, and the 3rdparty/mbedtls library sources into one executable, with APS5_VABI defined empty and a one-line NotImplementedAt_nid_no_patch that throws. No title or homebrew, and not built on Linux or macOS.

  • The test passes. It builds two groups for each of seven curves (409, 415, 714, 715, 716, 928, 934) and checks that every pair returns 0 for the same curve and 1 otherwise, in both argument orders. It also checks that a non-null ctx is left untouched and that each null-argument combination throws. The set includes secp256r1, secp256k1 and brainpoolP256r1, which share EC_GROUP_get_degree 256, so a degree-based comparison would fail.
  • Two deliberate bugs both make the test fail: inverting the comparison fails at line 41, and returning 0 for a null group fails the null checks.
  • -Wall -Wextra is clean for the new files, and python tools/check_conventions.py --base origin/main passes.

I searched open and merged pull requests for EC_GROUP_cmp just before opening this one, and none implements it. #16586, #16588, #16589 and #16848 change the same export inventory count, 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:5206446887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16918). Originally posted by [GalaxyGamingFR](https://github.com/GalaxyGamingFR) on 2026-11-07T22:31:14Z. --- ### What Implement `EC_GROUP_cmp` in `libSceLibreSsl3`, replacing its parameterless throwing placeholder in `AdditionalExports.cpp`. - Source: LibreSSL 4.0.0 at [`ce488b78` `ec_lib.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ec_lib.c#L578-L649), the revision the library's debt file already uses. Upstream returns 1 when both groups have curve names and they differ. Otherwise it compares the field type, `a`, `b`, `p`, the generator, the order and the cofactor, and returns 0 only when all of them match. - Every `EC_GROUP` in this code base comes from libSceLibreSsl `EC_GROUP_new_by_curve_name` (forwarded by `ParentExports.cpp`), which builds only the eleven named curves in `Ec.cpp`. Each NID there has its own parameters, so for these groups "same NID" and "same parameters" are equivalent, and the export returns `a nid != b nid ? 1 : 0`. - libSceLibreSsl3 cannot include `Ec.hpp`, because mbedcrypto is a private dependency of libSceLibreSsl and its headers are not visible here. The export reads the NID as the leading `int` of the group: `EcGroup` begins with `NamedCurve curve`, which begins with `int nid`. New static asserts in `Ec.hpp` pin this: `EcGroup` is standard-layout, `curve` is at offset 0 and `nid` is at offset 0. If the layout ever changes, the parent fails to compile instead of the child reading garbage. - `Api.hpp` now declares it as `int EC_GROUP_cmp(const EcGroup* a, const EcGroup* b, void* ctx)`. The `BN_CTX` is not used, as upstream only uses it as scratch space. - A null group throws `std::invalid_argument`, where upstream would dereference it. The gap is recorded in `docs/dev/debt/libSceLibreSsl3.md`: `-1` is never returned, and the shortcut only holds while groups are named curves. The export inventory is updated (138 exports, 128 named). No title's trace or disassembly was used, and the export was not measured on a PS5. ### Tested Windows 11, WinLibs GCC 15.2.0 UCRT r7. This is not a full CMake build. I compiled the new `tests/EcGroup.cpp` with `src/EcGroup.cpp`, libSceLibreSsl's `Ec.cpp` and `Error.cpp`, and the `3rdparty/mbedtls` library sources into one executable, with `APS5_VABI` defined empty and a one-line `NotImplementedAt_nid_no_patch` that throws. No title or homebrew, and not built on Linux or macOS. - The test passes. It builds two groups for each of seven curves (409, 415, 714, 715, 716, 928, 934) and checks that every pair returns 0 for the same curve and 1 otherwise, in both argument orders. It also checks that a non-null `ctx` is left untouched and that each null-argument combination throws. The set includes secp256r1, secp256k1 and brainpoolP256r1, which share `EC_GROUP_get_degree` 256, so a degree-based comparison would fail. - Two deliberate bugs both make the test fail: inverting the comparison fails at line 41, and returning 0 for a null group fails the null checks. - `-Wall -Wextra` is clean for the new files, and `python tools/check_conventions.py --base origin/main` passes. I searched open and merged pull requests for `EC_GROUP_cmp` just before opening this one, and none implements it. #16586, #16588, #16589 and #16848 change the same export inventory count, 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)
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!16918
No description provided.