/** * Test method for {@link GroupElement#equals(java.lang.Object)}. */ @Test public void testEqualsObject() { assertThat(GroupElement.p2(curve, ZERO, ONE, ONE), is(equalTo(P2_ZERO))); }
public Curve(Field f, byte[] d, FieldElement I) { this.f = f; this.d = f.fromByteArray(d); this.d2 = this.d.add(this.d); this.I = I; FieldElement zero = f.ZERO; FieldElement one = f.ONE; zeroP2 = GroupElement.p2(this, zero, one, one); zeroP3 = GroupElement.p3(this, zero, one, one, zero, false); zeroP3PrecomputedDouble = GroupElement.p3(this, zero, one, one, zero, true); zeroPrecomp = GroupElement.precomp(this, one, one, zero); }
/** * Test method for {@link GroupElement#isOnCurve(Curve)}. */ @Test public void testIsOnCurve() { assertThat(P2_ZERO.isOnCurve(curve), is(true)); assertThat(GroupElement.p2(curve, ZERO, ZERO, ONE).isOnCurve(curve), is(false)); assertThat(GroupElement.p2(curve, ONE, ONE, ONE).isOnCurve(curve), is(false)); assertThat(GroupElement.p2(curve, TEN, ZERO, ONE).isOnCurve(curve), is(false)); assertThat(GroupElement.p2(curve, ONE, TEN, ONE).isOnCurve(curve), is(false)); assertThat(GroupElement.p2(curve, PKR[0], PKR[1], ONE).isOnCurve(curve), is(true)); }
/** * Test method for {@link GroupElement#p2(Curve, FieldElement, FieldElement, FieldElement)}. */ @Test public void testP2() { final GroupElement t = GroupElement.p2(curve, ZERO, ONE, ONE); assertThat(t.curve, is(equalTo(curve))); assertThat(t.repr, is(GroupElement.Representation.P2)); assertThat(t.X, is(ZERO)); assertThat(t.Y, is(ONE)); assertThat(t.Z, is(ONE)); assertThat(t.T, is((FieldElement) null)); }
/** * Test method for {@link GroupElement#toByteArray()}. * <p> * TODO 20141001 BR: why test with points which are not on the curve? */ @Test public void testToByteArray() { byte[] zerozero = GroupElement.p2(curve, ZERO, ZERO, ONE).toByteArray(); assertThat(zerozero.length, is(equalTo(BYTES_ZEROZERO.length))); assertThat(zerozero, is(equalTo(BYTES_ZEROZERO))); byte[] oneone = GroupElement.p2(curve, ONE, ONE, ONE).toByteArray(); assertThat(oneone.length, is(equalTo(BYTES_ONEONE.length))); assertThat(oneone, is(equalTo(BYTES_ONEONE))); byte[] tenzero = GroupElement.p2(curve, TEN, ZERO, ONE).toByteArray(); assertThat(tenzero.length, is(equalTo(BYTES_TENZERO.length))); assertThat(tenzero, is(equalTo(BYTES_TENZERO))); byte[] oneten = GroupElement.p2(curve, ONE, TEN, ONE).toByteArray(); assertThat(oneten.length, is(equalTo(BYTES_ONETEN.length))); assertThat(oneten, is(equalTo(BYTES_ONETEN))); byte[] pkr = GroupElement.p2(curve, PKR[0], PKR[1], ONE).toByteArray(); assertThat(pkr.length, is(equalTo(BYTES_PKR.length))); assertThat(pkr, is(equalTo(BYTES_PKR))); }
switch (repr) { case P2: return p2(this.curve, this.X, this.Y, this.Z); default: throw new IllegalArgumentException(); switch (repr) { case P2: return p2(this.curve, this.X, this.Y, this.Z); case P3: return p3(this.curve, this.X, this.Y, this.Z, this.T); switch (repr) { case P2: return p2(this.curve, this.X.multiply(this.T), Y.multiply(this.Z), this.Z.multiply(this.T)); case P3: return p3(this.curve, this.X.multiply(this.T), Y.multiply(this.Z), this.Z.multiply(this.T), this.X.multiply(this.Y), false);
@Test public void isOnCurveReturnsFalseForPointsNotOnTheCurve() { for (int i=0; i<100; i++) { // Arrange: final GroupElement g = MathUtils.getRandomGroupElement(); final GroupElement h = GroupElement.p2(curve, g.getX(), g.getY(), g.getZ().multiply(curve.getField().TWO)); // Assert (can only fail for 5*Z^2=1): Assert.assertThat(h.isOnCurve(), IsEqual.equalTo(false)); } } }
return GroupElement.p2( curve, toFieldElement(x),
public Curve(Field f, byte[] d, FieldElement I) { this.f = f; this.d = f.fromByteArray(d); this.d2 = this.d.add(this.d); this.I = I; FieldElement zero = f.ZERO; FieldElement one = f.ONE; zeroP2 = GroupElement.p2(this, zero, one, one); zeroP3 = GroupElement.p3(this, zero, one, one, zero, false); zeroP3PrecomputedDouble = GroupElement.p3(this, zero, one, one, zero, true); zeroPrecomp = GroupElement.precomp(this, one, one, zero); }
switch (repr) { case P2: return p2(this.curve, this.X, this.Y, this.Z); default: throw new IllegalArgumentException(); switch (repr) { case P2: return p2(this.curve, this.X, this.Y, this.Z); case P3: return p3(this.curve, this.X, this.Y, this.Z, this.T); switch (repr) { case P2: return p2(this.curve, this.X.multiply(this.T), Y.multiply(this.Z), this.Z.multiply(this.T)); case P3: return p3(this.curve, this.X.multiply(this.T), Y.multiply(this.Z), this.Z.multiply(this.T), this.X.multiply(this.Y), false);