Skip to content

feat(libSceLibreSsl): implement EC_POINT_mul - #17275

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
MatteoSid:feat/libressl-ec-point-mul
Nov 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
MatteoSid:feat/libressl-ec-point-mul

Conversation

@MatteoSid

@MatteoSid MatteoSid commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements EC_POINT_mul (NID Sw6hs2iJZkU) on the EC code from #10395 and #15827, following LibreSSL 2.5.4's EC_POINT_mul and the early returns of ec_wNAF_mul:

  • the result is g_scalar times the generator plus p_scalar times point; a term whose scalar or point is null is left out, and with neither the result is the point at infinity; it returns 1;
  • scalars are read from the guest BIGNUM and taken modulo the group order, negative ones included. ec_wNAF_mul multiplies by the scalar itself, and every point on the 11 supported curves has the group order, so the residue gives the same point;
  • a point at infinity adds nothing, and the result may be the input point;
  • the multiplication runs on a local copy of the curve: mbedtls stores the generator's precomputed table in the group it multiplies with (MBEDTLS_ECP_FIXED_POINT_OPTIM), so the guest's EC_GROUP is never written and calls sharing one group do not race.

Gaps, in a new debt entry: a point off the curve throws, where LibreSSL computes with it; a point of another curve throws, as for the other EC_POINT functions; no error code is queued. Export.cpp goes from 100 to 99 NotImplemented_nid_no_patch stubs.

It does not read or store private keys, so it is independent of #11146 (EC_KEY_get0_private_key, EC_KEY_set_private_key).

Tested

Linux (Ubuntu 24.04 container, GCC 13.3), full configure with -DBUILD_TESTING=ON, Release: built libSceLibreSsl, libSceLibreSsl3, their patched .prx files and the 107 LibreSSL tests; ctest -R 'libressl|crypto_memcmp|public_headers' passes 172 of 172 (the 107 LibreSSL tests, public_headers and its 64 compile checks) on head 492e88855e, based on main f35f1e5eca. The new guest_libressl_ec_point_mul takes 0.6 s and checks, on all 11 curves:

  • a full-size scalar times the generator, through the generator term and through the point term, against a vector computed with separate affine arithmetic in Python and matched with OpenSSL 3.0.2 (cryptography 46 for nine curves, openssl ec for secp192k1 and secp224k1); and the RFC 6979 A.2.5 P-256 public key from its private key;
  • negative scalars, the order (infinity), order - 1 (the negated generator), 3 * order + 5, zero scalars, a term without its scalar or point, 7G + 3(5G) = 22G, terms that cancel, a point at infinity, no scalars at all, and the result being the input point;
  • on generated keys, a scalar times the public key equals ECDH_compute_key with the scalar times the generator.

The test fails when the negative-scalar handling or the two-term sum is removed, and throws when points at infinity are no longer skipped. nm -D on the patched libSceLibreSsl.prx lists Sw6hs2iJZkU. With AddressSanitizer and leak detection, a driver running the same EC_POINT_mul cases on stack BIGNUMs is clean, and so are guest_libressl_ec_keys, guest_libressl_ec and guest_libressl3_key_reference; the new test itself stops at its first BIGNUM allocation in that sanitizer build, as guest_libressl_bn on main does. tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch finds no overlap with the open PRs it could compare; the 21 that share files and conflict with main were checked by hand, and none changes EC_POINT_mul (#11146 and #11466 also touch Ec.cpp, and #11146 implements the private-key stubs next to this one). No title tested.

Windows: JJenkx ran guest_libressl_ec_point_mul on head 492e88855e merged onto main (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs (comment).

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

EC_POINT_mul follows LibreSSL 2.5.4's ec_lib.c and ec_wNAF_mul on
mbedtls's named curves: the generator and point terms are optional,
and scalars are taken modulo the group order, which gives LibreSSL's
points for negative scalars and scalars above the order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 11146 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/prx/libSceLibreSsl/src/Ec.cpp
docs/dev/debt/libSceLibreSsl.md
PR 11176 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11466 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/prx/libSceLibreSsl/src/Ec.cpp
docs/dev/debt/libSceLibreSsl.md
PR 12729 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 12730 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13266 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13285 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13546 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13547 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 13877 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14115 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 14212 docs/dev/debt/libSceLibreSsl.md
PR 15278 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15279 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15280 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15281 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15737 docs/dev/debt/libSceLibreSsl.md
PR 16529 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 16683 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16697 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16716 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16722 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16725 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16726 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16727 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16734 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 17813 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 17961 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 18396 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 492e88855e, merged onto main bfdb58119e (1b9625ea2f, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_libressl_ec_point_mul passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit f4c5f10 into boykopovar:main Nov 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants