@Test void succeedsWhenAttemptToDeserializeWithBFlagAndAFlagTrueThrowsIllegalArgumentException1() { String xInput = "0xe00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; assertThrows( IllegalArgumentException.class, () -> G1Point.fromBytesCompressed(Bytes.fromHexString(xInput))); }
public static G1Point fromBytesCompressed(Bytes bytes) { checkArgument( bytes.size() == fpPointSize, "Expected %s bytes but received %s.", fpPointSize, bytes.size()); byte[] xBytes = bytes.toArray(); boolean aIn = (xBytes[0] & (byte) (1 << 5)) != 0; boolean bIn = (xBytes[0] & (byte) (1 << 6)) != 0; boolean cIn = (xBytes[0] & (byte) (1 << 7)) != 0; xBytes[0] &= (byte) 31; if (!cIn) { throw new IllegalArgumentException("The serialized input does not have the C flag set."); } if (bIn) { if (!aIn && Bytes.wrap(xBytes).isZero()) { return new G1Point(); } else { throw new IllegalArgumentException( "The serialized input has B flag set, but A flag is set, or X is non-zero."); } } BIG xBig = BIG.fromBytes(xBytes); BIG modulus = new BIG(ROM.Modulus); if (BIG.comp(modulus, xBig) <= 0) { throw new IllegalArgumentException("X coordinate is too large."); } ECP point = new ECP(xBig); if (point.is_infinity()) { throw new IllegalArgumentException("X coordinate is not on the curve."); } if (!isInGroup(point)) { throw new IllegalArgumentException("The deserialized point is not in the G1 subgroup."); } if (aIn != Util.calculateYFlag(point.getY())) { FP x = new FP(point.getX()); FP yneg = new FP(point.getY()); yneg.neg(); point = new ECP(x.redc(), yneg.redc()); } return new G1Point(point); }
G1Point implements Group<G1Point> { public static G1Point fromBytesCompressed(Bytes bytes) { checkArgument( bytes.size() == fpPointSize, "Expected %s bytes but received %s.", fpPointSize, bytes.size()); byte[] xBytes = bytes.toArray(); boolean aIn = (xBytes[0] & (byte) (1 << 5)) != 0; boolean bIn = (xBytes[0] & (byte) (1 << 6)) != 0; boolean cIn = (xBytes[0] & (byte) (1 << 7)) != 0; xBytes[0] &= (byte) 31; if (!cIn) { throw new IllegalArgumentException("The serialized input does not have the C flag set."); } if (bIn) { if (!aIn && Bytes.wrap(xBytes).isZero()) { return new G1Point(); } else { throw new IllegalArgumentException( "The serialized input has B flag set, but A flag is set, or X is non-zero."); } } BIG xBig = BIG.fromBytes(xBytes); BIG modulus = new BIG(ROM.Modulus); if (BIG.comp(modulus, xBig) <= 0) { throw new IllegalArgumentException("X coordinate is too large."); } ECP point = new ECP(xBig); if (point.is_infinity()) { throw new IllegalArgumentException("X coordinate is not on the curve."); } if (!isInGroup(point)) { throw new IllegalArgumentException("The deserialized point is not in the G1 subgroup."); } if (aIn != Util.calculateYFlag(point.getY())) { FP x = new FP(point.getX()); FP yneg = new FP(point.getY()); yneg.neg(); point = new ECP(x.redc(), yneg.redc()); } return new G1Point(point); } }
G1Point implements Group<G1Point> { public static G1Point fromBytesCompressed(Bytes bytes) { checkArgument( bytes.size() == fpPointSize, "Expected %s bytes but received %s.", fpPointSize, bytes.size()); byte[] xBytes = bytes.toArray(); boolean aIn = (xBytes[0] & (byte) (1 << 5)) != 0; boolean bIn = (xBytes[0] & (byte) (1 << 6)) != 0; boolean cIn = (xBytes[0] & (byte) (1 << 7)) != 0; xBytes[0] &= (byte) 31; if (!cIn) { throw new IllegalArgumentException("The serialized input does not have the C flag set."); } if (bIn) { if (!aIn && Bytes.wrap(xBytes).isZero()) { return new G1Point(); } else { throw new IllegalArgumentException( "The serialized input has B flag set, but A flag is set, or X is non-zero."); } } BIG xBig = BIG.fromBytes(xBytes); BIG modulus = new BIG(ROM.Modulus); if (BIG.comp(modulus, xBig) <= 0) { throw new IllegalArgumentException("X coordinate is too large."); } ECP point = new ECP(xBig); if (point.is_infinity()) { throw new IllegalArgumentException("X coordinate is not on the curve."); } if (!isInGroup(point)) { throw new IllegalArgumentException("The deserialized point is not in the G1 subgroup."); } if (aIn != Util.calculateYFlag(point.getY())) { FP x = new FP(point.getX()); FP yneg = new FP(point.getY()); yneg.neg(); point = new ECP(x.redc(), yneg.redc()); } return new G1Point(point); } G1Point();  G1Point(ECP point); }
G1Point implements Group<G1Point> { public static G1Point fromBytesCompressed(Bytes bytes) { checkArgument( bytes.size() == fpPointSize, "Expected %s bytes but received %s.", fpPointSize, bytes.size()); byte[] xBytes = bytes.toArray(); boolean aIn = (xBytes[0] & (byte) (1 << 5)) != 0; boolean bIn = (xBytes[0] & (byte) (1 << 6)) != 0; boolean cIn = (xBytes[0] & (byte) (1 << 7)) != 0; xBytes[0] &= (byte) 31; if (!cIn) { throw new IllegalArgumentException("The serialized input does not have the C flag set."); } if (bIn) { if (!aIn && Bytes.wrap(xBytes).isZero()) { return new G1Point(); } else { throw new IllegalArgumentException( "The serialized input has B flag set, but A flag is set, or X is non-zero."); } } BIG xBig = BIG.fromBytes(xBytes); BIG modulus = new BIG(ROM.Modulus); if (BIG.comp(modulus, xBig) <= 0) { throw new IllegalArgumentException("X coordinate is too large."); } ECP point = new ECP(xBig); if (point.is_infinity()) { throw new IllegalArgumentException("X coordinate is not on the curve."); } if (!isInGroup(point)) { throw new IllegalArgumentException("The deserialized point is not in the G1 subgroup."); } if (aIn != Util.calculateYFlag(point.getY())) { FP x = new FP(point.getX()); FP yneg = new FP(point.getY()); yneg.neg(); point = new ECP(x.redc(), yneg.redc()); } return new G1Point(point); } G1Point();  G1Point(ECP point); static G1Point random(long seed); static G1Point fromBytes(Bytes bytes); static G1Point fromBytesCompressed(Bytes bytes); static ECP scaleWithCofactor(ECP point); @Override G1Point add(G1Point other); @Override G1Point mul(Scalar scalar); G1Point neg(); ECP getPoint(); Bytes toBytes(); Bytes toBytesCompressed(); static boolean isInGroup(ECP point); ECP ecpPoint(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }
G1Point implements Group<G1Point> { public static G1Point fromBytesCompressed(Bytes bytes) { checkArgument( bytes.size() == fpPointSize, "Expected %s bytes but received %s.", fpPointSize, bytes.size()); byte[] xBytes = bytes.toArray(); boolean aIn = (xBytes[0] & (byte) (1 << 5)) != 0; boolean bIn = (xBytes[0] & (byte) (1 << 6)) != 0; boolean cIn = (xBytes[0] & (byte) (1 << 7)) != 0; xBytes[0] &= (byte) 31; if (!cIn) { throw new IllegalArgumentException("The serialized input does not have the C flag set."); } if (bIn) { if (!aIn && Bytes.wrap(xBytes).isZero()) { return new G1Point(); } else { throw new IllegalArgumentException( "The serialized input has B flag set, but A flag is set, or X is non-zero."); } } BIG xBig = BIG.fromBytes(xBytes); BIG modulus = new BIG(ROM.Modulus); if (BIG.comp(modulus, xBig) <= 0) { throw new IllegalArgumentException("X coordinate is too large."); } ECP point = new ECP(xBig); if (point.is_infinity()) { throw new IllegalArgumentException("X coordinate is not on the curve."); } if (!isInGroup(point)) { throw new IllegalArgumentException("The deserialized point is not in the G1 subgroup."); } if (aIn != Util.calculateYFlag(point.getY())) { FP x = new FP(point.getX()); FP yneg = new FP(point.getY()); yneg.neg(); point = new ECP(x.redc(), yneg.redc()); } return new G1Point(point); } G1Point();  G1Point(ECP point); static G1Point random(long seed); static G1Point fromBytes(Bytes bytes); static G1Point fromBytesCompressed(Bytes bytes); static ECP scaleWithCofactor(ECP point); @Override G1Point add(G1Point other); @Override G1Point mul(Scalar scalar); G1Point neg(); ECP getPoint(); Bytes toBytes(); Bytes toBytesCompressed(); static boolean isInGroup(ECP point); ECP ecpPoint(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }