feat(libSceLibreSsl): implement EC_KEY_get0_private_key and EC_KEY_set_private_key #11146

Open
ahmadmuj wants to merge 61 commits from upstream-pr/11146 into main
ahmadmuj commented 2026-10-25 19:34:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T19:34:22Z.


What

Implements EC_KEY_get0_private_key and EC_KEY_set_private_key with a guest-heap BIGNUM. Copying, freeing and generation follow LibreSSL 2.5.4. Checking, ECDSA and ECDH use that stored key.

Head 596aeb860cc9fb1df689c6be571d9ebf2817cbe5 merges main 648ba19b3edec93a073217bda7087dedcfd85454 without rewriting history. Replacement #15827 is now merged. This keeps main's point operations, ASN.1 flags and 64-byte EcKey layout, 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):

cmake -S . -B ../../builds/align-11146-054 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_TESTING=ON -DANYPS5_LIBRESSL_ORACLE=OFF
cmake --build ../../builds/align-11146-054 --parallel 16 --target libSceLibreSsl guest_libressl_ec_tests guest_libressl_ec_keys_tests guest_libressl_ec_private_key_tests guest_libressl_ec_point_mul_tests guest_libressl_pkey_lifecycle_tests guest_libressl3_ec_key_asn1_flag_tests guest_libressl3_ec_group_tests guest_libressl3_ec_parameters_tests guest_libressl3_pkey_getters_tests guest_libressl3_ecdsa_tests guest_libressl3_ec_public_key_tests guest_libressl3_key_reference_tests guest_libressl3_key_der_tests guest_libressl3_pem_keys_tests guest_libressl3_pkey_context_tests libressl3_pkey_lifecycle_modules guest_libressl_ssl_lifecycle_tests guest_libressl_ex_data_tests
ctest --test-dir ../../builds/align-11146-054 -R '^(guest_libressl_(ec|ec_keys|ec_private_key|ec_point_mul|pkey_lifecycle|ssl_lifecycle|ex_data)|guest_libressl3_(ec_key_asn1_flag|ec_group|ec_parameters|pkey_getters|ecdsa|ec_public_key|key_reference|key_der|pem_keys|pkey_context))$' --output-on-failure -j4
python3 core/libs/tests/test_public_headers.py --compiler g++
python3 tools/check_conventions.py --base origin/main
python3 tools/debt_fold.py --check
git diff 648ba19b3edec93a073217bda7087dedcfd85454 HEAD --check

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

  • 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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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; #15827 merged as 27555b3f7c169e1053fa022244963450a5619658
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007975163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T19:34:22Z. --- ### What Implements `EC_KEY_get0_private_key` and `EC_KEY_set_private_key` with a guest-heap BIGNUM. Copying, freeing and generation follow [LibreSSL 2.5.4](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto). Checking, ECDSA and ECDH use that stored key. Head `596aeb860cc9fb1df689c6be571d9ebf2817cbe5` merges main `648ba19b3edec93a073217bda7087dedcfd85454` without rewriting history. Replacement #15827 is now merged. This keeps main's point operations, ASN.1 flags and 64-byte `EcKey` layout, 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): ```sh cmake -S . -B ../../builds/align-11146-054 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_TESTING=ON -DANYPS5_LIBRESSL_ORACLE=OFF cmake --build ../../builds/align-11146-054 --parallel 16 --target libSceLibreSsl guest_libressl_ec_tests guest_libressl_ec_keys_tests guest_libressl_ec_private_key_tests guest_libressl_ec_point_mul_tests guest_libressl_pkey_lifecycle_tests guest_libressl3_ec_key_asn1_flag_tests guest_libressl3_ec_group_tests guest_libressl3_ec_parameters_tests guest_libressl3_pkey_getters_tests guest_libressl3_ecdsa_tests guest_libressl3_ec_public_key_tests guest_libressl3_key_reference_tests guest_libressl3_key_der_tests guest_libressl3_pem_keys_tests guest_libressl3_pkey_context_tests libressl3_pkey_lifecycle_modules guest_libressl_ssl_lifecycle_tests guest_libressl_ex_data_tests ctest --test-dir ../../builds/align-11146-054 -R '^(guest_libressl_(ec|ec_keys|ec_private_key|ec_point_mul|pkey_lifecycle|ssl_lifecycle|ex_data)|guest_libressl3_(ec_key_asn1_flag|ec_group|ec_parameters|pkey_getters|ecdsa|ec_public_key|key_reference|key_der|pem_keys|pkey_context))$' --output-on-failure -j4 python3 core/libs/tests/test_public_headers.py --compiler g++ python3 tools/check_conventions.py --base origin/main python3 tools/debt_fold.py --check git diff 648ba19b3edec93a073217bda7087dedcfd85454 HEAD --check ``` 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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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; #15827 merged as `27555b3f7c169e1053fa022244963450a5619658` - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 19:39:55 +00:00 (Migrated from github.com)

Imported 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::privateKey integration order called out in MatteoSid's review comment. #10407 adds the EC point/key operations using that same member with an mbedtls_mpi representation, 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644912376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5644912376). Originally posted by [MarcZX10](https://github.com/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::privateKey` integration order called out in MatteoSid's review comment. #10407 adds the EC point/key operations using that same member with an `mbedtls_mpi` representation, 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.
XairRrR commented 2026-10-29 10:10:22 +00:00 (Migrated from github.com)

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_key code 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 current main, so it needs a re-merge before it can go in.

What I ran

  • Head: 29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2
  • main: e2722b27f1ad7c27ff85734026d6e17b3bd1bccc
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08). Release, Ninja, BUILD_TESTING=ON, in a clean worktree.

The merge onto main conflicted, so I built and tested the PR head itself.

git fetch origin main pull/11146/head:refs/review/11146
git checkout --detach origin/main
git merge --no-ff --no-edit refs/review/11146     # conflicts, aborted
git checkout --detach refs/review/11146
git diff --check origin/main...refs/review/11146
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target guest_libressl_ec_tests guest_libressl_ec_keys_tests \
  guest_libressl_ec_private_key_tests guest_libressl_rsa_tests libSceLibreSsl
cmake --build build -j10 --target libs
ctest --test-dir build -j4 --output-on-failure \
  -R '^(guest_libressl_ec|guest_libressl_ec_keys|guest_libressl_ec_private_key|guest_libressl_rsa|public_headers.*)$'
# four single-line mutants of src/Ec.cpp, each followed by:
cmake --build build -j10 --target guest_libressl_ec_private_key_tests
ctest --test-dir build -R '^guest_libressl_ec_private_key$' --output-on-failure

Results

Check Result
Merge into main e2722b27f1 Conflicts in 6 files
git diff --check clean
check_conventions.py --base origin/main passed
Build of the four test targets and libSceLibreSsl OK, no new warnings in the changed files
--target libs OK
guest_libressl_ec, guest_libressl_ec_keys, guest_libressl_ec_private_key, guest_libressl_rsa, public_headers* 69/69 passed, 20.4 s total. Each LibreSSL test takes 0.3 s or less
Mutants (see below) 4/4 fail guest_libressl_ec_private_key
Merge conflicts
CONFLICT (content): core/libs/prx/libSceLibreSsl/CMakeLists.txt
CONFLICT (content): core/libs/prx/libSceLibreSsl/Export.cpp
CONFLICT (content): core/libs/prx/libSceLibreSsl/include/Api.hpp
CONFLICT (add/add): core/libs/prx/libSceLibreSsl/src/Rsa.cpp
CONFLICT (add/add): core/libs/tests/GuestLibreSslRsa.cpp
CONFLICT (content): docs/dev/debt/libSceLibreSsl.md
ctest excerpt
64/69 Test #1724: guest_libressl_ec ................   Passed    0.00 sec
65/69 Test #1725: guest_libressl_rsa ...............   Passed    0.20 sec
66/69 Test #1727: guest_libressl_ec_private_key ....   Passed    0.02 sec
68/69 Test #1726: guest_libressl_ec_keys ...........   Passed    0.30 sec
100% tests passed out of 69

Negative control

Restoring the production files from main or from #10407's branch removes the two new exports, so the new test would not compile. I applied single-line mutants to src/Ec.cpp instead and rebuilt each one. All four fail the new test:

Mutant Failure
DuplicateBignum copies the source flags failed: a copy of three words
RandomRangeWords drops the extra bit failed: the generated private key has the words of BN_rand_range
EcBignumDeleter does not wipe the struct failed: the old words and BIGNUM are cleared before they are freed
EC_KEY_generate_key drops the static-words guard failed: EC_KEY_generate_key cannot grow static words

I restored the original file afterwards, rebuilt it and confirmed that the test passes again.

Findings

Blocking

  1. The head conflicts with current main. Merging 29cfe068b0 into main e2722b27f1 conflicts in the six files listed above. Most of this comes from the #10915 commits the branch carries. #10449 (RSA_flags, RSA_size) merged into main on 2026-10-26 as rebased commits (d7928af60f, ddb51767c0, 7477b90ecb). This branch still has the earlier copies (357a561f9a, e28a1529fe, e44f645642), so Rsa.cpp and GuestLibreSslRsa.cpp conflict add/add. Export.cpp, Api.hpp, CMakeLists.txt and the debt file also moved on main with the other LibreSSL merges. As a result, the "Based on current main" checklist line no longer holds. Fix: merge current main, plus #10915's current head (4ad9203124, not the 939a194466 carried here), resolve the conflicts, and re-run the tests. Also note that main now has its own copy of the 24-byte layout as LibreSslBignum (Rsa.cpp L10-L16 on main), so EcBignum in Ec.cpp becomes 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

  1. EC_KEY_check_key throws where 2.5.4's result is fixed and known. For a stored key that BN_cmp puts at or above the order, 2.5.4 returns 0 before any point arithmetic (ec_key.c L312-L316). BN_cmp compares top first, so this also covers keys with zero high words above the order's length. A zero key gives G·0 at 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, 7 with top 5: 0). Only negative keys need real arithmetic. ReadPrivateKey throws for all of these cases in EC_KEY_check_key. The throw is documented and the follow-up has been agreed, so this does not block. Still, check_key could return 0 for "zero, or BN_cmp ≥ order" now and throw only for negative keys, and the debt line would shrink to match.
  2. The shared-words and own-key throws are broader than the 2.5.4 UB they guard against. EC_KEY_set_private_key throws whenever the source overlaps the stored words (SharesWords). However, 2.5.4's BN_clear_free leaves the words alone when the stored BIGNUM has BN_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 without BN_FLG_MALLOCED reads a zeroed struct rather than freed memory. Both cases need guest code to rewrite the flags of the const BIGNUM that get0 returns, 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

  • The merged result: the merge conflicts, so nothing was built or tested on top of current main.
  • Windows and macOS builds, and console behaviour. A Windows run and firmware 13.42 data posted in the comments cover the earlier head 714a0abb61, not this one.
  • The author's LibreSSL 2.5.4 probe values: I read the 2.5.4 sources for EC_KEY_check_key, EC_KEY_set_private_key and BN_clear_free, but did not build LibreSSL.
  • Other guest_libressl_* tests and the full suite.

