How to use the mont function from bn.js

Find comprehensive JavaScript bn.js.mont code examples handpicked from public code repositorys.

132
133
134
135
136
137
138
139
140
141
}

function DH(prime, generator, malleable) {
  this.setGenerator(generator);
  this.__prime = new BN(prime);
  this._prime = BN.mont(this.__prime);
  this._primeLen = prime.length;
  this._pub = undefined;
  this._priv = undefined;
  this._primeCode = undefined;
fork icon11
star icon13
watch icon8

74
75
76
77
78
79
80
81
82
83
84
85


ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  // Find roots of for x^2 + x + 1 in F
  // Root = (-1 +- Sqrt(-3)) / 2
  //
  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);
fork icon7
star icon287
watch icon0

+ 2 other calls in file

28
29
30
31
32
33
34
35
36
37
38
39
  return start.add(this._randbelow(size));
};


MillerRabin.prototype.test = function test(n, k, cb) {
  var len = n.bitLength();
  var red = bn.mont(n);
  var rone = new bn(1).toRed(red);


  if (!k)
    k = Math.max(1, (len / 48) | 0);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

62
63
64
65
66
67
68
69
70
71
var unpacked = parseKeys.signature.decode(sig, 'der')
var s = unpacked.s
var r = unpacked.r
checkValue(s, q)
checkValue(r, q)
var montp = BN.mont(p)
var w = s.invm(q)
var v = g.toRed(montp)
  .redPow(new BN(hash).mul(w).mod(q))
  .fromRed()
fork icon0
star icon0
watch icon0

+ 3 other calls in file