simplito / elliptic-php

Fast, general Elliptic Curve Cryptography library. Supports curves used in Bitcoin, Ethereum and other cryptocurrencies (secp256k1, ed25519, ..)
MIT License
220 stars 52 forks source link

curve25519 is changing private key #43

Closed akadlec closed 2 years ago

akadlec commented 2 years ago

Hi, when I create private key from secret, EC is modifying it

$secret = random_bytes(32);

$ec = new EC('curve25519');

$keyPair = $ec->keyFromPrivate(bin2hex($secret), 16);

$keyPair->getPrivate('hex') !== bin2hex($secret);

and I think this secret should be same

ldudzsim commented 2 years ago

private key has to be lower than n, so when you pass random value it is always modified to fit https://github.com/simplito/elliptic-php/blob/master/lib/EC/KeyPair.php#L97