Search in sources :

Example 26 with AsymmetricCipherKeyPair

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

the class XMSSMTKeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        param = new XMSSMTKeyGenerationParameters(new XMSSMTParameters(10, 20, new SHA512Digest()), random);
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    XMSSMTPublicKeyParameters pub = (XMSSMTPublicKeyParameters) pair.getPublic();
    XMSSMTPrivateKeyParameters priv = (XMSSMTPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCXMSSMTPublicKey(treeDigest, pub), new BCXMSSMTPrivateKey(treeDigest, priv));
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) XMSSMTKeyGenerationParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTKeyGenerationParameters) XMSSMTPublicKeyParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTPublicKeyParameters) XMSSMTParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) XMSSMTPrivateKeyParameters(com.github.zhenwei.core.pqc.crypto.xmss.XMSSMTPrivateKeyParameters)

Example 27 with AsymmetricCipherKeyPair

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

the class McElieceCCA2KeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    if (!initialized) {
        initializeDefault();
    }
    // finite field GF(2^m)
    GF2mField field = new GF2mField(m, fieldPoly);
    // irreducible Goppa polynomial
    PolynomialGF2mSmallM gp = new PolynomialGF2mSmallM(field, t, PolynomialGF2mSmallM.RANDOM_IRREDUCIBLE_POLYNOMIAL, random);
    // generate canonical check matrix
    GF2Matrix h = GoppaCode.createCanonicalCheckMatrix(field, gp);
    // compute short systematic form of check matrix
    MaMaPe mmp = GoppaCode.computeSystematicForm(h, random);
    GF2Matrix shortH = mmp.getSecondMatrix();
    Permutation p = mmp.getPermutation();
    // compute short systematic form of generator matrix
    GF2Matrix shortG = (GF2Matrix) shortH.computeTranspose();
    // obtain number of rows of G (= dimension of the code)
    int k = shortG.getNumRows();
    // generate keys
    McElieceCCA2PublicKeyParameters pubKey = new McElieceCCA2PublicKeyParameters(n, t, shortG, mcElieceCCA2Params.getParameters().getDigest());
    McElieceCCA2PrivateKeyParameters privKey = new McElieceCCA2PrivateKeyParameters(n, k, field, gp, p, mcElieceCCA2Params.getParameters().getDigest());
    // return key pair
    return new AsymmetricCipherKeyPair(pubKey, privKey);
}
Also used : GF2mField(com.github.zhenwei.core.pqc.math.linearalgebra.GF2mField) PolynomialGF2mSmallM(com.github.zhenwei.core.pqc.math.linearalgebra.PolynomialGF2mSmallM) GF2Matrix(com.github.zhenwei.core.pqc.math.linearalgebra.GF2Matrix) Permutation(com.github.zhenwei.core.pqc.math.linearalgebra.Permutation) MaMaPe(com.github.zhenwei.core.pqc.math.linearalgebra.GoppaCode.MaMaPe) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 28 with AsymmetricCipherKeyPair

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

