feat(libSceLibreSsl): implement EC_KEY_get0_private_key and EC_KEY_set_private_key #11146
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11146"
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 ahmadmuj on 2026-10-25T19:34:22Z.
What
Implements
EC_KEY_get0_private_keyandEC_KEY_set_private_keywith a guest-heap BIGNUM. Copying, freeing and generation follow LibreSSL 2.5.4. Checking, ECDSA and ECDH use that stored key.Head
596aeb860cc9fb1df689c6be571d9ebf2817cbe5merges main648ba19b3edec93a073217bda7087dedcfd85454without rewriting history. Replacement #15827 is now merged. This keeps main's point operations, ASN.1 flags and 64-byteEcKeylayout, with references at offset 48.Native DER decoding and encoding now use the public BIGNUM APIs instead of the replaced private-key layout. The decoder keeps its range checks and error queue. Encoding keeps fixed-width scalar padding. Existing native test helpers use the same APIs. The EC parameters test registers its allocator before key generation.
The existing private-key regression and maintainer removals stay unchanged. Known limits stay in the debt fragment: unsupported negative or non-normalized keys throw; signing and ECDH reject out-of-range keys; some failures queue no error. No console layout claim is made. #11466 carries this feature as a dependency; its own point decoder changes different functions.
Tested
Linux x86_64, Ubuntu 24.04 on WSL2, GCC 13.3, Release, Intel Core i7-13700K. No title or console run.
On the exact head above, 17 focused CPU tests pass: legacy EC, EC keys, EC private key, EC point multiplication and PKEY lifecycle; native ASN.1 flag, EC group, EC parameters, PKEY getters, ECDSA, public key, key reference, DER, PEM and PKEY context. Main's SSL lifecycle and ex-data tests also pass.
The DER test checks exact P-256/P-384 round trips, scalar-one public-key derivation and padding, zero/order rejection, exact error codes and allocation balance. The earlier padding mutation fails, and its restoration passes, at
4bd52813585b11b9a768f66faeba39c5e3adace4. That source and test remain byte-identical here; this merge does not repeat the mutation.Commands to reproduce the checks, from a credential-free shell (the build targets ran in groups):
The focused targets build. Public headers, conventions, debt and whitespace checks pass. The upstream native import-binding harness passes against six freshly built and patched modules. This merge removes adjacent obsolete DTLS/private-key stubs. The existing private-key code, DER corrections, tests and debt remain unchanged. Main's method and lifecycle implementations remain intact. The fresh configure first misses the nested mbedTLS framework checkout; restoring its pinned submodule fixes setup. All scoped build and runtime checks then pass.
No full product build, full ctest, ASan, new oracle comparison, Windows, macOS, console, game or GPU run. Earlier Windows evidence checks an older head.
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)27555b3f7c169e1053fa022244963450a5619658Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:39:55Z.
Review: CHANGES_REQUESTED
Reviewed exact head
714a0abb61c173ec9d3ca4ddeb1099b6ad8ad40e. The private-key copy and clear/free behavior is consistent with the cited LibreSSL 2.5.4 paths; local conventions and diff checks pass, and the PR reports focused EC/RSA test coverage plus a LibreSSL differential.Before this stack is ready to merge, please resolve the shared
EcKey::privateKeyintegration order called out in MatteoSid's review comment. #10407 adds the EC point/key operations using that same member with anmbedtls_mpirepresentation, while this PR replaces it with the guest BIGNUM representation. The current checklist only declares #10395 and #10915, and this branch does not contain or rebase on #10407. Please add the dependency and update/rebase the stack in the agreed order after #10395, or coordinate an alternative order with the other author and document it. #10407 is currently closed by the intake limit; I have not reopened it or used its code.I am requesting changes for this unresolved integration dependency. The current upstream eligibility, conventions, intake, labels and report checks pass; the product build/test jobs are skipped by repository policy. I did not independently run the reported full build because this workspace's AnyPS5 submodules are uninitialized.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T10:10:22Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The
EC_KEY_get0_private_key/EC_KEY_set_private_keycode and the guest-BIGNUM swap build, pass their tests and match LibreSSL 2.5.4 where I checked them, but the head no longer merges into currentmain, so it needs a re-merge before it can go in.What I ran
29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2main:e2722b27f1ad7c27ff85734026d6e17b3bd1bcccBUILD_TESTING=ON, in a clean worktree.The merge onto
mainconflicted, so I built and tested the PR head itself.Results
maine2722b27f1git diff --checkcheck_conventions.py --base origin/mainlibSceLibreSsl--target libsguest_libressl_ec,guest_libressl_ec_keys,guest_libressl_ec_private_key,guest_libressl_rsa,public_headers*guest_libressl_ec_private_keyMerge conflicts
ctest excerpt
Negative control
Restoring the production files from
mainor from #10407's branch removes the two new exports, so the new test would not compile. I applied single-line mutants tosrc/Ec.cppinstead and rebuilt each one. All four fail the new test:DuplicateBignumcopies the sourceflagsfailed: a copy of three wordsRandomRangeWordsdrops the extra bitfailed: the generated private key has the words of BN_rand_rangeEcBignumDeleterdoes not wipe the structfailed: the old words and BIGNUM are cleared before they are freedEC_KEY_generate_keydrops the static-words guardfailed: EC_KEY_generate_key cannot grow static wordsI restored the original file afterwards, rebuilt it and confirmed that the test passes again.
Findings
Blocking
main. Merging29cfe068b0intomaine2722b27f1conflicts in the six files listed above. Most of this comes from the #10915 commits the branch carries. #10449 (RSA_flags,RSA_size) merged intomainon 2026-10-26 as rebased commits (d7928af60f,ddb51767c0,7477b90ecb). This branch still has the earlier copies (357a561f9a,e28a1529fe,e44f645642), soRsa.cppandGuestLibreSslRsa.cppconflict add/add.Export.cpp,Api.hpp,CMakeLists.txtand the debt file also moved onmainwith the other LibreSSL merges. As a result, the "Based on currentmain" checklist line no longer holds. Fix: merge currentmain, plus #10915's current head (4ad9203124, not the939a194466carried here), resolve the conflicts, and re-run the tests. Also note thatmainnow has its own copy of the 24-byte layout asLibreSslBignum(Rsa.cppL10-L16 onmain), soEcBignuminEc.cppbecomes a third definition of the same layout after the merge.I am not repeating the stacking/intake point from the earlier review. The conflict is a separate problem that appeared after #10449 merged.
Non-blocking
EC_KEY_check_keythrows where 2.5.4's result is fixed and known. For a stored key thatBN_cmpputs at or above the order, 2.5.4 returns 0 before any point arithmetic (ec_key.c L312-L316).BN_cmpcomparestopfirst, so this also covers keys with zero high words above the order's length. A zero key givesG·0at infinity, which cannot equal a public key that already passed the infinity check, so that case is 0 too. Your probe shows the same results (n+7: 0,0: 0,7withtop5: 0). Only negative keys need real arithmetic.ReadPrivateKeythrows for all of these cases inEC_KEY_check_key. The throw is documented and the follow-up has been agreed, so this does not block. Still,check_keycould return 0 for "zero, orBN_cmp≥ order" now and throw only for negative keys, and the debt line would shrink to match.EC_KEY_set_private_keythrows whenever the source overlaps the stored words (SharesWords). However, 2.5.4'sBN_clear_freeleaves the words alone when the stored BIGNUM hasBN_FLG_STATIC_DATA(bn_lib.c L216-L231). In that case a different source BIGNUM pointing into those words is copied with defined behaviour. Likewise, passing the key's own BIGNUM withoutBN_FLG_MALLOCEDreads a zeroed struct rather than freed memory. Both cases need guest code to rewrite the flags of theconstBIGNUM thatget0returns, so they are unlikely. Still, the debt line's reason ("which LibreSSL frees before it copies") is not accurate for them. Either narrow the check to the flags under which 2.5.4 actually frees, or reword the debt line.Not verified
main.714a0abb61, not this one.EC_KEY_check_key,EC_KEY_set_private_keyandBN_clear_free, but did not build LibreSSL.guest_libressl_*tests and the full suite.To get this to a good state
mainand #10915's current head, resolve the six conflicts, and re-runctest -R 'libressl|public_headers'andcheck_conventions.py.EC_KEY_check_keyreturn 0 for zero and for keys at or above the order, and narrow or reword the shared-words throw as described above.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T11:28:21Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2. MatteoSid’s confirmation preserves the original authorship, but it does not resolve the intake constraint: #10407 is still closed under the repository’s open-PR limit, and this branch carries its EC-point/ECDSA/ECDH implementation commits. The contribution rules and the standing repository-review constraints require intake-paused work to stay out of another open PR. Please keep #11146 out of the merge path until #10407 is eligible to reopen, then stack the work in the agreed order with the original commits/authorship preserved. The rebase/test integration against currentmainalso remains outstanding. The prior exact-head LibreSSL test reports are useful, but do not clear those integration constraints.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:19:42Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(096c45570f): head434897e60fconflicts incore/libs/prx/libSceLibreSsl/CMakeLists.txtcore/libs/prx/libSceLibreSsl/include/Api.hppdocs/dev/debt/libSceLibreSsl.mdPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T07:53:00Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected code shows no verified blocking defect; I could not run the reported checks or read every changed file, so a formal approval is not justified.
What I ran
The prepared review identifies head
7c1ad34b8bc17ebddbc324361698f26a9aeab98a. I used the pinnedrepo_read.pyreader to inspect the review materials and targeted repository ranges. No build or tests were run in this review.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
The description reports focused runtime tests and a Linux Release build, but these results were not independently run during this review.
Not verified
I read the prepared
description.md,commits.md,manifest.jsonanddiff.patch, plus repository filescore/libs/prx/libSceLibreSsl/src/Ec.cpp,core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Ec.hpp,core/libs/prx/libSceLibreSsl/include/Api.hppanddocs/dev/debt/libSceLibreSsl.md. The diff covers all changed files, but I did not read the full text ofcore/libs/prx/libSceLibreSsl/CMakeLists.txt,core/libs/tests/GuestLibreSslEcKeys.cpporcore/libs/tests/GuestLibreSslEcPrivateKey.cpp. Build, runtime tests, Windows, macOS and console behavior were not verified.To get this to a good state
Nothing is required. Optional: run the reported Linux build and focused tests on this head and confirm CI results.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T08:48:50Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
4bd5281358:tools/check_conventions.pypassed.guest_libressl3_ec_parameters_tests,guest_libressl3_key_der_tests,guest_libressl3_pem_keys_tests,guest_libressl3_pkey_context_tests,guest_libressl_ec_keys_tests,guest_libressl_ec_private_key_testsbuilt cleanly.guest_libressl_ec_keys,guest_libressl_ec_private_key,guest_libressl3_ec_parameters,guest_libressl3_pkey_context,guest_libressl3_key_der,guest_libressl3_pem_keys):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/include/Ec.hpp,core/libs/prx/libSceLibreSsl/src/Ec.cpp,core/libs/prx/libSceLibreSsl3/src/KeyDer.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T11:11:17Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation has no verified blocking defect, but I could not run the reported checks or complete a file-by-file review at this head.
What I ran
Reviewed the prepared diff at head
596aeb860cc9fb1df689c6be571d9ebf2817cbe5; no commands or tests were run. The author reports focused Linux x86_64 tests and checks passed, which I did not independently verify.Results
Negative control
Could not run the reported padding mutation and restoration on this head.
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Sources
Reviewed
review/description.md,review/commits.md,review/manifest.json, andreview/diff.patch. Inspected changed code incore/libs/prx/libSceLibreSsl/src/Ec.cppandcore/libs/prx/libSceLibreSsl3/src/KeyDer.cpp.Not verified
The changed test files, headers, CMake changes, export changes, and debt fragment were not independently read at the pinned head. The test results, build, platform behavior, console behavior, and full repository checks were not verified. The review bundle did not provide
review/files.jsonthrough the reader.To get this to a good state
Nothing is required. Optional: complete the remaining changed-file review and run the reported checks on this head before treating the review as complete.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:25:04Z.
Review: COMMENTED
Built the focused checks against the existing Linux runtime. The
GuestLibreSslEcKeysandGuestLibreSslEcPrivateKeyfixtures passed. The separate LibreSSL3 fixtures did not build with this standalone setup.AI-assisted: yes.
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.