To get this to a good state

  1. Merge current main and #10915's current head, resolve the six conflicts, and re-run ctest -R 'libressl|public_headers' and check_conventions.py.
  2. Optionally, make EC_KEY_check_key return 0 for zero and for keys at or above the order, and narrow or reword the shared-words throw as described above.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696018913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5696018913). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T10:10:22Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The `EC_KEY_get0_private_key` / `EC_KEY_set_private_key` code 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 current `main`, so it needs a re-merge before it can go in. ## What I ran - Head: `29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2` - `main`: `e2722b27f1ad7c27ff85734026d6e17b3bd1bccc` - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08). Release, Ninja, `BUILD_TESTING=ON`, in a clean worktree. The merge onto `main` conflicted, so I built and tested the PR head itself. ```sh git fetch origin main pull/11146/head:refs/review/11146 git checkout --detach origin/main git merge --no-ff --no-edit refs/review/11146 # conflicts, aborted git checkout --detach refs/review/11146 git diff --check origin/main...refs/review/11146 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target guest_libressl_ec_tests guest_libressl_ec_keys_tests \ guest_libressl_ec_private_key_tests guest_libressl_rsa_tests libSceLibreSsl cmake --build build -j10 --target libs ctest --test-dir build -j4 --output-on-failure \ -R '^(guest_libressl_ec|guest_libressl_ec_keys|guest_libressl_ec_private_key|guest_libressl_rsa|public_headers.*)$' # four single-line mutants of src/Ec.cpp, each followed by: cmake --build build -j10 --target guest_libressl_ec_private_key_tests ctest --test-dir build -R '^guest_libressl_ec_private_key$' --output-on-failure ``` ## Results | Check | Result | | - | - | | Merge into `main` `e2722b27f1` | **Conflicts** in 6 files | | `git diff --check` | clean | | `check_conventions.py --base origin/main` | passed | | Build of the four test targets and `libSceLibreSsl` | OK, no new warnings in the changed files | | `--target libs` | OK | | `guest_libressl_ec`, `guest_libressl_ec_keys`, `guest_libressl_ec_private_key`, `guest_libressl_rsa`, `public_headers*` | 69/69 passed, 20.4 s total. Each LibreSSL test takes 0.3 s or less | | Mutants (see below) | 4/4 fail `guest_libressl_ec_private_key` | <details><summary>Merge conflicts</summary> ``` CONFLICT (content): core/libs/prx/libSceLibreSsl/CMakeLists.txt CONFLICT (content): core/libs/prx/libSceLibreSsl/Export.cpp CONFLICT (content): core/libs/prx/libSceLibreSsl/include/Api.hpp CONFLICT (add/add): core/libs/prx/libSceLibreSsl/src/Rsa.cpp CONFLICT (add/add): core/libs/tests/GuestLibreSslRsa.cpp CONFLICT (content): docs/dev/debt/libSceLibreSsl.md ``` </details> <details><summary>ctest excerpt</summary> ``` 64/69 Test #1724: guest_libressl_ec ................ Passed 0.00 sec 65/69 Test #1725: guest_libressl_rsa ............... Passed 0.20 sec 66/69 Test #1727: guest_libressl_ec_private_key .... Passed 0.02 sec 68/69 Test #1726: guest_libressl_ec_keys ........... Passed 0.30 sec 100% tests passed out of 69 ``` </details> ## Negative control Restoring the production files from `main` or from #10407's branch removes the two new exports, so the new test would not compile. I applied single-line mutants to `src/Ec.cpp` instead and rebuilt each one. All four fail the new test: | Mutant | Failure | | - | - | | `DuplicateBignum` copies the source `flags` | `failed: a copy of three words` | | `RandomRangeWords` drops the extra bit | `failed: the generated private key has the words of BN_rand_range` | | `EcBignumDeleter` does not wipe the struct | `failed: the old words and BIGNUM are cleared before they are freed` | | `EC_KEY_generate_key` drops the static-words guard | `failed: EC_KEY_generate_key cannot grow static words` | I restored the original file afterwards, rebuilt it and confirmed that the test passes again. ## Findings ### Blocking 1. **The head conflicts with current `main`.** Merging `29cfe068b0` into `main` `e2722b27f1` conflicts in the six files listed above. Most of this comes from the #10915 commits the branch carries. #10449 (`RSA_flags`, `RSA_size`) merged into `main` on 2026-10-26 as rebased commits (`d7928af60f`, `ddb51767c0`, `7477b90ecb`). This branch still has the earlier copies (`357a561f9a`, `e28a1529fe`, `e44f645642`), so `Rsa.cpp` and `GuestLibreSslRsa.cpp` conflict add/add. `Export.cpp`, `Api.hpp`, `CMakeLists.txt` and the debt file also moved on `main` with the other LibreSSL merges. As a result, the "Based on current `main`" checklist line no longer holds. **Fix:** merge current `main`, plus #10915's current head (`4ad9203124`, not the `939a194466` carried here), resolve the conflicts, and re-run the tests. Also note that `main` now has its own copy of the 24-byte layout as `LibreSslBignum` ([`Rsa.cpp` L10-L16 on `main`](https://github.com/boykopovar/AnyPS5/blob/e2722b27f1ad7c27ff85734026d6e17b3bd1bccc/core/libs/prx/libSceLibreSsl/src/Rsa.cpp#L10-L16)), so `EcBignum` in `Ec.cpp` becomes 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 1. **`EC_KEY_check_key` throws where 2.5.4's result is fixed and known.** For a stored key that `BN_cmp` puts at or above the order, 2.5.4 returns 0 before any point arithmetic ([ec_key.c L312-L316](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/ec/ec_key.c#L312-L316)). `BN_cmp` compares `top` first, so this also covers keys with zero high words above the order's length. A zero key gives `G·0` at 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, `7` with `top` 5: 0). Only negative keys need real arithmetic. [`ReadPrivateKey`](https://github.com/boykopovar/AnyPS5/blob/29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2/core/libs/prx/libSceLibreSsl/src/Ec.cpp#L169-L177) throws for all of these cases in [`EC_KEY_check_key`](https://github.com/boykopovar/AnyPS5/blob/29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2/core/libs/prx/libSceLibreSsl/src/Ec.cpp#L490-L503). The throw is documented and the follow-up has been agreed, so this does not block. Still, `check_key` could return 0 for "zero, or `BN_cmp` ≥ order" now and throw only for negative keys, and the debt line would shrink to match. 2. **The shared-words and own-key throws are broader than the 2.5.4 UB they guard against.** [`EC_KEY_set_private_key`](https://github.com/boykopovar/AnyPS5/blob/29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2/core/libs/prx/libSceLibreSsl/src/Ec.cpp#L423-L436) throws whenever the source overlaps the stored words ([`SharesWords`](https://github.com/boykopovar/AnyPS5/blob/29cfe068b0f3ad5d7907c2f7c3c39bca838e8bd2/core/libs/prx/libSceLibreSsl/src/Ec.cpp#L133-L140)). However, 2.5.4's `BN_clear_free` leaves the words alone when the stored BIGNUM has `BN_FLG_STATIC_DATA` ([bn_lib.c L216-L231](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/bn/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 without `BN_FLG_MALLOCED` reads a zeroed struct rather than freed memory. Both cases need guest code to rewrite the flags of the `const` BIGNUM that `get0` returns, 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 - The merged result: the merge conflicts, so nothing was built or tested on top of current `main`. - Windows and macOS builds, and console behaviour. A Windows run and firmware 13.42 data posted in the comments cover the earlier head `714a0abb61`, not this one. - The author's LibreSSL 2.5.4 probe values: I read the 2.5.4 sources for `EC_KEY_check_key`, `EC_KEY_set_private_key` and `BN_clear_free`, but did not build LibreSSL. - Other `guest_libressl_*` tests and the full suite. ## To get this to a good state 1. Merge current `main` and #10915's current head, resolve the six conflicts, and re-run `ctest -R 'libressl|public_headers'` and `check_conventions.py`. 2. Optionally, make `EC_KEY_check_key` return 0 for zero and for keys at or above the order, and narrow or reword the shared-words throw as described above.
