feat(libSceLibreSsl): implement RSA_generate_key_ex #18396

Merged
SHOnnay merged 8 commits from upstream-pr/18396 into main 2026-11-17 17:39:53 +00:00
SHOnnay commented 2026-11-11 13:23:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SHOnnay on 2026-11-11T13:23:18Z.


What

Implements RSA_generate_key_ex in libSceLibreSsl. It is a port of the library's pinned LibreSSL 2.5.4 sources:

Behaviour, as in 2.5.4:

  • The method's rsa_keygen slot is called when set; otherwise missing components are created with BN_new.
  • Primes have the top two bits set, pass the 2048-prime sieve and get BN_prime_checks_for_size Miller-Rabin rounds.
  • The coprime-to-e loops run, and KEY_SIZE_TOO_SMALL is raised after three equal primes.
  • p > q is enforced by swapping, then d mod (p-1)(q-1), dmp1, dmq1 and iqmp are computed.

Implementation.

  • Uses the library's guest BIGNUM layout (written through BN_bin2bn) and its ErrorQueue with the 2.5.4 reason codes.
  • Arithmetic and Miller-Rabin come from the mbedcrypto the library already links.
  • New src/RsaKeygen.cpp. The stub is removed from Export.cpp, and the include/Api.hpp declaration gets the real signature (LibreSslRsa*, int, Bignum*, void*).

Still throws (recorded in docs/dev/debt/libSceLibreSsl.md):

  • a non-null BN_GENCB
  • an even or negative exponent (2.5.4 never returns for an even one)
  • primes over 8192 bits (the mbedtls limit)

The debt file also records that Miller-Rabin uses mbedtls with host entropy instead of LibreSSL's own code.

Tested

macOS 27 on Apple M1. The registered GuestLibreSslRsa test is a full-build test and was not run: the full build does not run on macOS. A Linux or Windows run is needed.

New test. TestGenerateKey in core/libs/tests/GuestLibreSslRsa.cpp. The test now also links mbedcrypto, to check results independently. It covers:

  • method dispatch and argument forwarding
  • the throw cases
  • the exact BN-then-RSA error codes for 2 and 3 bits
  • 512-bit and 1031-bit keys, and e=1: n=pq, p>q, primality, d·e≡1, the CRT values, an encrypt/decrypt round trip
  • the sieve-survivor property of p and q
  • the deterministic KEY_SIZE_TOO_SMALL for an 18-bit request
  • a static-data BIGNUM failing with RSA/ERR_LIB_BN

Harness. A temporary host harness, not committed, built the unchanged RsaKeygen.cpp, Bignum.cpp, Rsa.cpp, Error.cpp and ErrorQueue.cpp against a host-built mbedtls 3.6.7, with the test code copied verbatim. It passed 8 of 8 repeated runs on x86-64 under Rosetta and on arm64.

Mutation check. All 6 hand mutations failed the harness: wrong phi, weakened sieve, wrong error reason, e not stored, wrong top bits, dropped callback.

Syntax. clang++ -arch x86_64 -fsyntax-only passes on RsaKeygen.cpp, Export.cpp and the test file.

$ python3 tools/check_conventions.py --base upstream/main
All conventions checks passed.
$ python3 core/libs/tests/test_public_headers.py --audit-only
407 libraries, 34229 exports: unique declarations and umbrella coverage verified

Overlap. No open PR implements this export.

  • pr_overlap.py failed closed with 33 unconfirmed PRs. All their diffs were grepped.
  • #11466 and #16688 mention RSA_generate_key_ex only as unchanged stub context.
  • #17299 and #17303 rename only the libSceLibreSsl3 forwarder alias.
  • The libSceLibreSsl3 NID NOsUmPti3g4 already forwards to this export. Whether 4.0.0 RSA objects match the 2.5.4 layout was unverified before this change and remains so.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5260259705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396). Originally posted by [SHOnnay](https://github.com/SHOnnay) on 2026-11-11T13:23:18Z. --- ### What Implements `RSA_generate_key_ex` in libSceLibreSsl. It is a port of the library's pinned LibreSSL 2.5.4 sources: - [rsa_gen.c](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/rsa/rsa_gen.c) - [bn_prime.c](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/bn/bn_prime.c) (`BN_generate_prime_ex`, `probable_prime`) - `bn_rand.c` **Behaviour, as in 2.5.4:** - The method's `rsa_keygen` slot is called when set; otherwise missing components are created with `BN_new`. - Primes have the top two bits set, pass the 2048-prime sieve and get `BN_prime_checks_for_size` Miller-Rabin rounds. - The coprime-to-e loops run, and `KEY_SIZE_TOO_SMALL` is raised after three equal primes. - `p > q` is enforced by swapping, then d mod (p-1)(q-1), dmp1, dmq1 and iqmp are computed. **Implementation.** - Uses the library's guest `BIGNUM` layout (written through `BN_bin2bn`) and its ErrorQueue with the 2.5.4 reason codes. - Arithmetic and Miller-Rabin come from the mbedcrypto the library already links. - New `src/RsaKeygen.cpp`. The stub is removed from `Export.cpp`, and the `include/Api.hpp` declaration gets the real signature `(LibreSslRsa*, int, Bignum*, void*)`. **Still throws** (recorded in `docs/dev/debt/libSceLibreSsl.md`): - a non-null `BN_GENCB` - an even or negative exponent (2.5.4 never returns for an even one) - primes over 8192 bits (the mbedtls limit) The debt file also records that Miller-Rabin uses mbedtls with host entropy instead of LibreSSL's own code. ### Tested macOS 27 on Apple M1. The registered `GuestLibreSslRsa` test is a full-build test and was **not run**: the full build does not run on macOS. A Linux or Windows run is needed. **New test.** `TestGenerateKey` in `core/libs/tests/GuestLibreSslRsa.cpp`. The test now also links `mbedcrypto`, to check results independently. It covers: - method dispatch and argument forwarding - the throw cases - the exact BN-then-RSA error codes for 2 and 3 bits - 512-bit and 1031-bit keys, and e=1: n=pq, p>q, primality, d·e≡1, the CRT values, an encrypt/decrypt round trip - the sieve-survivor property of p and q - the deterministic `KEY_SIZE_TOO_SMALL` for an 18-bit request - a static-data BIGNUM failing with RSA/ERR_LIB_BN **Harness.** A temporary host harness, not committed, built the unchanged `RsaKeygen.cpp`, `Bignum.cpp`, `Rsa.cpp`, `Error.cpp` and `ErrorQueue.cpp` against a host-built mbedtls 3.6.7, with the test code copied verbatim. It passed 8 of 8 repeated runs on x86-64 under Rosetta and on arm64. **Mutation check.** All 6 hand mutations failed the harness: wrong phi, weakened sieve, wrong error reason, e not stored, wrong top bits, dropped callback. **Syntax.** `clang++ -arch x86_64 -fsyntax-only` passes on `RsaKeygen.cpp`, `Export.cpp` and the test file. ```text $ python3 tools/check_conventions.py --base upstream/main All conventions checks passed. $ python3 core/libs/tests/test_public_headers.py --audit-only 407 libraries, 34229 exports: unique declarations and umbrella coverage verified ``` **Overlap.** No open PR implements this export. - `pr_overlap.py` failed closed with 33 unconfirmed PRs. All their diffs were grepped. - #11466 and #16688 mention `RSA_generate_key_ex` only as unchanged stub context. - #17299 and #17303 rename only the libSceLibreSsl3 forwarder alias. - The libSceLibreSsl3 NID `NOsUmPti3g4` already forwards to this export. Whether 4.0.0 RSA objects match the 2.5.4 layout was unverified before this change and remains so. ### 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) - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-11 14:50:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T14:50:40Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 639ab6150a:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: add the '### What' heading of the template
    (pull request): error: [pr-template] Fill in the pull request template: add the '### Tested' heading of the template
    (pull request): error: [pr-template] Fill in the pull request template: add the '### Checklist' heading of the template
    3 findings, 3 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_libressl_rsa_tests built cleanly.
  • CTest (guest_libressl_rsa_private, guest_libressl_rsa_pss, guest_libressl_rsa):
    1/3 Test #3531: guest_libressl_rsa_private .......***Not Run   0.00 sec
    2/3 Test #3532: guest_libressl_rsa_pss ...........***Not Run   0.00 sec
    3/3 Test #3548: guest_libressl_rsa ...............   Passed    1.41 sec
    33% tests passed, 2 tests failed out of 3
    
    The following tests FAILED:
    

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5860623448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396#pullrequestreview-5860623448). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T14:50:40Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `639ab6150a`: - **Conventions**: `tools/check_conventions.py` failed; `git diff --check` clean. ``` (pull request): error: [pr-template] Fill in the pull request template: add the '### What' heading of the template (pull request): error: [pr-template] Fill in the pull request template: add the '### Tested' heading of the template (pull request): error: [pr-template] Fill in the pull request template: add the '### Checklist' heading of the template 3 findings, 3 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_libressl_rsa_tests` built cleanly. - **CTest** (`guest_libressl_rsa_private`, `guest_libressl_rsa_pss`, `guest_libressl_rsa`): ``` 1/3 Test #3531: guest_libressl_rsa_private .......***Not Run 0.00 sec 2/3 Test #3532: guest_libressl_rsa_pss ...........***Not Run 0.00 sec 3/3 Test #3548: guest_libressl_rsa ............... Passed 1.41 sec 33% tests passed, 2 tests failed out of 3 ``` ``` The following tests FAILED: ``` Requesting changes for the points above.
PrivacyOnion commented 2026-11-11 18:43:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:43:17Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 639ab6150a:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl_rsa_tests built cleanly.
  • CTest (guest_libressl_rsa_private, guest_libressl_rsa_pss, guest_libressl_rsa):
    1/3 Test #3532: guest_libressl_rsa_pss ...........   Passed    0.06 sec
    2/3 Test #3531: guest_libressl_rsa_private .......   Passed    0.10 sec
    3/3 Test #3548: guest_libressl_rsa ...............   Passed    1.97 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified AGENTS.md compliance: checked for forbidden comments across all changed files (CMakeLists.txt, Export.cpp, Api.hpp, RsaKeygen.cpp, GuestLibreSslRsa.cpp, docs/dev/debt/libSceLibreSsl.md).
    • Verified error code propagation and queuing: checked BignumBitsTooSmall (0x03FFF075), RsaBignumFailure (0x04FFF003), and RsaKeySizeTooSmall (0x04FFF078) in RsaKeygen.cpp and GuestLibreSslRsa.cpp.
    • Verified memory and bounds safety in RandomOdd, LoadExponent, SmallPrimes, and ProbablePrime against buffer overruns and integer overflow.
    • Verified math correctness for RSA key generation: modulus calculation, Euler totient / order, private exponent inverse modulo order, CRT exponents dmp1/dmq1, and coefficient iqmp (q^-1 mod p).
    • Verified pointer swap semantics when p < q for rsa.p and rsa.q matching LibreSSL 2.5.4 behavior and test coverage.
  • Concerns:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: The return value of Store(rsa.e, exponent, function) is ignored. If rsa->e is pre-allocated with static or insufficient buffer space (e.g. BignumStaticData), BN_bin2bn fails and Store returns false, but BuiltinKeygen continues key generation and returns 1 (success) with an unpopulated or corrupted rsa->e instead of returning fail(). It must be checked: if (!Store(rsa.e, exponent, function)) return fail();
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5863784653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396#pullrequestreview-5863784653). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T18:43:17Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `639ab6150a`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl_rsa_tests` built cleanly. - **CTest** (`guest_libressl_rsa_private`, `guest_libressl_rsa_pss`, `guest_libressl_rsa`): ``` 1/3 Test #3532: guest_libressl_rsa_pss ........... Passed 0.06 sec 2/3 Test #3531: guest_libressl_rsa_private ....... Passed 0.10 sec 3/3 Test #3548: guest_libressl_rsa ............... Passed 1.97 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl/Export.cpp`, `core/libs/prx/libSceLibreSsl/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified AGENTS.md compliance: checked for forbidden comments across all changed files (CMakeLists.txt, Export.cpp, Api.hpp, RsaKeygen.cpp, GuestLibreSslRsa.cpp, docs/dev/debt/libSceLibreSsl.md). - Verified error code propagation and queuing: checked BignumBitsTooSmall (0x03FFF075), RsaBignumFailure (0x04FFF003), and RsaKeySizeTooSmall (0x04FFF078) in RsaKeygen.cpp and GuestLibreSslRsa.cpp. - Verified memory and bounds safety in RandomOdd, LoadExponent, SmallPrimes, and ProbablePrime against buffer overruns and integer overflow. - Verified math correctness for RSA key generation: modulus calculation, Euler totient / order, private exponent inverse modulo order, CRT exponents dmp1/dmq1, and coefficient iqmp (q^-1 mod p). - Verified pointer swap semantics when p < q for rsa.p and rsa.q matching LibreSSL 2.5.4 behavior and test coverage. - **Concerns**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: The return value of Store(rsa.e, exponent, function) is ignored. If rsa->e is pre-allocated with static or insufficient buffer space (e.g. BignumStaticData), BN_bin2bn fails and Store returns false, but BuiltinKeygen continues key generation and returns 1 (success) with an unpopulated or corrupted rsa->e instead of returning fail(). It must be checked: if (!Store(rsa.e, exponent, function)) return fail(); - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-13 19:45:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T19:45:33Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 95a5beaf8b:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl_rsa_tests built cleanly.
  • CTest (guest_libressl_rsa_private, guest_libressl_rsa_sign_errors, guest_libressl_rsa_pss, guest_libressl_rsa):
    1/4 Test #3712: guest_libressl_rsa_sign_errors ...   Passed    0.02 sec
    2/4 Test #3713: guest_libressl_rsa_pss ...........   Passed    0.09 sec
    3/4 Test #3711: guest_libressl_rsa_private .......   Passed    0.15 sec
    4/4 Test #3730: guest_libressl_rsa ...............   Passed    2.26 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified RSA_generate_key_ex_nid_postfix pointer validation for null rsa, null rsa->meth, method keygen dispatch, and callback handling against AGENTS.md debt documentation.
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent validation for null exponent, negative values, and even values, ensuring proper exceptions and NotImplemented_nid_no_patch triggers.
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check bounds and error queue codes (BignumBitsTooSmall = 117, RsaBignumFailure = 3, KeySizeTooSmall = 120) when bits < 2 or primes collide.
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified CRT component calculations (d, dmp1, dmq1, iqmp) and the p > q pointer swap logic against LibreSSL 2.5.4 rsa_gen.c behavior.
    • core/libs/prx/libSceLibreSsl/CMakeLists.txt: Verified build target configurations and library dependencies including mbedcrypto linkage for guest_libressl_rsa_tests.
    • core/libs/tests/GuestLibreSslRsa.cpp: Verified test coverage in TestGenerateKey for dispatch, throw cases, CRT consistency, static buffer failures, and absence of unauthorized code comments under AGENTS.md rules.
  • Concerns:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: In BuiltinKeygen, Store(rsa.e, exponent, function); ignores the boolean return value of Store(). In contrast to all other fields (rsa.p, rsa.q, rsa.n, rsa.d, rsa.dmp1, rsa.dmq1, rsa.iqmp) which check if (!Store(...)) return fail();, if rsa->e has fixed unexpandable storage (e.g., BignumStaticData) or if BN_bin2bn_nid_postfix fails due to memory allocation failure, Store returns false but the error is discarded. Key generation then proceeds through prime generation and returns 1 (success) with rsa->e unwritten or corrupted, instead of returning 0 and queueing RsaBignumFailure (ERR_LIB_RSA / ERR_LIB_BN).
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5897042344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396#pullrequestreview-5897042344). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T19:45:33Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `95a5beaf8b`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl_rsa_tests` built cleanly. - **CTest** (`guest_libressl_rsa_private`, `guest_libressl_rsa_sign_errors`, `guest_libressl_rsa_pss`, `guest_libressl_rsa`): ``` 1/4 Test #3712: guest_libressl_rsa_sign_errors ... Passed 0.02 sec 2/4 Test #3713: guest_libressl_rsa_pss ........... Passed 0.09 sec 3/4 Test #3711: guest_libressl_rsa_private ....... Passed 0.15 sec 4/4 Test #3730: guest_libressl_rsa ............... Passed 2.26 sec 100% tests passed, 0 tests failed out of 4 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl/Export.cpp`, `core/libs/prx/libSceLibreSsl/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified RSA_generate_key_ex_nid_postfix pointer validation for null rsa, null rsa->meth, method keygen dispatch, and callback handling against AGENTS.md debt documentation. - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent validation for null exponent, negative values, and even values, ensuring proper exceptions and NotImplemented_nid_no_patch triggers. - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check bounds and error queue codes (BignumBitsTooSmall = 117, RsaBignumFailure = 3, KeySizeTooSmall = 120) when bits < 2 or primes collide. - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified CRT component calculations (d, dmp1, dmq1, iqmp) and the p > q pointer swap logic against LibreSSL 2.5.4 rsa_gen.c behavior. - core/libs/prx/libSceLibreSsl/CMakeLists.txt: Verified build target configurations and library dependencies including mbedcrypto linkage for guest_libressl_rsa_tests. - core/libs/tests/GuestLibreSslRsa.cpp: Verified test coverage in TestGenerateKey for dispatch, throw cases, CRT consistency, static buffer failures, and absence of unauthorized code comments under AGENTS.md rules. - **Concerns**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: In BuiltinKeygen, Store(rsa.e, exponent, function); ignores the boolean return value of Store(). In contrast to all other fields (rsa.p, rsa.q, rsa.n, rsa.d, rsa.dmp1, rsa.dmq1, rsa.iqmp) which check if (!Store(...)) return fail();, if rsa->e has fixed unexpandable storage (e.g., BignumStaticData) or if BN_bin2bn_nid_postfix fails due to memory allocation failure, Store returns false but the error is discarded. Key generation then proceeds through prime generation and returns 1 (success) with rsa->e unwritten or corrupted, instead of returning 0 and queueing RsaBignumFailure (ERR_LIB_RSA / ERR_LIB_BN). - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-15 21:04:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T21:04:49Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against e46d9f581b:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl_rsa_tests built cleanly.
  • CTest (guest_libressl_rsa_private, guest_libressl_rsa_sign_errors, guest_libressl_rsa_pss, guest_libressl_rsa):
    1/4 Test #3892: guest_libressl_rsa_sign_errors ...   Passed    0.05 sec
    2/4 Test #3891: guest_libressl_rsa_private .......   Passed    0.22 sec
    3/4 Test #3893: guest_libressl_rsa_pss ...........   Passed    0.17 sec
    4/4 Test #3910: guest_libressl_rsa ...............   Passed    6.40 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified RSA_generate_key_ex_nid_postfix pointer validation for null rsa, null rsa->meth, method keygen dispatch, and callback handling against AGENTS.md debt documentation.
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent validation for null exponent, negative values, and even values, ensuring proper exceptions and NotImplemented_nid_no_patch triggers.
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check bounds and error queue codes (BitsTooSmall = 117, RsaLibrary = 4, KeySizeTooSmall = 120) when bits < 2 or three equal primes occur.
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Checked Store() return value handling across rsa.e, rsa.p, rsa.q, rsa.n, rsa.d, rsa.dmp1, rsa.dmq1, and rsa.iqmp in BuiltinKeygen.
    • docs/dev/debt/changes/feat-libressl-rsa-keygen.md: Verified technical debt fragment documents unknown function info, callback/exponent/size limits, and error queue behavior.
  • Concerns:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: In BuiltinKeygen, Store(rsa.e, exponent, function); ignores the boolean return value of Store(). Unlike every other BIGNUM field (rsa.p, rsa.q, rsa.n, rsa.d, rsa.dmp1, rsa.dmq1, rsa.iqmp), which checks if (!Store(...)) return fail();, if rsa->e is pre-populated with a BIGNUM that cannot expand (e.g., BN_FLG_STATIC_DATA) or BN_bin2bn_nid_postfix fails, Store(rsa.e, ...) returns false and the failure is silently ignored. BuiltinKeygen then proceeds to generate primes and returns 1 (success) with rsa->e left unmodified/invalid instead of calling fail() to queue the ERR_LIB_RSA / ERR_LIB_BN error and return 0.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912928033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396#pullrequestreview-5912928033). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T21:04:49Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `e46d9f581b`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl_rsa_tests` built cleanly. - **CTest** (`guest_libressl_rsa_private`, `guest_libressl_rsa_sign_errors`, `guest_libressl_rsa_pss`, `guest_libressl_rsa`): ``` 1/4 Test #3892: guest_libressl_rsa_sign_errors ... Passed 0.05 sec 2/4 Test #3891: guest_libressl_rsa_private ....... Passed 0.22 sec 3/4 Test #3893: guest_libressl_rsa_pss ........... Passed 0.17 sec 4/4 Test #3910: guest_libressl_rsa ............... Passed 6.40 sec 100% tests passed, 0 tests failed out of 4 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl/Export.cpp`, `core/libs/prx/libSceLibreSsl/include/Api.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified RSA_generate_key_ex_nid_postfix pointer validation for null rsa, null rsa->meth, method keygen dispatch, and callback handling against AGENTS.md debt documentation. - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent validation for null exponent, negative values, and even values, ensuring proper exceptions and NotImplemented_nid_no_patch triggers. - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check bounds and error queue codes (BitsTooSmall = 117, RsaLibrary = 4, KeySizeTooSmall = 120) when bits < 2 or three equal primes occur. - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Checked Store() return value handling across rsa.e, rsa.p, rsa.q, rsa.n, rsa.d, rsa.dmp1, rsa.dmq1, and rsa.iqmp in BuiltinKeygen. - docs/dev/debt/changes/feat-libressl-rsa-keygen.md: Verified technical debt fragment documents unknown function info, callback/exponent/size limits, and error queue behavior. - **Concerns**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: In BuiltinKeygen, `Store(rsa.e, exponent, function);` ignores the boolean return value of `Store()`. Unlike every other BIGNUM field (`rsa.p`, `rsa.q`, `rsa.n`, `rsa.d`, `rsa.dmp1`, `rsa.dmq1`, `rsa.iqmp`), which checks `if (!Store(...)) return fail();`, if `rsa->e` is pre-populated with a BIGNUM that cannot expand (e.g., `BN_FLG_STATIC_DATA`) or `BN_bin2bn_nid_postfix` fails, `Store(rsa.e, ...)` returns `false` and the failure is silently ignored. `BuiltinKeygen` then proceeds to generate primes and returns `1` (success) with `rsa->e` left unmodified/invalid instead of calling `fail()` to queue the `ERR_LIB_RSA` / `ERR_LIB_BN` error and return `0`. Requesting changes for the points above.
PrivacyOnion commented 2026-11-17 09:16:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T09:16:09Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 63804d8804:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl_rsa_tests built cleanly.
  • CTest (guest_libressl_rsa):
    1/1 Test #4261: guest_libressl_rsa ...............   Passed    0.57 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp, core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified RSA_generate_key_ex_nid_postfix pointer validation for rsa and rsa->meth, method keygen callback delegation, and BN_GENCB rejection matching debt docs
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent validation for null exponent, malformed top/d pointers, negative values, and even values matching LibreSSL 2.5.4 constraints
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check bounds, small prime table generation, sieve modulo loop, and error queue codes (BitsTooSmall = 117, RsaLibrary = 4, KeySizeTooSmall = 120)
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified Store() return value handling on rsa.n, rsa.d, rsa.p, rsa.q, rsa.dmp1, rsa.dmq1, and rsa.iqmp failure paths
    • docs/dev/debt/changes/feat-libressl-rsa-keygen.md: Verified debt fragment correctly records BN_GENCB, negative/even exponents, mbedtls 8192-bit limits, and ERR_LIB_BN error behavior
  • Concerns:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: In BuiltinKeygen, Store(rsa.e, exponent, function); ignores the boolean return value of Store(). If rsa.e is pre-populated with a static/non-expandable BIGNUM (such as one with BN_FLG_STATIC_DATA) or BN_bin2bn_nid_postfix fails, Store returns false, but execution proceeds, generating primes and returning 1 (success) with rsa.e invalid or unmodified instead of calling if (!Store(rsa.e, exponent, function)) return fail(); to push ERR_LIB_RSA / ERR_LIB_BN to the error queue and return 0.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5935762599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396#pullrequestreview-5935762599). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T09:16:09Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `63804d8804`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl_rsa_tests` built cleanly. - **CTest** (`guest_libressl_rsa`): ``` 1/1 Test #4261: guest_libressl_rsa ............... Passed 0.57 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl/Export.cpp`, `core/libs/prx/libSceLibreSsl/include/Api.hpp`, `core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified RSA_generate_key_ex_nid_postfix pointer validation for rsa and rsa->meth, method keygen callback delegation, and BN_GENCB rejection matching debt docs - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent validation for null exponent, malformed top/d pointers, negative values, and even values matching LibreSSL 2.5.4 constraints - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check bounds, small prime table generation, sieve modulo loop, and error queue codes (BitsTooSmall = 117, RsaLibrary = 4, KeySizeTooSmall = 120) - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified Store() return value handling on rsa.n, rsa.d, rsa.p, rsa.q, rsa.dmp1, rsa.dmq1, and rsa.iqmp failure paths - docs/dev/debt/changes/feat-libressl-rsa-keygen.md: Verified debt fragment correctly records BN_GENCB, negative/even exponents, mbedtls 8192-bit limits, and ERR_LIB_BN error behavior - **Concerns**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp:195: In BuiltinKeygen, `Store(rsa.e, exponent, function);` ignores the boolean return value of `Store()`. If `rsa.e` is pre-populated with a static/non-expandable BIGNUM (such as one with `BN_FLG_STATIC_DATA`) or `BN_bin2bn_nid_postfix` fails, `Store` returns `false`, but execution proceeds, generating primes and returning `1` (success) with `rsa.e` invalid or unmodified instead of calling `if (!Store(rsa.e, exponent, function)) return fail();` to push `ERR_LIB_RSA` / `ERR_LIB_BN` to the error queue and return `0`. Requesting changes for the points above.
PrivacyOnion commented 2026-11-17 17:05:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T17:05:32Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against ca35c34749:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl_rsa_tests built cleanly.
  • CTest (guest_libressl_rsa):
    1/1 Test #4269: guest_libressl_rsa ...............   Passed    0.51 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp, core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified pointer validation for rsa and rsa->meth, delegating to rsa->meth->keygen when set, and rejecting BN_GENCB with NotImplemented_nid_no_patch as documented in debt
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent correctly validates null exponent, malformed top/d, negative exponent, and rejects even exponents matching LibreSSL 2.5.4 constraints
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check thresholds, SmallPrimes sieve loop, bits limits (MBEDTLS_MPI_MAX_SIZE), and exact LibreSSL error codes (BitsTooSmall = 117, KeySizeTooSmall = 120, RsaLibrary = 4, BignumLibrary = 3)
    • core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified Store() return value handling across all allocated fields (rsa.n, rsa.e, rsa.p, rsa.q, rsa.d, rsa.dmp1, rsa.dmq1, rsa.iqmp), properly pushing RsaLibrary / BignumLibrary on conversion or static bignum expansion failure
    • core/libs/tests/GuestLibreSslRsa.cpp: Verified comprehensive test coverage in TestGenerateKey including method dispatch, null/invalid parameter throwing, error queue validation for small bit lengths / small keys, key consistency, prime checks, CRT components, and static buffer allocation failure paths
    • docs/dev/debt/changes/feat-libressl-rsa-keygen.md: Verified debt fragment accurately documents all known gaps (BN_GENCB callback rejection, negative/even exponents, mbedtls 8192-bit limits, error queuing differences) according to AGENTS.md

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5943027959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18396#pullrequestreview-5943027959). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T17:05:32Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `ca35c34749`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl_rsa_tests` built cleanly. - **CTest** (`guest_libressl_rsa`): ``` 1/1 Test #4269: guest_libressl_rsa ............... Passed 0.51 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl/Export.cpp`, `core/libs/prx/libSceLibreSsl/include/Api.hpp`, `core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified pointer validation for rsa and rsa->meth, delegating to rsa->meth->keygen when set, and rejecting BN_GENCB with NotImplemented_nid_no_patch as documented in debt - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified LoadExponent correctly validates null exponent, malformed top/d, negative exponent, and rejects even exponents matching LibreSSL 2.5.4 constraints - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified BuiltinKeygen prime check thresholds, SmallPrimes sieve loop, bits limits (MBEDTLS_MPI_MAX_SIZE), and exact LibreSSL error codes (BitsTooSmall = 117, KeySizeTooSmall = 120, RsaLibrary = 4, BignumLibrary = 3) - core/libs/prx/libSceLibreSsl/src/RsaKeygen.cpp: Verified Store() return value handling across all allocated fields (rsa.n, rsa.e, rsa.p, rsa.q, rsa.d, rsa.dmp1, rsa.dmq1, rsa.iqmp), properly pushing RsaLibrary / BignumLibrary on conversion or static bignum expansion failure - core/libs/tests/GuestLibreSslRsa.cpp: Verified comprehensive test coverage in TestGenerateKey including method dispatch, null/invalid parameter throwing, error queue validation for small bit lengths / small keys, key consistency, prime checks, CRT components, and static buffer allocation failure paths - docs/dev/debt/changes/feat-libressl-rsa-keygen.md: Verified debt fragment accurately documents all known gaps (BN_GENCB callback rejection, negative/even exponents, mbedtls 8192-bit limits, error queuing differences) according to AGENTS.md Looks Good To Me
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!18396
No description provided.