[php-src] PR #21387: Fix GH-21083: Skip private_key_bits validation for EC/curve-based keys
| From: | iliaal | Date: | Sun, 08 Mar 2026 17:39:26 +0000 |
| Subject: | [php-src] PR #21387: Fix GH-21083: Skip private_key_bits validation for EC/curve-based keys | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35137@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21387
Author: iliaal
## Summary
openssl_pkey_new() checks private_key_bits >= 384 before generating any
key. EC and curve-based key types (X25519, ED25519, X448, ED448) don't use
private_key_bits at all — their size comes from the curve or is fixed.
This worked by accident because most openssl.cnf files set default_bits =
2048, which passes the check even though EC keys ignore it. OpenSSL 3.6 ships with
default_bits commented out, so priv_key_bits defaults to 0 and the check
rejects the key.
## Fix
Skip the priv_key_bits < MIN_KEY_LENGTH guard for key types where bit length is
inherent:
- OPENSSL_KEYTYPE_EC — size from curve name
- OPENSSL_KEYTYPE_X25519 / OPENSSL_KEYTYPE_X448 — fixed 256/448 bits
- OPENSSL_KEYTYPE_ED25519 / OPENSSL_KEYTYPE_ED448 — fixed 256/456 bits
## Test
ext/openssl/tests/gh21083.phpt creates a minimal openssl.cnf without
default_bits and generates EC, X25519, and ED25519 keys without specifying
private_key_bits. Fails before the fix, passes after.
Fixes #21083