the class LMSKeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    SecureRandom source = param.getRandom();
    byte[] I = new byte[16];
    source.nextBytes(I);
    byte[] rootSecret = new byte[32];
    source.nextBytes(rootSecret);
    LMSPrivateKeyParameters privKey = LMS.generateKeys(param.getParameters().getLMSigParam(), param.getParameters().getLMOTSParam(), 0, I, rootSecret);
    return new AsymmetricCipherKeyPair(privKey.getPublicKey(), privKey);
}
Also used : SecureRandom(java.security.SecureRandom) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 29 with AsymmetricCipherKeyPair

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

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        Integer paramStrength = Integers.valueOf(strength);
        if (params.containsKey(paramStrength)) {
            param = (DSAKeyGenerationParameters) params.get(paramStrength);
        } else {
            synchronized (lock) {
                // our key size.
                if (params.containsKey(paramStrength)) {
                    param = (DSAKeyGenerationParameters) params.get(paramStrength);
                } else {
                    DSAParametersGenerator pGen;
                    DSAParameterGenerationParameters dsaParams;
                    int certainty = PrimeCertaintyCalculator.getDefaultCertainty(strength);
                    // For legacy keysize that is less than 1024-bit, we just use the 186-2 style parameters
                    if (strength == 1024) {
                        pGen = new DSAParametersGenerator();
                        if (Properties.isOverrideSet("org.bouncycastle.dsa.FIPS186-2for1024bits")) {
                            pGen.init(strength, certainty, random);
                        } else {
                            dsaParams = new DSAParameterGenerationParameters(1024, 160, certainty, random);
                            pGen.init(dsaParams);
                        }
                    } else if (strength > 1024) {
                        dsaParams = new DSAParameterGenerationParameters(strength, 256, certainty, random);
                        pGen = new DSAParametersGenerator(new SHA256Digest());
                        pGen.init(dsaParams);
                    } else {
                        pGen = new DSAParametersGenerator();
                        pGen.init(strength, certainty, random);
                    }
                    param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
                    params.put(paramStrength, param);
                }
            }
        }
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    DSAPublicKeyParameters pub = (DSAPublicKeyParameters) pair.getPublic();
    DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCDSAPublicKey(pub), new BCDSAPrivateKey(priv));
}
Also used : DSAParametersGenerator(com.github.zhenwei.core.crypto.generators.DSAParametersGenerator) DSAPublicKeyParameters(com.github.zhenwei.core.crypto.params.DSAPublicKeyParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) DSAParameterGenerationParameters(com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters) DSAKeyGenerationParameters(com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters) DSAPrivateKeyParameters(com.github.zhenwei.core.crypto.params.DSAPrivateKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 30 with AsymmetricCipherKeyPair

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

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        DHParameterSpec dhParams = WeGooProvider.CONFIGURATION.getDHDefaultParameters(strength);
        if (dhParams != null) {
            param = new ElGamalKeyGenerationParameters(random, new ElGamalParameters(dhParams.getP(), dhParams.getG(), dhParams.getL()));
        } else {
            ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();
            pGen.init(strength, certainty, random);
            param = new ElGamalKeyGenerationParameters(random, pGen.generateParameters());
        }
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    ElGamalPublicKeyParameters pub = (ElGamalPublicKeyParameters) pair.getPublic();
    ElGamalPrivateKeyParameters priv = (ElGamalPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCElGamalPublicKey(pub), new BCElGamalPrivateKey(priv));
}
Also used : KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) ElGamalParameters(com.github.zhenwei.core.crypto.params.ElGamalParameters) ElGamalPrivateKeyParameters(com.github.zhenwei.core.crypto.params.ElGamalPrivateKeyParameters) ElGamalKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ElGamalKeyGenerationParameters) DHParameterSpec(javax.crypto.spec.DHParameterSpec) ElGamalPublicKeyParameters(com.github.zhenwei.core.crypto.params.ElGamalPublicKeyParameters) ElGamalParametersGenerator(com.github.zhenwei.core.crypto.generators.ElGamalParametersGenerator) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Aggregations

AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)41 KeyPair (java.security.KeyPair)17 BigInteger (java.math.BigInteger)9 ECPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ECPrivateKeyParameters)6 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)6 DHPublicKeyParameters (com.github.zhenwei.core.crypto.params.DHPublicKeyParameters)4 DHParameters (com.github.zhenwei.core.crypto.params.DHParameters)3 DHPrivateKeyParameters (com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters)3 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)3 SHA512Digest (com.github.zhenwei.core.crypto.digests.SHA512Digest)2 DHKeyGenerationParameters (com.github.zhenwei.core.crypto.params.DHKeyGenerationParameters)2 DSAPrivateKeyParameters (com.github.zhenwei.core.crypto.params.DSAPrivateKeyParameters)2 DSAPublicKeyParameters (com.github.zhenwei.core.crypto.params.DSAPublicKeyParameters)2 ElGamalParameters (com.github.zhenwei.core.crypto.params.ElGamalParameters)2 ElGamalPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ElGamalPrivateKeyParameters)2 ElGamalPublicKeyParameters (com.github.zhenwei.core.crypto.params.ElGamalPublicKeyParameters)2 GOST3410PrivateKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters)2 GOST3410PublicKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters)2 RSAKeyParameters (com.github.zhenwei.core.crypto.params.RSAKeyParameters)2 RSAPrivateCrtKeyParameters (com.github.zhenwei.core.crypto.params.RSAPrivateCrtKeyParameters)2