Skip to content

Commit

Permalink
6.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed May 25, 2016
1 parent 0d7910d commit 6a8ef14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
38 changes: 18 additions & 20 deletions dist/elliptic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3935,10 +3935,7 @@ utils.intFromLE = intFromLE;
// BN

function BN (number, base, endian) {
// May be `new BN(bn)` ?
if (number !== null &&
typeof number === 'object' &&
Array.isArray(number.words)) {
if (BN.isBN(number)) {
return number;
}

Expand Down Expand Up @@ -3973,6 +3970,11 @@ utils.intFromLE = intFromLE;
} catch (e) {
}

BN.isBN = function isBN (num) {
return num !== null && typeof num === 'object' &&
num.constructor.name === 'BN' && Array.isArray(num.words);
};

BN.max = function max (left, right) {
if (left.cmp(right) > 0) return left;
return right;
Expand Down Expand Up @@ -4131,6 +4133,7 @@ utils.intFromLE = intFromLE;
for (i = number.length - 6, j = 0; i >= start; i -= 6) {
w = parseHex(number, i, i + 6);
this.words[j] |= (w << off) & 0x3ffffff;
// NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
off += 24;
if (off >= 26) {
Expand Down Expand Up @@ -4405,16 +4408,13 @@ utils.intFromLE = intFromLE;
};

BN.prototype.toNumber = function toNumber () {
var length = this.bitLength();
var ret;
if (length <= 26) {
ret = this.words[0];
} else if (length <= 52) {
ret = (this.words[1] * 0x4000000) + this.words[0];
} else if (length === 53) {
var ret = this.words[0];
if (this.length === 2) {
ret += this.words[1] * 0x4000000;
} else if (this.length === 3 && this.words[2] === 0x01) {
// NOTE: at this stage it is known that the top bit is set
ret = 0x10000000000000 + (this.words[1] * 0x4000000) + this.words[0];
} else {
ret += 0x10000000000000 + (this.words[1] * 0x4000000);
} else if (this.length > 2) {
assert(false, 'Number can only safely store up to 53 bits');
}
return (this.negative !== 0) ? -ret : ret;
Expand Down Expand Up @@ -6652,9 +6652,7 @@ utils.intFromLE = intFromLE;
var w = this.words[0] | 0;
res = w === num ? 0 : w < num ? -1 : 1;
}
if (this.negative !== 0) {
res = -res;
}
if (this.negative !== 0) return -res | 0;
return res;
};

Expand All @@ -6667,8 +6665,7 @@ utils.intFromLE = intFromLE;
if (this.negative === 0 && num.negative !== 0) return 1;

var res = this.ucmp(num);
if (this.negative !== 0) return -res;

if (this.negative !== 0) return -res | 0;
return res;
};

Expand Down Expand Up @@ -6785,7 +6782,7 @@ utils.intFromLE = intFromLE;

BN.prototype.redShl = function redShl (num) {
assert(this.red, 'redShl works only with red numbers');
return this.red.ushl(this, num);
return this.red.shl(this, num);
};

BN.prototype.redMul = function redMul (num) {
Expand Down Expand Up @@ -7037,6 +7034,7 @@ utils.intFromLE = intFromLE;
this.m = prime.p;
this.prime = prime;
} else {
assert(m.gtn(1), 'modulus must be greater than 1');
this.m = m;
this.prime = null;
}
Expand Down Expand Up @@ -8554,7 +8552,7 @@ if (typeof Object.create === 'function') {
},{}],26:[function(require,module,exports){
module.exports={
"name": "elliptic",
"version": "6.2.6",
"version": "6.2.7",
"description": "EC cryptography",
"main": "lib/elliptic.js",
"files": [
Expand Down
Loading

0 comments on commit 6a8ef14

Please sign in to comment.