public boolean isValidFieldElement(BigInteger x) { return x != null && x.signum() >= 0 && x.compareTo(this.getField().getCharacteristic()) < 0; }
public ECPoint importPoint(ECPoint p) { if (this != p.getCurve() && this.getCoordinateSystem() == COORD_JACOBIAN && !p.isInfinity()) { switch (p.getCurve().getCoordinateSystem()) { case COORD_JACOBIAN: case COORD_JACOBIAN_CHUDNOVSKY: case COORD_JACOBIAN_MODIFIED: return new ECPoint.Fp(this, fromBigInteger(p.x.toBigInteger()), fromBigInteger(p.y.toBigInteger()), new ECFieldElement[]{ fromBigInteger(p.zs[0].toBigInteger()) }, p.withCompression); default: break; } } return super.importPoint(p); }
protected ECPoint decompressPoint(int yTilde, BigInteger X1) { ECFieldElement x = this.fromBigInteger(X1); ECFieldElement rhs = x.square().add(this.a).multiply(x).add(this.b); ECFieldElement y = rhs.sqrt(); /* * If y is not a square, then we haven't got a point on the curve */ if (y == null) { throw new IllegalArgumentException("Invalid point compression"); } if (y.testBitZero() != (yTilde == 1)) { // Use the other root y = y.negate(); } return this.createRawPoint(x, y, true); } }
public ECPoint importPoint(ECPoint p) { if (this != p.getCurve() && this.getCoordinateSystem() == ECCurve.COORD_JACOBIAN && !p.isInfinity()) { switch (p.getCurve().getCoordinateSystem()) { case ECCurve.COORD_JACOBIAN: case ECCurve.COORD_JACOBIAN_CHUDNOVSKY: case ECCurve.COORD_JACOBIAN_MODIFIED: return new ECPoint.Fp(this, fromBigInteger(p.x.toBigInteger()), fromBigInteger(p.y.toBigInteger()), new ECFieldElement[]{ fromBigInteger(p.zs[0].toBigInteger()) }, p.withCompression); default: break; } } return super.importPoint(p); }
protected ECPoint decompressPoint(int yTilde, BigInteger X1) { ECFieldElement x = this.fromBigInteger(X1); ECFieldElement rhs = x.square().add(a).multiply(x).add(b); ECFieldElement y = rhs.sqrt(); /* * If y is not a square, then we haven't got a point on the curve */ if (y == null) { throw new IllegalArgumentException("Invalid point compression"); } if (y.testBitZero() != (yTilde == 1)) { // Use the other root y = y.negate(); } return this.createRawPoint(x, y, true); } }