feat(libSceLibreSsl): implement EC points, key generation, ECDSA and ECDH #15827
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15827"
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-04T18:07:10Z.
What
Implements eleven libSceLibreSsl exports that were throwing
NotImplemented:EC_POINT_new,EC_POINT_free,EC_POINT_point2oct,EC_POINT_oct2point,EC_KEY_generate_key,EC_KEY_check_key,EC_KEY_get0_public_key,EC_KEY_set_public_key,ECDSA_sign,ECDSA_verifyandECDH_compute_key.Replaces #10407, which the open PR limit closed while #10395 was open; GitHub no longer reopens it. MarcZX10's review there asked for this stack to be refreshed onto current
mainafter #10395 and its LibreSSL tests rerun on the composed head; this is that head, with only this commit left on top ofmain.ec/ec_lib.c,ec/ec_key.c,ec/ec_oct.c,ec/ecp_oct.c,ecdsa/ecs_sign.c,ecdsa/ecs_vrf.c,ecdsa/ecs_ossl.candecdh/ech_key.c.EC_POINTis a host object holding anmbedtls_ecp_pointand its curve; anEC_KEYnow also holds its public point and private scalar.Api.hppdeclaresEcPointas opaque next toEcGroupandEcKey, with the exports' signatures; the layouts stay in the internalinclude/Ec.hpp. The three exports that take or return aBIGNUM(EC_POINT_mul,EC_KEY_get0_private_key,EC_KEY_set_private_key) still throw: #9446'sBIGNUMlanded after this branch was written, so they are left for a follow-up.EC_POINT_point2octandEC_POINT_oct2pointhandle the compressed, uncompressed and hybrid forms and the single zero octet for infinity, with LibreSSL's checks: form and y bit, exact length, coordinates below the prime, hybrid parity and the X9.62 on-curve test. A point that fails only the on-curve test keeps the decoded coordinates, as in LibreSSL, soEC_KEY_check_keycan reject it later.EC_KEY_generate_keydraws the scalar in [1, n-1] from host entropy and reuses the key's existing point object, as LibreSSL does.EC_KEY_check_keychecks infinity, the curve equation and, with a private key, that it gives the public key; the order test always passes because all 11 curves have cofactor 1.ECDSA_signsigns through mbedtls with a random nonce and writes LibreSSL's DER (unsigned INTEGERs, 0x00 pad when the top bit is set); a null buffer only returns the length.ECDSA_verifyreturns -1 unless the signature is canonical DER with nothing after it (what LibreSSL's decode and re-encode comparison accepts), 0 for r or s outside [1, n-1] or a mismatch, and -1 when u1·G + u2·Q is at infinity. Digests longer than the order are truncated to its bit length, likeecdsa_do_signandecdsa_do_verify.ECDH_compute_keyreturns the x coordinate padded to the field size: -1 without a private key, group or peer key, for a peer at infinity, for a length aboveINT_MAXor a buffer shorter than the secret without a KDF; a larger buffer is zero-filled. A KDF is called through the guest ABI and its output length is returned.Ec.cppstarts with the copyright notices, licence conditions and disclaimers of LibreSSL 2.5.4'sec/ecp_oct.c,ec/ec_key.c,ecdsa/ecs_ossl.candecdh/ech_key.c, verbatim from 2e2c612, becauseEC_POINT_point2oct,EC_POINT_oct2point,EC_KEY_check_key,ECDSA_verifyandECDH_compute_keyfollow their control flow.Gaps, in the debt file: no error is queued; a point used with a group of another curve throws, since LibreSSL's result depends on the EC methods its build picks; so does
EC_KEY_set_groupto another curve on a key that already has a public or private key; compressed points on secp224k1 and secp224r1 throw (mbedtls only decompresses for primes that are 3 mod 4);ECDSA_verifywith a public key at infinity or off the curve andECDH_compute_keywith a peer key off the curve throw, where LibreSSL computes with them. The EC debt entry is split in two to stay under 1000 characters.Export.cppgoes from 121 to 110NotImplemented_nid_no_patchstubs; since #11553 the debt file no longer states that count.Tested
Linux (Ubuntu 24.04 container, GCC 13.3), full configure with
-DBUILD_TESTING=ON, Release: builtlibSceLibreSsl,libSceLibreSsl3, their patched.prxfiles and the eighty-eight LibreSSL tests;ctest -R 'libressl|crypto_memcmp|public_headers'passes 153 of 153 (the eighty-eight LibreSSL tests,public_headersand its 64 compile checks) on head6e04d09675, based onmain06a9092274; the newguest_libressl_ec_keystakes 0.6 s. Built with AddressSanitizer and leak detection,guest_libressl_ec_keys,guest_libressl_ecandguest_libressl3_key_referenceare clean. It checks:EC_KEY_check_key, encoded sizes, sign and verify (another key, a changed signature, another digest, an empty digest), ECDH agreement on both sides and regeneration keeping the point object;cryptography46, and a secp224k1 signature from a Python reference implementation whose 225-bit order makes the truncation drop seven bits; ten non-DER signatures return -1 and five out-of-range ones return 0;EC_KEY_set_public_keycopies, own key, null, infinity and off-curve points, andEC_KEY_set_groupwith and without keys; null arguments throw. Unimplemented paths that throw (other curves, 224-bit compressed points, verify and ECDH with an off-curve or infinite key) are in the debt file and not tested.Windows: JJenkx ran
guest_libressl_ec_keyson head6e04d09675merged ontomain(Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs (comment).The test fails when the truncation shift, the hybrid y bit, the DER minimal-integer check or the ECDH zero fill is removed.
nm -Don the patchedlibSceLibreSsl.prxlists the eleven NIDs.tools/check_conventions.py --base origin/mainpasses; The overlap comment on6e04d09675lists no open PR with the same exports. #12729 and #12730, stacked on it, remove neighbouring stubs inExport.cppandApi.hpp, #16079 edits the EVP debt entry next to the EC entries, and #16719 adds anEVP_DigestVerifyFinalentry at the same place. I proposed this PR first and offered to rebase after theirs instead (comment). For #16079 the order is agreed: this PR first, with noDepends onon either side (reply). #12729, #12730 and #16719 have not answered yet. #14212 adds a blank line between debt entries across the repository; if it lands first, the rebase separates the two EC entries. #11146 depends on this PR and #11466 on #11146. 40 PRs that share these files conflict withmain, so they could not be compared. 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)🤖 Generated with Claude Code