Пример #1
0
  public static BigPoint addPoint(BigPoint left, BigPoint right) {
    if (left == right.getNegativePoint())
      throw new IllegalArgumentException("Für Punktaddition von P und Q muss P != -Q sein!");

    BigInteger s = BigInteger.ZERO, xR, yR;

    // s = (Y_P - Y_Q) / (X_P - X_Q) mod p = (Y_P - Y_Q) * (X_P - X_Q)^-1
    // mod p

    s =
        left.Y
            .subtract(right.Y)
            .multiply(
                ECCField.GetInverseValue(
                    left.X.subtract(right.X), Configuration._ellipticCurveParamP))
            .mod(Configuration._ellipticCurveParamP);

    // -> Berechnungen aufgedröselt:
    // BigInteger s1, s2, s3, s4, s5;
    // s1 = BigInteger.Subtract(left.Y, right.Y);
    // s2 = BigInteger.Subtract(left.X, right.X);
    // s3 = GetInverseValue(s2, Configuration._ellipticCurveParamP);
    // s4 = BigInteger.Multiply(s1, s3);
    // s5 = BigInteger.ModPow(s4, 1, Configuration._ellipticCurveParamP);
    // s = s5;

    // Normalisieren
    if (s.compareTo(BigInteger.ZERO) < 0) s = s.add(Configuration._ellipticCurveParamP);

    xR =
        s.modPow(new BigInteger("2"), Configuration._ellipticCurveParamP)
            .subtract(left.X)
            .subtract(right.X)
            .mod(Configuration._ellipticCurveParamP);

    // Normalisieren
    if (xR.compareTo(BigInteger.ZERO) < 0) xR = xR.add(Configuration._ellipticCurveParamP);

    yR =
        left.Y
            .negate()
            .add(s.multiply(left.X.subtract(xR)))
            .mod(Configuration._ellipticCurveParamP);

    // Normalisieren
    if (yR.compareTo(BigInteger.ZERO) < 0) yR = yR.add(Configuration._ellipticCurveParamP);

    return new BigPoint(xR, yR);
  }
Пример #2
0
 public static boolean equals(BigPoint left, BigPoint right) {
   return ((left.X.compareTo(right.X) == 0) && (left.Y.abs().compareTo(right.Y.abs())) == 0);
 }