feat(libSceLibreSsl3): implement d2i_ECParameters #19134

Merged
MatteoSid merged 5 commits from upstream-pr/19134 into main 2026-11-15 22:38:21 +00:00
MatteoSid commented 2026-11-12 21:04:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MatteoSid on 2026-11-12T21:04:21Z.


What

Implements d2i_ECParameters in libSceLibreSsl3 (NID hWwis8FUZVQ), following LibreSSL 4.0.0's d2i_ECParameters, d2i_ECPKParameters and ec_asn1_pkparameters2group, and the ECPKPARAMETERS CHOICE decode in tasn_dec.c:

  • a null in or *in queues EC ERR_R_PASSED_NULL_PARAMETER and returns null;
  • a null a or *a gets a new key from EC_KEY_new; otherwise *a is reused;
  • a namedCurve OID is looked up with libSceLibreSsl3's OBJ_obj2nid order. A NID in the 4.0.0 curve_list gets a group from libSceLibreSsl's EC_GROUP_new_by_curve_name, flagged OPENSSL_EC_NAMED_CURVE; it replaces the key's group, *a is set and the key is returned;
  • any other OID queues EC_R_UNKNOWN_GROUP (not for NID 0, as EC_GROUP_new_by_curve_name returns early there), EC_R_EC_GROUP_NEW_BY_NAME_FAILURE, EC_R_PKPARAMETERS2GROUP_FAILURE and ERR_R_EC_LIB; implicitlyCA (NULL) queues the last two. Both have already advanced *in past the element, as upstream;
  • malformed DER queues the ASN1 reasons of asn1_check_tag, asn1_d2i_primitive_content, c2i_ASN1_OBJECT_cbs and the CHOICE (BAD_OBJECT_HEADER, TOO_LONG, TYPE_NOT_PRIMITIVE, SEQUENCE_NOT_CONSTRUCTED, NULL_IS_WRONG_LENGTH, INVALID_OBJECT_ENCODING, NO_MATCHING_CHOICE_TYPE), each followed by the same number of ERR_R_NESTED_ASN1_ERROR as upstream, then EC_R_D2I_ECPKPARAMETERS_FAILURE and ERR_R_EC_LIB; a negative len queues only the last two. *in is left alone. BER is accepted as upstream (der_mode 0): high tag number form, long-form and non-minimal lengths;
  • on any failure a key created by the call is freed; a caller's *a is left unchanged, group included.

Explicit curve parameters (a SEQUENCE in the CHOICE) throw NotImplemented_nid_no_patch once their header is valid: libSceLibreSsl's EcGroup holds a named curve and rebuilds the mbedtls group from it (EC_POINT_mul), so an arbitrary curve cannot be represented. Curves in the 4.0.0 list that mbedtls lacks (secp112r1 to secp160r2, prime192v2/v3, prime239v1-3, wap-wsg wtls6-9/12, the other brainpool curves, FRP256v1) throw in libSceLibreSsl's EC_GROUP_new_by_curve_name. Binary curves such as sect163k1, which 4.0.0 no longer lists, return LibreSSL's error instead of reaching that throw.

Reachability: the title passes the DER buffer; the key it gets back works with the implemented EC_KEY_generate_key, EC_KEY_check_key, ECDSA_sign, ECDSA_verify, ECDSA_size and o2i_ECPublicKey, all exported by libSceLibreSsl3. Supported curves: prime192v1, prime256v1, secp192k1, secp224k1, secp224r1, secp256k1, secp384r1, secp521r1, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1.

src/EcAsn1.cpp now follows the control flow of tasn_dec.c, asn1_lib.c (header parsing) and a_object.c (OID validation) as well as ec_asn1.c, so it carries their notices too. Gaps, in a new debt entry added by the fragment docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md (#17217): the explicit-parameter and mbedtls-curve throws above; errors are queued without file, line or the Field=…, Type=… data; nothing is checked on the console. Export.cpp goes from 32 to 31 NotImplemented_nid_no_patch stubs on current main.

Tested

Head 3f7437407e only adds a clean merge of main 6a86d4d1a9c and moves the debt entry to the fragment; tools/debt_fold.py --check passes on it.

Linux (Ubuntu 24.04 container, GCC 13.3), configure with -DBUILD_TESTING=ON, Release, on head 7c2f281b2e, which merges main 99caf32535 (after #19063) into 21e84cf88d: built every LibreSSL test target and the patched .prx files. ctest -R 'libressl|libre_ssl|crypto_memcmp|public_headers' passes 218 of 218, including guest_libressl3_ec_parameters, guest_libressl3_ec_public_key and #19063's guest_libressl3_x509_store_context and guest_libressl_x509_store_context. The merge only resolves the Export.cpp conflict with #19063 by removing both stubs. The earlier run on db42ae7bca (based on a221a742da) passed 215 of 215, and the mutation results below are from that head.

Windows: JJenkx ran guest_libressl3_ec_parameters on the earlier head 21e84cf88d merged onto main (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped (comment). 21e84cf88d only adds the source-pin comment line at the top of src/EcAsn1.cpp to the tested db42ae7bca.

The new guest_libressl3_ec_parameters uses DER from OpenSSL 3.0.2 openssl ecparam -name <curve> -outform DER and checks:

  • each of the 11 supported curves, with a NULL after it in the buffer: the group's NID, EC_GROUP_get_degree, the OPENSSL_EC_NAMED_CURVE flag, *in advanced past the OID only, an empty error queue, then EC_KEY_generate_key, EC_KEY_check_key, ECDSA_sign and ECDSA_verify (and a failed verify on a changed digest);
  • BER headers (high tag number form, one- and two-byte long-form lengths) decode P-256;
  • *a == nullptr is filled; a P-384 key passed in *a is the object returned with a P-256 group, then takes the RFC 6979 A.2.5 public key through o2i_ECPublicKey and passes EC_KEY_check_key; a key from EC_KEY_new gets its group;
  • every failure is run with a null a, a null *a and a P-384 key in *a, checking the exact error queue, *in, that *a and its group are unchanged and that the key still signs and verifies: OID 1.2.3.4 (NID 0), sha256's OID, sect163k1, 05 00 and 05 81 00; empty input, truncated high tag, missing length, indefinite length on a primitive, 0xff length octet (also followed by 127 zero bytes), truncated long-form length, lengths past the buffer for OBJECT and SEQUENCE, INTEGER, context-specific [0] and [6] tags, constructed OBJECT and NULL (definite and indefinite), empty OID, an arc starting with 0x80, an unterminated arc, a non-empty NULL, a primitive SEQUENCE and a negative length;
  • a null in and a null *in queue exactly 0x10fff043 and leave the key alone.

Every one of these 24 mutations makes the test fail: no OPENSSL_EC_NAMED_CURVE flag, *in not advanced or advanced over the whole buffer, EC_R_UNKNOWN_GROUP also for NID 0, calling EC_GROUP_new_by_curve_name for NIDs outside the 4.0.0 list, two instead of three nested errors after a header error, a nested error after NO_MATCHING_CHOICE_TYPE, the tag class ignored, an unterminated arc or a leading 0x80 octet accepted, a constructed OBJECT, an indefinite primitive, a length past the buffer, a 0xff length octet or a non-empty NULL accepted, a primitive SEQUENCE reaching the explicit-parameter throw, the high tag number form rejected, *a never reused, *a not set, a null input queuing the malloc reason, a negative length decoded, implicitlyCA queuing the by-name failure, and a missing ERR_R_EC_LIB or EC_R_D2I_ECPKPARAMETERS_FAILURE. nm -D on the patched libSceLibreSsl3.prx lists hWwis8FUZVQ. tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch reports only #19063 (see below). The 15 open PRs it could not compare because they conflict with main were checked by hand: none changes d2i_ECParameters or EcAsn1.cpp, and none has a hunk next to the Export.cpp stub, the Api.hpp declaration, the new CMakeLists.txt block (after the EC_KEY_set_asn1_flag test block) or the new debt entry (after o2i_ECPublicKey's). No title tested.

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:5285179147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19134). Originally posted by [MatteoSid](https://github.com/MatteoSid) on 2026-11-12T21:04:21Z. --- ### What Implements `d2i_ECParameters` in libSceLibreSsl3 (NID `hWwis8FUZVQ`), following LibreSSL 4.0.0's [`d2i_ECParameters`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ec_asn1.c#L1245-L1273), [`d2i_ECPKParameters` and `ec_asn1_pkparameters2group`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ec_asn1.c#L976-L1035), and the `ECPKPARAMETERS` CHOICE decode in [`tasn_dec.c`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/asn1/tasn_dec.c#L641-L733): - a null `in` or `*in` queues `EC` `ERR_R_PASSED_NULL_PARAMETER` and returns null; - a null `a` or `*a` gets a new key from `EC_KEY_new`; otherwise `*a` is reused; - a namedCurve OID is looked up with libSceLibreSsl3's `OBJ_obj2nid` order. A NID in the 4.0.0 [`curve_list`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/ec/ec_curve.c#L2442-L2457) gets a group from libSceLibreSsl's `EC_GROUP_new_by_curve_name`, flagged `OPENSSL_EC_NAMED_CURVE`; it replaces the key's group, `*a` is set and the key is returned; - any other OID queues `EC_R_UNKNOWN_GROUP` (not for NID 0, as `EC_GROUP_new_by_curve_name` returns early there), `EC_R_EC_GROUP_NEW_BY_NAME_FAILURE`, `EC_R_PKPARAMETERS2GROUP_FAILURE` and `ERR_R_EC_LIB`; implicitlyCA (`NULL`) queues the last two. Both have already advanced `*in` past the element, as upstream; - malformed DER queues the `ASN1` reasons of `asn1_check_tag`, `asn1_d2i_primitive_content`, `c2i_ASN1_OBJECT_cbs` and the CHOICE (`BAD_OBJECT_HEADER`, `TOO_LONG`, `TYPE_NOT_PRIMITIVE`, `SEQUENCE_NOT_CONSTRUCTED`, `NULL_IS_WRONG_LENGTH`, `INVALID_OBJECT_ENCODING`, `NO_MATCHING_CHOICE_TYPE`), each followed by the same number of `ERR_R_NESTED_ASN1_ERROR` as upstream, then `EC_R_D2I_ECPKPARAMETERS_FAILURE` and `ERR_R_EC_LIB`; a negative `len` queues only the last two. `*in` is left alone. BER is accepted as upstream (`der_mode` 0): high tag number form, long-form and non-minimal lengths; - on any failure a key created by the call is freed; a caller's `*a` is left unchanged, group included. Explicit curve parameters (a `SEQUENCE` in the CHOICE) throw `NotImplemented_nid_no_patch` once their header is valid: libSceLibreSsl's `EcGroup` holds a named curve and rebuilds the mbedtls group from it (`EC_POINT_mul`), so an arbitrary curve cannot be represented. Curves in the 4.0.0 list that mbedtls lacks (secp112r1 to secp160r2, prime192v2/v3, prime239v1-3, wap-wsg wtls6-9/12, the other brainpool curves, FRP256v1) throw in libSceLibreSsl's `EC_GROUP_new_by_curve_name`. Binary curves such as sect163k1, which 4.0.0 no longer lists, return LibreSSL's error instead of reaching that throw. Reachability: the title passes the DER buffer; the key it gets back works with the implemented `EC_KEY_generate_key`, `EC_KEY_check_key`, `ECDSA_sign`, `ECDSA_verify`, `ECDSA_size` and `o2i_ECPublicKey`, all exported by libSceLibreSsl3. Supported curves: prime192v1, prime256v1, secp192k1, secp224k1, secp224r1, secp256k1, secp384r1, secp521r1, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1. `src/EcAsn1.cpp` now follows the control flow of `tasn_dec.c`, `asn1_lib.c` (header parsing) and `a_object.c` (OID validation) as well as `ec_asn1.c`, so it carries their notices too. Gaps, in a new debt entry added by the fragment [`docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md`](https://github.com/MatteoSid/AnyPS5/blob/feat/libressl3-d2i-ecparameters/docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md) (#17217): the explicit-parameter and mbedtls-curve throws above; errors are queued without file, line or the `Field=…, Type=…` data; nothing is checked on the console. `Export.cpp` goes from 32 to 31 `NotImplemented_nid_no_patch` stubs on current `main`. ### Tested Head `3f7437407e` only adds a clean merge of `main` `6a86d4d1a9c` and moves the debt entry to the fragment; `tools/debt_fold.py --check` passes on it. Linux (Ubuntu 24.04 container, GCC 13.3), configure with `-DBUILD_TESTING=ON`, Release, on head `7c2f281b2e`, which merges `main` `99caf32535` (after #19063) into `21e84cf88d`: built every LibreSSL test target and the patched `.prx` files. `ctest -R 'libressl|libre_ssl|crypto_memcmp|public_headers'` passes 218 of 218, including `guest_libressl3_ec_parameters`, `guest_libressl3_ec_public_key` and #19063's `guest_libressl3_x509_store_context` and `guest_libressl_x509_store_context`. The merge only resolves the `Export.cpp` conflict with #19063 by removing both stubs. The earlier run on `db42ae7bca` (based on `a221a742da`) passed 215 of 215, and the mutation results below are from that head. Windows: JJenkx ran `guest_libressl3_ec_parameters` on the earlier head `21e84cf88d` merged onto `main` (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped ([comment](https://github.com/boykopovar/AnyPS5/pull/19134#issuecomment-6838456375)). `21e84cf88d` only adds the source-pin comment line at the top of `src/EcAsn1.cpp` to the tested `db42ae7bca`. The new `guest_libressl3_ec_parameters` uses DER from OpenSSL 3.0.2 `openssl ecparam -name <curve> -outform DER` and checks: - each of the 11 supported curves, with a `NULL` after it in the buffer: the group's NID, `EC_GROUP_get_degree`, the `OPENSSL_EC_NAMED_CURVE` flag, `*in` advanced past the OID only, an empty error queue, then `EC_KEY_generate_key`, `EC_KEY_check_key`, `ECDSA_sign` and `ECDSA_verify` (and a failed verify on a changed digest); - BER headers (high tag number form, one- and two-byte long-form lengths) decode P-256; - `*a == nullptr` is filled; a P-384 key passed in `*a` is the object returned with a P-256 group, then takes the RFC 6979 A.2.5 public key through `o2i_ECPublicKey` and passes `EC_KEY_check_key`; a key from `EC_KEY_new` gets its group; - every failure is run with a null `a`, a null `*a` and a P-384 key in `*a`, checking the exact error queue, `*in`, that `*a` and its group are unchanged and that the key still signs and verifies: OID 1.2.3.4 (NID 0), sha256's OID, sect163k1, `05 00` and `05 81 00`; empty input, truncated high tag, missing length, indefinite length on a primitive, `0xff` length octet (also followed by 127 zero bytes), truncated long-form length, lengths past the buffer for OBJECT and SEQUENCE, INTEGER, context-specific `[0]` and `[6]` tags, constructed OBJECT and NULL (definite and indefinite), empty OID, an arc starting with `0x80`, an unterminated arc, a non-empty NULL, a primitive SEQUENCE and a negative length; - a null `in` and a null `*in` queue exactly `0x10fff043` and leave the key alone. Every one of these 24 mutations makes the test fail: no `OPENSSL_EC_NAMED_CURVE` flag, `*in` not advanced or advanced over the whole buffer, `EC_R_UNKNOWN_GROUP` also for NID 0, calling `EC_GROUP_new_by_curve_name` for NIDs outside the 4.0.0 list, two instead of three nested errors after a header error, a nested error after `NO_MATCHING_CHOICE_TYPE`, the tag class ignored, an unterminated arc or a leading `0x80` octet accepted, a constructed OBJECT, an indefinite primitive, a length past the buffer, a `0xff` length octet or a non-empty NULL accepted, a primitive SEQUENCE reaching the explicit-parameter throw, the high tag number form rejected, `*a` never reused, `*a` not set, a null input queuing the malloc reason, a negative length decoded, implicitlyCA queuing the by-name failure, and a missing `ERR_R_EC_LIB` or `EC_R_D2I_ECPKPARAMETERS_FAILURE`. `nm -D` on the patched `libSceLibreSsl3.prx` lists `hWwis8FUZVQ`. `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch` reports only #19063 (see below). The 15 open PRs it could not compare because they conflict with `main` were checked by hand: none changes `d2i_ECParameters` or `EcAsn1.cpp`, and none has a hunk next to the `Export.cpp` stub, the `Api.hpp` declaration, the new `CMakeLists.txt` block (after the `EC_KEY_set_asn1_flag` test block) or the new debt entry (after `o2i_ECPublicKey`'s). No title tested. ### 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
PrivacyOnion commented 2026-11-12 23:35:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T23:35:40Z.

Review: CHANGES_REQUESTED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_ec_parameters_tests built cleanly.
  • CTest (guest_libressl3_ec_parameters):
    1/1 Test #3719: guest_libressl3_ec_parameters ....   Passed    2.88 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp against LibreSSL 4.0.0 ec_asn1.c and tasn_dec.c for caller pointer handling, finding undefined behavior and missing null checks in d2i_ECParameters_nid_postfix when EC_KEY_new_nid_postfix fails.
    • Verified DecodeGroup in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp for input stream pointer progression on errors, finding that *in is erroneously advanced when group creation fails on unknown curve OIDs or NULL parameters (05 00), contrary to upstream LibreSSL d2i_ECPKParameters which only advances *in on success.
    • Verified error queue reasons in NamedCurveGroup and DecodeGroup against LibreSSL 4.0.0 ec_asn1_pkparameters2group, finding that unrecognized OIDs (NID_undef / 0) fail to queue EC_R_UNKNOWN_GROUP (129) and instead queue EC_R_EC_GROUP_NEW_BY_NAME_FAILURE (119).
    • Verified core/libs/prx/libSceLibreSsl3/tests/EcParameters.cpp test cases in RejectsCurvesItCannotName(), finding that the test codifies the stream advance defect and the incorrect error queue sequence for unknown OID 06032a0304.
    • Verified AGENTS.md rule compliance regarding code comments, technical debt documentation in docs/dev/debt/libSceLibreSsl3.md, NotImplemented_nid_no_patch stubs in Export.cpp, and CMake target configuration in core/libs/prx/libSceLibreSsl3/CMakeLists.txt.
  • Concerns:
    • core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp:259: In DecodeGroup, line 259 executes *in += parameters->consumed; before validating or creating the group. When parameters->namedCurve specifies an unknown or unsupported curve OID (e.g. 06032a0304 or 0609608648016503040201) or implicitlyCA (0500), NamedCurveGroup returns nullptr (or parameters->namedCurve is false) and DecodeGroup returns nullptr. d2i_ECParameters_nid_postfix fails and returns nullptr, but *in has already been advanced past the element. In LibreSSL upstream (ec_asn1.c:1014-1035), d2i_ECPKParameters operates on a local pointer p = *in; and only commits *in = p; after ec_asn1_pkparameters2group succeeds; on any failure, *in remains unchanged at the beginning of the input. Advancing *in on failure corrupts the caller's buffer cursor.
    • core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp:247: In NamedCurveGroup, line 247 checks if (nid > 0) PutError(UnknownGroup);. When an OID is not recognized (nid == 0 / NID_undef, such as 06032a0304), UnknownGroup (EC_R_UNKNOWN_GROUP, 129) is omitted. Subsequently, in DecodeGroup line 261, group == nullptr causes GroupNewByNameFailure (EC_R_EC_GROUP_NEW_BY_NAME_FAILURE, 119) to be queued instead. In LibreSSL 4.0.0 (ec_asn1.c:987-994), OBJ_obj2nid returning NID_undef explicitly queues EC_R_UNKNOWN_GROUP and returns NULL without attempting group creation (so EC_R_EC_GROUP_NEW_BY_NAME_FAILURE is never queued for NID 0).
    • core/libs/prx/libSceLibreSsl3/tests/EcParameters.cpp:198: In RejectsCurvesItCannotName(), test cases explicitly assert that cursor is advanced on decode failure (Require(cursor == start + consumed) with consumed values 5, 11, 7, 2, 3) and assert the incorrect error sequence {GroupByNameFailure, ToGroupFailure, EcLibraryFailure} for NID 0 rather than expecting *in to remain unadvanced (consumed == 0) and expecting UnknownGroup. The test suite actively validates and locks in the stream advancement bug and inverted error code.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5883726828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19134#pullrequestreview-5883726828). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T23:35:40Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `21e84cf88d`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_ec_parameters_tests` built cleanly. - **CTest** (`guest_libressl3_ec_parameters`): ``` 1/1 Test #3719: guest_libressl3_ec_parameters .... Passed 2.88 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/Export.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp against LibreSSL 4.0.0 ec_asn1.c and tasn_dec.c for caller pointer handling, finding undefined behavior and missing null checks in d2i_ECParameters_nid_postfix when EC_KEY_new_nid_postfix fails. - Verified DecodeGroup in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp for input stream pointer progression on errors, finding that *in is erroneously advanced when group creation fails on unknown curve OIDs or NULL parameters (05 00), contrary to upstream LibreSSL d2i_ECPKParameters which only advances *in on success. - Verified error queue reasons in NamedCurveGroup and DecodeGroup against LibreSSL 4.0.0 ec_asn1_pkparameters2group, finding that unrecognized OIDs (NID_undef / 0) fail to queue EC_R_UNKNOWN_GROUP (129) and instead queue EC_R_EC_GROUP_NEW_BY_NAME_FAILURE (119). - Verified core/libs/prx/libSceLibreSsl3/tests/EcParameters.cpp test cases in RejectsCurvesItCannotName(), finding that the test codifies the stream advance defect and the incorrect error queue sequence for unknown OID 06032a0304. - Verified AGENTS.md rule compliance regarding code comments, technical debt documentation in docs/dev/debt/libSceLibreSsl3.md, NotImplemented_nid_no_patch stubs in Export.cpp, and CMake target configuration in core/libs/prx/libSceLibreSsl3/CMakeLists.txt. - **Concerns**: - core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp:259: In DecodeGroup, line 259 executes *in += parameters->consumed; before validating or creating the group. When parameters->namedCurve specifies an unknown or unsupported curve OID (e.g. 06032a0304 or 0609608648016503040201) or implicitlyCA (0500), NamedCurveGroup returns nullptr (or parameters->namedCurve is false) and DecodeGroup returns nullptr. d2i_ECParameters_nid_postfix fails and returns nullptr, but *in has already been advanced past the element. In LibreSSL upstream (ec_asn1.c:1014-1035), d2i_ECPKParameters operates on a local pointer p = *in; and only commits *in = p; after ec_asn1_pkparameters2group succeeds; on any failure, *in remains unchanged at the beginning of the input. Advancing *in on failure corrupts the caller's buffer cursor. - core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp:247: In NamedCurveGroup, line 247 checks if (nid > 0) PutError(UnknownGroup);. When an OID is not recognized (nid == 0 / NID_undef, such as 06032a0304), UnknownGroup (EC_R_UNKNOWN_GROUP, 129) is omitted. Subsequently, in DecodeGroup line 261, group == nullptr causes GroupNewByNameFailure (EC_R_EC_GROUP_NEW_BY_NAME_FAILURE, 119) to be queued instead. In LibreSSL 4.0.0 (ec_asn1.c:987-994), OBJ_obj2nid returning NID_undef explicitly queues EC_R_UNKNOWN_GROUP and returns NULL without attempting group creation (so EC_R_EC_GROUP_NEW_BY_NAME_FAILURE is never queued for NID 0). - core/libs/prx/libSceLibreSsl3/tests/EcParameters.cpp:198: In RejectsCurvesItCannotName(), test cases explicitly assert that cursor is advanced on decode failure (Require(cursor == start + consumed) with consumed values 5, 11, 7, 2, 3) and assert the incorrect error sequence {GroupByNameFailure, ToGroupFailure, EcLibraryFailure} for NID 0 rather than expecting *in to remain unadvanced (consumed == 0) and expecting UnknownGroup. The test suite actively validates and locks in the stream advancement bug and inverted error code. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-15 20:24:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:24:13Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_ec_parameters_tests built cleanly.
  • CTest (guest_libressl3_ec_parameters):
    1/1 Test #3930: guest_libressl3_ec_parameters ....   Passed    1.55 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that d2i_ECParameters_nid_postfix validates in and *in against nullptr, emitting PassedNullParameter (ERR_R_PASSED_NULL_PARAMETER = 67) via LibreSslPutError_nid_no_patch before attempting any buffer access.
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that DecodeParameters correctly handles negative buffer lengths (length < 0), lengths exceeding buffer capacity, constructed primitives, non-constructed sequences, and invalid OID encodings with the exact expected ASN1 error reasons (BadObjectHeader, TooLong, NoMatchingChoiceType, TypeNotPrimitive, SequenceNotConstructed, NullIsWrongLength, InvalidObjectEncoding).
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that key reuse (*key != nullptr) frees the existing curve group via EC_GROUP_free_nid_postfix(result->group) before assigning the decoded group, and new keys allocated via EC_KEY_new_nid_postfix() are guarded by std::unique_ptr<EcKey, KeyDeleter> so they are freed on decode failure or exception unwinding.
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that *in is advanced past the element if and only if ASN.1 header, length, and primitive content decode succeeds, matching LibreSSL 4.0.0 behavior for unrecognized curve OIDs and implicitlyCA (NullTag).
    • Verified strict compliance with AGENTS.md: zero code comments in modified or added files (EcAsn1.cpp, EcParameters.cpp, Export.cpp, CMakeLists.txt), upstream copyright notices and commit pin retained verbatim, technical debt fragment created at docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md, and explicit curve parameters cleanly throwing NotImplemented_nid_no_patch.
    • Verified LP64 and LLP64 portability: length is typed as std::int64_t in Api.hpp and EcAsn1.cpp, avoiding 32-bit long truncation on Windows x64 (LLP64), and size comparisons against INT32_MAX prevent signed/unsigned narrowing issues.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912738497 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19134#pullrequestreview-5912738497). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T20:24:13Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `3f7437407e`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_ec_parameters_tests` built cleanly. - **CTest** (`guest_libressl3_ec_parameters`): ``` 1/1 Test #3930: guest_libressl3_ec_parameters .... Passed 1.55 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/Export.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that d2i_ECParameters_nid_postfix validates in and *in against nullptr, emitting PassedNullParameter (ERR_R_PASSED_NULL_PARAMETER = 67) via LibreSslPutError_nid_no_patch before attempting any buffer access. - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that DecodeParameters correctly handles negative buffer lengths (length < 0), lengths exceeding buffer capacity, constructed primitives, non-constructed sequences, and invalid OID encodings with the exact expected ASN1 error reasons (BadObjectHeader, TooLong, NoMatchingChoiceType, TypeNotPrimitive, SequenceNotConstructed, NullIsWrongLength, InvalidObjectEncoding). - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that key reuse (*key != nullptr) frees the existing curve group via EC_GROUP_free_nid_postfix(result->group) before assigning the decoded group, and new keys allocated via EC_KEY_new_nid_postfix() are guarded by std::unique_ptr<EcKey, KeyDeleter> so they are freed on decode failure or exception unwinding. - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that *in is advanced past the element if and only if ASN.1 header, length, and primitive content decode succeeds, matching LibreSSL 4.0.0 behavior for unrecognized curve OIDs and implicitlyCA (NullTag). - Verified strict compliance with AGENTS.md: zero code comments in modified or added files (EcAsn1.cpp, EcParameters.cpp, Export.cpp, CMakeLists.txt), upstream copyright notices and commit pin retained verbatim, technical debt fragment created at docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md, and explicit curve parameters cleanly throwing NotImplemented_nid_no_patch. - Verified LP64 and LLP64 portability: length is typed as std::int64_t in Api.hpp and EcAsn1.cpp, avoiding 32-bit long truncation on Windows x64 (LLP64), and size comparisons against INT32_MAX prevent signed/unsigned narrowing issues. - Note: the AI-assisted checkbox can stay. Looks Good To Me
PrivacyOnion commented 2026-11-15 20:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:24:14Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_ec_parameters_tests built cleanly.
  • CTest (guest_libressl3_ec_parameters):
    1/1 Test #3930: guest_libressl3_ec_parameters ....   Passed    1.55 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that d2i_ECParameters_nid_postfix validates in and *in against nullptr, emitting PassedNullParameter (ERR_R_PASSED_NULL_PARAMETER = 67) via LibreSslPutError_nid_no_patch before attempting any buffer access.
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that DecodeParameters correctly handles negative buffer lengths (length < 0), lengths exceeding buffer capacity, constructed primitives, non-constructed sequences, and invalid OID encodings with the exact expected ASN1 error reasons (BadObjectHeader, TooLong, NoMatchingChoiceType, TypeNotPrimitive, SequenceNotConstructed, NullIsWrongLength, InvalidObjectEncoding).
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that key reuse (*key != nullptr) frees the existing curve group via EC_GROUP_free_nid_postfix(result->group) before assigning the decoded group, and new keys allocated via EC_KEY_new_nid_postfix() are guarded by std::unique_ptr<EcKey, KeyDeleter> so they are freed on decode failure or exception unwinding.
    • Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that *in is advanced past the element if and only if ASN.1 header, length, and primitive content decode succeeds, matching LibreSSL 4.0.0 behavior for unrecognized curve OIDs and implicitlyCA (NullTag).
    • Verified strict compliance with AGENTS.md: zero code comments in modified or added files (EcAsn1.cpp, EcParameters.cpp, Export.cpp, CMakeLists.txt), upstream copyright notices and commit pin retained verbatim, technical debt fragment created at docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md, and explicit curve parameters cleanly throwing NotImplemented_nid_no_patch.
    • Verified LP64 and LLP64 portability: length is typed as std::int64_t in Api.hpp and EcAsn1.cpp, avoiding 32-bit long truncation on Windows x64 (LLP64), and size comparisons against INT32_MAX prevent signed/unsigned narrowing issues.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912738617 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19134#pullrequestreview-5912738617). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T20:24:14Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `3f7437407e`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_ec_parameters_tests` built cleanly. - **CTest** (`guest_libressl3_ec_parameters`): ``` 1/1 Test #3930: guest_libressl3_ec_parameters .... Passed 1.55 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/Export.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that d2i_ECParameters_nid_postfix validates in and *in against nullptr, emitting PassedNullParameter (ERR_R_PASSED_NULL_PARAMETER = 67) via LibreSslPutError_nid_no_patch before attempting any buffer access. - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that DecodeParameters correctly handles negative buffer lengths (length < 0), lengths exceeding buffer capacity, constructed primitives, non-constructed sequences, and invalid OID encodings with the exact expected ASN1 error reasons (BadObjectHeader, TooLong, NoMatchingChoiceType, TypeNotPrimitive, SequenceNotConstructed, NullIsWrongLength, InvalidObjectEncoding). - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that key reuse (*key != nullptr) frees the existing curve group via EC_GROUP_free_nid_postfix(result->group) before assigning the decoded group, and new keys allocated via EC_KEY_new_nid_postfix() are guarded by std::unique_ptr<EcKey, KeyDeleter> so they are freed on decode failure or exception unwinding. - Verified in core/libs/prx/libSceLibreSsl3/src/EcAsn1.cpp that *in is advanced past the element if and only if ASN.1 header, length, and primitive content decode succeeds, matching LibreSSL 4.0.0 behavior for unrecognized curve OIDs and implicitlyCA (NullTag). - Verified strict compliance with AGENTS.md: zero code comments in modified or added files (EcAsn1.cpp, EcParameters.cpp, Export.cpp, CMakeLists.txt), upstream copyright notices and commit pin retained verbatim, technical debt fragment created at docs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md, and explicit curve parameters cleanly throwing NotImplemented_nid_no_patch. - Verified LP64 and LLP64 portability: length is typed as std::int64_t in Api.hpp and EcAsn1.cpp, avoiding 32-bit long truncation on Windows x64 (LLP64), and size comparisons against INT32_MAX prevent signed/unsigned narrowing issues. - Note: the AI-assisted checkbox can stay. 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!19134
No description provided.