Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib failed comparison agains trusty native Curve25519 #18

Open
AsenOsen opened this issue Jan 7, 2020 · 1 comment
Open

Lib failed comparison agains trusty native Curve25519 #18

AsenOsen opened this issue Jan 7, 2020 · 1 comment

Comments

@AsenOsen
Copy link

AsenOsen commented Jan 7, 2020

I`ve decided to compare basic calculation of public key based on private key against Curve25519:

$secureRandom = openssl_random_pseudo_bytes ( 32);
// native curve25519.so
$trusty_private = curve25519_private($secureRandom);
$trusty_public = curve25519_public($trusty_private);

// this library
$ec = new EC('curve25519');
$untrusty_keypair = $ec->keyFromPrivate(bin2hex($trusty_private));
$untrusty_public = $untrusty_keypair->getPublic(true, 'hex');

echo $untrusty_public . PHP_EOL;
echo bin2hex($trusty_public) . PHP_EOL;

and this check has failed:

6aa466621807d91ec5a6777544a6796fde5adf8b72a842b23c25f0c479f3aa71
d323bc8387b836dca1cc42fb8f53cb533ff5eaaf2461adc8ef698640bd614a4b
@ldudzsim
Copy link
Member

In ECC public key is a point. In the Montgomery version of curve25519 in our lib we return public key in normalized form, it means that second coordinate is always 1, so only x is returned and it is returned in big endian order and that’s it.
When you use the edward version of curve (ed25519) you get a standard formatted public key with the beginning 0x02/0x03 for compact and 0x04 for the full version.
I don't know in what form your lib returns the public key, but it does not match with our lib for sure. Finally, I mention that our lib is port of elliptic-js, so you can also compare your lib with it, but the results will be similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants