feat(libSceLibreSsl): implement BN_print #16242

Closed
nabil88 wants to merge 1 commit from upstream-pr/16242 into main
nabil88 commented 2026-11-05 22:35:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nabil88 on 2026-11-05T22:35:21Z.


What

BN_print in libSceLibreSsl threw through NotImplemented_nid_no_patch. It now writes the uppercase hexadecimal form with no leading zeros, as LibreSSL 2.5.4 bn_print.c does, returning 0 when a write fails. A null BIGNUM or BIO throws, where LibreSSL dereferences it. The console behavior is not verified.

Tested

Windows, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON:

  • ctest --test-dir build-full -R "guest_libressl_bn" passes guest_libressl_bn, including the new zero, leading-zero, negative and wide-value print checks.
  • python tools/check_conventions.py --base origin/main passes.
  • pr_overlap reports no overlap with any open pull request.

Not tested on a console; the behavior follows the public LibreSSL source, unverified against the console.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5179756108 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16242). Originally posted by [nabil88](https://github.com/nabil88) on 2026-11-05T22:35:21Z. --- ### What `BN_print` in libSceLibreSsl threw through `NotImplemented_nid_no_patch`. It now writes the uppercase hexadecimal form with no leading zeros, as LibreSSL 2.5.4 `bn_print.c` does, returning 0 when a write fails. A null BIGNUM or BIO throws, where LibreSSL dereferences it. The console behavior is not verified. ### Tested Windows, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`: - `ctest --test-dir build-full -R "guest_libressl_bn"` passes `guest_libressl_bn`, including the new zero, leading-zero, negative and wide-value print checks. - `python tools/check_conventions.py --base origin/main` passes. - `pr_overlap` reports no overlap with any open pull request. Not tested on a console; the behavior follows the public LibreSSL source, unverified against the console. ### Checklist - [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
ahmadmuj commented 2026-11-06 09:01:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T09:01:12Z.

Review: COMMENTED


Head 08d6b9b2ca5c3fc3cd76dda3516ffecfc9513755, PR base d9d067f4e0b1025b099d6fe83ad8cae1826d6260. Linux: guest_libressl_bn passes. A separate probe links the actual libSceLibreSsl module. Its negative-zero case fails, passes with a temporary BN_print-only sign correction, then fails after restoration. Other zero, negative-one, positive and wide controls pass throughout.

At Bignum.cpp:320, loaded.neg loses a valid zero sign. Native LibreSSL 2.5.4 BN_hex2bn("-0") creates top=0, neg=1; BN_print returns 1 and writes exactly two bytes, -0. Using the public guest Bignum declaration with live limb storage, this head returns 1 but writes one byte, 0. Both probes check exact bytes, length, return and unchanged input. Could BN_print read the original sign instead of the arithmetic-normalized sign from Load?

This head's own BN_hex2bn normalizes -0 to unsigned zero, so that parser cannot supply the failing input. The probe constructs the source-supported state directly. This is a source compatibility finding, not a console or security claim. Current-main integration is checked for a clean merge only; runtime evidence is from the exact head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5797903364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16242#pullrequestreview-5797903364). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T09:01:12Z. **Review:** COMMENTED --- Head `08d6b9b2ca5c3fc3cd76dda3516ffecfc9513755`, PR base `d9d067f4e0b1025b099d6fe83ad8cae1826d6260`. Linux: `guest_libressl_bn` passes. A separate probe links the actual `libSceLibreSsl` module. Its negative-zero case fails, passes with a temporary BN_print-only sign correction, then fails after restoration. Other zero, negative-one, positive and wide controls pass throughout. At `Bignum.cpp:320`, `loaded.neg` loses a valid zero sign. Native [LibreSSL 2.5.4](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/bn/bn_print.c) `BN_hex2bn("-0")` creates `top=0, neg=1`; `BN_print` returns 1 and writes exactly two bytes, `-0`. Using the public guest `Bignum` declaration with live limb storage, this head returns 1 but writes one byte, `0`. Both probes check exact bytes, length, return and unchanged input. Could BN_print read the original sign instead of the arithmetic-normalized sign from Load? This head's own BN_hex2bn normalizes `-0` to unsigned zero, so that parser cannot supply the failing input. The probe constructs the source-supported state directly. This is a source compatibility finding, not a console or security claim. Current-main integration is checked for a clean merge only; runtime evidence is from the exact head.

Pull request closed

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!16242
No description provided.