public GroupElement createPoint(byte[] P, boolean precompute) { GroupElement ge = new GroupElement(this, P, precompute); return ge; }
/** * Creates a new group element in P2 representation. * * @param curve The curve. * @param X The X coordinate. * @param Y The Y coordinate. * @param Z The Z coordinate. * @return The group element in P2 representation. */ public static GroupElement p2( final Curve curve, final FieldElement X, final FieldElement Y, final FieldElement Z) { return new GroupElement(curve, Representation.P2, X, Y, Z, null); }
/** * Creates a new group element in PRECOMP representation. * * @param curve The curve. * @param ypx The y + x value. * @param ymx The y - x value. * @param xy2d The 2 * d * x * y value. * @return The group element in PRECOMP representation. */ public static GroupElement precomp( final Curve curve, final FieldElement ypx, final FieldElement ymx, final FieldElement xy2d) { return new GroupElement(curve, Representation.PRECOMP, ypx, ymx, xy2d, null); }
/** * Creates a new group element in CACHED representation. * * @param curve The curve. * @param YpX The Y + X value. * @param YmX The Y - X value. * @param Z The Z coordinate. * @param T2d The 2 * d * T value. * @return The group element in CACHED representation. */ public static GroupElement cached( final Curve curve, final FieldElement YpX, final FieldElement YmX, final FieldElement Z, final FieldElement T2d) { return new GroupElement(curve, Representation.CACHED, YpX, YmX, Z, T2d); }
/** * Creates a new group element in P1P1 representation. * * @param curve The curve. * @param X The X coordinate. * @param Y The Y coordinate. * @param Z The Z coordinate. * @param T The T coordinate. * @return The group element in P1P1 representation. */ public static GroupElement p1p1( final Curve curve, final FieldElement X, final FieldElement Y, final FieldElement Z, final FieldElement T) { return new GroupElement(curve, Representation.P1P1, X, Y, Z, T); }
/** * Creates a new group element in P3 representation, potentially with pre-computation. * * @param curve The curve. * @param X The X coordinate. * @param Y The Y coordinate. * @param Z The Z coordinate. * @param T The T coordinate. * @param precomputeDoubleOnly If true, populate dblPrecmp, else set to null. * @return The group element in P3 representation. * @since 0.9.36 */ public static GroupElement p3( final Curve curve, final FieldElement X, final FieldElement Y, final FieldElement Z, final FieldElement T, final boolean precomputeDoubleOnly) { return new GroupElement(curve, Representation.P3, X, Y, Z, T, precomputeDoubleOnly); }
/** * Gets a random group element in P3 representation, with precmp and dblPrecmp populated. * * @return The group element. */ public static GroupElement getRandomGroupElement(boolean precompute) { final byte[] bytes = new byte[32]; while (true) { try { random.nextBytes(bytes); return new GroupElement(curve, bytes, precompute); } catch (IllegalArgumentException e) { // Will fail in about 87.5%, so try again. } } }
/** * @param pk the public key * @param spec the parameter specification for this key * @throws IllegalArgumentException if key length is wrong */ public EdDSAPublicKeySpec(byte[] pk, EdDSAParameterSpec spec) { if (pk.length != spec.getCurve().getField().getb()/8) throw new IllegalArgumentException("public-key length is wrong"); this.A = new GroupElement(spec.getCurve(), pk); this.spec = spec; }
/** * Tests {@link GroupElement#GroupElement(Curve, byte[])} and * {@link GroupElement#toByteArray()} against valid public keys. */ @Test public void testToAndFromByteArray() { GroupElement t; for (Ed25519TestVectors.TestTuple testCase : Ed25519TestVectors.testCases) { t = new GroupElement(curve, testCase.pk); assertThat("Test case " + testCase.caseNum + " failed", t.toByteArray(), is(equalTo(testCase.pk))); } }
/** * Test method for {@link GroupElement#GroupElement(Curve, GroupElement.Representation, FieldElement, FieldElement, FieldElement, FieldElement)}. */ @Test public void testGroupElementCurveRepresentationFieldElementFieldElementFieldElementFieldElement() { final GroupElement t = new GroupElement(curve, GroupElement.Representation.P3, ZERO, ONE, ONE, ZERO); assertThat(t.curve, is(equalTo(curve))); assertThat(t.repr, is(GroupElement.Representation.P3)); assertThat(t.X, is(ZERO)); assertThat(t.Y, is(ONE)); assertThat(t.Z, is(ONE)); assertThat(t.T, is(ZERO)); }
/** * Test method for {@link GroupElement#GroupElement(Curve, GroupElement.Representation, FieldElement, FieldElement, FieldElement, FieldElement, boolean)}. */ @Test public void testGroupElementCurveRepresentationFieldElementFieldElementFieldElementFieldElementWithExplicitFlag() { final GroupElement t = new GroupElement(curve, GroupElement.Representation.P3, ZERO, ONE, ONE, ZERO, false); assertThat(t.curve, is(equalTo(curve))); assertThat(t.repr, is(GroupElement.Representation.P3)); assertThat(t.X, is(ZERO)); assertThat(t.Y, is(ONE)); assertThat(t.Z, is(ONE)); assertThat(t.T, is(ZERO)); }
/** * Test method for {@link GroupElement#GroupElement(Curve, byte[])}. */ @Test public void testGroupElementByteArray() { final GroupElement t = new GroupElement(curve, BYTES_PKR); final GroupElement s = GroupElement.p3(curve, PKR[0], PKR[1], ONE, PKR[0].multiply(PKR[1])); assertThat(t, is(equalTo(s))); }
@Test public void constructorUsingByteArrayReturnsExpectedResult() { for (int i=0; i<100; i++) { // Arrange: final GroupElement g = MathUtils.getRandomGroupElement(); final byte[] bytes = g.toByteArray(); // Act: final GroupElement h1 = new GroupElement(curve, bytes); final GroupElement h2 = MathUtils.toGroupElement(bytes); // Assert: Assert.assertThat(h1, IsEqual.equalTo(h2)); } }
public GroupElement createPoint(byte[] P, boolean precompute) { GroupElement ge = new GroupElement(this, P, precompute); return ge; }
/** * Creates a new group element in PRECOMP representation. * * @param curve The curve. * @param ypx The $y + x$ value. * @param ymx The $y - x$ value. * @param xy2d The $2 * d * x * y$ value. * @return The group element in PRECOMP representation. */ public static GroupElement precomp( final Curve curve, final FieldElement ypx, final FieldElement ymx, final FieldElement xy2d) { return new GroupElement(curve, Representation.PRECOMP, ypx, ymx, xy2d, null); }
/** * Creates a new group element in P1P1 representation. * * @param curve The curve. * @param X The $X$ coordinate. * @param Y The $Y$ coordinate. * @param Z The $Z$ coordinate. * @param T The $T$ coordinate. * @return The group element in P1P1 representation. */ public static GroupElement p1p1( final Curve curve, final FieldElement X, final FieldElement Y, final FieldElement Z, final FieldElement T) { return new GroupElement(curve, Representation.P1P1, X, Y, Z, T); }
/** * Creates a new group element in CACHED representation. * * @param curve The curve. * @param YpX The $Y + X$ value. * @param YmX The $Y - X$ value. * @param Z The $Z$ coordinate. * @param T2d The $2 * d * T$ value. * @return The group element in CACHED representation. */ public static GroupElement cached( final Curve curve, final FieldElement YpX, final FieldElement YmX, final FieldElement Z, final FieldElement T2d) { return new GroupElement(curve, Representation.CACHED, YpX, YmX, Z, T2d); }
/** * Test method for {@link GroupElement#scalarMultiply(byte[])}. * Test values generated with Python Ed25519 implementation. */ @Test public void testScalarMultiplyByteArray() { // Little-endian byte[] zero = Utils.hexToBytes("0000000000000000000000000000000000000000000000000000000000000000"); byte[] one = Utils.hexToBytes("0100000000000000000000000000000000000000000000000000000000000000"); byte[] two = Utils.hexToBytes("0200000000000000000000000000000000000000000000000000000000000000"); byte[] a = Utils.hexToBytes("d072f8dd9c07fa7bc8d22a4b325d26301ee9202f6db89aa7c3731529e37e437c"); GroupElement A = new GroupElement(curve, Utils.hexToBytes("d4cf8595571830644bd14af416954d09ab7159751ad9e0f7a6cbd92379e71a66")); assertThat("scalarMultiply(0) failed", ed25519.getB().scalarMultiply(zero), is(equalTo(curve.getZero(GroupElement.Representation.P3)))); assertThat("scalarMultiply(1) failed", ed25519.getB().scalarMultiply(one), is(equalTo(ed25519.getB()))); assertThat("scalarMultiply(2) failed", ed25519.getB().scalarMultiply(two), is(equalTo(ed25519.getB().dbl()))); assertThat("scalarMultiply(a) failed", ed25519.getB().scalarMultiply(a), is(equalTo(A))); }
byte[] two = Utils.hexToBytes("0200000000000000000000000000000000000000000000000000000000000000"); byte[] a = Utils.hexToBytes("d072f8dd9c07fa7bc8d22a4b325d26301ee9202f6db89aa7c3731529e37e437c"); GroupElement A = new GroupElement(curve, Utils.hexToBytes("d4cf8595571830644bd14af416954d09ab7159751ad9e0f7a6cbd92379e71a66")); GroupElement B = ed25519.getB(); GroupElement geZero = curve.getZero(GroupElement.Representation.P3PrecomputedDouble);
/** * @param pk the public key * @param spec the parameter specification for this key * @throws IllegalArgumentException if key length is wrong */ public EdDSAPublicKeySpec(byte[] pk, EdDSAParameterSpec spec) { if (pk.length != spec.getCurve().getField().getb()/8) throw new IllegalArgumentException("public-key length is wrong"); this.A = new GroupElement(spec.getCurve(), pk); this.spec = spec; }