Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (i === j)
continue;
const p = BN.decode(primes[i]);
const q = BN.decode(primes[j]);
const n = p.mul(q);
const pm1 = p.subn(1);
const qm1 = q.subn(1);
const phi = pm1.mul(qm1);
let e = null;
let d = null;
for (let i = 1; i < smallPrimes.length; i++) {
try {
e = new BN(smallPrimes[i]);
d = e.invert(phi);
} catch (e) {
continue;
}
break;
}
if (e == null || d == null)
throw new Error('Could not find a suitable exponent!');
const key = new rsa.RSAPrivateKey(
n.encode(),
e.encode(),
d.encode(),
p.encode(),
q.encode()
this.chal = new BN(0);
this.ell = new BN(0);
this.Aq = new BN(0);
this.Bq = new BN(0);
this.Cq = new BN(0);
this.Dq = new BN(0);
this.Eq = new BN(0);
this.z_w = new BN(0);
this.z_w2 = new BN(0);
this.z_s1 = new BN(0);
this.z_a = new BN(0);
this.z_an = new BN(0);
this.z_s1w = new BN(0);
this.z_sa = new BN(0);
this.z_s2 = new BN(0);
if (options != null)
this.init(options);
}
this.chal = new BN(0);
this.ell = new BN(0);
this.Aq = new BN(0);
this.Bq = new BN(0);
this.Cq = new BN(0);
this.Dq = new BN(0);
this.Eq = new BN(0);
this.z_w = new BN(0);
this.z_w2 = new BN(0);
this.z_s1 = new BN(0);
this.z_a = new BN(0);
this.z_an = new BN(0);
this.z_s1w = new BN(0);
this.z_sa = new BN(0);
this.z_s2 = new BN(0);
if (options != null)
this.init(options);
}
init(key, nonce) {
assert(Buffer.isBuffer(key));
assert(Buffer.isBuffer(nonce));
assert(key.length === 32);
assert(nonce.length >= 24);
this.ctx.init(key, nonce.slice(0, 24));
this.save = new BN(0);
this.total = 0;
return this;
}
constructor(options) {
this.C2 = new BN(0);
this.C3 = new BN(0);
this.t = new BN(0);
this.chal = new BN(0);
this.ell = new BN(0);
this.Aq = new BN(0);
this.Bq = new BN(0);
this.Cq = new BN(0);
this.Dq = new BN(0);
this.Eq = new BN(0);
this.z_w = new BN(0);
this.z_w2 = new BN(0);
this.z_s1 = new BN(0);
this.z_a = new BN(0);
this.z_an = new BN(0);
this.z_s1w = new BN(0);
this.z_sa = new BN(0);
this.z_s2 = new BN(0);
if (options != null)
this.init(options);
}
'use strict';
const assert = require('bsert');
const bio = require('bufio');
const BN = require('bcrypto/lib/bn.js');
const consensus = require('../protocol/consensus');
const Headers = require('../primitives/headers');
const InvItem = require('../primitives/invitem');
const util = require('../utils/util');
/*
* Constants
*/
const ZERO = new BN(0);
/**
* Chain Entry
* Represents an entry in the chain.
* @alias module:blockchain.ChainEntry
* @property {Hash} hash
* @property {Number} version
* @property {Hash} prevBlock
* @property {Hash} merkleRoot
* @property {Hash} witnessRoot
* @property {Hash} treeRoot
* @property {Hash} filterRoot
* @property {Hash} reservedRoot
* @property {Number} time
* @property {Number} bits
* @property {Buffer} nonce
constructor(n, g, h, bits) {
if (bits == null)
bits = 0;
assert(Buffer.isBuffer(n));
assert((g >>> 0) === g);
assert((h >>> 0) === h);
assert((bits >>> 0) === bits);
this.n = BN.decode(n);
this.red = BN.red(this.n);
this.g = new BN(g).toRed(this.red);
this.h = new BN(h).toRed(this.red);
this.nh = this.n.ushrn(1);
this.bits = this.n.bitLength();
this.size = (this.bits + 7) >>> 3;
this.randBits = this.bits - 1;
this.groupHash = SHA256.multi(this.g.fromRed().encode('be', 4),
this.h.fromRed().encode('be', 4),
this.n.encode('be'));
this.zero = new BN(0).toRed(this.red);
this.one = new BN(1).toRed(this.red);
this.wnaf0 = new Int32Array(constants.MAX_RSA_BITS + 1);
this.wnaf1 = new Int32Array(constants.ELL_BITS + 1);
constructor(options) {
this.C2 = new BN(0);
this.C3 = new BN(0);
this.t = new BN(0);
this.chal = new BN(0);
this.ell = new BN(0);
this.Aq = new BN(0);
this.Bq = new BN(0);
this.Cq = new BN(0);
this.Dq = new BN(0);
this.Eq = new BN(0);
this.z_w = new BN(0);
this.z_w2 = new BN(0);
this.z_s1 = new BN(0);
this.z_a = new BN(0);
this.z_an = new BN(0);
this.z_s1w = new BN(0);
this.z_sa = new BN(0);
constructor(options) {
this.C2 = new BN(0);
this.C3 = new BN(0);
this.t = new BN(0);
this.chal = new BN(0);
this.ell = new BN(0);
this.Aq = new BN(0);
this.Bq = new BN(0);
this.Cq = new BN(0);
this.Dq = new BN(0);
this.Eq = new BN(0);
this.z_w = new BN(0);
this.z_w2 = new BN(0);
this.z_s1 = new BN(0);
this.z_a = new BN(0);
this.z_an = new BN(0);
this.z_s1w = new BN(0);
if (p.isEven()) {
inc += 1;
p.iaddn(1);
}
while (!isPrime(p, key)) {
if (max != null && inc > max)
break;
p.iaddn(2);
inc += 2;
}
if (max != null && inc > max)
return new BN(0);
return p;
}