@Override public int hashCode() { return getA().hashCode(); } }
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); }
/** * Encode a FieldElement in its (b-1)-bit encoding. * @return the (b-1)-bit encoding of this FieldElement. */ public byte[] toByteArray() { return f.getEncoding().encode(this); }
/** * @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; }
public Field(int b, byte[] q, Encoding enc) { this.b = b; this.enc = enc; this.enc.setField(this); this.q = fromByteArray(q); // Set up constants ZERO = fromByteArray(Constants.ZERO); ONE = fromByteArray(Constants.ONE); TWO = fromByteArray(Constants.TWO); FOUR = fromByteArray(Constants.FOUR); FIVE = fromByteArray(Constants.FIVE); EIGHT = fromByteArray(Constants.EIGHT); // Precompute values qm2 = this.q.subtract(TWO); qm5d8 = this.q.subtract(FIVE).divide(EIGHT); }
/** * Converts a BigInteger to a field element. * * @param b The BigInteger. * @return The field element. */ public static FieldElement toFieldElement(final BigInteger b) { return getField().getEncoding().decode(toByteArray(b)); }
public boolean isNegative() { return f.getEncoding().isNegative(this); }
@Test (expected = IllegalArgumentException.class) public void toP2ThrowsIfGroupElementHasPrecompRepresentation() { // Arrange: final GroupElement g = MathUtils.toRepresentation(MathUtils.getRandomGroupElement(), GroupElement.Representation.PRECOMP); // Assert: g.toP2(); }
@Test (expected = IllegalArgumentException.class) public void toP3ThrowsIfGroupElementHasCachedRepresentation() { // Arrange: final GroupElement g = MathUtils.toRepresentation(MathUtils.getRandomGroupElement(), GroupElement.Representation.CACHED); // Assert: g.toP3(); }
@Test (expected = IllegalArgumentException.class) public void toCachedThrowsIfGroupElementHasPrecompRepresentation() { // Arrange: final GroupElement g = MathUtils.toRepresentation(MathUtils.getRandomGroupElement(), GroupElement.Representation.PRECOMP); // Assert: g.toCached(); }
public Ed25519PublicKey(EdDSAPublicKeySpec spec) { super(spec); EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName("Ed25519"); if (!spec.getParams().getCurve().equals(ed25519.getCurve())) { throw new SSHRuntimeException("Cannot create Ed25519 Public Key from wrong spec"); } }
/** * Converts a field element to a BigInteger. * * @param f The field element. * @return The BigInteger. */ public static BigInteger toBigInteger(final FieldElement f) { return toBigInteger(f.toByteArray()); }
/** * Converts the group element to the P3 representation. * * @return The group element in the P3 representation. */ public GroupElement toP3() { return toRep(Representation.P3); }
/** * Verify that a point is on its curve. * @return true if the point lies on its curve. */ public boolean isOnCurve() { return isOnCurve(curve); }
/** * Gets a random group element in P3 representation. * * @return The group element. */ public static GroupElement getRandomGroupElement() { return getRandomGroupElement(false); }
/** * Doubles a group element and returns the result in P3 representation. * It uses BigInteger arithmetic and the affine representation. * This method is a helper used to test the projective group doubling formula in GroupElement. * * @param g The group element. * @return g+g. */ public static GroupElement doubleGroupElement(final GroupElement g) { return addGroupElements(g, g); }
/** * Converts the group element to the P2 representation. * * @return The group element in the P2 representation. */ public GroupElement toP2() { return toRep(Representation.P2); }
/** * Converts the group element to the P3 representation, with dblPrecmp populated. * * @return The group element in the P3 representation. * @since 0.9.36 */ public GroupElement toP3PrecomputeDouble() { return toRep(Representation.P3PrecomputedDouble); }
/** * Converts the group element to the CACHED representation. * * @return The group element in the CACHED representation. */ public GroupElement toCached() { return toRep(Representation.CACHED); }