Comparing version 3.0.3 to 3.0.4
@@ -43,2 +43,3 @@ 'use strict'; | ||
BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) { | ||
assert(p.precomputed); | ||
var doubles = p._getDoubles(); | ||
@@ -263,2 +264,13 @@ | ||
BasePoint.prototype._hasDoubles = function _hasDoubles(k) { | ||
if (!this.precomputed) | ||
return false; | ||
var doubles = this.precomputed.doubles; | ||
if (!doubles) | ||
return false; | ||
return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step); | ||
}; | ||
BasePoint.prototype._getDoubles = function _getDoubles(step, power) { | ||
@@ -265,0 +277,0 @@ if (this.precomputed && this.precomputed.doubles) |
@@ -327,3 +327,3 @@ 'use strict'; | ||
Point.prototype.mul = function mul(k) { | ||
if (this.precomputed && this.precomputed.doubles) | ||
if (this._hasDoubles(k)) | ||
return this.curve._fixedNafMul(this, k); | ||
@@ -330,0 +330,0 @@ else |
@@ -424,3 +424,3 @@ 'use strict'; | ||
if (this.precomputed && this.precomputed.doubles) | ||
if (this._hasDoubles(k)) | ||
return this.curve._fixedNafMul(this, k); | ||
@@ -427,0 +427,0 @@ else if (this.curve.endo) |
{ | ||
"name": "elliptic", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "EC cryptography", | ||
@@ -5,0 +5,0 @@ "main": "lib/elliptic.js", |
@@ -9,7 +9,7 @@ var assert = require('assert'); | ||
assert(ec); | ||
assert(typeof(ec) == "object"); | ||
assert(typeof ec === 'object'); | ||
}); | ||
it('should throw error with invalid curve', function() { | ||
assert.throws(function(){ | ||
assert.throws(function() { | ||
var ec = new elliptic.ec('nonexistent-curve'); | ||
@@ -16,0 +16,0 @@ }, Error); |
@@ -83,3 +83,4 @@ var assert = require('assert'); | ||
assert(!g2.precomputed); | ||
var a = new bn('6d1229a6b24c2e775c062870ad26bc261051e0198c67203167273c7c62538846', 16); | ||
var a = new bn( | ||
'6d1229a6b24c2e775c062870ad26bc261051e0198c67203167273c7c62538846', 16); | ||
var p1 = g1.mul(a); | ||
@@ -90,6 +91,24 @@ var p2 = g2.mul(a); | ||
it('should not use fixed NAF when k is too large', function() { | ||
var curve = elliptic.curves.secp256k1.curve; | ||
var g1 = curve.g; // precomputed g | ||
assert(g1.precomputed); | ||
var g2 = curve.point(g1.getX(), g1.getY()); // not precomputed g | ||
assert(!g2.precomputed); | ||
var a = new bn( | ||
'6d1229a6b24c2e775c062870ad26bc26' + | ||
'1051e0198c67203167273c7c6253884612345678', | ||
16); | ||
var p1 = g1.mul(a); | ||
var p2 = g2.mul(a); | ||
assert(p1.eq(p2)); | ||
}); | ||
it('should not fail on secp256k1 regression', function() { | ||
var curve = elliptic.curves.secp256k1.curve; | ||
var k1 = new bn('32efeba414cd0c830aed727749e816a01c471831536fd2fce28c56b54f5a3bb1', 16); | ||
var k2 = new bn('5f2e49b5d64e53f9811545434706cde4de528af97bfd49fde1f6cf792ee37a8c', 16); | ||
var k1 = new bn( | ||
'32efeba414cd0c830aed727749e816a01c471831536fd2fce28c56b54f5a3bb1', 16); | ||
var k2 = new bn( | ||
'5f2e49b5d64e53f9811545434706cde4de528af97bfd49fde1f6cf792ee37a8c', 16); | ||
@@ -96,0 +115,0 @@ var p1 = curve.g.mul(k1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143359
3689