fix(libSceLibreSsl): report why RSA_sign fails #16865

Merged
AlexWhitehouse merged 1 commit from upstream-pr/16865 into main 2026-11-11 23:42:56 +00:00
AlexWhitehouse commented 2026-11-07 19:18:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T19:18:12Z.


What

libSceLibreSsl RSA_sign (NID HohNCzDzBW0) returned 0 on its early failures without queueing an error, so a caller's ERR_get_error saw nothing or an older, unrelated error. This PR makes each implemented failure branch queue what LibreSSL 2.5.4's rsa_sign.c queues through RSAerror (library RSA, function 0xfff). It follows my #16649 (EVP_DecryptFinal_ex) and #16741 (BN_mod_inverse).

Failure Reason
NID_md5_sha1 with a digest length other than 36 131, RSA_R_INVALID_MESSAGE_LENGTH
negative algorithm type (OBJ_nid2obj returns NULL) 117, RSA_R_UNKNOWN_ALGORITHM_TYPE
NID_undef, whose OID has length 0 116, RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD
encoded DigestInfo or MD5+SHA1 larger than RSA_size - RSA_PKCS1_PADDING_SIZE 112, RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY
  • OBJ error: for a negative type, the OBJ unknown-NID error that OBJ_nid2obj queues first, when the added-object table exists, is kept ahead of the RSA error.
  • Unchanged:
    • custom rsa_sign methods and RSA_private_encrypt callbacks keep their own result, output and errors, with no extra RSA_sign error, as upstream;
    • positive algorithm types outside the implemented digest table still throw;
    • RSA_verify isn't touched.
  • Allocation failure: encoding uses a host vector, so allocation failure still throws instead of queueing ERR_R_MALLOC_FAILURE. The new debt entry records this.

Tested

  • New test: guest_libressl_rsa_sign_errors (core/libs/tests/GuestLibreSslRsaSignErrors.cpp) queues a sentinel error before each call.
    • Failure branches: each one checks the queue order (sentinel, then any OBJ error, then the RSA reason, then empty). It also checks that the signature buffer and *siglen are left untouched.
    • Object types: NID_undef, and negative types with and without an added-object table (made with OBJ_create).
    • Callbacks: successful and failing RSA_private_encrypt callbacks and custom rsa_sign methods queue no extra error.
    • Throws: an unsupported digest type still throws.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, every failure branch fails its assertion with RSA_sign error 0x0 expected RSA/fff/<reason>;
    • with this PR, guest_libressl_rsa_sign_errors, guest_libressl_rsa, guest_libressl_rsa_private and guest_libressl_rsa_pss pass 4/4.
  • Windows 11: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):
    • the same four tests pass at 37c6f9b6d9, with no compiler warnings in the changed files;
    • with main's Rsa.cpp, guest_libressl_rsa_sign_errors fails with RSA_sign error 0x0 expected RSA/fff/131.
  • Mutation check: removing the reason-131 error fails its assertion.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • python3 tools/pr_overlap.py --branch fix/libscelibressl-rsa-sign-errors: no confirmed overlap. The tool couldn't compare these PRs because they conflict with main, so I read their diffs by hand:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5205035800 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16865). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-07T19:18:12Z. --- ### What libSceLibreSsl `RSA_sign` (NID `HohNCzDzBW0`) returned 0 on its early failures without queueing an error, so a caller's `ERR_get_error` saw nothing or an older, unrelated error. This PR makes each implemented failure branch queue what LibreSSL 2.5.4's [`rsa_sign.c`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/rsa/rsa_sign.c) queues through `RSAerror` (library RSA, function `0xfff`). It follows my #16649 (`EVP_DecryptFinal_ex`) and #16741 (`BN_mod_inverse`). | Failure | Reason | |---|---| | `NID_md5_sha1` with a digest length other than 36 | 131, `RSA_R_INVALID_MESSAGE_LENGTH` | | negative algorithm type (`OBJ_nid2obj` returns NULL) | 117, `RSA_R_UNKNOWN_ALGORITHM_TYPE` | | `NID_undef`, whose OID has length 0 | 116, `RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD` | | encoded DigestInfo or MD5+SHA1 larger than `RSA_size - RSA_PKCS1_PADDING_SIZE` | 112, `RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY` | - **OBJ error:** for a negative type, the OBJ unknown-NID error that [`OBJ_nid2obj`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/objects/obj_dat.c) queues first, when the added-object table exists, is kept ahead of the RSA error. - **Unchanged:** - custom `rsa_sign` methods and `RSA_private_encrypt` callbacks keep their own result, output and errors, with no extra `RSA_sign` error, as upstream; - positive algorithm types outside the implemented digest table still throw; - `RSA_verify` isn't touched. - **Allocation failure:** encoding uses a host vector, so allocation failure still throws instead of queueing `ERR_R_MALLOC_FAILURE`. The new debt entry records this. ### Tested - **New test:** `guest_libressl_rsa_sign_errors` (`core/libs/tests/GuestLibreSslRsaSignErrors.cpp`) queues a sentinel error before each call. - **Failure branches:** each one checks the queue order (sentinel, then any OBJ error, then the RSA reason, then empty). It also checks that the signature buffer and `*siglen` are left untouched. - **Object types:** `NID_undef`, and negative types with and without an added-object table (made with `OBJ_create`). - **Callbacks:** successful and failing `RSA_private_encrypt` callbacks and custom `rsa_sign` methods queue no extra error. - **Throws:** an unsupported digest type still throws. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, every failure branch fails its assertion with `RSA_sign error 0x0 expected RSA/fff/<reason>`; - with this PR, `guest_libressl_rsa_sign_errors`, `guest_libressl_rsa`, `guest_libressl_rsa_private` and `guest_libressl_rsa_pss` pass 4/4. - **Windows 11:** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): - the same four tests pass at 37c6f9b6d9, with no compiler warnings in the changed files; - with `main`'s `Rsa.cpp`, `guest_libressl_rsa_sign_errors` fails with `RSA_sign error 0x0 expected RSA/fff/131`. - **Mutation check:** removing the reason-131 error fails its assertion. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **`python3 tools/pr_overlap.py --branch fix/libscelibressl-rsa-sign-errors`:** no confirmed overlap. The tool couldn't compare these PRs because they conflict with `main`, so I read their diffs by hand: - #10508 and #14115 (object lookups); - #11466 (older RSA/EC work, whose RSA test hunks this PR avoids by using a new test file); - #13266, #13285, #13546, #13547 and #13877 (X509); - #15480 and #16242 (BIGNUM printing); - #15994 (OCSP); - #16241 (ASN.1 printing); - #14212 (debt formatting). None changes `RSA_sign`. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!16865
No description provided.