@Test
  public void ecPointOperationsAreConsistent() throws Exception {
    BigInteger p = EllipticCurvesUtil.getModulus(EllipticCurvesUtil.NIST_P256_PARAMS.getCurve());
    BigInteger a = EllipticCurvesUtil.NIST_P256_PARAMS.getCurve().getA();
    ECPoint point = EllipticCurvesUtil.NIST_P256_PARAMS.getGenerator();
    EllipticCurvesUtil.JacobianEcPoint jpoint = EllipticCurvesUtil.toJacobianEcPoint(point, p);
    EllipticCurvesUtil.JacobianEcPoint jpoint2 =
        EllipticCurvesUtil.addJacobianPoints(jpoint, jpoint, a, p);
    EllipticCurvesUtil.JacobianEcPoint jpoint3 =
        EllipticCurvesUtil.addJacobianPoints(jpoint2, jpoint, a, p);
    EllipticCurvesUtil.JacobianEcPoint jpoint4 =
        EllipticCurvesUtil.addJacobianPoints(jpoint3, jpoint, a, p);

    point = jpoint.toECPoint(p);
    ECPoint point2 = jpoint2.toECPoint(p);
    ECPoint point3 = jpoint3.toECPoint(p);
    ECPoint point4 = jpoint4.toECPoint(p);

    // All these points should be on P256.
    EllipticCurvesUtil.checkPointOnCurve(point, EllipticCurvesUtil.NIST_P256_PARAMS.getCurve());
    EllipticCurvesUtil.checkPointOnCurve(point2, EllipticCurvesUtil.NIST_P256_PARAMS.getCurve());
    EllipticCurvesUtil.checkPointOnCurve(point3, EllipticCurvesUtil.NIST_P256_PARAMS.getCurve());
    EllipticCurvesUtil.checkPointOnCurve(point4, EllipticCurvesUtil.NIST_P256_PARAMS.getCurve());

    // Other ways to calculate these points. All calculations should be consistent.
    assertThat(EllipticCurvesUtil.doubleJacobianPoint(jpoint, a, p).toECPoint(p)).isEqualTo(point2);
    assertThat(EllipticCurvesUtil.doubleJacobianPoint(jpoint2, a, p).toECPoint(p))
        .isEqualTo(point4);
    assertThat(EllipticCurvesUtil.addJacobianPoints(jpoint, jpoint2, a, p).toECPoint(p))
        .isEqualTo(point3);
    assertThat(EllipticCurvesUtil.addJacobianPoints(jpoint, jpoint3, a, p).toECPoint(p))
        .isEqualTo(point4);
    assertThat(EllipticCurvesUtil.addJacobianPoints(jpoint2, jpoint2, a, p).toECPoint(p))
        .isEqualTo(point4);
    assertThat(
            EllipticCurvesUtil.multiplyByGenerator(
                BigInteger.ONE, EllipticCurvesUtil.NIST_P256_PARAMS))
        .isEqualTo(point);
    assertThat(
            EllipticCurvesUtil.multiplyByGenerator(
                BigInteger.valueOf(2), EllipticCurvesUtil.NIST_P256_PARAMS))
        .isEqualTo(point2);
    assertThat(
            EllipticCurvesUtil.multiplyByGenerator(
                BigInteger.valueOf(3), EllipticCurvesUtil.NIST_P256_PARAMS))
        .isEqualTo(point3);
    assertThat(
            EllipticCurvesUtil.multiplyByGenerator(
                BigInteger.valueOf(4), EllipticCurvesUtil.NIST_P256_PARAMS))
        .isEqualTo(point4);
  }
Unit tests for {@link com.google.crypto.tink.subtle.EllipticCurvesUtil}.
java_src/src/test/java/com/google/crypto/tink/internal/EllipticCurvesUtilTest.java