feat(libSceLibreSsl): implement ASN.1 integer and string helpers #10005

Merged
AZLisme merged 5 commits from upstream-pr/10005 into main 2026-10-25 10:08:21 +00:00
AZLisme commented 2026-10-23 03:50:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AZLisme on 2026-10-23T03:50:09Z.


What

Implement five missing libSceLibreSsl exports: ASN1_INTEGER_get, ASN1_STRING_data, ASN1_STRING_length, ASN1_STRING_type, and ASN1_STRING_to_UTF8. The integer accessor uses a 64-bit guest long; string accessors preserve the supplied pointer, length and tag. Conversion supports every string tag accepted by the pinned implementation, including embedded NULs, and returns a separately allocated, terminated UTF-8 buffer through guest libc and its application allocator.

Signatures, the 24-byte guest string layout and behavior follow LibreSSL 2.5.4 ASN.1 sources, including asn1.h, a_int.c, asn1_lib.c, a_strex.c, a_mbstr.c and a_utf8.c. Firmware 13.40 reports this version in discussion #8981; console behavior was not independently measured. Nonpositive integer lengths return zero for valid INTEGER tags, as 2.5.4 does.

Malformed encodings and allocation failure still throw until ASN.1 error-queue reporting is implemented; these are recorded in docs/dev/debt/libSceLibreSsl.md. The regression suite keeps successful conversions, argument validation and successful allocator/free ownership coverage without requiring those unfinished error paths to throw. The integer accessor handles the full representable signed range, including negative magnitude 2^63, without signed overflow; larger unrepresentable values remain recorded as debt.

The five exports now have their sole declarations in include/Api.hpp, reached through libSceLibreSsl.hpp. The implementation and tests share its Asn1String record; local export declarations and duplicate layouts are removed. The former int function(void) declarations were unknown-signature placeholders for throwing stubs. The implemented API requires the pinned source’s arguments, pointer returns and 64-bit guest long, so those public declarations are corrected rather than retained. Guest libc allocation/free declarations also come from its canonical header.

Tested

Local Arch Linux x86-64, GCC 16.2.1, CMake 4.4.4, Ninja, Release with BUILD_TESTING=ON: exact head 6098cf2e6463f0a1726c121b5e3616d450c38246, rebased onto dc15ed65375228a0f69c41d7770c4c118adb38f2. Rebuilt the actual runtime libraries and nine focused executables. ctest --test-dir build -R 'libressl|crypto_memcmp' --output-on-failure: 10/10 passed, including both ASN.1 registrations and main's error-queue regression. ctest --test-dir build -R '^public_headers' -j2 --output-on-failure: 65/65 passed. Conventions and whitespace checks pass.

Coverage includes supported conversion tags and Unicode boundaries, embedded NULs, input preservation, accessors, signed integer limits including INT64_MIN, legacy nonpositive lengths, argument validation and successful application allocation followed by guest free. The overlap scanner and manual name/NID audits found no duplicate implementation. The latest refresh checked all 18 listed PR heads, including new ENGINE/init PR #10878 and the updated EC-helper PR #10395; neither duplicates these helpers or introduces a prerequisite.

Full Linux/Windows run 40155070561, attempt 2 is successful for exact head 6098cf2e6463f0a1726c121b5e3616d450c38246 merged onto main 52a8bed576e5c54a7f443728cdf663a080f8f9ed. The fresh Linux checkout/merge log independently verifies both commits.

  • Linux retry: 2,124 passed, 89 expected skips and zero failures. Its workflow skip checker ran and accepted every skip. guest_floating_point passed.
  • Windows original execution: 1,516 passed, 789 expected skips and zero failures; its skip checker accepted every skip. Attempt 2 carries this successful execution forward; Windows did not rerun.
  • All 10 LibreSSL/crypto tests and 65 public-header checks passed on both platforms.

The first Linux attempt failed the intermittent guest_floating_point assertion, which also reproduced on an isolated build of the exact base without this PR's changes. The base-reproduction evidence remains recorded; the successful retry does not establish or fix its underlying cause. The ASN.1 patch is unchanged.

