Search in sources :

Example 1 with ECNamedCurveGenParameterSpec

use of com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof GOST3410ParameterSpec) {
        GOST3410ParameterSpec gostParams = (GOST3410ParameterSpec) params;
        init(gostParams, random);
    } else if (params instanceof ECParameterSpec) {
        ECParameterSpec p = (ECParameterSpec) params;
        this.ecParams = params;
        param = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), random);
        engine.init(param);
        initialised = true;
    } else if (params instanceof java.security.spec.ECParameterSpec) {
        java.security.spec.ECParameterSpec p = (java.security.spec.ECParameterSpec) params;
        this.ecParams = params;
        ECCurve curve = EC5Util.convertCurve(p.getCurve());
        ECPoint g = EC5Util.convertPoint(curve, p.getGenerator());
        param = new ECKeyGenerationParameters(new ECDomainParameters(curve, g, p.getOrder(), BigInteger.valueOf(p.getCofactor())), random);
        engine.init(param);
        initialised = true;
    } else if (params instanceof ECGenParameterSpec || params instanceof ECNamedCurveGenParameterSpec) {
        String curveName;
        if (params instanceof ECGenParameterSpec) {
            curveName = ((ECGenParameterSpec) params).getName();
        } else {
            curveName = ((ECNamedCurveGenParameterSpec) params).getName();
        }
        init(new GOST3410ParameterSpec(curveName), random);
    } else if (params == null && WeGooProvider.CONFIGURATION.getEcImplicitlyCa() != null) {
        ECParameterSpec p = WeGooProvider.CONFIGURATION.getEcImplicitlyCa();
        this.ecParams = params;
        param = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), random);
        engine.init(param);
        initialised = true;
    } else if (params == null && WeGooProvider.CONFIGURATION.getEcImplicitlyCa() == null) {
        throw new InvalidAlgorithmParameterException("null parameter passed but no implicitCA set");
    } else {
        throw new InvalidAlgorithmParameterException("parameter object not a ECParameterSpec: " + params.getClass().getName());
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECGenParameterSpec(java.security.spec.ECGenParameterSpec) ECNamedCurveGenParameterSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECParameterSpec(com.github.zhenwei.provider.jce.spec.ECParameterSpec) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) GOST3410ParameterSpec(com.github.zhenwei.provider.jcajce.spec.GOST3410ParameterSpec) ECKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)

Example 2 with ECNamedCurveGenParameterSpec

use of com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof GOST3410ParameterSpec) {
        GOST3410ParameterSpec gostParams = (GOST3410ParameterSpec) params;
        init(gostParams, random);
    } else if (params instanceof ECParameterSpec) {
        ECParameterSpec p = (ECParameterSpec) params;
        this.ecParams = params;
        param = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), random);
        engine.init(param);
        initialised = true;
    } else if (params instanceof java.security.spec.ECParameterSpec) {
        java.security.spec.ECParameterSpec p = (java.security.spec.ECParameterSpec) params;
        this.ecParams = params;
        ECCurve curve = EC5Util.convertCurve(p.getCurve());
        ECPoint g = EC5Util.convertPoint(curve, p.getGenerator());
        param = new ECKeyGenerationParameters(new ECDomainParameters(curve, g, p.getOrder(), BigInteger.valueOf(p.getCofactor())), random);
        engine.init(param);
        initialised = true;
    } else if (params instanceof ECGenParameterSpec || params instanceof ECNamedCurveGenParameterSpec) {
        String curveName;
        if (params instanceof ECGenParameterSpec) {
            curveName = ((ECGenParameterSpec) params).getName();
        } else {
            curveName = ((ECNamedCurveGenParameterSpec) params).getName();
        }
        init(new GOST3410ParameterSpec(curveName), random);
    } else if (params == null && WeGooProvider.CONFIGURATION.getEcImplicitlyCa() != null) {
        ECParameterSpec p = WeGooProvider.CONFIGURATION.getEcImplicitlyCa();
        this.ecParams = params;
        param = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), random);
        engine.init(param);
        initialised = true;
    } else if (params == null && WeGooProvider.CONFIGURATION.getEcImplicitlyCa() == null) {
        throw new InvalidAlgorithmParameterException("null parameter passed but no implicitCA set");
    } else {
        throw new InvalidAlgorithmParameterException("parameter object not a ECParameterSpec: " + params.getClass().getName());
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECGenParameterSpec(java.security.spec.ECGenParameterSpec) ECNamedCurveGenParameterSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECParameterSpec(com.github.zhenwei.provider.jce.spec.ECParameterSpec) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) GOST3410ParameterSpec(com.github.zhenwei.provider.jcajce.spec.GOST3410ParameterSpec) ECKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)

