org.spongycastle.math.ec.ECCurve.getInfinity()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.spongycastle.math.ec.ECCurve.getInfinity()方法的一些代码示例,展示了ECCurve.getInfinity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ECCurve.getInfinity()方法的具体详情如下:
包路径:org.spongycastle.math.ec.ECCurve
类名称:ECCurve
方法名:getInfinity

ECCurve.getInfinity介绍

暂无

代码示例

代码示例来源:origin: com.madgag/sc-light-jdk15on

/**
 * Multiplies this <code>ECPoint</code> by the given number.
 * @param k The multiplicator.
 * @return <code>k * this</code>.
 */
public ECPoint multiply(BigInteger k)
{
  if (k.signum() < 0)
  {
    throw new IllegalArgumentException("The multiplicator cannot be negative");
  }
  if (this.isInfinity())
  {
    return this;
  }
  if (k.signum() == 0)
  {
    return this.curve.getInfinity();
  }
  assertECMultiplier();
  return this.multiplier.multiply(this, k, preCompInfo);
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
   * Joye's double-add algorithm.
   */
  protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
  {
    ECPoint[] R = new ECPoint[]{ p.getCurve().getInfinity(), p };

    int n = k.bitLength();
    for (int i = 0; i < n; ++i)
    {
      int b = k.testBit(i) ? 1 : 0;
      int bp = 1 - b;
      R[bp] = R[bp].twicePlus(R[b]);
    }

    return R[0];
  }
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

private static void assertNonInfinity(ECPoint point, String errorMessage) {
  if (point.equals(ECKey.CURVE.getCurve().getInfinity()))
    throw new HDDerivationException(errorMessage);
}

代码示例来源:origin: HashEngineering/dashj

private static void assertNonInfinity(ECPoint point, String errorMessage) {
  if (point.equals(ECKey.CURVE.getCurve().getInfinity()))
    throw new HDDerivationException(errorMessage);
}

代码示例来源:origin: fr.acinq/bitcoinj-core

private static void assertNonInfinity(ECPoint point, String errorMessage) {
  if (point.equals(ECKey.CURVE.getCurve().getInfinity()))
    throw new HDDerivationException(errorMessage);
}

代码示例来源:origin: com.madgag.spongycastle/core

public ECPoint multiply(ECPoint p, BigInteger k)
{
  int sign = k.signum();
  if (sign == 0 || p.isInfinity())
  {
    return p.getCurve().getInfinity();
  }
  ECPoint positive = multiplyPositive(p, k.abs());
  ECPoint result = sign > 0 ? positive : positive.negate();
  /*
   * Although the various multipliers ought not to produce invalid output under normal
   * circumstances, a final check here is advised to guard against fault attacks.
   */
  return ECAlgorithms.validatePoint(result);
}

代码示例来源:origin: greenaddress/GreenBits

private static void assertNonInfinity(ECPoint point, String errorMessage) {
  if (point.equals(ECKey.CURVE.getCurve().getInfinity()))
    throw new HDDerivationException(errorMessage);
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
   * Montgomery ladder.
   */
  protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
  {
    ECPoint[] R = new ECPoint[]{ p.getCurve().getInfinity(), p };

    int n = k.bitLength();
    int i = n;
    while (--i >= 0)
    {
      int b = k.testBit(i) ? 1 : 0;
      int bp = 1 - b;
      R[bp] = R[bp].add(R[b]);
      R[b] = R[b].twice();
    }
    return R[0];
  }
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

/**
   * Simple shift-and-add multiplication. Serves as reference implementation
   * to verify (possibly faster) implementations in
   * {@link org.spongycastle.math.ec.ECPoint ECPoint}.
   * 
   * @param p The point to multiply.
   * @param k The factor by which to multiply.
   * @return The result of the point multiplication <code>k * p</code>.
   */
  public ECPoint multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
  {
    ECPoint q = p.getCurve().getInfinity();
    int t = k.bitLength();
    for (int i = 0; i < t; i++)
    {
      if (k.testBit(i))
      {
        q = q.add(p);
      }
      p = p.twice();
    }
    return q;
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public ECPoint twice()
{
  if (this.isInfinity())
  {
    return this;
  }
  ECCurve curve = this.getCurve();
  ECFieldElement Y1 = this.y;
  if (Y1.isZero()) 
  {
    return curve.getInfinity();
  }
  return twiceJacobianModified(true);
}

代码示例来源:origin: com.madgag.spongycastle/core

protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
  {
    int[] naf = WNafUtil.generateCompactNaf(k);

    ECPoint R0 = p.getCurve().getInfinity(), R1 = p;

    int zeroes = 0;
    for (int i = 0; i < naf.length; ++i)
    {
      int ni = naf[i];
      int digit = ni >> 16;
      zeroes += ni & 0xFFFF;

      R1 = R1.timesPow2(zeroes);
      R0 = R0.add(digit < 0 ? R1.negate() : R1);

      zeroes = 1;
    }

    return R0;
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
   * 'Zeroless' Signed Digit Right-to-Left.
   */
  protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
  {
    ECPoint R0 = p.getCurve().getInfinity(), R1 = p;

    int n = k.bitLength();
    int s = k.getLowestSetBit();

    R1 = R1.timesPow2(s);

    int i = s;
    while (++i < n)
    {
      R0 = R0.add(k.testBit(i) ? R1 : R1.negate());
      R1 = R1.twice();
    }

    R0 = R0.add(R1);

    return R0;
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
  {
    int[] naf = WNafUtil.generateCompactNaf(k);

    ECPoint addP = p.normalize(), subP = addP.negate();

    ECPoint R = p.getCurve().getInfinity();

    int i = naf.length;
    while (--i >= 0)
    {
      int ni = naf[i];
      int digit = ni >> 16, zeroes = ni & 0xFFFF;

      R = R.twicePlus(digit < 0 ? subP : addP);
      R = R.timesPow2(zeroes);
    }

    return R;
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public ECPoint importPoint(ECPoint p)
{
  if (this == p.getCurve())
  {
    return p;
  }
  if (p.isInfinity())
  {
    return getInfinity();
  }
  // TODO Default behaviour could be improved if the two curves have the same coordinate system by copying any Z coordinates.
  p = p.normalize();
  return validatePoint(p.getXCoord().toBigInteger(), p.getYCoord().toBigInteger(), p.withCompression);
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

public ECPoint twice()
{
  if (this.isInfinity())
  {
    // Twice identity element (point at infinity) is identity
    return this;
  }
  if (this.y.toBigInteger().signum() == 0) 
  {
    // if y1 == 0, then (x1, y1) == (x1, -y1)
    // and hence this = -this and thus 2(x1, y1) == infinity
    return this.curve.getInfinity();
  }
  ECFieldElement TWO = this.curve.fromBigInteger(BigInteger.valueOf(2));
  ECFieldElement THREE = this.curve.fromBigInteger(BigInteger.valueOf(3));
  ECFieldElement gamma = this.x.square().multiply(THREE).add(curve.a).divide(y.multiply(TWO));
  ECFieldElement x3 = gamma.square().subtract(this.x.multiply(TWO));
  ECFieldElement y3 = gamma.multiply(this.x.subtract(x3)).subtract(this.y);
    
  return new ECPoint.Fp(curve, x3, y3, this.withCompression);
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

public ECPoint twice()
{
  if (this.isInfinity()) 
  {
    // Twice identity element (point at infinity) is identity
    return this;
  }
  if (this.x.toBigInteger().signum() == 0) 
  {
    // if x1 == 0, then (x1, y1) == (x1, x1 + y1)
    // and hence this = -this and thus 2(x1, y1) == infinity
    return this.curve.getInfinity();
  }
  ECFieldElement.F2m lambda
    = (ECFieldElement.F2m)this.x.add(this.y.divide(this.x));
  ECFieldElement.F2m x3
    = (ECFieldElement.F2m)lambda.square().add(lambda).
      add(this.curve.getA());
  ECFieldElement ONE = this.curve.fromBigInteger(ECConstants.ONE);
  ECFieldElement.F2m y3
    = (ECFieldElement.F2m)this.x.square().add(
      x3.multiply(lambda.add(ONE)));
  return new ECPoint.F2m(this.curve, x3, y3, withCompression);
}

代码示例来源:origin: com.madgag.spongycastle/core

static ECPoint implShamirsTrickJsf(ECPoint P, BigInteger k,
  ECPoint Q, BigInteger l)
{
  ECCurve curve = P.getCurve();
  ECPoint infinity = curve.getInfinity();
  // TODO conjugate co-Z addition (ZADDC) can return both of these
  ECPoint PaddQ = P.add(Q);
  ECPoint PsubQ = P.subtract(Q);
  ECPoint[] points = new ECPoint[]{ Q, PsubQ, P, PaddQ };
  curve.normalizeAll(points);
  ECPoint[] table = new ECPoint[] {
    points[3].negate(), points[2].negate(), points[1].negate(),
    points[0].negate(), infinity, points[0],
    points[1], points[2], points[3] };
  byte[] jsf = WNafUtil.generateJSF(k, l);
  ECPoint R = infinity;
  int i = jsf.length;
  while (--i >= 0)
  {
    int jsfi = jsf[i];
    // NOTE: The shifting ensures the sign is extended correctly
    int kDigit = ((jsfi << 24) >> 28), lDigit = ((jsfi << 28) >> 28);
    int index = 4 + (kDigit * 3) + lDigit;
    R = R.twicePlus(table[index]);
  }
  return R;
}

代码示例来源:origin: com.madgag.spongycastle/core

public ECPoint twice()
{
  if (this.isInfinity())
  {
    return this;
  }
  ECCurve curve = this.getCurve();
  ECFieldElement X1 = this.x;
  if (X1.isZero())
  {
    // A point with X == 0 is it's own additive inverse
    return curve.getInfinity();
  }
  ECFieldElement L1 = this.y, Z1 = this.zs[0];
  boolean Z1IsOne = Z1.isOne();
  ECFieldElement L1Z1 = Z1IsOne ? L1 : L1.multiply(Z1);
  ECFieldElement Z1Sq = Z1IsOne ? Z1 : Z1.square();
  ECFieldElement T = L1.square().add(L1Z1).add(Z1Sq);
  if (T.isZero())
  {
    return new SecT409R1Point(curve, T, curve.getB().sqrt(), withCompression);
  }
  ECFieldElement X3 = T.square();
  ECFieldElement Z3 = Z1IsOne ? T : T.multiply(Z1Sq);
  ECFieldElement X1Z1 = Z1IsOne ? X1 : X1.multiply(Z1);
  ECFieldElement L3 = X1Z1.squarePlusProduct(T, L1Z1).add(X3).add(Z3);
  return new SecT409R1Point(curve, X3, L3, new ECFieldElement[]{ Z3 }, this.withCompression);
}

代码示例来源:origin: com.madgag.spongycastle/core

public ECPoint twice()
{
  if (this.isInfinity())
  {
    return this;
  }
  ECCurve curve = this.getCurve();
  ECFieldElement X1 = this.x;
  if (X1.isZero())
  {
    // A point with X == 0 is it's own additive inverse
    return curve.getInfinity();
  }
  ECFieldElement L1 = this.y, Z1 = this.zs[0];
  boolean Z1IsOne = Z1.isOne();
  ECFieldElement L1Z1 = Z1IsOne ? L1 : L1.multiply(Z1);
  ECFieldElement Z1Sq = Z1IsOne ? Z1 : Z1.square();
  ECFieldElement T = L1.square().add(L1Z1).add(Z1Sq);
  if (T.isZero())
  {
    return new SecT163R2Point(curve, T, curve.getB().sqrt(), withCompression);
  }
  ECFieldElement X3 = T.square();
  ECFieldElement Z3 = Z1IsOne ? T : T.multiply(Z1Sq);
  ECFieldElement X1Z1 = Z1IsOne ? X1 : X1.multiply(Z1);
  ECFieldElement L3 = X1Z1.squarePlusProduct(T, L1Z1).add(X3).add(Z3);
  return new SecT163R2Point(curve, X3, L3, new ECFieldElement[]{ Z3 }, this.withCompression);
}

代码示例来源:origin: com.madgag.spongycastle/core

public ECPoint twice()
{
  if (this.isInfinity())
  {
    return this;
  }
  ECCurve curve = this.getCurve();
  ECFieldElement X1 = this.x;
  if (X1.isZero())
  {
    // A point with X == 0 is it's own additive inverse
    return curve.getInfinity();
  }
  ECFieldElement L1 = this.y, Z1 = this.zs[0];
  boolean Z1IsOne = Z1.isOne();
  ECFieldElement L1Z1 = Z1IsOne ? L1 : L1.multiply(Z1);
  ECFieldElement Z1Sq = Z1IsOne ? Z1 : Z1.square();
  ECFieldElement T = L1.square().add(L1Z1).add(Z1Sq);
  if (T.isZero())
  {
    return new SecT163K1Point(curve, T, curve.getB(), withCompression);
  }
  ECFieldElement X3 = T.square();
  ECFieldElement Z3 = Z1IsOne ? T : T.multiply(Z1Sq);
  ECFieldElement t1 = L1.add(X1).square();
  ECFieldElement L3 = t1.add(T).add(Z1Sq).multiply(t1).add(X3);
  return new SecT163K1Point(curve, X3, L3, new ECFieldElement[]{ Z3 }, this.withCompression);
}

相关文章