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

Error in _projDbl for ordinary Edwards curves #26

Open TiberiumFusion opened 4 years ago

TiberiumFusion commented 4 years ago

I'm trying to define and work with an ordinary Edwards curve, but it seems like there's an error in the implementation of the math for ordinary Edwards curves (in comparison, the math for twisted curves doesn't throw any errors).

Undefined property $this->c at https://github.com/simplito/elliptic-php/blob/master/lib/Curve/EdwardsCurve/Point.php#L143

// H = (c * Z1)^2
$h = $this->curve->_mulC($this->c->redMul($this->z))->redSqr();

This is how the elliptic,js code does it: https://github.com/indutny/elliptic/blob/475f066aebd14681591f0f0f18a2abc0ded8c390/lib/elliptic/curve/edwards.js#L252

// H = (c * Z1)^2
var h = this.curve._mulC(this.z).redSqr();

I'm not versed at all in the maths for working with Edwards curve, but this looks like a typo in the php version.