Example 3 with ECNamedCurveGenParameterSpec

use of com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof ECParameterSpec) {
        ECParameterSpec p = (ECParameterSpec) params;
        this.ecParams = params;
        param = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), random);
        engine.init(param);
        initialised = true;
    } else if (params instanceof java.security.spec.ECParameterSpec) {
        java.security.spec.ECParameterSpec p = (java.security.spec.ECParameterSpec) params;
        this.ecParams = params;
        ECCurve curve = EC5Util.convertCurve(p.getCurve());
        ECPoint g = EC5Util.convertPoint(curve, p.getGenerator());
        if (p instanceof DSTU4145ParameterSpec) {
            DSTU4145ParameterSpec dstuSpec = (DSTU4145ParameterSpec) p;
            param = new ECKeyGenerationParameters(new DSTU4145Parameters(new ECDomainParameters(curve, g, p.getOrder(), BigInteger.valueOf(p.getCofactor())), dstuSpec.getDKE()), random);
        } else {
            param = new ECKeyGenerationParameters(new ECDomainParameters(curve, g, p.getOrder(), BigInteger.valueOf(p.getCofactor())), random);
        }
        engine.init(param);
        initialised = true;
    } else if (params instanceof ECGenParameterSpec || params instanceof ECNamedCurveGenParameterSpec) {
        String curveName;
        if (params instanceof ECGenParameterSpec) {
            curveName = ((ECGenParameterSpec) params).getName();
        } else {
            curveName = ((ECNamedCurveGenParameterSpec) params).getName();
        }
        // ECDomainParameters ecP = ECGOST3410NamedCurves.getByName(curveName);
        ECDomainParameters ecP = DSTU4145NamedCurves.getByOID(new ASN1ObjectIdentifier(curveName));
        if (ecP == null) {
            throw new InvalidAlgorithmParameterException("unknown curve name: " + curveName);
        }
        this.ecParams = new ECNamedCurveSpec(curveName, ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
        java.security.spec.ECParameterSpec p = (java.security.spec.ECParameterSpec) ecParams;
        ECCurve curve = EC5Util.convertCurve(p.getCurve());
        ECPoint g = EC5Util.convertPoint(curve, p.getGenerator());
        param = new ECKeyGenerationParameters(new ECDomainParameters(curve, g, p.getOrder(), BigInteger.valueOf(p.getCofactor())), random);
        engine.init(param);
        initialised = true;
    } else if (params == null && WeGooProvider.CONFIGURATION.getEcImplicitlyCa() != null) {
        ECParameterSpec p = WeGooProvider.CONFIGURATION.getEcImplicitlyCa();
        this.ecParams = params;
        param = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()), random);
        engine.init(param);
        initialised = true;
    } else if (params == null && WeGooProvider.CONFIGURATION.getEcImplicitlyCa() == null) {
        throw new InvalidAlgorithmParameterException("null parameter passed but no implicitCA set");
    } else {
        throw new InvalidAlgorithmParameterException("parameter object not a ECParameterSpec: " + params.getClass().getName());
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECGenParameterSpec(java.security.spec.ECGenParameterSpec) ECNamedCurveGenParameterSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec) DSTU4145ParameterSpec(com.github.zhenwei.provider.jcajce.spec.DSTU4145ParameterSpec) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECParameterSpec(com.github.zhenwei.provider.jce.spec.ECParameterSpec) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) DSTU4145Parameters(com.github.zhenwei.core.crypto.params.DSTU4145Parameters) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) ECKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters) ECNamedCurveSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveSpec)

Aggregations

ECDomainParameters (com.github.zhenwei.core.crypto.params.ECDomainParameters)3 ECKeyGenerationParameters (com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)3 ECCurve (com.github.zhenwei.core.math.ec.ECCurve)3 ECPoint (com.github.zhenwei.core.math.ec.ECPoint)3 ECNamedCurveGenParameterSpec (com.github.zhenwei.provider.jce.spec.ECNamedCurveGenParameterSpec)3 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 ECGenParameterSpec (java.security.spec.ECGenParameterSpec)3 GOST3410ParameterSpec (com.github.zhenwei.provider.jcajce.spec.GOST3410ParameterSpec)2 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)1 DSTU4145Parameters (com.github.zhenwei.core.crypto.params.DSTU4145Parameters)1 DSTU4145ParameterSpec (com.github.zhenwei.provider.jcajce.spec.DSTU4145ParameterSpec)1 ECNamedCurveSpec (com.github.zhenwei.provider.jce.spec.ECNamedCurveSpec)1