Earlier run 40151824506 passed both configured platform suites for previous head 454f66248dd919868c706aa599af34fe039b5f1c; it does not qualify this rebase. macOS, PS5 and titles were not tested. No GPU code changed.

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

Overlap and rebase coordination

No prerequisite is required. As proposed by its author, draft #10418 will follow #10005 and rebase afterward. If a shared branch lands first, rebase while preserving the union of library sources, focused tests and Windows PATH entries; remove only the five throwing declarations replaced here. Keep independent debt entries and recount remaining throwing exports from the resulting source. Rerun relevant builds, focused tests, conventions and overlap checks before updating with --force-with-lease. This rebase preserved main's AES, DES, X509 error-string, RAND/CRYPTO runtime and ERR queue implementations, regression targets and debt entries; the reconciled pending-export count is 348.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4977526082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10005). Originally posted by [AZLisme](https://github.com/AZLisme) on 2026-10-23T03:50:09Z. --- ### What Implement five missing `libSceLibreSsl` exports: `ASN1_INTEGER_get`, `ASN1_STRING_data`, `ASN1_STRING_length`, `ASN1_STRING_type`, and `ASN1_STRING_to_UTF8`. The integer accessor uses a 64-bit guest `long`; string accessors preserve the supplied pointer, length and tag. Conversion supports every string tag accepted by the pinned implementation, including embedded NULs, and returns a separately allocated, terminated UTF-8 buffer through guest libc and its application allocator. Signatures, the 24-byte guest string layout and behavior follow [LibreSSL 2.5.4 ASN.1 sources](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/asn1), including `asn1.h`, `a_int.c`, `asn1_lib.c`, `a_strex.c`, `a_mbstr.c` and `a_utf8.c`. Firmware 13.40 reports this version in [discussion #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214); console behavior was not independently measured. Nonpositive integer lengths return zero for valid INTEGER tags, as 2.5.4 does. Malformed encodings and allocation failure still throw until ASN.1 error-queue reporting is implemented; these are recorded in `docs/dev/debt/libSceLibreSsl.md`. The regression suite keeps successful conversions, argument validation and successful allocator/free ownership coverage without requiring those unfinished error paths to throw. The integer accessor handles the full representable signed range, including negative magnitude `2^63`, without signed overflow; larger unrepresentable values remain recorded as debt. The five exports now have their sole declarations in `include/Api.hpp`, reached through `libSceLibreSsl.hpp`. The implementation and tests share its `Asn1String` record; local export declarations and duplicate layouts are removed. The former `int function(void)` declarations were unknown-signature placeholders for throwing stubs. The implemented API requires the pinned source’s arguments, pointer returns and 64-bit guest `long`, so those public declarations are corrected rather than retained. Guest libc allocation/free declarations also come from its canonical header. ### Tested Local Arch Linux x86-64, GCC 16.2.1, CMake 4.4.4, Ninja, Release with `BUILD_TESTING=ON`: exact head `6098cf2e6463f0a1726c121b5e3616d450c38246`, rebased onto `dc15ed65375228a0f69c41d7770c4c118adb38f2`. Rebuilt the actual runtime libraries and nine focused executables. `ctest --test-dir build -R 'libressl|crypto_memcmp' --output-on-failure`: **10/10 passed**, including both ASN.1 registrations and main's error-queue regression. `ctest --test-dir build -R '^public_headers' -j2 --output-on-failure`: **65/65 passed**. Conventions and whitespace checks pass. Coverage includes supported conversion tags and Unicode boundaries, embedded NULs, input preservation, accessors, signed integer limits including `INT64_MIN`, legacy nonpositive lengths, argument validation and successful application allocation followed by guest `free`. The overlap scanner and manual name/NID audits found no duplicate implementation. The latest refresh checked all 18 listed PR heads, including new ENGINE/init PR #10878 and the updated EC-helper PR #10395; neither duplicates these helpers or introduces a prerequisite. [Full Linux/Windows run 40155070561, attempt 2](https://github.com/boykopovar/AnyPS5/actions/runs/40155070561) is **successful** for exact head `6098cf2e6463f0a1726c121b5e3616d450c38246` merged onto main `52a8bed576e5c54a7f443728cdf663a080f8f9ed`. The fresh Linux checkout/merge log independently verifies both commits. - [Linux retry](https://github.com/boykopovar/AnyPS5/actions/runs/40155070561/job/121065174596): **2,124 passed**, 89 expected skips and zero failures. Its workflow skip checker ran and accepted every skip. `guest_floating_point` passed. - [Windows original execution](https://github.com/boykopovar/AnyPS5/actions/runs/40155070561/job/121054630111): **1,516 passed**, 789 expected skips and zero failures; its skip checker accepted every skip. Attempt 2 carries this successful execution forward; Windows did not rerun. - All **10 LibreSSL/crypto tests and 65 public-header checks passed on both platforms**. The first Linux attempt failed the intermittent `guest_floating_point` assertion, which also reproduced on an isolated build of the exact base without this PR's changes. The [base-reproduction evidence](https://github.com/boykopovar/AnyPS5/pull/10005#issuecomment-6392900122) remains recorded; the successful retry does not establish or fix its underlying cause. The ASN.1 patch is unchanged. [Earlier run 40151824506](https://github.com/boykopovar/AnyPS5/actions/runs/40151824506) passed both configured platform suites for previous head `454f66248dd919868c706aa599af34fe039b5f1c`; it does not qualify this rebase. macOS, PS5 and titles were not tested. No GPU code changed. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 ### Overlap and rebase coordination No prerequisite is required. As proposed by its author, draft #10418 will follow #10005 and rebase afterward. If a shared branch lands first, rebase while preserving the union of library sources, focused tests and Windows PATH entries; remove only the five throwing declarations replaced here. Keep independent debt entries and recount remaining throwing exports from the resulting source. Rerun relevant builds, focused tests, conventions and overlap checks before updating with `--force-with-lease`. This rebase preserved main's AES, DES, X509 error-string, RAND/CRYPTO runtime and ERR queue implementations, regression targets and debt entries; the reconciled pending-export count is 348.
MarcZX10 commented 2026-10-23 04:33:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:33:49Z.

Review: CHANGES_REQUESTED


I found a mismatch between the implementation and its own new regression. In core/libs/prx/libSceLibreSsl/src/Asn1.cpp, ASN1_INTEGER_get_nid_postfix rejects length > 8 but does not reject negative lengths. For the test case String value{-1, 2, data, 0}, the loop executes zero times, magnitude stays 0, and the function returns 0; Integers() asserts that this input returns -1. LibreSSL 2.5.4 also explicitly rejects aint->length < 0 in ASN1_INTEGER_get_int64 before decoding. Please add the negative-length check and rerun guest_libressl_asn1_tests and the focused test set; the reported 5/5 result should then be reconciled with the exact current source/head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623926905 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10005#pullrequestreview-5623926905). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T04:33:49Z. **Review:** CHANGES_REQUESTED --- I found a mismatch between the implementation and its own new regression. In `core/libs/prx/libSceLibreSsl/src/Asn1.cpp`, `ASN1_INTEGER_get_nid_postfix` rejects `length > 8` but does not reject negative lengths. For the test case `String value{-1, 2, data, 0}`, the loop executes zero times, `magnitude` stays 0, and the function returns 0; `Integers()` asserts that this input returns -1. LibreSSL 2.5.4 also explicitly rejects `aint->length < 0` in `ASN1_INTEGER_get_int64` before decoding. Please add the negative-length check and rerun `guest_libressl_asn1_tests` and the focused test set; the reported 5/5 result should then be reconciled with the exact current source/head.
MarcZX10 commented 2026-10-23 04:41:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:41:21Z.

Review: APPROVED


The updated exact head 1ba3d6defa37205b5149c33fd01ac0d0b47f7c47 resolves my earlier negative-length finding. The new length <= 0 guard avoids reading invalid data for nonpositive lengths, and the expanded regression covers INT32_MIN, -8, -1 and zero with both integer tags and null/valid/inaccessible data pointers. I also verified the version distinction in the cited source: LibreSSL 2.5.4 ASN1_INTEGER_get loops zero times for a negative length and returns 0, while the later ASN1_INTEGER_get_int64 explicitly rejects negative lengths. The implementation and updated tests now match the 2.5.4 contract the PR documents.

The author reports the exact-head ASN.1 tests and focused suite passing 5/5, plus conventions and whitespace checks; the hosted conventions check now passes. I did not run the C++ test executable locally in this session. My earlier request for changes applied to the superseded head and is resolved by this update.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623968386 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10005#pullrequestreview-5623968386). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T04:41:21Z. **Review:** APPROVED --- The updated exact head `1ba3d6defa37205b5149c33fd01ac0d0b47f7c47` resolves my earlier negative-length finding. The new `length <= 0` guard avoids reading invalid data for nonpositive lengths, and the expanded regression covers INT32_MIN, -8, -1 and zero with both integer tags and null/valid/inaccessible data pointers. I also verified the version distinction in the cited source: LibreSSL 2.5.4 `ASN1_INTEGER_get` loops zero times for a negative length and returns 0, while the later `ASN1_INTEGER_get_int64` explicitly rejects negative lengths. The implementation and updated tests now match the 2.5.4 contract the PR documents. The author reports the exact-head ASN.1 tests and focused suite passing 5/5, plus conventions and whitespace checks; the hosted conventions check now passes. I did not run the C++ test executable locally in this session. My earlier request for changes applied to the superseded head and is resolved by this update.
MarcZX10 commented 2026-10-23 23:15:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T23:15:52Z.

Review: CHANGES_REQUESTED


One remaining signed-boundary mismatch in ASN1_INTEGER_get_nid_postfix: the magnitude guard rejects 0x8000000000000000 before the negative tag can produce INT64_MIN. This is a valid 8-byte negative ASN.1 INTEGER magnitude in the representation used here. The pinned LibreSSL 2.5.4 ASN1_INTEGER_get accumulates through sizeof(long) and applies the negative tag afterward; it has no positive-magnitude guard at this point: github.com/libressl/openbsd@2e2c612066/src/lib/libcrypto/asn1/a_int.c (L1778-L1825). Please handle the negative 2^63 boundary with unsigned arithmetic before rejecting other unrepresentable magnitudes, and add a regression using bytes {0x80, 0, 0, 0, 0, 0, 0, 0}, length 8 and type 0x102, expecting INT64_MIN. The existing positive maximum test does not cover this boundary. I have not run the project test executable locally; this is a source and arithmetic review. The PR also currently reports a conflict with main in the debt file per the maintainer’s latest comment, so preserve both entries when rebasing.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5635424120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10005#pullrequestreview-5635424120). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T23:15:52Z. **Review:** CHANGES_REQUESTED --- One remaining signed-boundary mismatch in `ASN1_INTEGER_get_nid_postfix`: the magnitude guard rejects `0x8000000000000000` before the negative tag can produce `INT64_MIN`. This is a valid 8-byte negative ASN.1 INTEGER magnitude in the representation used here. The pinned LibreSSL 2.5.4 `ASN1_INTEGER_get` accumulates through `sizeof(long)` and applies the negative tag afterward; it has no positive-magnitude guard at this point: https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/asn1/a_int.c#L1778-L1825. Please handle the negative `2^63` boundary with unsigned arithmetic before rejecting other unrepresentable magnitudes, and add a regression using bytes `{0x80, 0, 0, 0, 0, 0, 0, 0}`, length 8 and type `0x102`, expecting `INT64_MIN`. The existing positive maximum test does not cover this boundary. I have not run the project test executable locally; this is a source and arithmetic review. The PR also currently reports a conflict with main in the debt file per the maintainer’s latest comment, so preserve both entries when rebasing.
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!10005
No description provided.