feat(libSceLibreSsl3): implement d2i_ECParameters #19134
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19134"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MatteoSid on 2026-11-12T21:04:21Z.
What
Implements
d2i_ECParametersin libSceLibreSsl3 (NIDhWwis8FUZVQ), following LibreSSL 4.0.0'sd2i_ECParameters,d2i_ECPKParametersandec_asn1_pkparameters2group, and theECPKPARAMETERSCHOICE decode intasn_dec.c:inor*inqueuesECERR_R_PASSED_NULL_PARAMETERand returns null;aor*agets a new key fromEC_KEY_new; otherwise*ais reused;OBJ_obj2nidorder. A NID in the 4.0.0curve_listgets a group from libSceLibreSsl'sEC_GROUP_new_by_curve_name, flaggedOPENSSL_EC_NAMED_CURVE; it replaces the key's group,*ais set and the key is returned;EC_R_UNKNOWN_GROUP(not for NID 0, asEC_GROUP_new_by_curve_namereturns early there),EC_R_EC_GROUP_NEW_BY_NAME_FAILURE,EC_R_PKPARAMETERS2GROUP_FAILUREandERR_R_EC_LIB; implicitlyCA (NULL) queues the last two. Both have already advanced*inpast the element, as upstream;ASN1reasons ofasn1_check_tag,asn1_d2i_primitive_content,c2i_ASN1_OBJECT_cbsand 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 ofERR_R_NESTED_ASN1_ERRORas upstream, thenEC_R_D2I_ECPKPARAMETERS_FAILUREandERR_R_EC_LIB; a negativelenqueues only the last two.*inis left alone. BER is accepted as upstream (der_mode0): high tag number form, long-form and non-minimal lengths;*ais left unchanged, group included.Explicit curve parameters (a
SEQUENCEin the CHOICE) throwNotImplemented_nid_no_patchonce their header is valid: libSceLibreSsl'sEcGroupholds 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'sEC_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_sizeando2i_ECPublicKey, all exported by libSceLibreSsl3. Supported curves: prime192v1, prime256v1, secp192k1, secp224k1, secp224r1, secp256k1, secp384r1, secp521r1, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1.src/EcAsn1.cppnow follows the control flow oftasn_dec.c,asn1_lib.c(header parsing) anda_object.c(OID validation) as well asec_asn1.c, so it carries their notices too. Gaps, in a new debt entry added by the fragmentdocs/dev/debt/changes/feat-libressl3-d2i-ecparameters.md(#17217): the explicit-parameter and mbedtls-curve throws above; errors are queued without file, line or theField=…, Type=…data; nothing is checked on the console.Export.cppgoes from 32 to 31NotImplemented_nid_no_patchstubs on currentmain.Tested
Head
3f7437407eonly adds a clean merge ofmain6a86d4d1a9cand moves the debt entry to the fragment;tools/debt_fold.py --checkpasses on it.Linux (Ubuntu 24.04 container, GCC 13.3), configure with
-DBUILD_TESTING=ON, Release, on head7c2f281b2e, which mergesmain99caf32535(after #19063) into21e84cf88d: built every LibreSSL test target and the patched.prxfiles.ctest -R 'libressl|libre_ssl|crypto_memcmp|public_headers'passes 218 of 218, includingguest_libressl3_ec_parameters,guest_libressl3_ec_public_keyand #19063'sguest_libressl3_x509_store_contextandguest_libressl_x509_store_context. The merge only resolves theExport.cppconflict with #19063 by removing both stubs. The earlier run ondb42ae7bca(based ona221a742da) passed 215 of 215, and the mutation results below are from that head.Windows: JJenkx ran
guest_libressl3_ec_parameterson the earlier head21e84cf88dmerged ontomain(Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped (comment).21e84cf88donly adds the source-pin comment line at the top ofsrc/EcAsn1.cppto the testeddb42ae7bca.The new
guest_libressl3_ec_parametersuses DER from OpenSSL 3.0.2openssl ecparam -name <curve> -outform DERand checks:NULLafter it in the buffer: the group's NID,EC_GROUP_get_degree, theOPENSSL_EC_NAMED_CURVEflag,*inadvanced past the OID only, an empty error queue, thenEC_KEY_generate_key,EC_KEY_check_key,ECDSA_signandECDSA_verify(and a failed verify on a changed digest);*a == nullptris filled; a P-384 key passed in*ais the object returned with a P-256 group, then takes the RFC 6979 A.2.5 public key througho2i_ECPublicKeyand passesEC_KEY_check_key; a key fromEC_KEY_newgets its group;a, a null*aand a P-384 key in*a, checking the exact error queue,*in, that*aand its group are unchanged and that the key still signs and verifies: OID 1.2.3.4 (NID 0), sha256's OID, sect163k1,05 00and05 81 00; empty input, truncated high tag, missing length, indefinite length on a primitive,0xfflength 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 with0x80, an unterminated arc, a non-empty NULL, a primitive SEQUENCE and a negative length;inand a null*inqueue exactly0x10fff043and leave the key alone.Every one of these 24 mutations makes the test fail: no
OPENSSL_EC_NAMED_CURVEflag,*innot advanced or advanced over the whole buffer,EC_R_UNKNOWN_GROUPalso for NID 0, callingEC_GROUP_new_by_curve_namefor NIDs outside the 4.0.0 list, two instead of three nested errors after a header error, a nested error afterNO_MATCHING_CHOICE_TYPE, the tag class ignored, an unterminated arc or a leading0x80octet accepted, a constructed OBJECT, an indefinite primitive, a length past the buffer, a0xfflength octet or a non-empty NULL accepted, a primitive SEQUENCE reaching the explicit-parameter throw, the high tag number form rejected,*anever reused,*anot set, a null input queuing the malloc reason, a negative length decoded, implicitlyCA queuing the by-name failure, and a missingERR_R_EC_LIBorEC_R_D2I_ECPKPARAMETERS_FAILURE.nm -Don the patchedlibSceLibreSsl3.prxlistshWwis8FUZVQ.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchreports only #19063 (see below). The 15 open PRs it could not compare because they conflict withmainwere checked by hand: none changesd2i_ECParametersorEcAsn1.cpp, and none has a hunk next to theExport.cppstub, theApi.hppdeclaration, the newCMakeLists.txtblock (after theEC_KEY_set_asn1_flagtest block) or the new debt entry (aftero2i_ECPublicKey's). No title tested.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl3_ec_parameters_testsbuilt cleanly.guest_libressl3_ec_parameters):core/libs/prx/libSceLibreSsl3/Export.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hpp,core/libs/prx/libSceLibreSsl3/src/EcAsn1.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Requesting changes for the points above.
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:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl3_ec_parameters_testsbuilt cleanly.guest_libressl3_ec_parameters):core/libs/prx/libSceLibreSsl3/Export.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hpp,core/libs/prx/libSceLibreSsl3/src/EcAsn1.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
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:tools/check_conventions.pypassed;git diff --checkclean.guest_libressl3_ec_parameters_testsbuilt cleanly.guest_libressl3_ec_parameters):core/libs/prx/libSceLibreSsl3/Export.cpp,core/libs/prx/libSceLibreSsl3/include/Api.hpp,core/libs/prx/libSceLibreSsl3/src/EcAsn1.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me