Search in sources :

Example 6 with ECKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method init.

private void init(GOST3410ParameterSpec gostParams, SecureRandom random) throws InvalidAlgorithmParameterException {
    ASN1ObjectIdentifier oid = gostParams.getPublicKeyParamSet();
    X9ECParameters ecP = ECGOST3410NamedCurves.getByOIDX9(oid);
    if (ecP == null) {
        throw new InvalidAlgorithmParameterException("unknown curve: " + oid);
    }
    this.ecParams = new ECNamedCurveSpec(ECGOST3410NamedCurves.getName(oid), ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
    param = new ECKeyGenerationParameters(new ECGOST3410Parameters(new ECNamedDomainParameters(oid, ecP), oid, gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()), random);
    engine.init(param);
    initialised = true;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) X9ECParameters(com.github.zhenwei.core.asn1.x9.X9ECParameters) ECGOST3410Parameters(com.github.zhenwei.core.crypto.params.ECGOST3410Parameters) ECNamedDomainParameters(com.github.zhenwei.core.crypto.params.ECNamedDomainParameters) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) ECNamedCurveSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveSpec) ECKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)

Example 7 with ECKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method init.

private void init(GOST3410ParameterSpec gostParams, SecureRandom random) throws InvalidAlgorithmParameterException {
    X9ECParameters ecP = ECGOST3410NamedCurves.getByOIDX9(gostParams.getPublicKeyParamSet());
    if (ecP == null) {
        throw new InvalidAlgorithmParameterException("unknown curve: " + gostParams.getPublicKeyParamSet());
    }
    this.ecParams = new ECNamedCurveSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()), ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
    param = new ECKeyGenerationParameters(new ECGOST3410Parameters(new ECNamedDomainParameters(gostParams.getPublicKeyParamSet(), ecP), gostParams.getPublicKeyParamSet(), gostParams.getDigestParamSet(), gostParams.getEncryptionParamSet()), random);
    engine.init(param);
    initialised = true;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) X9ECParameters(com.github.zhenwei.core.asn1.x9.X9ECParameters) ECGOST3410Parameters(com.github.zhenwei.core.crypto.params.ECGOST3410Parameters) ECNamedDomainParameters(com.github.zhenwei.core.crypto.params.ECNamedDomainParameters) ECNamedCurveSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveSpec) ECKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)

Example 8 with ECKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters 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

ECKeyGenerationParameters (com.github.zhenwei.core.crypto.params.ECKeyGenerationParameters)8 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)6 ECDomainParameters (com.github.zhenwei.core.crypto.params.ECDomainParameters)4 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 ECNamedCurveSpec (com.github.zhenwei.provider.jce.spec.ECNamedCurveSpec)3 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)3 ECGenParameterSpec (java.security.spec.ECGenParameterSpec)3 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)2 X9ECParameters (com.github.zhenwei.core.asn1.x9.X9ECParameters)2 ECKeyPairGenerator (com.github.zhenwei.core.crypto.generators.ECKeyPairGenerator)2 ECGOST3410Parameters (com.github.zhenwei.core.crypto.params.ECGOST3410Parameters)2 ECNamedDomainParameters (com.github.zhenwei.core.crypto.params.ECNamedDomainParameters)2 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)2 GOST3410ParameterSpec (com.github.zhenwei.provider.jcajce.spec.GOST3410ParameterSpec)2 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 CipherParameters (com.github.zhenwei.core.crypto.CipherParameters)1 DataLengthException (com.github.zhenwei.core.crypto.DataLengthException)1 InvalidCipherTextException (com.github.zhenwei.core.crypto.InvalidCipherTextException)1