类java.security.spec.ECField源码实例Demo

下面列出了怎么用java.security.spec.ECField的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: wycheproof   文件: EcUtil.java
public static void printParameters(ECParameterSpec spec) {
  System.out.println("cofactor:" + spec.getCofactor());
  EllipticCurve curve = spec.getCurve();
  System.out.println("A:" + curve.getA());
  System.out.println("B:" + curve.getB());
  ECField field = curve.getField();
  System.out.println("field size:" + field.getFieldSize());
  if (field instanceof ECFieldFp) {
    ECFieldFp fp = (ECFieldFp) field;
    System.out.println("P:" + fp.getP());
  }
  ECPoint generator = spec.getGenerator();
  System.out.println("Gx:" + generator.getAffineX());
  System.out.println("Gy:" + generator.getAffineY());
  System.out.println("order:" + spec.getOrder());
}
 
源代码2 项目: wycheproof   文件: EcUtil.java
/**
 * Decompress a point
 *
 * @param x The x-coordinate of the point
 * @param bit0 true if the least significant bit of y is set.
 * @param ecParams contains the curve of the point. This must be over a prime order field.
 */
public static ECPoint getPoint(BigInteger x, boolean bit0, ECParameterSpec ecParams)
    throws GeneralSecurityException {
  EllipticCurve ec = ecParams.getCurve();
  ECField field = ec.getField();
  if (!(field instanceof ECFieldFp)) {
    throw new GeneralSecurityException("Only curves over prime order fields are supported");
  }
  BigInteger p = ((java.security.spec.ECFieldFp) field).getP();
  if (x.compareTo(BigInteger.ZERO) == -1 || x.compareTo(p) != -1) {
    throw new GeneralSecurityException("x is out of range");
  }
  // Compute rhs == x^3 + a x + b (mod p)
  BigInteger rhs = x.multiply(x).add(ec.getA()).multiply(x).add(ec.getB()).mod(p);
  BigInteger y = modSqrt(rhs, p);
  if (bit0 != y.testBit(0)) {
    y = p.subtract(y).mod(p);
  }
  return new ECPoint(x, y);
}
 
源代码3 项目: RipplePower   文件: EC5Util.java
public static ECCurve convertCurve(
    EllipticCurve ec)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        ECCurve.Fp curve = new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);

        if (customCurves.containsKey(curve))
        {
            return (ECCurve)customCurves.get(curve);
        }

        return curve;
    }
    else
    {
        ECFieldF2m fieldF2m = (ECFieldF2m)field;
        int m = fieldF2m.getM();
        int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
        return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b); 
    }
}
 
源代码4 项目: ripple-lib-java   文件: EC5Util.java
public static ECCurve convertCurve(
    EllipticCurve ec)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        ECCurve.Fp curve = new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);

        if (customCurves.containsKey(curve))
        {
            return (ECCurve)customCurves.get(curve);
        }

        return curve;
    }
    else
    {
        ECFieldF2m fieldF2m = (ECFieldF2m)field;
        int m = fieldF2m.getM();
        int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
        return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b); 
    }
}
 
源代码5 项目: swim   文件: EcFieldDef.java
public static EcFieldDef from(ECField field) {
  if (field instanceof ECFieldFp) {
    return EcPrimeFieldDef.from((ECFieldFp) field);
  } else if (field instanceof ECFieldF2m) {
    return EcCharacteristic2FieldDef.from((ECFieldF2m) field);
  } else {
    throw new IllegalArgumentException(field.toString());
  }
}
 
源代码6 项目: termd   文件: BaseTestSupport.java
public static void assertECFieldEquals(String message, ECField expected, ECField actual) {
    if (expected == actual) {
        return;
    }

    assertEquals(message + "[size]", expected.getFieldSize(), actual.getFieldSize());
}
 
源代码7 项目: openjdk-jdk8u   文件: DOMKeyValue.java
private static Curve initializeCurve(String name, String oid,
        String sfield, String a, String b,
        String x, String y, String n, int h) {
    BigInteger p = bigInt(sfield);
    ECField field = new ECFieldFp(p);
    EllipticCurve curve = new EllipticCurve(field, bigInt(a),
                                            bigInt(b));
    ECPoint g = new ECPoint(bigInt(x), bigInt(y));
    return new Curve(name, oid, curve, g, bigInt(n), h);
}
 
源代码8 项目: openjdk-jdk8u   文件: GenerationTests.java
private static ECParameterSpec initECParams(
        String sfield, String a, String b, String gx, String gy,
        String n, int h) {
    ECField field = new ECFieldFp(bigInt(sfield));
    EllipticCurve curve = new EllipticCurve(field,
                                            bigInt(a), bigInt(b));
    ECPoint g = new ECPoint(bigInt(gx), bigInt(gy));
    return new ECParameterSpec(curve, g, bigInt(n), h);
}
 
