public BigInteger getCharacteristic() { return subfield.getCharacteristic(); }
public static boolean isF2mField(FiniteField field) { return field.getDimension() > 1 && field.getCharacteristic().equals(ECConstants.TWO) && field instanceof PolynomialExtensionField; }
public static boolean isFpField(FiniteField field) { return field.getDimension() == 1; }
public static boolean isFpCurve(ECCurve c) { return c.getField().getDimension() == 1; }
public BigInteger getCharacteristic() { return subfield.getCharacteristic(); }
public static boolean isF2mCurve(ECCurve c) { FiniteField field = c.getField(); return field.getDimension() > 1 && field.getCharacteristic().equals(ECConstants.TWO) && field instanceof PolynomialExtensionField; }
public int getDimension() { return subfield.getDimension() * minimalPolynomial.getDegree(); }
public boolean isValidFieldElement(BigInteger x) { return x != null && x.signum() >= 0 && x.compareTo(this.getField().getCharacteristic()) < 0; }
public int getDimension() { return subfield.getDimension() * minimalPolynomial.getDegree(); }
private static ECFieldElement[] findBetaValues(ECCurve c) { BigInteger q = c.getField().getCharacteristic(); BigInteger e = q.divide(ECConstants.THREE); // Search for a random value that generates a non-trival cube root of 1 SecureRandom random = new SecureRandom(); BigInteger b; do { BigInteger r = BigIntegers.createRandomInRange(ECConstants.TWO, q.subtract(ECConstants.TWO), random); b = r.modPow(e, q); } while (b.equals(ECConstants.ONE)); ECFieldElement beta = c.fromBigInteger(b); return new ECFieldElement[]{ beta, beta.square() }; }
public static void discoverEndomorphisms(X9ECParameters x9) { if (x9 == null) { throw new NullPointerException("x9"); } ECCurve c = x9.getCurve(); if (ECAlgorithms.isFpCurve(c)) { BigInteger characteristic = c.getField().getCharacteristic(); if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE)) { System.out.println("Curve has a 'GLV Type B' endomorphism with these parameters:"); printGLVTypeBParameters(x9); } } }
private static void discoverEndomorphism(String curveName) { X9ECParameters x9 = ECNamedCurveTable.getByName(curveName); if (x9 == null) { System.err.println("Unknown curve: " + curveName); return; } ECCurve c = x9.getCurve(); if (ECAlgorithms.isFpCurve(c)) { BigInteger characteristic = c.getField().getCharacteristic(); if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE)) { System.out.println("Curve '" + curveName + "' has a 'GLV Type B' endomorphism with these parameters: "); printGLVTypeBParameters(x9); } } }
private static void discoverEndomorphisms(String curveName) { X9ECParameters x9 = ECNamedCurveTable.getByName(curveName); if (x9 == null) { System.err.println("Unknown curve: " + curveName); return; } ECCurve c = x9.getCurve(); if (ECAlgorithms.isFpCurve(c)) { BigInteger characteristic = c.getField().getCharacteristic(); if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE)) { System.out.println("Curve '" + curveName + "' has a 'GLV Type B' endomorphism with these parameters:"); printGLVTypeBParameters(x9); } } }
long startTime = System.currentTimeMillis(); org.bouncycastle.jce.spec.ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(CURVE_NAME); ECField field = new ECFieldFp(ecSpec.getCurve().getField().getCharacteristic()); EllipticCurve curve = new EllipticCurve(field, ecSpec.getCurve().getA().toBigInteger(), ecSpec.getCurve().getB().toBigInteger());
BigInteger q = x9.getCurve().getField().getCharacteristic(); BigInteger e = q.divide(ECConstants.THREE);
public static ECField convertField(FiniteField field) { if (ECAlgorithms.isFpField(field)) { return new ECFieldFp(field.getCharacteristic()); } else //if (ECAlgorithms.isF2mField(curveField)) { Polynomial poly = ((PolynomialExtensionField)field).getMinimalPolynomial(); int[] exponents = poly.getExponentsPresent(); int[] ks = Arrays.reverse(Arrays.copyOfRange(exponents, 1, exponents.length - 1)); return new ECFieldF2m(poly.getDegree(), ks); } }
this.fieldID = new X9FieldID(curve.getField().getCharacteristic());
private static ECField convertField(FiniteField field) { if (ECAlgorithms.isFpField(field)) { return new ECFieldFp(field.getCharacteristic()); } else //if (ECAlgorithms.isF2mField(curveField)) { Polynomial poly = ((PolynomialExtensionField)field).getMinimalPolynomial(); int[] exponents = poly.getExponentsPresent(); int[] ks = Arrays.reverse(Arrays.copyOfRange(exponents, 1, exponents.length - 1)); return new ECFieldF2m(poly.getDegree(), ks); } }
this.fieldID = new X9FieldID(curve.getField().getCharacteristic());
/** * 解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)<br> * 见:https://www.cnblogs.com/xinzhao/p/8963724.html * * @param encodeByte 压缩公钥 * @param curveName EC曲线名 * @since 4.4.4 */ public static PublicKey decodeECPoint(byte[] encodeByte, String curveName) { final org.bouncycastle.jce.spec.ECNamedCurveParameterSpec namedSpec = org.bouncycastle.jce.ECNamedCurveTable.getParameterSpec(curveName); final ECCurve curve = namedSpec.getCurve(); final EllipticCurve ecCurve = new EllipticCurve(// new ECFieldFp(curve.getField().getCharacteristic()), // curve.getA().toBigInteger(), // curve.getB().toBigInteger()); // 根据X恢复点Y final ECPoint point = org.bouncycastle.jce.ECPointUtil.decodePoint(ecCurve, encodeByte); // 根据曲线恢复公钥格式 java.security.spec.ECParameterSpec ecSpec = new org.bouncycastle.jce.spec.ECNamedCurveSpec(curveName, curve, namedSpec.getG(), namedSpec.getN()); final KeyFactory PubKeyGen = getKeyFactory("EC"); try { return PubKeyGen.generatePublic(new ECPublicKeySpec(point, ecSpec)); } catch (GeneralSecurityException e) { throw new CryptoException(e); } } }