MarcZX10 commented 2026-10-29 11:28:21 +00:00 (Migrated from github.com)

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 current main also remains outstanding. The prior exact-head LibreSSL test reports are useful, but do not clear those integration constraints.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696934738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5696934738). Originally posted by [MarcZX10](https://github.com/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 current `main` also remains outstanding. The prior exact-head LibreSSL test reports are useful, but do not clear those integration constraints.
XairRrR commented 2026-11-02 20:19:42 +00:00 (Migrated from github.com)

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): head 434897e60f conflicts in

  • core/libs/prx/libSceLibreSsl/CMakeLists.txt
  • core/libs/prx/libSceLibreSsl/include/Api.hpp
  • docs/dev/debt/libSceLibreSsl.md

Please rebase it onto current main. I will review the change once it merges cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5742779344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5742779344). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T20:19:42Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested This pull request does not merge cleanly into `main` (096c45570f516de76a43bbe1b97781381c84f55f): head 434897e60fe16392acbc79d01f6d3514c404df3f conflicts in - `core/libs/prx/libSceLibreSsl/CMakeLists.txt` - `core/libs/prx/libSceLibreSsl/include/Api.hpp` - `docs/dev/debt/libSceLibreSsl.md` Please rebase it onto current `main`. I will review the change once it merges cleanly. <!-- anyps5-bots job=2337 head=434897e60fe16392acbc79d01f6d3514c404df3f -->
MarcZX10 commented 2026-11-14 07:53:00 +00:00 (Migrated from github.com)

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 pinned repo_read.py reader to inspect the review materials and targeted repository ranges. No build or tests were run in this review.

