diff options
Diffstat (limited to 'node_modules/elliptic')
-rw-r--r-- | node_modules/elliptic/README.md | 47 | ||||
-rw-r--r-- | node_modules/elliptic/lib/elliptic/curve/edwards.js | 14 | ||||
-rw-r--r-- | node_modules/elliptic/lib/elliptic/curve/short.js | 1 | ||||
-rw-r--r-- | node_modules/elliptic/package.json | 2 |
4 files changed, 37 insertions, 27 deletions
diff --git a/node_modules/elliptic/README.md b/node_modules/elliptic/README.md index 808984501..96219e55b 100644 --- a/node_modules/elliptic/README.md +++ b/node_modules/elliptic/README.md @@ -55,35 +55,46 @@ var ec = new EC('secp256k1'); // Generate keys var key = ec.genKeyPair(); -// Sign message (must be an array, or it'll be treated as a hex sequence) -var msg = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var signature = key.sign(msg); +// Sign the message's hash (input must be an array, or a hex-string) +var msgHash = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +var signature = key.sign(msgHash); // Export DER encoded signature in Array var derSign = signature.toDER(); // Verify signature -console.log(key.verify(msg, derSign)); +console.log(key.verify(msgHash, derSign)); // CHECK WITH NO PRIVATE KEY -// Public key as '04 + x + y' -var pub = '04bb1fa3...'; +var pubPoint = key.getPublic(); +var x = pubPoint.getX(); +var y = pubPoint.getY(); + +// Public Key MUST be either: +// 1) '04' + hex string of x + hex string of y; or +// 2) object with two hex string properties (x and y); or +// 3) object with two buffer properties (x and y) +var pub = pubPoint.encode('hex'); // case 1 +var pub = { x: x.toString('hex'), y: y.toString('hex') }; // case 2 +var pub = { x: x.toBuffer(), y: y.toBuffer() }; // case 3 +var pub = { x: x.toArrayLike(Buffer), y: y.toArrayLike(Buffer) }; // case 3 + +// Import public key +var key = ec.keyFromPublic(pub, 'hex'); // Signature MUST be either: -// 1) hex-string of DER-encoded signature; or +// 1) DER-encoded signature as hex-string; or // 2) DER-encoded signature as buffer; or -// 3) object with two hex-string properties (r and s) +// 3) object with two hex-string properties (r and s); or +// 4) object with two buffer properties (r and s) -var signature = 'b102ac...'; // case 1 +var signature = '3046022100...'; // case 1 var signature = new Buffer('...'); // case 2 var signature = { r: 'b1fc...', s: '9c42...' }; // case 3 -// Import public key -var key = ec.keyFromPublic(pub, 'hex'); - // Verify signature -console.log(key.verify(msg, signature)); +console.log(key.verify(msgHash, signature)); ``` ### EdDSA @@ -98,12 +109,12 @@ var ec = new EdDSA('ed25519'); // Create key pair from secret var key = ec.keyFromSecret('693e3c...'); // hex string, array or Buffer -// Sign message (must be an array, or it'll be treated as a hex sequence) -var msg = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var signature = key.sign(msg).toHex(); +// Sign the message's hash (input must be an array, or a hex-string) +var msgHash = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +var signature = key.sign(msgHash).toHex(); // Verify signature -console.log(key.verify(msg, signature)); +console.log(key.verify(msgHash, signature)); // CHECK WITH NO PRIVATE KEY @@ -113,7 +124,7 @@ var key = ec.keyFromPublic(pub, 'hex'); // Verify signature var signature = '70bed1...'; -console.log(key.verify(msg, signature)); +console.log(key.verify(msgHash, signature)); ``` ### ECDH diff --git a/node_modules/elliptic/lib/elliptic/curve/edwards.js b/node_modules/elliptic/lib/elliptic/curve/edwards.js index 6e9fb7742..a8965eaec 100644 --- a/node_modules/elliptic/lib/elliptic/curve/edwards.js +++ b/node_modules/elliptic/lib/elliptic/curve/edwards.js @@ -74,10 +74,10 @@ EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { if (!y.red) y = y.toRed(this.red); - // x^2 = (y^2 - 1) / (d y^2 + 1) + // x^2 = (y^2 - c^2) / (c^2 d y^2 - a) var y2 = y.redSqr(); - var lhs = y2.redSub(this.one); - var rhs = y2.redMul(this.d).redAdd(this.one); + var lhs = y2.redSub(this.c2); + var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a); var x2 = lhs.redMul(rhs.redInvm()); if (x2.cmp(this.zero) === 0) { @@ -91,7 +91,7 @@ EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error('invalid point'); - if (x.isOdd() !== odd) + if (x.fromRed().isOdd() !== odd) x = x.redNeg(); return this.point(x, y); @@ -168,7 +168,8 @@ Point.prototype.inspect = function inspect() { Point.prototype.isInfinity = function isInfinity() { // XXX This code assumes that zero is always zero in red return this.x.cmpn(0) === 0 && - this.y.cmp(this.z) === 0; + (this.y.cmp(this.z) === 0 || + (this.zOne && this.y.cmp(this.curve.c) === 0)); }; Point.prototype._extDbl = function _extDbl() { @@ -249,7 +250,7 @@ Point.prototype._projDbl = function _projDbl() { // E = C + D var e = c.redAdd(d); // H = (c * Z1)^2 - var h = this.curve._mulC(this.c.redMul(this.z)).redSqr(); + var h = this.curve._mulC(this.z).redSqr(); // J = E - 2 * H var j = e.redSub(h).redSub(h); // X3 = c * (B - E) * J @@ -425,7 +426,6 @@ Point.prototype.eqXToP = function eqXToP(x) { if (this.x.cmp(rx) === 0) return true; } - return false; }; // Compatibility with BaseCurve diff --git a/node_modules/elliptic/lib/elliptic/curve/short.js b/node_modules/elliptic/lib/elliptic/curve/short.js index 0a09d2497..5a0e86032 100644 --- a/node_modules/elliptic/lib/elliptic/curve/short.js +++ b/node_modules/elliptic/lib/elliptic/curve/short.js @@ -921,7 +921,6 @@ JPoint.prototype.eqXToP = function eqXToP(x) { if (this.x.cmp(rx) === 0) return true; } - return false; }; JPoint.prototype.inspect = function inspect() { diff --git a/node_modules/elliptic/package.json b/node_modules/elliptic/package.json index f0bdebb39..3c92205a5 100644 --- a/node_modules/elliptic/package.json +++ b/node_modules/elliptic/package.json @@ -1,6 +1,6 @@ { "name": "elliptic", - "version": "6.4.0", + "version": "6.4.1", "description": "EC cryptography", "main": "lib/elliptic.js", "files": [ |