Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bn.js

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bn.js - npm Package Compare versions

Comparing version 0.15.1 to 0.15.2

test/fixtures.js

53

lib/bn.js

@@ -620,4 +620,3 @@ // Utils

// Multiply `this` by `num` and store data in out
BN.prototype.mulTo = function mulTo(num, out) {
BN.prototype._smallMulTo = function _smallMulTo(num, out) {
out.sign = num.sign !== this.sign;

@@ -657,2 +656,52 @@ out.length = this.length + num.length;

BN.prototype._bigMulTo = function _bigMulTo(num, out) {
out.sign = num.sign !== this.sign;
out.length = this.length + num.length;
var carry = 0;
var hncarry = 0;
for (var k = 0; k < out.length - 1; k++) {
// Sum all words with the same `i + j = k` and accumulate `ncarry`,
// note that ncarry could be >= 0x3ffffff
var ncarry = hncarry;
hncarry = 0;
var rword = carry & 0x3ffffff;
var maxJ = Math.min(k, num.length - 1);
for (var j = Math.max(0, k - this.length + 1); j <= maxJ; j++) {
var i = k - j;
var a = this.words[i] | 0;
var b = num.words[j] | 0;
var r = a * b;
var lo = r & 0x3ffffff;
ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
lo = (lo + rword) | 0;
rword = lo & 0x3ffffff;
ncarry = (ncarry + (lo >>> 26)) | 0;
hncarry += ncarry >>> 26;
ncarry &= 0x3ffffff;
}
out.words[k] = rword;
carry = ncarry;
ncarry = hncarry;
}
if (carry !== 0) {
out.words[k] = carry;
} else {
out.length--;
}
return out.strip();
};
BN.prototype.mulTo = function mulTo(num, out) {
var res;
if (this.length + num.length < 63)
res = this._smallMulTo(num, out);
else
res = this._bigMulTo(num, out);
return res;
};
// Multiply `this` by `num`

@@ -659,0 +708,0 @@ BN.prototype.mul = function mul(num) {

2

package.json
{
"name": "bn.js",
"version": "0.15.1",
"version": "0.15.2",
"description": "Big number implementation in pure javascript",

@@ -5,0 +5,0 @@ "main": "lib/bn.js",

var assert = require('assert');
var BN = require('../').BN;
var fixtures = require('./fixtures');

@@ -215,2 +216,10 @@ describe('BN', function() {

it('should regress mul big numbers', function() {
var q = fixtures.dhGroups.p17.q;
var qs = fixtures.dhGroups.p17.qs;
var q = new BN(q, 16);
assert.equal(q.sqr().toString(16), qs);
});
it('should imul numbers', function() {

@@ -217,0 +226,0 @@ var a = new BN('abcdef01234567890abcd', 16);

var assert = require('assert');
var BN = require('../').BN;
var fixtures = require('./fixtures');

@@ -4,0 +5,0 @@ describe('BN.js/Reduction context', function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc