当前位置: 首页>>代码示例>>Java>>正文


Java ECField类代码示例

本文整理汇总了Java中java.security.spec.ECField的典型用法代码示例。如果您正苦于以下问题:Java ECField类的具体用法?Java ECField怎么用?Java ECField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ECField类属于java.security.spec包,在下文中一共展示了ECField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodeECParameterSpec

import java.security.spec.ECField; //导入依赖的package包/类
public static ECParameterSpec encodeECParameterSpec(EllipticCurveParameters params) {

        // Field
        final BigInteger pInt = new BigInteger(1, params.getP());
        final ECField field = new ECFieldFp(pInt);

        final BigInteger aInt = new BigInteger(1, params.getA());
        final BigInteger bInt = new BigInteger(1, params.getB());
        final EllipticCurve curve = new EllipticCurve(field, aInt, bInt);

        // Fixed Point G
        final BigInteger xInt = new BigInteger(1, params.getX());
        final BigInteger yInt = new BigInteger(1, params.getY());
        final ECPoint g = new ECPoint(xInt, yInt);

        // Order N
        final BigInteger nInt = new BigInteger(1, params.getN());

        return new ECParameterSpec(curve, g, nInt, params.getH());
    }
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:21,代码来源:EllipticCurveParameters.java

示例2: convertCurve

import java.security.spec.ECField; //导入依赖的package包/类
private static ECCurve convertCurve(
    EllipticCurve ec)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);
    }
    else
    {
        throw new IllegalStateException("not implemented yet!!!");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:JcaPublicKeyConverter.java

示例3: convertCurve

import java.security.spec.ECField; //导入依赖的package包/类
public static ECCurve convertCurve(
    EllipticCurve ec)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);
    }
    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); 
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:EC5Util.java

示例4: getECParameterSpec

import java.security.spec.ECField; //导入依赖的package包/类
ECParameterSpec getECParameterSpec() {
    final String curveName = NativeCrypto.EC_GROUP_get_curve_name(groupCtx);

    final byte[][] curveParams = NativeCrypto.EC_GROUP_get_curve(groupCtx);
    final BigInteger p = new BigInteger(curveParams[0]);
    final BigInteger a = new BigInteger(curveParams[1]);
    final BigInteger b = new BigInteger(curveParams[2]);

    final ECField field = new ECFieldFp(p);

    final EllipticCurve curve = new EllipticCurve(field, a, b);

    final OpenSSLECPointContext generatorCtx = new OpenSSLECPointContext(this,
            new NativeRef.EC_POINT(NativeCrypto.EC_GROUP_get_generator(groupCtx)));
    final ECPoint generator = generatorCtx.getECPoint();

    final BigInteger order = new BigInteger(NativeCrypto.EC_GROUP_get_order(groupCtx));
    final BigInteger cofactor = new BigInteger(NativeCrypto.EC_GROUP_get_cofactor(groupCtx));

    ECParameterSpec spec = new ECParameterSpec(curve, generator, order, cofactor.intValue());
    Platform.setCurveName(spec, curveName);
    return spec;
}
 
开发者ID:google,项目名称:conscrypt,代码行数:24,代码来源:OpenSSLECGroupContext.java

示例5: getPoint

import java.security.spec.ECField; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:google,项目名称:wycheproof,代码行数:27,代码来源:EcUtil.java

示例6: convertCurve

import java.security.spec.ECField; //导入依赖的package包/类
private static ECCurve convertCurve(
    EllipticCurve ec, BigInteger order, int coFactor)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b, order, BigInteger.valueOf(coFactor));
    }
    else
    {
        throw new IllegalStateException("not implemented yet!!!");
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:17,代码来源:JcaPublicKeyConverter.java

示例7: convertCurve

import java.security.spec.ECField; //导入依赖的package包/类
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); 
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:27,代码来源:EC5Util.java

示例8: testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05

import java.security.spec.ECField; //导入依赖的package包/类
/**
 * Test #5 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
 * constructor<br>
 * Assertion: array <code>seed</code> is copied to prevent subsequent modification<br>
 * Test preconditions: pass <code>seed</code> to the ctor then modify it<br>
 * Expected: getSeed() must return unmodified array
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Verifies that byte array of EllipticCurve can't be modified",
    method = "EllipticCurve",
    args = {java.security.spec.ECField.class, java.math.BigInteger.class, java.math.BigInteger.class, byte[].class}
)
public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05() {
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(0L);
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    byte[] seedCopy = seed.clone();
    EllipticCurve c = new EllipticCurve(f, a, b, seedCopy);
    // modify array passed
    seedCopy[0] = (byte) 1;
    // check that above modification did not changed
    // internal state of test object
    assertTrue(Arrays.equals(seed, c.getSeed()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:EllipticCurveTest.java

示例9: initializeCurve

import java.security.spec.ECField; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:DOMKeyValue.java

示例10: initECParams

import java.security.spec.ECField; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:GenerationTests.java

示例11: toBouncyCastleECCurve

import java.security.spec.ECField; //导入依赖的package包/类
private static ECCurve toBouncyCastleECCurve(final ECParameterSpec params) {
	final EllipticCurve curve = params.getCurve();
	final ECField field = curve.getField();
	if (!(field instanceof ECFieldFp)) {
		throw new IllegalArgumentException(
			"Solo se soporta 'ECFieldFp' y se proporciono  " + field.getClass().getCanonicalName() //$NON-NLS-1$
		);
	}
	final int coFactor = params.getCofactor();
	final BigInteger order = params.getOrder();
	final BigInteger a = curve.getA();
	final BigInteger b = curve.getB();
	final BigInteger p = getPrime(params);
	return new ECCurve.Fp(p, a, b, order, BigInteger.valueOf(coFactor));
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:16,代码来源:JseCryptoHelper.java

示例12: getPrime

import java.security.spec.ECField; //导入依赖的package包/类
private static BigInteger getPrime(final ECParameterSpec params) {
	if (params == null) {
		throw new IllegalArgumentException(
			"Los parametros no pueden ser nulos" //$NON-NLS-1$
		);
	}
	final EllipticCurve curve = params.getCurve();
	final ECField field = curve.getField();
	if (!(field instanceof ECFieldFp)) {
		throw new IllegalStateException(
			"Solo se soporta 'ECFieldFp' y se proporciono  " + field.getClass().getCanonicalName() //$NON-NLS-1$
		);
	}
	return ((ECFieldFp)field).getP();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:16,代码来源:JseCryptoHelper.java

示例13: toSpongyCastleECCurve

import java.security.spec.ECField; //导入依赖的package包/类
private static ECCurve toSpongyCastleECCurve(final ECParameterSpec params) {
	final EllipticCurve curve = params.getCurve();
	final ECField field = curve.getField();
	if (!(field instanceof ECFieldFp)) {
		throw new IllegalArgumentException(
			"Solo se soporta 'ECFieldFp' y se proporciono  " + field.getClass().getCanonicalName() //$NON-NLS-1$
		);
	}
	final int coFactor = params.getCofactor();
	final BigInteger order = params.getOrder();
	final BigInteger a = curve.getA();
	final BigInteger b = curve.getB();
	final BigInteger p = getPrime(params);
	return new ECCurve.Fp(p, a, b, order, BigInteger.valueOf(coFactor));
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:16,代码来源:JseCryptoHelper.java

示例14: getModulus

import java.security.spec.ECField; //导入依赖的package包/类
/**
 * 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");
  }
}
 
开发者ID:google,项目名称:wycheproof,代码行数:15,代码来源:EcUtil.java

示例15: decompressPoint

import java.security.spec.ECField; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:google,项目名称:wycheproof,代码行数:44,代码来源:EcUtil.java


注:本文中的java.security.spec.ECField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。