源代码9 项目: openjdk-jdk9   文件: DOMKeyValue.java
private static Curve initializeCurve(String name, String oid,
        String sfield, String a, String b,
        String x, String y, String n, int h) {
    BigInteger p = bigInt(sfield);
    ECField field = new ECFieldFp(p);
    EllipticCurve curve = new EllipticCurve(field, bigInt(a),
                                            bigInt(b));
    ECPoint g = new ECPoint(bigInt(x), bigInt(y));
    return new Curve(name, oid, curve, g, bigInt(n), h);
}
 
源代码10 项目: openjdk-jdk9   文件: GenerationTests.java
private static ECParameterSpec initECParams(
        String sfield, String a, String b, String gx, String gy,
        String n, int h) {
    ECField field = new ECFieldFp(bigInt(sfield));
    EllipticCurve curve = new EllipticCurve(field,
                                            bigInt(a), bigInt(b));
    ECPoint g = new ECPoint(bigInt(gx), bigInt(gy));
    return new ECParameterSpec(curve, g, bigInt(n), h);
}
 
源代码11 项目: wycheproof   文件: EcUtil.java
/**
 * Returns the modulus of the field used by the curve specified in ecParams.
 *
 * @param curve must be a prime order elliptic curve
 * @return the order of the finite field over which curve is defined.
 */
public static BigInteger getModulus(EllipticCurve curve) throws GeneralSecurityException {
  java.security.spec.ECField field = curve.getField();
  if (field instanceof java.security.spec.ECFieldFp) {
    return ((java.security.spec.ECFieldFp) field).getP();
  } else {
    throw new GeneralSecurityException("Only curves over prime order fields are supported");
  }
}
 
源代码12 项目: wycheproof   文件: EcUtil.java
/**
 * Decompress a point on an elliptic curve.
 *
 * @param bytes The compressed point. Its representation is z || x where z is 2+lsb(y) and x is
 *     using a unsigned fixed length big-endian representation.
 * @param ecParams the specification of the curve. Only Weierstrass curves over prime order fields
 *     are implemented.
 */
public static ECPoint decompressPoint(byte[] bytes, ECParameterSpec ecParams)
    throws GeneralSecurityException {
  EllipticCurve ec = ecParams.getCurve();
  ECField field = ec.getField();
  if (!(field instanceof ECFieldFp)) {
    throw new GeneralSecurityException("Only curves over prime order fields are supported");
  }
  BigInteger p = ((java.security.spec.ECFieldFp) field).getP();
  int expectedLength = 1 + (p.bitLength() + 7) / 8;
  if (bytes.length != expectedLength) {
    throw new GeneralSecurityException("compressed point has wrong length");
  }
  boolean lsb;
  switch (bytes[0]) {
    case 2:
      lsb = false;
      break;
    case 3:
      lsb = true;
      break;
    default:
      throw new GeneralSecurityException("Invalid format");
  }
  BigInteger x = new BigInteger(1, Arrays.copyOfRange(bytes, 1, bytes.length));
  if (x.compareTo(BigInteger.ZERO) == -1 || x.compareTo(p) != -1) {
    throw new GeneralSecurityException("x is out of range");
  }
  // Compute rhs == x^3 + a x + b (mod p)
  BigInteger rhs = x.multiply(x).add(ec.getA()).multiply(x).add(ec.getB()).mod(p);
  BigInteger y = modSqrt(rhs, p);
  if (lsb != y.testBit(0)) {
    y = p.subtract(y).mod(p);
  }
  return new ECPoint(x, y);
}
 
源代码13 项目: jdk8u_jdk   文件: DOMKeyValue.java
private static Curve initializeCurve(String name, String oid,
        String sfield, String a, String b,
        String x, String y, String n, int h) {
    BigInteger p = bigInt(sfield);
    ECField field = new ECFieldFp(p);
    EllipticCurve curve = new EllipticCurve(field, bigInt(a),
                                            bigInt(b));
    ECPoint g = new ECPoint(bigInt(x), bigInt(y));
    return new Curve(name, oid, curve, g, bigInt(n), h);
}
 
源代码14 项目: jdk8u_jdk   文件: GenerationTests.java
private static ECParameterSpec initECParams(
        String sfield, String a, String b, String gx, String gy,
        String n, int h) {
    ECField field = new ECFieldFp(bigInt(sfield));
    EllipticCurve curve = new EllipticCurve(field,
                                            bigInt(a), bigInt(b));
    ECPoint g = new ECPoint(bigInt(gx), bigInt(gy));
    return new ECParameterSpec(curve, g, bigInt(n), h);
}
 
源代码15 项目: termd   文件: BaseTestSupport.java
public static void assertECFieldEquals(String message, ECField expected, ECField actual) {
    if (expected == actual) {
        return;
    }

    assertEquals(message + "[size]", expected.getFieldSize(), actual.getFieldSize());
}
 
源代码16 项目: j2objc   文件: EllipticCurveTest.java
MyEllipticCurve(ECField f, BigInteger a, BigInteger b, byte[] seed) {
    super(f, a, b, seed);
}
 
源代码17 项目: swim   文件: EcFieldDef.java
public abstract ECField toECField();