Search in sources :

Example 1 with DSTU4145ParameterSpec

use of com.github.zhenwei.provider.jcajce.spec.DSTU4145ParameterSpec 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

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