@BeforeClass public static void beforeAll() { curve = new ECDomainParameters(IES_CURVE_PARAM.getCurve(), IES_CURVE_PARAM.getG(), IES_CURVE_PARAM.getN(), IES_CURVE_PARAM.getH()); }
private static ECPoint decode(final byte[] toAdd) { return CURVE.getCurve().decodePoint(toAdd); }
private static ECPoint decode(final byte[] toAdd) { return CURVE.getCurve().decodePoint(toAdd); }
private static ECPoint decode(final byte[] toAdd) { return CURVE.getCurve().decodePoint(toAdd); }
public static void printRootZ(X9ECParameters x9) { if (!ECAlgorithms.isF2mCurve(x9.getCurve())) { throw new IllegalArgumentException("Sqrt optimization only defined over characteristic-2 fields"); } implPrintRootZ(x9); }
public static void printNonZeroTraceBits(X9ECParameters x9) { if (!ECAlgorithms.isF2mCurve(x9.getCurve())) { throw new IllegalArgumentException("Trace only defined over characteristic-2 fields"); } implPrintNonZeroTraceBits(x9); }
private static void implPrintRootZ(X9ECParameters x9) { ECFieldElement z = x9.getCurve().fromBigInteger(BigInteger.valueOf(2)); ECFieldElement rootZ = z.sqrt(); System.out.println(rootZ.toBigInteger().toString(16).toUpperCase()); if (!rootZ.square().equals(z)) { throw new IllegalStateException("Optimized-sqrt sanity check failed"); } }
X9ECParameters x9 = NISTNamedCurves.getByName("P-224"); ECCurve.Fp curve = (Fp) x9.getCurve(); BigInteger q = curve.getQ(); ECFieldElement x1 = new ECFieldElement.Fp(q, new BigInteger("8")); ECFieldElement y1 = new ECFieldElement.Fp(q, new BigInteger("9"));
public static PrivateKey getPrivateKeyFromECBigIntAndCurve(BigInteger s, String curveName) { X9ECParameters ecCurve = ECNamedCurveTable.getByName(curveName); ECParameterSpec ecParameterSpec = new ECNamedCurveSpec(curveName, ecCurve.getCurve(), ecCurve.getG(), ecCurve.getN(), ecCurve.getH(), ecCurve.getSeed()); ECPrivateKeySpec privateKeySpec = new ECPrivateKeySpec(s, ecParameterSpec); try { KeyFactory keyFactory = KeyFactory.getInstance("EC"); return keyFactory.generatePrivate(privateKeySpec); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { e.printStackTrace(); return null; } }
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); } } }
public static void main(String[] args) { SortedSet names = new TreeSet(enumToList(ECNamedCurveTable.getNames())); names.addAll(enumToList(CustomNamedCurves.getNames())); Iterator it = names.iterator(); while (it.hasNext()) { String name = (String)it.next(); X9ECParameters x9 = CustomNamedCurves.getByName(name); if (x9 == null) { x9 = ECNamedCurveTable.getByName(name); } if (x9 != null && ECAlgorithms.isF2mCurve(x9.getCurve())) { System.out.print(name + ":"); implPrintRootZ(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); } } }
private static void printGLVTypeBParameters(X9ECParameters x9) { // x^2 + x + 1 = 0 mod n BigInteger[] lambdas = solveQuadraticEquation(x9.getN(), ECConstants.ONE, ECConstants.ONE); /* * The 'Beta' values are field elements of order 3. There are only two such values besides 1, each corresponding * to one choice for 'Lambda'. */ ECFieldElement[] betas = findBetaValues(x9.getCurve()); printGLVTypeBParameters(x9, lambdas[0], betas); System.out.println("OR"); printGLVTypeBParameters(x9, lambdas[1], betas); }
public static ASN1ObjectIdentifier getNamedCurveOid( ECParameterSpec ecParameterSpec) { for (Enumeration names = ECNamedCurveTable.getNames(); names.hasMoreElements();) { String name = (String)names.nextElement(); X9ECParameters params = ECNamedCurveTable.getByName(name); if (params.getN().equals(ecParameterSpec.getN()) && params.getH().equals(ecParameterSpec.getH()) && params.getCurve().equals(ecParameterSpec.getCurve()) && params.getG().equals(ecParameterSpec.getG())) { return org.spongycastle.asn1.x9.ECNamedCurveTable.getOID(name); } } return null; }
X9ECParameters ecP = CustomNamedCurves.getByName("curve25519"); ECParameterSpec ecSpec=new ECParameterSpec(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
static ECDomainParameters getECParameters(int namedCurve) { int index = namedCurve - 1; if (index < 0 || index >= curveNames.length) { return null; } String curveName = curveNames[index]; // Lazily created the first time a particular curve is accessed X9ECParameters ecP = SECNamedCurves.getByName(curveName); if (ecP == null) { return null; } // It's a bit inefficient to do this conversion every time return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); } }
public static ECParameterSpec convertToSpec( X9ECParameters domainParameters) { return new ECParameterSpec( convertCurve(domainParameters.getCurve(), null), // JDK 1.5 has trouble with this if it's not null... new ECPoint( domainParameters.getG().getAffineXCoord().toBigInteger(), domainParameters.getG().getAffineYCoord().toBigInteger()), domainParameters.getN(), domainParameters.getH().intValue()); }
public static ECDomainParameters getParametersForNamedCurve(int namedCurve) { String curveName = getNameOfNamedCurve(namedCurve); if (curveName == null) { return null; } // Parameters are lazily created the first time a particular curve is accessed X9ECParameters ecP = CustomNamedCurves.getByName(curveName); if (ecP == null) { ecP = ECNamedCurveTable.getByName(curveName); if (ecP == null) { return null; } } // It's a bit inefficient to do this conversion every time return new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); }
@BeforeClass public static void beforeAll() { curve = new ECDomainParameters(IES_CURVE_PARAM.getCurve(), IES_CURVE_PARAM.getG(), IES_CURVE_PARAM.getN(), IES_CURVE_PARAM.getH()); }