Curve25519 library with Ed25519 signatures extension for PHP. It supports PHP 8.
$randomBytes = random_bytes(32);
$private = curve25519_private($randomBytes);
$public = curve25519_public($private);
$agreement = curve25519_shared($private, $public);
$signature = curve25519_sign(random_bytes(64), $private, $message);
$verified = curve25519_verify($public, $message, $signature) == 0;
If you are using it in combination with LibSignal for PHP:
$randomBytes = random_bytes(32);
$private = curve25519_private($randomBytes);
$public = curve25519_public($private);
$keyPair = new ECKeyPair(new DjbECPublicKey($public), new DjbECPrivateKey($private));
$agreement = curve25519_shared($keyPair->getPrivateKey(), $keyPair->getPublicKey());
$signature = curve25519_sign(random_bytes(64), $signingKey->getPrivateKey(), $message);
$verified = curve25519_verify($signingKey->getPublicKey(), $message, $signature) == 0;
phpize
./configure
make
sudo make install
When installed, make sure to add it in your php.ini
env:
php --ini # will reveal your .ini path
# Edit the file and add:
extension=curve25519