Sha256: 6425a097b26b8fd083d1a525e66e4cdc12e3393be1c86e4727d1d5863b38edab

Contents?: true

Size: 1.18 KB

Versions: 39

Compression:

Stored size: 1.18 KB

Contents

var bn = require('bn.js');
var randomBytes = require('randombytes');
module.exports = crt;
function blind(priv) {
  var r = getr(priv);
  var blinder = r.toRed(bn.mont(priv.modulus))
  .redPow(new bn(priv.publicExponent)).fromRed();
  return {
    blinder: blinder,
    unblinder:r.invm(priv.modulus)
  };
}
function crt(msg, priv) {
  var blinds = blind(priv);
  var len = priv.modulus.byteLength();
  var mod = bn.mont(priv.modulus);
  var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
  var c1 = blinded.toRed(bn.mont(priv.prime1));
  var c2 = blinded.toRed(bn.mont(priv.prime2));
  var qinv = priv.coefficient;
  var p = priv.prime1;
  var q = priv.prime2;
  var m1 = c1.redPow(priv.exponent1);
  var m2 = c2.redPow(priv.exponent2);
  m1 = m1.fromRed();
  m2 = m2.fromRed();
  var h = m1.isub(m2).imul(qinv).umod(p);
  h.imul(q);
  m2.iadd(h);
  return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
}
crt.getr = getr;
function getr(priv) {
  var len = priv.modulus.byteLength();
  var r = new bn(randomBytes(len));
  while (r.cmp(priv.modulus) >=  0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
    r = new bn(randomBytes(len));
  }
  return r;
}

Version data entries

39 entries across 39 versions & 13 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/browserify-rsa/index.js
disco_app-0.18.0 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.18.2 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.16.1 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.15.2 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.18.4 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.18.1 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.14.0 test/dummy/node_modules/browserify-rsa/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/browserify-rsa/index.js
tang-0.2.1 spec/tang_app/node_modules/browserify-rsa/index.js
tang-0.2.0 spec/tang_app/node_modules/browserify-rsa/index.js
tang-0.1.0 spec/tang_app/node_modules/browserify-rsa/index.js
tang-0.0.9 spec/tang_app/node_modules/browserify-rsa/index.js
enju_library-0.3.8 spec/dummy/node_modules/browserify-rsa/index.js
ilog-0.4.1 node_modules/browserify-rsa/index.js
ilog-0.4.0 node_modules/browserify-rsa/index.js
ilog-0.3.3 node_modules/browserify-rsa/index.js
jester-data-8.0.0 node_modules/browserify-rsa/index.js
ezii-os-5.2.1 node_modules/browserify-rsa/index.js