Ejemplo n.º 1
0
ECFieldElementFp.prototype.getR = function() {
  if (this.r != undefined) return this.r;

  this.r = null;
  var bitLength = this.q.bitLength();
  if (bitLength > 128) {
    var firstWord = this.q.shiftRight(bitLength - 64);
    if (firstWord.intValue() == -1) {
      this.r = BigInteger.ONE.shiftLeft(bitLength).subtract(this.q);
    }
  }
  return this.r;
};
Ejemplo n.º 2
0
ECFieldElementFp.prototype.lucasSequence = function(P, Q, k) {
  var n = k.bitLength();
  var s = k.getLowestSetBit();

  var Uh = BigInteger.ONE;
  var Vl = BigInteger.ONE.add(BigInteger.ONE);
  var Vh = P;
  var Ql = BigInteger.ONE;
  var Qh = BigInteger.ONE;

  for (var j = n - 1; j >= s + 1; --j) {
    Ql = this.modMult(Ql, Qh);

    if (k.testBit(j)) {
      Qh = this.modMult(Ql, Q);
      Uh = this.modMult(Uh, Vh);
      Vl = this.modReduce(Vh.multiply(Vl).subtract(P.multiply(Ql)));
      Vh = this.modReduce(Vh.multiply(Vh).subtract(Qh.shiftLeft(1)));
    } else {
      Qh = Ql;
      Uh = this.modReduce(Uh.multiply(Vl).subtract(Ql));
      Vh = this.modReduce(Vh.multiply(Vl).subtract(P.multiply(Ql)));
      Vl = this.modReduce(Vl.multiply(Vl).subtract(Ql.shiftLeft(1)));
    }
  }

  Ql = this.modMult(Ql, Qh);
  Qh = this.modMult(Ql, Q);
  Uh = this.modReduce(Uh.multiply(Vl).subtract(Ql));
  Vl = this.modReduce(Vh.multiply(Vl).subtract(P.multiply(Ql)));
  Ql = this.modMult(Ql, Qh);

  for (var j = 1; j <= s; ++j) {
    Uh = this.modMult(Uh, Vl);
    Vl = this.modReduce(Vl.multiply(Vl).subtract(Ql.shiftLeft(1)));
    Ql = this.modMult(Ql, Ql);
  }

  return [Uh, Vl];
};