Comparing version 6.0.2 to 6.1.0
'use strict'; | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
var elliptic = require('../../elliptic'); | ||
@@ -12,14 +12,14 @@ var utils = elliptic.utils; | ||
this.type = type; | ||
this.p = new bn(conf.p, 16); | ||
this.p = new BN(conf.p, 16); | ||
// Use Montgomery, when there is no fast reduction for the prime | ||
this.red = conf.prime ? bn.red(conf.prime) : bn.mont(this.p); | ||
this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); | ||
// Useful for many curves | ||
this.zero = new bn(0).toRed(this.red); | ||
this.one = new bn(1).toRed(this.red); | ||
this.two = new bn(2).toRed(this.red); | ||
this.zero = new BN(0).toRed(this.red); | ||
this.one = new BN(1).toRed(this.red); | ||
this.two = new BN(2).toRed(this.red); | ||
// Curve configuration, optional | ||
this.n = conf.n && new bn(conf.n, 16); | ||
this.n = conf.n && new BN(conf.n, 16); | ||
this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); | ||
@@ -26,0 +26,0 @@ |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var elliptic = require('../../elliptic'); | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
var inherits = require('inherits'); | ||
@@ -20,7 +20,7 @@ var Base = curve.base; | ||
this.a = new bn(conf.a, 16).umod(this.red.m); | ||
this.a = new BN(conf.a, 16).umod(this.red.m); | ||
this.a = this.a.toRed(this.red); | ||
this.c = new bn(conf.c, 16).toRed(this.red); | ||
this.c = new BN(conf.c, 16).toRed(this.red); | ||
this.c2 = this.c.redSqr(); | ||
this.d = new bn(conf.d, 16).toRed(this.red); | ||
this.d = new BN(conf.d, 16).toRed(this.red); | ||
this.dd = this.d.redAdd(this.d); | ||
@@ -54,3 +54,3 @@ | ||
EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) { | ||
x = new bn(x, 16); | ||
x = new BN(x, 16); | ||
if (!x.red) | ||
@@ -72,3 +72,3 @@ x = x.toRed(this.red); | ||
EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { | ||
y = new bn(y, 16); | ||
y = new BN(y, 16); | ||
if (!y.red) | ||
@@ -124,6 +124,6 @@ y = y.toRed(this.red); | ||
} else { | ||
this.x = new bn(x, 16); | ||
this.y = new bn(y, 16); | ||
this.z = z ? new bn(z, 16) : this.curve.one; | ||
this.t = t && new bn(t, 16); | ||
this.x = new BN(x, 16); | ||
this.y = new BN(y, 16); | ||
this.z = z ? new BN(z, 16) : this.curve.one; | ||
this.t = t && new BN(t, 16); | ||
if (!this.x.red) | ||
@@ -130,0 +130,0 @@ this.x = this.x.toRed(this.curve.red); |
'use strict'; | ||
var curve = require('../curve'); | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
var inherits = require('inherits'); | ||
@@ -14,6 +14,6 @@ var Base = curve.base; | ||
this.a = new bn(conf.a, 16).toRed(this.red); | ||
this.b = new bn(conf.b, 16).toRed(this.red); | ||
this.i4 = new bn(4).toRed(this.red).redInvm(); | ||
this.two = new bn(2).toRed(this.red); | ||
this.a = new BN(conf.a, 16).toRed(this.red); | ||
this.b = new BN(conf.b, 16).toRed(this.red); | ||
this.i4 = new BN(4).toRed(this.red).redInvm(); | ||
this.two = new BN(2).toRed(this.red); | ||
this.a24 = this.i4.redMul(this.a.redAdd(this.two)); | ||
@@ -39,4 +39,4 @@ } | ||
} else { | ||
this.x = new bn(x, 16); | ||
this.z = new bn(z, 16); | ||
this.x = new BN(x, 16); | ||
this.z = new BN(z, 16); | ||
if (!this.x.red) | ||
@@ -43,0 +43,0 @@ this.x = this.x.toRed(this.curve.red); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var elliptic = require('../../elliptic'); | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
var inherits = require('inherits'); | ||
@@ -15,4 +15,4 @@ var Base = curve.base; | ||
this.a = new bn(conf.a, 16).toRed(this.red); | ||
this.b = new bn(conf.b, 16).toRed(this.red); | ||
this.a = new BN(conf.a, 16).toRed(this.red); | ||
this.b = new BN(conf.b, 16).toRed(this.red); | ||
this.tinv = this.two.redInvm(); | ||
@@ -40,3 +40,3 @@ | ||
if (conf.beta) { | ||
beta = new bn(conf.beta, 16).toRed(this.red); | ||
beta = new BN(conf.beta, 16).toRed(this.red); | ||
} else { | ||
@@ -49,3 +49,3 @@ var betas = this._getEndoRoots(this.p); | ||
if (conf.lambda) { | ||
lambda = new bn(conf.lambda, 16); | ||
lambda = new BN(conf.lambda, 16); | ||
} else { | ||
@@ -67,4 +67,4 @@ // Choose the lambda that is matching selected beta | ||
return { | ||
a: new bn(vec.a, 16), | ||
b: new bn(vec.b, 16) | ||
a: new BN(vec.a, 16), | ||
b: new BN(vec.b, 16) | ||
}; | ||
@@ -87,7 +87,7 @@ }); | ||
// | ||
var red = num === this.p ? this.red : bn.mont(num); | ||
var tinv = new bn(2).toRed(red).redInvm(); | ||
var red = num === this.p ? this.red : BN.mont(num); | ||
var tinv = new BN(2).toRed(red).redInvm(); | ||
var ntinv = tinv.redNeg(); | ||
var s = new bn(3).toRed(red).redNeg().redSqrt().redMul(tinv); | ||
var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv); | ||
@@ -107,6 +107,6 @@ var l1 = ntinv.redAdd(s).fromRed(); | ||
var v = this.n.clone(); | ||
var x1 = new bn(1); | ||
var y1 = new bn(0); | ||
var x2 = new bn(0); | ||
var y2 = new bn(1); | ||
var x1 = new BN(1); | ||
var y1 = new BN(0); | ||
var x2 = new BN(0); | ||
var y2 = new BN(1); | ||
@@ -196,3 +196,3 @@ // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n) | ||
ShortCurve.prototype.pointFromX = function pointFromX(x, odd) { | ||
x = new bn(x, 16); | ||
x = new BN(x, 16); | ||
if (!x.red) | ||
@@ -265,4 +265,4 @@ x = x.toRed(this.red); | ||
} else { | ||
this.x = new bn(x, 16); | ||
this.y = new bn(y, 16); | ||
this.x = new BN(x, 16); | ||
this.y = new BN(y, 16); | ||
// Force redgomery representation when loading from JSON | ||
@@ -431,3 +431,3 @@ if (isRed) { | ||
Point.prototype.mul = function mul(k) { | ||
k = new bn(k, 16); | ||
k = new BN(k, 16); | ||
@@ -494,7 +494,7 @@ if (this._hasDoubles(k)) | ||
this.y = this.curve.one; | ||
this.z = new bn(0); | ||
this.z = new BN(0); | ||
} else { | ||
this.x = new bn(x, 16); | ||
this.y = new bn(y, 16); | ||
this.z = new bn(z, 16); | ||
this.x = new BN(x, 16); | ||
this.y = new BN(y, 16); | ||
this.z = new BN(z, 16); | ||
} | ||
@@ -883,3 +883,3 @@ if (!this.x.red) | ||
JPoint.prototype.mul = function mul(k, kbase) { | ||
k = new bn(k, kbase); | ||
k = new BN(k, kbase); | ||
@@ -886,0 +886,0 @@ return this.curve._wnafMul(this, k); |
'use strict'; | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
var elliptic = require('../../elliptic'); | ||
@@ -65,5 +65,5 @@ var utils = elliptic.utils; | ||
var bytes = this.n.byteLength(); | ||
var ns2 = this.n.sub(new bn(2)); | ||
var ns2 = this.n.sub(new BN(2)); | ||
do { | ||
var priv = new bn(drbg.generate(bytes)); | ||
var priv = new BN(drbg.generate(bytes)); | ||
if (priv.cmp(ns2) > 0) | ||
@@ -96,14 +96,10 @@ continue; | ||
key = this.keyFromPrivate(key, enc); | ||
msg = this._truncateToN(new bn(msg, 16)); | ||
msg = this._truncateToN(new BN(msg, 16)); | ||
// Zero-extend key to provide enough entropy | ||
var bytes = this.n.byteLength(); | ||
var bkey = key.getPrivate().toArray(); | ||
for (var i = bkey.length; i < bytes; i++) | ||
bkey.unshift(0); | ||
var bkey = key.getPrivate().toArray('be', bytes); | ||
// Zero-extend nonce to have the same byte size as N | ||
var nonce = msg.toArray(); | ||
for (var i = nonce.length; i < bytes; i++) | ||
nonce.unshift(0); | ||
var nonce = msg.toArray('be', bytes); | ||
@@ -118,5 +114,8 @@ // Instantiate Hmac_DRBG | ||
// Number of bytes to generate | ||
var ns1 = this.n.sub(new bn(1)); | ||
do { | ||
var k = new bn(drbg.generate(this.n.byteLength())); | ||
var ns1 = this.n.sub(new BN(1)); | ||
for (var iter = 0; true; iter++) { | ||
var k = options.k ? | ||
options.k(iter) : | ||
new BN(drbg.generate(this.n.byteLength())); | ||
k = this._truncateToN(k, true); | ||
@@ -150,7 +149,7 @@ if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) | ||
return new Signature({ r: r, s: s, recoveryParam: recoveryParam }); | ||
} while (true); | ||
} | ||
}; | ||
EC.prototype.verify = function verify(msg, signature, key, enc) { | ||
msg = this._truncateToN(new bn(msg, 16)); | ||
msg = this._truncateToN(new BN(msg, 16)); | ||
key = this.keyFromPublic(key, enc); | ||
@@ -184,3 +183,3 @@ signature = new Signature(signature, 'hex'); | ||
var n = this.n; | ||
var e = new bn(msg); | ||
var e = new BN(msg); | ||
var r = signature.r; | ||
@@ -187,0 +186,0 @@ var s = signature.s; |
'use strict'; | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
@@ -75,3 +75,3 @@ function KeyPair(ec, options) { | ||
KeyPair.prototype._importPrivate = function _importPrivate(key, enc) { | ||
this.priv = new bn(key, enc || 16); | ||
this.priv = new BN(key, enc || 16); | ||
@@ -78,0 +78,0 @@ // Ensure that the priv won't be bigger than n, otherwise we may fail |
'use strict'; | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
@@ -17,4 +17,4 @@ var elliptic = require('../../elliptic'); | ||
assert(options.r && options.s, 'Signature without r or s'); | ||
this.r = new bn(options.r, 16); | ||
this.s = new bn(options.s, 16); | ||
this.r = new BN(options.r, 16); | ||
this.s = new BN(options.s, 16); | ||
if (options.recoveryParam !== null) | ||
@@ -89,4 +89,4 @@ this.recoveryParam = options.recoveryParam; | ||
this.r = new bn(r); | ||
this.s = new bn(s); | ||
this.r = new BN(r); | ||
this.s = new BN(s); | ||
this.recoveryParam = null; | ||
@@ -93,0 +93,0 @@ |
'use strict'; | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
var elliptic = require('../../elliptic'); | ||
@@ -35,3 +35,3 @@ var utils = elliptic.utils; | ||
this._R = sig.R; | ||
if (sig.S instanceof bn) | ||
if (sig.S instanceof BN) | ||
this._S = sig.S; | ||
@@ -38,0 +38,0 @@ |
'use strict'; | ||
var utils = exports; | ||
var bn = require('bn.js'); | ||
var BN = require('bn.js'); | ||
@@ -170,5 +170,5 @@ utils.assert = function assert(val, msg) { | ||
function intFromLE(bytes) { | ||
return new bn(bytes, 'hex', 'le'); | ||
return new BN(bytes, 'hex', 'le'); | ||
} | ||
utils.intFromLE = intFromLE; | ||
{ | ||
"name": "elliptic", | ||
"version": "6.0.2", | ||
"version": "6.1.0", | ||
"description": "EC cryptography", | ||
@@ -5,0 +5,0 @@ "main": "lib/elliptic.js", |
@@ -65,2 +65,22 @@ # Elliptic [![Build Status](https://secure.travis-ci.org/indutny/elliptic.png)](http://travis-ci.org/indutny/elliptic) [![Coverage Status](https://coveralls.io/repos/indutny/elliptic/badge.svg?branch=master&service=github)](https://coveralls.io/github/indutny/elliptic?branch=master) | ||
console.log(key.verify(msg, derSign)); | ||
// CHECK WITH NO PRIVATE KEY | ||
// Public key as '04 + x + y' | ||
var pub = '04bb1fa3...'; | ||
// Signature MUST be either: | ||
// 1) hex-string of DER-encoded signature; or | ||
// 2) DER-encoded signature as buffer; or | ||
// 3) object with two hex-string properties (r and s) | ||
var signature = 'b102ac...'; // 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)); | ||
``` | ||
@@ -100,2 +120,4 @@ | ||
* `p256` | ||
* `p384` | ||
* `p521` | ||
* `curve25519` | ||
@@ -102,0 +124,0 @@ * `ed25519` |
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
116126
171
3412