Search in sources :

Example 1 with LMSParameters

use of org.bouncycastle.pqc.crypto.lms.LMSParameters in project jmulticard by ctt-gob-es.

the class LMSKeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        param = new LMSKeyGenerationParameters(new LMSParameters(LMSigParameters.lms_sha256_n32_h10, LMOtsParameters.sha256_n32_w2), random);
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    if (engine instanceof LMSKeyPairGenerator) {
        LMSPublicKeyParameters pub = (LMSPublicKeyParameters) pair.getPublic();
        LMSPrivateKeyParameters priv = (LMSPrivateKeyParameters) pair.getPrivate();
        return new KeyPair(new BCLMSPublicKey(pub), new BCLMSPrivateKey(priv));
    } else {
        HSSPublicKeyParameters pub = (HSSPublicKeyParameters) pair.getPublic();
        HSSPrivateKeyParameters priv = (HSSPrivateKeyParameters) pair.getPrivate();
        return new KeyPair(new BCLMSPublicKey(pub), new BCLMSPrivateKey(priv));
    }
}
Also used : KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair) LMSKeyGenerationParameters(org.bouncycastle.pqc.crypto.lms.LMSKeyGenerationParameters) LMSPrivateKeyParameters(org.bouncycastle.pqc.crypto.lms.LMSPrivateKeyParameters) LMSKeyPairGenerator(org.bouncycastle.pqc.crypto.lms.LMSKeyPairGenerator) LMSPublicKeyParameters(org.bouncycastle.pqc.crypto.lms.LMSPublicKeyParameters) LMSParameters(org.bouncycastle.pqc.crypto.lms.LMSParameters) HSSPrivateKeyParameters(org.bouncycastle.pqc.crypto.lms.HSSPrivateKeyParameters) HSSPublicKeyParameters(org.bouncycastle.pqc.crypto.lms.HSSPublicKeyParameters) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Example 2 with LMSParameters

use of org.bouncycastle.pqc.crypto.lms.LMSParameters in project jmulticard by ctt-gob-es.

the class LMSKeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof LMSKeyGenParameterSpec) {
        LMSKeyGenParameterSpec lmsParams = (LMSKeyGenParameterSpec) params;
        param = new LMSKeyGenerationParameters(new LMSParameters(lmsParams.getSigParams(), lmsParams.getOtsParams()), random);
        engine = new LMSKeyPairGenerator();
        engine.init(param);
    } else if (params instanceof LMSHSSKeyGenParameterSpec) {
        LMSKeyGenParameterSpec[] lmsParams = ((LMSHSSKeyGenParameterSpec) params).getLMSSpecs();
        LMSParameters[] hssParams = new LMSParameters[lmsParams.length];
        for (int i = 0; i != lmsParams.length; i++) {
            hssParams[i] = new LMSParameters(lmsParams[i].getSigParams(), lmsParams[i].getOtsParams());
        }
        param = new HSSKeyGenerationParameters(hssParams, random);
        engine = new HSSKeyPairGenerator();
        engine.init(param);
    } else if (params instanceof LMSParameterSpec) {
        LMSParameterSpec lmsParams = (LMSParameterSpec) params;
        param = new LMSKeyGenerationParameters(new LMSParameters(lmsParams.getSigParams(), lmsParams.getOtsParams()), random);
        engine = new LMSKeyPairGenerator();
        engine.init(param);
    } else if (params instanceof LMSHSSParameterSpec) {
        LMSParameterSpec[] lmsParams = ((LMSHSSParameterSpec) params).getLMSSpecs();
        LMSParameters[] hssParams = new LMSParameters[lmsParams.length];
        for (int i = 0; i != lmsParams.length; i++) {
            hssParams[i] = new LMSParameters(lmsParams[i].getSigParams(), lmsParams[i].getOtsParams());
        }
        param = new HSSKeyGenerationParameters(hssParams, random);
        engine = new HSSKeyPairGenerator();
        engine.init(param);
    } else {
        throw new InvalidAlgorithmParameterException("parameter object not a LMSParameterSpec/LMSHSSParameterSpec");
    }
    initialised = true;
}
Also used : HSSKeyGenerationParameters(org.bouncycastle.pqc.crypto.lms.HSSKeyGenerationParameters) LMSKeyGenParameterSpec(org.bouncycastle.pqc.jcajce.spec.LMSKeyGenParameterSpec) LMSHSSParameterSpec(org.bouncycastle.pqc.jcajce.spec.LMSHSSParameterSpec) LMSKeyGenerationParameters(org.bouncycastle.pqc.crypto.lms.LMSKeyGenerationParameters) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) LMSParameterSpec(org.bouncycastle.pqc.jcajce.spec.LMSParameterSpec) LMSKeyPairGenerator(org.bouncycastle.pqc.crypto.lms.LMSKeyPairGenerator) LMSParameters(org.bouncycastle.pqc.crypto.lms.LMSParameters) LMSHSSKeyGenParameterSpec(org.bouncycastle.pqc.jcajce.spec.LMSHSSKeyGenParameterSpec) HSSKeyPairGenerator(org.bouncycastle.pqc.crypto.lms.HSSKeyPairGenerator)

Aggregations

LMSKeyGenerationParameters (org.bouncycastle.pqc.crypto.lms.LMSKeyGenerationParameters)2 LMSKeyPairGenerator (org.bouncycastle.pqc.crypto.lms.LMSKeyPairGenerator)2 LMSParameters (org.bouncycastle.pqc.crypto.lms.LMSParameters)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyPair (java.security.KeyPair)1 AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)1 HSSKeyGenerationParameters (org.bouncycastle.pqc.crypto.lms.HSSKeyGenerationParameters)1 HSSKeyPairGenerator (org.bouncycastle.pqc.crypto.lms.HSSKeyPairGenerator)1 HSSPrivateKeyParameters (org.bouncycastle.pqc.crypto.lms.HSSPrivateKeyParameters)1 HSSPublicKeyParameters (org.bouncycastle.pqc.crypto.lms.HSSPublicKeyParameters)1 LMSPrivateKeyParameters (org.bouncycastle.pqc.crypto.lms.LMSPrivateKeyParameters)1 LMSPublicKeyParameters (org.bouncycastle.pqc.crypto.lms.LMSPublicKeyParameters)1 LMSHSSKeyGenParameterSpec (org.bouncycastle.pqc.jcajce.spec.LMSHSSKeyGenParameterSpec)1 LMSHSSParameterSpec (org.bouncycastle.pqc.jcajce.spec.LMSHSSParameterSpec)1 LMSKeyGenParameterSpec (org.bouncycastle.pqc.jcajce.spec.LMSKeyGenParameterSpec)1 LMSParameterSpec (org.bouncycastle.pqc.jcajce.spec.LMSParameterSpec)1