[php-src] Issue #14074: openssl_dh_compute_key() silently fails for ECDH

From: Date: Mon, 29 Apr 2024 06:37:02 +0000
Subject: [php-src] Issue #14074: openssl_dh_compute_key() silently fails for ECDH
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246833@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14074 Author: paragonie-security ### Description The following code: ```php <?php $alice = file_get_contents(__DIR__ . '/alice-p256.pem'); $bob = file_get_contents(__DIR__ . '/bob-p256.pem'); $aSec = openssl_pkey_get_private($alice); $bSec = openssl_pkey_get_private($bob); $aliceP = file_get_contents(__DIR__ . '/alice-p256-public.pem'); $bobP = file_get_contents(__DIR__ . '/bob-p256-public.pem'); $shared = openssl_dh_compute_key($aliceP, $bSec); if (!is_string($shared)) { var_dump($shared, openssl_error_string()); exit; } $shared2 = openssl_dh_compute_key($bobP, $aSec); var_dump(bin2hex($shared)); var_dump($shared === $shared2); ``` Resulted in this output: ``` bool(false) bool(false) ``` But I expected this output instead: ``` string(64) "some-hex-characters-go-here" bool(true) ``` The docs say: > **Note**: ECDH is only supported as of PHP 8.1.0 and OpenSSL 3.0.0. Despite meeting these requirements, I get a failure and no information to troubleshoot further. ## Testing Key Pairs ### alice-p256.pem ``` -----BEGIN EC PRIVATE KEY----- MHcCAQEEIEbKuqHZtwa14TIsuwNAXU0CAzC0c3pZmI8Du42380PZoAoGCCqGSM49 AwEHoUQDQgAEtM4Z4WpPKeKGWfGzWA9G8arEH8mJvjbfvZO4STGLqFaccU/7Lx0m prZHJ/vcbFc56a1YS0JcrBrRhdINRTPnvQ== -----END EC PRIVATE KEY----- ``` ### alice-p256-public.pem ``` -----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtM4Z4WpPKeKGWfGzWA9G8arEH8mJ vjbfvZO4STGLqFaccU/7Lx0mprZHJ/vcbFc56a1YS0JcrBrRhdINRTPnvQ== -----END PUBLIC KEY----- ``` ### bob-p256.pem ``` -----BEGIN EC PRIVATE KEY----- MHcCAQEEIMPeAXETPfLEchfevO7CbHpmv89RRrDry0d07uPjL4OCoAoGCCqGSM49 AwEHoUQDQgAEA8W1N0jkdmEWFhu21TnT5JfDIDvwrKZKmVm2HZNpUtZ4W1l14FgE izaO6JhxXXt7q0NPVst94oWyUEbWW9eeng== -----END EC PRIVATE KEY----- ``` ### bob-p256-public.pem ``` -----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEA8W1N0jkdmEWFhu21TnT5JfDIDvw rKZKmVm2HZNpUtZ4W1l14FgEizaO6JhxXXt7q0NPVst94oWyUEbWW9eeng== -----END PUBLIC KEY----- ``` ### PHP Version PHP 8.1.2-ubuntu2.15 with OpenSSL 3.0.2 ### Operating System Ubuntu 24.04

« previous php.bugs (#246833) next »