Results

Check Result Note
Prepared diff and metadata passed Inspected
Targeted source review passed No blocking defect verified
Build and tests not run Only author-reported results available

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.json and diff.patch, plus repository files core/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.hpp and docs/dev/debt/libSceLibreSsl.md. The diff covers all changed files, but I did not read the full text of core/libs/prx/libSceLibreSsl/CMakeLists.txt, core/libs/tests/GuestLibreSslEcKeys.cpp or core/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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5902871685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5902871685). Originally posted by [MarcZX10](https://github.com/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 pinned `repo_read.py` reader to inspect the review materials and targeted repository ranges. No build or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Prepared diff and metadata | passed | Inspected | | Targeted source review | passed | No blocking defect verified | | Build and tests | not run | Only author-reported results available | ## 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.json` and `diff.patch`, plus repository files `core/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.hpp` and `docs/dev/debt/libSceLibreSsl.md`. The diff covers all changed files, but I did not read the full text of `core/libs/prx/libSceLibreSsl/CMakeLists.txt`, `core/libs/tests/GuestLibreSslEcKeys.cpp` or `core/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.
PrivacyOnion commented 2026-11-18 08:48:50 +00:00 (Migrated from github.com)

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:

  • Conventions: tools/check_conventions.py passed.
  • Build: 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_tests built cleanly.
  • CTest (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):
    1/6 Test #4378: guest_libressl3_ec_parameters ....   Passed    0.41 sec
    2/6 Test #4361: guest_libressl_ec_private_key ....   Passed    0.05 sec
    3/6 Test #4331: guest_libressl_ec_keys ...........   Passed    0.66 sec
    4/6 Test #4438: guest_libressl3_key_der ..........   Passed    0.03 sec
    5/6 Test #4440: guest_libressl3_pem_keys .........   Passed    0.06 sec
    6/6 Test #4436: guest_libressl3_pkey_context .....   Passed    1.06 sec
    100% tests passed, 0 tests failed out of 6
    
  • Negative control: with 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.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified EC_KEY_get0_private_key_nid_postfix and EC_KEY_set_private_key_nid_postfix signatures and null handling in core/libs/prx/libSceLibreSsl/src/Ec.cpp matching LibreSSL 2.5.4 semantics and ABI
    • Audited memory safety and guest heap allocation/free paths in NewBignum, DuplicateBignum, and EcBignumDeleter ensuring proper wiping (BN_clear_free behavior) and allocation matching malloc_nid_postfix/free_nid_postfix
    • Checked EC_KEY_generate_key_nid_postfix dynamic word buffer reallocation, static data checks, and keypair generation logic with mbedtls
    • Audited DER encoding and decoding updates in core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp, verifying correct range checks, error queue handling, and public key reconstruction
    • Verified documentation of known limitations and behaviors in docs/dev/debt/changes/feat-libressl-ec-private-key.md per AGENTS.md conventions

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5953315151 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5953315151). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T08:48:50Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `4bd5281358`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `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_tests` built cleanly. - **CTest** (`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`): ``` 1/6 Test #4378: guest_libressl3_ec_parameters .... Passed 0.41 sec 2/6 Test #4361: guest_libressl_ec_private_key .... Passed 0.05 sec 3/6 Test #4331: guest_libressl_ec_keys ........... Passed 0.66 sec 4/6 Test #4438: guest_libressl3_key_der .......... Passed 0.03 sec 5/6 Test #4440: guest_libressl3_pem_keys ......... Passed 0.06 sec 6/6 Test #4436: guest_libressl3_pkey_context ..... Passed 1.06 sec 100% tests passed, 0 tests failed out of 6 ``` - **Negative control**: with `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.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified EC_KEY_get0_private_key_nid_postfix and EC_KEY_set_private_key_nid_postfix signatures and null handling in core/libs/prx/libSceLibreSsl/src/Ec.cpp matching LibreSSL 2.5.4 semantics and ABI - Audited memory safety and guest heap allocation/free paths in NewBignum, DuplicateBignum, and EcBignumDeleter ensuring proper wiping (BN_clear_free behavior) and allocation matching malloc_nid_postfix/free_nid_postfix - Checked EC_KEY_generate_key_nid_postfix dynamic word buffer reallocation, static data checks, and keypair generation logic with mbedtls - Audited DER encoding and decoding updates in core/libs/prx/libSceLibreSsl3/src/KeyDer.cpp, verifying correct range checks, error queue handling, and public key reconstruction - Verified documentation of known limitations and behaviors in docs/dev/debt/changes/feat-libressl-ec-private-key.md per AGENTS.md conventions Looks Good To Me
MarcZX10 commented 2026-11-18 11:11:17 +00:00 (Migrated from github.com)

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

Check Result Note
Prepared diff review passed Core EC and DER paths inspected
Reported tests and checks not run Author-reported only
Negative control not run Not independently repeated

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, and review/diff.patch. Inspected changed code in core/libs/prx/libSceLibreSsl/src/Ec.cpp and core/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.json through 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5955453473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-5955453473). Originally posted by [MarcZX10](https://github.com/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 | Check | Result | Note | |---|---|---| | Prepared diff review | passed | Core EC and DER paths inspected | | Reported tests and checks | not run | Author-reported only | | Negative control | not run | Not independently repeated | ## 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`, and `review/diff.patch`. Inspected changed code in `core/libs/prx/libSceLibreSsl/src/Ec.cpp` and `core/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.json` through 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.
ligmaSec commented 2026-12-03 13:25:04 +00:00 (Migrated from github.com)

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 GuestLibreSslEcKeys and GuestLibreSslEcPrivateKey fixtures passed. The separate LibreSSL3 fixtures did not build with this standalone setup.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170652369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11146#pullrequestreview-6170652369). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:25:04Z. **Review:** COMMENTED --- Built the focused checks against the existing Linux runtime. The `GuestLibreSslEcKeys` and `GuestLibreSslEcPrivateKey` fixtures passed. The separate LibreSSL3 fixtures did not build with this standalone setup. AI-assisted: yes.
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/11146:upstream-pr/11146'
git switch 'upstream-pr/11146'

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/11146'
git switch 'upstream-pr/11146'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/11146'
git switch 'upstream-pr/11146'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/11146'
git switch 'main'
git merge --squash 'upstream-pr/11146'
git switch 'main'
git merge --ff-only 'upstream-pr/11146'
git switch 'main'
git merge 'upstream-pr/11146'
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!11146
No description provided.