/** * TODO want to figure out why BouncyCastle does not work. * @return The initialized curve25519 parameter spec */ public static AlgorithmParameterSpec getCurve25519Params() { X9ECParameters ecP = CustomNamedCurves.getByName("curve25519"); return new ECParameterSpec(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed()); } }
public BCECGOST3410PrivateKey( org.bouncycastle.jce.spec.ECPrivateKeySpec spec) { this.d = spec.getD(); if (spec.getParams() != null) // can be null if implicitlyCA { ECCurve curve = spec.getParams().getCurve(); EllipticCurve ellipticCurve; ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed()); this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams()); } else { this.ecSpec = null; } }
public static ECParameterSpec convertSpec( EllipticCurve ellipticCurve, org.bouncycastle.jce.spec.ECParameterSpec spec) { if (spec instanceof ECNamedCurveParameterSpec) { return new ECNamedCurveSpec( ((ECNamedCurveParameterSpec)spec).getName(), ellipticCurve, convertPoint(spec.getG()), spec.getN(), spec.getH()); } else { return new ECParameterSpec( ellipticCurve, convertPoint(spec.getG()), spec.getN(), spec.getH().intValue()); } }
public int engineGetKeySize(Key key) { if (key instanceof ECKey) { return ((ECKey)key).getParameters().getCurve().getFieldSize(); } else { throw new IllegalArgumentException("not an EC key"); } }
private static org.bouncycastle.math.ec.ECPoint calculateQ(BigInteger d, org.bouncycastle.jce.spec.ECParameterSpec spec) { return spec.getG().multiply(d).normalize(); }
public static int getOrderBitLength(ProviderConfiguration configuration, BigInteger order, BigInteger privateValue) { if (order == null) // implicitly CA { ECParameterSpec implicitCA = configuration.getEcImplicitlyCa(); if (implicitCA == null) { return privateValue.bitLength(); // a guess but better than an exception! } return implicitCA.getN().bitLength(); } else { return order.bitLength(); } }
public static ECPublicKeyParameters convertPublicKeyToParameters(BCECPublicKey ecPubKey) { ECParameterSpec parameterSpec = ecPubKey.getParameters(); ECDomainParameters domainParameters = new ECDomainParameters(parameterSpec.getCurve(), parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH()); return new ECPublicKeyParameters(ecPubKey.getQ(), domainParameters); }
public BCDSTU4145PrivateKey( org.bouncycastle.jce.spec.ECPrivateKeySpec spec) { this.d = spec.getD(); if (spec.getParams() != null) // can be null if implicitlyCA { ECCurve curve = spec.getParams().getCurve(); EllipticCurve ellipticCurve; ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed()); this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams()); } else { this.ecSpec = null; } }
public int engineGetKeySize(Key key) { if (key instanceof ECKey) { return ((ECKey)key).getParameters().getCurve().getFieldSize(); } else { throw new IllegalArgumentException("not an EC key"); } }
private org.bouncycastle.math.ec.ECPoint calculateQ(org.bouncycastle.jce.spec.ECParameterSpec spec) { return spec.getG().multiply(d).normalize(); }
/** * Get the key length for a public key * * @param pk * The public key * @return The key length */ public int getKeyLength(PublicKey pk) { LOGGER.debug("Extract key size"); int len= -1; if (pk instanceof RSAPublicKey) { final RSAPublicKey rsapub= (RSAPublicKey) pk; len= rsapub.getModulus().bitLength(); } else if (pk instanceof JCEECPublicKey) { len= ((JCEECPublicKey) pk).getParameters().getN().bitLength(); } else if (pk instanceof ECPublicKey) { len= ((ECPublicKey) pk).getParams().getOrder().bitLength(); } else if (pk instanceof DSAPublicKey) { len= ((DSAPublicKey) pk).getParams().getP().bitLength(); } return len; }
public static ECDomainParameters getDomainParameters( ProviderConfiguration configuration, java.security.spec.ECParameterSpec params) { ECDomainParameters domainParameters; if (params == null) { org.bouncycastle.jce.spec.ECParameterSpec iSpec = configuration.getEcImplicitlyCa(); domainParameters = new ECDomainParameters(iSpec.getCurve(), iSpec.getG(), iSpec.getN(), iSpec.getH(), iSpec.getSeed()); } else { domainParameters = ECUtil.getDomainParameters(configuration, convertSpec(params, false)); } return domainParameters; }
ECParameterSpec ecSpec = new ECParameterSpec(ecParam.getCurve(), ecParam.getG(), ecParam.getN(), ecParam.getH(), ecParam.getSeed()); KeyFactory keyFactory = KeyFactory.getInstance(ECDSA, BouncyCastleProvider.PROVIDER_NAME);
public BCECGOST3410_2012PrivateKey( org.bouncycastle.jce.spec.ECPrivateKeySpec spec) { this.d = spec.getD(); if (spec.getParams() != null) // can be null if implicitlyCA { ECCurve curve = spec.getParams().getCurve(); EllipticCurve ellipticCurve; ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed()); this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams()); } else { this.ecSpec = null; } }
/** * Load a public key from the private key. * * @param privateKey * @return */ public static ECPublicKey loadPublicKey(ECPrivateKey privateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException { KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM, PROVIDER_NAME); ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(CURVE); ECPoint Q = ecSpec.getG().multiply(privateKey.getD()); byte[] publicDerBytes = Q.getEncoded(false); ECPoint point = ecSpec.getCurve().decodePoint(publicDerBytes); ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, ecSpec); return (ECPublicKey) keyFactory.generatePublic(pubSpec); }
private PublicKey loadPublicKey(byte[] data) throws Exception { ECParameterSpec params = ECNamedCurveTable.getParameterSpec("prime192v1"); ECPublicKeySpec pubKey = new ECPublicKeySpec(params.getCurve().decodePoint(data), params); KeyFactory kf = KeyFactory.getInstance("ECDH", "BC"); return kf.generatePublic(pubKey); }
@Override public PublicKey publicKeyFromPrivateKey(PrivateKey privateKey, KeyFactory keyFactory) throws InvalidKeySpecException { ECPrivateKey ecPrivateKey = (ECPrivateKey) privateKey; ECParameterSpec ecParams = ecPrivateKey.getParameters(); ECPoint q = ecParams.getG().multiply(ecPrivateKey.getD()); ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(q, ecParams); return keyFactory.generatePublic(publicKeySpec); } }