Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.42 KB

README.md

File metadata and controls

48 lines (36 loc) · 1.42 KB

Curve25519 extension for PHP

php sponsor

Curve25519 library with Ed25519 signatures extension for PHP. It supports PHP 8.

Usage

$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;

Installation

Linux and MacOS

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